]> git.wh0rd.org - tt-rss.git/blobdiff - functions.php
config: remove option ENABLE_UPDATE_DAEMON
[tt-rss.git] / functions.php
index ddde9994e5075e5d79882492100dd7d5c704d9a4..141d7bc8c71e266768e987c18bb20401d3d38e5d 100644 (file)
 
        $config = HTMLPurifier_Config::createDefault();
 
-       $allowed = "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4,s";
+       $allowed = "p,a[href],i,em,b,strong,code,pre,blockquote,br,img[src|alt|title],ul,ol,li,h1,h2,h3,h4,s,object[classid|type|id|name|width|height|codebase],param[name|value]";
 
+       $config->set('HTML.SafeObject', true);
        $config->set('HTML', 'Allowed', $allowed);
+       $config->set('Output.FlashCompat', true);
+       $config->set('Attr.EnableID', true);
+
        $purifier = new HTMLPurifier($config);
 
        /**
 
                                        $post_needs_update = false;
 
-                                       if ($update_on_checksum_change && $content_hash != $orig_content_hash) {
+                                       if ($content_hash != $orig_content_hash) {
 //                                             print "<!-- [$entry_title] $content_hash vs $orig_content_hash -->";
                                                $post_needs_update = true;
                                        }
                                                db_query($link, "UPDATE ttrss_entries
                                                        SET title = '$entry_title', content = '$entry_content',
                                                                content_hash = '$content_hash',
+                                                               updated = '$entry_timestamp_fmt',
                                                                num_comments = '$num_comments'
                                                        WHERE id = '$ref_id'");
 
                                                if ($mark_unread_on_update) {
                                                        db_query($link, "UPDATE ttrss_user_entries
                                                                SET last_read = null, unread = true WHERE ref_id = '$ref_id'");
-                                               } else {
+                                               } else if ($update_on_checksum_change) {
                                                        db_query($link, "UPDATE ttrss_user_entries
                                                                SET last_read = null WHERE ref_id = '$ref_id' AND unread = false");
                                                }
                    FROM ttrss_users WHERE
                                        login = '$login'";
 
+                               if (defined('AUTO_CREATE_USER') && AUTO_CREATE_USER
+                                               && $_SERVER["REMOTE_USER"]) {
+                                       $result = db_query($link, $query);
+
+                                       // First login ?
+                                       if (db_num_rows($result) == 0) {
+                                               $query = "INSERT INTO ttrss_users
+                                                               (login,access_level,last_login,created)
+                                                               VALUES ('$login', 0, null, NOW())";
+                                               db_query($link, $query);
+                                       }
+                               }
+
                        } else {
                                $query = "SELECT id,login,access_level,pwd_hash
                    FROM ttrss_users WHERE
                                db_query($link, "UPDATE ttrss_users SET last_login = NOW() WHERE id = " .
                                        $_SESSION["uid"]);
 
+
+                               // LemonLDAP can send user informations via HTTP HEADER
+                               if (defined('AUTO_CREATE_USER') && AUTO_CREATE_USER){
+                                       // update user name
+                                       if ($_SERVER['HTTP_USER_NAME']){
+                                               $fullname = db_escape_string($_SERVER['HTTP_USER_NAME']);
+                                               db_query($link, "UPDATE ttrss_users SET full_name = '$fullname' WHERE id = " .
+                                                       $_SESSION["uid"]);
+                                       }
+                                       // update user mail
+                                       if ($_SERVER['HTTP_USER_MAIL']){
+                                               $email = db_escape_string($_SERVER['HTTP_USER_MAIL']);
+                                               db_query($link, "UPDATE ttrss_users SET email = '$email' WHERE id = " .
+                                                       $_SESSION["uid"]);
+                                       }
+                               }
+
                                $_SESSION["ip_address"] = $_SERVER["REMOTE_ADDR"];
                                $_SESSION["pwd_hash"] = db_fetch_result($result, 0, "pwd_hash");
 
 
                $params["theme"] = get_user_theme($link);
                $params["theme_options"] = get_user_theme_options($link);
-               $params["daemon_enabled"] = ENABLE_UPDATE_DAEMON;
 
                $params["sign_progress"] = theme_image($link, "images/indicator_white.gif");
                $params["sign_progress_tiny"] = theme_image($link, "images/indicator_tiny.gif");
                $data['last_article_id'] = getLastArticleId($link);
                $data['cdm_expanded'] = get_pref($link, 'CDM_EXPANDED');
 
-               if (ENABLE_UPDATE_DAEMON) {
+               if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
 
                        $data['daemon_is_running'] = (int) file_is_locked("update_daemon.lock");
 
        function generate_syndicated_feed($link, $owner_uid, $feed, $is_cat,
                $limit, $search, $search_mode, $match_on, $view_mode = false) {
 
+               require_once "lib/MiniTemplator.class.php";
+
                $note_style =   "float : right; background-color : #fff7d5; border-width : 1px; ".
                        "padding : 5px; border-style : dashed; border-color : #e7d796;".
                        "margin-bottom : 1em; color : #9a8c59;";
                $feed_site_url = $qfh_ret[2];
                $last_error = $qfh_ret[3];
 
+               $feed_self_url = get_self_url_prefix() .
+                       "/backend.php?op=rss&id=-2&key=" .
+                       get_feed_access_key($link, -2, false);
+
                if (!$feed_site_url) $feed_site_url = get_self_url_prefix();
 
-               print "<?xml version=\"1.0\" encoding=\"utf-8\"?>
-                       <?xml-stylesheet type=\"text/xsl\" href=\"rss.xsl\"?>
-                       <rss version=\"2.0\" xmlns:dc=\"http://purl.org/dc/elements/1.1/\"
-                                 xmlns:atom=\"http://www.w3.org/2005/Atom\">
-                       <channel>";
+               $tpl = new MiniTemplator;
+
+               $tpl->readTemplateFromFile("templates/generated_feed.txt");
+
+               $tpl->setVariable('FEED_TITLE', $feed_title);
+               $tpl->setVariable('VERSION', VERSION);
+               $tpl->setVariable('FEED_URL', htmlspecialchars($feed_self_url));
 
                if (PUBSUBHUBBUB_HUB && $feed == -2) {
-                       print "<atom:link rel='hub' href='".PUBSUBHUBBUB_HUB."'/>";
+                       $tpl->setVariable('HUB_URL', htmlspecialchars(PUBSUBHUBBUB_HUB));
+                       $tpl->addBlock('feed_hub');
                }
 
-               print "<title>$feed_title</title>
-                       <link>$feed_site_url</link>
-                       <description>Feed generated by Tiny Tiny RSS</description>";
+               $tpl->setVariable('SELF_URL', htmlspecialchars(get_self_url_prefix()));
 
                while ($line = db_fetch_assoc($result)) {
-                       print "<item>";
-                       print "<guid>" . htmlspecialchars($line["guid"]) . "</guid>";
-                       print "<link>" . htmlspecialchars($line["link"]) . "</link>";
+                       $tpl->setVariable('ARTICLE_ID', htmlspecialchars($line['link']));
+                       $tpl->setVariable('ARTICLE_LINK', htmlspecialchars($line['link']));
+                       $tpl->setVariable('ARTICLE_TITLE', htmlspecialchars($line['title']));
+                       $tpl->setVariable('ARTICLE_EXCERPT',
+                               truncate_string(strip_tags($line["content_preview"]), 100, '...'));
 
-                       $tags = get_article_tags($link, $line["id"], $owner_uid);
+                       $content = sanitize_rss($link, $line["content_preview"], false, $owner_uid);
 
-                       foreach ($tags as $tag) {
-                               print "<category>" . htmlspecialchars($tag) . "</category>";
+                       if ($line['note']) {
+                               $content = "<div style=\"$note_style\">" . $line['note'] . "</div>" .
+                                       $content;
                        }
 
-                       $rfc822_date = date('r', strtotime($line["updated"]));
+                       $tpl->setVariable('ARTICLE_CONTENT', $content);
 
-                       print "<pubDate>$rfc822_date</pubDate>";
+                       $tpl->setVariable('ARTICLE_UPDATED', date('c', strtotime($line["updated"])));
+                       $tpl->setVariable('ARTICLE_AUTHOR', htmlspecialchars($line['author']));
 
-                       if ($line["author"]) {
-                               print "<author>" . htmlspecialchars($line["author"]) . "</author>";
-                       }
-
-                       print "<title><![CDATA[" .
-                               htmlspecialchars($line["title"]) . "]]></title>";
-
-                       print "<description><![CDATA[";
+                       $tags = get_article_tags($link, $line["id"], $owner_uid);
 
-                       if ($line["note"]) {
-                               print "<div style='$note_style'>";
-                               print $line["note"];
-                               print "</div>";
+                       foreach ($tags as $tag) {
+                               $tpl->setVariable('ARTICLE_CATEGORY', htmlspecialchars($tag));
+                               $tpl->addBlock('category');
                        }
 
-                       print sanitize_rss($link, $line["content_preview"], false, $owner_uid);
-                       print "]]></description>";
-
                        $enclosures = get_article_enclosures($link, $line["id"]);
 
                        foreach ($enclosures as $e) {
                                $type = htmlspecialchars($e['content_type']);
                                $url = htmlspecialchars($e['content_url']);
                                $length = $e['duration'];
-                               print "<enclosure url=\"$url\" type=\"$type\" length=\"$length\"/>";
+
+                               $tpl->setVariable('ARTICLE_ENCLOSURE_URL', $url);
+                               $tpl->setVariable('ARTICLE_ENCLOSURE_TYPE', $type);
+                               $tpl->setVariable('ARTICLE_ENCLOSURE_LENGTH', $length);
+
+                               $tpl->addBlock('enclosure');
                        }
 
-                       print "</item>";
-               }
+                       $tpl->addBlock('entry');
+               }
 
-               print "</channel></rss>";
+               $tmp = "";
 
+               $tpl->addBlock('feed');
+               $tpl->generateOutputToString($tmp);
+
+               print $tmp;
        }
 
        function getCategoryTitle($link, $cat_id) {
 
                $res = trim($str); if (!$res) return '';
 
-               if (get_pref($link, "STRIP_UNSAFE_TAGS", $owner) || $force_strip_tags) {
-                       $res = $purifier->purify($res);
-               }
+//             if (get_pref($link, "STRIP_UNSAFE_TAGS", $owner) || $force_strip_tags) {
+               $res = $purifier->purify($res);
+//             }
 
                if (get_pref($link, "STRIP_IMAGES", $owner)) {
                        $res = preg_replace('/<img[^>]+>/is', '', $res);
                        $search_q = "";
                }
 
-               // Adaptive doesn't really make any sense for generated feeds
-               // All Articles is the default, so no need to insert it either
-               if ($view_mode == "adaptive" || $view_mode == "all_articles")
-                       $view_mode = "";
-               else
-                       $view_mode = "&view-mode=$view_mode";
-
                $reply .= "
                        <a href=\"#\"
                                title=\"".__("View as RSS feed")."\"
 
                $tag = mb_strtolower($tag, 'utf-8');
 
-               $tag = preg_replace('/[\"\+\>\<]/', "", $tag);
+               $tag = preg_replace('/[\'\"\+\>\<]/', "", $tag);
 
 //             $tag = str_replace('"', "", $tag);
 //             $tag = str_replace("+", " ", $tag);