From 601134c57e736e4639d0c105c7948279d9563813 Mon Sep 17 00:00:00 2001 From: rvelices Date: Fri, 13 Feb 2009 13:01:03 +0000 Subject: - 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 --- admin/include/functions_upgrade.php | 50 ++++++++++++++++- admin/template/goto/permalinks.tpl | 56 ++++++++++---------- include/category_default.inc.php | 7 +-- include/common.inc.php | 28 ++-------- include/config_default.inc.php | 1 - include/functions.inc.php | 78 +++++---------------------- include/functions_plugins.inc.php | 103 ++++++++++++++++-------------------- plugins/event_tracer/main.inc.php | 27 +++------- template/yoga/menubar.tpl | 2 - 9 files changed, 151 insertions(+), 201 deletions(-) diff --git a/admin/include/functions_upgrade.php b/admin/include/functions_upgrade.php index d7c1a4e96..3181946eb 100644 --- a/admin/include/functions_upgrade.php +++ b/admin/include/functions_upgrade.php @@ -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); +} + +?> \ No newline at end of file diff --git a/admin/template/goto/permalinks.tpl b/admin/template/goto/permalinks.tpl index 375853a40..3e04cc3d0 100644 --- a/admin/template/goto/permalinks.tpl +++ b/admin/template/goto/permalinks.tpl @@ -28,40 +28,40 @@

{'Permalinks'|@translate}

- - - - - + + + + + {foreach from=$permalinks item=permalink name="permalink_loop"} - - - - - + + + + + {/foreach}
Id {$SORT_ID}{'Category'|@translate} {$SORT_NAME}{'Permalink'|@translate} {$SORT_PERMALINK}
Id {$SORT_ID}{'Category'|@translate} {$SORT_NAME}{'Permalink'|@translate} {$SORT_PERMALINK}

{'Permalink history'|@translate}

- - - - - - - - - + + + + + + + + + {foreach from=$deleted_permalinks item=permalink} - - - - - - - - - + + + + + + + + + {/foreach}
Id {$SORT_OLD_CAT_ID}{'Category'|@translate}{'Permalink'|@translate} {$SORT_OLD_PERMALINK}Deleted on {$SORT_OLD_DATE_DELETED}Last hit {$SORT_OLD_LAST_HIT}Hit {$SORT_OLD_HIT}
Id {$SORT_OLD_CAT_ID}{'Category'|@translate}{'Permalink'|@translate} {$SORT_OLD_PERMALINK}Deleted on {$SORT_OLD_DATE_DELETED}Last hit {$SORT_OLD_LAST_HIT}Hit {$SORT_OLD_HIT}
{$permalink.cat_id}{$permalink.name}{$permalink.permalink}{$permalink.date_deleted}{$permalink.last_hit}{$permalink.hit}[{'delete'|@translate}]
{$permalink.cat_id}{$permalink.name}{$permalink.permalink}{$permalink.date_deleted}{$permalink.last_hit}{$permalink.hit}[{'delete'|@translate}]
diff --git a/include/category_default.inc.php b/include/category_default.inc.php index 025adcc40..98e6250f1 100644 --- a/include/category_default.inc.php +++ b/include/category_default.inc.php @@ -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; diff --git a/include/common.inc.php b/include/common.inc.php index db50f31f2..76054153a 100644 --- a/include/common.inc.php +++ b/include/common.inc.php @@ -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, ' .'upgrade now'; @@ -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'); -?> +?> \ No newline at end of file diff --git a/include/config_default.inc.php b/include/config_default.inc.php index c0f889808..81fe7ef0f 100644 --- a/include/config_default.inc.php +++ b/include/config_default.inc.php @@ -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), ); // +-----------------------------------------------------------------------+ diff --git a/include/functions.inc.php b/include/functions.inc.php index 1902acdac..1675dbce8 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -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( ' ', ' ', $remaining ); $treatment = str_replace( '-', '−', $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 ''; } diff --git a/include/functions_plugins.inc.php b/include/functions_plugins.inc.php index 14bb66271..5a5ea79e3 100644 --- a/include/functions_plugins.inc.php +++ b/include/functions_plugins.inc.php @@ -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); diff --git a/plugins/event_tracer/main.inc.php b/plugins/event_tracer/main.inc.php index 05058ac07..af45bfd6c 100644 --- a/plugins/event_tracer/main.inc.php +++ b/plugins/event_tracer/main.inc.php @@ -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); ?> diff --git a/template/yoga/menubar.tpl b/template/yoga/menubar.tpl index 99cac9b6d..8b1e8f4b6 100644 --- a/template/yoga/menubar.tpl +++ b/template/yoga/menubar.tpl @@ -1,7 +1,6 @@ {if !empty($blocks) } {/if} \ No newline at end of file -- cgit v1.2.3