Index: trunk/tools/rotatebot/upload.php |
— | — | @@ -18,6 +18,8 @@ |
19 | 19 | |
20 | 20 | wikiupload("commons.wikimedia.org","test2.jpg","Test for Rotatebot.jpg","",$descri);*/ |
21 | 21 | |
| 22 | +$homedir = "/home/luxo/rotbot/"; |
| 23 | + |
22 | 24 | // ############### EDIT WIKIPEDIA - FUNCTION ############### |
23 | 25 | function wikiupload($project,$filename_local,$filename_wiki,$license,$desc) |
24 | 26 | { |
— | — | @@ -70,7 +72,8 @@ |
71 | 73 | |
72 | 74 | function wiki_upload_file ($filename_local,$filename_wiki,$license,$desc,$wiki,$cookies) |
73 | 75 | { |
74 | | - $file1 = file_get_contents("/home/luxo/rotbot/cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)"); |
| 76 | + global $homedir; |
| 77 | + $file1 = file_get_contents($homedir . "cache/".$filename_local) or die("Fehler - Datei nicht gefunden! ($filename_local)"); |
75 | 78 | |
76 | 79 | $data_l = array("file.file" => $file1, |
77 | 80 | "wpDestFile" => $filename_wiki, |
— | — | @@ -142,6 +145,7 @@ |
143 | 146 | $res .= fread($fp, 1); |
144 | 147 | } |
145 | 148 | fclose($fp); |
146 | | - file_put_contents("/home/luxo/rotbot/cache/log.txt",$res); |
| 149 | + global $homedir; |
| 150 | + file_put_contents( $homedir . "cache/log.txt",$res); |
147 | 151 | return $res; |
148 | 152 | } |
Index: trunk/tools/rotatebot/login.php |
— | — | @@ -18,6 +18,7 @@ |
19 | 19 | |
20 | 20 | */ |
21 | 21 | |
| 22 | +$cookies = "/home/lux/cks"; |
22 | 23 | |
23 | 24 | // ############### EDIT WIKIPEDIA - FUNCTION ############### |
24 | 25 | function wikiedit($project,$page,$newtext,$description,$minor) |
— | — | @@ -252,13 +253,14 @@ |
253 | 254 | |
254 | 255 | $postlogin = "lgname=".urlencode($username)."&lgpassword=".urlencode($password)."&format=php"; |
255 | 256 | |
| 257 | + global $cookies; |
256 | 258 | if(!$useragent) { $useragent = "Luxo (Toolserver; php) luxo@ts.wikimedia.org"; } |
257 | 259 | $ch = curl_init($project.$getrequest); |
258 | 260 | curl_setopt($ch, CURLOPT_POST, TRUE); |
259 | 261 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
260 | 262 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
261 | 263 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
262 | | - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
| 264 | + curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); |
263 | 265 | |
264 | 266 | $rx = curl_exec($ch); |
265 | 267 | |
— | — | @@ -274,8 +276,8 @@ |
275 | 277 | curl_setopt($ch, CURLOPT_POSTFIELDS, $postlogin); |
276 | 278 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
277 | 279 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
278 | | - curl_setopt($ch, CURLOPT_COOKIEFILE, "/home/luxo/cks"); |
279 | | - curl_setopt($ch, CURLOPT_COOKIEJAR, "/home/luxo/cks"); |
| 280 | + curl_setopt($ch, CURLOPT_COOKIEFILE, $cookies); |
| 281 | + curl_setopt($ch, CURLOPT_COOKIEJAR, $cookies); |
280 | 282 | $ry = curl_exec($ch); |
281 | 283 | $data = unserialize($ry); |
282 | 284 | |
Index: trunk/tools/rotatebot/rotbot.php |
— | — | @@ -16,6 +16,7 @@ |
17 | 17 | */ |
18 | 18 | |
19 | 19 | $homedir = "/home/luxo/rotbot/"; |
| 20 | +$exiftool = "/home/luxor/rotbot/exiftool/exiftool"; |
20 | 21 | $myLockfile = $homedir."rotatebotlock"; |
21 | 22 | |
22 | 23 | ini_set('memory_limit', '100M'); //Speicher auf 100 MBytes hochsetzen |
— | — | @@ -208,7 +209,6 @@ |
209 | 210 | } |
210 | 211 | } |
211 | 212 | |
212 | | - |
213 | 213 | //Benutzer prüfen! ######################################### |
214 | 214 | if($catcontent[$arraykey]['tmplsetter']) //autoconfirmed |
215 | 215 | { |
— | — | @@ -295,29 +295,29 @@ |
296 | 296 | } |
297 | 297 | |
298 | 298 | |
299 | | - if(!$wrongfile) //Bild scheint OK zu sein |
300 | | - { |
301 | | - logfile("picture and user check finished, sorted for download"); |
| 299 | +if(!$wrongfile) //Bild scheint OK zu sein |
| 300 | +{ |
| 301 | + logfile("picture and user check finished, sorted for download"); |
302 | 302 | |
303 | | - $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]); |
304 | | - $catcontent[$arraykey]['degree'] = $picture["sortkey"]; |
305 | | - $catcontent[$arraykey]['since'] = $revitimestp; |
306 | | - $catcontent[$arraykey]['pageid'] = $picture['pageid']; |
307 | | - $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url']; |
308 | | - $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata']; |
309 | | - $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user']; |
310 | | - $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp']; |
311 | | - $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height']; |
312 | | - $catcontent[$arraykey]['exifkey'] = 0; |
313 | | - $catcontent[$arraykey]['exifkeyafter'] = 0; |
314 | | - $catcontent[$arraykey]['exifwriteerr'] = ""; |
315 | | - $arraykey = $arraykey +1; |
316 | | - } |
317 | | - else |
318 | | - { |
319 | | - //array löschen! |
320 | | - $papierkorb = array_splice($catcontent,$arraykey,1); |
321 | | - } |
| 303 | + $catcontent[$arraykey]['title'] = str_replace(" ", "_", $picture["title"]); |
| 304 | + $catcontent[$arraykey]['degree'] = $picture["sortkey"]; |
| 305 | + $catcontent[$arraykey]['since'] = $revitimestp; |
| 306 | + $catcontent[$arraykey]['pageid'] = $picture['pageid']; |
| 307 | + $catcontent[$arraykey]['url'] = $picture['imageinfo']['0']['url']; |
| 308 | + $catcontent[$arraykey]['metadata'] = $picture['imageinfo']['0']['metadata']; |
| 309 | + $catcontent[$arraykey]['uploader'] = $picture['imageinfo']['0']['user']; |
| 310 | + $catcontent[$arraykey]['upltime'] = $picture['imageinfo']['0']['timestamp']; |
| 311 | + $catcontent[$arraykey]['size'] = $picture['imageinfo']['0']['width']."x".$picture['imageinfo']['0']['height']; |
| 312 | + $catcontent[$arraykey]['exifkey'] = 0; |
| 313 | + $catcontent[$arraykey]['exifkeyafter'] = 0; |
| 314 | + $catcontent[$arraykey]['exifwriteerr'] = ""; |
| 315 | + $arraykey = $arraykey +1; |
| 316 | +} |
| 317 | +else |
| 318 | +{ |
| 319 | + //array löschen! |
| 320 | + $papierkorb = array_splice($catcontent,$arraykey,1); |
| 321 | +} |
322 | 322 | |
323 | 323 | } |
324 | 324 | |
— | — | @@ -363,7 +363,7 @@ |
364 | 364 | { |
365 | 365 | //Exif auslesen |
366 | 366 | // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
367 | | - $exif = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype'].""); |
| 367 | + $exif = system($exiftool . " -IFD0:Orientation -b -a ".$savepath.$filename.".".$arraycontent['filetype'].""); |
368 | 368 | settype($exif, "integer"); |
369 | 369 | logfile("EXIF ist auf $exif"); |
370 | 370 | $arraycontent['exifkey'] = $exif; //for editsummary |
— | — | @@ -421,118 +421,118 @@ |
422 | 422 | logfile("Bild muss um $realrotate Grad gedreht werden."); |
423 | 423 | $realrotate = (360 + ($realrotate % 360)) % 360; // convert to 0-259 |
424 | 424 | $arraycontent['realdegree'] = $realrotate; // for editsummary |
425 | | - } |
426 | | - switch($realrotate) |
427 | | - { |
428 | | - case 0: |
429 | | - //kopie erstellen |
430 | | - logfile("just exif correction, picture correct"); |
431 | | - $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype']; |
432 | | - logfile($cmd); |
433 | | - passthru($cmd); |
434 | | - break; |
435 | | - case 90: |
436 | | - case 180: |
437 | | - case 270: |
438 | | - //rotieren ... |
439 | | - $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype']; |
440 | | - logfile($cmd); |
441 | | - passthru($cmd,$return); |
442 | | - logfile($arraycontent['title']." rotated by ".$realrotate."°."); |
443 | | - break; |
| 425 | + } |
| 426 | + switch($realrotate) |
| 427 | + { |
| 428 | + case 0: |
| 429 | + //kopie erstellen |
| 430 | + logfile("just exif correction, picture correct"); |
| 431 | + $cmd = "cp ".$savepath.$filename.".".$arraycontent['filetype']." ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 432 | + logfile($cmd); |
| 433 | + passthru($cmd); |
| 434 | + break; |
| 435 | + case 90: |
| 436 | + case 180: |
| 437 | + case 270: |
| 438 | + //rotieren ... |
| 439 | + $cmd = "jpegtran -rotate ".$realrotate." -trim -copy all ".$savepath.$filename.".".$arraycontent['filetype']." > ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 440 | + logfile($cmd); |
| 441 | + passthru($cmd,$return); |
| 442 | + logfile($arraycontent['title']." rotated by ".$realrotate."°."); |
| 443 | + break; |
444 | 444 | |
445 | | - default: |
446 | | - logfile("Bullshit happend: realrotate was $realrotate."); |
447 | | - $return=1004; |
448 | | - } |
| 445 | + default: |
| 446 | + logfile("Bullshit happend: realrotate was $realrotate."); |
| 447 | + $return=1004; |
| 448 | + } |
449 | 449 | |
450 | | - //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet |
| 450 | + //escape shell nicht notwendig, keine Benutzerdaten im cmd verwendet |
451 | 451 | |
452 | | - $doBruteForceClean = false; // init |
| 452 | + $doBruteForceClean = false; // init |
453 | 453 | |
454 | 454 | if ($return == 0 && !($exif == 0 || $exif == 1)) { // only if no error occured and change necessary |
455 | | - //EXIF-orient-tag auf 1 stellen, nur bei jpeg |
456 | | - // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg |
457 | | - if ($exif >= 10) { //dupe Orientation tags? Kill 'em all! |
458 | | - // Needs to be removed because otherwise the duplicate tag stays |
459 | | - // first attempt |
460 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
461 | | - logfile($cmd); |
462 | | - passthru($cmd,$retexifwrite); |
463 | | - |
464 | | - if ($retexifwrite == 0) { // if successful |
465 | | - logfile("No errors on EXIF-to-0"); |
466 | | - $exifwriteerr = ""; // clear - no error since it worked in first attempt |
467 | | - } else { |
468 | | - // second attempt (ignoring minor errors) |
469 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 455 | + //EXIF-orient-tag auf 1 stellen, nur bei jpeg |
| 456 | + // /home/luxo/rotbot/exiftool/exiftool -Orientation=1 -n 1.jpg |
| 457 | + if ($exif >= 10) { //dupe Orientation tags? Kill 'em all! |
| 458 | + // Needs to be removed because otherwise the duplicate tag stays |
| 459 | + // first attempt |
| 460 | + $cmd = $exiftool . " -IFD0:Orientation= -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
470 | 461 | logfile($cmd); |
471 | 462 | passthru($cmd,$retexifwrite); |
472 | 463 | |
473 | 464 | if ($retexifwrite == 0) { // if successful |
474 | | - logfile("No errors on EXIF-to-0 (second try)"); |
475 | | - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 465 | + logfile("No errors on EXIF-to-0"); |
| 466 | + $exifwriteerr = ""; // clear - no error since it worked in first attempt |
476 | 467 | } else { |
477 | | - $doBruteForceClean = true; |
| 468 | + // second attempt (ignoring minor errors) |
| 469 | + $cmd = $exiftool . " -IFD0:Orientation= -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 470 | + logfile($cmd); |
| 471 | + passthru($cmd,$retexifwrite); |
| 472 | + |
| 473 | + if ($retexifwrite == 0) { // if successful |
| 474 | + logfile("No errors on EXIF-to-0 (second try)"); |
| 475 | + $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 476 | + } else { |
| 477 | + $doBruteForceClean = true; |
| 478 | + } |
478 | 479 | } |
479 | | - } |
480 | | - } else { |
481 | | - // first attempt |
482 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
483 | | - logfile($cmd); |
484 | | - passthru($cmd,$retexifwrite); |
485 | | - |
486 | | - if ($retexifwrite == 0) { // if successful |
487 | | - logfile("no errors when setting EXIF to 1"); |
488 | | - $exifwriteerr = ""; // clear - no error since it worked in first attempt |
489 | 480 | } else { |
490 | | - // second attempt (ignoring minor errors) |
491 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 481 | + // first attempt |
| 482 | + $cmd = $exiftool . " -IFD0:Orientation=1 -n ".$savepath.$filename."_2.".$arraycontent['filetype']; |
492 | 483 | logfile($cmd); |
493 | 484 | passthru($cmd,$retexifwrite); |
494 | 485 | |
495 | 486 | if ($retexifwrite == 0) { // if successful |
496 | | - logfile("no errors when setting EXIF to 1 (second try)"); |
497 | | - $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 487 | + logfile("no errors when setting EXIF to 1"); |
| 488 | + $exifwriteerr = ""; // clear - no error since it worked in first attempt |
498 | 489 | } else { |
499 | | - $doBruteForceClean = true; |
| 490 | + // second attempt (ignoring minor errors) |
| 491 | + $cmd = $exiftool . " -IFD0:Orientation=1 -n -m ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 492 | + logfile($cmd); |
| 493 | + passthru($cmd,$retexifwrite); |
| 494 | + |
| 495 | + if ($retexifwrite == 0) { // if successful |
| 496 | + logfile("no errors when setting EXIF to 1 (second try)"); |
| 497 | + $exifwriteerr = " - EXIF had minor errors. Some EXIF could be lost. - "; |
| 498 | + } else { |
| 499 | + $doBruteForceClean = true; |
| 500 | + } |
500 | 501 | } |
501 | 502 | } |
502 | | - } |
503 | 503 | |
504 | 504 | |
505 | | - if ($doBruteForceClean) { |
506 | | - // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away |
507 | | - $cmd = "/home/luxo/rotbot/exiftool/exiftool -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype']; |
508 | | - logfile($cmd); |
509 | | - passthru($cmd,$retexifwrite); |
| 505 | + if ($doBruteForceClean) { |
| 506 | + // third attempt (ignoring nearly all errors) - copy all readable tags but leave the Orientation tag away |
| 507 | + $cmd = $exiftool . " -all= -tagsfromfile @ -all:all --IFD0:Orientation ".$savepath.$filename."_2.".$arraycontent['filetype']; |
| 508 | + logfile($cmd); |
| 509 | + passthru($cmd,$retexifwrite); |
510 | 510 | |
511 | | - if ($retexifwrite == 0) { // if successful |
512 | | - logfile("no errors when setting EXIF to 0 (third try)"); |
513 | | - $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - "; |
514 | | - } else { |
515 | | - // complete failure |
516 | | - $return = 1005; |
| 511 | + if ($retexifwrite == 0) { // if successful |
| 512 | + logfile("no errors when setting EXIF to 0 (third try)"); |
| 513 | + $exifwriteerr = " - EXIF had major errors. Great parts of EXIF could be lost. - "; |
| 514 | + } else { |
| 515 | + // complete failure |
| 516 | + $return = 1005; |
| 517 | + } |
517 | 518 | } |
518 | | - } |
519 | 519 | |
520 | 520 | |
521 | | - $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary |
| 521 | + $arraycontent['exifwriteerr'] = $exifwriteerr; //for editsummary |
522 | 522 | } |
523 | 523 | |
524 | 524 | if ($return == 0) { // only if no error occured |
525 | | - //Exif auslesen als Test |
526 | | - // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
527 | | - $exifafter = system("/home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype'].""); |
528 | | - settype($exifafter, "integer"); |
529 | | - logfile("read EXIF after finish: $exifafter"); |
530 | | - $arraycontent['exifkeyafter'] = $exifafter; //for editsummary |
| 525 | + //Exif auslesen als Test |
| 526 | + // /home/luxo/rotbot/exiftool/exiftool -IFD0:Orientation -b 1.jpg -a is to get dupe tags, too |
| 527 | + $exifafter = system($exiftool . " -IFD0:Orientation -b -a ".$savepath.$filename."_2.".$arraycontent['filetype'].""); |
| 528 | + settype($exifafter, "integer"); |
| 529 | + logfile("read EXIF after finish: $exifafter"); |
| 530 | + $arraycontent['exifkeyafter'] = $exifafter; //for editsummary |
531 | 531 | |
532 | | - if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful |
533 | | - $return = 1006; |
| 532 | + if (!($exifafter == 0 || $exifafter == 1)) { // if unsuccessful |
| 533 | + $return = 1006; |
| 534 | + } |
534 | 535 | } |
535 | 536 | } |
536 | | - } |
537 | 537 | } |
538 | 538 | else //Für png's und gif's |
539 | 539 | { |
— | — | @@ -683,9 +683,9 @@ |
684 | 684 | //Cache leeren |
685 | 685 | foreach($catcontent2 as $filename => $arraycontent) |
686 | 686 | { |
687 | | - unlink("/home/luxo/rotbot/cache/".$filename.".".$arraycontent['filetype']); |
688 | | - unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']); |
689 | | - unlink("/home/luxo/rotbot/cache/".$filename."_2.".$arraycontent['filetype']."_original"); |
| 687 | + unlink($homedir . "cache/".$filename.".".$arraycontent['filetype']); |
| 688 | + unlink($homedir . "cache/".$filename."_2.".$arraycontent['filetype']); |
| 689 | + unlink($homedir . "cache/".$filename."_2.".$arraycontent['filetype']."_original"); |
690 | 690 | } |
691 | 691 | logfile("cache cleared. Write log now."); |
692 | 692 | |
— | — | @@ -869,6 +869,7 @@ |
870 | 870 | |
871 | 871 | function deleteold($content,$newab,$maxonlog,$logheader) |
872 | 872 | { |
| 873 | + global $homedir; |
873 | 874 | //$maxonlog = 20; //Maximale Logfileabschnitte hier einstellen |
874 | 875 | |
875 | 876 | $beginnat = 0; |
— | — | @@ -892,9 +893,9 @@ |
893 | 894 | return $content; |
894 | 895 | |
895 | 896 | //COUNTER |
896 | | - $counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
| 897 | + $counter = file_get_contents($homedir . "counter.txt"); |
897 | 898 | $counter = $counter + $newab; |
898 | | - file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
| 899 | + file_put_contents($homedir . "counter.txt",$counter); |
899 | 900 | } |
900 | 901 | else |
901 | 902 | { |
— | — | @@ -920,9 +921,9 @@ |
921 | 922 | $intro = substr($content,0,$abschnittarray['1']); |
922 | 923 | |
923 | 924 | //COUNTER |
924 | | - $counter = file_get_contents("/home/luxo/rotbot/counter.txt"); |
| 925 | + $counter = file_get_contents($homedir . "counter.txt"); |
925 | 926 | $counter = $counter + $newab; |
926 | | - file_put_contents("/home/luxo/rotbot/counter.txt",$counter); |
| 927 | + file_put_contents($homedir . "counter.txt",$counter); |
927 | 928 | logfile("new counter: $counter."); |
928 | 929 | |
929 | 930 | $intro = sprintf($logheader."\n",$abschnitteneu,$counter); //NEU in settings definiert: der header vom Log |