Beispiel #1
0
/**
 * Render a sepecific feed instance
 *
 * @param Feed $feed
 * @param Smarty $smarty
 * @return null
 */
function render_rss_feed($feed, $header = true)
{
    if ($header) {
        header('Content-Type: text/xml; charset=utf-8');
    }
    // if
    $result = "<rss version=\"2.0\">\n<channel>\n";
    $result .= '<title>' . clean($feed->getTitle()) . "</title>\n";
    $result .= '<link>' . clean($feed->getLink()) . "</link>\n";
    if ($description = trim($feed->getDescription())) {
        $result .= '<description><![CDATA[' . clean($description) . "]]></description>\n";
    }
    // if
    if ($language = trim($feed->getLanguage())) {
        $result .= '<language>' . clean($language) . "</language>\n";
    }
    // if
    foreach ($feed->getItems() as $item) {
        $result .= "<item>\n";
        $result .= '<title>' . clean($item->getTitle()) . "</title>\n";
        $result .= '<link>' . clean($item->getLink()) . "</link>\n";
        if ($description = trim($item->getDescription())) {
            $result .= '<description><![CDATA[' . $description . "]]></description>\n";
        }
        // if
        $author = $item->getAuthor();
        if (instance_of($author, 'FeedAuthor')) {
            $result .= '<author>' . clean($author->getEmail()) . ' (' . clean($author->getName()) . ")</author>\n";
        }
        // if
        $pubdate = $item->getPublicationDate();
        if (instance_of($pubdate, 'DateValue')) {
            $result .= '<pubDate>' . $pubdate->toRSS() . "</pubDate>\n";
        }
        // if
        $id = $item->getId();
        if ($id) {
            $result .= '<guid>' . clean($id) . "</guid>\n";
        }
        // if
        $result .= "</item>\n";
    }
    // foreach
    $result .= "</channel>\n</rss>";
    return $result;
}
Beispiel #2
0
    public function save(Feed $feed, $folderid)
    {
        $title = $feed->getTitle();
        $url = $feed->getUrl();
        $url_hash = md5($url);
        if (empty($title)) {
            $l = \OC_L10N::get('news');
            $title = $l->t('no title');
        }
        $favicon = $feed->getFavicon();
        //FIXME: Detect when feed contains already a database id
        $feedid = $this->findIdFromUrl($url);
        if ($feedid === null) {
            $query = \OCP\DB::prepare("\n\t\t\t\tINSERT INTO " . self::tableName . "(url, url_hash, title, favicon_link, folder_id, user_id, added, lastmodified)\n\t\t\t\tVALUES (?, ?, ?, ?, ?, ?, UNIX_TIMESTAMP(), UNIX_TIMESTAMP())\n\t\t\t\t");
            $params = array($url, $url_hash, $title, $favicon, $folderid, $this->userid);
            $query->execute($params);
            $feedid = \OCP\DB::insertid(self::tableName);
        } else {
            //update the db. it needs to be done, since it might be the first save after a full fetch
            $stmt = \OCP\DB::prepare('
					UPDATE ' . self::tableName . ' SET favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
					WHERE id = ?
					');
            $params = array($favicon, $folderid, $feedid);
            $stmt->execute($params);
        }
        $feed->setId($feedid);
        $itemMapper = new ItemMapper();
        $items = $feed->getItems();
        if ($items !== null) {
            foreach ($items as $item) {
                $itemMapper->save($item, $feedid);
            }
        }
        return $feedid;
    }
Beispiel #3
0
		function saveFeedItem($feedId,$feedVisibility,$item){
			global $database, $db, $event;

			$db->query("SELECT id FROM {$database['prefix']}DeleteHistory WHERE feed='$feedId' and permalink='{$item['permalink']}'");
			if ($db->numRows() > 0) 
				return false;
	
			if ($item['written']>gmmktime()+86400)
				return false;

			$item['title']=$db->escape($db->lessen(UTF8::correct($item['title'])));

			list($useRssOut) = Settings::gets('useRssOut');
		
			list($feedCreated,$localFilter,$localFilterType) = Feed::gets($feedId, 'created,filter,filterType');

			$tagString=$db->escape($db->lessen(UTF8::correct(implode(', ',$item['tags']))));

			list($globalFilter,$blackFilter,$globalFilterType,$blackFilterType) = Settings::gets('filter,blackfilter,filterType,blackfilterType');
			$filter = empty($globalFilter)?$localFilter:$globalFilter;
			$filterType = empty($globalFilter)?$localFilterType:$globalFilterType;


			if (!Validator::is_empty($filter)) {
				$filtered = true;				
				$allowTags = explode(',', $filter);

				if($filterType == 'tag' || $filterType == 'tag+title') {					
					foreach ($allowTags as $ftag) {
						if (Validator::enum($ftag, $tagString)) {
							$filtered = false;
							break;
						}
					}
				}

				if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) {
					foreach ($allowTags as $ftag) {
						if(strpos($item['title'],$ftag)!==false) {
							$filtered = false;
							break;
						}
					}
				}

				if ($filtered) return false;
			}

			if (!Validator::is_empty($blackFilter)) {
				$filtered = false;
				$denyTags = explode(',', $blackFilter);
				if($blackFilterType == 'tag' || $blackFilterType == 'tag+title') {					
					foreach ($denyTags as $ftag) {
						if (Validator::enum($ftag, $tagString)) {
							$filtered = true;
							break;
						}
					}
				}
				if($filtered && ($filterType == 'title' || $filterType == 'tag+title')) {
					foreach ($denyTags as $ftag) {
						if(strpos($item['title'],$ftag)!==false) {
							$filtered = true;
							break;
						}
					}
				}

				if ($filtered) return false;
			}

			if (preg_match('/\((.[^\)]+)\)$/Ui', trim($item['author']), $_matches)) $item['author'] = $_matches[1];
			$item['author']=$db->escape($db->lessen(UTF8::correct($item['author'])));
			$item['permalink']=$db->escape($db->lessen(UTF8::correct($item['permalink'])));
			$item['description']=$db->escape($db->lessen(UTF8::correct(trim($item['description'])),65535));
			
			$enclosures = array();
			foreach($item['enclosures'] as $en) {
				array_push($enclosures, $en['url']);
			}

			$enclosureString=$db->escape($db->lessen(UTF8::correct(implode('|',$enclosures))));				

			$deadLine=0;
			$feedLife = Settings::get('archivePeriod');
			if ($feedLife > 0) $deadLine=gmmktime()-($feedLife*86400);

			requireComponent('Bloglounge.Data.FeedItems');

			$oldTags = null;
			$id = FeedItem::getIdByURL($item['permalink']);
			if($id === false && isset($item['guid'])) {
				$item['guid']=$db->escape($db->lessen(UTF8::correct($item['guid'])));
				$id = FeedItem::getIdByURL($item['guid']);
			}

			$item['author'] = Feed::getAuthor($item, $feedId, $id);
			$item['title'] = Feed::getTitle($item, $feedId, $id);

			$affected = 0;
			$isRebuildData = false;

			$summarySave = Settings::get('summarySave');
			$description = $item['description'];
			if(Validator::getBool($summarySave)) { // summarySave
				$description = func::stripHTML($item['description'].'>');
				if (substr($description, -1) == '>') $description = substr($description, 0, strlen($description) - 1);
				$description = $db->lessen(func::htmltrim($description), 1000, '');
			}
			
			if (preg_match("/^[0-9]+$/",$id)) {
				$baseItem = FeedItem::getFeedItem($id);
			//	$baseItem['title']=$db->escape(UTF8::correct($baseItem['title']));
			//	$baseItem['description']=$db->escape(UTF8::correct(trim($baseItem['description'])));

				if(($baseItem['title']!=$item['title'])) {
					$isRebuildData = true;
					$tags = FeedItem::get($id, 'tags');
					requireComponent('LZ.PHP.Media');
					Media::delete($id);

					$oldTags = func::array_trim(explode(',', $tags));
					$db->execute("UPDATE {$database['prefix']}FeedItems SET author = '{$item['author']}', title = '{$item['title']}', description = '{$description}', tags = '$tagString', enclosure = '$enclosureString', written = {$item['written']} WHERE id = $id");
				}
			} else {
				if ($item['written']==0)
					$item['written']=gmmktime();
				if ($item['written']>$deadLine) {
					$db->execute("INSERT INTO {$database['prefix']}FeedItems (feed, author, permalink, title, description, tags, enclosure, written, feedVisibility) VALUES ($feedId, '{$item['author']}', '{$item['permalink']}', '{$item['title']}', '{$description}', '$tagString', '$enclosureString', {$item['written']},'{$feedVisibility}')");

					$id =$db->insertId();
					$db->execute('UPDATE '.$database['prefix'].'Feeds SET feedCount=feedCount+1 WHERE id="'.$feedId.'"');
					if (isset($this)) $this->updated++;
				}
				$isRebuildData = true;
			}			

			if(Validator::getBool(Settings::get('saveImages'))) {
				if($description = FeedItem::saveImages($feedId, $id, $item)) {
					$db->execute("UPDATE {$database['prefix']}FeedItems SET description = '{$description}' WHERE id = $id");
				}
			}
			
			$item = $event->on('Add.updateFeedItem', array($feedId, $id, $item));
			if(count($item)==3) $item = $item[2];
	
			$result = false;
			if($isRebuildData) {
				requireComponent('Bloglounge.Data.Groups');
				GroupCategory::buildGroupCategory($id, $feedId, $item['tags']);

				Tag::buildTagIndex($id, $item['tags'], $oldTags);
					

				Category::buildCategoryRelations($id, $item['tags'], $oldTags);
				
				$isSaveThumbnail = FeedItem::cacheThumbnail($id, $item);

				// 썸네일 저장 이벤트
				$event->on('Add.thumbnailSave',array($item, $feedId, $id, $isSaveThumbnail));
				
				$result = true;
			}

			return $result;
		}