We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 4095
    • 372 Posts
    I didn’t write this snippet, its an old Etomite one I have been using for ages. There have been a few new versions since this one, but mostly adding stuff I didn’t need.

    Thought it post it here since there was recently a request for "Creation Date" and "Last Edit Date" over at http://modxcms.com/forums/index.php/topic,3413.0.html


    /**
    | --------------------------------------------------------------------------
    | Snippet Title:     MetaTagsExtra
    | Snippet Version:   1.5 (final)
    |
    | Description:
    |   Returns HTML for document dependant meta tags: Generator,
    |   Description, Abstract, Author, Copyright, 
    |   Robots, Googlebot, Cache-Control, Pragma, Expires and Last Modified
    |
    | Snippet Author:
    |   Miels with mods by Lloyd Borrett ([email protected])
    |
    | Version History:
    |   1.3 - Lloyd Borrett added the Robots meta tag based 
    |   on the idea in the SearchableSE snippet by jaredc
    |
    |   1.4 - Lloyd Borrett added the Abstract meta tag
    |   based on the Site Name and the Long Title.
    |   Also added the Generator meta tag based on the MODx version details.
    |   The Robots meta tag is now only output if the document is non-searchable,
    |   to reduce HTML bloat. The Googlebot meta tag is now also output 
    |   when the document is non-searchable.
    |
    |   1.5 - Lloyd Borrett added no-cache directives via the Cache-Control 
    |   and Pragma meta tags if the document is non-cacheable.
    |   Abstract meta tag uses the document description if long title not set.
    |   Cleaned up some other tests. 
    |   
    |   Edited by Shane Briggs to refer to MODx rather than Etomite and 
    |   removed the Get Keyword function as that is provided by MODx
    |   natively as well as via the GetKeywords snippet
    |
    |
    | Snippet Category:
    |   Search Engines           
    |
    | Usage:
    |   Insert [[MetaTags]] anywhere in the head section of your template.
    |   Don't forget to set the full name of all document authors.
    |   You can find it at "Manage users" -> your username -> "full name".
    |   This value is used for the Author and Copyright meta tags.
    |
    |   When you mark a page as "NOT searchable" - a Robots meta tag 
    |   with "noindex, nofollow" is inserted to keep web search engines
    |   from indexing that document. After all, there's little value in 
    |   making your MODx document unsearchable to MODx, when 
    |   Google still knows where it is! For "searchable" documents, no
    |   Robots meta tag is inserted. The default is "index, follow", so not
    |   putting it in reduced HTML bloat.
    |   A Googlebot meta tag with "noindex, nofollow, noarchive, nosnippet"
    |   is also output, to tell Google to clean out its cache.
    |
    |   When you mark a page as "non cacheable", no-cache directives 
    |   are inserted via the Cache-Control and Pragma meta tags.
    | ---------------------------------------------------------------------------
    */
    
    $MetaGenerator = "";
    $MetaDesc = "";
    $MetaAbstract = "";
    $MetaAuthor = "";
    $MetaCopyright = "";
    $MetaRobots = "";
    $MetaGooglebot = "";
    $MetaCache = "";
    $MetaPragma = "";
    $MetaExpires = "";
    $MetaEditedOn = "";
    
    // *** GENERATOR ***
    $version = $modx->getVersionData();
    $MetaGenerator = " <meta name=\"version\" content=\"";
    if(!$version['version'] == ""){
       $MetaGenerator .= "MODx ".$version['version'];
    }
    if(!$version['code_name'] == ""){
       $MetaGenerator .= " (".$version['code_name'].")";
    }
    $MetaGenerator .= "\" />\n";
    
    $docInfo = $modx->getDocument($modx->documentIdentifier);
    
    // *** DESCRIPTION ***
    $description = $docInfo['description'];
    if(!$description == ""){
       $MetaDesc = " <meta name=\"description\" content=\"$description\" />\n";
    }
    // *** ABSTRACT ***
    // Use the Site Name and the documents Long Title (or Description)  
    // to build an Abstract meta tag.
    $sitename = $modx->config['site_name'];
    $abstract = $docInfo['longtitle'];
    if($abstract == ""){
       $abstract = $description;
    }
    if(!sitename == ""){
       $MetaAbstract = " <meta name=\"abstract\" content=\"".$sitename;
       if(!$abstract == ""){
          $MetaAbstract .= " - ".$abstract."\" />\n";
       } else {
          $MetaAbstract .= "\" />\n";
       }
    } else {
       if(!$abstract == ""){
          $MetaAbstract = " <meta name=\"abstract\" content=\"";
          $MetaAbstract .= $abstract."\" />\n";
       }
    }
    
    // *** AUTHOR, COPYRIGHT, PUBLISHER and COMPANY ***
    $authorid = $docInfo['createdby'];
    $createdon = date(Y,$docInfo['createdon']);
    $tbl = $modx->dbConfig['dbase'].".".$etomite->dbConfig['table_prefix']."user_attributes";
    $query = "SELECT fullname FROM $tbl WHERE $tbl.id = $authorid"; 
    $rs = $modx->dbQuery($query);
    $limit = $modx->recordCount($rs); 
    if($limit=1) {
      $resourceauthor = $etomite->fetchRow($rs); 
      $authorname = $resourceauthor['fullname'];  
    }
    if (!$authorname == ""){
      $MetaAuthor = " <meta name=\"author\" content=\"$authorname\" />\n";
      $MetaCopyright = " <meta name=\"copyright\" content=\"Copyright (c) $createdon by $authorname. All rights reserved.\" />\n";
    }
    
    // *** ROBOTS and GOOGLEBOT ***
    // Determine if this document has been set to non-searchable.
    // As the default for the Robots and Googlebot Meta Tags are index and follow,
    // these tags are only needed when we don't want the document searched. 
    if(!$modx->documentObject['searchable']){
      $MetaRobots = " <meta name=\"robots\" content=\"noindex, nofollow\" />\n";
      $MetaGooglebot = " <meta name=\"googlebot\" content=\"noindex, nofollow, noarchive, nosnippet\" />\n";
    }
    
    // *** CACHE-CONTROL and PRAGMA ***
    // Output no-cache directives via the Cache-Control and Pragma meta tags
    // if this document is set to non-cacheable. 
    $cacheable = $docInfo['cacheable'];
    if (!$cacheable) {
       $MetaCache = " <meta http-equiv=\"cache-control\" content=\"no-cache\" />\n";
       $MetaPragma = " <meta http-equiv=\"pragma\" content=\"no-cache\" />\n";
    }
    
    // *** EXPIRES ***
    $unpubdate = date(r,$docInfo['unpub_date']);
    if($unpubdate > 0){
       $MetaExpires = " <meta http-equiv=\"expires\" content=\"$unpubdate\" />\n";
    }
    
    // *** LAST MODIFIED ***
    $editedon = date(r,$docInfo['editedon']);
    $MetaEditedOn = " <meta http-equiv=\"last-modified\" content=\"$editedon\" />\n";
    
    
    // *** RETURN RESULTS ***
    
    $output = $MetaGenerator.$MetaDesc.$MetaAbstract.$MetaAuthor.$MetaCopyright;
    $output .= $MetaRobots.$MetaGooglebot.$MetaCache.$MetaPragma.$MetaExpires.$MetaEditedOn;
    
    return $output;
      [img]http://www.emanz.ac.nz/assets/images/logo/emanz-icon_16x16.gif[/img] Emergency Management Academy of New Zealand [br] http://www.emanz.ac.nz[br][br]MODx Sandbox Login: sandbox Password: castle [br]
      Admin Sandbox Login: sandbox Password: castle
      • 33337
      • 3,975 Posts
      Thanks for a nice snippet!

      regards,

      zi
        Zaigham R - MODX Professional | Skype | Email | Twitter

        Digging the interwebs for #MODX gems and bringing it to you. modx.link
        • 25468
        • 18 Posts
        very cool indeed..

        Looks as if you still have a few db call using $etomite though, Line 114 and 119.

        Cheers,
        Gregg
          /Gregg/
          • 25468
          • 18 Posts
          One other note I got a sql erro when attempting to use the original, swapped out the $tbl and $query values as follows:
          $tbl = $modx->getFullTableName("web_user_attributes");
          $query = "SELECT fullname FROM $tbl WHERE $tbl.id =abs($authorid)";
          


          I am new to modx but it seemed to work..

          Cheers,
          Gregg
            /Gregg/
            • 16711
            • 12 Posts
            Quote from: Briggsy at Mar 15, 2006, 07:30 AM

            Thought it post it here since there was recently a request for "Creation Date" and "Last Edit Date" over at http://modxcms.com/forums/index.php/topic,3413.0.html

            I like this. I`d like to use the snippet in my Website. Now I`ve installed the snipped, put the MetaTags in the head of my Template. Now I think I have to put some code as well in my Template? What code?

            Finally, I`d like a site like Brethous: http://www.brethous.fr - There is a Creation Date.


            Thanks for help