Ejemplo n.º 1
0
$foldermapper = new OCA\News\FolderMapper($userid);
$allfeeds = $foldermapper->childrenOfWithFeeds(0);
//$foldermapper->populate($folder);
$folderforest = $foldermapper->childrenOf(0);
//retrieve all the folders
$feedid = 0;
$feedtype = 0;
if ($allfeeds) {
    $feedid = isset($_GET['feedid']) ? $_GET['feedid'] : null;
    if ($feedid == null) {
        $feedmapper = new OCA\News\FeedMapper(OCP\USER::getUser($userid));
        $lastViewedId = OCP\Config::getUserValue($userid, 'news', 'lastViewedFeed');
        $lastViewedType = OCP\Config::getUserValue($userid, 'news', 'lastViewedFeedType');
        if ($lastViewedId == null || $lastViewedType == null) {
            $feedid = $feedmapper->mostRecent();
        } else {
            $feedid = $lastViewedId;
            $feedtype = $lastViewedType;
            // check if feed exists in table
            if ($feedmapper->findById($feedid) === null) {
                $feedid = $feedmapper->mostRecent();
            }
        }
    }
}
$tmpl = new OCP\Template('news', 'main', 'user');
$tmpl->assign('allfeeds', $allfeeds);
$tmpl->assign('folderforest', $folderforest);
$tmpl->assign('feedid', $feedid);
$tmpl->assign('feedtype', $feedtype);
$tmpl->printPage();
Ejemplo n.º 2
0
OCP\JSON::checkLoggedIn();
OCP\JSON::checkAppEnabled('news');
OCP\JSON::callCheck();
session_write_close();
$userid = OCP\USER::getUser();
$feedId = $_POST['id'];
$feedType = $_POST['type'];
OCP\Config::setUserValue(OCP\USER::getUser(), 'news', 'lastViewedFeed', $feedId);
OCP\Config::setUserValue(OCP\USER::getUser(), 'news', 'lastViewedFeedType', $feedType);
$l = OC_L10N::get('news');
$itemsTpl = new OCP\Template("news", "part.items");
$itemsTpl->assign('feedid', $feedId);
$feedItems = $itemsTpl->fetchPage();
$itemMapper = new OCA\News\ItemMapper();
switch ($feedId) {
    case -1:
        $feedTitle = $l->t('Starred');
        $unreadItemCount = $itemMapper->countAllStatus($feedId, OCA\News\StatusFlag::IMPORTANT);
        break;
    case -2:
        $feedTitle = $l->t('New articles');
        $unreadItemCount = $itemMapper->countEveryItemByStatus(OCA\News\StatusFlag::UNREAD);
        break;
    default:
        $feedMapper = new OCA\News\FeedMapper();
        $feed = $feedMapper->findById($feedId);
        $feedTitle = $feed->getTitle();
        $unreadItemCount = $itemMapper->countAllStatus($feedId, OCA\News\StatusFlag::UNREAD);
        break;
}
OCP\JSON::success(array('data' => array('message' => $l->t('Feed loaded!'), 'feedTitle' => $feedTitle, 'feedItems' => $feedItems, 'unreadItemCount' => $unreadItemCount)));