Ejemplo n.º 1
0
    /**
     * Adds a line in the meta box
     *
     * @todo [JRF] check if $class is added appropriately everywhere
     *
     * @param   array  $meta_field_def Contains the vars based on which output is generated.
     * @param   string $key            Internal key (without prefix).
     *
     * @return  string
     */
    function do_meta_box($meta_field_def, $key = '')
    {
        $content = '';
        $esc_form_key = esc_attr(self::$form_prefix . $key);
        $meta_value = self::get_value($key, $this->get_metabox_post()->ID);
        $class = '';
        if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
            $class = ' ' . $meta_field_def['class'];
        }
        $placeholder = '';
        if (isset($meta_field_def['placeholder']) && $meta_field_def['placeholder'] !== '') {
            $placeholder = $meta_field_def['placeholder'];
        }
        $aria_describedby = $description = '';
        if (isset($meta_field_def['description'])) {
            $aria_describedby = ' aria-describedby="' . $esc_form_key . '-desc"';
            $description = '<p id="' . $esc_form_key . '-desc">' . $meta_field_def['description'] . '</p>';
        }
        switch ($meta_field_def['type']) {
            case 'pageanalysis':
                $content .= '<div id="pageanalysis">';
                $content .= '<section class="yoast-section" id="wpseo-pageanalysis-section">';
                $content .= '<h3 class="yoast-section__heading yoast-section__heading-icon yoast-section__heading-icon-list">' . __('Analysis', 'wordpress-seo') . '</h3>';
                $content .= '<div id="wpseo-pageanalysis"></div>';
                $content .= '<div id="yoast-seo-content-analysis"></div>';
                $content .= '</section>';
                $content .= '</div>';
                break;
            case 'snippetpreview':
                $content .= '<div id="wpseosnippet" class="wpseosnippet"></div>';
                break;
            case 'focuskeyword':
                if ($placeholder !== '') {
                    $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
                }
                $content .= '<div id="wpseofocuskeyword">';
                $content .= '<section class="yoast-section" id="wpseo-focuskeyword-section">';
                $content .= '<h3 class="yoast-section__heading yoast-section__heading-icon yoast-section__heading-icon-key">' . esc_html($meta_field_def['title']) . '</h3>';
                $content .= '<label for="' . $esc_form_key . '" class="screen-reader-text">' . esc_html($meta_field_def['label']) . '</label>';
                $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" autocomplete="off" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" class="large-text' . $class . '"/><br />';
                $content .= '</section>';
                $content .= '</div>';
                break;
            case 'metakeywords':
                $content .= '<div id="wpseometakeywords">';
                $content .= '<section class="yoast-section" id="wpseo-metakeywords-section">';
                $content .= '<h3 class="yoast-section__heading yoast-section__heading-icon yoast-section__heading-icon-edit">' . esc_html($meta_field_def['title']) . '</h3>';
                $content .= '<label for="' . $esc_form_key . '" class="screen-reader-text">' . esc_html($meta_field_def['label']) . '</label>';
                $content .= '<input type="text" id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" class="large-text' . $class . '"' . $aria_describedby . '/><br />';
                $content .= $description;
                $content .= '</section>';
                $content .= '</div>';
                break;
            case 'text':
                $ac = '';
                if (isset($meta_field_def['autocomplete']) && $meta_field_def['autocomplete'] === false) {
                    $ac = 'autocomplete="off" ';
                }
                if ($placeholder !== '') {
                    $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
                }
                $content .= '<input type="text"' . $placeholder . 'id="' . $esc_form_key . '" ' . $ac . 'name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" class="large-text' . $class . '"' . $aria_describedby . '/><br />';
                break;
            case 'textarea':
                $rows = 3;
                if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
                    $rows = $meta_field_def['rows'];
                }
                $content .= '<textarea class="large-text' . $class . '" rows="' . esc_attr($rows) . '" id="' . $esc_form_key . '" name="' . $esc_form_key . '"' . $aria_describedby . '>' . esc_textarea($meta_value) . '</textarea>';
                break;
            case 'hidden':
                $content .= '<input type="hidden" id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '"/><br />';
                break;
            case 'select':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '" class="yoast' . $class . '">';
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $selected = selected($meta_value, $val, false);
                        $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
                    }
                    unset($val, $option, $selected);
                    $content .= '</select>';
                }
                break;
            case 'multiselect':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    // Set $meta_value as $selected_arr.
                    $selected_arr = $meta_value;
                    // If the multiselect field is 'meta-robots-adv' we should explode on ,.
                    if ('meta-robots-adv' === $key) {
                        $selected_arr = explode(',', $meta_value);
                    }
                    if (!is_array($selected_arr)) {
                        $selected_arr = (array) $selected_arr;
                    }
                    $options_count = count($meta_field_def['options']);
                    // This select now uses Select2.
                    $content .= '<select multiple="multiple" size="' . esc_attr($options_count) . '" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="yoast' . $class . '"' . $aria_describedby . '>';
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $selected = '';
                        if (in_array($val, $selected_arr)) {
                            $selected = ' selected="selected"';
                        }
                        $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
                    }
                    $content .= '</select>';
                    unset($val, $option, $selected, $selected_arr, $options_count);
                }
                break;
            case 'checkbox':
                $checked = checked($meta_value, 'on', false);
                $expl = isset($meta_field_def['expl']) ? esc_html($meta_field_def['expl']) : '';
                $content .= '<label for="' . $esc_form_key . '"><input type="checkbox" id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . ' value="on" class="yoast' . $class . '"' . $aria_describedby . '/> ' . $expl . '</label><br />';
                unset($checked, $expl);
                break;
            case 'radio':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $checked = checked($meta_value, $val, false);
                        $content .= '<input type="radio" ' . $checked . ' id="' . $esc_form_key . '_' . esc_attr($val) . '" name="' . $esc_form_key . '" value="' . esc_attr($val) . '"/> <label for="' . $esc_form_key . '_' . esc_attr($val) . '">' . esc_html($option) . '</label> ';
                    }
                    unset($val, $option, $checked);
                }
                break;
            case 'upload':
                $content .= '<input id="' . $esc_form_key . '" type="text" size="36" class="' . $class . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '"' . $aria_describedby . ' />';
                $content .= '<input id="' . $esc_form_key . '_button" class="wpseo_image_upload_button button" type="button" value="' . esc_attr__('Upload Image', 'wordpress-seo') . '" />';
                break;
        }
        $html = '';
        if ($content === '') {
            $content = apply_filters('wpseo_do_meta_box_field_' . $key, $content, $meta_value, $esc_form_key, $meta_field_def, $key);
        }
        if ($content !== '') {
            $label = esc_html($meta_field_def['title']);
            if (in_array($meta_field_def['type'], array('radio', 'checkbox'), true) === false) {
                $label = '<label for="' . $esc_form_key . '">' . $label . '</label>';
            }
            $help_button = $help_panel = '';
            if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
                $help = new WPSEO_Admin_Help_Panel($key, $meta_field_def['help-button'], $meta_field_def['help']);
                $help_button = $help->get_button_html();
                $help_panel = $help->get_panel_html();
            }
            if (in_array($meta_field_def['type'], array('snippetpreview', 'pageanalysis', 'focuskeyword', 'metakeywords'), true)) {
                return $this->create_content_box($content, $meta_field_def['type'], $help_button, $help_panel);
            }
            if ($meta_field_def['type'] === 'hidden') {
                $html = '<tr class="wpseo_hidden"><td colspan="2">' . $content . '</td></tr>';
            } else {
                $html = '
					<tr>
						<th scope="row">' . $label . $help_button . '</th>
						<td>' . $help_panel;
                $html .= $content . $description;
                $html .= '
					</td>
				</tr>';
            }
        }
        return $html;
    }
 /**
  * Returns the HTML for the row which contains label, help and the field.
  *
  * @param string                 $label       The html for the label if there was a label set.
  * @param WPSEO_Admin_Help_Panel $help        The help panel to render in this row.
  * @param string                 $field       The html for the field.
  *
  * @return string
  */
 private function parse_row($label, WPSEO_Admin_Help_Panel $help, $field)
 {
     if ($label !== '' || $help !== '') {
         return '<tr><th scope="row">' . $label . $help->get_button_html() . '</th><td>' . $help->get_panel_html() . $field . '</td></tr>';
     }
     return $field;
 }
 /**
  * Creates a filter link
  *
  * @param string  $category Issue type.
  * @param integer $count    Count for the type.
  *
  * @return string
  */
 private function create_view_link($category, $count)
 {
     $href = add_query_arg(array('category' => $category, 'paged' => 1));
     $class = 'gsc_category';
     if ($this->category === $category) {
         $class .= ' current';
     }
     $help_button = $help_panel = '';
     if ($this->filter_values[$category]['description'] !== '') {
         $help = new WPSEO_Admin_Help_Panel($category, $this->filter_values[$category]['help-button'], $this->filter_values[$category]['description'], 'has-wrapper');
         $help_button = $help->get_button_html();
         $help_panel = $help->get_panel_html();
     }
     return sprintf('<a href="%1$s" class="%2$s">%3$s</a> (<span id="gsc_count_%4$s">%5$s</span>) %6$s %7$s', esc_attr($href), $class, $this->filter_values[$category]['value'], $category, $count, $help_button, $help_panel);
 }
    /**
     * Adds a line in the meta box
     *
     * @todo [JRF] check if $class is added appropriately everywhere
     *
     * @param   array  $meta_field_def Contains the vars based on which output is generated.
     * @param   string $key            Internal key (without prefix).
     *
     * @return  string
     */
    function do_meta_box($meta_field_def, $key = '')
    {
        $content = '';
        $esc_form_key = esc_attr(self::$form_prefix . $key);
        $meta_value = self::get_value($key, $this->get_metabox_post()->ID);
        $class = '';
        if (isset($meta_field_def['class']) && $meta_field_def['class'] !== '') {
            $class = ' ' . $meta_field_def['class'];
        }
        $placeholder = '';
        if (isset($meta_field_def['placeholder']) && $meta_field_def['placeholder'] !== '') {
            $placeholder = $meta_field_def['placeholder'];
        }
        switch ($meta_field_def['type']) {
            case 'pageanalysis':
                $content .= '<div id="wpseo-pageanalysis"></div>';
                $content .= '<div id="yoast-seo-content-analysis"></div>';
                break;
            case 'snippetpreview':
                $content .= '<div id="wpseosnippet" class="wpseosnippet"></div>';
                break;
            case 'text':
                $ac = '';
                if (isset($meta_field_def['autocomplete']) && $meta_field_def['autocomplete'] === false) {
                    $ac = 'autocomplete="off" ';
                }
                if ($placeholder !== '') {
                    $placeholder = ' placeholder="' . esc_attr($placeholder) . '"';
                }
                $content .= '<input type="text"' . $placeholder . ' id="' . $esc_form_key . '" ' . $ac . 'name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" class="large-text' . $class . '"/><br />';
                break;
            case 'textarea':
                $rows = 3;
                if (isset($meta_field_def['rows']) && $meta_field_def['rows'] > 0) {
                    $rows = $meta_field_def['rows'];
                }
                $content .= '<textarea class="large-text' . $class . '" rows="' . esc_attr($rows) . '" id="' . $esc_form_key . '" name="' . $esc_form_key . '">' . esc_textarea($meta_value) . '</textarea>';
                break;
            case 'hidden':
                $content .= '<input type="hidden" id="' . $esc_form_key . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '"/><br />';
                break;
            case 'select':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    $content .= '<select name="' . $esc_form_key . '" id="' . $esc_form_key . '" class="yoast' . $class . '">';
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $selected = selected($meta_value, $val, false);
                        $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
                    }
                    unset($val, $option, $selected);
                    $content .= '</select>';
                }
                break;
            case 'multiselect':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    // Set $meta_value as $selected_arr.
                    $selected_arr = $meta_value;
                    // If the multiselect field is 'meta-robots-adv' we should explode on ,.
                    if ('meta-robots-adv' === $key) {
                        $selected_arr = explode(',', $meta_value);
                    }
                    if (!is_array($selected_arr)) {
                        $selected_arr = (array) $selected_arr;
                    }
                    $options_count = count($meta_field_def['options']);
                    // @todo [JRF => whomever] verify height calculation for older WP versions, was 16x, for WP3.8 20x is more appropriate.
                    $content .= '<select multiple="multiple" size="' . esc_attr($options_count) . '" style="height: ' . esc_attr($options_count * 20 + 4) . 'px;" name="' . $esc_form_key . '[]" id="' . $esc_form_key . '" class="yoast' . $class . '">';
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $selected = '';
                        if (in_array($val, $selected_arr)) {
                            $selected = ' selected="selected"';
                        }
                        $content .= '<option ' . $selected . ' value="' . esc_attr($val) . '">' . esc_html($option) . '</option>';
                    }
                    $content .= '</select>';
                    unset($val, $option, $selected, $selected_arr, $options_count);
                }
                break;
            case 'checkbox':
                $checked = checked($meta_value, 'on', false);
                $expl = isset($meta_field_def['expl']) ? esc_html($meta_field_def['expl']) : '';
                $content .= '<label for="' . $esc_form_key . '"><input type="checkbox" id="' . $esc_form_key . '" name="' . $esc_form_key . '" ' . $checked . ' value="on" class="yoast' . $class . '"/> ' . $expl . '</label><br />';
                unset($checked, $expl);
                break;
            case 'radio':
                if (isset($meta_field_def['options']) && is_array($meta_field_def['options']) && $meta_field_def['options'] !== array()) {
                    foreach ($meta_field_def['options'] as $val => $option) {
                        $checked = checked($meta_value, $val, false);
                        $content .= '<input type="radio" ' . $checked . ' id="' . $esc_form_key . '_' . esc_attr($val) . '" name="' . $esc_form_key . '" value="' . esc_attr($val) . '"/> <label for="' . $esc_form_key . '_' . esc_attr($val) . '">' . esc_html($option) . '</label> ';
                    }
                    unset($val, $option, $checked);
                }
                break;
            case 'upload':
                $content .= '<input id="' . $esc_form_key . '" type="text" size="36" class="' . $class . '" name="' . $esc_form_key . '" value="' . esc_attr($meta_value) . '" />';
                $content .= '<input id="' . $esc_form_key . '_button" class="wpseo_image_upload_button button" type="button" value="Upload Image" />';
                break;
        }
        $html = '';
        if ($content === '') {
            $content = apply_filters('wpseo_do_meta_box_field_' . $key, $content, $meta_value, $esc_form_key, $meta_field_def, $key);
        }
        if ($content !== '') {
            $label = esc_html($meta_field_def['title']);
            if (in_array($meta_field_def['type'], array('snippetpreview', 'pageanalysis', 'radio', 'checkbox'), true) === false) {
                $label = '<label for="' . $esc_form_key . '">' . $label . '</label>';
            }
            $help_button = $help_panel = '';
            if (isset($meta_field_def['help']) && $meta_field_def['help'] !== '') {
                $help = new WPSEO_Admin_Help_Panel($key, $meta_field_def['help-button'], $meta_field_def['help']);
                $help_button = $help->get_button_html();
                $help_panel = $help->get_panel_html();
            }
            if ($meta_field_def['type'] === 'hidden') {
                $html = '<tr class="wpseo_hidden"><td colspan="2">' . $content . '</td></tr>';
            } else {
                $html = '
					<tr>
						<th scope="row">' . $label . $help_button . '</th>
						<td>' . $help_panel;
                $html .= $content;
                if (isset($meta_field_def['description'])) {
                    $html .= '<div>' . $meta_field_def['description'] . '</div>';
                }
                $html .= '
					</td>
				</tr>';
            }
        }
        return $html;
    }
 /**
  * Creates a sections specific row.
  *
  * @param string                 $content      The content to show.
  * @param string                 $esc_form_key Escaped form key name.
  * @param WPSEO_Admin_Help_Panel $help         The help button.
  *
  * @return string
  */
 private function parse_section_row($content, $esc_form_key, WPSEO_Admin_Help_Panel $help)
 {
     $html = '<tr><td>';
     $html .= $content;
     $html .= '<div class="wpseo_hidden" id="help-yoast-' . $esc_form_key . '">' . $help->get_button_html() . $help->get_panel_html() . '</div>';
     $html .= '</td></tr>';
     return $html;
 }