Commit realizado el 12:13:52 08-04-2024

This commit is contained in:
Pagina Web Monito
2024-04-08 12:13:55 -04:00
commit 0c33094de9
7815 changed files with 1365694 additions and 0 deletions

View File

@@ -0,0 +1,148 @@
<?php
/**
* The class handles changes in image tag attributes.
*
* @since 1.0.15
* @package RankMath
* @subpackage RankMath\Image_Seo
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Image_Seo;
use stdClass;
use RankMath\Helper;
use RankMath\Traits\Hooker;
use RankMath\Helpers\HTML;
defined( 'ABSPATH' ) || exit;
/**
* Add Attributes class.
*/
class Add_Attributes {
use Hooker;
/**
* Stores the image alt format if it is set.
*
* @var string|false
*/
public $is_alt;
/**
* Stores the image title format if it is set.
*
* @var string|false
*/
public $is_title;
/**
* The Constructor.
*/
public function __construct() {
$this->action( 'wp', 'add_attributes', 9999 );
$this->action( 'rest_api_init', 'add_attributes' );
}
/**
* Add nofollow, target, title and alt attributes to images.
*/
public function add_attributes() {
// Add image title and alt.
$this->is_alt = Helper::get_settings( 'general.add_img_alt' ) && Helper::get_settings( 'general.img_alt_format' ) ? trim( Helper::get_settings( 'general.img_alt_format' ) ) : false;
$this->is_title = Helper::get_settings( 'general.add_img_title' ) && Helper::get_settings( 'general.img_title_format' ) ? trim( Helper::get_settings( 'general.img_title_format' ) ) : false;
if ( $this->is_alt || $this->is_title ) {
$this->filter( 'the_content', 'add_img_attributes', 11 );
$this->filter( 'post_thumbnail_html', 'add_img_attributes', 11, 2 );
$this->filter( 'woocommerce_single_product_image_thumbnail_html', 'add_img_attributes', 11 );
}
}
/**
* Add 'title' and 'alt' attribute to image.
*
* @param string $content Post content.
* @param null|int $post_id The current post ID.
* @return string
*/
public function add_img_attributes( $content, $post_id = null ) {
if ( empty( $content ) ) {
return $content;
}
$stripped_content = preg_replace( '@<(script|style)[^>]*?>.*?</\\1>@si', '', $content );
preg_match_all( '/<img ([^>]+)\/?>/iU', $stripped_content, $matches, PREG_SET_ORDER );
if ( empty( $matches ) ) {
return $content;
}
$post = $this->get_post( $post_id );
foreach ( $matches as $image ) {
$is_dirty = false;
$attrs = HTML::extract_attributes( $image[0] );
if ( ! isset( $attrs['src'] ) && ! isset( $attrs['data-ct-lazy'] ) ) {
continue;
}
$post->filename = isset( $attrs['data-ct-lazy'] ) ? $attrs['data-ct-lazy'] : $attrs['src'];
// Lazy load support.
if ( ! empty( $attrs['data-src'] ) ) {
$post->filename = $attrs['data-src'];
} elseif ( ! empty( $attrs['data-layzr'] ) ) {
$post->filename = $attrs['data-layzr'];
} elseif ( ! empty( $attrs['nitro-lazy-srcset'] ) ) {
$post->filename = $attrs['nitro-lazy-srcset'];
}
// Pass attributes so they can be used later.
$post->alttext = isset( $attrs['alt'] ) ? $attrs['alt'] : '';
$post->titletext = isset( $attrs['title'] ) ? $attrs['title'] : '';
$this->set_image_attribute( $attrs, 'alt', $this->is_alt, $is_dirty, $post );
$this->set_image_attribute( $attrs, 'title', $this->is_title, $is_dirty, $post );
if ( $is_dirty ) {
$new = '<img' . HTML::attributes_to_string( $attrs ) . '>';
$content = str_replace( $image[0], $new, $content );
}
}
return $content;
}
/**
* Get post object.
*
* @param null|int $post_id The post ID.
* @return object
*/
private function get_post( $post_id = null ) {
$post = \get_post( $post_id );
if ( empty( $post ) ) {
$post = new stdClass();
}
return $post;
}
/**
* Set image attribute after checking condition.
*
* @param array $attrs Array which hold rel attribute.
* @param string $attribute Attribute to set.
* @param boolean $condition Condition to check.
* @param boolean $is_dirty Is dirty variable.
* @param object $post Post Object.
*/
private function set_image_attribute( &$attrs, $attribute, $condition, &$is_dirty, $post ) {
if ( $condition && empty( $attrs[ $attribute ] ) ) {
$is_dirty = true;
$attrs[ $attribute ] = trim( Helper::replace_vars( $condition, $post ) );
}
}
}

View File

@@ -0,0 +1,57 @@
<?php
/**
* The admin-side functionality of the Image SEO module.
*
* @since 1.0
* @package RankMath
* @subpackage RankMath\Image_Seo
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Image_Seo;
use RankMath\KB;
use RankMath\Traits\Hooker;
use RankMath\Helpers\Arr;
defined( 'ABSPATH' ) || exit;
/**
* Admin class.
*/
class Admin {
use Hooker;
/**
* Constructor.
*/
public function __construct() {
$this->action( 'rank_math/settings/general', 'register_tab' );
}
/**
* Add the Images tab in the General Settings.
*
* @param array $tabs Original tabs array.
* @return array New tabs array.
*/
public function register_tab( $tabs ) {
Arr::insert(
$tabs,
[
'images' => [
'icon' => 'rm-icon rm-icon-images',
'title' => esc_html__( 'Images', 'rank-math' ),
/* translators: Link to kb article */
'desc' => sprintf( esc_html__( 'SEO options related to featured images and media appearing in your post content. %s.', 'rank-math' ), '<a href="' . KB::get( 'image-settings', 'Options Panel Images Tab' ) . '" target="_blank">' . esc_html__( 'Learn more', 'rank-math' ) . '</a>' ),
'file' => dirname( __FILE__ ) . '/options.php',
],
],
3
);
return $tabs;
}
}

View File

@@ -0,0 +1,51 @@
<?php
/**
* The Image SEO module.
*
* @since 1.0
* @package RankMath
* @subpackage RankMath\Image_Seo
* @author Rank Math <support@rankmath.com>
*/
namespace RankMath\Image_Seo;
use RankMath\Traits\Hooker;
defined( 'ABSPATH' ) || exit;
/**
* Image_Seo class.
*
* @codeCoverageIgnore
*/
class Image_Seo {
use Hooker;
/**
* Admin page object.
*
* @var object
*/
public $admin;
/**
* Constructor.
*/
public function __construct() {
$this->load_admin();
new Add_Attributes();
}
/**
* Load admin functionality.
*/
private function load_admin() {
if ( is_admin() ) {
$this->admin = new Admin();
}
}
}

View File

@@ -0,0 +1 @@
<?php // Silence is golden.

View File

@@ -0,0 +1,57 @@
<?php
/**
* The Image SEO settings.
*
* @package RankMath
* @subpackage RankMath\Image_Seo
*/
defined( 'ABSPATH' ) || exit;
$cmb->add_field(
[
'id' => 'add_img_alt',
'type' => 'toggle',
'name' => esc_html__( 'Add missing ALT attributes', 'rank-math' ),
'desc' => wp_kses_post( __( 'Add <code>alt</code> attributes for <code>images</code> without <code>alt</code> attributes automatically. The attribute is dynamically applied when the content is displayed, and the stored content is not changed.', 'rank-math' ) ),
'default' => 'off',
]
);
$cmb->add_field(
[
'id' => 'img_alt_format',
'type' => 'text',
'name' => esc_html__( 'Alt attribute format', 'rank-math' ),
'desc' => wp_kses_post( __( 'Format used for the new <code>alt</code> attribute values.', 'rank-math' ) ),
'classes' => 'large-text rank-math-supports-variables',
'default' => ' %filename%',
'dep' => [ [ 'add_img_alt', 'on' ] ],
'sanitization_cb' => [ '\RankMath\CMB2', 'sanitize_textfield' ],
'attributes' => [ 'data-exclude-variables' => 'seo_title,seo_description' ],
]
);
$cmb->add_field(
[
'id' => 'add_img_title',
'type' => 'toggle',
'name' => esc_html__( 'Add missing TITLE attributes', 'rank-math' ),
'desc' => wp_kses_post( __( 'Add <code>TITLE</code> attribute for all <code>images</code> without a <code>TITLE</code> attribute automatically. The attribute is dynamically applied when the content is displayed, and the stored content is not changed.', 'rank-math' ) ),
'default' => 'off',
]
);
$cmb->add_field(
[
'id' => 'img_title_format',
'type' => 'text',
'name' => esc_html__( 'Title attribute format', 'rank-math' ),
'desc' => wp_kses_post( __( 'Format used for the new <code>title</code> attribute values.', 'rank-math' ) ),
'classes' => 'large-text rank-math-supports-variables dropdown-up',
'default' => '%title% %count(title)%',
'dep' => [ [ 'add_img_title', 'on' ] ],
'sanitization_cb' => [ '\RankMath\CMB2', 'sanitize_textfield' ],
'attributes' => [ 'data-exclude-variables' => 'seo_title,seo_description' ],
]
);