Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 71 additions & 6 deletions MultilanguagePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ class MultilanguagePlugin extends Omeka_Plugin_AbstractPlugin
'after_save_simple_pages_page',
// No hook for exhibit form.
'after_save_exhibit',
'after_save_exhibit_page',
'after_delete_simple_pages_page',
'after_delete_exhibit',
'after_delete_exhibit_page',
// No hook to browse exhibit page: the language is the exhibit one.
'exhibits_browse_sql',
'simple_pages_pages_browse_sql',
);
Expand Down Expand Up @@ -151,8 +154,6 @@ public function hookUpgrade($args)
ADD FOREIGN KEY (`user_id`) REFERENCES `omeka_users` (`id`) ON DELETE CASCADE;
";
$db->query($sql);

// TODO Remove deleted records from MultilanguageContentLanguage.
}

if (version_compare($oldVersion, '1.2', '<')) {
Expand All @@ -177,9 +178,20 @@ public function hookUpgrade($args)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;
";
$db->query($sql);
}

// TODO Remove deleted records from MultilanguageContentLanguage.
if (version_compare($oldVersion, '1.4', '<')) {
// Set language of all exhibit pages to the exhibit’s one.
$exhibits = get_records('Exhibit', array(), 0);
foreach ($exhibits as $exhibit) {
$contentLanguage = $this->localeCodeRecord($exhibit);
if ($contentLanguage) {
$this->updateOrDeleteExhibitPagesLang($exhibit->id, $contentLanguage->lang);
}
}
}

// TODO Remove deleted records from MultilanguageContentLanguage.
}

public function hookConfigForm()
Expand Down Expand Up @@ -353,6 +365,25 @@ public function hookAfterSaveSimplePagesPage($args)
public function hookAfterSaveExhibit($args)
{
$this->saveMultilangueRecord($args);

// Set language of all exhibit pages to the exhibit’s one.
$exhibit = $args['record'];
$contentLanguage = $this->localeCodeRecord($exhibit);
$lang = $contentLanguage->lang ? $contentLanguage->lang : null;
$this->updateOrDeleteExhibitPagesLang($exhibit->id, $lang);
}

public function hookAfterSaveExhibitPage($args)
{
// Force the lang of the exhibit page.
$record = $args['record'];
$exhibit = get_record_by_id('Exhibit', $record->exhibit_id);
$contentLanguage = $this->localeCodeRecord($exhibit);
$lang = $contentLanguage->lang ? $contentLanguage->lang : null;
$post = $args['post'];
$post['locale_code'] = $lang;
$args['post'] = $post;
$this->saveMultilangueRecord($args);
}

public function hookAfterDeleteSimplePagesPage($args)
Expand All @@ -365,6 +396,11 @@ public function hookAfterDeleteExhibit($args)
$this->deleteMultilangueRecord($args);
}

public function hookAfterDeleteExhibitPage($args)
{
$this->deleteMultilangueRecord($args);
}

public function hookExhibitsBrowseSql($args)
{
$this->modelBrowseSql($args, 'Exhibit');
Expand Down Expand Up @@ -712,14 +748,14 @@ protected function processLocaleCodeRecord($record, $post)

protected function processRelatedRecordsRecord($record, $post)
{
$relatedRecordIds = array_filter(array_map('intval', $post['related_records']));
sort($relatedRecordIds);

// No relation can be set for a new record.
if ($post['insert']) {
return;
}

$relatedRecordIds = array_filter(array_map('intval', $post['related_records']));
sort($relatedRecordIds);

$recordType = get_class($record);
$recordId = (int) $record->id;

Expand Down Expand Up @@ -811,4 +847,33 @@ protected function relatedRecords($record, $recordId = null, $included = false)
->findRelatedRecords($recordType, $recordId, $included);
return $records;
}

/**
* Force the language of all pages to the exhibit's one.
*
* @param int $exhibitId
* @param string|null $lang
*/
protected function updateOrDeleteExhibitPagesLang($exhibitId, $lang)
{
$db = $this->_db;
if (empty($lang)) {
$sql = "
DELETE FROM `{$db->MultilanguageContentLanguage}`
WHERE `id` in (
SELECT DISTINCT `id` FROM `{$db->ExhibitPage}`
WHERE `exhibit_id` = $exhibitId;
);
";
} else {
$sql = "
INSERT INTO `{$db->MultilanguageContentLanguage}` (`record_type`, `record_id`, `lang`)
SELECT 'ExhibitPage', `id`, '$lang'
FROM `{$db->ExhibitPage}`
WHERE `exhibit_id` = $exhibitId;
";
}
$db->query($sql);
}
}

45 changes: 44 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Uncompress files and rename plugin folder `Multilanguage`.

Then install it like any other Omeka plugin and follow the config instructions.

The plugin [Translations] may be useful too to translate hard-coded strings of
the theme.


Configuration
-------------
Expand Down Expand Up @@ -63,9 +66,46 @@ the navigation menu.
For the exhibits, the list of exhibits will be limited to the exhibits that
match the current language of the user.

The language of the exhibit pages is forced to their exhibit’s one.

The pages and exhibits with a language that doesn’t match the current language
are still accessible, as long as the link is known or is hard coded somewhere.

### Theme adaptation

#### Standard functions

- `metadata()`
The option `no_escape` should be set to `true` anytime.

```php
// Instead of:
metadata($item, array('Dublin Core', 'Description'));
// the theme should use:
html_escape(metadata($item, array('Dublin Core', 'Description'), array('no_escape' => true)));
```
In particular, this is required when the option `snippet` is used.

```php
// Instead of:
metadata($item, array('Dublin Core', 'Description'), array('snippet' => 150));
// the theme should use:
html_escape(snippet(metadata($item, array('Dublin Core', 'Description'), array('no_escape' => true)), 0, 150));
```


#### Specific functions

Some functions should be used in themes in order to use features of Omeka.

- `locale_record()`
- `locale_record_from_id_or_slug()`
- `locale_exhibit_builder_display_random_featured_exhibit()`
- `locale_exhibit_builder_random_featured_exhibit()`
- `locale_convert_url()`

See the file [`helpers/functions.php`] for more information.


Limitations
-----------
Expand Down Expand Up @@ -105,7 +145,7 @@ exhibits in the new languages.

If the plugin is installed, Simple Pages and Exhibits content will disappear
without updating the language assignments from the Multilanguage Content tab.
Each new SP or Exhibit requires a language assignment from that page.
Each new simple page or Exhibit requires a language assignment from that page.


Warning
Expand Down Expand Up @@ -160,9 +200,12 @@ Copyright
[Multilanguage]: https://github.com/patrickmj/multilanguage
[Omeka]: https://omeka.org
[locale switcher]: https://github.com/Daniel-KM/Omeka-plugin-LocaleSwitcher
[Translations]: https://github.com/Daniel-KM/Omeka-plugin-Translations
[`helpers/functions.php`]: https://github.com/patrickmj/Multilanguage/blob/master/helpers/functions.php
[flag-icon-css]: http://flag-icon-css.lip.is/
[plugin issues]: https://github.com/patrickmj/Multilanguage/issues
[GNU/GPL v3]: https://www.gnu.org/licenses/gpl-3.0.html
[patrickmj]: https://github.com/patrickmj
[BibLibre]: https://github.com/BibLibre
[Daniel-KM]: https://github.com/Daniel-KM "Daniel Berthereau"

22 changes: 22 additions & 0 deletions controllers/SetlocaleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,28 @@ public function indexAction()
}
break;

case 'ExhibitPage':
$recordId = $request->getParam('id');
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$exhibit = get_record_by_id('Exhibit', $record->exhibit_id);
$url = exhibit_builder_exhibit_uri($exhibit, $record);
}
// If the page is not translated, redirect to the summary of the
// translated exhibit, if any.
else {
$record = get_record_by_id('ExhibitPage', $recordId);
$recordType = 'Exhibit';
$recordId = $record->exhibit_id;
$record = get_db()->getTable('MultilanguageRelatedRecord')
->findRelatedSourceRecordForLocale($recordType, $recordId, $locale);
if ($record) {
$url = exhibit_builder_exhibit_uri($record);
}
}
break;

case 'SimplePagesPage':
$recordId = $request->getParam('id');
$record = get_db()->getTable('MultilanguageRelatedRecord')
Expand Down
Loading