CMSMS Twitter UDT
CMS Made Simple heeft een Twitter module welke via een gebruikers gedefininieerde tag (UDT) te koppelen is aan de News module. In deze blog vindt je een implementatie voorbeeld.
Onderstaande voorbeeld werkt alleen wanneer je pretty url's, mod_rewrite werkend hebt op je website.
Installeer en configureer de Twitter module:
Installeer:
Uitbreidingen -> Module Manager -> Beschikbare Modules -> [t]
Twitter: Downloaden & Installeren
Configureer:
Inhoud -> Twitter -> [Options]
Maak een Gebruikergedefinieerde tags (UDT)
Uitbreidingen -> Gebruikergedefinieerde tags
Tag toevoegen
Naam: news_twitter_update_status
/*********************************************************************************
* about
*********************************************************************************/
/*
This UDT can be used to automatically post a Twitter message when a news article is added.
The functionality is based on the Twitter and News module.
- First you need to install and setup the News and Twitter module.
- After you need to create a UDT with this code, for example you can call it: 'news_twitter_update_status'
- At last you need to connect this UDT to the 'NewsArticleAdded' event.
This can be done via Extensions -> Event Manager.
! Currently this UDT only works when pretty urls are enabled.
It seems that the bit.ly url shortner ($twitter->shortenUrls($link)) has some problems with unfriendly urls.
Querystring parameters &var=1 are converted to &=1 which will break the link.
*/
/*********************************************************************************
* globals / objects
*********************************************************************************/
global $gCms;
$twitter = $gCms->modules['Twitter']['object'];
$news = $gCms->modules['News']['object'];
$root_url = $gCms->config['root_url'];
$debug = '0';
/*********************************************************************************
* variables
*********************************************************************************/
/* custom (string) */
$detailpage = '15';
/* news article related (string) */
$news_id = $params['news_id'];
$title = $params['title'];
/* added to link (array) */
$link['articleid'] = $params['news_id'];
/*********************************************************************************
* program
*********************************************************************************/
$aliased_title = munge_string_to_url($title);
$prettyurl = 'news/' . $news_id.'/'.$detailpage."/$aliased_title";
$prettyfullurl = $root_url . '/'. $prettyurl;
/* shorten URL does not work that well when pretty links are not enabled */
if ($debug) {
$link = $news->CreateLink($news_id, 'detail', $detailpage, '', $link,'', true, false, '', true, $prettyurl);
$shortlink = $twitter->shortenUrls($link);
//$message = $title.' '. $shortlink;
print "<pre>link: $link / shortlink: $shortlink \n</pre>";
}
$message = $title. ' '. $prettyfullurl;
if ($debug) {
print "<pre>twitter: $message status: $params[status] \n</pre>";
} else {
if ($params[status] == 'published') {
$twitter->updateStatus($message, false);
}
}
Koppel NewsArticleAdded gebeurtenis aan news_twitter_update_status tag
Uitbreidingen -> Gebeurtenissen beheer -> (Gebeurtenis) NewsArticleAdded [click]
Selecteer: news_twitter_update_status [Toevoegen]