aboutsummaryrefslogtreecommitdiffstats
path: root/comments.php
diff options
context:
space:
mode:
Diffstat (limited to 'comments.php')
-rw-r--r--comments.php186
1 files changed, 78 insertions, 108 deletions
diff --git a/comments.php b/comments.php
index 4dcb38fe2..beecdf30c 100644
--- a/comments.php
+++ b/comments.php
@@ -29,54 +29,77 @@
$phpwg_root_path = './';
include_once( $phpwg_root_path.'include/common.inc.php' );
-//------------------------------------------------------------------- functions
-function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
+//--------------------------------------------------- number of days to display
+if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
+else define( 'MAX_DAYS', 0 );
+//----------------------------------------- non specific section initialization
+$array_cat_directories = array();
+$array_cat_names = array();
+$array_cat_site_id = array();
+//------------------------------------------------------- last comments display
+
+//
+// Start output of page
+//
+$title= $lang['title_comments'];
+include('include/page_header.php');
+
+$template->set_filenames( array('comments'=>'comments.tpl') );
+initialize_template();
+
+$template->assign_vars(array(
+ 'L_TITLE' => $lang['title_comments'],
+ 'L_STATS' => $lang['stats_last_days'],
+ 'L_RETURN' => $lang['search_return_main_page'],
+
+ 'U_HOME' => add_session_id( 'category.php' )
+ )
+);
+
+foreach ( $conf['last_days'] as $option ) {
+ $url = './comments.php?last_days='.($option - 1);
+ $template->assign_block_vars('last_day_option', array (
+ 'OPTION'=>$option,
+ 'T_STYLE'=>(( $option == MAX_DAYS + 1 )?'text-decoration:underline;':''),
+ 'U_OPTION'=>add_session_id( $url )
+ ));
+}
+
+// 1. retrieving picture ids which have comments recently added
+$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
+list($year,$month,$day) = explode( '-', $date);
+$maxtime = mktime( 0,0,0,$month,$day,$year );
+$query = 'SELECT DISTINCT(ic.image_id) as image_id,';
+$query .= '(ic.category_id) as category_id';
+$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
+$query.= ', '.PREFIX_TABLE.'image_category AS ic';
+$query.= ' WHERE c.image_id = ic.image_id';
+$query.= ' AND date > '.$maxtime;
+$query.= " AND validated = 'true'";
+// we must not show pictures of a forbidden category
+if ( $user['forbidden_categories'] != '' )
{
- global $vtp,$handle,$lang,$conf,
- $array_cat_directories,$array_cat_site_id,$array_cat_names;
+ $query.= ' AND category_id NOT IN ';
+ $query.= '('.$user['forbidden_categories'].')';
+}
+$query.= ' ORDER BY ic.image_id DESC';
+$query.= ';';
+$result = mysql_query( $query );
- while ( $row = mysql_fetch_array( $mysql_result ) )
+while ( $row = mysql_fetch_array( $result ) )
{
- $vtp->addSession( $handle, 'picture' );
- // 1. find a category wich is authorized for the user to display a
- // category name.
- $query = 'SELECT category_id';
- $query.= ' FROM '.PREFIX_TABLE.'image_category';
- $query.= ' WHERE image_id = '.$row['image_id'];
- if ( count( $forbidden_cat_ids ) > 0 )
- {
- $query.= ' AND category_id NOT IN (';
- foreach ( $forbidden_cat_ids as $i => $restricted_cat ) {
- if ( $i > 0 ) $query.= ',';
- $query.= $restricted_cat;
- }
- $query.= ')';
- }
- $query.= ' ORDER BY RAND()';
- $query.= ';';
- $subrow = mysql_fetch_array( mysql_query( $query ) );
- $category_id = $subrow['category_id'];
+ $category_id=$row['category_id'];
- if ( !isset($array_cat_directories[$category_id]))
- {
- $array_cat_directories[$category_id] =
- get_complete_dir( $category_id );
- $cat_result = get_cat_info( $category_id );
- $array_cat_site_id[$category_id] = $cat_result['site_id'];
- $array_cat_names[$category_id] =
- get_cat_display_name( $cat_result['name'], ' > ', '' );
- }
-
- // 2. for each picture, getting informations for displaying thumbnail and
- // link to the full size picture
+ // for each picture, getting informations for displaying thumbnail and
+ // link to the full size picture
$query = 'SELECT name,file,storage_category_id as cat_id,tn_ext';
- $query.= ' FROM '.PREFIX_TABLE.'images';
+ $query.= ' FROM '.IMAGES_TABLE;
$query.= ' WHERE id = '.$row['image_id'];
$query.= ';';
$subresult = mysql_query( $query );
$subrow = mysql_fetch_array( $subresult );
- if ( $array_cat_directories[$subrow['cat_id']] == '' )
+ if ( !isset($array_cat_directories[$subrow['cat_id']]) )
{
$array_cat_directories[$subrow['cat_id']] =
get_complete_dir( $subrow['cat_id'] );
@@ -92,19 +115,23 @@ function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
if ( $subrow['name'] != '' ) $name.= $subrow['name'];
else $name.= str_replace( '_', ' ', $file );
$name.= ' [ '.$subrow['file'].' ]';
- $vtp->setVar( $handle, 'picture.title', $name );
- // source of the thumbnail picture
+ // source of the thumbnail picture
$src = $array_cat_directories[$subrow['cat_id']];
$src.= 'thumbnail/'.$conf['prefix_thumbnail'];
$src.= $file.'.'.$subrow['tn_ext'];
- $vtp->setVar( $handle, 'picture.thumb_src', $src );
- // link to the full size picture
+ // link to the full size picture
$url = './picture.php?cat='.$category_id;
$url.= '&image_id='.$row['image_id'];
- $vtp->setVar( $handle, 'picture.thumb_url', add_session_id( $url ) );
- // 3. for each picture, retrieving all comments
+
+ $template->assign_block_vars('picture',array(
+ 'TITLE_IMG'=>$name,
+ 'I_THUMB'=>$src,
+ 'U_THUMB'=>add_session_id( $url )
+ ));
+
+ // for each picture, retrieving all comments
$query = 'SELECT id,date,author,content';
- $query.= ' FROM '.PREFIX_TABLE.'comments';
+ $query.= ' FROM '.COMMENTS_TABLE;
$query.= ' WHERE image_id = '.$row['image_id'];
$query.= ' AND date > '.$maxtime;
$query.= " AND validated = 'true'";
@@ -113,13 +140,8 @@ function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
$handleresult = mysql_query( $query );
while ( $subrow = mysql_fetch_array( $handleresult ) )
{
- $vtp->addSession( $handle, 'comment' );
$author = $subrow['author'];
if ( $subrow['author'] == '' ) $author = $lang['guest'];
- $vtp->setVar( $handle, 'comment.author', $author );
- $displayed_date = format_date( $subrow['date'], 'unix', true );
- $vtp->setVar( $handle, 'comment.date', $displayed_date );
-
$content = nl2br( $subrow['content'] );
// replace _word_ by an underlined word
@@ -136,66 +158,14 @@ function display_pictures( $mysql_result, $maxtime, $forbidden_cat_ids )
$pattern = '/\/([^\s]*)\//';
$replacement = '<span style="font-style:italic;">\1</span>';
$content = preg_replace( $pattern, $replacement, $content );
-
- $vtp->setVar( $handle, 'comment.content', $content );
- $vtp->closeSession( $handle, 'comment' );
+ $template->assign_block_vars('picture.comment',array(
+ 'AUTHOR'=>$author,
+ 'DATE'=>format_date( $subrow['date'], 'unix', true ),
+ 'CONTENT'=>$content,
+ ));
}
- $vtp->closeSession( $handle, 'picture' );
}
-}
-//----------------------------------------------------- template initialization
-//
-// Start output of page
-//
-$title= $lang['title_comments'];
-include('include/page_header.php');
-
-$handle = $vtp->Open( './template/'.$user['template'].'/comments.vtp' );
-initialize_template();
-$tpl = array( 'title_comments','stats_last_days','search_return_main_page' );
-templatize_array( $tpl, 'lang', $handle );
-//--------------------------------------------------- number of days to display
-if ( isset( $_GET['last_days'] ) ) define( 'MAX_DAYS', $_GET['last_days'] );
-else define( 'MAX_DAYS', 0 );
-//----------------------------------------- non specific section initialization
-$array_cat_directories = array();
-$array_cat_names = array();
-$array_cat_site_id = array();
-//------------------------------------------------------- last comments display
-foreach ( $conf['last_days'] as $option ) {
- $vtp->addSession( $handle, 'last_day_option' );
- $vtp->setVar( $handle, 'last_day_option.option', $option );
- $url = './comments.php';
- $url.= '?last_days='.($option - 1);
- $vtp->setVar( $handle, 'last_day_option.link', add_session_id( $url ) );
- $style = '';
- if ( $option == MAX_DAYS + 1 ) $style = 'text-decoration:underline;';
- $vtp->setVar( $handle, 'last_day_option.style', $style );
- $vtp->closeSession( $handle, 'last_day_option' );
-}
-$vtp->setVar( $handle, 'back_url', add_session_id( './category.php' ) );
-// 1. retrieving picture ids which have comments recently added
-$date = date( 'Y-m-d', time() - ( MAX_DAYS*24*60*60 ) );
-list($year,$month,$day) = explode( '-', $date);
-$maxtime = mktime( 0,0,0,$month,$day,$year );
-$query = 'SELECT DISTINCT(ic.image_id) as image_id';
-$query.= ' FROM '.PREFIX_TABLE.'comments AS c';
-$query.= ', '.PREFIX_TABLE.'image_category AS ic';
-$query.= ' WHERE c.image_id = ic.image_id';
-$query.= ' AND date > '.$maxtime;
-$query.= " AND validated = 'true'";
-// we must not show pictures of a forbidden category
-if ( $user['forbidden_categories'] != '' )
-{
- $query.= ' AND category_id NOT IN ';
- $query.= '('.$user['forbidden_categories'].')';
-}
-$query.= ' ORDER BY ic.image_id DESC';
-$query.= ';';
-$result = mysql_query( $query );
-display_pictures( $result, $maxtime, $user['restrictions'] );
//----------------------------------------------------------- html code display
-$code = $vtp->Display( $handle, 0 );
-echo $code;
+$template->pparse('comments');
include('include/page_tail.php');
?> \ No newline at end of file