aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2012-10-04 04:15:28 +0000
committerrvelices <rv-github@modusoptimus.com>2012-10-04 04:15:28 +0000
commitcc558d869496f051c1b667d37e4dcfc474c007d1 (patch)
treed6447c2284e229c432139dd23aa46b422fe134f9
parentb90d2721e5f7f81ac821ab5075472fbbb0917c67 (diff)
php optimizations:
- use faster [] operator instead of array_push - if tags are grouped by letter, don't add level to tags, sort etc ... git-svn-id: http://piwigo.org/svn/trunk@18455 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to '')
-rw-r--r--include/functions_tag.inc.php17
-rw-r--r--tags.php58
-rw-r--r--themes/default/template/tags.tpl65
3 files changed, 69 insertions, 71 deletions
diff --git a/include/functions_tag.inc.php b/include/functions_tag.inc.php
index f42fe88f7..74b27f8e2 100644
--- a/include/functions_tag.inc.php
+++ b/include/functions_tag.inc.php
@@ -64,12 +64,12 @@ SELECT *
$tags = array();
while ($row = pwg_db_fetch_assoc($result))
{
- $counter = @$tag_counters[ $row['id'] ];
+ $counter = intval(@$tag_counters[ $row['id'] ]);
if ( $counter )
{
$row['counter'] = $counter;
$row['name'] = trigger_event('render_tag_name', $row['name']);
- array_push($tags, $row);
+ $tags[] = $row;
}
}
return $tags;
@@ -91,7 +91,7 @@ SELECT *
while ($row = pwg_db_fetch_assoc($result))
{
$row['name'] = trigger_event('render_tag_name', $row['name']);
- array_push($tags, $row);
+ $tags[] = $row;
}
usort($tags, 'tag_alpha_compare');
@@ -138,20 +138,21 @@ function add_level_to_tags($tags)
}
// display sorted tags
- foreach (array_keys($tags) as $k)
+ foreach ($tags as &$tag)
{
- $tags[$k]['level'] = 1;
+ $tag['level'] = 1;
// based on threshold, determine current tag level
for ($i = $conf['tags_levels'] - 1; $i >= 1; $i--)
{
- if ($tags[$k]['counter'] > $threshold_of_level[$i])
+ if ($tag['counter'] > $threshold_of_level[$i])
{
- $tags[$k]['level'] = $i + 1;
+ $tag['level'] = $i + 1;
break;
}
}
}
+ unset($tag);
return $tags;
}
@@ -254,7 +255,7 @@ SELECT t.*, count(*) AS counter
while($row = pwg_db_fetch_assoc($result))
{
$row['name'] = trigger_event('render_tag_name', $row['name']);
- array_push($tags, $row);
+ $tags[] = $row;
}
usort($tags, 'tag_alpha_compare');
return $tags;
diff --git a/tags.php b/tags.php
index ab6fa6fd2..518d46e58 100644
--- a/tags.php
+++ b/tags.php
@@ -159,43 +159,41 @@ if ($page['display_mode'] == 'letters') {
);
}
}
+else
+{
+ // +-----------------------------------------------------------------------+
+ // | tag cloud construction |
+ // +-----------------------------------------------------------------------+
-// +-----------------------------------------------------------------------+
-// | tag cloud construction |
-// +-----------------------------------------------------------------------+
-
-// we want only the first most represented tags, so we sort them by counter
-// and take the first tags
-usort($tags, 'counter_compare');
-$tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
+ // we want only the first most represented tags, so we sort them by counter
+ // and take the first tags
+ usort($tags, 'counter_compare');
+ $tags = array_slice($tags, 0, $conf['full_tag_cloud_items_number']);
-// depending on its counter and the other tags counter, each tag has a level
-$tags = add_level_to_tags($tags);
+ // depending on its counter and the other tags counter, each tag has a level
+ $tags = add_level_to_tags($tags);
-// we want tags diplayed in alphabetic order
-if ('letters' != $page['display_mode'])
-{
+ // we want tags diplayed in alphabetic order
usort($tags, 'tag_alpha_compare');
-}
-// display sorted tags
-foreach ($tags as $tag)
-{
- $template->append(
- 'tags',
- array_merge(
- $tag,
- array(
- 'URL' => make_index_url(
- array(
- 'tags' => array($tag),
- )
- ),
+ // display sorted tags
+ foreach ($tags as $tag)
+ {
+ $template->append(
+ 'tags',
+ array_merge(
+ $tag,
+ array(
+ 'URL' => make_index_url(
+ array(
+ 'tags' => array($tag),
+ )
+ ),
+ )
)
- )
- );
+ );
+ }
}
-
// include menubar
$themeconf = $template->get_template_vars('themeconf');
if (!isset($themeconf['hide_menu_on']) OR !in_array('theTagsPage', $themeconf['hide_menu_on']))
diff --git a/themes/default/template/tags.tpl b/themes/default/template/tags.tpl
index 2e47a3f83..c4327289a 100644
--- a/themes/default/template/tags.tpl
+++ b/themes/default/template/tags.tpl
@@ -19,40 +19,39 @@
{include file='infos_errors.tpl'}
-{if isset($tags)}
- {if $display_mode == 'cloud'}
- <div id="fullTagCloud">
- {foreach from=$tags item=tag}
- <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
- {/foreach}
- </div>
- {/if}
- {if $display_mode == 'letters'}
- <table>
- <tr>
- <td valign="top">
- {foreach from=$letters item=letter}
- <fieldset class="tagLetter">
- <legend class="tagLetterLegend">{$letter.TITLE}</legend>
- <table class="tagLetterContent">
- {foreach from=$letter.tags item=tag}
- <tr class="tagLine">
- <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
- <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
- </tr>
- {/foreach}
- </table>
- </fieldset>
- {if isset($letter.CHANGE_COLUMN) }
- </td>
- <td valign="top">
- {/if}
- {/foreach}
- </td>
- </tr>
- </table>
- {/if}
+{if $display_mode == 'cloud' and isset($tags)}
+<div id="fullTagCloud">
+ {foreach from=$tags item=tag}
+ <span><a href="{$tag.URL}" class="tagLevel{$tag.level}" title="{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}">{$tag.name}</a></span>
+ {/foreach}
+</div>
+{/if}
+
+{if $display_mode == 'letters' and isset($letters)}
+<table>
+ <tr>
+ <td valign="top">
+ {foreach from=$letters item=letter}
+<fieldset class="tagLetter">
+ <legend class="tagLetterLegend">{$letter.TITLE}</legend>
+ <table class="tagLetterContent">
+ {foreach from=$letter.tags item=tag}
+ <tr class="tagLine">
+ <td><a href="{$tag.URL}" title="{$tag.name}">{$tag.name}</a></td>
+ <td class="nbEntries">{$pwg->l10n_dec('%d photo', '%d photos', $tag.counter)}</td>
+ </tr>
+ {/foreach}
+ </table>
+</fieldset>
+ {if isset($letter.CHANGE_COLUMN) }
+ </td>
+ <td valign="top">
+ {/if}
+ {/foreach}
+ </td>
+ </tr>
+</table>
{/if}
</div> <!-- content -->