public function Do_Work($element) { $mt = microtime(true); // Consume some CPU time for ($a = 0; $a < 3000000; $a++) { } if ($element % 20 === 0) { // Be verbose for every multiple of 20 pecho("finished work on element #{$element} in " . number_format(microtime(true) - $mt, 2) . " sec."); } }
/** * Leaves a channel, or the locally stored channel(s) * @param string $chan Channel to part. Default null * @return void */ public function partChan($chan = null) { if (!is_null($chan)) { pecho("Parting {$chan}...\n", PECHO_VERBOSE); fwrite($this->f, 'PART ' . $chan . "\n"); usleep(5000); } else { foreach ($this->chan as $chan) { pecho("Parting {$chan}...\n", PECHO_VERBOSE); fwrite($this->f, 'PART ' . $chan . "\n"); usleep(5000); } } }
/** * Resize an image * * @access public * @param int $width Width of resized image. Default null * @param int $height Height of resized image. Default null. * @param bool $reupload Whether or not to automatically upload the image again. Default false * @param string $text Text to use for the image name * @param string $comment Upload comment. * @param bool $watch Whether or not to watch the image on uploading * @param bool $ignorewarnings Whether or not to ignore upload warnings * @throws DependencyError Relies on GD PHP plugin * @throws BadEntryError * @return boolean|void False on failure */ public function resize($width = null, $height = null, $reupload = false, $text = '', $comment = '', $watch = null, $ignorewarnings = true) { global $pgIP, $pgNotag, $pgTag; try { $this->preEditChecks("Resize"); } catch (EditError $e) { pecho("Error: {$e}\n\n", PECHO_FATAL); return false; } if (!$pgNotag) { $comment .= $pgTag; } if (!function_exists('ImageCreateTrueColor')) { throw new DependencyError("GD", "http://us2.php.net/manual/en/book.image.php"); } echo "1\n"; if (!is_null($width) && !is_null($height)) { $this->download(); $type = substr(strrchr($this->mime, '/'), 1); switch ($type) { case 'jpeg': $image_create_func = 'ImageCreateFromJPEG'; $image_save_func = 'ImageJPEG'; break; case 'png': $image_create_func = 'ImageCreateFromPNG'; $image_save_func = 'ImagePNG'; break; case 'bmp': $image_create_func = 'ImageCreateFromBMP'; $image_save_func = 'ImageBMP'; break; case 'gif': $image_create_func = 'ImageCreateFromGIF'; $image_save_func = 'ImageGIF'; break; case 'vnd.wap.wbmp': $image_create_func = 'ImageCreateFromWBMP'; $image_save_func = 'ImageWBMP'; break; case 'xbm': $image_create_func = 'ImageCreateFromXBM'; $image_save_func = 'ImageXBM'; break; default: $image_create_func = 'ImageCreateFromJPEG'; $image_save_func = 'ImageJPEG'; } echo "2\n"; $image = imagecreatetruecolor($width, $height); echo "3\n"; $new_image = $image_create_func($pgIP . 'Images/' . $this->localname); $info = getimagesize($pgIP . 'Images/' . $this->localname); imagecopyresampled($image, $new_image, 0, 0, 0, 0, $width, $height, $info[0], $info[1]); $image_save_func($image, $pgIP . 'Images/' . $this->localname); } elseif (!is_null($width)) { $this->download(null, $width); } elseif (!is_null($height)) { $this->download(null, $height + 100000, $height); } else { throw new BadEntryError("NoParams", "No parameters given"); } if ($reupload) { return $this->upload(null, $text, $comment, $watch, $ignorewarnings); } }
/** * @param $title * @param string $level * @param null $reason * @param bool|false $autoreview * @param bool|false $watch * @return bool * @throws AssertFailure * @throws BadEntryError * @throws HookError * @throws LoggedOut * @throws MWAPIError */ public function stabilize($title, $level = 'none', $reason = null, $autoreview = false, $watch = false) { if (!in_array('stablesettings', $this->wiki->get_userrights())) { pecho("User is not allowed to change the stabilization settings", PECHO_FATAL); return false; } $tokens = $this->wiki->get_tokens(); if ($tokens['edit'] == '+\\') { pecho("User has logged out.\n\n", PECHO_FATAL); return false; } if (mb_strlen($reason, '8bit') > 255) { pecho("Comment is over 255 bytes, the maximum allowed.\n\n", PECHO_FATAL); return false; } pecho("Stabilizing title...\n\n", PECHO_NOTICE); $editarray = array('action' => 'review', 'title' => $title, 'token' => $tokens['edit'], 'protectlevel' => $level); if ($watch) { $editArray['watch'] = 'yes'; } if (!empty($reason)) { $editArray['reason'] = $reason; } if ($this->wiki->get_maxlag()) { $editarray['maxlag'] = $this->wiki->get_maxlag(); } Hooks::runHook('StartStabilize', array(&$editarray)); $result = $this->wiki->apiQuery($editarray, true); if (isset($result['stabilize'])) { if (isset($result['stabilize']['title'])) { return true; } else { pecho("Stabilization error...\n\n" . print_r($result['stabilize'], true) . "\n\n", PECHO_FATAL); return false; } } else { pecho("Stabilization error...\n\n" . print_r($result, true), PECHO_FATAL); return false; } }
/** * Returns a list of all filters * * @access public * @param int $start Filter ID to start at. Default null * @param int $end Filter ID to end at. Default null * @param string $dir Direction to list. Default newer * @param bool $enabled Only list enabled filters. true => only enabled, false => only disabled, null => all * @param bool $deleted Only list deleted filters. true => only deleted, false => only non-deleted, null => all * @param bool $private Only list private filters. true => only private, false => only non-private, null => all * @param int $limit Number of filters to get. Default null * @param array $prop Properties to retrieve. Default array( 'id', 'description', 'pattern', 'actions', 'hits', 'comments', 'lasteditor', 'lastedittime', 'status', 'private' ) * @return array */ public function abusefilters($start = null, $end = null, $dir = 'newer', $enabled = null, $deleted = false, $private = null, $limit = null, $prop = array('id', 'description', 'pattern', 'actions', 'hits', 'comments', 'lasteditor', 'lastedittime', 'status', 'private')) { $tArray = array('prop' => $prop, '_code' => 'abf', 'abfdir' => $dir, '_limit' => $limit, 'abfshow' => array(), 'list' => 'abusefilters'); if (!is_null($enabled)) { if ($enabled) { $tArray['abfshow'][] = 'enabled'; } else { $tArray['abfshow'][] = '!enabled'; } } if (!is_null($deleted)) { if ($deleted) { $tArray['abfshow'][] = 'deleted'; } else { $tArray['abfshow'][] = '!deleted'; } } if (!is_null($private)) { if ($private) { $tArray['abfshow'][] = 'private'; } else { $tArray['abfshow'][] = '!private'; } } $tArray['abfshow'] = implode('|', $tArray['abfshow']); if (!is_null($start)) { $tArray['abfstartid'] = $start; } if (!is_null($end)) { $tArray['abfendid'] = $end; } pecho("Getting abuse filter list...\n\n", PECHO_NORMAL); return $this->wiki->listHandler($tArray); }
/** * Downloads an URL to the local disk * * @access public * * @param string $url URL to get * @param string $local Local filename to download to * @param array $headers Array of headers to pass to curl * @param bool|null $verifyssl * * @return bool */ function download($url, $local, $headers = array(), $verifyssl = null) { global $argv; $out = fopen($local, 'wb'); $this->setCurlHeaders($headers); $this->setVerifySSL($verifyssl); // curl_setopt($this->curl_instance, CURLOPT_FILE, $out); curl_setopt($this->curl_instance, CURLOPT_HTTPGET, 1); curl_setopt($this->curl_instance, CURLOPT_POST, 0); curl_setopt($this->curl_instance, CURLOPT_URL, $url); curl_setopt($this->curl_instance, CURLOPT_HEADER, 0); if (!is_null($argv) && in_array('peachyecho', $argv) || $this->echo) { pecho("DLOAD: {$url}\n", PECHO_NORMAL); } Hooks::runHook('HTTPDownload', array(&$this, &$url, &$local)); fwrite($out, $this->doCurlExecWithRetrys()); fclose($out); return true; }
/** * Parse style * * @param \DOMAttr $attribute * @param array $styles * @param \DOMNode $parentNode * @return array */ private static function parseStyle($attribute, $styles, $node, $parentNode) { $tagname = $node->nodeName; $properties = array(); if ($parentNode) { if ($parentNode->computedCssStyles) { foreach ($parentNode->computedCssStyles as $k => $v) { if (self::isInheritedStyleAttribute($k)) { $properties[$k] = $v; } } } } $css_file_rules = self::$cssParser->getStylesFromCssRules($node); if ($css_file_rules) { foreach ($css_file_rules as $k => $v) { $properties[$k] = $v; } } $own = explode(';', trim($attribute->value, " \t\n\r\v;")); foreach ($own as $property) { list($k, $v) = explode(':', $property); $k = trim($k); $v = trim($v); if (!$k) { continue; } $properties[$k] = $v; } $node->computedCssStyles = $properties; foreach ($properties as $k => $v) { if ('b' == $tagname || 'strong' == $tagname) { $styles['bold'] = true; } switch ($k) { case 'background-color': $styles["bgColor"] = self::cssColorToWordColor($v); break; case 'page-break-inside': case 'break-inside': $styles["cantSplit"] = 0 === stripos($v, 'avoid'); break; case 'border': case 'border-left': case 'border-right': case 'border-top': case 'border-bottom': list($unused, $pos) = explode('-', $k, 2); $pos = ucfirst($pos); list($b_w, $b_style, $b_c) = preg_split('#\\s+#', $v); if ($pos) { $styles["border{$pos}Size"] = $b_w * 1; $styles["border{$pos}Color"] = self::cssColorToWordColor($b_c); } else { foreach (explode('|', 'Top|Right|Bottom|Left') as $pos) { $styles["border{$pos}Size"] = $b_w * 1; $styles["border{$pos}Color"] = self::cssColorToWordColor($b_c); } } break; case 'color': $styles["color"] = self::cssColorToWordColor($v); break; case 'display': $styles["tblHeader"] = $v == 'table-header-group'; break; case 'float': $styles["align"] = $v; break; case 'font-size': $styles["size"] = self::cssToPoint($v); break; case 'font-family': $styles["name"] = reset(explode(',', $v)); break; case 'font-weight': $styles["bold"] = $v == 'bold' ? true : false; break; case 'font-style': $styles["italic"] = $v == 'italic'; break; case 'height': $styles["exactHeight"] = self::cssToTwips($v); break; case 'list-style-type': $styles["format"] = lcfirst(implode('', array_map('ucfirst', explode('-', $v)))); break; case 'line-height': $styles["lineHeight"] = $v; //(float)$v * 100; break; case 'left': $styles["left"] = self::cssToTwips($v); break; case 'margin-left': case 'margin-right': case 'margin-top': case 'margin-bottom': if ('table' == $tagname) { list($_, $pos) = explode('-', $k); $pos = ucfirst($pos); $styles["cellMargin{$pos}"] = self::cssToTwips($v); } else { if ('p' == $tagname || 'div' == $tagname) { if ('margin-left' == $k) { $styles["indent"] = self::cssToTwips($v) / 720; } if ('margin-top' == $k) { $styles["spaceBefore"] = self::cssToTwips($v); } if ('margin-bottom' == $k) { $styles["spaceAfter"] = self::cssToTwips($v); } } else { if ('li' == $tagname) { if ('margin-left' == $k) { $styles["marginLeft"] = self::cssToTwips($v); } if ('margin-top' == $k) { $styles["spaceBefore"] = self::cssToTwips($v); } if ('margin-bottom' == $k) { $styles["spaceAfter"] = self::cssToTwips($v); } if ('margin-right' == $k) { $styles["marginRight"] = self::cssToTwips($v); } } else { if ('margin-left' == $k) { $styles["marginLeft"] = self::cssToTwips($v); } if ('margin-top' == $k) { $styles["marginTop"] = self::cssToTwips($v); } if ('margin-bottom' == $k) { $styles["marginBottom"] = self::cssToTwips($v); } if ('margin-right' == $k) { $styles["marginRight"] = self::cssToTwips($v); } } } } break; case 'margin': list($top, $right, $bottom, $left) = preg_split('#\\s+#ims', $v); if (null === $left) { if (null === $bottom) { if (null === $right) { $right = $bottom = $left = $top; } else { $bottom = $top; $left = $right; } } else { $left = $right; } } if ('table' == $tagname) { $styles["cellMarginTop"] = self::cssToTwips($top); $styles["cellMarginRight"] = self::cssToTwips($right); $styles["cellMarginBottom"] = self::cssToTwips($bottom); $styles["cellMarginLeft"] = self::cssToTwips($left); } elseif ('p' == $tagname || 'div' == $tagname) { $styles["spaceBefore"] = self::cssToTwips($top); $styles["spaceAfter"] = self::cssToTwips($bottom); $styles["indent"] = self::cssToTwips($left) / 720; } elseif ('li' == $tagname) { $styles["spaceBefore"] = self::cssToTwips($top); $styles["spaceAfter"] = self::cssToTwips($bottom); $styles["left"] = self::cssToTwips($left); $styles["marginRight"] = self::cssToTwips($right); } else { $styles["marginTop"] = self::cssToTwips($top); $styles["marginRight"] = self::cssToTwips($right); $styles["marginBottom"] = self::cssToTwips($bottom); $styles["marginLeft"] = self::cssToTwips($left); } break; case 'page-break-inside': $styles["cantSplit"] = $v == 'avoid'; break; case 'padding-bottom': $styles["spaceAfter"] = self::cssToTwips($v); break; case 'position': if ('img' == $tagname) { $styles["pos"] = $v; $styles["hPos"] = $v; $styles["vPos"] = $v; } break; case 'text-decoration': $styles["underline"] = $v == 'underline'; $styles["strikethrough"] = $v == 'line-through'; break; case 'text-align': if ('justify' == $v) { $v = 'both'; } $styles["align"] = $v; break; case 'text-transform': $styles["allCaps"] = $v == 'uppercase'; $styles["smallCaps"] = $v == 'lowercase'; break; case 'text-indent': if ('li' == $tagname) { $styles["left"] = self::cssToTwips($v); } else { $styles["indent"] = self::cssToTwips($v) / 720; } break; case 'top': $styles["top"] = self::cssToTwips($v); break; case 'vertical-align': if ('middle' == $v) { $v = 'center'; } $styles["valign"] = $v; break; case 'width': if ('table' == $tagname) { if (preg_match('#\\%$#ims', $v)) { $styles["width"] = 100 * 50; $styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_PERCENT; } else { $styles["width"] = self::cssToTwips((double) $v); $styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_TWIP; } } elseif ('td' == $tagname || 'th' == $tagname) { $styles["width"] = self::cssToTwips($v); $styles['unit'] = \PhpOffice\PhpWord\Style\Table::WIDTH_TWIP; } break; case 'wrap': $styles["wrap"] = $v; break; } } if ($tagname == 'li') { pecho("stiluri pentru {$tagname}"); pecho($styles); } return $styles; }
/** * Extract subtitle with track id from mkv file * @param string $file Full path to mkv file * @param int $track_id Track id of the subtitle */ function extract_subtitle_track($file, $track_id) { $subtitle_path = preg_replace("#\\.mkv#ims", '.srt', $file); if (is_file($subtitle_path)) { //unlink($subtitle_path); pecho("Subtitle already exists."); return; } if ($track_id === '' || $track_id === null) { pecho("null track id"); return; } $cmd = 'mkvextract tracks "' . $file . '" ' . $track_id . ':"' . $subtitle_path . '"'; pecho($cmd); exec($cmd, $output, $ret); if ($ret) { pecho("command {$cmd} failed: {$ret} (" . implode("\n", $output) . ")"); return; } }
protected function installPHPseclib() { global $pgIP; $gitZip = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpseclibupdate.zip'; if (file_exists($gitZip)) { unlink($gitZip); } file_put_contents($gitZip, file_get_contents('http://github.com/phpseclib/phpseclib/archive/master.zip')); $zip = new ZipArchive(); $res = $zip->open($gitZip); if ($res === true) { $gitFolder = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'phpseclibupdate'; if (file_exists($gitFolder)) { $this->rrmdir($gitFolder); } mkdir($gitFolder, 02775); $zip->extractTo($gitFolder); $zip->close(); $this->copyOverGitFiles($gitFolder . DIRECTORY_SEPARATOR . 'phpseclib-master' . DIRECTORY_SEPARATOR . 'phpseclib' . DIRECTORY_SEPARATOR); pecho("Successfully installed SSH class\n\n", PECHO_NOTICE); file_put_contents($pgIP . 'Includes' . DIRECTORY_SEPARATOR . 'phpseclibupdate', serialize($this->commits)); } else { pecho("Unable to install SSH class\n\n", PECHO_WARN); } }
/** * List all deleted contributions. * The logged in user must have the 'deletedhistory' right * * @access public * @param bool $content Whether or not to return content of each contribution. Default false * @param string $start Timestamp to start at. Default null. * @param string $end Timestamp to end at. Default null. * @param string $dir Direction to list. Default 'older' * @param array $prop Information to retrieve. Default array( 'revid', 'user', 'parsedcomment', 'minor', 'len', 'content', 'token' ) * @return array */ public function deletedcontribs($content = false, $start = null, $end = null, $dir = 'older', $prop = array('revid', 'user', 'parsedcomment', 'minor', 'len', 'content', 'token')) { if (!in_array('deletedhistory', $this->wiki->get_userrights())) { pecho("User is not allowed to view deleted revisions", PECHO_FATAL); return false; } if ($content) { $prop[] = 'content'; } $drArray = array('_code' => 'dr', 'list' => 'deletedrevs', 'druser' => $this->username, 'drprop' => implode('|', $prop), 'drdir' => $dir); if (!is_null($start)) { $drArray['drstart'] = $start; } if (!is_null($end)) { $drArray['drend'] = $end; } Hooks::runHook('StartDelrevs', array(&$drArray)); pecho("Getting deleted revisions by {$this->username}...\n\n", PECHO_NORMAL); return $this->wiki->listHandler($drArray); }
/** * Updates the Peachy framework * * @access public * @return boolean|null */ public function updatePeachy() { global $pgIP, $pgExperimentalupdates; $gitZip = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'gitUpdate.zip'; if (file_exists($gitZip)) { unlink($gitZip); } file_put_contents($gitZip, file_get_contents('http://github.com/MW-Peachy/Peachy/archive/' . $this->repository . '.zip')); $zip = new ZipArchive(); $res = $zip->open($gitZip); if ($res === true) { $gitFolder = $pgIP . DIRECTORY_SEPARATOR . 'tmp' . DIRECTORY_SEPARATOR . 'gitUpdate'; if (file_exists($gitFolder)) { $this->rrmdir($gitFolder); } mkdir($gitFolder, 02775); $zip->extractTo($gitFolder); $zip->close(); $this->copyOverGitFiles($gitFolder . DIRECTORY_SEPARATOR . 'Peachy-' . $this->repository); file_put_contents($pgIP . 'Includes' . DIRECTORY_SEPARATOR . 'updateversion', serialize($pgExperimentalupdates ? 'master' : 'stable')); pecho("Peachy Updated! Changes will go into effect on the next run.\n\n", PECHO_NOTICE); file_put_contents($pgIP . 'Includes' . DIRECTORY_SEPARATOR . $this->logfile, serialize($this->commits)); } else { pecho("Update failed! Peachy could not retrieve all contents from GitHub.\n\n", PECHO_WARN); } }
public function done($t) { pecho("10000 IPC ops in " . sprintf("%.2f", $t) . " sec."); exit; }
/** * Returns array of pages that embed (transclude) the page given. * * @param array $namespace Which namespaces to search (default: null). * @param int $limit How many results to retrieve (default: null i.e. all). * @return array A list of pages the title is transcluded in. */ public function embeddedin($namespace = null, $limit = null) { $eiArray = array('list' => 'embeddedin', '_code' => 'ei', 'eititle' => $this->title, '_lhtitle' => 'title', '_limit' => $limit); if (!is_null($namespace)) { $eiArray['einamespace'] = $namespace; } Hooks::runHook('PreQueryEmbeddedin', array(&$eiArray)); pecho("Getting list of pages that include {$this->title}...\n\n", PECHO_NORMAL); return $this->wiki->listHandler($eiArray); }
/** * @param null|string $method * @param null|string $newfunction * @param string $message */ public static function deprecatedWarn($method, $newfunction, $message = null) { if (is_null($message)) { $message = "Warning: {$method} is deprecated. Please use {$newfunction} instead."; } $message = "[{$message}|YELLOW_BAR]\n\n"; pecho($message, PECHO_WARN, 'cecho'); }
/** * Performs nobots checking, new message checking, etc * * @param string $action Name of action. * @param null|string $title Name of page to check for nobots * @param null $pageidp * @throws AssertFailure * @throws EditError * @throws LoggedOut * @throws MWAPIError * @access public */ public function preEditChecks($action = "Edit", $title = null, $pageidp = null) { global $pgDisablechecks, $pgMasterrunpage; if ($pgDisablechecks) { return; } $preeditinfo = array('action' => 'query', 'meta' => 'userinfo', 'uiprop' => 'hasmsg|blockinfo', 'prop' => 'revisions', 'rvprop' => 'content'); if (!is_null($this->get_runpage())) { $preeditinfo['titles'] = $this->get_runpage(); } if (!is_null($title)) { $preeditinfo['titles'] = (!is_null($this->get_runpage()) ? $preeditinfo['titles'] . "|" : "") . $title; } $preeditinfo = $this->apiQuery($preeditinfo); $messages = false; $blocked = false; $oldtext = ''; $runtext = 'enable'; if (isset($preeditinfo['query']['pages'])) { //$oldtext = $preeditinfo['query']['pages'][$this->pageid]['revisions'][0]['*']; foreach ($preeditinfo['query']['pages'] as $pageid => $page) { if ($pageid == $pageidp) { $oldtext = $page['revisions'][0]['*']; } elseif ($pageid == "-1") { if ($page['title'] == $this->get_runpage()) { pecho("{$action} failed, enable page does not exist.\n\n", PECHO_WARN); throw new EditError("Enablepage", "Enable page does not exist."); } else { $oldtext = ''; } } else { $runtext = $page['revisions'][0]['*']; } } if (isset($preeditinfo['query']['userinfo']['messages'])) { $messages = true; } if (isset($preeditinfo['query']['userinfo']['blockedby'])) { $blocked = true; } } //Perform nobots checks, login checks, /Run checks if (checkExclusion($this, $oldtext, $this->get_username(), $this->get_optout(), $this->nobotsTaskname) && $this->get_nobots()) { throw new EditError("Nobots", "The page has a nobots template"); } if (!is_null($pgMasterrunpage) && !preg_match('/enable|yes|run|go|true/i', $this->initPage($pgMasterrunpage)->get_text())) { throw new EditError("Enablepage", "Script was disabled by Master Run page"); } if (!is_null($this->get_runpage()) && !preg_match('/enable|yes|run|go|true/i', $runtext)) { throw new EditError("Enablepage", "Script was disabled by Run page"); } if ($messages && $this->get_stoponnewmessages()) { throw new EditError("NewMessages", "User has new messages"); } if ($blocked) { throw new EditError("Blocked", "User has been blocked"); } }