Exemplo n.º 1
0
function update($id)
{
    $kses_allowed = getConfig('rss.input.allowed');
    //getAllowedTags();
    $updatedIds = array();
    $sql = "select id, url, title, mode from " . getTable("channels");
    if ($id != "" && is_numeric($id)) {
        $sql .= " where id={$id}";
        $sql .= " and not(mode & " . RSS_MODE_DELETED_STATE . ") ";
    } else {
        $sql .= " where not(mode & " . RSS_MODE_DELETED_STATE . ") ";
    }
    if (getConfig('rss.config.absoluteordering')) {
        $sql .= " order by parent, position";
    } else {
        $sql .= " order by parent, title";
    }
    $res = rss_query($sql);
    while (list($cid, $url, $title, $mode) = rss_fetch_row($res)) {
        // suppress warnings because Magpie is rather noisy
        $old_level = error_reporting(E_ERROR);
        $rss = fetch_rss($url);
        //reset
        error_reporting($old_level);
        if (!$rss && $id != "" && is_numeric($id)) {
            return array(magpie_error(), array());
        } elseif (!$rss || !($rss->rss_origin & MAGPIE_FEED_ORIGIN_HTTP_200)) {
            continue;
            // no need to do anything if we do not get a 200 OK from the feed
        }
        // base URL for items in this feed.
        if (array_key_exists('link', $rss->channel)) {
            $baseUrl = $rss->channel['link'];
        } else {
            $baseUrl = $url;
            // The feed is invalid
        }
        // Keep track of guids we've handled, because some feeds (hello,
        // Technorati!) have this insane habit of serving the same item
        // twice in the same feed.
        $guids = array();
        // Allow updates in this feed?
        $allowUpdates = getProperty($cid, 'rss.input.allowupdates');
        if ($allowUpdates === null) {
            $allowUpdates = getConfig('rss.input.allowupdates');
        }
        $itemIdsInFeed = array();
        // This variable will store the item id's of the elements in the feed
        foreach ($rss->items as $item) {
            $item = rss_plugin_hook('rss.plugins.rssitem', $item);
            // a plugin might delete this item
            if (!isset($item)) {
                continue;
            }
            // item title: strip out html tags
            $title = array_key_exists('title', $item) ? strip_tags($item['title']) : "";
            //$title = str_replace('& ', '& ', $title);
            $description = "";
            // item content, if any
            if (array_key_exists('content', $item) && is_array($item['content']) && array_key_exists('encoded', $item['content'])) {
                $description = $item['content']['encoded'];
            } elseif (array_key_exists('description', $item)) {
                $description = $item['description'];
            } elseif (array_key_exists('atom_content', $item)) {
                $description = $item['atom_content'];
            } elseif (array_key_exists('summary', $item)) {
                $description = $item['summary'];
            } else {
                $description = "";
            }
            $md5sum = "";
            $guid = "";
            if (array_key_exists('guid', $item) && $item['guid'] != "") {
                $guid = $item['guid'];
            } elseif (array_key_exists('id', $item) && $item['id'] != "") {
                $guid = $item['id'];
            }
            $guid = trim($guid);
            $guid = rss_real_escape_string($guid);
            // skip this one if it's an  in-feed-dupe
            if ($guid && isset($guids[$guid])) {
                continue;
            } elseif ($guid) {
                $guids[$guid] = true;
            }
            if ($description != "") {
                $md5sum = md5($description);
                $description = kses($description, $kses_allowed);
                // strip out tags
                if ($baseUrl != "") {
                    $description = relative_to_absolute($description, $baseUrl);
                }
            }
            // Now let plugins modify the description
            $description = rss_plugin_hook('rss.plugins.import.description', $description);
            // link
            if (array_key_exists('link', $item) && $item['link'] != "") {
                $url = $item['link'];
            } elseif (array_key_exists('guid', $item) && $item['guid'] != "") {
                $url = $item['guid'];
            } elseif (array_key_exists('link_', $item) && $item['link_'] != "") {
                $url = $item['link_'];
            } else {
                // fall back to something basic
                $url = md5($title);
            }
            // make sure the url is properly escaped
            $url = htmlentities($url, ENT_QUOTES);
            $url = rss_real_escape_string($url);
            // author
            if (array_key_exists('dc', $item) && array_key_exists('creator', $item['dc'])) {
                // RSS 1.0
                $author = $item['dc']['creator'];
            } else {
                if (array_key_exists('author_name', $item)) {
                    // Atom 0.3
                    $author = $item['author_name'];
                } else {
                    $author = "";
                }
            }
            $author = trim(strip_tags($author));
            // pubdate
            $cDate = -1;
            if (array_key_exists('dc', $item) && array_key_exists('date', $item['dc'])) {
                // RSS 1.0
                $cDate = parse_w3cdtf($item['dc']['date']);
            } elseif (array_key_exists('pubdate', $item)) {
                // RSS 2.0 (?)
                // We use the second param of strtotime here as a workaround
                // of a PHP bug with strtotime. If the pubdate field doesn't
                // contain seconds, the strtotime function will use the current
                // time to fill in seconds in PHP4. This interferes with the
                // update mechanism of gregarius. See ticket #328 for the full
                // gory details. Giving a known date as a second param to
                // strtotime fixes this problem, hence the 0 here.
                $cDate = strtotime($item['pubdate'], 0);
            } elseif (array_key_exists('published', $item)) {
                // atom 1.0
                $cDate = parse_iso8601($item['published']);
            } elseif (array_key_exists('issued', $item)) {
                //Atom, alternative
                $cDate = parse_iso8601($item['issued']);
            } elseif (array_key_exists('updated', $item)) {
                //Atom, alternative
                $cDate = parse_iso8601($item['updated']);
            } elseif (array_key_exists('created', $item)) {
                // atom 0.3
                $cDate = parse_iso8601($item['created']);
            }
            // enclosure
            if (array_key_exists('enclosure@url', $item)) {
                $enclosure = $item['enclosure@url'];
                // If the enclosure is an image, append it to the content
                // but only if it isn't there yet
                if ($enclosure && array_key_exists('enclosure@type', $item) && preg_match('#image/(png|gif|jpe?g)#', $item['enclosure@type']) && FALSE == strpos($description, $enclosure)) {
                    $description = '<img src="' . $enclosure . '" alt="" />' . $description;
                    $enclosure = '';
                }
            } else {
                $enclosure = "";
            }
            // drop items with an url exceeding our column length: we couldn't provide a
            // valid link back anyway.
            if (strlen($url) >= 255) {
                continue;
            }
            $dbtitle = rss_real_escape_string($title);
            if (strlen($dbtitle) >= 255) {
                $dbtitle = substr($dbtitle, 0, 254);
            }
            if ($cDate > 0) {
                $sec = "FROM_UNIXTIME({$cDate})";
            } else {
                $sec = "null";
            }
            // check whether we already have this item
            if ($guid) {
                $sql = "select id,unread, md5sum, guid, pubdate from " . getTable("item") . " where cid={$cid} and guid='{$guid}'";
            } else {
                $sql = "select id,unread, md5sum, guid, pubdate from " . getTable("item") . " where cid={$cid} and url='{$url}' and title='{$dbtitle}'" . " and (pubdate is NULL OR pubdate={$sec})";
            }
            $subres = rss_query($sql);
            list($indb, $state, $dbmd5sum, $dbGuid, $dbPubDate) = rss_fetch_row($subres);
            if ($indb) {
                $itemIdsInFeed[] = $indb;
                if (!($state & RSS_MODE_DELETED_STATE) && $md5sum != $dbmd5sum) {
                    // the md5sums do not match.
                    if ($allowUpdates) {
                        // Are we allowed update items in the db?
                        list($cid, $indb, $description) = rss_plugin_hook('rss.plugins.items.updated', array($cid, $indb, $description));
                        $sql = "update " . getTable("item") . " set " . " description='" . rss_real_escape_string($description) . "', " . " unread = unread | " . RSS_MODE_UNREAD_STATE . ", md5sum='{$md5sum}'" . " where cid={$cid} and id={$indb}";
                        rss_query($sql);
                        $updatedIds[] = $indb;
                        continue;
                    }
                }
            } else {
                // $indb = "" . This must be new item then. In you go.
                list($cid, $dbtitle, $url, $description) = rss_plugin_hook('rss.plugins.items.new', array($cid, $dbtitle, $url, $description));
                $sql = "insert into " . getTable("item") . " (cid, added, title, url, enclosure," . " description, author, unread, pubdate, md5sum, guid) " . " values (" . "{$cid}, now(), '{$dbtitle}', " . " '{$url}', '" . rss_real_escape_string($enclosure) . "', '" . rss_real_escape_string($description) . "', '" . rss_real_escape_string($author) . "', " . "{$mode}, {$sec}, '{$md5sum}', '{$guid}')";
                rss_query($sql);
                $newIid = rss_insert_id();
                $itemIdsInFeed[] = $newIid;
                $updatedIds[] = $newIid;
                rss_plugin_hook('rss.plugins.items.newiid', array($newIid, $item, $cid));
            }
            // end handling of this item
        }
        // end handling of all the items in this feed
        $sql = "update " . getTable("channels") . " set " . " itemsincache = '" . serialize($itemIdsInFeed) . "' where id={$cid}";
        rss_query($sql);
    }
    // end handling all the feeds we were asked to handle
    if ($id != "" && is_numeric($id)) {
        if ($rss) {
            // when everything went well, return the error code
            // and numer of new items
            return array($rss->rss_origin, $updatedIds);
        } else {
            return array(-1, array());
        }
    } else {
        return array(-1, $updatedIds);
    }
}
Exemplo n.º 2
0
 public function FW4_PDF($html)
 {
     $this->snappy = new Snappy_Pdf('/usr/bin/wkhtmltopdf');
     $this->html = relative_to_absolute($html);
 }
Exemplo n.º 3
0
    function onContentPrepare($context, &$article, &$params, $page = 0)
    {
        $input = JFactory::getApplication()->input;
        $view = $input->get('view');
        if (strstr(@$_SERVER["HTTP_REFERER"], "view=form") && strstr(@$_SERVER["HTTP_REFERER"], "layout=edit")) {
            return false;
        }
        $cosa_mostrare = $this->params->get("cosa_mostrare");
        if (!is_array($cosa_mostrare)) {
            $cosa_mostrare = array($cosa_mostrare);
        }
        $cats = $this->params->get("category");
        if (!is_array($cats)) {
            $cats = array($cats);
        }
        $counter = $this->params->get("counter", "0");
        $position = $this->params->get("position", "top");
        $css = $this->params->get("css", "color:#000; font-family:Arial; font-size:14px; line-height:19px; padding:20px;");
        $memory_limit = $this->params->get("memory_limit", "25");
        $visual_pdf = $this->params->get("visual_pdf", "0");
        $show_in_blog = $this->params->get("show_in_blog", "0");
        $icon_position = $this->params->get("icon_position", "left");
        if ($show_in_blog == 0 && ($view == "featured" || $view == "category")) {
            return false;
        }
        if ($icon_position == "right") {
            $document = JFactory::getDocument();
            $style = '.stButton {
			    float: right !important;
			}';
            $document->addStyleDeclaration($style);
        }
        if ($visual_pdf == 1) {
            $visual_pdf = 0;
        } else {
            $visual_pdf = 1;
        }
        //se l'articolo non è della giusta categoria esce subito
        $categoria_presente = 0;
        foreach ($cats as $cat) {
            if (@$article->catid == $cat) {
                $categoria_presente = 1;
            }
        }
        if ($categoria_presente == 0) {
            return false;
        } else {
            echo '<link rel="stylesheet" href="' . JURI::base() . 'plugins/content/articletool/style/style.css" type="text/css" />';
            if (JRequest::getVar('print', 0, 'get') != 1 && JRequest::getVar('download', 0, 'get') != 1) {
                //inserisce gli script per far funzionare sharethis
                foreach ($cosa_mostrare as $ico) {
                    if ($ico != "stampa" && $ico != "scarica") {
                        $http = "";
                        if ($_SERVER["REQUEST_SCHEME"] == "https") {
                            $http = "s";
                        }
                        $article->text .= '<script type="text/javascript">var switchTo5x=true;</script>
						<script type="text/javascript" src="http' . $http . '://w' . $http . '.sharethis.com/button/buttons.js"></script>
						<script type="text/javascript">stLight.options({publisher: "cf4e376e-1d9c-43b1-8df7-617e403ae918", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>';
                        break;
                    }
                }
                $icone = "";
                $uri = JFactory::getURI();
                //mostro le icone dei social, invia per mail, stampa e scarica
                foreach ($cosa_mostrare as $ico) {
                    if ($ico == "stampa") {
                        $uri->setVar('print', 1);
                        $uri->setVar('download', 0);
                        $uri->setVar('id', $article->id);
                        if ($counter == 0) {
                            $icone .= "\n\t\t\t\t\t\t\t<span class='stButton stButton_print'>\n\t\t\t\t\t\t\t<a id='article_tool_print' href='" . $uri->toString() . "' target='_blank'>\n\t\t\t\t\t\t\t\t<img src='" . JURI::base() . "plugins/content/articletool/images/print.png' />\n\t\t\t\t\t\t\t</a></span>";
                        } else {
                            $icone .= "<a id='article_tool_print' href='" . $uri->toString() . "' target='_blank'>\n\t\t\t\t\t\t\t<span class='stButton'><span class='stButton_gradient'>\n\t\t\t\t\t\t\t\t<img src='" . JURI::base() . "plugins/content/articletool/images/print.png' />\n\t\t\t\t\t\t\t<span class='chicklets chicklets_article_tool_print'>Print</span></span></span></a>";
                        }
                    } else {
                        if ($ico == "scarica") {
                            $uri->setVar('print', 0);
                            $uri->setVar('download', 1);
                            $uri->setVar('id', $article->id);
                            if ($counter == 0) {
                                $icone .= "\n\t\t\t\t\t\t\t<span class='stButton stButton_pdf'>\n\t\t\t\t\t\t\t<a id='article_tool_pdf' href='" . $uri->toString() . "' target='_blank'>\n\t\t\t\t\t\t\t\t<img src='" . JURI::base() . "plugins/content/articletool/images/pdf.png' />\n\t\t\t\t\t\t\t</a></span>";
                            } else {
                                $icone .= "<a id='article_tool_pdf' href='" . $uri->toString() . "' target='_blank'>\n\t\t\t\t\t\t\t<span class='stButton'><span class='stButton_gradient'>\n\t\t\t\t\t\t\t\t<img src='" . JURI::base() . "plugins/content/articletool/images/pdf.png' />\n\t\t\t\t\t\t\t<span class='chicklets chicklets_article_tool_pdf'>Download</span></span></span></a>";
                            }
                        } else {
                            $url_corrente = substr(JURI::base(), 0, -1) . JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid));
                            if ($counter == 0) {
                                $type = "large";
                            } else {
                                $type = "hcount";
                            }
                            $icone .= '<span class="st_' . $ico . '_' . $type . '" st_url="' . $url_corrente . '" displayText="' . $ico . '"></span>';
                        }
                    }
                }
                if ($position == "top") {
                    $article->text = "<div class='article_tool_container'>" . $icone . "</div><div class='article_tool_separator'></div>" . $article->text;
                }
                if ($position == "bottom") {
                    $article->text .= "<div class='article_tool_container'>" . $icone . "</div><div class='article_tool_separator'></div>";
                }
            }
            if (!function_exists('relative_to_absolute')) {
                function relative_to_absolute($article, $home)
                {
                    preg_match_all('/src="(.+?)"/', $article->text, $src);
                    preg_match_all('/href="(.+?)"/', $article->text, $href);
                    $urls = array_merge($src[1], $href[1]);
                    foreach ($urls as $url) {
                        if (!strstr($url, "http://") && !strstr($url, "https://")) {
                            $sepsl = "/";
                            if (substr($home, -1, 1) == "/") {
                                $sepsl = "";
                            }
                            $article->text = str_replace('"' . $url . '"', $home . $sepsl . $url, $article->text);
                        }
                    }
                    return $article->text;
                }
            }
            $article->text = relative_to_absolute($article, JURI::base());
            if (!function_exists('get_article_by_get')) {
                function get_article_by_get()
                {
                    $db = JFactory::getDBO();
                    $sql = "SELECT * FROM #__content WHERE id = " . JRequest::getVar('id', 0, 'get');
                    $db->setQuery($sql);
                    $fullArticle = $db->loadAssocList();
                    return $fullArticle[0]["introtext"] . $fullArticle[0]["fulltext"];
                }
            }
            $charset = new Charset();
            if (JRequest::getVar('print', 0, 'get') == 1) {
                $article->text = get_article_by_get();
                $article->text = relative_to_absolute($article, JURI::base());
                $article->text .= '
					<script type="text/javascript">
						window.print();
						window.close();
					</script>
				';
                echo "<meta http-equiv='content-type' content='text/html; charset=" . $charset->get() . "' /><div style='" . $css . "'>" . $article->text . "</div>";
                JFactory::getApplication()->close();
                die("");
            }
            if (JRequest::getVar('download', 0, 'get') == 1) {
                $article->text = get_article_by_get();
                $article->text = relative_to_absolute($article, JURI::base());
                //$txt_to_rend=file_get_contents(JURI::current());
                $txt_to_rend = "<meta http-equiv='content-type' content='text/html; charset=" . $charset->get() . "' /><div style='" . $css . "'>" . $article->text . "</div>";
                require_once "plugins/content/articletool/dompdf/dompdf_config.inc.php";
                if (get_magic_quotes_gpc()) {
                    $txt_to_rend = stripslashes($txt_to_rend);
                }
                $old_limit = ini_set("memory_limit", $memory_limit . "M");
                $dompdf = new DOMPDF();
                $dompdf->load_html($txt_to_rend);
                $dompdf->set_paper("portrait", "letter");
                $dompdf->render();
                /*i pdf possono essere messi in cache, vedere se nella jed ci sono componenti article to pdf*/
                $dompdf->stream($article->title . ".pdf", array("Attachment" => $visual_pdf));
                JFactory::getApplication()->close();
                die("");
            }
            return true;
        }
    }