From 755c2245e8184ceee2ba3382e4f60143da31e6df Mon Sep 17 00:00:00 2001
From: Friendika <info@friendika.com>
Date: Wed, 23 Feb 2011 15:16:12 -0800
Subject: [PATCH] move php path setting inside proc_run

---
 addon/poormancron/poormancron.php |  3 +--
 boot.php                          |  3 +++
 include/poller.php                |  3 +--
 mod/contacts.php                  |  4 +---
 mod/dfrn_confirm.php              |  7 ++-----
 mod/dfrn_notify.php               |  4 +---
 mod/follow.php                    |  4 +---
 mod/item.php                      | 10 ++--------
 mod/like.php                      | 10 ++--------
 mod/message.php                   |  9 +--------
 mod/photos.php                    | 13 ++++---------
 mod/profile_photo.php             |  8 ++------
 mod/profiles.php                  |  4 +---
 mod/register.php                  |  3 +--
 mod/regmod.php                    |  3 +--
 mod/settings.php                  |  4 +---
 16 files changed, 25 insertions(+), 67 deletions(-)

diff --git a/addon/poormancron/poormancron.php b/addon/poormancron/poormancron.php
index c31d2772c8..830c10ddfe 100644
--- a/addon/poormancron/poormancron.php
+++ b/addon/poormancron/poormancron.php
@@ -27,8 +27,7 @@ function poormancron_hook($a,&$b) {
     // 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");
+        proc_run('php',"include/poller.php");
     }
 }
 
diff --git a/boot.php b/boot.php
index 530baa7b91..d9786edcd5 100644
--- a/boot.php
+++ b/boot.php
@@ -2434,6 +2434,9 @@ if(! function_exists('proc_run')) {
 function proc_run($cmd){
 	$args = func_get_args();
 	call_hooks("proc_run", $args);
+
+	if(count($args) && $args[0] === 'php')
+        $args[0] = ((x($a->config,'php_path')) && (strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 	
 	foreach ($args as $arg){
 		$arg = escapeshellarg($arg);
diff --git a/include/poller.php b/include/poller.php
index 66df080a9d..d54c88e053 100644
--- a/include/poller.php
+++ b/include/poller.php
@@ -27,8 +27,7 @@ function poller_run($argv, $argc){
 	
 	// 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_run($php_path,"include/queue.php");
+	proc_run('php',"include/queue.php");
 	
 	// clear old cache
 	q("DELETE FROM `cache` WHERE `updated`<'%s'",
diff --git a/mod/contacts.php b/mod/contacts.php
index 36f42f8e59..8e069b2bd6 100644
--- a/mod/contacts.php
+++ b/mod/contacts.php
@@ -124,9 +124,7 @@ function contacts_content(&$a) {
 		if($cmd === 'update') {
 
 			// 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_run($php_path,"include/poller.php","$contact_id");
+			proc_run('php',"include/poller.php","$contact_id");
 			goaway($a->get_baseurl() . '/contacts/' . $contact_id);
 			// NOTREACHED
 		}
diff --git a/mod/dfrn_confirm.php b/mod/dfrn_confirm.php
index 24e8bf106a..1b42c13b8a 100644
--- a/mod/dfrn_confirm.php
+++ b/mod/dfrn_confirm.php
@@ -435,11 +435,8 @@ function dfrn_confirm_post(&$a,$handsfree = null) {
 				$arr['last-child'] = 1;
 
 				$i = item_store($arr);
-
-				$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_run($php_path,"include/notifier.php","activity","$i");
+				if($i)
+			    	proc_run('php',"include/notifier.php","activity","$i");
 
 			}
 
diff --git a/mod/dfrn_notify.php b/mod/dfrn_notify.php
index cd7b0cff01..0102727392 100644
--- a/mod/dfrn_notify.php
+++ b/mod/dfrn_notify.php
@@ -369,9 +369,7 @@ function dfrn_notify_post(&$a) {
 
 					if($posted_id && $parent) {
 				
-						$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-
-						proc_run($php_path,"include/notifier.php","comment-import","$posted_id");
+						proc_run('php',"include/notifier.php","comment-import","$posted_id");
 					
 						if((! $is_like) && ($importer['notify-flags'] & NOTIFY_COMMENT) && (! $importer['self'])) {
 							require_once('bbcode.php');
diff --git a/mod/follow.php b/mod/follow.php
index 28441eae8f..f3bd84669f 100644
--- a/mod/follow.php
+++ b/mod/follow.php
@@ -253,9 +253,7 @@ 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_run($php_path,"include/poller.php","$contact_id");
+	proc_run('php',"include/poller.php","$contact_id");
 
 	// create a follow slap
 
diff --git a/mod/item.php b/mod/item.php
index 8c6b181c0d..c2487435e4 100644
--- a/mod/item.php
+++ b/mod/item.php
@@ -460,11 +460,7 @@ function item_post(&$a) {
 		// NOTREACHED
 	}
 
-	$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
-
-	logger('mod_item: notifier invoked: ' . "\"$php_path\" \"include/notifier.php\" \"$notify_type\" \"$post_id\" &");
-
-	proc_run($php_path, "include/notifier.php", $notify_type, "$post_id");
+	proc_run('php', "include/notifier.php", $notify_type, "$post_id");
 
 	$datarray['id'] = $post_id;
 
@@ -595,12 +591,10 @@ function item_content(&$a) {
 				}	
 			}
 			$drop_id = intval($item['id']);
-			$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 			
 			// 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_run($php_path,"include/notifier.php","drop","$drop_id");
+			proc_run('php',"include/notifier.php","drop","$drop_id");
 
 			goaway($a->get_baseurl() . '/' . $_SESSION['return_url']);
 			//NOTREACHED
diff --git a/mod/like.php b/mod/like.php
index c78c1f030c..3a8ca4b7d3 100644
--- a/mod/like.php
+++ b/mod/like.php
@@ -101,9 +101,7 @@ function like_content(&$a) {
 			intval($r[0]['id'])
 		);
 
-		$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_run($php_path,"include/notifier.php","like","$post_id");
+		proc_run('php',"include/notifier.php","like","$post_id");
 		return;
 	}
 
@@ -173,11 +171,7 @@ 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_run($php_path,"include/notifier.php","like","$post_id");
+	proc_run('php',"include/notifier.php","like","$post_id");
 
 	return; // NOTREACHED
 }
\ No newline at end of file
diff --git a/mod/message.php b/mod/message.php
index ef3be2c5e9..466b0befa8 100644
--- a/mod/message.php
+++ b/mod/message.php
@@ -96,16 +96,9 @@ 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_run($php_path,"include/notifier.php","mail","$post_id");
+		proc_run('php',"include/notifier.php","mail","$post_id");
 		notice( t('Message sent.') . EOL );
 	}
 	else {
diff --git a/mod/photos.php b/mod/photos.php
index d4835ba5ea..bd48cfc9f9 100644
--- a/mod/photos.php
+++ b/mod/photos.php
@@ -182,13 +182,11 @@ foreach($_FILES AS $key => $val) {
 					);
 
 					$drop_id = intval($rr['id']);
-					$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 
 					// 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_run($php_path,"include/notifier.php","drop","$drop_id");
+						proc_run('php',"include/notifier.php","drop","$drop_id");
 				}
 			}
 		}
@@ -232,11 +230,9 @@ foreach($_FILES AS $key => $val) {
 
 				$url = $a->get_baseurl();
 				$drop_id = intval($i[0]['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_run($php_path,"include/notifier.php","drop","$drop_id");
+					proc_run('php',"include/notifier.php","drop","$drop_id");
 			}
 		}
 
@@ -474,9 +470,8 @@ foreach($_FILES AS $key => $val) {
 					$arr['target'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $a->get_baseurl() . '/photos/' . $owner_record['nickname'] . '/image/' . $p[0]['resource-id'] . '" />' . "\n" . '<link rel="preview" type="image/jpeg" href="' . $a->get_baseurl() . "/photo/" . $p[0]['resource-id'] . '-' . $best . '.jpg' . '" />') . '</link></target>';
 
 					$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_run($php_path,"include/notifier.php","tag","$item_id");
+					if($item_id)
+						proc_run('php',"include/notifier.php","tag","$item_id");
 				}
 
 			}
diff --git a/mod/profile_photo.php b/mod/profile_photo.php
index 4f0d567f40..0f84a85c92 100644
--- a/mod/profile_photo.php
+++ b/mod/profile_photo.php
@@ -87,11 +87,9 @@ function profile_photo_post(&$a) {
 				);
 
 				// Update global directory in background
-				$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_run($php_path,"include/directory.php","$url");
+					proc_run('php',"include/directory.php","$url");
 			}
 			else
 				notice( t('Unable to process image') . EOL);
@@ -169,11 +167,9 @@ function profile_photo_content(&$a) {
 			);
 			
 			// Update global directory in background
-			$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_run($php_path,"include/directory.php","$url");
+				proc_run('php',"include/directory.php","$url");
 			
 			goaway($a->get_baseurl() . '/profiles');
 			return; // NOTREACHED
diff --git a/mod/profiles.php b/mod/profiles.php
index d74219501a..4e3f03799a 100644
--- a/mod/profiles.php
+++ b/mod/profiles.php
@@ -200,11 +200,9 @@ function profiles_post(&$a) {
 
 		if($is_default) {
 			// Update global directory in background
-			$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_run($php_path,"include/directory.php","$url");
+				proc_run('php',"include/directory.php","$url");
 		}
 	}
 }
diff --git a/mod/register.php b/mod/register.php
index d885362325..97038def0b 100644
--- a/mod/register.php
+++ b/mod/register.php
@@ -292,9 +292,8 @@ function register_post(&$a) {
 	}
 
 	if($netpublish && $a->config['register_policy'] != REGISTER_APPROVE) {
-		$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 		$url = $a->get_baseurl() . "/profile/$nickname";
-		proc_run($php_path,"include/directory.php","$url");
+		proc_run('php',"include/directory.php","$url");
 	}
 
 
diff --git a/mod/regmod.php b/mod/regmod.php
index f662902d8d..00cfa06e21 100644
--- a/mod/regmod.php
+++ b/mod/regmod.php
@@ -74,10 +74,9 @@ function regmod_content(&$a) {
 			intval($user[0]['uid'])
 		);
 		if(count($r) && $r[0]['net-publish']) {
-			$php_path = ((strlen($a->config['php_path'])) ? $a->config['php_path'] : 'php');
 			$url = $a->get_baseurl() . '/profile/' . $user[0]['nickname'];
 			if($url && strlen(get_config('system','directory_submit_url')))
-				proc_run($php_path,"include/directory.php","$url");
+				proc_run('php',"include/directory.php","$url");
 		}
 
 		$email_tpl = load_view_file("view/register_open_eml.tpl");
diff --git a/mod/settings.php b/mod/settings.php
index dbbac8bdeb..ebe07612eb 100644
--- a/mod/settings.php
+++ b/mod/settings.php
@@ -179,11 +179,9 @@ function settings_post(&$a) {
 
 	if($old_visibility != $net_publish) {
 		// Update global directory in background
-		$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_run($php_path,"include/directory.php","$url");
+			proc_run('php',"include/directory.php","$url");
 	}
 
 	$_SESSION['theme'] = $theme;