Permalink
Browse files

Remove get_html_menu_category function and use smarty abilities.

git-svn-id: http://piwigo.org/svn/trunk@3171 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information...
patdenice
patdenice committed Mar 4, 2009
1 parent 9045f11 commit d3e6eabb053f311d5d8fd4ec80cfb0c1b32cf141
@@ -100,8 +100,31 @@ function get_categories_menu()
$result = pwg_query($query);
$cats = array();
+ $selected_category = isset($page['category']) ? $page['category'] : null;
while ($row = mysql_fetch_assoc($result))
{
+ $child_date_last = @$row['max_date_last']> @$row['date_last'];
+ $row = array_merge($row,
+ array(
+ 'NAME' => trigger_event(
+ 'render_category_name',
+ $row['name'],
+ 'get_categories_menu'
+ ),
+ 'TITLE' => get_display_images_count(
+ $row['nb_images'],
+ $row['count_images'],
+ $row['count_categories'],
+ false,
+ ' / '
+ ),
+ 'URL' => make_index_url(array('category' => $row)),
+ 'LEVEL' => substr_count($row['global_rank'], '.') + 1,
+ 'ICON_TS' => get_icon($row['max_date_last'], $child_date_last),
+ 'SELECTED' => $selected_category['id'] == $row['id'] ? true : false,
+ 'IS_UPPERCAT' => $selected_category['id_uppercat'] == $row['id'] ? true : false,
+ )
+ );
array_push($cats, $row);
if ($row['id']==@$page['category']['id']) //save the number of subcats for later optim
$page['category']['count_categories'] = $row['count_categories'];
@@ -114,7 +137,7 @@ function get_categories_menu()
update_cats_with_filtered_data($cats);
}
- return get_html_menu_category($cats, @$page['category'] );
+ return $cats;
}
@@ -373,104 +373,6 @@ function get_cat_display_name_cache($uppercats,
}
}
-/**
- * returns the HTML code for a category item in the menu (for the main page)
- *
- * HTML code generated uses logical list tags ul and each category is an
- * item li. The paramter given is the category informations as an array,
- * used keys are : id, name, nb_images, max_date_last, date_last
- * count_images, count_categories
- *
- * @param array categories
- * @return string
- */
-function get_html_menu_category($categories, $selected_category)
-{
- $ref_level = 0;
- $level = 0;
-
- $menu = trigger_event('get_html_menu_category', '',
- $categories, $selected_category);
- if (strlen($menu))
- {
- return $menu;
- }
-
- foreach ($categories as $category)
- {
- $level = substr_count($category['global_rank'], '.') + 1;
- if ($level > $ref_level)
- {
- $menu.= "\n<ul>";
- }
- else if ($level == $ref_level)
- {
- $menu.= "\n</li>";
- }
- else if ($level < $ref_level)
- {
- // we may have to close more than one level at the same time...
- $menu.= "\n</li>";
- $menu.= str_repeat("\n</ul></li>",($ref_level-$level));
- }
- $ref_level = $level;
-
- $menu.= "\n\n".'<li';
- if ($category['id'] == @$selected_category['id'])
- {
- $menu.= ' class="selected"';
- }
- $menu.= '>';
-
- $url = make_index_url(
- array(
- 'category' => $category
- )
- );
-
- $title = get_display_images_count
- (
- $category['nb_images'],
- $category['count_images'],
- $category['count_categories'],
- false,
- ' / '
- );
-
- $menu.= '<a href="'.$url.'"';
- if ($selected_category!=null
- and $category['id'] == $selected_category['id_uppercat'])
- {
- $menu.= ' rel="up"';
- }
- $menu.= ' title="'.$title.'">';
- $menu.= trigger_event(
- 'render_category_name',
- $category['name'],
- 'get_html_menu_category'
- );
- $menu.= '</a>';
-
- if ( $category['count_images']>0 )
- {// at least one direct or indirect image
- $menu.= "\n".'<span class="';
- // at least one image in this category -> class menuInfoCat
- $menu.= ($category['nb_images'] > 0 ? "menuInfoCat"
- : "menuInfoCatByChild").'"';
- $menu.= ' title=" '.$title.'">';
- // show total number of images
- $menu.= '['.$category['count_images'].']';
- $menu.= '</span>';
- }
- $child_date_last = @$category['max_date_last']> @$category['date_last'];
- $menu.= get_icon($category['max_date_last'], $child_date_last);
- }
-
- $menu.= str_repeat("\n</li></ul>",($level));
-
- return $menu;
-}
-
/**
* returns HTMLized comment contents retrieved from database
*
View
@@ -101,7 +101,7 @@ function initialize_menu()
{
$block->data = array(
'NB_PICTURE' => $user['nb_total_images'],
- 'MENU_CATEGORIES_CONTENT' => get_categories_menu(),
+ 'MENU_CATEGORIES' => get_categories_menu(),
'U_CATEGORIES' => make_index_url(array('section' => 'categories')),
'U_UPLOAD' => get_upload_menu_link()
);
@@ -8,7 +8,24 @@
<a href="{$block->data.U_CATEGORIES}">{'Categories'|@translate}</a>
</dt>
<dd>
- {$block->data.MENU_CATEGORIES_CONTENT}
+{assign var='ref_level' value=0}
+{foreach from=$block->data.MENU_CATEGORIES item=cat}
+ {if $cat.LEVEL > $ref_level}
+ <ul>
+ {else}
+ </li>
+ {'</ul></li>'|@str_repeat:$ref_level-$cat.LEVEL}
+ {/if}
+ <li {if $cat.SELECTED}class="selected"{/if}>
+ <a href="{$cat.URL}" {if $cat.IS_UPPERCAT}rel="up"{/if} title="{$cat.TITLE}">{$cat.NAME}</a>
+ {if $cat.count_images > 0}
+ <span class="{if $cat.nb_images > 0}menuInfoCat{else}menuInfoCatByChild{/if}" title="{$cat.TITLE}">[{$cat.count_images}]</span>
+ {/if}
+ {$cat.ICON_TS}
+ {assign var='ref_level' value=$cat.LEVEL}
+{/foreach}
+{'</li></ul>'|@str_repeat:$ref_level}
+
{if isset($block->data.U_UPLOAD)}
<ul>
<li>

0 comments on commit d3e6eab

Please sign in to comment.