/** * Display chapter and children * * @param array Params * @param integer Level of the category in the recursive tree */ function manual_display_chapter($params = array(), $level = 0) { $params = array_merge(array('Chapter' => NULL, 'chapter_path' => array()), $params); global $Blog; if (empty($params['Chapter'])) { // No Chapter, Exit here return; } $Chapter =& $params['Chapter']; $is_selected = false; $is_opened = false; $classes = array(); if (!empty($params['chapter_path']) && in_array($Chapter->ID, $params['chapter_path'])) { // A category is selected $is_selected = true; } if (!empty($Chapter->children) && $is_selected) { // A category is opened $is_opened = true; } else { if ($Chapter->has_posts() && $is_selected) { // A category is selected and it has the posts $is_opened = true; } } manual_display_chapter_row($Chapter, $level, $is_opened); if ($is_selected) { global $Settings; if ($Settings->get('chapter_ordering') == 'manual' && $Blog->get_setting('orderby') == 'order' && $Blog->get_setting('orderdir') == 'ASC') { // Items & categories are ordered by manual field 'order' // In this mode we should show them in one merged list ordered by field 'order' $chapters_items_mode = 'order'; } else { // Standard mode for all other cases $chapters_items_mode = 'std'; } if ($chapters_items_mode != 'order') { // Display all subchapters manual_display_chapters(array_merge($params, array('parent_cat_ID' => $Chapter->ID)), $level + 1); } if ($Chapter->has_posts() || $is_opened) { // Display the posts/subcategories of this chapter manual_display_posts(array_merge($params, array('chapter_ID' => $Chapter->ID, 'chapters_items_mode' => $chapters_items_mode)), $level + 1); } } }
/** * Display the manual pages results table * * @param array Params */ function items_manual_results_block($params = array()) { // Make sure we are not missing any param: $params = array_merge(array('results_param_prefix' => 'items_manual_'), $params); if (!is_logged_in()) { // Only logged in users can access to this function return; } global $current_User, $blog, $Blog, $admin_url, $Session; $result_fadeout = $Session->get('fadeout_array'); $cat_ID = param('cat_ID', 'integer', 0, true); if (empty($Blog)) { // Init Blog $BlogCache =& get_BlogCache(); $blog = get_param('blog'); if (!empty($blog)) { // Get Blog by ID $Blog = $BlogCache->get_by_ID($blog, false); } if (empty($Blog) && !empty($cat_ID)) { // Get Blog from chapter ID $ChapterCache =& get_ChapterCache(); if ($Chapter =& $ChapterCache->get_by_ID($cat_ID, false)) { $Blog = $Chapter->get_Blog(); $blog = $Blog->ID; } } } if (empty($Blog) || $Blog->get('type') != 'manual') { // No Blog, Exit here return; } if (is_ajax_content()) { $order_action = param('order_action', 'string'); if ($order_action == 'update') { // Update an order to new value $new_value = (int) param('new_value', 'string', 0); $order_data = param('order_data', 'string'); $order_data = explode('-', $order_data); $order_obj_ID = (int) $order_data[2]; if ($order_obj_ID > 0) { switch ($order_data[1]) { case 'chapter': // Update chapter order $ChapterCache =& get_ChapterCache(); if ($updated_Chapter =& $ChapterCache->get_by_ID($order_obj_ID, false)) { if ($current_User->check_perm('blog_cats', '', false, $updated_Chapter->blog_ID)) { // Check permission to edit this Chapter $updated_Chapter->set('order', $new_value); $updated_Chapter->dbupdate(); $ChapterCache->clear(); } } break; case 'item': // Update item order $ItemCache =& get_ItemCache(); if ($updated_Item =& $ItemCache->get_by_ID($order_obj_ID, false)) { if ($current_User->check_perm('item_post!CURSTATUS', 'edit', false, $updated_Item)) { // Check permission to edit this Item $updated_Item->set('order', $new_value); $updated_Item->dbupdate(); } } break; } } } } load_class('_core/ui/_uiwidget.class.php', 'Table'); $Table = new Table('Results', $params['results_param_prefix']); $Table->title = T_('Manual view'); // Redirect to manual pages after adding chapter $redirect_page = '&redirect_page=manual'; $Table->global_icon(T_('Add new chapter...'), 'add', $admin_url . '?ctrl=chapters&action=new&blog=' . $blog . $redirect_page, ' ' . T_('Add top level chapter') . ' »', 3, 4); $Table->cols[] = array('th' => T_('Name')); $Table->cols[] = array('th' => T_('URL "slug"')); $Table->cols[] = array('th' => T_('Order'), 'th_class' => 'shrinkwrap'); $Table->cols[] = array('th' => T_('Actions')); if (is_ajax_content()) { // init results param by template name if (!isset($params['skin_type']) || !isset($params['skin_name'])) { debug_die('Invalid ajax results request!'); } $Table->init_params_by_skin($params['skin_type'], $params['skin_name']); } $Table->display_init(NULL, $result_fadeout); echo $Table->params['before']; $Table->display_head(); echo $Table->replace_vars($Table->params['content_start']); $Table->display_list_start(); $Table->display_col_headers(); $Table->display_body_start(); manual_display_chapters(); $Table->display_body_end(); $Table->display_list_end(); // Flush fadeout $Session->delete('fadeout_array'); echo $Table->params['content_end']; echo $Table->params['after']; if (!is_ajax_content()) { // Create this hidden div to get a function name for AJAX request echo '<div id="' . $params['results_param_prefix'] . 'ajax_callback" style="display:none">' . __FUNCTION__ . '</div>'; } }