public static function enqueue_webfont_api_for_design_editor() { if (!HeadwayRoute::is_visual_editor_iframe('design')) { return; } wp_enqueue_script('webfont', headway_format_url_ssl('http://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js')); }
/** * Anything in here will be displayed when the block is being displayed. **/ function content($block) { global $SlideDeckPlugin; /* Make sure SlideDeck is activated and working */ if (!is_object($SlideDeckPlugin)) { echo '<div class="alert alert-red"><p>SlideDeck must be installed and activated in order for the SlideDeck block to work properly.</p></div>'; return; } /* Get the chosen SlideDeck ID */ $slidedeck_id = parent::get_setting($block, 'slidedeck-id', null); /* Make sure that there's a selected SlideDeck */ if (empty($slidedeck_id)) { echo '<div class="alert alert-red"><p>Please choose a SlideDeck to display.</p></div>'; return; } $slidedeck_query = $SlideDeckPlugin->SlideDeck->get($slidedeck_id); if (empty($slidedeck_query)) { echo '<div class="alert alert-red"><p>The SlideDeck you previously chose must\'ve been deleted or moved elsewhere. Please select another SlideDeck to display.</p></div>'; return; } /* Setup arguments */ $args = array('id' => $slidedeck_id, 'width' => null, 'height' => null); if (parent::get_setting($block, 'use-block-size', true)) { $args['width'] = HeadwayBlocksData::get_block_width($block); $args['height'] = HeadwayBlocksData::get_block_height($block); $args['proportional'] = false; } if (HeadwayRoute::is_visual_editor_iframe()) { $args['iframe'] = true; } if (!HeadwayRoute::is_visual_editor_iframe() && HeadwayResponsiveGrid::is_active()) { $args['ress'] = true; } /* Work around for iframe dimensions */ $GLOBALS['slidedeck-width'] = $args['width']; $GLOBALS['slidedeck-height'] = $args['height']; add_filter('slidedeck_dimensions', array(__CLASS__, 'modify_slidedeck_iframe_size_for_ajax'), 10, 5); /* End work around for iframe dimensions */ /* Show the SlideDeck! */ echo $SlideDeckPlugin->shortcode($args); /* Remove any filters if necessary */ remove_filter('slidedeck_dimensions', array(__CLASS__, 'modify_slidedeck_iframe_size_for_ajax')); if (isset($GLOBALS['slidedeck-width'])) { unset($GLOBALS['slidedeck-width']); } if (isset($GLOBALS['slidedeck-height'])) { unset($GLOBALS['slidedeck-height']); } /* End removing filters */ }
/** * Checks if the responsive grid is active or not. * * Will check against the main option that's set in the Grid mode of the visual editor * and the cookie that disables the responsive grid if the visitor wishes to do so. **/ public static function is_active() { //If the responsive grid isn't enabled then don't bother. if (!self::is_enabled()) { return false; } //If the user has clicked on the full site link in the footer block then it'll set this cookie that's being checked. if (self::is_user_disabled()) { return false; } //If it's the visual editor or the visual editor iframe if (HeadwayRoute::is_visual_editor() || HeadwayRoute::is_visual_editor_iframe() || headway_get('visual-editor-open')) { return false; } return true; }
/** * Traverses up the hierarchy tree to figure out which layout is being used. * * @return mixed **/ public static function get_current_in_use() { //If the user is viewing the site through the iframe and the mode is set to Layout, then display that exact layout. if (headway_get('ve-layout') && (HeadwayRoute::is_visual_editor_iframe() || HeadwayRoute::is_visual_editor())) { return headway_get('ve-layout'); } //Get hierarchy $hierarchy = array_reverse(self::get_current_hierarchy()); //Loop through entire hierarchy to find which one is customized or has a template foreach ($hierarchy as $layout) { $status = self::get_status($layout); //If the layout isn't customized or using a template, skip to next, otherwise we return the current layout in the next line. if ($status['customized'] === false && $status['template'] === false) { continue; } //If the layout has a template assigned to it, use the template. Templates will take precedence over customized status. if ($status['template']) { return 'template-' . $status['template']; } //If it's a customized layout, then use the layout itself after making sure there are blocks on the layout if ($status['customized'] && count(HeadwayBlocksData::get_blocks_by_layout($layout)) > 0) { return $layout; } } //If there's still not a customized layout, loop through the top-level layouts and find the first one that's customized. $top_level_layouts = array('index', 'single', 'archive', 'four04'); if (get_option('show_on_front') == 'page') { $top_level_layouts[] = 'front_page'; } foreach ($top_level_layouts as $top_level_layout) { $status = self::get_status($top_level_layout); if ($status['customized'] === false && $status['template'] === false) { continue; } //If the layout has a template assigned to it, use the template. Templates will take precedence over customized status. if ($status['template']) { return 'template-' . $status['template']; } //If it's a customized layout and the layout has blocks, then use the layout itself if ($status['customized'] && count(HeadwayBlocksData::get_blocks_by_layout($top_level_layout)) > 0) { return $top_level_layout; } } //If there STILL isn't a customized layout, just return the top level of the current layout. return end($hierarchy); }
/** * Loads all of the required core classes and initiates them. * * Dependency array setup: class (string) => init (bool) **/ public static function load_dependencies() { //Load route right away so we can optimize dependency loading below Headway::load(array('common/route' => true)); //Core loading set $dependencies = array('defaults/default-design-settings', 'data/data-options' => 'Option', 'data/data-layout-options', 'data/data-blocks', 'common/layout', 'common/capabilities' => true, 'common/responsive-grid' => true, 'common/seo' => true, 'common/social-optimization' => true, 'common/feed' => true, 'common/compiler' => true, 'admin/admin-bar' => true, 'api/api-panel', 'api/api-updater', 'blocks' => true, 'elements' => true, 'fonts/web-fonts-api', 'fonts/web-fonts-loader' => true, 'fonts/traditional-fonts', 'fonts/google-fonts', 'display' => true, 'display/wrappers' => true, 'widgets' => true); //Child theme API if (HEADWAY_CHILD_THEME_ACTIVE === true) { $dependencies['api/api-child-theme'] = 'ChildThemeAPI'; } //Visual editor classes if (HeadwayRoute::is_visual_editor() || defined('DOING_AJAX') && DOING_AJAX) { $dependencies['visual-editor'] = true; } //Admin classes if (is_admin()) { $dependencies['admin'] = true; } //Load stuff now Headway::load(apply_filters('headway_dependencies', $dependencies)); do_action('headway_setup'); }
/** * To promote caching on browsers, Headway can tell WordPress to not put in the query variables on the style and script URLs. **/ public static function remove_dependency_query_vars($query) { if (!HeadwayOption::get('remove-dependency-query-vars', 'general', false) && !HeadwayRoute::is_visual_editor_iframe()) { return $query; } return remove_query_arg('ver', $query); }
/** * @param string * * @return string **/ public static function get_url($file) { $cache = HeadwayOption::get('cache'); if (is_ssl() && strpos($file, '-https') === false) { $file = $file . '-https'; } //If the file isn't in the DB at all if (!isset($cache[$file])) { return false; } //If cache exists if (self::caching_enabled() && headway_get('filename', $cache[$file]) && file_exists(HEADWAY_CACHE_DIR . '/' . headway_get('filename', $cache[$file])) && !(HeadwayRoute::is_visual_editor_iframe() && !headway_get('iframe-cache', $cache[$file]))) { return apply_filters('headway_compiler_file_url', headway_cache_url() . '/' . headway_get('filename', $cache[$file])); //Cache doesn't exist } else { //If file doesn't exist, but we can still cache, let's cache the damn thing. if (self::caching_enabled() && !(HeadwayRoute::is_visual_editor_iframe() && !headway_get('iframe-cache', $cache[$file]))) { return self::cache_file($file) ? self::get_url($file) : null; //No caching available, now we have to use fallback method. } else { $query_args = array('headway-trigger' => 'compiler', 'file' => $file, 'layout-in-use' => HeadwayLayout::get_current_in_use(), 'rand' => rand()); if (HeadwayRoute::is_visual_editor_iframe()) { $query_args['visual-editor-open'] = 'true'; } if (HeadwayRoute::is_visual_editor_iframe() && headway_get('ve-preview')) { $query_args['ve-preview'] = 'true'; } return apply_filters('headway_compiler_trigger_url', add_query_arg($query_args, home_url('/'))); } } }
public static function home_link_filter($menu) { $block = self::$block; if (parent::get_setting($block, 'hide-home-link')) { return $menu; } if (get_option('show_on_front') == 'posts') { $current = is_home() || is_front_page() ? ' current_page_item' : null; $home_text = parent::get_setting($block, 'home-link-text') ? parent::get_setting($block, 'home-link-text') : 'Home'; /* If it's not the grid, then do not add the extra <span>'s */ if (!HeadwayRoute::is_grid() && !headway_get('ve-live-content-query', $block)) { $home_link = '<li class="menu-item-home headway-home-link' . $current . '"><a href="' . home_url() . '">' . $home_text . '</a></li>'; } else { $home_link = '<li class="menu-item-home headway-home-link' . $current . '"><a href="' . home_url() . '"><span>' . $home_text . '</span></a></li>'; } } else { $home_link = null; } return $home_link . $menu; }
/** * Assembles the classes for the body element. **/ public static function body_class($c) { global $wp_query, $authordata; $c[] = 'custom'; /* User Agents */ if (!HeadwayCompiler::is_plugin_caching()) { $user_agent = $_SERVER['HTTP_USER_AGENT']; /* IE */ if ($ie_version = headway_is_ie()) { $c[] = 'ie'; $c[] = 'ie' . $ie_version; } /* Modern Browsers */ if (stripos($user_agent, 'Safari') !== false) { $c[] = 'safari'; } elseif (stripos($user_agent, 'Firefox') !== false) { $c[] = 'firefox'; } elseif (stripos($user_agent, 'Chrome') !== false) { $c[] = 'chrome'; } elseif (stripos($user_agent, 'Opera') !== false) { $c[] = 'opera'; } /* Rendering Engines */ if (stripos($user_agent, 'WebKit') !== false) { $c[] = 'webkit'; } elseif (stripos($user_agent, 'Gecko') !== false) { $c[] = 'gecko'; } /* Mobile */ if (stripos($user_agent, 'iPhone') !== false) { $c[] = 'iphone'; } elseif (stripos($user_agent, 'iPod') !== false) { $c[] = 'ipod'; } elseif (stripos($user_agent, 'iPad') !== false) { $c[] = 'ipad'; } elseif (stripos($user_agent, 'Android') !== false) { $c[] = 'android'; } } /* End User Agents */ /* Responsive Grid */ if (HeadwayResponsiveGrid::is_enabled()) { $c[] = 'responsive-grid-enabled'; } if (HeadwayResponsiveGrid::is_active()) { $c[] = 'responsive-grid-active'; } /* Pages */ if (is_page() && isset($wp_query->post) && isset($wp_query->post->ID)) { $c[] = 'pageid-' . $wp_query->post->ID; $c[] = 'page-slug-' . $wp_query->post->post_name; } /* Posts & Pages */ if (is_singular() && isset($wp_query->post) && isset($wp_query->post->ID)) { //Add the custom classes from the meta box if ($custom_css_class = HeadwayLayoutOption::get($wp_query->post->ID, 'css-class', null)) { $custom_css_classes = str_replace(' ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags($custom_css_class)))); $c = array_merge($c, array_filter(explode(' ', $custom_css_classes))); } } /* Layout IDs, etc */ $c[] = 'layout-' . HeadwayLayout::get_current(); $c[] = 'layout-using-' . HeadwayLayout::get_current_in_use(); if (HeadwayRoute::is_visual_editor_iframe()) { $c[] = 've-iframe'; } if (headway_get('ve-iframe-mode') && HeadwayRoute::is_visual_editor_iframe()) { $c[] = 'visual-editor-mode-' . headway_get('ve-iframe-mode'); } if (!current_theme_supports('headway-design-editor')) { $c[] = 'design-editor-disabled'; } $c = array_unique(array_filter($c)); return $c; }
public static function display_block($block, $where = null) { //We'll allow this function to take either an integer argument to look up the block or to use the existing if (!is_array($block)) { $block = HeadwayBlocksData::get_block($block); } //Check that the block exists if (!is_array($block) || !$block) { return false; } $block_types = HeadwayBlocks::get_block_types(); //Set the original block for future use $original_block = $block; $original_block_id = $block['id']; //Set the block style to null so we don't get an ugly notice down the road if it's not used. $block_style_attr = null; //Check if the block type exists if (!($block_type_settings = headway_get($block['type'], $block_types, array()))) { $block['requested-type'] = $block['type']; $block['type'] = 'unknown'; } //Get the custom CSS classes and change commas to spaces and remove double spaces and remove HTML $custom_css_classes = str_replace(' ', ' ', str_replace(',', ' ', htmlspecialchars(strip_tags(headway_get('css-classes', $block['settings'], ''))))); $block_classes = array_unique(array_filter(explode(' ', $custom_css_classes))); $block_classes[] = 'block'; $block_classes[] = 'block-type-' . $block['type']; $block_classes[] = headway_get('fixed-height', $block_type_settings, false) !== true ? 'block-fluid-height' : 'block-fixed-height'; //Block Styles if (HEADWAY_CHILD_THEME_ACTIVE && ($block_style = headway_get(HEADWAY_CHILD_THEME_ID . '-block-style', $block['settings']))) { $block_style_classes = explode(' ', headway_get('class', headway_get($block_style, HeadwayChildThemeAPI::$block_styles))); foreach ($block_style_classes as $block_style_class) { $block_classes[] = $block_style_class; } } //If the block is being displayed in the Grid, then we need to make it work with absolute positioning. if ($where == 'grid') { $block_classes[] = 'grid-width-' . $original_block['dimensions']['width']; $block_classes[] = 'grid-left-' . $original_block['position']['left']; $block_style_attr = ' style="height: ' . $original_block['dimensions']['height'] . 'px; top: ' . $original_block['position']['top'] . 'px;"'; } //If the responsive grid is active, then add the responsive block hiding classes if (HeadwayResponsiveGrid::is_enabled()) { $responsive_block_hiding = headway_get('responsive-block-hiding', $block['settings'], array()); if (is_array($responsive_block_hiding) && count($responsive_block_hiding) > 0) { foreach ($responsive_block_hiding as $device) { $block_classes[] = 'responsive-block-hiding-device-' . $device; } } } //If it's a mirrored block, change $block to the mirrored block if ($mirrored_block = HeadwayBlocksData::is_block_mirrored($block)) { $block = $mirrored_block; $block['original'] = $original_block; //Add Classes for the mirroring $block_classes[] = 'block-mirrored'; if ($where != 'grid') { $block_classes[] = 'block-mirroring-' . $mirrored_block['id']; $block_classes[] = 'block-original-' . $original_block_id; } } //Fetch the HTML tag for the block $block_tag = ($html_tag = headway_get('html-tag', $block_type_settings)) ? $html_tag : 'div'; //The ID attribute for the block. This will change if mirrored. $block_id_for_id_attr = $block['id']; //Original block ID to be used in the Visual Editor if (HeadwayRoute::is_visual_editor_iframe()) { $block_data_attrs = implode(' ', array('data-id="' . str_replace('block-', '', $original_block_id) . '"', 'data-block-mirror="' . (isset($mirrored_block) ? $mirrored_block['id'] : '') . '"', 'data-block-mirror-layout-name="' . (isset($mirrored_block) ? HeadwayLayout::get_name($mirrored_block['layout']) : '') . '"', 'data-grid-left="' . $original_block['position']['left'] . '"', 'data-grid-top="' . $original_block['position']['top'] . '"', 'data-width="' . $original_block['dimensions']['width'] . '"', 'data-height="' . $original_block['dimensions']['height'] . '"', 'data-alias="' . headway_get('alias', headway_get('settings', $original_block, array())) . '"')); } else { $block_data_attrs = null; } //The grid will display blocks entirely differently and not use hooks. if ($where != 'grid') { do_action('headway_before_block', $block); do_action('headway_before_block_' . $block['id'], $block); echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter(apply_filters('headway_block_class', $block_classes, $block))) . '"' . $block_style_attr . $block_data_attrs . '>'; do_action('headway_block_open', $block); do_action('headway_block_open_' . $block['id'], $block); echo '<div class="block-content">'; do_action('headway_block_content_open', $block); do_action('headway_block_content_open_' . $block['id'], $block); do_action('headway_block_content_' . $block['type'], $block); do_action('headway_block_content_close', $block); do_action('headway_block_content_close_' . $block['id'], $block); echo '</div><!-- .block-content -->' . "\n"; do_action('headway_block_close', $block); do_action('headway_block_close_' . $block['id'], $block); echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n"; do_action('headway_after_block', $block); do_action('headway_after_block_' . $block['id'], $block); //Show the block in the grid } else { $show_content_in_grid = self::block_type_exists($block['type']) ? headway_get('show-content-in-grid', $block_type_settings, false) : false; if (!$show_content_in_grid) { $block_classes[] = 'hide-content-in-grid'; } if (!self::block_type_exists($block['type'])) { $block_classes[] = 'block-error'; } echo '<' . $block_tag . ' id="block-' . $block_id_for_id_attr . '" class="' . implode(' ', array_filter($block_classes)) . '"' . $block_style_attr . $block_data_attrs . '>'; echo '<div class="block-content-fade block-content">'; if (!self::block_type_exists($block['type'])) { self::unknown_block_content($block); } else { if (!$show_content_in_grid) { echo '<p class="hide-content-in-grid-notice"><strong>Notice:</strong> <em>' . self::block_type_nice($block['type']) . '</em> blocks do not display in the Grid Mode. Please switch to the Design mode to see the content in this block.</p>'; } } echo '</div><!-- .block-content-fade -->' . "\n"; echo '</' . $block_tag . '><!-- #block-' . $block_id_for_id_attr . ' -->' . "\n"; } //Spit the ID back out return $block['id']; }