Exemplo n.º 1
0
 public static function init()
 {
     self::check_option_groups();
     if (headway_get('ve-preview') && HeadwayCapabilities::can_user_visually_edit()) {
         HeadwayOption::$group_suffix = '_preview';
     }
 }
Exemplo n.º 2
0
 public static function add_admin_bar_nodes()
 {
     if (!HeadwayCapabilities::can_user_visually_edit()) {
         return;
     }
     global $wp_admin_bar;
     $default_visual_editor_mode = current_theme_supports('headway-grid') ? 'grid' : 'design';
     //Headway Root
     $wp_admin_bar->add_menu(array('id' => 'headway', 'title' => 'Headway', 'href' => add_query_arg(array('visual-editor' => 'true', 'visual-editor-mode' => $default_visual_editor_mode, 've-layout' => HeadwayLayout::get_current()), home_url())));
     //Visual Editor
     $wp_admin_bar->add_menu(array('parent' => 'headway', 'id' => 'headway-ve', 'title' => 'Visual Editor', 'href' => add_query_arg(array('visual-editor' => 'true', 'visual-editor-mode' => $default_visual_editor_mode, 've-layout' => HeadwayLayout::get_current()), home_url())));
     //Grid
     if (current_theme_supports('headway-grid')) {
         $wp_admin_bar->add_menu(array('parent' => 'headway-ve', 'id' => 'headway-ve-grid', 'title' => 'Grid', 'href' => add_query_arg(array('visual-editor' => 'true', 'visual-editor-mode' => 'grid', 've-layout' => HeadwayLayout::get_current()), home_url())));
     }
     //Design Editor
     $wp_admin_bar->add_menu(array('parent' => 'headway-ve', 'id' => 'headway-ve-design', 'title' => 'Design', 'href' => add_query_arg(array('visual-editor' => 'true', 'visual-editor-mode' => 'design', 've-layout' => HeadwayLayout::get_current()), home_url())));
     //Extend
     $wp_admin_bar->add_menu(array('parent' => 'headway', 'id' => 'headway-admin-extend', 'title' => 'Extend', 'href' => admin_url('admin.php?page=headway-extend')));
     //Admin Options
     $wp_admin_bar->add_menu(array('parent' => 'headway', 'id' => 'headway-admin-options', 'title' => 'Options', 'href' => admin_url('admin.php?page=headway-options')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-options', 'id' => 'headway-admin-options-general', 'title' => 'General', 'href' => admin_url('admin.php?page=headway-options#tab-general')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-options', 'id' => 'headway-admin-options-seo', 'title' => 'Search Engine Optimization', 'href' => admin_url('admin.php?page=headway-options#tab-seo')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-options', 'id' => 'headway-admin-options-scripts', 'title' => 'Scripts/Analytics', 'href' => admin_url('admin.php?page=headway-options#tab-scripts')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-options', 'id' => 'headway-admin-options-visual-editor', 'title' => 'Visual Editor', 'href' => admin_url('admin.php?page=headway-options#tab-visual-editor')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-options', 'id' => 'headway-admin-options-advanced', 'title' => 'Advanced', 'href' => admin_url('admin.php?page=headway-options#tab-advanced')));
     //Admin Tools
     $wp_admin_bar->add_menu(array('parent' => 'headway', 'id' => 'headway-admin-tools', 'title' => 'Tools', 'href' => admin_url('admin.php?page=headway-tools')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-tools', 'id' => 'headway-admin-tools-system-info', 'title' => 'System Info', 'href' => admin_url('admin.php?page=headway-tools#tab-system-info')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-tools', 'id' => 'headway-admin-tools-maintenance', 'title' => 'Maintenance', 'href' => admin_url('admin.php?page=headway-tools#tab-maintenance')));
     $wp_admin_bar->add_menu(array('parent' => 'headway-admin-tools', 'id' => 'headway-admin-tools-reset', 'title' => 'Reset', 'href' => admin_url('admin.php?page=headway-tools#tab-reset')));
 }
Exemplo n.º 3
0
 public static function open_in_visual_editor_button($return, $id, $new_title, $new_slug)
 {
     global $post;
     if (!isset($post->ID) || !is_numeric($post->ID) || $post->post_status != 'publish' || !HeadwayCapabilities::can_user_visually_edit()) {
         return $return;
     }
     $layout_id = 'single-' . $post->post_type . '-' . $post->ID;
     $visual_editor_url = home_url('/?visual-editor=true&ve-layout=' . $layout_id);
     $return .= '<span id="view-post-btn" style="margin-right: 3px;"><a href="' . $visual_editor_url . '" class="button button-primary" target="_blank">Open in Visual Editor</a></span>';
     return $return;
 }
Exemplo n.º 4
0
 public static function remove_preview_options()
 {
     if (!HeadwayCapabilities::can_user_visually_edit()) {
         return;
     }
     //Fetch all options in wp_options and remove the preview-specific options
     foreach (wp_load_alloptions() as $option => $option_value) {
         //This if statement is incredibly important and must not be tampered with and needs to be triple-checked if changed.
         if (preg_match('/^headway_(.*)?_preview$/', $option) && strpos($option, 'headway_') === 0 && strpos($option, '_preview') !== false) {
             delete_option($option);
         }
     }
 }
Exemplo n.º 5
0
 private function display_no_blocks_message()
 {
     echo '<div class="wrapper wrapper-no-blocks wrapper-fixed" id="wrapper-default">' . "\n\n";
     echo '<div class="block-type-content">';
     echo '<div class="entry-content">';
     echo '<h1 class="entry-title">' . __('No Content to Display', 'headway') . '</h1>';
     $visual_editor_url = add_query_arg(array('visual-editor' => 'true', 'visual-editor-mode' => 'grid', 've-layout' => HeadwayLayout::get_current()), home_url());
     if (HeadwayCapabilities::can_user_visually_edit()) {
         echo sprintf(__('<p>There are no blocks to display.  Add some by going to the <a href="%s">Headway Grid</a>!</p>', 'headway'), $visual_editor_url);
     } else {
         echo sprintf(__('<p>There is no content to display.  Please notify the site administrator or <a href="%s">login</a>.</p>', 'headway'), $visual_editor_url);
     }
     echo '</div><!-- .entry-content -->';
     echo '</div><!-- .block-type-content -->';
     echo '</div><!-- .wrapper -->';
     return false;
 }
Exemplo n.º 6
0
 public static function ajax()
 {
     Headway::load('visual-editor/display', 'VisualEditorDisplay');
     Headway::load('visual-editor/visual-editor-ajax');
     //Authenticate nonce
     check_ajax_referer('headway-visual-editor-ajax', 'security');
     $method = headway_post('method') ? headway_post('method') : headway_get('method');
     //Check for a non-secure (something that doesn't save data) AJAX request first (let debug mode authentication pass through)
     if (method_exists('HeadwayVisualEditorAJAX', 'method_' . $method) && HeadwayCapabilities::can_user_visually_edit()) {
         do_action('headway_visual_editor_ajax_pre_' . $method);
         call_user_func(array('HeadwayVisualEditorAJAX', 'method_' . $method));
         do_action('headway_visual_editor_ajax_post_' . $method);
     } elseif (method_exists('HeadwayVisualEditorAJAX', 'secure_method_' . $method) && HeadwayCapabilities::can_user_visually_edit(true)) {
         do_action('headway_visual_editor_ajax_pre_' . $method);
         call_user_func(array('HeadwayVisualEditorAJAX', 'secure_method_' . $method));
         do_action('headway_visual_editor_ajax_post_' . $method);
     }
     die;
 }
Exemplo n.º 7
0
 /**
  * Used for when a user clicks View Site in the Visual Editor
  **/
 public static function redirect_to_layout()
 {
     remove_filter('wp_redirect', '__return_false', 12);
     if (headway_get('debug') && HeadwayCapabilities::can_user_visually_edit()) {
         wp_die(HeadwayLayout::get_url(headway_get('layout')));
     }
     return wp_safe_redirect(HeadwayLayout::get_url(headway_get('layout')));
 }
Exemplo n.º 8
0
 public static function row_action_visual_editor($actions, $item)
 {
     if (!HeadwayCapabilities::can_user_visually_edit()) {
         return $actions;
     }
     /* Post */
     if (isset($item->post_status)) {
         if ($item->post_status != 'publish') {
             return $actions;
         }
         $post_type = get_post_type_object($item->post_type);
         if (!$post_type->public) {
             return $actions;
         }
         $layout_id = 'single-' . $item->post_type . '-' . $item->ID;
         /* Category */
     } elseif (isset($item->term_id) && $item->taxonomy == 'category') {
         $layout_id = 'archive-category-' . $item->term_id;
         /* Post Tag */
     } elseif (isset($item->term_id) && $item->taxonomy == 'post_tag') {
         $layout_id = 'archive-post_tag-' . $item->term_id;
         /* Taxonomy */
     } elseif (isset($item->term_id)) {
         $layout_id = 'archive-taxonomy-' . $item->taxonomy . '-' . $item->term_id;
     }
     $visual_editor_url = home_url('/?visual-editor=true&ve-layout=' . $layout_id);
     $actions['hw-visual-editor'] = '<a href="' . $visual_editor_url . '" title="Open in Headway Visual Editor" rel="permalink" target="_blank">Open in Visual Editor</a>';
     return $actions;
 }
Exemplo n.º 9
0
 public static function setup_block_actions()
 {
     /* If cache exists then use it */
     if (HeadwayOption::get('cached', 'block-actions-cache', false) && !(headway_get('ve-preview') && HeadwayCapabilities::can_user_visually_edit())) {
         self::$block_actions = array('init' => HeadwayOption::get('init', 'block-actions-cache', array()), 'enqueue' => HeadwayOption::get('enqueue', 'block-actions-cache', array()), 'dynamic-js' => HeadwayOption::get('dynamic-js', 'block-actions-cache', array()), 'dynamic-css' => HeadwayOption::get('dynamic-css', 'block-actions-cache', array()), 'block-objects' => HeadwayOption::get('block-objects', 'block-actions-cache', array()));
         return self::$block_actions;
     }
     /* Build the cache */
     $block_types = self::get_block_types();
     foreach ($block_types as $block_type => $block_type_options) {
         //Make sure that the block type has at least one of the following: init_action, enqueue_action, or dynamic_js
         if (!method_exists($block_type_options['class'], 'init_action') && !method_exists($block_type_options['class'], 'enqueue_action') && !(method_exists($block_type_options['class'], 'dynamic_js') || method_exists($block_type_options['class'], 'js_content')) && !method_exists($block_type_options['class'], 'dynamic_css')) {
             continue;
         }
         $blocks = HeadwayBlocksData::get_blocks_by_type($block_type);
         /* If there are no blocks for this type, skip it */
         if (!is_array($blocks) || count($blocks) === 0) {
             continue;
         }
         /* Go through each type and add a flag if the method exists */
         foreach ($blocks as $block_id => $layout_id) {
             /* Make sure that the layout is set to customized and not using a template */
             if (!HeadwayLayout::is_customized($layout_id) && strpos($layout_id, 'template-') === false) {
                 continue;
             }
             /* Retrieve block.  If it doesn't exist, skip it of course. */
             if (!($block = HeadwayBlocksData::get_block($block_id))) {
                 continue;
             }
             /* If layout ID is numeric (a post), change it to the single-POSTTYPE-ID format */
             if (is_numeric($layout_id)) {
                 $layout_id = 'single-' . get_post_type($layout_id) . '-' . $layout_id;
             }
             /* Init */
             if (method_exists($block_type_options['class'], 'init_action')) {
                 if (!isset(self::$block_actions['init'][$layout_id])) {
                     self::$block_actions['init'][$layout_id] = array();
                 }
                 if (!HeadwayBlocksData::is_block_mirrored($block)) {
                     self::$block_actions['init'][$layout_id][] = $block_id;
                 }
             }
             /* End Init */
             /* Enqueue */
             if (method_exists($block_type_options['class'], 'enqueue_action')) {
                 if (!isset(self::$block_actions['enqueue'][$layout_id])) {
                     self::$block_actions['enqueue'][$layout_id] = array();
                 }
                 self::$block_actions['enqueue'][$layout_id][] = $block_id;
             }
             /* End Enqueue */
             /* Dynamic JS */
             if (method_exists($block_type_options['class'], 'dynamic_js') || method_exists($block_type_options['class'], 'js_content')) {
                 if (!isset(self::$block_actions['dynamic-js'][$layout_id])) {
                     self::$block_actions['dynamic-js'][$layout_id] = array();
                 }
                 self::$block_actions['dynamic-js'][$layout_id][] = $block_id;
             }
             /* End JS Content */
             /* Dynamic CSS */
             if (method_exists($block_type_options['class'], 'dynamic_css')) {
                 if (!isset(self::$block_actions['dynamic-css'][$layout_id])) {
                     self::$block_actions['dynamic-css'][$layout_id] = array();
                 }
                 self::$block_actions['dynamic-css'][$layout_id][] = $block_id;
             }
             /* End Dynamic CSS */
             /* Add block to Block Objects Array */
             if (!isset(self::$block_actions['block-objects']) || !is_array(self::$block_actions['block-objects'])) {
                 self::$block_actions['block-objects'] = array();
             }
             if (!headway_get($block_id, self::$block_actions['block-objects'])) {
                 self::$block_actions['block-objects'][$block_id] = $block;
                 self::$block_actions['block-objects'][$block_id]['class'] = $block_type_options['class'];
                 self::$block_actions['block-objects'][$block_id]['layout'] = $layout_id;
             }
             /* End block objects array */
         }
     }
     /* Set the cache */
     HeadwayOption::set('init', self::$block_actions['init'], 'block-actions-cache');
     HeadwayOption::set('enqueue', self::$block_actions['enqueue'], 'block-actions-cache');
     HeadwayOption::set('dynamic-js', self::$block_actions['dynamic-js'], 'block-actions-cache');
     HeadwayOption::set('dynamic-css', self::$block_actions['dynamic-css'], 'block-actions-cache');
     HeadwayOption::set('block-objects', self::$block_actions['block-objects'], 'block-actions-cache');
     HeadwayOption::set('cached', true, 'block-actions-cache');
     return self::$block_actions;
 }
Exemplo n.º 10
0
 /**
  * Convert base64 encoded image into a file and move it to proper WP uploads directory.
  **/
 public static function decode_image_to_uploads($base64_string)
 {
     /* Make sure user has permissions to edit in the Visual Editor */
     if (!HeadwayCapabilities::can_user_visually_edit()) {
         return;
     }
     /* Create a temporary file and decode the base64 encoded image into it */
     $temporary_file = wp_tempnam();
     file_put_contents($temporary_file, base64_decode($base64_string));
     /* Use wp_check_filetype_and_ext() to figure out the real mimetype of the image.  Provide a bogus extension and then we'll use the 'proper_filename' later. */
     $filename = 'headway-imported-image.jpg';
     $file_information = wp_check_filetype_and_ext($temporary_file, $filename);
     /* Construct $file array which is similar to a PHP $_FILES array.  This array must be a variable since wp_handle_sideload() requires a variable reference argument. */
     if (headway_get('proper_filename', $file_information)) {
         $filename = $file_information['proper_filename'];
     }
     $file = array('name' => $filename, 'tmp_name' => $temporary_file);
     /* Let WordPress move the image and spit out the file path, URL, etc.  Set test_form to false that way it doesn't verify $_POST['action'] */
     $upload = wp_handle_sideload($file, array('test_form' => false));
     /* If there's an error, be sure to unlink/delete the temporary file in case wp_handle_sideload() doesn't. */
     if (isset($upload['error'])) {
         @unlink($temporary_file);
     }
     return $upload;
 }