Example #1
0
function opml_import($xml)
{
    $xml = html_only_entity_decode($xml);
    //!\ Assume UTF-8
    $dom = new DOMDocument();
    $dom->recover = true;
    $dom->strictErrorChecking = false;
    $dom->loadXML($xml);
    $dom->encoding = 'UTF-8';
    $opml = simplexml_import_dom($dom);
    if (!$opml) {
        throw new FreshRSS_Opml_Exception();
    }
    $catDAO = new FreshRSS_CategoryDAO();
    $catDAO->checkDefault();
    $defCat = $catDAO->getDefault();
    $categories = array();
    $feeds = array();
    foreach ($opml->body->outline as $outline) {
        if (!isset($outline['xmlUrl'])) {
            // Catégorie
            $title = '';
            if (isset($outline['text'])) {
                $title = (string) $outline['text'];
            } elseif (isset($outline['title'])) {
                $title = (string) $outline['title'];
            }
            if ($title) {
                // Permet d'éviter les soucis au niveau des id :
                // ceux-ci sont générés en fonction de la date,
                // un flux pourrait être dans une catégorie X avec l'id Y
                // alors qu'il existe déjà la catégorie X mais avec l'id Z
                // Y ne sera pas ajouté et le flux non plus vu que l'id
                // de sa catégorie n'exisera pas
                $title = htmlspecialchars($title, ENT_COMPAT, 'UTF-8');
                $catDAO = new FreshRSS_CategoryDAO();
                $cat = $catDAO->searchByName($title);
                if ($cat === false) {
                    $cat = new FreshRSS_Category($title);
                    $values = array('name' => $cat->name());
                    $cat->_id($catDAO->addCategory($values));
                }
                $feeds = array_merge($feeds, getFeedsOutline($outline, $cat->id()));
            }
        } else {
            // Flux rss sans catégorie, on récupère l'ajoute dans la catégorie par défaut
            $feeds[] = getFeed($outline, $defCat->id());
        }
    }
    return array($categories, $feeds);
}
Example #2
0
function sanitizeHTML($data, $base = '')
{
    static $simplePie = null;
    if ($simplePie == null) {
        $simplePie = customSimplePie();
        $simplePie->init();
    }
    return html_only_entity_decode($simplePie->sanitize->sanitize($data, SIMPLEPIE_CONSTRUCT_HTML, $base));
}
Example #3
0
 public function loadEntries($feed)
 {
     $entries = array();
     foreach ($feed->get_items() as $item) {
         $title = html_only_entity_decode(strip_tags($item->get_title()));
         $author = $item->get_author();
         $link = $item->get_permalink();
         $date = @strtotime($item->get_date());
         // gestion des tags (catégorie == tag)
         $tags_tmp = $item->get_categories();
         $tags = array();
         if ($tags_tmp !== null) {
             foreach ($tags_tmp as $tag) {
                 $tags[] = html_only_entity_decode($tag->get_label());
             }
         }
         $content = html_only_entity_decode($item->get_content());
         $elinks = array();
         foreach ($item->get_enclosures() as $enclosure) {
             $elink = $enclosure->get_link();
             if (empty($elinks[$elink])) {
                 $elinks[$elink] = '1';
                 $mime = strtolower($enclosure->get_type());
                 if (strpos($mime, 'image/') === 0) {
                     $content .= '<br /><img lazyload="" postpone="" src="' . $elink . '" alt="" />';
                 } elseif (strpos($mime, 'audio/') === 0) {
                     $content .= '<br /><audio lazyload="" postpone="" preload="none" src="' . $elink . '" controls="controls" />';
                 } elseif (strpos($mime, 'video/') === 0) {
                     $content .= '<br /><video lazyload="" postpone="" preload="none" src="' . $elink . '" controls="controls" />';
                 } else {
                     unset($elinks[$elink]);
                 }
             }
         }
         $entry = new FreshRSS_Entry($this->id(), $item->get_id(), $title === null ? '' : $title, $author === null ? '' : html_only_entity_decode($author->name), $content === null ? '' : $content, $link === null ? '' : $link, $date ? $date : time());
         $entry->_tags($tags);
         // permet de récupérer le contenu des flux tronqués
         $entry->loadCompleteContent($this->pathEntries());
         $entries[] = $entry;
         unset($item);
     }
     $this->entries = $entries;
 }