/** * 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($Blog->gen_blogurl(), 'disp=edit&p=' . $post_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($Blog->gen_blogurl(), 'disp=edit', '&'); } 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($Blog->gen_blogurl(), 'disp=edit', '&'); } // 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); $item_content = prepare_item_content($edited_Item->content); if (!$edited_Item->get_type_setting('allow_html')) { // HTML is disallowed for this post, content is encoded in DB and we need to decode it for editing: $item_content = htmlspecialchars_decode($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' $advanced_edit_link = array('href' => $admin_url . '?ctrl=items&action=' . $action . '&' . $tab_switch_params, 'onclick' => 'return b2edit_reload( document.getElementById(\'item_checkchanges\'), \'' . $admin_url . '?ctrl=items&blog=' . $Blog->ID . '\' );'); $form_action = get_samedomain_htsrv_url() . 'item_edit.php'; }