* @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);
}
}
}
- function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false) {
+ function sanitize($str, $force_remove_images = false, $owner = false, $site_url = false, $highlight_words = false, $article_id = false) {
if (!$owner) $owner = $_SESSION["uid"];
$res = trim($str); if (!$res) return '';
- if (strpos($res, "href=") === false)
- $res = rewrite_urls($res);
-
$charset_hack = '<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>';
$disallowed_attributes = array('id', 'style', 'class');
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_SANITIZE) as $plugin) {
- $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes);
+ $retval = $plugin->hook_sanitize($doc, $site_url, $allowed_elements, $disallowed_attributes, $article_id);
if (is_array($retval)) {
$doc = $retval[0];
$allowed_elements = $retval[1];
if ($highlight_words) {
foreach ($highlight_words as $word) {
- $elements = $xpath->query('//*[contains(.,"'.$word.'")]');
+ // http://stackoverflow.com/questions/4081372/highlight-keywords-in-a-paragraph
- foreach ($elements as $element) {
- foreach ($element->childNodes as $child) {
+ $elements = $xpath->query("//*/text()");
- if (!$child instanceof DomText) continue;
+ foreach ($elements as $child) {
- $fragment = $doc->createDocumentFragment();
- $text = $child->textContent;
- $stubs = array();
+ $fragment = $doc->createDocumentFragment();
+ $text = $child->textContent;
+ $stubs = array();
- while (($pos = stripos($text, $word)) !== false) {
- $fragment->appendChild(new DomText(substr($text, 0, $pos)));
- $word = substr($text, $pos, strlen($word));
- $highlight = $doc->createElement('span');
- $highlight->appendChild(new DomText($word));
- $highlight->setAttribute('class', 'highlight');
- $fragment->appendChild($highlight);
- $text = substr($text, $pos + strlen($word));
- }
+ while (($pos = mb_stripos($text, $word)) !== false) {
+ $fragment->appendChild(new DomText(mb_substr($text, 0, $pos)));
+ $word = mb_substr($text, $pos, mb_strlen($word));
+ $highlight = $doc->createElement('span');
+ $highlight->appendChild(new DomText($word));
+ $highlight->setAttribute('class', 'highlight');
+ $fragment->appendChild($highlight);
+ $text = mb_substr($text, $pos + mb_strlen($word));
+ }
- if (!empty($text)) $fragment->appendChild(new DomText($text));
+ if (!empty($text)) $fragment->appendChild(new DomText($text));
- $element->replaceChild($fragment, $child);
- }
+ $child->parentNode->replaceChild($fragment, $child);
}
}
}
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;
$line["content"] = sanitize($line["content"],
sql_bool_to_bool($line['hide_images']),
- $owner_uid, $line["site_url"]);
+ $owner_uid, $line["site_url"], false, $line["id"]);
foreach (PluginHost::getInstance()->get_hooks(PluginHost::HOOK_RENDER_ARTICLE) as $p) {
$line = $p->hook_render_article($line);
$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 = "— " . truncate_string($entry["title"], 30);
+ else
+ $title = "";
+
+ $rv .= "<option value=\"".htmlspecialchars($entry["url"])."\">" . htmlspecialchars($entry["filename"]) . "$title</option>";
};
}
- function rewrite_urls($html) {
- libxml_use_internal_errors(true);
-
- $charset_hack = '<head>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
- </head>';
-
- $doc = new DOMDocument();
- $doc->loadHTML($charset_hack . $html);
- $xpath = new DOMXPath($doc);
-
- $entries = $xpath->query('//*/text()');
-
- foreach ($entries as $entry) {
- if (strstr($entry->wholeText, "://") !== false) {
- $text = preg_replace("/((?<!=.)((http|https|ftp)+):\/\/[^ ,!]+)/i",
- "<a target=\"_blank\" href=\"\\1\">\\1</a>", $entry->wholeText);
-
- if ($text != $entry->wholeText) {
- $cdoc = new DOMDocument();
- $cdoc->loadHTML($charset_hack . $text);
-
-
- foreach ($cdoc->childNodes as $cnode) {
- $cnode = $doc->importNode($cnode, true);
-
- if ($cnode) {
- $entry->parentNode->insertBefore($cnode);
- }
- }
-
- $entry->parentNode->removeChild($entry);
-
- }
- }
- }
-
- $node = $doc->getElementsByTagName('body')->item(0);
-
- // http://tt-rss.org/forum/viewtopic.php?f=1&t=970
- if ($node)
- return $doc->saveXML($node);
- else
- return $html;
- }
-
function filter_to_sql($filter, $owner_uid) {
$query = array();
$qpart .= " AND $cat_qpart";
}
+ $qpart .= " AND feed_id IS NOT NULL";
+
array_push($query, "($qpart)");
}