Permalink
Browse files

bug 538883: enable separate bookmark sets per locale; update review page

  • Loading branch information...
1 parent 5960815 commit b29db8db0e52ee43f49dab1672c719a4bb4e080b @lmorchard committed Sep 9, 2010
@@ -137,4 +137,45 @@ protected function _parseIniFile($filename)
return $return;
}
+ /**
+ * Assign the key's value to the property list. Handles the
+ * nest separator for sub-properties.
+ *
+ * @param array $config
+ * @param string $key
+ * @param string $value
+ * @throws Zend_Config_Exception
+ * @return array
+ */
+ protected function _processKey($config, $key, $value)
+ {
+ if (strpos($key, $this->_nestSeparator) !== false) {
+ $pieces = explode($this->_nestSeparator, $key, 2);
+ if (strlen($pieces[0]) && strlen($pieces[1])) {
+ if (!isset($config[$pieces[0]])) {
+ if ($pieces[0] === '0' && !empty($config)) {
+ // convert the current values in $config into an array
+ $config = array($pieces[0] => $config);
+ } else {
+ $config[$pieces[0]] = array();
+ }
+ } elseif (!is_array($config[$pieces[0]])) {
+ // HACK: Support both value and subkeys for a key.
+ $orig_val = $config[$pieces[0]];
+ $config[$pieces[0]] = array( '__value__' => $orig_val );
+ }
+ $config[$pieces[0]] = $this->_processKey($config[$pieces[0]], $pieces[1], $value);
+ } else {
+ /**
+ * @see Zend_Config_Exception
+ */
+ require_once 'Zend/Config/Exception.php';
+ throw new Zend_Config_Exception("Invalid key '$key'");
+ }
+ } else {
+ $config[$key] = $value;
+ }
+ return $config;
+ }
+
}
@@ -81,6 +81,11 @@ protected function _addBranch(Zend_Config $config, $parents = array())
$iniString .= $this->_addBranch($value, $group);
} else {
$this->_current_name = implode($this->_nestSeparator, $group);
+ if (strpos($this->_current_name, '.__value__')) {
+ $this->_current_name = str_replace(
+ '.__value__', '', $this->_current_name
+ );
+ }
$iniString .= $this->_current_name
. '='
. $this->_prepareValue($value)
@@ -208,6 +208,35 @@ public function getAssetsDirectory()
return $assets_dir;
}
+ /**
+ * Return the current default locale, which itself defaults to en-US if not
+ * set.
+ */
+ public function getDefaultLocale()
+ {
+ return empty($this->default_locale) ?
+ 'en-US' : $this->default_locale;
+ }
+
+ /**
+ * Return a list of locales for this repack, each associated with a display
+ * label.
+ */
+ public function getLocalesWithLabels()
+ {
+ $default_locale = $this->getDefaultLocale();
+ $locales = array(
+ // i18n: %1$s = default locale
+ $default_locale => sprintf(_('Default (%1$s)'), $default_locale),
+ );
+ foreach ($this->locales as $locale) {
+ if ($default_locale == $locale) continue;
+ $locales[$locale] =
+ locale_selection::$locale_details->getEnglishNameForLocale($locale);
+ }
+ return $locales;
+ }
+
/**
* Extract bookmarks from form data.
@@ -320,7 +349,12 @@ public function validateBookmarkSet($item) {
false : $errors;
// Push the current item into the list.
- $items_out[] = $item_out;
+ $cleaned_item_out = array();
+ foreach ($item_out as $key=>$val) {
+ if (!$val) continue;
+ $cleaned_item_out[$key] = $val;
+ }
+ $items_out[] = $cleaned_item_out;
}
$item['items'] = $items_out;
@@ -27,8 +27,13 @@
<?php $none = false; ?>
<li class="subsection">
<h4><?=_('Search Plugins')?></h4>
- <ul><?php foreach ($search_plugins as $locale=>$plugins): ?>
- <li><span class="locale_name"><?=html::specialchars(locale_selection::$locale_details->getEnglishNameForLocale($locale))?></span>
+ <ul>
+ <?php foreach ($repack->getLocalesWithLabels() as $locale=>$locale_name): ?>
+ <?php
+ if (empty($search_plugins[$locale])) continue;
+ $plugins = $search_plugins[$locale];
+ ?>
+ <li><span class="locale_name"><?=$locale_name?></span>
<ul><?php foreach ($plugins as $fn=>$plugin): ?>
<?php
$e = html::escape_array(array(
@@ -27,11 +27,10 @@
<?php if ($has_locales): ?>
<div class="locale-selector">
<ul class="locales clearfix">
+ <li class="selected default"><a href="#" data-locale="<?=$default_locale?>" title="<?=$default_locale?>"><?=_('Default')?></a></li>
<?php foreach ($repack->locales as $locale): ?>
- <?php $selected = ( $locale == $default_locale ) ?>
- <li class="<?= $selected ? 'selected' : '' ?>">
- <a href="#" data-locale="<?=$locale?>"><?=$locale?></a>
- </li>
+ <?php if ($default_locale==$locale) { continue; } ?>
+ <li><a href="#" data-locale="<?=$locale?>"><?=$locale?></a></li>
<?php endforeach ?>
</ul>
</div>
@@ -98,9 +97,11 @@
<?php if ($has_locales): ?>
<li class="field_locale">
<div class="locale_buttons">
+ <button class="locale locale-<?=$default_locale?> locale-default selected"
+ data-locale="<?=$default_locale?>"><?=_('Default')?></button>
<?php foreach ($repack->locales as $locale): ?>
- <?php $selected = ( $locale == $default_locale ) ?>
- <button class="locale locale-<?=$locale?> <?= $selected ? 'selected' : '' ?>"
+ <?php if ( $locale == $default_locale ) { continue; } ?>
+ <button class="locale locale-<?=$locale?>"
data-locale="<?=$locale?>"><?=$locale?></button>
<?php endforeach ?>
</div>
@@ -1,6 +1,8 @@
<?php slot::set('is_popup', 'true') ?>
<?php
$edit_base = $repack->url() . ';edit?section=';
+$default_locale = empty($repack->default_locale) ?
+ 'en-US' : $repack->default_locale;
?>
<div class="part" id="part1">
<div class="header">
@@ -41,21 +43,36 @@
<li class="section bookmarks clearfix">
<h3><?=_('Bookmarks')?> <a target="_top" href="<?=$edit_base?>bookmarks"><?=_('edit')?></a></h3>
+ <?php
+ $bookmarks = $repack->bookmarks;
+ $none = true;
+ ?>
<ul>
- <?php
- $bookmarks = $repack->bookmarks;
- $none = true;
- ?>
- <?php foreach (array('toolbar', 'menu') as $kind): ?>
- <?php if (!empty($bookmarks[$kind])): ?>
- <?php
- $none = false;
- $bookmarks[$kind]['type'] = 'folder';
- View::factory('repacks/edit/review_bookmarks', array(
- 'bookmark' => $bookmarks[$kind]
- ))->render(TRUE);
- ?>
- <?php endif ?>
+ <?php foreach ($repack->getLocalesWithLabels() as $locale=>$locale_name): ?>
+ <?php
+ $items_name = ($default_locale == $locale) ?
+ 'items' : "items.{$locale}";
+ if (empty($bookmarks['toolbar'][$items_name]) &&
+ empty($bookmarks['menu'][$items_name])) continue;
+ $none = false;
+ ?>
+ <li><span class="locale_name"><?=html::specialchars($locale_name)?></span>
+ <ul>
+ <?php foreach (array('toolbar', 'menu') as $kind): ?>
+ <?php if (!empty($bookmarks[$kind])): ?>
+ <?php
+ $bookmarks[$kind]['type'] = 'folder';
+ View::factory('repacks/edit/review_bookmarks', array(
+ 'repack' => $repack,
+ 'bookmark' => $bookmarks[$kind],
+ 'locale' => $locale,
+ 'default_locale' => $default_locale,
+ ))->render(TRUE);
+ ?>
+ <?php endif ?>
+ <?php endforeach ?>
+ </ul>
+ </li>
<?php endforeach ?>
<?php if ($none): ?>
<li class="empty"><?=_('None.')?></li>
@@ -65,12 +82,14 @@
<li class="section collections">
<h3><?=_('Collections')?> <a target="_top" href="<?=$edit_base?>collections"><?=_('edit')?></a></h3>
- <p<?=_('Collection URL:')?>>
+ <p><?=_('Collection URL:')?>
<?php if (empty($repack->addons_collection_url)): ?>
<?=_('None.')?>
<?php else: ?>
- <a href="<?=html::specialchars($repack->addons_collection_url)?>" target="_new"><?=html::specialchars($repack->addons_collection_url)?></a></p>
+ <a href="<?=html::specialchars($repack->addons_collection_url)?>"
+ target="_new"><?=html::specialchars($repack->addons_collection_url)?></a>
<?php endif ?>
+ </p>
</li>
<ul>
@@ -1,25 +1,56 @@
<?php if ($bookmark['type'] != 'folder'): ?>
<li class="bookmark <?=$bookmark['type']?>">
- <span class="title"><?=html::specialchars($bookmark['title'])?></span>
- <?php if ('livemark' == $bookmark['type']): ?>
- <a target="_new" class="feed" href="<?=html::specialchars($bookmark['feedLink'])?>"><?=html::specialchars($bookmark['feedLink'])?></a>
- <a target="_new" class="location" href="<?=html::specialchars($bookmark['siteLink'])?>"><?=html::specialchars($bookmark['siteLink'])?></a>
- <?php else: ?>
- <a target="_new" class="location" href="<?=html::specialchars($bookmark['link'])?>"><?=html::specialchars($bookmark['link'])?></a>
- <span class="description"><?=html::specialchars($bookmark['description'])?></span>
- <?php endif ?>
+ <?php
+ $fields = ('livemark' == $bookmark['type']) ?
+ array(
+ 'title' => array(_('Title'), 'title', False),
+ 'feedLink' => array(_('Feed'), 'feed', True),
+ 'siteLink' => array(_('Site'), 'location', True),
+ )
+ :
+ array(
+ 'title' => array(_('Title'), 'title', False),
+ 'link' => array(_('Link'), 'location', True),
+ 'description' => array(_('Description'), 'description', False),
+ );
+ ?>
+ <table>
+ <?php foreach ($fields as $name => $spec): ?>
+ <?php list($label, $cls, $is_link) = $spec; ?>
+ <?php foreach ($repack->locales as $locale): ?>
+ <?php
+ $is_default = ($repack->default_locale == $locale);
+ $l_name = $is_default ? $name : "{$name}.{$locale}";
+ $locale_label = $is_default ? '' :
+ ' <span class="locale">(' . html::specialchars($locale) . ')</span> ';
+ if (empty($bookmark[$l_name])) continue;
+ $h_val = html::specialchars($bookmark[$l_name]);
+ ?>
+ <tr class="field"><th class="label"><?=$label.$locale_label?></th><td>
+ <?php if (!$is_link): ?>
+ <span class="<?=$cls?>"><?=$h_val?></span>
+ <?php else: ?>
+ <a target="_new" class="<?=$cls?>" href="<?=$h_val?>"><?=$h_val?></a>
+ <?php endif ?></td></tr>
+ <?php endforeach ?>
+ <?php endforeach ?>
+ </table>
</li>
<?php else: ?>
+ <?php
+ $items_name = (empty($locale) || $repack->default_locale == $locale) ?
+ 'items' : "items.{$locale}";
+ ?>
<li class="folder">
<h4><?=html::specialchars($bookmark['title'])?></h4>
<ul>
- <?php if (empty($bookmark['items'])): ?>
+ <?php if (empty($bookmark[$items_name])): ?>
<li class="empty"><?=_('None')?></li>
<?php else: ?>
- <?php foreach ($bookmark['items'] as $idx=>$bookmark): ?>
+ <?php foreach ($bookmark[$items_name] as $idx=>$bookmark): ?>
<?php
View::factory('repacks/edit/review_bookmarks', array(
- 'bookmark' => $bookmark
+ 'bookmark' => $bookmark, 'repack' => $repack
))->render(TRUE);
?>
<?php endforeach ?>
@@ -1,13 +1,16 @@
+<?php
+ $locale_suff = ($repack->default_locale == $locale) ? '' : $locale.'.';
+?>
<?php foreach (array('type', 'title', 'link', 'description', 'siteLink', 'feedLink') as $field_name): ?>
<?php if (!empty($bookmark[$field_name])):?>
-item.<?=$idx?>.<?=$field_name?>=<?=$bookmark[$field_name]."\n"?>
+item.<?=$locale_suff.$idx?>.<?=$field_name?>=<?=$bookmark[$field_name]."\n"?>
<?php endif ?>
<?php foreach ($repack->locales as $locale): ?>
<?php if (!empty($bookmark[$field_name.'.'.$locale])):?>
-item.<?=$idx?>.<?=$field_name?>.<?=$locale?>=<?=$bookmark[$field_name.'.'.$locale]."\n"?>
+item.<?=$locale_suff.$idx?>.<?=$field_name?>.<?=$locale?>=<?=$bookmark[$field_name.'.'.$locale]."\n"?>
<?php endif ?>
<?php endforeach ?>
<?php endforeach ?>
<?php if ('folder' == $bookmark['type'] && !empty($bookmark['items'])): ?>
-item.<?=$idx?>.folderId=<?=$bookmark['id']."\n"?>
+item.<?=$locale_suff.$idx?>.folderId=<?=$bookmark['id']."\n"?>
<?php endif ?>
@@ -8,13 +8,15 @@
'idx' => $idx+1,
'bookmark' => $bookmark,
'repack' => $repack,
+ 'locale' => $locale,
))->render(TRUE); ?>
<?php
if ('folder' == $bookmark['type'] && !empty($bookmark['items'])) {
$sub_folders[] = View::factory('repacks/ini/bookmarks', array(
'set_id' => "Folder-{$bookmark['id']}",
'bookmarks' => $bookmark['items'],
'repack' => $repack,
+ 'locale' => $locale,
))->render(FALSE);
}
?>
@@ -33,11 +33,16 @@
<?php foreach (array('menu', 'toolbar') as $kind): ?>
<?php if (!empty($bookmarks[$kind]) && !empty($bookmarks[$kind]['items'])): ?>
<?php
- View::factory('repacks/ini/bookmarks', array(
- 'set_id' => ucfirst($kind),
- 'bookmarks' => $bookmarks[$kind]['items'],
- 'repack' => $repack,
- ))->render(TRUE);
+ foreach ($r->locales as $locale) {
+ $locale_suff = ($locale == $r->default_locale) ? '' : '.'.$locale;
+ if (empty($bookmarks[$kind]['items'.$locale_suff])) { continue; }
+ View::factory('repacks/ini/bookmarks', array(
+ 'set_id' => ucfirst($kind),
+ 'bookmarks' => $bookmarks[$kind]['items'.$locale_suff],
+ 'repack' => $repack,
+ 'locale' => $locale,
+ ))->render(TRUE);
+ }
?>
<?php endif ?>
<?php endforeach ?>
Oops, something went wrong.

0 comments on commit b29db8d

Please sign in to comment.