<?php
//error_reporting(E_ALL);
error_reporting(0);
include('versions.php');
include('config/conf.inc.php');
//all required libs
require_once 'libraries/functions.php';
require_once 'libraries/formatting.php';
require_once 'libraries/simple_html_dom/simple_html_dom.php';
require_once 'libraries/readability/Readability.php';
require_once("libraries/JG_Cache.php");
//read and get config file's data.
if (file_exists('config/config.db')) {
$data = file_get_contents('config/config.db');
$data = unserialize( $data );
$site_name = $data['site_name'];
$email_id = $data['email_id'];
$cpalead_meta_tag = $data['cpalead_meta_tag'];
$search_top_ad = $data['search_top_ad'];
$search_bottom_ad = $data['search_bottom_ad'];
$search_right_ad = $data['search_right_ad'];
$content_top_ad = $data['content_top_ad'];
$analytics_code = $data['analytics_code'];
$content_lock_code = $data['content_lock_code'];
}else{
$site_name = '';
$email_id = '';
$cpalead_meta_tag = '';
$search_top_ad = '';
$search_bottom_ad = '';
$search_right_ad = '';
$content_top_ad = '';
$analytics_code = '';
$content_lock_code = $default_content_lock_code;
}
//build trends depends on date
function build_trends($date){
if(stristr($date, '-') === FALSE) {
$url = 'http://www.filestube.com/trends/month.html?date=' . $date;
}
else $url = 'http://www.filestube.com/trends/day.html?date=' . $date;
if( $_SERVER['SERVER_NAME'] == 'localhost.com'){
$url = 'http://mbit.tk/lab/php-download-script/html/trends-day.html';
}
$key = $url;
$cache = new JG_Cache('./store');
$trends = $cache->get($key);
if ($trends === FALSE)
{
//read day, day by date, month, month by date trends - all working
$html = fetch_url($url, 'http://google.com/');
$html = str_get_html($html);
$links = $html->find('div[class=bigtrends3]', 0)->find('a');
foreach ($links as $link) {
$trends[] = $link ->innertext;
}
$cache->set($key, serialize( $trends ));
}
else $trends = unserialize( $trends );
return $trends;
}
//update functions
$update_interval = 3600*24*7;
$version_url = 'http://freephpwebscripts.appspot.com/rapidsharebot_versions.txt';
if (!@file_exists('update_timer'))
{
file_put_contents('update_timer', 'update timer');
update_log('cache/update_log.txt', "Script installed first time at " . date("F j, Y, g:i a") . ".\n");
$update_check = true;
}
if (filemtime('update_timer') < (time() - $update_interval) || isset($_GET['force_update']) || isset($update_check) )
{
// update interval is over. check for versuons.txt and if new version found, update it.
$versions = fetch_url($version_url, $_SERVER['SERVER_NAME']);
if($versions){
$updat_found = false;
$versionList = explode(" ", $versions);
$version_number = $versionList[0];
$zip_url = $versionList[1];
if ( version_compare($version_number, VERSION) == 1 ) {
$updat_found = true;
$zip_file = fetch_url($zip_url, $_SERVER['SERVER_NAME']);
if($zip_file){
file_put_contents('source.zip', $zip_file);
//Zip archive
$zip = new ZipArchive;
if ($zip->open('source.zip') === TRUE) {
$zip->extractTo('./');
$zip->close();
$info = 'Updated successfully at ' . date("F j, Y, g:i a");
if( isset($_GET['force_update'])){
update_log('cache/update_log.txt', $info . " by force updater.\n");
echo $info;
}
else update_log('cache/update_log.txt', $info . " by autoupdater.\n");
touch('update_timer');
unlink('source.zip');
} else {
$info = 'Zip file read error. Update failed at ' . date("F j, Y, g:i a");
if( isset($_GET['force_update'])){
update_log('cache/update_log.txt', $info . " by force updater.\n");
echo $info;
}
else update_log('cache/update_log.txt', $info . " by autoupdater.\n");
}
}
}
if(!$updat_found){
if( isset($_GET['force_update'])){
echo "No update found.";
update_log('cache/update_log.txt', "No update found by force updater at " . date("F j, Y, g:i a") . "\n");
}
}
}
else{//if can't fetch version number.
$info = 'Can\'t fetch version number info and compare version number. Update process termineted at ' . date("F j, Y, g:i a");
if( isset($_GET['force_update'])){
update_log('cache/update_log.txt', $info . " by force updater.\n");
echo $info;
}
else update_log('cache/update_log.txt', $info . " by autoupdater.\n");
}
}
function update_log($path, $data){
$log_file = fopen($path, "a");
$bytes = fwrite($log_file, $data);
fclose($log_file);
}
?>