Changeset 3191295
- Timestamp:
- 11/18/2024 01:47:24 PM (17 months ago)
- Location:
- blog-image-sitemap/trunk
- Files:
-
- 4 edited
-
blog-image-sitemap.php (modified) (1 diff)
-
classes/CronScheduleAction.php (modified) (16 diffs)
-
inc/sitemap-images-example.xml (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
blog-image-sitemap/trunk/blog-image-sitemap.php
r2511382 r3191295 4 4 Description: Create sitemap for blog pictures with cron schedule 5 5 Author: Evgeniy Kozenok 6 Version: 0. 2.76 Version: 0.3.0 7 7 */ 8 8 -
blog-image-sitemap/trunk/classes/CronScheduleAction.php
r2511382 r3191295 7 7 class CronScheduleAction 8 8 { 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') 12 12 13 13 public function __construct() … … 27 27 } 28 28 29 public function hookHandle() 29 public function hookHandle(): void 30 30 { 31 31 echo 'prepareImagesSitemap hook start'; 32 if (! function_exists('get_supercache_dir')) {32 if (!$this->getCacheDir()) { 33 33 wp_die(); 34 34 } … … 46 46 47 47 foreach ($pagesListMapping as $lang => $pagesList) { 48 $langCacheFileName = str_replace('.xml', "-{$lang}.xml", $fileName); 49 48 $langCacheFileName = str_replace('.xml', "-$lang.xml", $fileName); 50 49 $langImagesSitemap = $this->handleSitemapImages($pagesList); 51 50 … … 68 67 $baseCacheFileAbs = $this->getAbsFilePathAndOldDelete($fileName); 69 68 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; 72 71 } 73 72 $baseCacheFileContent = file_get_contents(plugin_dir_path(IMAGE_SITEMAP_INDEX_FILE) . 'inc/sitemap-images-example.xml'); … … 75 74 76 75 file_put_contents($baseCacheFileAbs, $baseCacheFileContent); 77 return true;78 76 } 79 77 … … 83 81 * @return array 84 82 */ 85 private function getPagesListMapping() 83 private function getPagesListMapping(): array 86 84 { 87 85 global $sitepress; … … 105 103 106 104 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 ) { 109 109 continue; 110 110 } 111 111 112 array_push($langMap, $this->preparePageAddress(get_page_link($post->ID), $lang));112 $langMap[] = $this->preparePageAddress(get_page_link($post->ID), $lang); 113 113 } 114 114 … … 119 119 } 120 120 121 private function preparePageAddress($pagePath, $lang) 122 { 123 if (str pos($pagePath, '.html') !== false) {121 private function preparePageAddress($pagePath, $lang): string 122 { 123 if (str_contains($pagePath, '.html')) { 124 124 return $pagePath; 125 125 } … … 129 129 } 130 130 131 if (s ubstr($pagePath, -1, 1) == '/') {131 if (str_ends_with($pagePath, '/')) { 132 132 $pagePath = substr_replace($pagePath, '', -1); 133 133 } … … 147 147 } 148 148 149 private function getAbsFilePath(string $fileName) 149 private function getAbsFilePath(string $fileName): string 150 150 { 151 151 return get_home_path() . $fileName; 152 152 } 153 153 154 private function handleSitemapImages(array $pagesList) 154 private function handleSitemapImages(array $pagesList): ?string 155 155 { 156 156 if (!function_exists('str_get_html')) { … … 210 210 } 211 211 212 private function imageXmlPattern() 212 private function imageXmlPattern(): string 213 213 { 214 214 return … … 220 220 } 221 221 222 private function getUrlSetXmlPattern() 222 private function getUrlSetXmlPattern(): string 223 223 { 224 224 return … … 229 229 } 230 230 231 private function getUrlXmlPattern() 231 private function getUrlXmlPattern(): string 232 232 { 233 233 return … … 238 238 } 239 239 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); 244 244 $pageCachePath .= $https ? '/index-https.html' : '/index.html'; 245 245 … … 252 252 } 253 253 254 private function generateTableRowData(string $fileName) 254 private function generateTableRowData(string $fileName): string 255 255 { 256 256 return sprintf( … … 262 262 ); 263 263 } 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 } 264 281 } -
blog-image-sitemap/trunk/inc/sitemap-images-example.xml
r2505565 r3191295 1 1 <?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% 5 5 </sitemapindex> -
blog-image-sitemap/trunk/readme.txt
r2511382 r3191295 3 3 Tags: image, sitemap, cron event, back 4 4 Requires at least: 5.0 5 Tested up to: 5.76 Stable tag: 0. 2.75 Tested up to: 6.6 6 Stable tag: 0.3.0 7 7 License: GPL2 8 8 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 24 24 == Changelog == 25 25 26 = 0.3.0 = 27 * 2024-11-18: Php 8+. Add wpo cache plugin support 26 28 27 29 = 0.2.7 =
Note: See TracChangeset
for help on using the changeset viewer.