Changeset 3136 for trunk/include


Ignore:
Timestamp:
Feb 13, 2009, 2:01:03 PM (15 years ago)
Author:
rvelices
Message:
  • 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)
Location:
trunk/include
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/category_default.inc.php

    r3128 r3136  
    135135
    136136  if ($conf['show_thumbnail_caption'])
    137   {
    138     // name of the picture
     137  {// name of the picture
    139138    if (isset($row['name']) and $row['name'] != '')
    140139    {
     
    167166  if ( isset($nb_comments_of) )
    168167  {
    169     $row['nb_comments'] = isset($nb_comments_of[$row['id']])
    170         ? (int)$nb_comments_of[$row['id']] : 0;
    171     $tpl_var['NB_COMMENTS'] = $row['nb_comments'];
     168    $tpl_var['NB_COMMENTS'] = (int)@$nb_comments_of[$row['id']];
    172169  }
    173170
  • trunk/include/common.inc.php

    r3126 r3136  
    116116  }
    117117}
    118 else
    119 {
    120   if ( strtolower(PWG_CHARSET)!='iso-8859-1' )
    121   {
    122     fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
    123   }
    124 }
    125 
    126 //
    127 // Setup gallery wide options, if this fails then we output a CRITICAL_ERROR
    128 // since basic gallery information is not available
    129 //
     118elseif ( strtolower(PWG_CHARSET)!='iso-8859-1' )
     119{
     120  fatal_error('PWG supports only iso-8859-1 charset on MySql version '.mysql_get_server_info());
     121}
     122
    130123load_conf_from_db();
    131124load_plugins();
     
    188181if ($conf['check_upgrade_feed'])
    189182{
    190 
    191   // retrieve already applied upgrades
    192   $query = '
    193 SELECT id
    194   FROM '.UPGRADE_TABLE.'
    195 ;';
    196   $applied = array_from_query($query, 'id');
    197 
    198   // retrieve existing upgrades
    199   $existing = get_available_upgrade_ids();
    200 
    201   // which upgrades need to be applied?
    202   if (count(array_diff($existing, $applied)) > 0)
     183  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upgrade.php');
     184  if (check_upgrade_feed())
    203185  {
    204186    $header_msgs[] = 'Some database upgrades are missing, '
  • trunk/include/config_default.inc.php

    r3133 r3136  
    689689    'password' => array('cancel' => true),
    690690    'register' => array('cancel' => true),
    691     'upgrade_feed' => array('cancel' => true),
    692691  );
    693692
  • trunk/include/functions.inc.php

    r3122 r3136  
    134134  // $start represents the position of the next '<' character
    135135  // $end   represents the position of the next '>' character
    136   $start = 0;
    137   $end = 0;
    138   $start = strpos ( $remaining, '<' ); // -> 0
     136  ; // -> 0
    139137  $end   = strpos ( $remaining, '>' ); // -> 16
    140138  // as long as a '<' and his friend '>' are found, we loop
    141   while ( is_numeric( $start ) and is_numeric( $end ) )
     139  while ( ($start=strpos( $remaining, '<' )) !==false
     140        and ($end=strpos( $remaining, '>' )) !== false )
    142141  {
    143142    // $treatment is the part of the string to treat
     
    154153    // loop
    155154    $remaining = substr ( $remaining, $end + 1, strlen( $remaining ) );
    156     $start = strpos ( $remaining, '<' );
    157     $end   = strpos ( $remaining, '>' );
    158155  }
    159156  $treatment = str_replace( ' ', '&nbsp;', $remaining );
     
    243240  if ( !is_writable($dir) )
    244241  {
    245     if ( !is_writable($dir) )
    246     {
    247       !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
    248       return false;
    249     }
     242    !($flags&MKGETDIR_DIE_ON_ERROR) or fatal_error( "$dir ".l10n('no_write_access'));
     243    return false;
    250244  }
    251245  return true;
     
    465459  {
    466460    $path = PHPWG_ROOT_PATH.'language/'.$file;
    467     if (is_dir($path) and !is_link($path) and file_exists($path.'/iso.txt'))
     461    if (!is_link($path) and file_exists($path.'/iso.txt'))
    468462    {
    469463      list($language_name) = @file($path.'/iso.txt');
     
    527521
    528522  $tags_string = null;
    529   if (isset($page['section']) and $page['section'] == 'tags')
    530   {
    531     $tag_ids = array();
    532     foreach ($page['tags'] as $tag)
    533     {
    534       array_push($tag_ids, $tag['id']);
    535     }
    536 
    537     $tags_string = implode(',', $tag_ids);
     523  if ('tags'==@$page['section'])
     524  {
     525    $tags_string = implode(',', $page['tag_ids']);
    538526  }
    539527
     
    912900  if (!empty($element_info['filesize']))
    913901  {
    914     $thumbnail_title .= ' : '.l10n_dec('%d Kb', '%d Kb', $element_info['filesize']);
     902    $thumbnail_title .= ' : '.sprintf(l10n('%d Kb'), $element_info['filesize']);
    915903  }
    916904
     
    11401128
    11411129/**
    1142  * which upgrades are available ?
    1143  *
    1144  * @return array
    1145  */
    1146 function get_available_upgrade_ids()
    1147 {
    1148   $upgrades_path = PHPWG_ROOT_PATH.'install/db';
    1149 
    1150   $available_upgrade_ids = array();
    1151 
    1152   if ($contents = opendir($upgrades_path))
    1153   {
    1154     while (($node = readdir($contents)) !== false)
    1155     {
    1156       if (is_file($upgrades_path.'/'.$node)
    1157           and preg_match('/^(.*?)-database\.php$/', $node, $match))
    1158       {
    1159         array_push($available_upgrade_ids, $match[1]);
    1160       }
    1161     }
    1162   }
    1163   natcasesort($available_upgrade_ids);
    1164 
    1165   return $available_upgrade_ids;
    1166 }
    1167 
    1168 /**
    11691130 * Add configuration parameters from database to global $conf array
    11701131 *
     
    12751236  foreach (array('SCRIPT_NAME', 'SCRIPT_FILENAME', 'PHP_SELF') as $value)
    12761237  {
    1277     $continue = !empty($_SERVER[$value]);
    1278     if ($continue)
     1238    if (!empty($_SERVER[$value]))
    12791239    {
    12801240      $filename = strtolower($_SERVER[$value]);
    1281 
    1282       if ($conf['php_extension_in_urls'])
    1283       {
    1284         $continue = get_extension($filename) ===  'php';
    1285       }
    1286 
    1287       if ($continue)
    1288       {
    1289         $basename = basename($filename, '.php');
    1290         $continue = !empty($basename);
    1291       }
    1292 
    1293       if ($continue)
     1241      if ($conf['php_extension_in_urls'] and get_extension($filename)!=='php')
     1242        continue;
     1243      $basename = basename($filename, '.php');
     1244      if (!empty($basename))
    12941245      {
    12951246        return $basename;
     
    12971248    }
    12981249  }
    1299 
    13001250  return '';
    13011251}
  • trunk/include/functions_plugins.inc.php

    r3049 r3136  
    110110  global $pwg_event_handlers;
    111111
    112   // just for debugging
    113   trigger_action('pre_trigger_event',
    114         array('event'=>$event, 'data'=>$data) );
     112  if ( isset($pwg_event_handlers['trigger']) )
     113  {// just for debugging
     114    trigger_action('trigger',
     115        array('type'=>'event', 'event'=>$event, 'data'=>$data) );
     116  }
    115117
    116118  if ( !isset($pwg_event_handlers[$event]) )
    117119  {
    118     trigger_action('post_trigger_event',
    119         array('event'=>$event, 'data'=>$data) );
    120120    return $data;
    121121  }
     
    124124  foreach ($pwg_event_handlers[$event] as $priority => $handlers)
    125125  {
    126     if ( !is_null($handlers) )
    127     {
    128       foreach($handlers as $handler)
    129       {
    130         $all_args = array_merge( array($data), $args);
    131         $function_name = $handler['function'];
    132         $accepted_args = $handler['accepted_args'];
    133 
    134         if ( $accepted_args == 1 )
    135           $the_args = array($data);
    136         elseif ( $accepted_args > 1 )
    137           $the_args = array_slice($all_args, 0, $accepted_args);
    138         elseif ( $accepted_args == 0 )
    139           $the_args = NULL;
    140         else
    141           $the_args = $all_args;
    142 
    143         $data = call_user_func_array($function_name, $the_args);
    144       }
    145     }
    146   }
    147   trigger_action('post_trigger_event',
    148         array('event'=>$event, 'data'=>$data) );
     126    foreach($handlers as $handler)
     127    {
     128      $all_args = array_merge( array($data), $args);
     129      $function_name = $handler['function'];
     130      $accepted_args = $handler['accepted_args'];
     131
     132      if ( $accepted_args == 1 )
     133        $the_args = array($data);
     134      elseif ( $accepted_args > 1 )
     135        $the_args = array_slice($all_args, 0, $accepted_args);
     136      elseif ( $accepted_args == 0 )
     137        $the_args = NULL;
     138      else
     139        $the_args = $all_args;
     140
     141      $data = call_user_func_array($function_name, $the_args);
     142    }
     143  }
     144  trigger_action('trigger',
     145       array('type'=>'post_event', 'event'=>$event, 'data'=>$data) );
    149146  return $data;
    150147}
     
    153150{
    154151  global $pwg_event_handlers;
    155   if ($event!='pre_trigger_event'
    156     and $event!='post_trigger_event'
    157     and $event!='trigger_action')
     152  if ( isset($pwg_event_handlers['trigger']) and $event!='trigger' )
    158153  {// special case for debugging - avoid recursive calls
    159     trigger_action('trigger_action',
    160         array('event'=>$event, 'data'=>$data) );
     154    trigger_action('trigger',
     155        array('type'=>'action', 'event'=>$event, 'data'=>$data) );
    161156  }
    162157
     
    169164  foreach ($pwg_event_handlers[$event] as $priority => $handlers)
    170165  {
    171     if ( !is_null($handlers) )
    172     {
    173       foreach($handlers as $handler)
    174       {
    175         $all_args = array_merge( array($data), $args);
    176         $function_name = $handler['function'];
    177         $accepted_args = $handler['accepted_args'];
    178 
    179         if ( $accepted_args == 1 )
    180           $the_args = array($data);
    181         elseif ( $accepted_args > 1 )
    182           $the_args = array_slice($all_args, 0, $accepted_args);
    183         elseif ( $accepted_args == 0 )
    184           $the_args = NULL;
    185         else
    186           $the_args = $all_args;
    187 
    188         call_user_func_array($function_name, $the_args);
    189       }
     166    foreach($handlers as $handler)
     167    {
     168      $all_args = array_merge( array($data), $args);
     169      $function_name = $handler['function'];
     170      $accepted_args = $handler['accepted_args'];
     171
     172      if ( $accepted_args == 1 )
     173        $the_args = array($data);
     174      elseif ( $accepted_args > 1 )
     175        $the_args = array_slice($all_args, 0, $accepted_args);
     176      elseif ( $accepted_args == 0 )
     177        $the_args = NULL;
     178      else
     179        $the_args = $all_args;
     180
     181      call_user_func_array($function_name, $the_args);
    190182    }
    191183  }
     
    230222  $query = '
    231223SELECT * FROM '.PLUGINS_TABLE;
    232   if (!empty($state) or !empty($id) )
    233   {
    234     $query .= '
    235 WHERE 1=1';
    236     if (!empty($state))
    237     {
     224  $clauses = array();
     225  if (!empty($state))
     226  {
     227    $clauses[] = 'state="'.$state.'"';
     228  }
     229  if (!empty($id))
     230  {
     231    $clauses[] = 'id="'.$id.'"';
     232  }
     233  if (count($clauses))
     234  {
    238235      $query .= '
    239   AND state="'.$state.'"';
    240     }
    241     if (!empty($id))
    242     {
    243       $query .= '
    244   AND id="'.$id.'"';
    245     }
     236  WHERE '. implode(' AND ', $clauses);
    246237  }
    247238
Note: See TracChangeset for help on using the changeset viewer.