Home / Hashcash for 4images - Killing Comment Spam

Comment spam on my blog is nil, since I use Elliot Back's wp-hashcash plugin. Essentially, this plugin forces a commenter's browser to perform a time-sensitive computation in order to post comments. If someone tries to post a comment using something other than a browser, their comment is refused. Since implementing this plugin, I have gotten exactly ZERO comment spams to my blog. Since Elliot’s plugin works so well for WordPress, I decided to port it to 4images. Since implementing this mod, I have received ZERO spam comments in my photo album. Plus, I am tracking how many attempts are being made to post spam to the photo gallery and it looks like I’m blocking 20-25 attempts per day. Here's how to do it:

Step one:

Save this file as /4images/md5.js in your 4images directory (or whatever is your installation directory)


Step two:

Save this file as /4images/admin/plugins/spamlog_view.php in your 4images directory (again, or whatever your plugins directory is)


Step three:

Edit your comment_form.html file in your templates to delete any reference to the onsubmit event. For example, supposed your current comment_form.html contains the following line:
<form name="commentform" action="{self}" method="post" onsubmit="postbutton.disabled=true;">

You should change that into the following:
<form name="commentform" action="{self}" method="post">

Step four:

Make the following changes to your /4images/details.php file. NOTE that the hashcash_add_hidden_tag() function on line 607 of the new file replaces text in your comment_form.html template file. You might need to modify this section of code (or your templates).
Original details.php
Modified details.php
  1|<?php
  2|/**************************************************************************
  3| *                                                                        *
  4| *    4images - A Web Based Image Gallery Management System               *
  5| *    ----------------------------------------------------------------    *
  6| *                                                                        *
  7| *             File: details.php                                          *
  8| *        Copyright: (C) 2002 Jan Sorgalla                                *
  9| *            Email: jan@4homepages.de                                    *
 10| *              Web: http://www.4homepages.de                             *
 11| *    Scriptversion: 1.7.1                                                *
 12| *                                                                        *
 13| *    Never released without support from: Nicky (http://www.nicky.net)   *
 14| *                                                                        *
 15| **************************************************************************
 16| *                                                                        *
 17| *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 18| *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 19| *    ---------------------------------------------------------------     *
 20| *    This script is NOT freeware! Please read the Copyright Notice       *
 21| *    (Licence.txt) for further information.                              *
 22| *                                                                        *
 23| *************************************************************************/
 24|
 25|$main_template = 'details';
 26|
 27|define('GET_CACHES', 1);
 28|define('ROOT_PATH', './');
 29|include(ROOT_PATH.'global.php');
 30|require(ROOT_PATH.'includes/sessions.php');
 31|$user_access = get_permission();
 32|include(ROOT_PATH.'includes/page_header.php');
 33|
 34|if (!$image_id) {
 35|  redirector($site_sess->url($url, "&"));
 36|  exit;
 37|}
 38|
 39|$additional_sql = "";
 40|if (!empty($additional_image_fields)) {
 41|  foreach ($additional_image_fields as $key => $val) {
 42|    $additional_sql .= ", i.".$key;
 43|  }
 44|}
 45|
 46|$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email")."
 47|        FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
 48|        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
 49|        WHERE i.image_id = $image_id AND c.cat_id = i.cat_id";
 50|$image_row = $site_db->query_firstrow($sql);
 51|$cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;
 52|$is_image_owner = ($image_row['user_id'] > USER_AWAITING && $user_info['user_id'] == $image_row['user_id']) ? 1 : 0;
 53|
 54|if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {
 55|  redirector($site_sess->url($url, "&"));
 56|  exit;
 57|}
 58|
 59|$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
 60|$site_template->register_vars("random_cat_image", $random_cat_image);
 61|unset($random_cat_image);
 62|
 63|//-----------------------------------------------------
 64|//--- Show Image --------------------------------------
 65|//-----------------------------------------------------
 66|$image_allow_comments = (check_permission("auth_readcomment", $cat_id)) ? $image_row['image_allow_comments'] : 0;
 67|$image_name = htmlspecialchars($image_row['image_name']);
 68|show_image($image_row, $mode, 0, 1);
 69|
 70|$in_mode = 0;
 71|
 72|$sql = "";
 73|if ($mode == "lightbox") {
 74|  if (!empty($user_info['lightbox_image_ids'])) {
 75|    $image_id_sql = str_replace(" ", ", ", trim($user_info['lightbox_image_ids']));
 76|    $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
 77|            FROM ".IMAGES_TABLE."
 78|            WHERE image_active = 1 AND image_id IN ($image_id_sql) AND (cat_id NOT IN (".get_auth_cat_sql("auth_viewimage", "NOTIN").") AND cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN")."))
 79|            ORDER BY ".$config['image_order']." ".$config['image_sort'];
 80|    $in_mode = 1;
 81|  }
 82|}
 83|elseif ($mode == "search") {
 84|  if (!isset($session_info['searchid']) || empty($session_info['searchid'])) {
 85|    $session_info['search_id'] = $site_sess->get_session_var("search_id");
 86|  }
 87|
 88|  if (!empty($session_info['search_id'])) {
 89|    $search_id = unserialize($session_info['search_id']);
 90|  }
 91|
 92|  $sql_where_query = "";
 93|
 94|  if (!empty($search_id['image_ids'])) {
 95|    $sql_where_query .= "AND image_id IN (".$search_id['image_ids'].") ";
 96|  }
 97|
 98|  if (!empty($search_id['user_ids'])) {
 99|    $sql_where_query .= "AND user_id IN (".$search_id['user_ids'].") ";
100|  }
101|
102|  if (!empty($search_id['search_new_images']) && $search_id['search_new_images'] == 1) {
103|    $new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
104|    $sql_where_query .= "AND image_date >= $new_cutoff ";
105|  }
106|
107|  if (!empty($search_id['search_cat']) && $search_id['search_cat'] != 0) {
108|    $cat_id_sql = 0;
109|    $sub_cat_ids = get_subcat_ids($search_id['search_cat'], $search_id['search_cat'], $cat_parent_cache);
110|    if (check_permission("auth_viewcat", $search_id['search_cat'])) {
111|      $cat_id_sql .= ", ".$search_id['search_cat'];
112|      if (!empty($sub_cat_ids[$search_id['search_cat']])) {
113|        foreach ($sub_cat_ids[$search_id['search_cat']] as $val) {
114|          if (check_permission("auth_viewcat", $val)) {
115|            $cat_id_sql .= ", ".$val;
116|          }
117|        }
118|      }
119|    }
120|  }
121|  else {
122|    $cat_id_sql = get_auth_cat_sql("auth_viewcat");
123|  }
124|
125|  if (!empty($sql_where_query)) {
126|    $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
127|            FROM ".IMAGES_TABLE."
128|            WHERE image_active = 1
129|            $sql_where_query
130|            AND cat_id IN ($cat_id_sql)
131|            ORDER BY ".$config['image_order']." ".$config['image_sort'];
132|    $in_mode = 1;
133|  }
134|}
135|if (!$in_mode || empty($sql)) {
136|  $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
137|          FROM ".IMAGES_TABLE."
138|          WHERE image_active = 1 AND cat_id = $cat_id
139|          ORDER BY ".$config['image_order']." ".$config['image_sort'];
140|}
141|$result = $site_db->query($sql);
142|
143|$image_id_cache = array();
144|$next_prev_cache = array();
145|$break = 0;
146|$prev_id = 0;
147|while($row = $site_db->fetch_array($result)) {
148|  $image_id_cache[] = $row['image_id'];
149|  $next_prev_cache[$row['image_id']] = $row;
150|  if ($break) {
151|    break;
152|  }
153|  if ($prev_id == $image_id) {
154|    $break = 1;
155|  }
156|  $prev_id = $row['image_id'];
157|}
158|$site_db->free_result();
159|
160|if (!function_exists("array_search")) {
161|  function array_search($needle, $haystack) {
162|    $match = false;
163|    foreach ($haystack as $key => $value) {
164|      if ($value == $needle) {
165|        $match = $key;
166|      }
167|    }
168|    return $match;
169|  }
170|}
171|
172|$act_key = array_search($image_id, $image_id_cache);
173|$next_image_id = (isset($image_id_cache[$act_key + 1])) ? $image_id_cache[$act_key + 1] : 0;
174|$prev_image_id = (isset($image_id_cache[$act_key - 1])) ? $image_id_cache[$act_key - 1] : 0;
175|unset($image_id_cache);
176|
177|// Get next and previous image
178|if (!empty($next_prev_cache[$next_image_id])) {
179|  $next_image_name = htmlspecialchars($next_prev_cache[$next_image_id]['image_name']);
180|  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
181|  if (!get_file_path($next_prev_cache[$next_image_id]['image_media_file'], "media", $next_prev_cache[$next_image_id]['cat_id'], 0, 0)) {
182|    $next_image_file = ICON_PATH."/404.gif";
183|  }
184|  else {
185|    $next_image_file = get_file_path($next_prev_cache[$next_image_id]['image_media_file'], "media", $next_prev_cache[$next_image_id]['cat_id'], 0, 1);
186|  }
187|  if (!get_file_path($next_prev_cache[$next_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$next_image_id]['cat_id'], 0, 0)) {
188|    $next_thumb_file = ICON_PATH."/".get_file_extension($next_prev_cache[$next_image_id]['image_media_file']).".gif";
189|  }
190|  else {
191|    $next_thumb_file = get_file_path($next_prev_cache[$next_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$next_image_id]['cat_id'], 0, 1);
192|  }
193|}
194|else {
195|  $next_image_name = REPLACE_EMPTY;
196|  $next_image_url = REPLACE_EMPTY;
197|  $next_image_file = REPLACE_EMPTY;
198|  $next_thumb_file = REPLACE_EMPTY;
199|}
200|
201|if (!empty($next_prev_cache[$prev_image_id])) {
202|  $prev_image_name = htmlspecialchars($next_prev_cache[$prev_image_id]['image_name']);
203|  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
204|  if (!get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
205|    $prev_image_file = ICON_PATH."/404.gif";
206|  }
207|  else {
208|    $prev_image_file = get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
209|  }
210|  if (!get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
211|    $prev_thumb_file = ICON_PATH."/".get_file_extension($next_prev_cache[$prev_image_id]['image_media_file']).".gif";
212|  }
213|  else {
214|    $prev_thumb_file = get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
215|  }
216|}
217|else {
218|  $prev_image_name = REPLACE_EMPTY;
219|  $prev_image_url = REPLACE_EMPTY;
220|  $prev_image_file = REPLACE_EMPTY;
221|  $prev_thumb_file = REPLACE_EMPTY;
222|}
223|
224|$site_template->register_vars(array(
225|  "next_image_id" => $next_image_id,
226|  "next_image_name" => $next_image_name,
227|  "next_image_url" => $next_image_url,
228|  "next_image_file" => $next_image_file,
229|  "next_thumb_file" => $next_thumb_file,
230|  "prev_image_id" => $prev_image_id,
231|  "prev_image_name" => $prev_image_name,
232|  "prev_image_url" => $prev_image_url,
233|  "prev_image_file" => $prev_image_file,
234|  "prev_thumb_file" => $prev_thumb_file
235|));
236|unset($next_prev_cache);
237|
238|//-----------------------------------------------------
239|//--- Save Comment ------------------------------------
240|//-----------------------------------------------------
241|$error = 0;
242|if ($action == "postcomment" && isset($HTTP_POST_VARS[URL_ID])) {
243|  $id = intval($HTTP_POST_VARS[URL_ID]);
244|  $sql = "SELECT cat_id, image_allow_comments
245|          FROM ".IMAGES_TABLE."
246|          WHERE image_id = $id";
247|  $row = $site_db->query_firstrow($sql);
248|
249|  if ($row['image_allow_comments'] == 0 || !check_permission("auth_postcomment", $row['cat_id']) || !$row) {
250|    $msg = $lang['comments_deactivated'];
251|  }
252|  else {
253|    $user_name = un_htmlspecialchars(trim($HTTP_POST_VARS['user_name']));
254|    $comment_headline = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_headline']));
255|    $comment_text = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_text']));
256|
257|    // Flood Check
258|    $sql = "SELECT comment_ip, comment_date
259|            FROM ".COMMENTS_TABLE."
260|            WHERE image_id = $id
261|            ORDER BY comment_date DESC
262|            LIMIT 1";
263|    $spam_row = $site_db->query_firstrow($sql);
264|    $spamtime = $spam_row['comment_date'] + 180;
265|
266|    if ($session_info['session_ip'] == $spam_row['comment_ip'] && time() <= $spamtime && $user_info['user_level'] != ADMIN)  {
267|      $msg .= (($msg != "") ? "<br />" : "").$lang['spamming'];
268|      $error = 1;
269|    }
   
   
   
270|
271|    $user_name_field = get_user_table_field("", "user_name");
272|    if (!empty($user_name_field)) {
273|      if ($site_db->not_empty("SELECT $user_name_field FROM ".USERS_TABLE." WHERE $user_name_field = '".strtolower($user_name)."' AND ".get_user_table_field("", "user_id")." <> '".$user_info['user_id']."'")) {
274|        $msg .= (($msg != "") ? "<br />" : "").$lang['username_exists'];
275|        $error = 1;
276|      }
277|    }
278|    if ($user_name == "")  {
279|      $msg .= (($msg != "") ? "<br />" : "").$lang['name_required'];
280|      $error = 1;
281|    }
282|    if ($comment_headline == "")  {
283|      $msg .= (($msg != "") ? "<br />" : "").$lang['headline_required'];
284|      $error = 1;
285|    }
286|    if ($comment_text == "")  {
287|      $msg .= (($msg != "") ? "<br />" : "").$lang['comment_required'];
288|      $error = 1;
289|    }
290|
291|    if (!$error)  {
292|      $sql = "INSERT INTO ".COMMENTS_TABLE."
293|              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
294|              VALUES
295|              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
296|      $site_db->query($sql);
297|      $commentid = $site_db->get_insert_id();
298|      update_comment_count($id, $user_info['user_id']);
299|    }
300|  }
301|  unset($row);
302|  unset($spam_row);
303|}
304|
305|//-----------------------------------------------------
306|//--- Show Comments -----------------------------------
307|//-----------------------------------------------------
308|if ($image_allow_comments == 1) {
309|  $sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").get_user_table_field(", u.", "user_showemail").get_user_table_field(", u.", "user_invisible").get_user_table_field(", u.", "user_joindate").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").get_user_table_field(", u.", "user_homepage").get_user_table_field(", u.", "user_icq")."
310|          FROM ".COMMENTS_TABLE." c
311|          LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
312|          WHERE c.image_id = $image_id
313|          ORDER BY c.comment_date ASC";
314|  $result = $site_db->query($sql);
315|
316|  $comment_row = array();
317|  while ($row = $site_db->fetch_array($result)) {
318|    $comment_row[] = $row;
319|  }
320|  $site_db->free_result($result);
321|  $num_comments = sizeof($comment_row);
322|
323|  if (!$num_comments) {
324|    $comments = "<tr><td class=\"commentrow1\" colspan=\"2\">".$lang['no_comments']."</td></tr>";
325|  }
326|  else {
327|    $comments = "";
328|    $bgcounter = 0;
329|    for ($i = 0; $i < $num_comments; $i++) {
330|      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
331|
332|      $comment_user_email = "";
333|      $comment_user_email_save = "";
334|      $comment_user_mailform_link = "";
335|      $comment_user_email_button = "";
336|      $comment_user_homepage_button = "";
337|      $comment_user_icq_button = "";
338|      $comment_user_profile_button = "";
339|      $comment_user_status_img = REPLACE_EMPTY;
340|      $comment_user_name = htmlspecialchars($comment_row[$i]['comment_user_name']);
341|      $comment_user_info = $lang['userlevel_guest'];
342|
343|      $comment_user_id = $comment_row[$i]['user_id'];
344|
345|      if (isset($comment_row[$i][$user_table_fields['user_name']]) && $comment_user_id != GUEST) {
346|        $comment_user_name = htmlspecialchars($comment_row[$i][$user_table_fields['user_name']]);
347|
348|        $comment_user_profile_link = !empty($url_show_profile) ? $site_sess->url(preg_replace("/{user_id}/", $comment_user_id, $url_show_profile)) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$comment_user_id);
349|        $comment_user_profile_button = "<a href=\"".$comment_user_profile_link."\"><img src=\"".get_gallery_image("profile.gif")."\" border=\"0\" alt=\"".$comment_user_name."\" /></a>";
350|
351|        $comment_user_status_img = ($comment_row[$i][$user_table_fields['user_lastaction']] >= (time() - 300) && ((isset($comment_row[$i][$user_table_fields['user_invisible']]) && $comment_row[$i][$user_table_fields['user_invisible']] == 0) || $user_info['user_level'] == ADMIN)) ? "<img src=\"".get_gallery_image("user_online.gif")."\" border=\"0\" alt=\"Online\" />" : "<img src=\"".get_gallery_image("user_offline.gif")."\" border=\"0\" alt=\"Offline\" />";
352|
353|        $comment_user_homepage = (isset($comment_row[$i][$user_table_fields['user_homepage']])) ? format_url($comment_row[$i][$user_table_fields['user_homepage']]) : "";
354|        if (!empty($comment_user_homepage)) {
355|          $comment_user_homepage_button = "<a href=\"".$comment_user_homepage."\" target=\"_blank\"><img src=\"".get_gallery_image("homepage.gif")."\" border=\"0\" alt=\"".$comment_user_homepage."\" /></a>";
356|        }
357|
358|        $comment_user_icq = (isset($comment_row[$i][$user_table_fields['user_icq']])) ? $comment_row[$i][$user_table_fields['user_icq']] : "";
359|        if (!empty($comment_user_icq)) {
360|          $comment_user_icq_button = "<a href=\"http://wwp.icq.com/scripts/search.dll?to=".$comment_user_icq."\" target=\"_blank\"><img src=\"http://web.icq.com/whitepages/online?icq=".$comment_user_icq."&img=5\" width=\"18\" height=\"18\" border=\"0\" alt=\"".$comment_user_icq."\" /></a>";
361|        }
362|
363|        if (!empty($comment_row[$i][$user_table_fields['user_email']]) && (!isset($comment_row[$i][$user_table_fields['user_showemail']]) || (isset($comment_row[$i][$user_table_fields['user_showemail']]) && $comment_row[$i][$user_table_fields['user_showemail']] == 1))) {
364|          $comment_user_email = $comment_row[$i][$user_table_fields['user_email']];
365|          $comment_user_email_save = str_replace("@", " at ", $comment_row[$i][$user_table_fields['user_email']]);
366|          if (!empty($url_mailform)) {
367|            $comment_user_mailform_link = $site_sess->url(preg_replace("/{user_id}/", $comment_user_id, $url_mailform));
368|          }
369|          else {
370|            $comment_user_mailform_link = $site_sess->url(ROOT_PATH."member.php?action=mailform&amp;".URL_USER_ID."=".$comment_user_id);
371|          }
372|          $comment_user_email_button = "<a href=\"".$comment_user_mailform_link."\"><img src=\"".get_gallery_image("email.gif")."\" border=\"0\" alt=\"".$comment_user_email_save."\" /></a>";
373|        }
374|
375|        if (!isset($comment_row[$i][$user_table_fields['user_level']]) || (isset($comment_row[$i][$user_table_fields['user_level']]) && $comment_row[$i][$user_table_fields['user_level']] == USER)) {
376|          $comment_user_info = $lang['userlevel_user'];
377|        }
378|        elseif ($comment_row[$i][$user_table_fields['user_level']] == ADMIN) {
379|          $comment_user_info = $lang['userlevel_admin'];
380|        }
381|
382|        $comment_user_info .= "<br />";
383|        $comment_user_info .= (isset($comment_row[$i][$user_table_fields['user_joindate']])) ? "<br />".$lang['join_date']." ".format_date($config['date_format'], $comment_row[$i][$user_table_fields['user_joindate']]) : "";
384|        $comment_user_info .= (isset($comment_row[$i][$user_table_fields['user_comments']])) ? "<br />".$lang['comments']." ".$comment_row[$i][$user_table_fields['user_comments']] : "";
385|      }
386|
387|      $comment_user_ip = ($user_info['user_level'] == ADMIN) ? $comment_row[$i]['comment_ip'] : "";
388|
389|      $admin_links = "";
390|      if ($user_info['user_level'] == ADMIN) {
391|        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=editcomment&amp;comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
392|        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&amp;comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
393|      }
394|      elseif ($is_image_owner) {
395|        $admin_links .= ($config['user_edit_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editcomment&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['edit']."</a>&nbsp;";
396|        $admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['delete']."</a>";
397|      }
398|
399|      $site_template->register_vars(array(
400|        "comment_id" => $comment_row[$i]['comment_id'],
401|        "comment_user_id" => $comment_user_id,
402|        "comment_user_status_img" => $comment_user_status_img,
403|        "comment_user_name" => $comment_user_name,
404|        "comment_user_info" => $comment_user_info,
405|        "comment_user_profile_button" => $comment_user_profile_button,
406|        "comment_user_email" => $comment_user_email,
407|        "comment_user_email_save" => $comment_user_email_save,
408|        "comment_user_mailform_link" => $comment_user_mailform_link,
409|        "comment_user_email_button" => $comment_user_email_button,
410|        "comment_user_homepage_button" => $comment_user_homepage_button,
411|        "comment_user_icq_button" => $comment_user_icq_button,
412|        "comment_user_ip" => $comment_user_ip,
413|        "comment_headline" => format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
414|        "comment_text" => format_text($comment_row[$i]['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),
415|        "comment_date" => format_date($config['date_format']." ".$config['time_format'], $comment_row[$i]['comment_date']),
416|        "row_bg_number" => $row_bg_number,
417|        "admin_links" => $admin_links
418|      ));
419|      $comments .= $site_template->parse_template("comment_bit");
420|    } // end while
421|  } //end else
422|  $site_template->register_vars("comments", $comments);
423|  unset($comments);
424|
425|  //-----------------------------------------------------
426|  //--- BBCode & Form -----------------------------------
427|  //-----------------------------------------------------
428|  $allow_posting = check_permission("auth_postcomment", $cat_id);
429|  $bbcode = "";
430|  if ($config['bb_comments'] == 1 && $allow_posting) {
431|    $site_template->register_vars(array(
432|      "lang_bbcode" => $lang['bbcode'],
433|      "lang_tag_prompt" => $lang['tag_prompt'],
434|      "lang_link_text_prompt" => $lang['link_text_prompt'],
435|      "lang_link_url_prompt" => $lang['link_url_prompt'],
436|      "lang_link_email_prompt" => $lang['link_email_prompt'],
437|      "lang_list_type_prompt" => $lang['list_type_prompt'],
438|      "lang_list_item_prompt" => $lang['list_item_prompt']
439|    ));
440|    $bbcode = $site_template->parse_template("bbcode");
441|  }
442|
443|  if (!$allow_posting) {
444|    $comment_form = "";
445|  }
446|  else {
447|    $user_name = (isset($HTTP_POST_VARS['user_name']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['user_name']))) : (($user_info['user_level'] != GUEST) ? htmlspecialchars($user_info['user_name']) : "");
448|    $comment_headline = (isset($HTTP_POST_VARS['comment_headline']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['comment_headline']))) : "";
449|    $comment_text = (isset($HTTP_POST_VARS['comment_text']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['comment_text']))) : "";
450|
451|    $site_template->register_vars(array(
452|      "bbcode" => $bbcode,
453|      "user_name" => $user_name,
454|      "comment_headline" => $comment_headline,
455|      "comment_text" => $comment_text,
456|      "lang_post_comment" => $lang['post_comment'],
457|      "lang_name" => $lang['name'],
458|      "lang_headline" => $lang['headline'],
459|      "lang_comment" => $lang['comment']
460|    ));
461|    $comment_form = $site_template->parse_template("comment_form");
   
   
   
   
   
   
462|  }
463|  $site_template->register_vars("comment_form", $comment_form);
464|  unset($comment_form);
465|} // end if allow_comments
466|
467|// Admin Links
468|$admin_links = "";
469|if ($user_info['user_level'] == ADMIN) {
470|  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
471|  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a>";
472|}
473|elseif ($is_image_owner) {
474|  $admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
475|  $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
476|}
477|$site_template->register_vars("admin_links", $admin_links);
478|
479|// Update Hits
480|if ($user_info['user_level'] != ADMIN) {
481|  $sql = "UPDATE ".IMAGES_TABLE."
482|          SET image_hits = image_hits + 1
483|          WHERE image_id = $image_id";
484|  $site_db->query($sql);
485|}
486|
487|//-----------------------------------------------------
488|//---Clickstream---------------------------------------
489|//-----------------------------------------------------
490|$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
491|
492|if ($mode == "lightbox" && $in_mode) {
493|  $page_url = "";
494|  if (preg_match("/".URL_PAGE."=([0-9]+)/", $url, $regs)) {
495|    if (!empty($regs[1]) && $regs[1] != 1) {
496|      $page_url = "?".URL_PAGE."=".$regs[1];
497|    }
498|  }
499|  $clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."lightbox.php".$page_url)."\" class=\"clickstream\">".$lang['lightbox']."</a>".$config['category_separator'];
500|}
501|elseif ($mode == "search" && $in_mode) {
502|  $page_url = "";
503|  if (preg_match("/".URL_PAGE."=([0-9]+)/", $url, $regs)) {
504|    if (!empty($regs[1]) && $regs[1] != 1) {
505|      $page_url = "&amp;".URL_PAGE."=".$regs[1];
506|    }
507|  }
508|  $clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."search.php?show_result=1".$page_url)."\" class=\"clickstream\">".$lang['search']."</a>".$config['category_separator'];
509|}
510|else {
511|  $clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
512|}
513|$clickstream .= $image_name."</span>";
514|
515|//-----------------------------------------------------
516|//--- Print Out ---------------------------------------
517|//-----------------------------------------------------
518|$site_template->register_vars(array(
519|  "msg" => $msg,
520|  "clickstream" => $clickstream,
521|  "lang_category" => $lang['category'],
522|  "lang_added_by" => $lang['added_by'],
523|  "lang_description" => $lang['description'],
524|  "lang_keywords" => $lang['keywords'],
525|  "lang_date" => $lang['date'],
526|  "lang_hits" => $lang['hits'],
527|  "lang_downloads" => $lang['downloads'],
528|  "lang_rating" => $lang['rating'],
529|  "lang_votes" => $lang['votes'],
530|  "lang_author" => $lang['author'],
531|  "lang_comment" => $lang['comment'],
532|  "lang_prev_image" => $lang['prev_image'],
533|  "lang_next_image" => $lang['next_image'],
534|  "lang_file_size" => $lang['file_size']
535|));
536|
537|$site_template->print_template($site_template->parse_template($main_template));
538|include(ROOT_PATH.'includes/page_footer.php');
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
539|?>
  1|<?php
  2|/**************************************************************************
  3| *                                                                        *
  4| *    4images - A Web Based Image Gallery Management System               *
  5| *    ----------------------------------------------------------------    *
  6| *                                                                        *
  7| *             File: details.php                                          *
  8| *        Copyright: (C) 2002 Jan Sorgalla                                *
  9| *            Email: jan@4homepages.de                                    *
 10| *              Web: http://www.4homepages.de                             *
 11| *    Scriptversion: 1.7.1                                                *
 12| *                                                                        *
 13| *    Never released without support from: Nicky (http://www.nicky.net)   *
 14| *                                                                        *
 15| **************************************************************************
 16| *                                                                        *
 17| *    Dieses Script ist KEINE Freeware. Bitte lesen Sie die Lizenz-       *
 18| *    bedingungen (Lizenz.txt) für weitere Informationen.                 *
 19| *    ---------------------------------------------------------------     *
 20| *    This script is NOT freeware! Please read the Copyright Notice       *
 21| *    (Licence.txt) for further information.                              *
 22| *                                                                        *
 23| *************************************************************************/
 24|
 25|$main_template = 'details';
 26|
 27|define('GET_CACHES', 1);
 28|define('ROOT_PATH', './');
 29|include(ROOT_PATH.'global.php');
 30|require(ROOT_PATH.'includes/sessions.php');
 31|$user_access = get_permission();
 32|include(ROOT_PATH.'includes/page_header.php');
 33|
 34|if (!$image_id) {
 35|  redirector($site_sess->url($url, "&"));
 36|  exit;
 37|}
 38|
 39|$additional_sql = "";
 40|if (!empty($additional_image_fields)) {
 41|  foreach ($additional_image_fields as $key => $val) {
 42|    $additional_sql .= ", i.".$key;
 43|  }
 44|}
 45|
 46|$sql = "SELECT i.image_id, i.cat_id, i.user_id, i.image_name, i.image_description, i.image_keywords, i.image_date, i.image_active, i.image_media_file, i.image_thumb_file, i.image_download_url, i.image_allow_comments, i.image_comments, i.image_downloads, i.image_votes, i.image_rating, i.image_hits".$additional_sql.", c.cat_name".get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email")."
 47|        FROM ".IMAGES_TABLE." i,  ".CATEGORIES_TABLE." c
 48|        LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = i.user_id)
 49|        WHERE i.image_id = $image_id AND c.cat_id = i.cat_id";
 50|$image_row = $site_db->query_firstrow($sql);
 51|$cat_id = (isset($image_row['cat_id'])) ? $image_row['cat_id'] : 0;
 52|$is_image_owner = ($image_row['user_id'] > USER_AWAITING && $user_info['user_id'] == $image_row['user_id']) ? 1 : 0;
 53|
 54|if (!check_permission("auth_viewcat", $cat_id) || !check_permission("auth_viewimage", $cat_id) || !$image_row) {
 55|  redirector($site_sess->url($url, "&"));
 56|  exit;
 57|}
 58|
 59|$random_cat_image = (defined("SHOW_RANDOM_IMAGE") && SHOW_RANDOM_IMAGE == 0) ? "" : get_random_image($cat_id);
 60|$site_template->register_vars("random_cat_image", $random_cat_image);
 61|unset($random_cat_image);
 62|
 63|//-----------------------------------------------------
 64|//--- Show Image --------------------------------------
 65|//-----------------------------------------------------
 66|$image_allow_comments = (check_permission("auth_readcomment", $cat_id)) ? $image_row['image_allow_comments'] : 0;
 67|$image_name = htmlspecialchars($image_row['image_name']);
 68|show_image($image_row, $mode, 0, 1);
 69|
 70|$in_mode = 0;
 71|
 72|$sql = "";
 73|if ($mode == "lightbox") {
 74|  if (!empty($user_info['lightbox_image_ids'])) {
 75|    $image_id_sql = str_replace(" ", ", ", trim($user_info['lightbox_image_ids']));
 76|    $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
 77|            FROM ".IMAGES_TABLE."
 78|            WHERE image_active = 1 AND image_id IN ($image_id_sql) AND (cat_id NOT IN (".get_auth_cat_sql("auth_viewimage", "NOTIN").") AND cat_id NOT IN (".get_auth_cat_sql("auth_viewcat", "NOTIN")."))
 79|            ORDER BY ".$config['image_order']." ".$config['image_sort'];
 80|    $in_mode = 1;
 81|  }
 82|}
 83|elseif ($mode == "search") {
 84|  if (!isset($session_info['searchid']) || empty($session_info['searchid'])) {
 85|    $session_info['search_id'] = $site_sess->get_session_var("search_id");
 86|  }
 87|
 88|  if (!empty($session_info['search_id'])) {
 89|    $search_id = unserialize($session_info['search_id']);
 90|  }
 91|
 92|  $sql_where_query = "";
 93|
 94|  if (!empty($search_id['image_ids'])) {
 95|    $sql_where_query .= "AND image_id IN (".$search_id['image_ids'].") ";
 96|  }
 97|
 98|  if (!empty($search_id['user_ids'])) {
 99|    $sql_where_query .= "AND user_id IN (".$search_id['user_ids'].") ";
100|  }
101|
102|  if (!empty($search_id['search_new_images']) && $search_id['search_new_images'] == 1) {
103|    $new_cutoff = time() - 60 * 60 * 24 * $config['new_cutoff'];
104|    $sql_where_query .= "AND image_date >= $new_cutoff ";
105|  }
106|
107|  if (!empty($search_id['search_cat']) && $search_id['search_cat'] != 0) {
108|    $cat_id_sql = 0;
109|    $sub_cat_ids = get_subcat_ids($search_id['search_cat'], $search_id['search_cat'], $cat_parent_cache);
110|    if (check_permission("auth_viewcat", $search_id['search_cat'])) {
111|      $cat_id_sql .= ", ".$search_id['search_cat'];
112|      if (!empty($sub_cat_ids[$search_id['search_cat']])) {
113|        foreach ($sub_cat_ids[$search_id['search_cat']] as $val) {
114|          if (check_permission("auth_viewcat", $val)) {
115|            $cat_id_sql .= ", ".$val;
116|          }
117|        }
118|      }
119|    }
120|  }
121|  else {
122|    $cat_id_sql = get_auth_cat_sql("auth_viewcat");
123|  }
124|
125|  if (!empty($sql_where_query)) {
126|    $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
127|            FROM ".IMAGES_TABLE."
128|            WHERE image_active = 1
129|            $sql_where_query
130|            AND cat_id IN ($cat_id_sql)
131|            ORDER BY ".$config['image_order']." ".$config['image_sort'];
132|    $in_mode = 1;
133|  }
134|}
135|if (!$in_mode || empty($sql)) {
136|  $sql = "SELECT image_id, cat_id, image_name, image_media_file, image_thumb_file
137|          FROM ".IMAGES_TABLE."
138|          WHERE image_active = 1 AND cat_id = $cat_id
139|          ORDER BY ".$config['image_order']." ".$config['image_sort'];
140|}
141|$result = $site_db->query($sql);
142|
143|$image_id_cache = array();
144|$next_prev_cache = array();
145|$break = 0;
146|$prev_id = 0;
147|while($row = $site_db->fetch_array($result)) {
148|  $image_id_cache[] = $row['image_id'];
149|  $next_prev_cache[$row['image_id']] = $row;
150|  if ($break) {
151|    break;
152|  }
153|  if ($prev_id == $image_id) {
154|    $break = 1;
155|  }
156|  $prev_id = $row['image_id'];
157|}
158|$site_db->free_result();
159|
160|if (!function_exists("array_search")) {
161|  function array_search($needle, $haystack) {
162|    $match = false;
163|    foreach ($haystack as $key => $value) {
164|      if ($value == $needle) {
165|        $match = $key;
166|      }
167|    }
168|    return $match;
169|  }
170|}
171|
172|$act_key = array_search($image_id, $image_id_cache);
173|$next_image_id = (isset($image_id_cache[$act_key + 1])) ? $image_id_cache[$act_key + 1] : 0;
174|$prev_image_id = (isset($image_id_cache[$act_key - 1])) ? $image_id_cache[$act_key - 1] : 0;
175|unset($image_id_cache);
176|
177|// Get next and previous image
178|if (!empty($next_prev_cache[$next_image_id])) {
179|  $next_image_name = htmlspecialchars($next_prev_cache[$next_image_id]['image_name']);
180|  $next_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$next_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
181|  if (!get_file_path($next_prev_cache[$next_image_id]['image_media_file'], "media", $next_prev_cache[$next_image_id]['cat_id'], 0, 0)) {
182|    $next_image_file = ICON_PATH."/404.gif";
183|  }
184|  else {
185|    $next_image_file = get_file_path($next_prev_cache[$next_image_id]['image_media_file'], "media", $next_prev_cache[$next_image_id]['cat_id'], 0, 1);
186|  }
187|  if (!get_file_path($next_prev_cache[$next_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$next_image_id]['cat_id'], 0, 0)) {
188|    $next_thumb_file = ICON_PATH."/".get_file_extension($next_prev_cache[$next_image_id]['image_media_file']).".gif";
189|  }
190|  else {
191|    $next_thumb_file = get_file_path($next_prev_cache[$next_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$next_image_id]['cat_id'], 0, 1);
192|  }
193|}
194|else {
195|  $next_image_name = REPLACE_EMPTY;
196|  $next_image_url = REPLACE_EMPTY;
197|  $next_image_file = REPLACE_EMPTY;
198|  $next_thumb_file = REPLACE_EMPTY;
199|}
200|
201|if (!empty($next_prev_cache[$prev_image_id])) {
202|  $prev_image_name = htmlspecialchars($next_prev_cache[$prev_image_id]['image_name']);
203|  $prev_image_url = $site_sess->url(ROOT_PATH."details.php?".URL_IMAGE_ID."=".$prev_image_id.((!empty($mode)) ? "&amp;mode=".$mode : ""));
204|  if (!get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
205|    $prev_image_file = ICON_PATH."/404.gif";
206|  }
207|  else {
208|    $prev_image_file = get_file_path($next_prev_cache[$prev_image_id]['image_media_file'], "media", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
209|  }
210|  if (!get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 0)) {
211|    $prev_thumb_file = ICON_PATH."/".get_file_extension($next_prev_cache[$prev_image_id]['image_media_file']).".gif";
212|  }
213|  else {
214|    $prev_thumb_file = get_file_path($next_prev_cache[$prev_image_id]['image_thumb_file'], "thumb", $next_prev_cache[$prev_image_id]['cat_id'], 0, 1);
215|  }
216|}
217|else {
218|  $prev_image_name = REPLACE_EMPTY;
219|  $prev_image_url = REPLACE_EMPTY;
220|  $prev_image_file = REPLACE_EMPTY;
221|  $prev_thumb_file = REPLACE_EMPTY;
222|}
223|
224|$site_template->register_vars(array(
225|  "next_image_id" => $next_image_id,
226|  "next_image_name" => $next_image_name,
227|  "next_image_url" => $next_image_url,
228|  "next_image_file" => $next_image_file,
229|  "next_thumb_file" => $next_thumb_file,
230|  "prev_image_id" => $prev_image_id,
231|  "prev_image_name" => $prev_image_name,
232|  "prev_image_url" => $prev_image_url,
233|  "prev_image_file" => $prev_image_file,
234|  "prev_thumb_file" => $prev_thumb_file
235|));
236|unset($next_prev_cache);
237|
238|//-----------------------------------------------------
239|//--- Save Comment ------------------------------------
240|//-----------------------------------------------------
241|$error = 0;
242|if ($action == "postcomment" && isset($HTTP_POST_VARS[URL_ID])) {
243|  $id = intval($HTTP_POST_VARS[URL_ID]);
244|  $sql = "SELECT cat_id, image_allow_comments
245|          FROM ".IMAGES_TABLE."
246|          WHERE image_id = $id";
247|  $row = $site_db->query_firstrow($sql);
248|
249|  if ($row['image_allow_comments'] == 0 || !check_permission("auth_postcomment", $row['cat_id']) || !$row) {
250|    $msg = $lang['comments_deactivated'];
251|  }
252|  else {
253|    $user_name = un_htmlspecialchars(trim($HTTP_POST_VARS['user_name']));
254|    $comment_headline = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_headline']));
255|    $comment_text = un_htmlspecialchars(trim($HTTP_POST_VARS['comment_text']));
256|
257|    // Flood Check
258|    $sql = "SELECT comment_ip, comment_date
259|            FROM ".COMMENTS_TABLE."
260|            WHERE image_id = $id
261|            ORDER BY comment_date DESC
262|            LIMIT 1";
263|    $spam_row = $site_db->query_firstrow($sql);
264|    $spamtime = $spam_row['comment_date'] + 180;
265|
266|    if ($session_info['session_ip'] == $spam_row['comment_ip'] && time() <= $spamtime && $user_info['user_level'] != ADMIN)  {
267|      $msg .= (($msg != "") ? "<br />" : "").$lang['spamming'];
268|      $error = 1;
269|    }
270|    
271|    // check for hashcash here
272|     hashcash_check_hidden_tag($comment_headline." ".$comment_text);
273|
274|    $user_name_field = get_user_table_field("", "user_name");
275|    if (!empty($user_name_field)) {
276|      if ($site_db->not_empty("SELECT $user_name_field FROM ".USERS_TABLE." WHERE $user_name_field = '".strtolower($user_name)."' AND ".get_user_table_field("", "user_id")." <> '".$user_info['user_id']."'")) {
277|        $msg .= (($msg != "") ? "<br />" : "").$lang['username_exists'];
278|        $error = 1;
279|      }
280|    }
281|    if ($user_name == "")  {
282|      $msg .= (($msg != "") ? "<br />" : "").$lang['name_required'];
283|      $error = 1;
284|    }
285|    if ($comment_headline == "")  {
286|      $msg .= (($msg != "") ? "<br />" : "").$lang['headline_required'];
287|      $error = 1;
288|    }
289|    if ($comment_text == "")  {
290|      $msg .= (($msg != "") ? "<br />" : "").$lang['comment_required'];
291|      $error = 1;
292|    }
293|
294|    if (!$error)  {
295|      $sql = "INSERT INTO ".COMMENTS_TABLE."
296|              (image_id, user_id, user_name, comment_headline, comment_text, comment_ip, comment_date)
297|              VALUES
298|              ($id, ".$user_info['user_id'].", '$user_name', '$comment_headline', '$comment_text', '".$session_info['session_ip']."', ".time().")";
299|      $site_db->query($sql);
300|      $commentid = $site_db->get_insert_id();
301|      update_comment_count($id, $user_info['user_id']);
302|    }
303|  }
304|  unset($row);
305|  unset($spam_row);
306|}
307|
308|//-----------------------------------------------------
309|//--- Show Comments -----------------------------------
310|//-----------------------------------------------------
311|if ($image_allow_comments == 1) {
312|  $sql = "SELECT c.comment_id, c.image_id, c.user_id, c.user_name AS comment_user_name, c.comment_headline, c.comment_text, c.comment_ip, c.comment_date".get_user_table_field(", u.", "user_level").get_user_table_field(", u.", "user_name").get_user_table_field(", u.", "user_email").get_user_table_field(", u.", "user_showemail").get_user_table_field(", u.", "user_invisible").get_user_table_field(", u.", "user_joindate").get_user_table_field(", u.", "user_lastaction").get_user_table_field(", u.", "user_comments").get_user_table_field(", u.", "user_homepage").get_user_table_field(", u.", "user_icq")."
313|          FROM ".COMMENTS_TABLE." c
314|          LEFT JOIN ".USERS_TABLE." u ON (".get_user_table_field("u.", "user_id")." = c.user_id)
315|          WHERE c.image_id = $image_id
316|          ORDER BY c.comment_date ASC";
317|  $result = $site_db->query($sql);
318|
319|  $comment_row = array();
320|  while ($row = $site_db->fetch_array($result)) {
321|    $comment_row[] = $row;
322|  }
323|  $site_db->free_result($result);
324|  $num_comments = sizeof($comment_row);
325|
326|  if (!$num_comments) {
327|    $comments = "<tr><td class=\"commentrow1\" colspan=\"2\">".$lang['no_comments']."</td></tr>";
328|  }
329|  else {
330|    $comments = "";
331|    $bgcounter = 0;
332|    for ($i = 0; $i < $num_comments; $i++) {
333|      $row_bg_number = ($bgcounter++ % 2 == 0) ? 1 : 2;
334|
335|      $comment_user_email = "";
336|      $comment_user_email_save = "";
337|      $comment_user_mailform_link = "";
338|      $comment_user_email_button = "";
339|      $comment_user_homepage_button = "";
340|      $comment_user_icq_button = "";
341|      $comment_user_profile_button = "";
342|      $comment_user_status_img = REPLACE_EMPTY;
343|      $comment_user_name = htmlspecialchars($comment_row[$i]['comment_user_name']);
344|      $comment_user_info = $lang['userlevel_guest'];
345|
346|      $comment_user_id = $comment_row[$i]['user_id'];
347|
348|      if (isset($comment_row[$i][$user_table_fields['user_name']]) && $comment_user_id != GUEST) {
349|        $comment_user_name = htmlspecialchars($comment_row[$i][$user_table_fields['user_name']]);
350|
351|        $comment_user_profile_link = !empty($url_show_profile) ? $site_sess->url(preg_replace("/{user_id}/", $comment_user_id, $url_show_profile)) : $site_sess->url(ROOT_PATH."member.php?action=showprofile&amp;".URL_USER_ID."=".$comment_user_id);
352|        $comment_user_profile_button = "<a href=\"".$comment_user_profile_link."\"><img src=\"".get_gallery_image("profile.gif")."\" border=\"0\" alt=\"".$comment_user_name."\" /></a>";
353|
354|        $comment_user_status_img = ($comment_row[$i][$user_table_fields['user_lastaction']] >= (time() - 300) && ((isset($comment_row[$i][$user_table_fields['user_invisible']]) && $comment_row[$i][$user_table_fields['user_invisible']] == 0) || $user_info['user_level'] == ADMIN)) ? "<img src=\"".get_gallery_image("user_online.gif")."\" border=\"0\" alt=\"Online\" />" : "<img src=\"".get_gallery_image("user_offline.gif")."\" border=\"0\" alt=\"Offline\" />";
355|
356|        $comment_user_homepage = (isset($comment_row[$i][$user_table_fields['user_homepage']])) ? format_url($comment_row[$i][$user_table_fields['user_homepage']]) : "";
357|        if (!empty($comment_user_homepage)) {
358|          $comment_user_homepage_button = "<a href=\"".$comment_user_homepage."\" target=\"_blank\"><img src=\"".get_gallery_image("homepage.gif")."\" border=\"0\" alt=\"".$comment_user_homepage."\" /></a>";
359|        }
360|
361|        $comment_user_icq = (isset($comment_row[$i][$user_table_fields['user_icq']])) ? $comment_row[$i][$user_table_fields['user_icq']] : "";
362|        if (!empty($comment_user_icq)) {
363|          $comment_user_icq_button = "<a href=\"http://wwp.icq.com/scripts/search.dll?to=".$comment_user_icq."\" target=\"_blank\"><img src=\"http://web.icq.com/whitepages/online?icq=".$comment_user_icq."&img=5\" width=\"18\" height=\"18\" border=\"0\" alt=\"".$comment_user_icq."\" /></a>";
364|        }
365|
366|        if (!empty($comment_row[$i][$user_table_fields['user_email']]) && (!isset($comment_row[$i][$user_table_fields['user_showemail']]) || (isset($comment_row[$i][$user_table_fields['user_showemail']]) && $comment_row[$i][$user_table_fields['user_showemail']] == 1))) {
367|          $comment_user_email = $comment_row[$i][$user_table_fields['user_email']];
368|          $comment_user_email_save = str_replace("@", " at ", $comment_row[$i][$user_table_fields['user_email']]);
369|          if (!empty($url_mailform)) {
370|            $comment_user_mailform_link = $site_sess->url(preg_replace("/{user_id}/", $comment_user_id, $url_mailform));
371|          }
372|          else {
373|            $comment_user_mailform_link = $site_sess->url(ROOT_PATH."member.php?action=mailform&amp;".URL_USER_ID."=".$comment_user_id);
374|          }
375|          $comment_user_email_button = "<a href=\"".$comment_user_mailform_link."\"><img src=\"".get_gallery_image("email.gif")."\" border=\"0\" alt=\"".$comment_user_email_save."\" /></a>";
376|        }
377|
378|        if (!isset($comment_row[$i][$user_table_fields['user_level']]) || (isset($comment_row[$i][$user_table_fields['user_level']]) && $comment_row[$i][$user_table_fields['user_level']] == USER)) {
379|          $comment_user_info = $lang['userlevel_user'];
380|        }
381|        elseif ($comment_row[$i][$user_table_fields['user_level']] == ADMIN) {
382|          $comment_user_info = $lang['userlevel_admin'];
383|        }
384|
385|        $comment_user_info .= "<br />";
386|        $comment_user_info .= (isset($comment_row[$i][$user_table_fields['user_joindate']])) ? "<br />".$lang['join_date']." ".format_date($config['date_format'], $comment_row[$i][$user_table_fields['user_joindate']]) : "";
387|        $comment_user_info .= (isset($comment_row[$i][$user_table_fields['user_comments']])) ? "<br />".$lang['comments']." ".$comment_row[$i][$user_table_fields['user_comments']] : "";
388|      }
389|
390|      $comment_user_ip = ($user_info['user_level'] == ADMIN) ? $comment_row[$i]['comment_ip'] : "";
391|
392|      $admin_links = "";
393|      if ($user_info['user_level'] == ADMIN) {
394|        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=editcomment&amp;comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
395|        $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("comments.php?action=removecomment&amp;comment_id=".$comment_row[$i]['comment_id']))."\" target=\"_blank\">".$lang['delete']."</a>";
396|      }
397|      elseif ($is_image_owner) {
398|        $admin_links .= ($config['user_edit_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editcomment&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['edit']."</a>&nbsp;";
399|        $admin_links .= ($config['user_delete_comments'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removecomment&amp;".URL_COMMENT_ID."=".$comment_row[$i]['comment_id'])."\">".$lang['delete']."</a>";
400|      }
401|
402|      $site_template->register_vars(array(
403|        "comment_id" => $comment_row[$i]['comment_id'],
404|        "comment_user_id" => $comment_user_id,
405|        "comment_user_status_img" => $comment_user_status_img,
406|        "comment_user_name" => $comment_user_name,
407|        "comment_user_info" => $comment_user_info,
408|        "comment_user_profile_button" => $comment_user_profile_button,
409|        "comment_user_email" => $comment_user_email,
410|        "comment_user_email_save" => $comment_user_email_save,
411|        "comment_user_mailform_link" => $comment_user_mailform_link,
412|        "comment_user_email_button" => $comment_user_email_button,
413|        "comment_user_homepage_button" => $comment_user_homepage_button,
414|        "comment_user_icq_button" => $comment_user_icq_button,
415|        "comment_user_ip" => $comment_user_ip,
416|        "comment_headline" => format_text($comment_row[$i]['comment_headline'], 0, $config['wordwrap_comments'], 0, 0),
417|        "comment_text" => format_text($comment_row[$i]['comment_text'], $config['html_comments'], $config['wordwrap_comments'], $config['bb_comments'], $config['bb_img_comments']),
418|        "comment_date" => format_date($config['date_format']." ".$config['time_format'], $comment_row[$i]['comment_date']),
419|        "row_bg_number" => $row_bg_number,
420|        "admin_links" => $admin_links
421|      ));
422|      $comments .= $site_template->parse_template("comment_bit");
423|    } // end while
424|  } //end else
425|  $site_template->register_vars("comments", $comments);
426|  unset($comments);
427|
428|  //-----------------------------------------------------
429|  //--- BBCode & Form -----------------------------------
430|  //-----------------------------------------------------
431|  $allow_posting = check_permission("auth_postcomment", $cat_id);
432|  $bbcode = "";
433|  if ($config['bb_comments'] == 1 && $allow_posting) {
434|    $site_template->register_vars(array(
435|      "lang_bbcode" => $lang['bbcode'],
436|      "lang_tag_prompt" => $lang['tag_prompt'],
437|      "lang_link_text_prompt" => $lang['link_text_prompt'],
438|      "lang_link_url_prompt" => $lang['link_url_prompt'],
439|      "lang_link_email_prompt" => $lang['link_email_prompt'],
440|      "lang_list_type_prompt" => $lang['list_type_prompt'],
441|      "lang_list_item_prompt" => $lang['list_item_prompt']
442|    ));
443|    $bbcode = $site_template->parse_template("bbcode");
444|  }
445|
446|  if (!$allow_posting) {
447|    $comment_form = "";
448|  }
449|  else {
450|    $user_name = (isset($HTTP_POST_VARS['user_name']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['user_name']))) : (($user_info['user_level'] != GUEST) ? htmlspecialchars($user_info['user_name']) : "");
451|    $comment_headline = (isset($HTTP_POST_VARS['comment_headline']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['comment_headline']))) : "";
452|    $comment_text = (isset($HTTP_POST_VARS['comment_text']) && $error) ? stripslashes(htmlspecialchars(trim($HTTP_POST_VARS['comment_text']))) : "";
453|
454|    $site_template->register_vars(array(
455|      "bbcode" => $bbcode,
456|      "user_name" => $user_name,
457|      "comment_headline" => $comment_headline,
458|      "comment_text" => $comment_text,
459|      "lang_post_comment" => $lang['post_comment'],
460|      "lang_name" => $lang['name'],
461|      "lang_headline" => $lang['headline'],
462|      "lang_comment" => $lang['comment']
463|    ));
464|    $comment_form = $site_template->parse_template("comment_form");
465|    
466|    // search $comment_form for stuff to insert hashcash to catch comment spam in here
467|    // parse the $comment_form to insert the hashcash stuff
468|    
469|    $comment_form=hashcash_add_hidden_tag($comment_form);
470|    
471|  }
472|  $site_template->register_vars("comment_form", $comment_form);
473|  unset($comment_form);
474|} // end if allow_comments
475|
476|// Admin Links
477|$admin_links = "";
478|if ($user_info['user_level'] == ADMIN) {
479|  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=editimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['edit']."</a>&nbsp;";
480|  $admin_links .= "<a href=\"".$site_sess->url(ROOT_PATH."admin/index.php?goto=".urlencode("images.php?action=removeimage&amp;image_id=".$image_id))."\" target=\"_blank\">".$lang['delete']."</a>";
481|}
482|elseif ($is_image_owner) {
483|  $admin_links .= ($config['user_edit_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=editimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['edit']."</a>&nbsp;";
484|  $admin_links .= ($config['user_delete_image'] != 1) ? "" : "<a href=\"".$site_sess->url(ROOT_PATH."member.php?action=removeimage&amp;".URL_IMAGE_ID."=".$image_id)."\">".$lang['delete']."</a>";
485|}
486|$site_template->register_vars("admin_links", $admin_links);
487|
488|// Update Hits
489|if ($user_info['user_level'] != ADMIN) {
490|  $sql = "UPDATE ".IMAGES_TABLE."
491|          SET image_hits = image_hits + 1
492|          WHERE image_id = $image_id";
493|  $site_db->query($sql);
494|}
495|
496|//-----------------------------------------------------
497|//---Clickstream---------------------------------------
498|//-----------------------------------------------------
499|$clickstream = "<span class=\"clickstream\"><a href=\"".$site_sess->url(ROOT_PATH."index.php")."\" class=\"clickstream\">".$lang['home']."</a>".$config['category_separator'];
500|
501|if ($mode == "lightbox" && $in_mode) {
502|  $page_url = "";
503|  if (preg_match("/".URL_PAGE."=([0-9]+)/", $url, $regs)) {
504|    if (!empty($regs[1]) && $regs[1] != 1) {
505|      $page_url = "?".URL_PAGE."=".$regs[1];
506|    }
507|  }
508|  $clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."lightbox.php".$page_url)."\" class=\"clickstream\">".$lang['lightbox']."</a>".$config['category_separator'];
509|}
510|elseif ($mode == "search" && $in_mode) {
511|  $page_url = "";
512|  if (preg_match("/".URL_PAGE."=([0-9]+)/", $url, $regs)) {
513|    if (!empty($regs[1]) && $regs[1] != 1) {
514|      $page_url = "&amp;".URL_PAGE."=".$regs[1];
515|    }
516|  }
517|  $clickstream .= "<a href=\"".$site_sess->url(ROOT_PATH."search.php?show_result=1".$page_url)."\" class=\"clickstream\">".$lang['search']."</a>".$config['category_separator'];
518|}
519|else {
520|  $clickstream .= get_category_path($cat_id, 1).$config['category_separator'];
521|}
522|$clickstream .= $image_name."</span>";
523|
524|//-----------------------------------------------------
525|//--- Print Out ---------------------------------------
526|//-----------------------------------------------------
527|$site_template->register_vars(array(
528|  "msg" => $msg,
529|  "clickstream" => $clickstream,
530|  "lang_category" => $lang['category'],
531|  "lang_added_by" => $lang['added_by'],
532|  "lang_description" => $lang['description'],
533|  "lang_keywords" => $lang['keywords'],
534|  "lang_date" => $lang['date'],
535|  "lang_hits" => $lang['hits'],
536|  "lang_downloads" => $lang['downloads'],
537|  "lang_rating" => $lang['rating'],
538|  "lang_votes" => $lang['votes'],
539|  "lang_author" => $lang['author'],
540|  "lang_comment" => $lang['comment'],
541|  "lang_prev_image" => $lang['prev_image'],
542|  "lang_next_image" => $lang['next_image'],
543|  "lang_file_size" => $lang['file_size']
544|));
545|
546|$site_template->print_template($site_template->parse_template($main_template));
547|include(ROOT_PATH.'includes/page_footer.php');
548|
549|
550|// create hash cash stuff by Toby
551|/*
552|Plugin Name: 4images Hashcash, based on a WordPress plugin
553|Plugin URI: http://dev.wp-plugins.org/wiki/wp-hashcash
554|Description: Comment submitters compute a special code using javascript before their comment is submitted. Very effective at blocking spambots and not noticable for commenters. XHTML 1.1 compliant.
555|Author: Toby Simmons, Matt Mullenweg, Elliott Back
556|Author URI: http://www.simmonsconsulting.com, http://photomatt.net/, http://elliottback.com
557|Version: 1.7
558|Hat tips:   C.S. - http://www.cimmanon.org/
559|        Gene Shepherd - http://www.imporium.org/
560|        John F. - http://www.stonegauge.com/
561|        Magenson - http://blog.magenson.de/
562|        Matt Mullenweg - http://photomatt.net/
563|        Matt Warden - http://www.mattwarden.com/
564|        Paul Andrew Johnston - http://pajhome.org.uk/crypt/md5/
565|*/ 
566|
567|define('HASHCASH_DEBUG', true);
568|define('HASHCASH_LOG_SIZE', 64000);
569|
570|/* Generate a random string of length l */
571|function hashcash_random_string($l) {
572|    srand((double) microtime() * 1000000);
573|    
574|    $alphabet = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
575|    $chars = preg_split('//', $alphabet, -1, PREG_SPLIT_NO_EMPTY);
576|    $len = count($chars) - 1;
577|    
578|    $str = '';
579|    while(strlen($str) < $l){
580|        $str .= $chars[rand(0, $len)];
581|    }
582|    
583|    return $str;
584|}
585|
586|/* Use sessions if session is started / supported */
587|function hashcash_special_code(){
588|    $key = $session_info['session_ip'];
589|    
590|    if(!$key){
591|        $key = $_SERVER['REMOTE_ADDR'];
592|    }
593|    
594|    return md5($key . ABSPATH . $_SERVER['HTTP_USER_AGENT'] . date("F j, Y, g a"));
595|}
596|
597|function hashcash_field_value(){
598|//  global $posts;
599|//  return $posts[0]->ID * strlen(ABSPATH);
600|    global $image_id;
601|    
602|    return $image_id * strlen(ABSPATH);
603|    
604|}
605|
606|/* This adds a random hidden field to the form */
607|function hashcash_add_hidden_tag($page) {
608|
609|    $field_id = hashcash_random_string(rand(6,18));
610|    $field_name = hashcash_random_string(rand(6,18));
611|    $form_action = hashcash_random_string(rand(6,18));
612|
613|    // Write in hidden field
614|    $page = str_replace('<input type="hidden" name="id"', '<input type="hidden" id="' . $field_id . '" name="' . $field_name . '" value="' . hashcash_field_value() . '" /> <input type="hidden" name="id"', $page);
615|
616|    // The form action
617|    $page = str_replace('<form', '<form onsubmit="' . $form_action . '(\'' . hashcash_special_code() . '\');" ', $page);
618|
619|    // The jscript
620|    $page = str_replace('<form', '<script src="' . './md5.js" type="text/javascript"></script><script type="text/javascript"> function ' . $form_action . '(in_str){ eElement = document.getElementById("' . $field_id . '"); if(!eElement){ return false; } else{ eElement.name = hex_md5(in_str); return true; } }</script><form', $page);
621|    
622|    return $page;
623|}
624|
625|function write_comment_log($comment){
626|    
627|    
628|    /* Information to write to log */
629|    $user = array();
630|    $user[] = "Tech date: ".date("Y-m-d H:i:s");
631|    $user[] = "Date: ".date("F j, Y, g:i a");
632|    $user[] = "Remote Address: ".$_SERVER['REMOTE_ADDR'];
633|    $user[] = "Remote DNS: ".gethostbyaddr($_SERVER['REMOTE_ADDR']);
634|    $user[] = "User agent: ".$_SERVER['HTTP_USER_AGENT'];
635|    $user[] = "Referrer: ".$_SERVER['HTTP_REFERER'];
636|    $user[] = "Author: ".$_POST['author'];
637|    $user[] = "E-mail: ".$_POST['email'];
638|    $user[] = "URL: ".$_POST['url'];
639|    $user[] = "Comment: ---------- ".$comment." ----------";
640|    $user[] = "Image ID: ".$_POST['id']." ========== ";
641|
642|    $lines = join($user, " ");
643|    
644|    $fp = fopen("spamlog.txt", "a");
645|    fwrite($fp, $lines);
646|    fclose($fp);
647|
648|    echo "<pre>".$lines."</pre>";
649|    
650|}
651|
652|function hashcash_check_hidden_tag($comment) {
653|    // Our special codes, fixed to check the previous hour
654|    $special = array();
655|    $special[] = md5($_SERVER['REMOTE_ADDR'] . ABSPATH . $_SERVER['HTTP_USER_AGENT'] . date("F j, Y, g a"));
656|    $special[] = md5($_SERVER['REMOTE_ADDR'] . ABSPATH . $_SERVER['HTTP_USER_AGENT'] . date("F j, Y, g a", time()-(60*60)));
657|    $special[] = md5($session_info['session_ip'] . ABSPATH . $_SERVER['HTTP_USER_AGENT'] . date("F j, Y, g a"));
658|    $special[] = md5($session_info['session_ip'] . ABSPATH . $_SERVER['HTTP_USER_AGENT'] . date("F j, Y, g a", time()-(60*60)));
659|    
660|    foreach($special as $val){
661|        if($_POST[md5($val)] == ($_POST['id'] * strlen(ABSPATH) )){
662|            return $comment;
663|        }
664|    }   
665|    
666|    if( HASHCASH_DEBUG )
667|        write_comment_log($comment);
668|
669|    die();
670|}
671|
672|?>
Legend:
Added(133)
Deleted(0)
Changed(0)

Testing

You can test it by turning off javascript in your browser and trying to post a comment to your images gallery. Finally, when you go to your admin control panel, you can see a listing of all the comment spam that have been attempted.



home | spam | personal | software | photos

eof