Changeset 3145


Ignore:
Timestamp:
Feb 14, 2009, 3:24:10 AM (15 years ago)
Author:
rvelices
Message:

Last (I hope) paranoic optims ...

  • move get_uysername and get_groupname from public to admin/functions.inc.php
  • optim in index.php
  • tags.tpl does not need smarty modifier included
  • move func get_comment_post_key from functions_comment to functions (avoid extra inclusion every time on picture page)
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/include/functions.php

    r3072 r3145  
    144144  {
    145145    include_once(PHPWG_ROOT_PATH.'include/functions_picture.inc.php');
    146    
     146
    147147    // we can currently delete physically only photo with no
    148148    // storage_category_id (added via pLoader)
     
    18651865      $extents = array_merge($extents, get_extents($path));
    18661866    }
    1867     elseif ( !is_link($path) and file_exists($path) 
     1867    elseif ( !is_link($path) and file_exists($path)
    18681868            and get_extension($path) == 'tpl' )
    18691869    {
     
    20102010  $path = isset($src['path']) ? $src['path'] : '/';
    20112011  $path .= isset($src['query']) ? '?'.$src['query'] : '';
    2012  
     2012
    20132013  if (($s = @fsockopen($host,80,$errno,$errstr,5)) === false)
    20142014  {
     
    20672067}
    20682068
     2069
     2070/**
     2071 * returns the groupname corresponding to the given group identifier if
     2072 * exists
     2073 *
     2074 * @param int group_id
     2075 * @return mixed
     2076 */
     2077function get_groupname($group_id)
     2078{
     2079  $query = '
     2080SELECT name
     2081  FROM '.GROUPS_TABLE.'
     2082  WHERE id = '.intval($group_id).'
     2083;';
     2084  $result = pwg_query($query);
     2085  if (mysql_num_rows($result) > 0)
     2086  {
     2087    list($groupname) = mysql_fetch_row($result);
     2088  }
     2089  else
     2090  {
     2091    return false;
     2092  }
     2093
     2094  return $groupname;
     2095}
     2096
     2097/**
     2098 * returns the username corresponding to the given user identifier if exists
     2099 *
     2100 * @param int user_id
     2101 * @return mixed
     2102 */
     2103function get_username($user_id)
     2104{
     2105  global $conf;
     2106
     2107  $query = '
     2108SELECT '.$conf['user_fields']['username'].'
     2109  FROM '.USERS_TABLE.'
     2110  WHERE '.$conf['user_fields']['id'].' = '.intval($user_id).'
     2111;';
     2112  $result = pwg_query($query);
     2113  if (mysql_num_rows($result) > 0)
     2114  {
     2115    list($username) = mysql_fetch_row($result);
     2116  }
     2117  else
     2118  {
     2119    return false;
     2120  }
     2121
     2122  return $username;
     2123}
    20692124?>
  • trunk/include/functions.inc.php

    r3136 r3145  
    494494  closedir($dir);
    495495  @asort($languages);
    496   @reset($languages);
    497496
    498497  return $languages;
     
    13731372      $source_file = $f;
    13741373      break;
    1375     }
    1376 
    1377     if ($target_charset=='utf-8')
    1378     { // we accept conversion from ISO-8859-1 to UTF-8
    1379       $f = $dir.'.iso-8859-1/'.$filename;
    1380       if (file_exists($f))
    1381       {
    1382         $source_charset = 'iso-8859-1';
    1383         $source_file = $f;
    1384         break;
    1385       }
    13861374    }
    13871375  }
     
    14841472  }
    14851473}
     1474
     1475/**
     1476 * returns a "secret key" that is to be sent back when a user enters a comment
     1477 *
     1478 * @param int image_id
     1479 */
     1480function get_comment_post_key($image_id)
     1481{
     1482  global $conf;
     1483
     1484  $time = time();
     1485
     1486  return sprintf(
     1487    '%s:%s',
     1488    $time,
     1489    hash_hmac(
     1490      'md5',
     1491      $time.':'.$image_id,
     1492      $conf['secret_key']
     1493      )
     1494    );
     1495}
    14861496?>
  • trunk/include/functions_comment.inc.php

    r3049 r3145  
    2222// +-----------------------------------------------------------------------+
    2323
    24 /**
    25  * returns a "secret key" that is to be sent back when a user enters a comment
    26  */
    27 function get_comment_post_key($image_id)
    28 {
    29   global $conf;
    30 
    31   $time = time();
    32 
    33   return sprintf(
    34     '%s:%s',
    35     $time,
    36     hash_hmac(
    37       'md5',
    38       $time.':'.$image_id,
    39       $conf['secret_key']
    40       )
    41     );
    42 }
    43 
    4424//returns string action to perform on a new comment: validate, moderate, reject
    4525function user_comment_check($action, $comment)
     
    190170      (
    191171        ($comment_action=='validate' and $conf['email_admin_on_comment'])
    192         or 
     172        or
    193173        ($comment_action!='validate' and $conf['email_admin_on_comment_validation'])
    194174      )
  • trunk/include/functions_user.inc.php

    r3126 r3145  
    674674
    675675/**
    676  * returns the username corresponding to the given user identifier if exists
    677  *
    678  * @param int user_id
    679  * @return mixed
    680  */
    681 function get_username($user_id)
    682 {
    683   global $conf;
    684 
    685   $query = '
    686 SELECT '.$conf['user_fields']['username'].'
    687   FROM '.USERS_TABLE.'
    688   WHERE '.$conf['user_fields']['id'].' = '.intval($user_id).'
    689 ;';
    690   $result = pwg_query($query);
    691   if (mysql_num_rows($result) > 0)
    692   {
    693     list($username) = mysql_fetch_row($result);
    694   }
    695   else
    696   {
    697     return false;
    698   }
    699 
    700   return $username;
    701 }
    702 
    703 /**
    704676 * returns user identifier thanks to his name, false if not found
    705677 *
     
    933905  }
    934906}
    935 
    936 /**
    937  * returns the groupname corresponding to the given group identifier if
    938  * exists
    939  *
    940  * @param int group_id
    941  * @return mixed
    942  */
    943 function get_groupname($group_id)
    944 {
    945   $query = '
    946 SELECT name
    947   FROM '.GROUPS_TABLE.'
    948   WHERE id = '.intval($group_id).'
    949 ;';
    950   $result = pwg_query($query);
    951   if (mysql_num_rows($result) > 0)
    952   {
    953     list($groupname) = mysql_fetch_row($result);
    954   }
    955   else
    956   {
    957     return false;
    958   }
    959 
    960   return $groupname;
    961 }
    962 
    963907
    964908/**
  • trunk/include/picture_comment.inc.php

    r3122 r3145  
    8989if ($page['show_comments'])
    9090{
    91   // number of comment for this picture
    92   $query = 'SELECT COUNT(*) AS nb_comments';
    93   $query.= ' FROM '.COMMENTS_TABLE.' WHERE image_id = '.$page['image_id'];
    94   $query.= " AND validated = 'true'";
    95   $query.= ';';
     91  // number of comments for this picture
     92  $query = '
     93SELECT COUNT(*) AS nb_comments
     94  FROM '.COMMENTS_TABLE.'
     95  WHERE image_id='.$page['image_id']." AND validated = 'true'";
    9696  $row = mysql_fetch_array( pwg_query( $query ) );
    9797
     
    161161      or (is_a_guest() and $conf['comments_forall']))
    162162  {
    163     include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    164163    $key = get_comment_post_key($page['image_id']);
    165164    $content = '';
  • trunk/include/ws_functions.inc.php

    r3065 r3145  
    523523  }
    524524
    525   include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    526 
    527525  $comm = array(
    528526    'author' => trim( stripslashes($params['author']) ),
     
    703701      )
    704702  {
    705     include_once(PHPWG_ROOT_PATH.'include/functions_comment.inc.php');
    706703    $comment_post_data['author'] = $user['username'];
    707704    $comment_post_data['key'] = get_comment_post_key($params['image_id']);
     
    10421039      // last chance to make the directory writable
    10431040      @chmod($high_dir, 0777);
    1044      
     1041
    10451042      if (!is_writable($high_dir))
    10461043      {
     
    10481045      }
    10491046    }
    1050    
     1047
    10511048    secure_directory($high_dir);
    1052    
     1049
    10531050    // high resolution path, same name as web size file
    10541051    $high_path = sprintf(
     
    14831480  // thumbnail_content
    14841481  // thumbnail_sum
    1485  
     1482
    14861483  $params['image_id'] = (int)$params['image_id'];
    14871484  if ($params['image_id'] <= 0)
     
    15371534      );
    15381535  }
    1539  
     1536
    15401537  if (isset($params['categories']))
    15411538  {
     
    16181615          $current_rank_of[$cat_id] = 0;
    16191616        }
    1620        
     1617
    16211618        if ('auto' == $rank_on_category[$cat_id])
    16221619        {
  • trunk/tags.php

    r3049 r3145  
    150150  if (count($letter['tags']) > 0)
    151151  {
    152     $letter['CHANGE_COLUMN'] = false;
     152    unset($letter['CHANGE_COLUMN']);
    153153    $letter['TITLE'] = $current_letter;
    154154    $template->append(
  • trunk/template/yoga/index.tpl

    r3108 r3145  
    1515      </li>
    1616      {/if}
    17      
     17
    1818      {if isset($favorite) }
    1919      <li><a href="{$favorite.U_FAVORITE}" title="{'del_all_favorites_hint'|@translate}"><img src="{$favorite.FAVORITE_IMG}" class="button" alt="favorite" title="{'del_all_favorites_hint'|@translate}"></a></li>
     
    2929
    3030      {if isset($U_SEARCH_RULES) }
    31       <li><a href="{$U_SEARCH_RULES}" style="border:none;" onclick="popuphelp(this.href); return false;" title="{'Search rules'|@translate}" rel="nofollow"><img src="{$ROOT_URL}{$themeconf.icon_dir}/search_rules.png" class="button" alt="(?)"></a></li>
     31      <li><a href="{$U_SEARCH_RULES}" onclick="popuphelp(this.href); return false;" title="{'Search rules'|@translate}" rel="nofollow"><img src="{$ROOT_URL}{$themeconf.icon_dir}/search_rules.png" class="button" alt="(?)" /></a></li>
    3232      {/if}
    3333
  • trunk/template/yoga/tags.tpl

    r2648 r3145  
    4242    </table>
    4343  </fieldset>
    44       {if $letter.CHANGE_COLUMN|@default:false}
     44      {if isset($letter.CHANGE_COLUMN) }
    4545      </td>
    4646      <td valign="top">
Note: See TracChangeset for help on using the changeset viewer.