コード例 #1
0
 /**
  * is_allowed
  * Determines if a workflow tab is allowed to be shown.
  *
  * @param array $data The tab configuration object.
  *
  * @return array The statuse of whether its allowed.
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function is_allowed($data, $strict = true)
 {
     global $pagenow;
     $allowed = !$strict;
     // Check to see if there is an active flow
     if (isset($_REQUEST['flow']) && piklist::slug($flow, 'UTF-8') == $_REQUEST['flow']) {
         $allowed = true;
     }
     // Check Pages
     $pages = $data['data']['page'];
     if (!empty($pages)) {
         $allowed = in_array($pagenow, $pages);
         if (isset($_REQUEST['page'])) {
             $allowed = in_array($_REQUEST['page'], $pages);
         }
     }
     // Check Post Types
     if ($allowed && piklist_admin::is_post()) {
         $post_types = $data['data']['post_type'];
         $current_post_type = piklist_cpt::detect_post_type();
         if (!empty($post_types)) {
             $allowed = in_array($current_post_type, $post_types);
         }
     }
     // Check which mode we are on for the term pages
     if (piklist_admin::is_term()) {
         $taxonomies = $data['data']['taxonomy'];
         $current_taxonomy = isset($_REQUEST['taxonomy']) ? $_REQUEST['taxonomy'] : false;
         if (!empty($taxonomies) && $current_taxonomy) {
             $allowed = in_array($current_taxonomy, $taxonomies);
         }
         if (piklist_admin::is_term() === 'new') {
             $allowed = false;
         }
     }
     return $allowed;
 }
コード例 #2
0
ファイル: class-piklist-meta.php プロジェクト: a42/piklist
 /**
  * clear_screen
  * Clear the screen of all meta-boxes
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function clear_screen()
 {
     global $wp_meta_boxes, $current_screen;
     $workflow = piklist_workflow::get('workflow');
     if ($workflow && $workflow['data']['clear'] == true && piklist_admin::is_post()) {
         remove_post_type_support('post', 'editor');
         remove_post_type_support('post', 'title');
         foreach (array('normal', 'advanced', 'side') as $context) {
             foreach (array('high', 'sorted', 'core', 'default', 'low') as $priority) {
                 if (isset($wp_meta_boxes[$current_screen->id][$context][$priority])) {
                     foreach ($wp_meta_boxes[$current_screen->id][$context][$priority] as $meta_box) {
                         if ($meta_box['id'] != 'submitdiv') {
                             unset($wp_meta_boxes[$current_screen->id][$context][$priority][$meta_box['id']]);
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
ファイル: class-piklist-relate.php プロジェクト: a42/piklist
 /**
  * relate_field
  * Determine the default object id to relate to a field.
  *
  * @param array $field The field object.
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function relate_field($field)
 {
     global $wpdb;
     if (!isset($field['relate']) || !isset($field['relate']['scope'])) {
         return $field;
     }
     // Get the id of what we are relating the field to
     if (!isset($field['relate']['field'])) {
         switch ($field['relate']['scope']) {
             case 'post':
             case 'post_meta':
                 $field['relate_to'] = piklist_admin::is_post();
                 break;
             case 'user':
             case 'user_meta':
                 $field['relate_to'] = piklist_admin::is_user();
                 break;
             case 'comment':
             case 'comment_meta':
                 $field['relate_to'] = piklist_admin::is_comment();
                 break;
         }
     }
     if (in_array($field['scope'], array('post_meta', 'user_meta', 'comment_meta'))) {
         $field['value'] = self::get_object_ids($field['object_id'], $field['scope'], $field['relate']['scope']);
     } else {
         $field['object_id'] = self::get_object_ids($field['object_id'], $field['scope'], $field['relate']['scope']);
     }
     return $field;
 }
コード例 #4
0
ファイル: class-piklist-form.php プロジェクト: a42/piklist
 /**
  * render_field
  * Render a field from a field object.
  *
  * @param array $field The field object
  * @param bool $return Whether to return the output.
  *
  * @return string The field output if return is true.
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function render_field($field, $return = false)
 {
     // Setup the defaults
     $field = self::setup_field($field);
     /**
      * piklist_request_field
      * Filter the request field
      *
      * @param array $field
      *
      * @since 1.0
      */
     $field = apply_filters('piklist_request_field', $field);
     /**
      * piklist_request_field_$scope_$field
      * Filter a specific request field
      *
      * The dynamic portions of the hook name, `$field['scope']` and `$field['field']`,
      * refer to the 'scope' and 'field' parameters, of an individual field.
      *
      * @param array $field
      *
      * @since 1.0
      */
     $field = apply_filters('piklist_request_field_' . $field['scope'] . '_' . $field['field'], $field);
     // Validate field
     if (!$field || !self::validate_field($field) || $field['embed'] && !$return) {
         return false;
     }
     // Set Object ID
     if (is_null($field['object_id']) && (!$field['relate'] || $field['relate'] && in_array($field['scope'], array('post_meta', 'user_meta', 'comment_meta')))) {
         $field['object_id'] = self::get_field_object_id($field);
     }
     // Handle relate
     if (!$field['group_field']) {
         $field = piklist_relate::relate_field($field);
     }
     // Set Template
     if (!$field['template']) {
         $field['template'] = self::get_field_template($field['scope']);
     }
     if (!in_array($field['type'], self::$field_types_rendered)) {
         array_push(self::$field_types_rendered, $field['type']);
     }
     if ($field['type'] == 'html') {
         $field['display'] = true;
         if (!$field['field']) {
             $field['field'] = piklist::unique_id();
         }
     }
     // Manage Classes
     $field['attributes']['class'] = !is_array($field['attributes']['class']) ? explode(' ', $field['attributes']['class']) : $field['attributes']['class'];
     if ($field['type'] == 'hidden') {
         $field['attributes']['data-piklist-field-addmore-clear'] = false;
     }
     array_push($field['attributes']['class'], self::get_field_id(array('field' => $field['field'], 'scope' => $field['scope'], 'index' => false, 'prefix' => $field['prefix'])));
     array_push($field['attributes']['class'], 'piklist-field-element');
     // Set Wrapper clas
     $wrapper_classes = array();
     // Set Columns
     if (is_numeric($field['columns']) && !$field['child_field']) {
         array_push($wrapper_classes, 'piklist-field-type-group piklist-field-column-' . $field['columns']);
     }
     if (is_numeric($field['columns'])) {
         $field['attributes']['data-piklist-field-columns'] = $field['columns'];
     }
     if (isset($field['attributes']['columns']) && is_numeric($field['attributes']['columns'])) {
         array_push($field['attributes']['class'], 'piklist-field-column-' . $field['attributes']['columns']);
         unset($field['attributes']['columns']);
     }
     // Add wrapper class
     if (isset($field['attributes']['wrapper_class'])) {
         array_push($wrapper_classes, $field['attributes']['wrapper_class']);
     }
     // Check Statuses - Legacy, these get mapped to conditions post_status_hide, post_status_value
     if (!empty($field['on_post_status'])) {
         $object = !is_null($field['object_id']) ? get_post($field['object_id'], ARRAY_A) : (isset($GLOBALS['post']) ? (array) $GLOBALS['post'] : null);
         if ($object) {
             $status_list = isset($object['post_type']) ? piklist_cpt::get_post_statuses($object['post_type']) : array();
             foreach (array('value', 'hide') as $status_display) {
                 if (isset($field['on_post_status'][$status_display])) {
                     $field['on_post_status'][$status_display] = is_array($field['on_post_status'][$status_display]) ? $field['on_post_status'][$status_display] : array($field['on_post_status'][$status_display]);
                     foreach ($field['on_post_status'][$status_display] as $_status) {
                         if (strstr($_status, '--')) {
                             $status_range = explode('--', $_status);
                             $status_range_start = array_search($status_range[0], $status_list);
                             $status_range_end = array_search($status_range[1], $status_list);
                             if (is_numeric($status_range_start) && is_numeric($status_range_end)) {
                                 $status_slice = array();
                                 for ($i = $status_range_start; $i <= $status_range_end; $i++) {
                                     array_push($status_slice, $status_list[$i]);
                                 }
                                 array_splice($field['on_post_status'][$status_display], array_search($_status, $field['on_post_status'][$status_display]), 1, $status_slice);
                             }
                         }
                     }
                 }
             }
         }
         foreach ($field['on_post_status'] as $status_display => $statuses) {
             array_push($field['conditions'], array('type' => 'post_status_' . $status_display, 'value' => $statuses));
         }
         unset($field['on_post_status']);
     }
     // Get errors
     if (piklist_validate::errors() && !$field['group_field']) {
         $field['errors'] = piklist_validate::get_errors($field);
     }
     // Highlight errors if needed.
     if ($field['errors']) {
         array_push($field['attributes']['class'], 'piklist-error');
     }
     // Get field value
     if (!$field['group_field'] && $field['value'] !== false && !in_array($field['type'], array('button', 'submit', 'reset')) && (!$field['relate'] || $field['relate'] && !$field['value']) && $field['scope'] != piklist::$prefix) {
         if (piklist_validate::errors()) {
             $field['value'] = piklist_validate::get_request_value($field);
         } elseif (!piklist_validate::errors()) {
             $field['value'] = self::get_field_value($field['scope'], $field, $field['scope'], $field['object_id'], false);
         }
     }
     // Check for nested fields
     if ($field['description']) {
         $field['description'] = self::render_nested_field($field, $field['description']);
     }
     if (is_array($field['choices']) && !in_array($field['type'], array('select', 'multiselect'))) {
         foreach ($field['choices'] as &$choice) {
             $choice = self::render_nested_field($field, $choice);
         }
     }
     if (!empty($field['conditions'])) {
         array_push($field['attributes']['class'], 'piklist-field-element-condition');
         foreach ($field['conditions'] as &$condition) {
             if (is_array($condition)) {
                 if (!isset($condition['type']) || empty($condition['type'])) {
                     $condition['type'] = 'toggle';
                 } elseif (piklist_admin::is_post()) {
                     global $post;
                     $condition['value'] = is_array($condition['value']) ? $condition['value'] : array($condition['value']);
                     if (substr($condition['type'], 0, 12) == 'post_status_' && in_array($post->post_status, $condition['value'])) {
                         if ($condition['type'] == 'post_status_hide') {
                             return false;
                         } elseif ($condition['type'] == 'post_status_value') {
                             $field['display'] = true;
                         }
                     }
                 }
                 if (isset($condition['field'])) {
                     $condition['scope'] = isset($condition['scope']) ? $condition['scope'] : $field['scope'];
                     $condition_field = array('field' => $condition['field'], 'scope' => $condition['scope'], 'index' => false, 'prefix' => $field['prefix']);
                     $condition['id'] = self::get_field_id($condition_field);
                     $condition['name'] = self::get_field_name($condition_field);
                     $condition['reset'] = isset($condition['reset']) ? $condition['reset'] : true;
                     if (!in_array('piklist-field-condition', $field['attributes']['class'])) {
                         if (!in_array('piklist-field-condition', $wrapper_classes)) {
                             array_push($wrapper_classes, 'piklist-field-condition');
                         }
                         if (!in_array('piklist-field-condition-' . $condition['type'], $wrapper_classes)) {
                             array_push($wrapper_classes, 'piklist-field-condition-' . $condition['type']);
                         }
                     }
                 }
             }
         }
     }
     // Check if the field is an add more
     if (($field['add_more'] || $field['sortable']) && !$field['display']) {
         $field['attributes']['data-piklist-field-addmore'] = $field['add_more'];
         $field['attributes']['data-piklist-field-sortable'] = $field['sortable'];
         $field['attributes']['data-piklist-field-addmore-actions'] = $field['add_more'];
         $field['attributes']['data-piklist-field-addmore-single'] = $field['add_more'];
     }
     // Check if field is an editor and prepare its additional attributes
     if ($field['type'] == 'editor') {
         $editor_id = self::get_field_id($field);
         $editor_id = substr($editor_id, 0, -2);
         self::$field_editor_attributes[$editor_id] = '';
         foreach ($field['attributes'] as $key => $value) {
             if (substr($key, 0, strlen('data-piklist-field-')) == 'data-piklist-field-') {
                 self::$field_editor_attributes[$editor_id] .= $key . '="' . $value . '" ';
             }
         }
     }
     // Set the field template
     if ($field['group_field'] && self::get_field_template($field['scope']) == $field['template'] && (strstr(self::$templates[$field['template']]['template'], '</tr>') || $field['template'] == 'default')) {
         $field['child_field'] = true;
         $field['template'] = 'field';
     } elseif ($field['type'] == 'hidden' || $field['embed']) {
         $field['template'] = 'field';
     }
     $field['wrapper'] = preg_replace(array('/ {2,}/', '/<!--.*?-->|\\t|(?:\\r?\\n[ \\t]*)+/s'), array(' ', ''), sprintf(self::$templates[$field['template']]['template'], implode(' ', $wrapper_classes)));
     ksort($field);
     /**
      * piklist_pre_render_field
      * Filter the request field before it renders
      *
      * @param array $field
      *
      * @since 1.0
      */
     $field = apply_filters('piklist_pre_render_field', $field);
     /**
      * piklist_pre_render_field_$scope_$field
      * Filter a specific request field before it renders
      *
      * The dynamic portions of the hook name, `$field['scope']` and `$field['field']`,
      * refer to the 'scope' and 'field' parameters, of an individual field.
      *
      * @param array $field
      *
      * @since 1.0
      */
     $field = apply_filters('piklist_pre_render_field_' . $field['scope'] . '_' . $field['field'], $field);
     // Bail from rendering the field if its a display with no value or its already been rendered in this form
     if (!$field || !$field['group_field'] && ($field['display'] && empty($field['value']) && $field['type'] != 'group')) {
         return false;
     }
     $field_name = $field['field'] ? $field['field'] : piklist::unique_id();
     self::$field_rendering = $field;
     self::$fields_rendered[$field['scope']][$field_name] = $field;
     $field_to_render = self::template_tag_fetch('field_wrapper', $field['wrapper']);
     $rendered_field = do_shortcode($field_to_render);
     switch ($field['position']) {
         case 'start':
             $rendered_field = self::template_tag_fetch('field_wrapper', $field['wrapper'], 'start') . $rendered_field;
             break;
         case 'end':
             $rendered_field .= self::template_tag_fetch('field_wrapper', $field['wrapper'], 'end');
             break;
         case 'wrap':
             $rendered_field = self::template_tag_fetch('field_wrapper', $field['wrapper'], 'start') . $rendered_field . self::template_tag_fetch('field_wrapper', $field['wrapper'], 'end');
             break;
     }
     /**
      * piklist_post_render_field
      * Filter the request field after it renders
      *
      * @param array $field
      *
      * @return $rendered_field
      *
      * @since 1.0
      */
     $rendered_field = apply_filters('piklist_post_render_field', $rendered_field, $field);
     /**
      * piklist_post_render_field_$scope_$field
      * Filter a specific request field after it renders
      *
      * The dynamic portions of the hook name, `$field['scope']` and `$field['field']`,
      * refer to the 'scope' and 'field' parameters, of an individual field.
      *
      * @param array $field
      *
      * @return $rendered_field
      *
      * @since 1.0
      */
     $rendered_field = apply_filters('piklist_post_render_field_' . $field['scope'] . '_' . $field['field'], $rendered_field, $field);
     if ($field['type'] == 'editor') {
         self::$fields_rendered[$field['scope']][$field_name]['options'] = array_merge(self::$fields_rendered[$field['scope']][$field_name]['options'], self::$field_editor_settings);
     }
     self::$field_rendering = null;
     // Return the field as requested
     if ($return) {
         return $rendered_field;
     } else {
         echo $rendered_field;
     }
 }
コード例 #5
0
ファイル: class-piklist-cpt.php プロジェクト: a42/piklist
 /**
  * detect_post_type
  * Attempts to detect the post type given the state of the system when called.
  *
  * @return mixed The current post type or false.
  *
  * @access public
  * @static
  * @since 1.0
  */
 public static function detect_post_type($post_id = null)
 {
     global $typenow, $pagenow, $post;
     $post_type = false;
     if (piklist_admin::is_post()) {
         if (is_null($post_id)) {
             if ($post) {
                 $post_id = $post->ID;
             } elseif (isset($_REQUEST['post'])) {
                 $post_id = (int) $_REQUEST['post'];
             }
         }
         $post_type = get_post_type($post_id);
         if (!$post_type) {
             if ($typenow) {
                 $post_type = $typenow;
             } elseif (isset($_REQUEST['post_type'])) {
                 $post_type = esc_attr($_REQUEST['post_type']);
             } elseif ($pagenow == 'post-new.php') {
                 $post_type = 'post';
             }
         }
     }
     return $post_type;
 }