CMS MADE SIMPLE FORGE

SEOTools2

 

[#10640] Meta description not set

avatar
Created By: Patrick Schoenbach (pschoenb)
Date Submitted: Wed Sep 16 10:51:29 -0400 2015

Assigned To:
Version: None
CMSMS Version: 2.0
Severity: None
Resolution: None
State: Open
Summary:
Meta description not set
Detailed Description:
In CMSMS 2.0, the meta description is not filled in.

The code you mentioned in bug #8404 does not work either.


History

Comments
avatar
Date: 2015-09-20 11:25
Posted By: Patrick Schoenbach (pschoenb)

I propose the following patch which works for me. As I did not find an easy
solution to access the current meta description, I changed the logic. Please
feel free to adapt it, if you know a better solution.

diff -urN SEOTools2.old/event.Core.ContentPostRender.php
SEOTools2/event.Core.ContentPostRender.php
--- SEOTools2.old/event.Core.ContentPostRender.php	2015-09-20 17:07:51.606065843
+0200
+++ SEOTools2/event.Core.ContentPostRender.php	2015-09-19 17:21:26.214720200
+0200
@@ -33,15 +33,17 @@
 $smarty = cmsms()->GetSmarty();
 $tpl_vars = $smarty->get_template_vars();
 $html_version = $mod->GetPreference('meta_doctype');
-$close_tag = $html_version < 3 ? " />\n" : ">\n";
+$close_tag = $html_version < 3 ? " />" : ">";
 $content = $params['content'];
 $detail_keywords = '';
 
// Change the page meta description to a module detail page meta description eg
News, CGBlog, Products, etc
 if ($seo2blockname = $mod->GetPreference('description_block')) {
$seo2blockcontent = $tpl_vars['content_obj']->GetPropertyValue
($seo2blockname);
-  if ($tpl_vars['metadescription'] != $seo2blockcontent) {
-    $newtag = "<meta name='description'
content='".$tpl_vars['metadescription']."'" .$close_tag;
+  $hasMetaDescription = strpos($content,"<meta name='description'") >= 0;
+  $emptyMetaDescription = strpos($content,"<meta name='description'
content=''") >= 0;
+  if (!$hasMetaDescription || $emptyMetaDescription) {
+    $newtag = "<meta name='description' content='".$seo2blockcontent."'"
.$close_tag;
     $start = strpos($content,"<meta name='description'");
     $endoftag = strpos($content,">",$start);
     $length = $endoftag - $start + 1;

      
avatar
Date: 2015-09-20 13:26
Posted By: Patrick Schoenbach (pschoenb)

Sorry, I forgot one change. Here is an improved version of the patch.

diff -urN SEOTools2.old/event.Core.ContentPostRender.php
SEOTools2/event.Core.ContentPostRender.php
--- SEOTools2.old/event.Core.ContentPostRender.php	2015-09-20 17:07:51.606065800
+0200
+++ SEOTools2/event.Core.ContentPostRender.php	2015-09-20 19:11:48.555639100
+0200
@@ -33,15 +33,17 @@
 $smarty = cmsms()->GetSmarty();
 $tpl_vars = $smarty->get_template_vars();
 $html_version = $mod->GetPreference('meta_doctype');
-$close_tag = $html_version < 3 ? " />\n" : ">\n";
+$close_tag = $html_version < 3 ? " />" : ">";
 $content = $params['content'];
 $detail_keywords = '';
 
// Change the page meta description to a module detail page meta description eg
News, CGBlog, Products, etc
 if ($seo2blockname = $mod->GetPreference('description_block')) {
$seo2blockcontent = $tpl_vars['content_obj']->GetPropertyValue
($seo2blockname);
-  if ($tpl_vars['metadescription'] != $seo2blockcontent) {
-    $newtag = "<meta name='description'
content='".$tpl_vars['metadescription']."'" .$close_tag;
+  $hasMetaDescription = strpos($content,"<meta name='description'") >= 0;
+  $emptyMetaDescription = strpos($content,"<meta name='description'
content=''") >= 0;
+  if (!$hasMetaDescription || $emptyMetaDescription) {
+    $newtag = "<meta name='description' content='".$seo2blockcontent."'"
.$close_tag;
     $start = strpos($content,"<meta name='description'");
     $endoftag = strpos($content,">",$start);
     $length = $endoftag - $start + 1;
diff -urN SEOTools2.old/lib/class.seo2_utils.php
SEOTools2/lib/class.seo2_utils.php
--- SEOTools2.old/lib/class.seo2_utils.php	2015-09-16 15:49:34.000000000 +0200
+++ SEOTools2/lib/class.seo2_utils.php	2015-09-20 19:11:57.254136600 +0200
@@ -251,7 +251,7 @@
         $alert = Array();
         $alert['group'] = 'descriptions';
$alert['message'] =
$mod->Lang('meta_description_short',Array($problem['content_name']));
-        $alert['links'][] = '<a
href="'.$root_url.'/'.$config['admin_dir'].'/editcontent.php?'.CMS_SECURE_PARAM_NAME.'='.$_GET[CMS_SECURE_PARAM_NAME].'&content_id='.$problem['cid'].'">'.$mod->Lang('edit_page_to_fix').'</a>';
+        $alert['links'][] = '<a
href="'.$root_url.'/'.$config['admin_dir'].'/moduleinterface.php?mact=CMSContentManager,m1_,admin_editcontent,0&'.CMS_SECURE_PARAM_NAME.'='.$_GET[CMS_SECURE_PARAM_NAME].'&m1_content_id='.$problem['cid'].'">'.$mod->Lang('edit_page_to_fix').'</a>';
         $alerts[] = $alert;
       }
     }
@@ -665,4 +665,4 @@
   
 }
 
-?>
\ No newline at end of file
+?>

      
Updates

Updated: 2015-09-20 11:19
resolution_id: => 5