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>
59 <li><a href="'.$a->get_baseurl().'/widgets/like/?p=1&k='.$key.'">Likes count</a></li>
66 function widgets_module() {
70 function _abs_url($s){
72 return preg_replace("|href=(['\"])([^h][^t][^t][^p])|", "href=\$1".$a->get_baseurl()."/\$2", $s);
76 function widgets_content(&$a) {
78 if (!isset($_GET['k'])) {
79 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
83 $r = q("SELECT * FROM pconfig WHERE uid IN (SELECT uid FROM pconfig WHERE v='%s')AND cat='widgets'",
87 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
91 $conf['uid'] = $r[0]['uid'];
92 foreach($r as $e) { $conf[$e['k']]=$e['v']; }
96 $widgetfile =dirname(__file__)."/widget_".$a->argv[1].".php";
97 if (file_exists($widgetfile)){
98 require_once($widgetfile);
100 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
107 //echo "<pre>"; var_dump($a->argv); die();
108 if ($a->argv[2]=="cb"){
110 if (!isset($_GET['s']))
111 {header('HTTP/1.0 400 Bad Request'); killme();}
113 if (substr($_GET['s'],0,strlen($conf['site'])) !== $conf['site'])
114 {header('HTTP/1.0 400 Bad Request'); killme();}
116 widget_content($a, $o, $conf);
121 if (isset($_GET['p']) && local_user()==$conf['uid'] ) {
122 $o .= "<style>.f9k_widget { float: left;border:1px solid black; }</style>";
123 $o .= "<h1>Preview Widget</h1>";
124 $o .= '<a href="'.$a->get_baseurl().'/settings/addon">'. t("Plugin Settings") .'</a>';
125 $o .= "<br style='clear:left'/><br/>";
126 widget_help($a, $o, $conf);
127 $o .= "<br style='clear:left'/><br/>";
130 header("content-type: application/x-javascript");
136 $script = file_get_contents(dirname(__file__)."/widgets.js");
137 $o .= replace_macros($script, array(
138 '$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
139 '$key' => $conf['key'],
140 '$widget_id' => 'f9k_'.$a->argv[1]."_".time(),
141 '$loader' => $a->get_baseurl()."/images/rotator.gif",
145 if (isset($_GET['p'])) {
146 $jsargs = implode("</em>,<em>", widget_args());
147 if ($jsargs!='') $jsargs = "&a=<em>".$jsargs."</em>";
150 <br style='clear:left'/><br/>
151 <h4>Copy and paste this code</h4>
154 .htmlspecialchars('<script src="'.$a->get_baseurl().'/widgets/'.$a->argv[1].'?k='.$conf['key'])
156 .htmlspecialchars('"></script>')