Changeset 33


Ignore:
Timestamp:
Jul 23, 2003, 9:49:15 PM (21 years ago)
Author:
z0rglub
Message:

Support of keywords for pictures. They are used in the search

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/admin/infos_images.php

    r26 r33  
    2222{
    2323  // date arrives at this format : DD/MM/YYYY
    24   // checkdate ( int month, int day, int year)
    25   $tab_date = explode( '/', $date );
    26   return checkdate ( $tab_date[1], $tab_date[0], $tab_date[2]);
     24  list($day,$month,$year) = explode( '/', $date );
     25  return checkdate ( $month, $day, $year );
    2726}
    2827
     
    3130  // date arrives at this format : DD/MM/YYYY
    3231  // It must be transformed in YYYY-MM-DD
    33   $tab_date = explode( '/', $date );
    34   return $tab_date[2].'-'.$tab_date[1].'-'.$tab_date[0];
     32  list($day,$month,$year) = explode( '/', $date );
     33  return $year.'-'.$month.'-'.$day;
    3534}
    3635
     
    4140  if ( $date != '' )
    4241  {
    43     $tab_date = explode( '-', $date );
    44     return $tab_date[2].'/'.$tab_date[1].'/'.$tab_date[0];
     42    list($year,$month,$day) = explode( '-', $date );
     43    return $day.'/'.$month.'/'.$year;
    4544  }
    4645  else
     
    4847    return '';
    4948  }
     49}
     50
     51// get_keywords returns an array with relevant keywords found in the string
     52// given in argument. Keywords must be separated by comma in this string.
     53// keywords must :
     54//   - be longer or equal to 3 characters
     55//   - not contain ', " or blank characters
     56//   - unique in the string ("test,test" -> "test")
     57function get_keywords( $keywords_string )
     58{
     59  $keywords = array();
     60
     61  $candidates = explode( ',', $keywords_string );
     62  foreach ( $candidates as $candidate ) {
     63    if ( strlen($candidate) >= 3 and !preg_match( '/(\'|"|\s)/', $candidate ) )
     64      array_push( $keywords, $candidate );
     65  }
     66
     67  return array_unique( $keywords );
    5068}
    5169//-------------------------------------------------------------- initialization
     
    6785    $comment       = 'comment-'.$row['id'];
    6886    $date_creation = 'date_creation-'.$row['id'];
     87    $keywords      = 'keywords-'.$row['id'];
    6988    if ( isset( $_POST[$name] ) )
    7089    {
    7190      $query = 'UPDATE '.PREFIX_TABLE.'images';
     91
     92      $query.= ' SET name = ';
    7293      if ( $_POST[$name] == '' )
     94        $query.= 'NULL';
     95      else
     96        $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'";
     97
     98      $query.= ', author = ';
     99      if ( $_POST[$author] == '' )
     100        $query.= 'NULL';
     101      else
     102        $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'";
     103
     104      $query.= ', comment = ';
     105      if ( $_POST[$comment] == '' )
     106        $query.= 'NULL';
     107      else
     108        $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'";
     109
     110      $query.= ', date_creation = ';
     111      if ( check_date_format( $_POST[$date_creation] ) )
     112        $query.= "'".date_convert( $_POST[$date_creation] )."'";
     113      else if ( $_POST[$date_creation] == '' )
     114        $query.= 'NULL';
     115
     116      $query.= ', keywords = ';
     117      $keywords_array = get_keywords( $_POST[$keywords] );
     118      if ( count( $keywords_array ) == 0 )
     119        $query.= 'NULL';
     120      else
    73121      {
    74         $query.= ' SET name = NULL';
    75       }
    76       else
    77       {
    78         $query.= " SET name = '".htmlentities( $_POST[$name], ENT_QUOTES )."'";
    79       }
    80       if ( $_POST[$author] == '' )
    81       {
    82         $query.= ', author = NULL';
    83       }
    84       else
    85       {
    86         $query.= ", author = '".htmlentities($_POST[$author],ENT_QUOTES)."'";
    87       }
    88       if ( $_POST[$comment] == '' )
    89       {
    90         $query.= ', comment = NULL';
    91       }
    92       else
    93       {
    94         $query.= ", comment = '".htmlentities($_POST[$comment],ENT_QUOTES)."'";
    95       }
    96       if ( check_date_format( $_POST[$date_creation] ) )
    97       {
    98         $date = date_convert( $_POST[$date_creation] );
    99         $query.= ", date_creation = '".$date."'";
    100       }
    101       else if ( $_POST[$date_creation] == '' )
    102       {
    103         $query.= ', date_creation = NULL';
    104       }
     122        $query.= '"';
     123        foreach ( $keywords_array as $i => $keyword ) {
     124          if ( $i > 0 ) $query.= ',';
     125          $query.= $keyword;
     126        }
     127        $query.= '"';
     128      }
     129
    105130      $query.= ' WHERE id = '.$row['id'];
    106131      $query.= ';';
     
    147172      echo $lang['err_date'];
    148173    }
     174  }
     175  if ( $_POST['use_common_keywords'] == 1 )
     176  {
     177    $keywords = get_keywords( $_POST['keywords_cat'] );
     178    $query = 'UPDATE '.PREFIX_TABLE.'images';
     179    if ( count( $keywords ) == 0 )
     180    {
     181      $query.= ' SET keywords = NULL';
     182    }
     183    else
     184    {
     185      $query.= ' SET keywords = "';
     186      foreach ( $keywords as $i => $keyword ) {
     187        if ( $i > 0 ) $query.= ',';
     188        $query.= $keyword;
     189      }
     190      $query.= '"';
     191    }
     192    $query.= ' WHERE cat_id = '.$page['cat'];
     193    $query.= ';';
     194    mysql_query( $query );
    149195  }
    150196//--------------------------------------------------------- form initialization
     
    179225                'infoimage_creation_date','infoimage_detailed','thumbnail',
    180226                'infoimage_title','infoimage_comment',
    181                 'infoimage_creation_date' );
     227                'infoimage_creation_date','infoimage_keywords' );
    182228  templatize_array( $tpl, 'lang', $sub );
    183229//------------------------------------------------------------------------ form
     
    191237  $vtp->setVar( $sub, 'cat_name', $cat_name );
    192238
    193   $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation';
     239  $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords';
    194240  $query.= ' FROM '.PREFIX_TABLE.'images';
    195241  $query.= ' WHERE cat_id = '.$page['cat'];
     
    206252    $vtp->setVar( $sub, 'picture.author', $row['author'] );
    207253    $vtp->setVar( $sub, 'picture.comment', $row['comment'] );
     254    $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] );
    208255    $vtp->setVar( $sub, 'picture.date_creation',
    209256                  date_convert_back( $row['date_creation'] ) );
  • trunk/include/functions_category.inc.php

    r26 r33  
    422422
    423423        $page['where'] = ' WHERE (';
    424         $fields = array( 'file', 'name', 'comment' );
     424        $fields = array( 'file', 'name', 'comment', 'keywords' );
    425425        $words = explode( ',', $_GET['search'] );
    426426        $sql_search = array();
  • trunk/language/francais.php

    r26 r33  
    493493// start version 1.3
    494494  // $lang['infoimage_err_date'] = 'date erronée';
     495  $lang['infoimage_keywords'] = 'mots-clefs';
    495496// end version 1.3
    496497  $lang['infoimage_general'] = 'Options générale pour la catégorie';
  • trunk/template/default/admin/infos_image.vtp

    r25 r33  
    2626      </td>
    2727    </tr>
     28    <tr>
     29      <td>
     30        <div style="margin-left:50px;">{#infoimage_keywords}</div>
     31      </td>
     32      <td style="text-align:center;">
     33        <input type="text" name="keywords_cat" value="" size="12" maxlength="255" />
     34      </td>
     35      <td style="text-align:left;">
     36        <input type="checkbox" name="use_common_keywords" value="1" />
     37        {#infoimage_useforall}
     38      </td>
     39    </tr>
    2840  </table>
    2941  <table width="100%">
    3042    <tr>
    31       <th colspan="5">{#infoimage_detailed}</th>
     43      <th colspan="6">{#infoimage_detailed}</th>
    3244    </tr>
    3345    <tr>
    34       <td colspan="5" align="center">{#navigation_bar}</td>
     46      <td colspan="6" align="center">{#navigation_bar}</td>
    3547    </tr>
    3648    <tr>
     
    4052      <td class="row2" style="text-align:center;">{#infoimage_comment}</td>
    4153      <td class="row2" style="text-align:center;">{#infoimage_creation_date}</td>
     54      <td class="row2" style="text-align:center;">{#infoimage_keywords}</td>
    4255    </tr>
    4356    <!--VTP_picture-->
     
    4861      <td style="text-align:center;"><textarea name="comment-{#id}" rows="3" cols="40" style="overflow:auto">{#comment}</textarea></td>
    4962      <td style="text-align:center;"><input type="text" name="date_creation-{#id}" value="{#date_creation}" maxlength="10" size="12" /></td>
     63      <td style="text-align:center;"><input type="text" name="keywords-{#id}" value="{#keywords}" maxlength="255" /></td>
    5064    </tr>
    5165    <!--/VTP_picture-->
    5266    <tr>
    53       <td colspan="5" style="text-align:center;">
     67      <td colspan="6" style="text-align:center;">
    5468        <input type="submit" value="{#submit}" name="submit" />
    5569      </td>
Note: See TracChangeset for help on using the changeset viewer.