/**
  * Get contents from a url or a local file - Cache urls for given cachetime
  *
  * @param mixed $path The URL or file path
  * @return string | false
  */
 static function get($path)
 {
     # is local file
     if (!preg_match("~^(http|https)~i", $path)) {
         if (file_exists($path)) {
             return file_get_contents($path);
         }
         return false;
     }
     # is url
     $dir = CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp";
     $file = "{$dir}/filecontents." . md5($path);
     if (!file_exists($file) || filemtime($file) < time() - self::CACHETIME) {
         $data = self::loadUrl($path);
         if ($data === false) {
             RDR_Event::log(RDR_Event::TYPE_FEED_URLERROR, array("text" => $path));
             return;
         }
         # writing to cache
         file_put_contents($file, $data);
     } else {
         # return cached file
         return file_get_contents($file);
     }
     return $data;
 }
Example #2
0
 /**
  * Create a log entry
  *
  * @param int $type
  * @param array $params
  * @return self
  */
 static function log($type, $params = null)
 {
     $object = new self(db());
     $object->type = $type;
     if (is_array($params)) {
         foreach ($params as $key => $value) {
             $object->{$key} = $value;
         }
     }
     $object->store();
     self::$lastEvent = $object;
     return $object;
 }
Example #3
0
 /**
  * Old entries will be deleted automatically with this cleanup
  */
 static function cleanupEvents()
 {
     $time = RDR_Setting::get("maxeventlifetime")->value;
     if (!$time) {
         $time = "- 1 day";
     }
     while (true) {
         $tmp = RDR_Event::getByCondition("createTime < {0}", array(dt("now {$time}")), null, 1000);
         if (!$tmp) {
             break;
         }
         db()->deleteMultiple($tmp);
     }
 }
Example #4
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!inNormalMode()) {
         return;
     }
     # set time limit to max 10 minutes
     # if this limit is reached than the script stops and continue at next cron
     set_time_limit(RDR_Cron::MAXTIME);
     $cronPidFile = self::getPIDFile();
     # skip when cron is already running
     if (self::isRunning()) {
         RDR_Event::log(RDR_Event::TYPE_CRON_RUNNING);
         return;
     }
     # create a tmp file that show us the cron pid
     file_put_contents($cronPidFile, time());
     $param = $this->getParam("param");
     if ($param != self::getHash()) {
         die("Not allowed");
     }
     RDR_Event::log(RDR_Event::TYPE_CRON_START);
     RDR_Import::updateAllFeeds();
     RDR_Event::log(RDR_Event::TYPE_CRON_END);
     RDR_Cleanup::cleanupEvents();
     RDR_Cleanup::cleanupEntries();
     RDR_FileContents::cleanupTmpFiles();
     RDR_Proxy::cleanupTmpFiles();
     # optimizing tables
     $generator = CHOQ_DB_Generator::create(db());
     if ($generator instanceof CHOQ_DB_Generator_Mysql) {
         $generator->addModule("RDR");
         $generator->optimizeTables();
     }
     # delete tmp file that show us the cron pid
     unlink(CHOQ_ACTIVE_MODULE_DIRECTORY . "/tmp/cron.pid");
 }
Example #5
0
 /**
  * Get Simple xml from a feed url
  *
  * @param mixed $url
  * @return SimpleXMLElement | bool
  */
 private static function getSimpleXMLFromUrl($url)
 {
     $data = RDR_FileContents::get($url);
     if ($data === false) {
         return false;
     }
     $xml = @simplexml_load_string($data, null, LIBXML_NOCDATA);
     if (!$xml) {
         RDR_Event::log(RDR_Event::TYPE_SIMPLEXML_ERROR, array("text" => $url));
         return false;
     }
     return $xml;
 }
Example #6
0
    /**
     * Get content
     */
    public function getContent()
    {
        headline(t("dashboard"));
        $settings = array("note.opml.import" => array("url" => l("RDR_Organize")), "note.addfeed" => array("url" => ""), "note.bug" => array("url" => "https://bfldev.com/nreeda"), "note.opml.export" => array("url" => l("RDR_Organize")), "note.search" => array("url" => ""), "note.settings" => array("url" => ""));
        echo sprintf(t("hello"), '<b>' . user()->username . '</b>') . "<br/><br/>";
        foreach ($settings as $key => $data) {
            if (user()->setting($key)) {
                continue;
            }
            echo '<div class="note" data-id="' . $key . '" data-url="' . $data["url"] . '">' . t($key) . '</div>';
        }
        ?>

        <script type="text/javascript">
        $("#content .note").on("click", function(){
            var url = $(this).attr("data-url");
            var e = $(this);
            $.post(Global.vars.ajaxUrl, {action : "changesetting", "key" : $(this).attr("data-id"), "value" : 1}, function(data){
                e.remove();
                if(url){
                    if(url.match(/^http/)){
                        window.open(url);
                    }else{
                        window.location.href = url;
                    }
                }
            })
        });
        </script>

        <div class="spacer"></div>
        <?php 
        if (needRole(RDR_User::ROLE_ADMIN)) {
            headline(t("dashboard.eventlog"));
            $logs = RDR_Event::getByCondition(null, null, "-id", 50);
            ?>
            <div id="eventlog">
                <?php 
            if ($logs) {
                ?>
<input type="button" class="btn" value="<?php 
                echo t("dashboard.clearlog");
                ?>
"/><?php 
            }
            ?>
                <div class="spacer"></div>
                <?php 
            foreach ($logs as $log) {
                ?>
                    <div class="event">
                        <time datetime="<?php 
                echo $log->createTime->getUnixtime();
                ?>
" class="inline-btn"></time>
                        <?php 
                echo $log->getText();
                ?>
                    </div>
                <?php 
            }
            ?>
            </div>
            <div class="spacer"></div>
            <script type="text/javascript">
            $("#eventlog input.btn").on("click", function(){
                $.post(window.location.href, {clearlog : 1});
                $("#eventlog").remove();
            });
            </script>
            <?php 
            $file = CHOQ_ACTIVE_MODULE_DIRECTORY . "/logs/error.log.php";
            if (file_exists($file) && filesize($file)) {
                $data = file_get_contents($file);
                $data = substr($data, strpos($data, "\n\n"));
                headline(t("dashboard.errorlog"));
                ?>
                <div id="errorlog">
                    <input type="button" class="btn" value="<?php 
                echo t("dashboard.clearlog");
                ?>
"/>
                    <pre style="font-size:11px; overflow:auto; max-height:400px;"><code><?php 
                echo s(trim($data));
                ?>
</code></pre>
                </div>
                <script type="text/javascript">
                $("#errorlog input.btn").on("click", function(){
                    $.post(window.location.href, {clearerrorlog : 1});
                    $("#errorlog").remove();
                });
                </script>
                <?php 
            }
        }
    }