- moved check upgrade feed code to admin/include/functions_upgrade.php

- refactored some code (shorter and somehow faster - but nothing revolutionary)
- decrease lost space in permalinks.tpl and hard coded column width (was illisible)

git-svn-id: http://piwigo.org/svn/trunk@3136 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
rvelices
2009-02-13 13:01:03 +00:00
parent d4914a3447
commit 601134c57e
9 changed files with 151 additions and 201 deletions
+49 -1
View File
@@ -185,4 +185,52 @@ WHERE '.$conf['user_fields']['username'].'="'.$username.'"
define('PHPWG_IN_UPGRADE', true);
}
}
?>
/**
* which upgrades are available ?
*
* @return array
*/
function get_available_upgrade_ids()
{
$upgrades_path = PHPWG_ROOT_PATH.'install/db';
$available_upgrade_ids = array();
if ($contents = opendir($upgrades_path))
{
while (($node = readdir($contents)) !== false)
{
if (is_file($upgrades_path.'/'.$node)
and preg_match('/^(.*?)-database\.php$/', $node, $match))
{
array_push($available_upgrade_ids, $match[1]);
}
}
}
natcasesort($available_upgrade_ids);
return $available_upgrade_ids;
}
/**
* returns true if there are available upgrade files
*/
function check_upgrade_feed()
{
// retrieve already applied upgrades
$query = '
SELECT id
FROM '.UPGRADE_TABLE.'
;';
$applied = array_from_query($query, 'id');
// retrieve existing upgrades
$existing = get_available_upgrade_ids();
// which upgrades need to be applied?
return (count(array_diff($existing, $applied)) > 0);
}
?>
+28 -28
View File
@@ -28,40 +28,40 @@
<h3>{'Permalinks'|@translate}</h3>
<table class="table2">
<tr class="throw">
<td style="width:20%;">Id {$SORT_ID}</td>
<td style="width:20%;">{'Category'|@translate} {$SORT_NAME}</td>
<td style="width:20%;">{'Permalink'|@translate} {$SORT_PERMALINK}</td>
</tr>
<tr class="throw">
<td>Id {$SORT_ID}</td>
<td>{'Category'|@translate} {$SORT_NAME}</td>
<td>{'Permalink'|@translate} {$SORT_PERMALINK}</td>
</tr>
{foreach from=$permalinks item=permalink name="permalink_loop"}
<tr class="{if $smarty.foreach.permalink_loop.index is odd}row1{else}row2{/if}" style="line-height: 2.2em;">
<td style="text-align:center;">{$permalink.id}</td>
<td>{$permalink.name}</td>
<td>{$permalink.permalink}</td>
</tr>
<tr class="{if $smarty.foreach.permalink_loop.index is odd}row1{else}row2{/if}" style="line-height:1.5em;">
<td style="text-align:center;">{$permalink.id}</td>
<td>{$permalink.name}</td>
<td>{$permalink.permalink}</td>
</tr>
{/foreach}
</table>
<h3>{'Permalink history'|@translate} <a name="old_permalinks"></a></h3>
<table class="table2">
<tr class="throw">
<td style="width:40px;">Id {$SORT_OLD_CAT_ID}</td>
<td style="width:25%;">{'Category'|@translate}</td>
<td style="width:25%;">{'Permalink'|@translate} {$SORT_OLD_PERMALINK}</td>
<td style="width:15%;">Deleted on {$SORT_OLD_DATE_DELETED}</td>
<td style="width:15%;">Last hit {$SORT_OLD_LAST_HIT}</td>
<td style="width:20px;">Hit {$SORT_OLD_HIT}</td>
<td style="width:5px;"></td>
</tr>
<tr class="throw">
<td>Id {$SORT_OLD_CAT_ID}</td>
<td>{'Category'|@translate}</td>
<td>{'Permalink'|@translate} {$SORT_OLD_PERMALINK}</td>
<td>Deleted on {$SORT_OLD_DATE_DELETED}</td>
<td>Last hit {$SORT_OLD_LAST_HIT}</td>
<td style="width:20px;">Hit {$SORT_OLD_HIT}</td>
<td style="width:5px;"></td>
</tr>
{foreach from=$deleted_permalinks item=permalink}
<tr style="line-height: 2.2em;">
<td style="text-align:center;">{$permalink.cat_id}</td>
<td>{$permalink.name}</td>
<td>{$permalink.permalink}</td>
<td>{$permalink.date_deleted}</td>
<td>{$permalink.last_hit}</td>
<td>{$permalink.hit}</td>
<td><a href="{$permalink.U_DELETE}" {$TAG_INPUT_ENABLED}><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" alt="[{'delete'|@translate}]" class="button"></a></td>
</tr>
<tr style="line-height:1.5em;">
<td style="text-align:center;">{$permalink.cat_id}</td>
<td>{$permalink.name}</td>
<td>{$permalink.permalink}</td>
<td>{$permalink.date_deleted}</td>
<td>{$permalink.last_hit}</td>
<td>{$permalink.hit}</td>
<td><a href="{$permalink.U_DELETE}" {$TAG_INPUT_ENABLED}><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/delete.png" alt="[{'delete'|@translate}]" class="button"></a></td>
</tr>
{/foreach}
</table>
+2 -5
View File
@@ -134,8 +134,7 @@ foreach ($pictures as $row)
}
if ($conf['show_thumbnail_caption'])
{
// name of the picture
{// name of the picture
if (isset($row['name']) and $row['name'] != '')
{
$name = $row['name'];
@@ -166,9 +165,7 @@ foreach ($pictures as $row)
if ( isset($nb_comments_of) )
{
$row['nb_comments'] = isset($nb_comments_of[$row['id']])
? (int)$nb_comments_of[$row['id']] : 0;
$tpl_var['NB_COMMENTS'] = $row['nb_comments'];
$tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
}
$tpl_thumbnails_var[] = $tpl_var;
+5 -23
View File
@@ -115,18 +115,11 @@ if ( version_compare(mysql_get_server_info(), '4.1.0', '>=') )
pwg_query('SET NAMES "'.DB_CHARSET.'"');
}
}
else
elseif ( strtolower(PWG_CHARSET)!='iso-8859-1' )
{
if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
{
fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
}
fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
}
//
// Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
// since basic gallery information is not available
//
load_conf_from_db();
load_plugins();
@@ -187,19 +180,8 @@ if ($conf['gallery_locked'])
if ($conf['check_upgrade_feed'])
{
// retrieve already applied upgrades
$query = '
SELECT id
FROM '.UPGRADE_TABLE.'
;';
$applied = array_from_query($query, 'id');
// retrieve existing upgrades
$existing = get_available_upgrade_ids();
// which upgrades need to be applied?
if (count(array_diff($existing, $applied)) > 0)
include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
if (check_upgrade_feed())
{
$header_msgs[] = 'Some database upgrades are missing, '
.'<a href="'.get_absolute_root_url(false).'upgrade_feed.php">upgrade now</a>';
@@ -242,4 +224,4 @@ add_event_handler('render_comment_content', 'parse_comment_content');
add_event_handler('render_comment_author', 'strip_tags');
add_event_handler('blockmanager_register_blocks', 'register_default_menubar_blocks', EVENT_HANDLER_PRIORITY_NEUTRAL-1);
trigger_action('init');
?>
?>
-1
View File
@@ -688,7 +688,6 @@ $conf['filter_pages'] = array
'install' => array('cancel' => true),
'password' => array('cancel' => true),
'register' => array('cancel' => true),
'upgrade_feed' => array('cancel' => true),
);
// +-----------------------------------------------------------------------+
+14 -64
View File
@@ -133,12 +133,11 @@ function replace_space( $string )
$remaining = $string;
// $start represents the position of the next '<' character
// $end represents the position of the next '>' character
$start = 0;
$end = 0;
$start = strpos ( $remaining, '<' ); // -> 0
; // -> 0
$end = strpos ( $remaining, '>' ); // -> 16
// as long as a '<' and his friend '>' are found, we loop
while ( is_numeric( $start ) and is_numeric( $end ) )
while ( ($start=strpos( $remaining, '<' )) !==false
and ($end=strpos( $remaining, '>' )) !== false )
{
// $treatment is the part of the string to treat
// In the first loop of our example, this variable is empty, but in the
@@ -153,8 +152,6 @@ function replace_space( $string )
// the remaining string is deplaced to the part after the '>' of this
// loop
$remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
$start = strpos ( $remaining, '<' );
$end = strpos ( $remaining, '>' );
}
$treatment = str_replace( ' ', '&nbsp;', $remaining );
$treatment = str_replace( '-', '&minus;', $treatment );
@@ -242,11 +239,8 @@ function mkgetdir($dir, $flags=MKGETDIR_DEFAULT)
}
if ( !is_writable($dir) )
{
if ( !is_writable($dir) )
{
!($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
!($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
return false;
}
return true;
}
@@ -464,7 +458,7 @@ function get_languages($target_charset = null)
while ($file = readdir($dir))
{
$path = PHPWG_ROOT_PATH.'language/'.$file;
if (is_dir($path) and !is_link($path) and file_exists($path.'/iso.txt'))
if (!is_link($path) and file_exists($path.'/iso.txt'))
{
list($language_name) = @file($path.'/iso.txt');
@@ -526,15 +520,9 @@ function pwg_log($image_id = null, $image_type = null)
}
$tags_string = null;
if (isset($page['section']) and $page['section'] == 'tags')
if ('tags'==@$page['section'])
{
$tag_ids = array();
foreach ($page['tags'] as $tag)
{
array_push($tag_ids, $tag['id']);
}
$tags_string = implode(',', $tag_ids);
$tags_string = implode(',', $page['tag_ids']);
}
$query = '
@@ -911,7 +899,7 @@ function get_thumbnail_title($element_info)
if (!empty($element_info['filesize']))
{
$thumbnail_title .= ' : '.l10n_dec('%d Kb', '%d Kb', $element_info['filesize']);
$thumbnail_title .= ' : '.sprintf(l10n('%d Kb'), $element_info['filesize']);
}
return $thumbnail_title;
@@ -1138,33 +1126,6 @@ SELECT '.$conf['user_fields']['email'].'
return $email;
}
/**
* which upgrades are available ?
*
* @return array
*/
function get_available_upgrade_ids()
{
$upgrades_path = PHPWG_ROOT_PATH.'install/db';
$available_upgrade_ids = array();
if ($contents = opendir($upgrades_path))
{
while (($node = readdir($contents)) !== false)
{
if (is_file($upgrades_path.'/'.$node)
and preg_match('/^(.*?)-database\.php$/', $node, $match))
{
array_push($available_upgrade_ids, $match[1]);
}
}
}
natcasesort($available_upgrade_ids);
return $available_upgrade_ids;
}
/**
* Add configuration parameters from database to global $conf array
*
@@ -1274,29 +1235,18 @@ function script_basename()
foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value)
{
$continue = !empty($_SERVER[$value]);
if ($continue)
if (!empty($_SERVER[$value]))
{
$filename = strtolower($_SERVER[$value]);
if ($conf['php_extension_in_urls'])
{
$continue = get_extension($filename) === 'php';
}
if ($continue)
{
$basename = basename($filename, '.php');
$continue = !empty($basename);
}
if ($continue)
if ($conf['php_extension_in_urls'] and get_extension($filename)!=='php')
continue;
$basename = basename($filename, '.php');
if (!empty($basename))
{
return $basename;
}
}
}
return '';
}
+47 -56
View File
@@ -109,55 +109,50 @@ function trigger_event($event, $data=null)
{
global $pwg_event_handlers;
// just for debugging
trigger_action('pre_trigger_event',
array('event'=>$event, 'data'=>$data) );
if ( isset($pwg_event_handlers['trigger']) )
{// just for debugging
trigger_action('trigger',
array('type'=>'event', 'event'=>$event, 'data'=>$data) );
}
if ( !isset($pwg_event_handlers[$event]) )
{
trigger_action('post_trigger_event',
array('event'=>$event, 'data'=>$data) );
return $data;
}
$args = array_slice(func_get_args(), 2);
foreach ($pwg_event_handlers[$event] as $priority => $handlers)
{
if ( !is_null($handlers) )
foreach($handlers as $handler)
{
foreach($handlers as $handler)
{
$all_args = array_merge( array($data), $args);
$function_name = $handler['function'];
$accepted_args = $handler['accepted_args'];
$all_args = array_merge( array($data), $args);
$function_name = $handler['function'];
$accepted_args = $handler['accepted_args'];
if ( $accepted_args == 1 )
$the_args = array($data);
elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args);
elseif ( $accepted_args == 0 )
$the_args = NULL;
else
$the_args = $all_args;
if ( $accepted_args == 1 )
$the_args = array($data);
elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args);
elseif ( $accepted_args == 0 )
$the_args = NULL;
else
$the_args = $all_args;
$data = call_user_func_array($function_name, $the_args);
}
$data = call_user_func_array($function_name, $the_args);
}
}
trigger_action('post_trigger_event',
array('event'=>$event, 'data'=>$data) );
trigger_action('trigger',
array('type'=>'post_event', 'event'=>$event, 'data'=>$data) );
return $data;
}
function trigger_action($event, $data=null)
{
global $pwg_event_handlers;
if ($event!='pre_trigger_event'
and $event!='post_trigger_event'
and $event!='trigger_action')
if ( isset($pwg_event_handlers['trigger']) and $event!='trigger' )
{// special case for debugging - avoid recursive calls
trigger_action('trigger_action',
array('event'=>$event, 'data'=>$data) );
trigger_action('trigger',
array('type'=>'action', 'event'=>$event, 'data'=>$data) );
}
if ( !isset($pwg_event_handlers[$event]) )
@@ -168,25 +163,22 @@ function trigger_action($event, $data=null)
foreach ($pwg_event_handlers[$event] as $priority => $handlers)
{
if ( !is_null($handlers) )
foreach($handlers as $handler)
{
foreach($handlers as $handler)
{
$all_args = array_merge( array($data), $args);
$function_name = $handler['function'];
$accepted_args = $handler['accepted_args'];
$all_args = array_merge( array($data), $args);
$function_name = $handler['function'];
$accepted_args = $handler['accepted_args'];
if ( $accepted_args == 1 )
$the_args = array($data);
elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args);
elseif ( $accepted_args == 0 )
$the_args = NULL;
else
$the_args = $all_args;
if ( $accepted_args == 1 )
$the_args = array($data);
elseif ( $accepted_args > 1 )
$the_args = array_slice($all_args, 0, $accepted_args);
elseif ( $accepted_args == 0 )
$the_args = NULL;
else
$the_args = $all_args;
call_user_func_array($function_name, $the_args);
}
call_user_func_array($function_name, $the_args);
}
}
}
@@ -229,20 +221,19 @@ function get_db_plugins($state='', $id='')
{
$query = '
SELECT * FROM '.PLUGINS_TABLE;
if (!empty($state) or !empty($id) )
$clauses = array();
if (!empty($state))
{
$clauses[] = 'state="'.$state.'"';
}
if (!empty($id))
{
$clauses[] = 'id="'.$id.'"';
}
if (count($clauses))
{
$query .= '
WHERE 1=1';
if (!empty($state))
{
$query .= '
AND state="'.$state.'"';
}
if (!empty($id))
{
$query .= '
AND id="'.$id.'"';
}
WHERE '. implode(' AND ', $clauses);
}
$result = pwg_query($query);
+6 -21
View File
@@ -80,22 +80,6 @@ class EventTracer
fclose( $file );
}
function on_pre_trigger_event($event_info)
{
@$this->trigger_counts[$event_info['event']]++;
$this->dump('pre_trigger_event', $event_info);
}
function on_post_trigger_event($event_info)
{
$this->dump('post_trigger_event', $event_info);
}
function on_trigger_action($event_info)
{
@$this->trigger_counts[$event_info['event']]++;
$this->dump('trigger_action', $event_info);
}
function on_page_tail()
{
if (1 || @$this->my_config['show_registered'])
@@ -129,8 +113,11 @@ class EventTracer
}
}
function dump($event, $event_info)
function on_trigger($event_info)
{
if ($event_info['type']!='post_event')
@$this->trigger_counts[$event_info['event']]++;
foreach( $this->my_config['filters'] as $filter)
{
if ( preg_match( '/'.$filter.'/', $event_info['event'] ) )
@@ -143,7 +130,7 @@ class EventTracer
}
else
$s = '';
pwg_debug($event.' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) );
pwg_debug($event_info['type'].' "'.$event_info['event'].'" '.($this->trigger_counts[$event_info['event']]).' calls '.($s) );
break;
}
}
@@ -165,9 +152,7 @@ $obj = new EventTracer();
$obj->load_config();
add_event_handler('get_admin_plugin_menu_links', array(&$obj, 'plugin_admin_menu') );
add_event_handler('pre_trigger_event', array(&$obj, 'on_pre_trigger_event') );
add_event_handler('post_trigger_event', array(&$obj, 'on_post_trigger_event') );
add_event_handler('loc_begin_page_tail', array(&$obj, 'on_page_tail') );
add_event_handler('trigger_action', array(&$obj, 'on_trigger_action') );
add_event_handler('trigger', array(&$obj, 'on_trigger') );
set_plugin_data($plugin['id'], $obj);
?>
-2
View File
@@ -1,7 +1,6 @@
{if !empty($blocks) }
<div id="menubar">
{foreach from=$blocks key=id item=block}
{if ( not empty($block->template) or not empty($block->raw_content) )}
<dl id="{$id}">
{if not empty($block->template)}
{include file=$block->template|@get_extent:$id }
@@ -9,7 +8,6 @@
{$block->raw_content}
{/if}
</dl>
{/if}
{/foreach}
</div>
{/if}