]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
logout user: commit destroyed session
[tt-rss.git] / include / functions.php
index fe0586678aaa1b3cc5aca64c55f478bee9e3b860..d88e96dd600ce75b3f32a6fcbb4d4099cd05ce2d 100755 (executable)
        }
 
        function logout_user() {
-               session_destroy();
+               @session_destroy();
                if (isset($_COOKIE[session_name()])) {
                   setcookie(session_name(), '', time()-42000, '/');
                }
+               session_commit();
        }
 
        function validate_csrf($csrf_token) {
                                }
 
                                if (!$_SESSION["uid"]) {
-                                       @session_destroy();
-                                       setcookie(session_name(), '', time()-42000, '/');
+                                       logout_user();
 
                                        render_login_form();
                                        exit;
                $doc->loadHTML($charset_hack . $res);
                $xpath = new DOMXPath($doc);
 
-               $entries = $xpath->query('(//img[@src]|//video/source[@src]|//audio/source[@src])');
+               $entries = $xpath->query('(//img[@src]|//video[@poster]|//video/source[@src]|//audio/source[@src])');
 
                $need_saving = false;
 
                foreach ($entries as $entry) {
 
-                       if ($entry->hasAttribute('src')) {
+                       if ($entry->hasAttribute('src') || $entry->hasAttribute('poster')) {
 
                                // should be already absolutized because this is called after sanitize()
-                               $src = $entry->getAttribute('src');
+                               $src = $entry->hasAttribute('poster') ? $entry->getAttribute('poster') : $entry->getAttribute('src');
                                $cached_filename = CACHE_DIR . '/images/' . sha1($src);
 
                                if (file_exists($cached_filename)) {
 
                                        $src = get_self_url_prefix() . '/public.php?op=cached_url&hash=' . sha1($src) . $suffix;
 
-                                       $entry->setAttribute('src', $src);
+                                       if ($entry->hasAttribute('poster'))
+                                               $entry->setAttribute('poster', $src);
+                                       else
+                                               $entry->setAttribute('src', $src);
+
                                        $need_saving = true;
                                }
                        }
                                                }
                                        }
                                }
+                       }
+
+                       if ($entry->hasAttribute('src') &&
+                                       ($owner && get_pref("STRIP_IMAGES", $owner)) || $force_remove_images || $_SESSION["bw_limit"]) {
+
+                               $p = $doc->createElement('p');
 
-                               if (($owner && get_pref("STRIP_IMAGES", $owner)) ||
-                                       $force_remove_images || $_SESSION["bw_limit"]) {
+                               $a = $doc->createElement('a');
+                               $a->setAttribute('href', $entry->getAttribute('src'));
 
-                                       $p = $doc->createElement('p');
+                               $a->appendChild(new DOMText($entry->getAttribute('src')));
+                               $a->setAttribute('target', '_blank');
+                               $a->setAttribute('rel', 'noopener noreferrer');
 
-                                       $a = $doc->createElement('a');
-                                       $a->setAttribute('href', $entry->getAttribute('src'));
+                               $p->appendChild($a);
 
-                                       $a->appendChild(new DOMText($entry->getAttribute('src')));
-                                       $a->setAttribute('target', '_blank');
-                                       $a->setAttribute('rel', 'noopener noreferrer');
+                               if ($entry->nodeName == 'source') {
 
-                                       $p->appendChild($a);
+                                       if ($entry->parentNode && $entry->parentNode->parentNode)
+                                               $entry->parentNode->parentNode->replaceChild($p, $entry->parentNode);
+
+                               } else if ($entry->nodeName == 'img') {
+
+                                       if ($entry->parentNode)
+                                               $entry->parentNode->replaceChild($p, $entry);
 
-                                       $entry->parentNode->replaceChild($p, $entry);
                                }
                        }
 
                should be loaded systemwide in config.php */
        function send_local_file($filename) {
                if (file_exists($filename)) {
+
+                       if (is_writable($filename)) touch($filename);
+
                        $tmppluginhost = new PluginHost();
 
                        $tmppluginhost->load(PLUGINS, PluginHost::KIND_SYSTEM);