]> git.mxchange.org Git - friendica.git/commitdiff
Merge branch 'fabrixxm-master'
authorFriendika <info@friendika.com>
Sat, 29 Jan 2011 02:50:20 +0000 (18:50 -0800)
committerFriendika <info@friendika.com>
Sat, 29 Jan 2011 02:50:20 +0000 (18:50 -0800)
Conflicts:
boot.php

16 files changed:
addon/poormancron/poormancron.php [new file with mode: 0644]
boot.php
include/directory.php
include/notifier.php
include/poller.php
include/queue.php
mod/dfrn_confirm.php
mod/dfrn_notify.php
mod/follow.php
mod/item.php
mod/like.php
mod/message.php
mod/photos.php
mod/profile_photo.php
mod/profiles.php
mod/settings.php

diff --git a/addon/poormancron/poormancron.php b/addon/poormancron/poormancron.php
new file mode 100644 (file)
index 0000000..c31d277
--- /dev/null
@@ -0,0 +1,48 @@
+<?php
+/**
+ * Poor Man Cron. Execute updates on pageviews
+ *
+ * Addon Name: poormancron
+ *
+ */
+
+function poormancron_install() {
+       register_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
+       register_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
+       logger("installed poormancron");
+}
+
+function poormancron_uninstall() {
+       unregister_hook('page_end', 'addon/poormancron/poormancron.php', 'poormancron_hook');
+       unregister_hook('proc_run', 'addon/poormancron/poormancron.php','poormancron_procrun');
+       logger("removed poormancron");
+}
+
+
+
+function poormancron_hook($a,&$b) {
+    $now = time();
+    $lastupdate = get_config('poormancron', 'lastupdate');
+
+    // 300 secs, 5 mins
+    if (!$lastupdate || ($now-$lastupdate)>300) {
+        set_config('poormancron','lastupdate', $now);
+        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
+        proc_run($php_path,"include/poller.php");
+    }
+}
+
+function poormancron_procrun($a, $argv) {
+       logger("poormancron procrun ".implode(", ",$argv));
+       array_shift($argv);
+       $argc = count($argv);
+       logger("poormancron procrun require_once ".basename($argv[0]));
+       require_once(basename($argv[0]));
+       $funcname=str_replace(".php", "", basename($argv[0]))."_run";
+  
+       $funcname($argv, $argc);
+}
+
+
+
+?>
index 3cc98cc9b6febe84034872b87d26d5da8d20c68a..223c9416d1c62d4e07dd78ee8d245efbd08d2dc7 100644 (file)
--- a/boot.php
+++ b/boot.php
@@ -1655,7 +1655,6 @@ function attribute_contains($attr,$s) {
 
 if(! function_exists('logger')) {
 function logger($msg,$level = 0) {
-
        $debugging = get_config('system','debugging');
        $loglevel  = intval(get_config('system','loglevel'));
        $logfile   = get_config('system','logfile');
@@ -2225,7 +2224,31 @@ function prepare_body($item) {
        $s = smilies(bbcode($item['body']));
 
        return $s;
+}}
 
+/**
+ * 
+ * Wrap calls to proc_close(proc_open()) and call hook
+ * so plugins can take part in process :)
+ * 
+ * args:
+ * $cmd program to run
+ *  next args are passed as $cmd command line
+ * 
+ * e.g.: proc_run("ls","-la","/tmp");
+ * 
+ * $cmd and string args are surrounded with ""
+ */
 
+if(! function_exists('run_proc')) {
+function proc_run($cmd){
+       $args = func_get_args();
+       call_hooks("proc_run", $args);
+       
+       foreach ($args as &$arg){
+               if(is_string($arg)) $arg='"'.$arg.'"';
+       }
+       $cmdline = implode($args," ");
+       proc_close(proc_open($cmdline." &",array(),$foo));
+}}
 
-}}
\ No newline at end of file
index 5f835dc4bf58dc036a4ebbc33a46cfb3585bca0b..2c9daa5ea6f3b025241a0a2d65f79bc734c417c1 100644 (file)
@@ -1,17 +1,22 @@
 <?php
-
-       require_once("boot.php");
-
-       $a = new App;
-
-       @include(".htconfig.php");
-       require_once("dba.php");
-       $db = new dba($db_host, $db_user, $db_pass, $db_data);
-               unset($db_host, $db_user, $db_pass, $db_data);
-
+require_once("boot.php");
+
+function directory_run($argv, $argc){
+  global $a, $db;
+
+  if(is_null($a)){
+    $a = new App;
+  }
+  
+  if(is_null($db)){
+    @include(".htconfig.php");
+    require_once("dba.php");
+    $db = new dba($db_host, $db_user, $db_pass, $db_data);
+    unset($db_host, $db_user, $db_pass, $db_data);
+  };
 
        if($argc != 2)
-               exit;
+               return;
 
        load_config('system');
 
        $dir = get_config('system','directory_submit_url');
 
        if(! strlen($dir))
-               exit;
+               return;
 
        fetch_url($dir . '?url=' . bin2hex($argv[1]));
 
-       exit;
+       return;
+}
 
+if (array_search(__file__,get_included_files())===0){
+  directory_run($argv,$argc);
+  killme();
+}
index 4efdad4ce4fd480b864932b7c7ee0f2f083ad35e..dd5d55ed0009414301e2931d03c250174421862c 100644 (file)
@@ -1,14 +1,19 @@
 <?php
-
-       require_once("boot.php");
-
-       $a = new App;
-
-       @include(".htconfig.php");
-       require_once("dba.php");
-       $db = new dba($db_host, $db_user, $db_pass, $db_data);
-               unset($db_host, $db_user, $db_pass, $db_data);
-
+require_once("boot.php");
+
+function notifier_run($argv, $argc){
+  global $a, $db;
+
+  if(is_null($a)){
+    $a = new App;
+  }
+  
+  if(is_null($db)){
+    @include(".htconfig.php");
+    require_once("dba.php");
+    $db = new dba($db_host, $db_user, $db_pass, $db_data);
+    unset($db_host, $db_user, $db_pass, $db_data);
+  };
 
        require_once("session.php");
        require_once("datetime.php");
@@ -16,7 +21,7 @@
        require_once('include/bbcode.php');
 
        if($argc < 3)
-               exit;
+               return;
 
        $a->set_baseurl(get_config('system','url'));
 
@@ -29,8 +34,9 @@
                case 'mail':
                default:
                        $item_id = intval($argv[2]);
-                       if(! $item_id)
-                               killme();
+                       if(! $item_id){
+                               return;
+                       }
                        break;
        }
 
                $message = q("SELECT * FROM `mail` WHERE `id` = %d LIMIT 1",
                                intval($item_id)
                );
-               if(! count($message))
-                       killme();
+               if(! count($message)){
+                       return;
+               }
                $uid = $message[0]['uid'];
                $recipients[] = $message[0]['contact-id'];
                $item = $message[0];
 
        }
        else {
-               // find ancestors
 
+               // find ancestors
                $r = q("SELECT `parent`, `uid`, `edited` FROM `item` WHERE `id` = %d LIMIT 1",
                        intval($item_id)
                );
-               if(! count($r))
-                       killme();
-
+               if(! count($r)){
+                       return;
+               }
+  
                $parent_id = $r[0]['parent'];
                $uid = $r[0]['uid'];
                $updated = $r[0]['edited'];
@@ -66,8 +74,9 @@
                        intval($parent_id)
                );
 
-               if(! count($items))
-                       killme();
+               if(! count($items)){
+                       return;
+               }
        }
 
        $r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags` 
@@ -78,9 +87,9 @@
 
        if(count($r))
                $owner = $r[0];
-       else
-               killme();
-
+       else {
+               return;
+       }
        $hub = get_config('system','huburl');
 
        // If this is a public conversation, notify the feed hub
 
                $r = q("SELECT * FROM `contact` WHERE `id` IN ( $conversant_str ) AND `blocked` = 0 AND `pending` = 0");
 
-               if( ! count($r))
-                       killme();
+               if( ! count($r)){
+                       return;
+               }
 
                $contacts = $r;
        }
        $r = q("SELECT * FROM `contact` WHERE `id` IN ( %s ) AND `blocked` = 0 ",
                dbesc($recip_str)
        );
-       if(! count($r))
-               killme();
-
+       if(! count($r)){
+               return;
+       }
        // delivery loop
 
        require_once('include/salmon.php');
                }
        }
 
-       killme();
+       return;
+}
 
+if (array_search(__file__,get_included_files())===0){
+  echo "run!";
+  notifier_run($argv,$argc);
+  killme();
+}
index 024b9fbcd38c0c6144c8a4751224e7e0f286f003..1003b2f0816e144a9b4368386d55aadd888826f6 100644 (file)
@@ -1,14 +1,19 @@
 <?php
-
-
-       require_once('boot.php');
-
-       $a = new App;
-
-       @include('.htconfig.php');
-       require_once('dba.php');
-       $db = new dba($db_host, $db_user, $db_pass, $db_data);
-               unset($db_host, $db_user, $db_pass, $db_data);
+require_once("boot.php");
+
+function poller_run($argv, $argc){
+  global $a, $db;
+
+  if(is_null($a)){
+    $a = new App;
+  }
+  
+  if(is_null($db)){
+    @include(".htconfig.php");
+    require_once("dba.php");
+    $db = new dba($db_host, $db_user, $db_pass, $db_data);
+    unset($db_host, $db_user, $db_pass, $db_data);
+  };
 
        require_once('session.php');
        require_once('datetime.php');
        $a->set_baseurl(get_config('system','url'));
 
        logger('poller: start');
-
+       
        // run queue delivery process in the background
 
        $php_path = ((x($a->config,'php_path') && strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-       proc_close(proc_open("\"$php_path\" \"include/queue.php\" &", array(), $foo));
+       //proc_close(proc_open("\"$php_path\" \"include/queue.php\" &", array(), $foo));
+       proc_run($php_path,"include/queue.php");
 
 
        $hub_update = false;
@@ -46,8 +52,9 @@
                $sql_extra 
                AND `self` = 0 AND `blocked` = 0 AND `readonly` = 0 ORDER BY RAND()");
 
-       if(! count($contacts))
-               killme();
+       if(! count($contacts)){
+               return;
+       }
 
        foreach($contacts as $contact) {
 
                // loop - next contact
        }  
                
-       killme();
-
-
+       return;
+}
 
+if (array_search(__file__,get_included_files())===0){
+  poller_run($argv,$argc);
+  killme();
+}
index 96ddfa81bc143df6fb2def04ae0111502abbb22d..d4fc7dbd6277d0aa0cebd7fe198fa5a2efdc0d54 100644 (file)
@@ -1,5 +1,5 @@
 <?php
-
+require_once("boot.php");
 
 function update_queue_time($id) {
        logger('queue: requeue item ' . $id);
@@ -16,14 +16,19 @@ function remove_queue_item($id) {
        );
 }
 
-       require_once("boot.php");
-
-       $a = new App;
+function queue_run($argv, $argc){
+  global $a, $db;
 
-       @include(".htconfig.php");
-       require_once("dba.php");
-       $db = new dba($db_host, $db_user, $db_pass, $db_data);
-               unset($db_host, $db_user, $db_pass, $db_data);
+  if(is_null($a)){
+    $a = new App;
+  }
+  
+  if(is_null($db)){
+    @include(".htconfig.php");
+    require_once("dba.php");
+    $db = new dba($db_host, $db_user, $db_pass, $db_data);
+    unset($db_host, $db_user, $db_pass, $db_data);
+  };
 
 
        require_once("session.php");
@@ -50,9 +55,9 @@ function remove_queue_item($id) {
                
        $r = q("SELECT `id` FROM `queue` WHERE `last` < UTC_TIMESTAMP() - INTERVAL 15 MINUTE ");
 
-       if(! count($r))
-               killme();
-
+       if(! count($r)){
+               return;
+       }
        // delivery loop
 
        require_once('include/salmon.php');
@@ -118,7 +123,11 @@ function remove_queue_item($id) {
                }
        }
                
-       killme();
+       return;
 
-       // NOTREACHED
+}
 
+if (array_search(__file__,get_included_files())===0){
+  queue_run($argv,$argc);
+  killme();
+}
index 41e0771afa6f5b2fe3269517775cdb4004604011..24e8bf106a9a938dcf6e0ddf3352b2839fcbf38f 100644 (file)
@@ -438,8 +438,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
 
                                $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 
-                           proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"activity\" \"$i\" &",
-                       array(),$foo));
+                           //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"activity\" \"$i\" &", array(),$foo));
+                           proc_run($php_path,"include/notifier.php","activity","$i");
 
                        }
 
index f581702d8e23bcce60c3abd5ac327964a7a0c4c2..f904b06bc5e742740fa2df84782ca520e141c22e 100644 (file)
@@ -304,9 +304,9 @@ function dfrn_notify_post(&$a) {
 
                                        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 
-                                       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"comment-import\" \"$posted_id\" &", 
-                                               array(),$foo));
-
+                                       //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"comment-import\" \"$posted_id\" &", array(),$foo));
+                                       proc_run($php_path,"include/notifier.php","comment-import","$posted_id");
+                                       
                                        if((! $is_like) && ($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {
                                                require_once('bbcode.php');
                                                $from = stripslashes($datarray['author-name']);
index b4e50fa451c9f9df4e2785ef9a525e0d23ccf20d..a90ae3f5127b7239994520655ed22d647b3b614f 100644 (file)
@@ -208,8 +208,8 @@ function follow_post(&$a) {
        // pull feed and consume it, which should subscribe to the hub.
 
        $php_path = ((x($a->config,'php_path') && strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-       proc_close(proc_open("\"$php_path\" \"include/poller.php\" \"$contact_id\" &", array(), $foo));
-
+       //proc_close(proc_open("\"$php_path\" \"include/poller.php\" \"$contact_id\" &", array(), $foo));
+       proc_run($php_path,"include/poller.php","$contact_id");
 
        // create a follow slap
 
index feef7c95f8f5f3cea88e23579110e81b292bd130..11e79a7ab291fcf3655aa07290c6e2a91c85967f 100644 (file)
@@ -421,8 +421,7 @@ function item_post(&$a) {
 
        logger('mod_item: notifier invoked: ' . "\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" &");
 
-       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" &",
-               array(),$foo));
+  proc_run($php_path, "include/notifier.php", $notify_type, "$post_id");
 
        $datarray['id'] = $post_id;
 
@@ -520,8 +519,8 @@ function item_content(&$a) {
                        
                        // send the notification upstream/downstream as the case may be
 
-                       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" &",
-                               array(), $foo));
+                       //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" &", array(), $foo));
+                       proc_run($php_path,"include/notifier.php","drop","$drop_id");
 
                        goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
                        return; //NOTREACHED
index 7b20975781452166f942c333b65abf9b28f520ea..c78c1f030ca71d364d9e732f9ad0f28e1983d64d 100644 (file)
@@ -102,8 +102,8 @@ function like_content(&$a) {
                );
 
                $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-               proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &",
-                       array(),$foo));
+               //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &", array(),$foo));
+               proc_run($php_path,"include/notifier.php","like","$post_id");
                return;
        }
 
@@ -176,8 +176,8 @@ EOT;
 
        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 
-       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &",
-               array(),$foo));
+       //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"like\" \"$post_id\" &", array(),$foo));
+       proc_run($php_path,"include/notifier.php","like","$post_id");
 
        return; // NOTREACHED
 }
\ No newline at end of file
index 9cc2e2826cf0e5d6eae7d45a6609d2e52cefda77..7615f22bec727ff4ec22b63ba3e8d83296f56221 100644 (file)
@@ -72,8 +72,8 @@ function message_post(&$a) {
        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
        
        if($post_id) {
-               proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"mail\" \"$post_id\" &",
-                       array(),$foo));
+               //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"mail\" \"$post_id\" &", array(),$foo));
+               proc_run($php_path,"include/notifier.php","mail","$post_id");
                notice( t('Message sent.') . EOL );
        }
        else {
index 2a55fa5e9a81f7b03ceadf7c521f4b44be814abf..82060378e666d7fa7a54325ab2076a990a7f11e9 100644 (file)
@@ -187,9 +187,8 @@ foreach($_FILES AS $key => $val) {
                                        // send the notification upstream/downstream as the case may be
 
                                        if($rr['visible'])
-                                               proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
-                                                       array(),$foo));
-
+                                               //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",array(),$foo));
+                                               proc_run($php_path,"include/notifier.php","drop","$drop_id");
                                }
                        }
                }
@@ -236,8 +235,8 @@ foreach($_FILES AS $key => $val) {
                                $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 
                                if($i[0]['visible'])
-                                       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",
-                                               array(),$foo));
+                                       //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"drop\" \"$drop_id\" & ",       array(),$foo));
+                                       proc_run($php_path,"include/notifier.php","drop","$drop_id");
                        }
                }
 
@@ -462,8 +461,8 @@ foreach($_FILES AS $key => $val) {
 
                                        $item_id = item_store($arr);
                                        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-                                       proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",
-                                               array(),$foo));
+                                       //proc_close(proc_open("\"$php_path\" \"include/notifier.php\" \"tag\" \"$item_id\" & ",array(),$foo));
+                                       proc_run($php_path,"include/notifier.php","tag","$item_id");
                                }
 
                        }
index 64093b2de0fb4c062dbd3250f003963440e97761..8b72bfca06ee27104e4f450718dc2dd7dceaea44 100644 (file)
@@ -90,8 +90,8 @@ function profile_photo_post(&$a) {
                                $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
                                $url = $_SESSION['my_url'];
                                if($url && strlen(get_config('system','directory_submit_url')))
-                                       proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
-                                               array(),$foo));
+                                       //proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",array(),$foo));
+                                       proc_run($php_path,"include/directory.php","$url");
                        }
                        else
                                notice( t('Unable to process image') . EOL);
index 0bb476549eb89d93b624c404740b72aba13cd7b3..d74219501a0ce3501888994bf715e908320188af 100644 (file)
@@ -203,8 +203,8 @@ function profiles_post(&$a) {
                        $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
                        $url = $_SESSION['my_url'];
                        if($url && strlen(get_config('system','directory_submit_url')))
-                               proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
-                                       array(),$foo));
+                               //proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &", array(),$foo));
+                               proc_run($php_path,"include/directory.php","$url");
                }
        }
 }
index 32906d86e7c9017e9b31d91a081da06a94740f37..dbbac8bdeb3c9b14f2eededb6a74242c64889d29 100644 (file)
@@ -182,8 +182,8 @@ function settings_post(&$a) {
                $php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
                $url = $_SESSION['my_url'];
                if($url && strlen(get_config('system','directory_submit_url')))
-                       proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",
-                               array(),$foo));
+                       //proc_close(proc_open("\"$php_path\" \"include/directory.php\" \"$url\" &",array(),$foo));
+                       proc_run($php_path,"include/directory.php","$url");
        }
 
        $_SESSION['theme'] = $theme;