From 7229aa6c50016f90cdc0002c32c21a5f633e56c4 Mon Sep 17 00:00:00 2001 From: Cameron Date: Tue, 8 Dec 2020 18:15:08 -0800 Subject: [PATCH] Preparations for WebP conversions. e107::title() added to eventually replace defining e_PAGETITLE. --- e107_admin/image.php | 2 + e107_core/templates/header_default.php | 47 +++++++++++------- e107_handlers/application.php | 9 +++- e107_handlers/e107_class.php | 17 +++++-- e107_handlers/e_parse_class.php | 15 +++++- e107_languages/English/admin/lan_image.php | 4 ++ e107_plugins/news/news.php | 55 +++++++++------------- 7 files changed, 95 insertions(+), 54 deletions(-) diff --git a/e107_admin/image.php b/e107_admin/image.php index b6a211571..fdae4fca1 100644 --- a/e107_admin/image.php +++ b/e107_admin/image.php @@ -880,6 +880,8 @@ class media_admin_ui extends e_admin_ui // 'convert_to_jpeg' => array('title'=> IMALAN_182, 'type'=>'number', 'data'=>'int', 'writeParms'=> array('tdClassRight'=>'form-inline', 'post'=> CORE_LAN_KB), 'help'=>IMALAN_183), 'convert_to_jpeg' => array('title'=> IMALAN_182, 'type'=>'boolean', 'data'=>'int', 'writeParms'=>'', 'help'=>IMALAN_183), + 'convert_to_webp' => array('title'=> IMALAN_187, 'type'=>'boolean', 'data'=>'int', 'writeParms'=>'', 'help'=>IMALAN_189), + 'thumb_to_webp' => array('title'=> IMALAN_188, 'type'=>'boolean', 'data'=>'int', 'writeParms'=>'', 'help'=>IMALAN_189), 'im_width' => array('title'=> IMALAN_75, 'type'=>'number', 'data'=>'int', 'writeParms'=>'', 'help'=>IMALAN_76), 'im_height' => array('title'=> IMALAN_77, 'type'=>'number', 'data'=>'int', 'writeParms'=>'', 'help'=>IMALAN_76), diff --git a/e107_core/templates/header_default.php b/e107_core/templates/header_default.php index cad48f08c..5a92d8628 100644 --- a/e107_core/templates/header_default.php +++ b/e107_core/templates/header_default.php @@ -139,6 +139,14 @@ else echo (defined("CORE_LC")) ? "\n" : ""; } +// Load early +if(!defined('e_PAGETITLE') && ($_PAGE_TITLE = e107::getSingleton('eResponse')->getMetaTitle())) // use e107::title() to set. +{ + define('e_PAGETITLE', $_PAGE_TITLE); + unset($_PAGE_TITLE); +} + + // // C: Send start of HTML // @@ -147,13 +155,13 @@ if(!empty($pref['meta_copyright'][e_LANGUAGE])) e107::meta('dcterms.rights',$pre if(!empty($pref['meta_author'][e_LANGUAGE])) e107::meta('author',$pref['meta_author'][e_LANGUAGE]); if(!empty($pref['sitebutton'])) { - $siteButton = (strpos($pref['sitebutton'],'{e_MEDIA') !== false) ? $tp->thumbUrl($pref['sitebutton'],'w=800',false, true) : $tp->replaceConstants($pref['sitebutton'],'full'); + $siteButton = (strpos($pref['sitebutton'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitebutton'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitebutton'],'full'); e107::meta('og:image',$siteButton); unset($siteButton); } elseif(!empty($pref['sitelogo'])) // fallback to sitelogo { - $siteLogo = (strpos($pref['sitelogo'],'{e_MEDIA') !== false) ? $tp->thumbUrl($pref['sitelogo'],'w=800',false, true) : $tp->replaceConstants($pref['sitelogo'],'full'); + $siteLogo = (strpos($pref['sitelogo'],'{e_MEDIA') !== false) ? e107::getParser()->thumbUrl($pref['sitelogo'],'w=800',false, true) : e107::getParser()->replaceConstants($pref['sitelogo'],'full'); e107::meta('og:image',$siteLogo); unset($siteLogo); } @@ -185,7 +193,10 @@ if (deftrue('e_FRONTPAGE')) } else { - echo "".(defined('e_PAGETITLE') ? e_PAGETITLE.' - ' : (defined('PAGE_NAME') ? PAGE_NAME.' - ' : "")).SITENAME."\n\n"; + + echo "".(deftrue('e_PAGETITLE') ? e_PAGETITLE.' - ' : (defined('PAGE_NAME') ? PAGE_NAME.' - ' : "")).SITENAME."\n\n"; + + unset($_PAGE_TITLE); } @@ -194,7 +205,7 @@ else // $e_js = e107::getJs(); -$e_pref = e107::getConfig('core'); +$e_pref = e107::getConfig(); // Other Meta tags. @@ -216,7 +227,7 @@ if(THEME_LEGACY === true || !deftrue('BOOTSTRAP')) // re-initalize in case globals are destroyed from $e_headers includes $e_js = e107::getJs(); -$e_pref = e107::getConfig('core'); +$e_pref = e107::getConfig(); // --- Load plugin Meta files - now possible to add to all zones! -------- @@ -246,7 +257,7 @@ if (is_array($pref['e_meta_list'])) if(isset($pref['sitebutton'])) { - $appleIcon = $tp->thumbUrl($pref['sitebutton'],'w=144&h=144&crop=1',null, true); + $appleIcon = e107::getParser()->thumbUrl($pref['sitebutton'],'w=144&h=144&crop=1',null, true); echo "\n"; unset($appleIcon); } @@ -318,7 +329,7 @@ else { //echo ' //'; - $e_js->themeCSS(TEXTDIRECTION.'.css', 'all'); + $e_js->themeCSS(TEXTDIRECTION.'.css'); } } @@ -343,7 +354,7 @@ $CSSORDER = deftrue('CSSORDER') ? explode(",",CSSORDER) : array('library', 'othe foreach($CSSORDER as $val) { $cssId = $val."_css"; - $e_js->renderJs($cssId, false, 'css', false); + $e_js->renderJs($cssId, false, 'css'); } unset($CSSORDER); @@ -483,6 +494,10 @@ if(function_exists('theme_head')) $diz_merge = (defined("META_MERGE") && META_MERGE != FALSE && $pref['meta_description'][e_LANGUAGE]) ? $pref['meta_description'][e_LANGUAGE]." " : ""; $key_merge = (defined("META_MERGE") && META_MERGE != FALSE && $pref['meta_keywords'][e_LANGUAGE]) ? $pref['meta_keywords'][e_LANGUAGE]."," : ""; +/** + * @param $type + * @return string + */ function render_meta($type) { $tp = e107::getParser(); @@ -633,8 +648,8 @@ echo "\n"; // echo "MODE 0.6"; if($def == 'legacyCustom') { - $HEADER = ($CUSTOMHEADER) ? $CUSTOMHEADER : $HEADER; - $FOOTER = ($CUSTOMFOOTER) ? $CUSTOMFOOTER : $FOOTER; + $HEADER = isset($CUSTOMHEADER) ? $CUSTOMHEADER : $HEADER; + $FOOTER = isset($CUSTOMFOOTER) ? $CUSTOMFOOTER : $FOOTER; } } elseif($def && $def != "legacyCustom" && (isset($CUSTOMHEADER[$def]) || isset($CUSTOMFOOTER[$def]))) // 0.7/1.x themes @@ -659,12 +674,12 @@ echo "\n"; if(deftrue('e_IFRAME')) { - $HEADER = deftrue('e_IFRAME_HEADER',""); - $FOOTER = deftrue('e_IFRAME_FOOTER',""); + $HEADER = deftrue('e_IFRAME_HEADER'); + $FOOTER = deftrue('e_IFRAME_FOOTER'); $body_onload .= " class='e-iframe'"; } - $HEADER = str_replace("{e_PAGETITLE}",deftrue('e_PAGETITLE',''),$HEADER); + $HEADER = str_replace("{e_PAGETITLE}",deftrue('e_PAGETITLE'),$HEADER); //$body_onload .= " id='layout-".e107::getForm()->name2id(THEME_LAYOUT)."' "; @@ -672,7 +687,7 @@ if($noBody === true) // New in v2.2.2 - remove need for BODYTAG. { echo "\n\n"; } -elseif(!deftrue('BODYTAG')) // @deprecated. +elseif(!defined('BODYTAG')) // @deprecated. { $body_onload .= " id='layout-".e107::getForm()->name2id(THEME_LAYOUT)."' "; echo "\n"; @@ -767,8 +782,8 @@ if ($e107_popup != 1) { '{BODY_ONLOAD}' => $body_onload, '{LAYOUT_ID}' => 'layout-'.e107::getForm()->name2id(THEME_LAYOUT), '{---MODAL---}' => (isset($LAYOUT['_modal_']) ? $LAYOUT['_modal_'] : '') , - '{---HEADER---}' => $tp->parseTemplate('{HEADER}',true), - '{---FOOTER---}' => $tp->parseTemplate('{FOOTER}',true), + '{---HEADER---}' => e107::getParser()->parseTemplate('{HEADER}',true), + '{---FOOTER---}' => e107::getParser()->parseTemplate('{FOOTER}',true), ); parseheader($HEADER, $psc); diff --git a/e107_handlers/application.php b/e107_handlers/application.php index 1ec9b5d27..041b9891f 100644 --- a/e107_handlers/application.php +++ b/e107_handlers/application.php @@ -4454,12 +4454,17 @@ class eResponse * @param string $title * @return eResponse */ - function addMetaTitle($title) + public function addMetaTitle($title, $reset=false) { + if($reset) + { + $this->_e_PAGETITLE = array(); + } + return $this->addMetaData('e_PAGETITLE', $title); } - function getMetaTitle() + public function getMetaTitle() { return $this->getMetaData('e_PAGETITLE', $this->_meta_title_separator); } diff --git a/e107_handlers/e107_class.php b/e107_handlers/e107_class.php index bd3c6a8d4..f8b369038 100644 --- a/e107_handlers/e107_class.php +++ b/e107_handlers/e107_class.php @@ -2491,16 +2491,27 @@ class e107 if($name === 'description') { - $response->addMetaDescription($content); //Cam: TBD + $response->addMetaDescription($content); } if($name === 'keywords') { - $response->addMetaKeywords($content); //Cam: TBD + $response->addMetaKeywords($content); } return $response->addMeta($name, $content, $extended); - // return self::getUrl()->response()->addMeta($name, $content, $extended); + + } + + /** + * Set the Page Title ie. Whatever + * @param string $title + */ + public static function title($title) + { + /** @var eResponse $response */ + $response = self::getSingleton('eResponse'); + $response->addMetaTitle($title, true); } /** diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index 1d6e611b7..e21e19165 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -3839,7 +3839,7 @@ class e_parser protected $bootstrap = null; protected $fontawesome = null; - + protected $convertToWebp = false; protected $removedList = array(); protected $nodesToDelete = array(); @@ -3949,6 +3949,11 @@ class e_parser $this->staticUrl = e_HTTP_STATIC; } + // if(e107::pref('core', 'thumb_to_webp', false)) + { + $this->convertToWebp = true; + } + } /** @@ -4045,6 +4050,14 @@ class e_parser $this->bootstrap = (int) $version; } + /** + * @param bool $bool + */ + public function setConvertToWebp($bool) + { + $this->convertToWebp = (bool) $bool; + } + /** * Add leading zeros to a number. eg. 3 might become 000003 diff --git a/e107_languages/English/admin/lan_image.php b/e107_languages/English/admin/lan_image.php index bff384c66..f14ad1a0d 100644 --- a/e107_languages/English/admin/lan_image.php +++ b/e107_languages/English/admin/lan_image.php @@ -211,3 +211,7 @@ define("IMALAN_183", "PNG and GIF files will be automatically converted to jpeg define("IMALAN_184", "Default Image Sizes"); define("IMALAN_185", "Maximum height in pixels"); define("IMALAN_186", "Enter some text to filter results"); + +define("IMALAN_187", "Convert to webp during import"); +define("IMALAN_188", "Convert to webp during render"); +define("IMALAN_189", "JPEG, PNG and GIF files will be automatically converted to webp format. (icons excluded)"); \ No newline at end of file diff --git a/e107_plugins/news/news.php b/e107_plugins/news/news.php index af32666e3..90735dca6 100644 --- a/e107_plugins/news/news.php +++ b/e107_plugins/news/news.php @@ -192,6 +192,7 @@ class news_front return e107::getMenu()->renderMenu('forum','newforumposts_menu', $parms, true); } + return null; } @@ -248,6 +249,8 @@ class news_front { echo $this->renderComments($this->comments); } + + return null; } private function setActions() @@ -424,6 +427,8 @@ class news_front public function debug() { + $title = e107::getSingleton('eResponse')->getMetaTitle(); + echo "
"; echo "

News Debug Info

"; echo ""; @@ -431,7 +436,7 @@ class news_front echo ""; echo ""; echo ""; - echo ""; + echo ""; echo ""; echo ""; echo ""; @@ -494,7 +499,7 @@ class news_front $newsAr = $sql -> db_getList(); } - $i = $this->interval; + // $i = $this->interval; // require_once(e_CORE.'shortcodes/batch/news_archives.php'); @@ -549,23 +554,20 @@ class news_front case "tag": case "author": - if(!defined('e_PAGETITLE')) - { - define('e_PAGETITLE', $this->subAction); - e107::meta('og:title', $this->subAction); - } + + e107::title($this->subAction); + e107::meta('og:title', $this->subAction); e107::meta('robots', 'noindex'); break; case "list": $title = $tp->toHTML($news['category_name'],false,'TITLE_PLAIN'); - if(!defined('e_PAGETITLE')) - { - define('e_PAGETITLE', $title ); - e107::meta('og:title', $title); - } + + e107::title($title); + e107::meta('og:title', $title); e107::meta('robots', 'noindex'); + break; case "day": @@ -587,11 +589,8 @@ class news_front $this->dayMonth = $title; - if(!defined('e_PAGETITLE')) - { - define('e_PAGETITLE', $title ); - e107::meta('og:title', $title); - } + e107::title($title); + e107::meta('og:title', $title); e107::meta('robots', 'noindex'); break; @@ -613,9 +612,9 @@ class news_front e107::meta('robots', $news['news_meta_robots']); } - if($news['news_title'] && !defined('e_PAGETITLE')) + if($news['news_title']) { - define('e_PAGETITLE', $news['news_title']); + e107::title($news['news_title']); e107::meta('og:title',$news['news_title']); e107::meta('og:type','article'); e107::meta('twitter:card', 'summary'); @@ -699,9 +698,9 @@ class news_front - if($news['category_name'] && !defined('e_PAGETITLE') && $type == 'cat') + if($news['category_name'] && $type == 'cat') { - define('e_PAGETITLE', $tp->toHTML($news['category_name'],false,'TITLE_PLAIN')); + e107::title($tp->toHTML($news['category_name'],false,'TITLE_PLAIN')); } if($news['category_meta_keywords'] && !defined('META_KEYWORDS')) @@ -727,7 +726,7 @@ class news_front $e107cache->set($cache_tag, $cache_data); $e107cache->set($cache_tag."_caption", $this->caption); - $e107cache->set($cache_tag."_title", defined("e_PAGETITLE") ? e_PAGETITLE : ''); + $e107cache->set($cache_tag."_title", e107::getSingleton('eResponse')->getMetaTitle()); $e107cache->set($cache_tag."_diz", defined("META_DESCRIPTION") ? META_DESCRIPTION : ''); $e107cache->set($cache_tag."_rows", e107::serialize($rowData,'json')); @@ -776,7 +775,7 @@ class news_front if($etitle) { - define('e_PAGETITLE', $etitle); + e107::title($etitle); } if($ediz) @@ -980,7 +979,7 @@ class news_front // { // define('e_PAGETITLE', $tp->toHTML($category_name,FALSE,'TITLE')); // } - e107::getDebug()->log("PageTitle: ".e_PAGETITLE); + $currentNewsAction = $this->action; $action = $currentNewsAction; @@ -1568,14 +1567,6 @@ class news_front break; } - /*if($action != "" && !is_numeric($action)) - { - if($action == "item" && $this->pref['meta_news_summary'] && $newsAr[1]['news_title']) - { - define("META_DESCRIPTION",SITENAME.": ".$newsAr[1]['news_title']." - ".$newsAr[1]['news_summary']); - } - define("e_PAGETITLE", $p_title); - }*/ $currentNewsAction = $this->action;
subaction:".$this->subAction."
route:".$this->route."
e_QUERY:".e_QUERY."
e_PAGETITLE:".defset('e_PAGETITLE','(unassigned)')."
e_PAGETITLE:".vartrue($title,'(unassigned)')."
PAGE_NAME:".defset('PAGE_NAME','(unassigned)')."
CacheTimeout:".$this->cacheRefreshTime."
_GET:".print_r($_GET,true)."