$line) {
$file_info['lines']++;
$name=str_replace("&", "%26", $line);//urlencode($line);
if ($num==0) {
$query .= $name;
$num++;
} elseif ($num<$max_wikimedia_api_query) {
$query .= '|' . $name;
$num++;
} else {
$new_file .= $line; //Add content to temp array
$file_info['left']++;
}
}
$file_info['sent']=$num;
if ($new_file === "") {
unlink("upload/" . $file_name);
} else {
$query_again = $file_name;
file_put_contents("upload/".$file_name, $new_file);
}
$url = 'http://commons.wikimedia.org/w/api.php?action=query&format=xml&titles=' . $query . '&prop=imageinfo&iiprop=url&iiurlwidth=320&iiurlheight=320';
}
}
//$url='ttest.xml';
//echo $url . "
\n";
if (isset($url)) {
$xml = simplexml_load_file($url);
//print_r($xml);
$categories = explode(",",$_POST['categories']);
$max=0;
$sql = "SELECT MAX(id) AS max FROM rating_categories";
if (!$result=mysql_query($sql,$db_connection)){}
if($row = mysql_fetch_array($result)){
$max=$row['max'];
}
foreach ($categories as &$the_category) {
if ($the_category>$max){$the_category=0;}
}
unset($the_category);
$query_info=array();
$query_info['pages']=0;
$query_info['added']=0;
$query_info['db error1']=0;
$query_info['db error2']=0;
$query_info['in db']=0;
$query_info['missing']=0;
$query_info['no links']=0;
$query_info['not found']=0;
$query_content=array();
$query_content['added']="";
$query_content['missing']="";
$query_content['db_error1']="";
$query_content['db_error2']="";
$query_content['in_db']="";
$query_content['no_links']="";
$query_content['not_found']="";
$pages = $xml->query->pages->page;
foreach ($pages as $page) {
$query_info['pages']++;
if (isset($page['missing'])) {
$query_info['missing']++;
$query_content['missing'] .= $page['title'] . "\n";
//echo "Missing: " . $page['title'] . "
\n";
} elseif ($page['ns']=="6") {
$name = $page['title'];
$name1 = mysql_real_escape_string(substr($name, 5));
$sql = "SELECT * FROM rating_images WHERE `name`='$name1'";
if (!$result=mysql_query($sql,$db_connection)) {
$query_info['db error1']++;
$query_content['db_error1'] .= $page['title'] . "\n";
//echo "DB Error: " . $page['title'] . "
\n";
} elseif ($row = mysql_fetch_array($result)){
$query_info['in db']++;
$query_content['in_db'] .= $page['title'] . "\n";
//echo "In DB: " . $page['title'] . "
\n";
} else {
$link = $page->imageinfo->ii['thumburl'];
$description=$page->imageinfo->ii['descriptionurl'];
if ($link=="" or $description=="") {
$query_info['no links']++;
$query_content['no_links'] .= $page['title'] . "\n";
//echo "Redirect?: " . $page['title'] . "
\n";
} else {
$sql = "INSERT INTO rating_images (name, link, description, score) VALUES ('$name1','$link','$description',0)";
if (!mysql_query($sql,$db_connection)) {
$query_info['db error2']++;
$query_content['db_error2'] .= $page['title'] . "\n";
//echo "DB Error2: " . $page['title'] . "
\n";
} else {
$query_info['added']++;
$query_content['added'] .= $page['title'] . "\n";
//echo "Success: " . $page['title'] . "
\n";
//ADD CATEGORIES:
$sql = "SELECT * FROM rating_images WHERE `name`='$name1'";
if (!$result=mysql_query($sql,$db_connection)){}
if($row = mysql_fetch_array($result)){
$image_id=$row['id'];
}
foreach ($categories as $the_category) {
if ((int)$the_category) {
$sql = "INSERT INTO rating_imagecategories (`image`, `category`) VALUES ($image_id, ".(int)$the_category.")";
if (!mysql_query($sql,$db_connection)) {}
}
}
}
}
}
} else {
$query_info['not found']++;
$query_content['not_found'] .= $page['title'] . "\n";
//echo "Not found: " . $page['title'] . "
\n";
}
}
foreach ($query_content as $file => $content) {
file_put_contents("logs/".$file.".txt", $content, FILE_APPEND | LOCK_EX);
}
}
//If a file is uploaded
if (isset($_FILES['file'])) {
//print_r($_FILES);
$upload_info=array();
$upload_info['info']="";
$allowedExts = array("txt");//jpg", "jpeg", "gif", "png");
$extension = end(explode(".", $_FILES["file"]["name"]));
if ($_FILES["file"]["type"] != "text/plain") {
//Wrong file type
$upload_info['info'] = "Wrong file type";
} elseif ($_FILES["file"]["size"] > 200000) {
//File to big
$upload_info['info'] = "File to big";
} elseif (!in_array($extension, $allowedExts)) {
//Wrong file ending
$upload_info['info'] = "Wrong file ending: " . $extension . "";
} elseif ($_FILES["file"]["error"] > 0) {
//Error
$upload_info['info'] = "Return Code: " . $_FILES["file"]["error"];
} elseif (file_exists("" . $_FILES["file"]["name"])) {
//File already exists
$upload_info['info'] = $_FILES["file"]["name"] . " already exists";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
$upload_info['info'] = "Stored in: " . "" . $_FILES["file"]["name"];
}
}
//If a file is uploaded
if ($new_category = trim($_POST['new_category'])) {
$new_category1 = mysql_real_escape_string($new_category);
$sql = "INSERT INTO rating_categories (`name`) VALUES ('$new_category1')";
if (!mysql_query($sql,$db_connection)) {}
}
if (isset($file_info)) {
?>
Queried file: ()
|
$content) {
echo "" . $key . ": | " . $content . " |
\n";
}
?>
Query info:
|
$content) {
echo "" . $key . ": | " . $content . " |
\n";
}
?>
Query info:
|
$content) {
echo "" . $key . ": | " . $content . " |
\n";
}
?>
Uploaded files: |
Name: | Size: |
".$file1 . " | " . filesize($file) . " | \n";
}
?>
Categories: |
Name: | Id: |
".$row['name'] . " | " . $row['id'] . " | \n";
}
?>