Exemplo n.º 1
0
	function _getfeed($uid = 0) {
		if(!isset($this->feeddata[$uid])) {
			$conf = array(
				'type' => 'manyou',
				'num' => 5,
				'cachelife' => 0,
				'multipage' => 0,
				'uid' => $uid,
			);
			$feeds = get_feed($conf);
			$bi = 1;
			$str = '';
			if($feeds['data']) {
				$str = '<ul>';
				foreach($feeds['data'] as $k => $feed) {
					$trans['{addbuddy}'] = $view == 'all' && $feed['uid'] != $discuz_uid ? '<a href="my.php?item=buddylist&newbuddyid='.$feed['uid'].'&buddysubmit=yes" id="ajax_buddy_'.($bi++).'" title="'.$GLOBALS['scriptlang']['manyou']['add_buddy'].'" onclick="ajaxmenu(this, 3000);doane(event);"><img style="vertical-align:middle" src="manyou/images/myadd.gif" /></a>' : '';
					$feeds['data'][$k]['title'] = strtr($feed['title'], $trans);
					$feeds['data'][$k]['title'] = preg_replace("/<a(.+?)href=([\'\"]?)([^>\s]+)\\2([^>]*)>/i", '<a target="_blank" \\1 href="\\3" \\4>', $feeds['data'][$k]['title']);
					$feeds['data'][$k]['icon_image'] = 'http://appicon.manyou.com/icons/'.$feed['appid'];
					$str .= '<li><img class="appicon" src="'.$feeds['data'][$k]['icon_image'].'" /> '.$feeds['data'][$k]['title'].'</li>';
				}
				$str .= '</ul>';
			}
			$this->feeddata[$uid] = $str;
		}
		return $this->feeddata[$uid];
	}
Exemplo n.º 2
0
function run_notify($userid)
{
    $notification_number = 0;
    // Will be used to display number of notifications in an email
    $notification_message = "";
    // Variable holds body of email
    $result = db_query("SELECT * FROM notify WHERE `userid` = '{$userid}'");
    // Get user notification list
    while ($row = db_fetch_array($result)) {
        $feedid = $row['feedid'];
        $feed = get_feed($feedid);
        // Get all feed details from feed model function
        if (time() - strtotime($feed[3]) < 60 * 1) {
            $active = 1;
        } else {
            $active = 0;
        }
        // Check if feed is active
        // if feed becomes active again then the notification status needs to be reset to unsent
        if ($active && $row['oninactive_sent']) {
            db_query("UPDATE notify SET oninactive_sent = 0 WHERE feedid='{$feedid}'");
        }
        // if feed is not the onvalue value then notification status needs to be reset to unsent
        if ($feed[4] != $row['onvalue'] && $row['onvalue_sent']) {
            db_query("UPDATE notify SET onvalue_sent = 0 WHERE feedid='{$feedid}'");
        }
        if (!$row['onvalue_sent'] && $row['onvalue'] && $feed[4] == $row['onvalue']) {
            $notification_message .= "<p>" . _("Feed ") . $feed[1] . _(" is") . " == " . $row['onvalue'] . "</p>";
            $notification_number++;
            db_query("UPDATE notify SET onvalue_sent = 1 WHERE feedid='{$feedid}'");
        }
        if (!$row['oninactive_sent'] && $row['oninactive'] && !$active) {
            $notification_message .= "<p>" . _("Feed ") . $feed[1] . _(" is inactive") . "</p>";
            $notification_number++;
            db_query("UPDATE notify SET oninactive_sent = 1 WHERE feedid='{$feedid}'");
        }
    }
    $to = get_notify_recipients($userid);
    $subject = $notification_number . "x emoncms events";
    $body = $notification_message;
    if ($notification_number > 0) {
        send_mail($to, $subject, $body);
    }
    return $notification_message;
}
Exemplo n.º 3
0
<?php

include_once 'include.php';
$feeds = get_feed('http://feedblog.ameba.jp/rss/ameblo/racle007/rss20.xml');
echo $feeds;
Exemplo n.º 4
0
} else {
    $collapseimg['sidebar'] = 'collapsed_yes';
    $collapse['sidebar'] = 'display: none';
}
$infosidestatus['allow'] = $infosidestatus['allow'] && $infosidestatus[2] && $infosidestatus[2] != -1 ? !$collapse['sidebar'] ? 2 : 1 : 0;
if ($indexhot['status'] && $_DCACHE['heats']['expiration'] < $timestamp) {
    require_once DISCUZ_ROOT . './include/cache.func.php';
    updatecache('heats');
}
if (!$type) {
    $view = empty($view) ? 0 : 1;
    $conf = array('num' => 50, 'cachelife' => 300, 'multipage' => $view, 'page_url' => $indexname . (!empty($view) ? '?view=all&op=feeds' : ''));
} elseif ($type == 'manyou') {
    $conf = array('type' => 'manyou', 'num' => '50', 'cachelife' => 300, 'multipage' => 0, 'page_url' => $indexname);
}
$feeds = get_feed($conf);
$feeddate = '';
if (empty($type)) {
    foreach ($feeds['data'] as $k => $feed) {
        $feeds['data'][$k]['date'] = gmdate($dateformat, $feed['dbdateline'] + $timeoffset * 3600);
        $feeds['data'][$k]['daterange'] = $feeddate != $feeds['data'][$k]['date'] ? $feeds['data'][$k]['date'] : '';
        $feeds['data'][$k]['title'] = preg_replace("/<a(.+?)href=([\\'\"]?)([^>\\s]+)\\2([^>]*)>/i", '<a target="_blank" \\1 href="\\3&from=indexfeeds" \\4>', $feeds['data'][$k]['title']);
        $feeds['data'][$k]['body'] = preg_replace("/<a(.+?)href=([\\'\"]?)([^>\\s]+)\\2([^>]*)>/i", '<a target="_blank" \\1 href="\\3&from=indexfeeds" \\4>', $feeds['data'][$k]['body']);
        $feeddate = $feeds['data'][$k]['date'];
    }
} else {
    $bi = 1;
    foreach ($feeds['data'] as $k => $feed) {
        $trans['{addbuddy}'] = $feed['uid'] != $discuz_uid ? '<a href="my.php?item=buddylist&newbuddyid=' . $feed['uid'] . '&buddysubmit=yes" id="ajax_buddy_' . $bi++ . '" onclick="ajaxmenu(this, 3000);doane(event);"><img style="vertical-align:middle" src="manyou/images/myadd.gif" /></a>' : '';
        $feeds['data'][$k]['title'] = strtr($feed['title'], $trans);
        $feeds['data'][$k]['body'] = strtr($feed['body'], $trans);
Exemplo n.º 5
0
$param->connection = 'friends';
$param->table_name = 'friends_raw_data';
get_fb_friends($param);
echo "done<br/>";
*/
//me/statuses
echo 'processing fb statuses...';
$param->connection = 'statuses';
$param->table_name = 'statuses_raw_data';
get_statuses($param);
echo "done<br/>";
//me/feed
echo 'processing fb feeds...';
$param->connection = 'feed';
$param->table_name = 'feed_raw_data';
get_feed($param);
echo "done<br/>";
//me/photos
echo 'processing fb photos...';
$param->connection = 'photos';
$param->table_name = 'photos_raw_data';
get_photo($param);
echo "done<br/>";
//me/albums
echo 'processing fb albums...';
$param->connection = 'albums';
$param->table_name = 'albums_raw_data';
$album_ids = get_albums($param);
echo "done<br/>";
//album_id/photos
echo 'processing fb photos inside albums...';
Exemplo n.º 6
0
        config('views.root', 'system/admin/views');
        render('import', array('title' => 'Import feed - ' . blog_title(), 'description' => blog_description(), 'canonical' => site_url(), 'bodyclass' => 'importfeed', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Import feed'));
    } else {
        $login = site_url() . 'login';
        header("location: {$login}");
    }
    die;
});
// Submitted import page data
post('/admin/import', function () {
    $proper = is_csrf_proper(from($_REQUEST, 'csrf_token'));
    $url = from($_REQUEST, 'url');
    $credit = from($_REQUEST, 'credit');
    if (login() && !empty($url) && $proper) {
        get_feed($url, $credit);
        $log = get_feed($url, $credit);
        if (!empty($log)) {
            config('views.root', 'system/admin/views');
            render('import', array('title' => 'Import feed - ' . blog_title(), 'description' => blog_description(), 'canonical' => site_url(), 'error' => '<ul>' . $log . '</ul>', 'bodyclass' => 'editprofile', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Import feed'));
        }
    } else {
        $message['error'] = '';
        if (empty($url)) {
            $message['error'] .= '<li>You need to specify the feed url.</li>';
        }
        if (!$proper) {
            $message['error'] .= '<li>CSRF Token not correct.</li>';
        }
        config('views.root', 'system/admin/views');
        render('import', array('title' => 'Import feed - ' . blog_title(), 'description' => blog_description(), 'canonical' => site_url(), 'error' => '<ul>' . $message['error'] . '</ul>', 'url' => $url, 'bodyclass' => 'editprofile', 'breadcrumb' => '<a href="' . site_url() . '">' . config('breadcrumb.home') . '</a> &#187; Login'));
    }
Exemplo n.º 7
0
if (!empty($_GET['refresh_feed']) && !empty($_GET['token']) && check_token(600, 'refresh_feed')) {
    $query = $dbh->prepare('SELECT url FROM feeds WHERE id=:id');
    $query->execute(array('id' => intval($_GET['refresh_feed'])));
    $url = $query->fetch();
    if (!empty($url['url'])) {
        refresh_feeds(array(intval($_GET['refresh_feed']) => array('url' => $url['url'], 'post' => '')));
        // TODO
    }
    header('location: settings.php');
    exit;
}
// Handle OPML export
if (isset($_POST['export']) && !empty($_POST['token']) && check_token(600, 'export_form')) {
    $feeds = array();
    foreach ($_POST['export'] as $feed_id) {
        $feeds[] = get_feed($feed_id);
    }
    require_once 'inc/opml.php';
    $now = new DateTime();
    header('Content-disposition: attachment; filename="freeder_export_' . $now->format('d-m-Y_H-i') . '.xml"');
    header('Content-type: "text/xml"; charset="utf8"');
    exit(opml_export($feeds));
}
// Handle OPML import
if (isset($_FILES['import']) && isset($_POST['import_tags_opml']) && !empty($_POST['token']) && check_token(600, 'import_form')) {
    if ($_FILES['import']['error'] > 0) {
        $error = array();
        $error['type'] = 'error';
        $error['title'] = 'OPML import error';
        $error['content'] = '<p>The OPML file could not be imported.</p>';
        $tpl->assign('error', $error, RainTPL::RAINTPL_IGNORE_SANITIZE);
Exemplo n.º 8
0
 function handle($params)
 {
     require_once 'api.php';
     $query = Dataface_Application::getInstance()->getQuery();
     switch ($query['-do']) {
         case 'login':
             $token = login($query['username'], $query['password']);
             if (!$token) {
                 $this->output(array('code' => 400, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'token' => $token));
             }
             return;
         case 'logout':
             $token = logout($query['token']);
             if (!$token) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'register':
             $res = register($query['username'], $query['password']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'get_friends':
             $friends = get_friends($query['token']);
             if ($friends === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'friends' => $friends));
             }
             return;
         case 'find_users':
             $results = find_users($query['token'], $query['filter']);
             if ($results === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'results' => $results));
             }
             return;
         case 'get_pending_friend_requests':
             $requests = get_pending_friend_requests($query['token']);
             if ($requests === false) {
                 $this->output(array('code' => 500, 'message' => 'Failed to get friend requests'));
             } else {
                 $this->output(array('code' => 200, 'requests' => $requests));
             }
             return;
         case 'send_friend_request':
             $res = send_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'accept_friend_request':
             $res = accept_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'decline_friend_request':
             $res = decline_friend_request($query['token'], $query['friend']);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200));
             }
             return;
         case 'post':
             $file_path = null;
             $file_name = null;
             if (@$_FILES['photo']) {
                 $file_path = $_FILES['photo']['tmp_name'];
                 $file_name = $_FILES['photo']['name'];
             }
             $res = post($query['token'], $query['comment'], $file_path, $file_name);
             if (!$res) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'post_id' => $res));
             }
             return;
         case 'get_posts':
             $posts = get_posts($query['token'], @$query['username'], @$query['older_than']);
             if ($posts === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'posts' => $posts));
             }
             return;
         case 'get_feed':
             $posts = get_feed($query['token'], @$query['older_than']);
             if ($posts === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'posts' => $posts));
             }
             return;
         case 'get_profile':
             $profile = get_profile($query['token'], $query['username']);
             if ($profile === false) {
                 $this->output(array('code' => 500, 'message' => error_message()));
             } else {
                 $this->output(array('code' => 200, 'profile' => $profile));
             }
             return;
         case 'update_profile':
             $vals = array();
             if (@$query['screen_name']) {
                 $vals['screen_name'] = $query['screen_name'];
             }
             if (@$_FILES['avatar']) {
                 $vals['avatar'] = $_FILES['avatar']['tmp_name'];
             }
             $res = update_profile($query['token'], $vals);
             if ($res !== false) {
                 $this->output(array('code' => 200));
             } else {
                 $this->output(array('code' => 500, 'message' => error_message()));
             }
             return;
     }
 }
Exemplo n.º 9
0
// VIP cache
$vips = array("http://rhiaro.co.uk", "http://rhiaro.co.uk/", "http://tigo.rhiaro.co.uk/");
$images = set_default_images();
if (isset($_SESSION['images'])) {
    $images = $_SESSION['images'];
}
if (isset($_POST['images_source'])) {
    $fetch = get_images($_POST['images_source']);
    if (!$fetch) {
        $errors["Problem fetching images"] = "The images url needs to return a single page AS2 Collection as JSON[-LD]. {$_POST['images_source']} did not return this.";
    } else {
        $images = $fetch;
    }
}
if (isset($_POST['feed_source'])) {
    $feed = get_feed($_POST['feed_source']);
    if (!$feed) {
        $errors["Problem fetching feed"] = "Something went wrong";
    }
}
function dump_headers($curl, $header_line)
{
    echo "<br>YEAH: " . $header_line;
    // or do whatever
    return strlen($header_line);
}
function auth($code, $state, $client_id = "https://apps.rhiaro.co.uk/obtainium")
{
    $params = "code=" . $code . "&redirect_uri=" . urlencode($state) . "&state=" . urlencode($state) . "&client_id=" . $client_id;
    $ch = curl_init("https://indieauth.com/auth");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
Exemplo n.º 10
0
function get_all_news($feeds, $tools, $ttl)
{
    $all_news = array();
    sort($feeds);
    foreach ($feeds as $i => $vals) {
        $data[] = get_feed($tools, $vals[1], $vals[3], $vals[2], $i, $ttl);
    }
    $titles = array();
    foreach ($data as $i => $vals) {
        if (is_array($vals)) {
            foreach ($vals as $n => $news) {
                if ($n == 0) {
                    continue;
                }
                if (isset($news['title'])) {
                    if (in_array($news['title'], $titles)) {
                        continue;
                    } else {
                        $titles[] = $news['title'];
                    }
                }
                if (isset($news['updated'])) {
                    $news['pubdate'] = $news['updated'];
                }
                if (isset($news['pubdate'])) {
                    $news['source'] = $feeds[$i][0];
                    $news['source_url'] = $feeds[$i][1];
                    $all_news[] = $news;
                }
            }
        }
    }
    usort($all_news, 'sort_by_time');
    array_unshift($all_news, array('title' => '', 'description' => ''));
    return $all_news;
}
<?php

// Disallow direct access to this file for security reasons
if (!defined("IN_MYBB")) {
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}
$page->add_breadcrumb_item("CloudFlare Manager", "index.php?module=cloudflare");
$page->add_breadcrumb_item("News", "index.php?module=cloudflare-news");
if (!$mybb->input['action']) {
    $page->output_header("CloudFlare Manager - News");
    $sub_tabs['overview'] = array('title' => "Overview", 'link' => "index.php?module=cloudflare-overview", 'description' => "A general overview and summary of statistics and updates.");
    $sub_tabs['news'] = array('title' => "CloudFlare News", 'link' => "index.php?module=cloudflare-news", 'description' => "The latest news from the CloudFlare blog.");
    $page->output_nav_tabs($sub_tabs, 'news');
    $table = new Table();
    $table->construct_cell(get_feed());
    $table->construct_row();
    $table->output("Latest News From the <a href=\"http://blog.cloudflare.com/\" target=\"_blank\">CloudFlare Blog</a>");
    $page->output_footer();
}
function get_feed()
{
    $feed = @simplexml_load_file("http://blog.cloudflare.com/rss.xml");
    if ($feed) {
        foreach ($feed->channel->item as $entry) {
            return "<span style=\"font-size: 16px;\"><strong>{$entry->title} - {$entry->pubDate}</strong></span>" . "<br /><br />{$entry->description}<br /><br />";
        }
    } else {
        return "Error: Could not retrieve data.";
    }
}
Exemplo n.º 12
0
/**
 * Returns the feed array associated with an entry
 */
function get_feed_from_entry($entry, $feeds = array())
{
    $feed_id = $entry['feed_id'];
    $search = multiarray_search('id', $feed_id, $feeds, false);
    if ($search !== false) {
        return $search;
    } else {
        return get_feed($feed_id);
    }
}
Exemplo n.º 13
0
function permanently_delete_feeds($userid)
{
    $result = db_query("SELECT * FROM feed_relation WHERE userid = '{$userid}'");
    $feeds = array();
    if ($result) {
        while ($row = db_fetch_array($result)) {
            $feed = get_feed($row['feedid']);
            $feedid = $feed[0];
            if ($feed && $feed[7] == 1) {
                db_query("DELETE FROM feeds WHERE id = '{$feedid}'");
                db_query("DELETE FROM feeds WHERE id = '{$feedid}'");
                db_query("DELETE FROM feed_relation WHERE userid = '{$userid}' AND feedid = '{$feedid}' LIMIT 1");
                db_query("DROP TABLE feed_" . $feedid);
            }
        }
    }
}
Exemplo n.º 14
0
<?php

/* Generates the actual RSS feed from the database */
require 'lib.php';
$db = db_connect();
$feed = get_feed($db, $_GET['f']);
$articles = article_list($db, $_GET['f']);
header("Content-Type: application/rss+xml");
header("Content-Disposition: attachment; filename=\"{$feed['title']}.rss\"");
echo '<?xml version="1.0" encoding="ISO-8859-1" ?>';
?>
<rss version="2.0">
    <channel>
        <title><?php 
echo $feed['title'];
?>
</title>
        <link><?php 
echo $feed['link'];
?>
</link>
        <description><![CDATA[<?php 
echo $feed['description'];
?>
]]></description>
        <? if ($feed['category']!='') { ?>
        <category><?php 
echo $feed['category'];
?>
</category>
        <? } if ($feed['copyright']!='') { ?>
Exemplo n.º 15
0
function feed_controller()
{
    require "Models/feed_model.php";
    global $session, $action, $format;
    $output['content'] = "";
    $output['message'] = "";
    //---------------------------------------------------------------------------------------------------------
    // Set feed datatype: DataType::UNDEFINED|REALTIME|DAILY|HISTOGRAM
    // http://yoursite/emoncms/feed/type?id=1&type=1
    //---------------------------------------------------------------------------------------------------------
    if ($action == "type" && $session['write']) {
        $feedid = intval($_GET["id"]);
        $type = intval($_GET["type"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            set_feed_datatype($feedid, $type);
            $output['message'] = _("Feed type changed");
        } else {
            $output['message'] = _("Feed does not exist");
        }
        if ($format == 'html') {
            header("Location: view?id={$feedid}");
            // Return to feed list page
        }
    } elseif ($action == "tag" && $session['write']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            $newfeedtag = preg_replace('/[^\\w\\s-.]/', '', $_GET["tag"]);
            // filter out all except for alphanumeric white space and dash and full stop
            $newfeedtag = db_real_escape_string($newfeedtag);
            set_feed_tag($feedid, $newfeedtag);
            $output['message'] = _("Feed tag changed");
        } else {
            $output['message'] = _("Feed does not exist");
        }
        if ($format == 'html') {
            header("Location: list");
            // Return to feed list page
        }
    } elseif ($action == "rename" && $session['write']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            $newfeedname = preg_replace('/[^\\w\\s-.]/', '', $_GET["name"]);
            // filter out all except for alphanumeric white space and dash
            $newfeedname = db_real_escape_string($newfeedname);
            set_feed_name($feedid, $newfeedname);
            $output['message'] = _("Feed renamed");
        } else {
            $output['message'] = _("Feed does not exist");
        }
        if ($format == 'html') {
            header("Location: list");
            // Return to feed list page
        }
    } elseif ($action == "delete" && $session['write']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            delete_feed($userid, $feedid);
            $output['message'] = _("Feed ") . get_feed_name($feedid) . _(" deleted");
        } else {
            $output['message'] = _("Feed does not exist");
        }
    }
    //---------------------------------------------------------------------------------------------------------
    // Permanent delete equivalent to empty recycle bin
    // http://yoursite/emoncms/feed/permanentlydelete
    //---------------------------------------------------------------------------------------------------------
    if ($action == "permanentlydelete" && $session['write']) {
        permanently_delete_feeds($session['userid']);
        $output['message'] = "Deleted feeds are now permanently deleted";
    }
    //---------------------------------------------------------------------------------------------------------
    // Restore feed ( if in recycle bin )
    // http://yoursite/emoncms/feed/restore?id=1
    //---------------------------------------------------------------------------------------------------------
    if ($action == "restore" && $session['write']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            restore_feed($userid, $feedid);
        }
        $output['message'] = "feed restored";
        if ($format == 'html') {
            header("Location: list");
        }
        // Return to feed list page
    }
    //---------------------------------------------------------------------------------------------------------
    // Feed List
    // http://yoursite/emoncms/feed/list.html
    // http://yoursite/emoncms/feed/list.json
    //---------------------------------------------------------------------------------------------------------
    if ($action == 'list' && $session['read']) {
        $del = 0;
        if (isset($_GET["del"])) {
            $del = intval($_GET["del"]);
        }
        $feeds = get_user_feeds($session['userid'], $del);
        if ($format == 'json') {
            $output['content'] = json_encode($feeds);
        }
        if ($format == 'html') {
            $output['content'] = view("feed/list_view.php", array('feeds' => $feeds, 'del' => $del));
        }
    } elseif ($action == 'view' && $session['read']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            $feed = get_feed($feedid);
        }
        if ($format == 'json') {
            $output['content'] = json_encode($feed);
            // Allow for AJAX from remote source
            if ($_GET["callback"]) {
                $output['content'] = $_GET["callback"] . "(" . json_encode($feed) . ");";
            }
        }
        if ($format == 'html') {
            $output['content'] = view("feed/feed_view.php", array('feed' => $feed));
        }
    } elseif ($action == 'value' && $session['read']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            $output['content'] = get_feed_value($feedid);
        }
    } elseif ($action == 'data' && $session['read']) {
        $feedid = intval($_GET['id']);
        // Check if feed belongs to user
        if (feed_belongs_user($feedid, $session['userid'])) {
            $start = floatval($_GET['start']);
            $end = floatval($_GET['end']);
            $dp = intval($_GET['dp']);
            $data = get_feed_data($feedid, $start, $end, $dp);
            $output['content'] = json_encode($data);
        } else {
            $output['message'] = "Permission denied";
        }
    }
    //---------------------------------------------------------------------------------------------------------
    // get histogram data: energy used at different powers in the time range given
    // http://yoursite/emoncms/feed/histogram?id=1&start=000&end=000
    //---------------------------------------------------------------------------------------------------------
    if ($action == 'histogram' && $session['read']) {
        $feedid = intval($_GET['id']);
        // Check if feed belongs to user
        if (feed_belongs_user($feedid, $session['userid'])) {
            $start = floatval($_GET['start']);
            $end = floatval($_GET['end']);
            $data = get_histogram_data($feedid, $start, $end);
            $output['content'] = json_encode($data);
        } else {
            $output['message'] = "Permission denied";
        }
    }
    //---------------------------------------------------------------------------------------------------------
    // get kwh per day at given power range
    // http://yoursite/emoncms/feed/kwhatpower?id=3&min=1000&max=10000
    //---------------------------------------------------------------------------------------------------------
    if ($action == 'kwhatpower' && $session['read']) {
        $feedid = intval($_GET['id']);
        // Check if feed belongs to user
        if (feed_belongs_user($feedid, $session['userid'])) {
            $min = floatval($_GET['min']);
            $max = floatval($_GET['max']);
            $data = get_kwhd_atpower($feedid, $min, $max);
            $output['content'] = json_encode($data);
        } else {
            $output['message'] = "This is not your feed...";
        }
    }
    //---------------------------------------------------------------------------------------------------------
    // Set a datapoint at a given time.
    // http://yoursite/emoncms/feed/edit?id=1&time=...&newvalue=...
    //---------------------------------------------------------------------------------------------------------
    if ($action == "edit" && $session['write']) {
        $feedid = intval($_GET["id"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            $time = intval($_GET["time"]);
            $value = floatval($_GET["newvalue"]);
            update_feed_data($feedid, time(), $time, $value);
            $output['message'] = "Edit";
        }
    }
    if ($action == "export" && $session['write']) {
        // Feed id and start time of feed to export
        $feedid = intval($_GET["id"]);
        $start = intval($_GET["start"]);
        if (feed_belongs_user($feedid, $session['userid'])) {
            // Open database etc here
            // Extend timeout limit from 30s to 2mins
            set_time_limit(120);
            // Regulate mysql and apache load.
            $block_size = 1000;
            $sleep = 20000;
            $feedname = "feed_" . trim($feedid) . "";
            $fileName = $feedname . '.csv';
            // There is no need for the browser to cache the output
            header("Cache-Control: no-cache, no-store, must-revalidate");
            // Tell the browser to handle output as a csv file to be downloaded
            header('Content-Description: File Transfer');
            header("Content-type: text/csv");
            header("Content-Disposition: attachment; filename={$fileName}");
            header("Expires: 0");
            header("Pragma: no-cache");
            // Write to output stream
            $fh = @fopen('php://output', 'w');
            // Load new feed blocks until there is no more data
            $moredata_available = 1;
            while ($moredata_available) {
                // 1) Load a block
                $result = db_query("SELECT * FROM {$feedname} WHERE time>{$start}  \n          ORDER BY time Asc Limit {$block_size}");
                $moredata_available = 0;
                while ($row = db_fetch_array($result)) {
                    // Write block as csv to output stream
                    fputcsv($fh, array($row['time'], $row['data']));
                    // Set new start time so that we read the next block along
                    $start = $row['time'];
                    $moredata_available = 1;
                }
                // 2) Sleep for a bit
                usleep($sleep);
            }
            fclose($fh);
            exit;
        }
    }
    return $output;
}
Exemplo n.º 16
0
        foreach($node->getElementsByTagName('category') as $c)
            array_push($categories, $c->nodeValue);

        $itemRSS = array ( 
            'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
            'content' => $node->getElementsByTagName('encoded')->item(0)->nodeValue,
            'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
            'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
            'categories' => $categories
            );
        array_push($news_feed, $itemRSS);
    }
    return $news_feed;
}

$feed = get_feed($url);

$title = "News";
include("header.inc");
?>
<div id="main">
<h1> <?php 
echo $title;
?>
 </h1>

<? foreach ($feed as $item){ ?>
        <h2><?php 
echo $item['title'];
?>
</h2>