3 * widgets from friendika
5 * allow to embed info from friendika into another site
9 function widgets_install() {
10 register_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
11 register_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
12 logger("installed widgets");
14 function widgets_uninstall() {
15 unregister_hook('plugin_settings', 'addon/widgets/widgets.php', 'widgets_settings');
16 unregister_hook('plugin_settings_post', 'addon/widgets/widgets.php', 'widgets_settings_post');
20 function widgets_settings_post(){
22 if (isset($_POST['widgets-submit'])){
23 del_pconfig(local_user(), 'widgets', 'key');
28 function widgets_settings(&$a,&$o) {
33 $key = get_pconfig(local_user(), 'widgets', 'key' );
34 if ($key=='') { $key = mt_rand(); set_pconfig(local_user(), 'widgets', 'key', $key); }
36 $o .='<h3 class="settings-heading">Widgets</h3>';
40 <div id="settings-username-wrapper">
41 '. t('Widgets key: ') .'<strong>'.$key.'</strong>
43 <div id="settings-username-end"></div>
44 <div class="settings-submit-wrapper">
45 <input type="submit" value="'.t('Generate new key').'" class="settings-submit" name="widgets-submit">
49 $o.='<h4>Widgets:</h4>';
51 $d = dir(dirname(__file__));
52 while(false !== ($f = $d->read())) {
53 if(substr($f,0,7)=="widget_") {
54 preg_match("|widget_([^.]+).php|", $f, $m);
57 $o.='<li><a href="'.$a->get_baseurl().'/widgets/'.$w.'/?k='.$key.'&p=1">'. call_user_func($w."_widget_name") .'</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 $widgetfile =dirname(__file__)."/widget_".$a->argv[1].".php";
96 if (file_exists($widgetfile)){
97 require_once($widgetfile);
99 if($a->argv[2]=="cb"){header('HTTP/1.0 400 Bad Request'); killme();}
106 //echo "<pre>"; var_dump($a->argv); die();
107 if ($a->argv[2]=="cb"){
108 /*if (!local_user()){
109 if (!isset($_GET['s']))
110 {header('HTTP/1.0 400 Bad Request'); killme();}
112 if (substr($_GET['s'],0,strlen($conf['site'])) !== $conf['site'])
113 {header('HTTP/1.0 400 Bad Request'); killme();}
115 $o .= call_user_func($a->argv[1].'_widget_content',$a, $conf);
120 if (isset($_GET['p']) && local_user()==$conf['uid'] ) {
121 $o .= "<style>.f9k_widget { float: left;border:1px solid black; }</style>";
122 $o .= "<h1>Preview Widget</h1>";
123 $o .= '<a href="'.$a->get_baseurl().'/settings/addon">'. t("Plugin Settings") .'</a>';
125 $o .= "<h4>".call_user_func($a->argv[1].'_widget_name')."</h4>";
126 $o .= call_user_func($a->argv[1].'_widget_help');
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",
142 '$args' => (isset($_GET['a'])?$_GET['a']:''),
146 if (isset($_GET['p'])) {
147 $jsargs = implode("</em>,<em>", call_user_func($a->argv[1].'_widget_args'));
148 if ($jsargs!='') $jsargs = "&a=<em>".$jsargs."</em>";
151 <br style='clear:left'/><br/>
152 <h4>Copy and paste this code</h4>
155 .htmlspecialchars('<script src="'.$a->get_baseurl().'/widgets/'.$a->argv[1].'?k='.$conf['key'])
157 .htmlspecialchars('"></script>')