Merge pull request #3254 from Quix0r/rewrites/coding-convention-split2

Rewrites/coding convention split2
This commit is contained in:
Hypolite Petovan 2017-04-03 06:38:10 -04:00 committed by GitHub
commit 48dde02e75
18 changed files with 1866 additions and 1537 deletions

445
boot.php

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1503,10 +1503,12 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
if (is_object($item)) { if (is_object($item)) {
$rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor'); $rawtag = $item->get_item_tags(NAMESPACE_ACTIVITY,'actor');
if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) if ($rawtag && $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']) {
$nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data']; $nick = $rawtag[0]['child'][NAMESPACE_POCO]['preferredUsername'][0]['data'];
} else }
} else {
$nick = $item; $nick = $item;
}
if (is_array($contact)) { if (is_array($contact)) {
if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING) if (($contact['network'] == NETWORK_OSTATUS && $contact['rel'] == CONTACT_IS_SHARING)
@ -1544,11 +1546,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true); update_contact_avatar($photo, $importer["uid"], $contact_record["id"], true);
} }
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($importer['uid']) intval($importer['uid'])
); );
$a = get_app();
if (dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) { if (dbm::is_result($r) AND !in_array($r[0]['page-flags'], array(PAGE_SOAPBOX, PAGE_FREELOVE))) {
@ -1567,8 +1567,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
$def_gid = get_default_group($importer['uid'], $contact_record["network"]); $def_gid = get_default_group($importer['uid'], $contact_record["network"]);
if (intval($def_gid)) if (intval($def_gid)) {
group_add_member($importer['uid'], '', $contact_record['id'], $def_gid); group_add_member($importer['uid'], '', $contact_record['id'], $def_gid);
}
if (($r[0]['notify-flags'] & NOTIFY_INTRO) && if (($r[0]['notify-flags'] & NOTIFY_INTRO) &&
in_array($r[0]['page-flags'], array(PAGE_NORMAL))) { in_array($r[0]['page-flags'], array(PAGE_NORMAL))) {
@ -1599,7 +1600,7 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
} }
} }
function lose_follower($importer,$contact,$datarray = array(),$item = "") { function lose_follower($importer, $contact, array $datarray = array(), $item = "") {
if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_SHARING)) {
q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d",
@ -1611,7 +1612,7 @@ function lose_follower($importer,$contact,$datarray = array(),$item = "") {
} }
} }
function lose_sharer($importer,$contact,$datarray = array(),$item = "") { function lose_sharer($importer, $contact, array $datarray = array(), $item = "") {
if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) { if (($contact['rel'] == CONTACT_IS_FRIEND) || ($contact['rel'] == CONTACT_IS_FOLLOWER)) {
q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d", q("UPDATE `contact` SET `rel` = %d WHERE `id` = %d",

View file

@ -5,8 +5,8 @@ use \Friendica\Core\Config;
function update_gcontact_run(&$argv, &$argc) { function update_gcontact_run(&$argv, &$argc) {
global $a; global $a;
require_once('include/Scrape.php'); require_once 'include/Scrape.php';
require_once('include/socgraph.php'); require_once 'include/socgraph.php';
logger('update_gcontact: start'); logger('update_gcontact: start');
@ -21,11 +21,13 @@ function update_gcontact_run(&$argv, &$argc){
$r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
if (!$r) if (!dbm::_is_result($r)) {
return; return;
}
if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
return; return;
}
$data = probe_url($r[0]["url"]); $data = probe_url($r[0]["url"]);

115
index.php
View file

@ -28,17 +28,17 @@ $a->backend = false;
/** /**
* *
* Load the configuration file which contains our DB credentials. * Load the configuration file which contains our DB credentials.
* Ignore errors. If the file doesn't exist or is empty, we are running in installation mode. * Ignore errors. If the file doesn't exist or is empty, we are running in
* installation mode.
* *
*/ */
$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true); $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
@include(".htconfig.php"); // Only load config if found, don't surpress errors
if (!$install) {
include ".htconfig.php";
}
/** /**
* *
@ -46,7 +46,7 @@ $install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false
* *
*/ */
require_once("include/dba.php"); require_once "include/dba.php";
if (!$install) { if (!$install) {
$db = new dba($db_host, $db_user, $db_pass, $db_data, $install); $db = new dba($db_host, $db_user, $db_pass, $db_data, $install);
@ -233,12 +233,14 @@ if(strlen($a->module)) {
*/ */
// Compatibility with the Android Diaspora client // Compatibility with the Android Diaspora client
if ($a->module == "stream") if ($a->module == "stream") {
$a->module = "network"; $a->module = "network";
}
// Compatibility with the Firefox App // Compatibility with the Firefox App
if (($a->module == "users") AND ($a->cmd == "users/sign_in")) if (($a->module == "users") AND ($a->cmd == "users/sign_in")) {
$a->module = "login"; $a->module = "login";
}
$privateapps = get_config('config','private_addons'); $privateapps = get_config('config','private_addons');
@ -246,13 +248,13 @@ if(strlen($a->module)) {
//Check if module is an app and if public access to apps is allowed or not //Check if module is an app and if public access to apps is allowed or not
if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") { if ((!local_user()) && plugin_is_app($a->module) && $privateapps === "1") {
info( t("You must be logged in to use addons. ")); info( t("You must be logged in to use addons. "));
} } else {
else {
include_once("addon/{$a->module}/{$a->module}.php"); include_once("addon/{$a->module}/{$a->module}.php");
if(function_exists($a->module . '_module')) if (function_exists($a->module . '_module')) {
$a->module_loaded = true; $a->module_loaded = true;
} }
} }
}
/** /**
* If not, next look for a 'standard' program module in the 'mod' directory * If not, next look for a 'standard' program module in the 'mod' directory
@ -334,13 +336,6 @@ if($a->module_loaded) {
$func = str_replace('-','_',current_theme()) . '_init'; $func = str_replace('-','_',current_theme()) . '_init';
$func($a); $func($a);
} }
// elseif (x($a->theme_info,"extends") && file_exists("view/theme/".$a->theme_info["extends"]."/theme.php")) {
// require_once("view/theme/".$a->theme_info["extends"]."/theme.php");
// if(function_exists(str_replace('-','_',$a->theme_info["extends"]) . '_init')) {
// $func = str_replace('-','_',$a->theme_info["extends"]) . '_init';
// $func($a);
// }
// }
if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error) if (($_SERVER['REQUEST_METHOD'] === 'POST') && (! $a->error)
&& (function_exists($a->module . '_post')) && (function_exists($a->module . '_post'))
@ -374,82 +369,59 @@ if($a->module_loaded) {
/* /*
* Create the page head after setting the language * Create the page head after setting the language
* and getting any auth credentials * and getting any auth credentials.
* *
* Moved init_pagehead() and init_page_end() to after * Moved init_pagehead() and init_page_end() to after
* all the module functions have executed so that all * all the module functions have executed so that all
* theme choices made by the modules can take effect * theme choices made by the modules can take effect.
*/ */
$a->init_pagehead(); $a->init_pagehead();
/** /*
* Build the page ending -- this is stuff that goes right before * Build the page ending -- this is stuff that goes right before
* the closing </body> tag * the closing </body> tag
*/ */
$a->init_page_end(); $a->init_page_end();
// If you're just visiting, let javascript take you home // If you're just visiting, let javascript take you home
if (x($_SESSION, 'visitor_home')) {
if(x($_SESSION,'visitor_home'))
$homebase = $_SESSION['visitor_home']; $homebase = $_SESSION['visitor_home'];
elseif(local_user()) } elseif (local_user()) {
$homebase = 'profile/' . $a->user['nickname']; $homebase = 'profile/' . $a->user['nickname'];
}
if(isset($homebase)) if (isset($homebase)) {
$a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>'; $a->page['content'] .= '<script>var homebase="' . $homebase . '" ; </script>';
}
// now that we've been through the module content, see if the page reported /*
// a permission problem and if so, a 403 response would seem to be in order. * now that we've been through the module content, see if the page reported
* a permission problem and if so, a 403 response would seem to be in order.
*/
if (stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) { if (stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.')); header($_SERVER["SERVER_PROTOCOL"] . ' 403 ' . t('Permission denied.'));
} }
/** /*
*
* Report anything which needs to be communicated in the notification area (before the main body) * Report anything which needs to be communicated in the notification area (before the main body)
*
*/ */
/*if(x($_SESSION,'sysmsg')) {
$a->page['content'] = "<div id=\"sysmsg\" class=\"error-message\">{$_SESSION['sysmsg']}</div>\r\n"
. ((x($a->page,'content')) ? $a->page['content'] : '');
$_SESSION['sysmsg']="";
unset($_SESSION['sysmsg']);
}
if(x($_SESSION,'sysmsg_info')) {
$a->page['content'] = "<div id=\"sysmsg_info\" class=\"info-message\">{$_SESSION['sysmsg_info']}</div>\r\n"
. ((x($a->page,'content')) ? $a->page['content'] : '');
$_SESSION['sysmsg_info']="";
unset($_SESSION['sysmsg_info']);
}*/
call_hooks('page_end', $a->page['content']); call_hooks('page_end', $a->page['content']);
/*
/**
*
* Add the navigation (menu) template * Add the navigation (menu) template
*
*/ */
if ($a->module != 'install' && $a->module != 'maintenance') { if ($a->module != 'install' && $a->module != 'maintenance') {
nav($a); nav($a);
} }
/** /*
* Add a "toggle mobile" link if we're using a mobile device * Add a "toggle mobile" link if we're using a mobile device
*/ */
if ($a->is_mobile || $a->is_tablet) { if ($a->is_mobile || $a->is_tablet) {
if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) { if (isset($_SESSION['show-mobile']) && !$_SESSION['show-mobile']) {
$link = 'toggle_mobile?address=' . curPageURL(); $link = 'toggle_mobile?address=' . curPageURL();
} } else {
else {
$link = 'toggle_mobile?off=1&address=' . curPageURL(); $link = 'toggle_mobile?off=1&address=' . curPageURL();
} }
$a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array( $a->page['footer'] = replace_macros(get_markup_template("toggle_mobile_footer.tpl"), array(
@ -462,10 +434,11 @@ if($a->is_mobile || $a->is_tablet) {
* Build the page - now that we have all the components * Build the page - now that we have all the components
*/ */
if(!$a->theme['stylesheet']) if (!$a->theme['stylesheet']) {
$stylesheet = current_theme_url(); $stylesheet = current_theme_url();
else } else {
$stylesheet = $a->theme['stylesheet']; $stylesheet = $a->theme['stylesheet'];
}
$a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']); $a->page['htmlhead'] = str_replace('{{$stylesheet}}',$stylesheet,$a->page['htmlhead']);
//$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet)); //$a->page['htmlhead'] = replace_macros($a->page['htmlhead'], array('$stylesheet' => $stylesheet));
@ -478,6 +451,7 @@ if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "min
$content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8"); $content = mb_convert_encoding($a->page["content"], 'HTML-ENTITIES', "UTF-8");
/// @TODO one day, kill those error-surpressing @ stuff, or PHP should ban it
@$doc->loadHTML($content); @$doc->loadHTML($content);
$xpath = new DomXPath($doc); $xpath = new DomXPath($doc);
@ -485,7 +459,6 @@ if (isset($_GET["mode"]) AND (($_GET["mode"] == "raw") OR ($_GET["mode"] == "min
$list = $xpath->query("//*[contains(@id,'tread-wrapper-')]"); /* */ $list = $xpath->query("//*[contains(@id,'tread-wrapper-')]"); /* */
foreach ($list as $item) { foreach ($list as $item) {
$item = $target->importNode($item, true); $item = $target->importNode($item, true);
// And then append it to the target // And then append it to the target
@ -499,10 +472,7 @@ if (isset($_GET["mode"]) AND ($_GET["mode"] == "raw")) {
echo substr($target->saveHTML(), 6, -8); echo substr($target->saveHTML(), 6, -8);
if (!$a->is_backend()) killme();
session_write_close();
exit;
} }
$page = $a->page; $page = $a->page;
@ -511,9 +481,11 @@ $profile = $a->profile;
header("X-Friendica-Version: " . FRIENDICA_VERSION); header("X-Friendica-Version: " . FRIENDICA_VERSION);
header("Content-type: text/html; charset=utf-8"); header("Content-type: text/html; charset=utf-8");
// We use $_GET["mode"] for special page templates. So we will check if we have /*
// to load another page template than the default one * We use $_GET["mode"] for special page templates. So we will check if we have
// The page templates are located in /view/php/ or in the theme directory * to load another page template than the default one.
* The page templates are located in /view/php/ or in the theme directory.
*/
if (isset($_GET["mode"])) { if (isset($_GET["mode"])) {
$template = theme_include($_GET["mode"] . '.php'); $template = theme_include($_GET["mode"] . '.php');
} }
@ -523,8 +495,7 @@ if(!$template) {
$template = theme_include("default.php"); $template = theme_include("default.php");
} }
require_once($template); /// @TODO Looks unsafe (remote-inclusion), is maybe not but theme_include() uses file_exists() but does not escape anything
require_once $template;
if (!$a->is_backend()) killme();
session_write_close();
exit;

View file

@ -2009,14 +2009,14 @@ function admin_page_features_post(App $a) {
$feature_state = 'feature_' . $feature; $feature_state = 'feature_' . $feature;
$featurelock = 'featurelock_' . $feature; $featurelock = 'featurelock_' . $feature;
if (x($_POST[$feature_state])) { if (x($_POST, $feature_state)) {
$val = intval($_POST['feature_'.$feature]); $val = intval($_POST[$feature_state]);
} else { } else {
$val = 0; $val = 0;
} }
set_config('feature',$feature,$val); set_config('feature',$feature,$val);
if (x($_POST[$featurelock])) { if (x($_POST, $featurelock)) {
set_config('feature_lock', $feature, $val); set_config('feature_lock', $feature, $val);
} else { } else {
del_config('feature_lock', $feature); del_config('feature_lock', $feature);

View file

@ -586,17 +586,18 @@ function dfrn_confirm_post(App $a, $handsfree = null) {
dbesc($decrypted_source_url), dbesc($decrypted_source_url),
intval($local_uid) intval($local_uid)
); );
if(! count($ret)) { if (!dbm::is_result($ret)) {
if(strstr($decrypted_source_url,'http:')) if (strstr($decrypted_source_url,'http:')) {
$newurl = str_replace('http:','https:',$decrypted_source_url); $newurl = str_replace('http:','https:',$decrypted_source_url);
else } else {
$newurl = str_replace('https:','http:',$decrypted_source_url); $newurl = str_replace('https:','http:',$decrypted_source_url);
}
$ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1", $ret = q("SELECT * FROM `contact` WHERE `url` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newurl), dbesc($newurl),
intval($local_uid) intval($local_uid)
); );
if(! count($ret)) { if (!dbm::is_result($ret)) {
// this is either a bogus confirmation (?) or we deleted the original introduction. // this is either a bogus confirmation (?) or we deleted the original introduction.
$message = t('Contact record was not found for you on our site.'); $message = t('Contact record was not found for you on our site.');
xml_status(3,$message); xml_status(3,$message);

View file

@ -70,9 +70,11 @@ function dfrn_notify_post(App $a) {
break; // NOTREACHED break; // NOTREACHED
} }
// be careful - $importer will contain both the contact information for the contact /*
// sending us the post, and also the user information for the person receiving it. * be careful - $importer will contain both the contact information for the contact
// since they are mixed together, it is easy to get them confused. * sending us the post, and also the user information for the person receiving it.
* since they are mixed together, it is easy to get them confused.
*/
$r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`, $r = q("SELECT `contact`.*, `contact`.`uid` AS `importer_uid`,
`contact`.`pubkey` AS `cpubkey`, `contact`.`pubkey` AS `cpubkey`,
@ -107,8 +109,9 @@ function dfrn_notify_post(App $a) {
intval($prv), intval($prv),
intval($importer['id']) intval($importer['id'])
); );
if($writable != (-1)) if ($writable != (-1)) {
$importer['writable'] = $writable; $importer['writable'] = $writable;
}
$importer['forum'] = $page; $importer['forum'] = $page;
} }
@ -133,13 +136,6 @@ function dfrn_notify_post(App $a) {
} }
// If we are setup as a soapbox we aren't accepting input from this person
// This behaviour is deactivated since it really doesn't make sense to even disallow comments
// The check if someone is a friend or simply a follower is done in a later place so it needn't to be done here
//if($importer['page-flags'] == PAGE_SOAPBOX)
// xml_status(0);
$rino = get_config('system', 'rino_encrypt'); $rino = get_config('system', 'rino_encrypt');
$rino = intval($rino); $rino = intval($rino);
@ -161,16 +157,13 @@ function dfrn_notify_post(App $a) {
if ($dfrn_version >= 2.1) { if ($dfrn_version >= 2.1) {
if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) { if ((($importer['duplex']) && strlen($importer['cprvkey'])) || (! strlen($importer['cpubkey']))) {
openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']);
} } else {
else {
openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']);
} }
} } else {
else {
if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) { if ((($importer['duplex']) && strlen($importer['cpubkey'])) || (! strlen($importer['cprvkey']))) {
openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']); openssl_public_decrypt($rawkey, $final_key, $importer['cpubkey']);
} } else {
else {
openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']); openssl_private_decrypt($rawkey, $final_key, $importer['cprvkey']);
} }
} }
@ -180,19 +173,23 @@ function dfrn_notify_post(App $a) {
switch($rino_remote) { switch($rino_remote) {
case 0: case 0:
case 1: case 1:
// we got a key. old code send only the key, without RINO version. /*
// we assume RINO 1 if key and no RINO version *we got a key. old code send only the key, without RINO version.
* we assume RINO 1 if key and no RINO version
*/
$data = dfrn::aes_decrypt(hex2bin($data), $final_key); $data = dfrn::aes_decrypt(hex2bin($data), $final_key);
break; break;
case 2: case 2:
try { try {
$data = Crypto::decrypt(hex2bin($data), $final_key); $data = Crypto::decrypt(hex2bin($data), $final_key);
} catch (InvalidCiphertext $ex) { // VERY IMPORTANT } catch (InvalidCiphertext $ex) { // VERY IMPORTANT
// Either: /*
// 1. The ciphertext was modified by the attacker, * Either:
// 2. The key is wrong, or * 1. The ciphertext was modified by the attacker,
// 3. $ciphertext is not a valid ciphertext or was corrupted. * 2. The key is wrong, or
// Assume the worst. * 3. $ciphertext is not a valid ciphertext or was corrupted.
* Assume the worst.
*/
logger('The ciphertext has been tampered with!'); logger('The ciphertext has been tampered with!');
xml_status(0, 'The ciphertext has been tampered with!'); xml_status(0, 'The ciphertext has been tampered with!');
} catch (Ex\CryptoTestFailed $ex) { } catch (Ex\CryptoTestFailed $ex) {
@ -223,8 +220,10 @@ function dfrn_notify_content(App $a) {
if(x($_GET,'dfrn_id')) { if(x($_GET,'dfrn_id')) {
// initial communication from external contact, $direction is their direction. /*
// If this is a duplex communication, ours will be the opposite. * initial communication from external contact, $direction is their direction.
* If this is a duplex communication, ours will be the opposite.
*/
$dfrn_id = notags(trim($_GET['dfrn_id'])); $dfrn_id = notags(trim($_GET['dfrn_id']));
$dfrn_version = (float) $_GET['dfrn_version']; $dfrn_version = (float) $_GET['dfrn_version'];
@ -299,13 +298,13 @@ function dfrn_notify_content(App $a) {
if ((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) { if ((($dplx) && (strlen($prv_key))) || ((strlen($prv_key)) && (!(strlen($pub_key))))) {
openssl_private_encrypt($hash, $challenge, $prv_key); openssl_private_encrypt($hash, $challenge, $prv_key);
openssl_private_encrypt($id_str, $encrypted_id, $prv_key); openssl_private_encrypt($id_str, $encrypted_id, $prv_key);
} } elseif (strlen($pub_key)) {
elseif(strlen($pub_key)) {
openssl_public_encrypt($hash, $challenge, $pub_key); openssl_public_encrypt($hash, $challenge, $pub_key);
openssl_public_encrypt($id_str, $encrypted_id, $pub_key); openssl_public_encrypt($id_str, $encrypted_id, $pub_key);
} } else {
else /// @TODO these kind of else-blocks are making the code harder to understand
$status = 1; $status = 1;
}
$challenge = bin2hex($challenge); $challenge = bin2hex($challenge);
$encrypted_id = bin2hex($encrypted_id); $encrypted_id = bin2hex($encrypted_id);
@ -318,12 +317,13 @@ function dfrn_notify_content(App $a) {
// if requested rino is lower than enabled local rino, lower local rino version // if requested rino is lower than enabled local rino, lower local rino version
// if requested rino is higher than enabled local rino, reply with local rino // if requested rino is higher than enabled local rino, reply with local rino
if ($rino_remote < $rino) $rino = $rino_remote; if ($rino_remote < $rino) {
$rino = $rino_remote;
}
if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) { if((($r[0]['rel']) && ($r[0]['rel'] != CONTACT_IS_SHARING)) || ($r[0]['page-flags'] == PAGE_COMMUNITY)) {
$perm = 'rw'; $perm = 'rw';
} } else {
else {
$perm = 'r'; $perm = 'r';
} }

View file

@ -460,9 +460,6 @@ function check_funcs(&$checks) {
$ck_funcs[6]['status'] = false; $ck_funcs[6]['status'] = false;
$ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.'); $ck_funcs[6]['help'] = t('Error, XML PHP module required but not installed.');
} }
/*if((x($_SESSION,'sysmsg')) && is_array($_SESSION['sysmsg']) && count($_SESSION['sysmsg']))
notice( t('Please see the file "INSTALL.txt".') . EOL);*/
} }

View file

@ -1,38 +1,39 @@
<?php <?php
/** /*
*
* This is the POST destination for most all locally posted * This is the POST destination for most all locally posted
* text stuff. This function handles status, wall-to-wall status, * text stuff. This function handles status, wall-to-wall status,
* local comments, and remote coments that are posted on this site * local comments, and remote coments that are posted on this site
* (as opposed to being delivered in a feed). * (as opposed to being delivered in a feed).
* Also processed here are posts and comments coming through the * Also processed here are posts and comments coming through the
* statusnet/twitter API. * statusnet/twitter API.
*
* All of these become an "item" which is our basic unit of * All of these become an "item" which is our basic unit of
* information. * information.
*
* Posts that originate externally or do not fall into the above * Posts that originate externally or do not fall into the above
* posting categories go through item_store() instead of this function. * posting categories go through item_store() instead of this function.
*
*/ */
require_once('include/crypto.php'); require_once 'include/crypto.php';
require_once('include/enotify.php'); require_once 'include/enotify.php';
require_once('include/email.php'); require_once 'include/email.php';
require_once('include/tags.php'); require_once 'include/tags.php';
require_once('include/files.php'); require_once 'include/files.php';
require_once('include/threads.php'); require_once 'include/threads.php';
require_once('include/text.php'); require_once 'include/text.php';
require_once('include/items.php'); require_once 'include/items.php';
require_once('include/Scrape.php'); require_once 'include/Scrape.php';
require_once('include/diaspora.php'); require_once 'include/diaspora.php';
require_once('include/Contact.php'); require_once 'include/Contact.php';
function item_post(App $a) { function item_post(App $a) {
if((! local_user()) && (! remote_user()) && (! x($_REQUEST,'commenter'))) if ((! local_user()) && (! remote_user()) && (! x($_REQUEST, 'commenter'))) {
return; return;
}
require_once('include/security.php'); require_once 'include/security.php';
$uid = local_user(); $uid = local_user();
@ -55,24 +56,21 @@ function item_post(App $a) {
$return_path = ((x($_REQUEST, 'return')) ? $_REQUEST['return'] : ''); $return_path = ((x($_REQUEST, 'return')) ? $_REQUEST['return'] : '');
$preview = ((x($_REQUEST, 'preview')) ? intval($_REQUEST['preview']) : 0); $preview = ((x($_REQUEST, 'preview')) ? intval($_REQUEST['preview']) : 0);
/*
// Check for doubly-submitted posts, and reject duplicates * Check for doubly-submitted posts, and reject duplicates
// Note that we have to ignore previews, otherwise nothing will post * Note that we have to ignore previews, otherwise nothing will post
// after it's been previewed * after it's been previewed
if (!$preview && x($_REQUEST['post_id_random'])) { */
if (x($_SESSION['post-random']) && $_SESSION['post-random'] == $_REQUEST['post_id_random']) { if (!$preview && x($_REQUEST, 'post_id_random')) {
if (x($_SESSION, 'post-random') && $_SESSION['post-random'] == $_REQUEST['post_id_random']) {
logger("item post: duplicate post", LOGGER_DEBUG); logger("item post: duplicate post", LOGGER_DEBUG);
item_post_return(App::get_baseurl(), $api_source, $return_path); item_post_return(App::get_baseurl(), $api_source, $return_path);
} } else {
else {
$_SESSION['post-random'] = $_REQUEST['post_id_random']; $_SESSION['post-random'] = $_REQUEST['post_id_random'];
} }
} }
/** // Is this a reply to something?
* Is this a reply to something?
*/
$parent = ((x($_REQUEST, 'parent')) ? intval($_REQUEST['parent']) : 0); $parent = ((x($_REQUEST, 'parent')) ? intval($_REQUEST['parent']) : 0);
$parent_uri = ((x($_REQUEST, 'parent_uri')) ? trim($_REQUEST['parent_uri']) : ''); $parent_uri = ((x($_REQUEST, 'parent_uri')) ? trim($_REQUEST['parent_uri']) : '');
@ -133,8 +131,9 @@ function item_post(App $a) {
intval($parent_item['contact-id']), intval($parent_item['contact-id']),
intval($uid) intval($uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$parent_contact = $r[0]; $parent_contact = $r[0];
}
// If the contact id doesn't fit with the contact, then set the contact to null // If the contact id doesn't fit with the contact, then set the contact to null
$thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent)); $thrparent = q("SELECT `author-link`, `network` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($thr_parent));
@ -143,7 +142,7 @@ function item_post(App $a) {
$parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]); $parent_contact = get_contact_details_by_url($thrparent[0]["author-link"]);
if (!isset($parent_contact["nick"])) { if (!isset($parent_contact["nick"])) {
require_once("include/Scrape.php"); require_once 'include/Scrape.php';
$probed_contact = probe_url($thrparent[0]["author-link"]); $probed_contact = probe_url($thrparent[0]["author-link"]);
if ($probed_contact["network"] != NETWORK_FEED) { if ($probed_contact["network"] != NETWORK_FEED) {
$parent_contact = $probed_contact; $parent_contact = $probed_contact;
@ -154,15 +153,19 @@ function item_post(App $a) {
} }
} }
logger('no contact found: ' . print_r($thrparent, true), LOGGER_DEBUG); logger('no contact found: ' . print_r($thrparent, true), LOGGER_DEBUG);
} else } else {
logger('parent contact: ' . print_r($parent_contact, true), LOGGER_DEBUG); logger('parent contact: ' . print_r($parent_contact, true), LOGGER_DEBUG);
}
if ($parent_contact["nick"] == "") if ($parent_contact["nick"] == "") {
$parent_contact["nick"] = $parent_contact["name"]; $parent_contact["nick"] = $parent_contact["name"];
} }
} }
}
if($parent) logger('mod_item: item_post parent=' . $parent); if ($parent) {
logger('mod_item: item_post parent=' . $parent);
}
$profile_uid = ((x($_REQUEST, 'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0); $profile_uid = ((x($_REQUEST, 'profile_uid')) ? intval($_REQUEST['profile_uid']) : 0);
$post_id = ((x($_REQUEST, 'post_id')) ? intval($_REQUEST['post_id']) : 0); $post_id = ((x($_REQUEST, 'post_id')) ? intval($_REQUEST['post_id']) : 0);
@ -191,20 +194,21 @@ function item_post(App $a) {
if ((x($_REQUEST, 'commenter')) && ((! $parent) || (! $parent_item['wall']))) { if ((x($_REQUEST, 'commenter')) && ((! $parent) || (! $parent_item['wall']))) {
notice(t('Permission denied.') . EOL) ; notice(t('Permission denied.') . EOL) ;
if(x($_REQUEST,'return')) if (x($_REQUEST, 'return')) {
goaway($return_path); goaway($return_path);
}
killme(); killme();
} }
// Now check that it is a page_type of PAGE_BLOG, and that valid personal details /*
// have been provided, and run any anti-spam plugins * Now check that it is a page_type of PAGE_BLOG, and that valid personal details
* have been provided, and run any anti-spam plugins
*/
if ((! can_write_wall($a, $profile_uid)) && (! $allow_moderated)) { if ((! can_write_wall($a, $profile_uid)) && (! $allow_moderated)) {
notice(t('Permission denied.') . EOL) ; notice(t('Permission denied.') . EOL) ;
if(x($_REQUEST,'return')) if (x($_REQUEST, 'return')) {
goaway($return_path); goaway($return_path);
}
killme(); killme();
} }
@ -229,8 +233,9 @@ function item_post(App $a) {
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($profile_uid) intval($profile_uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$user = $r[0]; $user = $r[0];
}
if ($orig_post) { if ($orig_post) {
$str_group_allow = $orig_post['allow_gid']; $str_group_allow = $orig_post['allow_gid'];
@ -254,10 +259,12 @@ function item_post(App $a) {
} else { } else {
// if coming from the API and no privacy settings are set, /*
// use the user default permissions - as they won't have * if coming from the API and no privacy settings are set,
// been supplied via a form. * use the user default permissions - as they won't have
* been supplied via a form.
*/
/// @TODO use x($_REQUEST, 'foo') here
if (($api_source) if (($api_source)
&& (! array_key_exists('contact_allow', $_REQUEST)) && (! array_key_exists('contact_allow', $_REQUEST))
&& (! array_key_exists('group_allow', $_REQUEST)) && (! array_key_exists('group_allow', $_REQUEST))
@ -267,8 +274,7 @@ function item_post(App $a) {
$str_contact_allow = $user['allow_cid']; $str_contact_allow = $user['allow_cid'];
$str_group_deny = $user['deny_gid']; $str_group_deny = $user['deny_gid'];
$str_contact_deny = $user['deny_cid']; $str_contact_deny = $user['deny_cid'];
} } else {
else {
// use the posted permissions // use the posted permissions
@ -287,16 +293,14 @@ function item_post(App $a) {
$network = notags(trim($_REQUEST['network'])); $network = notags(trim($_REQUEST['network']));
$guid = get_guid(32); $guid = get_guid(32);
item_add_language_opt($_REQUEST); item_add_language_opt($_REQUEST);
$postopts = $_REQUEST['postopts'] ? $_REQUEST['postopts'] : ""; $postopts = $_REQUEST['postopts'] ? $_REQUEST['postopts'] : "";
$private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0); $private = ((strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny)) ? 1 : 0);
if ($user['hidewall']) {
if($user['hidewall'])
$private = 2; $private = 2;
}
// If this is a comment, set the permissions from the parent. // If this is a comment, set the permissions from the parent.
@ -305,8 +309,9 @@ function item_post(App $a) {
// for non native networks use the network of the original post as network of the item // for non native networks use the network of the original post as network of the item
if (($parent_item['network'] != NETWORK_DIASPORA) if (($parent_item['network'] != NETWORK_DIASPORA)
AND ($parent_item['network'] != NETWORK_OSTATUS) AND ($parent_item['network'] != NETWORK_OSTATUS)
AND ($network == "")) AND ($network == "")) {
$network = $parent_item['network']; $network = $parent_item['network'];
}
$str_contact_allow = $parent_item['allow_cid']; $str_contact_allow = $parent_item['allow_cid'];
$str_group_allow = $parent_item['allow_gid']; $str_group_allow = $parent_item['allow_gid'];
@ -322,20 +327,24 @@ function item_post(App $a) {
if ($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) { if ($api_source && $profile_uid && $profile_uid == local_user() && (! $private)) {
$mail_disabled = ((function_exists('imap_open') && (! get_config('system', 'imap_disabled'))) ? 0 : 1); $mail_disabled = ((function_exists('imap_open') && (! get_config('system', 'imap_disabled'))) ? 0 : 1);
if (! $mail_disabled) { if (! $mail_disabled) {
/// @TODO Check if only pubmail is loaded, * loads all columns
$r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1",
intval(local_user()) intval(local_user())
); );
if (dbm::is_result($r) && intval($r[0]['pubmail'])) if (dbm::is_result($r) && intval($r[0]['pubmail'])) {
$pubmail_enabled = true; $pubmail_enabled = true;
} }
} }
}
if (! strlen($body)) { if (! strlen($body)) {
if($preview) if ($preview) {
killme(); killme();
}
info(t('Empty post discarded.') . EOL ); info(t('Empty post discarded.') . EOL );
if(x($_REQUEST,'return')) if (x($_REQUEST, 'return')) {
goaway($return_path); goaway($return_path);
}
killme(); killme();
} }
} }
@ -363,9 +372,8 @@ function item_post(App $a) {
$self = true; $self = true;
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($_SESSION['uid'])); intval($_SESSION['uid']));
} } elseif(remote_user()) {
elseif(remote_user()) { if (x($_SESSION, 'remote') && is_array($_SESSION['remote'])) {
if(is_array($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $v) { foreach ($_SESSION['remote'] as $v) {
if ($v['uid'] == $profile_uid) { if ($v['uid'] == $profile_uid) {
$contact_id = $v['cid']; $contact_id = $v['cid'];
@ -389,28 +397,26 @@ function item_post(App $a) {
if ($profile_uid == local_user()) { if ($profile_uid == local_user()) {
$contact_record = $author; $contact_record = $author;
} } else {
else {
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1",
intval($profile_uid) intval($profile_uid)
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$contact_record = $r[0]; $contact_record = $r[0];
} }
}
$post_type = notags(trim($_REQUEST['type'])); $post_type = notags(trim($_REQUEST['type']));
if($post_type === 'net-comment') { if ($post_type === 'net-comment' && $parent_item !== null) {
if($parent_item !== null) { if ($parent_item['wall'] == 1) {
if($parent_item['wall'] == 1)
$post_type = 'wall-comment'; $post_type = 'wall-comment';
else } else {
$post_type = 'remote-comment'; $post_type = 'remote-comment';
} }
} }
/** /*
*
* When a photo was uploaded into the message using the (profile wall) ajax * When a photo was uploaded into the message using the (profile wall) ajax
* uploader, The permissions are initially set to disallow anybody but the * uploader, The permissions are initially set to disallow anybody but the
* owner from seeing it. This is because the permissions may not yet have been * owner from seeing it. This is because the permissions may not yet have been
@ -418,7 +424,6 @@ function item_post(App $a) {
* appropriately. But we didn't know the final permissions on the post until * appropriately. But we didn't know the final permissions on the post until
* now. So now we'll look for links of uploaded messages that are in the * now. So now we'll look for links of uploaded messages that are in the
* post and set them to the same permissions as the post itself. * post and set them to the same permissions as the post itself.
*
*/ */
$match = null; $match = null;
@ -466,10 +471,9 @@ function item_post(App $a) {
} }
/** /*
* Next link in any attachment references we find in the post. * Next link in any attachment references we find in the post.
*/ */
$match = false; $match = false;
if ((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) { if ((! $preview) && preg_match_all("/\[attachment\](.*?)\[\/attachment\]/", $body, $match)) {
@ -507,41 +511,34 @@ function item_post(App $a) {
$body = bb_translate_video($body); $body = bb_translate_video($body);
/** // Fold multi-line [code] sequences
* Fold multi-line [code] sequences
*/
$body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body); $body = preg_replace('/\[\/code\]\s*\[code\]/ism', "\n", $body);
$body = scale_external_images($body, false); $body = scale_external_images($body, false);
// Setting the object type if not defined before // Setting the object type if not defined before
if (!$objecttype) { if (!$objecttype) {
$objecttype = ACTIVITY_OBJ_NOTE; // Default value $objecttype = ACTIVITY_OBJ_NOTE; // Default value
require_once("include/plaintext.php"); require_once 'include/plaintext.php';
$objectdata = get_attached_data($body); $objectdata = get_attached_data($body);
if ($post["type"] == "link") if ($post["type"] == "link") {
$objecttype = ACTIVITY_OBJ_BOOKMARK; $objecttype = ACTIVITY_OBJ_BOOKMARK;
elseif ($post["type"] == "video") } elseif ($post["type"] == "video") {
$objecttype = ACTIVITY_OBJ_VIDEO; $objecttype = ACTIVITY_OBJ_VIDEO;
elseif ($post["type"] == "photo") } elseif ($post["type"] == "photo") {
$objecttype = ACTIVITY_OBJ_IMAGE; $objecttype = ACTIVITY_OBJ_IMAGE;
}
} }
/** // Look for any tags and linkify them
* Look for any tags and linkify them
*/
$str_tags = ''; $str_tags = '';
$inform = ''; $inform = '';
$tags = get_tags($body); $tags = get_tags($body);
/** /*
* add a statusnet style reply tag if the original post was from there * add a statusnet style reply tag if the original post was from there
* and we are replying, and there isn't one already * and we are replying, and there isn't one already
*/ */
@ -557,16 +554,17 @@ function item_post(App $a) {
$toplevel_parent = q("SELECT `contact`.* FROM `contact` $toplevel_parent = q("SELECT `contact`.* FROM `contact`
INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `contact`.`url` = `item`.`author-link` INNER JOIN `item` ON `item`.`contact-id` = `contact`.`id` AND `contact`.`url` = `item`.`author-link`
WHERE `item`.`id` = `item`.`parent` AND `item`.`parent` = %d", intval($parent)); WHERE `item`.`id` = `item`.`parent` AND `item`.`parent` = %d", intval($parent));
if ($toplevel_parent) if (dbm::is_result($toplevel_parent)) {
$toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id']; $toplevel_contact = '@' . $toplevel_parent[0]['nick'] . '+' . $toplevel_parent[0]['id'];
else { } else {
$toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent)); $toplevel_parent = q("SELECT `author-link`, `author-name` FROM `item` WHERE `id` = `parent` AND `parent` = %d", intval($parent));
$toplevel_contact = '@[url=' . $toplevel_parent[0]['author-link'] . ']' . $toplevel_parent[0]['author-name'] . '[/url]'; $toplevel_contact = '@[url=' . $toplevel_parent[0]['author-link'] . ']' . $toplevel_parent[0]['author-name'] . '[/url]';
} }
if (!in_array($toplevel_contact,$tags)) if (!in_array($toplevel_contact, $tags)) {
$tags[] = $toplevel_contact; $tags[] = $toplevel_contact;
} }
}
$tagged = array(); $tagged = array();
@ -575,21 +573,25 @@ function item_post(App $a) {
if (count($tags)) { if (count($tags)) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
if(strpos($tag,'#') === 0) if (strpos($tag, '#') === 0) {
continue; continue;
}
// If we already tagged 'Robert Johnson', don't try and tag 'Robert'. /*
// Robert Johnson should be first in the $tags array * If we already tagged 'Robert Johnson', don't try and tag 'Robert'.
* Robert Johnson should be first in the $tags array
*/
$fullnametagged = false; $fullnametagged = false;
for($x = 0; $x < count($tagged); $x ++) { /// @TODO $tagged is initialized above if() block and is not filled, maybe old-lost code?
if(stristr($tagged[$x],$tag . ' ')) { foreach ($tagged as $nextTag) {
if (stristr($nextTag, $tag . ' ')) {
$fullnametagged = true; $fullnametagged = true;
break; break;
} }
} }
if($fullnametagged) if ($fullnametagged) {
continue; continue;
}
$success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network); $success = handle_tag($a, $body, $inform, $str_tags, (local_user()) ? local_user() : $profile_uid , $tag, $network);
if ($success['replaced']) { if ($success['replaced']) {
@ -668,11 +670,11 @@ function item_post(App $a) {
$datarray['owner-name'] = $contact_record['name']; $datarray['owner-name'] = $contact_record['name'];
$datarray['owner-link'] = $contact_record['url']; $datarray['owner-link'] = $contact_record['url'];
$datarray['owner-avatar'] = $contact_record['thumb']; $datarray['owner-avatar'] = $contact_record['thumb'];
$datarray["owner-id"] = get_contact($datarray["owner-link"], 0); $datarray['owner-id'] = get_contact($datarray['owner-link'], 0);
$datarray['author-name'] = $author['name']; $datarray['author-name'] = $author['name'];
$datarray['author-link'] = $author['url']; $datarray['author-link'] = $author['url'];
$datarray['author-avatar'] = $author['thumb']; $datarray['author-avatar'] = $author['thumb'];
$datarray["author-id"] = get_contact($datarray["author-link"], 0); $datarray['author-id'] = get_contact($datarray['author-link'], 0);
$datarray['created'] = datetime_convert(); $datarray['created'] = datetime_convert();
$datarray['edited'] = datetime_convert(); $datarray['edited'] = datetime_convert();
$datarray['commented'] = datetime_convert(); $datarray['commented'] = datetime_convert();
@ -707,12 +709,11 @@ function item_post(App $a) {
"photo" => $datarray['author-avatar'], "name" => $datarray['author-name'])); "photo" => $datarray['author-avatar'], "name" => $datarray['author-name']));
$datarray['object'] = $object; $datarray['object'] = $object;
/** /*
* These fields are for the convenience of plugins... * These fields are for the convenience of plugins...
* 'self' if true indicates the owner is posting on their own wall * 'self' if true indicates the owner is posting on their own wall
* If parent is 0 it is a top-level post. * If parent is 0 it is a top-level post.
*/ */
$datarray['parent'] = $parent; $datarray['parent'] = $parent;
$datarray['self'] = $self; $datarray['self'] = $self;
// $datarray['prvnets'] = $user['prvnets']; // $datarray['prvnets'] = $user['prvnets'];
@ -722,16 +723,16 @@ function item_post(App $a) {
$datarray['last-child'] = 1; $datarray['last-child'] = 1;
$datarray['visible'] = 1; $datarray['visible'] = 1;
if($orig_post) if ($orig_post) {
$datarray['edit'] = true; $datarray['edit'] = true;
}
// Search for hashtags // Search for hashtags
item_body_set_hashtags($datarray); item_body_set_hashtags($datarray);
// preview mode - prepare the body for display and send it via json // preview mode - prepare the body for display and send it via json
if ($preview) { if ($preview) {
require_once('include/conversation.php'); require_once 'include/conversation.php';
// We set the datarray ID to -1 because in preview mode the dataray // We set the datarray ID to -1 because in preview mode the dataray
// doesn't have an ID. // doesn't have an ID.
$datarray["id"] = -1; $datarray["id"] = -1;
@ -741,7 +742,6 @@ function item_post(App $a) {
killme(); killme();
} }
call_hooks('post_local',$datarray); call_hooks('post_local',$datarray);
if (x($datarray, 'cancel')) { if (x($datarray, 'cancel')) {
@ -790,8 +790,9 @@ function item_post(App $a) {
goaway($return_path); goaway($return_path);
} }
killme(); killme();
} else } else {
$post_id = 0; $post_id = 0;
}
q("COMMIT"); q("COMMIT");
q("START TRANSACTION;"); q("START TRANSACTION;");
@ -974,8 +975,9 @@ function item_post(App $a) {
if (count($erecips)) { if (count($erecips)) {
foreach ($erecips as $recip) { foreach ($erecips as $recip) {
$addr = trim($recip); $addr = trim($recip);
if(! strlen($addr)) if (! strlen($addr)) {
continue; continue;
}
$disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username']) $disclaimer = '<hr />' . sprintf( t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username'])
. '<br />'; . '<br />';
$disclaimer .= sprintf( t('You may visit them online at %s'), App::get_baseurl() . '/profile/' . $a->user['nickname']) . EOL; $disclaimer .= sprintf( t('You may visit them online at %s'), App::get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
@ -988,7 +990,7 @@ function item_post(App $a) {
$link = '<a href="' . App::get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />'; $link = '<a href="' . App::get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
$html = prepare_body($datarray); $html = prepare_body($datarray);
$message = '<html><body>' . $link . $html . $disclaimer . '</body></html>'; $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
include_once('include/html2plain.php'); include_once 'include/html2plain.php';
$params = array ( $params = array (
'fromName' => $a->user['username'], 'fromName' => $a->user['username'],
'fromEmail' => $a->user['email'], 'fromEmail' => $a->user['email'],
@ -1032,8 +1034,9 @@ function item_post(App $a) {
function item_post_return($baseurl, $api_source, $return_path) { function item_post_return($baseurl, $api_source, $return_path) {
// figure out how to return, depending on from whence we came // figure out how to return, depending on from whence we came
if($api_source) if ($api_source) {
return; return;
}
if ($return_path) { if ($return_path) {
goaway($return_path); goaway($return_path);
@ -1058,7 +1061,7 @@ function item_content(App $a) {
return; return;
} }
require_once('include/security.php'); require_once 'include/security.php';
$o = ''; $o = '';
if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) { if (($a->argc == 3) && ($a->argv[1] === 'drop') && intval($a->argv[2])) {
@ -1086,9 +1089,9 @@ function item_content(App $a) {
* *
* @return boolean true if replaced, false if not replaced * @return boolean true if replaced, false if not replaced
*/ */
function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") { function handle_tag(App $a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $network = "") {
require_once("include/Scrape.php"); require_once 'include/Scrape.php';
require_once("include/socgraph.php"); require_once 'include/socgraph.php';
$replaced = false; $replaced = false;
$r = null; $r = null;
@ -1111,19 +1114,22 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
$r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0", $r = q("SELECT `alias`, `name` FROM `contact` WHERE `nurl` = '%s' AND `alias` != '' AND `uid` = 0",
normalise_link($matches[1])); normalise_link($matches[1]));
if (!$r) if (!dbm::is_result($r)) {
$r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''", $r = q("SELECT `alias`, `name` FROM `gcontact` WHERE `nurl` = '%s' AND `alias` != ''",
normalise_link($matches[1])); normalise_link($matches[1]));
if ($r) }
if (dbm::is_result($r)) {
$data = $r[0]; $data = $r[0];
else } else {
$data = probe_url($matches[1]); $data = probe_url($matches[1]);
}
if ($data["alias"] != "") { if ($data["alias"] != "") {
$newtag = '@[url=' . $data["alias"] . ']' . $data["name"] . '[/url]'; $newtag = '@[url=' . $data["alias"] . ']' . $data["name"] . '[/url]';
if (!stristr($str_tags, $newtag)) { if (!stristr($str_tags, $newtag)) {
if(strlen($str_tags)) if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
}
$str_tags .= $newtag; $str_tags .= $newtag;
} }
} }
@ -1155,7 +1161,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
); );
// Then check in the contact table for the url // Then check in the contact table for the url
if (!$r) if (!dbm::is_result($r)) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact` $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `contact`
WHERE `nurl` = '%s' AND `uid` = %d AND WHERE `nurl` = '%s' AND `uid` = %d AND
(`network` != '%s' OR (`notify` != '' AND `alias` != '')) (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
@ -1164,26 +1170,29 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
intval($profile_uid), intval($profile_uid),
dbesc(NETWORK_OSTATUS) dbesc(NETWORK_OSTATUS)
); );
}
// Then check in the global contacts for the address // Then check in the global contacts for the address
if (!$r) if (!dbm::is_result($r)) {
$r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact` $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
WHERE `addr` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) WHERE `addr` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
LIMIT 1", LIMIT 1",
dbesc($name), dbesc($name),
dbesc(NETWORK_OSTATUS) dbesc(NETWORK_OSTATUS)
); );
}
// Then check in the global contacts for the url // Then check in the global contacts for the url
if (!$r) if (!dbm::is_result($r)) {
$r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact` $r = q("SELECT `url`, `nick`, `name`, `alias`, `network`, `notify` FROM `gcontact`
WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != '')) WHERE `nurl` = '%s' AND (`network` != '%s' OR (`notify` != '' AND `alias` != ''))
LIMIT 1", LIMIT 1",
dbesc(normalise_link($name)), dbesc(normalise_link($name)),
dbesc(NETWORK_OSTATUS) dbesc(NETWORK_OSTATUS)
); );
}
if (!$r) { if (!dbm::is_result($r)) {
$probed = probe_url($name); $probed = probe_url($name);
if ($result['network'] != NETWORK_PHANTOM) { if ($result['network'] != NETWORK_PHANTOM) {
update_gcontact($probed); update_gcontact($probed);
@ -1204,7 +1213,7 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
} }
// select someone by attag or nick and the name passed in the current network // select someone by attag or nick and the name passed in the current network
if(!$r AND ($network != "")) if(!dbm::is_result($r) AND ($network != ""))
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `network` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name), dbesc($name),
dbesc($name), dbesc($name),
@ -1213,46 +1222,51 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
); );
//select someone from this user's contacts by name in the current network //select someone from this user's contacts by name in the current network
if (!$r AND ($network != "")) if (!dbm::is_result($r) AND ($network != "")) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `network` = '%s' AND `uid` = %d LIMIT 1",
dbesc($name), dbesc($name),
dbesc($network), dbesc($network),
intval($profile_uid) intval($profile_uid)
); );
}
// select someone by attag or nick and the name passed in // select someone by attag or nick and the name passed in
if(!$r) if(!dbm::is_result($r)) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name), dbesc($name),
dbesc($name), dbesc($name),
intval($profile_uid) intval($profile_uid)
); );
}
// select someone from this user's contacts by name // select someone from this user's contacts by name
if(!$r) if(!dbm::is_result($r)) {
$r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT `id`, `url`, `nick`, `name`, `alias`, `network` FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($name), dbesc($name),
intval($profile_uid) intval($profile_uid)
); );
} }
}
if ($r) { if (dbm::is_result($r)) {
if(strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) if (strlen($inform) AND (isset($r[0]["notify"]) OR isset($r[0]["id"]))) {
$inform .= ','; $inform .= ',';
}
if (isset($r[0]["id"])) if (isset($r[0]["id"])) {
$inform .= 'cid:' . $r[0]["id"]; $inform .= 'cid:' . $r[0]["id"];
elseif (isset($r[0]["notify"])) } elseif (isset($r[0]["notify"])) {
$inform .= $r[0]["notify"]; $inform .= $r[0]["notify"];
}
$profile = $r[0]["url"]; $profile = $r[0]["url"];
$alias = $r[0]["alias"]; $alias = $r[0]["alias"];
$newname = $r[0]["nick"]; $newname = $r[0]["nick"];
if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER) if (($newname == "") OR (($r[0]["network"] != NETWORK_OSTATUS) AND ($r[0]["network"] != NETWORK_TWITTER)
AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) AND ($r[0]["network"] != NETWORK_STATUSNET) AND ($r[0]["network"] != NETWORK_APPNET))) {
$newname = $r[0]["name"]; $newname = $r[0]["name"];
} }
}
//if there is an url for this persons profile //if there is an url for this persons profile
if (isset($profile) AND ($newname != "")) { if (isset($profile) AND ($newname != "")) {
@ -1264,19 +1278,22 @@ function handle_tag($a, &$body, &$inform, &$str_tags, $profile_uid, $tag, $netwo
$body = str_replace('@' . $name, $newtag, $body); $body = str_replace('@' . $name, $newtag, $body);
// append tag to str_tags // append tag to str_tags
if (! stristr($str_tags, $newtag)) { if (! stristr($str_tags, $newtag)) {
if(strlen($str_tags)) if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
}
$str_tags .= $newtag; $str_tags .= $newtag;
} }
// Status.Net seems to require the numeric ID URL in a mention if the person isn't /*
// subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both. * Status.Net seems to require the numeric ID URL in a mention if the person isn't
* subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
*/
if (strlen($alias)) { if (strlen($alias)) {
$newtag = '@[url=' . $alias . ']' . $newname . '[/url]'; $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
if (! stristr($str_tags, $newtag)) { if (! stristr($str_tags, $newtag)) {
if(strlen($str_tags)) if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
}
$str_tags .= $newtag; $str_tags .= $newtag;
} }
} }

View file

@ -22,20 +22,21 @@ function manage_post(App $a) {
} }
} }
$r = q("select * from manage where uid = %d", $r = q("SELECT * FROM `manage` WHERE `uid` = %d",
intval($uid) intval($uid)
); );
$submanage = $r; $submanage = $r;
$identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0); $identity = ((x($_POST['identity'])) ? intval($_POST['identity']) : 0);
if(! $identity) if (! $identity) {
return; return;
}
$limited_id = 0; $limited_id = 0;
$original_id = $uid; $original_id = $uid;
if(count($submanage)) { if (dbm::is_result($submanage)) {
foreach ($submanage as $m) { foreach ($submanage as $m) {
if ($identity == $m['mid']) { if ($identity == $m['mid']) {
$limited_id = $m['mid']; $limited_id = $m['mid'];
@ -48,8 +49,7 @@ function manage_post(App $a) {
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1",
intval($limited_id) intval($limited_id)
); );
} } else {
else {
$r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1", $r = q("SELECT * FROM `user` WHERE `uid` = %d AND `email` = '%s' AND `password` = '%s' LIMIT 1",
intval($identity), intval($identity),
dbesc($orig_record['email']), dbesc($orig_record['email']),
@ -70,18 +70,22 @@ function manage_post(App $a) {
unset($_SESSION['mobile-theme']); unset($_SESSION['mobile-theme']);
unset($_SESSION['page_flags']); unset($_SESSION['page_flags']);
unset($_SESSION['return_url']); unset($_SESSION['return_url']);
if(x($_SESSION,'submanage')) if (x($_SESSION, 'submanage')) {
unset($_SESSION['submanage']); unset($_SESSION['submanage']);
if(x($_SESSION,'sysmsg')) }
if (x($_SESSION, 'sysmsg')) {
unset($_SESSION['sysmsg']); unset($_SESSION['sysmsg']);
if(x($_SESSION,'sysmsg_info')) }
if (x($_SESSION, 'sysmsg_info')) {
unset($_SESSION['sysmsg_info']); unset($_SESSION['sysmsg_info']);
}
require_once('include/security.php'); require_once('include/security.php');
authenticate_success($r[0], true, true); authenticate_success($r[0], true, true);
if($limited_id) if ($limited_id) {
$_SESSION['submanage'] = $original_id; $_SESSION['submanage'] = $original_id;
}
$ret = array(); $ret = array();
call_hooks('home_init',$ret); call_hooks('home_init',$ret);
@ -113,26 +117,32 @@ function manage_content(App $a) {
dbesc($id['uid']) dbesc($id['uid'])
); );
$identities[$key][thumb] = $thumb[0][thumb]; $identities[$key]['thumb'] = $thumb[0]['thumb'];
$identities[$key]['selected'] = (($id['nickname'] === $a->user['nickname']) ? true : false); $identities[$key]['selected'] = ($id['nickname'] === $a->user['nickname']);
$notifications = 0; $notifications = 0;
$r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))", $r = q("SELECT DISTINCT(`parent`) FROM `notify` WHERE `uid` = %d AND NOT `seen` AND NOT (`type` IN (%d, %d))",
intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL)); intval($id['uid']), intval(NOTIFY_INTRO), intval(NOTIFY_MAIL));
if ($r)
if (dbm::is_result($r)) {
$notifications = sizeof($r); $notifications = sizeof($r);
}
$r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`", $r = q("SELECT DISTINCT(`convid`) FROM `mail` WHERE `uid` = %d AND NOT `seen`",
intval($id['uid'])); intval($id['uid']));
if ($r)
if (dbm::is_result($r)) {
$notifications = $notifications + sizeof($r); $notifications = $notifications + sizeof($r);
}
$r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d", $r = q("SELECT COUNT(*) AS `introductions` FROM `intro` WHERE NOT `blocked` AND NOT `ignore` AND `uid` = %d",
intval($id['uid'])); intval($id['uid']));
if ($r)
if (dbm::is_result($r)) {
$notifications = $notifications + $r[0]["introductions"]; $notifications = $notifications + $r[0]["introductions"];
}
$identities[$key]['notifications'] = $notifications; $identities[$key]['notifications'] = $notifications;
} }

View file

@ -6,7 +6,7 @@ function network_init(App $a) {
} }
$is_a_date_query = false; $is_a_date_query = false;
if (x($_GET['cid']) && intval($_GET['cid']) != 0) { if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
$cid = $_GET['cid']; $cid = $_GET['cid'];
} }
@ -103,20 +103,23 @@ function network_init(App $a) {
} }
} }
if(x($_GET['nets']) && $_GET['nets'] === 'all') // If nets is set to all, unset it
if (x($_GET, 'nets') && $_GET['nets'] === 'all') {
unset($_GET['nets']); unset($_GET['nets']);
}
$group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0); $group_id = (($a->argc > 1 && is_numeric($a->argv[1])) ? intval($a->argv[1]) : 0);
set_pconfig(local_user(), 'network.view', 'group.selected', $group_id); set_pconfig(local_user(), 'network.view', 'group.selected', $group_id);
require_once('include/group.php'); require_once 'include/group.php';
require_once('include/contact_widgets.php'); require_once 'include/contact_widgets.php';
require_once('include/items.php'); require_once 'include/items.php';
require_once('include/ForumManager.php'); require_once 'include/ForumManager.php';
if(! x($a->page,'aside')) if (! x($a->page, 'aside')) {
$a->page['aside'] = ''; $a->page['aside'] = '';
}
$search = ((x($_GET, 'search')) ? escape_tags($_GET['search']) : ''); $search = ((x($_GET, 'search')) ? escape_tags($_GET['search']) : '');
@ -157,8 +160,9 @@ function network_init(App $a) {
function saved_searches($search) { function saved_searches($search) {
if(! feature_enabled(local_user(),'savedsearch')) if (! feature_enabled(local_user(),'savedsearch')) {
return ''; return '';
}
$a = get_app(); $a = get_app();

View file

@ -1,21 +1,22 @@
<?php <?php
require_once('include/Photo.php'); require_once 'include/Photo.php';
require_once('include/photos.php'); require_once 'include/photos.php';
require_once('include/items.php'); require_once 'include/items.php';
require_once('include/acl_selectors.php'); require_once 'include/acl_selectors.php';
require_once('include/bbcode.php'); require_once 'include/bbcode.php';
require_once('include/security.php'); require_once 'include/security.php';
require_once('include/redir.php'); require_once 'include/redir.php';
require_once('include/tags.php'); require_once 'include/tags.php';
require_once('include/threads.php'); require_once 'include/threads.php';
require_once('include/Probe.php'); require_once 'include/Probe.php';
use \Friendica\Core\Config; use \Friendica\Core\Config;
function photos_init(App $a) { function photos_init(App $a) {
if ($a->argc > 1) if ($a->argc > 1) {
auto_redir($a, $a->argv[1]); auto_redir($a, $a->argv[1]);
}
if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) { if ((get_config('system', 'block_public')) && (! local_user()) && (! remote_user())) {
return; return;
@ -29,8 +30,9 @@ function photos_init(App $a) {
dbesc($nick) dbesc($nick)
); );
if (! count($user)) if (! dbm::is_result($user)) {
return; return;
}
$a->data['user'] = $user[0]; $a->data['user'] = $user[0];
$a->profile_uid = $user[0]['uid']; $a->profile_uid = $user[0]['uid'];
@ -59,8 +61,9 @@ function photos_init(App $a) {
if ($albums) { if ($albums) {
$a->data['albums'] = $albums; $a->data['albums'] = $albums;
if ($albums_visible) if ($albums_visible) {
$ret['success'] = true; $ret['success'] = true;
}
$ret['albums'] = array(); $ret['albums'] = array();
foreach ($albums as $k => $album) { foreach ($albums as $k => $album) {
@ -80,8 +83,9 @@ function photos_init(App $a) {
$albums = $ret; $albums = $ret;
if (local_user() && $a->data['user']['uid'] == local_user()) if (local_user() && $a->data['user']['uid'] == local_user()) {
$can_post = true; $can_post = true;
}
if ($albums['success']) { if ($albums['success']) {
$photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array( $photo_albums_widget = replace_macros(get_markup_template('photo_albums.tpl'), array(
@ -96,8 +100,9 @@ function photos_init(App $a) {
} }
if (! x($a->page,'aside')) if (! x($a->page, 'aside')) {
$a->page['aside'] = ''; $a->page['aside'] = '';
}
$a->page['aside'] .= $vcard_widget; $a->page['aside'] .= $vcard_widget;
$a->page['aside'] .= $photo_albums_widget; $a->page['aside'] .= $photo_albums_widget;
@ -130,9 +135,9 @@ function photos_post(App $a) {
$page_owner_uid = $a->data['user']['uid']; $page_owner_uid = $a->data['user']['uid'];
$community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false); $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
if ((local_user()) && (local_user() == $page_owner_uid)) if ((local_user()) && (local_user() == $page_owner_uid)) {
$can_post = true; $can_post = true;
else { } else {
if ($community_page && remote_user()) { if ($community_page && remote_user()) {
$contact_id = 0; $contact_id = 0;
if (is_array($_SESSION['remote'])) { if (is_array($_SESSION['remote'])) {
@ -295,10 +300,11 @@ function photos_post(App $a) {
// send the notification upstream/downstream as the case may be // send the notification upstream/downstream as the case may be
if ($rr['visible']) if ($rr['visible']) {
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
} }
} }
}
// Update the photo albums cache // Update the photo albums cache
photo_albums($page_owner_uid, true); photo_albums($page_owner_uid, true);
@ -371,10 +377,11 @@ function photos_post(App $a) {
// Update the photo albums cache // Update the photo albums cache
photo_albums($page_owner_uid, true); photo_albums($page_owner_uid, true);
if ($i[0]['visible']) if ($i[0]['visible']) {
proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id); proc_run(PRIORITY_HIGH, "include/notifier.php", "drop", $drop_id);
} }
} }
}
goaway('photos/' . $a->data['user']['nickname']); goaway('photos/' . $a->data['user']['nickname']);
return; // NOTREACHED return; // NOTREACHED
@ -394,15 +401,16 @@ function photos_post(App $a) {
$resource_id = $a->argv[2]; $resource_id = $a->argv[2];
if (! strlen($albname)) if (! strlen($albname)) {
$albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); $albname = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
}
if ((x($_POST,'rotate') !== false) && if ((x($_POST,'rotate') !== false) &&
( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) { ( (intval($_POST['rotate']) == 1) || (intval($_POST['rotate']) == 2) )) {
logger('rotate'); logger('rotate');
$r = q("select * from photo where `resource-id` = '%s' and uid = %d and scale = 0 limit 1", $r = q("SELECT * FROM `photo` WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0 LIMIT 1",
dbesc($resource_id), dbesc($resource_id),
intval($page_owner_uid) intval($page_owner_uid)
); );
@ -415,7 +423,7 @@ function photos_post(App $a) {
$width = $ph->getWidth(); $width = $ph->getWidth();
$height = $ph->getHeight(); $height = $ph->getHeight();
$x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 0", $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 0",
dbesc($ph->imageString()), dbesc($ph->imageString()),
intval($height), intval($height),
intval($width), intval($width),
@ -428,7 +436,7 @@ function photos_post(App $a) {
$width = $ph->getWidth(); $width = $ph->getWidth();
$height = $ph->getHeight(); $height = $ph->getHeight();
$x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 1", $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 1",
dbesc($ph->imageString()), dbesc($ph->imageString()),
intval($height), intval($height),
intval($width), intval($width),
@ -442,7 +450,7 @@ function photos_post(App $a) {
$width = $ph->getWidth(); $width = $ph->getWidth();
$height = $ph->getHeight(); $height = $ph->getHeight();
$x = q("update photo set data = '%s', height = %d, width = %d where `resource-id` = '%s' and uid = %d and scale = 2", $x = q("UPDATE `photo` SET `data` = '%s', `height` = %d, `width` = %d WHERE `resource-id` = '%s' AND `uid` = %d AND `scale` = 2",
dbesc($ph->imageString()), dbesc($ph->imageString()),
intval($height), intval($height),
intval($width), intval($width),
@ -458,7 +466,7 @@ function photos_post(App $a) {
dbesc($resource_id), dbesc($resource_id),
intval($page_owner_uid) intval($page_owner_uid)
); );
if (count($p)) { if (dbm::is_result($p)) {
$ext = $phototypes[$p[0]['type']]; $ext = $phototypes[$p[0]['type']];
$r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d", $r = q("UPDATE `photo` SET `desc` = '%s', `album` = '%s', `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s' WHERE `resource-id` = '%s' AND `uid` = %d",
dbesc($desc), dbesc($desc),
@ -470,6 +478,7 @@ function photos_post(App $a) {
dbesc($resource_id), dbesc($resource_id),
intval($page_owner_uid) intval($page_owner_uid)
); );
// Update the photo albums cache if album name was changed // Update the photo albums cache if album name was changed
if ($albname !== $origaname) { if ($albname !== $origaname) {
photo_albums($page_owner_uid, true); photo_albums($page_owner_uid, true);
@ -479,8 +488,9 @@ function photos_post(App $a) {
/* Don't make the item visible if the only change was the album name */ /* Don't make the item visible if the only change was the album name */
$visibility = 0; $visibility = 0;
if ($p[0]['desc'] !== $desc || strlen($rawtags)) if ($p[0]['desc'] !== $desc || strlen($rawtags)) {
$visibility = 1; $visibility = 1;
}
if (! $item_id) { if (! $item_id) {
@ -540,16 +550,18 @@ function photos_post(App $a) {
// if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag // if the new tag doesn't have a namespace specifier (@foo or #foo) give it a hashtag
$x = substr($rawtags,0,1); $x = substr($rawtags,0,1);
if ($x !== '@' && $x !== '#') if ($x !== '@' && $x !== '#') {
$rawtags = '#' . $rawtags; $rawtags = '#' . $rawtags;
}
$taginfo = array(); $taginfo = array();
$tags = get_tags($rawtags); $tags = get_tags($rawtags);
if (count($tags)) { if (count($tags)) {
foreach ($tags as $tag) { foreach ($tags as $tag) {
if (isset($profile)) if (isset($profile)) {
unset($profile); unset($profile);
}
if (strpos($tag, '@') === 0) { if (strpos($tag, '@') === 0) {
$name = substr($tag,1); $name = substr($tag,1);
if ((strpos($name, '@')) || (strpos($name, 'http://'))) { if ((strpos($name, '@')) || (strpos($name, 'http://'))) {
@ -557,12 +569,14 @@ function photos_post(App $a) {
$links = @Probe::lrdd($name); $links = @Probe::lrdd($name);
if (count($links)) { if (count($links)) {
foreach ($links as $link) { foreach ($links as $link) {
if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
$profile = $link['@attributes']['href']; $profile = $link['@attributes']['href'];
}
if ($link['@attributes']['rel'] === 'salmon') { if ($link['@attributes']['rel'] === 'salmon') {
$salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']); $salmon = '$url:' . str_replace(',', '%sc', $link['@attributes']['href']);
if (strlen($inform)) if (strlen($inform)) {
$inform .= ','; $inform .= ',';
}
$inform .= $salmon; $inform .= $salmon;
} }
} }
@ -572,8 +586,9 @@ function photos_post(App $a) {
$newname = $name; $newname = $name;
$alias = ''; $alias = '';
$tagcid = 0; $tagcid = 0;
if (strrpos($newname,'+')) if (strrpos($newname, '+')) {
$tagcid = intval(substr($newname, strrpos($newname, '+') + 1)); $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
}
if ($tagcid) { if ($tagcid) {
$r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1",
@ -589,7 +604,7 @@ function photos_post(App $a) {
intval($page_owner_uid) intval($page_owner_uid)
); );
if (! $r) { if (! dbm::is_result($r)) {
//select someone by attag or nick and the name passed in //select someone by attag or nick and the name passed in
$r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name), dbesc($name),
@ -598,35 +613,26 @@ function photos_post(App $a) {
); );
} }
} }
/* elseif (strstr($name,'_') || strstr($name,' ')) {
$newname = str_replace('_',' ',$name);
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname),
intval($page_owner_uid)
);
} else {
$r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1",
dbesc($name),
dbesc($name),
intval($page_owner_uid)
);
}*/
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$newname = $r[0]['name']; $newname = $r[0]['name'];
$profile = $r[0]['url']; $profile = $r[0]['url'];
$notify = 'cid:' . $r[0]['id']; $notify = 'cid:' . $r[0]['id'];
if (strlen($inform)) if (strlen($inform)) {
$inform .= ','; $inform .= ',';
}
$inform .= $notify; $inform .= $notify;
} }
} }
if ($profile) { if ($profile) {
if (substr($notify,0,4) === 'cid:') if (substr($notify, 0, 4) === 'cid:') {
$taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]'); $taginfo[] = array($newname, $profile, $notify, $r[0], '@[url=' . str_replace(',','%2c',$profile) . ']' . $newname . '[/url]');
else } else {
$taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]'); $taginfo[] = array($newname, $profile, $notify, null, $str_tags .= '@[url=' . $profile . ']' . $newname . '[/url]');
if (strlen($str_tags)) }
if (strlen($str_tags)) {
$str_tags .= ','; $str_tags .= ',';
}
$profile = str_replace(',', '%2c', $profile); $profile = str_replace(',', '%2c', $profile);
$str_tags .= '@[url='.$profile.']'.$newname.'[/url]'; $str_tags .= '@[url='.$profile.']'.$newname.'[/url]';
} }
@ -638,13 +644,15 @@ function photos_post(App $a) {
} }
$newtag = $old_tag; $newtag = $old_tag;
if (strlen($newtag) && strlen($str_tags)) if (strlen($newtag) && strlen($str_tags)) {
$newtag .= ','; $newtag .= ',';
}
$newtag .= $str_tags; $newtag .= $str_tags;
$newinform = $old_inform; $newinform = $old_inform;
if (strlen($newinform) && strlen($inform)) if (strlen($newinform) && strlen($inform)) {
$newinform .= ','; $newinform .= ',';
}
$newinform .= $inform; $newinform .= $inform;
$r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d", $r = q("UPDATE `item` SET `tag` = '%s', `inform` = '%s', `edited` = '%s', `changed` = '%s' WHERE `id` = %d AND `uid` = %d",
@ -707,8 +715,9 @@ function photos_post(App $a) {
$arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>'; $arr['object'] = '<object><type>' . ACTIVITY_OBJ_PERSON . '</type><title>' . $tagged[0] . '</title><id>' . $tagged[1] . '/' . $tagged[0] . '</id>';
$arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n"); $arr['object'] .= '<link>' . xmlify('<link rel="alternate" type="text/html" href="' . $tagged[1] . '" />' . "\n");
if ($tagged[3]) if ($tagged[3]) {
$arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n"); $arr['object'] .= xmlify('<link rel="photo" type="'.$p[0]['type'].'" href="' . $tagged[3]['photo'] . '" />' . "\n");
}
$arr['object'] .= '</link></object>' . "\n"; $arr['object'] .= '</link></object>' . "\n";
$arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>' $arr['target'] = '<target><type>' . ACTIVITY_OBJ_IMAGE . '</type><title>' . $p[0]['desc'] . '</title><id>'
@ -720,9 +729,7 @@ function photos_post(App $a) {
proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id); proc_run(PRIORITY_HIGH, "include/notifier.php", "tag", $item_id);
} }
} }
} }
} }
goaway($_SESSION['photo_return']); goaway($_SESSION['photo_return']);
return; // NOTREACHED return; // NOTREACHED
@ -745,33 +752,34 @@ function photos_post(App $a) {
logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG); logger('mod/photos.php: photos_post(): album= ' . $album . ' newalbum= ' . $newalbum , LOGGER_DEBUG);
if (! strlen($album)) { if (! strlen($album)) {
if (strlen($newalbum)) if (strlen($newalbum)) {
$album = $newalbum; $album = $newalbum;
else } else {
$album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y'); $album = datetime_convert('UTC',date_default_timezone_get(),'now', 'Y');
} }
}
/** /*
*
* We create a wall item for every photo, but we don't want to * We create a wall item for every photo, but we don't want to
* overwhelm the data stream with a hundred newly uploaded photos. * overwhelm the data stream with a hundred newly uploaded photos.
* So we will make the first photo uploaded to this album in the last several hours * So we will make the first photo uploaded to this album in the last several hours
* visible by default, the rest will become visible over time when and if * visible by default, the rest will become visible over time when and if
* they acquire comments, likes, dislikes, and/or tags * they acquire comments, likes, dislikes, and/or tags
*
*/ */
$r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ", $r = q("SELECT * FROM `photo` WHERE `album` = '%s' AND `uid` = %d AND `created` > UTC_TIMESTAMP() - INTERVAL 3 HOUR ",
dbesc($album), dbesc($album),
intval($page_owner_uid) intval($page_owner_uid)
); );
if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) if ((! dbm::is_result($r)) || ($album == t('Profile Photos'))) {
$visible = 1; $visible = 1;
else } else {
$visible = 0; $visible = 0;
}
if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') if (intval($_REQUEST['not_visible']) || $_REQUEST['not_visible'] === 'true') {
$visible = 0; $visible = 0;
}
$str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',', $_REQUEST['group_allow']))); $str_group_allow = perms2str(((is_array($_REQUEST['group_allow'])) ? $_REQUEST['group_allow'] : explode(',', $_REQUEST['group_allow'])));
$str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow']))); $str_contact_allow = perms2str(((is_array($_REQUEST['contact_allow'])) ? $_REQUEST['contact_allow'] : explode(',', $_REQUEST['contact_allow'])));
@ -793,7 +801,9 @@ function photos_post(App $a) {
$filesize = intval($_FILES['userfile']['size']); $filesize = intval($_FILES['userfile']['size']);
$type = $_FILES['userfile']['type']; $type = $_FILES['userfile']['type'];
} }
if ($type=="") $type=guess_image_type($filename); if ($type == "") {
$type = guess_image_type($filename);
}
logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG); logger('photos: upload: received file: ' . $filename . ' as ' . $src . ' ('. $type . ') ' . $filesize . ' bytes', LOGGER_DEBUG);
@ -823,7 +833,7 @@ function photos_post(App $a) {
$limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit'); $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
if ($limit) { if ($limit) {
$r = q("select sum(octet_length(data)) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", $r = q("SELECT SUM(OCTET_LENGTH(`data`)) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'",
intval($a->data['user']['uid']) intval($a->data['user']['uid'])
); );
$size = $r[0]['total']; $size = $r[0]['total'];
@ -852,10 +862,12 @@ function photos_post(App $a) {
@unlink($src); @unlink($src);
$max_length = get_config('system', 'max_image_length'); $max_length = get_config('system', 'max_image_length');
if (! $max_length) if (! $max_length) {
$max_length = MAX_IMAGE_LENGTH; $max_length = MAX_IMAGE_LENGTH;
if ($max_length > 0) }
if ($max_length > 0) {
$ph->scaleImage($max_length); $ph->scaleImage($max_length);
}
$width = $ph->getWidth(); $width = $ph->getWidth();
$height = $ph->getHeight(); $height = $ph->getHeight();
@ -891,6 +903,7 @@ function photos_post(App $a) {
$lat = $lon = null; $lat = $lon = null;
/// @TODO merge these 2 if() into one?
if ($exif && $exif['GPS']) { if ($exif && $exif['GPS']) {
if (feature_enabled($channel_id,'photo_location')) { if (feature_enabled($channel_id,'photo_location')) {
$lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']); $lat = getGps($exif['GPS']['GPSLatitude'], $exif['GPS']['GPSLatitudeRef']);
@ -900,8 +913,9 @@ function photos_post(App $a) {
$arr = array(); $arr = array();
if ($lat && $lon) if ($lat && $lon) {
$arr['coord'] = $lat . ' ' . $lon; $arr['coord'] = $lat . ' ' . $lon;
}
$arr['guid'] = get_guid(32); $arr['guid'] = get_guid(32);
$arr['uid'] = $page_owner_uid; $arr['uid'] = $page_owner_uid;
@ -934,20 +948,21 @@ function photos_post(App $a) {
// Update the photo albums cache // Update the photo albums cache
photo_albums($page_owner_uid, true); photo_albums($page_owner_uid, true);
if ($visible) if ($visible) {
proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id); proc_run(PRIORITY_HIGH, "include/notifier.php", 'wall-new', $item_id);
}
call_hooks('photo_post_end',intval($item_id)); call_hooks('photo_post_end',intval($item_id));
// addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook /*
// if they do not wish to be redirected * addon uploaders should call "killme()" [e.g. exit] within the photo_post_end hook
* if they do not wish to be redirected
*/
goaway($_SESSION['photo_return']); goaway($_SESSION['photo_return']);
// NOTREACHED // NOTREACHED
} }
function photos_content(App $a) { function photos_content(App $a) {
// URLs: // URLs:
@ -965,7 +980,6 @@ function photos_content(App $a) {
return; return;
} }
require_once('include/bbcode.php'); require_once('include/bbcode.php');
require_once('include/security.php'); require_once('include/security.php');
require_once('include/conversation.php'); require_once('include/conversation.php');
@ -986,15 +1000,17 @@ function photos_content(App $a) {
if ($a->argc > 3) { if ($a->argc > 3) {
$datatype = $a->argv[2]; $datatype = $a->argv[2];
$datum = $a->argv[3]; $datum = $a->argv[3];
} elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) } elseif (($a->argc > 2) && ($a->argv[2] === 'upload')) {
$datatype = 'upload'; $datatype = 'upload';
else } else {
$datatype = 'summary'; $datatype = 'summary';
}
if ($a->argc > 4) if ($a->argc > 4) {
$cmd = $a->argv[4]; $cmd = $a->argv[4];
else } else {
$cmd = 'view'; $cmd = 'view';
}
// //
// Setup permissions structures // Setup permissions structures
@ -1010,9 +1026,9 @@ function photos_content(App $a) {
$community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false); $community_page = (($a->data['user']['page-flags'] == PAGE_COMMUNITY) ? true : false);
if ((local_user()) && (local_user() == $owner_uid)) if ((local_user()) && (local_user() == $owner_uid)) {
$can_post = true; $can_post = true;
else { } else {
if ($community_page && remote_user()) { if ($community_page && remote_user()) {
if (is_array($_SESSION['remote'])) { if (is_array($_SESSION['remote'])) {
foreach ($_SESSION['remote'] as $v) { foreach ($_SESSION['remote'] as $v) {
@ -1063,6 +1079,7 @@ function photos_content(App $a) {
} }
} }
/// @TODO merge these 2 if() into one?
if (! $remote_contact) { if (! $remote_contact) {
if (local_user()) { if (local_user()) {
$contact_id = $_SESSION['cid']; $contact_id = $_SESSION['cid'];
@ -1103,8 +1120,9 @@ function photos_content(App $a) {
$albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>'; $albumselect .= '<option value="" ' . ((! $selname) ? ' selected="selected" ' : '') . '>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</option>';
if (count($a->data['albums'])) { if (count($a->data['albums'])) {
foreach ($a->data['albums'] as $album) { foreach ($a->data['albums'] as $album) {
if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) if (($album['album'] === '') || ($album['album'] === 'Contact Photos') || ($album['album'] === t('Contact Photos'))) {
continue; continue;
}
$selected = (($selname === $album['album']) ? ' selected="selected" ' : ''); $selected = (($selname === $album['album']) ? ' selected="selected" ' : '');
$albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>'; $albumselect .= '<option value="' . $album['album'] . '"' . $selected . '>' . $album['album'] . '</option>';
} }
@ -1116,7 +1134,6 @@ function photos_content(App $a) {
'addon_text' => $uploader, 'addon_text' => $uploader,
'default_upload' => true); 'default_upload' => true);
call_hooks('photo_upload_form',$ret); call_hooks('photo_upload_form',$ret);
$default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array()); $default_upload_box = replace_macros(get_markup_template('photos_default_uploader_box.tpl'), array());
@ -1128,7 +1145,7 @@ function photos_content(App $a) {
$limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit'); $limit = service_class_fetch($a->data['user']['uid'], 'photo_upload_limit');
if ($limit !== false) { if ($limit !== false) {
$r = q("select sum(datasize) as total from photo where uid = %d and scale = 0 and album != 'Contact Photos' ", $r = q("SELECT SUM(`datasize`) AS `total` FROM `photo` WHERE `uid` = %d AND `scale` = 0 AND `album` != 'Contact Photos'",
intval($a->data['user']['uid']) intval($a->data['user']['uid'])
); );
$usage_message = sprintf(t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 ); $usage_message = sprintf(t("You have used %1$.2f Mbytes of %2$.2f Mbytes photo storage."), $r[0]['total'] / 1024000, $limit / 1024000 );
@ -1137,22 +1154,25 @@ function photos_content(App $a) {
// Private/public post links for the non-JS ACL form // Private/public post links for the non-JS ACL form
$private_post = 1; $private_post = 1;
if ($_REQUEST['public']) if ($_REQUEST['public']) {
$private_post = 0; $private_post = 0;
}
$query_str = $a->query_string; $query_str = $a->query_string;
if (strpos($query_str, 'public=1') !== false) if (strpos($query_str, 'public=1') !== false) {
$query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
}
// I think $a->query_string may never have ? in it, but I could be wrong /*
// It looks like it's from the index.php?q=[etc] rewrite that the web * I think $a->query_string may never have ? in it, but I could be wrong
// server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 * It looks like it's from the index.php?q=[etc] rewrite that the web
if (strpos($query_str, '?') === false) * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
*/
if (strpos($query_str, '?') === false) {
$public_post_link = '?public=1'; $public_post_link = '?public=1';
else } else {
$public_post_link = '&public=1'; $public_post_link = '&public=1';
}
$tpl = get_markup_template('photos_upload.tpl'); $tpl = get_markup_template('photos_upload.tpl');
@ -1213,10 +1233,12 @@ function photos_content(App $a) {
$a->set_pager_itemspage(20); $a->set_pager_itemspage(20);
} }
if ($_GET['order'] === 'posted') /// @TODO I have seen this many times, maybe generalize it script-wide and encapsulate it?
if ($_GET['order'] === 'posted') {
$order = 'ASC'; $order = 'ASC';
else } else {
$order = 'DESC'; $order = 'DESC';
}
$r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s' $r = q("SELECT `resource-id`, `id`, `filename`, type, max(`scale`) AS `scale`, `desc` FROM `photo` WHERE `uid` = %d AND `album` = '%s'
AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d", AND `scale` <= 4 $sql_extra GROUP BY `resource-id` ORDER BY `created` $order LIMIT %d , %d",
@ -1249,27 +1271,27 @@ function photos_content(App $a) {
} }
} }
} else { } else {
if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos'))) { if (($album !== t('Profile Photos')) && ($album !== 'Contact Photos') && ($album !== t('Contact Photos')) && $can_post) {
if ($can_post) {
$edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit'); $edit = array(t('Edit Album'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '/edit');
} }
} }
}
if ($_GET['order'] === 'posted') if ($_GET['order'] === 'posted') {
$order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album)); $order = array(t('Show Newest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album));
else } else {
$order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted'); $order = array(t('Show Oldest First'), 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($album) . '?f=&order=posted');
}
$photos = array(); $photos = array();
if (dbm::is_result($r)) if (dbm::is_result($r))
$twist = 'rotright'; $twist = 'rotright';
foreach ($r as $rr) { foreach ($r as $rr) {
if ($twist == 'rotright') if ($twist == 'rotright') {
$twist = 'rotleft'; $twist = 'rotleft';
else } else {
$twist = 'rotright'; $twist = 'rotright';
}
$ext = $phototypes[$rr['type']]; $ext = $phototypes[$rr['type']];
@ -1310,10 +1332,9 @@ function photos_content(App $a) {
} }
/** /*
* Display one photo * Display one photo
*/ */
if ($datatype === 'image') { if ($datatype === 'image') {
//$o = ''; //$o = '';
@ -1325,16 +1346,17 @@ function photos_content(App $a) {
dbesc($datum) dbesc($datum)
); );
if (! count($ph)) { if (! dbm::is_result($ph)) {
$ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s' $ph = q("SELECT `id` FROM `photo` WHERE `uid` = %d AND `resource-id` = '%s'
LIMIT 1", LIMIT 1",
intval($owner_uid), intval($owner_uid),
dbesc($datum) dbesc($datum)
); );
if (count($ph)) if (dbm::is_result($ph)) {
notice(t('Permission denied. Access to this item may be restricted.')); notice(t('Permission denied. Access to this item may be restricted.'));
else } else {
notice(t('Photo not available') . EOL ); notice(t('Photo not available') . EOL );
}
return; return;
} }
@ -1356,15 +1378,17 @@ function photos_content(App $a) {
intval($owner_uid) intval($owner_uid)
); );
if (count($prvnxt)) { if (dbm::is_result($prvnxt)) {
for($z = 0; $z < count($prvnxt); $z++) { foreach ($prvnxt as $z => $entry) {
if ($prvnxt[$z]['resource-id'] == $ph[0]['resource-id']) { if ($entry['resource-id'] == $ph[0]['resource-id']) {
$prv = $z - 1; $prv = $z - 1;
$nxt = $z + 1; $nxt = $z + 1;
if ($prv < 0) if ($prv < 0) {
$prv = count($prvnxt) - 1; $prv = count($prvnxt) - 1;
if ($nxt >= count($prvnxt)) }
if ($nxt >= count($prvnxt)) {
$nxt = 0; $nxt = 0;
}
break; break;
} }
} }
@ -1387,8 +1411,8 @@ function photos_content(App $a) {
} }
$album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']); $album_link = 'photos/' . $a->data['user']['nickname'] . '/album/' . bin2hex($ph[0]['album']);
$tools = Null; $tools = null;
$lock = Null; $lock = null;
if ($can_post && ($ph[0]['uid'] == $owner_uid)) { if ($can_post && ($ph[0]['uid'] == $owner_uid)) {
$tools = array( $tools = array(
@ -1426,8 +1450,9 @@ function photos_content(App $a) {
'filename' => $hires['filename'], 'filename' => $hires['filename'],
); );
if ($nextlink) if ($nextlink) {
$nextlink = array($nextlink, '<div class="icon next"></div>'); $nextlink = array($nextlink, '<div class="icon next"></div>');
}
// Do we have an item for this photo? // Do we have an item for this photo?
@ -1444,8 +1469,9 @@ function photos_content(App $a) {
$map = null; $map = null;
if (count($linked_items)) { if (dbm::is_result($linked_items)) {
$link_item = $linked_items[0]; $link_item = $linked_items[0];
$r = qu("SELECT COUNT(*) AS `total` $r = qu("SELECT COUNT(*) AS `total`
FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` FROM `item` LEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id`
WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0 WHERE `parent-uri` = '%s' AND `uri` != '%s' AND `item`.`deleted` = 0 and `item`.`moderated` = 0
@ -1458,8 +1484,9 @@ function photos_content(App $a) {
); );
if (dbm::is_result($r)) if (dbm::is_result($r)) {
$a->set_pager_total($r[0]['total']); $a->set_pager_total($r[0]['total']);
}
$r = qu("SELECT `item`.*, `item`.`id` AS `item_id`, $r = qu("SELECT `item`.*, `item`.`id` AS `item_id`,
@ -1493,15 +1520,16 @@ function photos_content(App $a) {
} }
} }
$tags=Null; $tags = null;
if (count($linked_items) && strlen($link_item['tag'])) { if (count($linked_items) && strlen($link_item['tag'])) {
$arr = explode(',', $link_item['tag']); $arr = explode(',', $link_item['tag']);
// parse tags and add links // parse tags and add links
$tag_str = ''; $tag_str = '';
foreach ($arr as $t) { foreach ($arr as $t) {
if (strlen($tag_str)) if (strlen($tag_str)) {
$tag_str .= ', '; $tag_str .= ', ';
}
$tag_str .= bbcode($t); $tag_str .= bbcode($t);
} }
$tags = array(t('Tags: '), $tag_str); $tags = array(t('Tags: '), $tag_str);
@ -1518,21 +1546,25 @@ function photos_content(App $a) {
// Private/public post links for the non-JS ACL form // Private/public post links for the non-JS ACL form
$private_post = 1; $private_post = 1;
if ($_REQUEST['public']) if ($_REQUEST['public']) {
$private_post = 0; $private_post = 0;
}
$query_str = $a->query_string; $query_str = $a->query_string;
if (strpos($query_str, 'public=1') !== false) if (strpos($query_str, 'public=1') !== false) {
$query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str); $query_str = str_replace(array('?public=1', '&public=1'), array('', ''), $query_str);
}
// I think $a->query_string may never have ? in it, but I could be wrong /*
// It looks like it's from the index.php?q=[etc] rewrite that the web * I think $a->query_string may never have ? in it, but I could be wrong
// server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61 * It looks like it's from the index.php?q=[etc] rewrite that the web
if (strpos($query_str, '?') === false) * server does, which converts any ? to &, e.g. suggest&ignore=61 for suggest?ignore=61
*/
if (strpos($query_str, '?') === false) {
$public_post_link = '?public=1'; $public_post_link = '?public=1';
else } else {
$public_post_link = '&public=1'; $public_post_link = '&public=1';
}
if ($a->theme['template_engine'] === 'internal') { if ($a->theme['template_engine'] === 'internal') {
$album_e = template_escape($ph[0]['album']); $album_e = template_escape($ph[0]['album']);
@ -1596,8 +1628,7 @@ function photos_content(App $a) {
$comments = ''; $comments = '';
if (! dbm::is_result($r)) { if (! dbm::is_result($r)) {
if ($can_post || can_write_wall($a,$owner_uid)) { if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
if ($link_item['last-child']) {
$comments .= replace_macros($cmnt_tpl, array( $comments .= replace_macros($cmnt_tpl, array(
'$return_path' => '', '$return_path' => '',
'$jsreload' => $return_url, '$jsreload' => $return_url,
@ -1617,7 +1648,6 @@ function photos_content(App $a) {
)); ));
} }
} }
}
$alike = array(); $alike = array();
$dlike = array(); $dlike = array();
@ -1630,8 +1660,6 @@ function photos_content(App $a) {
'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title')) 'attendyes' => array('title' => t('Attending','title')), 'attendno' => array('title' => t('Not attending','title')), 'attendmaybe' => array('title' => t('Might attend','title'))
); );
// display comments // display comments
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
@ -1642,10 +1670,7 @@ function photos_content(App $a) {
$like = ((x($conv_responses['like'], $link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : ''); $like = ((x($conv_responses['like'], $link_item['uri'])) ? format_like($conv_responses['like'][$link_item['uri']], $conv_responses['like'][$link_item['uri'] . '-l'], 'like',$link_item['id']) : '');
$dislike = ((x($conv_responses['dislike'], $link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : ''); $dislike = ((x($conv_responses['dislike'], $link_item['uri'])) ? format_like($conv_responses['dislike'][$link_item['uri']], $conv_responses['dislike'][$link_item['uri'] . '-l'], 'dislike',$link_item['id']) : '');
if (($can_post || can_write_wall($a, $owner_uid)) && $link_item['last-child']) {
if ($can_post || can_write_wall($a,$owner_uid)) {
if ($link_item['last-child']) {
$comments .= replace_macros($cmnt_tpl,array( $comments .= replace_macros($cmnt_tpl,array(
'$return_path' => '', '$return_path' => '',
'$jsreload' => $return_url, '$jsreload' => $return_url,
@ -1664,7 +1689,6 @@ function photos_content(App $a) {
'$rand_num' => random_digits(12) '$rand_num' => random_digits(12)
)); ));
} }
}
foreach ($r as $item) { foreach ($r as $item) {
@ -1694,8 +1718,6 @@ function photos_content(App $a) {
$profile_link = $profile_url; $profile_link = $profile_url;
$dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user())); $dropping = (($item['contact-id'] == $contact_id) || ($item['uid'] == local_user()));
$drop = array( $drop = array(
'dropping' => $dropping, 'dropping' => $dropping,
@ -1704,7 +1726,6 @@ function photos_content(App $a) {
'delete' => t('Delete'), 'delete' => t('Delete'),
); );
if ($a->theme['template_engine'] === 'internal') { if ($a->theme['template_engine'] === 'internal') {
$name_e = template_escape($profile_name); $name_e = template_escape($profile_name);
$title_e = template_escape($item['title']); $title_e = template_escape($item['title']);
@ -1729,9 +1750,7 @@ function photos_content(App $a) {
'$comment' => $comment '$comment' => $comment
)); ));
if ($can_post || can_write_wall($a,$owner_uid)) { if (($can_post || can_write_wall($a, $owner_uid)) && $item['last-child']) {
if ($item['last-child']) {
$comments .= replace_macros($cmnt_tpl, array( $comments .= replace_macros($cmnt_tpl, array(
'$return_path' => '', '$return_path' => '',
'$jsreload' => $return_url, '$jsreload' => $return_url,
@ -1752,15 +1771,15 @@ function photos_content(App $a) {
} }
} }
} }
}
$paginate = paginate($a); $paginate = paginate($a);
} }
$response_verbs = array('like'); $response_verbs = array('like');
if (feature_enabled($owner_uid,'dislike')) if (feature_enabled($owner_uid, 'dislike')) {
$response_verbs[] = 'dislike'; $response_verbs[] = 'dislike';
}
$responses = get_responses($conv_responses,$response_verbs, '', $link_item); $responses = get_responses($conv_responses,$response_verbs, '', $link_item);
$photo_tpl = get_markup_template('photo_view.tpl'); $photo_tpl = get_markup_template('photo_view.tpl');

View file

@ -34,24 +34,22 @@ function profiles_init(App $a) {
intval($a->argv[2]), intval($a->argv[2]),
intval(local_user()) intval(local_user())
); );
if($r) if (dbm::is_result($r)) {
info(t('Profile deleted.').EOL); info(t('Profile deleted.').EOL);
}
goaway('profiles'); goaway('profiles');
return; // NOTREACHED return; // NOTREACHED
} }
if (($a->argc > 1) && ($a->argv[1] === 'new')) { if (($a->argc > 1) && ($a->argv[1] === 'new')) {
check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't'); check_form_security_token_redirectOnErr('/profiles', 'profile_new', 't');
$r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
intval(local_user())); intval(local_user()));
$num_profiles = count($r0);
$num_profiles = (dbm::is_result($r0) ? count($r0) : 0);
$name = t('Profile-') . ($num_profiles + 1); $name = t('Profile-') . ($num_profiles + 1);
@ -73,8 +71,9 @@ function profiles_init(App $a) {
); );
info( t('New profile created.') . EOL); info( t('New profile created.') . EOL);
if(count($r3) == 1) if (dbm::is_result($r3) && count($r3) == 1) {
goaway('profiles/' . $r3[0]['id']); goaway('profiles/' . $r3[0]['id']);
}
goaway('profiles'); goaway('profiles');
} }
@ -85,7 +84,8 @@ function profiles_init(App $a) {
$r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d", $r0 = q("SELECT `id` FROM `profile` WHERE `uid` = %d",
intval(local_user())); intval(local_user()));
$num_profiles = count($r0);
$num_profiles = (dbm::is_result($r0) ? count($r0) : 0);
$name = t('Profile-') . ($num_profiles + 1); $name = t('Profile-') . ($num_profiles + 1);
$r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1", $r1 = q("SELECT * FROM `profile` WHERE `uid` = %d AND `id` = %d LIMIT 1",
@ -116,8 +116,9 @@ function profiles_init(App $a) {
dbesc($name) dbesc($name)
); );
info( t('New profile created.') . EOL); info( t('New profile created.') . EOL);
if ((dbm::is_result($r3)) && (count($r3) == 1)) if ((dbm::is_result($r3)) && (count($r3) == 1)) {
goaway('profiles/'.$r3[0]['id']); goaway('profiles/'.$r3[0]['id']);
}
goaway('profiles'); goaway('profiles');
@ -151,9 +152,10 @@ function profile_clean_keywords($keywords) {
foreach ($keywords as $keyword) { foreach ($keywords as $keyword) {
$keyword = trim(strtolower($keyword)); $keyword = trim(strtolower($keyword));
$keyword = trim($keyword, "#"); $keyword = trim($keyword, "#");
if ($keyword != "") if ($keyword != "") {
$cleaned[] = $keyword; $cleaned[] = $keyword;
} }
}
$keywords = implode(", ", $cleaned); $keywords = implode(", ", $cleaned);
@ -176,7 +178,7 @@ function profiles_post(App $a) {
intval($a->argv[1]), intval($a->argv[1]),
intval(local_user()) intval(local_user())
); );
if(! count($orig)) { if (! dbm::is_result($orig)) {
notice( t('Profile not found.') . EOL); notice( t('Profile not found.') . EOL);
return; return;
} }
@ -194,19 +196,22 @@ function profiles_post(App $a) {
$dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated? $dob = $_POST['dob'] ? escape_tags(trim($_POST['dob'])) : '0000-00-00'; // FIXME: Needs to be validated?
$y = substr($dob, 0, 4); $y = substr($dob, 0, 4);
if((! ctype_digit($y)) || ($y < 1900)) if ((! ctype_digit($y)) || ($y < 1900)) {
$ignore_year = true; $ignore_year = true;
else } else {
$ignore_year = false; $ignore_year = false;
}
if ($dob != '0000-00-00') { if ($dob != '0000-00-00') {
if (strpos($dob, '0000-') === 0) { if (strpos($dob, '0000-') === 0) {
$ignore_year = true; $ignore_year = true;
$dob = substr($dob, 5); $dob = substr($dob, 5);
} }
$dob = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d')); $dob = datetime_convert('UTC', 'UTC', (($ignore_year) ? '1900-' . $dob : $dob), (($ignore_year) ? 'm-d' : 'Y-m-d'));
if($ignore_year)
if ($ignore_year) {
$dob = '0000-' . $dob; $dob = '0000-' . $dob;
} }
}
$name = notags(trim($_POST['name'])); $name = notags(trim($_POST['name']));
@ -214,10 +219,9 @@ function profiles_post(App $a) {
$name = '[No Name]'; $name = '[No Name]';
} }
if($orig[0]['name'] != $name) if ($orig[0]['name'] != $name) {
$namechanged = true; $namechanged = true;
}
$pdesc = notags(trim($_POST['pdesc'])); $pdesc = notags(trim($_POST['pdesc']));
$gender = notags(trim($_POST['gender'])); $gender = notags(trim($_POST['gender']));
@ -247,8 +251,9 @@ function profiles_post(App $a) {
$withchanged = true; $withchanged = true;
$prf = ''; $prf = '';
$lookup = $with; $lookup = $with;
if(strpos($lookup,'@') === 0) if (strpos($lookup, '@') === 0) {
$lookup = substr($lookup, 1); $lookup = substr($lookup, 1);
}
$lookup = str_replace('_',' ', $lookup); $lookup = str_replace('_',' ', $lookup);
if (strpos($lookup, '@') || (strpos($lookup, 'http://'))) { if (strpos($lookup, '@') || (strpos($lookup, 'http://'))) {
$newname = $lookup; $newname = $lookup;
@ -260,27 +265,14 @@ function profiles_post(App $a) {
} }
} }
} }
} } else {
else {
$newname = $lookup; $newname = $lookup;
/* if(strstr($lookup,' ')) {
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname),
intval(local_user())
);
}
else {
$r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
dbesc($lookup),
intval(local_user())
);
}*/
$r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1",
dbesc($newname), dbesc($newname),
intval(local_user()) intval(local_user())
); );
if(! $r) { if (! dbm::is_result($r)) {
$r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1", $r = q("SELECT * FROM `contact` WHERE `nick` = '%s' AND `uid` = %d LIMIT 1",
dbesc($lookup), dbesc($lookup),
intval(local_user()) intval(local_user())
@ -294,14 +286,16 @@ function profiles_post(App $a) {
if ($prf) { if ($prf) {
$with = str_replace($lookup, '<a href="' . $prf . '">' . $newname . '</a>', $with); $with = str_replace($lookup, '<a href="' . $prf . '">' . $newname . '</a>', $with);
if(strpos($with,'@') === 0) if (strpos($with, '@') === 0) {
$with = substr($with, 1); $with = substr($with, 1);
} }
} }
else } else {
$with = $orig[0]['with']; $with = $orig[0]['with'];
} }
}
/// @TODO Not flexible enough for later expansion, let's have more OOP here
$sexual = notags(trim($_POST['sexual'])); $sexual = notags(trim($_POST['sexual']));
$xmpp = notags(trim($_POST['xmpp'])); $xmpp = notags(trim($_POST['xmpp']));
$homepage = notags(trim($_POST['homepage'])); $homepage = notags(trim($_POST['homepage']));
@ -473,8 +467,9 @@ function profiles_post(App $a) {
intval(local_user()) intval(local_user())
); );
if($r) if ($r) {
info(t('Profile updated.') . EOL); info(t('Profile updated.') . EOL);
}
if ($namechanged && $is_default) { if ($namechanged && $is_default) {
@ -519,14 +514,17 @@ function profiles_post(App $a) {
function profile_activity($changed, $value) { function profile_activity($changed, $value) {
$a = get_app(); $a = get_app();
if(! local_user() || ! is_array($changed) || ! count($changed)) if (! local_user() || ! is_array($changed) || ! count($changed)) {
return; return;
}
if($a->user['hidewall'] || get_config('system','block_public')) if ($a->user['hidewall'] || get_config('system', 'block_public')) {
return; return;
}
if(! get_pconfig(local_user(),'system','post_profilechange')) if (! get_pconfig(local_user(), 'system', 'post_profilechange')) {
return; return;
}
require_once('include/items.php'); require_once('include/items.php');
@ -534,8 +532,9 @@ function profile_activity($changed, $value) {
intval(local_user()) intval(local_user())
); );
if(! count($self)) if (! dbm::is_result($self)) {
return; return;
}
$arr = array(); $arr = array();
@ -561,11 +560,12 @@ function profile_activity($changed, $value) {
$z = 0; $z = 0;
foreach ($changed as $ch) { foreach ($changed as $ch) {
if (strlen($changes)) { if (strlen($changes)) {
if ($z == ($t - 1)) if ($z == ($t - 1)) {
$changes .= t(' and '); $changes .= t(' and ');
else } else {
$changes .= ', '; $changes .= ', ';
} }
}
$z ++; $z ++;
$changes .= $ch; $changes .= $ch;
} }
@ -575,9 +575,9 @@ function profile_activity($changed, $value) {
if ($t == 1 && strlen($value)) { if ($t == 1 && strlen($value)) {
$message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value); $message = sprintf( t('%1$s changed %2$s to &ldquo;%3$s&rdquo;'), $A, $changes, $value);
$message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof); $message .= "\n\n" . sprintf( t(' - Visit %1$s\'s %2$s'), $A, $prof);
} } else {
else
$message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes); $message = sprintf( t('%1$s has an updated %2$s, changing %3$s.'), $A, $prof, $changes);
}
$arr['body'] = $message; $arr['body'] = $message;
@ -652,8 +652,9 @@ function profiles_content(App $a) {
$detailled_profile = (get_pconfig(local_user(), 'system', 'detailled_profile') AND $personal_account); $detailled_profile = (get_pconfig(local_user(), 'system', 'detailled_profile') AND $personal_account);
$f = get_config('system', 'birthday_input_format'); $f = get_config('system', 'birthday_input_format');
if(! $f) if (! $f) {
$f = 'ymd'; $f = 'ymd';
}
$is_default = (($r[0]['is-default']) ? 1 : 0); $is_default = (($r[0]['is-default']) ? 1 : 0);
$tpl = get_markup_template("profile_edit.tpl"); $tpl = get_markup_template("profile_edit.tpl");
@ -748,15 +749,11 @@ function profiles_content(App $a) {
call_hooks('profile_edit', $arr); call_hooks('profile_edit', $arr);
return $o; return $o;
} } else {
//Profiles list.
else {
// If we don't support multi profiles, don't display this list. // If we don't support multi profiles, don't display this list.
if (!feature_enabled(local_user(), 'multi_profiles')) { if (!feature_enabled(local_user(), 'multi_profiles')) {
$r = q( $r = q("SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
"SELECT * FROM `profile` WHERE `uid` = %d AND `is-default`=1",
local_user() local_user()
); );
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
@ -767,6 +764,7 @@ function profiles_content(App $a) {
$r = q("SELECT * FROM `profile` WHERE `uid` = %d", $r = q("SELECT * FROM `profile` WHERE `uid` = %d",
local_user()); local_user());
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$tpl = get_markup_template('profile_entry.tpl'); $tpl = get_markup_template('profile_entry.tpl');

View file

@ -15,7 +15,8 @@
*/ */
if(($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) if (($_SERVER["argc"] > 1) && isset($_SERVER["argv"][1])) {
echo $_SERVER["argv"][1]; echo $_SERVER["argv"][1];
else } else {
echo ''; echo '';
}

View file

@ -308,7 +308,7 @@ function update_1030() {
function update_1031() { function update_1031() {
// Repair any bad links that slipped into the item table // Repair any bad links that slipped into the item table
$r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' "); $r = q("SELECT `id`, `object` FROM `item` WHERE `object` != '' ");
if($r && dbm::is_result($r)) { if (dbm::is_result($r)) {
foreach ($r as $rr) { foreach ($r as $rr) {
if (strstr($rr['object'],'type=&quot;http')) { if (strstr($rr['object'],'type=&quot;http')) {
q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d", q("UPDATE `item` SET `object` = '%s' WHERE `id` = %d",
@ -329,19 +329,20 @@ function update_1033() {
`k` CHAR( 255 ) NOT NULL PRIMARY KEY , `k` CHAR( 255 ) NOT NULL PRIMARY KEY ,
`v` TEXT NOT NULL, `v` TEXT NOT NULL,
`updated` DATETIME NOT NULL `updated` DATETIME NOT NULL
) ENGINE = MYISAM DEFAULT CHARSET=utf8 "); ) DEFAULT CHARSET=utf8 ");
} }
function update_1034() { function update_1034() {
// If you have any of these parent-less posts they can cause problems, and /*
// we need to delete them. You can't see them anyway. * If you have any of these parent-less posts they can cause problems, and
// Legitimate items will usually get re-created on the next * we need to delete them. You can't see them anyway.
// pull from the hub. * Legitimate items will usually get re-created on the next
// But don't get rid of a post that may have just come in * pull from the hub.
// and may not yet have the parent id set. * But don't get rid of a post that may have just come in
* and may not yet have the parent id set.
*/
q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE"); q("DELETE FROM `item` WHERE `parent` = 0 AND `created` < UTC_TIMESTAMP() - INTERVAL 2 MINUTE");
} }

View file

@ -12,12 +12,11 @@ function po2php_run(&$argv, &$argc) {
$pofile = $argv[1]; $pofile = $argv[1];
$outfile = dirname($pofile)."/strings.php"; $outfile = dirname($pofile)."/strings.php";
if(strstr($outfile,'util')) if (strstr($outfile, 'util')) {
$lang = 'en'; $lang = 'en';
else } else {
$lang = str_replace('-','_',basename(dirname($pofile))); $lang = str_replace('-','_',basename(dirname($pofile)));
}
if (!file_exists($pofile)) { if (!file_exists($pofile)) {
print "Unable to find '$pofile'\n"; print "Unable to find '$pofile'\n";
@ -31,9 +30,9 @@ function po2php_run(&$argv, &$argc) {
$infile = file($pofile); $infile = file($pofile);
$k = ""; $k = "";
$v = ""; $v = "";
$arr = False; $arr = false;
$ink = False; $ink = false;
$inv = False; $inv = false;
$escape_s_exp = '|[^\\\\]\$[a-z]|'; $escape_s_exp = '|[^\\\\]\$[a-z]|';
function escape_s($match) { function escape_s($match) {
return str_replace('$','\$',$match[0]); return str_replace('$','\$',$match[0]);
@ -41,9 +40,11 @@ function po2php_run(&$argv, &$argc) {
foreach ($infile as $l) { foreach ($infile as $l) {
$l = str_replace('\"', DQ_ESCAPE, $l); $l = str_replace('\"', DQ_ESCAPE, $l);
$len = strlen($l); $len = strlen($l);
if ($l[0]=="#") $l=""; if ($l[0] == "#") {
$l = "";
}
if (substr($l, 0, 15) == '"Plural-Forms: ') { if (substr($l, 0, 15) == '"Plural-Forms: ') {
$match=Array(); $match = array();
preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match); preg_match("|nplurals=([0-9]*); *plural=(.*)[;\\\\]|", $l, $match);
$cond = str_replace('n', '$n', $match[2]); $cond = str_replace('n', '$n', $match[2]);
// define plural select function if not already defined // define plural select function if not already defined
@ -54,36 +55,48 @@ function po2php_run(&$argv, &$argc) {
$out .= '}}' . "\n"; $out .= '}}' . "\n";
} }
if ($k != "" && substr($l, 0, 7) == "msgstr ") { if ($k != "" && substr($l, 0, 7) == "msgstr ") {
if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } if ($ink) {
if ($inv) { $inv = False; $out .= '"'.$v.'"'; } $ink = false;
$out .= '$a->strings["' . $k . '"] = ';
}
if ($inv) {
$inv = false;
$out .= '"' . $v . '"';
}
$v = substr($l, 8, $len - 10); $v = substr($l, 8, $len - 10);
$v = preg_replace_callback($escape_s_exp, 'escape_s', $v); $v = preg_replace_callback($escape_s_exp, 'escape_s', $v);
$inv = True; $inv = true;
//$out .= $v; //$out .= $v;
} }
if ($k != "" && substr($l, 0, 7) == "msgstr[") { if ($k != "" && substr($l, 0, 7) == "msgstr[") {
if ($ink) { $ink = False; $out .= '$a->strings["'.$k.'"] = '; } if ($ink) {
if ($inv) { $inv = False; $out .= '"'.$v.'"'; } $ink = false;
$out .= '$a->strings["' . $k . '"] = ';
}
if ($inv) {
$inv = false;
$out .= '"' . $v . '"';
}
if (!$arr) { if (!$arr) {
$arr=True; $arr=True;
$out .= "array(\n"; $out .= "array(\n";
} }
$match=Array(); $match = array();
preg_match("|\[([0-9]*)\] (.*)|", $l, $match); preg_match("|\[([0-9]*)\] (.*)|", $l, $match);
$out .= "\t". $out .= "\t"
preg_replace_callback($escape_s_exp,'escape_s',$match[1]) . preg_replace_callback($escape_s_exp, 'escape_s', $match[1])
. " => " . " => "
.preg_replace_callback($escape_s_exp,'escape_s',$match[2]) .",\n"; . preg_replace_callback($escape_s_exp, 'escape_s', $match[2])
. ",\n";
} }
if (substr($l,0,6)=="msgid_") { $ink = False; $out .= '$a->strings["'.$k.'"] = '; }; if (substr($l, 0, 6) == "msgid_") {
$ink = false;
$out .= '$a->strings["' . $k . '"] = ';
}
if ($ink) { if ($ink) {
$k .= trim($l, "\"\r\n"); $k .= trim($l, "\"\r\n");
@ -92,9 +105,14 @@ function po2php_run(&$argv, &$argc) {
} }
if (substr($l, 0, 6) == "msgid ") { if (substr($l, 0, 6) == "msgid ") {
if ($inv) { $inv = False; $out .= '"'.$v.'"'; } if ($inv) {
if ($k!="") $out .= $arr?");\n":";\n"; $inv = false;
$arr=False; $out .= '"' . $v . '"';
}
if ($k != "") {
$out .= ($arr) ? ");\n" : ";\n";
}
$arr = false;
$k = str_replace("msgid ", "", $l); $k = str_replace("msgid ", "", $l);
if ($k != '""') { if ($k != '""') {
$k = trim($k, "\"\r\n"); $k = trim($k, "\"\r\n");
@ -103,7 +121,7 @@ function po2php_run(&$argv, &$argc) {
} }
$k = preg_replace_callback($escape_s_exp, 'escape_s', $k); $k = preg_replace_callback($escape_s_exp, 'escape_s', $k);
$ink = True; $ink = true;
} }
if ($inv && substr($l, 0, 6) != "msgstr") { if ($inv && substr($l, 0, 6) != "msgstr") {
@ -115,14 +133,19 @@ function po2php_run(&$argv, &$argc) {
} }
if ($inv) { $inv = False; $out .= '"'.$v.'"'; } if ($inv) {
if ($k!="") $out .= $arr?");\n":";\n"; $inv = false;
$out .= '"' . $v . '"';
}
if ($k != "") {
$out .= ($arr ? ");\n" : ";\n");
}
$out = str_replace(DQ_ESCAPE, '\"', $out); $out = str_replace(DQ_ESCAPE, '\"', $out);
file_put_contents($outfile, $out); file_put_contents($outfile, $out);
} }
if (array_search(__file__,get_included_files())===0){ if (array_search(__FILE__, get_included_files()) === 0) {
po2php_run($_SERVER["argv"],$_SERVER["argc"]); po2php_run($_SERVER["argv"],$_SERVER["argc"]);
} }

View file

@ -9,9 +9,9 @@
* Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/ * Description: "Vier" is a very compact and modern theme. It uses the font awesome font library: http://fortawesome.github.com/Font-Awesome/
*/ */
require_once("include/plugin.php"); require_once "include/plugin.php";
require_once("include/socgraph.php"); require_once "include/socgraph.php";
require_once("mod/proxy.php"); require_once "mod/proxy.php";
function vier_init(App $a) { function vier_init(App $a) {
@ -101,6 +101,7 @@ EOT;
} }
// Hide the left menu bar // Hide the left menu bar
/// @TODO maybe move this static array out where it should belong?
if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications", if (($a->page['aside'] == "") AND in_array($a->argv[0], array("community", "events", "help", "manage", "notifications",
"probe", "webfinger", "login", "invite", "credits"))) { "probe", "webfinger", "login", "invite", "credits"))) {
$a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />"; $a->page['htmlhead'] .= "<link rel='stylesheet' href='view/theme/vier/hide.css' />";
@ -110,13 +111,15 @@ EOT;
function get_vier_config($key, $default = false, $admin = false) { function get_vier_config($key, $default = false, $admin = false) {
if (local_user() AND !$admin) { if (local_user() AND !$admin) {
$result = get_pconfig(local_user(), "vier", $key); $result = get_pconfig(local_user(), "vier", $key);
if ($result !== false) if ($result !== false) {
return $result; return $result;
} }
}
$result = get_config("vier", $key); $result = get_config("vier", $key);
if ($result !== false) if ($result !== false) {
return $result; return $result;
}
return $default; return $default;
} }
@ -191,12 +194,12 @@ function vier_community_info() {
//right_aside FIND FRIENDS //right_aside FIND FRIENDS
if ($show_friends AND local_user()) { if ($show_friends AND local_user()) {
$nv = array(); $nv = array();
$nv['title'] = Array("", t('Find Friends'), "", ""); $nv['title'] = array("", t('Find Friends'), "", "");
$nv['directory'] = Array('directory', t('Local Directory'), "", ""); $nv['directory'] = array('directory', t('Local Directory'), "", "");
$nv['global_directory'] = Array(get_server(), t('Global Directory'), "", ""); $nv['global_directory'] = Array(get_server(), t('Global Directory'), "", "");
$nv['match'] = Array('match', t('Similar Interests'), "", ""); $nv['match'] = array('match', t('Similar Interests'), "", "");
$nv['suggest'] = Array('suggest', t('Friend Suggestions'), "", ""); $nv['suggest'] = array('suggest', t('Friend Suggestions'), "", "");
$nv['invite'] = Array('invite', t('Invite Friends'), "", ""); $nv['invite'] = array('invite', t('Invite Friends'), "", "");
$nv['search'] = '<form name="simple_bar" method="get" action="dirfind"> $nv['search'] = '<form name="simple_bar" method="get" action="dirfind">
<span class="sbox_l"></span> <span class="sbox_l"></span>
@ -211,10 +214,11 @@ function vier_community_info() {
//Community_Pages at right_aside //Community_Pages at right_aside
if ($show_pages AND local_user()) { if ($show_pages AND local_user()) {
require_once('include/ForumManager.php'); require_once 'include/ForumManager.php';
if (x($_GET['cid']) && intval($_GET['cid']) != 0) if (x($_GET, 'cid') && intval($_GET['cid']) != 0) {
$cid = $_GET['cid']; $cid = $_GET['cid'];
}
//sort by last updated item //sort by last updated item
$lastitem = true; $lastitem = true;
@ -283,14 +287,14 @@ function vier_community_info() {
foreach ($r AS $index => $helper) foreach ($r AS $index => $helper)
$r[$index]["url"] = zrl($helper["url"]); $r[$index]["url"] = zrl($helper["url"]);
$r[] = Array("url" => "help/Quick-Start-guide", "name" => t("Quick Start")); $r[] = array("url" => "help/Quick-Start-guide", "name" => t("Quick Start"));
$tpl = get_markup_template('ch_helpers.tpl'); $tpl = get_markup_template('ch_helpers.tpl');
if ($r) { if ($r) {
$helpers = array(); $helpers = array();
$helpers['title'] = Array("", t('Help'), "", ""); $helpers['title'] = array("", t('Help'), "", "");
$aside['$helpers_items'] = array(); $aside['$helpers_items'] = array();
@ -345,6 +349,7 @@ function vier_community_info() {
$r[] = array("photo" => "images/googleplus.png", "name" => "Google+"); $r[] = array("photo" => "images/googleplus.png", "name" => "Google+");
} }
/// @TODO old-lost code (and below)?
//if (plugin_enabled("ijpost")) { //if (plugin_enabled("ijpost")) {
// $r[] = array("photo" => "images/", "name" => ""); // $r[] = array("photo" => "images/", "name" => "");
//} //}
@ -382,7 +387,7 @@ function vier_community_info() {
if (dbm::is_result($r)) { if (dbm::is_result($r)) {
$con_services = array(); $con_services = array();
$con_services['title'] = Array("", t('Connect Services'), "", ""); $con_services['title'] = array("", t('Connect Services'), "", "");
$aside['$con_services'] = $con_services; $aside['$con_services'] = $con_services;
foreach ($r as $rr) { foreach ($r as $rr) {