]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/util.php
Cleanup and documentation of common_ensure_session
[quix0rs-gnu-social.git] / lib / util.php
index 07773a06f39d08f414ac27955f5a9c2f0dccd582..f2e09daa936fd66801cda26371734bb144297c15 100644 (file)
@@ -197,7 +197,7 @@ function common_language()
     if (common_config('site', 'langdetect')) {
         $httplang = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : null;
         if (!empty($httplang)) {
-            $language = client_prefered_language($httplang);
+            $language = client_preferred_language($httplang);
             if ($language)
               return $language;
         }
@@ -275,25 +275,25 @@ function common_have_session()
     return (0 != strcmp(session_id(), ''));
 }
 
+/**
+ * Make sure session is started and handled by
+ * the correct handler.
+ */
 function common_ensure_session()
 {
-    $c = null;
-    if (array_key_exists(session_name(), $_COOKIE)) {
-        $c = $_COOKIE[session_name()];
-    }
     if (!common_have_session()) {
         if (common_config('sessions', 'handle')) {
-            Session::setSaveHandler();
+            session_set_save_handler(new InternalSessionHandler(), true);
+        }
+        if (array_key_exists(session_name(), $_GET)) {
+            $id = $_GET[session_name()];
+        } else if (array_key_exists(session_name(), $_COOKIE)) {
+            $id = $_COOKIE[session_name()];
         }
-       if (array_key_exists(session_name(), $_GET)) {
-           $id = $_GET[session_name()];
-       } else if (array_key_exists(session_name(), $_COOKIE)) {
-           $id = $_COOKIE[session_name()];
-       }
-       if (isset($id)) {
-           session_id($id);
-       }
-        @session_start();
+        if (isset($id)) {
+            session_id($id);
+        }
+        session_start();
         if (!isset($_SESSION['started'])) {
             $_SESSION['started'] = time();
             if (!empty($id)) {
@@ -610,6 +610,10 @@ function common_purify($html, array $args=array())
         $cfg->set('URI.Base', $args['URI.Base']);   // if null this is like unsetting it I presume
         $cfg->set('URI.MakeAbsolute', !is_null($args['URI.Base']));   // if we have a URI base, convert relative URLs to absolute ones.
     }
+    if (common_config('cache', 'dir')) {
+        $cfg->set('Cache.SerializerPath', common_config('cache', 'dir'));
+    }
+    // if you don't want to use the default cache dir for htmlpurifier, set it specifically as $config['htmlpurifier']['Cache.SerializerPath'] = '/tmp'; or something.
     foreach (common_config('htmlpurifier') as $key=>$val) {
         $cfg->set($key, $val);
     }
@@ -847,9 +851,8 @@ function common_find_mentions($text, Profile $sender, Notice $parent=null)
                                 'url' => $url);
         }
 
-        preg_match_all('/'.Nickname::BEFORE_MENTIONS.'!(' . Nickname::DISPLAY_FMT . ')/',
-                       $text, $hmatches, PREG_OFFSET_CAPTURE);
-        foreach ($hmatches[1] as $hmatch) {
+        $hmatches = common_find_mentions_raw($text, '!');
+        foreach ($hmatches as $hmatch) {
             $nickname = Nickname::normalize($hmatch[0]);
             $group = User_group::getForNickname($nickname, $sender);