Merge pull request #1008 from annando/master

Expire, "attachment" element and database structure
This commit is contained in:
fabrixxm 2014-06-14 20:05:10 +02:00
commit adefb06ff7
13 changed files with 588 additions and 376 deletions

View file

@ -2,6 +2,79 @@
require_once("include/oembed.php");
require_once('include/event.php');
function bb_attachment($Text, $plaintext = false, $tryoembed = true) {
$Text = preg_replace_callback("/\[attachment(.*?)\](.*?)\[\/attachment\]/ism",
function ($match) use ($plaintext){
$attributes = $match[1];
$type = "";
preg_match("/type='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$type = $matches[1];
preg_match('/type="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$type = $matches[1];
if ($type == "")
return($match[0]);
if (!in_array($type, array("link", "audio", "video")))
return($match[0]);
$url = "";
preg_match("/url='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$url = $matches[1];
preg_match('/url="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$url = $matches[1];
$title = "";
preg_match("/title='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$title = $matches[1];
preg_match('/title="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$title = $matches[1];
$image = "";
preg_match("/image='(.*?)'/ism", $attributes, $matches);
if ($matches[1] != "")
$image = $matches[1];
preg_match('/image="(.*?)"/ism', $attributes, $matches);
if ($matches[1] != "")
$image = $matches[1];
if ($plaintext)
$text = sprintf('<a href="%s" target="_blank">%s</a>', $url, $title);
else {
$text = sprintf('<span class="type-%s">', $type);
$bookmark = array(sprintf('[bookmark=%s]%s[/bookmark]', $url, $title), $title, $url);
if ($tryoembed)
$oembed = tryoembed($bookmark);
else
$oembed = $bookmark[0];
if (($image != "") AND !strstr(strtolower($oembed), "<img "))
$text .= sprintf('<img src="%s" alt="%s" />', $image, $title); // To-Do: Anführungszeichen in "alt"
$text .= $oembed;
$text .= sprintf('<blockquote>%s</blockquote></span>', trim($match[2]));
}
return($text);
},$Text);
return($Text);
}
function bb_rearrange_link($shared) {
if ($shared[1] != "type-link")
return($shared[0]);
@ -535,6 +608,10 @@ function GetProfileUsername($profile, $username) {
if ($twitter != $profile)
return($username." (".$twitter.")");
$appnet = preg_replace("=https?://alpha.app.net/(.*)=ism", "$1@alpha.app.net", $profile);
if ($appnet != $profile)
return($username." (".$appnet.")");
$gplus = preg_replace("=https?://plus.google.com/(.*)=ism", "$1@plus.google.com", $profile);
if ($gplus != $profile)
return($username." (".$gplus.")");
@ -561,7 +638,7 @@ function GetProfileUsername($profile, $username) {
// pumpio (http://host.name/user)
$rest = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$3", $profile);
if ($rest == "") {
$pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "*$2@$1*", $profile);
$pumpio = preg_replace("=https?://([\.\w]+)/([\.\w]+)(.*)=ism", "$2@$1", $profile);
if ($pumpio != $profile)
return($username." (".$pumpio.")");
}
@ -706,6 +783,9 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
$Text = preg_replace("/\n\[code\]/ism", "[code]", $Text);
$Text = preg_replace("/\[\/code\]\n/ism", "[/code]", $Text);
// Handle attached links or videos
$Text = bb_attachment($Text, ($simplehtml != 4) AND ($simplehtml != 0), $tryoembed);
// Rearrange shared links
if (get_config("system", "rearrange_shared_links") AND (!$simplehtml OR $tryoembed))
$Text = preg_replace_callback("(\[class=(.*?)\](.*?)\[\/class\])ism","bb_rearrange_link",$Text);
@ -822,8 +902,8 @@ function bbcode($Text,$preserve_nl = false, $tryoembed = true, $simplehtml = fal
// Check for sized text
// [size=50] --> font-size: 50px (with the unit).
$Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1px;\">$2</span>",$Text);
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1;\">$2</span>",$Text);
$Text = preg_replace("(\[size=(\d*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1px; line-height: initial;\">$2</span>",$Text);
$Text = preg_replace("(\[size=(.*?)\](.*?)\[\/size\])ism","<span style=\"font-size: $1; line-height: initial;\">$2</span>",$Text);
// Check for centered text
$Text = preg_replace("(\[center\](.*?)\[\/center\])ism","<div style=\"text-align:center;\">$1</div>",$Text);

View file

@ -88,7 +88,8 @@ function network_to_name($s) {
NETWORK_PUMPIO => t('pump.io'),
NETWORK_TWITTER => t('Twitter'),
NETWORK_DIASPORA2 => t('Diaspora Connector'),
NETWORK_STATUSNET => t('Statusnet')
NETWORK_STATUSNET => t('Statusnet'),
NETWORK_APPNET => t('App.net')
);
call_hooks('network_to_name', $nets);

View file

@ -100,7 +100,7 @@ class dba {
public function q($sql, $onlyquery = false) {
global $a;
$strHandler = (true === $onlyquery) ? 'PDOStatement' : 'MULTI';
$strQueryAlias = md5($sql);

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,7 @@ function expire_run(&$argv, &$argc){
if(is_null($a)) {
$a = new App;
}
if(is_null($db)) {
@include(".htconfig.php");
require_once("include/dba.php");
@ -38,7 +38,7 @@ function expire_run(&$argv, &$argc){
q("optimize table item");
logger('expire: start');
$r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0");
if(count($r)) {
foreach($r as $rr) {
@ -47,6 +47,10 @@ function expire_run(&$argv, &$argc){
}
}
load_hooks();
call_hooks('expire');
return;
}

View file

@ -4102,7 +4102,7 @@ function item_getfeedattach($item) {
function item_expire($uid,$days) {
function item_expire($uid, $days, $network = "", $force = false) {
if((! $uid) || ($days < 1))
return;
@ -4113,9 +4113,17 @@ function item_expire($uid,$days) {
$expire_network_only = get_pconfig($uid,'expire','network_only');
$sql_extra = ((intval($expire_network_only)) ? " AND wall = 0 " : "");
if ($network != "") {
$sql_extra .= sprintf(" AND network = '%s' ", dbesc($network));
// There is an index "uid_network_received" but not "uid_network_created"
// This avoids the creation of another index just for one purpose.
// And it doesn't really matter wether to look at "received" or "created"
$range = "AND `received` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
} else
$range = "AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
$r = q("SELECT * FROM `item`
WHERE `uid` = %d
AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY
WHERE `uid` = %d $range
AND `id` = `parent`
$sql_extra
AND `deleted` = 0",
@ -4129,6 +4137,10 @@ function item_expire($uid,$days) {
$expire_items = get_pconfig($uid, 'expire','items');
$expire_items = (($expire_items===false)?1:intval($expire_items)); // default if not set: 1
// Forcing expiring of items - but not notes and marked items
if ($force)
$expire_items = true;
$expire_notes = get_pconfig($uid, 'expire','notes');
$expire_notes = (($expire_notes===false)?1:intval($expire_notes)); // default if not set: 1