Nieuws koppelen aan Twitter via UDT en Events [update]
Posted: Wed Jun 23, 2010 11:17 am
----------
Content management as it is meant to be
https://forum.cmsmadesimple.org/
Ronny[10:17] svn: twitter - . (rev: 17) totophe: OAuth final implementation
Ik las dat hier al meer over is geschreven en er nog geen oplossing voor is gevonden.Module is not properly cleaning input params
Code: Select all
/*******************************************************
* 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.
[s]! 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.[/s]
==
update: 16 Dec 2011
==
- This UDT is now compatible with cmsms 1.10
- Works with and without pretty urls bit.ly problem seems solved
- Added the ability to shortenurl's
- Added support for the news_url field, if you use these it's best to turnshortenurl's off
config:
- specify: $detailpage (page_id) of the cgblog detail view.
- specify: $shortenurl (true|false) will use the bit.ly url shortner or not.
*/
/*******************************************************
* globals/objects
*******************************************************/
$modops = cmsms()->GetModuleOperations();
$twitter = $modops->get_module_instance('Twitter');
$cgblog = $modops->get_module_instance('CGBlog');
/*******************************************************
* config
*******************************************************/
/* debug (bool) */
$debug = false;
/* custom (string) */
$detailpage = '15';
/* shortenurl (bool) */
$shortenurl = false;
/*******************************************************
* variables
*******************************************************/
/* CGBlog article related (string) */
$cgblog_id = $params['cgblog_id'];
$title = $params['title'];
/* added to link (array) */
$link['articleid'] = $params['cgblog_id'];
/*******************************************************
* program
*******************************************************/
$aliased_title = munge_string_to_url($title);
$cgblog_url = fetch_cgblog_url($cgblog_id);
if ($cgblog_url != '') {
$prettyurl = $cgblog_url;
} else {
$prettyurl = 'logboek/' . $cgblog_id.'/'.$detailpage."/$aliased_title";
}
$link = $cgblog->CreateLink($cgblog_id, 'detail', $detailpage, '', $link,'', true, false, '', true, $prettyurl);
if ($shortenurl) {
$shortlink = $twitter->shortenUrls($link);
$message = $title. ' '. $shortlink;
} else {
$message = $title. ' '. $link;
}
if ($debug) {
print "<pre>twitter: $message status: $params[status] link: $link title: $title prettyurl: $prettyurl \n</pre>";
} else {
if ($params[status] == 'published') {
$twitter->updateStatus($message, false);
}
}
/*******************************************************
* subroutines
*******************************************************/
/**
* fetch the $cgblog_url by $cgblog_id
*
* @param string $cgblog_id
* @return string $cgblog_url
*
*/
function fetch_cgblog_url($cgblog_id) {
$db = cmsms()->GetDb();
$query = "SELECT url
FROM ". cms_db_prefix(). "module_cgblog
WHERE cgblog_id = ?";
$cgblog_url = $db->GetOne($query, array($cgblog_id));
return $cgblog_url;
}