Example #1
0
 }
 // Check if new category was started to create. If yes check if it is valid.
 check_categories($post_category, $post_extracats);
 // Check permission on statuses:
 $current_User->check_perm('cats_post!' . $post_status, 'create', true, $post_extracats);
 // Check permission on post type:
 check_perm_posttype($post_extracats);
 // CREATE NEW POST:
 load_class('items/model/_item.class.php', 'Item');
 $edited_Item = new Item();
 // Set the params we already got:
 $edited_Item->set('status', $post_status);
 $edited_Item->set('main_cat_ID', $post_category);
 $edited_Item->set('extra_cat_IDs', $post_extracats);
 // Set object params:
 $edited_Item->load_from_Request($action == 'create_edit', true);
 $Plugins->trigger_event('AdminBeforeItemEditCreate', array('Item' => &$edited_Item));
 if (!empty($mass_create)) {
     // ------ MASS CREATE ------
     $Items =& create_multiple_posts($edited_Item, param('paragraphs_linebreak', 'boolean', 0));
     if (empty($Items)) {
         param_error('content', T_('Content must not be empty.'));
     }
 }
 $result = !$Messages->has_errors();
 if ($result) {
     // There are no validation errors
     if (isset($Items) && !empty($Items)) {
         // We can create multiple posts from single post
         foreach ($Items as $edited_Item) {
             // INSERT NEW POST INTO DB:
Example #2
0
/**
 * Prepare the 'In-skin editing'.
 *
 */
function init_inskin_editing()
{
    global $Blog, $edited_Item, $action, $form_action;
    global $item_tags, $item_title, $item_content;
    global $admin_url, $redirect_to, $advanced_edit_link;
    if (!$Blog->get_setting('in_skin_editing')) {
        // Redirect to the Back-office editing (setting is OFF)
        header_redirect($admin_url . '?ctrl=items&action=new&blog=' . $Blog->ID);
    }
    $tab_switch_params = 'blog=' . $Blog->ID;
    // Post ID, go from $_GET when we edit post from Front-office
    $post_ID = param('p', 'integer', 0);
    // Post ID, go from $_GET when we copy post from Front-office
    $copy_post_ID = param('cp', 'integer', 0);
    if ($post_ID > 0) {
        // Edit post
        global $post_extracats;
        $action = 'edit';
        $ItemCache =& get_ItemCache();
        $edited_Item = $ItemCache->get_by_ID($post_ID);
        check_categories_nosave($post_category, $post_extracats);
        $post_extracats = postcats_get_byID($post_ID);
        $redirect_to = url_add_param($admin_url, 'ctrl=items&filter=restore&blog=' . $Blog->ID . '&highlight=' . $edited_Item->ID, '&');
        $tab_switch_params .= '&p=' . $edited_Item->ID;
    } elseif ($copy_post_ID > 0) {
        // Copy post
        global $localtimenow;
        $action = 'new';
        $ItemCache =& get_ItemCache();
        $edited_Item = $ItemCache->get_by_ID($copy_post_ID);
        $edited_Item_Blog = $edited_Item->get_Blog();
        $item_status = $edited_Item_Blog->get_allowed_item_status();
        $edited_Item->set('status', $item_status);
        $edited_Item->set('dateset', 0);
        // Date not explicitly set yet
        $edited_Item->set('issue_date', date('Y-m-d H:i:s', $localtimenow));
        modules_call_method('constructor_item', array('Item' => &$edited_Item));
        check_categories_nosave($post_category, $post_extracats);
        $redirect_to = url_add_param($admin_url, 'ctrl=items&filter=restore&blog=' . $Blog->ID, '&');
    } elseif (empty($action)) {
        // Create new post (from Front-office)
        $action = 'new';
        load_class('items/model/_item.class.php', 'Item');
        $edited_Item = new Item();
        $def_status = get_highest_publish_status('post', $Blog->ID, false);
        $edited_Item->set('status', $def_status);
        check_categories_nosave($post_category, $post_extracats);
        $edited_Item->set('main_cat_ID', $Blog->get_default_cat_ID());
        // Set default locations from current user
        $edited_Item->set_creator_location('country');
        $edited_Item->set_creator_location('region');
        $edited_Item->set_creator_location('subregion');
        $edited_Item->set_creator_location('city');
        // Set object params:
        $edited_Item->load_from_Request(false, true);
        $redirect_to = url_add_param($admin_url, 'ctrl=items&filter=restore&blog=' . $Blog->ID, '&');
    }
    // Used in the edit form:
    // We never allow HTML in titles, so we always encode and decode special chars.
    $item_title = htmlspecialchars_decode($edited_Item->title);
    if ($Blog->get_setting('allow_html_post')) {
        // HTML is allowed for this post, we have HTML in the DB and we can edit it:
        $item_content = $edited_Item->content;
    } else {
        // HTML is disallowed for this post, content is encoded in DB and we need to decode it for editing:
        $item_content = htmlspecialchars_decode($edited_Item->content);
    }
    // Format content for editing, if we were not already in editing...
    $Plugins_admin =& get_Plugins_admin();
    $edited_Item->load_Blog();
    $params = array('object_type' => 'Item', 'object_Blog' => &$edited_Item->Blog);
    $Plugins_admin->unfilter_contents($item_title, $item_content, $edited_Item->get_renderers_validated(), $params);
    $item_tags = implode(', ', $edited_Item->get_tags());
    // Get an url for a link 'Go to advanced edit screen'
    $mode_editing = param('mode_editing', 'string', 'expert');
    $entries = get_item_edit_modes($Blog->ID, $action, $admin_url, $tab_switch_params);
    $advanced_edit_link = $entries[$mode_editing];
    $form_action = get_samedomain_htsrv_url() . 'item_edit.php';
}