function rss_import_showpage() { global $main_smarty, $the_template, $db; include_once 'config.php'; include_once mnminclude . 'html1.php'; include_once mnminclude . 'link.php'; include_once mnminclude . 'tags.php'; include_once mnminclude . 'smartyvariables.php'; require_once 'class.rssimport.php'; require_once 'modules/rss_import/magpierss/rss_fetch.inc'; define('MAGPIE_CACHE_DIR', 'cache/templates_c/'); define('rss_import_export_version', '0.4'); $smarty = $main_smarty; include_once mnminclude . 'qeip_0_3.php'; force_authentication(); $amIgod = 0; $amIgod = $amIgod + checklevel('god'); // pagename define('modulename', 'rss_import'); $main_smarty->assign('modulename', modulename); // breadcrumbs and page title $navwhere['text1'] = $smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel'); $navwhere['link1'] = getmyurl('admin', ''); $navwhere['text2'] = $smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel_RSSImport'); $smarty->assign('navbar_where', $navwhere); $smarty->assign('posttitle', ' / ' . $smarty->get_config_vars('PLIGG_Visual_Header_AdminPanel_RSSImport')); // sidebar $main_smarty = do_sidebar($main_smarty); if ($amIgod == 1) { $tableexists = checkfortable(table_prefix . 'feeds'); if (!$tableexists) { echo "Creating Tables<hr />"; include_once 'create_feed_tables.php'; die("<hr />If there are no errors then refresh this page to continue"); } $filename = 'create_feed_tables.php'; if (file_exists($filename)) { // die("Please delete or rename the file create_feed_tables.php, then refresh this page"); } $smarty->register_function('feedsListFeeds', 'smarty_function_feedsListFeeds'); $smarty->register_function('feedsListFeedLinks', 'smarty_function_feedsListFeedLinks'); $smarty->register_function('feedsListFeedFields', 'smarty_function_feedsListFeedFields'); $smarty->register_function('feedsListPliggLinkFields', 'smarty_function_feedsListPliggLinkFields'); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_name', 'key' => 'feed_id'); // a unique identifier for the row $smarty->assign('qeip_FeedName', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_url', 'key' => 'feed_id'); // a unique identifier for the row $smarty->assign('qeip_FeedURL', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_category', 'key' => 'feed_id'); // a unique identifier for the row $smarty->assign('qeip_FeedCategory', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_freq_hours', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedFreqHours', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_votes', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedVotes', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_item_limit', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedItemLimit', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_url_dupe', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedURLDupe', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_title_dupe', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedTitleDupe', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_submitter', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedSubmitter', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feed_link', 'field_name' => 'feed_field', 'key' => 'feed_link_id', 'eip_type' => 'select'); // the type of EIP field to show $smarty->assign('qeip_FeedLink_FeedField', $QEIPA); $QEIPA = array('table_name' => table_prefix . 'feed_link', 'field_name' => 'pligg_field', 'key' => 'feed_link_id', 'eip_type' => 'select'); // the type of EIP field to show $smarty->assign('qeip_FeedLink_PliggField', $QEIPA); // feed oldest first $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_last_item_first', 'key' => 'feed_id'); // a unique identifier for the row $smarty->assign('qeip_FeedLastItemFirst', $QEIPA); // feed random vote $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_random_vote_enable', 'key' => 'feed_id'); // a unique identifier for the row $smarty->assign('qeip_FeedRandomVoteEnable', $QEIPA); // feed random vote min $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_random_vote_min', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedRandomVotesMin', $QEIPA); // feed random vote max $QEIPA = array('table_name' => table_prefix . 'feeds', 'field_name' => 'feed_random_vote_max', 'key' => 'feed_id', 'field_type' => 'number'); // the type of database field we are reading from / writing to $smarty->assign('qeip_FeedRandomVotesMax', $QEIPA); $QEIP = new QuickEIP(); if (!isset($_REQUEST['action'])) { $smarty->assign('tpl_center', rss_import_tpl_path . 'admin_rss_center'); $main_smarty->display($template_dir . '/admin/admin.tpl'); echo $QEIP->ShowOnloadJS(); } else { if ($_REQUEST['action'] == "addnewfieldlink") { $RSSImport = new RSSImport(); $RSSImport->FeedLinkId = $_REQUEST['FeedLinkId']; $RSSImport->new_field_link(); redirect('module.php?module=rss_import&action=editfeed&feed_id=' . $_REQUEST['FeedLinkId']); } if ($_REQUEST['action'] == "dropfieldlink") { $RSSImport = new RSSImport(); $RSSImport->FeedLinkId = $_REQUEST['FeedLinkId']; $RSSImport->drop_field_link(); redirect('module.php?module=rss_import'); } if ($_REQUEST['action'] == "addnewfeed") { $RSSImport = new RSSImport(); $RSSImport->FeedName = "New Feed"; $RSSImport->new_feed(); redirect('module.php?module=rss_import'); } if ($_REQUEST['action'] == "dropfeed") { $RSSImport = new RSSImport(); $RSSImport->FeedId = $_REQUEST['feed_id']; $RSSImport->drop_feed(); redirect('module.php?module=rss_import'); } if ($_REQUEST['action'] == "save") { echo $QEIP->save_field($smarty); } if ($_REQUEST['action'] == "examinefeed") { $RSSImport = new RSSImport(); $RSSImport->FeedId = $_REQUEST['feed_id']; $RSSImport->read_feed(); $rss = fetch_rss($RSSImport->FeedURL); $z = $rss->items[0]; if ($z) { echo 'First item in the feed.<hr />'; print_r_html($z); echo '<hr />Feed dump.<hr />'; print_r_html($rss); } else { echo '<hr />There are no items in this feed<hr />'; } } if ($_REQUEST['action'] == "editfeed") { $RSSImport = new RSSImport(); $RSSImport->FeedId = $_REQUEST['feed_id']; $smarty->assign('tpl_center', rss_import_tpl_path . 'admin_rss_center2'); $main_smarty->display($template_dir . '/admin/admin.tpl'); } if ($_REQUEST['action'] == "exportfeed") { echo 'copy all the text in the box<br />'; echo '<textarea rows=10 cols=70>' . serialize_feed($_REQUEST['feed_id']) . '</textarea>'; echo '<br /><br /><a href = "module.php?module=rss_import">return to the rss importer</a>'; } if ($_REQUEST['action'] == "importprebuiltfeed_go") { $feed = stripslashes($_REQUEST['prebuiltfeed']); if (strpos($feed, '://') < 10) { $r = new HTTPRequest($feed); $feed = $r->DownloadToString(); } if (import_prebuilt($feed)) { redirect(my_pligg_base . '/module.php?module=rss_import'); } else { // what do we do if error? } } } //echo $QEIP->ShowOnloadJS(); } }
<?php include '../config.php'; require mnminclude . 'link.php'; require mnminclude . 'tags.php'; require './libs/rssimport.php'; require_once '../3rdparty/magpierss/rss_fetch.inc'; define('MAGPIE_CACHE_DIR', '../templates_c'); $RSSImport = new RSSImport(); $feeds_list = $RSSImport->get_feeds_lists(); if (!$feeds_list) { die("You have not setup any feeds yet!"); } foreach ($feeds_list as $feed) { $url = $feed->feed_url; $rss = fetch_rss($url); echo "<h1>Site: ", $rss->channel['title'], "</h1><hr>"; if (time() - $feed->feed_freq_hours * 3600 > strtotime($feed->feed_last_check) || $_GET['override'] == $feed->feed_id) { $MyArray = array(); $Feed_Links = $RSSImport->get_feed_field_links($feed->feed_id); if (count($Feed_Links) > 0) { foreach ($Feed_Links as $link) { if ($link->pligg_field == 'link_title') { $MyArray['title'] = $link->feed_field; } if ($link->pligg_field == 'link_content') { $MyArray['content'] = $link->feed_field; } if ($link->pligg_field == 'link_url') { $MyArray['link_url'] = $link->feed_field; }
function do_the_import_stuff($feed) { global $db, $dblang, $RSSImport; $RSSImport = new RSSImport(); $added_one = false; $url = $feed->feed_url; $rss = fetch_rss($url); if ($_GET['override'] == $feed->feed_id) { $canIhaveAccess = 0; $canIhaveAccess = $canIhaveAccess + checklevel('god'); if (!$canIhaveAccess == 1) { die('You are not authorized to override.'); } } $MyArray = array(); $Feed_Links = $RSSImport->get_feed_field_links($feed->feed_id); if (count($Feed_Links) > 0) { foreach ($Feed_Links as $link) { if ($link->pligg_field == 'link_title') { $MyArray['title'] = $link->feed_field; } if ($link->pligg_field == 'link_content') { $MyArray['content'] = $link->feed_field; } if ($link->pligg_field == 'link_url') { $MyArray['link_url'] = $link->feed_field; } if ($link->pligg_field == 'link_tags') { $MyArray['link_tags'] = $link->feed_field; } if ($link->pligg_field == 'link_field1') { $MyArray['link_field1'] = $link->feed_field; } if ($link->pligg_field == 'link_field2') { $MyArray['link_field2'] = $link->feed_field; } if ($link->pligg_field == 'link_field3') { $MyArray['link_field3'] = $link->feed_field; } if ($link->pligg_field == 'link_field4') { $MyArray['link_field4'] = $link->feed_field; } if ($link->pligg_field == 'link_field5') { $MyArray['link_field5'] = $link->feed_field; } if ($link->pligg_field == 'link_field6') { $MyArray['link_field6'] = $link->feed_field; } if ($link->pligg_field == 'link_field7') { $MyArray['link_field7'] = $link->feed_field; } if ($link->pligg_field == 'link_field8') { $MyArray['link_field8'] = $link->feed_field; } if ($link->pligg_field == 'link_field9') { $MyArray['link_field9'] = $link->feed_field; } if ($link->pligg_field == 'link_field10') { $MyArray['link_field10'] = $link->feed_field; } if ($link->pligg_field == 'link_field11') { $MyArray['link_field11'] = $link->feed_field; } if ($link->pligg_field == 'link_field12') { $MyArray['link_field12'] = $link->feed_field; } if ($link->pligg_field == 'link_field13') { $MyArray['link_field13'] = $link->feed_field; } if ($link->pligg_field == 'link_field14') { $MyArray['link_field14'] = $link->feed_field; } if ($link->pligg_field == 'link_field15') { $MyArray['link_field15'] = $link->feed_field; } } $thecount = 0; if ($feed->feed_last_item_first == 0) { $the_items = array_reverse($rss->items); } else { $the_items = $rss->items; } foreach ($the_items as $item) { echo "<strong>Title: " . get_val($item, $MyArray['title']) . "</strong><br/>"; echo "<strong>Content:</strong> " . strip_tags(substr(get_val($item, $MyArray['content']), 0, 256)) . "...<br>"; echo "<strong>URL:</strong> " . get_val($item, $MyArray['link_url']) . "<br/>"; $skipthis = 0; $linkres = new Link(); $linkres->randkey = rand(10000, 10000000); $linkres->status = $feed->feed_status; $linkres->author = $feed->feed_submitter; $linkres->title = get_val($item, $MyArray['title']); $linkres->title = strip_tags($linkres->title); $linkres->tags = get_val($item, $MyArray['link_tags']); // MJE: MOD to include title words as tags ---------------------------- if (trim($linkres->tags) == '') { $temp1 = strtolower($linkres->title); $stopwords = file(mnmpath . '/modules/rss_import/templates/stopwords.txt'); for ($zz = 0; $zz < count($stopwords); $zz++) { $pos = strpos($temp1, $stopwords[$zz] . ' '); if ($pos !== false && $pos == 0) { $temp1 = str_replace(trim($stopwords[$zz]) . ' ', ' ', $temp1); } $temp1 = str_replace(' ' . trim($stopwords[$zz]) . ' ', ' ', $temp1); } $pos = strpos($temp1, ' '); while ($pos !== false) { $temp1 = str_replace(' ', ' ', $temp1); $pos = strpos($temp1, ' '); } $temp1 = str_replace(' ', ", ", $temp1); // $out = ereg_replace("[^[:alpha:]]", "", $in); // strip all except letters and spaces and commas $linkres->tags = preg_replace('/[^a-z A-Z,]+/i', '', $temp1); } //---------------------------------------------------------------------- if (checklevel('god')) { $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_God; } elseif (checklevel('admin')) { $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_Admin; } else { $Story_Content_Tags_To_Allow = Story_Content_Tags_To_Allow_Normal; } $linkres->title_url = makeUrlFriendly($linkres->title); $linkres->url = get_val($item, $MyArray['link_url']); $linkres->url_title = $linkres->title; $linkres->content = get_val($item, $MyArray['content']); $linkres->content = strip_tags($linkres->content, $Story_Content_Tags_To_Allow); $linkres->content = str_replace("\n", "<br />", $linkres->content); $linkres->link_field1 = get_val($item, $MyArray['link_field1']); $linkres->link_field2 = get_val($item, $MyArray['link_field2']); $linkres->link_field3 = get_val($item, $MyArray['link_field3']); $linkres->link_field4 = get_val($item, $MyArray['link_field4']); $linkres->link_field5 = get_val($item, $MyArray['link_field5']); $linkres->link_field6 = get_val($item, $MyArray['link_field6']); $linkres->link_field7 = get_val($item, $MyArray['link_field7']); $linkres->link_field8 = get_val($item, $MyArray['link_field8']); $linkres->link_field9 = get_val($item, $MyArray['link_field9']); $linkres->link_field10 = get_val($item, $MyArray['link_field10']); $linkres->link_field11 = get_val($item, $MyArray['link_field11']); $linkres->link_field12 = get_val($item, $MyArray['link_field12']); $linkres->link_field13 = get_val($item, $MyArray['link_field13']); $linkres->link_field14 = get_val($item, $MyArray['link_field14']); $linkres->link_field15 = get_val($item, $MyArray['link_field15']); $linkres->category = $feed->feed_category; //MJE: MOD $linkres->link_summary = utf8_substr(strip_tags($linkres->content), 0, StorySummary_ContentTruncate - 1); //--------- if ($thecount >= $feed->feed_item_limit && $skipthis == 0) { echo "Reached import limit, skipping<HR>"; $skipthis = 1; } if ($feed->feed_title_dupe == 0 && $skipthis == 0) { // 0 means don't allow, 1 means allow if ($linkres->duplicates_title($linkres->title) > 0) { //echo "Title Match, skipping: " . $linkres->title . "<HR>"; echo '<span style="color:#fc0000;">Title Match, skipping</span> <hr>'; $skipthis = 1; } } if ($feed->feed_url_dupe == 0 && $linkres->url != "" && $skipthis == 0) { // 0 means don't allow, 1 means allow if ($linkres->duplicates($linkres->url) > 0) { //echo "URL Match, skipping: " . $linkres->title . "<HR>"; echo '<span style="color:#fc0000;">URL Match, skipping</span> <hr>'; $skipthis = 1; } } if ($skipthis == 0) { echo "Importing <hr>"; $added_one = true; $linkres->store(); totals_adjust_count($linkres->status, 1); tags_insert_string($linkres->id, $dblang, $linkres->tags); require_once mnminclude . 'votes.php'; if ($feed->feed_random_vote_enable == 1) { $feed->feed_votes = rand($feed->feed_random_vote_min, $feed->feed_random_vote_max); } $votes = 0; for ($i = 1; $i <= $feed->feed_votes; $i++) { $value = 1; $vote = new Vote(); $vote->type = 'links'; $vote->user = 0; $vote->link = $linkres->id; $vote->ip = '0.0.0.' . $i; $vote->value = $value; $vote->insert(); $vote = ""; $votes += $value; // $vote = new Vote; // $vote->type='links'; // $vote->link=$linkres->id; } $linkres->votes = $votes; $linkres->store_basic(); $linkres->check_should_publish(); $thecount = $thecount + 1; } } $sql = "UPDATE `" . table_feeds . "` SET `feed_last_check` = FROM_UNIXTIME(" . (time() - 300) . ") WHERE `feed_id` = {$feed->feed_id};"; //echo $sql; $db->query($sql); } else { echo "Feed not fully setup, skipping <hr>"; } if ($added_one) { return true; } else { return false; } }
header("Location: rss_main.php"); } if ($_REQUEST['action'] == "dropfieldlink") { $RSSImport = new RSSImport(); $RSSImport->FeedLinkId = $_REQUEST['FeedLinkId']; $RSSImport->drop_field_link(); header("Location: rss_main.php"); } if ($_REQUEST['action'] == "addnewfeed") { $RSSImport = new RSSImport(); $RSSImport->FeedName = "New Feed"; $RSSImport->new_feed(); header("Location: rss_main.php"); } if ($_REQUEST['action'] == "dropfeed") { $RSSImport = new RSSImport(); $RSSImport->FeedId = $_REQUEST['feed_id']; $RSSImport->drop_feed(); header("Location: rss_main.php"); } if ($_REQUEST['action'] == "save") { echo $QEIP->save_field(); } } echo $QEIP->ShowOnloadJS(); } // FEED FUNCTIONS function smarty_function_feedsListFeeds($params, &$smarty) { // get a list of feeds in the database and put them into smarty varliable $params['varname'] global $db;