Files

118 lines
5.2 KiB
PHP
Raw Permalink Normal View History

2026-11-17 16:15:01 -05:00
<?php
class SQ_Models_Focuspages_Image extends SQ_Models_Abstract_Assistant {
protected $_category = 'image';
protected $_keyword = false;
protected $_image = false;
public function init() {
parent::init();
if (!isset($this->_audit->data)) {
$this->_error = true;
return;
}
if (isset($this->_audit->data->sq_seo_keywords->value) && $this->_audit->data->sq_seo_keywords->value <> '') {
$this->_keyword = $this->_audit->data->sq_seo_keywords->value;
}
if (isset($this->_audit->data->sq_seo_open_graph->value) && $this->_audit->data->sq_seo_open_graph->value <> '') {
$og = json_decode($this->_audit->data->sq_seo_open_graph->value);
if (isset($og->image)) {
$this->_image = $og->image;
}
} elseif (isset($this->_audit->data->sq_seo_twittercard->value) && $this->_audit->data->sq_seo_twittercard->value <> '') {
$tc = json_decode($this->_audit->data->sq_seo_twittercard->value);
if (isset($tc->image)) {
$this->_image = $tc->image;
}
} elseif ($this->_post->post_content <> '') {
@preg_match_all('/<img[^>]*src=[\'"]([^\'"]+)[\'"][^>]*>/i', stripslashes($this->_post->post_content), $out);
if (!empty($out)) {
if (is_array($out[1]) && count((array)$out[1]) > 0) {
foreach ($out[1] as $row) {
$this->_image = $row;
break;
}
}
}
}
}
public function setTasks($tasks) {
parent::setTasks($tasks);
$this->_tasks[$this->_category] = array(
'filename' => array(
'title' => __("Keyword in filename", _SQ_PLUGIN_NAME_),
'value' => ($this->_image ? $this->_image : ''),
'penalty' => 5,
'description' => sprintf(__('Your filename for one of the images in this Focus Page should be: %s keyword.jpg %s Download a relevant image from your page. Change the filename. Then re-upload with the SEO filename and add it your page\'s content again. %s It\'s best to keep this at only one filename which contains the main keyword of the page. %s Why? %s Because Google could consider over-optimization if you used it more than once.', _SQ_PLUGIN_NAME_), '<br /><br />', '<br /><br />', '<br /><br />', '<br /><br />', '<br /><br />'),
),
);
}
/**
* @param $content
* @param $task
* @return string
*/
public function getHeader() {
$edit_link = '';
$header = '<li class="completed">';
if ($this->_keyword) {
$header .= '<div class="font-weight-bold text-black-50 mb-2 text-center">' . __('Keyword', _SQ_PLUGIN_NAME_) . ': ' . $this->_keyword . '</div>';
if (isset($this->_post->ID)) {
if (isset($this->_post->ID)) {
$edit_link = SQ_Classes_Helpers_Tools::getAdminUrl('sq_seosettings', 'bulkseo') . '&sid=' . $this->_post->ID . '&stype=' . $this->_post->post_type;
}
$header .= '<a href="' . $edit_link . '" target="_blank" class="btn bg-primary text-white col-sm-8 offset-2 mt-3">' . __('Edit your snippet', _SQ_PLUGIN_NAME_) . '</a>';
}
} else {
$header .= '<div class="font-weight-bold text-warning m-0 text-center">' . __('No Keyword Found', _SQ_PLUGIN_NAME_) . '</div>';
$header .= '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'research') . '" target="_blank" class="btn bg-primary text-white col-sm-8 offset-2 mt-3">' . __('Do a research', _SQ_PLUGIN_NAME_) . '</a>';
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 .= '<a href="' . $edit_link . '" target="_blank" class="btn bg-primary text-white col-sm-10 offset-1 mt-3">' . __('Optimize for a keyword', _SQ_PLUGIN_NAME_) . '</a>';
}
}
$header .= '</li>';
return $header;
}
/*********************************************/
/**
* Check if the keyword is in the file name | API keyword in filename
* @return bool
*/
public function checkFilename($task) {
$task['completed'] = false;
if (!$this->_keyword) {
$this->_tasks[$this->_category]['filename']['description'] = sprintf(__('Optimize the post first using a Keyword from Squirrly Briefcase', _SQ_PLUGIN_NAME_), '<a href="' . SQ_Classes_Helpers_Tools::getAdminUrl('sq_research', 'briefcase') . '" target="_blank">', '</a>');
$task['completed'] = false;
} elseif ($this->_image) {
$image = str_replace(array('_', '-', '/', '.'), ' ', $this->_image);
if (stripos($image, $this->_keyword) !== false) {
$task['completed'] = true;
}
}
return $task;
}
}