├── .gitignore ├── bot.php ├── commands ├── !.php ├── 1337.php ├── 1337.txt ├── 8ball.php ├── aliases.php ├── amazon.php ├── anagram.php ├── array-rand.php ├── backwards.php ├── backwards.txt ├── baddebug.php ├── battle.php ├── bootsncats.php ├── borat.php ├── c.php ├── c.txt ├── cat.php ├── cat.txt ├── clear.php ├── clear.txt ├── color.php ├── converse.php ├── date.php ├── destroy-server.php ├── die!.php ├── die!.txt ├── dilbert.php ├── dilbert.txt ├── domain.php ├── domain.txt ├── domainr.php ├── em.php ├── entropy.php ├── eval.php ├── everybody.php ├── fail.php ├── fail.txt ├── fib.php ├── fortune.php ├── fortune.txt ├── fp.php ├── fp.txt ├── geoip.php ├── geoip.txt ├── gif.php ├── gir.php ├── github.php ├── github.txt ├── gl.php ├── gl.txt ├── gong.php ├── google.php ├── help.txt ├── ip.php ├── ip.txt ├── ipcalc.php ├── ipsum.php ├── ipsum.txt ├── it.php ├── j.php ├── j.txt ├── jinx.php ├── join.php ├── jpeg.php ├── jpeg.txt ├── kick.php ├── kirbydance.php ├── kirbydance.txt ├── lmgtfy.php ├── loic.php ├── loic.txt ├── man.php ├── math-old.php ├── math-old.txt ├── math.php ├── math.txt ├── md5.php ├── movie.php ├── nick.php ├── nooo.php ├── nslookup.php ├── nutrition.php ├── p.php ├── p.txt ├── part.php ├── password.php ├── permute.php ├── php.php ├── ping.php ├── ping.txt ├── ping_native.php ├── ping_native.txt ├── pirate.php ├── pirate.txt ├── pizzatime.php ├── poll.php ├── prime.php ├── q.php ├── q.txt ├── qr.php ├── qr.txt ├── quote.php ├── rainbow.php ├── rainbowshout.php ├── rainbowshout2.php ├── rand.php ├── rand.txt ├── randuser.php ├── rdns.php ├── rdns.txt ├── rebuild.php ├── rebuild.txt ├── rejoin.php ├── reload.php ├── reload.txt ├── say.php ├── say.txt ├── scream.php ├── scrumtime.php ├── sha1.php ├── shout.php ├── shout.txt ├── shout2.php ├── showme.php ├── showme.txt ├── shuffle.php ├── slap.php ├── so.php ├── startup.php ├── startup.txt ├── sudo.php ├── sudo.txt ├── tell.php ├── tell.txt ├── time.php ├── timer.php ├── timer.txt ├── translate.php ├── tweet.php ├── ud.php ├── ud.txt ├── urlencode.php ├── uuid.php ├── vote.php ├── wa.php ├── wargames.php ├── wargames.txt ├── weather.php ├── weather.txt ├── whoami.php ├── whoami.txt ├── whois.php ├── wiki.php ├── win.php ├── wiseman.php ├── woot.php ├── xkcd.php ├── xkcd.txt ├── yoda.php ├── yoda.txt ├── youtube.php └── youtube.txt ├── config-sample.php ├── lib ├── AmazonECS.class.php ├── OAuth.php ├── Twilio.php ├── Twilio │ ├── AutoPagingIterator.php │ ├── Capability.php │ ├── HttpException.php │ ├── HttpStream.php │ ├── InstanceResource.php │ ├── ListResource.php │ ├── NumberType.php │ ├── Page.php │ ├── PartialApplicationHelper.php │ ├── RequestValidator.php │ ├── Resource.php │ ├── Rest │ │ ├── Account.php │ │ ├── Accounts.php │ │ ├── Application.php │ │ ├── Applications.php │ │ ├── AuthorizedConnectApp.php │ │ ├── AuthorizedConnectApps.php │ │ ├── AvailablePhoneNumber.php │ │ ├── AvailablePhoneNumbers.php │ │ ├── Call.php │ │ ├── Calls.php │ │ ├── Conference.php │ │ ├── Conferences.php │ │ ├── ConnectApp.php │ │ ├── ConnectApps.php │ │ ├── Credential.php │ │ ├── CredentialList.php │ │ ├── CredentialListMapping.php │ │ ├── CredentialListMappings.php │ │ ├── CredentialLists.php │ │ ├── Credentials.php │ │ ├── Domain.php │ │ ├── Domains.php │ │ ├── IncomingPhoneNumber.php │ │ ├── IncomingPhoneNumbers.php │ │ ├── IpAccessControlList.php │ │ ├── IpAccessControlListMapping.php │ │ ├── IpAccessControlListMappings.php │ │ ├── IpAccessControlLists.php │ │ ├── IpAddress.php │ │ ├── IpAddresses.php │ │ ├── Media.php │ │ ├── MediaInstance.php │ │ ├── Member.php │ │ ├── Members.php │ │ ├── Message.php │ │ ├── Messages.php │ │ ├── Notification.php │ │ ├── Notifications.php │ │ ├── OutgoingCallerId.php │ │ ├── OutgoingCallerIds.php │ │ ├── Participant.php │ │ ├── Participants.php │ │ ├── Queue.php │ │ ├── Queues.php │ │ ├── Recording.php │ │ ├── Recordings.php │ │ ├── Sandbox.php │ │ ├── ShortCode.php │ │ ├── ShortCodes.php │ │ ├── Sip.php │ │ ├── SmsMessage.php │ │ ├── SmsMessages.php │ │ ├── Transcription.php │ │ ├── Transcriptions.php │ │ ├── UsageRecord.php │ │ ├── UsageRecords.php │ │ ├── UsageTrigger.php │ │ └── UsageTriggers.php │ ├── RestException.php │ ├── SIPListResource.php │ ├── TimeRangeResource.php │ ├── TinyHttp.php │ ├── Twiml.php │ └── UsageResource.php ├── Unirest.php ├── Unirest │ ├── HttpMethod.php │ ├── HttpResponse.php │ └── Unirest.php ├── XMPPHP │ ├── BOSH.php │ ├── Exception.php │ ├── Log.php │ ├── Roster.php │ ├── XMLObj.php │ ├── XMLStream.php │ ├── XMPP.php │ └── XMPP_Old.php ├── cacert.pem ├── chatterbotapi.php ├── domain.class.php ├── evalmath.class.php ├── json.php ├── json_decode_loose.php ├── latex │ ├── latex_add.php │ ├── latex_divide.php │ ├── latex_exponent.php │ ├── latex_multiply.php │ ├── latex_operation.php │ ├── latex_parenthesis.php │ ├── latex_subtract.php │ └── latex_value.php ├── mstranslate.php ├── phpQuery-onefile.php ├── tmdb4php │ ├── Asset.php │ ├── Collection.php │ ├── Company.php │ ├── Genre.php │ ├── Movie.php │ ├── Person.php │ ├── README.md │ └── TMDB.php └── twitteroauth.php └── res ├── badwords.gz └── wordlist.txt /.gitignore: -------------------------------------------------------------------------------- 1 | config.php 2 | -------------------------------------------------------------------------------- /commands/!.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "New Twitter doesn't use a hashbang anymore, history.pushState() was better.", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/1337.php: -------------------------------------------------------------------------------- 1 | $mash_key)); 7 | $conn->message($event['from'], $response->raw_body, $event['type']); 8 | } else { 9 | $conn->message($event['from'], "Usage: #1337 ", $event['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/1337.txt: -------------------------------------------------------------------------------- 1 | Usage: #1337 2 | Converts the sentence to leet speak. -------------------------------------------------------------------------------- /commands/8ball.php: -------------------------------------------------------------------------------- 1 | message($event['from'], $responses[array_rand($responses)], $event['type']); 29 | } 30 | ?> 31 | -------------------------------------------------------------------------------- /commands/aliases.php: -------------------------------------------------------------------------------- 1 | $command) { 6 | $list[] = $alias . " -> " . $command; 7 | } 8 | $msg = implode(", ", $list); 9 | $conn->message($pl['from'], rtrim($msg), $pl['type']); 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/amazon.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Amazon Associate Tag and Key must be set in configuration.", $event['type']); 8 | return false; 9 | } 10 | 11 | try { 12 | if (!empty($params[0])) { 13 | $amazonEcs = new AmazonECS($amazon_key, $amazon_secret, 'com', $amazon_associate_tag); 14 | $result = $amazonEcs->Category('All')->responseGroup('ItemAttributes,Offers')->search(implode(" ", $params)); 15 | 16 | if(!empty($result->Items->Item)) { 17 | $first = $result->Items->Item[0]; 18 | 19 | // Top hit 20 | $html = "" . htmlentities($first->ItemAttributes->Title). ""; 21 | $html .= " - {$first->ItemAttributes->ListPrice->FormattedPrice}"; 22 | if(!empty($first->ItemAttributes->Feature)) { 23 | $html .= "\n
• " . implode("\n
• ", $first->ItemAttributes->Feature); 24 | } 25 | 26 | // Next few results 27 | foreach($result->Items->Item as $i=>$item) { 28 | // Show first 5 products 29 | if($i == 0 || $i >= 5) { 30 | continue; 31 | } 32 | 33 | $html .= "\n
" . htmlentities($item->ItemAttributes->Title). " - {$item->ItemAttributes->ListPrice->FormattedPrice}"; 34 | } 35 | 36 | $conn->htmlmessage($event['from'], $html, $event['type']); 37 | } else { 38 | $conn->message($event['from'], "Nada.", $event['type']); 39 | } 40 | } else { 41 | $conn->message($event['from'], "Usage: #amazon ", $event['type']); 42 | } 43 | } catch(Exception $ex) { 44 | $conn->message($event['from'], "Amazon item lookup failed.", $event['type']); 45 | } 46 | } 47 | ?> 48 | -------------------------------------------------------------------------------- /commands/anagram.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "hashbot", $event['type']); 7 | return; 8 | } 9 | $result = json_decode(curl_get_contents("http://www.anagramica.com/all/" . urlencode($params[0]))); 10 | if(!empty($result->all)) { 11 | $conn->message($event['from'], implode(", ", $result->all), $event['type']); 12 | } else { 13 | print_r($result); 14 | $conn->message($event['from'], "No anagrams found.", $event['type']); 15 | } 16 | } else { 17 | $conn->message($event['from'], "Usage: #anagram ", $event['type']); 18 | } 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /commands/array-rand.php: -------------------------------------------------------------------------------- 1 | 1) { 4 | $val = $params[array_rand($params)]; 5 | $conn->message($event['from'], $val, $event['type']); 6 | } else { 7 | $conn->message($event['from'], "Usage: #array-rand [item1] [item2] ... [itemN]", $event['type']); 8 | } 9 | } 10 | ?> 11 | -------------------------------------------------------------------------------- /commands/backwards.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], strrev($param_str), $pl['type']); 6 | } else { 7 | $conn->message($pl['from'], "Usage: #backwards ", $pl['type']); 8 | } 9 | } 10 | ?> 11 | -------------------------------------------------------------------------------- /commands/backwards.txt: -------------------------------------------------------------------------------- 1 | Usage: #backwards 2 | Prints back the string in reverse order. -------------------------------------------------------------------------------- /commands/baddebug.php: -------------------------------------------------------------------------------- 1 | message($event['from'], count($wordfilter) . " words in database.", $event['type']); 7 | } 8 | ?> 9 | -------------------------------------------------------------------------------- /commands/battle.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "Usage: #battle vs ", $pl['type']); 9 | return; 10 | } 11 | 12 | $queries[0] = trim($queries[0]); 13 | $url0 = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=" . urlencode($queries[0]); 14 | $response0 = json_decode(curl_get_contents($url0), true); 15 | 16 | $queries[1] = trim($queries[1]); 17 | $url1 = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0&rsz=1&q=" . urlencode($queries[1]); 18 | $response1 = json_decode(curl_get_contents($url1), true); 19 | 20 | if (isset($response0['responseData']['cursor']['estimatedResultCount'])) { 21 | 22 | $result0 = $response0['responseData']['cursor']['estimatedResultCount']; 23 | $result1 = $response1['responseData']['cursor']['estimatedResultCount']; 24 | 25 | if($result0 > $result1) { 26 | $conn->message($pl['from'], $queries[0] . " wins " . number_format($result0) . " - " . number_format($result1) . "!", $pl['type']); 27 | } elseif($result1 > $result0) { 28 | $conn->message($pl['from'], $queries[1] . " wins " . number_format($result1) . " - " . number_format($result0) . "!", $pl['type']); 29 | } else { 30 | $conn->message($pl['from'], "It's a tie at " . number_format($result0) . "!", $pl['type']); 31 | } 32 | 33 | } else { 34 | $conn->message($pl['from'], "The opponent didn't show.", $pl['type']); 35 | } 36 | } else { 37 | $conn->message($pl['from'], "Usage: #battle vs ", $pl['type']); 38 | } 39 | } 40 | ?> 41 | -------------------------------------------------------------------------------- /commands/bootsncats.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Usage: #bootsncats ", $event['type']); 7 | } elseif ($params[0] > 200) { 8 | $conn->message($event['from'], "Nope :P", $event['type']); 9 | } else { 10 | $arr = array(); 11 | for($i = 0; $i < $params[0]; $i++) { 12 | $arr[] = $str; 13 | } 14 | $conn->message($event['from'], ucfirst(implode($cat, $arr)) . ".", $event['type']); 15 | } 16 | } 17 | ?> 18 | -------------------------------------------------------------------------------- /commands/borat.php: -------------------------------------------------------------------------------- 1 | get("statuses/user_timeline", array("screen_name" => "DEVOPS_BORAT", "trim_user" => true, "count" => 3000)); 9 | } 10 | 11 | $tweet = $devops_borat_feed[array_rand($devops_borat_feed)]; 12 | 13 | if($tweet) { 14 | $conn->message($event['from'], $tweet->text, $event['type']); 15 | } else { 16 | print_r($devops_borat_feed); 17 | unset($devops_borat_feed); 18 | $conn->message($event['from'], "Unable to load tweet :(", $event['type']); 19 | } 20 | 21 | } 22 | ?> 23 | -------------------------------------------------------------------------------- /commands/c.php: -------------------------------------------------------------------------------- 1 | create(ChatterBotType::CLEVERBOT); 9 | if(!isset($chat_session_c)) 10 | $chat_session_c = $chat_c->createSession(); 11 | 12 | if (!empty($params[0])) { 13 | $param_str = implode(" ",$params); 14 | $response = $chat_session_c->think($param_str); 15 | echo "Response: " . trim($response) . "\n"; 16 | $conn->message($event['from'], trim($response), $event['type']); 17 | } else { 18 | $conn->message($event['from'], "Usage: #c ", $event['type']); 19 | } 20 | } 21 | ?> 22 | -------------------------------------------------------------------------------- /commands/c.txt: -------------------------------------------------------------------------------- 1 | Usage: #c 2 | Sends a message to Cleverbot and returns the response. -------------------------------------------------------------------------------- /commands/cat.php: -------------------------------------------------------------------------------- 1 | message($event['from'], $cat->data->images->image->url, $event['type']); 10 | } elseif(in_array($params[0],$categories)) { 11 | $url = "http://thecatapi.com/api/images/get?format=xml&category=" . urlencode($params[0]); 12 | if(!empty($params[1]) && $params[1] == "gif") { 13 | $url .= "&type=gif"; 14 | } 15 | 16 | $cat_xml = curl_get_contents($url); 17 | $cat = new SimpleXMLElement($cat_xml); 18 | if(!empty($cat->data->images)) { 19 | $conn->message($event['from'], $cat->data->images->image->url, $event['type']); 20 | } else { 21 | $conn->message($event['from'], "No kittehs here :(", $event['type']); 22 | } 23 | } else { 24 | $conn->message($event['from'], "Available categories: " . implode(" ",$categories), $event['type']); 25 | } 26 | } else { 27 | $cat_xml = curl_get_contents("http://thecatapi.com/api/images/get?format=xml"); 28 | $cat = new SimpleXMLElement($cat_xml); 29 | $conn->message($event['from'], $cat->data->images->image->url, $event['type']); 30 | } 31 | } catch(Exception $ex) { 32 | echo $cat_xml; 33 | $conn->message($event['from'], "Failed to get a kitteh!", $event['type']); 34 | } 35 | } 36 | ?> 37 | -------------------------------------------------------------------------------- /commands/cat.txt: -------------------------------------------------------------------------------- 1 | Usage: #cat [category|help] [gif] 2 | Gets a random cat picture, optionally from a specific category and/or an animated gif. -------------------------------------------------------------------------------- /commands/clear.php: -------------------------------------------------------------------------------- 1 | 100) { 5 | $conn->message($pl['from'], "Yeah, no.", $pl['type']); 6 | return; 7 | } elseif(intval($params[0]) > 0) { 8 | $lines = intval($params[0]); 9 | } 10 | } else { 11 | $lines = 30; 12 | } 13 | if(!empty($lines)) { 14 | $conn->message($pl['from'], str_repeat("\n", $lines), $pl['type']); 15 | } else { 16 | $conn->message($pl['from'], "Usage: #clear [lines]", $pl['type']); 17 | } 18 | } 19 | ?> -------------------------------------------------------------------------------- /commands/clear.txt: -------------------------------------------------------------------------------- 1 | Usage: #clear [lines] 2 | Clears the chat window by outputting 30 or [lines] new lines. -------------------------------------------------------------------------------- /commands/color.php: -------------------------------------------------------------------------------- 1 | htmlmessage($pl['from'], "

███

", $pl['type']); 5 | } else { 6 | $conn->message($pl['from'], "Usage: #color ", $pl['type']); 7 | } 8 | } 9 | ?> -------------------------------------------------------------------------------- /commands/converse.php: -------------------------------------------------------------------------------- 1 | create(ChatterBotType::JABBERWACKY); 9 | if(!isset($chat_p)) 10 | $chat_p = $chat_factory->create(ChatterBotType::PANDORABOTS, 'cca4a7a23e347bc7'); // b0dafd24ee35a477 11 | $chat_session_j = $chat_j->createSession(); 12 | $chat_session_p = $chat_p->createSession(); 13 | 14 | if (!empty($params[0]) && intval($params[0]) > 0 && intval($params[0]) <= 20 && !empty($params[1])) { 15 | $count = intval($params[0]); 16 | unset($params[0]); 17 | $response = implode(" ",$params); 18 | for($i = 0; $i < $count; $i++) { 19 | // Pandorabot 20 | $response = $chat_session_p->think($response); 21 | $msg = "PB: " . trim($response) . " [" . ($i + 1) . "/" . $count . "]"; 22 | echo strip_tags($msg) . "\n"; 23 | $conn->htmlmessage($event['from'], $msg, $event['type']); 24 | // Jabberwacky 25 | $response = $chat_session_j->think($response); 26 | $msg = "JW: " . trim($response) . " [" . ($i + 1) . "/" . $count . "]"; 27 | echo strip_tags($msg) . "\n"; 28 | $conn->htmlmessage($event['from'], $msg, $event['type']); 29 | } 30 | } else { 31 | $conn->message($event['from'], "Usage: #converse ", $event['type']); 32 | } 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /commands/date.php: -------------------------------------------------------------------------------- 1 | message($event['from'], date(implode(" ", $params)), $event['type']); 7 | } else { 8 | $conn->message($event['from'], "Usage: #date ", $event['type']); 9 | } 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/destroy-server.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Destroying $params[0]", $event['type']); 5 | sleep(2); 6 | $conn->htmlmessage($event['from'], "The server named {$params[0]} has been destroy using the rm -Rf / command", $event['type']); 7 | } else { 8 | $conn->message($event['from'], "Please enter a server to destroy", $event['type']); 9 | } 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/die!.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "/me dies", $pl['type']); 7 | $conn->disconnect(); 8 | } else { 9 | $conn->message($pl['from'], "Only my master can kill me!", $pl['type']); 10 | } 11 | } else { 12 | $conn->message($pl['from'], "/me decides not to die.", $pl['type']); 13 | } 14 | } 15 | ?> 16 | -------------------------------------------------------------------------------- /commands/die!.txt: -------------------------------------------------------------------------------- 1 | Usage: #die! 2 | Kills the bot, but only if you are its master. -------------------------------------------------------------------------------- /commands/dilbert.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "http://dilbert.com/fast/" . $date . "/", $pl['type']); 5 | } 6 | ?> 7 | -------------------------------------------------------------------------------- /commands/dilbert.txt: -------------------------------------------------------------------------------- 1 | Usage: #dilbert 2 | Shows a random Dilbert comic 3 | -------------------------------------------------------------------------------- /commands/domain.php: -------------------------------------------------------------------------------- 1 | body); 6 | if(!empty($response->body->error_message)) { 7 | $str = "Error: " . htmlentities($response->body->error_message); 8 | } else { 9 | $str = htmlentities($response->body->domain) . ": " . htmlentities($response->body->availability) . ""; 10 | /*if($response->body->availability == "available") { 11 | $str = " {$response->body->domain} Register"; 12 | } elseif($response->body->availability == "maybe") { 13 | $str = " {$response->body->domain} Check"; 14 | } else { 15 | $str = " {$response->body->domain}"; 16 | }*/ 17 | } 18 | $conn->htmlmessage($event['from'], $str, $event['type']); 19 | } else { 20 | $conn->message($event['from'], "Usage: #domain ", $event['type']); 21 | } 22 | } 23 | ?> 24 | -------------------------------------------------------------------------------- /commands/domain.txt: -------------------------------------------------------------------------------- 1 | Usage: #domain [...] 2 | Checks whether the given domains are available to register. -------------------------------------------------------------------------------- /commands/domainr.php: -------------------------------------------------------------------------------- 1 | body->error_message)) { 6 | $str = "Error: " . $response->body->error_message; 7 | } else { 8 | $str = ""; 9 | foreach($response->body->results as $result) { 10 | if(($result->availability == "available" || $result->availability == "maybe") && empty($result->path)) { 11 | //$str .= "\n" . $result->subdomain . $result->path . ": "; 12 | $str .= "\n" . $result->subdomain . ": " . $result->availability . " - " . $result->register_url; 13 | /*} else { 14 | $str .= $result->availability;*/ 15 | } 16 | } 17 | if(!$str) { 18 | $str = "No matching domains available."; 19 | } else { 20 | $str = "Available domains:" . $str; 21 | } 22 | } 23 | $conn->message($event['from'], $str, $event['type']); 24 | } else { 25 | $conn->message($event['from'], "Usage: #domainr ", $event['type']); 26 | } 27 | } 28 | ?> 29 | -------------------------------------------------------------------------------- /commands/em.php: -------------------------------------------------------------------------------- 1 | htmlmessage($pl['from'], "

{$text[$i]}

", $pl['type']); 157 | usleep(90000); 158 | } 159 | $i++; 160 | } 161 | } 162 | } 163 | else { 164 | $conn->message($event['from'], "Usage: #em ", $event['type']); 165 | } 166 | } 167 | 168 | 169 | ?> 170 | -------------------------------------------------------------------------------- /commands/entropy.php: -------------------------------------------------------------------------------- 1 | 1 ? (2 * (min($len, 8) - 1)) : 0) + ($len > 8 ? (1.5 * (min($len, 20) - 8)) : 0) + ($len > 20 ? ($len - 20) : 0) + 6 * (bool)(preg_match('/[A-Z].*?[0-9[:punct:]]|[0-9[:punct:]].*?[A-Z]/', $str)); 7 | if($entropy < 20) { 8 | $result = "Weak"; 9 | } elseif($entropy < 25) { 10 | $result = "Moderate"; 11 | } else { 12 | $result = "strong"; 13 | } 14 | $conn->message($pl['from'], $entropy . " ($result)", $pl['type']); 15 | } else { 16 | $conn->message($pl['from'], "Usage: #entropy ", $pl['type']); 17 | } 18 | } 19 | ?> 20 | -------------------------------------------------------------------------------- /commands/everybody.php: -------------------------------------------------------------------------------- 1 | 20) { 5 | $conn->message($pl['from'], "Uh... no.", $pl['type']); 6 | } else { 7 | $conn->message($pl['from'], trim(str_repeat("everybody, ", $params[0]), ", "), $pl['type']); 8 | } 9 | } else { 10 | $conn->message($pl['from'], "Usage: #everybody ", $pl['type']); 11 | } 12 | } 13 | ?> 14 | -------------------------------------------------------------------------------- /commands/fail.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], $param_str . "'s fail level is over 9000!!!!!!!11", $pl['type']); 7 | } else { 8 | $conn->message($pl['from'], "On a fail of 1-100, " . $param_str . " failed at " . rand(1, 100) . ".", $pl['type']); 9 | } 10 | } else { 11 | $conn->message($pl['from'], "Usage: #fail ", $pl['type']); 12 | } 13 | } 14 | ?> 15 | -------------------------------------------------------------------------------- /commands/fail.txt: -------------------------------------------------------------------------------- 1 | Usage: #fail 2 | Calculates the fail level of a person who failed. -------------------------------------------------------------------------------- /commands/fib.php: -------------------------------------------------------------------------------- 1 | 0) { // && intval($params[0]) < 100000000000000) { 4 | $max = intval($params[0]); 5 | $fib = array(0,1); 6 | for ($i = 1; $i < $max; $i++) { 7 | $fib[] = $fib[$i]+$fib[$i-1]; 8 | } 9 | $z = $fib[count($fib) - 1]; 10 | $conn->message($pl['from'], $z, $pl['type']); 11 | } else { 12 | $conn->message($pl['from'], "Usage: #fib ", $pl['type']); 13 | } 14 | } 15 | ?> 16 | -------------------------------------------------------------------------------- /commands/fortune.php: -------------------------------------------------------------------------------- 1 | message($event['from'], trim($response), $event['type']); 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/fortune.txt: -------------------------------------------------------------------------------- 1 | Usage: #fortune [category] 2 | Get a random fortune from the classic Unix fortune program. -------------------------------------------------------------------------------- /commands/fp.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "http://facepalm.org/images/{$img}.jpg", $event['type']); 5 | } 6 | ?> 7 | -------------------------------------------------------------------------------- /commands/fp.txt: -------------------------------------------------------------------------------- 1 | Usage: #fp 2 | Gets a random facepalm image. -------------------------------------------------------------------------------- /commands/geoip.php: -------------------------------------------------------------------------------- 1 | body->country_code) { 7 | $output = $response->body->city . ", " . $response->body->region_code . ", " . $response->body->country_code . " "; 8 | $output .= "(" . $response->body->latitude . " " . $response->body->longitude . ")"; 9 | } else { 10 | $output = "IP " . $params[0] . " not in database."; 11 | } 12 | $conn->message($pl['from'], $output, $pl['type']); 13 | } else { 14 | $conn->message($pl['from'], "Usage: #geoip ", $pl['type']); 15 | } 16 | } 17 | ?> 18 | -------------------------------------------------------------------------------- /commands/geoip.txt: -------------------------------------------------------------------------------- 1 | Usage: #geoip 2 | Perform a geo-ip lookup to determine where the IP address is located. -------------------------------------------------------------------------------- /commands/gif.php: -------------------------------------------------------------------------------- 1 | body->data) && !empty($result->body->data[0])) { 8 | $i = array_rand($result->body->data); 9 | $img = $result->body->data[$i]->images->original; 10 | $conn->message($event['from'], $img->url, $event['type']); 11 | } else { 12 | $conn->message($event['from'], "Nada.", $event['type']); 13 | } 14 | } else { 15 | $conn->message($event['from'], "Usage: #gif ", $event['type']); 16 | } 17 | } 18 | ?> -------------------------------------------------------------------------------- /commands/gir.php: -------------------------------------------------------------------------------- 1 | message($event['from'], $responses[array_rand($responses)], $event['type']); 23 | } 24 | ?> 25 | -------------------------------------------------------------------------------- /commands/github.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Unable to load repository.", $event['type']); 9 | return; 10 | } 11 | if(is_array($response) && !empty($response[0]->commit)) { 12 | $commit = $response[0]->commit; 13 | $commit_tag = substr($response[0]->html_url, -40, 7); 14 | $conn->htmlmessage($event['from'], "Last commit: $commit_tag\n
{$commit->author->name}: {$commit->message}\n
", $event['type']); 15 | } else { 16 | $conn->message($event['from'], $params[0] . "/" . $params[1] . " has no visible commits!", $event['type']); 17 | } 18 | } else { 19 | // Get repo list 20 | $response = json_decode(curl_get_contents("https://api.github.com/users/" . $params[0] . "/repos", "Alanaktion/chatbot")); 21 | $str = $params[0] . "'s repositories:"; 22 | if(!empty($response) && is_array($response)) { 23 | foreach($response as $repo) { 24 | $str .= "\n
{$repo->name} - {$repo->description}"; 25 | } 26 | $conn->htmlmessage($event['from'], $str, $event['type']); 27 | } else { 28 | $conn->message($event['from'], "User not found, or has no visible repositories.", $event['type']); 29 | } 30 | } 31 | } else { 32 | $conn->message($event['from'], "Usage: #github [repository]", $event['type']); 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /commands/github.txt: -------------------------------------------------------------------------------- 1 | Usage: #github [repository] 2 | Lists a Github user's repositories or shows the last commit to a repository. -------------------------------------------------------------------------------- /commands/gl.php: -------------------------------------------------------------------------------- 1 | id)) { 6 | $conn->message($pl['from'], $response->id, $pl['type']); 7 | } 8 | } else { 9 | $conn->message($pl['from'], "Usage: #gl ", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/gl.txt: -------------------------------------------------------------------------------- 1 | Usage: #gl 2 | Generates a short URL on goog.gl. 3 | Currently broken. -------------------------------------------------------------------------------- /commands/gong.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "http://x.co/gonnng", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/google.php: -------------------------------------------------------------------------------- 1 | "https://github.com/Alanaktion/chatbot")); 7 | print_r($response); 8 | if (!empty($response->body->responseData->results[0])) { 9 | $top = $response->body->responseData->results[0]; 10 | $conn->message($pl['from'], html_entity_decode($top->titleNoFormatting) . " " . rawurldecode($top->url), $pl['type']); 11 | } elseif(!empty($response->body->responseDetails)) { 12 | $conn->message($pl['from'], $response->body->responseDetails, $pl['type']); 13 | } else { 14 | $conn->message($pl['from'], "Nothing found!", $pl['type']); 15 | } 16 | } else { 17 | $conn->message($pl['from'], "Usage: #google ", $pl['type']); 18 | } 19 | } 20 | ?> 21 | -------------------------------------------------------------------------------- /commands/help.txt: -------------------------------------------------------------------------------- 1 | Usage: #help [command] 2 | Running #help without any parameters lists all available commands. 3 | If the command parameter is specified, the help page for that command will be shown, if one is available. -------------------------------------------------------------------------------- /commands/ip.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], $response, $pl['type']); 5 | } 6 | ?> 7 | -------------------------------------------------------------------------------- /commands/ip.txt: -------------------------------------------------------------------------------- 1 | Usage: #ip 2 | Get the public IP address of the bot. -------------------------------------------------------------------------------- /commands/ipcalc.php: -------------------------------------------------------------------------------- 1 | = $i ? '1' : '0'; 8 | 9 | $netmask = long2ip(bindec($bin)); 10 | 11 | if ($netmask == "0.0.0.0") 12 | return false; 13 | 14 | return $netmask; 15 | } 16 | 17 | function cidr2network($ip, $cidr) { 18 | return long2ip((ip2long($ip)) & ((-1 << (32 - (int)$cidr)))); 19 | } 20 | 21 | function netmask2cidr($netmask) { 22 | $bits = 0; 23 | $netmask = explode(".", $netmask); 24 | 25 | foreach($netmask as $octect) 26 | $bits += strlen(str_replace("0", "", decbin($octect))); 27 | 28 | return $bits; 29 | } 30 | 31 | function cidr_match($ip, $network, $cidr) { 32 | if ((ip2long($ip) & ~((1 << (32 - $cidr)) - 1) ) == ip2long($network)) { 33 | return true; 34 | } 35 | return false; 36 | } 37 | 38 | } 39 | if (!empty($params[0])) { 40 | if(preg_match("/([0-9]+\.){2}[0-9]+\/[0-9]{1,2}/", $params[0])) { 41 | $netmask = cidr2netmask(substr($params[0], strpos($params[0], "/") + 1)); 42 | $cidr = netmask2cidr($netmask); 43 | $address = cidr2network(substr($params[0], 0, strpos($params[0], "/")), $cidr); 44 | } else { 45 | $conn->message($event["from"], "Invalid Address/CIDR", $event["type"]); 46 | return; 47 | } 48 | 49 | $out = "\n"; 50 | $out .= "Address: $address"; 51 | $out .= "Netmask: $netmask = $cidr"; 52 | $conn->message($event["from"], $out, $event["type"]); 53 | 54 | } else { 55 | $conn->message($event["from"], "Usage: #ipcalc ", $event["type"]); 56 | } 57 | } 58 | ?> 59 | -------------------------------------------------------------------------------- /commands/ipsum.txt: -------------------------------------------------------------------------------- 1 | Usage: #ipsum [lorem|hipster|corporate] 2 | Outputs a paragraph of Lorem Ipsum or the passed variation. 3 | -------------------------------------------------------------------------------- /commands/it.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "/me pounds it.", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/j.php: -------------------------------------------------------------------------------- 1 | create(ChatterBotType::JABBERWACKY); 9 | if(!isset($chat_session_j)) 10 | $chat_session_j = $chat_j->createSession(); 11 | 12 | if (!empty($params[0])) { 13 | $param_str = implode(" ",$params); 14 | $response = $chat_session_j->think($param_str); 15 | echo "Response: " . trim($response) . "\n"; 16 | $conn->message($event['from'], trim($response), $event['type']); 17 | } else { 18 | $conn->message($event['from'], "Usage: #j ", $event['type']); 19 | } 20 | } 21 | ?> 22 | -------------------------------------------------------------------------------- /commands/j.txt: -------------------------------------------------------------------------------- 1 | Usage: #j 2 | Sends a message to Jabberwacky and returns the response. -------------------------------------------------------------------------------- /commands/jinx.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], $param_str . " owes " . $short_from . " a " . $array_of_lots_of_stuff[array_rand($array_of_lots_of_stuff)], $pl['type']); 13 | } else { 14 | $conn->message($pl['from'], "Usage: #jinx ", $pl['type']); 15 | } 16 | } 17 | ?> -------------------------------------------------------------------------------- /commands/join.php: -------------------------------------------------------------------------------- 1 | joinRoom($room, $room_server, $nick, $room_password); 13 | $conn->message($event['from'], "Joining room {$room}@{$room_server} as {$nick}", $event['type']); 14 | } else { 15 | $conn->message($event['from'], "Usage: #join [room_server] [nick] [password]", $event['type']); 16 | } 17 | } 18 | ?> 19 | 20 | -------------------------------------------------------------------------------- /commands/jpeg.php: -------------------------------------------------------------------------------- 1 | responseData->results)) { 12 | $conn->message($event['from'], "Found image, JPEGing it...", $event['type']); 13 | $index = array_rand($response->responseData->results); 14 | $src = $response->responseData->results[$index]->unescapedUrl; 15 | $result = curl_post_get_contents("http://needsmorejpeg.com/process", array("image" => $src), null); 16 | print_r($result); 17 | if(preg_match("#/i/[0-9a-z]+\\.jpe?g#i", $result, $matches)) { 18 | print_r($matches); 19 | $jpeg = $matches[0]; 20 | $conn->message($event['from'], $response->responseData->results[$index]->titleNoFormatting . " - http://needsmorejpeg.com" . $jpeg, $event['type']); 21 | } else { 22 | $conn->message($event['from'], "Failed to JPEG :(", $event['type']); 23 | } 24 | } else { 25 | $conn->message($event['from'], "Nada.", $event['type']); 26 | } 27 | } else { 28 | $conn->message($event['from'], "Usage: #jpeg ", $event['type']); 29 | } 30 | } 31 | ?> 32 | -------------------------------------------------------------------------------- /commands/jpeg.txt: -------------------------------------------------------------------------------- 1 | Usage: #jpeg 2 | Google's a random image for the terms, then more jpegs it. 3 | -------------------------------------------------------------------------------- /commands/kick.php: -------------------------------------------------------------------------------- 1 | kickMember($room, $room_server, $nick, $message); 8 | } else { 9 | $conn->message($pl['from'], "Usage: #kick [message]", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/kirbydance.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "<(^.^<)", $pl['type']); 4 | sleep(1); 5 | $conn->message($pl['from'], "(>^.^)>", $pl['type']); 6 | sleep(1); 7 | $conn->message($pl['from'], "<(^.^<)", $pl['type']); 8 | sleep(1); 9 | $conn->message($pl['from'], "(>^.^)>", $pl['type']); 10 | sleep(1); 11 | $conn->message($pl['from'], "^( ^.^ )^", $pl['type']); 12 | } 13 | ?> 14 | -------------------------------------------------------------------------------- /commands/kirbydance.txt: -------------------------------------------------------------------------------- 1 | Do the Kirby dance! 2 | -------------------------------------------------------------------------------- /commands/lmgtfy.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Usage: #lmgtfy ", $event['type']); 5 | } else { 6 | $conn->message($event['from'], "http://lmgtfy.com/?q=" . urlencode(implode(" ",$params)), $event['type']); 7 | } 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/loic.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Targeting...", $event['type']); 5 | sleep(2); 6 | $conn->htmlmessage($event['from'], "{$params[0]} has been destroyed.", $event['type']); 7 | 8 | } else { 9 | $conn->message($event['from'], "Please enter a website to target", $event['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/loic.txt: -------------------------------------------------------------------------------- 1 | Usage: #loic [url] 2 | Fire the LOIC on [url]. -------------------------------------------------------------------------------- /commands/man.php: -------------------------------------------------------------------------------- 1 | message($pl['from'], "http://linux.die.net/man/1/" . strtolower($params[0]), $pl['type']); 5 | } else { 6 | $conn->message($pl['from'], "Usage: #man ", $pl['type']); 7 | } 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/math-old.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Calculator reset.", $event['type']); 10 | return; 11 | } 12 | 13 | // Ensure $math is defined 14 | if(!isset($math)) { 15 | $math = new EvalMath(); 16 | } 17 | 18 | // Show user defined variables and functions 19 | if($params[0] == "vars") { 20 | $vars = $math->vars(); 21 | $conn->message($event['from'], print_r($vars, true), $event['type']); 22 | return; 23 | } 24 | if($params[0] == "funcs") { 25 | $funcs = $math->funcs(); 26 | $conn->message($event['from'], print_r($funcs, true), $event['type']); 27 | return; 28 | } 29 | 30 | $expr = str_replace(",", "", implode(" ", $params)); 31 | $result = $math->evaluate($expr); 32 | if($result === false) { 33 | $conn->htmlmessage($event['from'], "

Error: " . htmlentities($math->last_error) . "

", $event['type']); 34 | } elseif(is_nan($result)) { 35 | $conn->htmlmessage($event['from'], "

NaN

", $event['type']); 36 | } elseif($result > 1000) { 37 | if($result > 9000 && $result < 10000) { 38 | $conn->message($event['from'], "OVER 9000! (" . number_format($result) . ")", $event['type']); 39 | } else { 40 | $conn->message($event['from'], number_format($result), $event['type']); 41 | } 42 | } else { 43 | $conn->message($event['from'], $result, $event['type']); 44 | } 45 | } else { 46 | $conn->message($event['from'], "Usage: #math ", $event['type']); 47 | } 48 | } 49 | ?> 50 | -------------------------------------------------------------------------------- /commands/math-old.txt: -------------------------------------------------------------------------------- 1 | Usage: #math-old 2 | Evaluates a mathematic expression. 3 | -------------------------------------------------------------------------------- /commands/math.php: -------------------------------------------------------------------------------- 1 | $mash_key)); 7 | $conn->message($event['from'], $response->raw_body, $event['type']); 8 | } else { 9 | $conn->message($event['from'], "Usage: #math ", $event['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/math.txt: -------------------------------------------------------------------------------- 1 | Usage: #math 2 | Evaluate a mathematical expression, solve an equation, or convert units and currencies 3 | -------------------------------------------------------------------------------- /commands/md5.php: -------------------------------------------------------------------------------- 1 | message($event['from'], "Usage: #md5 ", $event['type']); 5 | } else { 6 | $conn->message($event['from'], md5(implode(" ",$params)), $event['type']); 7 | } 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/movie.php: -------------------------------------------------------------------------------- 1 | paged = true; 7 | if (!empty($params[0])) { 8 | $param_str = implode(" ",$params); 9 | $movies = $db->search("movie", array("query" => $param_str)); 10 | if(!empty($movies)) { 11 | $html = ""; 12 | $text = ""; 13 | foreach($movies as $movie) { 14 | $html .= "
" . htmlentities($movie->title) . "
\n" . $movie->release_date . " - " . str_repeat("★", round($movie->vote_average / 2)) . str_repeat("☆", 5 - round($movie->vote_average / 2)); 15 | $text .= "\n" . htmlentities($movie->title) . "\n" . $movie->release_date . " - " . str_repeat("★", round($movie->vote_average / 2)) . str_repeat("☆", 5 - round($movie->vote_average / 2)); 16 | } 17 | $conn->htmlmessage($pl['from'], $html, $pl['type'], $text); 18 | } else { 19 | $conn->message($pl['from'], "Nada.", $pl['type']); 20 | } 21 | } else { 22 | $conn->message($pl['from'], "Usage: #movie ", $pl['type']); 23 | } 24 | } 25 | ?> 26 | -------------------------------------------------------------------------------- /commands/nick.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['nick'] = function(&$conn, $pl, $params) { 3 | global $room, $room_server, $nick; 4 | if (!empty($params[0])) { 5 | $nick = implode(" ",$params); 6 | if($pl['type'] != "groupchat") { 7 | $conn->message($pl['from'], "Changing nickname...", $pl['type']); 8 | } 9 | $conn->joinRoom($room, $room_server, $nick); 10 | } else { 11 | $conn->message($pl['from'], "Usage: #nick <Nickname>", $pl['type']); 12 | } 13 | } 14 | ?> 15 | -------------------------------------------------------------------------------- /commands/nooo.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['nooo'] = function(&$conn, $event, $params) { 3 | $conn->message($event['from'], "http://nooooooooooooooo.com/", $event['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/nslookup.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['nslookup'] = function(&$conn, $event, $params) { 3 | if(!empty($params[0])) { 4 | $result = gethostbyname($params[0]); 5 | if(!empty($result)) { 6 | $conn->message($event['from'], $result, $event['type']); 7 | } else { 8 | $conn->message($event['from'], "No matching hosts found.", $event['type']); 9 | } 10 | } else { 11 | $conn->message($event['from'], "Usage: #nslookup <host>", $event['type']); 12 | } 13 | } 14 | ?> 15 | -------------------------------------------------------------------------------- /commands/nutrition.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['nutrition'] = function(&$conn, $event, $params) { 3 | if(!empty($params[0])) { 4 | $search = strtolower(implode(" ", $params)); 5 | if($search == "pizza") { 6 | $conn->message($event['from'], "Bad", $event['type']); 7 | return; 8 | } 9 | $result =file_get_contents("https://api.nutritionix.com/v1_1/search/" . urlencode($search) . "?results=0:1&fields=item_name,brand_name,nf_calories,nf_total_fat,nf_trans_fatty_acid,nf_cholestorol,nf_sodium,nf_total_carbohydrate,nf_dietary_fiber,nf_sugars,nf_protein,nf_vitamin_a_dv,nf_vitamin_c_dv,nf_calcium_dv,nf_iron_dv,nf_serving_size_unit,nf_serving_size_qty,nf_serving_weight_grams&appId=39f195bb&appKey=580ad3c3d167b790a9bc80e4a9f0b299"); 10 | $result = json_decode($result); 11 | if(!empty($result->hits[0])) { 12 | $name = $result->hits[0]->fields->item_name; 13 | $brand = $result->hits[0]->fields->brand_name; 14 | 15 | $serving_size = $result->hits[0]->fields->nf_serving_size_qty . " " . $result->hits[0]->fields->nf_serving_size_unit; 16 | if ($result->hits[0]->fields->nf_serving_size_unit != "grams"){ 17 | $serving_size .= " (" . $result->hits[0]->fields->nf_serving_weight_grams . "g )"; 18 | } 19 | 20 | $protein = $result->hits[0]->fields->nf_protein; 21 | $fat = $result->hits[0]->fields->nf_total_fat; 22 | $calories = $result->hits[0]->fields->nf_calories; 23 | $tran = $result->hits[0]->fields->nf_trans_fatty_acid; 24 | $cholestorol = $result->hits[0]->fields->nf_cholestorol; 25 | $carbs = $result->hits[0]->fields->nf_total_carbohydrate; 26 | $fiber = $result->hits[0]->fields->nf_dietary_fiber; 27 | $sugars = $result->hits[0]->fields->nf_sugars; 28 | $sodium = $result->hits[0]->fields->nf_sodium; 29 | $vit_a = $result->hits[0]->fields->nf_vitamin_a_dv; 30 | $vit_c = $result->hits[0]->fields->nf_vitamin_c_dv; 31 | $calcium = $result->hits[0]->fields->nf_calcium_dv; 32 | $iron = $result->hits[0]->fields->nf_iron_dv; 33 | 34 | $html_text = "<br /><b>Name: </b>{$name}<br />"; 35 | $html_text .= "<b>Brand: </b>{$brand}<br />"; 36 | $html_text .= "<b>Serving Size: </b>{$serving_size}<br />"; 37 | if(!empty($calories)){ 38 | $html_text .= " <b>Calories: </b>{$calories}<br />"; 39 | } 40 | if(!empty($protein)){ 41 | $html_text .= " <b>Protein: </b>{$protein}g<br />"; 42 | } 43 | if(!empty($fat)){ 44 | $html_text .= "<b>Fat: </b>{$fat}g<br />"; 45 | } 46 | if(!empty($tran)){ 47 | $html_text .= "<b>Trans Fat:</b> {$tran}g<br />"; 48 | } 49 | if(!empty($cholestorol)){ 50 | $html_text .= "<b>Cholestorol:</b> {$cholestorol}g<br />"; 51 | } 52 | if(!empty($carbs)){ 53 | $html_text .= "<b>Carbs:</b> {$carbs}g<br />"; 54 | } 55 | if(!empty($fiber)){ 56 | $html_text .= " <b>Fiber: </b>{$fiber}g<br />"; 57 | } 58 | if(!empty($sugars)){ 59 | $html_text .= "<b>Sugars:</b> {$sugars}g<br />"; 60 | } 61 | if(!empty($sodium)){ 62 | $html_text .= "<b>Sodium:</b> {$sodium}mg<br />"; 63 | } 64 | if(!empty($vit_a)){ 65 | $html_text .= "<b>Vitamin A:</b> {$vit_a}% daily value<br />"; 66 | } 67 | if(!empty($vit_c)){ 68 | $html_text .= "<b>Vitamin C:</b> {$vit_c}% daily value<br />"; 69 | } 70 | if(!empty($calcium)){ 71 | $html_text .= "<b>Calcium:</b> {$calcium}% daily value<br />"; 72 | } 73 | if(!empty($iron)){ 74 | $html_text .= "<b>Iron:</b> {$vit_a}% daily value<br />"; 75 | } 76 | 77 | $conn->htmlmessage($event['from'], $html_text, $event['type']); 78 | } else { 79 | $conn->message($event['from'], "No nutritional data found.", $event['type']); 80 | } 81 | } else { 82 | $conn->message($event['from'], "Usage: #nutrition <food>", $event['type']); 83 | } 84 | } 85 | ?> -------------------------------------------------------------------------------- /commands/p.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['p'] = function(&$conn, $event, $params) { 3 | global $chat_factory, $chat_p, $chat_session_p; 4 | 5 | if(!isset($chat_factory)) 6 | $chat_factory = new ChatterBotFactory(); 7 | if(!isset($chat_p)) 8 | $chat_p = $chat_factory->create(ChatterBotType::PANDORABOTS, 'cca4a7a23e347bc7'); // b0dafd24ee35a477 9 | if(!isset($chat_session_p)) 10 | $chat_session_p = $chat_p->createSession(); 11 | 12 | if (!empty($params[0])) { 13 | $param_str = implode(" ",$params); 14 | $response = $chat_session_p->think($param_str); 15 | $response = strip_tags(str_replace(array("<br />","<br>","<br/>"),"\r\n",$response)); 16 | echo "Response: " . trim($response) . "\n"; 17 | $conn->message($event['from'], trim($response), $event['type']); 18 | } else { 19 | $conn->message($event['from'], "Usage: #p <words, yo>", $event['type']); 20 | } 21 | } 22 | ?> 23 | -------------------------------------------------------------------------------- /commands/p.txt: -------------------------------------------------------------------------------- 1 | Usage: #p <message> 2 | Sends a message to the Hashbot PandoraBot and returns the response. -------------------------------------------------------------------------------- /commands/part.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['part'] = function(&$conn, $pl, $params) { 3 | global $room, $room_server, $nick, $room_password; 4 | 5 | // Don't allow a group message to kill the bot 6 | if($pl['type'] == "chat") { 7 | if(strpos($pl['from'],"ahardman") !== false) { 8 | $conn->message($pl['from'], "/me leaves the room", $pl['type']); 9 | $status = null; 10 | if(!empty($params[0])) { 11 | $status = implode(" ", $params); 12 | } 13 | $conn->leaveRoom($room, $room_server, $nick, $status); 14 | } 15 | } else { 16 | $conn->message($pl['from'], "This command tells me to leave the room. Only my master can use it.", $pl['type']); 17 | } 18 | } 19 | ?> 20 | -------------------------------------------------------------------------------- /commands/password.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands["password"] = function(&$conn, $event, $params) use ($wordlist) { 3 | if(empty($wordlist)) { 4 | $wordfile = file_get_contents(dirname(__FILE__) . "/../res/wordlist.txt"); 5 | $wordlist = explode(",", $wordfile); 6 | } 7 | 8 | $words = $wordlist; 9 | 10 | shuffle($words); 11 | shuffle($nums); 12 | 13 | // Start with two words 14 | $pass = ucfirst($words[0]) . ucfirst($words[1]); 15 | 16 | $len = 15; 17 | if(!empty($params[0]) && is_numeric($params[0])) { 18 | if($params[0] > 200) { 19 | $conn->message($event["from"], "Maximum length is 200 characters.", $event["type"]); 20 | return; 21 | } 22 | $len = intval($params[0]); 23 | } 24 | 25 | $i = 2; 26 | while(strlen($pass) < $len) { 27 | $pass .= ucfirst($words[$i]); 28 | $i++; 29 | } 30 | 31 | if(rand(0,1)) { 32 | $pass .= rand(0,9); 33 | } 34 | 35 | $conn->message($event["from"], $pass, $event["type"]); 36 | } 37 | ?> 38 | -------------------------------------------------------------------------------- /commands/php.php: -------------------------------------------------------------------------------- 1 | <?php 2 | include_once dirname(__FILE__) . '/../lib/phpQuery-onefile.php'; 3 | $commands['php'] = function(&$conn, $event, $params) { 4 | if(!empty($params[0])) { 5 | $html = file_get_contents("http://www.php.net/manual/en/function." . str_replace("_", "-", $params[0]) . ".php"); 6 | $doc = phpQuery::newDocumentHtml($html); 7 | 8 | // Function type/name/params 9 | $msg = "<span style='color: #693;'>" . $doc['.methodsynopsis > .type']->text() . "</span> "; 10 | $function_name = $doc['.methodsynopsis .methodname']->text(); 11 | $msg .= "<a href='http://php.net/" . str_replace("_", "-", $function_name) . "'>{$function_name}</a> "; 12 | $msg .= "<span style='color: #737373;'>( "; 13 | foreach($doc['.methodsynopsis .methodparam'] as $i=>$param) { 14 | $p = pq($param); 15 | $optional = !!$p->find(".initializer")->text(); 16 | 17 | if($i) { 18 | if($optional) { 19 | $msg .= " [, "; 20 | } else { 21 | $msg .= " , "; 22 | } 23 | } elseif($optional) { 24 | $msg .= "["; 25 | } 26 | 27 | $msg .= htmlspecialchars($p->text()); 28 | 29 | if($optional) { 30 | $msg .= " ]"; 31 | } 32 | } 33 | $msg .= " )</span>"; 34 | 35 | // Add description 36 | foreach($doc['.refsect1.description .para'] as $para) { 37 | $msg .= "<br />\n" . htmlspecialchars(trim(preg_replace(array("/[^(\x20-\x7F)]*/", "/\s+/"), array("", " "), pq($para)->text()))); 38 | } 39 | 40 | echo $msg; 41 | 42 | $conn->htmlmessage($event['from'], $msg, $event['type']); 43 | } else { 44 | $conn->message($event['from'], "Usage: #php <function name>", $event['type']); 45 | } 46 | 47 | } 48 | ?> 49 | -------------------------------------------------------------------------------- /commands/ping.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['ping'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $response = Unirest::get("http://phpizza.com/~alan/ping.php?host=" . urlencode($params[0])); 6 | if($response->body->online) { 7 | $output = "Online - " . $response->body->ping; 8 | } else { 9 | $output = "Unable to connect to host."; 10 | } 11 | $conn->message($pl['from'], $output, $pl['type']); 12 | } else { 13 | $conn->message($pl['from'], "Usage: #ping <host>", $pl['type']); 14 | } 15 | } 16 | ?> 17 | -------------------------------------------------------------------------------- /commands/ping.txt: -------------------------------------------------------------------------------- 1 | Usage: #ping <host> 2 | Ping a host to check its online status and latency. -------------------------------------------------------------------------------- /commands/ping_native.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['ping_native'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | 5 | // Filter server string 6 | $host = preg_replace("/[^a-z0-9\\.-]/i", "", $params[0]); 7 | if(!$host) { 8 | $conn->message($event['from'], "Invalid host.", $event['type']); 9 | return false; 10 | } 11 | 12 | // Check if on Windows 13 | $win = (strncasecmp(PHP_OS, 'WIN', 3) == 0); 14 | 15 | // Get [count] parameter 16 | if(!empty($params[1])) { 17 | $count = intval($params[1]); 18 | } else { 19 | $count = 1; 20 | } 21 | 22 | // Run command 23 | $ph = popen("ping -" . ($win ? "n" : "c") . " {$count} {$host}", "r"); 24 | while (! feof($ph)) { 25 | $str = trim(fgets($ph, 1024)); 26 | if($str && !preg_match("/Ping statistics for|Approximate round trip times|ping statistics/", $str)) { 27 | $conn->message($event['from'], $str, $event['type']); 28 | } 29 | } 30 | pclose($ph); 31 | } else { 32 | $conn->message($event['from'], "Usage: #ping_native <server> [count]", $event['type']); 33 | } 34 | } 35 | ?> 36 | -------------------------------------------------------------------------------- /commands/ping_native.txt: -------------------------------------------------------------------------------- 1 | Usage: #ping_native <host> [count] 2 | Ping a host using the bot's system's native ping tool. If count is not specified, the server will be pinged 5 times. 3 | No response is given until the system's program exits, so an offline host will cause the command to pause the bot until all ping requests time out. -------------------------------------------------------------------------------- /commands/pirate.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['pirate'] = function(&$conn, $pl, $params) { 3 | if (!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | $response = file_get_contents("http://isithackday.com/arrpi.php?text=" . urlencode($param_str)); 6 | $conn->message($pl['from'], $response, $pl['type']); 7 | } else { 8 | $conn->message($pl['from'], "Usage: #pirate <sentence>", $pl['type']); 9 | } 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/pirate.txt: -------------------------------------------------------------------------------- 1 | Usage: #pirate <sentence> 2 | Converts the sentence to pirate speak! Arrg! -------------------------------------------------------------------------------- /commands/pizzatime.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['pizzatime'] = function(&$conn, $event, $params) { 3 | $ascii = <<<EOT 4 | 5 | //\\ PPPPP IIII ZZZZZ ZZZZZ A 6 | // O \\ PP PP II ZZ ZZ A A 7 | || O o \\ PPPPP II ZZ ZZ AAAAA 8 | ||__o__O__\\ PP IIII ZZZZZ ZZZZZ A A 9 | EOT; 10 | $ascii_array = explode("\n", $ascii); 11 | $conn->htmlmessage($event['from'], nl2br("\n") . "<p style='font-family: monospace;'>" . nl2br($ascii) . "</p>", $event['type']); 12 | } 13 | ?> 14 | -------------------------------------------------------------------------------- /commands/poll.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['poll'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | switch($params[0]) { 5 | case "new": 6 | if(empty($params[1])) { 7 | $conn->message($event['from'], "Usage: #poll new [choice1, choice2, ...]" . implode("\n", $stats), $event['type']); 8 | return; 9 | } 10 | if(isset($GLOBALS['poll'])) { 11 | $conn->message($event['from'], "There is already a running poll. The creator of the current poll can end it with #poll end." . implode("\n", $stats), $event['type']); 12 | return; 13 | } 14 | break; 15 | case "end": 16 | if(isset($GLOBALS['poll'])) { 17 | $conn->message($event['from'], "There is already a running poll. The creator of the current poll can end it with #poll end." . implode("\n", $stats), $event['type']); 18 | return; 19 | } 20 | break; 21 | case "vote": 22 | if(empty($params[1])) { 23 | $conn->message($event['from'], "Usage: #poll vote <choice #>" . implode("\n", $stats), $event['type']); 24 | return; 25 | } 26 | break; 27 | } 28 | } else { 29 | if(isset($GLOBALS['poll'])) { 30 | $stats = array(); 31 | $conn->message($event['from'], "Current poll statistics: " . implode("\n", $stats), $event['type']); 32 | } else { 33 | $conn->message($event['from'], "No open polls. Use \"#poll new [choice1, choice2, ...]\" to start a new poll.", $event['type']); 34 | } 35 | } 36 | }; 37 | -------------------------------------------------------------------------------- /commands/prime.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['prime'] = function(&$conn, $pl, $params) { 3 | if(!empty($params[0]) && intval($params[0]) > 0) { 4 | 5 | $n = intval($params[0]); 6 | 7 | if($n > 10000000) { 8 | $conn->message($pl['from'], "Max allowed: 10,000,000", $pl['type']); 9 | return; 10 | } 11 | 12 | $max = "No prime number found"; 13 | 14 | switch($n) { 15 | case 1: 16 | break; 17 | case 2: 18 | case 3: 19 | $max = $n; 20 | break; 21 | default: 22 | // Give more memory if generating massive primes 23 | if($n > 3000000) { 24 | ini_set("memory_limit", "512M"); 25 | } 26 | 27 | // Adapted from http://damianoferrari.com/php-prime-number-generator/ 28 | if ($n < 5) { 29 | return (($n < 2) ? false : (($n < 3) ? array(2) : array(2, 3))); 30 | } 31 | 32 | $primes = range(3, $n, 2); 33 | for ($i = 0, $sqrtN = sqrt($n), $pTot = count($primes); $j = 0, $k = $primes[$i], $k <= $sqrtN; $i++) { 34 | if ($k == null) { 35 | continue; 36 | } 37 | while (++$j * $k < $pTot) { 38 | $primes[$j * $k + $i] = null; 39 | } 40 | } 41 | 42 | array_unshift($primes, 2); 43 | $result = array_values(array_filter($primes)); 44 | 45 | $max = $result[count($result) - 1]; 46 | } 47 | 48 | if(!empty($params[1]) && intval($params[1]) && isset($result)) { 49 | $display_result = array_slice($result, -$params[1]); 50 | $conn->message($pl['from'], implode(", ", $display_result), $pl['type']); 51 | } else { 52 | $conn->message($pl['from'], $max, $pl['type']); 53 | } 54 | 55 | } else { 56 | $conn->message($pl['from'], "Usage: #prime <max> [count]", $pl['type']); 57 | } 58 | } 59 | ?> 60 | -------------------------------------------------------------------------------- /commands/q.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['q'] = function(&$conn, $pl, $params) { 3 | if (!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | $url = "http://www.faroo.com/api?q=" . urlencode($param_str) . "&length=1&l=en&src=web&i=false&f=json"; 6 | $result = json_decode(file_get_contents($url), true); 7 | if (isset($result['results'][0])) { 8 | $top = $result['results'][0]; 9 | $conn->message($pl['from'], $top['title'] . " " . $top['url'], $pl['type']); 10 | } else { 11 | $conn->message($pl['from'], "Nothing found!", $pl['type']); 12 | } 13 | } else { 14 | $conn->message($pl['from'], "Usage: #q <search terms>", $pl['type']); 15 | } 16 | } 17 | ?> 18 | -------------------------------------------------------------------------------- /commands/q.txt: -------------------------------------------------------------------------------- 1 | Usage: #q <search terms> 2 | Queries the Faroo Search API and returns the first result. 3 | Some day I will switch this to use Google. -------------------------------------------------------------------------------- /commands/qr.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['qr'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $param_str = implode(" ",$params); 6 | $response = Unirest::get("https://mutationevent-qr-code-generator.p.mashape.com/generate.php?content=" . urlencode($param_str), array("X-Mashape-Authorization" => $mash_key)); 7 | $conn->message($pl['from'], $response->body->image_url, $pl['type']); 8 | } else { 9 | $conn->message($pl['from'], "Usage: #qr <text>", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/qr.txt: -------------------------------------------------------------------------------- 1 | Usage: #qr <text> 2 | Generates a QR code of the given text. -------------------------------------------------------------------------------- /commands/quote.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['quote'] = function(&$conn, $event, $params) { 3 | $response = curl_get_contents("http://www.iheartquotes.com/api/v1/random?max_lines=1&show_source=false&show_permalink=false"); 4 | $conn->message($event['from'], trim($response), $event['type']); 5 | } 6 | ?> 7 | -------------------------------------------------------------------------------- /commands/rainbow.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rainbow'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | $text = implode(" ",$params); 5 | $ret = ""; 6 | $colors = array( 7 | 'ff00ff', 8 | 'ff00cc', 9 | 'ff0099', 10 | 'ff0066', 11 | 'ff0033', 12 | 'ff0000', 13 | 'ff3300', 14 | 'ff6600', 15 | 'ff9900', 16 | 'ffcc00', 17 | 'ffff00', 18 | 'ccff00', 19 | '99ff00', 20 | '66ff00', 21 | '33ff00', 22 | '00ff00', 23 | '00ff33', 24 | '00ff66', 25 | '00ff99', 26 | '00ffcc', 27 | '00ffff', 28 | '00ccff', 29 | '0099ff', 30 | '0066ff', 31 | '0033ff', 32 | '0000ff', 33 | '3300ff', 34 | '6600ff', 35 | '9900ff', 36 | 'cc00ff' 37 | ); 38 | $i = 0; 39 | $textlength = strlen($text); 40 | while($i <= $textlength) { 41 | foreach($colors as $value) { 42 | if ($text[$i] != "") { 43 | $ret .= '<span style="color:#'.$value.';">' . htmlentities($text[$i]) . "</span>"; 44 | } 45 | $i++; 46 | } 47 | } 48 | 49 | $conn->htmlmessage($event['from'], $ret, $event['type'], "Your client does not support rainbows. Lame."); 50 | } else { 51 | $conn->message($event['from'], "Usage: #rainbow <words, yo>", $event['type']); 52 | } 53 | } 54 | ?> -------------------------------------------------------------------------------- /commands/rainbowshout.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rainbowshout'] = function(&$conn, $event, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | if($params[0] == "fonts") { 6 | $response = curl_get_contents("https://artii.herokuapp.com/fonts_list"); 7 | $response = implode(", ", explode("\n", $response)); 8 | $conn->message($event['from'], "\n" . $response, $event['type']); 9 | } elseif(substr($params[0], 0, 5) == "font=") { 10 | $font = substr($params[0], 5); 11 | unset($params[0]); 12 | $param_str = implode(" ",$params); 13 | $response = curl_get_contents("https://artii.herokuapp.com/make?text=" . urlencode($param_str) . "&font=" . urlencode($font)); 14 | } else { 15 | $param_str = implode(" ",$params); 16 | $response = curl_get_contents("https://artii.herokuapp.com/make?text=" . urlencode($param_str)); 17 | } 18 | if (!empty($response)) { 19 | $lines = explode("\n", $response); 20 | foreach($lines as $text) { 21 | $text = rtrim($text); 22 | $ret = ""; 23 | $colors = array('ff00ff', 'ff00cc', 'ff0099', 'ff0066', 'ff0033', 'ff0000', 'ff3300', 'ff6600', 'ff9900', 'ffcc00', 'ffff00', 'ccff00', '99ff00', '66ff00', '33ff00', '00ff00', '00ff33', '00ff66', '00ff99', '00ffcc', '00ffff', '00ccff', '0099ff', '0066ff', '0033ff', '0000ff', '3300ff', '6600ff', '9900ff', 'cc00ff'); 24 | $i = 0; 25 | $textlength = strlen($text); 26 | while($i <= $textlength) { 27 | foreach($colors as $value) { 28 | if ($text[$i] == " ") { 29 | $ret = " "; 30 | } elseif ($text[$i] != "") { 31 | $ret .= '<span style="color:#'.$value.';">' . htmlentities($text[$i]) . "</span>"; 32 | } 33 | $i++; 34 | } 35 | } 36 | 37 | echo $ret; 38 | 39 | $conn->htmlmessage($event['from'], $ret, $event['type'], rtrim($text)); 40 | } 41 | } 42 | } else { 43 | $conn->message($event['from'], "Usage: #shout [fonts|font=font] <words, yo>", $event['type']); 44 | } 45 | } 46 | ?> 47 | -------------------------------------------------------------------------------- /commands/rainbowshout2.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rainbowshout2'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | $text = implode(" ",$params); 5 | $ret = ""; 6 | $colors = array( 7 | 'ff00ff', 8 | 'ff00cc', 9 | 'ff0099', 10 | 'ff0066', 11 | 'ff0033', 12 | 'ff0000', 13 | 'ff3300', 14 | 'ff6600', 15 | 'ff9900', 16 | 'ffcc00', 17 | 'ffff00', 18 | 'ccff00', 19 | '99ff00', 20 | '66ff00', 21 | '33ff00', 22 | '00ff00', 23 | '00ff33', 24 | '00ff66', 25 | '00ff99', 26 | '00ffcc', 27 | '00ffff', 28 | '00ccff', 29 | '0099ff', 30 | '0066ff', 31 | '0033ff', 32 | '0000ff', 33 | '3300ff', 34 | '6600ff', 35 | '9900ff', 36 | 'cc00ff' 37 | ); 38 | $i = 0; 39 | $textlength = strlen($text); 40 | while($i <= $textlength) { 41 | foreach($colors as $value) { 42 | if ($text[$i] != "") { 43 | $ret .= '<span style="color:#'.$value.';">' . htmlentities($text[$i]) . "</span>"; 44 | } 45 | $i++; 46 | } 47 | } 48 | 49 | $conn->htmlmessage($event['from'], "<p style='font-size:xx-large;font-weight:bold;background:#000;'>" . $ret . "</p>", $event['type'], "Your client does not support rainbows. Lame."); 50 | } else { 51 | $conn->message($event['from'], "Usage: #rainbowshout2 <words, yo>", $event['type']); 52 | } 53 | } 54 | ?> 55 | -------------------------------------------------------------------------------- /commands/rand.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rand'] = function(&$conn, $event, $params) { 3 | if(empty($params)) { 4 | $val = rand(); 5 | } elseif(isset($params[1]) && is_numeric($params[0]) && is_numeric($params[1])) { 6 | $val = rand(intval($params[0]), intval($params[1])); 7 | } elseif(isset($params[0]) && is_numeric($params[0])) { 8 | $val = rand(1, intval($params[0])); 9 | } 10 | if(isset($val)) { 11 | $conn->message($event['from'], $val, $event['type']); 12 | } else { 13 | $conn->message($event['from'], "Usage: #rand [max] OR #rand [min] [max]", $event['type']); 14 | } 15 | } 16 | ?> 17 | -------------------------------------------------------------------------------- /commands/rand.txt: -------------------------------------------------------------------------------- 1 | Usage: #rand [max] OR #rand [min] [max] 2 | Generates a random number between 1 and max, min and max, or 0 and getrandmax() 3 | -------------------------------------------------------------------------------- /commands/randuser.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['randuser'] = function(&$conn, $event, $params) { 3 | try { 4 | $result = json_decode(curl_get_contents("http://api.randomuser.me/")); 5 | $user = $result->results[0]->user; 6 | } catch (Exception $e) { 7 | $conn->message($event['from'], "API call failed.", $event['type']); 8 | @print_r($result); 9 | return false; 10 | } 11 | 12 | // Build text response 13 | $text = '<a href="' . $user->picture->large . '">' . ucwords($user->name->first . " " . $user->name->last) . "</a><br />\n"; 14 | $text .= "Email: " . $user->email . "<br />\n"; 15 | $text .= "Phone: " . $user->phone; 16 | 17 | $conn->htmlmessage($event['from'], $text, $event['type']); 18 | } 19 | ?> 20 | -------------------------------------------------------------------------------- /commands/rdns.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rdns'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | // Use gethostbyaddr() for local addresses 6 | if(preg_match("/^192|127|169\\./", $params[0])) { 7 | $conn->message($pl['from'], gethostbyaddr($params[0]), $pl['type']); 8 | } else { 9 | $response = Unirest::get("https://mark-sutuer-ip-utils.p.mashape.com/api.php?_method=resolveIp&address=" . urlencode($params[0]), array("X-Mashape-Authorization" => $mash_key)); 10 | $conn->message($pl['from'], $response->body->host, $pl['type']); 11 | } 12 | } else { 13 | $conn->message($pl['from'], "Usage: #rdns <ip address>", $pl['type']); 14 | } 15 | } 16 | ?> 17 | -------------------------------------------------------------------------------- /commands/rdns.txt: -------------------------------------------------------------------------------- 1 | Usage: #rdns <ip address> 2 | Runs a reverse DNS lookup on the given IP. -------------------------------------------------------------------------------- /commands/rebuild.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rebuild'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | $conn->message($event['from'], "Rebuilding...", $event['type']); 5 | sleep(2); 6 | $conn->htmlmessage($event['from'], "<a href='http://0.0.0.0'>{$params[0]}</a> has been rebuilt from a loic blast", $event['type']); 7 | 8 | } else { 9 | $conn->message($event['from'], "Please enter a website to rebuild", $event['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/rebuild.txt: -------------------------------------------------------------------------------- 1 | Usage: #rebuild [url] 2 | Rebuild a area destory by the LOIC on [url]. -------------------------------------------------------------------------------- /commands/rejoin.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['rejoin'] = function(&$conn, $pl, $params) { 3 | global $room, $room_server, $nick, $room_password; 4 | $param_str = implode(" ",$params); 5 | $conn->message($pl['from'], "Rejoining room...", $pl['type']); 6 | $conn->joinRoom($room, $room_server, $nick, $room_password); 7 | } 8 | ?> 9 | -------------------------------------------------------------------------------- /commands/reload.php: -------------------------------------------------------------------------------- 1 | <?php 2 | // Messy, but it should work :P 3 | include dirname(__FILE__) . '/../config.php'; 4 | $commands['reload'] = function(&$conn, $pl, $params) { 5 | $conn->message($pl['from'], "Configuration reloaded.", $pl['type']); 6 | } 7 | ?> 8 | -------------------------------------------------------------------------------- /commands/reload.txt: -------------------------------------------------------------------------------- 1 | Usage: #reload 2 | Reloads bot configuration. -------------------------------------------------------------------------------- /commands/say.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['say'] = function(&$conn, $event, $params) { 3 | if(empty($params)) { 4 | $conn->message($event['from'], "Usage: #say <message>", $event['type']); 5 | } elseif ($params[0]{0} == "#") { 6 | $conn->message($event['from'], "Nope :P", $event['type']); 7 | } else { 8 | $conn->message($event['from'], implode(" ",$params), $event['type']); 9 | } 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/say.txt: -------------------------------------------------------------------------------- 1 | Usage: #say <message> 2 | Instructs the bot to say a message back to the current user or group. -------------------------------------------------------------------------------- /commands/scream.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['scream'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $param_str = implode(" ",$params); 6 | $response = curl_get_contents("https://artii.herokuapp.com/make?font=doh&text=" . urlencode($param_str)); 7 | $conn->message($pl['from'], "\n" . rtrim($response), $pl['type']); 8 | } else { 9 | $conn->message($pl['from'], "Usage: #scream <words of fury>", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/scrumtime.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['scrumtime'] = function(&$conn, $pl, $params) { 3 | $colors = array( 4 | 'ff00ff', 5 | 'ff0066', 6 | 'ff3300', 7 | 'ffcc00', 8 | '99ff00', 9 | '00ff00', 10 | '00ff99', 11 | '00ccff', 12 | '0033ff', 13 | '6600ff', 14 | ); 15 | foreach(str_split("SCRUMTIME!") as $i=>$char) { 16 | $conn->htmlmessage($pl['from'], "<p style='font-size: large; font-weight: bold; color:#{$colors[$i]}; background: #000; padding:0 60px;'> $char </p>", $pl['type']); 17 | usleep(90000); 18 | } 19 | }; 20 | -------------------------------------------------------------------------------- /commands/sha1.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['sha1'] = function(&$conn, $event, $params) { 3 | if(empty($params)) { 4 | $conn->message($event['from'], "Usage: #sha1 <string>", $event['type']); 5 | } else { 6 | $conn->message($event['from'], sha1(implode(" ",$params)), $event['type']); 7 | } 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/shout.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /* Need to add formatting to the message so I don't have to use monospace for everything 4 | <message type='chat' id='purplefdf1031f' to='hashbot@chat.shelfreliance.com/hashbot'> 5 | <body>cool</body> 6 | <html xmlns='http://jabber.org/protocol/xhtml-im'> 7 | <body xmlns='http://www.w3.org/1999/xhtml'> 8 | <p> 9 | <span style='font-family: Raavi;'>cool</span> 10 | </p> 11 | </body> 12 | </html> 13 | </message> */ 14 | 15 | $commands['shout'] = function(&$conn, $event, $params) { 16 | global $mash_key; 17 | if (!empty($params[0])) { 18 | if($params[0] == "fonts") { 19 | $response = curl_get_contents("https://artii.herokuapp.com/fonts_list"); 20 | $response = implode(", ", explode("\n", $response)); 21 | $conn->message($event['from'], "\n" . $response, $event['type']); 22 | } elseif(substr($params[0], 0, 5) == "font=") { 23 | $font = substr($params[0], 5); 24 | unset($params[0]); 25 | $param_str = implode(" ",$params); 26 | $response = curl_get_contents("https://artii.herokuapp.com/make?text=" . urlencode($param_str) . "&font=" . urlencode($font)); 27 | $conn->htmlmessage($event['from'], "<br /><p style='font-family: monospace;'> " . nl2br(htmlentities(rtrim($response))) . '</p>', $event['type'], "\n" . rtrim($response)); 28 | } else { 29 | $param_str = implode(" ",$params); 30 | $response = curl_get_contents("https://artii.herokuapp.com/make?text=" . urlencode($param_str)); 31 | $conn->htmlmessage($event['from'], "<br /><p style='font-family: monospace;'> " . nl2br(htmlentities(rtrim($response))) . '</p>', $event['type'], "\n" . rtrim($response)); 32 | } 33 | } else { 34 | $conn->message($event['from'], "Usage: #shout [fonts|font=font] <words, yo>", $event['type']); 35 | } 36 | } 37 | ?> 38 | -------------------------------------------------------------------------------- /commands/shout.txt: -------------------------------------------------------------------------------- 1 | Usage: #shout <words, yo> 2 | Prints the given words in ASCII Art. Support for additional fonts is coming soon. -------------------------------------------------------------------------------- /commands/shout2.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['shout2'] = function(&$conn, $event, $params) { 3 | if(empty($params)) { 4 | $conn->message($event['from'], "Usage: #shout2 <message>", $event['type']); 5 | } elseif ($params[0]{0} == "#") { 6 | $conn->message($event['from'], "Wat.", $event['type']); 7 | } else { 8 | $conn->htmlmessage($event['from'], "<p><span style='font-size:xx-large;font-weight:bold;color:yellow;background:#444;'>" . htmlentities(implode(" ", $params)) . "</span></p>", $event['type']); 9 | } 10 | } 11 | ?> 12 | -------------------------------------------------------------------------------- /commands/showme.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['showme'] = function(&$conn, $event, $params) { 3 | if(!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | $url = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&q=" . urlencode($param_str); 6 | $body = curl_get_contents($url); 7 | $response = json_decode($body); 8 | if(!empty($response->responseData->results)) { 9 | $index = array_rand($response->responseData->results); 10 | $conn->message($event['from'], $response->responseData->results[$index]->titleNoFormatting . " - " . $response->responseData->results[$index]->unescapedUrl, $event['type']); 11 | 12 | /*$text = $response->responseData->results[$index]->titleNoFormatting . " - " . $response->responseData->results[$index]->unescapedUrl; 13 | $html = "<p>" . htmlentities($response->responseData->results[$index]->titleNoFormatting) . "</p><p><img src='" . htmlentities($response->responseData->results[$index]->unescapedUrl) . "' /></p>"; 14 | 15 | $conn->htmlmessage($event['from'], $html, $event['type'], $text);*/ 16 | 17 | } else { 18 | $conn->message($event['from'], "Nada.", $event['type']); 19 | } 20 | } else { 21 | $conn->message($event['from'], "Usage: #showme <search terms>", $event['type']); 22 | } 23 | } 24 | ?> 25 | -------------------------------------------------------------------------------- /commands/showme.txt: -------------------------------------------------------------------------------- 1 | Usage: #showme <search terms> 2 | Returns a random result from the first page of a Google Images search for the given terms. -------------------------------------------------------------------------------- /commands/shuffle.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['shuffle'] = function(&$conn, $event, $params) { 3 | if (isset($params[1])) { 4 | shuffle($params); 5 | $conn->message($event['from'], implode(" ", $params), $event['type']); 6 | } elseif (isset($params[0])) { 7 | $conn->message($event['from'], str_shuffle($params[0]), $event['type']); 8 | } else { 9 | $conn->message($event['from'], "Usage: #shuffle <word> [word]", $event['type']); 10 | } 11 | }; 12 | -------------------------------------------------------------------------------- /commands/slap.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['slap'] = function(&$conn, $pl, $params) { 3 | if (!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | 6 | $short_from = mb_substr($pl['realfrom'], 0, mb_strpos($pl['realfrom'], "@")); 7 | if ($pl['type'] == "groupchat" && mb_strpos($pl['realfrom'],"/")) { 8 | $short_from = mb_substr($pl['realfrom'], mb_strpos($pl['realfrom'], "/") + 1); 9 | } 10 | 11 | $conn->message($pl['from'], $short_from . " slaps " . $param_str, $pl['type']); 12 | } else { 13 | $conn->message($pl['from'], "Usage: #slap <name>", $pl['type']); 14 | } 15 | } 16 | ?> -------------------------------------------------------------------------------- /commands/so.php: -------------------------------------------------------------------------------- 1 | <?php 2 | # https://api.stackexchange.com/2.1/search 3 | $commands['so'] = function(&$conn, $pl, $params) { 4 | $conn->message($pl['from'], "It's failing for some reason, I'll fix it later.", $pl['type']); 5 | return; 6 | if (!empty($params[0])) { 7 | $param_str = implode(" ", $params); 8 | //$tags = implode(";", $params); 9 | $url = "https://api.stackexchange.com/2.1/search?sort=relevance&site=stackoverflow&intitle=" . urlencode($param_str); // . "&tagged=" . urlencode($tags); 10 | $json = file_get_contents($url); 11 | echo $json; 12 | $response = json_decode($json, true); 13 | file_put_contents("C:/Alan/GitHub/chatbot.log", print_r($response,true)); 14 | print_r($response); 15 | if (isset($response['items'][0])) { 16 | $top = $response['items'][0]; 17 | $conn->message($pl['from'], $top['title'] . " " . $top['link'], $pl['type']); 18 | } else { 19 | $conn->message($pl['from'], "Nothing found!", $pl['type']); 20 | } 21 | } else { 22 | $conn->message($pl['from'], "Usage: #so <search terms>", $pl['type']); 23 | } 24 | } 25 | ?> 26 | -------------------------------------------------------------------------------- /commands/startup.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['startup'] = function(&$conn, $pl, $params) { 3 | $response = json_decode(file_get_contents("http://itsthisforthat.com/api.php?json")); 4 | $conn->message($pl['from'], $response->this . " for " . $response->that, $pl['type']); 5 | } 6 | ?> 7 | -------------------------------------------------------------------------------- /commands/startup.txt: -------------------------------------------------------------------------------- 1 | Usage: #startup 2 | Generates a (usually stupid) startup idea. -------------------------------------------------------------------------------- /commands/sudo.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['sudo'] = function(&$conn, $pl, $params) { 3 | if(!empty($params[0])) { 4 | $conn->message($pl['from'], "Okay.", $pl['type']); 5 | } else { 6 | $conn->message($pl['from'], "Usage: #sudo <command>", $pl['type']); 7 | } 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/sudo.txt: -------------------------------------------------------------------------------- 1 | Usage: #sudo <command> 2 | Runs a command as the root user. Sort of. -------------------------------------------------------------------------------- /commands/tell.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['tell'] = function(&$conn, $pl, $params) { 3 | global $room, $room_server; 4 | if(!empty($params[0])) { 5 | $to = $params[0]; 6 | unset($params[0]); 7 | 8 | // Convert alternate forms to complete names 9 | if($to == "groupchat") { 10 | $to = $room . "@" . $room_server; 11 | } 12 | if($to == $room . "@" . $room_server) { 13 | $pl['type'] = "groupchat"; 14 | } 15 | if(!strpos($to, "@")) { 16 | $to = $to . "@" . $server; 17 | } 18 | 19 | try { 20 | $conn->message($to, implode(" ",$params), $pl['type']); 21 | } catch(Exception $ex) { 22 | var_dump($ex); 23 | $conn->message($pl['from'], "Fatal Error! See console for details.", $pl['type']); 24 | } 25 | } else { 26 | $conn->message($pl['from'], "Usage: #tell <user[@host]|groupchat> <message>", $pl['type']); 27 | } 28 | } 29 | ?> 30 | -------------------------------------------------------------------------------- /commands/tell.txt: -------------------------------------------------------------------------------- 1 | Usage: #tell <user[@host]|groupchat> <message> 2 | Sends a message to a specific user or to the currently connected group. -------------------------------------------------------------------------------- /commands/time.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['time'] = function(&$conn, $pl, $params) { 3 | global $timezone; 4 | date_default_timezone_set($timezone); 5 | $conn->message($pl['from'], date("r"), $pl['type']); 6 | } 7 | ?> 8 | -------------------------------------------------------------------------------- /commands/timer.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['timer'] = function(&$conn, $pl, $params) { 3 | global $timer; 4 | 5 | if(!empty($timer)) { 6 | $init = time() - $timer; 7 | $hours = floor($init / 3600); 8 | $minutes = floor(($init / 60) % 60); 9 | $seconds = $init % 60; 10 | $str = sprintf("%02d:%02d:%02d", $hours, $minutes, $seconds); 11 | } 12 | 13 | if (empty($params[0])) { 14 | if (!empty($timer)) { 15 | $conn->message($pl['from'], "Timer running: $str", $pl['type']); 16 | } else { 17 | $conn->message($pl['from'], "Timer isn't running!", $pl['type']); 18 | } 19 | } elseif ($params[0] == "start") { 20 | $timer = time(); 21 | $conn->message($pl['from'], "Starting timer", $pl['type']); 22 | } elseif ($params[0] == "stop") { 23 | if (!empty($timer)) { 24 | $conn->message($pl['from'], "Timer stopped. Time: $str", $pl['type']); 25 | $timer = 0; 26 | unset($timer); 27 | } else { 28 | $conn->message($pl['from'], "Timer isn't running!", $pl['type']); 29 | } 30 | } else { 31 | $conn->message($pl['from'], "Usage: #timer [start|stop]", $pl['type']); 32 | } 33 | } 34 | ?> 35 | -------------------------------------------------------------------------------- /commands/timer.txt: -------------------------------------------------------------------------------- 1 | Usage: #timer [start|stop] 2 | A stopwatch-type thing. This was just a test command when the bot was first being built. -------------------------------------------------------------------------------- /commands/translate.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['translate'] = function(&$conn, $event, $params) { 3 | global $translate_token, $token_response; 4 | if(empty($translate_token)) { 5 | $token_request = http_build_query(array( 6 | "client_id" => $client_id, 7 | "client_secret" => $client_secret, 8 | "scope" => "http://api.microsofttranslator.com", 9 | "grant_type" => "client_credentials", 10 | ), "", "&"); 11 | $token_response = Unirest::post("https://datamarket.accesscontrol.windows.net/v2/OAuth2-13?" . $token_request); //, array(), $token_request); 12 | if(!empty($token_reponse->body->access_token)) { 13 | $translate_token = $token_reponse->body->access_token; 14 | } else { 15 | print_r($token_response->body); 16 | $conn->message($event['from'], "Failed to retrieve access token.", $event['type']); 17 | } 18 | } 19 | if (!empty($params[0]) && !empty($params[1]) && !empty($params[2])) { 20 | $to = $params[0]; 21 | $from = $params[1]; 22 | unset($params[0], $params[1]); 23 | $message = implode(" ", $params); 24 | 25 | $url = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" . urlencode($message) . "&from=" . urlencode($from) . "&to=" . urlencode($to); 26 | $headers = array("Authorization" => "Bearer $translate_token"); 27 | $result = Unirest::post($url, $headers); 28 | 29 | print_r($response->body); 30 | 31 | $conn->message($event['from'], $result->raw_body, $event['type']); 32 | } else { 33 | $conn->message($event['from'], "Usage: #translate <to> <from> <message>", $event['type']); 34 | } 35 | } 36 | ?> 37 | -------------------------------------------------------------------------------- /commands/tweet.php: -------------------------------------------------------------------------------- 1 | <?php 2 | include_once dirname(__FILE__) . '/../lib/twitteroauth.php'; 3 | $commands['tweet'] = function(&$conn, $event, $params) { 4 | global $twitterConsumerKey, $twitterConsumerSecret, $twitterOAuthToken, $twitterOAuthSecret; 5 | if(isset($params[0])) { 6 | $tweet = new TwitterOAuth($twitterConsumerKey, $twitterConsumerSecret, $twitterOAuthToken, $twitterOAuthSecret); 7 | $message = implode(" ", $params); 8 | if(strlen($message) > 140) { 9 | $conn->message($event['from'], "Error: tweets must be 140 characters or less. That message is " . strlen($message) . ".", $event['type']); 10 | return false; 11 | } 12 | 13 | $post = $tweet->post("statuses/update", array("status" => $message)); 14 | if(!empty($post->id)) { 15 | $conn->htmlmessage($event['from'], "<a href='https://twitter.com/{$post->user->screen_name}/statuses/{$post->id_str}'>Tweet posted to @{$post->user->screen_name}.</a>", $event['type'], "Tweet posted: https://twitter.com/{$post->user->screen_name}/statuses/{$post->id_str}"); 16 | } else { 17 | $conn->message($event['from'], "Failed to post tweet!", $event['type']); 18 | } 19 | } else { 20 | $conn->message($event['from'], "Usage: #tweet <message>", $event['type']); 21 | } 22 | } 23 | ?> 24 | -------------------------------------------------------------------------------- /commands/ud.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['ud'] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | $text = implode(" ",$params); 5 | $result = json_decode(file_get_contents("http://api.urbandictionary.com/v0/define?term=" . urlencode($text))); 6 | if($result->result_type != "no_results") { 7 | $def = $result->list[0]; 8 | /* $str = "<strong>" . htmlspecialchars($def->word) . "</strong>:<br />\n"; 9 | $str .= htmlspecialchars($def->definition) . "<br />\n"; 10 | $str .= "<em>" . htmlspecialchars($def->example) . "</em>"; 11 | $conn->htmlmessage($event['from'], $str, $event['type']); */ 12 | $str = $def->word . ": " . $def->definition . "\n"; 13 | $str .= "\"" . $def->example . "\""; 14 | $conn->message($event['from'], $str, $event['type']); 15 | } else { 16 | $conn->message($event['from'], "Nada.", $event['type']); 17 | } 18 | } else { 19 | $conn->message($event['from'], "Usage: #ud <word>", $event['type']); 20 | } 21 | } 22 | ?> -------------------------------------------------------------------------------- /commands/ud.txt: -------------------------------------------------------------------------------- 1 | Usage: #ud <word> 2 | Show the definition of a word according to Urban Dictionary -------------------------------------------------------------------------------- /commands/urlencode.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands["urlencode"] = function(&$conn, $event, $params) { 3 | if (!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | $conn->message($event["from"], urlencode($param_str), $event["type"]); 6 | } else { 7 | $conn->message($event["from"], "Usage: #urlencode <string>", $event["type"]); 8 | } 9 | } 10 | ?> 11 | -------------------------------------------------------------------------------- /commands/uuid.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['uuid'] = function(&$conn, $pl, $params) { 3 | $uuid = sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', 4 | // 32 bits for "time_low" 5 | mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), 6 | 7 | // 16 bits for "time_mid" 8 | mt_rand( 0, 0xffff ), 9 | 10 | // 16 bits for "time_hi_and_version", 11 | // four most significant bits holds version number 4 12 | mt_rand( 0, 0x0fff ) | 0x4000, 13 | 14 | // 16 bits, 8 bits for "clk_seq_hi_res", 15 | // 8 bits for "clk_seq_low", 16 | // two most significant bits holds zero and one for variant DCE1.1 17 | mt_rand( 0, 0x3fff ) | 0x8000, 18 | 19 | // 48 bits for "node" 20 | mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ), mt_rand( 0, 0xffff ) 21 | ); 22 | 23 | $conn->message($pl['from'], $uuid, $pl['type']); 24 | } 25 | ?> 26 | -------------------------------------------------------------------------------- /commands/vote.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['vote'] = function(&$conn, $event, $params) { 3 | 4 | $val = rand(0,1); 5 | if($val == 1) { 6 | $response = "(y) <a href='http://xkcd.com/yes/'>Yes</a>"; 7 | } else { 8 | $response = "👎 <a href='http://xkcd.com/no/'>No</a>"; 9 | } 10 | 11 | if(isset($response)) { 12 | $conn->htmlmessage($event['from'], $response, $event['type']); 13 | } else { 14 | $conn->message($event['from'], "Usage: #vote", $event['type']); 15 | } 16 | } 17 | ?> 18 | -------------------------------------------------------------------------------- /commands/wa.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['wa'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $param_str = implode(" ",$params); 6 | $response = curl_get_contents("http://api.wolframalpha.com/v2/query?input=" . urlencode($param_str) . "&appid=" . urlencode($wa_app) . "&format=plaintext"); 7 | $conn->message($pl['from'], "\n" . $response, $pl['type']); 8 | } else { 9 | $conn->message($pl['from'], "Usage: #wa <expression>", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/wargames.php: -------------------------------------------------------------------------------- 1 | <?php 2 | //HOW ABOUT A NICE GAME OF CHESS? 3 | $commands['wargames'] = function(&$conn, $event, $params) { 4 | if (!empty($params[0]) && implode(" ", $params) == "GLOBAL THERMALNUCLEAR WAR") { 5 | $conn->message($event['from'], "LOGON:", $event['type']); 6 | 7 | } else if (!empty($params[0]) && $params[0] == "JOSHUA") { 8 | global $room, $room_server, $nick; 9 | $conn->joinRoom($room, $room_server, "WOPR"); 10 | sleep(2); 11 | $conn->message($event['from'], "CPE1704TKS", $event['type']); 12 | sleep(2); 13 | $conn->message($event['from'], "U.S. FIRST STRIKE", $event['type']); 14 | sleep(2); 15 | $conn->message($event['from'], "WINNER: NONE", $event['type']); 16 | sleep(2); 17 | $conn->message($event['from'], "USSR FIRST STRIKE", $event['type']); 18 | sleep(2); 19 | $conn->message($event['from'], "WINNER: NONE", $event['type']); 20 | sleep(2); 21 | $conn->message($event['from'], "NATO / WARSAW PACT: NONE", $event['type']); 22 | sleep(2); 23 | $conn->message($event['from'], "FAR EAST STRATEGY: NONE", $event['type']); 24 | sleep(2); 25 | $conn->message($event['from'], "U.S. USSR ESCALATION: NONE", $event['type']); 26 | sleep(2); 27 | $conn->message($event['from'], "GREETINGS, PROFESSOR FALKEN.", $event['type']); 28 | sleep(2); 29 | $conn->message($event['from'], "A STRANGE GAME. THE ONLY WINNING MOVE IS NOT TO PLAY.", $event['type']); 30 | 31 | sleep(2); 32 | $conn->message($event['from'], "HOW ABOUT A NICE GAME OF CHESS?", $event['type']); 33 | 34 | 35 | $conn->joinRoom($room, $room_server, "Hashbot"); 36 | 37 | } else if (!empty($params[0]) && $params[0] == "TIC-TAC-TOE") { 38 | $conn->message($event['from'], "STALEMATE.", $event['type']); 39 | $conn->message($event['from'], "WANT TO PLAY AGAIN?", $event['type']); 40 | } else if (!empty($params[0]) && implode(" ", $params) == "List Games") { 41 | $conn->message($event['from'], " 42 | FALKEN'S MAZE 43 | BLACK JACK 44 | GIN RUMMY 45 | HEARTS 46 | BRIDGE 47 | CHECKERS 48 | CHESS 49 | POKER 50 | FIGHTER COMBAT 51 | GUERRILLA ENGAGEMENT 52 | DESERT WARFARE 53 | AIR-TO-GROUND ACTIONS 54 | THEATERWIDE TACTICAL WARFARE 55 | THEATERWIDE BIOTOXIC AND CHEMICAL WARFARE 56 | 57 | GLOBAL THERMALNUCLEAR WAR 58 | ", $event['type']); 59 | } else { 60 | $conn->message($event['from'], "GREETINGS,", $event['type']); 61 | $conn->message($event['from'], "SHALL WE PLAY A GAME?", $event['type']); 62 | } 63 | } 64 | ?> 65 | -------------------------------------------------------------------------------- /commands/wargames.txt: -------------------------------------------------------------------------------- 1 | Usage: #wargames [number] 2 | List the WOPR games list. -------------------------------------------------------------------------------- /commands/weather.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['weather'] = function(&$conn, $event, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $d = 2; 6 | if(preg_match("/^[0-9]+d$/i", trim($params[0])) && count($params) > 1) { 7 | $d = intval($params[0]); 8 | unset($params[0]); 9 | } 10 | 11 | $param_str = implode(' ',$params); 12 | $conn->message($event['from'], "Checking the forecast for " . $param_str . "...", $event['type']); 13 | $response = Unirest::get("https://george-vustrey-weather.p.mashape.com/api.php?_method=getForecasts&location=" . urlencode($param_str), array("X-Mashape-Authorization" => $mash_key)); 14 | $str = "Forecast for " . $param_str; 15 | 16 | $str.= "\nToday: ▲ " . round($response->body[0]->high) . " ▼ " . round($response->body[0]->low) . " " . $response->body[0]->condition; 17 | $str.= "\nTomorrow: ▲ " . round($response->body[1]->high) . " ▼ " . round($response->body[1]->low) . " " . $response->body[1]->condition; 18 | 19 | if(count($response->body) < $d) { 20 | $d = count($response->body); 21 | } 22 | if($d > 2) { 23 | for($i = 2; $i < $d; $i++) { 24 | $day_name = date("l", strtotime("+{$i} days")); 25 | $str.= "\n{$day_name}: ▲ " . round($response->body[$i]->high) . " ▼ " . round($response->body[$i]->low) . " " . $response->body[$i]->condition; 26 | } 27 | } 28 | $conn->message($event['from'], $str, $event['type']); 29 | } else { 30 | $conn->message($event['from'], "Usage: #weather [Nd] <location>", $event['type']); 31 | } 32 | } 33 | ?> 34 | -------------------------------------------------------------------------------- /commands/weather.txt: -------------------------------------------------------------------------------- 1 | Usage: #weather [Nd] <location> 2 | Gets basic weather information for a given location. 3 | Location can be in any common format including a ZIP code or State, City format. International locations are valid. 4 | For a custom number of days, supply the Nd paramter, like "5d" for five days. -------------------------------------------------------------------------------- /commands/whoami.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['whoami'] = function(&$conn, $pl, $params) { 3 | $links = array( 4 | "https://www.youtube.com/watch?v=AK2B5ffWR6g&t=10", 5 | "http://bit.ly/GQ5vfd" 6 | ); 7 | $conn->htmlmessage($pl['from'], "<a href='" . htmlentities($links[array_rand($links)]) . "'>" . $pl['realfrom'] . "</a>", $pl['type'], $pl['realfrom']); 8 | } 9 | ?> 10 | -------------------------------------------------------------------------------- /commands/whoami.txt: -------------------------------------------------------------------------------- 1 | Usage: #whoami 2 | Tells you who you are, assuming it knows. -------------------------------------------------------------------------------- /commands/whois.php: -------------------------------------------------------------------------------- 1 | <?php 2 | include_once dirname(__FILE__) . '/../lib/domain.class.php'; 3 | $commands['whois'] = function(&$conn, $pl, $params) { 4 | if(!empty($params[0])) { 5 | $domain = new domain($params[0]); 6 | if($domain->is_valid()) { 7 | echo "Whois Server: ", $domain->get_whois_server(), "\n"; 8 | 9 | $response = $domain->info(); 10 | if($domain->is_available()){ 11 | $conn->message($pl['from'], "Domain " . $domain->get_domain() . "." . $domain->get_tld() . " is not registered.", $pl['type']); 12 | return; 13 | } 14 | 15 | echo $response; 16 | 17 | if($pos = strpos($response, "REGISTRANT CONTACT INFO")) { 18 | $info = substr($response + 23, $pos); 19 | $info = substr($info, 0, strpos($info, "\n\n")); 20 | } else { 21 | $lines = explode("\n", $info); 22 | $registrant = array(); 23 | foreach($lines as $l) { 24 | if(strpos($l, "Registrant") !== false) { 25 | $registrant[] = trim(substr($l, strlen("Registrant"))); 26 | } 27 | } 28 | if(!empty($registrant)) { 29 | $info = "\n" . implode("\n", $registrant); 30 | } else { 31 | $info = "Response format not supported. "; 32 | $info .= "<a href='http://alanaktion.net/tools/whois.php?domain=" . $domain->get_domain() . "." . $domain->get_tld() . "'>Full response</a>"; 33 | $conn->htmlmessage($pl['from'], $info, $pl['type'], "Response format not supported."); 34 | return false; 35 | } 36 | } 37 | 38 | $conn->message($pl['from'], $info, $pl['type']); 39 | } else { 40 | $conn->message($pl['from'], "Invalid domain name.", $pl['type']); 41 | } 42 | } else { 43 | $conn->message($pl['from'], "Usage: #whois <domain>", $pl['type']); 44 | } 45 | } 46 | ?> 47 | -------------------------------------------------------------------------------- /commands/wiki.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['wiki'] = function(&$conn, $pl, $params) { 3 | if (!empty($params[0])) { 4 | $param_str = implode(" ",$params); 5 | $url = "https://en.wikipedia.org/w/api.php?action=query&prop=info&format=json&titles=" . urlencode($param_str); 6 | $response = Unirest::get($url); 7 | print_r($response); 8 | if(!empty($response->body->query->pages)) { 9 | foreach($response->body->query->pages as $curpage) { 10 | $page = $curpage; 11 | break; 12 | } 13 | $conn->message($pl['from'], "https://en.wikipedia.org/wiki/" . ucfirst(str_replace(" ", "_", $page->title)), $pl['type']); 14 | } else { 15 | $conn->message($pl['from'], "Nothing found!", $pl['type']); 16 | } 17 | } else { 18 | $conn->message($pl['from'], "Usage: #wiki <search terms>", $pl['type']); 19 | } 20 | } 21 | ?> 22 | -------------------------------------------------------------------------------- /commands/win.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['win'] = function(&$conn, $pl, $params) { 3 | $conn->message($pl['from'], "Woohoo!", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/wiseman.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['wiseman'] = function(&$conn, $pl, $params) { 3 | $conn->message($pl['from'], "I know.", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/woot.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['woot'] = function(&$conn, $pl, $params) { 3 | $conn->message($pl['from'], "http://x.co/wootlight", $pl['type']); 4 | } 5 | ?> 6 | -------------------------------------------------------------------------------- /commands/xkcd.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['xkcd'] = function(&$conn, $pl, $params) { 3 | if (!empty($params[0])) { 4 | $response = json_decode(curl_get_contents("http://xkcd.com/" . intval($params[0]) . "/info.0.json")); 5 | $conn->message($pl['from'], $response->img, $pl['type']); 6 | } else { 7 | $response = json_decode(curl_get_contents("http://xkcd.com/info.0.json")); 8 | //$conn->message($pl['from'], "Latest: http://xkcd.com/" . $response->num . "/", $pl['type']); 9 | $conn->message($pl['from'], $response->img, $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/xkcd.txt: -------------------------------------------------------------------------------- 1 | Usage: #xkcd [number] 2 | Returns the most recent xkcd comic, or any past comic by number. -------------------------------------------------------------------------------- /commands/yoda.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['yoda'] = function(&$conn, $pl, $params) { 3 | global $mash_key; 4 | if (!empty($params[0])) { 5 | $param_str = implode(" ",$params); 6 | $response = Unirest::get("https://yoda.p.mashape.com/yoda?sentence=" . urlencode($param_str), array("X-Mashape-Authorization" => $mash_key)); 7 | $conn->message($pl['from'], $response->raw_body, $pl['type']); 8 | } else { 9 | $conn->message($pl['from'], "Usage: #yoda <sentence>", $pl['type']); 10 | } 11 | } 12 | ?> 13 | -------------------------------------------------------------------------------- /commands/yoda.txt: -------------------------------------------------------------------------------- 1 | Usage: #yoda <sentence> 2 | Translates a sentence into Yoda-speak. -------------------------------------------------------------------------------- /commands/youtube.php: -------------------------------------------------------------------------------- 1 | <?php 2 | $commands['youtube'] = function(&$conn, $event, $params) { 3 | global $youtube_key; 4 | if (!empty($params[0])) { 5 | 6 | $param_str = implode(" ",$params); 7 | $url = "https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&type=video&q=" . urlencode($param_str) . "&key=" . urlencode($youtube_key); 8 | 9 | $result = json_decode(file_get_contents($url)); 10 | 11 | if (isset($result->items[0])) { 12 | $video = $result->items[0]; 13 | $url = 'https://www.youtube.com/watch?v=' . urlencode($video->id->videoId); 14 | $title = $video->snippet->title; 15 | 16 | $conn->htmlmessage($event['from'], "<a href='$url'>" . htmlentities($title) . "</a>", $event['type'], $url . " - " . $title); 17 | } else { 18 | $conn->message($event['from'], "Nothing found!", $event['type']); 19 | } 20 | 21 | } else { 22 | $conn->message($event['from'], "Usage: #yt|youtube <search terms>", $event['type']); 23 | } 24 | } 25 | ?> 26 | -------------------------------------------------------------------------------- /commands/youtube.txt: -------------------------------------------------------------------------------- 1 | Usage: #yt|youtube <search terms> 2 | Returns the first result for the search terms on YouTube. -------------------------------------------------------------------------------- /config-sample.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | // Bot Configuration 4 | $old_auth = true; 5 | 6 | // Connection 7 | $server = 'chat.example.com'; 8 | $port = 5222; 9 | $user = 'hashbot'; 10 | $domain = $server; 11 | $pass = 'letmein'; 12 | $clientid = 'hashbot'; 13 | 14 | // Chat room (optional) 15 | $room = 'roomname'; 16 | $room_password = ''; 17 | $room_server = 'conference.chat.example.com'; 18 | $nick = 'Hashbot'; 19 | 20 | // Error reporting 21 | $errors = E_ALL & ~E_DEPRECATED & ~E_NOTICE; 22 | 23 | // Log level 24 | const LEVEL_ERROR = 0; 25 | const LEVEL_WARNING = 1; 26 | const LEVEL_INFO = 2; 27 | const LEVEL_DEBUG = 3; 28 | const LEVEL_VERBOSE = 4; 29 | $logging = LEVEL_INFO; 30 | 31 | // Command Aliases 32 | $aliases = array( 33 | "commands" => "help", 34 | "yt" => "youtube", 35 | "=" => "math", 36 | "leet" => "1337", 37 | "facepalm" => "fp", 38 | "lorem" => "ipsum", 39 | "movies" => "movie", 40 | "arand" => "array-rand", 41 | ); 42 | 43 | // Disabled Commands 44 | $disabled = array( 45 | "scream", 46 | "recursion", 47 | "math_b", 48 | ); 49 | 50 | // Status message 51 | $status_message = "I'm alive!"; 52 | 53 | // Greetings 54 | $greetings = array( 55 | "hi " . strtolower($nick), 56 | "hey " . strtolower($nick), 57 | "hello " . strtolower($nick), 58 | "hi hash", 59 | "hey hash", 60 | ); 61 | 62 | // Bad Word Filter 63 | $filter_badwords = false; 64 | 65 | // Time Zone 66 | $timezone = 'America/Denver'; 67 | 68 | // Mashape API key 69 | $mash_key = ""; 70 | 71 | // Wolfram|Alpha App ID 72 | $wa_app = ""; 73 | 74 | // Windows Azure Account Key (used for #translate) 75 | $azure_key = ""; 76 | $azure_clientid = ""; 77 | $azure_secret = ""; 78 | 79 | // Amazon Product Advertising API Access Key 80 | $amazon_associate_tag = ""; 81 | $amazon_key = ""; 82 | $amazon_secret = ""; 83 | 84 | // Twitter OAuth 85 | $twitterConsumerKey = ""; 86 | $twitterConsumerSecret = ""; 87 | $twitterOAuthToken = ""; 88 | $twitterOAuthSecret = ""; 89 | 90 | // Show incoming @mentions in the configured chatroom 91 | $enable_mentions = false; 92 | 93 | // The Movie Database 94 | $tmdb_key = ""; 95 | 96 | // MX Toolbox API 97 | $mxtoolbox_key = ""; 98 | $mxtoolbox_enable_pro = false; 99 | 100 | // YouTube API 101 | $youtube_key = ""; 102 | -------------------------------------------------------------------------------- /lib/Twilio/AutoPagingIterator.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_AutoPagingIterator 4 | implements Iterator 5 | { 6 | protected $generator; 7 | protected $args; 8 | protected $items; 9 | 10 | private $_args; 11 | 12 | public function __construct($generator, $page, $size, $filters) { 13 | $this->generator = $generator; 14 | $this->page = $page; 15 | $this->size = $size; 16 | $this->filters = $filters; 17 | $this->items = array(); 18 | 19 | // Save a backup for rewind() 20 | $this->_args = array( 21 | 'page' => $page, 22 | 'size' => $size, 23 | 'filters' => $filters, 24 | ); 25 | } 26 | 27 | public function current() 28 | { 29 | return current($this->items); 30 | } 31 | 32 | public function key() 33 | { 34 | return key($this->items); 35 | } 36 | 37 | /* 38 | * Return the next item in the list, making another HTTP call to the next 39 | * page of resources if necessary. 40 | */ 41 | public function next() 42 | { 43 | try { 44 | $this->loadIfNecessary(); 45 | return next($this->items); 46 | } 47 | catch (Services_Twilio_RestException $e) { 48 | // 20006 is an out of range paging error, everything else is valid 49 | if ($e->getCode() != 20006) { 50 | throw $e; 51 | } 52 | } 53 | } 54 | 55 | /* 56 | * Restore everything to the way it was before we began paging. This gets 57 | * called at the beginning of any foreach() loop 58 | */ 59 | public function rewind() 60 | { 61 | foreach ($this->_args as $arg => $val) { 62 | $this->$arg = $val; 63 | } 64 | $this->items = array(); 65 | $this->next_page_uri = null; 66 | } 67 | 68 | public function count() 69 | { 70 | throw new BadMethodCallException('Not allowed'); 71 | } 72 | 73 | public function valid() 74 | { 75 | try { 76 | $this->loadIfNecessary(); 77 | return key($this->items) !== null; 78 | } 79 | catch (Services_Twilio_RestException $e) { 80 | // 20006 is an out of range paging error, everything else is valid 81 | if ($e->getCode() != 20006) { 82 | throw $e; 83 | } 84 | } 85 | return false; 86 | } 87 | 88 | /* 89 | * Fill $this->items with a new page from the API, if necessary. 90 | */ 91 | protected function loadIfNecessary() 92 | { 93 | if (// Empty because it's the first time or last page was empty 94 | empty($this->items) 95 | // null key when the items list is iterated over completely 96 | || key($this->items) === null 97 | ) { 98 | $page = call_user_func_array($this->generator, array( 99 | $this->page, 100 | $this->size, 101 | $this->filters, 102 | $this->next_page_uri, 103 | )); 104 | $this->next_page_uri = $page->next_page_uri; 105 | $this->items = $page->getItems(); 106 | $this->page = $this->page + 1; 107 | } 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /lib/Twilio/HttpException.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_HttpException extends ErrorException {} -------------------------------------------------------------------------------- /lib/Twilio/HttpStream.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * HTTP Stream version of the TinyHttp Client used to connect to Twilio 4 | * services. 5 | */ 6 | 7 | class Services_Twilio_HttpStreamException extends ErrorException {} 8 | 9 | class Services_Twilio_HttpStream { 10 | 11 | private $auth_header = null; 12 | private $uri = null; 13 | private $debug = false; 14 | private static $default_options = array( 15 | "http" => array( 16 | "headers" => "", 17 | "timeout" => 60, 18 | "follow_location" => true, 19 | "ignore_errors" => true, 20 | ), 21 | "ssl" => array(), 22 | ); 23 | private $options = array(); 24 | 25 | public function __construct($uri = '', $kwargs = array()) { 26 | $this->uri = $uri; 27 | if (isset($kwargs['debug'])) { 28 | $this->debug = true; 29 | } 30 | if (isset($kwargs['http_options'])) { 31 | $this->options = $kwargs['http_options'] + self::$default_options; 32 | } else { 33 | $this->options = self::$default_options; 34 | } 35 | } 36 | 37 | public function __call($name, $args) { 38 | list($res, $req_headers, $req_body) = $args + array(0, array(), ''); 39 | 40 | $request_options = $this->options; 41 | $url = $this->uri . $res; 42 | 43 | if (isset($req_body) && strlen($req_body) > 0) { 44 | $request_options['http']['content'] = $req_body; 45 | } 46 | 47 | foreach($req_headers as $key => $value) { 48 | $request_options['http']['header'] .= sprintf("%s: %s\r\n", $key, $value); 49 | } 50 | 51 | if (isset($this->auth_header)) { 52 | $request_options['http']['header'] .= $this->auth_header; 53 | } 54 | 55 | $request_options['http']['method'] = strtoupper($name); 56 | $request_options['http']['ignore_errors'] = true; 57 | 58 | if ($this->debug) { 59 | error_log(var_export($request_options, true)); 60 | } 61 | $ctx = stream_context_create($request_options); 62 | $result = file_get_contents($url, false, $ctx); 63 | 64 | if (false === $result) { 65 | throw new Services_Twilio_HttpStreamException( 66 | "Unable to connect to service"); 67 | } 68 | 69 | $status_header = array_shift($http_response_header); 70 | if (1 !== preg_match('#HTTP/\d+\.\d+ (\d+)#', $status_header, $matches)) { 71 | throw new Services_Twilio_HttpStreamException( 72 | "Unable to detect the status code in the HTTP result."); 73 | } 74 | 75 | $status_code = intval($matches[1]); 76 | $response_headers = array(); 77 | 78 | foreach($http_response_header as $header) { 79 | list($key, $val) = explode(":", $header); 80 | $response_headers[trim($key)] = trim($val); 81 | } 82 | 83 | return array($status_code, $response_headers, $result); 84 | } 85 | 86 | public function authenticate($user, $pass) { 87 | if (isset($user) && isset($pass)) { 88 | $this->auth_header = sprintf("Authorization: Basic %s", 89 | base64_encode(sprintf("%s:%s", $user, $pass))); 90 | } else { 91 | $this->auth_header = null; 92 | } 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /lib/Twilio/InstanceResource.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * @category Services 5 | * @package Services_Twilio 6 | * @author Neuman Vong <neuman@twilio.com> 7 | * @license http://creativecommons.org/licenses/MIT/ MIT 8 | * @link http://pear.php.net/package/Services_Twilio 9 | */ 10 | 11 | /** 12 | * Abstraction of an instance resource from the Twilio API. 13 | */ 14 | abstract class Services_Twilio_InstanceResource extends Services_Twilio_Resource { 15 | 16 | /** 17 | * Make a request to the API to update an instance resource 18 | * 19 | * :param mixed $params: An array of updates, or a property name 20 | * :param mixed $value: A value with which to update the resource 21 | * 22 | * :rtype: null 23 | * :throws: a :php:class:`RestException <Services_Twilio_RestException>` if 24 | * the update fails. 25 | */ 26 | public function update($params, $value = null) 27 | { 28 | if (!is_array($params)) { 29 | $params = array($params => $value); 30 | } 31 | $decamelizedParams = $this->client->createData($this->uri, $params); 32 | $this->updateAttributes($decamelizedParams); 33 | } 34 | 35 | /* 36 | * Add all properties from an associative array (the JSON response body) as 37 | * properties on this instance resource, except the URI 38 | * 39 | * :param stdClass $params: An object containing all of the parameters of 40 | * this instance 41 | * :return: Nothing, this is purely side effecting 42 | * :rtype: null 43 | */ 44 | public function updateAttributes($params) { 45 | unset($params->uri); 46 | foreach ($params as $name => $value) { 47 | $this->$name = $value; 48 | } 49 | } 50 | 51 | /** 52 | * Get the value of a property on this resource. 53 | * 54 | * Instead of defining all of the properties of an object directly, we rely 55 | * on the API to tell us which properties an object has. This method will 56 | * query the API to retrieve a property for an object, if it is not already 57 | * set on the object. 58 | * 59 | * If the call is to a subresource, eg ``$client->account->messages``, no 60 | * request is made. 61 | * 62 | * To help with lazy HTTP requests, we don't actually retrieve an object 63 | * from the API unless you really need it. Hence, this function may make API 64 | * requests even if the property you're requesting isn't available on the 65 | * resource. 66 | * 67 | * :param string $key: The property name 68 | * 69 | * :return mixed: Could be anything. 70 | * :throws: a :php:class:`RestException <Services_Twilio_RestException>` if 71 | * the update fails. 72 | */ 73 | public function __get($key) 74 | { 75 | if ($subresource = $this->getSubresources($key)) { 76 | return $subresource; 77 | } 78 | if (!isset($this->$key)) { 79 | $params = $this->client->retrieveData($this->uri); 80 | $this->updateAttributes($params); 81 | } 82 | return $this->$key; 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /lib/Twilio/NumberType.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_NumberType extends Services_Twilio_ListResource 4 | { 5 | public function getResourceName($camelized = false) { 6 | $this->instance_name = 'Services_Twilio_Rest_IncomingPhoneNumber'; 7 | return $camelized ? 'IncomingPhoneNumbers' : 'incoming_phone_numbers'; 8 | } 9 | 10 | /** 11 | * Purchase a new phone number. 12 | * 13 | * Example usage: 14 | * 15 | * .. code-block:: php 16 | * 17 | * $marlosBurner = '+14105551234'; 18 | * $client->account->incoming_phone_numbers->local->purchase($marlosBurner); 19 | * 20 | * :param string $phone_number: The phone number to purchase 21 | * :param array $params: An optional array of parameters to pass along with 22 | * the request (to configure the phone number) 23 | */ 24 | public function purchase($phone_number, array $params = array()) { 25 | $postParams = array( 26 | 'PhoneNumber' => $phone_number 27 | ); 28 | return $this->create($postParams + $params); 29 | } 30 | 31 | public function create(array $params = array()) { 32 | return parent::_create($params); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /lib/Twilio/Page.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A representation of a page of resources. 5 | * 6 | * @category Services 7 | * @package Services_Twilio 8 | * @author Neuman Vong <neuman@twilio.com> 9 | * @license http://creativecommons.org/licenses/MIT/ MIT 10 | * @link http://pear.php.net/package/Services_Twilio 11 | */ 12 | class Services_Twilio_Page 13 | implements IteratorAggregate 14 | { 15 | 16 | /** 17 | * The item list. 18 | * 19 | * @var array $items 20 | */ 21 | protected $items; 22 | 23 | /** 24 | * Constructs a page. 25 | * 26 | * @param object $page The page object 27 | * @param string $name The key of the item list 28 | */ 29 | public function __construct($page, $name, $next_page_uri = null) 30 | { 31 | $this->page = $page; 32 | $this->items = $page->{$name}; 33 | $this->next_page_uri = $next_page_uri; 34 | } 35 | 36 | /** 37 | * The item list of the page. 38 | * 39 | * @return array A list of instance resources 40 | */ 41 | public function getItems() 42 | { 43 | return $this->items; 44 | } 45 | 46 | /** 47 | * Magic method to allow retrieving the properties of the wrapped page. 48 | * 49 | * @param string $prop The property name 50 | * 51 | * @return mixed Could be anything 52 | */ 53 | public function __get($prop) 54 | { 55 | return $this->page->$prop; 56 | } 57 | 58 | /** 59 | * Implementation of IteratorAggregate::getIterator(). 60 | * 61 | * @return Traversable 62 | */ 63 | public function getIterator() 64 | { 65 | return $this->getItems(); 66 | } 67 | } 68 | 69 | -------------------------------------------------------------------------------- /lib/Twilio/PartialApplicationHelper.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Helper class to wrap an object with a modified interface created by 5 | * a partial application of its existing methods. 6 | * 7 | * @category Services 8 | * @package Services_Twilio 9 | * @author Neuman Vong <neuman@twilio.com> 10 | * @license http://creativecommons.org/licenses/MIT/ MIT 11 | * @link http://pear.php.net/package/Services_Twilio 12 | */ 13 | class Services_Twilio_PartialApplicationHelper 14 | { 15 | private $callbacks; 16 | 17 | public function __construct() 18 | { 19 | $this->callbacks = array(); 20 | } 21 | 22 | public function set($method, $callback, array $args) 23 | { 24 | if (!is_callable($callback)) { 25 | return FALSE; 26 | } 27 | $this->callbacks[$method] = array($callback, $args); 28 | } 29 | 30 | public function __call($method, $args) 31 | { 32 | if (!isset($this->callbacks[$method])) { 33 | throw new Exception("Method not found: $method"); 34 | } 35 | list($callback, $cb_args) = $this->callbacks[$method]; 36 | return call_user_func_array( 37 | $callback, 38 | array_merge($cb_args, $args) 39 | ); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/Twilio/RequestValidator.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_RequestValidator 4 | { 5 | 6 | protected $AuthToken; 7 | 8 | function __construct($token) 9 | { 10 | $this->AuthToken = $token; 11 | } 12 | 13 | public function computeSignature($url, $data = array()) 14 | { 15 | // sort the array by keys 16 | ksort($data); 17 | 18 | // append them to the data string in order 19 | // with no delimiters 20 | foreach($data as $key => $value) 21 | $url .= "$key$value"; 22 | 23 | // This function calculates the HMAC hash of the data with the key 24 | // passed in 25 | // Note: hash_hmac requires PHP 5 >= 5.1.2 or PECL hash:1.1-1.5 26 | // Or http://pear.php.net/package/Crypt_HMAC/ 27 | return base64_encode(hash_hmac("sha1", $url, $this->AuthToken, true)); 28 | } 29 | 30 | public function validate($expectedSignature, $url, $data = array()) 31 | { 32 | return $this->computeSignature($url, $data) 33 | == $expectedSignature; 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /lib/Twilio/Resource.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Abstraction of a Twilio resource. 5 | * 6 | * @category Services 7 | * @package Services_Twilio 8 | * @author Neuman Vong <neuman@twilio.com> 9 | * @license http://creativecommons.org/licenses/MIT/ MIT 10 | * @link http://pear.php.net/package/Services_Twilio 11 | */ 12 | abstract class Services_Twilio_Resource { 13 | protected $subresources; 14 | 15 | public function __construct($client, $uri, $params = array()) 16 | { 17 | $this->subresources = array(); 18 | $this->client = $client; 19 | 20 | foreach ($params as $name => $param) { 21 | $this->$name = $param; 22 | } 23 | 24 | $this->uri = $uri; 25 | $this->init($client, $uri); 26 | } 27 | 28 | protected function init($client, $uri) 29 | { 30 | // Left empty for derived classes to implement 31 | } 32 | 33 | public function getSubresources($name = null) { 34 | if (isset($name)) { 35 | return isset($this->subresources[$name]) 36 | ? $this->subresources[$name] 37 | : null; 38 | } 39 | return $this->subresources; 40 | } 41 | 42 | protected function setupSubresources() 43 | { 44 | foreach (func_get_args() as $name) { 45 | $constantized = ucfirst(self::camelize($name)); 46 | $type = "Services_Twilio_Rest_" . $constantized; 47 | $this->subresources[$name] = new $type( 48 | $this->client, $this->uri . "/$constantized" 49 | ); 50 | } 51 | } 52 | 53 | /* 54 | * Get the resource name from the classname 55 | * 56 | * Ex: Services_Twilio_Rest_Accounts -> Accounts 57 | * 58 | * @param boolean $camelized Whether to return camel case or not 59 | */ 60 | public function getResourceName($camelized = false) 61 | { 62 | $name = get_class($this); 63 | $parts = explode('_', $name); 64 | $basename = end($parts); 65 | if ($camelized) { 66 | return $basename; 67 | } else { 68 | return self::decamelize($basename); 69 | } 70 | } 71 | 72 | public static function decamelize($word) 73 | { 74 | $callback = create_function('$matches', 75 | 'return strtolower(strlen("$matches[1]") ? "$matches[1]_$matches[2]" : "$matches[2]");'); 76 | 77 | return preg_replace_callback( 78 | '/(^|[a-z])([A-Z])/', 79 | $callback, 80 | $word 81 | ); 82 | } 83 | 84 | /** 85 | * Return camelized version of a word 86 | * Examples: sms_messages => SMSMessages, calls => Calls, 87 | * incoming_phone_numbers => IncomingPhoneNumbers 88 | * 89 | * @param string $word The word to camelize 90 | * @return string 91 | */ 92 | public static function camelize($word) { 93 | $callback = create_function('$matches', 'return strtoupper("$matches[2]");'); 94 | 95 | return preg_replace_callback('/(^|_)([a-z])/', 96 | $callback, 97 | $word); 98 | } 99 | 100 | /** 101 | * Get the value of a property on this resource. 102 | * 103 | * @param string $key The property name 104 | * @return mixed Could be anything. 105 | */ 106 | public function __get($key) { 107 | if ($subresource = $this->getSubresources($key)) { 108 | return $subresource; 109 | } 110 | return $this->$key; 111 | } 112 | 113 | /** 114 | * Print a JSON representation of this object. Strips the HTTP client 115 | * before returning. 116 | * 117 | * Note, this should mainly be used for debugging, and is not guaranteed 118 | * to correspond 1:1 with the JSON API output. 119 | * 120 | * Note that echoing an object before an HTTP request has been made to 121 | * "fill in" its properties may return an empty object 122 | */ 123 | public function __toString() { 124 | $out = array(); 125 | foreach ($this as $key => $value) { 126 | if ($key !== 'client' && $key !== 'subresources') { 127 | $out[$key] = $value; 128 | } 129 | } 130 | return json_encode($out, true); 131 | } 132 | 133 | } 134 | 135 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Account.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Account extends Services_Twilio_InstanceResource { 4 | 5 | protected function init($client, $uri) { 6 | $this->setupSubresources( 7 | 'applications', 8 | 'available_phone_numbers', 9 | 'outgoing_caller_ids', 10 | 'calls', 11 | 'conferences', 12 | 'incoming_phone_numbers', 13 | 'media', 14 | 'messages', 15 | 'notifications', 16 | 'outgoing_callerids', 17 | 'recordings', 18 | 'sms_messages', 19 | 'short_codes', 20 | 'transcriptions', 21 | 'connect_apps', 22 | 'authorized_connect_apps', 23 | 'usage_records', 24 | 'usage_triggers', 25 | 'queues', 26 | 'sip' 27 | ); 28 | 29 | $this->sandbox = new Services_Twilio_Rest_Sandbox( 30 | $client, $uri . '/Sandbox' 31 | ); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Accounts.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * For more information, see the `Account List Resource 5 | * <http://www.twilio.com/docs/api/rest/account#list>`_ documentation. 6 | */ 7 | class Services_Twilio_Rest_Accounts extends Services_Twilio_ListResource { 8 | 9 | /** 10 | * Create a new subaccount. 11 | * 12 | * :param array $params: An array of parameters describing the new 13 | * subaccount. The ``$params`` array can contain the following keys: 14 | * 15 | * *FriendlyName* 16 | * A description of this account, up to 64 characters long 17 | * 18 | * :returns: The new subaccount 19 | * :rtype: :php:class:`Services_Twilio_Rest_Account` 20 | * 21 | */ 22 | public function create($params = array()) { 23 | return parent::_create($params); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Application.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Application 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Applications.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Applications 4 | extends Services_Twilio_ListResource 5 | { 6 | public function create($name, array $params = array()) 7 | { 8 | return parent::_create(array( 9 | 'FriendlyName' => $name 10 | ) + $params); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/AuthorizedConnectApp.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_AuthorizedConnectApp 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/AuthorizedConnectApps.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_AuthorizedConnectApps 4 | extends Services_Twilio_ListResource 5 | { 6 | public function create($name, array $params = array()) 7 | { 8 | throw new BadMethodCallException('Not allowed'); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/AvailablePhoneNumber.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_AvailablePhoneNumber 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | 8 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/AvailablePhoneNumbers.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_AvailablePhoneNumbers 4 | extends Services_Twilio_ListResource 5 | { 6 | public function getLocal($country) { 7 | $curried = new Services_Twilio_PartialApplicationHelper(); 8 | $curried->set( 9 | 'getList', 10 | array($this, 'getList'), 11 | array($country, 'Local') 12 | ); 13 | return $curried; 14 | } 15 | public function getTollFree($country) { 16 | $curried = new Services_Twilio_PartialApplicationHelper(); 17 | $curried->set( 18 | 'getList', 19 | array($this, 'getList'), 20 | array($country, 'TollFree') 21 | ); 22 | return $curried; 23 | } 24 | 25 | public function getMobile($country) 26 | { 27 | $curried = new Services_Twilio_PartialApplicationHelper(); 28 | $curried->set( 29 | 'getList', 30 | array($this, 'getList'), 31 | array($country, 'Mobile') 32 | ); 33 | return $curried; 34 | } 35 | 36 | /** 37 | * Get a list of available phone numbers. 38 | * 39 | * @param string $country The 2-digit country code you'd like to search for 40 | * numbers e.g. ('US', 'CA', 'GB') 41 | * @param string $type The type of number ('Local', 'TollFree', or 'Mobile') 42 | * @return object The object representation of the resource 43 | */ 44 | public function getList($country, $type, array $params = array()) 45 | { 46 | return $this->client->retrieveData($this->uri . "/$country/$type", $params); 47 | } 48 | 49 | public function getResourceName($camelized = false) { 50 | // You can't page through the list of available phone numbers. 51 | $this->instance_name = 'Services_Twilio_Rest_AvailablePhoneNumber'; 52 | return $camelized ? 'Countries' : 'countries'; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Call.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * For more information, see the `Call Instance Resource <http://www.twilio.com/docs/api/rest/call#instance>`_ documentation. 5 | * 6 | * .. php:attr:: sid 7 | * 8 | * A 34 character string that uniquely identifies this resource. 9 | * 10 | * .. php:attr:: parent_call_sid 11 | * 12 | * A 34 character string that uniquely identifies the call that created this leg. 13 | * 14 | * .. php:attr:: date_created 15 | * 16 | * The date that this resource was created, given as GMT in RFC 2822 format. 17 | * 18 | * .. php:attr:: date_updated 19 | * 20 | * The date that this resource was last updated, given as GMT in RFC 2822 format. 21 | * 22 | * .. php:attr:: account_sid 23 | * 24 | * The unique id of the Account responsible for creating this call. 25 | * 26 | * .. php:attr:: to 27 | * 28 | * The phone number that received this call. e.g., +16175551212 (E.164 format) 29 | * 30 | * .. php:attr:: from 31 | * 32 | * The phone number that made this call. e.g., +16175551212 (E.164 format) 33 | * 34 | * .. php:attr:: phone_number_sid 35 | * 36 | * If the call was inbound, this is the Sid of the IncomingPhoneNumber that 37 | * received the call. If the call was outbound, it is the Sid of the 38 | * OutgoingCallerId from which the call was placed. 39 | * 40 | * .. php:attr:: status 41 | * 42 | * A string representing the status of the call. May be `QUEUED`, `RINGING`, 43 | * `IN-PROGRESS`, `COMPLETED`, `FAILED`, `BUSY` or `NO_ANSWER`. 44 | * 45 | * .. php:attr:: stat_time 46 | * 47 | * The start time of the call, given as GMT in RFC 2822 format. Empty if the call has not yet been dialed. 48 | * 49 | * .. php:attr:: end_time 50 | * 51 | * The end time of the call, given as GMT in RFC 2822 format. Empty if the call did not complete successfully. 52 | * 53 | * .. php:attr:: duration 54 | * 55 | * The length of the call in seconds. This value is empty for busy, failed, unanswered or ongoing calls. 56 | * 57 | * .. php:attr:: price 58 | * 59 | * The charge for this call in USD. Populated after the call is completed. May not be immediately available. 60 | * 61 | * .. php:attr:: direction 62 | * 63 | * A string describing the direction of the call. inbound for inbound 64 | * calls, outbound-api for calls initiated via the REST API or 65 | * outbound-dial for calls initiated by a <Dial> verb. 66 | * 67 | * .. php:attr:: answered_by 68 | * 69 | * If this call was initiated with answering machine detection, either human or machine. Empty otherwise. 70 | * 71 | * .. php:attr:: forwarded_from 72 | * 73 | * If this call was an incoming call forwarded from another number, the 74 | * forwarding phone number (depends on carrier supporting forwarding). 75 | * Empty otherwise. 76 | * 77 | * .. php:attr:: caller_name 78 | * 79 | * If this call was an incoming call from a phone number with Caller ID Lookup enabled, the caller's name. Empty otherwise. 80 | */ 81 | class Services_Twilio_Rest_Call extends Services_Twilio_InstanceResource { 82 | 83 | /** 84 | * Hang up the call 85 | */ 86 | public function hangup() { 87 | $this->update('Status', 'completed'); 88 | } 89 | 90 | /** 91 | * Redirect the call to a new URL 92 | * 93 | * :param string $url: the new URL to retrieve call flow from. 94 | */ 95 | public function route($url) { 96 | $this->update('Url', $url); 97 | } 98 | 99 | protected function init($client, $uri) { 100 | $this->setupSubresources( 101 | 'notifications', 102 | 'recordings' 103 | ); 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Calls.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Calls 4 | extends Services_Twilio_ListResource 5 | { 6 | 7 | public static function isApplicationSid($value) 8 | { 9 | return strlen($value) == 34 10 | && !(strpos($value, "AP") === false); 11 | } 12 | 13 | public function create($from, $to, $url, array $params = array()) 14 | { 15 | 16 | $params["To"] = $to; 17 | $params["From"] = $from; 18 | 19 | if (self::isApplicationSid($url)) { 20 | $params["ApplicationSid"] = $url; 21 | } else { 22 | $params["Url"] = $url; 23 | } 24 | 25 | return parent::_create($params); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Conference.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Conference 4 | extends Services_Twilio_InstanceResource 5 | { 6 | protected function init($client, $uri) 7 | { 8 | $this->setupSubresources( 9 | 'participants' 10 | ); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Conferences.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Conferences 4 | extends Services_Twilio_ListResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/ConnectApp.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_ConnectApp 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/ConnectApps.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_ConnectApps 4 | extends Services_Twilio_ListResource 5 | { 6 | public function create($name, array $params = array()) 7 | { 8 | throw new BadMethodCallException('Not allowed'); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Credential.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single Credential 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the Credential was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the Credential was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that created this credential 21 | * 22 | * .. php:attr:: username 23 | * 24 | * The username of this Credential object 25 | * 26 | * .. php:attr:: uri 27 | * 28 | * The uri of this Credential object 29 | */ 30 | class Services_Twilio_Rest_Credential extends Services_Twilio_InstanceResource { } 31 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/CredentialList.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single CredentialList 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the credential list was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the credential list was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that created the credential list 21 | * 22 | * .. php:attr:: friendly_name 23 | * 24 | * The friendly name of the credential list 25 | * 26 | * .. php:attr:: uri 27 | * 28 | * The uri of the credential list 29 | * 30 | * .. php:attr:: subresource_uris 31 | * 32 | * The subresources associated with this credential list (Credentials) 33 | */ 34 | 35 | class Services_Twilio_Rest_CredentialList extends Services_Twilio_InstanceResource { 36 | protected function init($client, $uri) { 37 | $this->setupSubresources( 38 | 'credentials' 39 | ); 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/CredentialListMapping.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single CredentialListMapping 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date this mapping was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date this mapping was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * The sid of this mapping 17 | * 18 | * .. php:attr:: friendly_name 19 | * 20 | * The friendly name of this mapping 21 | * 22 | * .. php:attr:: uri 23 | * 24 | * The uri of this mapping 25 | * 26 | * .. php:attr:: subresource_uris 27 | * 28 | * The subresources associated with this mapping (Credentials) 29 | */ 30 | 31 | class Services_Twilio_Rest_CredentialListMapping extends Services_Twilio_InstanceResource { 32 | protected function init($client, $uri) { 33 | $this->setupSubresources( 34 | 'credentials' 35 | ); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/CredentialListMappings.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_CredentialListMappings extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new CredentialListMapping instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->domains->get('SDXXX')->credential_list_mappings->create("CLXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 13 | * 14 | * :param string $credential_list_sid: the sid of the CredentialList you're adding to this domain. 15 | * :param array $params: a single array of parameters which is serialized and 16 | * sent directly to the Twilio API. 17 | */ 18 | public function create($credential_list_sid, $params = array()) { 19 | return parent::_create(array( 20 | 'CredentialListSid' => $credential_list_sid, 21 | ) + $params); 22 | } 23 | } 24 | 25 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/CredentialLists.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_CredentialLists extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new CredentialList instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->credential_lists->create("MyFriendlyName"); 13 | * 14 | * :param string $friendly_name: the friendly name of this credential list 15 | * :param array $params: a single array of parameters which is serialized and 16 | * sent directly to the Twilio API. 17 | */ 18 | public function create($friendly_name, $params = array()) { 19 | return parent::_create(array( 20 | 'FriendlyName' => $friendly_name, 21 | ) + $params); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Credentials.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Credentials extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new Credential instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->credential_lists->get('CLXXX')->credentials->create( 13 | * "AwesomeUsername", "SuperSecretPassword", 14 | * ); 15 | * 16 | * :param string $username: the username for the new Credential object 17 | * :param string $password: the password for the new Credential object 18 | * :param array $params: a single array of parameters which is serialized and 19 | * sent directly to the Twilio API. 20 | */ 21 | public function create($username, $password, $params = array()) { 22 | return parent::_create(array( 23 | 'Username' => $username, 24 | 'Password' => $password, 25 | ) + $params); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Domain.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single Domain 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the domain was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the domain was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that created the domain 21 | * 22 | * .. php:attr:: friendly_name 23 | * 24 | * The friendly name of the domain 25 | * 26 | * .. php:attr:: domain_name 27 | * 28 | * The *.sip.twilio domain for the domain 29 | * 30 | * .. php:attr:: auth_type 31 | * 32 | * The auth type used for the domain 33 | * 34 | * .. php:attr:: voice_url 35 | * 36 | * The voice url for the domain 37 | * 38 | * .. php:attr:: voice_fallback_url 39 | * 40 | * The voice fallback url for the domain 41 | * 42 | * .. php:attr:: voice_fallback_method 43 | * 44 | * The voice fallback method for the domain 45 | * 46 | * .. php:attr:: voice_status_callback_url 47 | * 48 | * The voice status callback url for the domain 49 | * 50 | * .. php:attr:: voice_status_callback_method 51 | * 52 | * The voice status_callback_method for the domain 53 | * 54 | * .. php:attr:: uri 55 | * 56 | * The uri of the domain 57 | * 58 | * .. php:attr:: subresource_uris 59 | * 60 | * The subresources associated with this domain (IpAccessControlListMappings, CredentialListMappings) 61 | * 62 | */ 63 | class Services_Twilio_Rest_Domain extends Services_Twilio_InstanceResource { 64 | protected function init($client, $uri) { 65 | $this->setupSubresources( 66 | 'ip_access_control_list_mappings', 67 | 'credential_list_mappings' 68 | ); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Domains.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Domains extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new Domain instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->domains->create( 13 | * "MyFriendlyName", "MyDomainName" 14 | * ); 15 | * 16 | * :param string $friendly_name: the friendly name of this domain 17 | * :param string $domain_name: the domain name for this domain 18 | * :param array $params: a single array of parameters which is serialized and 19 | * sent directly to the Twilio API. 20 | */ 21 | public function create($friendly_name, $domain_name, $params = array()) { 22 | return parent::_create(array( 23 | 'FriendlyName' => $friendly_name, 24 | 'DomainName' => $domain_name, 25 | ) + $params); 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IncomingPhoneNumber.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * An object representing a single phone number. For more 5 | * information, see the `IncomingPhoneNumber Instance Resource 6 | * <http://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance>`_ 7 | * documentation. 8 | * 9 | * .. php:attr:: sid 10 | * 11 | * A 34 character string that uniquely idetifies this resource. 12 | * 13 | * .. php:attr:: date_created 14 | * 15 | * The date that this resource was created, given as GMT RFC 2822 format. 16 | * 17 | * .. php:attr:: date_updated 18 | * 19 | * The date that this resource was last updated, given as GMT RFC 2822 format. 20 | * 21 | * .. php:attr:: friendly_name 22 | * 23 | * A human readable descriptive text for this resource, up to 64 24 | * characters long. By default, the FriendlyName is a nicely formatted 25 | * version of the phone number. 26 | * 27 | * .. php:attr:: account_sid 28 | * 29 | * The unique id of the Account responsible for this phone number. 30 | * 31 | * .. php:attr:: phone_number 32 | * 33 | * The incoming phone number. e.g., +16175551212 (E.164 format) 34 | * 35 | * .. php:attr:: api_version 36 | * 37 | * Calls to this phone number will start a new TwiML session with this 38 | * API version. 39 | * 40 | * .. php:attr:: voice_caller_id_lookup 41 | * 42 | * Look up the caller's caller-ID name from the CNAM database (additional charges apply). Either true or false. 43 | * 44 | * .. php:attr:: voice_url 45 | * 46 | * The URL Twilio will request when this phone number receives a call. 47 | * 48 | * .. php:attr:: voice_method 49 | * 50 | * The HTTP method Twilio will use when requesting the above Url. Either GET or POST. 51 | * 52 | * .. php:attr:: voice_fallback_url 53 | * 54 | * The URL that Twilio will request if an error occurs retrieving or executing the TwiML requested by Url. 55 | * 56 | * .. php:attr:: voice_fallback_method 57 | * 58 | * The HTTP method Twilio will use when requesting the VoiceFallbackUrl. Either GET or POST. 59 | * 60 | * .. php:attr:: status_callback 61 | * 62 | * The URL that Twilio will request to pass status parameters (such as call ended) to your application. 63 | * 64 | * .. php:attr:: status_callback_method 65 | * 66 | * The HTTP method Twilio will use to make requests to the StatusCallback URL. Either GET or POST. 67 | * 68 | * .. php:attr:: sms_url 69 | * 70 | * The URL Twilio will request when receiving an incoming SMS message to this number. 71 | * 72 | * .. php:attr:: sms_method 73 | * 74 | * The HTTP method Twilio will use when making requests to the SmsUrl. Either GET or POST. 75 | * 76 | * .. php:attr:: sms_fallback_url 77 | * 78 | * The URL that Twilio will request if an error occurs retrieving or executing the TwiML from SmsUrl. 79 | * 80 | * .. php:attr:: sms_fallback_method 81 | * 82 | * The HTTP method Twilio will use when requesting the above URL. Either GET or POST. 83 | * 84 | * .. php:attr:: uri 85 | * 86 | * The URI for this resource, relative to https://api.twilio.com. 87 | */ 88 | class Services_Twilio_Rest_IncomingPhoneNumber 89 | extends Services_Twilio_InstanceResource 90 | { 91 | } 92 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IncomingPhoneNumbers.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * For more information, see the 5 | * `IncomingPhoneNumbers API Resource 6 | * <http://www.twilio.com/docs/api/rest/incoming-phone-numbers#local>`_ 7 | * documentation at twilio.com. 8 | */ 9 | class Services_Twilio_Rest_IncomingPhoneNumbers extends Services_Twilio_ListResource { 10 | function init($client, $uri) { 11 | $this->setupSubresources( 12 | 'local', 13 | 'toll_free', 14 | 'mobile' 15 | ); 16 | } 17 | 18 | function create(array $params = array()) { 19 | return parent::_create($params); 20 | } 21 | 22 | function getList($type, array $params = array()) 23 | { 24 | return $this->client->retrieveData($this->uri . "/$type", $params); 25 | } 26 | 27 | /** 28 | * Return a phone number instance from its E.164 representation. If more 29 | * than one number matches the search string, returns the first one. 30 | * 31 | * Example usage: 32 | * 33 | * .. code-block:: php 34 | * 35 | * $number = $client->account->incoming_phone_numbers->getNumber('+14105551234'); 36 | * echo $number->sid; 37 | * 38 | * :param string $number: The number in E.164 format, eg "+684105551234" 39 | * :return: A :php:class:`Services_Twilio_Rest_IncomingPhoneNumber` object, or null 40 | * :raises: a A :php:class:`Services_Twilio_RestException` if the number is 41 | * invalid, not provided in E.164 format or for any other API exception. 42 | */ 43 | public function getNumber($number) { 44 | $page = $this->getPage(0, 1, array( 45 | 'PhoneNumber' => $number 46 | )); 47 | $items = $page->getItems(); 48 | if (is_null($items) || empty($items)) { 49 | return null; 50 | } 51 | return $items[0]; 52 | } 53 | } 54 | 55 | class Services_Twilio_Rest_Local extends Services_Twilio_NumberType { } 56 | 57 | class Services_Twilio_Rest_Mobile extends Services_Twilio_NumberType { } 58 | 59 | class Services_Twilio_Rest_TollFree extends Services_Twilio_NumberType { } 60 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAccessControlList.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single IpAccessControlList 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the ip access control list was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the ip access control list was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that created the ip access control list 21 | * 22 | * .. php:attr:: friendly_name 23 | * 24 | * The friendly name of the ip access control list 25 | * 26 | * .. php:attr:: uri 27 | * 28 | * The uri of the ip access control list 29 | * 30 | * .. php:attr:: subresource_uris 31 | * 32 | * The subresources associated with this ip access control list (IpAddresses) 33 | */ 34 | class Services_Twilio_Rest_IpAccessControlList extends Services_Twilio_InstanceResource { 35 | protected function init($client, $uri) { 36 | $this->setupSubresources( 37 | 'ip_addresses' 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAccessControlListMapping.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single IpAccessControlListMapping 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date this mapping was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date this mapping was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * The sid of this mapping 17 | * 18 | * .. php:attr:: friendly_name 19 | * 20 | * The friendly name of this mapping 21 | * 22 | * .. php:attr:: uri 23 | * 24 | * The uri of this mapping 25 | * 26 | * .. php:attr:: subresource_uris 27 | * 28 | * The subresources associated with this mapping (IpAddresses) 29 | */ 30 | class Services_Twilio_Rest_IpAccessControlListMapping extends Services_Twilio_InstanceResource { 31 | protected function init($client, $uri) { 32 | $this->setupSubresources( 33 | 'ip_addresses' 34 | ); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAccessControlListMappings.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_IpAccessControlListMappings extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new IpAccessControlListMapping instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->domains->get('SDXXX')->ip_access_control_list_mappings->create("ALXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); 13 | * 14 | * :param string $ip_access_control_list_sid: the sid of the IpAccessControList 15 | * you're adding to this domain. 16 | * :param array $params: a single array of parameters which is serialized and 17 | * sent directly to the Twilio API. 18 | */ 19 | public function create($ip_access_control_list_sid, $params = array()) { 20 | return parent::_create(array( 21 | 'IpAccessControlListSid' => $ip_access_control_list_sid, 22 | ) + $params); 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAccessControlLists.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_IpAccessControlLists extends Services_Twilio_SIPListResource { 4 | 5 | /** 6 | * Creates a new IpAccessControlLists instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->sip->ip_access_control_lists->create("MyFriendlyName"); 13 | * 14 | * :param string $friendly_name: the friendly name of this ip access control list 15 | * :param array $params: a single array of parameters which is serialized and 16 | * sent directly to the Twilio API. 17 | * :return: the created list 18 | * :rtype: :class:`Services_Twilio_Rest_IpAccessControlList` 19 | * 20 | */ 21 | public function create($friendly_name, $params = array()) { 22 | return parent::_create(array( 23 | 'FriendlyName' => $friendly_name, 24 | ) + $params); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAddress.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single IpAddress 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the IpAddress was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the IpAddress was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that created this credential 21 | * 22 | * .. php:attr:: friendly_name 23 | * 24 | * The friendly name of the IpAddress 25 | * 26 | * .. php:attr:: ip_address 27 | * 28 | * The ip address of this IpAddress object 29 | * 30 | * .. php:attr:: uri 31 | * 32 | * The uri of this IpAddress object 33 | */ 34 | class Services_Twilio_Rest_IpAddress extends Services_Twilio_InstanceResource { } 35 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/IpAddresses.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_IpAddresses extends Services_Twilio_SIPListResource { 4 | 5 | public function __construct($client, $uri) { 6 | $this->instance_name = "Services_Twilio_Rest_IpAddress"; 7 | parent::__construct($client, $uri); 8 | } 9 | 10 | /** 11 | * Creates a new IpAddress instance 12 | * 13 | * Example usage: 14 | * 15 | * .. code-block:: php 16 | * 17 | * $client->account->sip->ip_access_control_lists->get('ALXXX')->ip_addresses->create( 18 | * "FriendlyName", "127.0.0.1" 19 | * ); 20 | * 21 | * :param string $friendly_name: the friendly name for the new IpAddress object 22 | * :param string $ip_address: the ip address for the new IpAddress object 23 | * :param array $params: a single array of parameters which is serialized and 24 | * sent directly to the Twilio API. 25 | */ 26 | public function create($friendly_name, $ip_address, $params = array()) { 27 | return parent::_create(array( 28 | 'FriendlyName' => $friendly_name, 29 | 'IpAddress' => $ip_address, 30 | ) + $params); 31 | } 32 | } 33 | 34 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Media.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A list of :class:`Media <Services_Twilio_Rest_MediaInstance>` objects. 5 | * For the definitive reference, see the `Twilio Media List Documentation 6 | * <https://www.twilio.com/docs/api/rest/media>`_. 7 | */ 8 | class Services_Twilio_Rest_Media extends Services_Twilio_ListResource { 9 | 10 | 11 | // This is overridden because the list key in the Twilio response 12 | // is "media_list", not "media". 13 | public function getResourceName($camelized = false) 14 | { 15 | if ($camelized) { 16 | return "MediaList"; 17 | } else { 18 | return "media_list"; 19 | } 20 | } 21 | 22 | // We manually set the instance name here so that the parent 23 | // constructor doesn't attempt to figure out it. It would do it 24 | // incorrectly because we override getResourceName above. 25 | public function __construct($client, $uri) { 26 | $this->instance_name = "Services_Twilio_Rest_MediaInstance"; 27 | parent::__construct($client, $uri); 28 | } 29 | 30 | } 31 | 32 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/MediaInstance.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single Media object. For the definitive reference, see the `Twilio Media 5 | * Documentation <https://www.twilio.com/docs/api/rest/media>`_. 6 | * 7 | * .. php:attr:: sid 8 | * 9 | * A 34 character string that identifies this object 10 | * 11 | * .. php:attr:: account_sid 12 | * 13 | * A 34 character string representing the account that sent the message 14 | * 15 | * .. php:attr:: parent_sid 16 | * 17 | * The sid of the message that created this media. 18 | * 19 | * .. php:attr:: date_created 20 | * 21 | * The date the message was created 22 | * 23 | * .. php:attr:: date_updated 24 | * 25 | * The date the message was updated 26 | * 27 | * .. php:attr:: content_type 28 | * 29 | * The content-type of the media. 30 | */ 31 | class Services_Twilio_Rest_MediaInstance extends Services_Twilio_InstanceResource { 32 | public function __construct($client, $uri) { 33 | $uri = str_replace('MediaInstance', 'Media', $uri); 34 | parent::__construct($client, $uri); 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Member.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Member 4 | extends Services_Twilio_InstanceResource 5 | { 6 | 7 | /** 8 | * Dequeue this member 9 | * 10 | * @param string $url The Twiml URL to play for this member, after 11 | * dequeueing them 12 | * @param string $method The HTTP method to use when fetching the Twiml 13 | * URL. Defaults to POST. 14 | * @return Services_Twilio_Rest_Member The dequeued member 15 | */ 16 | public function dequeue($url, $method = 'POST') { 17 | return self::update(array( 18 | 'Url' => $url, 19 | 'Method' => $method, 20 | )); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Members.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Members 4 | extends Services_Twilio_ListResource 5 | { 6 | /** 7 | * Return the member at the front of the queue. Note that any operations 8 | * performed on the Member returned from this function will use the /Front 9 | * Uri, not the Member's CallSid. 10 | * 11 | * @return Services_Twilio_Rest_Member The member at the front of the queue 12 | */ 13 | public function front() { 14 | return new $this->instance_name($this->client, $this->uri . '/Front'); 15 | } 16 | 17 | /* Participants are identified by CallSid, not like ME123 */ 18 | public function getObjectFromJson($params, $idParam = 'sid') { 19 | return parent::getObjectFromJson($params, 'call_sid'); 20 | } 21 | 22 | public function getResourceName($camelized = false) 23 | { 24 | // The JSON property name is atypical. 25 | return $camelized ? 'Members' : 'queue_members'; 26 | } 27 | } 28 | 29 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Message.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * A single Message 5 | * 6 | * .. php:attr:: date_created 7 | * 8 | * The date the message was created 9 | * 10 | * .. php:attr:: date_updated 11 | * 12 | * The date the message was updated 13 | * 14 | * .. php:attr:: sid 15 | * 16 | * A 34 character string that identifies this object 17 | * 18 | * .. php:attr:: account_sid 19 | * 20 | * The account that sent the message 21 | * 22 | * .. php:attr:: body 23 | * 24 | * The body of the message 25 | * 26 | * .. php:attr:: num_segments 27 | * 28 | * The number of sms messages used to deliver the body 29 | * 30 | * .. php:attr:: num_media 31 | * 32 | * The number of media that are associated with the image 33 | * 34 | * .. php:attr:: subresource_uris 35 | * 36 | * The subresources associated with this message (just Media at the moment) 37 | * 38 | * .. php:attr:: from 39 | * 40 | * The number this message was sent from 41 | * 42 | * .. php:attr:: to 43 | * 44 | * The phone number this message was sent to 45 | */ 46 | class Services_Twilio_Rest_Message extends Services_Twilio_InstanceResource { 47 | protected function init($client, $uri) { 48 | $this->setupSubresources( 49 | 'media' 50 | ); 51 | } 52 | } 53 | 54 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Messages.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Messages extends Services_Twilio_ListResource { 4 | 5 | /** 6 | * Create a new Message instance 7 | * 8 | * Example usage: 9 | * 10 | * .. code-block:: php 11 | * 12 | * $client->account->messages->create(array( 13 | * "Body" => "foo", 14 | * "From" => "+14105551234", 15 | * "To" => "+14105556789", 16 | * )); 17 | * 18 | * :param array $params: a single array of parameters which is serialized and 19 | * sent directly to the Twilio API. You may find it easier to use the 20 | * sendMessage helper instead of this function. 21 | * 22 | */ 23 | public function create($params = array()) { 24 | return parent::_create($params); 25 | } 26 | 27 | /** 28 | * Send a message 29 | * 30 | * .. code-block:: php 31 | * 32 | * $client = new Services_Twilio('AC123', '123'); 33 | * $message = $client->account->messages->sendMessage( 34 | * '+14105551234', // From a Twilio number in your account 35 | * '+14105556789', // Text any number 36 | * 'Come at the king, you best not miss.' // Message body (if any) 37 | * array('https://demo.twilio.com/owl.png'), // An array of MediaUrls 38 | * ); 39 | * 40 | * :param string $from: the from number for the message, this must be a 41 | * number you purchased from Twilio 42 | * :param string $to: the message recipient's phone number 43 | * :param $mediaUrls: the URLs of images to send in this MMS 44 | * :type $mediaUrls: null (don't include media), a single URL, or an array 45 | * of URLs to send as media with this message 46 | * :param string $body: the text to include along with this MMS 47 | * :param array $params: Any additional params (callback, etc) you'd like to 48 | * send with this request, these are serialized and sent as POST 49 | * parameters 50 | * 51 | * :return: The created :class:`Services_Twilio_Rest_Message` 52 | * :raises: :class:`Services_Twilio_RestException` 53 | * An exception if the parameters are invalid (for example, the from 54 | * number is not a Twilio number registered to your account, or is 55 | * unable to send MMS) 56 | */ 57 | public function sendMessage($from, $to, $body = null, $mediaUrls = null, 58 | $params = array() 59 | ) { 60 | $postParams = array( 61 | 'From' => $from, 62 | 'To' => $to, 63 | ); 64 | // When the request is made, this will get serialized into MediaUrl=a&MediaUrl=b 65 | if (!is_null($mediaUrls)) { 66 | $postParams['MediaUrl'] = $mediaUrls; 67 | } 68 | if (!is_null($body)) { 69 | $postParams['Body'] = $body; 70 | } 71 | return self::create($postParams + $params); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Notification.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Notification 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Notifications.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Notifications 4 | extends Services_Twilio_ListResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/OutgoingCallerId.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_OutgoingCallerId 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/OutgoingCallerIds.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_OutgoingCallerIds 4 | extends Services_Twilio_ListResource 5 | { 6 | public function create($phoneNumber, array $params = array()) 7 | { 8 | return parent::_create(array( 9 | 'PhoneNumber' => $phoneNumber, 10 | ) + $params); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Participant.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Participant 4 | extends Services_Twilio_InstanceResource 5 | { 6 | public function mute() 7 | { 8 | $this->update('Muted', 'true'); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Participants.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Participants 4 | extends Services_Twilio_ListResource 5 | { 6 | /* Participants are identified by CallSid, not like PI123 */ 7 | public function getObjectFromJson($params, $idParam = "sid") { 8 | return parent::getObjectFromJson($params, "call_sid"); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Queue.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Queue 4 | extends Services_Twilio_InstanceResource { 5 | 6 | protected function init($client, $uri) { 7 | $this->setupSubresources('members'); 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Queues.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Queues 4 | extends Services_Twilio_ListResource 5 | { 6 | /** 7 | * Create a new Queue 8 | * 9 | * @param string $friendly_name The name of this queue 10 | * @param array $params A list of optional parameters, and their values 11 | * @return Services_Twilio_Rest_Queue The created Queue 12 | */ 13 | function create($friendly_name, array $params = array()) { 14 | return parent::_create(array( 15 | 'FriendlyName' => $friendly_name, 16 | ) + $params); 17 | } 18 | } 19 | 20 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Recording.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Recording 4 | extends Services_Twilio_InstanceResource 5 | { 6 | protected function init($client, $uri) { 7 | $this->setupSubresources('transcriptions'); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Recordings.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Recordings 4 | extends Services_Twilio_ListResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Sandbox.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Sandbox 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/ShortCode.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_ShortCode 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/ShortCodes.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_ShortCodes 4 | extends Services_Twilio_ListResource 5 | { 6 | public function __construct($client, $uri) { 7 | $uri = preg_replace("#ShortCodes#", "SMS/ShortCodes", $uri); 8 | parent::__construct($client, $uri); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Sip.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * For Linux filename compatibility, this file needs to be named Sip.php, or 5 | * camelize() needs to be special cased in setupSubresources 6 | */ 7 | class Services_Twilio_Rest_SIP extends Services_Twilio_InstanceResource { 8 | protected function init($client, $uri) { 9 | $this->setupSubresources( 10 | 'domains', 11 | 'ip_access_control_lists', 12 | 'credential_lists' 13 | ); 14 | } 15 | 16 | public function getResourceName($camelized = false) { 17 | return "SIP"; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/SmsMessage.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_SmsMessage 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/SmsMessages.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_SmsMessages 4 | extends Services_Twilio_ListResource 5 | { 6 | public function __construct($client, $uri) { 7 | $uri = preg_replace("#SmsMessages#", "SMS/Messages", $uri); 8 | parent::__construct($client, $uri); 9 | } 10 | 11 | function create($from, $to, $body, array $params = array()) { 12 | return parent::_create(array( 13 | 'From' => $from, 14 | 'To' => $to, 15 | 'Body' => $body 16 | ) + $params); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Transcription.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Transcription 4 | extends Services_Twilio_InstanceResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/Transcriptions.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_Transcriptions 4 | extends Services_Twilio_ListResource 5 | { 6 | } 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/UsageRecord.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_UsageRecord extends Services_Twilio_InstanceResource 4 | { 5 | } 6 | 7 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/UsageRecords.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_UsageRecords extends Services_Twilio_TimeRangeResource { 4 | 5 | public function init($client, $uri) { 6 | $this->setupSubresources( 7 | 'today', 8 | 'yesterday', 9 | 'all_time', 10 | 'this_month', 11 | 'last_month', 12 | 'daily', 13 | 'monthly', 14 | 'yearly' 15 | ); 16 | } 17 | } 18 | 19 | class Services_Twilio_Rest_Today extends Services_Twilio_TimeRangeResource { } 20 | 21 | class Services_Twilio_Rest_Yesterday extends Services_Twilio_TimeRangeResource { } 22 | 23 | class Services_Twilio_Rest_LastMonth extends Services_Twilio_TimeRangeResource { } 24 | 25 | class Services_Twilio_Rest_ThisMonth extends Services_Twilio_TimeRangeResource { } 26 | 27 | class Services_Twilio_Rest_AllTime extends Services_Twilio_TimeRangeResource { } 28 | 29 | class Services_Twilio_Rest_Daily extends Services_Twilio_UsageResource { } 30 | 31 | class Services_Twilio_Rest_Monthly extends Services_Twilio_UsageResource { } 32 | 33 | class Services_Twilio_Rest_Yearly extends Services_Twilio_UsageResource { } 34 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/UsageTrigger.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_UsageTrigger 4 | extends Services_Twilio_InstanceResource { } 5 | 6 | -------------------------------------------------------------------------------- /lib/Twilio/Rest/UsageTriggers.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Services_Twilio_Rest_UsageTriggers extends Services_Twilio_ListResource { 4 | 5 | public function __construct($client, $uri) { 6 | $uri = preg_replace("#UsageTriggers#", "Usage/Triggers", $uri); 7 | parent::__construct($client, $uri); 8 | } 9 | 10 | /** 11 | * Create a new UsageTrigger 12 | * @param string $category The category of usage to fire a trigger for. A full list of categories can be found in the `Usage Categories documentation <http://www.twilio.com/docs/api/rest/usage-records#usage-categories>`_. 13 | * @param string $value Fire the trigger when usage crosses this value. 14 | * @param string $url The URL to request when the trigger fires. 15 | * @param array $params Optional parameters for this trigger. A full list of parameters can be found in the `Usage Trigger documentation <http://www.twilio.com/docs/api/rest/usage-triggers#list-post-optional-parameters>`_. 16 | * @return Services_Twilio_Rest_UsageTrigger The created trigger 17 | */ 18 | function create($category, $value, $url, array $params = array()) { 19 | return parent::_create(array( 20 | 'UsageCategory' => $category, 21 | 'TriggerValue' => $value, 22 | 'CallbackUrl' => $url, 23 | ) + $params); 24 | } 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /lib/Twilio/RestException.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * An exception talking to the Twilio API. This is thrown whenever the Twilio 5 | * API returns a 400 or 500-level exception. 6 | * 7 | * :param int $status: the HTTP status for the exception 8 | * :param string $message: a human-readable error message for the exception 9 | * :param int $code: a Twilio-specific error code for the exception 10 | * :param string $info: a link to more information 11 | */ 12 | class Services_Twilio_RestException extends Exception { 13 | 14 | /** 15 | * The HTTP status for the exception. 16 | */ 17 | protected $status; 18 | 19 | /** 20 | * A URL to get more information about the error. This is not always 21 | * available 22 | */ 23 | protected $info; 24 | 25 | public function __construct($status, $message, $code = 0, $info = '') { 26 | $this->status = $status; 27 | $this->info = $info; 28 | parent::__construct($message, $code); 29 | } 30 | 31 | /** 32 | * Get the HTTP status code 33 | */ 34 | public function getStatus() { 35 | return $this->status; 36 | } 37 | 38 | /** 39 | * Get a link to more information 40 | */ 41 | public function getInfo() { 42 | return $this->info; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/Twilio/SIPListResource.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * This subclass of ListResource is used solely to update 5 | * the URI for sip resources. 6 | */ 7 | abstract class Services_Twilio_SIPListResource extends Services_Twilio_ListResource { 8 | public function __construct($client, $uri) { 9 | // Rename all /Sip/ uris to /SIP/ 10 | $uri = preg_replace("#/Sip#", "/SIP", $uri); 11 | parent::__construct($client, $uri); 12 | } 13 | } 14 | 15 | -------------------------------------------------------------------------------- /lib/Twilio/TimeRangeResource.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Parent class for usage resources that expose a single date, eg 'Today', 'ThisMonth', etc 5 | * @author Kevin Burke <kevin@twilio.com> 6 | * @license http://creativecommons.org/licenses/MIT/ MIT 7 | * @link http://pear.php.net/package/Services_Twilio 8 | */ 9 | class Services_Twilio_TimeRangeResource extends Services_Twilio_UsageResource { 10 | 11 | /** 12 | * Return a UsageRecord corresponding to the given category. 13 | * 14 | * @param string $category The category of usage to retrieve. For a full 15 | * list of valid categories, please see the documentation at 16 | * http://www.twilio.com/docs/api/rest/usage-records#usage-all-categories 17 | * @return Services_Twilio_Rest_UsageRecord 18 | * @throws Services_Twilio_RestException 19 | */ 20 | public function getCategory($category) { 21 | $page = $this->getPage(0, 1, array( 22 | 'Category' => $category, 23 | )); 24 | $items = $page->getItems(); 25 | if (!is_array($items) || count($items) === 0) { 26 | throw new Services_Twilio_RestException( 27 | 400, "Usage record data is unformattable."); 28 | } 29 | return $items[0]; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/Twilio/UsageResource.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Parent class for all UsageRecord subclasses 5 | * @author Kevin Burke <kevin@twilio.com> 6 | * @license http://creativecommons.org/licenses/MIT/ MIT 7 | * @link http://pear.php.net/package/Services_Twilio 8 | */ 9 | class Services_Twilio_UsageResource extends Services_Twilio_ListResource { 10 | public function getResourceName($camelized = false) { 11 | $this->instance_name = 'Services_Twilio_Rest_UsageRecord'; 12 | return $camelized ? 'UsageRecords' : 'usage_records'; 13 | } 14 | 15 | public function __construct($client, $uri) { 16 | $uri = preg_replace("#UsageRecords#", "Usage/Records", $uri); 17 | parent::__construct($client, $uri); 18 | } 19 | } 20 | 21 | -------------------------------------------------------------------------------- /lib/Unirest.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | require(dirname(__FILE__) . '/Unirest/HttpMethod.php'); 4 | require(dirname(__FILE__) . '/Unirest/HttpResponse.php'); 5 | require(dirname(__FILE__) . '/Unirest/Unirest.php'); 6 | 7 | ?> -------------------------------------------------------------------------------- /lib/Unirest/HttpMethod.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class HttpMethod 3 | { 4 | const DELETE = "DELETE"; 5 | const GET = "GET"; 6 | const POST = "POST"; 7 | const PUT = "PUT"; 8 | const PATCH = "PATCH"; 9 | } -------------------------------------------------------------------------------- /lib/Unirest/HttpResponse.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class HttpResponse 3 | { 4 | private $code; 5 | private $raw_body; 6 | private $body; 7 | private $headers; 8 | 9 | /** 10 | * HttpResponse constructor 11 | * @param int $code Response code of the cURL request 12 | * @param string $raw_body The raw body of the cURL response 13 | * @param string $headers Raw header string from cURL response 14 | */ 15 | function __construct($code, $raw_body, $headers) 16 | { 17 | $this->code = $code; 18 | $this->headers = $this->get_headers_from_curl_response($headers); 19 | $this->raw_body = $raw_body; 20 | $this->body = $raw_body; 21 | $json = json_decode($raw_body); 22 | if (json_last_error() == JSON_ERROR_NONE) { 23 | $this->body = $json; 24 | } 25 | } 26 | 27 | /** 28 | * Return a property of the response if it exists 29 | * Possibilities include: 30 | * - code 31 | * - raw_body 32 | * - body (if the response is json-decodable) 33 | * - headers 34 | * @param [type] $property [description] 35 | * @return [type] [description] 36 | */ 37 | public function __get($property) 38 | { 39 | if (property_exists($this, $property)) { 40 | return $this->$property; 41 | } 42 | } 43 | 44 | /** 45 | * Set the properties of this object 46 | * @param string $property The property name 47 | * @param mixed $value The property value 48 | */ 49 | public function __set($property, $value) 50 | { 51 | if (property_exists($this, $property)) { 52 | $this->$property = $value; 53 | } 54 | return $this; 55 | } 56 | 57 | /** 58 | * Retrieve the cURL response headers from the 59 | * header string and convert it into an array 60 | * @param string $headers header string from cURL response 61 | * @return array headers in array form 62 | */ 63 | private function get_headers_from_curl_response($headers) 64 | { 65 | foreach (explode("\r\n", $headers) as $i => $line) { 66 | if ($i !== 0) { 67 | if (!empty($key) && substr($key, 0, 4) != "HTTP") { 68 | $result[$key] = $value; 69 | } else { 70 | list ($key, $value) = explode(': ', $line); 71 | } 72 | } 73 | } 74 | 75 | return $result; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/XMPPHP/Exception.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * XMPPHP: The PHP XMPP Library 4 | * Copyright (C) 2008 Nathanael C. Fritz 5 | * This file is part of SleekXMPP. 6 | * 7 | * XMPPHP is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * XMPPHP is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XMPPHP; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * @category xmpphp 22 | * @package XMPPHP 23 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 24 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 25 | * @author Michael Garvin <JID: gar@netflint.net> 26 | * @copyright 2008 Nathanael C. Fritz 27 | */ 28 | 29 | /** 30 | * XMPPHP Exception 31 | * 32 | * @category xmpphp 33 | * @package XMPPHP 34 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 35 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 36 | * @author Michael Garvin <JID: gar@netflint.net> 37 | * @copyright 2008 Nathanael C. Fritz 38 | * @version $Id$ 39 | */ 40 | class XMPPHP_Exception extends Exception { 41 | } 42 | -------------------------------------------------------------------------------- /lib/XMPPHP/Log.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * XMPPHP: The PHP XMPP Library 4 | * Copyright (C) 2008 Nathanael C. Fritz 5 | * This file is part of SleekXMPP. 6 | * 7 | * XMPPHP is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * XMPPHP is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XMPPHP; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * @category xmpphp 22 | * @package XMPPHP 23 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 24 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 25 | * @author Michael Garvin <JID: gar@netflint.net> 26 | * @copyright 2008 Nathanael C. Fritz 27 | */ 28 | 29 | /** 30 | * XMPPHP Log 31 | * 32 | * @package XMPPHP 33 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 34 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 35 | * @author Michael Garvin <JID: gar@netflint.net> 36 | * @copyright 2008 Nathanael C. Fritz 37 | * @version $Id$ 38 | */ 39 | class XMPPHP_Log { 40 | 41 | const LEVEL_ERROR = 0; 42 | const LEVEL_WARNING = 1; 43 | const LEVEL_INFO = 2; 44 | const LEVEL_DEBUG = 3; 45 | const LEVEL_VERBOSE = 4; 46 | 47 | /** 48 | * @var array 49 | */ 50 | protected $data = array(); 51 | 52 | /** 53 | * @var array 54 | */ 55 | protected $names = array('ERROR', 'WARNING', 'INFO', 'DEBUG', 'VERBOSE'); 56 | 57 | /** 58 | * @var integer 59 | */ 60 | protected $runlevel; 61 | 62 | /** 63 | * @var boolean 64 | */ 65 | protected $printout; 66 | 67 | /** 68 | * Constructor 69 | * 70 | * @param boolean $printout 71 | * @param string $runlevel 72 | */ 73 | public function __construct($printout = false, $runlevel = self::LEVEL_INFO) { 74 | $this->printout = (boolean)$printout; 75 | $this->runlevel = (int)$runlevel; 76 | } 77 | 78 | /** 79 | * Add a message to the log data array 80 | * If printout in this instance is set to true, directly output the message 81 | * 82 | * @param string $msg 83 | * @param integer $runlevel 84 | */ 85 | public function log($msg, $runlevel = self::LEVEL_INFO) { 86 | $time = time(); 87 | #$this->data[] = array($this->runlevel, $msg, $time); 88 | if($this->printout and $runlevel <= $this->runlevel) { 89 | $this->writeLine($msg, $runlevel, $time); 90 | } 91 | } 92 | 93 | /** 94 | * Output the complete log. 95 | * Log will be cleared if $clear = true 96 | * 97 | * @param boolean $clear 98 | * @param integer $runlevel 99 | */ 100 | public function printout($clear = true, $runlevel = null) { 101 | if($runlevel === null) { 102 | $runlevel = $this->runlevel; 103 | } 104 | foreach($this->data as $data) { 105 | if($runlevel <= $data[0]) { 106 | $this->writeLine($data[1], $runlevel, $data[2]); 107 | } 108 | } 109 | if($clear) { 110 | $this->data = array(); 111 | } 112 | } 113 | 114 | protected function writeLine($msg, $runlevel, $time) { 115 | //echo date('Y-m-d H:i:s', $time)." [".$this->names[$runlevel]."]: ".$msg."\n"; 116 | echo $time." [".$this->names[$runlevel]."]: ".$msg."\n"; 117 | flush(); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /lib/XMPPHP/XMLObj.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * XMPPHP: The PHP XMPP Library 4 | * Copyright (C) 2008 Nathanael C. Fritz 5 | * This file is part of SleekXMPP. 6 | * 7 | * XMPPHP is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * XMPPHP is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XMPPHP; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * @category xmpphp 22 | * @package XMPPHP 23 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 24 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 25 | * @author Michael Garvin <JID: gar@netflint.net> 26 | * @copyright 2008 Nathanael C. Fritz 27 | */ 28 | 29 | /** 30 | * XMPPHP XML Object 31 | * 32 | * @category xmpphp 33 | * @package XMPPHP 34 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 35 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 36 | * @author Michael Garvin <JID: gar@netflint.net> 37 | * @copyright 2008 Nathanael C. Fritz 38 | * @version $Id$ 39 | */ 40 | class XMPPHP_XMLObj { 41 | /** 42 | * Tag name 43 | * 44 | * @var string 45 | */ 46 | public $name; 47 | 48 | /** 49 | * Namespace 50 | * 51 | * @var string 52 | */ 53 | public $ns; 54 | 55 | /** 56 | * Attributes 57 | * 58 | * @var array 59 | */ 60 | public $attrs = array(); 61 | 62 | /** 63 | * Subs? 64 | * 65 | * @var array 66 | */ 67 | public $subs = array(); 68 | 69 | /** 70 | * Node data 71 | * 72 | * @var string 73 | */ 74 | public $data = ''; 75 | 76 | /** 77 | * Constructor 78 | * 79 | * @param string $name 80 | * @param string $ns 81 | * @param array $attrs 82 | * @param string $data 83 | */ 84 | public function __construct($name, $ns = '', $attrs = array(), $data = '') { 85 | $this->name = strtolower($name); 86 | $this->ns = $ns; 87 | if(is_array($attrs) && count($attrs)) { 88 | foreach($attrs as $key => $value) { 89 | $this->attrs[strtolower($key)] = $value; 90 | } 91 | } 92 | $this->data = $data; 93 | } 94 | 95 | /** 96 | * Dump this XML Object to output. 97 | * 98 | * @param integer $depth 99 | */ 100 | public function printObj($depth = 0) { 101 | print str_repeat("\t", $depth) . $this->name . " " . $this->ns . ' ' . $this->data; 102 | print "\n"; 103 | foreach($this->subs as $sub) { 104 | $sub->printObj($depth + 1); 105 | } 106 | } 107 | 108 | /** 109 | * Return this XML Object in xml notation 110 | * 111 | * @param string $str 112 | */ 113 | public function toString($str = '') { 114 | $str .= "<{$this->name} xmlns='{$this->ns}' "; 115 | foreach($this->attrs as $key => $value) { 116 | if($key != 'xmlns') { 117 | $value = htmlspecialchars($value); 118 | $str .= "$key='$value' "; 119 | } 120 | } 121 | $str .= ">"; 122 | foreach($this->subs as $sub) { 123 | $str .= $sub->toString(); 124 | } 125 | $body = htmlspecialchars($this->data); 126 | $str .= "$body</{$this->name}>"; 127 | return $str; 128 | } 129 | 130 | /** 131 | * Has this XML Object the given sub? 132 | * 133 | * @param string $name 134 | * @return boolean 135 | */ 136 | public function hasSub($name, $ns = null) { 137 | foreach($this->subs as $sub) { 138 | if(($name == "*" or $sub->name == $name) and ($ns == null or $sub->ns == $ns)) return true; 139 | } 140 | return false; 141 | } 142 | 143 | /** 144 | * Return a sub 145 | * 146 | * @param string $name 147 | * @param string $attrs 148 | * @param string $ns 149 | */ 150 | public function sub($name, $attrs = null, $ns = null) { 151 | #TODO attrs is ignored 152 | foreach($this->subs as $sub) { 153 | if($sub->name == $name and ($ns == null or $sub->ns == $ns)) { 154 | return $sub; 155 | } 156 | } 157 | } 158 | } 159 | -------------------------------------------------------------------------------- /lib/XMPPHP/XMPP_Old.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * XMPPHP: The PHP XMPP Library 4 | * Copyright (C) 2008 Nathanael C. Fritz 5 | * This file is part of SleekXMPP. 6 | * 7 | * XMPPHP is free software; you can redistribute it and/or modify 8 | * it under the terms of the GNU General Public License as published by 9 | * the Free Software Foundation; either version 2 of the License, or 10 | * (at your option) any later version. 11 | * 12 | * XMPPHP is distributed in the hope that it will be useful, 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | * GNU General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU General Public License 18 | * along with XMPPHP; if not, write to the Free Software 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 | * 21 | * @category xmpphp 22 | * @package XMPPHP 23 | * @author Nathanael C. Fritz <JID: fritzy@netflint.net> 24 | * @author Stephan Wentz <JID: stephan@jabber.wentz.it> 25 | * @author Michael Garvin <JID: gar@netflint.net> 26 | * @copyright 2008 Nathanael C. Fritz 27 | */ 28 | 29 | /** XMPPHP_XMPP 30 | * 31 | * This file is unnecessary unless you need to connect to older, non-XMPP-compliant servers like Dreamhost's. 32 | * In this case, use instead of XMPPHP_XMPP, otherwise feel free to delete it. 33 | * The old Jabber protocol wasn't standardized, so use at your own risk. 34 | * 35 | */ 36 | require_once "XMPP.php"; 37 | 38 | class XMPPHP_XMPPOld extends XMPPHP_XMPP { 39 | /** 40 | * 41 | * @var string 42 | */ 43 | protected $session_id; 44 | 45 | public function __construct($host, $port, $user, $password, $resource, $server = null, $printlog = false, $loglevel = null) { 46 | parent::__construct($host, $port, $user, $password, $resource, $server, $printlog, $loglevel); 47 | if(!$server) $server = $host; 48 | $this->stream_start = '<stream:stream to="' . $server . '" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">'; 49 | $this->fulljid = "{$user}@{$server}/{$resource}"; 50 | } 51 | 52 | /** 53 | * Override XMLStream's startXML 54 | * 55 | * @param parser $parser 56 | * @param string $name 57 | * @param array $attr 58 | */ 59 | public function startXML($parser, $name, $attr) { 60 | if($this->xml_depth == 0) { 61 | $this->session_id = $attr['ID']; 62 | $this->authenticate(); 63 | } 64 | parent::startXML($parser, $name, $attr); 65 | } 66 | 67 | /** 68 | * Send Authenticate Info Request 69 | * 70 | */ 71 | public function authenticate() { 72 | $id = $this->getId(); 73 | $this->addidhandler($id, 'authfieldshandler'); 74 | $this->send("<iq type='get' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username></query></iq>"); 75 | } 76 | 77 | /** 78 | * Retrieve auth fields and send auth attempt 79 | * 80 | * @param XMLObj $xml 81 | */ 82 | public function authFieldsHandler($xml) { 83 | $id = $this->getId(); 84 | $this->addidhandler($id, 'oldAuthResultHandler'); 85 | if($xml->sub('query')->hasSub('digest')) { 86 | $hash = sha1($this->session_id . $this->password); 87 | print "{$this->session_id} {$this->password}\n"; 88 | $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><digest>{$hash}</digest><resource>{$this->resource}</resource></query></iq>"; 89 | } else { 90 | $out = "<iq type='set' id='$id'><query xmlns='jabber:iq:auth'><username>{$this->user}</username><password>{$this->password}</password><resource>{$this->resource}</resource></query></iq>"; 91 | } 92 | $this->send($out); 93 | 94 | } 95 | 96 | /** 97 | * Determine authenticated or failure 98 | * 99 | * @param XMLObj $xml 100 | */ 101 | public function oldAuthResultHandler($xml) { 102 | if($xml->attrs['type'] != 'result') { 103 | $this->log->log("Auth failed!", XMPPHP_Log::LEVEL_ERROR); 104 | $this->disconnect(); 105 | throw new XMPPHP_Exception('Auth failed!'); 106 | } else { 107 | $this->log->log("Session started"); 108 | $this->event('session_start'); 109 | } 110 | } 111 | } 112 | 113 | 114 | ?> 115 | -------------------------------------------------------------------------------- /lib/json_decode_loose.php: -------------------------------------------------------------------------------- 1 | <?php 2 | # 3 | # this is a 'loose' JSON decoder. the built-in PHP JSON decoder 4 | # is very strict, and will not accept things which are fairly 5 | # common in the wild: 6 | # 7 | # * unquoted keys, e.g. {foo: 1} 8 | # * single-quoted strings, e.g. {"foo": 'bar'} 9 | # * escaped single quoted, e.g. {"foo": "b\'ar"} 10 | # * empty array elements, e.g. [1,,2] 11 | # 12 | 13 | $GLOBALS['json_strings'] = array(); 14 | 15 | # these are used as placeholders. they must: 16 | # 1) only contain alpha, numerics, underscore and dash 17 | # 2) not exist in the actual json 18 | $GLOBALS['json_str_prefix'] = 'JSON-STRING-XYZ'; 19 | $GLOBALS['json_slash_temp'] = 'JSON-SLASH-PAIR-XYZ'; 20 | 21 | function json_decode_loose($json){ 22 | 23 | $GLOBALS['json_strings'] = array(); 24 | 25 | 26 | # 27 | # first find obvious strings 28 | # 29 | #echo "PRE-FIND: $json\n"; 30 | $json = preg_replace_callback('!"((?:[^\\\\"]|\\\\\\\\|\\\\")*)"!', 'json_dqs', $json); 31 | $json = preg_replace_callback("!'((?:[^\\\\']|\\\\\\\\|\\\\')*)'!", 'json_sqs', $json); 32 | #echo "POST-FIND: $json\n"; 33 | #print_r($GLOBALS['json_strings']); 34 | 35 | $json = preg_replace('!\s+!', '', $json); 36 | 37 | 38 | # 39 | # missing elements 40 | # 41 | 42 | $json = str_replace('[,', '[null,', $json); 43 | $json = str_replace('{,', '{', $json); 44 | 45 | $json = str_replace(',]', ']', $json); 46 | $json = str_replace(',}', '}', $json); 47 | 48 | $json = preg_replace('!\[([^[{]+),(\s*),!', '[$1,null,', $json); 49 | $json = preg_replace('!\{([^[{]+),(\s*),!', '{$1,', $json); 50 | 51 | 52 | # 53 | # quote unquoted key names 54 | # 55 | 56 | $json = preg_replace_callback('!([a-zA-Z0-9-_]+):!', 'json_key', $json); 57 | 58 | 59 | # 60 | # turn remaning barewords into nulls. 61 | # loosely based on the ECMA spec, but avoiding requiring unicode PCRE. 62 | # http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf 63 | # (section 7.6) 64 | # 65 | 66 | $start = "[A-Za-z\$_]|(\\\\u[0-9A-Fa-f]{4})"; 67 | $continue = $start.'|[0-9-.]'; 68 | 69 | $json = preg_replace_callback("!(($start)($continue)*)!", 'json_bareword', $json); 70 | 71 | 72 | # 73 | # strip functions 74 | # 75 | 76 | $l = strlen($json); 77 | while (1){ 78 | $json = preg_replace("!null\(([^()]*)\)!", 'null', $json); 79 | $l2 = strlen($json); 80 | if ($l == $l2) break; 81 | $l = $l2; 82 | } 83 | 84 | 85 | # 86 | # replace the strings 87 | # 88 | 89 | #echo "PRE-CONV: $json\n"; 90 | 91 | $pre = preg_quote($GLOBALS['json_str_prefix'], '!'); 92 | $json = preg_replace_callback('!'.$pre.'(\d+)!', 'json_strs', $json); 93 | 94 | #echo "POST-CONV: $json\n"; 95 | 96 | $ret = JSON_decode($json, true); 97 | 98 | if ($ret === null){ 99 | //die("Failed to parse JSON:\n$json\n"); 100 | echo "Failed to parse JSON:\n$json\n"; 101 | } 102 | 103 | return $ret; 104 | } 105 | 106 | 107 | function json_dqs($m){ 108 | 109 | $idx = count($GLOBALS['json_strings']); 110 | $GLOBALS['json_strings'][$idx] = $m[1]; 111 | 112 | return $GLOBALS['json_str_prefix'].$idx; 113 | } 114 | 115 | function json_sqs($m){ 116 | 117 | $text = str_replace("\\\\", $GLOBALS['json_slash_temp'], $m[1]); 118 | $text = str_replace("\\'", "'", $text); 119 | $text = str_replace('"', "\\\"", $text); 120 | $text = str_replace($GLOBALS['json_slash_temp'], "\\\\", $text); 121 | 122 | $idx = count($GLOBALS['json_strings']); 123 | $GLOBALS['json_strings'][$idx] = $text; 124 | 125 | return $GLOBALS['json_str_prefix'].$idx; 126 | } 127 | 128 | function json_strs($m){ 129 | 130 | return '"'.$GLOBALS['json_strings'][$m[1]].'"'; 131 | } 132 | 133 | function json_key($m){ 134 | 135 | if (strpos($m[1], $GLOBALS['json_str_prefix']) === 0) return $m[0]; 136 | 137 | $idx = count($GLOBALS['json_strings']); 138 | $GLOBALS['json_strings'][$idx] = $m[1]; 139 | 140 | return $GLOBALS['json_str_prefix'].$idx.':'; 141 | } 142 | 143 | function json_bareword($m){ 144 | 145 | # just a string token 146 | if (strpos($m[1], $GLOBALS['json_str_prefix']) === 0) return $m[0]; 147 | 148 | # reserved words we allow 149 | $low = StrToLower($m[1]); 150 | if ($low == 'null') return 'null'; 151 | if ($low == 'true') return 'true'; 152 | if ($low == 'false') return 'false'; 153 | 154 | # otherwise it's likely a variable reference, so remove it 155 | return 'null'; 156 | } -------------------------------------------------------------------------------- /lib/latex/latex_add.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexAdd { 3 | 4 | function format($a, $b) { 5 | return "$a+$b"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /lib/latex/latex_divide.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexDivide { 3 | 4 | function format($a, $b) { 5 | return "\\frac{{$a}}{{$b}}"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /lib/latex/latex_exponent.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexExponent { 3 | 4 | function format($a, $b) { 5 | return "$a^{{$b}}"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /lib/latex/latex_multiply.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexMultiply { 3 | 4 | function format($a, $b) { 5 | return "$a\\times$b"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /lib/latex/latex_operation.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexOperation { 3 | 4 | private $left; 5 | private $right; 6 | private $formatter; 7 | 8 | function __construct($left, $formatter, $right) { 9 | $this->left = $left; 10 | $this->right = $right; 11 | $this->formatter = $formatter; 12 | } 13 | 14 | function get() { 15 | return $this->formatter->format($this->left->get(), $this->right->get()); 16 | } 17 | 18 | } -------------------------------------------------------------------------------- /lib/latex/latex_parenthesis.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexParenthesis { 3 | 4 | private $operand; 5 | 6 | function __construct($operand) { 7 | $this->operand = $operand; 8 | } 9 | 10 | function get() { 11 | return "({$this->operand->get()})"; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /lib/latex/latex_subtract.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexSubtract { 3 | 4 | function format($a, $b) { 5 | return "$a-$b"; 6 | } 7 | 8 | } -------------------------------------------------------------------------------- /lib/latex/latex_value.php: -------------------------------------------------------------------------------- 1 | <?php 2 | class LatexValue { 3 | 4 | private $value; 5 | 6 | function __construct($value) { 7 | $this->value = $value; 8 | } 9 | 10 | function get() { 11 | return $this->value; 12 | } 13 | 14 | } -------------------------------------------------------------------------------- /lib/tmdb4php/Asset.php: -------------------------------------------------------------------------------- 1 | <?php 2 | /** 3 | * Base class for all API helper classes 4 | */ 5 | class Asset { 6 | 7 | public static $type = 'abstract'; 8 | 9 | public function __construct($data){ 10 | if(is_numeric($data)){ 11 | $db = TMDB::getInstance(); 12 | $data = $db->info(self::$type, $data); 13 | } 14 | foreach($data as $key => $value){ 15 | $this->{$key} = $value; 16 | } 17 | } 18 | 19 | 20 | /** 21 | * Get an image base method 22 | * @param unknown_type $type 'backdrop', 'poster', 'profile', 'logo', ... 23 | * @param unknown_type $size int or preset 24 | * @param unknown_type $random true or false 25 | * @param unknown_type $language optional language to return the image in 26 | */ 27 | public function image($type, $size=false, $random=false, $language=null){ 28 | $image = false; 29 | $typeset = $type . 's'; // multiple 30 | $path_key = $type . '_path'; 31 | 32 | if($random){ 33 | $images = $this->images($language, false); 34 | if(count($images)>1) { 35 | $index = rand(0, count($images->{$typeset})-1); 36 | $this->{$path_key} = $images->{$typeset}[$index]->file_path; 37 | } 38 | } 39 | 40 | if(isset($this->{$path_key})){ 41 | if($size){ 42 | $db = TMDB::getInstance(); 43 | $image = $db->image_url($type, $size, $this->{$path_key}); 44 | } else { 45 | $image = $this->{$path_key}; 46 | } 47 | } 48 | 49 | return $image; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /lib/tmdb4php/Collection.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Helper class to hold the Collection Info API calls 5 | * 6 | * @link http://help.themoviedb.org/kb/api/collection-info 7 | */ 8 | class Collection extends Asset { 9 | 10 | public static $type = 'collection'; 11 | 12 | //////////////////////////////////////////////////////////////////// 13 | // Additional helpers 14 | 15 | /** 16 | * Retrieve the parts as Movie objects 17 | * @link http://help.themoviedb.org/kb/api/collection-info 18 | */ 19 | public function parts(){ 20 | $parts = array(); 21 | foreach($this->parts as $index => $part){ 22 | $parts[$part->id] = new Movie($part->id); 23 | } 24 | return $parts; 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /lib/tmdb4php/Company.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Company extends Asset { 4 | 5 | public static $type = 'company'; 6 | 7 | /** 8 | * @link http://help.themoviedb.org/kb/api/company-movies 9 | */ 10 | public function movies($language=null, $page=1){ 11 | $db = TMDB::getInstance(); 12 | $movies = array(); 13 | $info = $db->info(self::$type, $this->id, 'movies', array('language'=>$language, 'page'=>$page)); 14 | foreach($info->results as $index => $movie){ 15 | $movies[$movie->id] = new Movie($movie); 16 | } 17 | return $movies; 18 | } 19 | 20 | //////////////////////////////////////////////////////////////////// 21 | // Additional helpers 22 | 23 | /** 24 | * Get the logo pictures 25 | */ 26 | public function logo($size=false) { 27 | return $this->image('logo', $size); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/tmdb4php/Genre.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | /** 4 | * Helper class to hold the Genre Info API calls 5 | * 6 | * @link http://help.themoviedb.org/kb/api/genre-info 7 | */ 8 | class Genre extends Asset { 9 | 10 | public static $type = 'genre'; 11 | 12 | public function __construct($data, $language=null){ 13 | if(is_number($data)){ 14 | $this->id = $data; 15 | $db = TMDB::getInstance(); 16 | $data = $this->l1st($language); 17 | } 18 | parent::__construct($data); 19 | } 20 | 21 | /** 22 | * @link http://help.themoviedb.org/kb/api/genre-list 23 | */ 24 | public function l1st($language=null){ 25 | $db = TMDB::getInstance(); 26 | $info = $db->info(self::$type, $this->id, 'list', array('language'=>$language)); 27 | return $info; 28 | } 29 | 30 | /** 31 | * @link http://help.themoviedb.org/kb/api/genre-movies 32 | */ 33 | public function movies($language=null, $page=1){ 34 | $db = TMDB::getInstance(); 35 | $movies = array(); 36 | $info = $db->info(self::$type, $this->id, 'movies', array('language'=>$language, 'page'=>$page)); 37 | foreach($info->results as $index => $movie){ 38 | $movies[$movie->id] = new Movie($movie); 39 | } 40 | return $movies; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /lib/tmdb4php/Person.php: -------------------------------------------------------------------------------- 1 | <?php 2 | 3 | class Person extends Asset { 4 | 5 | public static $type = 'person'; 6 | 7 | /** 8 | * @link http://help.themoviedb.org/kb/api/person-credits 9 | */ 10 | public function credits($language=null){ 11 | $db = TMDB::getInstance(); 12 | $info = $db->info(self::$type, $this->id, 'credits', array('language'=>$language)); 13 | return $info; 14 | } 15 | 16 | /** 17 | * @link http://help.themoviedb.org/kb/api/person-images 18 | */ 19 | public function images($size=false){ 20 | $db = TMDB::getInstance(); 21 | $info = $db->info(self::$type, $this->id, 'images'); 22 | foreach($info as $type => $images){ 23 | if(!is_array($images)) continue; 24 | foreach($images as $index => $data) { 25 | if($size){ 26 | $info->{$type}[$index]->file_path = $db->image_url(substr($type, 0, strlen($type)-1), $size, $data->file_path); 27 | } 28 | } 29 | } 30 | return $info; 31 | } 32 | 33 | //////////////////////////////////////////////////////////////////// 34 | // Additional helpers 35 | 36 | /** 37 | * Get the profile picture 38 | */ 39 | public function profile($size=false) { 40 | return $this->image('profile', $size); 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /lib/tmdb4php/README.md: -------------------------------------------------------------------------------- 1 | TMDB4PHP 2 | ======== 3 | 4 | PHP wrapper classes for TMDB (TheMovieDatabase) API v3. 5 | 6 | Thanks to: 7 | Calibrate (www.calibrate.be) 8 | 9 | Requirements: 10 | ------------ 11 | PHP 5.3+ 12 | Curl 13 | TMDB Api-key 14 | 15 | Basic usage: 16 | ----------- 17 | require_once('TMDB.php'); 18 | 19 | $db = TMDB::getInstance('<your api-key>'); 20 | $db->adult = true; // return adult content 21 | $db->paged = false; // merges all paged results into a single result automatically 22 | 23 | $title = 'The Matrix'; 24 | $year = '1999'; 25 | 26 | $results = $db->search('movie', array('query'=>$title, 'year'=>$year)); 27 | 28 | $movie = reset($results); 29 | $images = $movie->posters('300'); 30 | 31 | TMDB.php 32 | contains the API wrapper for querying TMDB. Results are transformed into the helper objects automatically. 33 | For example searching for 'movie' will result in a array of Movie objects. 34 | 35 | More info will come soon. 36 | 37 | Assets 38 | ------ 39 | 40 | I created several objects for the 'assets' TMDB uses. These include: 41 | * Movie 42 | * Person 43 | * Company 44 | * Collection 45 | * Genre 46 | 47 | You can create a new asset and have it filled in with information automatically by passing in the id in the constructor. 48 | 49 | For example: 50 | 51 | $movie = new Movie(10); 52 | Will load a movie object with the info for a movie with tmdb id 10; 53 | 54 | -------------------------------------------------------------------------------- /res/badwords.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Alanaktion/chatbot/ba16218fd34eb6ad222dd073006ecfa9e7a9bc2d/res/badwords.gz --------------------------------------------------------------------------------