function bit_files_load($pRow) { // this fuction broken, will fix soon - spiderr // I think its fixed now - no promises though! - drewslater global $gBitSystem, $gLibertySystem; $ret = array(); if (!empty($pRow['foreign_id']) && is_numeric($pRow['foreign_id'])) { $query = "\n\t\t\tSELECT *\n\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON (lf.`file_id` = la.`foreign_id`)\n\t\t\tWHERE la.`foreign_id` = ? AND `attachment_plugin_guid` = ?"; if ($ret = $gBitSystem->mDb->getRow($query, array($pRow['foreign_id'], PLUGIN_GUID_BIT_FILES))) { $ret['file_name'] = basename($ret['file_name']); $ret['source_file'] = liberty_mime_get_source_file($ret); $canThumbFunc = liberty_get_function('can_thumbnail'); if ($canThumbFunc($ret['mime_type'])) { $thumbHash['default_image'] = LIBERTY_PKG_URL . 'icons/generating_thumbnails.png'; } $ret['source_url'] = liberty_mime_get_source_url($ret); $ret['thumbnail_url'] = liberty_fetch_thumbnails($ret); $ret['wiki_plugin_link'] = "{attachment id=" . $ret['attachment_id'] . "}"; } } return $ret; }
function mime_default_load($pFileHash, &$pPrefs) { global $gBitSystem, $gLibertySystem; $ret = FALSE; if (@BitBase::verifyId($pFileHash['attachment_id'])) { $query = "\n\t\t\t\tSELECT *\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_attachments` la\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lf ON( la.`foreign_id` = lf.`file_id` )\n\t\t\t\tWHERE la.`attachment_id`=?"; if ($row = $gBitSystem->mDb->getRow($query, array($pFileHash['attachment_id']))) { $ret = array_merge($pFileHash, $row); $storageName = basename($row['file_name']); // compatibility with _FILES hash $row['name'] = $storageName; $row['type'] = $row['mime_type']; $storageBranch = liberty_mime_get_storage_branch(array('attachment_id' => $row['attachment_id'])) . $storageName; // this will fetch the correct thumbnails $thumbHash['source_file'] = STORAGE_PKG_PATH . $storageBranch; $row['source_file'] = STORAGE_PKG_PATH . $storageBranch; $canThumbFunc = liberty_get_function('can_thumbnail'); if ($canThumbFunc && $canThumbFunc($row['mime_type'])) { $thumbHash['default_image'] = LIBERTY_PKG_URL . 'icons/generating_thumbnails.png'; } $ret['thumbnail_url'] = liberty_fetch_thumbnails($thumbHash); // indicate that this is a mime thumbnail if (!empty($ret['thumbnail_url']['medium']) && strpos($ret['thumbnail_url']['medium'], '/mime/')) { $ret['thumbnail_is_mime'] = TRUE; } // pretty URLs if ($gBitSystem->isFeatureActive("pretty_urls") || $gBitSystem->isFeatureActive("pretty_urls_extended")) { $ret['display_url'] = LIBERTY_PKG_URL . "view/file/" . $row['attachment_id']; } else { $ret['display_url'] = LIBERTY_PKG_URL . "view_file.php?attachment_id=" . $row['attachment_id']; } // legacy table data was named storage path and included a partial path. strip out any path just in case $ret['file_name'] = $storageName; $ret['preferences'] = $pPrefs; // some stuff is only available if we have a source file // make sure to check for these when you use them. frequently the original might not be available // e.g.: video files are large and the original might be deleted after conversion if (is_file(STORAGE_PKG_PATH . $storageBranch)) { $ret['source_file'] = STORAGE_PKG_PATH . $storageBranch; $ret['source_url'] = STORAGE_PKG_URL . $storageBranch; $ret['last_modified'] = filemtime($ret['source_file']); if ($gBitSystem->isFeatureActive("pretty_urls") || $gBitSystem->isFeatureActive("pretty_urls_extended")) { $ret['download_url'] = LIBERTY_PKG_URL . "download/file/" . $row['attachment_id']; } else { $ret['download_url'] = LIBERTY_PKG_URL . "download_file.php?attachment_id=" . $row['attachment_id']; } } // add a description of how to insert this file into a wiki page if ($gLibertySystem->isPluginActive('dataattachment')) { $ret['wiki_plugin_link'] = "{image id=" . $row['attachment_id'] . "}"; } // additionally we'll add this to distinguish between old plugins and new ones // TODO: this should hopefully not be necessary for too long $ret['is_mime'] = TRUE; } } return $ret; }
/** * fetch a single available thumbnail for a given item. if no thumbnail is present, return NULL * * @param array $pParamHash Hash of all settings used to fetch thumbnails including: size, source_file, default_image, and mime_image * @access public * @return string url * TODO: individual options are only for legacy reasons - remove options and deprecated() soon - xing - Monday Jun 23, 2008 22:36:53 CEST */ function liberty_fetch_thumbnail_url($pParamHash) { if (!empty($pParamHash['source_file'])) { if (empty($pParamHash['size'])) { $pParamHash['size'] = 'small'; } $pParamHash['thumbnail_sizes'] = array($pParamHash['size']); $ret = liberty_fetch_thumbnails($pParamHash); return !empty($ret[$pParamHash['size']]) ? $ret[$pParamHash['size']] : NULL; } }
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; }
/** * Get a list of all content * * @param string $pListHash['content_type_guid'] Content GUID to limit the list to * @param integer $pListHash['max_records'] Number of the first record to access ( used to page the list ) * @param integer $pListHash['offset'] Number of records to return * @param string $pListHash['sort_mode'] Name of the field to sort by ( extended by _asc or _desc for sort direction ) * @param array $pListHash['find'] List of text elements to filter the results by * @param integer $pListHash[''] User ID - If set, then only the objcets created by that user will be returned * $pListHash['last_modified'] date - modified since * $pListHash['end_date'] date - modified before * @return array An array of mInfo type arrays of content objects **/ function getContentList(&$pListHash) { global $gLibertySystem, $gBitSystem, $gBitUser, $gBitSmarty; LibertyContent::prepGetList($pListHash); $hashSql = array('select' => array(), 'join' => array(), 'where' => array()); $hashBindVars = array('select' => array(), 'where' => array(), 'join' => array()); if (!empty($pListHash['content_type_guid']) && is_array($pListHash['content_type_guid'])) { foreach ($pListHash['content_type_guid'] as $contentTypeGuid) { $this->getFilter($contentTypeGuid, $hashSql, $hashBindVars, $pListHash); } } elseif (!empty($pListHash['content_type_guid'])) { $this->getFilter($pListHash['content_type_guid'], $hashSql, $hashBindVars, $pListHash); } if (!empty($hashSql['select'])) { $selectSql = ',' . implode(',', $hashSql['select']); } else { $selectSql = ''; } $joinSql = implode(' ', $hashSql['join']); $whereSql = ''; if (empty($hashBindVars['join'])) { $bindVars = array(); } else { $bindVars = $hashBindVars['join']; } $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars, NULL, $pListHash); if ($pListHash['sort_mode'] == 'size_desc') { $pListHash['sort_mode'] = 'wiki_page_size_desc'; } if ($pListHash['sort_mode'] == 'size_asc') { $pListHash['sort_mode'] = 'wiki_page_size_asc'; } $old_sort_mode = ''; $sortHash = array('versions_desc', 'versions_asc', 'links_asc', 'links_desc', 'backlinks_asc', 'backlinks_desc'); if (in_array($pListHash['sort_mode'], $sortHash)) { $old_offset = $pListHash['offset']; $old_max_records = $pListHash['max_records']; $old_sort_mode = $pListHash['sort_mode']; $pListHash['sort_mode'] = 'modifier_user_desc'; $pListHash['offset'] = 0; $pListHash['max_records'] = -1; } if (is_array($pListHash['find'])) { // you can use an array of titles $whereSql .= " AND lc.`title` IN ( " . implode(',', array_fill(0, count($pListHash['find']), '?')) . ") "; $bindVars = array_merge($pListHash['find'], $pListHash['find']); } elseif (!empty($pListHash['find']) && is_string($pListHash['find'])) { // or a string $whereSql .= " AND UPPER(lc.`title`) like ? "; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; } if (!empty($pListHash['content_id_list'])) { // you can use an array of titles $whereSql .= " AND lc.`content_id` IN ( " . implode(',', array_fill(0, count($pListHash['content_id_list']), '?')) . ") "; $bindVars = array_merge($bindVars, $pListHash['content_id_list']); } // this is necessary to display useful information in the liberty RSS feed if (!empty($pListHash['include_data'])) { $selectSql .= ", lc.`data`, lc.`format_guid`"; } // if we want the primary attachment for each object if ($gBitSystem->isFeatureActive('liberty_display_primary_attach')) { $selectSql .= ', lfp.`file_name`, lfp.`mime_type`, la.`attachment_id`, '; $joinSql .= "LEFT 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\t\t LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lfp ON( lfp.`file_id` = la.`foreign_id` )"; } // Allow selection based on arbitrary time limits -- used in calendar // TODO: We should replace usages of from_date and until_date with this generic setup and depricate those if (!empty($pListHash['time_limit_column'])) { if (empty($pListHash['time_limit_table'])) { $pListHash['time_limit_table'] = 'lc.'; } if (!empty($pListHash['time_limit_start'])) { $whereSql .= " AND " . $pListHash['time_limit_table'] . "`" . $pListHash['time_limit_column'] . "` >= ? "; $bindVars[] = $pListHash['time_limit_start']; } if (!empty($pListHash['time_limit_stop'])) { $whereSql .= " AND " . $pListHash['time_limit_table'] . "`" . $pListHash['time_limit_column'] . "` <= ? "; $bindVars[] = $pListHash['time_limit_stop']; } } if (@$this->verifyId($pListHash['user_id'])) { $whereSql .= " AND lc.`user_id` = ? "; $bindVars[] = $pListHash['user_id']; } if (@$this->verifyId($pListHash['link_content_id'])) { $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "liberty_content_links` lclk ON ( lc.`content_id` = lclk.`to_content_id` )"; $whereSql .= " AND lclk.`from_content_id` = ? "; $bindVars[] = (int) $pListHash['link_content_id']; } if ($gBitSystem->isFeatureActive('liberty_display_status') && $gBitUser->hasPermission('p_liberty_view_all_status')) { $selectSql .= ", lcs.`content_status_id`, lcs.`content_status_name`"; $joinSql .= " LEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_status` lcs ON ( lc.`content_status_id` = lcs.`content_status_id` )"; if (!empty($pListHash['content_status_id'])) { if ($pListHash['content_status_id'] == 'not_available') { $whereSql .= " AND lcs.`content_status_id` <> ? "; $bindVars[] = 50; } else { $whereSql .= " AND lcs.`content_status_id` = ? "; $bindVars[] = (int) $pListHash['content_status_id']; } } } // join on specific content_type_guids if (!empty($pListHash['content_type_guid']) && is_string($pListHash['content_type_guid'])) { $whereSql .= ' AND lc.`content_type_guid`=? '; $bindVars[] = $pListHash['content_type_guid']; } elseif (!empty($pListHash['content_type_guid']) && is_array($pListHash['content_type_guid'])) { $whereSql .= " AND lc.`content_type_guid` IN ( " . implode(',', array_fill(0, count($pListHash['content_type_guid']), '?')) . " )"; $bindVars = array_merge($bindVars, $pListHash['content_type_guid']); } // exclude by content_type_guids if (!empty($pListHash['exclude_content_type_guid']) && is_string($pListHash['exclude_content_type_guid'])) { $whereSql .= " AND lc.`content_type_guid` != ?"; $bindVars[] = $pListHash['exclude_content_type_guid']; } elseif (!empty($pListHash['exclude_content_type_guid']) && is_array($pListHash['exclude_content_type_guid'])) { $whereSql .= " AND lc.`content_type_guid` NOT IN ( " . implode(',', array_fill(0, count($pListHash['exclude_content_type_guid']), '?')) . " )"; $bindVars = array_merge($bindVars, $pListHash['exclude_content_type_guid']); } // only display content modified more recently than this (UTC timestamp) if (!empty($pListHash['from_date'])) { $whereSql .= ' AND lc.`last_modified` >= ?'; $bindVars[] = $pListHash['from_date']; } // only display content modified before this (UTC timestamp) if (!empty($pListHash['until_date'])) { $whereSql .= ' AND lc.`last_modified` <= ?'; $bindVars[] = $pListHash['until_date']; } // Should results be hashed or sequential indexed $hashKeySql = ''; if (!empty($pListHash['hash_key'])) { $hashKeySql = $pListHash['hash_key'] . ' AS `hash_key`, '; } if ($gBitSystem->isPackageActive('gatekeeper')) { if ($gBitSystem->isPackageActive('fisheye')) { // This is really ugly to have in here, and really would be better off somewhere else. // However, because of the specific nature of the current implementation of fisheye galleries, I am afraid // this is the only place it can go to properly enforce gatekeeper protections. Hopefully a new content generic // solution will be available in ReleaseTwo - spiderr if ($this->mDb->isAdvancedPostgresEnabled()) { // $joinSql .= " LEFT OUTER JOIN `".BIT_DB_PREFIX."fisheye_gallery_image_map` fgim ON (fgim.`item_content_id`=lc.`content_id`)"; $whereSql .= " AND (SELECT ls.`security_id` FROM connectby('fisheye_gallery_image_map', 'gallery_content_id', 'item_content_id', 'item_content_id', text( lc.`content_id` ), 0, '/') AS t(`cb_gallery_content_id` int, `cb_item_content_id` int, level int, branch text, pos int), `" . BIT_DB_PREFIX . "gatekeeper_security_map` cgm, `" . BIT_DB_PREFIX . "gatekeeper_security` ls\n\t\t\t\t\t\t\tWHERE ls.`security_id`=cgm.`security_id` AND cgm.`content_id`=`cb_gallery_content_id` LIMIT 1) IS NULL"; } } } $sortHash = array('content_id_desc', 'content_id_asc', 'modifier_user_desc', 'modifier_user_asc', 'modifier_real_name_desc', 'modifier_real_name_asc', 'creator_user_desc', 'creator_user_asc', 'creator_real_name_desc', 'creator_real_name_asc'); if (in_array($pListHash['sort_mode'], $sortHash)) { $orderTable = ''; } elseif (!empty($pListHash['order_table'])) { $orderTable = $pListHash['order_table']; } elseif (!empty($pListHash['sort_mode']) && strtolower(substr($pListHash['sort_mode'], 0, 4)) == 'hits') { $orderTable = 'lch.'; } elseif (strpos($pListHash['sort_mode'], '.')) { // do not specifiy orderTable of sort_mode already has a . in it $orderTable = ''; } else { $orderTable = 'lc.'; } if (!empty($hashSql['where'])) { $whereSql .= ' AND ' . implode(' ', $hashSql['where']); } if (!empty($hashBindVars['where'])) { $bindVars = array_merge($bindVars, $hashBindVars['where']); } $whereSql = preg_replace('/^[\\s]*AND\\b/i', 'WHERE ', $whereSql); // If sort mode is versions then offset is 0, max_records is -1 (again) and sort_mode is nil // If sort mode is links then offset is 0, max_records is -1 (again) and sort_mode is nil // If sort mode is backlinks then offset is 0, max_records is -1 (again) and sort_mode is nil $query = "\n\t\t\tSELECT\n\t\t\t\t{$hashKeySql}\n\t\t\t\tuue.`login` AS `modifier_user`,\n\t\t\t\tuue.`real_name` AS `modifier_real_name`,\n\t\t\t\tuue.`user_id` AS `modifier_user_id`,\n\t\t\t\tuuc.`login` AS `creator_user`,\n\t\t\t\tuuc.`real_name` AS `creator_real_name`,\n\t\t\t\tuuc.`user_id` AS `creator_user_id`,\n\t\t\t\tlch.`hits`,\n\t\t\t\tlch.`last_hit`,\n\t\t\t\tlc.`event_time`,\n\t\t\t\tlc.`title`,\n\t\t\t\tlc.`last_modified`,\n\t\t\t\tlc.`content_type_guid`,\n\t\t\t\tlc.`ip`,\n\t\t\t\tlc.`created`,\n\t\t\t\tlc.`content_id`,\n\t\t\t\tlcds.`data` AS `summary`\n\t\t\t\t{$selectSql}\n\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_content` lc\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON (lc.`user_id`=uuc.`user_id`)\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uue ON (lc.`modifier_user_id`=uue.`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\t{$joinSql}\n\t\t\t\t{$whereSql}\n\t\t\tORDER BY " . $orderTable . $this->convertSortMode($pListHash['sort_mode']); $query_cant = "\n\t\t\tSELECT\n\t\t\t\tCOUNT(lc.`content_id`)\n\t\t\tFROM `" . BIT_DB_PREFIX . "liberty_content` lc\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (lc.`modifier_user_id`=uu.`user_id`)\n\t\t\t{$joinSql}\n\t\t\t{$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; } if (!empty($hashBindVars['select'])) { $bindVars = array_merge($hashBindVars['select'], $bindVars); } $result = $this->mDb->query($query, $bindVars, $pListHash['max_records'], $pListHash['offset']); $ret = array(); $contentTypes = $gLibertySystem->mContentTypes; while ($aux = $result->fetchRow()) { if (!empty($contentTypes[$aux['content_type_guid']])) { // quick alias for code readability $type =& $contentTypes[$aux['content_type_guid']]; $aux['content_name'] = $type['content_name']; $aux['creator'] = isset($aux['creator_real_name']) ? $aux['creator_real_name'] : $aux['creator_user']; $aux['real_name'] = isset($aux['creator_real_name']) ? $aux['creator_real_name'] : $aux['creator_user']; $aux['editor'] = isset($aux['modifier_real_name']) ? $aux['modifier_real_name'] : $aux['modifier_user']; $aux['user'] = $aux['creator_user']; $aux['user_id'] = $aux['creator_user_id']; if (!empty($gBitSystem->mPackages[$type['handler_package']])) { include_once $gBitSystem->mPackages[$type['handler_package']]['path'] . $type['handler_file']; if ($aux['content_type_guid'] == BITUSER_CONTENT_TYPE_GUID) { // here we provide getDisplay(Link|Url) with user-specific information that we get the correct links to display in pages $userInfo = $gBitUser->getUserInfo(array('content_id' => $aux['content_id'])); $aux['title'] = $type['handler_class']::getTitleFromHash($userInfo); $aux['display_link'] = $type['handler_class']::getDisplayLink($userInfo['login'], $userInfo); $aux['display_url'] = $type['handler_class']::getDisplayUrl($userInfo['login']); } else { $aux['title'] = $type['handler_class']::getTitleFromHash($aux); $aux['display_link'] = $type['handler_class']::getDisplayLink($aux['title'], $aux); /** * @TODO standardize getDisplayUrl params * nice try, but you can't do this because individual classes have gone off the reservation changing the params they accept * for distributed packages we need to enforce that method overrides all take the same basic params. **/ // $aux['display_url'] = $type['content_object']->getDisplayUrl( NULL, $aux ); $aux['display_url'] = BIT_ROOT_URL . "index.php?content_id=" . $aux['content_id']; } if (!empty($pListHash['thumbnail_size'])) { $aux['content_object'] = static::getLibertyObject($aux['content_id'], $aux['content_type_guid']); if ($aux['content_object']->load(FALSE)) { $aux['thumbnail_url'] = $aux['content_object']->getThumbnailUrl($pListHash['thumbnail_size']); } } } /** * @TODO standardize use of thumbnail_url and provision for hash of thumbnail sizes * * We have a bit of a mess with the use of thumbnail_url where sometimes it is a hash of sizes, and sometimes it is a single size * we should standardize the param and what kind of value it returns, and if we need both types then have two params. * This ultimately might need to be more sophisticated to deal with different mime types. **/ if ($gBitSystem->isFeatureActive('liberty_display_primary_attach')) { $aux['thumbnail_urls'] = liberty_fetch_thumbnails($aux); } if (isset($aux['hash_key'])) { $ret[$aux['hash_key']] = $aux; } else { $ret[] = $aux; } } } // If sortmode is versions, links or backlinks sort using the ad-hoc function and reduce using old_offse and old_max_records if ($old_sort_mode == 'versions_asc' && !empty($ret['versions'])) { usort($ret, 'compare_versions'); } if ($old_sort_mode == 'versions_desc' && !empty($ret['versions'])) { usort($ret, 'r_compare_versions'); } if ($old_sort_mode == 'links_desc' && !empty($ret['links'])) { usort($ret, 'compare_links'); } if ($old_sort_mode == 'links_asc' && !empty($ret['links'])) { usort($ret, 'r_compare_links'); } if ($old_sort_mode == 'backlinks_desc' && !empty($ret['backlinks'])) { usort($ret, 'compare_backlinks'); } if ($old_sort_mode == 'backlinks_asc' && !empty($ret['backlinks'])) { usort($ret, 'r_compare_backlinks'); } if (in_array($old_sort_mode, array('versions_desc', 'versions_asc', 'links_asc', 'links_desc', 'backlinks_asc', 'backlinks_desc'))) { $ret = array_slice($ret, $old_offset, $old_max_records); } LibertyContent::postGetList($pListHash); return $ret; }
function getBlog($pBlogId, $pContentId = NULL) { global $gBitSystem; $ret = NULL; $lookupId = !empty($pBlogId) ? $pBlogId : $pContentId; $lookupColumn = !empty($pBlogId) ? 'blog_id' : 'content_id'; $bindVars = array((int) $lookupId); $selectSql = ''; $joinSql = ''; $whereSql = ''; $this->getServicesSql('content_load_sql_function', $selectSql, $joinSql, $whereSql, $bindVars); if (BitBase::verifyId($lookupId)) { $query = "\n\t\t\t\tSELECT b.*, lc.*, lch.`hits`, uu.`login`, uu.`login`, uu.`user_id`, 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\t\t\t{$selectSql}\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "blogs` b\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON (lc.`content_id` = b.`content_id`)\n\t\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uu ON (uu.`user_id` = lc.`user_id`)\n\t\t\t\t\t{$joinSql}\n\t\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_content_hits` lch ON (lc.`content_id` = lch.`content_id`)\n\t\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\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files`\t lfa ON lfa.`file_id`\t\t = laa.`foreign_id`\n\t\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\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lfp ON lfp.`file_id` = lap.`foreign_id`\n\t\t\t\tWHERE b.`{$lookupColumn}`= ? {$whereSql}"; if ($this->mInfo = $this->mDb->getRow($query, $bindVars)) { $this->mContentId = $this->getField('content_id'); $this->mBlogId = $this->getField('blog_id'); foreach (array('avatar', 'image') as $img) { $this->mInfo[$img] = liberty_fetch_thumbnails(array('source_file' => $this->getSourceFile(array('user_id' => $this->getField('user_id'), 'package' => liberty_mime_get_storage_sub_dir_name(array('type' => $this->getField($img . '_mime_type'), 'name' => $this->getField($img . '_file_name'))), 'file_name' => basename($this->mInfo[$img . '_file_name']), 'sub_dir' => $this->getField($img . '_attachment_id'))))); } parent::load(); $this->mInfo['postscant'] = $this->getPostsCount($this->mContentId); } } return count($this->mInfo) != 0; }
/** * Get the URL for any given article image * @param $pParamHash pass in full set of data returned from article query * @return url to image * @access public **/ public static function getImageThumbnails($pParamHash) { global $gBitSystem, $gThumbSizes; $ret = NULL; $thumbHash['mime_image'] = FALSE; if (!empty($pParamHash['image_attachment_path'])) { $thumbHash['source_file'] = $pParamHash['image_attachment_path']; $ret = liberty_fetch_thumbnails($thumbHash); } elseif (!empty($pParamHash['has_topic_image']) && $pParamHash['has_topic_image'] == 'y') { $thumbHash['source_file'] = preg_replace("#^/+#", "", BitArticleTopic::getTopicImageStorageUrl($pParamHash['topic_id'])); $ret = liberty_fetch_thumbnails($thumbHash); } return $ret; }
/** * This function generates a list of records from the liberty_content database for use in a list page **/ function getList(&$pParamHash) { global $gBitSystem, $gBitUser; // this makes sure parameters used later on are set 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); if (isset($pParamHash['user_id'])) { $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "users_groups_map` ugm ON (g.`group_id` = ugm.`group_id`)"; $whereSql .= " AND ugm.`user_id` = ?"; $bindVars[] = $pParamHash['user_id']; } if (isset($pParamHash['mapped_content_id'])) { $joinSql .= " INNER JOIN `" . BIT_DB_PREFIX . "groups_content_cnxn_map` gccm1 ON (g.`content_id` = gccm1.`group_content_id`)"; $whereSql .= " AND gccm1.`to_content_id` = ?"; $bindVars[] = $pParamHash['mapped_content_id']; } if (is_array($find)) { // you can use an array of groups $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) . '%'; } $query = "SELECT g.*, \n\t\t\tlc.`content_id`, \n\t\t\tlc.`title`, \n\t\t\tlc.`data`, \n\t\t\tlcds.`data` AS `summary`, \n\t\t\tlc.`content_type_guid`, \n\t\t\tlct.`content_name`, \n\t\t\tlct.`content_name_plural`, \n\t\t\tlc.`last_modified`, \n\t\t\tlc.`created`,\n\t\t\tlfp.file_name AS `image_attachment_path`, \n\t\t\tuue.`login` AS `modifier_user`,\n\t\t\tuue.`real_name` AS `modifier_real_name`,\n\t\t\tuue.`user_id` AS `modifier_user_id`,\n\t\t\tuuc.`login` AS `creator_user`,\n\t\t\tuuc.`real_name` AS `creator_real_name`,\n\t\t\tuuc.`user_id` AS `creator_user_id`,\n\t\t\tug.*, \n\t\t\tbrd.`board_id`\n\t\t\t{$selectSql}\n\t\t\tFROM `" . BIT_DB_PREFIX . "groups` g \n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( lc.`content_id` = g.`content_id` ) \n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content_types` lct ON (lc.`content_type_guid`=lct.`content_type_guid`)\n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_groups` ug ON( ug.`group_id` = g.`group_id` ) \n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON (lc.`user_id`=uuc.`user_id`)\n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_users` uue ON (lc.`modifier_user_id`=uue.`user_id`)\n\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\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_attachments` la ON( la.`content_id` = lc.`content_id` AND la.`is_primary` = 'y' ) \n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "liberty_files` lfp ON( lfp.`file_id` = la.`foreign_id` )\n\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "groups_content_cnxn_map` gccm ON ( lc.`content_id` = gccm.`group_content_id` )\n\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "boards` brd ON (gccm.`to_content_id` = brd.`content_id`)\n\t\t\t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}\n\t\t\tORDER BY " . $this->mDb->convertSortmode($sort_mode); $query_cant = "select count(*)\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "groups` g \n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON( lc.`content_id` = g.`content_id` )\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "users_groups` ug ON( ug.`group_id` = g.`group_id` ) \n\t\t\t \t{$joinSql}\n\t\t\tWHERE lc.`content_type_guid` = ? {$whereSql}"; $result = $this->mDb->query($query, $bindVars, $max_records, $offset); $ret = array(); while ($res = $result->fetchRow()) { $res['display_url'] = $this->getDisplayUrl($res); $res['num_members'] = $this->getMembersCount($res['group_id']); $res['thumbnail_url'] = liberty_fetch_thumbnails(array("storage_path" => $res['image_attachment_path'])); $res['display_urls'] = $this->getDisplayUrls($res); $ret[] = $res; } $pParamHash["cant"] = $this->mDb->getOne($query_cant, $bindVars); // add all pagination info to pParamHash LibertyContent::postGetList($pParamHash); return $ret; }
/** * Get list of all treasury galleries * * @param $pListHash contains array of items used to limit search results * @param $pListHash[sort_mode] column and orientation by which search results are sorted * @param $pListHash[find] search for a gallery title - case insensitive * @param $pListHash[max_records] maximum number of rows to return * @param $pListHash[offset] number of results data is offset by * @param $pListHash[title] gallery name * @param $pListHash[parent_id] gallery parent_id * @param $pListHash[get_sub_tree] get the subtree to every gallery * @access public * @return List of galleries **/ function getList(&$pListHash) { global $gBitDbType, $gBitSystem, $gBitUser; LibertyContent::prepGetList($pListHash); $ret = $bindVars = array(); $selectSql = $joinSql = $orderSql = $whereSql = ''; if (@BitBase::verifyId($pListHash['root_structure_id'])) { $whereSql .= empty($whereSql) ? ' WHERE ' : ' AND '; $whereSql .= " ls.`root_structure_id`=? "; $bindVars[] = $pListHash['root_structure_id']; } if (!empty($pListHash['get_sub_tree'])) { $whereSql .= empty($whereSql) ? ' WHERE ' : ' AND '; $whereSql .= " ls.`structure_id`=ls.`root_structure_id` "; } if (!empty($pListHash['find'])) { $whereSql .= empty($whereSql) ? ' WHERE ' : ' AND '; $whereSql .= " UPPER( lc.`title` ) LIKE ? "; $bindVars[] = '%' . strtoupper($pListHash['find']) . '%'; } if (isset($pListHash['parent_id'])) { $whereSql .= empty($whereSql) ? ' WHERE ' : ' AND '; $whereSql .= ' ls.`parent_id` = ? '; $bindVars[] = $pListHash['parent_id']; } if (!empty($pListHash['sort_mode'])) { $orderSql .= " ORDER BY " . $this->mDb->convertSortmode($pListHash['sort_mode']) . " "; } else { // default sort mode makes list look nice $orderSql .= " ORDER BY ls.`root_structure_id`, ls.`structure_id` ASC"; } // update query with service sql $this->getServicesSql('content_list_sql_function', $selectSql, $joinSql, $whereSql, $bindVars); // get the number of files in this gallery if ($gBitDbType != 'mysql' && $gBitDbType != 'mysqli') { $subselect = ", (\n\t\t\t\tSELECT COUNT( trm.`item_content_id` )\n\t\t\t\tFROM `" . BIT_DB_PREFIX . "treasury_map` trm\n\t\t\t\tWHERE trm.`gallery_content_id`=trg.`content_id`\n\t\t\t) AS item_count"; } else { $subselect = ""; } // don't fetch trg.`is_private` for list, because it conflicts with gks.is_private // and it's not used on list anyway $query = "\n\t\t\tSELECT trg.`content_id`, trg.`structure_id`,\n\t\t\tls.`root_structure_id`, ls.`parent_id`,\n\t\t\tlc.`title`, lc.`data`, lc.`user_id`, lc.`content_type_guid`, lc.`created`, lc.`format_guid`, lch.`hits`,\n\t\t\tuue.`login` AS modifier_user, uue.`real_name` AS modifier_real_name,\n\t\t\tuuc.`login` AS creator_user, uuc.`real_name` AS creator_real_name {$subselect} {$selectSql}\n\t\t\tFROM `" . BIT_DB_PREFIX . "treasury_gallery` trg\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON ( lc.`content_id` = trg.`content_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 . "users_users` uue ON ( uue.`user_id` = lc.`modifier_user_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON ( uuc.`user_id` = lc.`user_id` )\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_structures` ls ON ( ls.`structure_id` = trg.`structure_id` )\n\t\t\t\t{$joinSql}\n\t\t\t{$whereSql}\n\t\t\t{$orderSql}"; $result = $this->mDb->query($query, $bindVars, $pListHash['max_records'], $pListHash['offset']); if (!empty($pListHash['get_sub_tree'])) { $struct = new LibertyStructure(); } while ($aux = $result->fetchRow()) { $hasUserPerm = TRUE; // check to see if we have premissions to do someing specific with this gallery if (!empty($pListHash['content_permission'])) { $gal = new TreasuryGallery(NULL, $aux['content_id']); if (!$gal->hasUserPermission($pListHash['content_permission'])) { $hasUserPerm = FALSE; } } if ($hasUserPerm) { $content_ids[] = $aux['content_id']; $aux['user'] = $aux['creator_user']; $aux['real_name'] = isset($aux['creator_real_name']) ? $aux['creator_real_name'] : $aux['creator_user']; $aux['editor'] = isset($aux['modifier_real_name']) ? $aux['modifier_real_name'] : $aux['modifier_user']; $aux['display_name'] = BitUser::getDisplayNameFromHash(FALSE, $aux); $aux['display_url'] = self::getDisplayUrlFromHash($aux); $aux['display_link'] = $this->getDisplayLink($aux['title'], $aux); $aux['thumbnail_url'] = liberty_fetch_thumbnails(array('storage_path' => $this->getGalleryThumbBaseUrl($aux['content_id']), 'mime_image' => FALSE)); // deal with the parsing $parseHash['format_guid'] = $aux['format_guid']; $parseHash['content_id'] = $aux['content_id']; $parseHash['user_id'] = $aux['user_id']; $parseHash['data'] = $aux['data']; $aux['parsed_data'] = $this->parseData($parseHash); // sucky additional query to fetch item number without subselect if ($gBitDbType == 'mysql' || $gBitDbType == 'mysqli') { $item_count_query = "SELECT COUNT( trm.`item_content_id` ) FROM `" . BIT_DB_PREFIX . "treasury_map` trm WHERE trm.`gallery_content_id`=?"; $aux['item_count'] = $this->mDb->getOne($item_count_query, array($aux['content_id'])); } if (!empty($pListHash['get_sub_tree'])) { $aux['subtree'] = $struct->getSubTree($aux['structure_id']); } $ret[$aux['content_id']] = $aux; } } $query = "SELECT COUNT( lc.`title` )\n\t\t\tFROM `" . BIT_DB_PREFIX . "treasury_gallery` trg\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_content` lc ON ( lc.`content_id` = trg.`content_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_users` uue ON ( uue.`user_id` = lc.`modifier_user_id` )\n\t\t\t\tLEFT OUTER JOIN `" . BIT_DB_PREFIX . "users_users` uuc ON ( uuc.`user_id` = lc.`user_id` )\n\t\t\t\tINNER JOIN `" . BIT_DB_PREFIX . "liberty_structures` ls ON ( ls.`structure_id` = trg.`structure_id` )\n\t\t\t{$joinSql} {$whereSql}"; $pListHash['cant'] = $this->mDb->getOne($query, $bindVars); LibertyContent::postGetList($pListHash); return $ret; }
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; }
/** * Get the URL for any given action image * @param $pParamHash pass in full set of data returned from action query * @return url to image * @access public **/ function getImageThumbnails($pParamHash) { global $gBitSystem, $gThumbSizes; $ret = NULL; if (!empty($pParamHash['image_attachment_path'])) { $thumbHash = array('mime_image' => FALSE, 'storage_path' => $pParamHash['image_attachment_path']); $ret = liberty_fetch_thumbnails($thumbHash); $ret['original'] = "/" . $pParamHash['image_attachment_path']; } return $ret; }