public static function start() { $target = isset($_GET['target']) ? $_GET['target'] : 'showForm'; switch ($target) { case 'register': require_once dirname(__FILE__) . '/ParticipationView.php'; if (isset($_GET['idExhibition']) && $_GET['idExhibition'] > 0) { require_once dirname(__FILE__) . '/Dog.php'; $dog = new Dog(); $dog->setBreed('retriiver')->setGender('m')->setBirthDate('2000-12-21'); require_once dirname(__FILE__) . '/Exhibition.php'; $exhibition = new Exhibition(); $exhibition->setId($_GET['idExhibition']); $exhibition->setCompleteExhibition(); $exhibition->insertDog($dog); echo ParticipationView::buildMessage(array('dog' => $dog, 'exhibition' => $exhibition)); } else { echo ParticipationView::buildErrorMessage(); } break; case 'showForm': default: require_once dirname(__FILE__) . '/Exhibition.php'; $exhibitions = Exhibition::getListOfTypeExhibitions(); require_once dirname(__FILE__) . '/ParticipationView.php'; echo ParticipationView::buildRegistrationForm(array('exhibitions' => $exhibitions)); break; } }
/** * @throws \ValidationException * @throws null */ public function testCallback_ManyConditions_CalledBack() { $dog = new Dog(); $dog->Name = 'Johnny'; $owner1 = new Human(); $owner1->Name = 'Bob'; $owner2 = new Human(); $owner2->Name = 'Wot'; $cat = new Cat(); $cat->Name = 'Agnis'; $afterExists = new \OnAfterExists(function () use($dog) { $dog->write(); }); $afterExists->addCondition($owner1, function ($owner) use($dog) { $dog->Name .= ' ' . $owner->Name; $dog->OwnerID = $owner->ID; }); $afterExists->addCondition($owner2, function ($owner) use($dog) { $dog->Name .= ' ' . $owner->Name; $dog->OwnerID = $owner->ID; }); $afterExists->addCondition($cat, function ($cat) use($dog) { $dog->Name .= ' ' . $cat->Name; }); $owner1->write(); $this->assertFalse($dog->exists()); $owner2->write(); $this->assertFalse($dog->exists()); $cat->write(); $this->assertTrue($dog->exists()); $this->assertEquals($owner2->ID, $dog->OwnerID); $this->assertEquals('Johnny Bob Wot Agnis', $dog->Name); }
public function testShouldChooseOnlyTheFavorite() { $priority = array('Balsamao', 'Fernando', 'Evaldo', 'Tagliati'); $dog = new Dog($priority); $availablePeople = array('Fernando', 'Balsamao'); $result = $dog->chooseFavoritePerson($availablePeople); $expect = "Not Found"; $this->assertEquals($expect, $result); }
public function testDog() { $dog = new Dog("Benji"); $this->assertEquals("Benji", $dog->getName()); $this->assertEquals("Benji the Dog", (string) $dog); $dog->setName("Rover"); $this->assertEquals("Rover", $dog->getName()); $this->assertEquals("Rover the Dog", (string) $dog); }
public function addNewPhotos(Dog $dog) { $dogID = $dog->getID(); $stmt = $this->db->prepare("select " . self::$headShot . ",\n " . self::$standLeft . ",\n " . self::$standRight . ",\n " . self::$eventPlace . ",\n " . self::$eventDate . ",\n " . self::$eventDescr . ",\n " . self::$photographer . ",\n " . self::$isPuppy . "\n from dog\n INNER JOIN images ON dog.dogID = images.dogID\n INNER JOIN event ON images.eventID = event.eventID\n INNER JOIN photographer ON images.photographerID = photographer.photographerID\n where dog.dogID ='{$dogID}'"); if ($stmt === FALSE) { throw new \Exception($this->db->error); } $stmt->execute(); $stmt->bind_result($headshot, $standLeft, $standRight, $eventPlace, $eventDate, $eventDescr, $photographer, $isPuppy); while ($stmt->fetch()) { $photo = new Photo($headshot, $standLeft, $standRight, $eventDate, $this->encodeToIso($eventPlace), $this->encodeToIso($eventDescr), $this->encodeToIso($photographer), $isPuppy); $dog->addPhoto($photo); } }
public function reply($message) { Dog::reply($message); return true; // if (true === $this->player->isOptionEnabled(SR_Player::WWW_OUT)) // { // $this->player->message($message); // } // else // { // Dog::reply($message); // if (NULL === ($user = $this->player->getUser())) // { // echo "PLAYER HAS NO USER IN SHADOWRAP.\n"; // } // elseif (false === ($server = $user->getServer())) // { // echo "USER HAS NO SERVER IN SHADOWRAP.\n"; // } // else // { // # BAH // } // } // return true; }
public function providerRequestPing() { $walker_id = Session::get('walker_id'); $time = date("Y-m-d H:i:s"); $query = "SELECT id,owner_id,TIMESTAMPDIFF(SECOND,request_start_time, '{$time}') as diff from request where is_cancelled = 0 and status = 0 and current_walker={$walker_id} and TIMESTAMPDIFF(SECOND,request_start_time, '{$time}') <= 600 limit 1"; $requests = DB::select(DB::raw($query)); $request_data = array(); foreach ($requests as $request) { $request_data['success'] = "true"; $request_data['request_id'] = $request->id; $request_data['time_left_to_respond'] = 600 - $request->diff; $owner = Owner::find($request->owner_id); $request_data['owner'] = array(); $request_data['owner']['name'] = $owner->first_name . " " . $owner->last_name; $request_data['owner']['picture'] = $owner->picture; $request_data['owner']['phone'] = $owner->phone; $request_data['owner']['address'] = $owner->address; $request_data['owner']['latitude'] = $owner->latitude; $request_data['owner']['longitude'] = $owner->longitude; $request_data['owner']['rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->avg('rating') ?: 0; $request_data['owner']['num_rating'] = DB::table('review_dog')->where('owner_id', '=', $owner->id)->count(); $request_data['dog'] = array(); if ($dog = Dog::find($owner->dog_id)) { $request_data['dog']['name'] = $dog->name; $request_data['dog']['age'] = $dog->age; $request_data['dog']['breed'] = $dog->breed; $request_data['dog']['likes'] = $dog->likes; $request_data['dog']['picture'] = $dog->image_url; } } $response_code = 200; $response = Response::json($request_data, $response_code); return $response; }
/** * @throws \ValidationException * @throws null */ public function testBranchDeleteIDs_DeleteManyIDs_ObjectsDeleted() { $className = ''; $ids = array(); for ($i = 0; $i < 100; $i++) { $dog = new Dog(); $dog->Name = 'Pup ' . $i; $dog->Color = 'Fifty Shade No. ' . $i; $dog->write(); $className = $dog->ClassName; $ids[] = $dog->ID; } $batch = new \Batch(); $batch->deleteIDs($className, $ids); $this->assertEquals(0, Dog::get()->Count()); }
/** * @throws \ValidationException * @throws null */ public function testCallback_SetOnAfterExistsCallback_CallbackCalled() { $dog1 = new Dog(); $dog1->Name = 'Jim bob'; $dog2 = new Dog(); $dog2->Name = 'Super Dog'; $owner = new Human(); $owner->Name = 'Hilly Stewart'; $owner->write(); $owner->onAfterExistsCallback(function ($owner) use($dog1) { $dog1->OwnerID = $owner->ID; $dog1->write(); }); $owner->write(); $owner->onAfterExistsCallback(function ($owner) use($dog2) { $dog2->OwnerID = $owner->ID; $dog2->write(); }); $this->assertTrue($owner->exists()); $this->assertTrue($dog1->exists()); $this->assertTrue($dog2->exists()); $this->assertEquals(1, Human::get()->Count()); $this->assertEquals(2, Dog::get()->Count()); $this->assertEquals($owner->ID, $dog1->OwnerID); $this->assertEquals($owner->ID, $dog2->OwnerID); }
private static function getAutoTargetISO() { if (false !== ($channel = Dog::getChannel())) { return $channel->getLangISO(); } else { return Dog::getUser()->getLangISO(); } }
public static function connect(Dog_Server $server) { if (false === ($nick = self::getNickData($server))) { return Dog_Log::warn(sprintf('No nicks for %s.', $server->displayName())); } $server->addUser(Dog::getOrCreateUserByName($nick->getName())); $conn = $server->getConnection(); return self::sendUser($conn, $server, $nick) && self::sendNick($conn, $server, $nick); }
public function claim() { foreach (Dog::getServers() as $server) { $server instanceof Dog_Server; if ($this->isEnabled($server, false) && $server->isConnected()) { $this->claimServer($server); } } }
function dog_plugin_alert_func4(array $args) { global $DOG_PLUG_ALERT_TIMERS; $scope = $args[0]; $scope instanceof Dog_Scope; Dog::setScope($scope); Dog::reply($args[1]); $DOG_PLUG_ALERT_TIMERS[$scope->getUser()->getID()]--; }
private function announceVideo(array $data) { // Pick ISO for channel? if (false !== ($chan = Dog::getChannel())) { $iso = $chan->getLangISO(); } else { $iso = Dog::getUser()->getLangISO(); } $vars = array($data['title'], GWF_TimeConvert::humanDurationISO($iso, $data['duration']), sprintf('%.02f', $data['rating']), number_format($data['views']), number_format($data['num_raters'])); Dog::reply($this->langISO($iso, 'video', $vars)); }
/** * */ public function testWrite_WriteObjects_ObjectsWritten() { $batchSizes = array(10, 30, 100, 300); foreach ($batchSizes as $size) { $owners = array(); $dogs = array(); $cats = array(); $writer = new \BatchedWriter($size); for ($i = 0; $i < 100; $i++) { $owner = new Human(); $owner->Name = 'Human ' . $i; $dog = new Dog(); $dog->Name = 'Dog ' . $i; $cat = new Cat(); $cat->Name = 'Cat ' . $i; $owner->onAfterExistsCallback(function ($owner) use($dog, $writer) { $dog->OwnerID = $owner->ID; $writer->write($dog); }); $dog->onAfterExistsCallback(function ($dog) use($cat, $writer) { $cat->EnemyID = $dog->ID; $writer->write($cat); }); $owners[] = $owner; $dogs[] = $dog; $cats[] = $cat; } // writes dogs first time $writer->write($dogs); // dogs written again from owner callback $writer->write($owners); $writer->finish(); $owners = Human::get(); $dogs = Dog::get(); $cats = Cat::get(); $this->assertEquals(100, $owners->Count()); $this->assertEquals(100, $dogs->Count()); $this->assertEquals(100, $cats->Count()); for ($i = 0; $i < 100; $i++) { $owner = $owners[$i]; $dog = $dogs[$i]; $cat = $cats[$i]; $this->assertEquals($owner->ID, $dog->OwnerID); $this->assertEquals($dog->ID, $cat->EnemyID); } $writer->delete($owners); $writer->delete($dogs); $writer->delete($cats); $writer->finish(); $this->assertEquals(0, Human::get()->Count()); $this->assertEquals(0, Dog::get()->Count()); $this->assertEquals(0, Cat::get()->Count()); } }
public function on_hang_Pc() { $channel = Dog::getChannel(); if (false === isset($this->instances[$channel->getID()])) { $config = array('solution_allowed_everytime' => $this->getConfig('solve_anytime', 'c') === '1', 'placeholder' => $this->getConfig('placeholder', 'c'), 'lives' => $this->getConfig('lives', 'c'), 'singleplayer' => $this->getConfig('singleplayer', 'c') === '1'); $this->instances[$channel->getID()] = new HangmanGame($config); } $hang = $this->instances[$channel->getID()]; $hang instanceof HangmanGame; $this->reply($hang->onGuess(Dog::getUser()->getName(), $this->msgarg())); }
public function on_peak_Lc() { $channel = Dog::getChannel(); if (false === ($peak = Dog_ChannelPeak::getPeak($channel))) { return Dog::err('ERR_DATABASE', array(__FILE__, __LINE__)); } $date = $peak->getVar('lcpeak_date'); $count = $peak->getVar('lcpeak_peak'); $count_now = $channel->getUserCount(); $age = GWF_Time::displayAge($date); $date = GWF_Time::displayDate($date); $args = array($count, $channel->getName(), Dog::getServer()->displayLongName(), $date, $age, $this->peekshowstring()); $this->rply('old_peak', $args); }
public static function onLocationGlobalMessage(SR_Player $player, $key, $args = NULL) { $server = Dog::getServer(); $channel = Dog::getChannel(); $sid = $server->getID(); // $cid = $channel->getID(); $party = $player->getParty(); // $b = chr(2); // $message = sprintf('%s in %s: "%s".', $player->getName(), $party->getLocation(), $message); // $sent = 0; foreach (Shadowrun4::getParties() as $pid => $p) { // echo "party $pid\n"; if ($party->sharesLocation($p)) { // echo "partyy $pid\n"; foreach ($p->getMembers() as $m) { $m instanceof SR_Player; if ($m->isCreated()) { // if (false === ($u = $m->getUser())) // { // continue; // } // if (false === ($s = $u->getServer())) // { // continue; // } // $c = $s->getChannelByName('#shadowlamb'); // if ($sid === $s->getID()) // { // if ( ($channel !== false) && ($channel->getUserByName($u->getName()) !== false) ) // { // # TODO: fix this // // continue; # player already read it in irc. // } // } # send to player. echo "Sending to {$m->getName()}\n"; $m->msg($key, $args); // $m->message($message); // $sent++; } } } } // if ($sent > 0) // { // $player->message(sprintf('%s players on cross servers read your message inside the same location. Use #exit or privmsg/query/pm with the bot.')); // } }
public static function cleanup($message = 'Clean shutdown!') { GWF_CachedCounter::persist(); if (NULL !== Dog_Init::getStartupTime()) { GWF_Counter::increaseCount('dog_uptime', Dog_Init::getUptime()); } if (self::$CLEANED === false) { self::$CLEANED = true; foreach (Dog::getServers() as $server) { $server instanceof Dog_Server; if ($server->isConnected()) { $server->disconnect($message); } } } die(0); }
public function getItemDescription() { if (false === ($user = Dog::getUser())) { $username = ''; } else { $username = $user->getName(); } $partner = 'Your PC'; switch ($username) { case 'ynori7': $partner = 'CPUkiller'; break; case 'CPUkiller': $partner = 'ynori7'; break; } return 'Your wedding ring. You are currently married to ' . $partner . '.'; }
public static function execute(SR_Player $player, array $args) { $bot = Shadowrap::instance($player); if (count($args) < 2 || count($args) > 3) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } if (false === ($spell = SR_Spell::getSpell($args[1]))) { $bot->reply("The spell {$args[1]} is unknown."); return false; } $server = $player->getUser()->getServer(); if (false === ($user = Dog::getUserByArg($args[0]))) { $bot->reply(sprintf('The user %s is unknown.', $args[0])); return false; } if (false === ($target = Shadowrun4::getPlayerByUID($user->getID()))) { $bot->reply(sprintf('The player %s is unknown.', $user->getName())); return false; } if (false === $target->isCreated()) { $bot->reply(sprintf('The player %s has not started a game yet.', $args[0])); return false; } $by = 1; if (count($args) === 3) { if (!Common::isNumeric($args[2])) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } if (false === ($base = $player->getSpellBaseLevel($args[1]))) { $bot->reply(Shadowhelp::getHelp($player, 'gmsp')); return false; } $by = $args[2] - $base; } $target->levelupSpell($spell->getName(), $by); $target->modify(); $base = $target->getSpellBaseLevel($args[1]); return $bot->reply(sprintf('The target got changed spells!')); }
/** * * @param string $user the username * @param string|char $message the guess * @return the answer */ public function onGuess($user, $message) { $message = trim($message); if ($this->finish) { if ($message === 'false') { $this->CONFIG['solution_allowed_everytime'] = false; } $iso = Common::substrFrom($message, ' ', Dog::getChannel()->getLangISO()); $this->onStartGame($iso); } elseif ($message === '') { $this->sendOutput('The game has already started'); } else { if (GWF_String::strlen($message) !== 1) { $this->trySolution($user, $message); } else { $this->tryChar($user, $message); } if (GWF_String::toLower($this->grid) === GWF_String::tolower($this->solution)) { $this->winGame($nick); } } return $this->clearOutput(); }
/** * We got triggered by !seen. */ public function on_seen_Pb() { $argv = $this->argv(); $argc = count($argv); if ($argc === 1) { if (!preg_match('/^[a-z0-9_!]+$/iD', $argv[0])) { return Dog::rply('err_user'); } if (false === ($server = Dog::getServerBySuffix($argv[0]))) { return Dog::rply('err_server'); } if (false === ($user = Dog_User::getByLongName($argv[0]))) { return Dog::rply('err_user'); } if (false === ($seen = Dog_Seen::getSeen($user))) { return $this->rply('never', array($user->displayName())); } $channel = $seen->getChannel(); $channam = $channel === false ? '!NOCHAN!' : $channel->displayName(); $this->rply($seen->getEvent(), array($user->displayName(), $server->displayName(), $channam, $seen->displayDate(), $seen->displayAge(), $seen->getMessage())); } else { $this->showHelp('seen'); } }
function fetchDefinitionE(Dog_Plugin $plugin, $term) { $output = array(); $res = GWF_HTTP::getFromUrl('http://www.urbandictionary.com/define.php?term=' . $term); if ($res === false) { return Dog::lang('err_timeout'); } if (strstr($res, "isn't defined <a href")) { return $plugin->lang('none_yet', array($term, urlencode($term))); } preg_match('#<div class=\'meaning\'>(.+?)</div>.*?<div class=\'example\'>(.*?)</div>#s', $res, $arr); $definition = trim(html_entity_decode(strip_tags(preg_replace('#<\\s*?br\\s*?/?\\s*?>#', "\n", $arr[1])))); $definition = strtr($definition, array("\r" => ' ', "\n" => ' ')); while (false !== strstr($definition, ' ')) { $definition = str_replace(' ', ' ', $definition); } if (strlen($definition) > 800) { $definition = substr($definition, 0, 800) . '...'; } $output['definition'] = $definition; if (!empty($arr[2])) { $example = trim(html_entity_decode(strip_tags(preg_replace('#<\\s*?br\\s*?/?\\s*?>#', "\n", $arr[2])))); $example = strtr($example, array("\r" => ' | ', "\n" => ' | ')); while (false !== strstr($example, ' | | ')) { $example = str_replace(' | | ', ' | ', $example); } while (false !== strstr($example, ' ')) { $example = str_replace(' ', ' ', $example); } if (strlen($example) > 800) { $example = substr($example, 0, 800) . '...'; } $output['example'] = $example; } return $output; }
<?php $lang = array('en' => array('help' => 'Usage: %CMD%. Print memory usage statistics.', 'usage' => 'Currently there are %s in use. Max memory peak was %s.'), 'de' => array('help' => 'Nutze: %CMD%. Gibt Statistiken über die Speichernutzung aus.', 'usage' => 'Zur Zeit werden %s Speicher verwendet. Die maximale Auslastung betrug %s.')); Dog::getPlugin()->rply('usage', array(GWF_Upload::humanFilesize(memory_get_usage(true), '1000'), GWF_Upload::humanFilesize(memory_get_peak_usage(true), '1000')));
<?php $lang = array('en' => array('help' => 'Usage: %CMD% [<server>]. List the channels where %BOT% is online.', 'none' => 'I am not connected to any channel on %s.', 'out' => 'I am in %d channels on %s: %s.')); $plugin = Dog::getPlugin(); $argv = $plugin->argv(); $argc = count($argv); if ($argc === 0) { $server = Dog::getServer(); } elseif ($argc !== 1) { return $plugin->showHelp(); } else { if (false === ($server = Dog::getServerByArg($argv[0]))) { return Dog::rply('err_server'); } } if (!$server->isConnected()) { return Dog::rply('err_connection'); } $out = ''; $channels = $server->getChannels(); foreach ($channels as $channel) { $channel instanceof Lamb_Channel; $out .= sprintf(', %s(%d)', $channel->getName(), count($channel->getUsers())); } if ($out === '') { return $plugin->rply('none', array($server->displayName())); } $plugin->rply('out', array(count($channels), $server->displayName(), substr($out, 2)));
private function checkout_git(Dog_Repo $repo) { $calldata = array($repo->getGDOData()); $callback = array($this, 'after_checkout'); $callargs = array($repo->getID()); $includes = array($this->getPath() . 'workers/Dog_CVS_Git_Worker.php'); if (!Dog::getWorker()->async_method('Dog_CVS_Git_Worker', 'checkout', $calldata, $callback, $callargs, $includes)) { $this->rply('err_worker'); } else { $this->rply('msg_checking_out', array($repo->getType(), $repo->getURL(), $repo->getName())); } }
<?php $lang = array('en' => array('help' => 'Usage: %CMD% <string here>. Print the length of an ascii string. See %T%strlen8.', 'out' => 'Bytes: %s.')); $plugin = Dog::getPlugin(); if ('' === ($message = $plugin->msg())) { return $plugin->showHelp(); } $plugin->rply('out', array(strlen($message)));
<?php require 'dog.php'; $dog = new Dog('Rony'); echo 'The dog name is :' . $dog->name . '<br>'; echo 'The dog says: ' . $dog->speak() . '<br>';
<?php require_once dirname(__FILE__) . '/Dog.php'; $josefine = new Dog("Josefine", "Labrador", "Male"); $josefine->sayWoof(true); $harriet = new Dog("Harriet", "Golden retriever", "Female"); $harriet->sayWoof(false); $harriet->setName("Harry"); $harriet->sayWoof("Male"); $harriet->sayWoof(true);