当前位置: 首页>>代码示例>>PHP>>正文


PHP Set::applyNative方法代码示例

本文整理汇总了PHP中Set::applyNative方法的典型用法代码示例。如果您正苦于以下问题:PHP Set::applyNative方法的具体用法?PHP Set::applyNative怎么用?PHP Set::applyNative使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Set的用法示例。


在下文中一共展示了Set::applyNative方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: find

 /**
  * @param string $optionId
  * @param array $options
  * @return mixed False if option not set
  */
 public function find($optionId, $options = array())
 {
     $options = array_merge(array('booleanize' => false), $options);
     $optionId = $this->gummOptionId($optionId);
     if (strpos($optionId, '.') !== false) {
         $optionPath = explode('.', $optionId);
         $rootOptionId = array_shift($optionPath);
         $rootValue = get_option($rootOptionId);
         if ($rootValue) {
             $optionXPath = implode('/', $optionPath);
             $extractedValue = Set::extract('/Option/' . $optionXPath, array('Option' => $rootValue));
             $optionLastId = end($optionPath);
             $parsedValue = array();
             if ($extractedValue) {
                 foreach ($extractedValue as $val) {
                     if (is_array($val)) {
                         if (isset($val[$optionLastId])) {
                             $val = $val[$optionLastId];
                         }
                         $parsedValue = array_merge($parsedValue, $val);
                     } else {
                         // We are working with ids, so extract will match only one id, and if not array - we need the string returned
                         $parsedValue = $val;
                         break;
                     }
                 }
                 if ($options['booleanize']) {
                     $parsedValue = Set::booleanize($parsedValue);
                 }
                 if (is_array($parsedValue)) {
                     $parsedValue = Set::applyNative(Set::filter($parsedValue), 'stripslashes');
                 } elseif ($parsedValue !== false) {
                     $parsedValue = stripslashes($parsedValue);
                 }
                 return $parsedValue;
             }
         }
     }
     // if (strpos($optionId, '[') !== false) {
     //  if (preg_match_all("'(.*)(\[(.*)\])+'msU", $optionId, $out)) {
     //      $baseOptionId = $out[1][0];
     //      $baseValue = get_option($baseOptionId);
     //      if (is_array($baseValue)) {
     //          $innerVal = Set::extract('/Option/' . implode('/', $out[3]), array('Option' => $baseValue));
     //          if ($innerVal) return reset($innerVal);
     //      }
     //  }
     // }
     $value = get_option($optionId);
     if ($value === false) {
         $configOption = $this->getConfigOption($optionId);
         if (isset($configOption['default'])) {
             $value = $configOption['default'];
             if (isset($optionPath) && is_array($optionPath)) {
                 $optionLastId = end($optionPath);
                 if (isset($optionLastId) && $value && is_array($value) && isset($value[$optionLastId])) {
                     $value = $value[$optionLastId];
                 }
             }
         } elseif (isset($configOption['options'])) {
             $value = array();
             foreach ($configOption['options'] as $configSubOption) {
                 if (preg_match_all("'(.*)(\\[(.*)\\])+'msU", $configSubOption['id'], $out)) {
                     $valueKey = end($out[3]);
                     $value[$valueKey] = $this->find($configSubOption['id']);
                 }
             }
         }
     }
     if (is_array($value)) {
         $value = Set::applyNative(Set::filter($value), 'stripslashes');
     } elseif ($value !== false) {
         $value = stripslashes($value);
     }
     if ($optionId === GUMM_THEME_PREFIX . '_email' && !$value) {
         $value = get_option('admin_email');
     }
     if ($options['booleanize']) {
         $value = Set::booleanize($value);
     }
     return $value;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:87,代码来源:option.php

示例2: postTypePicker

 /**
  * @param array $options
  * @param array $attributes
  * @param array $settings
  * @return string
  */
 public function postTypePicker(array $option, array $attributes, array $settings)
 {
     $postTypes = array_merge(array('post' => 'post'), get_post_types(array('capability_type' => 'post', '_builtin' => false, 'public' => true)));
     $postTypes = Set::applyNative($postTypes, 'ucwords');
     // if (isset($attributes['name'])) $option['id'] = $attributes['name'];
     $originalValue = $this->value;
     $value = null;
     $val = 'post';
     if ($originalValue && is_array($originalValue) && isset($originalValue['post_type'])) {
         $val = $value = $originalValue['post_type'];
     }
     $outputHtml = '';
     // $outputHtml = '<div class="layout-element-post-type-select">';
     $theInputField = array('id' => $option['id'] . '.post_type', 'name' => $option['name'], 'inputOptions' => $postTypes, 'type' => 'tabbed-input', 'tabs' => array());
     foreach ($postTypes as $postType => $postTypeName) {
         $inputOptions = array();
         $termName = $postType == 'post' ? 'category' : $postType . '_category';
         if ($terms = get_terms($termName)) {
             if (!isset($terms->errors)) {
                 foreach ($terms as $term) {
                     $inputOptions[$term->term_id] = $term->name;
                 }
             }
         }
         $hiddenClass = $postType == $val ? '' : ' hidden';
         $value = null;
         if ($originalValue && is_array($originalValue) && isset($originalValue[$postType . '-category'])) {
             $value = $originalValue[$postType . '-category'];
         }
         $theCategoriesContent = '<em>' . __('There are no available categories for this post type.', 'gummfw') . '</em>';
         if ($inputOptions) {
             $theCategoriesContent = $this->input($this->model, array('name' => ucwords($postType) . ' ' . __('Category', 'gummfw'), 'id' => $option['id'] . '.' . $postType . '-category', 'type' => 'checkboxes', 'inputOptions' => $inputOptions), array('value' => $value));
         }
         $theInputField['tabs'][] = $theCategoriesContent;
     }
     $outputHtml .= $this->input($this->model, $theInputField, array('value' => $val));
     $value = null;
     if ($originalValue && is_array($originalValue) && isset($originalValue['posts_number'])) {
         $value = $originalValue['posts_number'];
     }
     $outputHtml .= $this->input($this->model, array('name' => __('Number of posts', 'gummfw'), 'id' => $option['id'] . '.posts_number', 'type' => 'number', 'default' => 4), array('value' => $value), array('slider' => array('min' => 1, 'max' => 50, 'numberType' => '')));
     // $outputHtml .= '</div>';
     return $outputHtml;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:50,代码来源:form.php

示例3: _postTypeFields

 protected function _postTypeFields()
 {
     if (isset($this->params['postType'])) {
         $val = $this->params['postType'];
     } elseif (isset($this->supports['postType']) && isset($this->supports['postType']['value'])) {
         $val = $this->supports['postType']['value'];
     } elseif (isset($this->supports['postType'])) {
         $val = $this->supports['postType'];
     } else {
         $val = 'post';
     }
     $postTypes = array_merge(array('post' => 'post'), get_post_types(array('capability_type' => 'post', '_builtin' => false, 'public' => true)));
     $postTypes = Set::applyNative($postTypes, 'ucwords');
     $fields = array('postType' => array('name' => __('Data Source', 'gummfw'), 'type' => 'tabbed-input', 'inputOptions' => $postTypes, 'value' => $val, 'inputAttributes' => array('class' => 'layout-element-post-type-select-input gumm-input'), 'tabs' => array()), 'postOrder' => array('name' => __('Order', 'gummfw'), 'type' => 'tabbed-input', 'inputOptions' => array('default' => __('Default', 'gummfw'), 'custom' => __('Custom', 'gummfw')), 'value' => 'default', 'tabs' => array(array('tabText' => __('Default WordPress ordering will be used.', 'gummfw')), array('postOrderBy' => array('name' => __('Order by:', 'gummfw'), 'type' => 'select', 'inputOptions' => array('title' => __('Title', 'gummfw'), 'name' => __('Post name (post slug)', 'gummfw'), 'date' => __('Date'), 'modified' => __('Last modified date', 'gummfw'), 'menu_order' => __('Page/post order field', 'gummfw'), 'rand' => __('Random', 'gummfw')), 'value' => 'date'), 'postOrderDirection' => array('name' => __('Order direction:', 'gummfw'), 'type' => 'select', 'inputOptions' => array('DESC' => __('Descending', 'gummfw'), 'ASC' => __('Ascending', 'gummfw')), 'value' => 'DESC')))));
     foreach ($postTypes as $postType => $postTypeName) {
         $categoryField = $this->_categoriesFields($postType);
         $tabContentInput = $categoryField[$postType . '-category'];
         if (count($categoryField[$postType . '-category']['inputOptions']) === 0) {
             $tabContentInput = array('tabText' => __('There are no available categories for this post type.', 'gummfw'));
         }
         $fields['postType']['tabs'][][$postType . '-category'] = $tabContentInput;
     }
     if (isset($this->supports['postType']) && isset($this->supports['postType']['flickr']) && $this->supports['postType']['flickr']) {
         $fields['postType']['inputOptions']['flickr'] = __('Flickr', 'gummfw');
         $fields['postType']['tabs'][] = array('flickrUser' => array('name' => __('Flickr username', 'gummfw'), 'type' => 'text'));
     }
     $fields['postType']['inputOptions']['default'] = __('Default', 'gummfw');
     $fields['postType']['tabs'][] = array('tabText' => __('Use default WordPress query.', 'gummfw', 'gummfw'));
     return $fields;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:30,代码来源:gumm_layout_element.php

示例4: applyNative

 /**
  * Allows the application of a native php callback function to elements of an array
  *
  * @param array $data An array of data to extract from & then process with the $callback.
  * @param mixed $callback Callback method to be applied to extracted data.
  * See http://ca2.php.net/manual/en/language.pseudo-types.php#language.types.callback for examples
  * of callback formats.
  * @param string $to Can be 'values', 'keys', 'both'
  * @return mixed Result of the callback when applied to extracted data
  * @access public
  * @static
  */
 public static function applyNative($data, $callback, $to = 'values')
 {
     $parsed = array();
     if ($data) {
         foreach ($data as $key => $value) {
             if (in_array($to, array('keys', 'both'))) {
                 $key = $callback($key);
             }
             if (in_array($to, array('values', 'both'))) {
                 if (is_array($value)) {
                     $value = Set::applyNative($value, $callback, $to);
                 } else {
                     $value = $callback($value);
                 }
                 $parsed[$key] = $value;
             }
         }
     }
     return $parsed;
 }
开发者ID:nikolaskarica,项目名称:bds-alliance,代码行数:32,代码来源:set.php


注:本文中的Set::applyNative方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。