Файл: public_html/admin/cron.php
Строк: 99
<?php
include 'config.php';
$db_hostname="localhost";
$db_username="";
$db_password="";
$db_databasename = '';
mysql_connect($db_hostname, $db_username, $db_password) or die(mysql_error());
mysql_select_db($db_databasename) or die(mysql_error());
function bm_extract_string($start, $end, $original) {
    $original1 = stripos($original, $start);
    $trimmed = stripos($original, $end);
    return substr($original, $original1+strlen($start), $trimmed-$original1-strlen($start));
}
$resultrss = mysql_query("SELECT * FROM feeds"); 
while($rowfeeds = mysql_fetch_array( $resultrss )) {
$feed = $rowfeeds["link"];
$feedid = $rowfeeds["id"];
$feedtitle = $rowfeeds["title"];
$category = $rowfeeds["category"];
$feed_url = $feed;
//    echo "Starting to work with feed URL '" . $feed_url . "'";
    $RSS_DOC = simpleXML_load_file($feed_url);
    $rss_title = $RSS_DOC->channel->title;
    $rss_link = $RSS_DOC->channel->link;
    $rss_editor = $RSS_DOC->channel->managingEditor;
    $rss_copyright = $RSS_DOC->channel->copyright;
    $rss_date = $RSS_DOC->channel->pubDate;
    foreach($RSS_DOC->channel->item as $RSSitem)
    {
        $item_id     = md5($RSSitem->title);
        $fetch_date = date("Y-m-j G:i:s"); 
        $item_title = $RSSitem->title;
        $item_content = $RSSitem->description;
        
$searchit = array(
    '“', // 1. Left Double Quotation Mark “
    '”', // 2. Right Double Quotation Mark ”
    '‘', // 3. Left Single Quotation Mark ‘
    '’', // 4. Right Single Quotation Mark ’
    ''',  // 5. Normal Single Quotation Mark '
    '&',   // 6. Ampersand &
    '"',  // 7. Normal Double Qoute
    '<',    // 8. Less Than <
    '>',    // 9. Greater Than >
    '’',     // 10. Crappy apostrphe
    "'"     // 10. Crappy apostrphe
    
);
$replaceit = array(
    '"', // 1
    '"', // 2
    "'", // 3
    "'", // 4
    "'", // 5
    "'", // 6
    '"', // 7
    "<", // 8
    ">",  // 9
    "'",  // 10
    "'" //11
);
$fixed_string = htmlspecialchars($item_content, ENT_QUOTES);
$fixed_string = str_replace($searchit, $replaceit, $fixed_string);        
$fixed_string2 = htmlspecialchars($item_title, ENT_QUOTES);
$fixed_string2 = str_replace($searchit, $replaceit, $fixed_string2);
$item_title2 = mysql_real_escape_string($fixed_string2);
$item_title2 = str_replace(" ","-",$item_title2);
$item_title2 = str_replace(".com","",$item_title2);
$item_title2 = str_replace(".net","",$item_title2);
$item_title2 = str_replace(".org","",$item_title2);
$item_title2 = str_replace(".co.uk","",$item_title2);
$item_title2 = str_replace(".","",$item_title2);
$item_title2 = str_replace(",","",$item_title2);
$item_title2 = str_replace("/","",$item_title2);
$item_title2 = str_replace("?","",$item_title2);
$item_content2 = mysql_real_escape_string($fixed_string);
        
    //    $item_date  = date("Y-m-j", strtotime($RSSitem->pubDate));
        $item_date = date('Y-m-d H:i:s', strtotime($RSSitem->pubDate));
    //    $item_date = $RSSitem->pubDate;
        $iso8601 = date('c', strtotime($RSSitem->pubDate));
        $item_url    = $RSSitem->link;
    if (preg_match_all('/<img[^>]+>/i',$item_content, $matches)) {
    if (strpos($item_content,'height="1"') !== false) {
    $aticleimage = '';
    $item_status = '1';
} else if (strpos($item_content,'height="1px"') !== false) {
    $aticleimage = '';
    $item_status = '1';
} else {
    $aticleimage = $matches[0][0];
    $item_status = '1';
    }
    } else {
    $aticleimage = '';
    $item_status = '1';
    }
        
//        echo "Processing item '" , $item_id , "' on " , $fetch_date     , "<br/>";
//        echo $item_title, " - ";
//        echo $item_date, "<br/>";
//        echo $item_url, "<br/>";
        
$querytitleexists = mysql_query("SELECT * FROM rssarticles WHERE item_title='$item_title'");
$querytitleexistsurl = mysql_query("SELECT * FROM rssarticles WHERE item_url='$item_url'");
$item_exists = mysql_query("SELECT * FROM rssarticles where item_id = '$item_id'");
    
        
        if(mysql_num_rows($item_exists) == 0)
        {
//        echo "<font color=green>Inserting new item..</font><br/>";
        mysql_query("INSERT INTO rssarticles (item_id, feed_url, item_content, item_title, item_date, item_url, item_image, item_status, item_category_id) VALUES('$item_id', '$feed_url', '$item_content2','$item_title2', '$iso8601', '$item_url', '$aticleimage', '$item_status', '$category')");
        
        }
        else
        {
    //        echo "<font color=blue>Article Already Exists</font><br/>";
        }
    //    echo "<br/>";
    }
// echo 'FINISHED - Waiting for next item...';
$newdate = date("c");
mysql_query("UPDATE feeds set lastupdate='$newdate' WHERE id='$feedid'");
}
?>