Changeset 355


Ignore:
Timestamp:
Feb 8, 2004, 2:28:18 AM (20 years ago)
Author:
gweltas
Message:

Template migration

Location:
trunk
Files:
2 added
2 deleted
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/comments.php

    r354 r355  
    3030include_once( $phpwg_root_path.'include/common.inc.php' );
    3131
    32 //------------------------------------------------------------------- functions
    33 function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
     32//--------------------------------------------------- number of days to display
     33if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
     34else                               define( 'MAX_DAYS', 0 );
     35//----------------------------------------- non specific section initialization
     36$array_cat_directories = array();
     37$array_cat_names       = array();
     38$array_cat_site_id     = array();
     39//------------------------------------------------------- last comments display
     40
     41//
     42// Start output of page
     43//
     44$title= $lang['title_comments'];
     45include('include/page_header.php');
     46
     47$template->set_filenames( array('comments'=>'comments.tpl') );
     48initialize_template();
     49
     50$template->assign_vars(array(
     51  'L_TITLE' => $lang['title_comments'],
     52  'L_STATS' => $lang['stats_last_days'],
     53  'L_RETURN' => $lang['search_return_main_page'],
     54 
     55  'U_HOME' => add_session_id( 'category.php' )
     56  )
     57);
     58
     59foreach ( $conf['last_days'] as $option ) {
     60  $url = './comments.php?last_days='.($option - 1);
     61  $template->assign_block_vars('last_day_option', array (
     62    'OPTION'=>$option,
     63        'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
     64        'U_OPTION'=>add_session_id( $url )
     65        ));
     66}
     67
     68// 1. retrieving picture ids which have comments recently added
     69$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
     70list($year,$month,$day) = explode( '-', $date);
     71$maxtime = mktime( 0,0,0,$month,$day,$year );
     72$query = 'SELECT DISTINCT(ic.image_id) as image_id,';
     73$query .= '(ic.category_id) as category_id';
     74$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
     75$query.=     ', '.PREFIX_TABLE.'image_category AS ic';
     76$query.= ' WHERE c.image_id = ic.image_id';
     77$query.= ' AND date > '.$maxtime;
     78$query.= " AND validated = 'true'";
     79// we must not show pictures of a forbidden category
     80if ( $user['forbidden_categories'] != '' )
    3481{
    35   global $vtp,$handle,$lang,$conf,
    36     $array_cat_directories,$array_cat_site_id,$array_cat_names;
     82  $query.= ' AND category_id NOT IN ';
     83  $query.= '('.$user['forbidden_categories'].')';
     84}
     85$query.= ' ORDER BY ic.image_id DESC';
     86$query.= ';';
     87$result = mysql_query( $query );
    3788
    38   while ( $row = mysql_fetch_array( $mysql_result ) )
     89while ( $row = mysql_fetch_array( $result ) )
    3990  {
    40     $vtp->addSession( $handle, 'picture' );
    41     // 1. find a category wich is authorized for the user to display a
    42     //    category name.
    43     $query = 'SELECT category_id';
    44     $query.= ' FROM '.PREFIX_TABLE.'image_category';
    45     $query.= ' WHERE image_id = '.$row['image_id'];
    46     if ( count( $forbidden_cat_ids ) > 0 )
    47     {
    48       $query.= ' AND category_id NOT IN (';
    49       foreach ( $forbidden_cat_ids as $i => $restricted_cat ) {
    50         if ( $i > 0 ) $query.= ',';
    51         $query.= $restricted_cat;
    52       }
    53       $query.= ')';
    54     }
    55     $query.= ' ORDER BY RAND()';
    56     $query.= ';';
    57     $subrow = mysql_fetch_array( mysql_query( $query ) );
    58     $category_id = $subrow['category_id'];
     91    $category_id=$row['category_id'];
    5992
    60     if ( !isset($array_cat_directories[$category_id]))
    61     {
    62       $array_cat_directories[$category_id] =
    63         get_complete_dir( $category_id );
    64       $cat_result = get_cat_info( $category_id );
    65       $array_cat_site_id[$category_id] = $cat_result['site_id'];
    66       $array_cat_names[$category_id] =
    67         get_cat_display_name( $cat_result['name'], ' > ', '' );
    68     }
    69    
    70     // 2. for each picture, getting informations for displaying thumbnail and
    71     //    link to the full size picture
     93    // for each picture, getting informations for displaying thumbnail and
     94    // link to the full size picture
    7295    $query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
    73     $query.= ' FROM '.PREFIX_TABLE.'images';
     96    $query.= ' FROM '.IMAGES_TABLE;
    7497    $query.= ' WHERE id = '.$row['image_id'];
    7598    $query.= ';';
     
    77100    $subrow = mysql_fetch_array( $subresult );
    78101
    79     if ( $array_cat_directories[$subrow['cat_id']] == '' )
     102    if ( !isset($array_cat_directories[$subrow['cat_id']]) )
    80103    {
    81104      $array_cat_directories[$subrow['cat_id']] =
     
    93116    else                         $name.= str_replace( '_', ' ', $file );
    94117    $name.= ' [ '.$subrow['file'].' ]';
    95     $vtp->setVar( $handle, 'picture.title', $name );
    96     // source of the thumbnail picture
     118        // source of the thumbnail picture
    97119    $src = $array_cat_directories[$subrow['cat_id']];
    98120    $src.= 'thumbnail/'.$conf['prefix_thumbnail'];
    99121    $src.= $file.'.'.$subrow['tn_ext'];
    100     $vtp->setVar( $handle, 'picture.thumb_src', $src );
    101     // link to the full size picture
     122        // link to the full size picture
    102123    $url = './picture.php?cat='.$category_id;
    103124    $url.= '&image_id='.$row['image_id'];
    104     $vtp->setVar( $handle, 'picture.thumb_url', add_session_id( $url ) );
    105     // 3. for each picture, retrieving all comments
     125       
     126        $template->assign_block_vars('picture',array(
     127          'TITLE_IMG'=>$name,
     128          'I_THUMB'=>$src,
     129          'U_THUMB'=>add_session_id( $url )
     130          ));
     131
     132    // for each picture, retrieving all comments
    106133    $query = 'SELECT id,date,author,content';
    107     $query.= ' FROM '.PREFIX_TABLE.'comments';
     134    $query.= ' FROM '.COMMENTS_TABLE;
    108135    $query.= ' WHERE image_id = '.$row['image_id'];
    109136    $query.= ' AND date > '.$maxtime;
     
    114141    while ( $subrow = mysql_fetch_array( $handleresult ) )
    115142    {
    116       $vtp->addSession( $handle, 'comment' );
    117143      $author = $subrow['author'];
    118144      if ( $subrow['author'] == '' ) $author = $lang['guest'];
    119       $vtp->setVar( $handle, 'comment.author', $author );
    120       $displayed_date = format_date( $subrow['date'], 'unix', true );
    121       $vtp->setVar( $handle, 'comment.date', $displayed_date );
    122 
    123145      $content = nl2br( $subrow['content'] );
    124146     
     
    137159      $replacement = '<span style="font-style:italic;">\1</span>';
    138160      $content = preg_replace( $pattern, $replacement, $content );
    139      
    140       $vtp->setVar( $handle, 'comment.content', $content );
    141       $vtp->closeSession( $handle, 'comment' );
     161      $template->assign_block_vars('picture.comment',array(
     162            'AUTHOR'=>$author,
     163                'DATE'=>format_date( $subrow['date'], 'unix', true ),
     164                'CONTENT'=>$content,
     165                ));
    142166    }
    143     $vtp->closeSession( $handle, 'picture' );
    144167  }
    145 }
    146 //----------------------------------------------------- template initialization
    147 //
    148 // Start output of page
    149 //
    150 $title= $lang['title_comments'];
    151 include('include/page_header.php');
    152 
    153 $handle = $vtp->Open( './template/'.$user['template'].'/comments.vtp' );
    154 initialize_template();
    155 $tpl = array( 'title_comments','stats_last_days','search_return_main_page' );
    156 templatize_array( $tpl, 'lang', $handle );
    157 //--------------------------------------------------- number of days to display
    158 if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
    159 else                               define( 'MAX_DAYS', 0 );
    160 //----------------------------------------- non specific section initialization
    161 $array_cat_directories = array();
    162 $array_cat_names       = array();
    163 $array_cat_site_id     = array();
    164 //------------------------------------------------------- last comments display
    165 foreach ( $conf['last_days'] as $option ) {
    166   $vtp->addSession( $handle, 'last_day_option' );
    167   $vtp->setVar( $handle, 'last_day_option.option', $option );
    168   $url = './comments.php';
    169   $url.= '?last_days='.($option - 1);
    170   $vtp->setVar( $handle, 'last_day_option.link', add_session_id( $url ) );
    171   $style = '';
    172   if ( $option == MAX_DAYS + 1 ) $style = 'text-decoration:underline;';
    173   $vtp->setVar( $handle, 'last_day_option.style', $style );
    174   $vtp->closeSession( $handle, 'last_day_option' );
    175 }
    176 $vtp->setVar( $handle, 'back_url', add_session_id( './category.php' ) );
    177 // 1. retrieving picture ids which have comments recently added
    178 $date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
    179 list($year,$month,$day) = explode( '-', $date);
    180 $maxtime = mktime( 0,0,0,$month,$day,$year );
    181 $query = 'SELECT DISTINCT(ic.image_id) as image_id';
    182 $query.= ' FROM '.PREFIX_TABLE.'comments AS c';
    183 $query.=     ', '.PREFIX_TABLE.'image_category AS ic';
    184 $query.= ' WHERE c.image_id = ic.image_id';
    185 $query.= ' AND date > '.$maxtime;
    186 $query.= " AND validated = 'true'";
    187 // we must not show pictures of a forbidden category
    188 if ( $user['forbidden_categories'] != '' )
    189 {
    190   $query.= ' AND category_id NOT IN ';
    191   $query.= '('.$user['forbidden_categories'].')';
    192 }
    193 $query.= ' ORDER BY ic.image_id DESC';
    194 $query.= ';';
    195 $result = mysql_query( $query );
    196 display_pictures( $result, $maxtime, $user['restrictions'] );
    197168//----------------------------------------------------------- html code display
    198 $code = $vtp->Display( $handle, 0 );
    199 echo $code;
     169$template->pparse('comments');
    200170include('include/page_tail.php');
    201171?>
  • trunk/search.php

    r354 r355  
    6969include('include/page_header.php');
    7070
    71 $handle = $vtp->Open( './template/'.$user['template'].'/search.vtp' );
     71$template->set_filenames( array('search'=>'search.tpl') );
    7272initialize_template();
    73 $tpl = array( 'search_title','search_return_main_page','submit',
    74               'search_comments' );
    75 templatize_array( $tpl, 'lang', $handle );
    76 //----------------------------------------------------------------- form action
    77 $vtp->setGlobalVar( $handle, 'form_action', add_session_id( './search.php' ) );
     73
     74$template->assign_vars(array(
     75  'L_TITLE' => $lang['search_title'],
     76  'L_COMMENTS' => $lang['search_comments'],
     77  'L_RETURN' => $lang['search_return_main_page'],
     78  'L_SUBMIT' => $lang['submit'],
     79  'L_SEARCH'=>$lang['search_field_search'].' *',
     80  'L_SEARCH_OR'=>$lang['search_mode_or'],
     81  'L_SEARCH_AND'=>$lang['search_mode_and'],
     82 
     83  'F_ACTION' => add_session_id( 'search.php' ),
     84  'F_TEXT_VALUE' => isset($_POST['search'])?$_POST['search']:'',
     85   
     86  'U_HOME' => add_session_id( 'category.php' )
     87  )
     88);
     89
    7890//-------------------------------------------------------------- errors display
    7991if ( sizeof( $error ) != 0 )
    8092{
    81   $vtp->addSession( $handle, 'errors' );
     93  $template->assign_block_vars('errors',array());
    8294  for ( $i = 0; $i < sizeof( $error ); $i++ )
    8395  {
    84     $vtp->addSession( $handle, 'li' );
    85     $vtp->setVar( $handle, 'li.li', $error[$i] );
    86     $vtp->closeSession( $handle, 'li' );
     96    $template->assign_block_vars('errors.error',array('ERROR'=>$error[$i]));
    8797  }
    88   $vtp->closeSession( $handle, 'errors' );
    8998}
    90 //------------------------------------------------------------------------ form
    91 // search field
    92 $vtp->addSession( $handle, 'line' );
    93 $vtp->setVar( $handle, 'line.name', $lang['search_field_search'].' *' );
    94 $vtp->addSession( $handle, 'text' );
    95 $vtp->setVar( $handle, 'text.size', '40' );
    96 $vtp->setVar( $handle, 'text.name', 'search' );
    97 if (isset($_POST['search']))
    98 $vtp->setVar( $handle, 'text.value', $_POST['search'] );
    99 $vtp->closeSession( $handle, 'text' );
    100 $vtp->closeSession( $handle, 'line' );
    101 // mode of search : match all words or at least one of this words
    102 $vtp->addSession( $handle, 'line' );
    103 $vtp->addSession( $handle, 'group' );
    104 
    105 $vtp->addSession( $handle, 'radio' );
    106 $vtp->setVar( $handle, 'radio.name', 'mode' );
    107 $vtp->setVar( $handle, 'radio.value', 'OR' );
    108 $vtp->setVar( $handle, 'radio.option', $lang['search_mode_or'] );
    109 if (!isset($_POST['mode']) || $_POST['mode'] == 'OR' )
    110 {
    111   $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
    112 }
    113 $vtp->closeSession( $handle, 'radio' );
    114 
    115 $vtp->addSession( $handle, 'radio' );
    116 $vtp->setVar( $handle, 'radio.name', 'mode' );
    117 $vtp->setVar( $handle, 'radio.value', 'AND' );
    118 $vtp->setVar( $handle, 'radio.option', $lang['search_mode_and'] );
    119 if ( isset($_POST['mode']) && $_POST['mode'] == 'AND' )
    120 {
    121   $vtp->setVar( $handle, 'radio.checked', ' checked="checked"' );
    122 }
    123 $vtp->closeSession( $handle, 'radio' );
    124 
    125 $vtp->closeSession( $handle, 'group' );
    126 $vtp->closeSession( $handle, 'line' );
    127 //---------------------------------------------------- return to main page link
    128 $vtp->setGlobalVar( $handle, 'back_url', add_session_id( './category.php' ) );
    129 //----------------------------------------------------------- html code display
    130 $code = $vtp->Display( $handle, 0 );
    131 echo $code;
    13299//------------------------------------------------------------ log informations
    133100pwg_log( 'search', $title );
    134101mysql_close();
     102$template->pparse('search');
    135103include('include/page_tail.php');
    136104?>
  • trunk/template/default/category.tpl

    r351 r355  
    22  <tr>
    33        <td valign="top" style="width:1%;padding:10px;">
    4           {F_START}100%{F_BEGIN}
     4          {T_START}100%{T_BEGIN}
    55                <div class="titreMenu">
    66                  <a href="{U_HOME}">{L_CATEGORIES}</a>
     
    3131                  <br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<img src="{T_COLLAPSED}" alt='' />&nbsp;<a href="{U_RECENT}"><span title="{L_RECENT_HINT}" style="font-weight:bold;">{L_RECENT}</span></a> {T_SHORT}
    3232                </div>
    33           {F_END}
     33          {T_END}
    3434          <div style="margin-bottom:5px;">&nbsp;</div>
    35           {F_START}100%{F_BEGIN}
     35          {T_START}100%{T_BEGIN}
    3636                <div class="titreMenu">{L_SUMMARY}</div>
    3737                <div class="menu">
     
    4343                  <!-- END upload -->
    4444                </div>
    45           {F_END}
     45          {T_END}
    4646        </td>
    4747        <td style="padding:5px;width:99%;" valign="top">
     
    4949                <tr>
    5050                  <td align="center">
    51                         {F_START}1%{F_BEGIN}
     51                        {T_START}1%{T_BEGIN}
    5252                          <div class="titrePage">{TITLE}</div>
    53                         {F_END}
     53                        {T_END}
    5454                        <div style="margin-bottom:5px;">&nbsp;</div>
    5555                        <!-- BEGIN thumbnails -->
     
    9595                <tr>
    9696                  <td align="right">
    97                         {F_START}1%{F_BEGIN}
     97                        {T_START}1%{T_BEGIN}
    9898                          <div class="info">
    9999                                {L_USER}&nbsp;{USERNAME}<br />
     
    104104                                {L_SEND_MAIL}&nbsp;<a href="mailto:{S_MAIL}?subject={L_TITLE_MAIL}"><span style="font-weight:bold;">{S_WEBMASTER}</span></a>
    105105                          </div>
    106                         {F_END}
     106                        {T_END}
    107107                  </td>
    108108                </tr>
  • trunk/template/default/htmlfunctions.inc.php

    r351 r355  
    144144 
    145145  $template->assign_vars(array(
    146         'F_START' => get_frame_start(),
    147         'F_BEGIN' => get_frame_begin(),
    148         'F_END' =>  get_frame_end()
     146        'T_START' => get_frame_start(),
     147        'T_BEGIN' => get_frame_begin(),
     148        'T_END' =>  get_frame_end()
    149149        )
    150150        );
Note: See TracChangeset for help on using the changeset viewer.