function board_comments_moderation($pModerationInfo) { if ($pModerationInfo['type'] == 'comment_post') { $storeComment = new LibertyComment(NULL, $pModerationInfo['content_id']); $storeComment->load(); $comments_return_url = ''; $root_id = $storeComment->mInfo['root_id']; global $gContent; $board = new BitBoard(NULL, $root_id); $board->load(); $boardSync = $board->getPreference('board_sync_list_address'); $code = $storeComment->getPreference('board_confirm_code'); $approved = $board->getPreference('boards_mailing_list_password'); // Possible race. Did we beat the cron? if (empty($code)) { require_once BOARDS_PKG_PATH . 'admin/boardsync_inc.php'; // Try to pick up the message! board_sync_run(TRUE); } if (!empty($code) && !empty($boardSync) && !empty($approved)) { $boardSync = str_replace('@', '-request@', $boardSync); $code = 'confirm ' . $code; require_once KERNEL_PKG_PATH . 'BitMailer.php'; $mailer = new BitMailer(); if ($pModerationInfo['last_status'] == MODERATION_DELETE) { // Send a reject message $mailer->sendEmail($code, '', $boardSync, array('sender' => BitBoard::getBoardSyncInbox())); } else { // Send an accept message $mailer->sendEmail($code, '', $boardSync, array('sender' => BitBoard::getBoardSyncInbox(), 'x_headers' => array('Approved' => $approved))); } } } }
function feed_get_status($pListHash) { global $gBitDb; $whereSql = ''; $bindVars = array(); $statuses = array(); BitBase::prepGetList($pListHash); if (!empty($pListHash['user_id'])) { $whereSql = " WHERE lal.user_id = ? "; $bindVars[] = $pListHash['user_id']; } else { $whereSql = "WHERE 1=1 "; } $query = "SELECT lal.content_id, lal.user_id, lal.log_message, MAX(lal.last_modified) AS last_modified, lc.data, uu.login, uu.real_name, uu.email\n\t\t\t FROM liberty_action_log lal\n\t\t\t INNER JOIN liberty_content lc ON (lc.content_id=lal.content_id)\n\t\t\t INNER JOIN liberty_comments lcs ON (lcs.content_id = lc.content_id)\n\t\t\t INNER JOIN users_users uu ON (uu.user_id=lal.user_id)\n\t\t\t {$whereSql} AND lc.content_type_guid = 'feedstatus'\n\t\t\t GROUP BY lal.content_id, lal.user_id, uu.login, uu.real_name, uu.email, lal.log_message,lc.data\n\t\t\t ORDER BY MAX(lal.last_modified) DESC"; $res = $gBitDb->query($query, $bindVars, $pListHash['max_records']); $user = new BitUser($pListHash['user_id']); $user->load(); while ($status = $res->fetchRow()) { $avatarUrl = $user->getThumbnailUrl(); if (empty($avatarUrl)) { $avatarUrl = USERS_PKG_URI . "icons/silhouette.png"; } $status['feed_icon_url'] = $avatarUrl; $comment = new LibertyComment(NULL, $status['content_id']); $replies = $comment->getComments($status['content_id'], null, null, 'commentDate_asc'); $status['replies'] = $replies; foreach ($status['replies'] as &$reply) { $replyUser = new BitUser($reply['user_id']); $replyUser->load(); $replyAvatarUrl = $replyUser->getThumbnailUrl(); if (empty($replyAvatarUrl)) { $replyAvatarUrl = USERS_PKG_URI . "icons/silhouette.png"; } $reply['feed_icon_url'] = $replyAvatarUrl; } //after loading up the thumbnails in the prior array layout for ease, we break up the array to split long comment threads $MAX_SHOWN_REPLIES = 3; if (count($status['replies']) > $MAX_SHOWN_REPLIES) { $maxIteration = count($status['replies']) - $MAX_SHOWN_REPLIES; $i = 0; foreach ($status['replies'] as $excess) { if ($i < $maxIteration) { $status['replies_excess'][$excess['content_id']] = $excess; //use content_id to index for consistency with normal replies array unset($status['replies'][$excess['content_id']]); //remove from the normal replies array } else { break; } $i++; } } $statuses[] = $status; } return $statuses; }
function data_quote($pData, $pParams) { global $gLibertySystem, $gBitSmarty, $gBitSystem; if (empty($pParams['format_guid'])) { // default should be set - if not, we'll use tikiwiki - can't use PLUGIN_GUID_TIKIWIKI since it might not be defined. $pParams['format_guid'] = $gBitSystem->getConfig('default_format', 'tikiwiki'); } $rendererHash = array(); $rendererHash['content_id'] = 0; $rendererHash['format_guid'] = $pParams['format_guid']; $rendererHash['data'] = trim($pData); $formatGuid = $rendererHash['format_guid']; $ret = ""; if ($func = $gLibertySystem->getPluginFunction($formatGuid, 'load_function')) { $ret = $func($rendererHash, $this); } $quote = array(); $user = empty($pParams['user']) ? NULL : $pParams['user']; if (!empty($pParams['comment_id'])) { if ($gBitSystem->getActivePackage() == 'boards') { $c = new BitBoardPost(preg_replace('/[^0-9]/', '', $pParams['comment_id'])); } else { $c = new LibertyComment(preg_replace('/[^0-9]/', '', $pParams['comment_id'])); } if (empty($c->mInfo['title'])) { $c->mInfo['title'] = "#" . $c->mCommentId; } $quote['cite_url'] = $c->getDisplayUrl(); $quote['title'] = $c->mInfo['title']; $quote['created'] = $c->mInfo['created']; if (empty($user)) { $user = $c->mInfo['login']; } } $quote['login'] = $user; if (!empty($user)) { $u = new BitUser(); $u->load(TRUE, $user); $quote['user_url'] = $u->getDisplayUrl(); $quote['user_display_name'] = $u->mInfo['display_name']; } $quote['ret'] = $ret; $gBitSmarty->assign("quote", $quote); $repl = $gBitSmarty->fetch("bitpackage:liberty/plugins/data_quote.tpl"); return $repl; }
function modcomments_moderation_callback(&$pModeration) { global $gBitUser, $gBitSystem; if ($pModeration['type'] == 'comment_post') { $comment = new LibertyComment(NULL, $pModeration['content_id']); $comment->load(); if ($pModeration['status'] == MODERATION_APPROVED) { // change its status $comment->storeStatus(50); // delete the ticket $pModeration['status'] = MODERATION_DELETE; } else { if ($pModeration['status'] == MODERATION_REJECTED) { // change its status to soft delete $comment->storeStatus(-999); // delete the ticket $pModeration['status'] = MODERATION_DELETE; } } } return TRUE; }
/** * smarty_function_poll */ function smarty_function_poll($params, &$gBitSmarty) { global $polllib, $gBitSystem; extract($params); // Param = zone include_once POLLS_PKG_PATH . 'poll_lib.php'; include_once LIBERTY_PKG_PATH . 'LibertyComment.php'; if (empty($id)) { $id = $polllib->get_random_active_poll(); } if ($id) { $menu_info = $polllib->get_poll($id); $channels = $polllib->list_poll_options($id, 0, -1, 'option_id_asc', ''); if ($gBitSystem->getConfig('feature_poll_comments') == 'y') { $comments = new LibertyComment(); $comments_count = $comments->count_comments("poll:" . $menu_info["poll_id"]); } $gBitSmarty->assign('comments', $comments_count); $gBitSmarty->assign('ownurl', POLLS_PKG_URL . 'results.php?poll_id=' . $id); $gBitSmarty->assign('menu_info', $menu_info); $gBitSmarty->assign('channels', $channels["data"]); $gBitSmarty->display('bitpackage:polls/poll.tpl'); } }
/** * During initialisation, be sure to call our base constructors **/ function FeedStatus($pCommentId = NULL, $pContentId = NULL, $pInfo = NULL) { LibertyComment::LibertyComment($pCommentId, $pContentId, $pInfo); /* // Permission setup $this->mViewContentPerm = 'p_boards_read'; $this->mUpdateContentPerm = 'p_boards_post_update'; $this->mAdminContentPerm = 'p_boards_admin'; */ $this->mContentTypeGuid = FEEDSTATUS_CONTENT_TYPE_GUID; $this->registerContentType(FEEDSTATUS_CONTENT_TYPE_GUID, array('content_type_guid' => FEEDSTATUS_CONTENT_TYPE_GUID, 'content_name' => 'Feed Status', 'handler_class' => 'FeedStatus', 'handler_package' => 'feed', 'handler_file' => 'FeedStatus.php', 'maintainer_url' => 'http://www.bitweaver.org')); /* $this->mViewContentPerm = 'p_loc_view'; $this->mCreateContentPerm = 'p_loc_edit'; $this->mUpdateContentPerm = 'p_loc_edit'; $this->mAdminContentPerm = 'p_loc_admin'; */ }
function getList(&$pListHash) { global $gBitUser, $gBitSystem; $this->prepGetList($pListHash); $ret = NULL; $bindVars = array(); $selectSql = ''; $joinSql = ''; $whereSql = ''; array_push($bindVars, $this->mContentTypeGuid); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars); if (@$this->verifyId($pListHash['gmap_id']) || isset($pListHash['set_id'])) { $selectSql .= ", gmk.*, gms.`set_id`, gms.`style_id`, gms.`icon_id` "; $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "gmaps_marker_keychain` gmk ON (gm.`marker_id` = gmk.`marker_id`) "; $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "gmaps_marker_sets` gms ON (gmk.`set_id` = gms.`set_id`) "; } if (@$this->verifyId($pListHash['user_id'])) { array_push($bindVars, (int) $pListHash['user_id']); $whereSql .= ' AND lc.`user_id` = ? '; } // map user to login in case we used one instead of the other if (!empty($pListHash['user'])) { $pListHash['login'] = $pListHash['user']; } if (!empty($pListHash['login'])) { array_push($bindVars, $pListHash['login']); $whereSql .= ' AND uu.`login` = ? '; } if (isset($pListHash['set_id'])) { if (!is_array($pListHash['set_id']) && is_numeric($pListHash['set_id'])) { $sets = array($pListHash['set_id']); } elseif (is_array($pListHash['set_id'])) { $sets = $pListHash['set_id']; } $hasOne = FALSE; foreach ($sets as $value) { if (@$this->verifyId($value)) { if ($hasOne != TRUE) { $whereSql .= " AND ( gmk.`set_id` = ? "; $hasOne = TRUE; } else { $whereSql .= " OR gmk.`set_id` = ? "; } array_push($bindVars, (int) $value); } } if ($hasOne == TRUE) { $whereSql .= " ) "; } } if (@$this->verifyId($pListHash['gmap_id'])) { $selectSql .= ", gsk.* "; $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "gmaps_sets_keychain` gsk ON( gms.`set_id` = gsk.`set_id`) "; $whereSql .= " AND gsk.`set_type` = 'markers' AND gsk.`gmap_id` = ? "; array_push($bindVars, (int) $pListHash['gmap_id']); } if (isset($pListHash['favorites'])) { $selectSql .= ", ufm.* "; $joinSql .= " LEFT JOIN `" . BIT_DB_PREFIX . "users_favorites_map` ufm ON ( lc.`content_id`=ufm.`favorite_content_id` ) "; $whereSql .= " AND ufm.`favorite_content_id` IS NOT NULL "; } switch ($pListHash['sort_mode']) { case 'pos_desc': case 'pos_asc': $sortModePrefix = 'gmk.'; break; default: $sortModePrefix = 'lc.'; break; } $secondarySortMode = $pListHash['sort_mode'] != 'title_asc' ? ', lc.title ASC' : ''; $sort_mode = $sortModePrefix . $this->mDb->convertSortmode($pListHash['sort_mode']) . $secondarySortMode; $query = "SELECT lc.*, gm.*, \n\t\t\t\t uue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,\n\t\t\t\t uuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name,\n\t\t\t\t lf.storage_path AS `image_attachment_path` {$selectSql}\n\t\t\t\t FROM `" . BIT_DB_PREFIX . "gmaps_markers` gm \n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( gm.`content_id`=lc.`content_id` ) {$joinSql}\n\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "users_users` uue ON (uue.`user_id` = lc.`modifier_user_id`)\n\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON (uuc.`user_id` = lc.`user_id`)\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' )\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON( lf.`file_id` = la.`foreign_id` )\n\t\t\t\t WHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\t\t ORDER BY {$sort_mode}"; $query_cant = "\n\t\t\tSELECT COUNT( * )\n\t\t FROM `" . BIT_DB_PREFIX . "gmaps_markers` gm \n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON lc.`content_id` = gm.`content_id`\n\t\t\t\tINNER JOIN\t\t`" . BIT_DB_PREFIX . "users_users`\t\t\t uu ON uu.`user_id`\t\t\t = lc.`user_id`\n\t\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql} "; $result = $this->mDb->query($query, $bindVars, $pListHash['max_records'], $pListHash['offset']); $cant = $this->mDb->getOne($query_cant, $bindVars); $comment = new LibertyComment(); while ($res = $result->fetchrow()) { $res['display_url'] = $this->getDisplayUrl(NULL, $res); //need something like this - but need to get the prefs in the query $res['allow_comments'] = "n"; if ($this->getPreference('allow_comments', null, $res['content_id']) == 'y') { $res['allow_comments'] = "y"; $res['num_comments'] = $comment->getNumComments($res['content_id']); } $res['thumbnail_url'] = liberty_fetch_thumbnails(array("storage_path" => $res['image_attachment_path'])); /* not sure the best way to go about * cleaning this kind of crap out - * but since gmaps uses plenty of javascript * we can't have this business in here * if someone slipped it in somehow. * there shouldnt be line breaks in titles anyway, * but sometimes someone gets one in. -wjames5 */ $res['title'] = str_replace("\n", "", $res['title']); // to support html in labels $res['parsed_label_data'] = $this->parseData($res['label_data'], $res['format_guid']); $res['parsed_label_data'] = addslashes($res['parsed_label_data']); // this should escape line breaks for javascript $res['label_data'] = addslashes($res['label_data']); $res['label_data'] = str_replace("\n", "\\n", $res['label_data']); $ret[] = $res; } $pListHash["data"] = $ret; $pListHash["cant"] = $cant; LibertyContent::postGetList($pListHash); return $pListHash; }
$postComment['user_id'] = $gBitUser->mUserId; $postComment['title'] = $_REQUEST['comment_title']; if (!empty($_REQUEST['comment_name'])) { $postComment['anon_name'] = $_REQUEST['comment_name']; } $postComment['data'] = $_REQUEST['comment_data']; $postComment['format_guid'] = empty($_REQUEST['format_guid']) ? $gBitSystem->getConfig('default_format') : $_REQUEST['format_guid']; $postComment['parsed_data'] = LibertyComment::parseData($postComment); $postComment['created'] = time(); $postComment['last_modified'] = time(); $gBitSmarty->assign('post_comment_preview', TRUE); } // $post_comment_reply_id is the content_id which a post is replying to if (@BitBase::verifyId($_REQUEST['post_comment_reply_id'])) { $post_comment_reply_id = $_REQUEST['post_comment_reply_id']; $tmpComment = new LibertyComment(NULL, $post_comment_reply_id); if (!empty($_REQUEST['quote'])) { $postComment['data'] = $tmpComment->getQuoted(); } if (preg_match('/^' . tra('Re:') . '/', $tmpComment->mInfo['title'])) { $comment_prefix = ''; } else { $comment_prefix = tra('Re:') . " "; } //this always overrides the title with "Re: Parent Title" -- not sure what it really should do so I put in this conditional for previews if (!isset($_REQUEST['comment_title'])) { $postComment['title'] = $comment_prefix . $tmpComment->mInfo['title']; } $gBitSmarty->assign('post_comment_reply_id', $post_comment_reply_id); } if ($gContent->hasUserPermission('p_liberty_read_comments')) {
$moduleTitle = !empty($moduleParams['title']) ? $moduleParams['title'] : 'Recent Activity'; $userId = NULL; if (!empty($gQueryUser->mUserId)) { $userId = $gQueryUser->mUserId; } $listHash = array('user_id' => $userId, 'max_records' => $moduleParams['module_rows']); if (!empty($params['full'])) { $listHash['parse'] = TRUE; } $listHash['full'] = !empty($params['full']) ? $params['full'] : TRUE; $listHash['thumb_size'] = !empty($params['thumb_size']) ? $params['thumb_size'] : 'avatar'; $listHash['show_date'] = !empty($params['show_date']) ? $params['show_date'] : TRUE; if (!empty($params['root_content_type_guid'])) { $listHash['root_content_type_guid'] = $params['root_content_type_guid']; } $gBitSmarty->assign('moduleTitle', $moduleTitle); $lcom = new LibertyComment(); $modLastComments = $lcom->getList($listHash); $keys = array_keys($modLastComments); foreach ($keys as $k) { if ($modLastComments[$k]['parent_content_type_guid'] == 'feedstatus') { //if comment is a reply to a status, use the poster as the object, otherwise our thumbnail will be of the content we commented on (the other user,status) $user = new BitUser($modLastComments[$k]['user_id']); $user->load(); $modLastComments[$k]['object'] = $user; } else { //If a comment on a piece of content, use piece of content as object in question $modLastComments[$k]['object'] = LibertyBase::getLibertyObject($modLastComments[$k]['root_id'], $modLastComments[$k]['root_content_type_guid']); } } $gBitSmarty->assign('modLastComments', $modLastComments);
function getList(&$pListHash) { global $gBitUser, $gBitSystem; $this->prepGetList($pListHash); $selectSql = ''; $joinSql = ''; $whereSql = ''; $bindVars = array(); array_push($bindVars, $this->mContentTypeGuid); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pListHash); if (@$this->verifyId($pListHash['blog_id'])) { $selectSql .= ', bpm.crosspost_note'; array_push($bindVars, (int) $pListHash['blog_id']); $joinSql .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "blogs_posts_map` bpm ON ( bpm.`post_content_id` = bp.`content_id` ) "; $joinSql .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "blogs` b ON ( bpm.`blog_content_id`=b.`content_id` ) "; // " ON ( b.`content_id` = bpm.`blog_content_id` AND bp.`content_id` = bpm.`post_content_id` )"; $whereSql .= ' AND b.`blog_id` = ? '; $pListHash['sort_mode'] = 'publish_date_desc'; } if (@$this->verifyId($pListHash['post_id_gt'])) { array_push($bindVars, (int) $pListHash['post_id_gt']); $whereSql .= ' AND bp.`post_id` > ? '; } if (@$this->verifyId($pListHash['post_id_lt'])) { array_push($bindVars, (int) $pListHash['post_id_lt']); $whereSql .= ' AND bp.`post_id` < ? '; } if (@$this->verifyId($pListHash['user_id'])) { array_push($bindVars, (int) $pListHash['user_id']); $whereSql .= ' AND lc.`user_id` = ? '; } $this->getServicesSql('content_user_collection_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pListHash); // map user to login in case we used one instead of the other if (!empty($pListHash['user'])) { $pListHash['login'] = $pListHash['user']; } if (!empty($pListHash['login'])) { array_push($bindVars, $pListHash['login']); $whereSql .= ' AND uu.`login` = ? '; } if ($pListHash['find']) { $findesc = '%' . strtoupper($pListHash['find']) . '%'; $whereSql .= "AND (UPPER(lc.`data`) like ?) "; $bindVars[] = $findesc; } if (!empty($pListHash['date']) && is_numeric($pListHash['date'])) { $whereSql .= " AND lc.`created`<=? "; $bindVars[] = $pListHash['date']; } if (!empty($pListHash['date_start']) && is_numeric($pListHash['date_start'])) { $whereSql .= " AND lc.`created`>=? "; $bindVars[] = $pListHash['date_start']; } if (!empty($pListHash['date_end']) && is_numeric($pListHash['date_end'])) { $whereSql .= " AND lc.`created`<=? "; $bindVars[] = $pListHash['date_end']; } if (!empty($pListHash['content_perm_name'])) { $this->getContentListPermissionsSql($pListHash['content_perm_name'], $selectSql, $joinSql, $whereSql, $bindVars); } /* Check if the post wants to be viewed before / after respective dates * Note: expiring posts are determined by the expired date being greater than the publish date */ static::getDateRestrictions($pListHash, $whereSql, $bindVars); /* sort_mode is never empty due to call to prepGetList above * I think this will have to be perminently removed and default * set before passing the list hash in if a different default is * desired from that in prepGetList. -wjames5 */ /* if( empty( $pListHash['sort_mode'] ) ) { $pListHash['sort_mode'] = 'publish_date_desc'; $sortModePrefix = 'bp'; //$pListHash['sort_mode'] = 'created_desc'; } else { */ $sortModePrefix = ''; if (!empty($pListHash['sort_mode']) && !strpos($pListHash['sort_mode'], '.')) { switch ($pListHash['sort_mode']) { case 'publish_date_asc': case 'publish_date_desc': case 'post_id_desc': case 'post_id_asc': $sortModePrefix = 'bp.'; break; case 'date_added_desc': $sortModePrefix = 'bpm.'; break; case 'hits_asc': case 'hits_desc': $sortModePrefix = 'lch.'; break; case 'sort_date_asc': case 'sort_date_desc': break; case 'real_name_asc': case 'real_name_desc': $sortModePrefix = 'uu.'; break; // these technicall are not correct, however, we do not double join on users_users, so we sort by creator real_name // these technicall are not correct, however, we do not double join on users_users, so we sort by creator real_name case 'creator_real_name_asc': case 'modifier_real_name_asc': $sortModePrefix = 'uu.'; $pListHash['sort_mode'] = 'real_name_asc'; break; case 'registration_date_desc': $sortModePrefix = 'uu.'; $pListHash['sort_mode'] = 'registration_date_desc'; break; case 'creator_real_name_desc': case 'modifier_real_name_desc': $sortModePrefix = 'uu.'; $pListHash['sort_mode'] = 'real_name_desc'; break; default: $sortModePrefix = 'lc.'; break; } } $secondarySortMode = $pListHash['sort_mode'] != 'last_modified_desc' ? ', last_modified DESC' : ''; $sort_mode = $sortModePrefix . $this->mDb->convertSortmode($pListHash['sort_mode']) . $secondarySortMode; $query = "\n\t\t\tSELECT\n\t\t\t\tbp.`post_id`, bp.`publish_date`, bp.`expire_date`, bp.`trackbacks_to`, bp.`trackbacks_from`,\n\t\t\t\tlc.*, lch.`hits`, lcds.`data` AS `summary`, COALESCE( bp.`publish_date`, lc.`last_modified` ) AS sort_date,\n\t\t\t\tuu.`email`, uu.`login`, uu.`real_name`,\n\t\t\t\t\tlfa.`file_name` as `avatar_file_name`, lfa.`mime_type` AS `avatar_mime_type`, laa.`attachment_id` AS `avatar_attachment_id`,\n\t\t\t\t\tlfp.`file_name` AS `image_file_name`, lfp.`mime_type` AS `image_mime_type`, lap.`attachment_id` AS `image_attachment_id`\n\t\t\tFROM `" . BIT_DB_PREFIX . "blog_posts` bp\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON lc.`content_id` = bp.`content_id`\n\t\t\t\tINNER JOIN\t\t`" . BIT_DB_PREFIX . "users_users`\t\t\t uu ON uu.`user_id`\t\t\t = lc.`user_id`\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON lc.`content_id` = lch.`content_id`\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_data` lcds ON (lc.`content_id` = lcds.`content_id` AND lcds.`data_type`='summary')\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments`\tlaa ON (uu.`user_id` = laa.`user_id` AND laa.`attachment_id` = uu.`avatar_attachment_id`)\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files`\t lfa ON lfa.`file_id`\t\t = laa.`foreign_id`\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` lap ON lap.`content_id` = lc.`content_id` AND lap.`is_primary` = 'y'\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lfp ON lfp.`file_id` = lap.`foreign_id`\n\t\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\tORDER BY {$sort_mode}"; # Get count of total number of items available $query_cant = "\n\t\t\tSELECT COUNT( * )\n\t\t\tFROM `" . BIT_DB_PREFIX . "blog_posts` bp\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON lc.`content_id` = bp.`content_id`\n\t\t\t\tINNER JOIN\t\t`" . BIT_DB_PREFIX . "users_users`\t\t\t uu ON uu.`user_id`\t\t\t = lc.`user_id`\n\t\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql} "; $cant = $this->mDb->getOne($query_cant, $bindVars); $pListHash["cant"] = $cant; # Check for offset out of range if ($pListHash['offset'] < 0) { $pListHash['offset'] = 0; } elseif ($pListHash['offset'] > $pListHash["cant"]) { $lastPageNumber = ceil($pListHash["cant"] / $pListHash['max_records']) - 1; $pListHash['offset'] = $pListHash['max_records'] * $lastPageNumber; } $result = $this->mDb->query($query, $bindVars, $pListHash['max_records'], $pListHash['offset']); $ret = array(); $comment = new LibertyComment(); while ($res = $result->fetchRow()) { $res['no_fatal'] = TRUE; $accessError = $this->invokeServices('content_verify_access', $res, FALSE); if (empty($accessError)) { foreach (array('avatar', 'image') as $img) { $res[$img] = liberty_fetch_thumbnails(array('source_file' => liberty_mime_get_source_file(array('user_id' => $res['user_id'], 'package' => liberty_mime_get_storage_sub_dir_name(array('mime_type' => $res[$img . '_mime_type'], 'name' => $res[$img . '_file_name'])), 'file_name' => basename($res[$img . '_file_name']), 'sub_dir' => $res[$img . '_attachment_id'])))); } $res['thumbnail_url'] = BitBlogPost::getImageThumbnails($res); $res['num_comments'] = $comment->getNumComments($res['content_id']); $res['post_url'] = BitBlogPost::getDisplayUrlFromHash($res); $res['display_url'] = $res['post_url']; $res['display_link'] = $this->getDisplayLink($res['title'], $res); $res['blogs'] = $this->getBlogMemberships($res['content_id']); // trackbacks if ($res['trackbacks_from'] != null) { $res['trackbacks_from'] = unserialize($res['trackbacks_from']); } if (!is_array($res['trackbacks_from'])) { $res['trackbacks_from'] = array(); } $res['trackbacks_from_count'] = count(array_keys($res['trackbacks_from'])); if ($res['trackbacks_to'] != null) { $res['trackbacks_to'] = unserialize($res['trackbacks_to']); } if ($res['user_id'] == $gBitUser->mUserId) { $res['ownsblog'] = 'y'; } else { $res['ownsblog'] = 'n'; } $res['trackbacks_to_count'] = count($res['trackbacks_to']); $res['pages'] = $this->getNumberOfPages($res['data']); // deal with the parsing $parseHash['format_guid'] = $res['format_guid']; $parseHash['content_id'] = $res['content_id']; $parseHash['user_id'] = $res['user_id']; // support for ...split... and auto split if (!empty($pListHash['full_data'])) { $parseHash['data'] = $res['data']; $res['parsed'] = $this->parseData($parseHash); } else { $parseHash['data'] = $res['data']; $parseHash['no_cache'] = TRUE; $splitArray = $this->parseSplit($parseHash, $gBitSystem->getConfig('blog_posts_description_length', 500)); $res = array_merge($res, $splitArray); } if (!empty($this->mInfo['summary'])) { $res['summary'] = $parseHash['data'] = $this->mInfo['summary']; $parseHash['no_cache'] = TRUE; $res['parsed_summary'] = $this->parsedData($parseHash); } if (!empty($res['crosspost_note'])) { $res['crosspost_note_raw'] = $parseHash['data'] = $res['crosspost_note']; $parseHash['no_cache'] = TRUE; $res['crosspost_note'] = $this->parseData($parseHash); } $ret[] = $res; } elseif (!empty($accessError)) { if (!empty($accessError['access_control'])) { $res['post_url'] = BitBlogPost::getDisplayUrlFromHash($res['content_id'], $res); $res['display_url'] = $res['post_url']; /* this needs to be part of loop that gets all blogs post is in $res['blog_url'] = BitBlog::getDisplayUrlFromHash( $res['blog_content_id'] ); */ $res["parsed_data"] = $accessError['access_control']; $ret[] = $res; } } else { } } LibertyContent::postGetList($pListHash); return $ret; }
function migrate_phpbb_topic($pTopicId, &$pRootComment) { global $db; $sql = "SELECT bbp.*, bbpt.* FROM " . POSTS_TABLE . " bbp\n\t\t\t\tINNER JOIN " . POSTS_TEXT_TABLE . " bbpt ON(bbpt.post_id=bbp.post_id) \n\t\t\t\tINNER JOIN " . TOPICS_TABLE . " bbt ON(bbt.topic_id=bbp.topic_id) \n\t\t\tWHERE bbp.topic_id={$pTopicId} AND bbp.post_id != bbt.topic_first_post_id\n\t\t\tORDER BY bbp.post_time "; if (!($result = $db->sql_query($sql))) { message_die(GENERAL_ERROR, "Could not obtain topic/post information.", '', __LINE__, __FILE__, $sql); } while ($row = $db->sql_fetchrow($result)) { print "Migrating Post {$row['post_id']}<br/>\n"; $commentHash = array(); $commentHash['root_id'] = $pRootComment->getField('root_id'); $commentHash['parent_id'] = $pRootComment->getField('content_id'); $commentHash['anon_name'] = $row['post_username']; $commentHash['title'] = $row['post_subject']; $commentHash['edit'] = $row['post_text']; $commentHash['format_guid'] = 'bbcode'; $commentHash['created'] = $row['post_time']; $commentHash['last_modified'] = $row['post_edit_time']; $commentHash['user_id'] = $row['poster_id']; $commentHash['modifier_user_id'] = $row['poster_id']; $commentHash['ip'] = decode_ip($row['poster_ip']); $newComment = new LibertyComment(); if ($newComment->storeComment($commentHash)) { $postHash['migrate_post_id'] = $row['post_id']; $newPost = new BitBoardPost($newComment->mCommentId); $newPost->store($postHash); } else { vd($row); vd($commentHash); vd($newComment->mErrors); die; } } }
/** * This function gets a list of posts */ function getList(&$pListHash) { global $gBitUser, $gBitSystem; $this->prepGetList($pListHash); $joinSql = $selectSql = $whereSql = ''; $ret = array(); $contentId = $this->mCommentId; // $mid = 'ORDER BY `thread_forward_sequence` ASC'; $bindVars = array(); if (!empty($pListHash['content_id'])) { if (is_array($contentId)) { $mid2 = 'in (' . implode(',', array_fill(0, count($pListHash['content_id']), '?')) . ')'; $bindVars = $contentId; $selectSql = ', lcp.content_type_guid as parent_content_type_guid, lcp.title as parent_title '; $joinSql .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lcp ON (lcp.content_id = lcom.parent_id) "; } elseif (is_numeric($contentId)) { $whereSql .= " AND `thread_forward_sequence` LIKE '" . sprintf("%09d.", $contentId) . "%'"; } } if ($gBitSystem->isFeatureActive('boards_posts_anon_moderation') && !($gBitUser->hasPermission('p_boards_update') || $gBitUser->hasPermission('p_boards_post_update'))) { $whereSql .= " AND ((post.`is_approved` = 1) OR (lc.`user_id` >= 0))"; } $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, $this); if (!empty($pListHash['board_id'])) { $joinSql .= "INNER JOIN `" . BIT_DB_PREFIX . "boards` b ON (b.`content_id` = bm.`board_content_id`)"; $whereSql .= ' AND b.`board_id`=? '; array_push($bindVars, (int) $pListHash['board_id']); } if (BitBase::verifyId($pListHash['user_id'])) { $whereSql .= ' AND lc.`user_id`=? '; array_push($bindVars, $pListHash['user_id']); } if (!empty($whereSql)) { $whereSql = preg_replace('/^[\\s]*AND\\b/i', 'WHERE ', $whereSql); } $sql = "SELECT lcom.`comment_id`, lcom.`parent_id`, lcom.`root_id`, lcom.`thread_forward_sequence`, lcom.`thread_reverse_sequence`, lcom.`anon_name`, lc.*, uu.`email`, uu.`real_name`, uu.`login`, post.is_approved, post.is_warned, post.warned_message, uu.registration_date AS registration_date,\n\t\t\t\t\ttf_ava.`file_name` AS `avatar_file_name`, tf_ava.`mime_type` AS `avatar_mime_type`, tf_ava.`user_id` AS `avatar_user_id`, ta_ava.`attachment_id` AS `avatar_attachment_id`\n\t\t\t\t\t{$selectSql}\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` lcom\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "boards_map` bm ON (lcom.`root_id` = bm.`topic_content_id`)\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (lc.`user_id` = uu.`user_id`)\n\t\t\t\t\t {$joinSql}\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` ta_ava ON ( uu.`avatar_attachment_id`=ta_ava.`attachment_id` )\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` tf_ava ON ( tf_ava.`file_id`=ta_ava.`foreign_id` )\n\t\t\t\t\tLEFT JOIN `" . BIT_DB_PREFIX . "boards_posts` post ON (post.`comment_id` = lcom.`comment_id`)\n\t\t\t\t{$whereSql} ORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']); $ret = array(); if ($result = $this->mDb->query($sql, $bindVars, $pListHash['max_records'], $pListHash['offset'])) { while ($row = $result->FetchRow()) { if (empty($row['anon_name'])) { $row['anon_name'] = "Anonymous"; } if (!empty($row['avatar_file_name'])) { $row['user_avatar_url'] = liberty_fetch_thumbnail_url(array('source_file' => liberty_mime_get_source_file(array('user_id' => $row['avatar_user_id'], 'file_name' => $row['avatar_file_name'], 'mime_type' => $row['avatar_mime_type'], 'attachment_id' => $row['avatar_attachment_id'])), 'size' => 'avatar')); } else { $row['user_avatar_url'] = FALSE; } unset($row['avatar_file_name']); if (!empty($row['warned_message'])) { $row['warned_message'] = str_replace("\n", "<br />\n", $row['warned_message']); } $row['data'] = trim($row['data']); $row['user_url'] = BitUser::getDisplayUrlFromHash($row); $row['parsed_data'] = $this->parseData($row); $row['level'] = substr_count($row['thread_forward_sequence'], '.') - 1; $row['topic_id'] = boards_get_topic_comment($row['thread_forward_sequence']); $row['display_url'] = static::getDisplayUrlFromHash($row); $c = new LibertyComment(); $c->mInfo = $row; $row['is_editable'] = $c->userCanEdit(); $ret[] = $row; //va($row); } } return $ret; }
} // Remove a topic } elseif (isset($_REQUEST['remove'])) { // Check permissions to edit this topic if the root object is the board check its perms, otherwise check general comment admin perms if (!($gContent->mInfo['root_id'] == $gContent->mInfo['board_content_id'] && $board->hasAdminPermission() || $gBitUser->hasPermission('p_liberty_admin_comments'))) { $gBitSystem->fatalError(tra('You do not have permission to delete this topic.')); } if (!empty($_REQUEST['cancel'])) { // user cancelled - just continue on, doing nothing } elseif (empty($_REQUEST['confirm'])) { $formHash['remove'] = TRUE; $formHash['t'] = $_REQUEST['t']; $gBitSystem->confirmDialog($formHash, array('warning' => tra('Are you sure you want to delete this topic?') . ' ' . $gContent->getTitle(), 'error' => tra('This cannot be undone!'))); } else { // @TODO Topic should extend LibertyComment - but until that day we load it up a second time $topicAsComment = new LibertyComment($_REQUEST['t']); if (!$topicAsComment->expunge()) { $gBitSmarty->assignByRef('errors', $topicAsComment->mErrors); } // send us back to the baord - http_referer won't work with confirm process bit_redirect(BOARDS_PKG_URL . 'index.php?b=' . $gContent->mInfo['board_id']); } // User pref options on a topic - not really editing but this simplifies topic related processes putting it here } elseif (isset($_REQUEST['new']) || isset($_REQUEST['notify'])) { // Check permissions to view this topic $gContent->verifyViewPermission(); if (isset($_REQUEST['new']) && is_numeric($_REQUEST['new'])) { $rslt = $gContent->readTopicSet($_REQUEST['new']); } elseif (isset($_REQUEST['notify']) && is_numeric($_REQUEST['notify'])) { $rslt = $gContent->notify($_REQUEST['notify']); }
/** * This function moves a topic to a new messageboard */ function moveTo($board_id) { // start transaction $this->StartTrans(); // create a new comment letting people know it has beem moved $lcom = new LibertyComment(); $lcom_hash['edit'] = "The comments from: {$this->mInfo['title']} ({$this->mRootId}) have been is_moved to {$board_id}"; $lcom_hash['title'] = $this->mInfo['title']; $lcom_hash['parent_id'] = $this->mInfo['th_root_id']; $lcom_hash['root_id'] = $this->mInfo['th_root_id']; $lcom_hash['created'] = $this->mInfo['flc_created']; $lcom_hash['last_modified'] = $this->mInfo['flc_last_modified']; $lcom->storeComment($lcom_hash); // map the move to the topic table $data = array(); $data['parent_id'] = $lcom->mContentId; $data['is_moved'] = $this->mRootId; $this->mDb->associateInsert(BIT_DB_PREFIX . "boards_topics", $data); // move the comment we want to move to the target board $query = "UPDATE `" . BIT_DB_PREFIX . "liberty_comments` SET `root_id` = ?, `parent_id` = ?\n\t\t\t\t WHERE `thread_forward_sequence` LIKE '" . sprintf("%09d.", $this->mRootId) . "%' AND `root_id`=`parent_id`"; $result = $this->mDb->query($query, array($board_id, $board_id)); $query = "UPDATE `" . BIT_DB_PREFIX . "liberty_comments` SET `root_id` = ?\n\t\t\t\t WHERE `thread_forward_sequence` LIKE '" . sprintf("%09d.", $this->mRootId) . "%'"; $result = $this->mDb->query($query, array($board_id)); // end transaction $this->CompleteTrans(); return TRUE; }
<?php /** * Copyright (c) 2004 bitweaver.org * Copyright (c) 2003 tikwiki.org * Copyright (c) 2002-2003, Luis Argerich, Garland Foster, Eduardo Polidor, et. al. * All Rights Reserved. See below for details and a complete list of authors. * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details * * @package wiki * @subpackage modules */ /** * Show last comments on wiki pages */ global $gQueryUserId, $moduleParams; /** * required setup */ if ($gBitUser->hasPermission('p_wiki_view_page')) { require_once LIBERTY_PKG_PATH . 'LibertyComment.php'; $cmt = new LibertyComment(); $listHash = array('max_records' => $moduleParams['module_rows'], 'user_id' => $gQueryUserId, 'content_type_guid' => BITPAGE_CONTENT_TYPE_GUID); $lastComments = $cmt->getList($listHash); $_template->tpl_vars['lastComments'] = new Smarty_variable($lastComments); $_template->tpl_vars['moretooltips'] = new Smarty_variable(isset($module_params["moretooltips"]) ? $module_params["moretooltips"] : 'n'); }
/** * This function generates a list of records from the liberty_content database for use in a list page * @param $pParamHash contains an array of conditions to sort by * @return array of articles * @access public **/ public function getList(&$pParamHash) { global $gBitSystem, $gBitUser, $gLibertySystem; if (empty($pParamHash['sort_mode'])) { // no idea what this is supposed to do //$pParamHash['sort_mode'] = $gBitSystem->isFeatureActive('articles_auto_approve') ? 'order_key_desc' : 'publish_date_desc'; $pParamHash['sort_mode'] = 'publish_date_desc'; } LibertyContent::prepGetList($pParamHash); $joinSql = ''; $selectSql = ''; $bindVars = array(); array_push($bindVars, $this->mContentTypeGuid); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash); $find = $pParamHash['find']; if (is_array($find)) { // you can use an array of articles $whereSql .= " AND lc.`title` IN( " . implode(',', array_fill(0, count($find), '?')) . " )"; $bindVars = array_merge($bindVars, $find); } elseif (is_string($find)) { // or a string $whereSql .= " AND UPPER( lc.`title` ) LIKE ? "; $bindVars[] = '%' . strtoupper($find) . '%'; } elseif (@$this->verifyId($pParamHash['user_id'])) { // or gate on a user $whereSql .= " AND lc.`user_id` = ? "; $bindVars[] = (int) $pParamHash['user_id']; } if (@$this->verifyId($pParamHash['status_id'])) { $whereSql .= " AND a.`status_id` = ? "; $bindVars[] = $pParamHash['status_id']; } if (@$this->verifyId($pParamHash['type_id'])) { $whereSql .= " AND a.`article_type_id` = ? "; $bindVars[] = (int) $pParamHash['type_id']; } // TODO: we need to check if the article wants to be viewed before / after respective dates // someone better at SQL please get this working without an additional db call - xing $now = $gBitSystem->getUTCTime(); if (!empty($pParamHash['show_future']) && !empty($pParamHash['show_expired']) && $gBitUser->hasPermission('p_articles_admin')) { // this will show all articles at once - future, current and expired } elseif (!empty($pParamHash['show_future']) && $gBitUser->hasPermission('p_articles_admin')) { // hide expired articles $whereSql .= " AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ) "; $bindVars[] = (int) $now; $bindVars[] = 'y'; } elseif (!empty($pParamHash['show_expired']) && $gBitUser->hasPermission('p_articles_admin')) { // hide future articles $whereSql .= " AND ( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) "; $bindVars[] = (int) $now; $bindVars[] = 'y'; } elseif (!empty($pParamHash['get_future'])) { // show only future // if we're trying to view these articles, we better have the perms to do so if (!$gBitUser->hasPermission('p_articles_admin')) { return array(); } $whereSql .= " AND a.`publish_date` > ?"; $bindVars[] = (int) $now; } elseif (!empty($pParamHash['get_expired'])) { // show only expired articles // if we're trying to view these articles, we better have the perms to do so if (!$gBitUser->hasPermission('p_articles_admin')) { return array(); } $whereSql .= " AND a.`expire_date` < ? "; $bindVars[] = (int) $now; } else { // hide future and expired articles - this is the default behaviour // we need all these AND and ORs to ensure that other conditions such as status_id are respected as well $whereSql .= " AND (( a.`publish_date` > a.`expire_date` ) OR (( a.`publish_date` < ? OR atype.`show_pre_publ` = ? ) AND ( a.`expire_date` > ? OR atype.`show_post_expire` = ? ))) "; $bindVars[] = (int) $now; $bindVars[] = 'y'; $bindVars[] = (int) $now; $bindVars[] = 'y'; } if (@$this->verifyId($pParamHash['topic_id'])) { $whereSql .= " AND a.`topic_id` = ? "; $bindVars[] = (int) $pParamHash['topic_id']; } elseif (!empty($pParamHash['topic'])) { $whereSql .= " AND UPPER( atopic.`topic_name` ) = ? "; $bindVars[] = strtoupper($pParamHash['topic']); } else { $whereSql .= " AND ( atopic.`active_topic` != 'n' OR atopic.`active_topic` IS NULL ) "; //$whereSql .= " AND atopic.`active_topic` != 'n' "; } // Oracle is very particular about naming multiple columns, so need to explicity name them ORA-00918: column ambiguously defined $query = "SELECT\n\t\t\t\ta.`article_id`, a.`description`, a.`author_name`, a.`publish_date`, a.`expire_date`, a.`rating`,\n\t\t\t\tatopic.`topic_id`, atopic.`topic_name`, atopic.`has_topic_image`, atopic.`active_topic`,\n\t\t\t\tastatus.`status_id`, astatus.`status_name`,\n\t\t\t\tlch.`hits`,\n\t\t\t\tatype.*, lc.*, la.`attachment_id` AS `primary_attachment_id`, lf.`file_name` AS `image_attachment_path` {$selectSql}\n\t\t\tFROM `" . BIT_DB_PREFIX . "articles` a\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( lc.`content_id` = a.`content_id` )\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "article_status` astatus ON( astatus.`status_id` = a.`status_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON( lc.`content_id` = lch.`content_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_topics` atopic ON( atopic.`topic_id` = a.`topic_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_types` atype ON( atype.`article_type_id` = a.`article_type_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON( lf.`file_id` = la.`foreign_id` )\n\t\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($pParamHash['sort_mode']); $query_cant = "SELECT COUNT( * )FROM `" . BIT_DB_PREFIX . "articles` a\n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON lc.`content_id` = a.`content_id`\n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_topics` atopic ON atopic.`topic_id` = a.`topic_id` {$joinSql}\n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "article_types` atype ON atype.`article_type_id` = a.`article_type_id`\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}"; $result = $this->mDb->query($query, $bindVars, $pParamHash['max_records'], $pParamHash['offset']); $ret = array(); $comment = new LibertyComment(); while ($res = $result->fetchRow()) { // get this stuff parsed $res = array_merge($this->parseSplit($res, $gBitSystem->getConfig('articles_description_length', 500)), $res); $res['thumbnail_url'] = static::getImageThumbnails($res); $res['num_comments'] = $comment->getNumComments($res['content_id']); $res['display_url'] = self::getDisplayUrlFromHash($res); $res['display_link'] = $this->getDisplayLink($res['title'], $res); // fetch the primary attachment that we can display the file on the front page if needed $res['primary_attachment'] = LibertyMime::loadAttachment($res['primary_attachment_id']); $ret[] = $res; } $pParamHash["cant"] = $this->mDb->getOne($query_cant, $bindVars); LibertyContent::postGetList($pParamHash); return $ret; }
then we check permission to delete boards. if so, we call histlib's method remove_all_versions for all the checked boards. */ if (isset($_REQUEST["submit_mult"]) && isset($_REQUEST["checked"]) && $_REQUEST["submit_mult"] == "remove_boards") { // Now check permissions to remove the selected bitboard $gContent->verifyUserPermission('p_boards_remove'); $gBitUser->verifyTicket(); if (!empty($_REQUEST['cancel'])) { // user cancelled - just continue on, doing nothing } elseif (empty($_REQUEST['confirm'])) { $formHash['b'] = $_REQUEST['b']; $formHash['delete'] = TRUE; $formHash['submit_mult'] = 'remove_boards'; foreach ($_REQUEST["checked"] as $del) { $formHash['input'][] = '<input type="hidden" name="checked[]" value="' . $del . '"/>'; } $gBitSystem->confirmDialog($formHash, array('warning' => tra('Are you sure you want to delete these topics?') . ' (' . tra('Count: ') . count($_REQUEST["checked"]) . ')', 'error' => tra('This cannot be undone!'))); } else { foreach ($_REQUEST["checked"] as $deleteId) { $deleteComment = new LibertyComment($deleteId); if ($deleteComment->isValid() && $gBitUser->hasPermission('p_liberty_admin_comments')) { if (!$deleteComment->expunge()) { $gBitSmarty->assignByRef('errors', $deleteComment->mErrors); } } } if (!empty($errors)) { $gBitSmarty->assignByRef('errors', $errors); } } }
/** * $pMsgHeader is a imap_headerinfo generated array **/ function board_sync_process_message($pMbox, $pMsgNum, $pMsgHeader, $pMsgStructure, $pModerate = FALSE, $pLog = FALSE, $pDeliveredTo = NULL) { global $gBitSystem, $gBitDb; // vd( $pMsgHeader ); // Collect a bit of header information $message_id = board_sync_get_headerinfo($pMsgHeader, 'message_id'); // @TODO comment or clean up, not sure why this is here -wjames5 if (empty($message_id)) { $message_id = board_sync_get_headerinfo($pMsgHeader, 'message_id'); } $subject = board_sync_get_headerinfo($pMsgHeader, 'Subject'); if (empty($message_id)) { bit_error_log("Email sync for message: " . $subject . " failed: No Message Id in mail header."); } else { if ($pLog) { print "Processing: " . $message_id . "\n"; } if ($pLog) { print " Subject: " . $subject . "\n"; } $matches = array(); $toAddresses = array(); $allRecipients = ""; if (empty($pDeliveredTo)) { if (isset($pMsgHeader->toaddress)) { $allRecipients .= $pMsgHeader->toaddress; if ($pLog) { print " To addresses: " . $pMsgHeader->toaddress . "\n"; } } if (isset($pMsgHeader->ccaddress)) { $allRecipients .= ($allRecipients != "" ? "," : "") . $pMsgHeader->ccaddress; if ($pLog) { print " CC addresses: " . $pMsgHeader->ccaddress . "\n"; } } if ($pLog) { print " All Recipients: " . $allRecipients . "\n"; } $allSplit = split(',', $allRecipients); foreach ($allSplit as $s) { $s = trim($s); $matches = array(); if (strpos($s, '<') !== FALSE) { if (preg_match("/\\s*(.*)\\s*<\\s*(.*)\\s*>/", $s, $matches)) { $toAddresses[] = array('name' => $matches[1], 'email' => $matches[2]); } elseif (preg_match('/<\\s*(.*)\\s*>\\s*(.*)\\s*/', $s, $matches)) { $toAddresses[] = array('email' => $matches[1], 'name' => $matches[2]); } } elseif (validate_email_syntax($s)) { $toAddresses[] = array('email' => $s); } } } else { foreach ($pDeliveredTo as $address) { $toAddresses[] = array('email' => $address); } } if ($pLog) { print_r($toAddresses); } $date = board_sync_get_headerinfo($pMsgHeader, 'Date'); $from = board_sync_get_headerinfo($pMsgHeader, 'from'); $fromaddress = $from[0]->mailbox . "@" . $from[0]->host; // personal is not always defined. if (isset($from[0]->personal)) { $personal = ucwords($from[0]->personal); } else { $personal = null; } $in_reply_to = board_sync_get_headerinfo($pMsgHeader, 'in_reply_to'); if ($pLog) { print "\n---- " . date("Y-m-d HH:mm:ss") . " -------------------------\nImporting: " . $message_id . "\nDate: " . $date . "\nFrom: " . $fromaddress . "\nTo: " . $allRecipients . "\nSubject: " . $subject . "\nIn Reply To: " . $in_reply_to . "\nName: " . $personal . (is_array($pDeliveredTo) ? "\nDelivered-To:" . implode(", ", $pDeliveredTo) : '') . "\n"; } foreach ($toAddresses as $to) { if ($pLog) { print " Processing email: " . strtolower($to['email']) . "\n"; } // get a board match for the email address if ($boardContentId = cache_check_content_prefs('board_sync_list_address', strtolower($to['email']), TRUE)) { if ($pLog) { print "Found Board Content {$boardContentId} for {$to['email']}\n"; } // Do we already have this message in this board? $contentId = NULL; if ($message_id != NULL) { $sql = "SELECT `content_id` FROM `" . BIT_DB_PREFIX . "liberty_comments` WHERE `message_guid`=? AND `root_id`=?"; $contentId = $gBitDb->getOne($sql, array($message_id, $boardContentId)); } if (empty($contentId)) { if (!empty($in_reply_to)) { if ($parent = $gBitDb->GetRow("SELECT `content_id`, `root_id` FROM `" . BIT_DB_PREFIX . "liberty_comments` WHERE `message_guid`=?", array($in_reply_to))) { $replyId = $parent['content_id']; $rootId = $parent['root_id']; } else { if ($pLog) { print "WARNING: Reply to unfound message: " . $in_reply_to; } $replyId = $boardContentId; $rootId = $boardContentId; } // if no reply to message guid then match on title - this looks dangerous as titles could easily be duplicated -wjames } elseif ($parent = $gBitDb->GetRow("SELECT lcom.`content_id`, lcom.`root_id` FROM `" . BIT_DB_PREFIX . "liberty_comments` lcom INNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON(lcom.`content_id`=lc.`content_id`) WHERE lc.`title`=?", array(preg_replace('/re: /i', '', $subject)))) { $replyId = $parent['content_id']; $rootId = $parent['root_id']; // attach to board as first level comment e.g. new topic } else { $replyId = $boardContentId; $rootId = $boardContentId; } $userInfo = board_sync_get_user($fromaddress); // prep the storage hash $storeRow = array(); $storeRow['created'] = strtotime($date); $storeRow['last_modified'] = $storeRow['created']; $storeRow['user_id'] = $userInfo['user_id']; $storeRow['modifier_user_id'] = $userInfo['user_id']; $storeRow['title'] = $subject; $storeRow['message_guid'] = $message_id; if ($userInfo['user_id'] == ANONYMOUS_USER_ID && !empty($personal)) { $storeRow['anon_name'] = $personal; } $storeRow['root_id'] = $rootId; $storeRow['parent_id'] = $replyId; $partHash = array(); switch ($pMsgStructure->type) { case '0': if ($pLog) { print "Structure Type: text\n"; } board_parse_msg_parts($partHash, $pMbox, $pMsgNum, $pMsgStructure, 1, $pLog); break; case '1': if ($pLog) { print "Structure Type: multipart\n"; } if ($pModerate) { $prefix = '2.'; } else { $prefix = ''; } foreach ($pMsgStructure->parts as $partNum => $part) { board_parse_msg_parts($partHash, $pMbox, $pMsgNum, $part, $prefix . ($partNum + 1), $pLog); } break; } $plainBody = ""; $htmlBody = ""; foreach (array_keys($partHash) as $i) { if (!empty($partHash[$i]['plain'])) { $plainBody .= $partHash[$i]['plain']; } if (!empty($partHash[$i]['html'])) { $htmlBody .= $partHash[$i]['html']; } if (!empty($partHash[$i]['attachment'])) { $storeRow['_files_override'][] = array('tmp_name' => $partHash[$i]['attachment'], 'type' => $gBitSystem->verifyMimeType($partHash[$i]['attachment']), 'size' => filesize($partHash[$i]['attachment']), 'name' => basename($partHash[$i]['attachment']), 'user_id' => $userInfo['user_id']); } } if (!empty($htmlBody)) { $storeRow['edit'] = $htmlBody; $storeRow['format_guid'] = 'bithtml'; } elseif (!empty($plainBody)) { $storeRow['edit'] = nl2br($plainBody); $storeRow['format_guid'] = 'bithtml'; } // Nuke all email addresses from the body. if (!empty($storeRow['edit'])) { $storeRow['edit'] = ereg_replace('[-!#$%&\\`*+\\./0-9=?A-Z^_`a-z{|}~]+' . '@' . '(localhost|[-!$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\\.' . '[-!$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+)', '', $storeRow['edit']); } // We trust the user from this source // and count on moderation to handle links global $gBitUser; $gBitUser->setPermissionOverride('p_liberty_trusted_editor', true); // Check to add attachments // NOTE: we temporarily change the gBitUser here! // This is so we can run a proper content permissions check // for attachment permission against the parent // board object. This is sort of a hack to deal // with the fact that LibertyContent does not have a // means to check the permissions of any user except gBitUser -wjames5 // Important store a reference so we can switch back when we are done $gBitUserOrg = $gBitUser; // Load the message sending user if ($userInfo['user_id'] != ANONYMOUS_USER_ID) { $userClass = $gBitSystem->getConfig('user_class', 'BitPermUser'); $newBitUser = new $userClass($userInfo['user_id']); $newBitUser->load(TRUE); } if (!empty($newBitUser) && $newBitUser->isValid()) { // flip gBitUser to our message sender $gBitUser = $newBitUser; } // Load the parent board $board = new BitBoard(NULL, $boardContentId); $board->load(); // Check the permission for the user on the board if ($gBitSystem->isFeatureActive('comments_allow_attachments') && $board->hasUserPermission('p_liberty_attach_attachments')) { // note we grant the permission to the anonymous user which will become gBitUser once again $gBitUserOrg->setPermissionOverride('p_liberty_attach_attachments', true); } // Clear the reference to this board so we dont mistakenly use it later unset($board); // Important: switch gBitUser back! $gBitUser = $gBitUserOrg; // End check to add attachments to comments to the parent board // Check for an empty body // Duplicate subject if we have it if (empty($storeRow['edit'])) { if (!empty($storeRow['title'])) { $storeRow['edit'] = $storeRow['title']; } else { $storeRow['edit'] = "."; } } $storeComment = new LibertyComment(NULL); $gBitDb->StartTrans(); if ($storeComment->storeComment($storeRow)) { // undo the attachment permission $gBitUser->setPermissionOverride('p_liberty_attach_attachments', false); // set moderation approval if (!$pModerate && $gBitSystem->isPackageActive('moderation') && $gBitSystem->isPackageActive('modcomments')) { global $gModerationSystem, $gBitUser; $moderation = $gModerationSystem->getModeration(NULL, $storeComment->mContentId); if (!empty($moderation)) { // Allow to moderate $gBitUser->setPermissionOverride('p_admin', TRUE); $gModerationSystem->setModerationReply($moderation['moderation_id'], MODERATION_APPROVED); $gBitUser->setPermissionOverride('p_admin', FALSE); } } if (!empty($storeRow['message_guid'])) { // map the message guid to the comment $storeComment->mDb->query("UPDATE `" . BIT_DB_PREFIX . "liberty_comments` SET `message_guid`=? WHERE `content_id`=?", array($storeRow['message_guid'], $storeComment->mContentId)); // Store the confirm code if ($pModerate) { $storeComment->storePreference('board_confirm_code', $pModerate); } // done $gBitDb->CompleteTrans(); return TRUE; } else { bit_error_log("Email sync error: Message Id not set. You shouldn't have even gotten this far."); $gBitDb->RollbackTrans(); return FALSE; } } else { if (count($storeComment->mErrors) == 1 && !empty($storeComment->mErrors['store']) && $storeComment->mErrors['store'] == 'Duplicate comment.') { return TRUE; } else { foreach ($storeComment->mErrors as $error) { bit_error_log($error); } $gBitDb->RollbackTrans(); return FALSE; } } } else { if ($pLog) { print "Message Exists: {$contentId} : {$boardContentId} : {$message_id} : {$pModerate}\n"; } // If this isn't a moderation message if ($pModerate === FALSE) { // If the message exists it must have been approved via some // moderation mechanism, so make sure it is available if ($gBitSystem->isPackageActive('moderation') && $gBitSystem->isPackageActive('modcomments')) { global $gModerationSystem, $gBitUser; $storeComment = new LibertyComment(NULL, $contentId); $storeComment->loadComment(); if ($storeComment->mInfo['content_status_id'] > 0) { if ($pLog) { print "Already approved: {$contentId}\n"; } } else { $moderation = $gModerationSystem->getModeration(NULL, $contentId); // vd($moderation); if (!empty($moderation)) { $gBitUser->setPermissionOverride('p_admin', TRUE); if ($pLog) { print "Setting approved: {$contentId}\n"; } $gModerationSystem->setModerationReply($moderation['moderation_id'], MODERATION_APPROVED); $gBitUser->setPermissionOverride('p_admin', FALSE); if ($pLog) { print "Done"; } } else { if ($pLog) { print "ERROR: Unable to find moderation to approve for: {$contentId}"; } } } } } else { // Store the approve code; if ($pLog) { print "Storing approval code: " . $contentId . ":" . $pModerate . "\n"; } $storeComment = new LibertyComment(NULL, $contentId); $storeComment->storePreference('board_confirm_code', $pModerate); } return TRUE; } } else { if ($pLog) { print "No Board match found for {$to['email']}\n"; } } } } return FALSE; }
/** * This function removes a single image area tag **/ function expunge_tag($itagId) { $ret = FALSE; $storeComment = new LibertyComment(@BitBase::verifyId($itagId) ? $itagId : NULL); $storeComment->mDb->StartTrans(); if ($storeComment->verifyId($storeComment->mCommentId)) { $storeComment->mDb->query("DELETE FROM `" . BIT_DB_PREFIX . "itags_image_areas` WHERE `attachment_id`=? and `comment_id`=?", array($this->mAttachementId, $storeComment->mCommentId)); } $storeComment->expunge(); $storeComment->mDb->CompleteTrans(); $this->load(); return $ret; }
/** * This function generates a list of records from the liberty_content database for use in a list page **/ function getList(&$pParamHash) { global $commentsLib; LibertyContent::prepGetList($pParamHash); $selectSql = ''; $joinSql = ''; $whereSql = ''; $bindVars = array(); array_push($bindVars, $this->mContentTypeGuid); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pParamHash); // this will set $find, $sort_mode, $max_records and $offset extract($pParamHash); // quick search support from find field if (is_array($find)) { // you can use an array of pages $whereSql .= " AND lc.`title` IN( " . implode(',', array_fill(0, count($find), '?')) . " )"; $bindVars = array_merge($bindVars, $find); } elseif (is_string($find)) { // or a string $whereSql .= " AND UPPER( lc.`title` )like ? "; $bindVars[] = '%' . strtoupper($find) . '%'; } $sortModePrefix = 'lc.'; $sort_mode = $sortModePrefix . $this->mDb->convertSortmode($pParamHash['sort_mode']); $query = "SELECT bm.*, lc.`content_id`, lc.`title`, lc.`data`, lcds.`data` AS `summary`,\n\t\t\t\t\t\tlc.`format_guid`, lc.`last_modified`, lc.`created`, lc.`version` \n\t\t\t\t\t\t{$selectSql}\n\t\t\t\t FROM `" . BIT_DB_PREFIX . "gmaps` bm \n\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( lc.`content_id` = bm.`content_id` )\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_data` lcds ON (lc.`content_id` = lcds.`content_id` AND lcds.`data_type`='summary')\n\t\t\t\t\t\t{$joinSql}\n\t\t\t\t WHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\t\t ORDER BY {$sort_mode}"; $query_cant = "SELECT COUNT( * )\n\t\t\t\t\t\tFROM\t`" . BIT_DB_PREFIX . "gmaps` bm \n\t\t\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( lc.`content_id` = bm.`content_id` ) {$joinSql}\n\t\t\t\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}"; $result = $this->mDb->query($query, $bindVars, $max_records, $offset); $ret = array(); $comment = new LibertyComment(); while ($res = $result->fetchRow()) { if ($this->getPreference('allow_comments', null, $res['content_id']) == 'y') { $res['num_comments'] = $comment->getNumComments($res['content_id']); } $res['display_url'] = $this->getDisplayUrl(NULL, $res); $ret[] = $res; } $pParamHash["data"] = $ret; $pParamHash["cant"] = $this->mDb->getOne($query_cant, $bindVars); LibertyContent::postGetList($pParamHash); return $pParamHash; }
/** * Delete comment entries relating to the content object * * @access public * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure */ function expungeComments() { require_once LIBERTY_PKG_PATH . 'LibertyComment.php'; // Delete all comments associated with this piece of content $query = "SELECT `comment_id` FROM `" . BIT_DB_PREFIX . "liberty_comments` WHERE `root_id` = ?"; if ($commentIds = $this->mDb->getCol($query, array($this->mContentId))) { foreach ($commentIds as $commentId) { $tmpComment = new LibertyComment($commentId); $tmpComment->expunge(); } } return parent::expunge(); }
} if (!empty($moduleParams['module_rows'])) { $listHash['max_records'] = $moduleParams['module_rows']; } elseif (!empty($moduleParams['module_params']['max_records'])) { $listHash['max_records'] = $moduleParams['module_params']['max_records']; } if (!empty($moduleParams['module_params']['user_id'])) { $listHash['user_id'] = $moduleParams['module_params']['user_id']; } else { $listHash['user_id'] = $gQueryUser->mUserId; } $statuses = feed_get_status($listHash); $_template->tpl_vars['statuses'] = new Smarty_variable($statuses); foreach ($statuses as $status) { $commentContentId = 'comment_' . $status['content_id']; if (!empty($_REQUEST[$commentContentId])) { //then there is a reply to this comment and break, we only handle one at a time $reply = new LibertyComment(); $pParamHash['root_id'] = $status['content_id']; $pParamHash['parent_id'] = $status['content_id']; $pParamHash['comment_data'] = $_REQUEST[$commentContentId]; $pParamHash['title'] = substr($_REQUEST[$commentContentId], 0, 20); $reply->storeComment($pParamHash); $statuses = feed_get_status($listHash); $_template->tpl_vars['statuses'] = new Smarty_variable($statuses); break; } } ?>
function getComments($pContentId = NULL, $pMaxComments = NULL, $pOffset = NULL, $pSortOrder = NULL, $pDisplayMode = NULL) { if ($pDisplayMode != "flat") { if ($pSortOrder == "commentDate_asc") { $pSortOrder = 'thread_asc'; } else { $pSortOrder = 'thread_desc'; } } $contentId = NULL; $ret = array(); if (!$pContentId && $this->mContentId) { $contentId = $this->mContentId; } elseif ($pContentId) { $contentId = $pContentId; } $mid = ""; $sort_order = "ASC"; $mid = 'created ASC'; if (!empty($pSortOrder)) { if ($pSortOrder == 'commentDate_desc') { $mid = 'created DESC'; } else { if ($pSortOrder == 'commentDate_asc') { $mid = 'created ASC'; } elseif ($pSortOrder == 'thread_asc') { $mid = 'thread_forward_sequence ASC'; // thread newest first is harder... } elseif ($pSortOrder == 'thread_desc') { $mid = 'thread_reverse_sequence ASC'; } else { $mid = $this->mDb->convertSortmode($pSortOrder); } } } $mid = 'order by ' . $mid; $bindVars = array(); if (is_array($pContentId)) { $mid2 = 'in (' . implode(',', array_fill(0, count($pContentId), '?')) . ')'; $bindVars = $pContentId; $select1 = ', lcp.`content_type_guid` as parent_content_type_guid, lcp.`title` as parent_title '; $join1 = " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lcp ON (lcp.`content_id` = lcom.`parent_id`) "; } elseif ($pContentId) { $mid2 = '=?'; $bindVars = array($pContentId); $select1 = ''; $join1 = ''; } $joinSql = $selectSql = $whereSql = ''; $pListHash = array('content_id' => $contentId, 'max_records' => $pMaxComments, 'offset' => $pOffset, 'sort_mode' => $pSortOrder, 'display_mode' => $pDisplayMode, 'has_comment_view_perm' => TRUE); $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, $this, $pListHash); if ($pContentId) { $sql = "SELECT lcom.`comment_id`, lcom.`parent_id`, lcom.`root_id`, lcom.`thread_forward_sequence`, lcom.`thread_reverse_sequence`, lcom.`anon_name`, lc.*, uu.`email`, uu.`real_name`, uu.`login` {$selectSql} {$select1}\n\t\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_comments` lcom\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lcom.`content_id` = lc.`content_id`)\n\t\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (lc.`user_id` = uu.`user_id`) {$joinSql} {$join1}\n\t\t\t\t WHERE lcom.root_id {$mid2} {$whereSql} {$mid}"; $flat_comments = array(); if ($result = $this->mDb->query($sql, $bindVars, $pMaxComments, $pOffset)) { while ($row = $result->FetchRow()) { $row['parsed_data'] = $this->parseData($row); $row['level'] = substr_count($row['thread_forward_sequence'], '.') - 1; $c = new LibertyComment(); $c->mInfo = $row; $c->mRootObj = $this->getRootObj(); $row['is_editable'] = $c->userCanUpdate($c->mRootObj); global $gBitSystem; if ($gBitSystem->isFeatureActive('comments_allow_attachments')) { // get attachments for each comment global $gLibertySystem; $query = "SELECT * FROM `" . BIT_DB_PREFIX . "liberty_attachments` la WHERE la.`content_id`=? ORDER BY la.`pos` ASC, la.`attachment_id` ASC"; if ($result2 = $this->mDb->query($query, array((int) $row['content_id']))) { while ($row2 = $result2->fetchRow()) { if ($func = $gLibertySystem->getPluginFunction($row2['attachment_plugin_guid'], 'load_function', 'mime')) { // we will pass the preferences by reference that the plugin can easily update them if (empty($row['storage'][$row2['attachment_id']])) { $row['storage'][$row2['attachment_id']] = array(); } $row['storage'][$row2['attachment_id']] = $func($row2, $row['storage'][$row2['attachment_id']]); } else { print "No load_function for " . $row2['attachment_plugin_guid']; } } } // end get attachements for each comment } $flat_comments[$row['content_id']] = $row; } } # now select comments wanted $ret = $flat_comments; } return $ret; }
* * @package wiki * @subpackage functions */ /** * required setup */ require_once '../kernel/setup_inc.php'; include_once WIKI_PKG_PATH . 'BitPage.php'; $gBitSystem->verifyPackage('wiki'); $gBitSystem->verifyFeature('users_watches'); $gBitSystem->verifyPermission('p_admin_users', tra("Permission denied you cannot browse these page watches")); // Get the page from the request var or default it to HomePage include WIKI_PKG_PATH . 'lookup_page_inc.php'; // make comment count for this page available for templates $gComment = new LibertyComment(); $numComments = $gComment->getNumComments($gContent->mContentId); $gBitSmarty->assign('comments_count', $numComments); //vd($gContent->mPageId);vd($gContent->mInfo); if (!$gContent->isValid() || empty($gContent->mInfo)) { $gBitSystem->fatalError(tra("Unknown page")); } $watches = NULL; if (!empty($gContent->mPageId)) { $event = 'wiki_page_changed'; $watches = $gBitUser->get_event_watches($event, $gContent->mPageId); $gBitSmarty->assignByRef('watches', $watches); $gBitSmarty->assignByRef('pageInfo', $gContent->mInfo); } // Display the template $gBitSystem->display('bitpackage:wiki/page_watches.tpl', NULL, array('display_mode' => 'display'));
function migrate_wp_comments() { global $wpdb, $gBitSystem, $gBitSmarty, $gUserMap, $gErrorMap, $gBlogMap, $gPostMap, $gCommentMap, $gMaxComment; // vd("Blog Map"); // vd($gBlogMap); // vd("Post Map"); // vd($gPostMap); // vd("User map"); // vd($gUserMap); $query = "select * from " . $wpdb->table_prefix . "wp_comments WHERE comment_type = '' AND comment_id > {$gMaxComment} ORDER BY comment_id"; $comments = $wpdb->get_results($query); if (!empty($comments)) { foreach ($comments as $comment) { // vd($comment); $pParamHash = array(); $pParamHash['edit'] = wptexturize(convert_chars(wpautop($comment->comment_content))); if (empty($comment->user_id)) { $pParamHash['annon_name'] = $comment->comment_author; } else { if (empty($gUserMap[$comment->user_id])) { $pParamHash['owner_id'] = 1; $gErrorMap[]['warning'] = "Comment: " . $comment->comment_ID . " author defaulted to Administrator."; } else { $pParamHash['owner_id'] = $gUserMap[$comment->user_id]; $pParamHash['current_owner_id'] = -1; } } if ($comment->comment_approved) { $pParamHash['content_status'] = 50; } else { $pParamHash['content_status'] = -1; } $pParamHash['last_modified'] = $gBitSystem->mServerTimestamp->getTimestampFromIso($comment->comment_date_gmt); if (!empty($gPostMap[$comment->comment_post_ID])) { $pParamHash['root_id'] = $gPostMap[$comment->comment_post_ID]; $pParamHash['parent_id'] = $gPostMap[$comment->comment_post_ID]; } else { $gErrorMap[]['error'] = "Comment: Unable to map to post_id: " . $comment->comment_ID . " : Post ID: " . $comment->comment_post_ID; } $c = new LibertyComment(); $c->storeComment($pParamHash); if (!empty($c->mContentId)) { $gCommentMap[$comment->comment_ID] = $c->mContentId; $query = "UPDATE liberty_content set IP = ?, created = ? WHERE content_id = ?"; $gBitSystem->mDb->query($query, array($comment->comment_author_IP, $pParamHash['last_modified'], $c->mContentId)); } else { $gErrorMap[]['error'] = "Coment: Unable to store: " . $comment->comment_ID . " : " . implode(", ", $c->mErrors); } } } // vd("Comments Map."); // vd($gCommentMap); $sql = "INSERT INTO `" . BIT_DB_PREFIX . "blogs_wp_comments` (`wp_id`, `comment_id`) VALUES (?, ?)"; foreach ($gCommentMap as $wp_id => $comment_id) { if ($wp_id > $gMaxComment) { $gBitSystem->mDb->query($sql, array($wp_id, $comment_id)); } } }