function bit_files_expunge($pStorageId) { global $gBitUser, $gBitSystem; $ret = FALSE; if (is_numeric($pStorageId)) { $sql = "SELECT * FROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON (lf.`file_id`=la.`foreign_id`)\n\t\t\t\tWHERE la.`attachment_id` = ?"; if ($row = $gBitSystem->mDb->getRow($sql, array($pStorageId))) { $sourceFile = liberty_mime_get_source_file($row); if ($gBitUser->isAdmin() || $gBitUser->mUserId == $row['user_id']) { if (file_exists($sourceFile)) { // make sure this is a valid storage directory before removing it if (preg_match('!/users/\\d+/\\d+/\\w+/\\d+/.+!', $sourceFile)) { unlink_r(dirname($sourceFile)); } else { unlink($sourceFile); } } $query = "DELETE FROM `" . BIT_DB_PREFIX . "liberty_files` WHERE `file_id` = ?"; $gBitSystem->mDb->query($query, array($row['foreign_id'])); $ret = TRUE; } } } return $ret; }
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; }
/** * 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; }