X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=lib%2Futil.php;h=d35833851900758a2354849063050cdfe745e865;hb=14fe22e4307044f2eb08264a7b83f9c2de245dba;hp=d48d4c18c59b485c6ded326c1d8493be6bda1fa8;hpb=f47027abbefe35d17df50c67eec7cd1156a5e39a;p=quix0rs-gnu-social.git diff --git a/lib/util.php b/lib/util.php index d48d4c18c5..d358338519 100644 --- a/lib/util.php +++ b/lib/util.php @@ -1,7 +1,7 @@ id), @@ -638,7 +644,7 @@ function common_linkify_mention($mention) $xs->elementStart('span', 'vcard'); $xs->elementStart('a', $attrs); - $xs->element('span', 'fn nickname', $mention['text']); + $xs->element('span', 'fn nickname mention', $mention['text']); $xs->elementEnd('a'); $xs->elementEnd('span'); @@ -1150,7 +1156,7 @@ function common_group_link($sender_id, $nickname) $xs = new XMLStringer(); $xs->elementStart('span', 'vcard'); $xs->elementStart('a', $attrs); - $xs->element('span', 'fn nickname', $nickname); + $xs->element('span', 'fn nickname group', $nickname); $xs->elementEnd('a'); $xs->elementEnd('span'); return $xs->getString(); @@ -1221,19 +1227,22 @@ function common_relative_profile($sender, $nickname, $dt=null) function common_local_url($action, $args=null, $params=null, $fragment=null, $addSession=true) { - $r = Router::get(); - $path = $r->build($action, $args, $params, $fragment); + if (Event::handle('StartLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url))) { + $r = Router::get(); + $path = $r->build($action, $args, $params, $fragment); - $ssl = common_is_sensitive($action); + $ssl = common_is_sensitive($action); - if (common_config('site','fancy')) { - $url = common_path(mb_substr($path, 1), $ssl, $addSession); - } else { - if (mb_strpos($path, '/index.php') === 0) { + if (common_config('site','fancy')) { $url = common_path(mb_substr($path, 1), $ssl, $addSession); } else { - $url = common_path('index.php'.$path, $ssl, $addSession); + if (mb_strpos($path, '/index.php') === 0) { + $url = common_path(mb_substr($path, 1), $ssl, $addSession); + } else { + $url = common_path('index.php'.$path, $ssl, $addSession); + } } + Event::handle('EndLocalURL', array(&$action, &$params, &$fragment, &$addSession, &$url)); } return $url; } @@ -1461,8 +1470,7 @@ function common_redirect($url, $code=307) function common_enqueue_notice($notice) { - static $localTransports = array('omb', - 'ping'); + static $localTransports = array('ping'); $transports = array(); if (common_config('sms', 'enabled')) { @@ -1493,7 +1501,7 @@ function common_enqueue_notice($notice) } /** - * Broadcast profile updates to OMB and other remote subscribers. + * Broadcast profile updates to remote subscribers. * * Since this may be slow with a lot of subscribers or bad remote sites, * this is run through the background queues if possible. @@ -1857,6 +1865,30 @@ function common_config($main, $sub) array_key_exists($sub, $config[$main])) ? $config[$main][$sub] : false; } +function common_config_set($main, $sub, $value) +{ + global $config; + if (!array_key_exists($main, $config)) { + $config[$main] = array(); + } + $config[$main][$sub] = $value; +} + +function common_config_append($main, $sub, $value) +{ + global $config; + if (!array_key_exists($main, $config)) { + $config[$main] = array(); + } + if (!array_key_exists($sub, $config[$main])) { + $config[$main][$sub] = array(); + } + if (!is_array($config[$main][$sub])) { + $config[$main][$sub] = array($config[$main][$sub]); + } + array_push($config[$main][$sub], $value); +} + /** * Pull arguments from a GET/POST/REQUEST array with first-level input checks: * strips "magic quotes" slashes if necessary, and kills invalid UTF-8 strings. @@ -1928,30 +1960,68 @@ function common_confirmation_code($bits) // convert markup to HTML -function common_markup_to_html($c) +function common_markup_to_html($c, $args=null) { + if (is_null($args)) { + $args = array(); + } + + // XXX: not very efficient + + foreach ($args as $name => $value) { + $c = preg_replace('/%%arg.'.$name.'%%/', $value, $c); + } + + $c = preg_replace('/%%user.(\w+)%%/e', "common_user_property('\\1')", $c); $c = preg_replace('/%%action.(\w+)%%/e', "common_local_url('\\1')", $c); $c = preg_replace('/%%doc.(\w+)%%/e', "common_local_url('doc', array('title'=>'\\1'))", $c); $c = preg_replace('/%%(\w+).(\w+)%%/e', 'common_config(\'\\1\', \'\\2\')', $c); return Markdown($c); } -function common_profile_uri($profile) +function common_user_property($property) { - if (!$profile) { + $profile = Profile::current(); + + if (empty($profile)) { return null; } - $user = User::staticGet($profile->id); - if ($user) { - return $user->uri; + + switch ($property) { + case 'profileurl': + case 'nickname': + case 'fullname': + case 'location': + case 'bio': + return $profile->$property; + break; + case 'avatar': + return $profile->getAvatar(AVATAR_STREAM_SIZE); + break; + case 'bestname': + return $profile->getBestName(); + break; + default: + return null; } +} - $remote = Remote_profile::staticGet($profile->id); - if ($remote) { - return $remote->uri; +function common_profile_uri($profile) +{ + $uri = null; + + if (!empty($profile)) { + if (Event::handle('StartCommonProfileURI', array($profile, &$uri))) { + $user = User::staticGet($profile->id); + if (!empty($user)) { + $uri = $user->uri; + } + Event::handle('EndCommonProfileURI', array($profile, &$uri)); + } } + // XXX: this is a very bad profile! - return null; + return $uri; } function common_canonical_sms($sms) @@ -2232,3 +2302,8 @@ function common_log_perf_counters() } } } + +function common_is_email($str) +{ + return (strpos($str, '@') !== false); +}