]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Link rtsp, mms & tel URI schemes, correct pseudo-protocol ones.
[quix0rs-gnu-social.git] / lib / util.php
index 42bc08e7ee5df115b918eae82c412d8f231a96f3..d7af3f2045eba96552e1e9f07d7e9b1b4c5d26d1 100644 (file)
 
 function common_server_error($msg, $code=500)
 {
-    static $status = array(500 => 'Internal Server Error',
-                           501 => 'Not Implemented',
-                           502 => 'Bad Gateway',
-                           503 => 'Service Unavailable',
-                           504 => 'Gateway Timeout',
-                           505 => 'HTTP Version Not Supported');
-
-    if (!array_key_exists($code, $status)) {
-        $code = 500;
-    }
-
-    $status_string = $status[$code];
-
-    header('HTTP/1.1 '.$code.' '.$status_string);
-    header('Content-type: text/plain');
-
-    print $msg;
-    print "\n";
-    exit();
+    $err = new ServerErrorAction($msg, $code);
+    $err->showPage();
 }
 
 // Show a user error
 function common_user_error($msg, $code=400)
 {
-    static $status = array(400 => 'Bad Request',
-                           401 => 'Unauthorized',
-                           402 => 'Payment Required',
-                           403 => 'Forbidden',
-                           404 => 'Not Found',
-                           405 => 'Method Not Allowed',
-                           406 => 'Not Acceptable',
-                           407 => 'Proxy Authentication Required',
-                           408 => 'Request Timeout',
-                           409 => 'Conflict',
-                           410 => 'Gone',
-                           411 => 'Length Required',
-                           412 => 'Precondition Failed',
-                           413 => 'Request Entity Too Large',
-                           414 => 'Request-URI Too Long',
-                           415 => 'Unsupported Media Type',
-                           416 => 'Requested Range Not Satisfiable',
-                           417 => 'Expectation Failed');
-
-    if (!array_key_exists($code, $status)) {
-        $code = 400;
-    }
-
-    $status_string = $status[$code];
-
-    header('HTTP/1.1 '.$code.' '.$status_string);
-
-    common_show_header('Error');
-    common_element('div', array('class' => 'error'), $msg);
-    common_show_footer();
+    $err = new ClientErrorAction($msg, $code);
+    $err->showPage();
 }
 
 function common_init_locale($language=null)
@@ -415,8 +370,6 @@ function common_canonical_email($email)
     return $email;
 }
 
-define('URL_REGEX', '^|[ \t\r\n])((ftp|http|https|gopher|mailto|news|nntp|telnet|wais|file|prospero|aim|webcal):(([A-Za-z0-9$_.+!*(),;/?:@&~=-])|%[A-Fa-f0-9]{2}){2,}(#([a-zA-Z0-9][a-zA-Z0-9$_.+!*(),;/?:@&~=%-]*))?([A-Za-z0-9$_+!*();/?:~-]))');
-
 function common_render_content($text, $notice)
 {
     $r = common_render_text($text);
@@ -433,7 +386,8 @@ function common_render_text($text)
     $r = htmlspecialchars($text);
 
     $r = preg_replace('/[\x{0}-\x{8}\x{b}-\x{c}\x{e}-\x{19}]/', '', $r);
-    $r = preg_replace_callback('@https?://[^\]>\s]+@', 'common_render_uri_thingy', $r);
+    $r = preg_replace_callback('@(ftp|http|https|mms|rtsp|gopher|news|nntp|telnet|wais|file|prospero|webcal|xmpp|irc)://[^\]>\s]+@', 'common_render_uri_thingy', $r);
+    $r = preg_replace_callback('@(mailto|aim|tel):[^\]>\s]+@', 'common_render_uri_thingy', $r); // Pseudo-protocols don't require '//' after ':'.
     $r = preg_replace('/(^|\s+)#([A-Za-z0-9_\-\.]{1,64})/e', "'\\1#'.common_tag_link('\\2')", $r);
     // XXX: machine tags
     return $r;
@@ -868,6 +822,8 @@ function common_fancy_url($action, $args=null)
         return common_path('settings/im');
      case 'avatarsettings':
         return common_path('settings/avatar');
+     case 'groupsearch':
+        return common_path('search/group' . (($args) ? ('?' . http_build_query($args)) : ''));
      case 'peoplesearch':
         return common_path('search/people' . (($args) ? ('?' . http_build_query($args)) : ''));
      case 'noticesearch':
@@ -930,7 +886,7 @@ function common_fancy_url($action, $args=null)
      case 'newgroup':
         return common_path('group/new');
      case 'showgroup':
-        return common_path('group/'.$args['nickname']);
+        return common_path('group/'.$args['nickname'] . (($args['page']) ? ('?page=' . $args['page']) : ''));
      case 'editgroup':
         return common_path('group/'.$args['nickname'].'/edit');
      case 'joingroup':
@@ -943,10 +899,14 @@ function common_fancy_url($action, $args=null)
         return common_path('group/'.$args['nickname'].'/rss');
      case 'groupmembers':
         return common_path('group/'.$args['nickname'].'/members');
+     case 'grouplogo':
+        return common_path('group/'.$args['nickname'].'/logo');
      case 'usergroups':
-        return common_path($args['nickname'].'/groups');
+        $nickname = $args['nickname'];
+        unset($args['nickname']);
+        return common_path($nickname.'/groups' . (($args) ? ('?' . http_build_query($args)) : ''));
      case 'groups':
-        return common_path('group');
+        return common_path('group' . (($args) ? ('?' . http_build_query($args)) : ''));
      default:
         return common_simple_url($action, $args);
     }
@@ -1181,23 +1141,6 @@ function common_enqueue_notice($notice)
     return $result;
 }
 
-function common_dequeue_notice($notice)
-{
-    $qi = Queue_item::staticGet($notice->id);
-    if ($qi) {
-        $result = $qi->delete();
-        if (!$result) {
-            $last_error = &PEAR::getStaticProperty('DB_DataObject','lastError');
-            common_log(LOG_ERR, 'DB error deleting queue item: ' . $last_error->message);
-            return false;
-        }
-        common_log(LOG_DEBUG, 'complete dequeueing notice ID = ' . $notice->id);
-        return $result;
-    } else {
-        return false;
-    }
-}
-
 function common_real_broadcast($notice, $remote=false)
 {
     $success = true;