]> git.mxchange.org Git - friendica-addons.git/commitdiff
Fix widgets crosssite ajax, make like widget works
authorFabio Comuni <fabrix.xm@gmail.com>
Tue, 18 Oct 2011 15:18:58 +0000 (17:18 +0200)
committerFabio Comuni <fabrix.xm@gmail.com>
Tue, 18 Oct 2011 15:18:58 +0000 (17:18 +0200)
widgets/widget_friends.php
widgets/widget_like.php
widgets/widget_like.tpl [new file with mode: 0644]
widgets/widgets.js
widgets/widgets.php

index 2286f68cad867f38665bd5f6010e3c1b68026eaa..fc7d7aa9846418c012b43d46251e3ed0ee9ea6ee 100644 (file)
@@ -23,8 +23,13 @@ function friends_widget_content(&$a, $conf){
 
        $o = "";
        $o .= "<style>
+               .f9k_widget {font-size: 0.8em;}
+               .f9k_widget #contact-block { overflow: hidden; height: auto; }
+               .f9k_widget .contact-block-h4 { float: left; margin: 0px; }
+               .f9k_widget .allcontact-link { float: right; margin: 0px; }
+               .f9k_widget .contact-block-content { clear:both; }
                .f9k_widget .contact-block-div { display: block !important; float: left!important; width: 50px!important; height: 50px!important; margin: 2px!important;}
-               .f9k_widget #contact-block-end { clear: left; }
+               
        </style>";
        $o .= _abs_url(contact_block());
        $o .= "<a href='".$a->get_baseurl().'/profile/'.$a->profile['nickname']."'>". t('Connect on Friendika!') ."</a>";
index 6927d43241390a35e064b20e987839884ddeedcf..b60d2d94d9ed483c8c1e509bc96828ace2db3b3f 100644 (file)
@@ -14,9 +14,49 @@ function like_widget_args(){
 function like_widget_content(&$a, $conf){
        $args = explode(",",$_GET['a']);
        
-       if ($args[0]!=""){
-               return " #TODO like/dislike count for item with <em>" .$args[0]. "</em> # ";
-       } else {
-               return " #TODO# ";
-       }
+       
+       $baseq="SELECT COUNT(`item`.`id`) as `c`, `p`.`id`
+                                       FROM `item`, 
+                                               (SELECT `i`.`id` FROM `item` as `i` WHERE 
+                                                       `i`.`visible` = 1 AND `i`.`deleted` = 0
+                                                       AND (( `i`.`wall` = 1 AND `i`.`allow_cid` = ''  
+                                                                       AND `i`.`allow_gid` = '' 
+                                                                       AND `i`.`deny_cid`  = '' 
+                                                                       AND `i`.`deny_gid`  = '' ) 
+                                                                 OR `i`.`uid` = %d )
+                                                       AND `i`.`body` LIKE '%%%s%%' LIMIT 1) as `p`
+                                       WHERE `item`.`parent` = `p`.`id` ";
+       
+       // count likes
+       $r = q( $baseq . "AND `item`.`verb` = 'http://activitystrea.ms/schema/1.0/like'",
+                       intval($conf['uid']),
+                       dbesc($args[0])
+       );
+       $likes = $r[0]['c'];
+       $iid = $r[0]['id'];
+       
+       // count dislikes
+       $r = q( $baseq . "AND `item`.`verb` = 'http://purl.org/macgirvin/dfrn/1.0/dislike'",
+                       intval($conf['uid']),
+                       dbesc($args[0])
+       );
+       $dislikes = $r[0]['c'];
+       
+       
+       require_once("include/conversation.php");
+       
+       $o = "";
+       
+       $t = file_get_contents( dirname(__file__). "/widget_like.tpl" );
+       $o .= replace_macros($t, array(
+               '$like'         => $likes,
+               '$strlike'      => sprintf( tt("%d person likes this", "%d people like this", $likes), $likes),
+               
+               '$dislike'      => $dislikes,
+               '$strdislike'=> sprintf( tt("%d person doesn't like this", "%d people don't like this", $dislikes), $dislikes),
+               
+               '$baseurl' => $a->get_baseurl(),
+       ));
+               
+       return $o;
 }
diff --git a/widgets/widget_like.tpl b/widgets/widget_like.tpl
new file mode 100644 (file)
index 0000000..e43e7a5
--- /dev/null
@@ -0,0 +1,2 @@
+<span class='f9k_like' title="$strlike">$like <img src="$baseurl/images/like.gif" alt="like"/></span> 
+<span class='f9k_dislike' title="$strdislike">$dislike <img src="$baseurl/images/dislike.gif" alt="dislike"/></span>
index 45d36c4d7d184aa120ea6e001a3ec59856e45bfc..e6382d711d8ab403346fb16eb1ae908c3e7c40ed 100644 (file)
@@ -22,11 +22,13 @@ var f9a_widget_$widget_id = {
        dorequest : function(args, cb) {
                if (args===null) args = new Array();
                args['k']=this.key;
-               args['s']=window.location;
+               args['s']=window.location.href;
                args['a']=this.argstr;
                var urlencodedargs = new Array();
-               for(k in args){ urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) ); }
-       
+               for(k in args){ 
+                       if (typeof args[k] != 'function')
+                               urlencodedargs.push( encodeURIComponent(k)+"="+encodeURIComponent(args[k]) );
+                }
                var url = this.entrypoint + "?"+ urlencodedargs.join("&");
 
                this.xmlhttp.open("GET", url  ,true);
index 13c4f93bb255ec3cde2b9b93180db200bd682650..cedaea34b1ca7167d9a99ca00bfcb22e6cce3be2 100644 (file)
@@ -40,8 +40,10 @@ function widgets_settings(&$a,&$o) {
                 if(substr($f,0,7)=="widget_") {
                         preg_match("|widget_([^.]+).php|", $f, $m);
                         $w=$m[1];
-                        require_once($f);
-                        $widgets[] = array($w, call_user_func($w."_widget_name"));
+                        if ($w!=""){
+                               require_once($f);
+                               $widgets[] = array($w, call_user_func($w."_widget_name"));
+                       }
 
                 }
        }
@@ -104,13 +106,7 @@ function widgets_content(&$a) {
 
        //echo "<pre>"; var_dump($a->argv); die();
        if ($a->argv[2]=="cb"){
-               /*if (!local_user()){
-                       if (!isset($_GET['s']))
-                               {header('HTTP/1.0 400 Bad Request'); killme();}
-                       
-                       if (substr($_GET['s'],0,strlen($conf['site'])) !== $conf['site'])
-                               {header('HTTP/1.0 400 Bad Request'); killme();}
-               } */
+               header('Access-Control-Allow-Origin: *');
                $o .= call_user_func($a->argv[1].'_widget_content',$a, $conf);
                
        } else {
@@ -136,14 +132,15 @@ function widgets_content(&$a) {
                $o .= replace_macros($script, array(
                        '$entrypoint' => $a->get_baseurl()."/widgets/".$a->argv[1]."/cb/",
                        '$key' => $conf['key'],
-                       '$widget_id' => 'f9k_'.$a->argv[1]."_".time(),
+                       '$widget_id' => 'f9a_'.$a->argv[1]."_". ceil(microtime(true)*100),
                        '$loader' => $a->get_baseurl()."/images/rotator.gif",
                        '$args' => (isset($_GET['a'])?$_GET['a']:''),
                ));
 
        
                if (isset($_GET['p'])) {
-                       $jsargs = implode("</em>,<em>", call_user_func($a->argv[1].'_widget_args'));
+                       $wargs = call_user_func($a->argv[1].'_widget_args');
+                       $jsargs = implode("</em>,<em>", $wargs);
                        if ($jsargs!='') $jsargs = "&a=<em>".$jsargs."</em>";
                                
                        $o .= "</script>
@@ -155,6 +152,8 @@ function widgets_content(&$a) {
                        .$jsargs
                        .htmlspecialchars('"></script>')
                        ."</code>";
+
+                       
                        return $o;
                }