Пример #1
0
 /**
  * Update all existing feeds in the database
  */
 static function updateAllFeeds()
 {
     ini_set("memory_limit", "256M");
     set_time_limit(6000);
     $feeds = RDR_Feed::getByCondition(null, null, "+lastImport");
     foreach ($feeds as $feed) {
         try {
             self::importFavicon($feed);
             self::importFeedEntries($feed);
             $feed->lastImport = dt("now");
             $feed->store();
         } catch (Exception $e) {
             RDR_Event::log(RDR_Event::TYPE_ERROR, array("text" => $e->getMessage()));
             $feed->lastImport = dt("now");
             $feed->store();
         }
     }
     try {
         # cleanup old tmp files
         $dir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp";
         $files = CHOQ_FileManager::getFiles($dir, false, true);
         foreach ($files as $file) {
             if (!is_dir($file) && preg_match("~^import\\.|proxy\\.~i", $file) && filemtime($file) < dt("now -1 day")->getUnixtime()) {
                 unlink($file);
             }
         }
     } catch (Exception $e) {
         RDR_Event::log(RDR_Event::TYPE_ERROR, array("text" => $e->getMessage()));
     }
 }
Пример #2
0
 /**
  * Get a instance for a url
  *
  * @param string $url
  * @return self
  */
 static function get($url)
 {
     $object = RDR_Feed::getByCondition("url = {0}", array($url));
     if ($object) {
         return reset($object);
     }
     $object = new self(db());
     $object->url = $url;
     return $object;
 }
Пример #3
0
    /**
     * Get content
     */
    public function getContent()
    {
        headline(t("admin.update.cron.title"));
        ?>
        <div class="indent">
            <?php 
        echo nl2br(t("admin.update.cron.text"));
        ?>
<br/>
            <code style="font-size: 11px;">*/10 * * * * php -f <?php 
        echo escapeshellarg(CHOQ_ROOT_DIRECTORY . DIRECTORY_SEPARATOR . "console.php");
        ?>
 <?php 
        echo escapeshellarg("cron");
        ?>
</code>
        </div>
        <div class="spacer"></div>

        <?php 
        headline(t("admin.update.webcron.title"));
        ?>
        <div class="indent">
            <?php 
        echo nl2br(t("admin.update.webcron.text"));
        ?>
<br/>
            <code style="font-size: 11px;"><a href="<?php 
        echo RDR_Cron::getLink();
        ?>
" target="_blank"><?php 
        echo RDR_Cron::getLink();
        ?>
</a></code>
        </div>
        <div class="spacer"></div>

        <?php 
        headline(t("admin.update.3"));
        ?>
        <div class="indent">
            <?php 
        echo t("admin.update.4");
        ?>
.<br/><br/>
            <div class="btn update-all"><?php 
        echo t("admin.update.5");
        ?>
</div>
            <div class="spacer"></div>
            <?php 
        $feeds = RDR_Feed::getByCondition(null, null, "+name");
        foreach ($feeds as $feed) {
            ?>
                <div style="padding-left: 20px; margin-bottom: 2px;" class="feed">
                    <div class="inline-btn update-feed" data-id="<?php 
            echo $feed->getId();
            ?>
"><?php 
            echo t("admin.update.6");
            ?>
</div>
                    <div class="inline-btn delete-feed" data-id="<?php 
            echo $feed->getId();
            ?>
"><?php 
            echo t("organize.15");
            ?>
</div>
                    <img src="<?php 
            echo url()->getByAlias("public", "img/loading-2.gif");
            ?>
" alt="" style="position: relative; top:2px; display: none;" class="loading-feed"/>
                    <a href="<?php 
            echo $feed->getLink();
            ?>
"><?php 
            echo s($feed->name);
            ?>
</a><br/>
                    <div class="small" style="margin-top:3px;"><a href="<?php 
            echo s($feed->url);
            ?>
"><?php 
            echo s($feed->url);
            ?>
</a></div>
                </div>
            <?php 
        }
        ?>
        </div>

        <script type="text/javascript">
        (function(){
            $("#content div.update-feed.inline-btn").on("click", function(){
                $("img.loading-feed").hide();
                pipeline = [$(this).attr("data-id")];
                runUpdate();
            });
            $("#content div.delete-feed.inline-btn").on("click", function(){
                if(confirm(<?php 
        echo json_encode(t("organize.13"));
        ?>
)){
                    API.req("delete-feed-admin", {"fid" : $(this).attr("data-id")});
                    $(this).closest(".feed").remove();
                }
            });
            $("#content div.update-all").on("click", function(){
                $("#content img.loading-feed").hide();
                pipeline = [];
                $("#content div.update-feed.inline-btn").each(function(){
                    pipeline.push($(this).attr("data-id"));
                });
                runUpdate();
            });

            var pipeline = [];
            function runUpdate(){
                if(!pipeline.length) {
                    Global.updateNewsCache();
                    return;
                }
                var id = pipeline.shift();
                var btn = $("#content div.update-feed[data-id='"+id+"']").parent().find(".loading-feed");
                btn.show();
                $.post('<?php 
        echo url()->getUri();
        ?>
', {"update" : id}, function(){
                    btn.hide();
                    runUpdate();
                });
            }
        })();
        </script>
        <?php 
    }