]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
define Reply::pkeyGet()
[quix0rs-gnu-social.git] / lib / util.php
index 05c5407cdb5b6db216254e8416f875b62ed2be62..d35833851900758a2354849063050cdfe745e865 100644 (file)
@@ -1,7 +1,7 @@
 <?php
 /*
  * StatusNet - the distributed open-source microblogging tool
- * Copyright (C) 2008, 2009, StatusNet, Inc.
+ * Copyright (C) 2008-2011, StatusNet, Inc.
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU Affero General Public License as published by
@@ -233,7 +233,13 @@ function common_check_user($nickname, $password)
     $authenticatedUser = false;
 
     if (Event::handle('StartCheckPassword', array($nickname, $password, &$authenticatedUser))) {
-        $user = User::staticGet('nickname', common_canonical_nickname($nickname));
+
+        if (common_is_email($nickname)) {
+            $user = User::staticGet('email', common_canonical_email($nickname));
+        } else {
+            $user = User::staticGet('nickname', common_canonical_nickname($nickname));
+        }
+
         if (!empty($user)) {
             if (!empty($password)) { // never allow login with blank password
                 if (0 == strcmp(common_munge_password($password, $user->id),
@@ -1464,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')) {
@@ -1496,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.
@@ -1860,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.
@@ -1933,7 +1962,16 @@ function common_confirmation_code($bits)
 
 function common_markup_to_html($c, $args=null)
 {
-    $c = preg_replace('/%%arg.(\w+)%%/', "{$args['\\1']}", $c);
+    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);
@@ -1970,20 +2008,20 @@ function common_user_property($property)
 
 function common_profile_uri($profile)
 {
-    if (!$profile) {
-        return null;
-    }
-    $user = User::staticGet($profile->id);
-    if ($user) {
-        return $user->uri;
-    }
+    $uri = null;
 
-    $remote = Remote_profile::staticGet($profile->id);
-    if ($remote) {
-        return $remote->uri;
+    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)
@@ -2264,3 +2302,8 @@ function common_log_perf_counters()
         }
     }
 }
+
+function common_is_email($str)
+{
+    return (strpos($str, '@') !== false);
+}