Exemplo n.º 1
0
<?php

/**
 * PHP SDK for QQ登录 OpenAPI
 *
 * @version 1.5
 * @author connect@qq.com
 * @copyright © 2011, Tencent Corporation. All rights reserved.
 */
require_once "../comm/utils.php";
/**
 * @brief 发布一条动态(feeds)到QQ空间中,展现给好友.请求需经过URL编码,编码时请遵循 RFC 1738
 *
 * @param $appid
 * @param $appkey
 * @param $access_token
 * @param $access_token_secret
 * @param $openid
 */
function add_feeds($appid, $appkey, $access_token, $access_token_secret, $openid)
{
    //发布一条动态的接口地址, 不要更改!!
    $url = "http://openapi.qzone.qq.com/share/add_share";
    echo do_post($url, $appid, $appkey, $access_token, $access_token_secret, $openid);
}
//接口调用示例:
add_feeds($_SESSION["appid"], $_SESSION["appkey"], $_SESSION["token"], $_SESSION["secret"], $_SESSION["openid"]);
Exemplo n.º 2
0
     $tpl->assign('error', $error, RainTPL::RAINTPL_IGNORE_SANITIZE);
     $tpl->draw('settings');
     exit;
 }
 require_once 'inc/opml.php';
 $feeds_opml = opml_import(file_get_contents($_FILES['import']['tmp_name']));
 if ($feeds_opml === false) {
     $error = array();
     $error['type'] = 'error';
     $error['title'] = 'OPML import error';
     $error['content'] = '<p>An error occurred during the OPML import. Maybe you did not upload a valid OPML file ?</p>';
     $tpl->assign('error', $error, RainTPL::RAINTPL_IGNORE_SANITIZE);
     $tpl->draw('settings');
     exit;
 }
 $errors_refresh = add_feeds($feeds_opml, (bool) $_POST['import_tags_opml']);
 if (empty($errors_refresh)) {
     header('location: settings.php');
     exit;
 } else {
     // Some feeds errorred
     $error = array();
     $error['type'] = 'warning';
     $error['title'] = 'OPML import error';
     $error['content'] = '<p>Some of the imported feeds encountered errors during refresh. The following feeds were <strong>NOT</strong> imported:</p><ul>';
     foreach ($errors_refresh as $error_refresh) {
         $error['content'] .= '<li><a href="' . sanitize($error_refresh['url']) . '">' . sanitize($error_refresh['url']) . '</a> (' . sanitize($error_refresh['msg']) . ')</li>';
     }
     $error['content'] .= '</ul>';
     $tpl->assign('error', $error, RainTPL::RAINTPL_IGNORE_SANITIZE);
     $tpl->draw('settings');
Exemplo n.º 3
0
/**
 * Add feeds in the database and refresh them.
 *
 * @param $urls is an array of associative arrays {url, post} for each url. Post is a JSON array of POST data to send
 * @return errored urls in array
 */
function add_feeds($urls, $import_tags = NULL)
{
    global $dbh, $config;
    $errors = array();
    $added = array();
    $dbh->beginTransaction();
    $query = $dbh->prepare('INSERT OR IGNORE INTO feeds(url, title, has_user_title, post, import_tags_from_feed) VALUES(:url, :title, CASE WHEN :title="" THEN 0 ELSE 1 END, :post, :import_tags)');
    $query->bindParam(':url', $url);
    $query->bindParam(':title', $title);
    $query->bindParam(':post', $post);
    $import_tags_db = $import_tags === NULL ? FALSE : (int) $import_tags;
    $query->bindParam(':import_tags', $import_tags_db, PDO::PARAM_INT);
    foreach ($urls as $url_array) {
        $url = $url_array['url'];
        if (isset($url_array['post'])) {
            $post = $url_array['post'];
        } else {
            $post = '';
        }
        if (isset($url_array['title'])) {
            $title = $url_array['title'];
        } else {
            $title = '';
        }
        if (isset($url_array['tags'])) {
            $tags = $url_array['tags'];
        } else {
            $tags = array();
        }
        if (filter_var($url, FILTER_VALIDATE_URL)) {
            $query->execute();
            $id = $dbh->lastInsertId();
            if ($id != 0) {
                $added[] = array('id' => $dbh->lastInsertId(), 'url' => $url, 'post' => $post, 'tags' => $tags, 'import_tags_from_feed' => $import_tags === true || $config->import_tags_from_feeds != 0);
            } else {
                $errors[] = array('url' => $url, 'msg' => 'Feed already exists');
            }
        } else {
            $errors[] = array('url' => $url, 'msg' => 'Invalid URL');
        }
    }
    $dbh->commit();
    $errors_refresh = refresh_feeds($added, true);
    $errors_urls = array();
    foreach ($errors_refresh as $error) {
        delete_feed_url($error['url']);
        $errors_urls[] = $error['url'];
    }
    $search_feed_url = get_feed_url_from_html($errors_refresh);
    if (!empty($search_feed_url['urls'])) {
        foreach ($search_feed_url['urls'] as $error) {
            $key = array_search($error['original_url'], $errors_urls);
            if ($key !== false) {
                unset($errors_urls[$key]);
            }
            foreach ($errors_refresh as $key => $error_refresh) {
                if ($error_refresh['url'] == $error['original_url']) {
                    unset($errors_refresh[$key]);
                }
            }
        }
        add_feeds($search_feed_url['urls']);
    }
    // Add feeds tags
    if ($import_tags === true || $config->import_tags_from_feeds != 0) {
        $dbh->beginTransaction();
        $query_insert_tag = $dbh->prepare('INSERT OR IGNORE INTO tags(name) VALUES(:name)');
        $query_insert_tag->bindParam(':name', $tag_name);
        // Register the tags of the feed
        $query_tags = $dbh->prepare('INSERT INTO tags_feeds(tag_id, feed_id, auto_added_tag) VALUES((SELECT id FROM tags WHERE name=:name), :feed_id, 0)');
        $query_tags->bindParam(':name', $tag_name);
        $query_tags->bindParam(':feed_id', $feed_id);
        foreach ($added as $url_array) {
            if (in_array($url_array['url'], $errors_urls)) {
                continue;
            }
            $feed_id = $url_array['id'];
            foreach ($url_array['tags'] as $tag_name) {
                $query_insert_tag->execute();
                $query_tags->execute();
            }
        }
        $dbh->commit();
    }
    return array_merge($errors, $errors_refresh);
}