/**
  * Generates list of shortcodes only for Grid element.
  *
  * This method parses the list of mapped shortcodes and creates categories list for users.
  * Also it checks is 'is_grid_item_element' attribute true.
  *
  * @static
  *
  * @param bool $force - force data generation even data already generated.
  */
 protected static function generateGitemUserData($force = false)
 {
     if (!$force && self::$gitem_user_sc !== false && self::$gitem_user_categories !== false) {
         return;
     }
     // $settings = self::getSettings();
     self::$gitem_user_sc = self::$gitem_user_categories = self::$gitem_user_sorted_sc = array();
     $deprecated = 'deprecated';
     $add_deprecated = false;
     if (is_array(self::$sc) && !empty(self::$sc)) {
         foreach (self::$sc as $name => $values) {
             if (isset($values['post_type']) && Vc_Grid_Item_Editor::postType() === $values['post_type']) {
                 if (!isset($values['content_element']) || $values['content_element'] === true) {
                     $categories = isset($values['category']) ? $values['category'] : '_other_category_';
                     $values['_category_ids'] = array();
                     if (isset($values['deprecated']) && $values['deprecated'] !== false) {
                         $add_deprecated = true;
                         $values['_category_ids'][] = $deprecated;
                     } else {
                         if (is_array($categories) && !empty($categories)) {
                             foreach ($categories as $c) {
                                 if (array_search($c, self::$gitem_user_categories) === false) {
                                     self::$gitem_user_categories[] = $c;
                                 }
                                 $values['_category_ids'][] = md5($c);
                                 // array_search($category, self::$categories);
                             }
                         } else {
                             if (array_search($categories, self::$gitem_user_categories) === false) {
                                 self::$gitem_user_categories[] = $categories;
                             }
                             $values['_category_ids'][] = md5($categories);
                             // array_search($category, self::$categories);
                         }
                     }
                 }
                 self::$gitem_user_sc[$name] = $values;
                 self::$gitem_user_sorted_sc[] = $values;
             }
         }
     }
     if ($add_deprecated) {
         self::$gitem_user_categories[] = $deprecated;
     }
     $sort = new Vc_Sort(self::$gitem_user_sorted_sc);
     self::$gitem_user_sorted_sc = $sort->sortByKey();
 }
Beispiel #2
0
 /**
  * Add new param to shortcode params list after specified parameter.
  *
  * @static
  *
  * @param $name
  * @param array $attribute
  *
  * @return bool - true if added, false if scheduled/rejected
  */
 public static function addParamAfter($name, $attribute = array(), $after = false)
 {
     if (!$after) {
         return self::addParam($name, $attribute);
     }
     if (!self::$is_init) {
         vc_mapper()->addActivity('mapper', 'add_param', array('name' => $name, 'attribute' => $attribute));
         return false;
     }
     if (!isset(self::$sc[$name])) {
         trigger_error(sprintf(__("Wrong name for shortcode:%s. Name required", "js_composer"), $name));
     } elseif (!isset($attribute['param_name'])) {
         trigger_error(sprintf(__("Wrong attribute for '%s' shortcode. Attribute 'param_name' required", "js_composer"), $name));
     } else {
         $replaced = false;
         foreach (self::$sc[$name]['params'] as $index => $param) {
             if ($param['param_name'] == $attribute['param_name']) {
                 $replaced = true;
                 self::$sc[$name]['params'][$index] = $attribute;
             }
         }
         if ($replaced === false) {
             $after_index = false;
             foreach (self::$sc[$name]['params'] as $index => $param) {
                 if ($param['param_name'] == $after) {
                     $after_index = $index;
                     break;
                 }
             }
             if ($after_index) {
                 array_splice(self::$sc[$name]['params'], $after_index + 1, 0, array($attribute));
             } else {
                 self::$sc[$name]['params'][] = $attribute;
             }
         }
         $sort = new Vc_Sort(self::$sc[$name]['params']);
         self::$sc[$name]['params'] = $sort->sortByKey();
         visual_composer()->addShortCode(self::$sc[$name]);
         return true;
     }
     return false;
 }
 /**
  * Change param attributes of mapped shortcode.
  *
  * @static
  *
  * @param $name
  * @param array $attribute
  *
  * @return bool
  */
 public static function mutateParam($name, $attribute = array())
 {
     if (!self::$is_init) {
         vc_mapper()->addActivity('mapper', 'mutate_param', array('name' => $name, 'attribute' => $attribute));
         return false;
     }
     if (!isset(self::$sc[$name])) {
         return trigger_error(sprintf(__('Wrong name for shortcode:%s. Name required', 'js_composer'), $name));
     } elseif (!isset($attribute['param_name'])) {
         trigger_error(sprintf(__("Wrong attribute for '%s' shortcode. Attribute 'param_name' required", 'js_composer'), $name));
     } else {
         $replaced = false;
         foreach (self::$sc[$name]['params'] as $index => $param) {
             if ($param['param_name'] == $attribute['param_name']) {
                 $replaced = true;
                 self::$sc[$name]['params'][$index] = array_merge($param, $attribute);
             }
         }
         if (false === $replaced) {
             self::$sc[$name]['params'][] = $attribute;
         }
         $sort = new Vc_Sort(self::$sc[$name]['params']);
         self::$sc[$name]['params'] = $sort->sortByKey();
         visual_composer()->addShortCode(self::$sc[$name]);
     }
     return true;
 }