示例#1
0
 /**
  * Converts an XML url or string to a PHP array format
  *
  * @static
  * @access public
  * @param string $data Either an url to an xml file, or a raw XML string. Peachy will autodetect which is which.
  * @return array Parsed XML
  * @throws BadEntryError
  * @throws DependencyError
  * @throws HookError
  * @throws XMLError
  */
 public static function load($data)
 {
     $http = HTTP::getDefaultInstance();
     if (!function_exists('simplexml_load_string')) {
         throw new DependencyError("SimpleXML", "http://us.php.net/manual/en/book.simplexml.php");
     }
     libxml_use_internal_errors(true);
     if (in_string("<?xml", $data)) {
         $xmlout = $data;
     } else {
         $xmlout = $http->get($data);
     }
     Hooks::runHook('PreSimpleXMLLoad', array(&$xmlout));
     $xml = simplexml_load_string($xmlout);
     Hooks::runHook('PostSimpleXMLLoad', array(&$xml));
     if (!$xml) {
         foreach (libxml_get_errors() as $error) {
             throw new XMLError($error);
         }
     }
     $outArr = array();
     $namespaces = $xml->getNamespaces(true);
     $namespaces['default'] = '';
     self::recurse($xml, $outArr, $namespaces);
     libxml_clear_errors();
     return $outArr;
 }
示例#2
0
 /**
  * Takes a class name and attempt to load it
  *
  * @param $class_name String: name of class we're looking for.
  * @return boolean|null Returning false is important on failure as
  * 		it allows Zend to try and look in other registered autoloaders
  * 		as well.
  */
 public static function autoload($class_name)
 {
     global $pgIP, $pgAutoloader;
     if (isset($pgAutoloader[$class_name]) && is_file($pgIP . $pgAutoloader[$class_name])) {
         require_once $pgIP . $pgAutoloader[$class_name];
         return true;
     }
     if (is_file($pgIP . 'Plugins/' . $class_name . '.php')) {
         Hooks::runHook('LoadPlugin', array(&$class_name));
         require_once $pgIP . 'Plugins/' . $class_name . '.php';
         return true;
     }
 }
示例#3
0
文件: Peachy.php 项目: emijrp/Peachy
 /**
  * Initializes Peachy, logs in with a either configuration file or a given username and password
  *
  * @static
  * @access public
  *
  * @param string $config_name Name of the config file stored in the Configs directory, minus the .cfg extension. Default null
  * @param string $pgUsername Username to log in if no config file specified. Default null
  * @param string $password Password to log in with if no config file specified. Default null
  * @param string $base_url URL to api.php if no config file specified. Defaults to English Wikipedia's API.
  * @param string $classname
  *
  * @throws LoginError
  * @return Wiki Instance of the Wiki class, where most functions are stored
  */
 public static function newWiki($config_name = null, $pgUsername = null, $password = null, $base_url = 'http://en.wikipedia.org/w/api.php', $classname = 'Wiki')
 {
     pecho("Loading Peachy (version " . PEACHYVERSION . ")...\n\n", PECHO_NORMAL);
     /*$updater = new AutoUpdate();
     		$Uptodate = $updater->Checkforupdate();
     		if( !$Uptodate ) $updater->updatePeachy();*/
     if (!is_null($config_name)) {
         $config_params = self::parse_config($config_name);
     } else {
         $config_params = array('username' => $pgUsername, 'password' => $password, 'baseurl' => $base_url);
     }
     if (is_null($config_params['baseurl']) || !isset($config_params['baseurl'])) {
         throw new LoginError(array("MissingParam", "The baseurl parameter was not set."));
     }
     if (!isset($config_params['username']) || !isset($config_params['password'])) {
         $config_params['nologin'] = true;
     }
     list($version, $extensions) = self::wikiChecks($config_params['baseurl']);
     Hooks::runHook('StartLogin', array(&$config_params, &$extensions));
     $w = new $classname($config_params, $extensions, false, null);
     $w->mwversion = $version;
     return $w;
 }
示例#4
0
 public function update($rev)
 {
     Hooks::runHook('StartCodeReviewUpdate', array(&$rev));
     $apiRes = $this->wiki->apiQuery(array('action' => 'codeupdate', 'repo' => $this->repo, 'rev' => $rev), true);
     print_r($apiRes);
 }
示例#5
0
文件: IRC.php 项目: emijrp/Peachy
 function __construct($server, $pgPort = 6667, $user, $pass, $nick, $channel, $callback = null)
 {
     global $pgIRCTrigger, $pgHooks;
     if (func_num_args() > 6) {
         $this->server = $server;
         $this->port = $pgPort;
         $this->user = $user;
         $this->pass = $pass;
         $this->nick = $nick;
         $this->channel = $channel;
         $this->callback = $callback;
     } else {
         $this->server = $server;
         $this->port = 6667;
         $this->user = $pgPort;
         $this->pass = $user;
         $this->nick = $pass;
         $this->channel = $nick;
         $this->callback = $channel;
     }
     $pgHooks['SimpleIRCPrivMSG'][] = $callback;
     $irc = new IRC($this->user, $this->nick, $this->pass, $this->server, $this->port, "Peachy IRC Bot Version " . PEACHYVERSION, $this->channel);
     while (!feof($irc->f)) {
         $parsed = IRC::parseLine(fgets($irc->f, 1024), $pgIRCTrigger, true);
         if (@$parsed['n!u@h'] == 'PING') {
             $irc->sendPong($parsed['payload']);
         }
         if (@$parsed['type'] == '376' || @$parser['type'] == '422') {
             $feed->joinChan();
             sleep(5);
         }
         if (@$parsed['type'] == 'PRIVMSG') {
             Hooks::runHook('SimpleIRCPrivMSG', array(&$parsed, &$irc, &$this));
         }
     }
 }
示例#6
0
 /**
  * @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;
     }
 }
示例#7
0
文件: Image.php 项目: emijrp/Peachy
 /**
  * Downloads an image to the local disk
  *
  * @param string $localname Filename to store image as. Default null.
  * @param int $width Width of image to download. Default -1.
  * @param int $height Height of image to download. Default -1.
  * @return void
  */
 public function download($localname = null, $width = -1, $height = -1)
 {
     global $pgIP;
     if (!$this->get_exists()) {
         pecho("Attempted to download a non-existant file.", PECHO_NOTICE);
     }
     $ii = $this->imageinfo(1, $width, $height);
     if (is_array($ii)) {
         $ii = $ii[0];
         if ($width != -1) {
             $url = $ii['thumburl'];
         } else {
             $url = $ii['url'];
         }
         if (is_null($localname)) {
             $localname = $pgIP . 'Images/' . $this->localname;
         }
         Hooks::runHook('DownloadImage', array(&$url, &$localname));
         pecho("Downloading {$this->title} to {$localname}..\n\n", PECHO_NOTICE);
         $this->wiki->get_http()->download($url, $localname);
     } else {
         pecho("Error in getting image URL.\n\n" . print_r($ii) . "\n\n", PECHO_FATAL);
     }
 }
示例#8
0
文件: HTTP.php 项目: emijrp/Peachy
 /**
  * Destructor, deletes cookies and closes cURL class
  *
  * @access public
  * @return void
  */
 public function __destruct()
 {
     Hooks::runHook('HTTPClose', array(&$this));
     curl_close($this->curl_instance);
     //@unlink($this->cookie_jar);
 }
示例#9
0
文件: User.php 项目: emijrp/Peachy
 /**
  * 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);
 }
示例#10
0
/**
 * Outputs text if the given category is in the allowed types
 *
 * @param string $text Text to display
 * @param int $cat Category of text, such as PECHO_WARN, PECHO_NORMAL
 * @param string $func
 * @return void
 */
function outputText($text, $cat = 0, $func = 'echo')
{
    global $pgVerbose;
    Hooks::runHook('OutputText', array(&$text, &$cat, &$func));
    if (in_array($cat, $pgVerbose)) {
        if ($func == 'echo') {
            echo $text;
        } else {
            $func($text);
        }
    }
}
示例#11
0
文件: Page.php 项目: emijrp/Peachy
 /**
  * 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);
 }
示例#12
0
文件: Wiki.php 项目: emijrp/Peachy
 /**
  * Regenerate and return edit tokens
  *
  * @access public
  * @param bool $force Whether to force use of the API, not cache.
  * @return array Edit tokens
  */
 public function get_tokens($force = false)
 {
     Hooks::runHook('GetTokens', array(&$this->tokens));
     if (!$force && !empty($this->tokens)) {
         return $this->tokens;
     }
     $tokens = $this->apiQuery(array('action' => 'tokens', 'type' => 'block|delete|deleteglobalaccount|edit|email|import|move|options|patrol|protect|setglobalaccountstatus|unblock|watch'));
     foreach ($tokens['tokens'] as $y => $z) {
         if (in_string('token', $y)) {
             $this->tokens[str_replace('token', '', $y)] = $z;
         }
     }
     $token = $this->apiQuery(array('action' => 'query', 'list' => 'users', 'ususers' => $this->username, 'ustoken' => 'userrights'));
     if (isset($token['query']['users'][0]['userrightstoken'])) {
         $this->tokens['userrights'] = $token['query']['users'][0]['userrightstoken'];
     } else {
         pecho("Error retrieving userrights token...\n\n", PECHO_FATAL);
         return array();
     }
     return $this->tokens;
 }