85 lines
3.5 KiB
PHP
85 lines
3.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
class SQ_Models_Focuspages_Innerlinks extends SQ_Models_Abstract_Assistant {
|
||
|
|
|
||
|
|
protected $_category = 'innerlinks';
|
||
|
|
public $_permalink = false;
|
||
|
|
public $_inner_links = false;
|
||
|
|
public $_total_posts = false;
|
||
|
|
|
||
|
|
const INNERS_MINVAL = 5;
|
||
|
|
const INNERS_RECOMMENDED = 20;
|
||
|
|
|
||
|
|
/** TODO if there are less pages than the ones required in inner links */
|
||
|
|
public function init() {
|
||
|
|
parent::init();
|
||
|
|
|
||
|
|
if (!isset($this->_audit->data)) {
|
||
|
|
$this->_error = true;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
$this->_permalink = (isset($this->_post->url) && $this->_post->url <> '' ? $this->_post->url : $this->_audit->permalink);
|
||
|
|
|
||
|
|
if ($this->_permalink <> '') {
|
||
|
|
global $wpdb;
|
||
|
|
|
||
|
|
if ($row = $wpdb->get_row("SELECT COUNT(`ID`) as count FROM " . $wpdb->posts . " WHERE `post_status` = 'publish'")) {
|
||
|
|
$this->_total_posts = $row->count;
|
||
|
|
}
|
||
|
|
if ($row = $wpdb->get_row("SELECT COUNT(`ID`) as count FROM " . $wpdb->posts . " WHERE `post_content` LIKE '%" . $this->_permalink . "%' AND `post_status` = 'publish'")) {
|
||
|
|
$this->_inner_links = $row->count;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (isset($this->_audit->data->sq_seo_innerlinks->value)) {
|
||
|
|
$this->_inner_links = max((int)$this->_inner_links, (int)$this->_audit->data->sq_seo_innerlinks->value);
|
||
|
|
}
|
||
|
|
|
||
|
|
SQ_Debug::dump($this->_inner_links, $this->_total_posts);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function setTasks($tasks) {
|
||
|
|
parent::setTasks($tasks);
|
||
|
|
|
||
|
|
$this->_tasks[$this->_category] = array(
|
||
|
|
'innerlinks' => array(
|
||
|
|
'title' => sprintf(__("Get %s inner links", _SQ_PLUGIN_NAME_), self::INNERS_MINVAL),
|
||
|
|
'value' => (int)$this->_inner_links. ' ' . __('inner links', _SQ_PLUGIN_NAME_),
|
||
|
|
'penalty' => 5,
|
||
|
|
'description' => sprintf(__("Get %s Inner Links %s Recommended is: %s %s Inner Links are links that you send from one URL of your site to another URL of your site. %s Since your Focus Pages are the most important pages in your site, you should make sure that you link to them from many pages of your website. %s Follow the best practices for this. (highlighted in the Best Practices section)", _SQ_PLUGIN_NAME_), self::INNERS_MINVAL, '<br /><br />', self::INNERS_RECOMMENDED, '<br /><br />', '<br /><br />', '<br /><br />'),
|
||
|
|
),
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
/*********************************************/
|
||
|
|
public function getHeader() {
|
||
|
|
$header = '';
|
||
|
|
if (isset($this->_post->ID)) {
|
||
|
|
$edit_link = SQ_Classes_Helpers_Tools::getAdminUrl('post.php?post=' . (int)$this->_post->ID . '&action=edit');
|
||
|
|
if ($this->_post->post_type <> 'profile') {
|
||
|
|
$edit_link = get_edit_post_link($this->_post->ID, false);
|
||
|
|
}
|
||
|
|
|
||
|
|
$header = '';
|
||
|
|
$header .= '<li class="completed">';
|
||
|
|
$header .= '<a href="' . $edit_link . '" target="_blank" class="btn bg-primary text-white col-sm-10 offset-1 mt-3">' . __('Build with Blogging Assistant', _SQ_PLUGIN_NAME_) . '</a>';
|
||
|
|
$header .= '</li>';
|
||
|
|
}
|
||
|
|
return $header;
|
||
|
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
* Get the inner links from the other posts
|
||
|
|
* @return bool|WP_Error
|
||
|
|
*/
|
||
|
|
public function checkInnerlinks($task) {
|
||
|
|
$task['completed'] = ((int)$this->_inner_links && (int)$this->_inner_links >= self::INNERS_MINVAL);
|
||
|
|
return $task;
|
||
|
|
|
||
|
|
$task['error'] = true;
|
||
|
|
return $task;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|