Exemplo n.º 1
0
 /**
  * Render a meta box
  * @param object $taxonomy_key
  * @param array $term_config
  * @param bool $return Return the output? If false, echoes the output
  */
 public function renderMetaBox($taxonomy_key, $term_config, $return = false)
 {
     $config =& $term_config['args'];
     if (!Arr::iterable($config['fields'])) {
         return false;
     }
     $extra = get_option($this->getOptionID());
     $out = array();
     $out[] = '<table class="form-table">';
     foreach ($config['fields'] as $name => $field) {
         // Hack to determine if we're on the category admin page
         $is_quick_add_page = !preg_match('/tag_ID/', $_SERVER['REQUEST_URI']);
         if ($is_quick_add_page && is_array($field) && array_key_exists('value', $field)) {
             $field['value'] = $field['value'];
         } elseif (is_array($extra) && array_key_exists($name, $extra)) {
             $field['value'] = $extra[$name];
         } else {
             $field['value'] = null;
         }
         // Remove the escaped double quotes that WordPress fails to remove
         // when it unserializes data stored in the options table.
         // This bug was identified when links were added to a WYSIWYG field
         // and the anchor tags were rendered like <a href=\"foo.com\">...
         $field['value'] = str_replace('\\"', '"', $field['value']);
         $default = null;
         if (array_key_exists('default', $field)) {
             if ($field['type'] === 'select') {
                 $default = $field['options'][$field['default']];
             } elseif ($field['type'] === 'image') {
                 $default = '<br>' . Html::image($field['default'], null, array('style' => 'max-width:100px;'));
             } else {
                 $default = nl2br($field['default']);
             }
         }
         $tr_class = $name . ' form-field';
         if ($field['type'] === 'hidden') {
             $tr_class .= ' hidden';
         }
         $out[] = sprintf('<tr%s><td><label for="%s">%s%s</label></td><td>%s%s</td><td>%s</td></tr>', Html::attribs(array('class' => $tr_class)), array_key_exists('id', $field) ? $field['id'] : $name, array_key_exists('label', $field) ? $field['label'] : Str::human($name), array_key_exists('required', $field) && $field['required'] ? '&nbsp;<span class="required">*</span>' : '', $this->getRenderMetaBoxField($name, $field), array_key_exists('description', $field) ? Html::p($field['description'], array('class' => 'description')) : null, !is_null($default) ? sprintf('<p class="description">Default: %s</p>', $default) : null);
     }
     $out[] = '</table>';
     $html = join("\n", $out);
     if ($return) {
         return $html;
     }
     echo $html;
 }
Exemplo n.º 2
0
 /**
  * Render a meta box
  * @param object $post
  * @param array $post_config
  * @param bool $return Return the output? If false, echoes the output
  */
 public function renderMetaBox($post, $post_config, $return = false)
 {
     $config = $this->getMetaBoxConfig($post_config['args']);
     if (!Arr::iterable($config['fields'])) {
         return false;
     }
     $this->load($post);
     $out = array();
     $out[] = '<table>';
     foreach ($config['fields'] as $name => $field) {
         // Hack to know if we're editing an existing post
         $is_existing_post = is_array($_SERVER) && array_key_exists('REQUEST_URI', $_SERVER) && preg_match('/post=([\\d]{1,})/', $_SERVER['REQUEST_URI']);
         $field['type'] = array_key_exists('type', $field) ? $field['type'] : 'text';
         if (array_key_exists($name, $this->_info)) {
             $field['value'] = $this->_info[$name];
         } elseif ($is_existing_post && $field['type'] !== 'html') {
             $field['value'] = null;
         }
         $default = null;
         if (array_key_exists('default', $field)) {
             if ($field['type'] === 'select') {
                 $default = $field['options'][$field['default']];
             } elseif ($field['type'] === 'image') {
                 $default = '<br>' . Html::image($field['default'], null, array('style' => 'max-width:100px;'));
             } else {
                 $default = nl2br($field['default']);
             }
         }
         $tr_class = $name;
         if ($field['type'] === 'hidden') {
             $tr_class .= ' hidden';
         }
         $out[] = sprintf('<tr%s><td>%s</td><td>%s%s%s</td></tr>', Html::attribs(array('class' => $tr_class)), $this->getRenderLabel($name), $this->getRenderMetaBoxField($name, $field), array_key_exists('description', $field) ? Html::p($field['description'], array('class' => 'description')) : null, !is_null($default) ? sprintf('<p class="description">Default: %s</p>', $default) : null);
     }
     $out[] = '</table>';
     $html = join("\n", $out);
     if ($return) {
         return $html;
     }
     echo $html;
 }