function generate_cache()
{
    global $albumid, $albumsfeed, $photosfeed;
    // ignore_user_abort();
    if ($albumid) {
        $photosfeed = get_rss_content(true);
        get_json_content(false, true);
        echo "{$photosfeed->feed->title->_t} is updated<br/>";
        exit;
    }
    $albumsfeed = get_rss_content(true);
    echo "{$albumsfeed->feed->title->_t} is updated<br/>";
    for ($i = 0; $i < count($albumsfeed->feed->entry); $i++) {
        $album = $albumsfeed->feed->entry[$i];
        $id_begin = strpos($album->id->_t, 'albumid/') + 8;
        $id_end = strpos($album->id->_t, '?');
        $albumid = substr($album->id->_t, $id_begin, $id_end - $id_begin);
        $img_update = substr($album->updated->_t, 0, 10);
        $mod_date = get_cache_date();
        // echo $mod_date."".$img_update."<br/>";
        if ($mod_date < $img_update) {
            get_rss_content(true);
            get_json_content(false, true);
            echo "{$album->title->_t} is updated<br/>";
        }
    }
}
$pwa_directory = ABSPATH . "/wp-content/themes/yuewei/cache/";
// cache directory
$snoopy_file = ABSPATH . "/wp-includes/class-snoopy.php";
$picasa_uri = "http://zhiqiang.org/blog/wp-content/themes/yuewei/webpicasa.php";
// input
$albumid = isset($_REQUEST['albumid']) ? $_REQUEST['albumid'] : '';
$np = isset($_REQUEST['np']) ? (int) $_REQUEST['np'] : -1;
if (isset($_REQUEST['json'])) {
    header("Cache-Control: public");
    header("Pragma: cache");
    $offset = 60 * 60 * 24;
    $ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
    header($ExpStr);
    header($LmStr);
    header('Content-Type: text/javascript; charset: UTF-8');
    get_json_content(true);
    exit;
}
function get_rss_uri()
{
    global $albumid, $username;
    if ($albumid) {
        return "http://picasaweb.google.com/data/feed/base/user/{$username}/albumid/{$albumid}?category=photo&alt=json&access=public";
    } else {
        return "http://picasaweb.google.com/data/feed/base/user/{$username}?category=album&alt=json&access=public";
    }
}
function get_rss_content()
{
    global $snoopy_file, $pwa_directory;
    $rss_uri = get_rss_uri();
Esempio n. 3
0
/**
 * Check if content.json file has any post in its array.
 * @return mixed|bool returns array on success, false on fail.
 */
function content_posts_exist()
{
    $output = false;
    $content = get_json_content(CONTENTPATH . 'content.json');
    if (is_array($content) && isset($content['posts']) && !empty($content['posts'])) {
        $output = $content;
    }
    return $output;
}
/**
 * Change the status of a given comment from PENDING to APPROVED
 * @param int $comment_id 
 * @return bool Returns true on success and False on fail
 */
function approve_comment($comment_id)
{
    $output = false;
    $i = 0;
    if (comment_exist((int) $comment_id)) {
        $comment_file = get_json_content(CONTENTPATH . 'comments.json');
        $comments =& $comment_file['comments'];
        while ($i < count($comments)) {
            if ($comments[$i]['id'] === (int) $comment_id) {
                $comments[$i]['status'] = 'APPROVED';
                $approved = true;
                break;
            }
            $i++;
        }
        if ($approved === true) {
            if (write_to_json(CONTENTPATH . 'comments.json', $comment_file)) {
                $output = true;
            }
        }
    }
    return $output;
}
Esempio n. 5
0
<?php

/**
 * Exercise #4: Photos from Flickr
 */
require "get_content.php";
$url = "http://api.flickr.com/services/feeds/photos_public.gne";
$params = array("nojsoncallback" => 1, "tags" => "stavanger", "tagmode" => "any", "format" => "json");
// get response as an associative array
$data = get_json_content($url, $params);
?>

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Exercise #4: Photos from Flickr</title>
    <style>
        td {
            border: 1px solid grey;
        }
    </style>
</head>
<body>
<table>

    <?php 
$photos = $data['items'];
for ($i = 0; $i < min(5, count($photos)); $i++) {
    echo '<tr><td><a href="' . $photos[$i]['link'] . '">' . '<img src="' . $photos[$i]['media']['m'] . '" width="100px"></a></td>' . '<td><strong>' . $photos[$i]['title'] . '</strong><br/>' . $photos[$i]['published'] . '<br /><br />' . $photos[$i]['tags'] . '</td></tr>';
}
<?php

renew_session();
$update_msg = '';
if (isset($_POST) && !empty($_POST)) {
    if (update_posts_settings($_POST)) {
        $update_msg = '<div class="green-msg"><p>New settings have been successfully accepted.</p></div>';
    } else {
        $update_msg = '<div class="warning-msg"><p>Something went wrong, changes were not accepted.</p></div>';
    }
}
if (file_exists(LOCKPATH . 'posts-config.json')) {
    //Get settings file
    $set_file = get_json_content(LOCKPATH . 'posts-config.json');
    $sets_now = $set_file['postssettings'];
    //Get individual settings value
    //ALLOW SECTION
    $allowcomments = $sets_now['allowcomments'] === '1' ? 'checked' : '';
    $allowwritercard = $sets_now['allowwritercard'] === '1' ? 'checked' : '';
    $allowsidebarposts = isset($sets_now['allowsidebarposts']) ? $sets_now['allowsidebarposts'] : '';
    $allowpostsperpage = isset($sets_now['allowpostsperpage']) ? $sets_now['allowpostsperpage'] : '';
    $allowcatfeed = $sets_now['allowcatfeed'] === '1' ? 'checked' : '';
    //SOCIAL SECTION
    $sbar = $sets_now['socialbar'];
    $socialfbID = !empty($sbar['socialfbID']) ? $sbar['socialfbID'] : '';
    $socialbarshow = $sbar['socialbarshow'] === '1' ? 'checked' : '';
    $socialfb = $sbar['socialfacebook'] === '1' ? 'checked' : '';
    $socialgplus = $sbar['socialgplus'] === '1' ? 'checked' : '';
    $socialpin = $sbar['socialpinterest'] === '1' ? 'checked' : '';
    $socialtwit = $sbar['socialtwitter'] === '1' ? 'checked' : '';
    $sociallink = $sbar['sociallinkedin'] === '1' ? 'checked' : '';