18. 3. 2011  |  4390 ogledov  |   povratna povezava  |  0 komentarjev

Customizing T3blog

Number of Views

To keep the number of views as realistic as possible, we should exclude at least our indexing engine, e.g., Mnogosearch. We can do that with an extra TypoScript definition and a small change in the function checkRiseViewNumber() that can be found in

/ext/t3blog/pi1/widgets/blogList/class.singleFunctions.php.

Add the following code after the if statement that checkes if user is loggen in the BE and before the cookies are checked.

PHP 
  1. if (t3lib_div::cmpIPv4(t3lib_div::getIndpEnv(REMOTE_ADDR), $this->conf['ignoreIP_list'])) {
  2.   return $rise;
  3. }
  4.  
if (t3lib_div::cmpIPv4(t3lib_div::getIndpEnv(REMOTE_ADDR), $this->conf['ignoreIP_list'])) {
  return $rise;
}

Now, we can define a list of IP's that should be ignored in the setup of the T3blog:

plugin.tx_t3blog_pi1.blogList.ignoreIP_list = 127.0.0.1, 192.168.0.1

Next, we have to disable caching for the "Single View" of the blog post, otherwise only cliks that put the page into cache will be counted for.

TypoScript 
  1. [globalVar = GP:tx_t3blog_pi1|blogList|showUid > 0]
  2.   config.no_cache = 1
  3. [end]
[globalVar = GP:tx_t3blog_pi1|blogList|showUid > 0]
  config.no_cache = 1
[end]

Counting our readers has its price that shows in page loading times. If we don't mind that readers see "old" numbers in the list view, we could store entry page of our blog in cache.  What exactly "old" means depends on your cache configuration. To allow caching add following TypoScript.

TypoScript 
  1. plugin.tx_t3blog_pi1.blogList.listItem.5.40.10 = COA
plugin.tx_t3blog_pi1.blogList.listItem.5.40.10 = COA

Be aware, that now you should refresh your cache for Blog page when you update or add an entry! You can find how this can be done quite easy with your favorite browser on Wikipedia's Baypass your Cache article.

TypoScript 
  1. [globalVar = GP:tx_t3blog_pi1|blogList|showUid > 0]
  2.   config.no_cache = 1
  3. [end]
  4.  
  5. plugin.tx_t3blog_pi1.blogList {
  6.   requiredFields = commentauthor, commenttext, commentauthoremail, commenttitle, captcha
  7. }
[globalVar = GP:tx_t3blog_pi1|blogList|showUid > 0]
  config.no_cache = 1
[end]

plugin.tx_t3blog_pi1.blogList {
  requiredFields = commentauthor, commenttext, commentauthoremail, commenttitle, captcha
}

Comments

Checking syntax of the fields will return an error if you omit any of the following fields:

  • author,
  • title,
  • author e-mail,
  • author web site, and
  • commenttext.

This is hardcoded in PHP function validateCommentSubmission that can be found in

typo3conf/ext/t3blog/pi1/widgets/blogList/class.singleFunctions.php.

We did not want to bother our readers with their web site address, so we commented out the commentauthorwebsite check in the $testData. Additionally, you have to define that this field is not required. We use:

PHP 
  1. plugin.tx_t3blog_pi1.blogList {
  2.   requiredFields = commentauthor, commenttext, commentauthoremail, commenttitle, captcha
  3. } 
plugin.tx_t3blog_pi1.blogList {
  requiredFields = commentauthor, commenttext, commentauthoremail, commenttitle, captcha
} 

To submit a form in T3blog configuration where it does not generate the whole page, e.g., it is used as content element, you should disable caching during the submit with folowing TypoScript Setup:

TypoScript 
  1. [globalVar = GP:tx_t3blog_pi1|blogList|insert = 1]
  2.   config.no_cache = 1
  3. [end]
[globalVar = GP:tx_t3blog_pi1|blogList|insert = 1]
  config.no_cache = 1
[end]

Localization

At first we were planning to extend the t3blog with multilanguage support, but with a twist. Since it is unrealistic that we would write single blog post in more than one language, we were planning to provide articles in all languages at Slovenian pages. All technical posts would be in English languge, which is not a problem for most of the Slovenian visitors. English speaking visitor would get only English texts. After first version of the extention upgrade, which was based on post from zBlog, we noticed that this is probably unnecessary. Most of the elements can be translated without any changes in PHP code, which would limit our upgrade options and introduce some additional effort at the time of publication. So, we decided that English speaking visitors just won't follow links with titles in Slovenian :-) If you believe that this is problematic, do write a comment and tell us about it.

References:

  1. Localization for "titletag"
  2. Missing localang Text
  3. multi-language T3BLOG

Linking to selected posts

Linking to your posts from other content elements at your web page can be handled with some additional configuration of the linkhandler. We are using RTE editor tynimce and it's Typo3Link functionality, but linkhandler configuration should work with other editors, too. Please report your success in comments.

Add following setup in the page TS of the root page. In the provided example, 41 is the UID of the page with blog posts. If you have multiple blogs, you should configure linkhandler for every blog.

TypoScript 
  1. #RTE.default.tx_linkhandler is used for RTE linkbrowser
  2. RTE.default.linkhandler {
  3.   tx_t3blog_post {          
  4.     41 { 
  5.         #storage folder
  6.         parameter = 41            
  7.         select = uid,title as header,hidden
  8.         sorting = crdate desc
  9.       }
  10.   }        
  11.   tx_t3blog_cat {            
  12.     41 {                
  13.       #storage folder
  14.       parameter = 41                
  15.       select = uid,catname as header,hidden                
  16.       sorting = crdate desc            
  17.     }
  18.   }
  19. }
  20.  
  21. #mod.tx_linkhandler  is used for normal linkbrowser
  22. mod.tx_linkhandler {
  23.   tx_t3blog_post {
  24.     label=Blog-zapisi
  25.     listTables=tx_t3blog_post
  26.    onlyPids=41
  27.   }
  28.   tx_t3blog_cat {
  29.     label=Blog-kategorije
  30.     listTables=tx_t3blog_cat
  31.     onlyPids=41
  32.   }
  33. }
#RTE.default.tx_linkhandler is used for RTE linkbrowser
RTE.default.linkhandler {
  tx_t3blog_post {          
    41 { 
        #storage folder
        parameter = 41             
        select = uid,title as header,hidden
        sorting = crdate desc
      }
  }        
  tx_t3blog_cat {            
    41 {                
      #storage folder
      parameter = 41                
      select = uid,catname as header,hidden                
      sorting = crdate desc            
    }
  }
}

#mod.tx_linkhandler  is used for normal linkbrowser
mod.tx_linkhandler {
  tx_t3blog_post {
    label=Blog-zapisi
    listTables=tx_t3blog_post
   onlyPids=41
  }
  tx_t3blog_cat {
    label=Blog-kategorije
    listTables=tx_t3blog_cat
    onlyPids=41
  }
}

For linkgeneration in the FE add following TS code to the Setup field of blog template.

TypoScript 
  1. plugin.tx_linkhandler {
  2.   tx_t3blog_post {
  3.     forceLink = 0
  4.     parameter = 43
  5.     additionalParams = &tx_t3blog_pi1[blogList][showUidPerma]={field:uid}
  6.     additionalParams.insertData = 1
  7.     useCacheHash = 1
  8.   }
  9.   tx_t3blog_cat {
  10.     forceLink = 0
  11.     parameter = 43
  12.     additionalParams = &tx_t3blog_pi1[blogList][category]={field:uid}
  13.     additionalParams.insertData = 1
  14.     useCacheHash = 1
  15.   }
  16. }
plugin.tx_linkhandler {
  tx_t3blog_post {
    forceLink = 0
    parameter = 43
    additionalParams = &tx_t3blog_pi1[blogList][showUidPerma]={field:uid}
    additionalParams.insertData = 1 
    useCacheHash = 1
  }
  tx_t3blog_cat {
    forceLink = 0
    parameter = 43
    additionalParams = &tx_t3blog_pi1[blogList][category]={field:uid}
    additionalParams.insertData = 1 
    useCacheHash = 1
  }
}

Couple of examples:

Archive

To list only years that acctually have blog posts, small change in class.archive.php is neccessary. The added condition is market with comment.

PHP 
  1. /**
  2.  * Creates the content from collected post information through years.
  3.  *
  4.  * @return string
  5.  */
  6. protected function assembleContent() {
  7.         $content = '';
  8.         if (count($this->years) > 0) {
  9.                 foreach ($this->years as $year => $row) {       //wrap year li
  10.                         $dataCatLinkYear = array(
  11.                                 'text'          => $year,
  12.                                 'datefrom'      => $this->getMonthStart(1, $year),
  13.                                 'dateto'        => $this->getMonthEnd(12, $year),
  14.                                 'entries'       => $row['entries'],
  15.                                 'id'            => $year
  16.                         );
  17.                         $dataYearLi = array(
  18.                                 'class' => 'year',
  19.                                 'text'  => t3blog_div::getSingle($dataCatLinkYear, 'catLink', $this->conf) . $row['data']
  20.                         );
  21.                         /* Bostjan, 2011.04.12 */
  22.                         if ($dataCatLinkYear['entries']  > 0) {
  23.                                 $yearsInArchive .= t3blog_div::getSingle($dataYearLi, 'itemWrap', $this->conf);
  24.                         }
  25.                         /*** end ******************/
  26.                 }
  27.  
  28.                 $dataYearUl = array(
  29.                         'class' => 'archive',
  30.                         'text'  => $yearsInArchive
  31.                 );
  32.                 $content = t3blog_div::getSingle($dataYearUl, 'listWrap', $this->conf);
  33.                 $content = t3blog_div::getSingle(
  34.                         array(  
  35.                                 'categoryTree'  => $content,
  36.                                 'title' => $this->pi_getLL('title')
  37.                         ), 'globalWrap', $this->conf
  38.                 );
  39.         }
  40.         return $content;
  41. }
/**
 * Creates the content from collected post information through years.
 *
 * @return string
 */
protected function assembleContent() {
        $content = '';
        if (count($this->years) > 0) {
                foreach ($this->years as $year => $row) {       //wrap year li
                        $dataCatLinkYear = array(
                                'text'          => $year,
                                'datefrom'      => $this->getMonthStart(1, $year),
                                'dateto'        => $this->getMonthEnd(12, $year),
                                'entries'       => $row['entries'],
                                'id'            => $year
                        );
                        $dataYearLi = array(
                                'class' => 'year',
                                'text'  => t3blog_div::getSingle($dataCatLinkYear, 'catLink', $this->conf) . $row['data']
                        );
                        /* Bostjan, 2011.04.12 */
                        if ($dataCatLinkYear['entries']  > 0) {
                                $yearsInArchive .= t3blog_div::getSingle($dataYearLi, 'itemWrap', $this->conf);
                        }
                        /*** end ******************/
                }

                $dataYearUl = array(
                        'class' => 'archive',
                        'text'  => $yearsInArchive
                );
                $content = t3blog_div::getSingle($dataYearUl, 'listWrap', $this->conf);
                $content = t3blog_div::getSingle(
                        array(  
                                'categoryTree'  => $content,
                                'title' => $this->pi_getLL('title')
                        ), 'globalWrap', $this->conf
                );
        }
        return $content;
}

Na seznam prispevkov

« Marec 2011»
N P T S Č P S
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    

Zadnje objave

Najbolj brano

Arhiv

  • 2012(1)
    • Marec(1)
  • 2011(14)
    • Oktober(2)
    • September(2)
    • Junij(2)
    • Maj(2)
    • April(1)
    • Marec(3)
    • Februar(2)
  • 2004(3)
    • April(3)
  • 2003(1)
    • April(1)
  • 2002(1)
    • Februar(1)
  • 2001(1)
    • April(1)