Merge pull request #758 from annando/master

Better use of APC,  	Preparations for the pumpio synchronisation, fix youtube for firefox
This commit is contained in:
fabrixxm 2013-09-06 07:55:03 -07:00
commit 51d934ee70
11 changed files with 90 additions and 30 deletions

View File

@ -139,6 +139,8 @@ define ( 'NETWORK_LINKEDIN', 'lnkd'); // LinkedIn
define ( 'NETWORK_XMPP', 'xmpp'); // XMPP
define ( 'NETWORK_MYSPACE', 'mysp'); // MySpace
define ( 'NETWORK_GPLUS', 'goog'); // Google+
define ( 'NETWORK_PUMPIO', 'pump'); // pump.io
define ( 'NETWORK_TWITTER', 'twit'); // Twitter
define ( 'NETWORK_PHANTOM', 'unkn'); // Place holder
@ -161,6 +163,8 @@ $netgroup_ids = array(
NETWORK_XMPP => (-10),
NETWORK_MYSPACE => (-11),
NETWORK_GPLUS => (-12),
NETWORK_PUMPIO => (-13),
NETWORK_TWITTER => (-14),
NETWORK_PHANTOM => (-127),
);

View File

@ -534,6 +534,9 @@ class Photo {
ob_start();
// Enable interlacing
imageinterlace($this->image, true);
switch($this->getType()){
case "image/png":
$quality = get_config('system','png_quality');
@ -676,6 +679,7 @@ function guess_image_type($filename, $fromcurl=false) {
*/
$image = new Imagick($filename);
$type = $image->getImageMimeType();
$image->setInterlaceScheme(Imagick::INTERLACE_PLANE);
} else {
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$types = Photo::supportedTypes();

View File

@ -36,7 +36,11 @@ function stripcode_br_cb($s) {
function tryoembed($match){
$url = ((count($match)==2)?$match[1]:$match[2]);
// logger("tryoembed: $url");
// Always embed the SSL version
$url = str_replace("http://www.youtube.com/", "https://www.youtube.com/", $url);
//logger("tryoembed: $url");
$o = oembed_fetch_url($url);
@ -423,8 +427,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// removing multiplicated newlines
if (get_config("system", "remove_multiplicated_lines")) {
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]");
$search = array("\n\n\n", "\n ", " \n", "[/quote]\n\n", "\n[/quote]", "[/li]\n", "\n[li]", "\n[ul]", "[/ul]\n");
$replace = array("\n\n", "\n", "\n", "[/quote]\n", "[/quote]", "[/li]", "[li]", "[ul]", "[/ul]");
do {
$oldtext = $Text;
$Text = str_replace($search, $replace, $Text);
@ -638,19 +642,19 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Youtube extensions
if ($tryoembed) {
$Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
$Text = preg_replace_callback("/\[youtube\](https?:\/\/www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\[youtube\](www.youtube.com\/watch\?v\=.*?)\[\/youtube\]/ism", 'tryoembed', $Text);
$Text = preg_replace_callback("/\[youtube\](https?:\/\/youtu.be\/.*?)\[\/youtube\]/ism",'tryoembed',$Text);
}
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/watch\?v\=(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/www.youtube.com\/embed\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
$Text = preg_replace("/\[youtube\]https?:\/\/youtu.be\/(.*?)\[\/youtube\]/ism",'[youtube]$1[/youtube]',$Text);
if ($tryoembed)
$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="http://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", '<iframe width="' . $a->videowidth . '" height="' . $a->videoheight . '" src="https://www.youtube.com/embed/$1" frameborder="0" ></iframe>', $Text);
else
$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "http://www.youtube.com/watch?v=$1", $Text);
$Text = preg_replace("/\[youtube\]([A-Za-z0-9\-_=]+)(.*?)\[\/youtube\]/ism", "https://www.youtube.com/watch?v=$1", $Text);
if ($tryoembed) {
@ -714,22 +718,29 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Only do it when it has to be done - for performance reasons
// Update: Now it is done every time - since bad structured html can break a whole page
//if (!$tryoembed) {
// $doc = new DOMDocument();
// $doc->preserveWhiteSpace = false;
// $doc = new DOMDocument();
// $doc->preserveWhiteSpace = false;
// $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8");
// $Text = mb_convert_encoding($Text, 'HTML-ENTITIES', "UTF-8");
// $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
// @$doc->loadHTML($doctype."<html><body>".$Text."</body></html>");
// $doctype = '<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">';
// @$doc->loadHTML($doctype."<html><body>".$Text."</body></html>");
// $Text = $doc->saveHTML();
// $Text = str_replace(array("<html><body>", "</body></html>", $doctype), array("", "", ""), $Text);
// $Text = $doc->saveHTML();
// $Text = str_replace(array("<html><body>", "</body></html>", $doctype), array("", "", ""), $Text);
// $Text = str_replace('<br></li>','</li>', $Text);
// $Text = str_replace('<br></li>','</li>', $Text);
// $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
// $Text = mb_convert_encoding($Text, "UTF-8", 'HTML-ENTITIES');
//}
// Clean up some useless linebreaks in lists
//$Text = str_replace('<br /><ul','<ul ', $Text);
//$Text = str_replace('</ul><br />','</ul>', $Text);
//$Text = str_replace('</li><br />','</li>', $Text);
//$Text = str_replace('<br /><li>','<li>', $Text);
// $Text = str_replace('<br /><ul','<ul ', $Text);
// Remove all hashtag addresses
if (!$tryoembed AND get_config("system", "remove_hashtags_on_export")) {
$pattern = '/#<a.*?href="(.*?)".*?>(.*?)<\/a>/is';

View File

@ -28,4 +28,4 @@ function cli_startup() {
load_hooks();
}
}

View File

@ -18,6 +18,9 @@
if(! function_exists('load_config')) {
function load_config($family) {
global $a;
// To-Do: How to integrate APC here?
$r = q("SELECT * FROM `config` WHERE `cat` = '%s'", dbesc($family));
if(count($r)) {
foreach($r as $rr) {
@ -68,7 +71,11 @@ function get_config($family, $key, $instore = false) {
if (apc_exists($family."|".$key)) {
$val = apc_fetch($family."|".$key);
$a->config[$family][$key] = $val;
return $val;
if ($val === '!<unset>!')
return false;
else
return $val;
}
$ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
@ -79,10 +86,19 @@ function get_config($family, $key, $instore = false) {
// manage array value
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
$a->config[$family][$key] = $val;
// If APC is enabled then store the data there
if (function_exists("apc_store"))
apc_store($family."|".$key, $val, 600);
return $val;
}
else {
$a->config[$family][$key] = '!<unset>!';
// If APC is enabled then store the data there
if (function_exists("apc_store"))
apc_store($family."|".$key, '!<unset>!', 600);
}
return false;
}}
@ -182,9 +198,14 @@ function get_pconfig($uid,$family, $key, $instore = false) {
if (apc_exists($uid."|".$family."|".$key)) {
$val = apc_fetch($uid."|".$family."|".$key);
$a->config[$uid][$family][$key] = $val;
return $val;
if ($val === '!<unset>!')
return false;
else
return $val;
}
$ret = q("SELECT `v` FROM `pconfig` WHERE `uid` = %d AND `cat` = '%s' AND `k` = '%s' LIMIT 1",
intval($uid),
dbesc($family),
@ -194,10 +215,19 @@ function get_pconfig($uid,$family, $key, $instore = false) {
if(count($ret)) {
$val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
$a->config[$uid][$family][$key] = $val;
// If APC is enabled then store the data there
if (function_exists("apc_store"))
apc_store($uid."|".$family."|".$key, $val, 600);
return $val;
}
else {
$a->config[$uid][$family][$key] = '!<unset>!';
// If APC is enabled then store the data there
if (function_exists("apc_store"))
apc_store($uid."|".$family."|".$key, '!<unset>!', 600);
}
return false;
}}

View File

@ -84,7 +84,8 @@ function network_to_name($s) {
NETWORK_XMPP => t('XMPP/IM'),
NETWORK_MYSPACE => t('MySpace'),
NETWORK_MAIL2 => t('Email'),
NETWORK_GPLUS => t('Google+')
NETWORK_GPLUS => t('Google+'),
NETWORK_PUMPIO => t('pump.io')
);
call_hooks('network_to_name', $nets);

View File

@ -542,7 +542,7 @@ function delivery_run(&$argv, &$argc){
diaspora_send_relay($target_item,$owner,$contact,$public_message);
break;
}
}
elseif(($top_level) && (! $walltowall)) {
// currently no workable solution for sending walltowall
logger('delivery: diaspora status: ' . $loc);
@ -558,6 +558,9 @@ function delivery_run(&$argv, &$argc){
case NETWORK_FACEBOOK :
if(get_config('system','dfrn_only'))
break;
case NETWORK_PUMPIO :
if(get_config('system','dfrn_only'))
break;
default:
break;
}

View File

@ -25,7 +25,6 @@ function expire_run(&$argv, &$argc){
load_config('config');
load_config('system');
$a->set_baseurl(get_config('system','url'));

View File

@ -881,12 +881,15 @@ function notifier_run(&$argv, &$argc){
case NETWORK_FACEBOOK:
if(get_config('system','dfrn_only'))
break;
case NETWORK_PUMPIO:
if(get_config('system','dfrn_only'))
break;
default:
break;
}
}
}
// send additional slaps to mentioned remote tags (@foo@example.com)
if($slap && count($url_recipients) && ($followup || $top_level) && $public_message && (! $expire)) {

View File

@ -76,7 +76,7 @@ function onepoll_run(&$argv, &$argc){
$contacts = q("SELECT `contact`.* FROM `contact`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
AND NOT `network` IN ( '%s', '%s' )
AND NOT `network` IN ( '%s', '%s', '%s' )
AND `contact`.`id` = %d
AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
AND `contact`.`archive` = 0 LIMIT 1",
@ -84,6 +84,7 @@ function onepoll_run(&$argv, &$argc){
intval(CONTACT_IS_FRIEND),
dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_FACEBOOK),
dbesc(NETWORK_PUMPIO),
intval($contact_id)
);
@ -526,6 +527,9 @@ function onepoll_run(&$argv, &$argc){
elseif($contact['network'] === NETWORK_FACEBOOK) {
// This is picked up by the Facebook plugin on a cron hook.
// Ignored here.
} elseif($contact['network'] === NETWORK_PUMPIO) {
// This is picked up by the pump.io plugin on a cron hook.
// Ignored here.
}
if($xml) {
@ -544,7 +548,7 @@ function onepoll_run(&$argv, &$argc){
// do it twice. Ensures that children of parents which may be later in the stream aren't tossed
consume_feed($xml,$importer,$contact,$hub,1,2);
$hubmode = 'subscribe';

View File

@ -173,7 +173,7 @@ function poller_run(&$argv, &$argc){
$contacts = q("SELECT `contact`.`id` FROM `contact` LEFT JOIN `user` ON `user`.`uid` = `contact`.`uid`
WHERE ( `rel` = %d OR `rel` = %d ) AND `poll` != ''
AND NOT `network` IN ( '%s', '%s' )
AND NOT `network` IN ( '%s', '%s', '%s' )
$sql_extra
AND `self` = 0 AND `contact`.`blocked` = 0 AND `contact`.`readonly` = 0
AND `contact`.`archive` = 0
@ -181,7 +181,8 @@ function poller_run(&$argv, &$argc){
intval(CONTACT_IS_SHARING),
intval(CONTACT_IS_FRIEND),
dbesc(NETWORK_DIASPORA),
dbesc(NETWORK_FACEBOOK)
dbesc(NETWORK_FACEBOOK),
dbesc(NETWORK_PUMPIO)
);
if(! count($contacts)) {