From c3c37b1f37b967ed71afc258024ffc04f41e2382 Mon Sep 17 00:00:00 2001 From: danpros Date: Wed, 22 Nov 2023 17:15:14 +0700 Subject: [PATCH] PHP 8.x compatibility Remove deprecated warning for PHP 8.x --- composer.json | 10 +--- lang/{ir_FA.ini => fa_IR.ini} | 0 system/admin/admin.php | 67 +--------------------- system/admin/views/config.html.php | 28 ++++----- system/htmly.php | 52 ++++++++--------- system/includes/functions.php | 28 +++++---- .../vendor/kanti/hub-updater/src/CacheOneFile.php | 2 +- system/vendor/kanti/hub-updater/src/HubUpdater.php | 2 +- .../michelf/php-markdown/Michelf/MarkdownExtra.php | 2 +- 9 files changed, 60 insertions(+), 131 deletions(-) rename lang/{ir_FA.ini => fa_IR.ini} (100%) diff --git a/composer.json b/composer.json index 113feaa..87e47f8 100644 --- a/composer.json +++ b/composer.json @@ -1,11 +1,4 @@ { - "repositories": [ - { - "type": "vcs", - "url": "https://github.com/Youpie/simple-html-dom" - } - ], - "config": { "vendor-dir": "system/vendor/", "optimize-autoloader": true, @@ -18,8 +11,7 @@ "michelf/php-markdown": "1.*", "suin/php-rss-writer": "1.*", "kanti/hub-updater": "0.*", - "jbroadway/urlify": "^1.0", - "simple-html-dom/simple-html-dom": "*" + "jbroadway/urlify": "^1.0" }, "autoload": { "files": [ diff --git a/lang/ir_FA.ini b/lang/fa_IR.ini similarity index 100% rename from lang/ir_FA.ini rename to lang/fa_IR.ini diff --git a/system/admin/admin.php b/system/admin/admin.php index d7c3ea3..951332b 100644 --- a/system/admin/admin.php +++ b/system/admin/admin.php @@ -85,7 +85,7 @@ function remove_accent($str) } // Add content -function add_content($title, $tag, $url, $content, $user, $description = null, $media = null, $draft, $category, $type) +function add_content($title, $tag, $url, $content, $user, $draft, $category, $type, $description = null, $media = null) { $tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ','))); @@ -218,7 +218,7 @@ function add_content($title, $tag, $url, $content, $user, $description = null, $ } // Edit content -function edit_content($title, $tag, $url, $content, $oldfile, $destination = null, $description = null, $date = null, $media = null, $revertPost, $publishDraft, $category, $type) +function edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, $type, $destination = null, $description = null, $date = null, $media = null) { $tag = explode(',', preg_replace("/\s*,\s*/", ",", rtrim($tag, ','))); @@ -775,7 +775,6 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) } else { $post_content = '' . "\n" . '' . "\n\n" . $content; } - if (!empty($post_title) && !empty($post_tag) && !empty($post_url) && !empty($post_content)) { $post_content = stripslashes($post_content); @@ -789,31 +788,8 @@ function migrate($title, $time, $tags, $content, $url, $user, $source) file_put_contents($dir . $filename, print_r($post_content, true)); } save_tag_i18n($post_tag, $post_tagmd); - // import images - if(count($images) > 0) { - foreach ($images as $image_url) { - $imagefile = basename($image_url); - if(!@copy($image_url,'content/images/'.$imagefile)) - { - $errors= error_get_last(); - echo "COPY ERROR: ".$errors['type']; - echo "
\n".$errors['message']; - } else { - echo "$imagefile copied from remote!
\n"; - // $images_imported++; - } - } - } - $redirect = site_url() . 'admin/clear-cache'; header("Location: $redirect"); - } else { - echo "

Found empty Fields:

\r\n"; - echo "post title: $post_title
\n"; - echo "post tag: $post_tag
\n"; - echo "post url: $post_url
\n"; - echo "post content: ".substr($post_content, 0, 50)."
\n"; - echo "

I WILL NOT IMPORT THIS !!!

\r\n
\r\n"; } } @@ -846,44 +822,7 @@ function get_feed($feed_url, $credit) } else { $source = null; } - - $images = array(); - // identify the host-name of the rss feed we are parsing - $source_host = parse_url($feed_url); - if(empty($source_host['host'])) { - $source_host['host'] = $_SERVER['SERVER_NAME']; // seems like we are parsing a local feed - } - - $cnt_images = 0; - $html = new \SimpleHtmlDom\simple_html_dom($content); - foreach ($html->find('img') as $img) { - $src = $img->src; - // identify host of img url - $img_host = parse_url($src, PHP_URL_HOST); - $img_path = parse_url($src, PHP_URL_PATH); - if(empty($img_host)) { - $img_host = $source_host['host']; - } - // we only import images if they match the host of the rss feed, - // otherwise legal consequences (copyright breach) may occur - if($img_host == $source_host['host']) { - $cnt_images ++; - $images[] = $source_host['scheme'].'://'.$img_host.$img_path; - // alter the path of the image, point to local src after import - $img->src = '/content/images/'.basename($src); - } - } - - // debug - /** - if($cnt_images > 0) { - echo "

IMAGES and bent content

"; - echo var_export($images, true); - echo "
" . htmlspecialchars($html) . "
"; - } - */ - - migrate($title, $time, $tags, $html, $url, $user, $images, $source); + migrate($title, $time, $tags, $content, $url, $user, $source); } } else { return $str = '
  • Unsupported feed.
  • '; diff --git a/system/admin/views/config.html.php b/system/admin/views/config.html.php index cfbce47..67da930 100644 --- a/system/admin/views/config.html.php +++ b/system/admin/views/config.html.php @@ -66,45 +66,45 @@
    - checked> + checked>
    - checked> + checked>
    - checked> + checked>
    - checked> + checked>
    - checked> + checked>
    - checked> + checked>
    - checked> + checked>
    diff --git a/system/htmly.php b/system/htmly.php index 93c75a5..bcb4d8f 100644 --- a/system/htmly.php +++ b/system/htmly.php @@ -474,45 +474,45 @@ post('/add/content', function () { if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, null, $draft, $category, 'post'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, null, $draft, $category, 'post'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'post', $description, null); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($image)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, $image, $draft, $category, 'image'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, $image, $draft, $category, 'image'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'image', $description, $image); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, $video, $draft, $category, 'video'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, $video, $draft, $category, 'video'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'video', $description, $video); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, $audio, $draft, $category, 'audio'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, $audio, $draft, $category, 'audio'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'audio', $description, $audio); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, $quote, $draft, $category, 'quote'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, $quote, $draft, $category, 'quote'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'quote', $description, $quote); } } elseif ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (!empty($url)) { - add_content($title, $tag, $url, $content, $user, $description, $link, $draft, $category, 'link'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link); } else { $url = $title; - add_content($title, $tag, $url, $content, $user, $description, $link, $draft, $category, 'link'); + add_content($title, $tag, $url, $content, $user, $draft, $category, 'link', $description, $link); } } else { $message['error'] = ''; @@ -2070,9 +2070,9 @@ get('/archive/:req', function ($req) { $date = strtotime($req); if (isset($time[0]) && isset($time[1]) && isset($time[2])) { - $timestamp = strftime('%d %B %Y', $date); + $timestamp = format_date($date, 'dd MMMM yyyy'); } elseif (isset($time[0]) && isset($time[1])) { - $timestamp = strftime('%B %Y', $date); + $timestamp = format_date($date, 'MMMM yyyy'); } else { $timestamp = $req; } @@ -2442,37 +2442,37 @@ post('/post/:name/edit', function () { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft, $category, 'image'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft, $category, 'video'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft, $category, 'link'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft, $category, 'quote'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft, $category, 'audio'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, null, $revertPost, $publishDraft, $category, 'post'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null); } else { $message['error'] = ''; @@ -3435,37 +3435,37 @@ post('/:year/:month/:name/edit', function () { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $image, $revertPost, $publishDraft, $category, 'image'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'image', $destination, $description, $dateTime, $image); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($video)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $video, $revertPost, $publishDraft, $category, 'video'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'video', $destination, $description, $dateTime, $video); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($link)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $link, $revertPost, $publishDraft, $category, 'link'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'link', $destination, $description, $dateTime, $link); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($quote)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $quote, $revertPost, $publishDraft, $category, 'quote'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'quote', $destination, $description, $dateTime, $quote); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($audio)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, $audio, $revertPost, $publishDraft, $category, 'audio'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'audio', $destination, $description, $dateTime, $audio); } else if ($proper && !empty($title) && !empty($tag) && !empty($content) && !empty($is_post)) { if (empty($url)) { $url = $title; } - edit_content($title, $tag, $url, $content, $oldfile, $destination, $description, $dateTime, null, $revertPost, $publishDraft, $category, 'post'); + edit_content($title, $tag, $url, $content, $oldfile, $revertPost, $publishDraft, $category, 'post', $destination, $description, $dateTime, null); } else { $message['error'] = ''; diff --git a/system/includes/functions.php b/system/includes/functions.php index af08faf..e9a5af9 100644 --- a/system/includes/functions.php +++ b/system/includes/functions.php @@ -570,7 +570,7 @@ function get_category_info($category) } } - if (strtolower($category) == 'uncategorized') { + if (strtolower($category ?? '') == 'uncategorized') { return default_category(); } @@ -1432,7 +1432,7 @@ EOF; echo '
      '; foreach ($by_month as $month => $count) { - $name = strftime('%B', mktime(0, 0, 0, $month, 1, 2010)); + $name = format_date(mktime(0, 0, 0, $month, 1, 2010), 'MMMM'); echo '
    • ' . $name . ''; echo ' (' . $count . ')
    • '; } @@ -1596,7 +1596,7 @@ function has_pagination($total, $perpage, $page = 1) } $totalPage = ceil($total / $perpage); $number = i18n('Page') . ' ' . $page . ' ' . i18n('of') . ' ' . $totalPage; - $pager = get_pagination($page, $total, $perpage, 2); + $pager = get_pagination($total, $page, $perpage, 2); return array( 'prev' => $page > 1, 'next' => $total > $page * $perpage, @@ -1608,7 +1608,7 @@ function has_pagination($total, $perpage, $page = 1) } //function to return the pagination string -function get_pagination($page = 1, $totalitems, $perpage = 10, $adjacents = 1, $pagestring = '?page=') +function get_pagination($totalitems, $page = 1, $perpage = 10, $adjacents = 1, $pagestring = '?page=') { //defaults if(!$adjacents) $adjacents = 1; @@ -2152,7 +2152,7 @@ function menu($class = null) } } - return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', utf8_decode($doc->saveHTML($doc->documentElement))); + return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($doc->saveHTML($doc->documentElement), 'UTF-8')); } } else { @@ -3225,11 +3225,11 @@ function replace_href($string, $tag, $class, $url) if ($_tag->getAttribute('class') == $class) { // If match class get the href value $old = $_tag->getAttribute('href'); - $new = $_tag->setAttribute('href', $url . utf8_decode($old)); + $new = $_tag->setAttribute('href', $url . mb_convert_encoding($old, 'UTF-8')); } } - return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', utf8_decode($doc->saveHTML($doc->documentElement))); + return preg_replace('~<(?:!DOCTYPE|/?(?:html|head|body))[^>]*>\s*~i', '', mb_convert_encoding($doc->saveHTML($doc->documentElement), 'UTF-8')); } @@ -3251,16 +3251,14 @@ function get_language() } -function format_date($date) +function format_date($date, $date_format = null) { - - $date_format = config('date.format'); - - if (!isset($date_format) || empty($date_format)) { - return strftime('%e %B %Y', $date); - } else { - return strftime($date_format, $date); + if (empty($date_format)) { + $date_format = config('date.format'); } + $formatter = new IntlDateFormatter(config('language'), IntlDateFormatter::LONG, IntlDateFormatter::NONE, config('timezone'), IntlDateFormatter::GREGORIAN, $date_format); + + return $formatter->format($date); } diff --git a/system/vendor/kanti/hub-updater/src/CacheOneFile.php b/system/vendor/kanti/hub-updater/src/CacheOneFile.php index f0af728..e55e499 100644 --- a/system/vendor/kanti/hub-updater/src/CacheOneFile.php +++ b/system/vendor/kanti/hub-updater/src/CacheOneFile.php @@ -1,7 +1,7 @@ deleted from doc # - $parts = preg_split('/(?