/** * Allow recursive category selection. * * @todo Allow to use a dropdown (select) to switch between blogs ( CSS / JS onchange - no submit.. ) * * @param Form * @param boolean true: use form fields, false: display only * @param boolean true: show links for add new category & manual * @param array Params */ function cat_select($Form, $form_fields = true, $show_title_links = true, $params = array()) { global $cache_categories, $blog, $current_blog_ID, $current_User, $edited_Item, $cat_select_form_fields; global $cat_sel_total_count, $dispatcher; global $rsc_url; if (get_post_cat_setting($blog) < 1) { // No categories for $blog return; } $params = array_merge(array('categories_name' => T_('Categories')), $params); $cat = param('cat', 'integer', 0); if (empty($edited_Item->ID) && !empty($cat)) { // If the GET param 'cat' is defined we should preselect the category for new created post global $post_extracats; $post_extracats = array($cat); $edited_Item->main_cat_ID = $cat; } if ($show_title_links) { // Use in Back-office $fieldset_title = get_newcategory_link() . $params['categories_name'] . get_manual_link('item_categories_fieldset'); } else { $fieldset_title = $params['categories_name']; } $Form->begin_fieldset($fieldset_title, array('class' => 'extracats', 'id' => 'itemform_categories')); $cat_sel_total_count = 0; $r = ''; $cat_select_form_fields = $form_fields; cat_load_cache(); // make sure the caches are loaded $r .= '<table cellspacing="0" class="catselect">'; if (get_post_cat_setting($blog) == 3) { // Main + Extra cats option is set, display header $r .= cat_select_header($params); } if (get_allow_cross_posting() >= 2 || isset($blog) && get_post_cat_setting($blog) > 1 && get_allow_cross_posting() == 1) { // If BLOG cross posting enabled, go through all blogs with cats: /** * @var BlogCache */ $BlogCache =& get_BlogCache(); /** * @var Blog */ for ($l_Blog =& $BlogCache->get_first(); !is_null($l_Blog); $l_Blog =& $BlogCache->get_next()) { // run recursively through the cats if (!blog_has_cats($l_Blog->ID)) { continue; } if (!$current_User->check_perm('blog_post_statuses', 'edit', false, $l_Blog->ID)) { continue; } $r .= '<tr class="group" id="catselect_blog' . $l_Blog->ID . '"><td colspan="3">' . $l_Blog->dget('name') . "</td></tr>\n"; $cat_sel_total_count++; // the header uses 1 line $current_blog_ID = $l_Blog->ID; // Global needed in callbacks $r .= cat_children($cache_categories, $l_Blog->ID, NULL, 'cat_select_before_first', 'cat_select_before_each', 'cat_select_after_each', 'cat_select_after_last', 1); if ($blog == $l_Blog->ID) { $r .= cat_select_new(); } } } else { // BLOG Cross posting is disabled. Current blog only: $current_blog_ID = $blog; $r .= cat_children($cache_categories, $current_blog_ID, NULL, 'cat_select_before_first', 'cat_select_before_each', 'cat_select_after_each', 'cat_select_after_last', 1); $r .= cat_select_new(); } $r .= '</table>'; echo $r; if (isset($blog) && get_allow_cross_posting()) { echo '<script type="text/javascript">jQuery.getScript("' . $rsc_url . 'js/jquery/jquery.scrollto.js", function () { jQuery("#itemform_categories").scrollTo( "#catselect_blog' . $blog . '" ); });</script>'; } $Form->end_fieldset(); }
/** * Allow recursive category selection. * * @todo Allow to use a dropdown (select) to switch between blogs ( CSS / JS onchange - no submit.. ) * * @param Form * @param boolean true: use form fields, false: display only * @param boolean true: show links for add new category & manual * @param array Params */ function cat_select($Form, $form_fields = true, $show_title_links = true, $params = array()) { global $blog, $current_blog_ID, $current_User, $edited_Item, $cat_select_form_fields; global $admin_url, $rsc_url; if (get_post_cat_setting($blog) < 1) { // No categories for $blog return; } $params = array_merge(array('categories_name' => T_('Categories'), 'fold' => false), $params); $cat = param('cat', 'integer', 0); if (empty($edited_Item->ID) && !empty($cat)) { // If the GET param 'cat' is defined we should preselect the category for new created post global $post_extracats; $post_extracats = array($cat); $edited_Item->main_cat_ID = $cat; } if ($show_title_links) { // Use in Back-office $fieldset_title = $params['categories_name'] . get_manual_link('post-categories-panel') . action_icon(T_('Categories'), 'edit', $admin_url . '?ctrl=chapters&blog=' . $blog, T_('Categories'), 3, 4, array('class' => 'action_icon pull-right')); } else { $fieldset_title = $params['categories_name']; } $Form->begin_fieldset($fieldset_title, array('class' => 'extracats', 'id' => 'itemform_categories', 'fold' => $params['fold'])); $r = ''; $cat_select_form_fields = $form_fields; $ChapterCache =& get_ChapterCache(); $r .= '<table cellspacing="0" class="catselect table table-striped table-hover table-condensed">'; if (get_post_cat_setting($blog) == 3) { // Main + Extra cats option is set, display header $r .= cat_select_header($params); } $callbacks = array('before_first' => 'cat_select_before_first', 'before_each' => 'cat_select_before_each', 'after_each' => 'cat_select_after_each', 'after_last' => 'cat_select_after_last'); // Init cat display param $cat_display_params = array('total_count' => 0); if (get_allow_cross_posting() >= 2 || isset($blog) && get_post_cat_setting($blog) > 1 && get_allow_cross_posting() == 1) { // If BLOG cross posting enabled, go through all blogs with cats: /** * @var BlogCache */ $BlogCache =& get_BlogCache(); $ChapterCache->reveal_children(NULL, true); /** * @var Blog */ for ($l_Blog =& $BlogCache->get_first(); !is_null($l_Blog); $l_Blog =& $BlogCache->get_next()) { // run recursively through the cats if (!blog_has_cats($l_Blog->ID)) { continue; } if (!$current_User->check_perm('blog_post_statuses', 'edit', false, $l_Blog->ID)) { continue; } $r .= '<tr class="group' . ($blog == $l_Blog->ID ? ' catselect_blog__current' : '') . '" id="catselect_blog' . $l_Blog->ID . '"><td colspan="3">' . $l_Blog->dget('name') . "</td></tr>\n"; $current_blog_ID = $l_Blog->ID; // Global needed in callbacks foreach ($ChapterCache->subset_root_cats[$current_blog_ID] as $root_Chapter) { $r .= cat_select_display($root_Chapter, $callbacks, $cat_display_params); } if ($blog == $current_blog_ID) { $r .= cat_select_new($cat_display_params); } } } else { // BLOG Cross posting is disabled. Current blog only: $current_blog_ID = $blog; $ChapterCache->reveal_children($current_blog_ID, true); foreach ($ChapterCache->subset_root_cats[$blog] as $root_Chapter) { $r .= cat_select_display($root_Chapter, $callbacks, $cat_display_params); } $r .= cat_select_new($cat_display_params); } $r .= '</table>'; echo $r; $Form->end_fieldset(); if (isset($blog) && get_allow_cross_posting()) { echo '<script type="text/javascript">jQuery.getScript("' . get_require_url('#scrollto#') . '", function () { jQuery("[id$=itemform_categories]").scrollTo( "#catselect_blog' . $blog . '" ); });</script>'; } }