Conflicts:
	include/poller.php
This commit is contained in:
Michael - piratica.eu 2013-01-20 14:17:09 +01:00
commit cc9ce39e3f
741 changed files with 9987 additions and 5350 deletions

View file

@ -42,6 +42,10 @@ function z_mime_content_type($filename) {
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'ogg' => 'application/ogg',
'mp4' => 'video/mp4',
'avi' => 'video/x-msvideo',
'wmv' => 'video/x-ms-wmv',
'wma' => 'audio/x-ms-wma',
// adobe
'pdf' => 'application/pdf',

View file

@ -254,12 +254,22 @@ function bb_ShareAttributes($match) {
if ($matches[1] != "")
$profile = $matches[1];
$posted = "";
preg_match("/posted='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$posted = $matches[1];
preg_match('/posted="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$posted = $matches[1];
$reldate = (($posted) ? " " . relative_date($posted) : '');
$headline = '<div class="shared_header">';
if ($avatar != "")
$headline .= '<img src="'.$avatar.'" height="32" width="32" >';
$headline .= sprintf(t('<span><a href="%s" target="external-link">%s</a> wrote the following <a href="%s" target="external-link">post</a>:</span>'), $profile, $author, $link);
$headline .= sprintf(t('<span><a href="%s" target="external-link">%s</a> wrote the following <a href="%s" target="external-link">post</a>'.$reldate.':</span>'), $profile, $author, $link);
$headline .= "</div>";
@ -312,6 +322,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = preg_replace("/\s?\[share(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","[share$1]$2[/share]",$Text);
$Text = preg_replace("/\s?\[quote(.*?)\]\s?(.*?)\s?\[\/quote\]\s?/ism","[quote$1]$2[/quote]",$Text);
$Text = preg_replace("/\n\[code\]/ism", "[code]", $Text);
$Text = preg_replace("/\[\/code\]\n/ism", "[/code]", $Text);
// when the content is meant exporting to other systems then remove the avatar picture since this doesn't really look good on these systems
if (!$tryoembed)
$Text = preg_replace("/\[share(.*?)avatar\s?=\s?'.*?'\s?(.*?)\]\s?(.*?)\s?\[\/share\]\s?/ism","\n[share$1$2]$3[/share]",$Text);
@ -327,12 +340,13 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true) {
$Text = str_replace("\r\n","\n", $Text);
// removing multiplicated newlines
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
do {
$oldtext = $Text;
$Text = str_replace($search, $replace, $Text);
} while ($oldtext != $Text);
// $search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
// $replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
// do {
// $oldtext = $Text;
// $Text = str_replace($search, $replace, $Text);
// } while ($oldtext != $Text);
$Text = str_replace(array("\r","\n"), array('<br />','<br />'), $Text);

View file

@ -524,7 +524,7 @@ function conversation(&$a, $items, $mode, $update, $preview = false) {
$hashtags = array();
$mentions = array();
$taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d)",
$taglist = q("SELECT `type`, `term`, `url` FROM `term` WHERE `otype` = %d AND `oid` = %d AND `type` IN (%d, %d) ORDER BY `tid`",
intval(TERM_OBJ_POST), intval($item['id']), intval(TERM_HASHTAG), intval(TERM_MENTION));
foreach($taglist as $tag) {
@ -896,26 +896,21 @@ function format_like($cnt,$arr,$type,$id) {
if($cnt == 1)
$o .= (($type === 'like') ? sprintf( t('%s likes this.'), $arr[0]) : sprintf( t('%s doesn\'t like this.'), $arr[0])) . EOL ;
else {
//$spanatts = 'class="fakelink" onclick="openClose(\'' . $type . 'list-' . $id . '\');"';
$spanatts = "class=\"fakelink\" onclick=\"openClose('{$type}list-$id');\"";
switch($type) {
case 'like':
// $phrase = sprintf( t('<span %1$s>%2$d people</span> like this.'), $spanatts, $cnt);
$mood = t('like this');
$phrase = sprintf( t('<span %1$s>%2$d people</span> like this'), $spanatts, $cnt);
break;
case 'dislike':
// $phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this.'), $spanatts, $cnt);
$mood = t('don\'t like this');
$phrase = sprintf( t('<span %1$s>%2$d people</span> don\'t like this'), $spanatts, $cnt);
break;
}
$tpl = get_markup_template("voting_fakelink.tpl");
$phrase = replace_macros($tpl, array(
'$vote_id' => $type . 'list-' . $id,
'$count' => $cnt,
'$people' => t('people'),
'$vote_mood' => $mood
$phrase .= EOL ;
$o .= replace_macros(get_markup_template('voting_fakelink.tpl'), array(
'$phrase' => $phrase,
'$type' => $type,
'$id' => $id
));
$o .= $phrase;
// $o .= EOL ;
$total = count($arr);
if($total >= MAX_LIKERS)

29
include/dbupdate.php Normal file
View file

@ -0,0 +1,29 @@
<?php
require_once("boot.php");
function dbupdate_run(&$argv, &$argc) {
global $a, $db;
if(is_null($a)){
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
}
load_config('config');
load_config('system');
check_config($a);
}
if (array_search(__file__,get_included_files())===0){
dbupdate_run($argv,$argc);
killme();
}

View file

@ -16,7 +16,9 @@ function diaspora_dispatch_public($msg) {
return;
}
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN ( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' ) AND `account_expired` = 0 AND `account_removed` = 0 ",
$r = q("SELECT `user`.* FROM `user` WHERE `user`.`uid` IN
( SELECT `contact`.`uid` FROM `contact` WHERE `contact`.`network` = '%s' AND `contact`.`addr` = '%s' )
AND `account_expired` = 0 AND `account_removed` = 0 ",
dbesc(NETWORK_DIASPORA),
dbesc($msg['author'])
);
@ -32,7 +34,7 @@ function diaspora_dispatch_public($msg) {
function diaspora_dispatch($importer,$msg) {
function diaspora_dispatch($importer,$msg,$attempt=1) {
$ret = 0;
@ -88,7 +90,7 @@ function diaspora_dispatch($importer,$msg) {
$ret = diaspora_signed_retraction($importer,$xmlbase->relayable_retraction,$msg);
}
elseif($xmlbase->photo) {
$ret = diaspora_photo($importer,$xmlbase->photo,$msg);
$ret = diaspora_photo($importer,$xmlbase->photo,$msg,$attempt);
}
elseif($xmlbase->conversation) {
$ret = diaspora_conversation($importer,$xmlbase->conversation,$msg);
@ -1669,7 +1671,7 @@ function diaspora_message($importer,$xml,$msg) {
}
function diaspora_photo($importer,$xml,$msg) {
function diaspora_photo($importer,$xml,$msg,$attempt=1) {
$a = get_app();
@ -1707,7 +1709,14 @@ function diaspora_photo($importer,$xml,$msg) {
dbesc($status_message_guid)
);
if(! count($r)) {
logger('diaspora_photo: parent item not found: parent: ' . $parent_guid . ' item: ' . $guid);
if($attempt <= 3) {
q("INSERT INTO dsprphotoq (uid, msg, attempt) VALUES (%d, '%s', %d)",
intval($importer['uid']),
dbesc(serialize($msg)),
intval($attempt + 1)
);
}
logger('diaspora_photo: attempt = ' . $attempt . '; status message not found: ' . $status_message_guid . ' for photo: ' . $guid);
return;
}
@ -2333,13 +2342,15 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
$myaddr = $owner['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(),'://') + 3);
// $theiraddr = $contact['addr'];
// Diaspora doesn't support threaded comments
/*if($item['thr-parent']) {
// Diaspora doesn't support threaded comments, but some
// versions of Diaspora (i.e. Diaspora-pistos) support
// likes on comments
if($item['verb'] === ACTIVITY_LIKE && $item['thr-parent']) {
$p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1",
dbesc($item['thr-parent'])
);
}
else {*/
else {
// The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
// return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
// The only item with `parent` and `id` as the parent id is the parent item.
@ -2347,7 +2358,7 @@ function diaspora_send_followup($item,$owner,$contact,$public_batch = false) {
intval($item['parent']),
intval($item['parent'])
);
//}
}
if(count($p))
$parent = $p[0];
else
@ -2409,13 +2420,15 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
$body = $item['body'];
$text = html_entity_decode(bb2diaspora($body));
// Diaspora doesn't support threaded comments
/*if($item['thr-parent']) {
// Diaspora doesn't support threaded comments, but some
// versions of Diaspora (i.e. Diaspora-pistos) support
// likes on comments
if($item['verb'] === ACTIVITY_LIKE && $item['thr-parent']) {
$p = q("select guid, type, uri, `parent-uri` from item where uri = '%s' limit 1",
dbesc($item['thr-parent'])
);
}
else {*/
else {
// The first item in the `item` table with the parent id is the parent. However, MySQL doesn't always
// return the items ordered by `item`.`id`, in which case the wrong item is chosen as the parent.
// The only item with `parent` and `id` as the parent id is the parent item.
@ -2423,7 +2436,7 @@ function diaspora_send_relay($item,$owner,$contact,$public_batch = false) {
intval($item['parent']),
intval($item['parent'])
);
//}
}
if(count($p))
$parent = $p[0];
else

50
include/dsprphotoq.php Normal file
View file

@ -0,0 +1,50 @@
<?php
require_once("boot.php");
require_once('include/diaspora.php');
function dsprphotoq_run($argv, $argc){
global $a, $db;
if(is_null($a)){
$a = new App;
}
if(is_null($db)){
@include(".htconfig.php");
require_once("include/dba.php");
$db = new dba($db_host, $db_user, $db_pass, $db_data);
unset($db_host, $db_user, $db_pass, $db_data);
};
logger("diaspora photo queue: running", LOGGER_DEBUG);
$r = q("SELECT * FROM dsprphotoq");
if(!$r)
return;
$dphotos = $r;
logger("diaspora photo queue: processing " . count($dphotos) . " photos");
foreach($dphotos as $dphoto) {
$r = q("SELECT * FROM user WHERE uid = %d",
intval($dphoto['uid'])
);
if(!$r) {
logger("diaspora photo queue: user " . $dphoto['uid'] . " not found");
return;
}
$ret = diaspora_dispatch($r[0],unserialize($dphoto['msg']),$dphoto['attempt']);
q("DELETE FROM dsprphotoq WHERE id = %d",
intval($dphoto['id'])
);
}
}
if (array_search(__file__,get_included_files())===0){
dsprphotoq_run($argv,$argc);
killme();
}

View file

@ -471,8 +471,8 @@ class enotify {
// generate a multipart/alternative message header
$messageHeader =
$params['additionalMailHeader'] .
"From: {$params['fromName']} <{$params['fromEmail']}>\n" .
"Reply-To: {$params['fromName']} <{$params['replyTo']}>\n" .
"From: $fromName <{$params['fromEmail']}>\n" .
"Reply-To: $fromName <{$params['replyTo']}>\n" .
"MIME-Version: 1.0\n" .
"Content-Type: multipart/alternative; boundary=\"{$mimeBoundary}\"";
@ -493,7 +493,7 @@ class enotify {
// send the message
$res = mail(
$params['toEmail'], // send to address
$params['messageSubject'], // subject
$messageSubject, // subject
$multipartMessageBody, // message body
$messageHeader // message headers
);

View file

@ -24,8 +24,11 @@ class FriendicaSmarty extends Smarty {
$this->setConfigDir('view/smarty3/config/');
$this->setCacheDir('view/smarty3/cache/');
$this->left_delimiter = $a->smarty3_ldelim;
$this->right_delimiter = $a->smarty3_rdelim;
$this->left_delimiter = $a->get_template_ldelim('smarty3');
$this->right_delimiter = $a->get_template_rdelim('smarty3');
// Don't report errors so verbosely
$this->error_reporting = E_ALL & ~E_NOTICE;
}
function parsed($template = '') {

View file

@ -209,7 +209,7 @@ function html2plain($html, $wraplength = 75, $compact = false)
if (!$compact) {
$counter = 1;
foreach ($urls as $id=>$url)
if (strpos($message, $url) == false)
if (strpos($message, $url) === false)
$message .= "\n".$url." ";
//$message .= "\n[".($counter++)."] ".$url;
}

View file

@ -6,6 +6,8 @@ require_once('include/salmon.php');
require_once('include/crypto.php');
require_once('include/Photo.php');
require_once('include/tags.php');
require_once('include/text.php');
require_once('include/email.php');
function get_feed_for(&$a, $dfrn_id, $owner_nick, $last_update, $direction = 0) {
@ -238,7 +240,7 @@ function construct_activity_object($item) {
$r->link = str_replace('&','&amp;', $r->link);
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
$o .= $r->link;
}
}
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
@ -270,7 +272,7 @@ function construct_activity_target($item) {
$r->link = str_replace('&','&amp;', $r->link);
$r->link = preg_replace('/\<link(.*?)\"\>/','<link$1"/>',$r->link);
$o .= $r->link;
}
}
else
$o .= '<link rel="alternate" type="text/html" href="' . xmlify($r->link) . '" />' . "\r\n";
}
@ -882,7 +884,7 @@ function item_store($arr,$force_parent = false) {
$arr['gravity'] = 0;
elseif(activity_match($arr['verb'],ACTIVITY_POST))
$arr['gravity'] = 6;
else
else
$arr['gravity'] = 6; // extensible catchall
if(! x($arr,'type'))
@ -1072,10 +1074,9 @@ function item_store($arr,$force_parent = false) {
if(count($r)) {
$current_post = $r[0]['id'];
create_tags_from_item($r[0]['id']);
logger('item_store: created item ' . $current_post);
}
else {
create_tags_from_item($r[0]['id']);
} else {
logger('item_store: could not locate created item');
return 0;
}
@ -1153,6 +1154,15 @@ function item_store($arr,$force_parent = false) {
tag_deliver($arr['uid'],$current_post);
// Store the fresh generated item into the cache
$cachefile = get_cachefile($arr["guid"]."-".hash("md5", $arr['body']));
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($arr['body']);
file_put_contents($cachefile, $s);
logger('item_store: put item '.$current_post.' into cachefile '.$cachefile);
}
return $current_post;
}
@ -3401,9 +3411,9 @@ function new_follower($importer,$contact,$datarray,$item,$sharing = false) {
'$sitename' => $a->config['sitename']
));
$res = mail($r[0]['email'],
(($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],
email_header_encode((($sharing) ? t('A new person is sharing with you at ') : t("You have a new follower at ")) . $a->config['sitename'],'UTF-8'),
$email,
'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
. 'Content-type: text/plain; charset=UTF-8' . "\n"
. 'Content-transfer-encoding: 8bit' );
@ -3763,11 +3773,11 @@ function item_getfeedtags($item) {
function item_getfeedattach($item) {
$ret = '';
$arr = explode(',',$item['attach']);
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
foreach($arr as $r) {
$matches = false;
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches);
$cnt = preg_match('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches);
if($cnt) {
$ret .= '<link rel="enclosure" href="' . xmlify($matches[1]) . '" type="' . xmlify($matches[3]) . '" ';
if(intval($matches[2]))

View file

@ -37,6 +37,7 @@ require_once('include/html2plain.php');
* tag (in photos.php, poke.php, tagger.php)
* tgroup (in items.php)
* wall-new (in photos.php, item.php)
* removeme (in Contact.php)
*
* and ITEM_ID is the id of the item in the database that needs to be sent to others.
*/
@ -138,14 +139,17 @@ function notifier_run(&$argv, &$argc){
$r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($item_id));
if (! $r)
return;
$user = $r[0];
$r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($item_id));
if (! $r)
return;
$self = $r[0];
$r = q("SELECT * FROM `contact` WHERE `self` = 0 AND `uid` = %d", intval($item_id));
if(! $r)
return;
require_once('include/Contact.php');
foreach($r as $contact) {
terminate_friendship($user, $self, $contact);

View file

@ -62,6 +62,10 @@ function poller_run(&$argv, &$argc){
proc_run('php',"include/queue.php");
// run diaspora photo queue process in the background
proc_run('php',"include/dsprphotoq.php");
// expire any expired accounts
q("UPDATE user SET `account_expired` = 1 where `account_expired` = 0

View file

@ -2,7 +2,6 @@
require_once('include/datetime.php');
/*
* poco_load
*

View file

@ -25,7 +25,7 @@ function create_tags_from_item($itemid) {
$searchpath = $a->get_baseurl()."/search?tag=";
$messages = q("SELECT `uri`, `uid`, `id`, `created`, `edited`, `commented`, `received`, `changed`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
$messages = q("SELECT `guid`, `uid`, `id`, `edited`, `deleted`, `title`, `body`, `tag` FROM `item` WHERE `id` = %d LIMIT 1", intval($itemid));
if (!$messages)
return;
@ -42,6 +42,14 @@ function create_tags_from_item($itemid) {
if ($message["deleted"])
return;
$cachefile = get_cachefile($message["guid"]."-".hash("md5", $message['body']));
if (($cachefile != '') AND !file_exists($cachefile)) {
$s = prepare_text($message['body']);
file_put_contents($cachefile, $s);
logger('create_tags_from_item: put item '.$message["id"].' into cachefile '.$cachefile);
}
$taglist = explode(",", $message["tag"]);
$tags = "";

View file

@ -23,7 +23,6 @@ function replace_macros($s,$r) {
if(gettype($s) === 'string') {
$template = $s;
$s = new FriendicaSmarty();
$s->error_reporting = E_ALL & ~E_NOTICE;
}
foreach($r as $key=>$value) {
if($key[0] === '$') {
@ -490,12 +489,12 @@ function get_template_file($a, $filename, $root = '') {
if($root !== '' && $root[strlen($root)-1] !== '/')
$root = $root . '/';
if(file_exists($root . "view/theme/$theme/$filename"))
$template_file = $root . "view/theme/$theme/$filename";
elseif (x($a->theme_info,"extends") && file_exists($root . "view/theme/".$a->theme_info["extends"]."/$filename"))
$template_file = $root . "view/theme/".$a->theme_info["extends"]."/$filename";
if(file_exists("{$root}view/theme/$theme/$filename"))
$template_file = "{$root}view/theme/$theme/$filename";
elseif (x($a->theme_info,"extends") && file_exists("{$root}view/theme/{$a->theme_info["extends"]}/$filename"))
$template_file = "{$root}view/theme/{$a->theme_info["extends"]}/$filename";
else
$template_file = $root . "view/$filename";
$template_file = "{$root}view/$filename";
return $template_file;
}}
@ -1019,7 +1018,8 @@ function prepare_body($item,$attach = false) {
$a = get_app();
call_hooks('prepare_body_init', $item);
$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
//$cachefile = get_cachefile($item["guid"]."-".strtotime($item["edited"])."-".hash("crc32", $item['body']));
$cachefile = get_cachefile($item["guid"]."-".hash("md5", $item['body']));
if (($cachefile != '')) {
if (file_exists($cachefile))
@ -1027,6 +1027,7 @@ function prepare_body($item,$attach = false) {
else {
$s = prepare_text($item['body']);
file_put_contents($cachefile, $s);
logger('prepare_body: put item '.$item["id"].' into cachefile '.$cachefile);
}
} else
$s = prepare_text($item['body']);
@ -1043,13 +1044,13 @@ function prepare_body($item,$attach = false) {
return $s;
}
$arr = explode(',',$item['attach']);
$arr = explode('[/attach],',$item['attach']);
if(count($arr)) {
$s .= '<div class="body-attach">';
foreach($arr as $r) {
$matches = false;
$icon = '';
$cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"\[\/attach\]|',$r,$matches, PREG_SET_ORDER);
$cnt = preg_match_all('|\[attach\]href=\"(.*?)\" length=\"(.*?)\" type=\"(.*?)\" title=\"(.*?)\"|',$r,$matches, PREG_SET_ORDER);
if($cnt) {
foreach($matches as $mtch) {
$icontype = strtolower(substr($mtch[3],0,strpos($mtch[3],'/')));

View file

@ -7,6 +7,7 @@ require_once('include/text.php');
require_once('include/pgettext.php');
require_once('include/datetime.php');
function create_user($arr) {
// Required: { username, nickname, email } or { openid_url }