4 * Description: Allow to embed info from friendika into another site
6 * Author: Fabio Comuni <http://kirgroup.com/profile/fabrix/>
10 function widgets_install() {
11 register_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
12 register_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
13 logger("installed widgets");
15 function widgets_uninstall() {
16 unregister_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
17 unregister_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
21 function widgets_settings_post(){
23 if (isset($_POST['widgets-submit'])){
24 del_pconfig(local_user(), 'widgets', 'key');
29 function widgets_settings(&$a,&$o) {
34 $key = get_pconfig(local_user(), 'widgets', 'key' );
35 if ($key=='') { $key = mt_rand(); set_pconfig(local_user(), 'widgets', 'key', $key); }
37 $o .='<h3 class="settings-heading">Widgets</h3>';
41 <div id="settings-username-wrapper">
42 '. t('Widgets key: ') .'<strong>'.$key.'</strong>
44 <div id="settings-username-end"></div>
45 <div class="settings-submit-wrapper">
46 <input type="submit" value="'.t('Generate new key').'" class="settings-submit" name="widgets-submit">
50 $o.='<h4>Widgets:</h4>';
52 $d = dir(dirname(__file__));
53 while(false !== ($f = $d->read())) {
54 if(substr($f,0,7)=="widget_") {
55 preg_match("|widget_([^.]+).php|", $f, $m);
58 $o.='<li><a href="'.$a->get_baseurl().'/widgets/'.$w.'/?k='.$key.'&p=1">'. call_user_func($w."_widget_name") .'</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"){
109 /*if (!local_user()){
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 $o .= call_user_func($a->argv[1].'_widget_content',$a, $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>';
126 $o .= "<h4>".call_user_func($a->argv[1].'_widget_name')."</h4>";
127 $o .= call_user_func($a->argv[1].'_widget_help');
128 $o .= "<br style='clear:left'/><br/>";
131 header("content-type: application/x-javascript");
137 $script = file_get_contents(dirname(__file__)."/widgets.js");
138 $o .= replace_macros($script, array(
139 '$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
140 '$key' => $conf['key'],
141 '$widget_id' => 'f9k_'.$a->argv[1]."_".time(),
142 '$loader' => $a->get_baseurl()."/images/rotator.gif",
143 '$args' => (isset($_GET['a'])?$_GET['a']:''),
147 if (isset($_GET['p'])) {
148 $jsargs = implode("</em>,<em>", call_user_func($a->argv[1].'_widget_args'));
149 if ($jsargs!='') $jsargs = "&a=<em>".$jsargs."</em>";
152 <br style='clear:left'/><br/>
153 <h4>Copy and paste this code</h4>
156 .htmlspecialchars('<script src="'.$a->get_baseurl().'/widgets/'.$a->argv[1].'?k='.$conf['key'])
158 .htmlspecialchars('"></script>')