/**
     * Get content
     */
    public function getContent()
    {
        if (get("feed") && is_array(get("feed"))) {
            if (post("save")) {
                $count = 0;
                $feeds = post("feed");
                $message = array();
                if (is_array($feeds)) {
                    foreach ($feeds as $key => $feed) {
                        $href = post("href[{$key}]");
                        $title = post("title[{$key}]");
                        $cat = post("cat[{$key}]");
                        $category = RDR_Category::get($cat);
                        $event = RDR_Import::addFeed($href, $category);
                        if ($event->feed) {
                            RDR_Import::importFeedEntries($event->feed);
                            if ($href != $title) {
                                $event->feed->setCustomName($category, $title);
                                $category->store();
                            }
                        }
                        $message[] = $event->getText();
                    }
                }
                headline(t("browserscript.log"));
                ?>
                <p><?php 
                echo implode("<br/>", $message);
                ?>
</p>
                <p><?php 
                echo t("browserscript.close");
                ?>
</p>
                <?php 
                return;
            }
            headline(sprintf(t("browserscript.addfeeds"), s(get("site"))));
            $feeds = get("feed");
            ?>
            <form name="d" method="post" action="">
            <p>
            <?php 
            $categories = user()->getCategories();
            foreach ($feeds as $id => $feed) {
                $exp = explode(";", $feed, 2);
                ?>
                <input type="hidden" name="href[<?php 
                echo s($id);
                ?>
]" value="<?php 
                echo $exp[0];
                ?>
"/>
                <input type="hidden" name="title[<?php 
                echo s($id);
                ?>
]" value="<?php 
                echo $exp[1];
                ?>
"/>
                <input type="checkbox" name="feed[<?php 
                echo s($id);
                ?>
]" value="<?php 
                echo $feed;
                ?>
"/>
                <select name="cat[<?php 
                echo s($id);
                ?>
]">
                    <option value="<?php 
                echo t("uncategorized");
                ?>
"><?php 
                echo t("uncategorized");
                ?>
</option>
                    <?php 
                foreach ($categories as $category) {
                    if ($category->name == t("uncategorized")) {
                        continue;
                    }
                    ?>
                        <option value="<?php 
                    echo $category->name;
                    ?>
"><?php 
                    echo s($category->name);
                    ?>
</option>
                    <?php 
                }
                ?>
                </select>
                <a href="<?php 
                echo urldecode($exp[0]);
                ?>
" target="_blank"><?php 
                echo urldecode($exp[1]);
                ?>
</a><br/>
                <?php 
            }
            ?>
<br/>
            <input type="submit" name="save" class="btn" value="<?php 
            echo t("browserscript.addfeeds.btn");
            ?>
"/>
            </p>
            </form>
            <?php 
            return;
        }
        $script = file_get_contents(CHOQ_ACTIVE_MODULE_DIRECTORY . "/view/_js/browser-script.js");
        $script = str_replace(array("\t", "\r", "\n"), "", $script);
        $script = preg_replace("~\\s{2,99}~", "", $script);
        $script = str_replace("{url}", url()->getByAlias("root", l($this)), $script);
        $script = str_replace("{nofeed}", t("browserscript.nofeed"), $script);
        $script = str_replace("{forward}", t("browserscript.forward"), $script);
        $script = "javascript:" . $script;
        headline(t("sidebar.25"));
        ?>
        <p><?php 
        echo t("browserscript.info");
        ?>
</p>
        <?php 
        headline(t("browserscript.use"));
        ?>
        <p><?php 
        echo t("browserscript.bookmark");
        ?>
<br/><br/>

        <a href='<?php 
        echo $script;
        ?>
'><?php 
        echo s($script);
        ?>
</a>
        </p>
        <?php 
    }
Exemple #2
0
 /**
  * Load the View
  */
 public function onLoad()
 {
     if (!needRole()) {
         return;
     }
     $jsonData = null;
     switch (post("action")) {
         case "delete-feed-user":
             $feed = RDR_Feed::getById(post("data[fid]"));
             if ($feed) {
                 $cats = user()->getCategories();
                 foreach ($cats as $category) {
                     $feeds = $category->feeds;
                     if ($feeds) {
                         foreach ($feeds as $key => $catFeed) {
                             if (compare($catFeed, $feed)) {
                                 unset($feeds[$key]);
                             }
                         }
                         if (count($feeds) != count($category->feeds)) {
                             $category->feeds = $feeds;
                             $category->store();
                         }
                     }
                 }
             }
             break;
         case "delete-feed-admin":
             if (needRole(RDR_User::ROLE_ADMIN)) {
                 $feed = RDR_Feed::getById(post("data[fid]"));
                 if ($feed) {
                     $feed->delete();
                 }
             }
             break;
         case "add-feed":
             $event = RDR_Import::addFeed(post("data[url]"), RDR_Category::get(post("data[category]")));
             if ($event->feed) {
                 RDR_Import::importFeedEntries($event->feed);
             }
             break;
         case "mark-all-as-readed":
             $cache = session("entry.ids.original");
             if ($cache) {
                 $ids = array_keys($cache);
                 user()->loadReadedFlags(array_keys($ids));
                 $insertIds = array();
                 foreach ($ids as $id) {
                     if (!isset(user()->_cacheReaded[$id])) {
                         $insertIds[$id] = $id;
                     }
                 }
                 if ($insertIds) {
                     $query = "INSERT IGNORE INTO RDR_User_readed (o,k,v) VALUES ";
                     foreach ($insertIds as $id) {
                         $query .= " (" . user()->getId() . ", {$id}, 1), ";
                     }
                     $query = substr($query, 0, -2);
                     db()->query($query);
                     user()->updateReadedCount();
                 }
             }
             break;
         case "update-setting-user":
             user()->setting(post("data[key]"), post("data[value]"));
             user()->store();
             break;
         case "update-newscache":
             user()->updateNewsCache();
             $jsonData = user()->getAjaxData();
             break;
         case "set-entries-readed":
             if (post("data[ids]")) {
                 $entries = RDR_Entry::getByIds(post("data[ids]"));
                 if ($entries) {
                     user()->loadReadedFlags(array_keys($entries));
                     $insertIds = $deleteIds = array();
                     foreach ($entries as $entry) {
                         $id = $entry->getId();
                         if ($id < user()->setting("init.entry")) {
                             continue;
                         }
                         if (isset(user()->_cacheReaded[$id])) {
                             $deleteIds[$id] = $id;
                         } else {
                             $insertIds[$id] = $id;
                         }
                     }
                     if ($insertIds) {
                         $query = "INSERT IGNORE INTO RDR_User_readed (o,k,v) VALUES ";
                         foreach ($insertIds as $id) {
                             $query .= " (" . user()->getId() . ", {$id}, 1), ";
                         }
                         $query = substr($query, 0, -2);
                         db()->query($query);
                     }
                     if ($deleteIds) {
                         $query = "DELETE FROM RDR_User_readed WHERE o = " . user()->getId() . " && k IN " . db()->toDb($deleteIds);
                     }
                     user()->updateReadedCount();
                 }
             }
             break;
         case "set-entries-saved":
             if (post("data[ids]")) {
                 $entry = RDR_Entry::getById(post("data[ids][0]"));
                 if ($entry) {
                     if (user()->getByKey("saved", $entry->getId())) {
                         user()->remove("saved", $entry->getId());
                     } else {
                         user()->add("saved", 1, $entry->getId());
                     }
                     user()->store();
                 }
             }
             break;
         case "set-feed-property":
             if (needRole(RDR_User::ROLE_ADMIN)) {
                 $feed = RDR_Feed::getById(post("data[feed]"));
                 if ($feed) {
                     $feed->{post("data[field]")} = post("data[value]");
                     $feed->store();
                 }
             }
             break;
     }
     echo json_encode($jsonData, JSON_FORCE_OBJECT);
 }