Changeset 1113


Ignore:
Timestamp:
Mar 30, 2006, 2:37:07 AM (18 years ago)
Author:
rvelices
Message:

fix: image_order cookie path fixed for url rewriting

improve: add function access_denied called when check_status or
check_restrictions fail

fix: french language correction

fix: remove php warnings in clean_iptc_value

split search functions into include/functions_search.inc.php

Location:
trunk
Files:
1 added
9 edited

Legend:

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

    r1109 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    786786
    787787/**
    788  * Prepends and appends a string at each value of the given array.
    789  *
    790  * @param array
    791  * @param string prefix to each array values
    792  * @param string suffix to each array values
    793  */
    794 function prepend_append_array_items($array, $prepend_str, $append_str)
    795 {
    796   array_walk(
    797     $array,
    798     create_function('&$s', '$s = "'.$prepend_str.'".$s."'.$append_str.'";')
    799     );
    800 
    801   return $array;
    802 }
    803 
    804 /**
    805  * returns search rules stored into a serialized array in "search"
    806  * table. Each search rules set is numericaly identified.
    807  *
    808  * @param int search_id
    809  * @return array
    810  */
    811 function get_search_array($search_id)
    812 {
    813   if (!is_numeric($search_id))
    814   {
    815     die('Search id must be an integer');
    816   }
    817 
    818   $query = '
    819 SELECT rules
    820   FROM '.SEARCH_TABLE.'
    821   WHERE id = '.$search_id.'
    822 ;';
    823   list($serialized_rules) = mysql_fetch_row(pwg_query($query));
    824 
    825   return unserialize($serialized_rules);
    826 }
    827 
    828 /**
    829  * returns the SQL clause from a search identifier
    830  *
    831  * Search rules are stored in search table as a serialized array. This array
    832  * need to be transformed into an SQL clause to be used in queries.
    833  *
    834  * @param int search_id
    835  * @return string
    836  */
    837 function get_sql_search_clause($search_id)
    838 {
    839   $search = get_search_array($search_id);
    840 
    841   // SQL where clauses are stored in $clauses array during query
    842   // construction
    843   $clauses = array();
    844 
    845   foreach (array('file','name','comment','keywords','author') as $textfield)
    846   {
    847     if (isset($search['fields'][$textfield]))
    848     {
    849       $local_clauses = array();
    850       foreach ($search['fields'][$textfield]['words'] as $word)
    851       {
    852         array_push($local_clauses, $textfield." LIKE '%".$word."%'");
    853       }
    854 
    855       // adds brackets around where clauses
    856       $local_clauses = prepend_append_array_items($local_clauses, '(', ')');
    857 
    858       array_push(
    859         $clauses,
    860         implode(
    861           ' '.$search['fields'][$textfield]['mode'].' ',
    862           $local_clauses
    863           )
    864         );
    865     }
    866   }
    867 
    868   if (isset($search['fields']['allwords']))
    869   {
    870     $fields = array('file', 'name', 'comment', 'keywords', 'author');
    871     // in the OR mode, request bust be :
    872     // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
    873     // OR (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
    874     //
    875     // in the AND mode :
    876     // ((field1 LIKE '%word1%' OR field2 LIKE '%word1%')
    877     // AND (field1 LIKE '%word2%' OR field2 LIKE '%word2%'))
    878     $word_clauses = array();
    879     foreach ($search['fields']['allwords']['words'] as $word)
    880     {
    881       $field_clauses = array();
    882       foreach ($fields as $field)
    883       {
    884         array_push($field_clauses, $field." LIKE '%".$word."%'");
    885       }
    886       // adds brackets around where clauses
    887       array_push(
    888         $word_clauses,
    889         implode(
    890           "\n          OR ",
    891           $field_clauses
    892           )
    893         );
    894     }
    895 
    896     array_walk(
    897       $word_clauses,
    898       create_function('&$s','$s="(".$s.")";')
    899       );
    900 
    901     array_push(
    902       $clauses,
    903       "\n         ".
    904       implode(
    905         "\n         ".
    906               $search['fields']['allwords']['mode'].
    907         "\n         ",
    908         $word_clauses
    909         )
    910       );
    911   }
    912 
    913   foreach (array('date_available', 'date_creation') as $datefield)
    914   {
    915     if (isset($search['fields'][$datefield]))
    916     {
    917       array_push(
    918         $clauses,
    919         $datefield." = '".$search['fields'][$datefield]['date']."'"
    920         );
    921     }
    922 
    923     foreach (array('after','before') as $suffix)
    924     {
    925       $key = $datefield.'-'.$suffix;
    926 
    927       if (isset($search['fields'][$key]))
    928       {
    929         array_push(
    930           $clauses,
    931 
    932           $datefield.
    933           ($suffix == 'after'             ? ' >' : ' <').
    934           ($search['fields'][$key]['inc'] ? '='  : '').
    935           " '".$search['fields'][$key]['date']."'"
    936 
    937           );
    938       }
    939     }
    940   }
    941 
    942   if (isset($search['fields']['cat']))
    943   {
    944     if ($search['fields']['cat']['sub_inc'])
    945     {
    946       // searching all the categories id of sub-categories
    947       $cat_ids = get_subcat_ids($search['fields']['cat']['words']);
    948     }
    949     else
    950     {
    951       $cat_ids = $search['fields']['cat']['words'];
    952     }
    953 
    954     $local_clause = 'category_id IN ('.implode(',', $cat_ids).')';
    955     array_push($clauses, $local_clause);
    956   }
    957 
    958   // adds brackets around where clauses
    959   $clauses = prepend_append_array_items($clauses, '(', ')');
    960 
    961   $where_separator =
    962     implode(
    963       "\n    ".$search['mode'].' ',
    964       $clauses
    965       );
    966 
    967   $search_clause = $where_separator;
    968 
    969   if (isset($forbidden))
    970   {
    971     $search_clause.= "\n    AND ".$forbidden;
    972   }
    973 
    974   return $search_clause;
    975 }
    976 
    977 /**
    978788 * Returns webmaster mail address depending on $conf['webmaster_id']
    979789 *
  • trunk/include/functions_category.inc.php

    r1092 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    4343function check_restrictions($category_id)
    4444{
    45   global $user, $lang;
     45  global $user;
    4646
    4747  if (in_array($category_id, explode(',', $user['forbidden_categories'])))
    4848  {
    49     $login_url =
    50       get_root_url().'identification.php?redirect='
    51       .urlencode(urlencode($_SERVER['REQUEST_URI']));
    52 
    53     if (!$user['is_the_guest'])
    54     {
    55       die('Fatal: you are trying to reach a forbidden category');
    56     }
    57     else
    58     {
    59       redirect($login_url);
    60     }
     49    access_denied();
    6150  }
    6251}
  • trunk/include/functions_html.inc.php

    r1092 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    494494  return get_cat_display_name($cat_info['name'], $url, $replace_space);
    495495}
     496
     497/**
     498 * exits the current script (either exit or redirect)
     499 */
     500function access_denied()
     501{
     502  global $user, $lang;
     503
     504  $login_url =
     505      get_root_url().'identification.php?redirect='
     506      .urlencode(urlencode($_SERVER['REQUEST_URI']));
     507
     508  if ( isset($user['is_the_guest']) and !$user['is_the_guest'] )
     509  {
     510    echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
     511    echo '<a href="'.get_root_url().'identification.php">'.$lang['identification'].'</a>&nbsp;';
     512    echo '<a href="'.make_index_url().'">'.$lang['home'].'</a></div>';
     513    exit();
     514  }
     515  else
     516  {
     517    header('HTTP/1.1 401 Authorization required');
     518    header('Status: 401 Authorization required');
     519    redirect($login_url);
     520  }
     521}
    496522?>
  • trunk/include/functions_metadata.inc.php

    r858 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    3636{
    3737  $result = array();
    38  
     38
    3939  // Read IPTC data
    4040  $iptc = array();
    41  
     41
    4242  $imginfo = array();
    4343  getimagesize($filename, $imginfo);
    44  
     44
    4545  if (isset($imginfo['APP13']))
    4646  {
     
    8383{
    8484  // strip leading zeros (weird Kodak Scanner software)
    85   while ($value[0] == chr(0))
     85  while ( isset($value[0]) and $value[0] == chr(0))
    8686  {
    8787    $value = substr($value, 1);
     
    8989  // remove binary nulls
    9090  $value = str_replace(chr(0x00), ' ', $value);
    91  
     91
    9292  return $value;
    9393}
     
    108108    die('Exif extension not available, admin should disable exif use');
    109109  }
    110  
     110
    111111  // Read EXIF data
    112112  if ($exif = @read_exif_data($filename))
  • trunk/include/functions_user.inc.php

    r1085 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
    11 // | revision      : $Revision$
    1211// | revision      : $Revision$
    1312// +-----------------------------------------------------------------------+
     
    609608function check_status($access_type, $user_status = '')
    610609{
    611   global $lang;
    612 
    613610  if (!is_autorize_status($access_type, $user_status))
    614611  {
    615     echo '<div style="text-align:center;">'.$lang['access_forbiden'].'<br />';
    616     echo '<a href="'.PHPWG_ROOT_PATH.'identification.php">'.$lang['identification'].'</a></div>';
    617     exit();
     612    access_denied();
    618613  }
    619614}
  • trunk/include/section_init.inc.php

    r1109 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
     8// | file          : $Id$
    99// | last update   : $Date$
    1010// | last modifier : $Author$
     
    343343  if ($page['section'] == 'search')
    344344  {
     345    include_once( PHPWG_ROOT_PATH .'include/functions_search.inc.php' );
    345346    $query = '
    346347SELECT DISTINCT(id)
  • trunk/index.php

    r1109 r1113  
    5555    'pwg_image_order',
    5656    $_GET['image_order'] > 0 ? $_GET['image_order'] : '',
    57     0
     57    0, cookie_path()
    5858    );
    5959
  • trunk/language/fr_FR.iso-8859-1/common.lang.php

    r1103 r1113  
    246246$lang['picture'] = 'image';
    247247$lang['picture_high'] = 'Cliquer sur l\'image pour la visualiser en haute définition';
    248 $lang['picture_show_metadata'] = 'Monter les méta-données du fichier';
     248$lang['picture_show_metadata'] = 'Montrer les méta-données du fichier';
    249249$lang['powered_by'] = 'Propulsé par';
    250250$lang['preferences'] = 'Préférences';
  • trunk/search_rules.php

    • Property svn:keywords set to Author Date Id Revision
    r1092 r1113  
    66// +-----------------------------------------------------------------------+
    77// | branch        : BSF (Best So Far)
    8 // | file          : $RCSfile$
    9 // | last update   : $Date: 2005-09-27 23:57:14 +0200 (mar, 27 sep 2005) $
    10 // | last modifier : $Author: plg $
    11 // | revision      : $Revision: 879 $
     8// | file          : $Id$
     9// | last update   : $Date$
     10// | last modifier : $Author$
     11// | revision      : $Revision$
    1212// +-----------------------------------------------------------------------+
    1313// | This program is free software; you can redistribute it and/or modify  |
     
    4444define('PHPWG_ROOT_PATH','./');
    4545include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
     46include_once( PHPWG_ROOT_PATH.'include/functions_search.inc.php' );
    4647
    4748$page['body_id'] = 'thePopuphelpPage';
Note: See TracChangeset for help on using the changeset viewer.