assign(
array(
'COA_PATH' => COA_PATH,
'ICON_COLOR' => $conf['comments_on_albums']['icon_color'],
'ICON_COLOR_OVER' => $conf['comments_on_albums']['icon_color_over'],
)
);
// +-----------------------------------------------------------------------+
// | main page |
// +-----------------------------------------------------------------------+
if (!isset($_GET['display_mode']))
{
// adds a button for switch page
$template->set_prefilter('comments', 'coa_add_button');
function coa_add_button($content, &$smarty)
{
$search = '
';
$replacement = '
{html_head}
{/html_head}
'.$search.'
-
' . l10n('Comments on albums') . '
';
return str_replace($search, $replacement, $content);
}
// +-----------------------------------------------------------------------+
// comments on albums page |
// +-----------------------------------------------------------------------+
}
else if ($_GET['display_mode'] == 'albums')
{
// reset some template vars
$template->clear_assign(array('comments', 'navbar', 'sort_by_options'));
// sort_by : database fields proposed for sorting comments list
$sort_by = array(
'date' => l10n('comment date'),
'category_id' => l10n('album')
);
$template->assign('sort_by_options', $sort_by);
// +-----------------------------------------------------------------------+
// | comments management |
// +-----------------------------------------------------------------------+
$comment_id = null;
$action = null;
$actions = array('delete_albums', 'validate_albums', 'edit_albums'); // different indexes to not interfer with the main process
foreach ($actions as $loop_action)
{
if (isset($_GET[$loop_action]))
{
$action = $loop_action;
check_input_parameter($action, $_GET, false, PATTERN_ID);
$comment_id = $_GET[$action];
break;
}
}
if (isset($action))
{
include_once(COA_PATH.'include/functions_comment.inc.php');
check_pwg_token();
$comment_author_id = get_comment_author_id_albums($comment_id);
$true_action = str_replace('_albums', null, $action); // but we must check true action names
if (can_manage_comment($true_action, $comment_author_id))
{
$perform_redirect = false;
if ('delete_albums' == $action)
{
delete_user_comment_albums($comment_id);
$perform_redirect = true;
}
if ('validate_albums' == $action)
{
validate_user_comment_albums($comment_id);
$perform_redirect = true;
}
if ('edit_albums' == $action)
{
if (!empty($_POST['content']))
{
update_user_comment_albums(
array(
'comment_id' => $_GET['edit_albums'],
'category_id' => $_POST['image_id'],
'content' => $_POST['content']
),
$_POST['key']
);
//$perform_redirect = true;
$edit_comment = null;
}
else
{
$edit_comment = $_GET['edit_albums'];
}
}
if ($perform_redirect)
{
$redirect_url =
PHPWG_ROOT_PATH
.'comments.php'
.get_query_string_diff(array('delete_albums','validate_albums','edit_albums','pwg_token'));
redirect($redirect_url);
}
}
}
// +-----------------------------------------------------------------------+
// | navigation bar |
// +-----------------------------------------------------------------------+
if (isset($_GET['start']) and is_numeric($_GET['start']))
{
$start = $_GET['start'];
}
else
{
$start = 0;
}
$query = '
SELECT
COUNT(DISTINCT(com.id))
FROM '.COA_TABLE.' AS com
LEFT JOIN '.USERS_TABLE.' As u
ON u.'.$conf['user_fields']['id'].' = com.author_id
WHERE '.implode('
AND ', $page['where_clauses']).'
;';
list($counter) = pwg_db_fetch_row(pwg_query($query));
$url =
PHPWG_ROOT_PATH
.'comments.php'
.get_query_string_diff(array('start','delete_albums','validate_albums','edit_albums','pwg_token'));
$navbar = create_navigation_bar(
$url,
$counter,
$start,
$page['items_number'],
''
);
$template->assign('navbar', $navbar);
// +-----------------------------------------------------------------------+
// | last comments display |
// +-----------------------------------------------------------------------+
$comments = array();
$element_ids = array();
$category_ids = array();
$query = '
SELECT
com.id AS comment_id,
com.category_id,
com.author,
com.author_id,
'.$conf['user_fields']['username'].' AS username,
com.date,
com.content,
com.validated
FROM '.COA_TABLE.' AS com
LEFT JOIN '.USERS_TABLE.' As u
ON u.'.$conf['user_fields']['id'].' = com.author_id
WHERE '.implode('
AND ', $page['where_clauses']).'
GROUP BY
comment_id,
com.category_id,
com.author,
com.author_id,
com.date,
com.content,
com.validated
ORDER BY '.$page['sort_by'].' '.$page['sort_order'];
if ('all' != $page['items_number'])
{
$query.= '
LIMIT '.$page['items_number'].' OFFSET '.$start;
}
$query.= '
;';
$result = pwg_query($query);
while ($row = pwg_db_fetch_assoc($result))
{
array_push($comments, $row);
array_push($element_ids, $row['category_id']);
}
if (count($comments) > 0)
{
// retrieving category informations
$query = '
SELECT
cat.id,
cat.name,
cat.permalink,
cat.uppercats,
com.id as comment_id,
img.id AS image_id,
img.path,
img.tn_ext
FROM '.CATEGORIES_TABLE.' AS cat
LEFT JOIN '.COA_TABLE.' AS com
ON com.category_id = cat.id
LEFT JOIN '.USER_CACHE_CATEGORIES_TABLE.' AS ucc
ON ucc.cat_id = cat.id AND ucc.user_id = '.$user['id'].'
LEFT JOIN '.IMAGES_TABLE.' AS img
ON img.id = ucc.user_representative_picture_id
'.get_sql_condition_FandF(
array(
'forbidden_categories' => 'cat.id',
'visible_categories' => 'cat.id'
),
'WHERE'
).'
AND cat.id IN ('.implode(',', $element_ids).')
;';
$categories = hash_from_query($query, 'comment_id');
foreach ($comments as $comment)
{
// category url
$comment['cat_url'] = duplicate_index_url(
array(
'category' => array(
'id' => $categories[$comment['comment_id']]['id'],
'name' => $categories[$comment['comment_id']]['name'],
'permalink' => $categories[$comment['comment_id']]['permalink'],
),
array('start')
)
);
// category thumbnail
$comment['thumb'] = get_thumbnail_url(
array(
'id' => $categories[$comment['comment_id']]['image_id'],
'path' => $categories[$comment['comment_id']]['path'],
'tn_ext' => @$categories[$comment['comment_id']]['tn_ext'],
)
);
// comment content
$tpl_comment = array(
'ID' => $comment['comment_id'],
'U_PICTURE' => $comment['cat_url'],
'ALT' => trigger_event('render_category_name', $categories[$comment['comment_id']]['name']),
'TN_SRC' => $comment['thumb'],
'AUTHOR' => trigger_event('render_comment_author', $comment['author']),
'DATE' => format_date($comment['date'], true),
'CONTENT' => trigger_event('render_comment_content', $comment['content'], 'album'),
);
// rights
if (can_manage_comment('delete', $comment['author_id']))
{
$url =
get_root_url()
.'comments.php'
.get_query_string_diff(array('delete','validate','edit', 'pwg_token'));
$tpl_comment['U_DELETE'] = add_url_params(
$url,
array(
'delete_albums' => $comment['comment_id'],
'pwg_token' => get_pwg_token(),
)
);
}
if (can_manage_comment('edit', $comment['author_id']))
{
$url =
get_root_url()
.'comments.php'
.get_query_string_diff(array('edit', 'delete','validate', 'pwg_token'));
$tpl_comment['U_EDIT'] = add_url_params(
$url,
array(
'edit_albums' => $comment['comment_id'],
'pwg_token' => get_pwg_token(),
)
);
if (isset($edit_comment) and ($comment['comment_id'] == $edit_comment))
{
$key = get_ephemeral_key(2, $comment['category_id']);
$tpl_comment['IN_EDIT'] = true;
$tpl_comment['KEY'] = $key;
$tpl_comment['IMAGE_ID'] = $comment['category_id'];
$tpl_comment['CONTENT'] = $comment['content'];
}
}
if (can_manage_comment('validate', $comment['author_id']))
{
if ('true' != $comment['validated'])
{
$tpl_comment['U_VALIDATE'] = add_url_params(
$url,
array(
'validate_albums'=> $comment['comment_id'],
'pwg_token' => get_pwg_token(),
)
);
}
}
$template->append('comments', $tpl_comment);
}
}
// +-----------------------------------------------------------------------+
// | template |
// +-----------------------------------------------------------------------+
$template->set_filenames(array('comments'=> dirname(__FILE__).'/../template/comments_page.tpl'));
// add a line to display category name
$template->set_prefilter('comments', 'coa_change_comments_list');
function coa_change_comments_list($content, &$smarty) {
$search = '';
$replacement = $search.'
{$comment.ALT}';
return str_replace($search, $replacement, $content);
}
}
?>