[3609] | 1 | <?php |
---|
| 2 | |
---|
| 3 | if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!'); |
---|
[4539] | 4 | global $user, $conf; |
---|
[3609] | 5 | |
---|
| 6 | // +-----------------------------------------------------------------------+ |
---|
| 7 | // | comments management | |
---|
| 8 | // +-----------------------------------------------------------------------+ |
---|
| 9 | // comments deletion |
---|
| 10 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) and is_admin() and !is_adviser()) |
---|
| 11 | { |
---|
| 12 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 13 | $query = ' |
---|
| 14 | DELETE FROM ' . COMMENTS_TABLE . ' |
---|
| 15 | WHERE id=' . $_GET['delete'] . ' |
---|
| 16 | ;'; |
---|
| 17 | pwg_query($query); |
---|
| 18 | } |
---|
| 19 | |
---|
| 20 | // comments validation |
---|
| 21 | if (isset($_GET['validate']) and is_numeric($_GET['validate']) and is_admin() and !is_adviser()) |
---|
| 22 | { |
---|
| 23 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 24 | $query = ' |
---|
| 25 | UPDATE ' . COMMENTS_TABLE . ' |
---|
| 26 | SET validated = \'true\' |
---|
| 27 | , validation_date = NOW() |
---|
| 28 | WHERE id=' . $_GET['validate'] . ' |
---|
| 29 | ;'; |
---|
| 30 | pwg_query($query); |
---|
| 31 | } |
---|
| 32 | |
---|
| 33 | // +-----------------------------------------------------------------------+ |
---|
| 34 | // | last comments display | |
---|
| 35 | // +-----------------------------------------------------------------------+ |
---|
| 36 | $comments = array(); |
---|
| 37 | $element_ids = array(); |
---|
| 38 | $category_ids = array(); |
---|
| 39 | $max_width = 0; |
---|
| 40 | if (!is_admin()) |
---|
| 41 | { |
---|
| 42 | $clauses[] = 'validated="true"'; |
---|
| 43 | } |
---|
| 44 | $clauses[] = get_sql_condition_FandF ( |
---|
| 45 | array ('forbidden_categories' => 'category_id', |
---|
| 46 | 'visible_categories' => 'category_id', |
---|
| 47 | 'visible_images' => 'ic.image_id'), '', true); |
---|
| 48 | |
---|
| 49 | $query = 'SELECT com.id AS comment_id |
---|
| 50 | , com.image_id |
---|
| 51 | , ic.category_id |
---|
| 52 | , com.author |
---|
| 53 | , com.date |
---|
| 54 | , com.content |
---|
| 55 | , com.id AS comment_id |
---|
| 56 | , com.validated |
---|
| 57 | FROM ' . IMAGE_CATEGORY_TABLE . ' AS ic |
---|
| 58 | INNER JOIN ' . COMMENTS_TABLE . ' AS com |
---|
| 59 | ON ic.image_id = com.image_id |
---|
| 60 | WHERE ' . implode(' AND ', $clauses) . ' |
---|
| 61 | GROUP BY comment_id |
---|
| 62 | ORDER BY date DESC |
---|
| 63 | LIMIT 0, ' . $datas[0] . ';'; |
---|
| 64 | |
---|
| 65 | $result = pwg_query($query); |
---|
| 66 | while ($row = mysql_fetch_assoc($result)) |
---|
| 67 | { |
---|
| 68 | array_push($comments, $row); |
---|
| 69 | array_push($element_ids, $row['image_id']); |
---|
| 70 | array_push($category_ids, $row['category_id']); |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if (count($comments) > 0) |
---|
| 74 | { |
---|
| 75 | $block['TITLE_URL'] = 'comments.php'; |
---|
| 76 | $block['comments'] = array(); |
---|
| 77 | |
---|
| 78 | // retrieving element informations |
---|
| 79 | $elements = array(); |
---|
| 80 | $query = ' |
---|
| 81 | SELECT id, name, file, path, tn_ext |
---|
| 82 | FROM '.IMAGES_TABLE.' |
---|
| 83 | WHERE id IN ('.implode(',', $element_ids).') |
---|
| 84 | ;'; |
---|
| 85 | $result = pwg_query($query); |
---|
| 86 | while ($row = mysql_fetch_assoc($result)) |
---|
| 87 | { |
---|
| 88 | $elements[$row['id']] = $row; |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | // retrieving category informations |
---|
| 92 | $query = ' |
---|
| 93 | SELECT id, name, permalink, uppercats |
---|
| 94 | FROM '.CATEGORIES_TABLE.' |
---|
| 95 | WHERE id IN ('.implode(',', $category_ids).') |
---|
| 96 | ;'; |
---|
| 97 | $categories = hash_from_query($query, 'id'); |
---|
| 98 | |
---|
| 99 | foreach ($comments as $comment) |
---|
| 100 | { |
---|
| 101 | if (!empty($elements[$comment['image_id']]['name'])) |
---|
| 102 | { |
---|
| 103 | $name=$elements[$comment['image_id']]['name']; |
---|
| 104 | } |
---|
| 105 | else |
---|
| 106 | { |
---|
| 107 | $name=get_name_from_file($elements[$comment['image_id']]['file']); |
---|
| 108 | } |
---|
| 109 | |
---|
| 110 | // source of the thumbnail picture |
---|
| 111 | $thumbnail_src = get_thumbnail_url( $elements[$comment['image_id']] ); |
---|
| 112 | |
---|
| 113 | // link to the full size picture |
---|
| 114 | $url = make_picture_url( |
---|
| 115 | array( |
---|
| 116 | 'category' => $categories[ $comment['category_id'] ], |
---|
| 117 | 'image_id' => $comment['image_id'], |
---|
| 118 | 'image_file' => $elements[$comment['image_id']]['file'], |
---|
| 119 | ) |
---|
| 120 | ); |
---|
| 121 | |
---|
| 122 | $author = $comment['author']; |
---|
| 123 | if (empty($comment['author'])) |
---|
| 124 | { |
---|
| 125 | $author = l10n('guest'); |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | $tpl_comment = |
---|
| 129 | array( |
---|
| 130 | 'U_PICTURE' => $url, |
---|
| 131 | 'TN_SRC' => $thumbnail_src, |
---|
| 132 | 'ALT' => $name, |
---|
| 133 | 'AUTHOR' => trigger_event('render_comment_author', $author), |
---|
| 134 | 'DATE' => format_date($comment['date'],'mysql_datetime',true), |
---|
| 135 | 'CONTENT' => trigger_event('render_comment_content',$comment['content']), |
---|
| 136 | 'WIDTH' => $datas[3], |
---|
| 137 | 'HEIGHT' => $datas[4], |
---|
| 138 | ); |
---|
| 139 | |
---|
| 140 | switch ($datas[2]) |
---|
| 141 | { |
---|
| 142 | case 1 : |
---|
| 143 | $tpl_comment['CLASS'] = 'one_comment'; |
---|
| 144 | break; |
---|
| 145 | case 2 : |
---|
| 146 | $tpl_comment['CLASS'] = 'two_comment'; |
---|
| 147 | break; |
---|
| 148 | case 3 : |
---|
| 149 | $tpl_comment['CLASS'] = 'three_comment'; |
---|
| 150 | break; |
---|
| 151 | } |
---|
| 152 | |
---|
| 153 | if ( is_admin() ) |
---|
| 154 | { |
---|
| 155 | $url = get_root_url().'index.php'.get_query_string_diff(array('delete','validate')); |
---|
| 156 | $tpl_comment['U_DELETE'] = add_url_params($url, |
---|
| 157 | array('delete'=>$comment['comment_id']) |
---|
| 158 | ); |
---|
| 159 | |
---|
| 160 | if ($comment['validated'] != 'true') |
---|
| 161 | { |
---|
| 162 | $tpl_comment['U_VALIDATE'] = add_url_params($url, |
---|
| 163 | array('validate'=>$comment['comment_id']) |
---|
| 164 | ); |
---|
| 165 | } |
---|
| 166 | } |
---|
[4539] | 167 | |
---|
| 168 | // Show comment editor link |
---|
| 169 | if (defined('CE_PATH') and ((!is_a_guest() and ($user[$conf['user_fields']['username']] == $author)) or is_admin())) |
---|
| 170 | { |
---|
| 171 | load_language('plugin.lang', CE_PATH); |
---|
| 172 | $tpl_comment['U_EDIT'] = add_url_params(get_root_url() . 'index.php', array( |
---|
| 173 | CE_ACTION => CE_ACTION_EDIT, |
---|
| 174 | CE_ID => $comment['comment_id'])); |
---|
| 175 | } |
---|
[3609] | 176 | array_push($block['comments'], $tpl_comment); |
---|
| 177 | } |
---|
| 178 | } |
---|
| 179 | else |
---|
| 180 | { |
---|
| 181 | return false; |
---|
| 182 | } |
---|
| 183 | |
---|
[3300] | 184 | ?> |
---|