From 52cf8f5bfa1833d483c83965f686f8896b53e400 Mon Sep 17 00:00:00 2001 From: Cameron Date: Wed, 8 Jun 2022 18:29:37 -0700 Subject: [PATCH] Closes #4783 Added Page Meta-Title field and synced with Page title. Issue #6 global LAN_META_DESCRIPTION and LAN_META_TITLE added and replacements made throughout. --- e107_admin/cpage.php | 22 ++++++- e107_admin/newspost.php | 51 +++------------- e107_core/sql/core_sql.php | 1 + e107_handlers/application.php | 58 +++++++++++++++++++ e107_handlers/cache_handler.php | 9 ++- e107_handlers/form_handler.php | 31 +++++++--- e107_languages/English/admin/lan_admin.php | 2 + e107_languages/English/admin/lan_cpage.php | 2 +- e107_languages/English/lan_submitnews.php | 2 +- e107_plugins/faqs/admin_config.php | 2 +- .../faqs/languages/English/English_admin.php | 2 +- page.php | 6 +- submitnews.php | 2 +- 13 files changed, 128 insertions(+), 62 deletions(-) diff --git a/e107_admin/cpage.php b/e107_admin/cpage.php index ab4daf2a6..6ae4ec219 100644 --- a/e107_admin/cpage.php +++ b/e107_admin/cpage.php @@ -599,8 +599,10 @@ class page_admin_ui extends e_admin_ui 'page_comment_flag' => array('title'=> LAN_COMMENTS, 'tab' => 1, 'type' => 'boolean', 'data'=>'int', 'width' => '5%', 'thclass' => 'center', 'class' => 'center' ), 'page_password' => array('title'=> LAN_PASSWORD, 'tab' => 1, 'type' => 'text', 'data'=>'str', 'width' => 'auto', 'writeParms'=>array('password'=>1, 'nomask'=>1, 'size' => 40, 'class' => 'tbox e-password', 'generate' => 1, 'strength' => 1, 'required'=>0)), 'page_sef' => array('title'=> LAN_SEFURL, 'tab' => 1, 'type' => 'text', 'batch'=>true, 'data'=>'str', 'inline'=>true, 'width' => 'auto', 'writeParms'=>'size=xxlarge&sef=page_title'), + 'page_metatitle' => array('title'=> LAN_META_TITLE, 'tab' => 1, 'type' => 'text', 'data'=>'str', 'width' => 'auto', 'inline'=>true, 'writeParms'=>['size'=>'xxlarge']), + 'page_metadscr' => array('title'=> LAN_META_DESCRIPTION, 'tab' => 1, 'type' => 'textarea', 'data'=>'str', 'help'=>CUSLAN_82, 'width' => 'auto', 'writeParms'=>array('size'=>'xxlarge', 'rows'=>2, 'maxlength'=>155)), 'page_metakeys' => array('title'=> LAN_KEYWORDS, 'tab' => 1, 'type' => 'tags', 'data'=>'str', 'width' => 'auto', 'inline'=>true), - 'page_metadscr' => array('title'=> CUSLAN_11, 'tab' => 1, 'type' => 'textarea', 'data'=>'str', 'help'=>CUSLAN_82, 'width' => 'auto', 'writeParms'=>array('size'=>'xxlarge', 'rows'=>2, 'maxlength'=>155)), + 'page_metaimage' => array('title'=> CUSLAN_81, 'nolist'=>false, 'tab' => 1, 'type' => 'image', 'help'=> CUSLAN_82, 'width' => '110px', 'thclass' => 'center', 'class' => "center", 'nosort' => false, 'readParms'=>'thumb=60&thumb_urlraw=0&thumb_aw=60','writeParms'=>'media=page^&video=1', 'readonly'=>false), 'page_metarobots' => array('title' => LAN_ROBOTS, 'tab'=>1, 'type' => 'dropdown', 'data'=>'safestr', 'batch'=>true, 'inline'=>true, 'readParms'=>array('type'=>'checkboxes'), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'filter'=>true), @@ -928,7 +930,7 @@ class page_admin_ui extends e_admin_ui { parent::CreateObserver(); $this->initCustomFields(0); - + $this->initSEOFields(); } @@ -944,9 +946,25 @@ class page_admin_ui extends e_admin_ui $this->initCustomFields($chap); $this->loadCustomFieldsData(); + $this->initSEOFields(); } + private function initSEOFields() + { + eHelper::syncSEOTitle('page-title', 'page-metatitle'); + + $seoTitleLimit = (int) e107::pref('core', 'seo_title_limit', 100); + $seoDescriptionLimit = (int) e107::pref('core', 'seo_description_limit', 180); + + $this->fields['page_metatitle']['writeParms']['counter'] = $seoTitleLimit; + $this->fields['page_metatitle']['help'] = e107::getParser()->lanVars(LAN_SEARCH_ENGINES_X_LIMIT, $seoTitleLimit); + $this->fields['page_metadscr']['writeParms']['counter'] = $seoDescriptionLimit; + $this->fields['page_metadscr']['help'] = e107::getParser()->lanVars(LAN_SEARCH_ENGINES_X_LIMIT, $seoDescriptionLimit); + + } + + /** * Filter/Process Posted page_field data; * @param $new_data diff --git a/e107_admin/newspost.php b/e107_admin/newspost.php index c05b820ef..5e616ad8e 100644 --- a/e107_admin/newspost.php +++ b/e107_admin/newspost.php @@ -27,31 +27,8 @@ e107::css('inline', " "); -e107::js('footer-inline', ' -$("#news-meta-title").focus(function() { - - var title = $("#news-title").val() + " | " + "'.SITENAME.'"; - - if(!$(this).val()) - { - $(this).val(title); - } - else - { - $(this).attr("placeholder",title); - } - -}); -$("#news-title").on("input change focus", function() -{ - var title = $("#news-title").val() + " | " + "'.SITENAME.'"; - $("#news-meta-title").attr("placeholder",title); - -}); - -'); class news_admin extends e_admin_dispatcher { @@ -434,9 +411,6 @@ class news_sub_form_ui extends e_admin_form_ui } - -define('NEWS_TITLE_META_LIMIT', 50); -define('NEWS_DIZ_META_LIMIT',155); // Main News Area. class news_admin_ui extends e_admin_ui @@ -477,9 +451,9 @@ class news_admin_ui extends e_admin_ui 'news_body' => array('title' => "", 'type' => 'method', 'data'=>'str', 'tab'=>0, 'nolist'=>true, 'writeParms'=>'nolabel=1', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), 'news_extended' => array('title' => "", 'type' => null, 'data'=>'str', 'tab'=>0, 'nolist'=>true, 'noedit'=>true, 'writeParms'=>'nolabel=1', 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), - 'news_meta_title' => array('title' => LAN_TITLE, 'type' => 'text', 'data'=>'safestr', 'filter'=>true, 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'help'=>'', 'writeParms'=>['size'=>'xxlarge', 'placeholder'=>'', 'counter'=>0, 'maxlength'=> 255], 'nosort' => false), + 'news_meta_title' => array('title' => LAN_META_TITLE, 'type' => 'text', 'data'=>'safestr', 'filter'=>true, 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'help'=>'', 'writeParms'=>['size'=>'xxlarge', 'placeholder'=>'', 'counter'=>0, 'maxlength'=> 255], 'nosort' => false), 'news_meta_keywords' => array('title' => LAN_KEYWORDS, 'type' => 'tags', 'data'=>'safestr', 'filter'=>true, 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false), - 'news_meta_description' => array('title' => LAN_DESCRIPTION,'type' => 'textarea', 'data'=>'safestr','filter'=>true, 'tab'=>1, 'width' => 'auto', 'thclass' => '', 'help'=>'', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge', 'counter'=>0, 'maxlength'=>255, 'rows'=>2)), + 'news_meta_description' => array('title' => LAN_META_DESCRIPTION,'type' => 'textarea', 'data'=>'safestr','filter'=>true, 'tab'=>1, 'width' => 'auto', 'thclass' => '', 'help'=>'', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge', 'counter'=>0, 'maxlength'=>255, 'rows'=>2)), 'news_meta_robots' => array('title' => LAN_ROBOTS, 'type' => 'dropdown', 'data'=>'safestr', 'tab'=>1, 'inline'=>true, 'readParms'=>array('type'=>'checkboxes'), 'writeParms'=>array('multiple'=>1), 'width' => 'auto', 'thclass' => 'left', 'class' => 'left', 'nosort' => false, 'batch'=>true, 'filter'=>true), 'news_sef' => array('title' => LAN_SEFURL, 'type' => 'text', 'batch'=>1, 'data'=>'str', 'tab'=>1, 'inline'=>true, 'width' => 'auto', 'thclass' => '', 'class' => null, 'nosort' => false, 'writeParms'=>array('size'=>'xxlarge', 'show'=>1, 'sef'=>'news_title')), @@ -962,8 +936,10 @@ class news_admin_ui extends e_admin_ui } - private function setSEOLimits() + private function initSEOFields() { + eHelper::syncSEOTitle('news-title', 'news-meta-title'); + $seoTitleLimit = (int) e107::pref('core', 'seo_title_limit', 100); $seoDescriptionLimit = (int) e107::pref('core', 'seo_description_limit', 180); @@ -977,27 +953,14 @@ class news_admin_ui extends e_admin_ui function EditObserver() { parent::EditObserver(); - - $title = $this->getFieldVar('news_title'). ' | '.SITENAME; - $placeholder = $this->getFieldVar('news_meta_title'); - - if(empty($placeholder)) - { - $this->fields['news_meta_title']['writeParms']['placeholder'] = html_entity_decode($title); - } - else - { - $this->fields['news_meta_title']['writeParms']['placeholder'] = html_entity_decode($placeholder); - } - - $this->setSEOLimits(); + $this->initSEOFields(); } function CreateObserver() { parent::CreateObserver(); - $this->setSEOLimits(); + $this->initSEOFields(); } diff --git a/e107_core/sql/core_sql.php b/e107_core/sql/core_sql.php index 8d3b8f04b..b657ad1f9 100755 --- a/e107_core/sql/core_sql.php +++ b/e107_core/sql/core_sql.php @@ -384,6 +384,7 @@ CREATE TABLE page ( page_subtitle varchar(250) NOT NULL default '', page_sef varchar (250) NOT NULL default '', page_chapter int(10) unsigned NOT NULL default '0', + page_metatitle varchar(255) NOT NULL default '', page_metakeys varchar (250) NOT NULL default '', page_metadscr mediumtext, page_metaimage varchar (250) NOT NULL default '', diff --git a/e107_handlers/application.php b/e107_handlers/application.php index e7bc7558b..8734ce453 100644 --- a/e107_handlers/application.php +++ b/e107_handlers/application.php @@ -5286,4 +5286,62 @@ class eHelper } + /** + * Duplicates the value from a title form field into the meta-title form field. + * @param str $titleID eg. news-title + * @param str $metaTitleID eg. news-meta-title + * @return void + */ + public static function syncSEOTitle($titleID, $metaTitleID) + { + + e107::js('footer-inline', ' + + $(window).on("load", function () { + + if(!$("#'.$metaTitleID.'").val()) + { + var title = $("#'.$titleID.'").val() + " | " + "'.SITENAME.'"; + var charlimit = $("#'.$metaTitleID.'").attr("data-char-count"); + + $("#'.$metaTitleID.'").attr("placeholder",title); + + if(title.length > charlimit) + { + $("#'.$metaTitleID.'").addClass("has-error"); + } + } + + }); + + + $("#'.$metaTitleID.'").on("ready focus", function() { + + var title = $("#'.$titleID.'").val() + " | " + "'.SITENAME.'"; + + if(!$(this).val()) + { + $(this).val(title); + } + else + { + $(this).attr("placeholder",title); + } + + }); + + + $("#'.$titleID.'").on("input change focus", function() + { + var title = $("#'.$titleID.'").val() + " | " + "'.SITENAME.'"; + $("#'.$metaTitleID.'").attr("placeholder",title); + + }); + + '); + + + } + + } diff --git a/e107_handlers/cache_handler.php b/e107_handlers/cache_handler.php index b72216e5d..1deb74a51 100644 --- a/e107_handlers/cache_handler.php +++ b/e107_handlers/cache_handler.php @@ -356,23 +356,26 @@ class ecache { { $path = null; - e107::getEvent()->trigger('cache_clear_all', ['type'=>$type,'mask'=>$mask]); + $event = e107::getEvent(); if($type =='content') { - $this->clear(); + $this->clear(); + $event->trigger('cache_clear_all', ['type'=>$type,'mask'=>$mask]); return; } if($type === 'system') { $this->clear_sys(); + $event->trigger('cache_clear_all', ['type'=>$type,'mask'=>$mask]); return; } if($type === 'browser') { e107::getConfig()->set('e_jslib_browser_cache', time())->save(false); + $event->trigger('cache_clear_all', ['type'=>$type,'mask'=>$mask]); return; } @@ -422,6 +425,8 @@ class ecache { unlink($path.$file); } } + + $event->trigger('cache_clear_all', ['type'=>$type,'mask'=>$mask]); } } diff --git a/e107_handlers/form_handler.php b/e107_handlers/form_handler.php index b04689fbc..3fc230e1a 100644 --- a/e107_handlers/form_handler.php +++ b/e107_handlers/form_handler.php @@ -4503,6 +4503,17 @@ var_dump($select_options);*/ public function columnSelector($columnsArray, $columnsDefault = array(), $id = 'column_options') { $columnsArray = array_filter($columnsArray); + + try + { + $tabs = e107::getAdminUI()->getController()->getTabs(); + } + catch (Exception $e) + { + // do something + } + + // navbar-header nav-header // navbar-header nav-header @@ -4527,10 +4538,21 @@ var_dump($select_options);*/ if (empty($fld['forced']) && empty($fld['nolist']) && $theType !== 'hidden' && $theType !== 'upload') { $checked = (in_array($key,$columnsDefault)) ? TRUE : FALSE; + $title = ''; + if(isset($fld['tab'])) + { + $tb = $fld['tab']; + if(!empty($tabs[$tb])) + { + $title = $tabs[$tb].": "; + } + } + $ttl = isset($fld['title']) ? defset($fld['title'], $fld['title']) : $key; + $title .= $ttl; $text .= " -
  • +
  • ".$this->checkbox('e-columns[]', $key, $checked,'label='.$ttl). '
  • @@ -6626,11 +6648,6 @@ var_dump($select_options);*/ $parms['class'] = 'tbox e-count'; $parms['data-char-count'] = $parms['counter']; - if(!empty($parms['placeholder']) && (strlen($parms['placeholder']) > (int) $parms['counter'])) - { - $parms['class'] .= " has-error"; - } - if(!isset($parms['pattern'])) { $parms['pattern'] = '.{0,'.$parms['counter'].'}'; @@ -6689,7 +6706,7 @@ var_dump($select_options);*/ { $parms['class'] = 'tbox e-count'; - if(!empty($parms['placeholder']) && (strlen($parms['placeholder']) > (int) $parms['counter'])) + if(!empty($value) && (strlen($value) > (int) $parms['counter'])) { $parms['class'] .= " has-error"; } diff --git a/e107_languages/English/admin/lan_admin.php b/e107_languages/English/admin/lan_admin.php index 369585760..c15545568 100644 --- a/e107_languages/English/admin/lan_admin.php +++ b/e107_languages/English/admin/lan_admin.php @@ -596,3 +596,5 @@ define("LAN_UI_FILTER_THIS_MONTH", "This Month"); define("LAN_UI_FILTER_THIS_YEAR", "This Year"); define("LAN_SEARCH_ENGINES_X_LIMIT", "Read by search engines. Maximum [x] characters."); +define("LAN_META_TITLE", "Meta Title"); +define("LAN_META_DESCRIPTION", "Meta Description"); \ No newline at end of file diff --git a/e107_languages/English/admin/lan_cpage.php b/e107_languages/English/admin/lan_cpage.php index 17d906545..7c70eede1 100644 --- a/e107_languages/English/admin/lan_cpage.php +++ b/e107_languages/English/admin/lan_cpage.php @@ -13,7 +13,7 @@ define("CUSLAN_4", "Custom Fields"); define("CUSLAN_5", "(New Book)"); define("CUSLAN_9", "Text"); -define("CUSLAN_11", "Meta description"); +// define("CUSLAN_11", "Meta description"); @see LAN_META_DESCRIPTION define("CUSLAN_12", "Create Page/Menu"); define("CUSLAN_29", "List pages if no page selected"); define("CUSLAN_30", "Expiry time for cookie (in seconds)"); diff --git a/e107_languages/English/lan_submitnews.php b/e107_languages/English/lan_submitnews.php index 6e5965c0f..4400af5d4 100644 --- a/e107_languages/English/lan_submitnews.php +++ b/e107_languages/English/lan_submitnews.php @@ -33,7 +33,7 @@ define("SUBNEWSLAN_7", "You must give your name and email address"); define("SUBNEWSLAN_8", "Error uploading image"); define("SUBNEWSLAN_9", "Keywords"); //define("SUBNEWSLAN_10", "Summary");//LAN_SUMMARY -define("SUBNEWSLAN_11", "Meta Description"); +// define("SUBNEWSLAN_11", "Meta Description"); LAN_META_DESCRIPTION define("SUBNEWSLAN_12", "Used by Facebook etc."); define("SUBNEWSLAN_13", "Media URLs"); diff --git a/e107_plugins/faqs/admin_config.php b/e107_plugins/faqs/admin_config.php index e12f1cdf7..2c9b50565 100644 --- a/e107_plugins/faqs/admin_config.php +++ b/e107_plugins/faqs/admin_config.php @@ -95,7 +95,7 @@ class faq_cat_ui extends e_admin_ui 'faq_info_about' => array('title'=> LAN_DESCRIPTION, 'type' => 'bbarea', 'width' => '30%', 'readParms' => 'expand=...&truncate=50&bb=1'), // Display name 'faq_info_parent' => array('title'=> LAN_CATEGORY, 'type' => 'dropdown', 'width' => '5%', 'writeParms'=>''), 'faq_info_class' => array('title'=> LAN_VISIBILITY, 'type' => 'userclass', 'width' => 'auto', 'data' => 'int', 'inline'=>true), - 'faq_info_metad' => array('title'=> LANA_FAQ_METAD, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'), + 'faq_info_metad' => array('title'=> LAN_META_DESCRIPTION, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'), 'faq_info_metak' => array('title'=> LANA_FAQ_METAK, 'type' => 'tags', 'width' => 'auto', 'thclass' => 'left', 'readParms'=>'editable=1'), 'faq_info_sef' => array('title'=> LAN_SEFURL, 'type' => 'text', 'width' => 'auto', 'thclass' => 'left', 'inline'=>true, 'writeParms'=>'size=xxlarge'), diff --git a/e107_plugins/faqs/languages/English/English_admin.php b/e107_plugins/faqs/languages/English/English_admin.php index 5dc448b5d..8168f5e05 100644 --- a/e107_plugins/faqs/languages/English/English_admin.php +++ b/e107_plugins/faqs/languages/English/English_admin.php @@ -14,7 +14,7 @@ define("LANA_FAQ_COMMENT", "Comment Class"); define("LANA_FAQ_ULOGINNAME", "User login"); //FIXME Use generic define("LANA_FAQ_TAGS", "Tags"); define("LANA_FAQ_TAGS_HELP", "Comma separated tag list"); -define("LANA_FAQ_METAD", "Meta Description"); +// define("LANA_FAQ_METAD", "Meta Description"); LAN_META_DESCRIPTION define("LANA_FAQ_METAK", "Meta Keywords"); define("LANA_FAQ_PREF_1", "Allow submitting of FAQs by:"); diff --git a/page.php b/page.php index 366338b49..0109a2b13 100644 --- a/page.php +++ b/page.php @@ -745,8 +745,10 @@ class pageClass e107::title($metaTitle); e107::meta('twitter:title', $metaTitle); - - + if(!empty($this->page['page_metatitle'])) + { + e107::title(eHelper::formatMetaTitle($this->page['page_metatitle']),true); + } if(!empty($this->page['page_metakeys'])) { diff --git a/submitnews.php b/submitnews.php index c827076ab..cb9e249c6 100644 --- a/submitnews.php +++ b/submitnews.php @@ -310,7 +310,7 @@ class submitNews $fields = array(); $fields['submitnews_keywords'] = array('title'=>SUBNEWSLAN_9, 'type'=>'tags'); $fields['submitnews_summary'] = array('title'=>LAN_SUMMARY, 'type'=>'text', 'writeParms'=>array('maxlength'=>255, 'size'=>'xxlarge')); - $fields['submitnews_description'] = array('title'=>SUBNEWSLAN_11, 'type'=>'textarea','writeParms'=>array('placeholder'=>SUBNEWSLAN_12)); + $fields['submitnews_description'] = array('title'=>LAN_META_DESCRIPTION, 'type'=>'textarea','writeParms'=>array('placeholder'=>SUBNEWSLAN_12)); $fields['submitnews_media'] = array('title'=>SUBNEWSLAN_13, 'type'=>'method', 'method'=>'submitNewsForm::submitnews_media');