Esempio n. 1
0
function txRssFeedAccess()
{
    global $DB, $json, $C;
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $out = array('status' => JSON_FAILURE, 'message' => 'Could not access the RSS feed');
    $http = new Http();
    if ($http->Get($_REQUEST['url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($feed = $parser->Parse($http->body)) !== FALSE) {
            if (count($feed['items']) > 0) {
                $out['status'] = JSON_SUCCESS;
                $item = $feed['items'][0];
                ob_start();
                eval('?>' . file_get_contents('includes/rss-feeds-item.php'));
                $out['html'] .= ob_get_contents();
                ob_end_clean();
            } else {
                $out['message'] = 'No <item> tags could be found in the RSS feed';
            }
        } else {
            $out['message'] = $parser->errstr;
        }
    } else {
        $out['message'] = 'Accessing RSS feed failed: ' . $http->errstr;
    }
    echo $json->encode($out);
}
Esempio n. 2
0
function ImportFromRss($feed)
{
    global $DB, $C;
    $settings = unserialize($feed['settings']);
    $category = $DB->Row('SELECT * FROM `tx_categories` WHERE `category_id`=?', array($settings['category']));
    $columns = $DB->GetColumns('tx_gallery_fields');
    $imported = 0;
    $defaults = array('gallery_url' => null, 'description' => null, 'keywords' => null, 'thumbnails' => 0, 'email' => $C['from_email'], 'nickname' => null, 'weight' => $C['gallery_weight'], 'clicks' => 0, 'submit_ip' => GetIpFromUrl($feed['feed_url']), 'gallery_ip' => '', 'sponsor_id' => !empty($feed['sponsor_id']) ? $feed['sponsor_id'] : null, 'type' => $settings['type'], 'format' => $settings['format'], 'status' => $settings['status'], 'previous_status' => null, 'date_scanned' => null, 'date_added' => MYSQL_NOW, 'date_approved' => null, 'date_scheduled' => null, 'date_displayed' => null, 'date_deletion' => null, 'partner' => null, 'administrator' => $_SERVER['REMOTE_USER'], 'admin_comments' => null, 'page_hash' => null, 'has_recip' => 0, 'has_preview' => 0, 'allow_scan' => 1, 'allow_preview' => 1, 'times_selected' => 0, 'used_counter' => 0, 'build_counter' => 0, 'tags' => null, 'categories' => MIXED_CATEGORY . " " . $category['tag'], 'preview_url' => null, 'dimensions' => null);
    require_once "{$GLOBALS['BASE_DIR']}/includes/rssparser.class.php";
    $http = new Http();
    if ($http->Get($feed['feed_url'], TRUE, $C['install_url'])) {
        $parser = new RSSParser();
        if (($rss = $parser->Parse($http->body)) !== FALSE) {
            foreach ($rss['items'] as $item) {
                $gallery = array();
                $gallery['gallery_url'] = html_entity_decode($item[$settings['gallery_url_from']]);
                $gallery['description'] = html_entity_decode($item[$settings['description_from']]);
                if (!empty($settings['date_added_from'])) {
                    if (($timestamp = strtotime($item[$settings['date_added_from']])) !== FALSE) {
                        $gallery['date_added'] = date(DF_DATETIME, $timestamp);
                    }
                }
                if (!empty($settings['preview_from'])) {
                    if (!is_array($item[$settings['preview_from']])) {
                        $item[$settings['preview_from']] = array($item[$settings['preview_from']]);
                    }
                    foreach ($item[$settings['preview_from']] as $item_value) {
                        if (preg_match('~(http://[^>< ]+\\.(jpg|png))~i', $item_value, $matches)) {
                            $gallery['preview_url'] = $matches[1];
                            break;
                        }
                    }
                }
                // Remove HTML tags and trim the description
                $gallery['description'] = trim(strip_tags($gallery['description']));
                // Merge with the defaults
                $gallery = array_merge($defaults, $gallery);
                // Skip over duplicate or empty URLs
                if ($DB->Count('SELECT COUNT(*) FROM `tx_galleries` WHERE `gallery_url`=?', array($gallery['gallery_url'])) || IsEmptyString($gallery['gallery_url'])) {
                    continue;
                }
                $imported++;
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $gallery['has_preview'] = 1;
                }
                // Add regular fields
                $DB->Update('INSERT INTO `tx_galleries` VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)', array(null, $gallery['gallery_url'], $gallery['description'], $gallery['keywords'], $gallery['thumbnails'], $gallery['email'], $gallery['nickname'], $gallery['weight'], $gallery['clicks'], $gallery['submit_ip'], $gallery['gallery_ip'], $gallery['sponsor_id'], $gallery['type'], $gallery['format'], $gallery['status'], $gallery['previous_status'], $gallery['date_scanned'], $gallery['date_added'], $gallery['date_approved'], $gallery['date_scheduled'], $gallery['date_displayed'], $gallery['date_deletion'], $gallery['partner'], $gallery['administrator'], $gallery['admin_comments'], $gallery['page_hash'], $gallery['has_recip'], $gallery['has_preview'], $gallery['allow_scan'], $gallery['allow_preview'], $gallery['times_selected'], $gallery['used_counter'], $gallery['build_counter'], $gallery['tags'], $gallery['categories']));
                $gallery['gallery_id'] = $DB->InsertID();
                // Add user defined fields
                $query_data = CreateUserInsert('tx_gallery_fields', $gallery, $columns);
                $DB->Update('INSERT INTO `tx_gallery_fields` VALUES (' . $query_data['bind_list'] . ')', $query_data['binds']);
                // Has a preview thumbnail
                if (!empty($gallery['preview_url'])) {
                    $DB->Update('INSERT INTO `tx_gallery_previews` VALUES (?,?,?,?)', array(null, $gallery['gallery_id'], $gallery['preview_url'], $gallery['dimensions']));
                }
            }
        }
        $DB->Update('UPDATE `tx_rss_feeds` SET `date_last_import`=? WHERE `feed_id`=?', array(MYSQL_NOW, $feed['feed_id']));
    } else {
        return "Could not access the RSS feed: " . $http->errstr;
    }
    return $imported;
}