Esempio n. 1
0
/**
 * 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();
}
Esempio n. 2
0
function fieldset_cats()
{
    global $cache_blogs, $cache_categories;
    ?>
	<fieldset title="default categories set" style="background-color:#fafafa; border:1px solid #ccc; padding: 1em; display:inline; float:right; white-space:nowrap;">
		<legend>Default categories set (only needed if you want to map categories to this)</legend>
		<p class="extracatnote">
		<?php 
    if (count($cache_categories)) {
        echo T_('Select main category in target blog and optionally check additional categories') . ':';
    } else {
        echo 'No categories in your blogs..';
    }
    ?>
		</p>

		<?php 
    // ----------------------------  CATEGORIES ------------------------------
    $default_main_cat = 0;
    $blog = 1;
    // ----------------- START RECURSIVE CAT LIST ----------------
    cat_load_cache();
    // make sure the caches are loaded
    function import_cat_select_before_first($parent_cat_ID, $level)
    {
        // callback to start sublist
        echo "\n<ul>\n";
    }
    function import_cat_select_before_each($cat_ID, $level)
    {
        // callback to display sublist element
        global $current_blog_ID, $blog, $cat, $postdata, $default_main_cat, $action, $tabindex;
        echo '<li>';
        if (get_allow_cross_posting() >= 1) {
            // We allow cross posting, display checkbox:
            echo '<input type="checkbox" name="post_extracats[]" class="checkbox" title="', T_('Select as an additionnal category'), '" value="', $cat_ID, '"';
            echo ' />';
        }
        // Radio for main cat:
        if ($current_blog_ID == $blog) {
            if ($default_main_cat == 0 && $action == 'post') {
                // Assign default cat for new post
                $default_main_cat = $cat_ID;
            }
            echo ' <input type="radio" name="post_category" class="checkbox" title="', T_('Select as MAIN category'), '" value="', $cat_ID, '"';
            if ($cat_ID == $postdata["Category"] || $cat_ID == $default_main_cat) {
                echo ' checked="checked"';
            }
            echo ' />';
        }
        echo ' ' . htmlspecialchars(get_catname($cat_ID));
    }
    function import_cat_select_after_each($cat_ID, $level)
    {
        // callback after each sublist element
        echo "</li>\n";
    }
    function import_cat_select_after_last($parent_cat_ID, $level)
    {
        // callback to end sublist
        echo "</ul>\n";
    }
    // go through all blogs with cats:
    foreach ($cache_blogs as $i_blog) {
        // run recursively through the cats
        $current_blog_ID = $i_blog->blog_ID;
        if (!blog_has_cats($current_blog_ID)) {
            continue;
        }
        #if( ! $current_User->check_perm( 'blog_post_statuses', 'any', false, $current_blog_ID ) ) continue;
        echo "<h4>" . $i_blog->blog_name . "</h4>\n";
        cat_children($cache_categories, $current_blog_ID, NULL, 'import_cat_select_before_first', 'import_cat_select_before_each', 'import_cat_select_after_each', 'import_cat_select_after_last', 1);
    }
    // ----------------- END RECURSIVE CAT LIST ----------------
    ?>
	</fieldset>
<?php 
}
Esempio n. 3
0
/**
 * Allow recursive category selection.
 *
 * @todo Allow to use a dropdown (select) to switch between blogs ( CSS / JS onchange - no submit.. )
 *
 * @param boolean
 * @param boolean true: use form fields, false: display only
 */
function cat_select($display_info = true, $form_fields = true)
{
    global $allow_cross_posting, $cache_categories, $blog, $current_blog_ID, $current_User, $edited_Item, $cat_select_form_fields;
    $r = '<div class="extracats"><div>';
    $cat_select_form_fields = $form_fields;
    cat_load_cache();
    // make sure the caches are loaded
    $r .= '<table cellspacing="0" class="catselect">';
    $r .= cat_select_header();
    if ($allow_cross_posting >= 2) {
        // If BLOG cross posting enabled, go through all blogs with cats:
        /**
         * @var BlogCache
         */
        $BlogCache =& get_Cache('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"><td colspan="3">' . $l_Blog->dget('name') . "</td></tr>\n";
            $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);
        }
    } 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 .= '</table>';
    if ($current_User->check_perm('blog_cats', '', false, $blog)) {
        $r .= '<p class="extracatnote"><a href="admin.php?ctrl=chapters&amp;action=new&amp;blog=' . $blog . '">' . T_('Add a new category') . ' &raquo;</a></p>';
    }
    if ($display_info) {
        $r .= '<p class="extracatnote">' . T_('Select main category in target blog and optionally check additional categories') . '</p>';
        $r .= '<p class="extracatnote">';
        if ($allow_cross_posting >= 3) {
            $r .= T_('Note: Moving posts across blogs is enabled. Use with caution.');
        } elseif ($allow_cross_posting >= 2) {
            $r .= T_('Note: Cross posting among multiple blogs is enabled.');
        } elseif ($allow_cross_posting) {
            $r .= T_('Note: Cross posting among multiple blogs is currently disabled.');
        } else {
            $r .= T_('Note: Cross posting among multiple categories is currently disabled.');
        }
        $r .= '</p>';
    }
    $r .= '</div></div>';
    return $r;
}
Esempio n. 4
0
/**
 * Compiles the cat array from $cat (recursive + optional modifiers) and $catsel[] (non recursive)
 *
 * @param string
 * @param array
 * @param array by ref, will be modified
 * @param string by ref, will be modified
 * @param integer blog number to restrict to
 */
function compile_cat_array($cat, $catsel, &$cat_array, &$cat_modifier, $restrict_to_blog = 0)
{
    global $cache_categories;
    // echo '$cat='.$cat;
    // pre_dump( $catsel );
    // echo '$restrict_to_blog'.$restrict_to_blog;
    $cat_array = array();
    $cat_modifier = '';
    // Check for cat string (which will be handled recursively)
    if ($cat != 'all' && !empty($cat)) {
        // specified a category string:
        $cat_modifier = substr($cat, 0, 1);
        // echo 'cats['.$first_char.']';
        if ($cat_modifier == '*' || $cat_modifier == '-') {
            $cat = substr($cat, 1);
        } else {
            $cat_modifier = '';
        }
        if (strlen($cat)) {
            // There are some values to explode...
            $req_cat_array = explode(',', $cat);
            // Getting required sub-categories:
            // and add everything to cat array
            // ----------------- START RECURSIVE CAT LIST ----------------
            cat_load_cache();
            // make sure the caches are loaded
            foreach ($req_cat_array as $cat_ID) {
                // run recursively through the cats
                if (!in_array($cat_ID, $cat_array)) {
                    // Not already in list
                    $cat_array[] = $cat_ID;
                    cat_children($cache_categories, $restrict_to_blog, $cat_ID, 'cat_req_dummy', 'cat_req', 'cat_req_dummy', 'cat_req_dummy', 1);
                }
            }
            // ----------------- END RECURSIVE CAT LIST ----------------
        }
    }
    // Add explicit selections:
    if (!empty($catsel)) {
        // echo "Explicit selections!<br />";
        $cat_array = array_merge($cat_array, $catsel);
        $cat_array = array_unique($cat_array);
    }
    // echo '$cat_modifier='.$cat_modifier;
    // pre_dump( $cat_array );
}