3 * widgets from friendika
5 * allow to embed info from friendika into another site
9 function widgets_install() {
10 // we need some hooks, for the configuration and for sending tweets
11 register_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
12 register_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
14 logger("installed widgets");
17 function widgets_settings_post(){
19 if (isset($_POST['widgets-submit'])){
20 set_pconfig(local_user(), 'widgets', 'site', $_POST['widgets-site']);
21 set_pconfig(local_user(), 'widgets', 'key', $_POST['widgets-key']);
25 function widgets_settings(&$a,&$o) {
29 $key = get_pconfig(local_user(), 'widgets', 'key' );
30 $site = get_pconfig(local_user(), 'widgets', 'site' );
32 if ($key=='') $key = mt_rand();
35 <h3 class="settings-heading">Widgets</h3>
36 <div id="settings-username-wrapper">
37 <label for="widgets-site" id="settings-username-label">'.t('Remote site: ').'</label>
38 <input type="text" value="'.$site.'" id="settings-username" name="widgets-site">
40 <div id="settings-username-end"></div>
41 <div id="settings-username-wrapper">
42 <label for="widgets-key" id="settings-username-label">'.t('Widgets key: ').'</label>
43 <input type="hidden" value="'.$key.'" id="settings-username" name="widgets-key">
44 <strong>'.$key.'</strong>
46 <div id="settings-username-end"></div>
50 <div class="settings-submit-wrapper">
51 <input type="submit" value="'.t('Submit').'" class="settings-submit" name="widgets-submit">
55 if ($key!='' and $site!='') {
56 $o.='<h4>Widgets:</h4>
58 <li><a href="'.$a->get_baseurl().'/widgets/friends/?p=1&k='.$key.'">Friend list</a></li>
65 function widgets_module() {
69 function _abs_url($s){
71 return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->get_baseurl()."/\$2", $s);
75 function widgets_content(&$a) {
77 if (!isset($_GET['k'])) {
78 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
82 $r = q("SELECT * FROM pconfig WHERE uid IN (SELECT uid FROM pconfig WHERE v='%s')AND cat='widgets'",
86 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
90 $conf['uid'] = $r[0]['uid'];
91 foreach($r as $e) { $conf[$e['k']]=$e['v']; }
95 // echo "<pre>"; var_dump($a->argv); die();
96 if ($a->argv[2]=="cb"){
99 widget_friends_content($a, $o, $conf);
106 if (isset($_GET['p'])) {
107 $o .= "<style>.f9k_widget { float: left;border:1px solid black; }</style>";
108 $o .= "<h1>Preview Widget</h1>";
109 $o .= '<a href="'.$a->get_baseurl().'/settings/addon">'. t("Plugin Settings") .'</a>';
110 $o .= "<br style='clear:left'/><br/>";
113 header("content-type: application/x-javascript");
119 $script = file_get_contents(dirname(__file__)."/widgets.js");
120 $o .= replace_macros($script, array(
121 '$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
122 '$key' => $conf['key'],
123 '$widget_id' => 'f9k_'.$a->argv[1]."_".time(),
124 '$loader' => $a->get_baseurl()."/images/rotator.gif",
128 if (isset($_GET['p'])) {
130 <br style='clear:left'/><br/>
131 <h4>Copy and paste this code</h4>
134 .htmlspecialchars('<script src="'.$a->get_baseurl().'/widgets/'.$a->argv[1].'?k='.$conf['key'].'"></script>')
146 function widget_friends_content(&$a, &$o, $conf){
148 if (!isset($_GET['s']))
149 header('HTTP/1.0 400 Bad Request');
151 if (substr($_GET['s'],0,strlen($conf['site'])) !== $conf['site'])
152 header('HTTP/1.0 400 Bad Request');
154 $r = q("SELECT `profile`.`uid` AS `profile_uid`, `profile`.* , `user`.* FROM `profile`
155 LEFT JOIN `user` ON `profile`.`uid` = `user`.`uid`
156 WHERE `user`.`uid` = %s AND `profile`.`is-default` = 1 LIMIT 1",
160 if(!count($r)) return;
163 $o .= _abs_url(contact_block());
164 $o .= "<a href='".$a->get_baseurl().'/profile/'.$a->profile['nickname']."'>". t('Connect on Friendika!') ."</a>";