function fix_attachment_body($content, $cell, $renderer) { global $post; // Do not render attachment post type posts' bodies automatically if ($this->is_wp_post_object($post) && $post->post_type === 'attachment' && $this->attachment_markup) { $content = WPDD_Utils::str_replace_once($this->attachment_markup, '', $content); } return $content; }
private function _check_nonce() { if (WPDD_Utils::user_not_admin()) { die('You don\'t have permission to perform this action'); } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'wp_nonce_individual-pages-assigned')) { die('verification failed'); } }
private function valid_per_post($post) { if (!class_exists('WPDD_Utils') || !method_exists('WPDD_Utils', 'page_has_layout') || !is_object($post)) { return false; } if (self::$layout_id = WPDD_Utils::page_has_layout($post->ID)) { self::$layout_id = WPDD_Utils::get_layout_id_from_post_name(self::$layout_id); return true; } return false; }
public function save_layouts_css_framework_option_callback() { if (user_can_edit_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['set-layout-css-framework-nonce'], 'set-layout-css-framework-nonce')) { $framework_saved = $this->set_framework($_POST['css_framework']); $current = $this->get_current_framework_name(); $send = wp_json_encode(array('message' => array('text' => sprintf(__('The CSS framework has been set to %s. Please make sure that your theme supports %s.', 'ddl-layouts'), $current, $current), 'is_saved' => $framework_saved))); $this->set_up_features(); $this->options_manager->update_options(self::FRAMEWORK_SET, true, true); } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
public function duplicate_layout_callback() { // Clear any errors that may have been rendered that we don't have control of. if (ob_get_length()) { ob_clean(); } if (user_can_create_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['layout-duplicate-layout-nonce'], 'layout-duplicate-layout-nonce')) { global $wpdb, $wpddlayout; $result = $wpdb->get_row($wpdb->prepare("SELECT ID, post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d AND post_status = 'publish'", WPDDL_LAYOUTS_POST_TYPE, $_POST['layout_id'])); if ($result) { $layout_json = WPDD_Layouts::get_layout_settings($result->ID); $layout_array = json_decode($layout_json, true); $layout_name_base = __('Copy of ', 'ddl-layouts') . str_replace('\\', '\\\\', $layout_array['name']); $layout_name = $layout_name_base; $count = 1; while ($wpddlayout->does_layout_with_this_name_exist($layout_name)) { $layout_name = $layout_name_base . ' - ' . $count; $count++; } $postarr = array('post_title' => $layout_name, 'post_content' => '', 'post_status' => 'publish', 'post_type' => WPDDL_LAYOUTS_POST_TYPE); $post_id = wp_insert_post($postarr); $post_slug = $wpdb->get_var($wpdb->prepare("SELECT post_name FROM {$wpdb->posts} WHERE post_type=%s AND ID=%d", WPDDL_LAYOUTS_POST_TYPE, $post_id)); $layout_array['name'] = $layout_name; $layout_array['slug'] = $post_slug; WPDD_Layouts::save_layout_settings($post_id, $layout_array); $wpddlayout->register_strings_for_translation($post_id); } $send = $wpddlayout->listing_page->get_send(isset($_GET['status']) && $_GET['status'] === 'trash' ? $_GET['status'] : 'publish', false, $post_id, $post_id, '', $_POST); } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
function template_have_layout($file) { return WPDD_Utils::template_have_layout($file); }
public function get_all_layouts_posts() { if (ob_get_length()) { ob_clean(); } if (user_can_edit_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['nonce'], 'ddl_listing_show_posts_nonce')) { $data = json_decode(stripslashes($_POST['data']), true); $layout = (object) $data['layout']; $post_types = isset($data['post_types']) ? $data['post_types'] : array(); $posts = $this->get_posts_where_used((object) $layout, $post_types); $send = wp_json_encode(array('Data' => array('posts' => $posts))); } else { $send = WPDD_Utils::ajax_nonce_fail(__METHOD__); } die($send); }
function wpddl_save_post($pidd) { global $wpddlayout; if ($_POST && isset($_POST['action']) && $_POST['action'] != 'inline-save') { // Don't save in quick edit mode. $layout_data = $wpddlayout->post_types_manager->get_layout_to_type_object(get_post_type($pidd)); $layout_template = isset($_POST['layouts_template']) && $_POST['layouts_template'] ? $_POST['layouts_template'] : null; if ($layout_template) { $layout_selected = $layout_template; if (isset($_POST['page_template']) && $wpddlayout->template_have_layout($_POST['page_template']) === false || $layout_selected == '0') { if (isset($_POST['action']) && $_POST['action'] === 'wcml_update_product') { return; } $wpddlayout->individual_assignment_manager->remove_layout_from_post_db($pidd); } else { WPDD_Utils::assign_layout_to_post_object($pidd, $layout_selected, null); } } elseif (!empty($layout_data->layout_id) && is_null($layout_template)) { if (isset($_POST['action']) && $_POST['action'] === 'wcml_update_product') { return; } WPDD_Utils::remove_layout_assignment_to_post_object($pidd, '', true); } else { // when we set a non-layout template after a layout has been set $meta = get_post_meta($pidd, WPDDL_LAYOUTS_META_KEY, true); if ($meta) { if (isset($_POST['action']) && $_POST['action'] === 'wcml_update_product') { return; } WPDD_Utils::remove_layout_assignment_to_post_object($pidd, $meta, false); } } } }
?> " <?php if (!$wpddlayout_theme->file_manager_export->dir_is_writable()) { ?> disabled<?php } ?> > </p> </form> <?php if (isset($_POST['export_to_theme_dir'])) { $nonce = $_POST["wp_nonce_export_layouts_to_theme"]; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (wp_verify_nonce($nonce, 'wp_nonce_export_layouts_to_theme')) { $results = $wpddlayout_theme->export_layouts_to_theme($wpddlayout_theme->file_manager_export->get_layouts_theme_dir()); ?> <?php if (sizeof($results)) { ?> <p> <?php _e('The following layouts have been exported.', 'ddl-layouts'); ?> </p>
function filter_orphaned_cells_of_type($cell) { if (is_object($cell) && property_exists($cell, 'cell_type') && $cell->cell_type === $this->cell_type && $cell->content && $cell->content->{$this->property}) { return WPDD_Utils::is_post_published($cell->content->{$this->property}) === false; } }
function ddl_save_view_columns() { global $wpdb; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'ddl_layout_view_nonce')) { die('verification failed'); } $result = array(); print wp_json_encode($result); die; }
function get_posts_for_post_content_json() { if (user_can_edit_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['nonce'], 'ddl-post-content-post-type-select')) { $send = wp_json_encode(array('Data' => $this->show_posts_options($_POST['post_type'], get_ddl_name_attr('selected_post'), $_POST['selected'], $_POST['page'], $_POST['page']))); } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
public static function ddl_set_max_posts_amount() { if (user_can_edit_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['ddl_max-posts-num_nonce'], 'ddl_max-posts-num_nonce')) { $update = false; $amount = isset($_POST['amount_posts']) ? $_POST['amount_posts'] : self::$max_posts_num_option; if ($amount !== self::$max_posts_num_option) { self::$max_posts_num_option = $amount; $update = self::set_option_max_num_posts($amount); } if ($update) { $send = wp_json_encode(array('Data' => array('message' => __('Updated option', 'ddl-layouts'), 'amount' => $amount))); } else { $send = wp_json_encode(array('Data' => array('error' => __('Option not updated', 'ddl-layouts'), 'amount' => $amount))); } } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
function widget_cell_get_controls() { if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (wp_verify_nonce($_POST['nonce'], 'ddl-get-widget')) { global $wp_widget_factory; foreach ($wp_widget_factory->widgets as $widget) { if ($widget->widget_options['classname'] == $_POST['widget']) { $widget->form(null); // Output a field so we can work out how the fields are named. // We use this in JS to load and save the settings to the layout. ?> <input type="hidden" id="ddl-widget-name-ref" value="<?php echo $widget->get_field_name('ddl-layouts'); ?> "> <?php break; } } } die; }
public function set_layouts_post_types_on_usage_change() { if (user_can_assign_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['layout-set-change-post-types-nonce'], 'layout-set-change-post-types-nonce')) { $post_types = isset($_POST[self::POST_TYPES_OPTION_NAME]) && is_array($_POST[self::POST_TYPES_OPTION_NAME]) ? array_unique($_POST[self::POST_TYPES_OPTION_NAME]) : array(); if (isset($_POST['extras'])) { $extras = $_POST['extras']; if (isset($extras['post_types']) && count($extras['post_types']) > 0) { $types_to_batch = $extras['post_types']; } } if (isset($extras) && isset($types_to_batch)) { $send = wp_json_encode(array('message' => array('changed' => $this->handle_set_option_and_bulk_at_once($_POST['layout_id'], $post_types, null), 'done' => 'yes'))); } else { $send = wp_json_encode(array('message' => array('changed' => $this->handle_post_type_data_save($_POST['layout_id'], $post_types, true), 'done' => 'yes'))); } } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }
function save_css_settings() { if ($_POST && $_POST['action'] == 'ddl_layout_save_css_settings') { if (user_can_edit_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if (!wp_verify_nonce($_POST['ddl_layout_css_settings_nonce'], 'ddl_layout_css_settings_nonce')) { die(WPDD_Utils::ajax_nonce_fail(__METHOD__)); } $mode = $_POST['layout_css_option']; $save_in = $this->css_settings_handle_mode($mode); if (isset($save_in['db_ok']) && $save_in['db_ok'] === false) { die(wp_json_encode(array("error" => __("There are problems saving this option in the database.", 'ddl-layouts')))); } else { if (isset($save_in['db_ok']) && $save_in['db_ok']) { $message = array("message" => __("CSS option saved.", 'ddl-layouts')); } } $copy_css = $save_in != $this->options_manager->get_options('mode'); if ($copy_css) { // we need to copy the css. $css = $this->get_layouts_css(); } $this->options_manager->update_options('mode', $save_in, true); if ($copy_css) { $this->handle_layout_css_save($css); } die(wp_json_encode($message)); } die(wp_json_encode(array("error" => __("Something went wrong communicating with the server", 'ddl-layouts')))); }
function ddl_get_option_for_cred_form_callback() { global $wpdb; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (!isset($_POST['wpnonce']) || !wp_verify_nonce($_POST['wpnonce'], 'ddl_layout_cred_nonce')) { die('verification failed'); } $result = array(); $fm = CRED_Loader::get('MODEL/Forms'); $form = $fm->getForm($_POST['cred_id']); $post_title = $wpdb->get_var($wpdb->prepare("SELECT post_title FROM {$wpdb->posts} WHERE ID = %d ", $_POST['cred_id'])); $result['option'] = $this->ddl_cred_get_option_element($_POST['cred_id'], $post_title, $form->fields['form_settings']->form['type'], $form->fields['form_settings']->post['post_type']); print wp_json_encode($result); die; }
function export_and_download_layouts() { if (isset($_POST['export_and_download'])) { $nonce = $_POST["wp_nonce_export_layouts"]; if (WPDD_Utils::user_not_admin()) { die(__("You don't have permission to perform this action!", 'ddl-layouts')); } if (wp_verify_nonce($nonce, 'wp_nonce_export_layouts')) { $results = $this->export_for_download(); $sitename = sanitize_key(get_bloginfo('name')); if (!empty($sitename)) { $sitename .= '.'; } require_once WPDDL_TOOLSET_COMMON_ABSPATH . '/Zip.php'; if (class_exists('Zip')) { $dirname = $sitename . 'dd-layouts.' . date('Y-m-d'); $zipName = $dirname . '.zip'; $zip = new Zip(); $zip->addDirectory($dirname); foreach ($results as $file_data) { $zip->addFile($file_data['file_data'], $dirname . '/' . $file_data['file_name']); } $zip->sendZip($zipName); } } die; } }
public function view_layout_from_editor_callback() { global $wpddlayout; if (user_can_assign_layouts() === false) { die(WPDD_Utils::ajax_caps_fail(__METHOD__)); } if ($_POST && wp_verify_nonce($_POST['ddl-view-layout-nonce'], 'ddl-view-layout-nonce')) { $layout = WPDD_Layouts::get_layout_settings($_POST['layout_id'], true); if ($layout && isset($layout->has_child) && ($layout->has_child === 'true' || $layout->has_child === true)) { $send = wp_json_encode(array('message' => __("This layout contains a child layout and can't be viewed directly.", 'ddl-layouts') . '<br />' . __("You'll need to switch to one of the child layouts and view it.", 'ddl-layouts'))); } else { $items = $this->get_where_used_x_amount_of_posts($_POST['layout_id'], false, 3); $posts = $items->posts; $layout_post_types = $wpddlayout->post_types_manager->get_layout_post_types($_POST['layout_id']); $loops = $wpddlayout->layout_post_loop_cell_manager->get_layout_loops($_POST['layout_id']); if (count($posts) === 0 && count($loops) === 0 && count($layout_post_types) === 0) { $send = wp_json_encode(array('message' => __(sprintf("This layout is not assigned to any content. %sFirst, assign it to content and then you can view it on the site's front-end. %sYou can assign this layout to content at the bottom of the layout editor.", '<br>', '<br>'), 'ddl-layouts'))); } else { $items = array(); foreach ($layout_post_types as $post_type) { $push = $this->get_x_posts_of_type($post_type, $_POST['layout_id'], 1); if (is_array($push)) { $posts = array_merge($posts, $push); } } foreach ($posts as $post) { $post_types = $wpddlayout->post_types_manager->get_post_types_from_wp(); $label = $post_types[$post->post_type]->labels->singular_name; $labels = $post_types[$post->post_type]->labels->name; $item = array('href' => get_permalink($post->ID), 'title' => $post->post_title, 'type' => $label, 'types' => $labels); if (in_array($item, $items) === false) { $items[] = $item; } } foreach ($loops as $loop) { $push = $wpddlayout->layout_post_loop_cell_manager->get_loop_display_object($loop); if (null !== $push) { array_push($items, $push); } } $send = wp_json_encode(array('Data' => $items, 'message' => __(sprintf("This layout is not assigned to any content. %sFirst, assign it to content and then you can view it on the site's front-end. %sYou can assign this layout to content at the bottom of the layout editor.", '<br>', '<br>'), 'ddl-layouts'), 'no_preview_message' => __('No previews available', 'ddl-layouts'))); } } } else { $send = wp_json_encode(array('error' => __(sprintf('Nonce problem: apparently we do not know where the request comes from. %s', __METHOD__), 'ddl-layouts'))); } die($send); }