--- /dev/null
+<?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);
+}
+
+
+
+?>
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');
$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
<?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();
+}
<?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");
require_once('include/bbcode.php');
if($argc < 3)
- exit;
+ return;
$a->set_baseurl(get_config('system','url'));
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'];
intval($parent_id)
);
- if(! count($items))
- killme();
+ if(! count($items)){
+ return;
+ }
}
$r = q("SELECT `contact`.*, `user`.`nickname`, `user`.`sprvkey`, `user`.`spubkey`, `user`.`page-flags`
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();
+}
<?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;
$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();
+}
<?php
-
+require_once("boot.php");
function update_queue_time($id) {
logger('queue: requeue 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");
$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');
}
}
- killme();
+ return;
- // NOTREACHED
+}
+if (array_search(__file__,get_included_files())===0){
+ queue_run($argv,$argc);
+ killme();
+}
$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");
}
$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']);
// 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
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;
// 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
);
$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;
}
$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
$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 {
// 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");
}
}
}
$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");
}
}
$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");
}
}
$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);
$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");
}
}
}
$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;