]> git.wh0rd.org - tt-rss.git/blobdiff - include/functions.php
pass logfile to child tasks if locking is possible, lock logfile before writing,...
[tt-rss.git] / include / functions.php
index 56361472ee5f4cc9b280fc6a5fce02932c89d7bf..8ede14a0bfa7a188b036d8ac704aff70dd7c22a9 100644 (file)
         * @return void
         */
        function _debug($msg, $show = true) {
+               if (defined('SUPPRESS_DEBUGGING'))
+                       return false;
 
                $ts = strftime("%H:%M:%S", time());
                if (function_exists('posix_getpid')) {
                        $fp = fopen(LOGFILE, 'a+');
 
                        if ($fp) {
+                               $locked = false;
+
+                               if (function_exists("flock")) {
+                                       $tries = 0;
+
+                                       // try to lock logfile for writing
+                                       while ($tries < 5 && !$locked = flock($fp, LOCK_EX | LOCK_NB)) {
+                                               sleep(1);
+                                               ++$tries;
+                                       }
+
+                                       if (!$locked) {
+                                               fclose($fp);
+                                               return;
+                                       }
+                               }
+
                                fputs($fp, "[$ts] $msg\n");
+
+                               if (function_exists("flock")) {
+                                       flock($fp, LOCK_UN);
+                               }
+
                                fclose($fp);
                        }
                }
                if (preg_match("/^[0-9]*$/", $tag)) return false;
                if (mb_strlen($tag) > 250) return false;
 
-               if (function_exists('iconv')) {
-                       $tag = iconv("utf-8", "utf-8", $tag);
-               }
-
                if (!$tag) return false;
 
                return true;
 
                $cat_id = (int)getFeedCategory($feed_id);
 
+               if ($cat_id == 0)
+                       $null_cat_qpart = "cat_id IS NULL OR";
+               else
+                       $null_cat_qpart = "";
+
                $result = db_query("SELECT * FROM ttrss_filters2 WHERE
                        owner_uid = $owner_uid AND enabled = true ORDER BY order_id, title");
 
                                FROM ttrss_filters2_rules AS r,
                                ttrss_filter_types AS t
                                WHERE
-                                       (cat_id IS NULL OR cat_id IN ($check_cats)) AND
+                                       ($null_cat_qpart (cat_id IS NULL AND cat_filter = false) OR cat_id IN ($check_cats)) AND
                                        (feed_id IS NULL OR feed_id = '$feed_id') AND
                                        filter_type = t.id AND filter_id = '$filter_id'");
 
 
                                $url = $line["content_url"];
                                $ctype = $line["content_type"];
+                               $title = $line["title"];
 
                                if (!$ctype) $ctype = __("unknown type");
 
                                $entry["type"] = $ctype;
                                $entry["filename"] = $filename;
                                $entry["url"] = $url;
+                               $entry["title"] = $title;
 
                                array_push($entries, $entry);
                        }
                                                                        $rv .= "<p><a target=\"_blank\"
                                                                        href=\"".htmlspecialchars($entry["url"])."\"
                                                                        >" .htmlspecialchars($entry["url"]) . "</a></p>";
+                                                               }
 
+                                                               if ($entry['title']) {
+                                                                       $rv.= "<div class=\"enclosure_title\">${entry['title']}</div>";
                                                                }
                                                }
                                        }
                                "<option value=''>" . __('Attachments')."</option>";
 
                        foreach ($entries as $entry) {
-                               $rv .= "<option value=\"".htmlspecialchars($entry["url"])."\">" . htmlspecialchars($entry["filename"]) . "</option>";
+                               if ($entry["title"])
+                                       $title = "&mdash; " . truncate_string($entry["title"], 30);
+                               else
+                                       $title = "";
+
+                               $rv .= "<option value=\"".htmlspecialchars($entry["url"])."\">" . htmlspecialchars($entry["filename"]) . "$title</option>";
 
                        };
 
                                        $qpart .= " AND $cat_qpart";
                                }
 
+                               $qpart .= " AND feed_id IS NOT NULL";
+
                                array_push($query, "($qpart)");
 
                        }