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
 /**
  * Get an HTML link from attributes that come from a link object
  * This is mainly used with the field type of link
  * @param object $link_attr
  * @param string $body
  * @param string $classes
  * @param string $id
  * @param string $styles
  * @return string
  */
 public function linkAttribsToHTMLString($link_attr, $body = '', $classes = '', $id = '', $styles = '')
 {
     $link_text = null;
     if (strlen($link_attr->title)) {
         $link_text = $link_attr->title;
     } elseif (strlen($body)) {
         $link_text = $body;
     } else {
         $link_text = $link_attr->href;
     }
     return Html::link($link_attr->href, $link_text, array('title' => $link_attr->title, 'target' => $link_attr->target, 'class' => $classes, 'id' => $id, 'style' => $styles));
 }
Exemplo n.º 3
0
 /**
  * Render an admin column
  * @param string $column_name
  * @param integer $item_id
  */
 public function renderAdminColumn($column_name, $item_id)
 {
     $columns = $this->getAdminColumns();
     if (!in_array($column_name, $columns)) {
         return;
     }
     $field = $this->getField($column_name);
     if (is_array($field)) {
         $class = get_called_class();
         $entry = new $class();
         $entry->load($item_id);
         $out = $entry->get($column_name);
         if (isset($field['type'])) {
             switch ($field['type']) {
                 case 'checkbox':
                     $checkbox_display = $entry->getCheckboxDisplay($column_name);
                     $out = $entry->get($column_name) ? reset($checkbox_display) : end($checkbox_display);
                     break;
                 case 'image':
                     $out = Html::image($entry->get($column_name), $entry->get($column_name), array('class' => 'thumbnail'));
                     break;
                 case 'select':
                     $out = array_key_exists($entry->get($column_name), $field['options']) ? $field['options'][$entry->get($column_name)] : null;
                     break;
             }
         }
         // Hide the title field if necessary.
         // But since the title field is the link to the edit page
         // we are instead going to link the first custom field column.
         if (method_exists($this, 'getHideTitleFromAdminColumns') && $this->getHideTitleFromAdminColumns() && method_exists($this, 'getEditPermalink') && array_search($column_name, array_values($columns)) === 0) {
             $out = sprintf('<a href="%s">%s</a>', $this->getEditPermalink(), $out);
         }
         echo $out;
         return;
     }
     if (Arr::iterable($this->getTaxonomies())) {
         $taxonomy_key = $this->getTaxonomyKey($column_name);
         if ($taxonomy_key) {
             echo get_the_term_list($item_id, $taxonomy_key, null, ', ');
             return;
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Render a public field
  * @param string $key See code below for accepted vals
  * @param array $field
  * @param bool $load_value
  * @return string
  */
 public function getRenderPublicField($key, $field = null, $load_value = true)
 {
     $class = get_called_class();
     if ($key === self::KEY_CLASS) {
         $attribs = array('type' => 'hidden', 'name' => $key, 'value' => $class);
         return Html::tag('input', null, $attribs);
     }
     if ($key === self::KEY_NONCE) {
         $attribs = array('type' => 'hidden', 'name' => $key, 'value' => wp_create_nonce($this->getNonceAction()));
         return Html::tag('input', null, $attribs);
     }
     if ($load_value) {
         if (!is_array($field)) {
             $field = self::getField($key);
         }
         if (!array_key_exists('value', $field)) {
             $field['value'] = $this->{$key};
         }
     }
     return self::getRenderMetaBoxField($key, $field);
 }