예제 #1
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;
 }