server = $server; $this->sock = socket_create ( AF_INET, SOCK_STREAM, SOL_TCP ); //socket_set_nonblock($this->sock); //socket_bind ( $this->sock, $server, $port ); if (! socket_connect ( $this->sock, $server, $port )) { echo socket_strerror(socket_last_error()); die ( "Conection Problem with IRC server $server" ); } else { echo "Successfully Connected to $server \n"; } sleep( 1 ); socket_write ( $this->sock, "NICK $nick \r\n" ); socket_write ( $this->sock, "USER $nick * *: $nick \r\n" ); sleep( 1 ); if ($nickpass != NULL) { socket_write ( $this->sock, "PRIVMSG NICKSERV : identify $nickpass \r\n" ); echo "Logged Into Nickserv \n"; sleep ( 1 ); } } /*function log ($logfile) { socket_read ( $this->sock, 1024 ); }*/ function join( $channel) { if ( ! socket_write ( $this->sock, "JOIN :$channel\r\n" ) ) { die( 'Socket Error: ' . socket_strerror( socket_last_error() ) . " on IRC Server $this->server" ); } echo "Joined Channel $channel \n"; sleep( 1 ); } function pong( $server ) { if( ! socket_write ( $this->sock, "PONG :$server\r\n" ) ) { die( 'Socket Error: ' . socket_strerror( socket_last_error() ) . " on IRC Server $this->server" ); } } function say( $location, $text) { if( ! socket_write ( $this->sock, "PRIVMSG $location : $text\r\n" ) ) { die( 'Socket Error: ' . socket_strerror( socket_last_error() ) . " on IRC Server $this->server" ); } echo "$location, $text \n"; } function quit( $message = NULL ) { if ( ! socket_write ( $this->sock, "QUIT $message\r\n" ) ) { die( 'Socket Error: ' . socket_strerror( socket_last_error() . " on IRC Server $this->server") ); } echo "Disconnecting from $this->server\n"; } function read ( ) { $msg = socket_read($this->sock, 1024); //echo $msg; return $msg; } /* function readcontinue ( ) { if ( socket_select( $this->sock, NULL, NULL, NULL )){ $msg = socket_read($this->sock, 1024); } else { echo 'nothing new'; } //echo $msg; return $msg; }*/ } function curlinit () { $curl = curl_init (); $options = array( CURLOPT_COOKIEJAR => 'cookie/cookie.wikipedia.' . time() . '.txt', CURLOPT_COOKIEFILE => 'cookie/cookie.wikipedia.' . time() . '.txt', CURLOPT_VERBOSE => FALSE, CURLOPT_RETURNTRANSFER => TRUE, CURLOPT_COOKIESESSION => FALSE, CURLOPT_FOLLOWLOCATION => FALSE ); curl_setopt_array( $curl, $options); return $curl; } function curlexec ( $resource, $options ) { curl_setopt_array ( $resource , $options ); $page = curl_exec( $resource ); return $page; } class wikiapi { //public $page; //public $options; public $url; public $priv_curl; function __construct() { $this->url = 'http://en.wikipedia.org/w/api.php?format=xml&'; /*global $curl; if ( ! isset ( $curl ) ) { $curl = new curlsetup (); $curl->init(); }*/ } function login($user, $pass) { $postdata = "lgname=$user&lgpassword=$pass"; $options = array ( CURLOPT_URL => $this->url . 'action=login', CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $postdata, ); $page = curlexec ( $this->priv_curl, $options ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); if ($xml->login->attributes()->result == 'WrongPass') { die ('Login Problem'); } elseif ($xml->login->attributes()->result == 'NeedToWait') { die ('Login Wait Time Not Yet Expired'); } unset ($options, $page ); return $xml; } function pageinfo($page, $needtoken = TRUE) { $options = array ( CURLOPT_POST => FALSE ); if ( $needtoken ) { $options[CURLOPT_URL] = $this->url . "action=query&titles=$page&prop=info&inprop=protection&intoken=edit"; } else { $options[CURLOPT_URL] = $this->url . "action=query&titles=$page&prop=info&inprop=protection"; } $page = curlexec ( $this->priv_curl, $options ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); return $xml; } function last_creator_revsion( $page, $page_creator ) { $options = array ( CURLOPT_URL => $this->url . "action=query&prop=revisions&titles=$page&rvuser=$page_creator&rvlimit=1&rvdir=older", CURLOPT_POST => FALSE ); $page = curlexec ( $this->priv_curl, $options ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); return $xml; } function expandtemplates ( $template ) { $options = array ( CURLOPT_URL => $this->url . "action=expandtemplates&titles=$template", CURLOPT_POST => FALSE ); $page = curlexec ( $this->priv_curl, $options ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); return $xml; } function get_token ( ) { $options = array ( CURLOPT_URL => $this->url . "action&prop=revisions&title=$page&token=$token&summary=test§ion=new&text=Testing&bot=1", CURLOPT_POST => FALSE ); curl_setopt_array ( $this->curl, $options ); $page = curl_exec ( $this->curl ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); return $xml; } function edit ( $text, $summary, $page, $token, $minor = FALSE, $section = NULL ) { $options = array ( CURLOPT_URL => $this->url . "action=edit&title=$page&token=$token&summary=$summary&text=$text", CURLOPT_POST => FALSE ); if ( $minor ) { $options[CURLOPT_URL] .= '&minor=1'; } else { $options[CURLOPT_URL] .= '¬minor=1'; } if ( $section ) { $options[CURLOPT_URL] .= "section=$section"; } curl_setopt_array ( $this->curl, $this->options ); $page = curl_exec ( $this->curl ); echo "$page \n\n\n"; $xml = simplexml_load_string($page); return $xml; } function log($directory, $logname) { //Lets check to make sure the directory the logs will be stored in, and if not lets make a directory if (file_exists ( $directory ) && is_dir ( $directory )) { $log_name = "$directory/" . date ( 'm-d-Y' ) . "_$logname"; //If there is a log file open already lets add to it, if not lets create a new log if (file_exists ( $directory / $logname ) && is_file ( $directory / $logname )) { if (! fopen ( "$log_name", 'a' )) { echo "Problem Opening and Appending to Log \n"; } else { echo "Log Created \n"; } } else { if (! fopen ( "$log_name", 'x' )) { echo "Problem Creating Log \n"; } else { echo "Log Created \n"; } } } else { echo "Creating Directory for Log Files \n"; mkdir ( $directory ); $log_name = "$directory/" . date ( 'm-d-Y' ) . "_$logname"; if (file_exists ( $directory / $logname ) && is_file ( $directory / $logname )) { if (! fopen ( "$log_name", 'a' )) { echo "Problem Creating Log \n"; } else { echo "Log Created \n"; } } } } } class wikiindex { //public $options; private $url; public $priv_curl; public $time; function __construct() { $this->url = 'http://en.wikipedia.org/w/index.php?'; /*global $curl; $this->priv_curl = &$curl; if ( ! isset ( $curl ) ) { $curl = new curlsetup (); $curl->init(); }*/ } function edit ( $page, $edittext, $editsummary, $edittoken, $combinedtime, $minoredit = FALSE) { $curtime = date( 'YmdHis' ); $postdata = array( 'wpStarttime' => "$curtime", 'wpEdittime' => "$combinedtime", 'wpEditToken' => "$edittoken", 'wpTextbox1' => "$edittext", 'wpSummary' => "$editsummary", 'wpIgnoreBlankSummary' => 0, 'wpSave' => 'Save page' ); if( $minoredit ) { $postdata['wpMinoredit'] = 1; } $this->options = array ( CURLOPT_URL => $this->url . "action=submit&title=$page", CURLOPT_POST => TRUE, CURLOPT_POSTFIELDS => $postdata ); $page = $this->curl->curlexec ( $this->options ); echo "$page \n\n\n"; $xml = simplexml_load_string( $page ); return $xml; } function getcontent ( $page , $section = NULL ) { $options = array ( CURLOPT_URL => $this->url . "title=$page&action=raw", CURLOPT_POST => FALSE ); if ( $section != NULL ) { $options[CURLOPT_URL] .= "§ion=$section"; } $page = curlexec ( $this->priv_curl, $options ); echo "$page \n\n\n"; return $page; } function getrss ( ) { $options = array ( CURLOPT_URL => $this->url . "title=Special:RecentChanges&feed=rss", CURLOPT_POST => FALSE, CURLOPT_VERBOSE => false, CURLOPT_RETURNTRANSFER => TRUE, ); /*if ( $modified_time ) { //$options[CURLOPT_TIMECONDITION] = CURL_TIMECOND_IFMODSINCE; //$options[CURLOPT_TIMEVALUE] = $this->time; //$options[CURLOPT_HEADER] = TRUE; $options[CURLOPT_HTTP200ALIASES] = array ( '304' ); $options[CURLOPT_HTTPHEADER] = array('If-modified-since: ' . date( 'D, j M Y G:i:s ', $this->time) . 'GMT'); }*/ $page = curlexec ( $this->priv_curl, $options ); return $page; } } ?>