/** * Fetches the Picture Comment HTML for a single picture * * @param array Information regarding the picture * @param array (return) Statistics regarding the messages shown * @param integer The current page pumber * @param integer The number of comments per page * @param integer A specific comment ID to focus on (causes pagenumber to be ignored) * @param boolean Whether to show ignored messages in their full * * @return string The HTML for the picture comments * */ function fetch_picturecommentbits($pictureinfo, &$messagestats, &$pagenumber, &$perpage, $commentid = 0, $showignored = false) { global $vbulletin, $vbphrase, $show; require_once(DIR . '/includes/class_bbcode.php'); require_once(DIR . '/includes/class_picturecomment.php'); if ($vbulletin->options['globalignore'] != '' AND !can_moderate(0, 'candeletepicturecomments') AND !can_moderate(0, 'canremovepicturecomments')) { require_once(DIR . '/includes/functions_bigthree.php'); $coventry = fetch_coventry('string'); } $messagestats = array(); $state = array('visible'); $state_or = array(); if (fetch_user_picture_message_perm('canmoderatemessages', $pictureinfo)) { $state[] = 'moderation'; } else if ($vbulletin->userinfo['userid']) { $state_or[] = "(picturecomment.postuserid = " . $vbulletin->userinfo['userid'] . " AND state = 'moderation')"; } if (can_moderate(0, 'canmoderatepicturecomments') OR ($vbulletin->userinfo['userid'] == $pictureinfo['userid'] AND $vbulletin->userinfo['permissions']['albumpermissions'] & $vbulletin->bf_ugp_albumpermissions['canmanagepiccomment'])) { $state[] = 'deleted'; $deljoinsql = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON (picturecomment.commentid = deletionlog.primaryid AND deletionlog.type = 'picturecomment')"; } else { $deljoinsql = ''; } $state_or[] = "picturecomment.state IN ('" . implode("','", $state) . "')"; $perpage = (!$perpage OR $perpage > $vbulletin->options['pc_maxperpage']) ? $vbulletin->options['pc_perpage'] : $perpage; if ($commentid AND $commentinfo = fetch_picturecommentinfo($pictureinfo['filedataid'], $pictureinfo['userid'], $commentid)) { $getpagenum = $vbulletin->db->query_first(" SELECT COUNT(*) AS comments FROM " . TABLE_PREFIX . "picturecomment AS picturecomment WHERE filedataid = $pictureinfo[filedataid] AND userid = $pictureinfo[userid] AND (" . implode(" OR ", $state_or) . ") AND dateline <= $commentinfo[dateline] " . ($coventry ? "AND picturecomment.postuserid NOT IN (" . $coventry . ")" : '' ) . " "); $pagenumber = ceil($getpagenum['comments'] / $perpage); } do { if (!$pagenumber) { $pagenumber = 1; } $start = ($pagenumber - 1) * $perpage; $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook('picture_comment_query')) ? eval($hook) : false; $messagebits = ''; $messages = $vbulletin->db->query_read(" SELECT SQL_CALC_FOUND_ROWS picturecomment.*, user.*, picturecomment.ipaddress AS messageipaddress " . ($deljoinsql ? ",deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason" : "") . " " . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, filedata_thumb, NOT ISNULL(customavatar.userid) AS hascustom" : "") . " $hook_query_fields FROM " . TABLE_PREFIX . "picturecomment AS picturecomment LEFT JOIN " . TABLE_PREFIX . "user AS user ON (picturecomment.postuserid = user.userid) " . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . " $deljoinsql $hook_query_joins WHERE picturecomment.filedataid = $pictureinfo[filedataid] AND picturecomment.userid = $pictureinfo[userid] AND (" . implode(" OR ", $state_or) . ") " . ($coventry ? "AND picturecomment.postuserid NOT IN (" . $coventry . ")" : '' ) . " $hook_query_where ORDER BY picturecomment.dateline LIMIT $start, $perpage "); list($messagestats['total']) = $vbulletin->db->query_first("SELECT FOUND_ROWS()", DBARRAY_NUM); if ($start >= $messagestats['total']) { $pagenumber = ceil($messagestats['total'] / $perpage); } } while ($start >= $messagestats['total'] AND $messagestats['total']); $messagestats['start'] = $start + 1; $messagestats['end'] = min($start + $perpage, $messagestats['total']); $bbcode = new vB_BbCodeParser($vbulletin, fetch_tag_list()); $factory = new vB_Picture_CommentFactory($vbulletin, $bbcode, $pictureinfo); $messagebits = ''; $firstrecord = array(); $read_ids = array(); if ($vbulletin->userinfo['userid'] AND !$showignored) { $ignorelist = preg_split('/( )+/', trim($vbulletin->userinfo['ignorelist']), -1, PREG_SPLIT_NO_EMPTY); } else { $ignorelist = array(); } while ($message = $vbulletin->db->fetch_array($messages)) { if (!$firstrecord) { $firstrecord = $message; } if ($ignorelist AND in_array($message['postuserid'], $ignorelist)) { $message['ignored'] = true; } if (!$showignored AND in_coventry($message['postuserid'])) { $message['ignored'] = true; } $response_handler =& $factory->create($message); $response_handler->cachable = false; $messagebits .= $response_handler->construct(); if (!$message['messageread'] AND $message['state'] == 'visible' AND $pictureinfo['userid'] == $vbulletin->userinfo['userid']) { $read_ids[] = $message['commentid']; } $messagestats['lastcomment'] = $message['dateline']; } if ($pictureinfo['userid'] == $vbulletin->userinfo['userid']) { $readpcs = 0; if (!empty($read_ids)) { $readpcs = sizeof($read_ids); $vbulletin->db->query_write("UPDATE " . TABLE_PREFIX . "picturecomment SET messageread = 1 WHERE commentid IN (" . implode(',', $read_ids) . ")"); } if ($vbulletin->userinfo['pcunreadcount'] - $readpcs > 0 AND $vbulletin->options['globalignore'] != '') { build_picture_comment_counters($vbulletin->userinfo['userid']); } else if ($readpcs) { $vbulletin->db->query_write(" UPDATE " . TABLE_PREFIX . "user SET pcunreadcount = IF(pcunreadcount >= $readpcs, pcunreadcount - $readpcs, 0) WHERE userid = " . $vbulletin->userinfo['userid'] ); } } $messagestats['perpage'] = $perpage; $show['delete'] = fetch_user_picture_message_perm('candeletemessages', $pictureinfo); $show['undelete'] = fetch_user_picture_message_perm('canundeletemessages', $pictureinfo); $show['approve'] = fetch_user_picture_message_perm('canmoderatemessages', $pictureinfo); $show['inlinemod'] = ($show['delete'] OR $show['undelete'] OR $show['approve']); return $messagebits; }
} else { if ($vbulletin->userinfo['userid']) { $state_or[] = "(picturecomment.postuserid = " . $vbulletin->userinfo['userid'] . " AND state = 'moderation')"; } } if (can_moderate(0, 'canmoderatepicturecomments') or $vbulletin->userinfo['userid'] == $pictureinfo['userid'] and $vbulletin->userinfo['permissions']['albumpermissions'] & $vbulletin->bf_ugp_albumpermissions['canmanagepiccomment']) { $state[] = 'deleted'; $deljoinsql = "LEFT JOIN " . TABLE_PREFIX . "deletionlog AS deletionlog ON (picturecomment.commentid = deletionlog.primaryid AND deletionlog.type = 'picturecomment')"; } else { $deljoinsql = ''; } $state_or[] = "picturecomment.state IN ('" . implode("','", $state) . "')"; require_once DIR . '/includes/class_bbcode.php'; require_once DIR . '/includes/class_picturecomment.php'; $bbcode = new vB_BbCodeParser($vbulletin, fetch_tag_list()); $factory = new vB_Picture_CommentFactory($vbulletin, $bbcode, $pictureinfo); $hook_query_fields = $hook_query_joins = $hook_query_where = ''; ($hook = vBulletinHook::fetch_hook('picture_comment_post_ajax')) ? eval($hook) : false; $read_ids = array(); if ($commentid === true) { $commentid = $vbulletin->GPC['commentid']; } $messages = $db->query_read_slave("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tpicturecomment.*, user.*, picturecomment.ipaddress AS messageipaddress\n\t\t\t\t\t\t" . ($deljoinsql ? ",deletionlog.userid AS del_userid, deletionlog.username AS del_username, deletionlog.reason AS del_reason" : "") . "\n\t\t\t\t\t\t" . ($vbulletin->options['avatarenabled'] ? ",avatar.avatarpath, NOT ISNULL(customavatar.userid) AS hascustomavatar, customavatar.dateline AS avatardateline,customavatar.width AS avwidth,customavatar.height AS avheight, customavatar.width_thumb AS avwidth_thumb, customavatar.height_thumb AS avheight_thumb, customavatar.filedata_thumb" : "") . "\n\t\t\t\t\t\t{$hook_query_fields}\n\t\t\t\t\tFROM " . TABLE_PREFIX . "picturecomment AS picturecomment\n\t\t\t\t\tLEFT JOIN " . TABLE_PREFIX . "user AS user ON (picturecomment.postuserid = user.userid)\n\t\t\t\t\t" . ($vbulletin->options['avatarenabled'] ? "LEFT JOIN " . TABLE_PREFIX . "avatar AS avatar ON(avatar.avatarid = user.avatarid) LEFT JOIN " . TABLE_PREFIX . "customavatar AS customavatar ON(customavatar.userid = user.userid)" : "") . "\n\t\t\t\t\t{$deljoinsql}\n\t\t\t\t\t{$hook_query_joins}\n\t\t\t\t\tWHERE\n\t\t\t\t\t\tpicturecomment.filedataid = {$pictureinfo['filedataid']}\n\t\t\t\t\t\t\tAND\n\t\t\t\t\t\tpicturecomment.userid = {$pictureinfo['userid']}\n\t\t\t\t\t\t\tAND (" . implode(" OR ", $state_or) . ")\n\t\t\t\t\t\t\tAND " . (($lastviewed = $vbulletin->GPC['lastcomment']) ? "(picturecomment.dateline > {$lastviewed} OR picturecomment.commentid = {$commentid})" : "picturecomment.commentid = {$commentid}") . "\n\t\t\t\t\t\t{$hook_query_where}\n\t\t\t\t\tORDER BY picturecomment.dateline ASC\n\t\t\t\t"); while ($message = $db->fetch_array($messages)) { if ($message['state'] == 'visible' and !$message['messageread']) { $read_ids[] = $message['commentid']; } $response_handler =& $factory->create($message); // Shall we pre parse these? $response_handler->cachable = false; $xml->add_tag('message', process_replacement_vars($response_handler->construct()), array('commentid' => $message['commentid'], 'visible' => $message['state'] == 'visible' ? 1 : 0, 'bgclass' => $bgclass, 'quickedit' => 1));