minor changes to config api and markdown_to_bb

This commit is contained in:
zotlabs 2016-12-05 14:50:34 -08:00
parent bdd713413a
commit fbf13dde21
8 changed files with 32 additions and 30 deletions

View File

@ -10,8 +10,8 @@ class AConfig {
return XConfig::Load('a_' . $account_id); return XConfig::Load('a_' . $account_id);
} }
static public function Get($account_id,$family,$key) { static public function Get($account_id,$family,$key,$default = false) {
return XConfig::Get('a_' . $account_id,$family,$key); return XConfig::Get('a_' . $account_id,$family,$key, $default);
} }
static public function Set($account_id,$family,$key,$value) { static public function Set($account_id,$family,$key,$value) {

View File

@ -16,7 +16,7 @@ class AbConfig {
} }
static public function Get($chan,$xhash,$family,$key) { static public function Get($chan,$xhash,$family,$key, $default = false) {
$r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1", $r = q("select * from abconfig where chan = %d and xchan = '%s' and cat = '%s' and k = '%s' limit 1",
intval($chan), intval($chan),
dbesc($xhash), dbesc($xhash),
@ -26,7 +26,7 @@ class AbConfig {
if($r) { if($r) {
return ((preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']); return ((preg_match('|^a:[0-9]+:{.*}$|s', $r[0]['v'])) ? unserialize($r[0]['v']) : $r[0]['v']);
} }
return false; return $default;
} }

View File

@ -98,13 +98,13 @@ class Config {
* @return mixed Return value or false on error or if not set * @return mixed Return value or false on error or if not set
*/ */
static public function Get($family,$key) { static public function Get($family,$key,$default = false) {
if((! array_key_exists($family, \App::$config)) || (! array_key_exists('config_loaded', \App::$config[$family]))) if((! array_key_exists($family, \App::$config)) || (! array_key_exists('config_loaded', \App::$config[$family])))
self::Load($family); self::Load($family);
if(array_key_exists('config_loaded', \App::$config[$family])) { if(array_key_exists('config_loaded', \App::$config[$family])) {
if(! array_key_exists($key, \App::$config[$family])) { if(! array_key_exists($key, \App::$config[$family])) {
return false; return $default;
} }
return ((! is_array(\App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$family][$key])) return ((! is_array(\App::$config[$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$family][$key]))
? unserialize(\App::$config[$family][$key]) ? unserialize(\App::$config[$family][$key])
@ -112,7 +112,7 @@ class Config {
); );
} }
return false; return $default;
} }
/** /**

View File

@ -10,7 +10,7 @@ class IConfig {
return; return;
} }
static public function Get(&$item, $family, $key) { static public function Get(&$item, $family, $key, $default = false) {
$is_item = false; $is_item = false;
@ -28,7 +28,7 @@ class IConfig {
$iid = $item; $iid = $item;
if(! $iid) if(! $iid)
return false; return $default;
if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) { if(is_array($item) && array_key_exists('iconfig',$item) && is_array($item['iconfig'])) {
foreach($item['iconfig'] as $c) { foreach($item['iconfig'] as $c) {
@ -48,7 +48,7 @@ class IConfig {
$item['iconfig'][] = $r[0]; $item['iconfig'][] = $r[0];
return $r[0]['v']; return $r[0]['v'];
} }
return false; return $default;
} }

View File

@ -67,16 +67,16 @@ class PConfig {
* @return mixed Stored value or false if it does not exist * @return mixed Stored value or false if it does not exist
*/ */
static public function Get($uid,$family,$key,$instore = false) { static public function Get($uid,$family,$key,$default = false) {
if(is_null($uid) || $uid === false) if(is_null($uid) || $uid === false)
return false; return $default;
if(! array_key_exists($uid, \App::$config)) if(! array_key_exists($uid, \App::$config))
self::Load($uid); self::Load($uid);
if((! array_key_exists($family, \App::$config[$uid])) || (! array_key_exists($key, \App::$config[$uid][$family]))) if((! array_key_exists($family, \App::$config[$uid])) || (! array_key_exists($key, \App::$config[$uid][$family])))
return false; return $default;
return ((! is_array(\App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$uid][$family][$key])) return ((! is_array(\App::$config[$uid][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$uid][$family][$key]))
? unserialize(\App::$config[$uid][$family][$key]) ? unserialize(\App::$config[$uid][$family][$key])

View File

@ -59,16 +59,16 @@ class XConfig {
* @return mixed Stored $value or false if it does not exist * @return mixed Stored $value or false if it does not exist
*/ */
static public function Get($xchan, $family, $key) { static public function Get($xchan, $family, $key, $default = false) {
if(! $xchan) if(! $xchan)
return false; return $default;
if(! array_key_exists($xchan, \App::$config)) if(! array_key_exists($xchan, \App::$config))
load_xconfig($xchan); load_xconfig($xchan);
if((! array_key_exists($family, \App::$config[$xchan])) || (! array_key_exists($key, \App::$config[$xchan][$family]))) if((! array_key_exists($family, \App::$config[$xchan])) || (! array_key_exists($key, \App::$config[$xchan][$family])))
return false; return $default;
return ((! is_array(\App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$xchan][$family][$key])) return ((! is_array(\App::$config[$xchan][$family][$key])) && (preg_match('|^a:[0-9]+:{.*}$|s', \App::$config[$xchan][$family][$key]))
? unserialize(\App::$config[$xchan][$family][$key]) ? unserialize(\App::$config[$xchan][$family][$key])

View File

@ -149,16 +149,18 @@ function markdown_to_bb($s, $use_zrl = false) {
$s = html2bbcode($s); $s = html2bbcode($s);
$s = preg_replace("/\[([uz])rl=(.*?)\]\[\/[uz]rl\]/ism",'[$1rl=$2]$2[/$1rl]',$s);
// protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands // protect the recycle symbol from turning into a tag, but without unescaping angles and naked ampersands
$s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s); $s = str_replace('♲',html_entity_decode('♲',ENT_QUOTES,'UTF-8'),$s);
// Convert everything that looks like a link to a link // Convert everything that looks like a link to a link
if($use_zrl) { if($use_zrl) {
$s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s); $s = str_replace(array('[img','/img]'),array('[zmg','/zmg]'),$s);
$s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s); $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[zrl=$2$3]$2$3[/zrl]',$s);
} }
else { else {
$s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,]+)/ism", '$1[url=$2$3]$2$3[/url]',$s); $s = preg_replace("/([^\]\=]|^)(https?\:\/\/)([a-zA-Z0-9\:\/\-\?\&\;\.\=\_\~\#\%\$\!\+\,\(\)]+)/ism", '$1[url=$2$3]$2$3[/url]',$s);
} }
// remove duplicate adjacent code tags // remove duplicate adjacent code tags

View File

@ -35,8 +35,8 @@ function load_config($family) {
Zlib\Config::Load($family); Zlib\Config::Load($family);
} }
function get_config($family, $key) { function get_config($family, $key, $default = false) {
return Zlib\Config::Get($family,$key); return Zlib\Config::Get($family,$key,$default);
} }
function set_config($family, $key, $value) { function set_config($family, $key, $value) {
@ -51,8 +51,8 @@ function load_pconfig($uid) {
Zlib\PConfig::Load($uid); Zlib\PConfig::Load($uid);
} }
function get_pconfig($uid, $family, $key, $instore = false) { function get_pconfig($uid, $family, $key, $default = false) {
return Zlib\PConfig::Get($uid,$family,$key,$instore = false); return Zlib\PConfig::Get($uid,$family,$key,$default);
} }
function set_pconfig($uid, $family, $key, $value) { function set_pconfig($uid, $family, $key, $value) {
@ -67,8 +67,8 @@ function load_xconfig($xchan) {
Zlib\XConfig::Load($xchan); Zlib\XConfig::Load($xchan);
} }
function get_xconfig($xchan, $family, $key) { function get_xconfig($xchan, $family, $key, $default = false) {
return Zlib\XConfig::Get($xchan,$family,$key); return Zlib\XConfig::Get($xchan,$family,$key, $default);
} }
function set_xconfig($xchan, $family, $key, $value) { function set_xconfig($xchan, $family, $key, $value) {
@ -83,8 +83,8 @@ function load_aconfig($account_id) {
Zlib\AConfig::Load($account_id); Zlib\AConfig::Load($account_id);
} }
function get_aconfig($account_id, $family, $key) { function get_aconfig($account_id, $family, $key, $default = false) {
return Zlib\AConfig::Get($account_id, $family, $key); return Zlib\AConfig::Get($account_id, $family, $key, $default);
} }
function set_aconfig($account_id, $family, $key, $value) { function set_aconfig($account_id, $family, $key, $value) {
@ -99,8 +99,8 @@ function load_abconfig($chan, $xhash, $family = '') {
return Zlib\AbConfig::Load($chan,$xhash,$family); return Zlib\AbConfig::Load($chan,$xhash,$family);
} }
function get_abconfig($chan,$xhash,$family,$key) { function get_abconfig($chan,$xhash,$family,$key, $default = false) {
return Zlib\AbConfig::Get($chan,$xhash,$family,$key); return Zlib\AbConfig::Get($chan,$xhash,$family,$key, $default);
} }
function set_abconfig($chan,$xhash,$family,$key,$value) { function set_abconfig($chan,$xhash,$family,$key,$value) {
@ -115,8 +115,8 @@ function load_iconfig(&$item) {
Zlib\IConfig::Load($item); Zlib\IConfig::Load($item);
} }
function get_iconfig(&$item, $family, $key) { function get_iconfig(&$item, $family, $key, $default = false) {
return Zlib\IConfig::Get($item, $family, $key); return Zlib\IConfig::Get($item, $family, $key, $default);
} }
function set_iconfig(&$item, $family, $key, $value, $sharing = false) { function set_iconfig(&$item, $family, $key, $value, $sharing = false) {