martedì 15 novembre 2011

Title tags: different methods... typoscript or php?

A while ago i set up some page to change the title tag based on url parameters or sql query...

As i may have state before... 'speaking' parameters may be of help with google indexing...

So i made a typoscript extension for the page with this code:

config.noPageTitle = 2

page.headerData.20 = TEXT
page.headerData.20.value = Felix - Il portale del gatto: disponibile - foto -
page.headerData.20.wrap = <title>|
page.headerData.21 = TEXT
page.headerData.21.data = global : HTTP_GET_VARS |ALR
page.headerData.21.noTrimWrap=|   ||
page.headerData.23 = TEXT
page.headerData.23.data = global : HTTP_GET_VARS |GATTO
page.headerData.23.noTrimWrap=|   ||
page.headerData.24 = TEXT

page.headerData.50.value = </title>


page.headerData.22 = CONTENT
page.headerData.22{
  table=fxbreeder
   
  select{
    selectFields=lrazz,uid
    andWhere.data = global:HTTP_GET_VARS|ALZ
    andWhere.wrap = uid='|'
   
  }
  renderObj=COA
  renderObj{
    5=TEXT
    5{
            field=lrazz
    }   
  }
}
 First line config.noPageTitle = 2 is very important since delete the basic title tag for the page and open the opportuinity  of write the title tag through the typoscript system.

But... i noticed though google webmaster tools that when the title becomes too long the </title> was not written in the page.  The title tag become oversized in the whole page and i get this behavior:

the page http://www.felixweb.it/public/index.php?id=266&FID=1035&ALZ=130&GATTO=Torakiki%20Love%20of%20my%20Life%20%20black%20silver%20mackerel%20&%20white&L=0

got the title trunked title tag:

Felix - Il portale del gatto: disponibile - foto - Torakiki Love of my Life black silver mackerel <meta name ....

You can see the next tag in the header appearing in the title tag!

So i decided to change method:

You still need the first row with config.noPageTitle = 2 in order to get your php lumo record to work.

This is the part of the script for the new method:

<?php
$fid = $_GET['FID'];
$gatto = $_GET['GATTO'];
$alr= $_GET['ALR'];
$GLOBALS ['TSFE'] -> additionalHeaderData ['100 '] ='<title>Felix - Il portale del gatto: foto '.$gatto.'</title>';
In this case the script goes on and render the rest of the page with a query from the FID url paramether, but this is old story!

lunedì 14 novembre 2011

Experimenting with link rel canonical

One year ago i put a sitemap on google to fix the problem of the duplicate page caused by the way typo3 manages urlvars. I have found this is not the correct solution for a growning and changing site...
does not work very well and constant repopulation of the map is needed as new parameters value compare.

So, since now i know how to revrite header on any page, i am trying a different solution.

I'm going to setup this for root pages (level 1).

Again lumo php record is the main tool.

Here is a sample code:

<?php
$fid = $_GET['FID'];
$canurl='http://www.felixweb.it/galleria_foto_gatti.php';
$imgg="galleria_gatti_thmb.JPG";
$title="FELIX - la galleria : foto e immagini dei gatti più belli degli allevamenti e degli amici di FELIX";
$GLOBALS ['TSFE'] -> additionalHeaderData ['100 '] ='<meta property="og:title" content="'.$title.'" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['101 '] ='<meta property="og:type" content="website" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['102 '] ='<meta property="og:url" content="'.$canurl.'" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['103 '] ='<meta property="og:image" content="http://www.felixweb.it/public/fileadmin/user_upload/gallery2/thumb/'.$imgg.'" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['104 '] ='<meta property="og:site_name" content="FELIX il portale del gatto" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['105 '] ='<meta property="fb:admins" content="1466516534" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['106 '] ='<link rel="canonical"  href="'.$canurl.'"/>';

?>

As you can see i have setup all parameters in variable at the beginning of the code.  Next you can find header for facebook, always useful, and is good to do all headers work on the same place to avoid indexing problem (if a second script write another additionalHeaderData ['105 '] this one will be lost!

The last HeaderData (number 106) is the link rel canonical one. As you can see i am using a speaking url as canonical...

I hope this solution works well... i will keep you informed!

mercoledì 9 novembre 2011

Typo3: pinging a google sitemap

If you give to a number of users to ability to post content on your Typo3 website, maybe you will feel the need to let google notice you have frequent changes on your site.

This is both a content indexing need and a raniking/positioning matter.

The basic operation to go with is have a google sitemap containting the changing pages to ping when new content appears.

So, i made a very simple sitemap and upload it through my google webmaster tools page. It contains a little number of pages, with the date of the last change.

Then, i inserted a little lumo php record on the landing page where the user is leaded after he posted the new content.

This little php thing do a pair things:

  1. check the actual google sitemap dates. if date match with today date, then job is already done... Exit! 
  2. update the google site map date with today date
  3. ping the sitemap
As you can see from point 1, i only ping the xml one time per day. No need to do it more times!
To archive point 3 i stole a chunk of code from the web.

Here's a sample code:
<?php
$filename = "googlesitemaptoping.xml";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$pos = strrpos($contents, date("Y-m-d"));
if ($pos === false) {
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
$contents = str_replace("DDDDDD", date("Y-m-d"), $contents);
$handle = fopen($filename, "w");
fwrite($handle, $contents);
fclose($handle);
/**
 * Function to ping Google Sitemaps.
 *
 * Function to ping Google Sitemaps. Returns an integer, e.g. 200 or 404,
 * 0 on error.
 *
 * @author     J de Silva                           <giddomains@gmail.com>
 * @copyright  Copyright &copy; 2005, J de Silva
 * @link       http://www.gidnetwork.com/b-54.html  PHP function to ping Google Sitemaps
 * @param      string   $url_xml  The sitemap url, e.g. http://www.example.com/google-sitemap-index.xml
 * @return     integer            Status code, e.g. 200|404|302 or 0 on error
 */
 $url_xml="http://www.yourwebsiteurl.org/".$filename;

   $status = 0;
   $google = 'www.google.com';
   if( $fp=@fsockopen($google, 80) )
   {
      $req =  'GET /webmasters/sitemaps/ping?sitemap=' .
              urlencode( $url_xml ) . " HTTP/1.1\r\n" .
              "Host: $google\r\n" .
              "User-Agent: Mozilla/5.0 (compatible; " .
              PHP_OS . ") PHP/" . PHP_VERSION . "\r\n" .
              "Connection: Close\r\n\r\n";
      fwrite( $fp, $req );
      while( !feof($fp) )
      {
         if( @preg_match('~^HTTP/\d\.\d (\d+)~i', fgets($fp, 128), $m) )
         {
            $status = intval( $m[1] );
            break;
         }
      }
      fclose( $fp );
   }
}
?>
As usual, this will also work on any php enabled webserver.

venerdì 4 novembre 2011

Socialize your typo3: typo3 and php for facebook integration

Maybe, like me, you have experienced mixed results when sharing your typo3 pages through facebook. THe social network platform tend to select the wrong image has thumbnail, some times the wrong texts too...

Looking at youtube i understand that there must be some way to control thoose things...

The final result of my search:

$GLOBALS ['TSFE'] -> additionalHeaderData ['100 '] ='<meta property="og:title" content="'.$tagg.'" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['101 '] ='<meta property="og:type" content="website" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['102 '] ='<meta property="og:url" content="http://www.urltoshare.org" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['103 '] ='<meta property="og:image" content="http://www.urltoshare.org/thumb/thumb_of_this_page.jpg" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['104 '] ='<meta property="og:site_name" content="Your site name" />';
$GLOBALS ['TSFE'] -> additionalHeaderData ['105 '] ='<meta property="fb:admins" content="123456789" />';
I insert this lines in a php script on a lumo net php object at the start of the page (i guess i may not work if you insert LATELY). As you can see, the first line has a $tagg variable i insert to example the options of get the contet of the  Facebook header datas from your (to say one) database... as i do!

Have a special look to the og:image line... it points to the right thumb image. You need a compliant thumb, i usually have my engine create 150x130 circa thumbs. See the specs on the facebook developers page.

The last muber sequence i guess you should get your own from facebook developers system!

You can see a sample of the final result here:

http://www.felixweb.it/galleria.php

You see my felixweb gallery of cat's picture's. Under every image you got a like button. Click one and you will share not the actual gallery page, nor the raw image, but a different page that contains a larger version of the image, the proper thumb and the php lumo that tells facebook the right thing to do to share your page.

Works really well for me!

mercoledì 2 novembre 2011

My Typo3 basic extensions: LumoNet PHP

Before i go in deep on some of my tips, i need to let you know the basic tool.
This simple plugin do what i most need to do on a Typo3 page:
RUN PHP CODE ON A TYPO3 PAGE INSIDE THE PHP ENGINE!

As you my guess, this is pretty cool when you go 'advanced' in T3 developement.

The basics (my way...):
1-You must have your standardphpcode.php ranamed to standardphp.txt
2-Create a new record on the page and select 'PHP include' plugin as new content element
3-Upload from local your standardphp.txt
4-Next time when you need to edit, i suggest you to go from ftp to uploads/tx_lumophpinclude and edit from here to avoid the creation of undreds of version inside the folder

Now have a look at your page, see the result and start the hardwork!

Some other thips on php and lumo i'd like to share:

This sample to get access to the Typo3db via the Typo3 Engine and its conenction:
<?php
$sel="SELECT * FROM yourtable";
$res = $GLOBALS['TYPO3_DB']->sql(TYPO3_db,$sel);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
echo $row['yourfield']."<br>";
}
?>
 And with this simple line you get the actual FE_USER id (really useful for someone!):

$usrlog=$GLOBALS['TSFE']->fe_user->user['uid'];
 If you want to check a simple result of a php 'in-page' code, here my 'cat show results' page:
http://www.felixweb.it/public/index.php?id=231&L=2

I use php to build up the data from two tables, build the html table and the various href links to the details of the single shows.
There is also a management system in the front end to allow the fe_users in the 'manager' group to arrange manage the results data.

domenica 30 ottobre 2011

Easy speaking urls on typo3 and others...

As you may know Typo3 default urls in the format of http://www.typo3site.org/index.php?id=27 aren't the best thing when it comes to google indexing.

The format http://www.sitename.org/pagename.php has indeed a better keywording.

Typo3 offers a variety of extensions to help with human readable urls such as realurl.

I tried realurl and some other on one of my Typo3 sites, the one i usually test thing with because is the less complex. It did not work for me. I did not liked the result and i did not liked the configuration effort (i don't need the thing to work on all pages, only main pages and some other).

I needed a different solution so i keep searching for a better solution.

Redirect pages are not a solution. Google search engine penalize redirects.

So, my final solution was this:

<?php
$contents = file_get_contents('http://www.typo3site.org/index.php?id=27');
echo $contents;
?>


i create this new page called pagename.php and saved it on the root of typo3.
It works really easy: gets the content on the destination page and display on the actual page.

If you, like me, have your typo3 in a subdir but you want to put your speaking pages on the root of the site, you need some more code on your script:

<?php
$contents = file_get_contents('http://www.typo3site.org/typo3subdir/index.php?id=27');

$contents=str_replace('href="index', 'href="typo3subdir/index',$contents);
$contents=str_replace('href="typo3', 'href="typo3subdir/typo3',$contents);
$contents=str_replace('href="fileadmin', 'href="typo3subdir/fileadmin',$contents);
$contents=str_replace('src="fileadmin', 'src="typo3subdir/fileadmin',$contents);
echo $contents;
?>


Next i will build a little php script to build automatically the pages i need, insert it on a sitemap and ping the sitemap from typo3 to index the new pages, but this is another post!

Here is a sample of the working thing:

http://www.felixweb.it/public/allevamenti_gatti_persiani.php