1<?php 2// (c) Copyright by authors of the Tiki Wiki CMS Groupware Project 3// 4// All Rights Reserved. See copyright.txt for details and a complete list of authors. 5// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details. 6// $Id$ 7 8//this script may only be included - so its better to die if called directly. 9if (strpos($_SERVER["SCRIPT_NAME"], basename(__FILE__)) !== false) { 10 header("location: index.php"); 11 exit; 12} 13 14// Module special params: 15// - user: Tiki username to show Twitter timeline of 16 17/** 18 * @return array 19 */ 20function module_twitter_info() 21{ 22 return [ 23 'name' => tra('Tweets'), 24 'description' => tra('Shows the tweets from the Twitter timeline of a user'), 25 'params' => [ 26 'user' => [ 27 'name' => 'user', 28 'description' => tra('Tiki user to show Twitter timeline of.'), 29 'required' => true 30 ], 31 'timelinetype' => [ 32 'name' => 'Timeline type', 33 'description' => tra('Show public|friends timeline. '), 34 'default' => 'public', 35 ], 36 'search' => [ 37 'name' => 'search', 38 'description' => tra('Search string.'), 39 'default' => 'tikiwiki', 40 ], 41 'showuser' => [ 42 'name' => 'showuser', 43 'description' => tra('Show username in timeline. y|n'), 44 'default' => 'n', 45 ], 46 ], 47 'common_params' => ['nonums', 'rows'], 48 ]; 49} 50 51/** 52 * @param $mod_reference 53 * @param $module_params 54 */ 55function module_twitter($mod_reference, $module_params) 56{ 57 global $prefs; 58 global $socialnetworkslib; 59 require_once('lib/socialnetworkslib.php'); 60 $smarty = TikiLib::lib('smarty'); 61 $tikilib = TikiLib::lib('tiki'); 62 63 if (! empty($module_params['user'])) { 64 $user = $module_params['user']; 65 66 $token = $tikilib->get_user_preference($user, 'twitter_token', ''); 67 $smarty->assign('twitter', ($token != '')); 68 69 $response = $socialnetworkslib->getTwitterTimeline($user, $mod_reference['params']['timelinetype'], $module_params['search']); 70 if ($response == -1) { 71 $timeline[0]['text'] = tra('user not registered with twitter') . ": $user"; 72 } 73 74 $module_params['timelinetype'] == 'search' ? $response = $response->statuses : true; 75 for ($i = 0, $count_response_status = count($response); $i < $count_response_status; $i++) { 76 $timeline[$i]['text'] = $response[$i]->text; 77 $timeline[$i]['id'] = $response[$i]->id; 78 $timeline[$i]['created_at'] = $response[$i]->created_at; 79 $timeline[$i]['screen_name'] = $response[$i]->user->screen_name; 80 } 81 } else { 82 $i = 0; 83 $timeline[$i]['text'] = tra('No username given'); 84 $timeline[$i]['created_at'] = ''; 85 $timeline[$i]['screen_name'] = ''; 86 } 87 88 $timeline = array_splice($timeline, 0, $mod_reference['rows'] ? $mod_reference['rows'] : 10); 89 $smarty->assign('timeline', $timeline); 90} 91