Commit c05b5a38 authored by Freddy's avatar Freddy Committed by Luke081515

add

parent 73dfc3bf
#!/usr/bin/php
<?php
require './Cygnus/BotCore.php';
require '../BKLLC/Cygnus/BotCore.php';
/** Corrector.php
* Searches for occurences and allows you to correct the manually
* @Author Luke081515
......@@ -8,31 +8,164 @@ require './Cygnus/BotCore.php';
* @Status Alpha
*/
class Corrector extends Core {
private $summary;
private $search;
private $replace;
private $needle;
private $accountname;
public function __construct($Account, $Job, $pUseHTTPS = true) {
$this->initcurl($Account, $Job, $pUseHTTPS);
$this->accountname = $Account;
echo "\n";
$this->defineConditions();
$this->searchPages();
$this->setSummary();
$this->goAllPages();
/*
$this->display();*/
}
/** defineConditions
* Defines the condition for search and replace
*/
private function defineConditions () {}
/**
private function defineConditions () {
$needle = $this->askOperator('What should be replaced? ');
$replace = $this->askOperator('What should be the replacement? ');
$this->needle = $needle;
$this->replace = $replace;
}
/** setSummary
* @return void
*/
private function setSummary() {
if($this->summary == null) {
$answer = strtoupper($this->askOperator('Set Summary to "Replace ' . $this->needle . ' with ' . $this->replace . '"? [Y], [N]'));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
$this->summary = 'Replace ' . $this->needle . ' with ' . $this->replace;
} else {
$newsummary = $this->askOperator('What Summary should I use instead?');
$this->summary = $newsummary;
}
echo 'OK, Summary is now: ' . $this->summary . "\n";
}
}
}
/** search
*
*/
private function search () {}
private function searchPages () {
echo "\n" . 'Searching…' . "\n";
$suche = urlencode('insource:' . $this->needle);
$i = 0;
$Again = true;
$Continue = '0';
while ($Again === true) {
$SearchResult = unserialize($this->httpRequest('action=query&format=php&list=search&srsearch=' . $suche . '&srnamespace=0&srlimit=max&sroffset=' . $Continue . '&srqiprofile=classic&srinfo=totalhits&srprop=', 'PersoenlichkeitenCirrus', 'GET'));
foreach($SearchResult['query']['search'] as $Ergebnis) {
$Seite[$i] = $Ergebnis['title'];
$i++;
}
if (isset($SearchResult['continue']['sroffset']) === true) {
$Continue = $SearchResult['continue']['sroffset'];
} else {
$Again = false;
}
}
echo 'Found ' . count($Seite) . ' Results.' . "\n";
//print_r($Seite);
$this->search = $Seite;
}
private function goAllPages() {
for($i = 0; $i < count($this->search); $i++) {
echo "\n\n\033[1mTitle:\033[0m " . $this->search[$i] . "\n";
for($j = 0; $j < count(unserialize($this->getLoginName())); $j++) {
if(unserialize($this->getLoginName())[$j] == $this->accountname) {
$loginhost = unserialize($this->getLoginHost())[$j];
}
}
echo 'URL: http://' . $loginhost . '/wiki/' . urlencode($this->search[$i]) . "\n";
$seite = $this->readPage($this->search[$i]);
$this->display($seite, $this->needle, $this->replace);
}
}
private function display () {
$html = "dddasdfdddasdffff";
$needle = "asdf";
$lastPos = 0;
$positions = array();
while (($lastPos = strpos($html, $needle, $lastPos))!== false) {
$positions[] = $lastPos;
$lastPos = $lastPos + strlen($needle);
private function display ($html = '', $needle = '', $new = '') {
$htmlarr = explode("\n", $html);
$red = "\033[0;31m";
$green = "\033[0;32m";
$end = "\033[0m";
for($i = 0; $i < count($htmlarr); $i++) {
$anzahl = substr_count($htmlarr[$i], $needle);
//echo $anzahl;
if($anzahl > 0) {
// cut off long lines
if(stripos($htmlarr[$i], $needle) > 70) {
$htmlarr[$i] = substr($htmlarr[$i], stripos($htmlarr[$i], $needle) - 50);
}
if(strripos($htmlarr[$i], $needle) + strlen($needle) + 70 < strlen($htmlarr[$i])) {
$htmlarr[$i] = substr($htmlarr[$i], 0, strripos($htmlarr[$i], $needle) + strlen($needle) + 50);
}
$old = str_replace($needle, $red . $needle . $end, $htmlarr[$i]);
$newstr = str_replace($needle, $new, $htmlarr[$i]);
$newstr = str_replace($new, $green . $new . $end, $newstr);
echo 'Zeile ' . ($i + 1) . ":\n– " . $old . "\n+ " . $newstr . "\n\n";
}
}
$answer = strtoupper($this->askOperator('Replace all occurrences? [Y], [N] '));
if($this->validateAnswer($answer)) {
if($answer == 'Y') {
$newhtml = $this->replace($html, $needle, $new);
// ToDo: Add Save Page
// Do replace
} else {
echo "\n" . 'Not replaced. Skipping…' . "\n";
// Leave it as it is
}
}
}
/** replace
* Replaces a string
* @param String $html – Full string
* @param String $needle – What to replace
* @param String $replace – Replacement
* @return String replaced String
*/
private function replace($html, $needle, $replace) {
return str_replace($needle, $replace, $html);
}
/** validateAnswer
* validates if the answer is Y or N
* @param String $answer – String of answer
* @return boolean true if string equals 'Y' or 'N'
*/
private function validateAnswer($answer) {
if($answer == 'Y' || $answer == 'N') {
return true;
} else {
$this->validateAnswer(strtoupper($this->askOperator('Please answer [Y], [N]')));
}
}
private function repalce () {}
}
$Bot = new Corrector ('Luke081515@dewiki', 'Corrector');
new Corrector ('BKLLC@dewiki', 'Corrector');
?>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment