/** * Prepare the MainList object for displaying skins. * * @param integer max # of posts on the page */ function init_MainList($items_nb_limit) { global $MainList; global $Blog; global $timestamp_min, $timestamp_max; global $preview; global $disp; global $postIDlist, $postIDarray; $MainList = new ItemList2($Blog, $timestamp_min, $timestamp_max, $items_nb_limit); // COPY (FUNC) if (!$preview) { if ($disp == 'page') { // Get pages: $MainList->set_default_filters(array('types' => '1000')); } // else: we are either in single or in page mode // pre_dump( $MainList->default_filters ); $MainList->load_from_Request(false); // pre_dump( $MainList->filters ); // echo '<br/>'.( $MainList->is_filtered() ? 'filtered' : 'NOT filtered' ); // $MainList->dump_active_filters(); // Run the query: $MainList->query(); // Old style globals for category.funcs: $postIDlist = $MainList->get_page_ID_list(); $postIDarray = $MainList->get_page_ID_array(); } else { // We want to preview a single post, we are going to fake a lot of things... $MainList->preview_from_request(); // Legacy for the category display $cat_array = array(); } param('more', 'integer', 0, true); param('page', 'integer', 1, true); // Post page to show param('c', 'integer', 0, true); // Display comments? param('tb', 'integer', 0, true); // Display trackbacks? param('pb', 'integer', 0, true); // Display pingbacks? }
/** * Initialize list mode; Several actions need this. */ function init_list_mode() { global $tab, $Blog, $UserSettings, $ItemList, $AdminUI, $posttypes_perms; // set default itemslist param prefix $items_list_param_prefix = 'items_'; if (param('p', 'integer', NULL) || param('title', 'string', NULL)) { // Single post requested, do not filter any post types. If the user // has clicked a post link on the dashboard and previously has selected // a tab which would filter this post, it wouldn't be displayed now. $tab = 'full'; // in case of single item view params prefix must be empty $items_list_param_prefix = NULL; } else { // Store/retrieve preferred tab from UserSettings: $UserSettings->param_Request('tab', 'pref_browse_tab', 'string', NULL, true, true); } /* * Init list of posts to display: */ load_class('items/model/_itemlist.class.php', 'ItemList2'); if (!empty($tab) && !empty($items_list_param_prefix)) { // Use different param prefix for each tab $items_list_param_prefix .= substr($tab, 0, 7) . '_'; } // Create empty List: $ItemList = new ItemList2($Blog, NULL, NULL, $UserSettings->get('results_per_page'), 'ItemCache', $items_list_param_prefix, $tab); // COPY (func) $ItemList->set_default_filters(array('visibility_array' => get_visibility_statuses('keys'))); if ($Blog->get_setting('orderby') == 'RAND') { // Do not display random posts in backoffice for easy management $ItemList->set_default_filters(array('orderby' => 'datemodified')); } switch ($tab) { case 'full': $ItemList->set_default_filters(array('types' => NULL)); // $AdminUI->breadcrumbpath_add( T_('All items'), '?ctrl=items&blog=$blog$&tab='.$tab.'&filter=restore' ); // require colorbox js require_js_helper('colorbox'); break; case 'manual': if ($Blog->get('type') != 'manual') { // Display this tab only for manual blogs global $admin_url; header_redirect($admin_url . '?ctrl=items&blog=' . $Blog->ID . '&tab=list&filter=restore'); } $AdminUI->breadcrumbpath_add(T_('Manual Pages'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'list': // Nothing special $AdminUI->breadcrumbpath_add(T_('Regular posts'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'pages': $ItemList->set_default_filters(array('types' => implode(',', $posttypes_perms['page']))); $AdminUI->breadcrumbpath_add(T_('Pages'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'intros': $ItemList->set_default_filters(array('types' => implode(',', $posttypes_perms['intro']))); $AdminUI->breadcrumbpath_add(T_('Intro posts'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'podcasts': $ItemList->set_default_filters(array('types' => implode(',', $posttypes_perms['podcast']))); $AdminUI->breadcrumbpath_add(T_('Podcasts'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'links': $ItemList->set_default_filters(array('types' => '3000')); $AdminUI->breadcrumbpath_add(T_('Links'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'ads': $ItemList->set_default_filters(array('types' => '4000')); $AdminUI->breadcrumbpath_add(T_('Advertisements'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'tracker': // In tracker mode, we want a different default sort: $ItemList->set_default_filters(array('orderby' => 'priority', 'order' => 'ASC')); break; default: // Delete the pref_browse_tab setting so that the default // (full) gets used the next time the user wants to browse // a blog and we don't run into the same error again. $UserSettings->delete('pref_browse_tab'); $UserSettings->dbupdate(); debug_die('Unknown filterset [' . $tab . ']'); } // Init filter params: if (!$ItemList->load_from_Request()) { // If we could not init a filterset from request // typically happens when we could no fall back to previously saved filterset... // echo ' no filterset!'; } }
/** * Return an Item if an Intro or a Featured item is available for display in current disp. * * @return Item */ function &get_featured_Item() { global $Blog; global $disp, $disp_detail, $MainList, $FeaturedList; global $featured_displayed_item_IDs; if ($disp != 'posts' || !isset($MainList)) { // If we're not currently displaying posts, no need to try & display a featured/intro post on top! $Item = NULL; return $Item; } if (!isset($FeaturedList)) { // Don't repeat if we've done this already -- Initialize the featured list only first time this function is called in a skin: // Get ready to obtain 1 post only: $FeaturedList = new ItemList2($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 1); // Set default filters for the current page: $FeaturedList->set_default_filters($MainList->filters); if (!$MainList->is_filtered()) { // This is not a filtered page, so we are on the home page. // The competing intro-* types are: 'main' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1500,1600'; } else { // We are on a filtered... it means a category page or sth like this... // echo $disp_detail; switch ($disp_detail) { case 'posts-cat': case 'posts-subcat': // The competing intro-* types are: 'cat' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1520,1600'; break; case 'posts-tag': // The competing intro-* types are: 'tag' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1530,1600'; break; default: // The competing intro-* types are: 'sub' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1570,1600'; } } $FeaturedList->set_filters(array('types' => $restrict_to_types), false); // pre_dump( $FeaturedList->filters ); // Run the query: $FeaturedList->query(); if ($FeaturedList->result_num_rows == 0) { // No Intro page was found, try to find a featured post instead: $FeaturedList->reset(); $FeaturedList->set_filters(array('featured' => 1), false); // Run the query: $FeaturedList->query(); } } // Get next featured item $Item = $FeaturedList->get_item(); if ($Item) { // Memorize that ID so that it can later be filtered out normal display: $featured_displayed_item_IDs[] = $Item->ID; } return $Item; }
/** * Display a button to view the Recent/New Topics */ function display_button_recent_topics() { global $Blog; if (!is_logged_in() || !$Blog->get_setting('track_unread_content')) { // For not logged in users AND if the tracking of unread content is turned off for the collection $btn_class = 'btn-info'; $btn_title = T_('Recent Topics'); } else { // For logged in users: global $current_User, $DB, $localtimenow; // Initialize SQL query to get only the posts which are displayed by global $MainList on disp=posts: $ItemList2 = new ItemList2($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), NULL, 'ItemCache', 'recent_topics'); $ItemList2->set_default_filters(array('unit' => 'all')); $ItemList2->query_init(); // Get a count of the unread topics for current user: $unread_posts_SQL = new SQL(); $unread_posts_SQL->SELECT('COUNT( post_ID )'); $unread_posts_SQL->FROM('T_items__item'); $unread_posts_SQL->FROM_add('LEFT JOIN T_users__postreadstatus ON post_ID = uprs_post_ID AND uprs_user_ID = ' . $DB->quote($current_User->ID)); $unread_posts_SQL->FROM_add('INNER JOIN T_categories ON post_main_cat_ID = cat_ID'); $unread_posts_SQL->WHERE($ItemList2->ItemQuery->get_where('')); $unread_posts_SQL->WHERE_and('post_last_touched_ts > ' . $DB->quote(date2mysql($localtimenow - 30 * 86400))); // In theory, it would be more safe to use this comparison: // $unread_posts_SQL->WHERE_and( 'uprs_post_ID IS NULL OR uprs_read_post_ts <= post_last_touched_ts' ); // But until we have milli- or micro-second precision on timestamps, we decided it was a better trade-off to never see our own edits as unread. So we use: $unread_posts_SQL->WHERE_and('uprs_post_ID IS NULL OR uprs_read_post_ts < post_last_touched_ts'); // Execute a query with to know if current user has new data to view: $unread_posts_count = $DB->get_var($unread_posts_SQL->get(), 0, NULL, 'Get a count of the unread topics for current user'); if ($unread_posts_count > 0) { // If at least one new unread topic exists $btn_class = 'btn-warning'; $btn_title = T_('New Topics') . ' <span class="badge">' . $unread_posts_count . '</span>'; } else { // Current user already have read all topics $btn_class = 'btn-info'; $btn_title = T_('Recent Topics'); } } // Print out the button: echo '<a href="' . $Blog->get('recentpostsurl') . '" class="btn ' . $btn_class . ' pull-right btn_recent_topics">' . $btn_title . '</a>'; }
/** * If an Intro Post is available, return it. If not, see if a Featured Post is available and return it. * * Note: this will set the global $FeaturedList which may be used to obtain several featured Items. * * @param string Name of $disp where we should display it * @param string Collection IDs: * NULL: depend on blog setting "Collections to aggregate" * empty: current blog only * "*": all blogs * "1,2,3":blog IDs separated by comma * "-": current blog only and exclude the aggregated blogs * @return Item */ function &get_featured_Item($restrict_disp = 'posts', $coll_IDs = NULL) { global $Blog, $cat; global $disp, $disp_detail, $MainList, $FeaturedList; global $featured_displayed_item_IDs; if ($disp != $restrict_disp || !isset($MainList)) { // If we're not currently displaying posts, no need to try & display a featured/intro post on top! $Item = NULL; return $Item; } if (!isset($FeaturedList)) { // Don't repeat if we've done this already -- Initialize the featured list only first time this function is called in a skin: // Get ready to obtain 1 post only: $FeaturedList = new ItemList2($Blog, $Blog->get_timestamp_min(), $Blog->get_timestamp_max(), 1); $featured_list_filters = $MainList->filters; if (!empty($cat)) { // Get a featured post only of the selected category and don't touch the posts of the child categories: $featured_list_filters['cat_array'] = array($cat); } // Set default filters for the current page: $FeaturedList->set_default_filters($featured_list_filters); // FIRST: Try to find an Intro post: if (!$MainList->is_filtered()) { // This is not a filtered page, so we are on the home page. if ($restrict_disp == 'front') { // Special Front page: // Use Intro-Front posts $restrict_to_types = '1400'; } else { // Default front page displaying posts: // The competing intro-* types are: 'main' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1500,1600'; } } else { // We are on a filtered... it means a category page or sth like this... // echo $disp_detail; switch ($disp_detail) { case 'posts-cat': case 'posts-subcat': // The competing intro-* types are: 'cat' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1520,1600'; break; case 'posts-tag': // The competing intro-* types are: 'tag' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1530,1600'; break; default: // The competing intro-* types are: 'sub' and 'all': // fplanque> IMPORTANT> nobody changes this without consulting the manual and talking to me first! $restrict_to_types = '1570,1600'; } } $FeaturedList->set_filters(array('coll_IDs' => $coll_IDs, 'types' => $restrict_to_types), false); // pre_dump( $FeaturedList->filters ); // Run the query: $FeaturedList->query(); // SECOND: If no Intro, try to find an Featured post: if ($FeaturedList->result_num_rows == 0 && $restrict_disp != 'front') { // No Intro page was found, try to find a featured post instead: $FeaturedList->reset(); $FeaturedList->set_filters(array('coll_IDs' => $coll_IDs, 'featured' => 1), false); // Run the query: $FeaturedList->query(); } } // Get first Item in the result set. $Item = $FeaturedList->get_item(); if ($Item) { // Memorize that ID so that it can later be filtered out of normal display: $featured_displayed_item_IDs[] = $Item->ID; } return $Item; }
/** * Initialize list mode; Several actions need this. */ function init_list_mode() { global $tab, $tab_type, $Blog, $UserSettings, $ItemList, $AdminUI; // set default itemslist param prefix $items_list_param_prefix = 'items_'; if (param('p', 'integer', NULL) || param('title', 'string', NULL)) { // Single post requested, do not filter any post types. If the user // has clicked a post link on the dashboard and previously has selected // a tab which would filter this post, it wouldn't be displayed now. $tab = 'full'; // in case of single item view params prefix must be empty $items_list_param_prefix = NULL; } else { // Store/retrieve preferred tab from UserSettings: $UserSettings->param_Request('tab', 'pref_browse_tab', 'string', NULL, true, true); $UserSettings->param_Request('tab_type', 'pref_browse_tab_type', 'string', NULL, true, true); } if ($tab == 'tracker' && !$Blog->get_setting('use_workflow')) { // Display workflow view only if it is enabled global $Messages; $Messages->add(T_('Workflow feature has not been enabled for this collection.'), 'note'); $tab = 'full'; } /* * Init list of posts to display: */ load_class('items/model/_itemlist.class.php', 'ItemList2'); if (!empty($tab) && !empty($items_list_param_prefix)) { // Use different param prefix for each tab $items_list_param_prefix .= substr($tab, 0, 7) . '_'; //.utf8_strtolower( $tab_type ).'_'; } // Set different filterset name for each different tab and tab_type $filterset_name = $tab == 'type' ? $tab . '_' . utf8_strtolower($tab_type) : $tab; // Create empty List: $ItemList = new ItemList2($Blog, NULL, NULL, $UserSettings->get('results_per_page'), 'ItemCache', $items_list_param_prefix, $filterset_name); // COPY (func) $ItemList->set_default_filters(array('visibility_array' => get_visibility_statuses('keys'))); if ($Blog->get_setting('orderby') == 'RAND') { // Do not display random posts in backoffice for easy management $ItemList->set_default_filters(array('orderby' => 'datemodified')); } switch ($tab) { case 'full': $ItemList->set_default_filters(array('types' => NULL)); // $AdminUI->breadcrumbpath_add( T_('All items'), '?ctrl=items&blog=$blog$&tab='.$tab.'&filter=restore' ); // require colorbox js require_js_helper('colorbox'); $AdminUI->breadcrumbpath_add(T_('All'), '?ctrl=items&blog=$blog$&tab=full&filter=restore'); break; case 'manual': if ($Blog->get('type') != 'manual') { // Display this tab only for manual blogs global $admin_url; header_redirect($admin_url . '?ctrl=items&blog=' . $Blog->ID . '&tab=type&tab_type=posts&filter=restore'); } global $ReqURI, $blog; init_field_editor_js(array('action_url' => $ReqURI . '&blog=' . $blog . '&order_action=update&order_data=')); $AdminUI->breadcrumbpath_add(T_('Manual view'), '?ctrl=items&blog=$blog$&tab=' . $tab . '&filter=restore'); break; case 'type': // Filter a posts list by type $ItemList->set_default_filters(array('types' => get_item_types_by_tab($tab_type))); $AdminUI->breadcrumbpath_add(T_($tab_type), '?ctrl=items&blog=$blog$&tab=' . $tab . '&tab_type=' . urlencode($tab_type) . '&filter=restore'); break; case 'tracker': // In tracker mode, we want a different default sort: $ItemList->set_default_filters(array('orderby' => 'priority', 'order' => 'ASC')); $AdminUI->breadcrumbpath_add(T_('Workflow view'), '?ctrl=items&blog=$blog$&tab=tracker&filter=restore'); $AdminUI->set_page_manual_link('workflow-features'); // JS to edit priority of items from list view require_js('jquery/jquery.jeditable.js', 'rsc_url'); break; default: // Delete the pref_browse_tab setting so that the default // (full) gets used the next time the user wants to browse // a blog and we don't run into the same error again. $UserSettings->delete('pref_browse_tab'); $UserSettings->dbupdate(); debug_die('Unknown filterset [' . $tab . ']'); } // Init filter params: if (!$ItemList->load_from_Request()) { // If we could not init a filterset from request // typically happens when we could no fall back to previously saved filterset... // echo ' no filterset!'; } }
/** * Initialize list mode; Several actions need this. */ function init_list_mode() { global $tab, $Blog, $UserSettings, $ItemList; // Store/retrieve preferred tab from UserSettings: $UserSettings->param_Request('tab', 'pref_browse_tab', 'string', NULL, true); /* * Init list of posts to display: */ load_class('items/model/_itemlist.class.php'); // Create empty List: $ItemList = new ItemList2($Blog, NULL, NULL, $UserSettings->get('results_per_page')); // COPY (func) $ItemList->set_default_filters(array('visibility_array' => array('published', 'protected', 'private', 'draft', 'deprecated', 'redirected'), 'types' => NULL)); if ($tab == 'tracker') { // In tracker mode, we want a different default sort: $ItemList->set_default_filters(array('orderby' => 'priority', 'order' => 'ASC')); } // Init filter params: if (!$ItemList->load_from_Request()) { // If we could not init a filterset from request // typically happens when we could no fall back to previously saved filterset... // echo ' no filterset!'; } }