aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorrvelices <rv-github@modusoptimus.com>2009-02-13 13:02:20 +0000
committerrvelices <rv-github@modusoptimus.com>2009-02-13 13:02:20 +0000
commitb77b4f0aba107444ad5003d4c6e9b72cb348a6ca (patch)
tree02ffed73dbc2c052da0df1e8f9f69efa119a7f44 /include
parentbd8b4f51bb68178ea48db2cd55b1ea3a15c63c45 (diff)
merge r3136 from trunk
- 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/branches/2.0@3137 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'include')
-rw-r--r--include/category_default.inc.php7
-rw-r--r--include/common.inc.php28
-rw-r--r--include/config_default.inc.php1
-rw-r--r--include/functions.inc.php78
-rw-r--r--include/functions_plugins.inc.php103
5 files changed, 68 insertions, 149 deletions
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, '
.'<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');
-?>
+?> \ 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( ' ', '&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;
@@ -1139,33 +1127,6 @@ SELECT '.$conf['user_fields']['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
*
* @return void
@@ -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);