Plugin Directory

Changeset 3191295


Ignore:
Timestamp:
11/18/2024 01:47:24 PM (17 months ago)
Author:
john1302
Message:

Add wpo cache plugin support

Location:
blog-image-sitemap/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • blog-image-sitemap/trunk/blog-image-sitemap.php

    r2511382 r3191295  
    44Description: Create sitemap for blog pictures with cron schedule
    55Author: Evgeniy Kozenok
    6 Version: 0.2.7
     6Version: 0.3.0
    77*/
    88
  • blog-image-sitemap/trunk/classes/CronScheduleAction.php

    r2511382 r3191295  
    77class CronScheduleAction
    88{
    9     private $siteUrl;
    10     private $defaultFileName = 'sitemap-images.xml';
    11     private $optionName = '5ba4c23331acf0c1249786f43138a12b'; // md5('prepareImagesSitemap')
     9    private string $siteUrl;
     10    private string $defaultFileName = 'sitemap-images.xml';
     11    private string $optionName = '5ba4c23331acf0c1249786f43138a12b'; // md5('prepareImagesSitemap')
    1212
    1313    public function __construct()
     
    2727    }
    2828
    29     public function hookHandle()
     29    public function hookHandle(): void
    3030    {
    3131        echo 'prepareImagesSitemap hook start';
    32         if (!function_exists('get_supercache_dir')) {
     32        if (!$this->getCacheDir()) {
    3333            wp_die();
    3434        }
     
    4646
    4747        foreach ($pagesListMapping as $lang => $pagesList) {
    48             $langCacheFileName = str_replace('.xml', "-{$lang}.xml", $fileName);
    49 
     48            $langCacheFileName = str_replace('.xml', "-$lang.xml", $fileName);
    5049            $langImagesSitemap = $this->handleSitemapImages($pagesList);
    5150
     
    6867        $baseCacheFileAbs = $this->getAbsFilePathAndOldDelete($fileName);
    6968        if (!$amountSitemapPages) {
    70             echo 'Page not found in ' . get_supercache_dir() . ' dir';
    71             return false;
     69            echo 'Page not found in ' . $this->getCacheDir() . ' dir';
     70            return;
    7271        }
    7372        $baseCacheFileContent = file_get_contents(plugin_dir_path(IMAGE_SITEMAP_INDEX_FILE) . 'inc/sitemap-images-example.xml');
     
    7574
    7675        file_put_contents($baseCacheFileAbs, $baseCacheFileContent);
    77         return true;
    7876    }
    7977
     
    8381     * @return array
    8482     */
    85     private function getPagesListMapping()
     83    private function getPagesListMapping(): array
    8684    {
    8785        global $sitepress;
     
    105103
    106104            foreach ($posts as $post) {
    107                 $noIndex = WPSEO_Meta::get_value('meta-robots-noindex', $post->ID);
    108                 if ($noIndex == true) {
     105                if (
     106                    class_exists('WPSEO_Meta')
     107                    && (int)WPSEO_Meta::get_value('meta-robots-noindex', $post->ID) == 1
     108                ) {
    109109                    continue;
    110110                }
    111111
    112                 array_push($langMap, $this->preparePageAddress(get_page_link($post->ID), $lang));
     112                $langMap[] = $this->preparePageAddress(get_page_link($post->ID), $lang);
    113113            }
    114114
     
    119119    }
    120120
    121     private function preparePageAddress($pagePath, $lang)
    122     {
    123         if (strpos($pagePath, '.html') !== false) {
     121    private function preparePageAddress($pagePath, $lang): string
     122    {
     123        if (str_contains($pagePath, '.html')) {
    124124            return $pagePath;
    125125        }
     
    129129        }
    130130
    131         if (substr($pagePath, -1, 1) == '/') {
     131        if (str_ends_with($pagePath, '/')) {
    132132            $pagePath = substr_replace($pagePath, '', -1);
    133133        }
     
    147147    }
    148148
    149     private function getAbsFilePath(string $fileName)
     149    private function getAbsFilePath(string $fileName): string
    150150    {
    151151        return get_home_path() . $fileName;
    152152    }
    153153
    154     private function handleSitemapImages(array $pagesList)
     154    private function handleSitemapImages(array $pagesList): ?string
    155155    {
    156156        if (!function_exists('str_get_html')) {
     
    210210    }
    211211
    212     private function imageXmlPattern()
     212    private function imageXmlPattern(): string
    213213    {
    214214        return
     
    220220    }
    221221
    222     private function getUrlSetXmlPattern()
     222    private function getUrlSetXmlPattern(): string
    223223    {
    224224        return
     
    229229    }
    230230
    231     private function getUrlXmlPattern()
     231    private function getUrlXmlPattern(): string
    232232    {
    233233        return
     
    238238    }
    239239
    240     private function getPageContentByUrl($pageUrlAddress, $https)
    241     {
    242         $superCacheDir = get_supercache_dir();
    243         $pageCachePath = str_replace($this->siteUrl, $superCacheDir, $pageUrlAddress);
     240    private function getPageContentByUrl($pageUrlAddress, $https): string
     241    {
     242        $cacheDir = $this->getCacheDir();
     243        $pageCachePath = str_replace($this->siteUrl, $cacheDir, $pageUrlAddress);
    244244        $pageCachePath .= $https ? '/index-https.html' : '/index.html';
    245245
     
    252252    }
    253253
    254     private function generateTableRowData(string $fileName)
     254    private function generateTableRowData(string $fileName): string
    255255    {
    256256        return sprintf(
     
    262262        );
    263263    }
     264
     265    private function getCacheDir(): string
     266    {
     267        if (function_exists('get_supercache_dir')) {
     268            return get_supercache_dir();
     269        }
     270
     271        if (defined('WPO_CACHE_FILES_DIR') && WPO_CACHE_FILES_DIR) {
     272            return sprintf(
     273                '%s%s/',
     274                str_replace('//', '/', WPO_CACHE_FILES_DIR . '/'),
     275                parse_url($this->siteUrl, PHP_URL_HOST)
     276            );
     277        }
     278
     279        return '';
     280    }
    264281}
  • blog-image-sitemap/trunk/inc/sitemap-images-example.xml

    r2505565 r3191295  
    11<?xml version="1.0" encoding="UTF-8"?>
    2 <sitemapindex xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    3               xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
    4               xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">%sitemap_rows%
     2<sitemapindex xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
     3              xsi:schemaLocation="https://www.sitemaps.org/schemas/sitemap/0.9 https://www.sitemaps.org/schemas/sitemap/0.9/siteindex.xsd"
     4              xmlns="https://www.sitemaps.org/schemas/sitemap/0.9">%sitemap_rows%
    55</sitemapindex>
  • blog-image-sitemap/trunk/readme.txt

    r2511382 r3191295  
    33Tags: image, sitemap, cron event, back
    44Requires at least: 5.0
    5 Tested up to: 5.7
    6 Stable tag: 0.2.7
     5Tested up to: 6.6
     6Stable tag: 0.3.0
    77License: GPL2
    88License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    2424== Changelog ==
    2525
     26= 0.3.0 =
     27* 2024-11-18: Php 8+. Add wpo cache plugin support
    2628
    2729= 0.2.7 =
Note: See TracChangeset for help on using the changeset viewer.