From 042c61ed6de1bbc993eefe47552028157f3e1e28 Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Fri, 13 Mar 2009 13:21:35 +0100 Subject: [PATCH 1/2] Piwik Analytics Plugin This is a rewrite of the Google Analytics Plugin to support Piwik. --- plugins/PiwikAnalyticsPlugin.php | 86 ++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 plugins/PiwikAnalyticsPlugin.php diff --git a/plugins/PiwikAnalyticsPlugin.php b/plugins/PiwikAnalyticsPlugin.php new file mode 100644 index 0000000000..458b577fa0 --- /dev/null +++ b/plugins/PiwikAnalyticsPlugin.php @@ -0,0 +1,86 @@ +. + * + * @category Plugin + * @package Laconica + * @author Evan Prodromou + * @copyright 2008 Control Yourself, Inc. + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + */ + +if (!defined('LACONICA')) { + exit(1); +} + +/** + * Plugin to use Piwik Analytics (based on the Google Analytics plugin by Evan) + * + * This plugin will spoot out the correct JavaScript spell to invoke Piwik Analytics on a page. + * + * To use this plugin please add the following three lines to your config.php +#Add Piwik Analytics +require_once('plugins/PiwikAnalyticsPlugin.php'); +$pa = new PiwikAnalyticsPlugin("example.com/piwik/","id"); + * + * exchange example.com/piwik/ with the url (without http:// or https:// !) to your + * piwik installation and make sure you don't forget the final / + * exchange id with the ID your laconica installation has in your Piwik analytics + * + * @category Plugin + * @package Laconica + * @author Tobias Diekershoff + * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License version 3.0 + * @link http://laconi.ca/ + * + * @see Event + */ + +class PiwikAnalyticsPlugin extends Plugin +{ + // the base of your Piwik installation + var $piwikroot = null; + // the Piwik Id of your laconica installation + var $piwikId = null; + + function __construct($root=null, $id=null) + { + $this->piwikroot = $root; + $this->piwikid = $id; + parent::__construct(); + } + + function onEndShowScripts($action) + { + $js1 = 'var pkBaseURL = (("https:" == document.location.protocol) ? "https://'. + $this->piwikroot.'" : "http://'.$this->piwikroot. + '"); document.write(unescape("%3Cscript src=\'" + pkBaseURL + "piwik.js\''. + ' type=\'text/javascript\'%3E%3C/script%3E"));'; + $js2 = 'piwik_action_name = ""; piwik_idsite = '.$this->piwikid. + '; piwik_url = pkBaseURL + "piwik.php"; piwik_log(piwik_action_name, piwik_idsite, piwik_url);'; + $action->elementStart('script', array('type' => 'text/javascript')); + $action->raw($js1); + $action->elementEnd('script'); + $action->elementStart('script', array('type' => 'text/javascript')); + $action->raw($js2); + $action->elementEnd('script'); + } +} \ No newline at end of file From 7196410bb0398c15fbab767a9b7cedc513e6520b Mon Sep 17 00:00:00 2001 From: Tobias Diekershoff Date: Sat, 18 Apr 2009 19:00:20 +0200 Subject: [PATCH 2/2] shortening links in notices from XMPP This patch enables shortening of links, that where send from XMPP. The problem was, that in util.php common_current_user() is not finding the user account from which is posted, so the service to shorten is not known, so no shortening at all... This patch cleans up the xmppdaemon a little bit and hard codes ur1.ca as shortening service _if_ the user is not set. Ugly but working. --- lib/util.php | 20 ++++++-------------- scripts/xmppdaemon.php | 17 +++++------------ 2 files changed, 11 insertions(+), 26 deletions(-) diff --git a/lib/util.php b/lib/util.php index 675ff51f01..ab5e99593e 100644 --- a/lib/util.php +++ b/lib/util.php @@ -519,11 +519,16 @@ function common_shorten_links($text) function common_shorten_link($url, $reverse = false) { + static $url_cache = array(); if ($reverse) return isset($url_cache[$url]) ? $url_cache[$url] : $url; $user = common_current_user(); - + if (!isset($user)) { + // common current user does not find a user when called from the XMPP daemon + // therefore we'll set one here fix, so that XMPP given URLs may be shortened + $user->urlshorteningservice = 'ur1.ca'; + } $curlh = curl_init(); curl_setopt($curlh, CURLOPT_CONNECTTIMEOUT, 20); // # seconds to wait curl_setopt($curlh, CURLOPT_USERAGENT, 'Laconica'); @@ -1321,16 +1326,3 @@ function common_compatible_license($from, $to) // XXX: better compatibility check needed here! return ($from == $to); } - -/** - * returns a quoted table name, if required according to config - */ -function common_database_tablename($tablename) -{ - - if(common_config('db','quote_identifiers')) { - $tablename = '"'. $tablename .'"'; - } - //table prefixes could be added here later - return $tablename; -} \ No newline at end of file diff --git a/scripts/xmppdaemon.php b/scripts/xmppdaemon.php index ef3f8c63d8..5711f715df 100755 --- a/scripts/xmppdaemon.php +++ b/scripts/xmppdaemon.php @@ -152,11 +152,6 @@ class XMPPDaemon extends Daemon $body = preg_replace('/d[\ ]*('. $to .')[\ ]*/', '', $pl['body']); $this->add_direct($user, $body, $to, $from); } else { - $len = mb_strlen($pl['body']); - if($len > 140) { - $this->from_site($from, 'Message too long - maximum is 140 characters, you sent ' . $len); - return; - } $this->add_notice($user, $pl); } @@ -255,15 +250,13 @@ class XMPPDaemon extends Daemon function add_notice(&$user, &$pl) { $body = trim($pl['body']); - $content_shortened = common_shorten_link($body); + $content_shortened = common_shorten_links($body); if (mb_strlen($content_shortened) > 140) { - $content = trim(mb_substr($body, 0, 140)); - $content_shortened = common_shorten_link($content); + $from = jabber_normalize_jid($pl['from']); + $this->from_site($from, "Message too long - maximum is 140 characters, you sent ".mb_strlen($content_shortened)); + return; } - else { - $content = $body; - } - $notice = Notice::saveNew($user->id, $content, 'xmpp'); + $notice = Notice::saveNew($user->id, $content_shortened, 'xmpp'); if (is_string($notice)) { $this->log(LOG_ERR, $notice); return;