/**
 * Return the full permalink of the current post.
 * @return string
 */
function get_full_permalink()
{
    $permalinkArray = get_sample_permalink($post->ID);
    $permalinkTemplate = array_values($permalinkArray);
    $permalinkSlug = array_values($permalinkArray);
    return str_replace('%postname%', $permalinkSlug[1], $permalinkTemplate[0]);
}
    public function script()
    {
        global $post;
        if (!isset($post)) {
            return;
        }
        $options = get_wpseo_options();
        $date = '';
        if ($post->post_type == 'post' && (!isset($options['disabledatesnippet']) || !$options['disabledatesnippet'])) {
            $date = $this->get_post_date($post);
            $this->wpseo_meta_length = $this->wpseo_meta_length - (strlen($date) + 5);
            $this->wpseo_meta_length_reason = __(' (because of date display)', 'wordpress-seo');
        }
        $this->wpseo_meta_length_reason = apply_filters('wpseo_metadesc_length_reason', $this->wpseo_meta_length_reason);
        $this->wpseo_meta_length = apply_filters('wpseo_metadesc_length', $this->wpseo_meta_length);
        unset($date);
        $title_template = '';
        if (isset($options['title-' . $post->post_type])) {
            $title_template = $options['title-' . $post->post_type];
        }
        // If there's no title template set, use the default, otherwise title preview won't work.
        if ($title_template == '') {
            $title_template = '%%title%% - %%sitename%%';
        }
        $title_template = wpseo_replace_vars($title_template, $post, array('%%title%%'));
        $metadesc_template = '';
        if (isset($options['metadesc-' . $post->post_type])) {
            $metadesc_template = wpseo_replace_vars($options['metadesc-' . $post->post_type], $post, array('%%excerpt%%', '%%excerpt_only%%'));
        }
        $sample_permalink = get_sample_permalink($post->ID);
        $sample_permalink = str_replace('%page', '%post', $sample_permalink[0]);
        ?>
		<script type="text/javascript">
			var wpseo_lang ='<?php 
        echo substr(get_locale(), 0, 2);
        ?>
';
			var wpseo_meta_desc_length = '<?php 
        echo $this->wpseo_meta_length;
        ?>
';
			var wpseo_title_template = '<?php 
        echo esc_attr($title_template);
        ?>
';
			var wpseo_metadesc_template = '<?php 
        echo esc_attr($metadesc_template);
        ?>
';
			var wpseo_permalink_template = '<?php 
        echo $sample_permalink;
        ?>
';
			var wpseo_keyword_suggest_nonce = '<?php 
        echo wp_create_nonce('wpseo-get-suggest');
        ?>
';
		</script>
		<?php 
    }
Exemple #3
0
function fix_permalink($ID)
{
    $short_codes = array('pt_br', 'en_us', 'es_es');
    list($permalink, $post_name) = get_sample_permalink($ID, null, null);
    $original_slug = $post_name;
    if (!wp_is_post_revision($post_id)) {
        remove_action('save_post', 'fix_permalink');
        foreach ($short_codes as $sc) {
            $pos_sc = strpos($original_slug, $sc);
            if ($pos_sc === FALSE) {
                //avoid return 0 as a valid position
                $found_short_codes[] = 10000;
            } else {
                $found_short_codes[] = $pos_sc;
            }
        }
        if (array_sum($found_short_codes) < 30000) {
            array_multisort($found_short_codes, $short_codes);
            $extracted_text = explode($short_codes[0], $original_slug);
            $new_slug = $extracted_text[1];
        } else {
            $new_slug = $original_slug;
        }
        $update_slug = array('ID' => $ID, 'post_name' => $new_slug);
        wp_update_post($update_slug);
        add_action('save_post', 'fix_permalink');
    }
}
/**
 * Per-post/page options (Wordpress > 2.9)
 *
 * @package CustomPermalinks
 * @since 0.6
 */
function custom_permalink_get_sample_permalink_html($html, $id, $new_title, $new_slug)
{
    $permalink = get_post_meta($id, 'custom_permalink', true);
    $post =& get_post($id);
    ob_start();
    ?>
	<?php 
    custom_permalinks_form($permalink, $post->post_type == "page" ? custom_permalinks_original_page_link($id) : custom_permalinks_original_post_link($id), false);
    ?>
	<?php 
    $content = ob_get_contents();
    ob_end_clean();
    if ('publish' == $post->post_status) {
        $view_post = 'page' == $post->post_type ? __('View Page') : __('View Post');
    }
    if (preg_match("@view-post-btn.*?href='([^']+)'@s", $html, $matches)) {
        $permalink = $matches[1];
    } else {
        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
        if (false !== strpos($permalink, '%postname%') || false !== strpos($permalink, '%pagename%')) {
            $permalink = str_replace(array('%pagename%', '%postname%'), $post_name, $permalink);
        }
    }
    return '<strong>' . __('Permalink:') . "</strong>\n" . $content . (isset($view_post) ? "<span id='view-post-btn'><a href='{$permalink}' class='button' target='_blank'>{$view_post}</a></span>\n" : "");
}
Exemple #5
0
/**
 * Returns the HTML of the sample permalink slug editor.
 *
 * @since 2.5.0
 *
 * @param int|object $id Post ID or post object.
 * @param string $new_title Optional. New title.
 * @param string $new_slug Optional. New slug.
 * @return string The HTML of the sample permalink slug editor.
 */
function get_sample_permalink_html($id, $new_title = null, $new_slug = null)
{
    $post = get_post($id);
    if (!$post) {
        return '';
    }
    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    if ('publish' == get_post_status($post)) {
        $ptype = get_post_type_object($post->post_type);
        $view_post = $ptype->labels->view_item;
        $title = __('Click to edit this part of the permalink');
    } else {
        $title = __('Temporary permalink. Click to edit this part.');
    }
    if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
        if ('' == get_option('permalink_structure') && current_user_can('manage_options') && !('page' == get_option('show_on_front') && $id == get_option('page_on_front'))) {
            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
        }
        if (isset($view_post)) {
            $return .= "<span id='view-post-btn'><a href='{$permalink}' class='button button-small'>{$view_post}</a></span>\n";
        }
        $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
        return $return;
    }
    if (function_exists('mb_strlen')) {
        if (mb_strlen($post_name) > 30) {
            $post_name_abridged = mb_substr($post_name, 0, 14) . '&hellip;' . mb_substr($post_name, -14);
        } else {
            $post_name_abridged = $post_name;
        }
    } else {
        if (strlen($post_name) > 30) {
            $post_name_abridged = substr($post_name, 0, 14) . '&hellip;' . substr($post_name, -14);
        } else {
            $post_name_abridged = $post_name;
        }
    }
    $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    $display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, $permalink);
    $view_link = str_replace(array('%pagename%', '%postname%'), $post_name, $permalink);
    $return = '<strong>' . __('Permalink:') . "</strong>\n";
    $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
    $return .= '&lrm;';
    // Fix bi-directional text display defect in RTL languages.
    $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    if (isset($view_post)) {
        $return .= "<span id='view-post-btn'><a href='{$view_link}' class='button button-small'>{$view_post}</a></span>\n";
    }
    $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
    return $return;
}
Exemple #6
0
/**
 * Returns the HTML of the sample permalink slug editor.
 *
 * @since 2.5.0
 *
 * @param int    $id        Post ID or post object.
 * @param string $new_title Optional. New title. Default null.
 * @param string $new_slug  Optional. New slug. Default null.
 * @return string The HTML of the sample permalink slug editor.
 */
function get_sample_permalink_html($id, $new_title = null, $new_slug = null)
{
    $post = get_post($id);
    if (!$post) {
        return '';
    }
    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    if (current_user_can('read_post', $post->ID)) {
        $ptype = get_post_type_object($post->post_type);
        $view_post = $ptype->labels->view_item;
    }
    if ('publish' == get_post_status($post)) {
        $title = __('Click to edit this part of the permalink');
    } else {
        $title = __('Temporary permalink. Click to edit this part.');
    }
    if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink" tabindex="-1">' . $permalink . "</span>\n";
        if ('' == get_option('permalink_structure') && current_user_can('manage_options') && !('page' == get_option('show_on_front') && $id == get_option('page_on_front'))) {
            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
        }
    } else {
        if (function_exists('mb_strlen')) {
            if (mb_strlen($post_name) > 30) {
                $post_name_abridged = mb_substr($post_name, 0, 14) . '&hellip;' . mb_substr($post_name, -14);
            } else {
                $post_name_abridged = $post_name;
            }
        } else {
            if (strlen($post_name) > 30) {
                $post_name_abridged = substr($post_name, 0, 14) . '&hellip;' . substr($post_name, -14);
            } else {
                $post_name_abridged = $post_name;
            }
        }
        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
        $display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, urldecode($permalink));
        $return = '<strong>' . __('Permalink:') . "</strong>\n";
        $return .= '<span id="sample-permalink" tabindex="-1">' . $display_link . "</span>\n";
        $return .= '&lrm;';
        // Fix bi-directional text display defect in RTL languages.
        $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button button-small hide-if-no-js" onclick="editPermalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
        $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    }
    if (isset($view_post)) {
        if ('draft' == $post->post_status) {
            $preview_link = set_url_scheme(get_permalink($post->ID));
            /** This filter is documented in wp-admin/includes/meta-boxes.php */
            $preview_link = apply_filters('preview_post_link', add_query_arg('preview', 'true', $preview_link), $post);
            $return .= "<span id='view-post-btn'><a href='" . esc_url($preview_link) . "' class='button button-small' target='wp-preview-{$post->ID}'>{$view_post}</a></span>\n";
        } else {
            $return .= "<span id='view-post-btn'><a href='" . get_permalink($post) . "' class='button button-small'>{$view_post}</a></span>\n";
        }
    }
    /**
     * Filter the sample permalink HTML markup.
     *
     * @since 2.9.0
     *
     * @param string      $return    Sample permalink HTML markup.
     * @param int|WP_Post $id        Post object or ID.
     * @param string      $new_title New sample permalink title.
     * @param string      $new_slug  New sample permalink slug.
     */
    $return = apply_filters('get_sample_permalink_html', $return, $id, $new_title, $new_slug);
    return $return;
}
 /**
  * Calculate the page analysis results for post.
  *
  * @param object $post Post to calculate the results for.
  * @return array
  */
 function calculate_results($post)
 {
     $options = get_wpseo_options();
     if (!class_exists('DOMDocument')) {
         $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo'));
         return $result;
     }
     if (!wpseo_get_value('focuskw', $post->ID)) {
         $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type));
         wpseo_set_value('linkdex', 0, $post->ID);
         return $result;
     }
     $results = array();
     $job = array();
     $sampleurl = get_sample_permalink($post);
     $job["pageUrl"] = preg_replace('/%(post|page)name%/', $sampleurl[1], $sampleurl[0]);
     $job["pageSlug"] = urldecode($post->post_name);
     $job["keyword"] = trim(wpseo_get_value('focuskw'));
     $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]);
     $job["post_id"] = $post->ID;
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML($post->post_content);
     $xpath = new DOMXPath($dom);
     $statistics = new Yoast_TextStatistics();
     // Check if this focus keyword has been used already.
     $this->check_double_focus_keyword($job, $results);
     // Keyword
     $this->score_keyword($job['keyword'], $results);
     // Title
     if (wpseo_get_value('title')) {
         $job['title'] = wpseo_get_value('title');
     } else {
         if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] != '') {
             $title_template = $options['title-' . $post->post_type];
         } else {
             $title_template = '%%title%% - %%sitename%%';
         }
         $job['title'] = wpseo_replace_vars($title_template, (array) $post);
     }
     $this->score_title($job, $results, $statistics);
     // Meta description
     $description = '';
     if (wpseo_get_value('metadesc')) {
         $description = wpseo_get_value('metadesc');
     } else {
         if (isset($options['metadesc-' . $post->post_type]) && !empty($options['metadesc-' . $post->post_type])) {
             $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
         }
     }
     $meta_length = apply_filters('wpseo_metadesc_length', 156, $post);
     $this->score_description($job, $results, $description, $statistics, $meta_length);
     unset($description);
     // Body
     $body = $this->get_body($post);
     $firstp = $this->get_first_paragraph($post);
     $this->score_body($job, $results, $body, $firstp, $statistics);
     unset($body);
     unset($firstp);
     // URL
     $this->score_url($job, $results, $statistics);
     // Headings
     $headings = $this->get_headings($post->post_content);
     $this->score_headings($job, $results, $headings);
     unset($headings);
     // Images
     $imgs = array();
     $imgs['count'] = substr_count($post->post_content, '<img');
     $imgs = $this->get_images_alt_text($post, $imgs);
     $this->score_images_alt_text($job, $results, $imgs);
     unset($imgs);
     // Anchors
     $anchors = $this->get_anchor_texts($xpath);
     $count = $this->get_anchor_count($xpath);
     $this->score_anchor_texts($job, $results, $anchors, $count);
     unset($anchors, $count, $dom);
     $results = apply_filters('wpseo_linkdex_results', $results, $job, $post);
     $this->aasort($results, 'val');
     $overall = 0;
     $overall_max = 0;
     foreach ($results as $result) {
         $overall += $result['val'];
         $overall_max += 9;
     }
     if ($overall < 1) {
         $overall = 1;
     }
     $score = round($overall / $overall_max * 100);
     wpseo_set_value('linkdex', absint($score), $post->ID);
     return $results;
 }
function WPSR_render_meta_box($post)
{
    global $wpdb, $table_prefix, $util;
    $table_name = $table_prefix . 'WP_SEO_Redirection';
    if (get_post_status() != 'auto-draft') {
        $permalink = "";
        if (in_array($post->post_status, array('draft', 'pending'))) {
            list($permalink, $postname) = get_sample_permalink($post->ID);
            $permalink = str_replace('%postname%', $postname, $permalink);
        } else {
            $permalink = get_permalink($post->ID);
        }
        $permalink = $util->make_relative_url($permalink);
        $postID = $post->ID;
        $theurl = $wpdb->get_row(" select redirect_to,redirect_from from {$table_name} where postID='{$postID}'  ");
        $urlredirect_to = '';
        if ($wpdb->num_rows > 0) {
            $urlredirect_to = $theurl->redirect_to;
        }
        if ($urlredirect_to != '' && $theurl->redirect_from != $permalink) {
            // the post_name field changed!
            $wpdb->query(" update {$table_name} set redirect_from='{$permalink}'  where postID='{$postID}' ");
            if ($util->get_option_value('reflect_modifications') == '1') {
                $wpdb->query(" update {$table_name} set redirect_to='{$permalink}'  where redirect_to='" . $theurl->redirect_from . "' ");
                $util->info_option_msg('<b>SEO Redirection</b> has detected a change in Permalink, this will be reflected to the redirection records!');
            }
            //-------------------------------------------
        }
        echo '
<table border="0" width="100%" cellpadding="2">
	<tr>
		<td width="99%"><input onchange="redirect_check_click()" type="checkbox" name="redirect_check"  id="redirect_check" value="ON">
		Redirect&nbsp;<font color="#008000">' . $permalink . '</font><input type="hidden" name="wp_seo_redirection_url_from" value="' . $permalink . '"></td>
	</tr>
</table>
<div id="redirect_frame">
<table border="0" width="100%" cellpadding="2">
	<tr>
		<td><b>Redirect to</b> <input type="text" name="wp_seo_redirection_url" id="wp_seo_redirection_url" value="' . $urlredirect_to . '" size="62"></td>
	</tr>
	<tr>
		<td>
		<ul>
			<li>To make a redirection, put the full <b>URL</b> including <b>\'http://\'</b> in the text field above and then click the button <b>Update</b>.</li>
			<li>If you have a caching plugin installed, clear cache to reflect the
			changes immediately.</li>

			<li>To remove the redirection, just uncheck the check box above and then click the button <b>Update</b>.</li>
		</ul>
		</td>
	</tr>
</table>
</div>';
        echo "\n\n<script type='text/javascript'>\nfunction WSR_check_status(x)\n{\n\tif(x==0)\n\t{\n\t\tdocument.getElementById('redirect_check').checked=false;\n\t\tdocument.getElementById('redirect_frame').style.display = 'none';\n\t\tdocument.getElementById('wp_seo_redirection_url').value='';\n\t}else\n\t{\n\t   \tdocument.getElementById('redirect_check').checked=true;\n\t   \tdocument.getElementById('redirect_frame').style.display= 'block';\n\t}\n\n}\n\nfunction redirect_check_click()\n{\n\tif(document.getElementById('redirect_check').checked)\n\tWSR_check_status(1);\n\telse\n\tWSR_check_status(0);\n}\n</script>\n";
        if ($urlredirect_to == '') {
            echo "<script type='text/javascript'>WSR_check_status(0);</script>";
        } else {
            echo "<script type='text/javascript'>WSR_check_status(1);</script>";
        }
    } else {
        echo 'You can not make a redirection for the new posts before saving them.';
    }
}
Exemple #9
0
 function output($post)
 {
     global $wpseo_metabox;
     $options = get_wpseo_options();
     if (is_int($post)) {
         $post = get_post($post);
     }
     if (!$post) {
         return;
     }
     if (!class_exists('DOMDocument')) {
         $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . sprintf(__("your hosting environment does not support PHP's %sDocument Object Model%s."), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.") . '</p></div>';
         return $output;
     }
     if (!wpseo_get_value('focuskw')) {
         $output = '<div class="wpseo_msg"><p><strong>' . __('Error') . ':</strong> ' . __("you have not specified a focus keyword, you'll have to enter one, then save or update this post, before this report works.") . '</p></div>';
         return $output;
     }
     $output = '<div class="wpseo_msg"><p><strong>' . __('Note') . ':</strong> ' . __('to update this page analysis, save as draft or update and check this tab again') . '.</p></div>';
     $results = '';
     $job = array();
     $sampleurl = get_sample_permalink($post->ID);
     $job["pageUrl"] = str_replace('%postname%', $sampleurl[1], $sampleurl[0]);
     $job["pageSlug"] = urldecode($post->post_name);
     $job["keyword"] = wpseo_get_value('focuskw');
     $job["keyword_folded"] = $this->strip_separators_and_fold($job["keyword"]);
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     @$dom->loadHTML($post->post_content);
     $xpath = new DOMXPath($dom);
     $statistics = new TextStatistics();
     // Keyword
     $this->ScoreKeyword($job, $results);
     // Title
     if (wpseo_get_value('title')) {
         $title = wpseo_get_value('title');
     } else {
         if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] != '') {
             $title_template = $options['title-' . $post->post_type];
         } else {
             $title_template = '%%title%% - %%sitename%%';
         }
         $title = wpseo_replace_vars($title_template, (array) $post);
     }
     $this->ScoreTitle($job, $results, $title, $statistics);
     unset($title);
     // Meta description
     $description = '';
     if (wpseo_get_value('metadesc')) {
         $description = wpseo_get_value('metadesc');
     } else {
         if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] != '') {
             $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
         }
     }
     $this->ScoreDescription($job, $results, $description, $wpseo_metabox->wpseo_meta_length, $statistics);
     unset($description);
     // Body
     $body = $this->GetBody($post);
     $firstp = $this->GetFirstParagraph($post);
     $this->ScoreBody($job, $results, $body, $firstp, $statistics);
     unset($body);
     unset($firstp);
     // URL
     $this->ScoreUrl($job, $results, $statistics);
     // Headings
     $headings = $this->GetHeadings($post->post_content);
     $this->ScoreHeadings($job, $results, $headings);
     unset($headings);
     // Images
     $alts = $this->GetImagesAltText($post->post_content);
     $imgs = $this->GetImageCount($dom, $xpath);
     $this->ScoreImagesAltText($job, $results, $alts, $imgs);
     unset($alts);
     unset($imgs);
     // Anchors
     $anchors = $this->GetAnchorTexts($dom, $xpath);
     $count = $this->GetAnchorCount($dom, $xpath);
     $this->ScoreAnchorTexts($job, $results, $anchors, $count);
     unset($anchors);
     unset($count);
     unset($dom);
     asort($results);
     $output .= '<table class="wpseoanalysis">';
     foreach ($results as $result) {
         $scoreval = substr($result, 0, 1);
         switch ($scoreval) {
             case 1:
             case 2:
             case 3:
                 $score = 'poor';
                 break;
             case 4:
             case 5:
             case 6:
                 $score = 'ok';
                 break;
             case 7:
             case 8:
             case 9:
                 $score = 'good';
                 break;
         }
         $analysis = substr($result, 2, strlen($result));
         $output .= '<tr><td class="score"><img alt="' . $score . '" src="' . WPSEO_URL . 'images/score_' . $score . '.png"/></td><td>' . $analysis . '</td></tr>';
     }
     $output .= '</table>';
     $output .= '<hr/>';
     $output .= '<p style="font-size: 13px;"><a href="http://yoa.st/linkdex"><img class="alignleft" style="margin: 0 10px 5px 0;" src="' . WPSEO_URL . 'images/linkdex-logo.png" alt="Linkdex"/></a>' . 'This page analysis brought to you by the collaboration of Yoast and <a href="http://yoa.st/linkdex">Linkdex</a>. <a href="http://yoa.st/linkdex">Linkdex</a> is an SEO suite that helps you optimize your site and offers you all the SEO tools you\'ll need. Yoast uses <a href="http://yoa.st/linkdex">Linkdex</a> and highly recommends you do too!' . '</p>';
     unset($results);
     unset($job);
     return $output;
 }
 public function insert(&$obj)
 {
     // Incluir post do evento
     /* @var $wpdb wpdb */
     $values = array('post_title' => $obj->titulo, 'post_status' => 'publish', 'post_type' => 'tgo_evento', 'post_date' => 'current_timestamp', 'post_date_gmt' => 'current_timestamp');
     $filter = function_exists('wp_db_null_value') ? 'wp_db_null_value' : 'DB::wpDbNullValue';
     add_filter('query', $filter);
     $ok = $this->wpdb()->insert($this->tableName, $values);
     if ($ok === false) {
         throw new \Exception($this->wpdb()->last_error);
     }
     $id = $this->wpdb()->insert_id;
     remove_filter('query', $filter);
     $evento = $this->getById($id);
     // Obter permalink
     get_sample_permalink($id, $evento->titulo);
     $post_id = $id;
     // Descricao2
     meta_update($post_id, 'descricao_2', false);
     meta_update($post_id, 'descricao_3', false);
     // Publico Alvo
     meta_update($post_id, 'publico_alvo');
     // Local
     meta_update($post_id, 'id_local', false);
     // Organizador
     if (get_option('singleOrganizer', true) && get_option('idSingleOrganizer', null) != null) {
         update_post_meta($post_id, 'id_organizador', get_option('idSingleOrganizer'));
     } else {
         meta_update($post_id, 'id_organizador', false);
     }
     meta_update($post_id, 'data');
     meta_update($post_id, 'hora');
     meta_update($post_id, 'data_fim');
     meta_update($post_id, 'hora_fim');
     meta_update($post_id, 'vagas');
     meta_update($post_id, 'pago');
     meta_update($post_id, 'valor');
     return $this->getById($id);
 }
Exemple #11
0
 /**
  * Hack to work around post status check in get_sample_permalink_html
  * 
  * 
  * The get_sample_permalink_html checks the status of the post and if it's
  * a draft generates a certain permalink structure.
  * We need to do the same work it's doing for custom statuses in order
  * to support this link
  * @see https://core.trac.wordpress.org/browser/tags/4.5.2/src/wp-admin/includes/post.php#L1296
  *
  * @since 0.8.2
  * 
  * @param string  $return    Sample permalink HTML markup
  * @param int 	  $post_id   Post ID
  * @param string  $new_title New sample permalink title
  * @param string  $new_slug  New sample permalink kslug
  * @param WP_Post $post 	 Post object
  */
 function fix_get_sample_permalink_html($return, $post_id, $new_title, $new_slug, $post)
 {
     $status_slugs = wp_list_pluck($this->get_custom_statuses(), 'slug');
     list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
     $view_link = false;
     $preview_target = '';
     if (current_user_can('read_post', $post_id)) {
         if (in_array($post->post_status, $status_slugs)) {
             $view_link = $this->get_preview_link($post);
             $preview_target = " target='wp-preview-{$post->ID}'";
         } else {
             if ('publish' === $post->post_status || 'attachment' === $post->post_type) {
                 $view_link = get_permalink($post);
             } else {
                 // Allow non-published (private, future) to be viewed at a pretty permalink.
                 $view_link = str_replace(array('%pagename%', '%postname%'), $post->post_name, $permalink);
             }
         }
     }
     // Permalinks without a post/page name placeholder don't have anything to edit
     if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
         $return = '<strong>' . __('Permalink:') . "</strong>\n";
         if (false !== $view_link) {
             $display_link = urldecode($view_link);
             $return .= '<a id="sample-permalink" href="' . esc_url($view_link) . '"' . $preview_target . '>' . $display_link . "</a>\n";
         } else {
             $return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
         }
         // Encourage a pretty permalink setting
         if ('' == get_option('permalink_structure') && current_user_can('manage_options') && !('page' == get_option('show_on_front') && $id == get_option('page_on_front'))) {
             $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
         }
     } else {
         if (function_exists('mb_strlen')) {
             if (mb_strlen($post_name) > 34) {
                 $post_name_abridged = mb_substr($post_name, 0, 16) . '&hellip;' . mb_substr($post_name, -16);
             } else {
                 $post_name_abridged = $post_name;
             }
         } else {
             if (strlen($post_name) > 34) {
                 $post_name_abridged = substr($post_name, 0, 16) . '&hellip;' . substr($post_name, -16);
             } else {
                 $post_name_abridged = $post_name;
             }
         }
         $post_name_html = '<span id="editable-post-name">' . $post_name_abridged . '</span>';
         $display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, urldecode($permalink));
         $return = '<strong>' . __('Permalink:') . "</strong>\n";
         $return .= '<span id="sample-permalink"><a href="' . esc_url($view_link) . '"' . $preview_target . '>' . $display_link . "</a></span>\n";
         $return .= '&lrm;';
         // Fix bi-directional text display defect in RTL languages.
         $return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __('Edit permalink') . '">' . __('Edit') . "</button></span>\n";
         $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
     }
     return $return;
 }
function uci_display_permalink_metabox($post)
{
    $permalink = get_permalink($post->ID);
    if (in_array($post->post_status, array('draft', 'pending', 'auto-draft'))) {
        require_once ABSPATH . '/wp-admin/includes/post.php';
        list($permalink, $postname) = get_sample_permalink($post->ID);
        $permalink = str_replace('%pagename%', $postname, $permalink);
    }
    ?>
    <script type="text/javascript">
        jQuery(document).on('focus', '#<?php 
    echo UCI_META_PERMALINK;
    ?>
:text', function(e) {
            jQuery(this).select();
        }).on('mouseup', '#<?php 
    echo UCI_META_PERMALINK;
    ?>
:text', function(e) {
            e.preventDefault();
        });
    </script>
    <input style="width:100%;" type="text" name="<?php 
    echo UCI_META_PERMALINK;
    ?>
" id="<?php 
    echo UCI_META_PERMALINK;
    ?>
" value="<?php 
    echo $permalink;
    ?>
" />
    <?php 
}
Exemple #13
0
    /**
     * Output the permalink editing form with the option to fully customise the
     * slug alongside the default editing option.
     *
     * NOTE: A custom filter is applied here, allowing you to modify the
     * permalink structure via external plugins by adding a filter:
     * add_filter( 'get_custom_permalink_sample', 'callback_function', 1, 2 );
     *
     * @param string $html
     * @param int|object $id
     * @param string $new_title
     * @param string $new_slug
     */
    function get_sample_permalink_html($html, $id, $new_title, $new_slug)
    {
        $post =& get_post($id);
        // Get the current original...
        list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
        // Define the home url...
        $home_url = home_url('/');
        // Fetch the default permalink...
        $this->remove_filters($this->individual_permalink_filters);
        list($default, ) = get_sample_permalink($post->ID);
        // Build the default permalink and replace any tokens...
        $default_permalink = apply_filters('get_custom_permalink_sample', $this->build_permalink($default, $post_name), $post);
        $this->add_filters($this->individual_permalink_filters);
        // Set the permalink to the new one...
        if (isset($_REQUEST['custom_slug'])) {
            $custom_slug = $this->reformat_permalink($_REQUEST['custom_slug'], '');
            if (!empty($custom_slug) && !$this->permalinks_match($custom_slug, $default_permalink)) {
                $post_name = $this->unique_custom_permalink($post->ID, $custom_slug);
                $permalink = $home_url . $post_name;
            } else {
                $permalink = $default;
            }
        } else {
            if ($new_slug) {
                $permalink = $default;
            } else {
                if ($custom = get_post_meta($id, '_' . $this->tag, true)) {
                    $post_name = ltrim($custom, '/');
                    $permalink = $home_url . $post_name;
                }
            }
        }
        // By default we will display the permalink as it is...
        $view_link = $permalink;
        // Fetch the post type label and set the edit title...
        if ('publish' == $post->post_status) {
            $post_type = get_post_type_object($post->post_type);
            $view_post = $post_type->labels->view_item;
            $title = __('Click to edit this part of the permalink');
        } else {
            $title = __('Temporary permalink. Click to edit this part.');
        }
        // Run the permalink through our custom filter...
        $permalink = apply_filters('get_custom_permalink_sample', remove_accents($permalink), $post);
        // Highlight the post name in the permalink...
        $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name . '</span>';
        ob_start();
        ?>
		<strong><?php 
        _e('Permalink:');
        ?>
</strong>
		<?php 
        if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
            $display_link = str_replace($permalink, $post_name_html, $view_link);
            ?>
			<?php 
            echo $home_url;
            ?>
<span id="sample-permalink"><?php 
            echo $display_link;
            ?>
</span>
		<?php 
        } else {
            $view_link = $home_url . $this->build_permalink($permalink, $post_name);
            $display_link = $this->build_permalink($permalink, $post_name_html);
            ?>
			<?php 
            echo $home_url;
            ?>
<span id="sample-permalink"><?php 
            echo $display_link;
            ?>
</span>
			&lrm;
			<span id="edit-slug-buttons">
				<a href="#post_name"
					class="edit-slug button hide-if-no-js"
					onclick="editOriginalPermalink(<?php 
            echo $id;
            ?>
); return false;"><?php 
            _e('Edit');
            ?>
</a>
			</span>
		<?php 
        }
        ?>
			<span id="customise-permalink-buttons">
				<a href="#"
					class="customise-permalink button hide-if-no-js"
					onclick="editCustomPermalink(<?php 
        echo $id;
        ?>
); return false;"><?php 
        _e('Customise');
        ?>
</a>
			</span>
			<span id="editable-post-name-full"><?php 
        echo $post_name;
        ?>
</span>
		<?php 
        // If the post is publicly viewable, display permalink view options...
        if (isset($view_post)) {
            ?>
			<span id="view-post-btn">
				<a href="<?php 
            echo $view_link;
            ?>
"
					class="button"
					target="_blank"><?php 
            echo $view_post;
            ?>
</a>
			</span>
			<?php 
            if ($new_title && ($shortlink = wp_get_shortlink($post->ID, $post->post_type))) {
                ?>
    		<input id="shortlink" type="hidden" value="<?php 
                esc_attr_e($shortlink);
                ?>
" />
    		<a href="#"
    			class="button hide-if-nojs"
    			onclick="prompt( 'URL:', jQuery( '#shortlink' ).val() ); return false;"><?php 
                _e('Get Shortlink');
                ?>
</a>
			<?php 
            }
            ?>
		<?php 
        }
        $return = ob_get_contents();
        ob_end_clean();
        return $return;
    }
Exemple #14
0
 /**
  * @ticket 5305
  */
 public function test_get_sample_permalink_should_allow_daylike_slugs_if_permastruct_does_not_cause_an_archive_conflict()
 {
     global $wp_rewrite;
     $wp_rewrite->init();
     $wp_rewrite->set_permalink_structure('/%year%/%month%/%day%/%postname%/');
     $wp_rewrite->flush_rules();
     $p = $this->factory->post->create(array('post_name' => '30'));
     $found = get_sample_permalink($p);
     $this->assertEquals('30', $found[1]);
     $wp_rewrite->set_permalink_structure('');
     flush_rewrite_rules();
 }
 /**
  * Get extra post permalink suggestions
  * @return array	array of permalink suggestions: 'permalink_URL', 'suggested_slug'
  */
 public function get_permalink_suggestions($title)
 {
     $suggestions = array();
     list($suggestions['permalink_URL'], $suggestions['suggested_slug']) = get_sample_permalink($this->post->ID, $title);
     return $suggestions;
 }
Exemple #16
0
 /**
  * Calculate the page analysis results for post.
  *
  * @todo [JRF => whomever] check whether the results of this method are always checked with is_wp_error()
  * @todo [JRF => whomever] check the usage of this method as it's quite intense/heavy, see if it's only
  * used when really necessary
  * @todo [JRF => whomever] see if we can get rid of the passing by reference of $results as it makes
  * the code obfuscated
  *
  * @param  object $post Post to calculate the results for.
  *
  * @return  array|WP_Error
  */
 function calculate_results($post)
 {
     $options = WPSEO_Options::get_all();
     if (!class_exists('DOMDocument')) {
         $result = new WP_Error('no-domdocument', sprintf(__("Your hosting environment does not support PHP's %sDocument Object Model%s.", 'wordpress-seo'), '<a href="http://php.net/manual/en/book.dom.php">', '</a>') . ' ' . __("To enjoy all the benefits of the page analysis feature, you'll need to (get your host to) install it.", 'wordpress-seo'));
         return $result;
     }
     if (!is_array($post) && !is_object($post)) {
         $result = new WP_Error('no-post', __('No post content to analyse.', 'wordpress-seo'));
         return $result;
     } elseif (self::get_value('focuskw', $post->ID) === '') {
         $result = new WP_Error('no-focuskw', sprintf(__('No focus keyword was set for this %s. If you do not set a focus keyword, no score can be calculated.', 'wordpress-seo'), $post->post_type));
         self::set_value('linkdex', 0, $post->ID);
         return $result;
     } elseif (apply_filters('wpseo_use_page_analysis', true) !== true) {
         $result = new WP_Error('page-analysis-disabled', sprintf(__('Page Analysis has been disabled.', 'wordpress-seo'), $post->post_type));
         return $result;
     }
     $results = array();
     $job = array();
     $sampleurl = get_sample_permalink($post);
     $job['pageUrl'] = preg_replace('`%(?:post|page)name%`', $sampleurl[1], $sampleurl[0]);
     $job['pageSlug'] = urldecode($post->post_name);
     $job['keyword'] = self::get_value('focuskw');
     $job['keyword_folded'] = $this->strip_separators_and_fold($job['keyword']);
     $job['post_id'] = $post->ID;
     $job['post_type'] = $post->post_type;
     $dom = new domDocument();
     $dom->strictErrorChecking = false;
     $dom->preserveWhiteSpace = false;
     /**
      * Filter: 'wpseo_pre_analysis_post_content' - Make the post content filterable before calculating the page analysis
      *
      * @api string $post_content The post content
      * @param object $post The post
      */
     $post_content = apply_filters('wpseo_pre_analysis_post_content', $post->post_content, $post);
     // Check if the post content is not empty
     if (!empty($post_content)) {
         @$dom->loadHTML($post_content);
     }
     unset($post_content);
     $xpath = new DOMXPath($dom);
     // Check if this focus keyword has been used already.
     $this->check_double_focus_keyword($job, $results);
     // Keyword
     $this->score_keyword($job['keyword'], $results);
     // Title
     $title = self::get_value('title');
     if ($title !== '') {
         $job['title'] = $title;
     } else {
         if (isset($options['title-' . $post->post_type]) && $options['title-' . $post->post_type] !== '') {
             $title_template = $options['title-' . $post->post_type];
         } else {
             $title_template = '%%title%% - %%sitename%%';
         }
         $job['title'] = wpseo_replace_vars($title_template, (array) $post);
     }
     unset($title);
     $this->score_title($job, $results);
     // Meta description
     $description = '';
     $desc_meta = self::get_value('metadesc');
     if ($desc_meta !== '') {
         $description = $desc_meta;
     } else {
         if (isset($options['metadesc-' . $post->post_type]) && $options['metadesc-' . $post->post_type] !== '') {
             $description = wpseo_replace_vars($options['metadesc-' . $post->post_type], (array) $post);
         }
     }
     unset($desc_meta);
     self::$meta_length = apply_filters('wpseo_metadesc_length', self::$meta_length, $post);
     $this->score_description($job, $results, $description, self::$meta_length);
     unset($description);
     // Body
     $body = $this->get_body($post);
     $firstp = $this->get_first_paragraph($body);
     $this->score_body($job, $results, $body, $firstp);
     unset($firstp);
     // URL
     $this->score_url($job, $results);
     // Headings
     $headings = $this->get_headings($body);
     $this->score_headings($job, $results, $headings);
     unset($headings);
     // Images
     $imgs = array();
     $imgs['count'] = substr_count($body, '<img');
     $imgs = $this->get_images_alt_text($post->ID, $body, $imgs);
     // Check featured image
     if (function_exists('has_post_thumbnail') && has_post_thumbnail()) {
         $imgs['count'] += 1;
         if (empty($imgs['alts'])) {
             $imgs['alts'] = array();
         }
         $feature_image = get_the_post_thumbnail($post->ID);
         if (preg_match('`alt=(["\'])(.*?)\\1`', $feature_image, $alt) && isset($alt[2])) {
             $imgs['alts'][] = $this->strtolower_utf8($alt[2]);
         }
     }
     $this->score_images_alt_text($job, $results, $imgs);
     unset($imgs);
     unset($body);
     // Anchors
     $anchors = $this->get_anchor_texts($xpath);
     $count = $this->get_anchor_count($xpath);
     $this->score_anchor_texts($job, $results, $anchors, $count);
     unset($anchors, $count, $dom);
     $results = apply_filters('wpseo_linkdex_results', $results, $job, $post);
     $this->aasort($results, 'val');
     $overall = 0;
     $overall_max = 0;
     foreach ($results as $result) {
         $overall += $result['val'];
         $overall_max += 9;
     }
     if ($overall < 1) {
         $overall = 1;
     }
     $score = wpseo_calc(wpseo_calc($overall, '/', $overall_max), '*', 100, true);
     self::set_value('linkdex', absint($score), $post->ID);
     return $results;
 }
 function get_sample_permalink($post)
 {
     $_post = get_post($post);
     $_post->post_status = 'published';
     $sample = get_sample_permalink($_post);
     return $sample[0];
 }
 /**
  * Include admin post code if necessary.
  *
  * @link https://github.com/iseulde/wp-front-end-editor/pull/230
  */
 function get_sample_permalink($post)
 {
     $_post = get_post($post);
     $_post->post_status = 'published';
     // MOD by CAC
     if (!function_exists('get_sample_permalink')) {
         require_once ABSPATH . '/wp-admin/includes/post.php';
     }
     // end MOD
     $sample = get_sample_permalink($_post);
     return $sample[0];
 }
function kapost_byline_xmlrpc_getPermalink($args)
{
    global $wp_xmlrpc_server;
    $wp_xmlrpc_server->escape($args);
    $post_id = intval($args[0]);
    $username = $args[1];
    $password = $args[2];
    if (!($user = $wp_xmlrpc_server->login($username, $password))) {
        return $wp_xmlrpc_server->error;
    }
    if (!current_user_can('edit_post', $post_id)) {
        return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
    }
    $post = get_post($post_id);
    if (!is_object($post) || !isset($post->ID)) {
        return new IXR_Error(401, __('Sorry, you cannot edit this post.'));
    }
    list($permalink, $post_name) = get_sample_permalink($post->ID);
    $permalink = str_replace(array('%postname%', '%pagename%'), $post_name, $permalink);
    if (strpos($permalink, "%") === false) {
        # make sure it doesn't contain %day%, etc.
        return $permalink;
    }
    return get_permalink($post);
}
 /**
  * @ticket 5305
  */
 public function test_get_sample_permalink_should_allow_daylike_slugs_if_permastruct_does_not_cause_an_archive_conflict()
 {
     $this->set_permalink_structure('/%year%/%month%/%day%/%postname%/');
     $p = self::factory()->post->create(array('post_name' => '30'));
     $found = get_sample_permalink($p);
     $this->assertEquals('30', $found[1]);
 }
 /**
  * @ticket 35368
  */
 public function test_get_sample_permalink_should_respect_hierarchy_of_draft_pages()
 {
     $this->set_permalink_structure('/%postname%/');
     $parent = self::factory()->post->create(array('post_type' => 'page', 'post_title' => 'Parent Page'));
     $child = self::factory()->post->create(array('post_type' => 'page', 'post_title' => 'Child Page', 'post_parent' => $parent, 'post_status' => 'draft'));
     $actual = get_sample_permalink($child);
     $this->assertSame(home_url() . '/parent-page/%pagename%/', $actual[0]);
     $this->assertSame('child-page', $actual[1]);
 }
    /**
     * Add language tabs to wpseo metabox ( .wpseo-metabox-tabs-div )
     */
    public static function action__wpseo_tab_content()
    {
        /** @global WP_Post $post */
        global $post;
        $type = empty($post) ? '' : $post->post_type;
        if (WPGlobus::O()->disabled_entity($type)) {
            return;
        }
        $permalink = array();
        if ('publish' === $post->post_status) {
            $permalink['url'] = get_permalink($post->ID);
            $permalink['action'] = 'complete';
        } else {
            $permalink['url'] = trailingslashit(home_url());
            $permalink['action'] = '';
        }
        // #wpseo-metabox-tabs
        /**
         * Array of id to make multilingual
         */
        $ids = array('wpseo-add-keyword-popup', 'wpseosnippet', 'snippet_preview', 'title_container', 'snippet_title', 'snippet_sitename', 'url_container', 'snippet_citeBase', 'snippet_cite', 'meta_container', 'snippet_meta', 'yoast_wpseo_focuskw_text_input', 'yoast_wpseo_focuskw', 'focuskwresults', 'yoast_wpseo_title', 'yoast_wpseo_metadesc', 'yoast_wpseo_linkdex', 'wpseo-pageanalysis', 'yoast-seo-content-analysis', 'YoastSEO-plugin-loading', 'snippet-editor-title', 'snippet-editor-slug', 'snippet-editor-meta-description');
        $names = array('yoast_wpseo_focuskw_text_input', 'yoast_wpseo_focuskw', 'yoast_wpseo_title', 'yoast_wpseo_metadesc', 'yoast_wpseo_linkdex');
        $qtip = array('snippetpreviewhelp', 'focuskw_text_inputhelp', 'pageanalysishelp', 'snippetpreview-help', 'focuskw_text_input-help', 'pageanalysis-help', 'snippetpreview-help-toggle', 'focuskw_text_input-help-toggle', 'pageanalysis-help-toggle');
        ?>

		<div id="wpglobus-wpseo-tabs" style="width:90%; float:right;">    <?php 
        /**
         * Use span with attributes 'data' for send to js script ids, names elements for which needs to be set new ids, names with language code.
         */
        ?>
			<span id="wpglobus-wpseo-attr"
			      data-ids="<?php 
        echo esc_attr(implode(',', $ids));
        ?>
"
			      data-names="<?php 
        echo esc_attr(implode(',', $names));
        ?>
"
			      data-qtip="<?php 
        echo esc_attr(implode(',', $qtip));
        ?>
">
			</span>
			<ul class="wpglobus-wpseo-tabs-list">    <?php 
        $order = 0;
        foreach (WPGlobus::Config()->open_languages as $language) {
            ?>
					<li id="wpseo-link-tab-<?php 
            echo esc_attr($language);
            ?>
"
					    data-language="<?php 
            echo esc_attr($language);
            ?>
"
					    data-order="<?php 
            echo esc_attr($order);
            ?>
"
					    class="wpglobus-wpseo-tab"><a
							href="#wpseo-tab-<?php 
            echo $language;
            ?>
"><?php 
            echo esc_attr(WPGlobus::Config()->en_language_name[$language]);
            ?>
</a>
					</li> <?php 
            $order++;
        }
        ?>
			</ul> <?php 
        /**
         * Get meta description
         */
        $metadesc = get_post_meta($post->ID, '_yoast_wpseo_metadesc', true);
        /**
         * Get title
         */
        $wpseotitle = get_post_meta($post->ID, '_yoast_wpseo_title', true);
        /**
         * From Yoast3 focus keyword key is '_yoast_wpseo_focuskw_text_input'
         */
        $focuskw = get_post_meta($post->ID, '_yoast_wpseo_focuskw_text_input', true);
        /**
         * make yoast cite base
         */
        list($yoast_permalink) = get_sample_permalink($post->ID);
        $yoast_permalink = str_replace(array('%pagename%', '%postname%'), '', urldecode($yoast_permalink));
        /**
         *  Set cite does not editable by default
         */
        $cite_contenteditable = 'false';
        foreach (WPGlobus::Config()->open_languages as $language) {
            $yoast_cite_base = WPGlobus_Utils::localize_url($yoast_permalink, $language);
            $yoast_cite_base = str_replace(array('http://', 'https://'), '', $yoast_cite_base);
            $yoast_cite_base = str_replace('//', '/', $yoast_cite_base);
            $permalink['url'] = WPGlobus_Utils::localize_url($permalink['url'], $language);
            $url = apply_filters('wpglobus_wpseo_permalink', $permalink['url'], $language);
            if ($url !== $permalink['url']) {
                /* We accept that user's filter make complete permalink for draft */
                /* @todo maybe need more investigation */
                $permalink['action'] = 'complete';
            } else {
                if ('publish' !== $post->post_status) {
                    /**
                     * We cannot get post-name-full to make correct url here ( for draft & auto-draft ). We do it in JS
                     * @see var wpseosnippet_url in wpglobus-wpseo-**.js
                     */
                    $permalink['action'] = '';
                }
            }
            ?>
				<div id="wpseo-tab-<?php 
            echo $language;
            ?>
" class="wpglobus-wpseo-general"
				     data-language="<?php 
            echo $language;
            ?>
"
				     data-url-<?php 
            echo $language;
            ?>
="<?php 
            echo esc_attr($url);
            ?>
"
				     data-yoast-cite-base="<?php 
            echo esc_attr($yoast_cite_base);
            ?>
"
				     data-cite-contenteditable="<?php 
            echo esc_attr($cite_contenteditable);
            ?>
"
				     data-permalink="<?php 
            echo esc_attr($permalink['action']);
            ?>
"
				     data-metadesc="<?php 
            echo esc_attr(WPGlobus_Core::text_filter($metadesc, $language, WPGlobus::RETURN_EMPTY));
            ?>
"
				     data-wpseotitle="<?php 
            echo esc_attr(WPGlobus_Core::text_filter($wpseotitle, $language, WPGlobus::RETURN_EMPTY));
            ?>
"
				     data-focuskw="<?php 
            echo esc_attr(WPGlobus_Core::text_filter($focuskw, $language, WPGlobus::RETURN_EMPTY));
            ?>
">
				</div> <?php 
        }
        ?>
		</div>
		<?php 
    }
Exemple #23
0
/**
 * {@internal Missing Short Description}}
 *
 * @since unknown
 *
 * @param unknown_type $id
 * @param unknown_type $new_title
 * @param unknown_type $new_slug
 * @return unknown
 */
function get_sample_permalink_html($id, $new_title = null, $new_slug = null)
{
    $post =& get_post($id);
    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    if ('publish' == $post->post_status) {
        $view_post = 'post' == $post->post_type ? __('View Post') : __('View Page');
    }
    if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
        $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $permalink . "</span>\n";
        $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
        if (isset($view_post)) {
            $return .= "<span id='view-post-btn'><a href='{$permalink}' class='button' target='_blank'>{$view_post}</a></span>\n";
        }
        return $return;
    }
    $title = __('Click to edit this part of the permalink');
    if (function_exists('mb_strlen')) {
        if (mb_strlen($post_name) > 30) {
            $post_name_abridged = mb_substr($post_name, 0, 14) . '&hellip;' . mb_substr($post_name, -14);
        } else {
            $post_name_abridged = $post_name;
        }
    } else {
        if (strlen($post_name) > 30) {
            $post_name_abridged = substr($post_name, 0, 14) . '&hellip;' . substr($post_name, -14);
        } else {
            $post_name_abridged = $post_name;
        }
    }
    $post_name_html = '<span id="editable-post-name" title="' . $title . '">' . $post_name_abridged . '</span>';
    $display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, $permalink);
    $view_link = str_replace(array('%pagename%', '%postname%'), $post_name, $permalink);
    $return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
    $return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug button" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
    $return .= '<span id="editable-post-name-full">' . $post_name . "</span>\n";
    if (isset($view_post)) {
        $return .= "<span id='view-post-btn'><a href='{$view_link}' class='button' target='_blank'>{$view_post}</a></span>\n";
    }
    return $return;
}
function get_sample_permalink_html($id, $new_title=null, $new_slug=null) {
	$post = &get_post($id);
	list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
	if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
		return '';
	}
	$title = __('Click to edit this part of the permalink');
	if (strlen($post_name) > 30) {
		$post_name_abridged = substr($post_name, 0, 14). '&hellip;' . substr($post_name, -14);
	} else {
		$post_name_abridged = $post_name;
	}
	$post_name_html = '<span id="editable-post-name" title="'.$title.'">'.$post_name_abridged.'</span><span id="editable-post-name-full">'.$post_name.'</span>';
	$display_link = str_replace(array('%pagename%','%postname%'), $post_name_html, $permalink);
	$return = '<strong>' . __('Permalink:') . "</strong>\n" . '<span id="sample-permalink">' . $display_link . "</span>\n";
	$return .= '<span id="edit-slug-buttons"><a href="#post_name" class="edit-slug" onclick="edit_permalink(' . $id . '); return false;">' . __('Edit') . "</a></span>\n";
	return $return;
}
 /**
  * Get sample permalink
  *
  * @param    object $post
  *
  * @return    array
  */
 function get_sample_permalink($post)
 {
     if (!function_exists('get_sample_permalink')) {
         // Front-end post update
         include_once ABSPATH . 'wp-admin/includes/post.php';
     }
     return get_sample_permalink($post);
 }
	/**
	 * @ticket 30910
	 */
	public function test_get_sample_permalink_should_return_pretty_permalink_for_posts_with_post_status_future() {
		global $wp_rewrite;

		$old_permalink_structure = get_option( 'permalink_structure' );
		$permalink_structure = '%postname%';
		$wp_rewrite->set_permalink_structure( "/$permalink_structure/" );
		flush_rewrite_rules();

		$future_date = date( 'Y-m-d H:i:s', time() + 100 );
		$p = $this->factory->post->create( array( 'post_status' => 'future', 'post_name' => 'foo', 'post_date' => $future_date ) );

		$found = get_sample_permalink( $p );
		$expected = trailingslashit( home_url( $permalink_structure ) );

		$this->assertSame( $expected, $found[0] );

		$wp_rewrite->set_permalink_structure( $old_permalink_structure );
		flush_rewrite_rules();
	}
Exemple #27
0
/**
 * Returns the HTML of the sample permalink slug editor.
 *
 * @since 2.5.0
 *
 * @param int    $id        Post ID or post object.
 * @param string $new_title Optional. New title. Default null.
 * @param string $new_slug  Optional. New slug. Default null.
 * @return string The HTML of the sample permalink slug editor.
 */
function get_sample_permalink_html($id, $new_title = null, $new_slug = null)
{
    $post = get_post($id);
    if (!$post) {
        return '';
    }
    list($permalink, $post_name) = get_sample_permalink($post->ID, $new_title, $new_slug);
    $view_link = false;
    $preview_target = '';
    if (current_user_can('read_post', $post->ID)) {
        if ('draft' === $post->post_status || empty($post->post_name)) {
            $view_link = get_preview_post_link($post);
            $preview_target = " target='wp-preview-{$post->ID}'";
        } else {
            if ('publish' === $post->post_status || 'attachment' === $post->post_type) {
                $view_link = get_permalink($post);
            } else {
                // Allow non-published (private, future) to be viewed at a pretty permalink, in case $post->post_name is set
                $view_link = str_replace(array('%pagename%', '%postname%'), $post->post_name, $permalink);
            }
        }
    }
    // Permalinks without a post/page name placeholder don't have anything to edit
    if (false === strpos($permalink, '%postname%') && false === strpos($permalink, '%pagename%')) {
        $return = '<strong>' . __('Permalink:') . "</strong>\n";
        if (false !== $view_link) {
            $display_link = urldecode($view_link);
            $return .= '<a id="sample-permalink" href="' . esc_url($view_link) . '"' . $preview_target . '>' . esc_html($display_link) . "</a>\n";
        } else {
            $return .= '<span id="sample-permalink">' . $permalink . "</span>\n";
        }
        // Encourage a pretty permalink setting
        if ('' == get_option('permalink_structure') && current_user_can('manage_options') && !('page' == get_option('show_on_front') && $id == get_option('page_on_front'))) {
            $return .= '<span id="change-permalinks"><a href="options-permalink.php" class="button button-small" target="_blank">' . __('Change Permalinks') . "</a></span>\n";
        }
    } else {
        if (mb_strlen($post_name) > 34) {
            $post_name_abridged = mb_substr($post_name, 0, 16) . '&hellip;' . mb_substr($post_name, -16);
        } else {
            $post_name_abridged = $post_name;
        }
        $post_name_html = '<span id="editable-post-name">' . esc_html($post_name_abridged) . '</span>';
        $display_link = str_replace(array('%pagename%', '%postname%'), $post_name_html, esc_html(urldecode($permalink)));
        $return = '<strong>' . __('Permalink:') . "</strong>\n";
        $return .= '<span id="sample-permalink"><a href="' . esc_url($view_link) . '"' . $preview_target . '>' . $display_link . "</a></span>\n";
        $return .= '&lrm;';
        // Fix bi-directional text display defect in RTL languages.
        $return .= '<span id="edit-slug-buttons"><button type="button" class="edit-slug button button-small hide-if-no-js" aria-label="' . __('Edit permalink') . '">' . __('Edit') . "</button></span>\n";
        $return .= '<span id="editable-post-name-full">' . esc_html($post_name) . "</span>\n";
    }
    /**
     * Filters the sample permalink HTML markup.
     *
     * @since 2.9.0
     * @since 4.4.0 Added `$post` parameter.
     *
     * @param string  $return    Sample permalink HTML markup.
     * @param int     $post_id   Post ID.
     * @param string  $new_title New sample permalink title.
     * @param string  $new_slug  New sample permalink slug.
     * @param WP_Post $post      Post object.
     */
    $return = apply_filters('get_sample_permalink_html', $return, $post->ID, $new_title, $new_slug, $post);
    return $return;
}
 /**
  * Pass variables to js for use with the post-scraper
  *
  * @return array
  */
 public function localize_post_scraper_script()
 {
     $post = $this->get_metabox_post();
     $permalink = '';
     if (is_object($post)) {
         $permalink = get_sample_permalink($post->ID);
         $permalink = $permalink[0];
     }
     $post_formatter = new WPSEO_Metabox_Formatter(new WPSEO_Post_Metabox_Formatter($post, WPSEO_Options::get_option('wpseo_titles'), $permalink));
     return $post_formatter->get_values();
 }
 /**
  * Returns a base URL for use in the JS, takes permalink structure into account
  *
  * @return string
  */
 private function get_base_url_for_js()
 {
     global $pagenow;
     // The default base is the home_url.
     $base_url = home_url('/', null);
     if ('post-new.php' === $pagenow) {
         return $base_url;
     }
     $permalink = get_sample_permalink(null);
     $permalink = $permalink[0];
     // If %postname% is the last tag, just strip it and use that as a base.
     if (1 === preg_match('#%postname%/?$#', $permalink)) {
         $base_url = preg_replace('#%postname%/?$#', '', $permalink);
     }
     return $base_url;
 }
function screenstepslive_changePagePermalink($data)
{
    $pageID = (int) $_POST['post_ID'];
    // Find settings for this page
    // Can't find way to determine if revision is being inserted other than this.
    // ID doesn't seem to be available anywhere. Silly.
    if ($pageID > 0 && $data != $pageID . '-revision' && $data != $pageID . '-autosave') {
        $pages = get_option('screenstepslive_pages');
        // Update permalink for page
        foreach ($pages as $key => $page_entry) {
            if ($page_entry['id'] == $pageID) {
                if (empty($data)) {
                    // WordPress hasn't assigned permalink yet. Grab one.
                    $data = get_sample_permalink($pageID);
                    $data = $data[1];
                }
                $pages[$key]['permalink'] = $data;
                update_option('screenstepslive_pages', $pages);
                break;
            }
        }
    }
    return $data;
}