public static function fromEmail($email){ $body = str_replace(array("o","l","i"), array("0","1","1"), $email["body"]); preg_match_all("/([a-z0-9]{5}[0-9])/i", $body, $handles); if(count($handles) < 2 || empty($handles[1])) { echo "Invalid email body. No proper handle specified: "; var_dump($email); return false; } $handles = __::map($handles[1], function($h){ return strtolower($h); }); preg_match("/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i", $email["overview"][0]->from, $targets); if(empty($targets)) { echo "Unable to extract target email address: "; var_dump($email); return false; } $target = $targets[0]; $request = new SubscriptionRequest(); $request->handles = $handles; $request->target = $target; $request->distribution_type = "email"; $request->subscription_request_received = $email["date_pulled"]; $request->generateId(); return $request; }
public function testNow() { // Act $x = __::now(); // Assert $this->assertEquals(true, is_numeric($x)); }
public function __construct(){ $this->handlers = __::reduce( func_get_args(), function($memo, $fulfillmentHandler){ $memo[$fulfillmentHandler->handlesType()] = $fulfillmentHandler; return $memo; },array()); }
public function testUrlify() { // Arrange $a = 'I love https://google.com'; // Act $x = __::urlify($a); // Assert $this->assertEquals('I love <a href="https://google.com">google.com</a>', $x); }
public function testRepeat() { // Arrange $string = 'foo'; // Act $x = __::repeat('foo', 3); // Assert $this->assertEquals(['foo', 'foo', 'foo'], $x); }
public function testIsString() { // Arrange $a = 'fred'; // Act $x = __::isString($a); // Assert $this->assertEquals(true, $x); }
public function __construct(){ $params = func_get_args(); if(count($params) == 0 ) throw new Exception(self::InvalidConstructionException); if(count($params) == 1 && get_class($params[0]) == "stdClass") { $this->config = $params[0]; } else { $configFiles = __::map(func_get_args(), function($path){ return "$path/config"; }); $configContents = array_merge( array((object) array()), __::map($configFiles, function($configFile){ return json_decode(file_get_contents($configFile)); }) ); $this->config = call_user_func_array( array("__", "extend"), $configContents); } }
public function testIsString() { $str1 = '1'; $str2 = 'a'; $str3 = ' '; $str4 = 'false'; $str5 = 1; $str6 = null; $str7 = true; $this->assertEquals(__::isString($str1), true); $this->assertEquals(__::isString($str2), true); $this->assertEquals(__::isString($str3), true); $this->assertEquals(__::isString($str4), true); $this->assertEquals(__::isString($str5), false); $this->assertEquals(__::isString($str6), false); $this->assertEquals(__::isString($str7), false); }
protected function getEmails(){ $mbox = imap_open("{imap.gmail.com:993/imap/ssl}{$this->mailbox}", $this->user, $this->pass) or die('Cannot connect to Gmail: ' . imap_last_error()); $emailIds = imap_search($mbox,'UNSEEN'); if(empty($emailIds)) return array(); $emails = __::map($emailIds, function($id) use($mbox) { return array( "overview" => imap_fetch_overview($mbox, $id, 0), "body" => strip_tags(imap_fetchbody($mbox, $id, 2)), "date_pulled" => date("m-d-Y") ); }); imap_close($mbox); return $emails; }
function set_sort_order($direction) { switch ($direction) { case 'asc': $this->contents = __::sortBy($this->contents, function ($block) { return -strtotime($block->connected_at); }); break; case 'desc': $this->contents = __::sortBy($this->contents, function ($block) { return strtotime($block->connected_at); }); break; case 'position': $this->contents = __::sortBy($this->contents, function ($block) { return $block->position; }); break; } }
public function testSelectRejectSortBy() { // from js $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $numbers = __($numbers)->chain()->select(function ($n) { return $n % 2 === 0; })->reject(function ($n) { return $n % 4 === 0; })->sortBy(function ($n) { return -$n; })->value(); $this->assertEquals(array(10, 6, 2), $numbers, 'filtered and reversed the numbers in OO-style call'); $numbers = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); $numbers = __::chain($numbers)->select(function ($n) { return $n % 2 === 0; })->reject(function ($n) { return $n % 4 === 0; })->sortBy(function ($n) { return -$n; })->value(); $this->assertEquals(array(10, 6, 2), $numbers, 'filtered and reversed the numbers in static call'); }
function each_channel($template) { __::each($this->channels, $template); }
public function getInstance() { if (!isset(self::$_instance)) { $c = __CLASS__; self::$_instance = new $c(); } return self::$_instance; }
public function actionSearch($query) { $query = preg_replace('/[^\\p{L}]+/u', ' ', $query); $query = trim($query); $query = preg_replace('/\\s+/', ' ', $query); if (3 > strlen($query)) { $this->render('search', array('query' => $query, 'errorMessage' => Yii::t('app', 'The search string must be atleast three characters long.'))); Yii::app()->end(); } $limit = 100; $results = array(); // Users $criteria = new CDbCriteria(); $criteria->addSearchCondition('first_name', $query, true, 'OR'); $criteria->addSearchCondition('last_name', $query, true, 'OR'); $criteria->addSearchCondition('description', $query, true, 'OR'); $criteria->order = 'registration_time'; $criteria->limit = $limit; $users = User::model()->findAll($criteria); foreach ($users as $user) { $results[] = array('name' => Yii::t('app', '{userName} – Registered @ {registrationTime}', array('{userName}' => $user->full_name, '{registrationTime}' => $user->registration_time)), 'description' => $user->description, 'url' => $this->createUrl('//user/view', array('id' => $user->id)), 'time' => $user->registration_time); } // Locations $criteria = new CDbCriteria(); $criteria->addSearchCondition('name', $query, true, 'OR'); $criteria->addSearchCondition('description', $query, true, 'OR'); $criteria->order = 'creation_time'; $criteria->limit = $limit; $locations = Location::model()->findAll($criteria); foreach ($locations as $location) { $nameParams = array('{placeName}' => $location->name, '{creationTime}' => $location->creation_time); if ($location->createdByUser) { $nameParams['{userName}'] = $location->createdByUser->full_name; $name = Yii::t('app', '{placeName} tagged by {userName} @ {creationTime}', $nameParams); } else { $name = Yii::t('app', '{placeName} tagged @ {creationTime}', $nameParams); } $results[] = array('name' => $name, 'description' => $location->description, 'url' => $this->createUrl('//location/view', array('id' => $location->id)), 'time' => $location->creation_time); } // Projects $criteria = new CDbCriteria(); $criteria->addSearchCondition('name', $query, true, 'OR'); $criteria->addSearchCondition('description', $query, true, 'OR'); $criteria->order = 'creation_time'; $criteria->limit = $limit; $projects = Project::model()->findAll($criteria); foreach ($projects as $project) { $results[] = array('name' => $project->name, 'description' => $project->description, 'url' => $this->createUrl('//location/view', array('id' => $project->location->id, '#' => $project->slug)), 'time' => $project->creation_time); } // Posts $criteria = new CDbCriteria(); $criteria->addSearchCondition('text', $query, true, 'OR'); $criteria->order = 'creation_time'; $criteria->limit = $limit; $posts = Post::model()->findAll($criteria); foreach ($posts as $post) { $nameParams = array('{userName}' => $post->user->full_name, '{creationTime}' => $post->creation_time); if ($post->feed->region) { $url = $this->createUrl('/resource/list', array('id' => $post->feed->region->id, '#' => 'post-' . $post->id)); $nameParams['{feedName}'] = $post->feed->region->name; } else { if ($post->feed->location) { $url = $this->createUrl('/location/view', array('id' => $post->feed->location->id, '#' => 'post-' . $post->id)); $nameParams['{feedName}'] = $post->feed->location->name; } else { if ($post->feed->project) { $url = $this->createUrl('/location/view', array('id' => $post->feed->project->location->id, '#' => 'post-' . $post->id)); $nameParams['{feedName}'] = $post->feed->project->name; } else { continue; } } } if (Post::TEXT === $post->type) { $name = Yii::t('app', 'Posted to {feedName} by {userName} @ {creationTime}', $nameParams); } else { if (Post::IMAGE == $post->type) { $name = Yii::t('app', 'Image added to {feedName} by {userName} @ {creationTime}', $nameParams); } else { if (Post::RESOURCE === $post->type) { $nameParams['{resourceType}'] = ucfirst(Yii::t('app', $post->resource_type)); $name = Yii::t('app', '{resourceType} added to {feedName} by {userName} @ {creationTime}', $nameParams); } else { continue; } } } $results[] = array('name' => $name, 'description' => $post->text, 'url' => $url, 'time' => $post->creation_time); } // Sort by $results = __::sortBy($results, function ($result) { return -strtotime($result['time']); }); $this->render('search', array('query' => $query, 'results' => $results)); }
echo "No Talking Points Found. Exiting\n"; exit(0); } $points = __::reduce( $points_results->rows, function($memo, $row){ $memo[$row->value->handle] = $row->value->points; return $memo; },array() ); /* ======================= Configure SubscriptionFulfilment ----------------------- */ $fulfillment = new SubscriptionFulfillment(new EmailSubscriptionFulfillment()); /* ======================== Main Distribution processing ------------------------ */ __::each($subscriptions, function($subscription) use($points, $fulfillment){ if(!$subscription) continue; $pointsForSubscriber = __::reduce( $subscription->handles, function($memo, $handle) use ($points){ if(empty($points[$handle])) return $memo; return array_merge($memo, $points[$handle]); }, array()); $fulfillment->handle($subscription, $pointsForSubscriber); });
public function testGet() { $array = ['foo' => ['bar' => 'ololo']]; $result = __::get($array, 'foo.bar'); $this->assertEquals('ololo', $result); }
public function testAfter() { // from js $testAfter = function ($afterAmount, $timesCalled) { $afterCalled = 0; $after = __::after($afterAmount, function () use(&$afterCalled) { $afterCalled++; }); while ($timesCalled--) { $after(); } return $afterCalled; }; $this->assertEquals(1, $testAfter(5, 5), 'after(N) should fire after being called N times'); $this->assertEquals(0, $testAfter(5, 4), 'after(N) should not fire unless called N times'); $this->assertEquals(1, $testAfter(0, 0), 'after(0) should fire immediately'); // docs $str = ''; $func = __::after(3, function () use(&$str) { $str = 'x'; }); $func(); $func(); $func(); $this->assertEquals('x', $str); }
public function testPluck() { $object = array(array('a' => '1', 'b' => '643'), array('a' => '2', 'b' => '423'), array('a' => '3', 'b' => '123')); $return = array(1, 2, 3); $result = __::pluck($object, 'a'); $this->assertEquals($return, $result); }
public function testRange() { // from js $this->assertEquals(array(), __::range(0), 'range with 0 as a first argument generates an empty array'); $this->assertEquals(array(0, 1, 2, 3), __::range(4), 'range with a single positive argument generates an array of elements 0,1,2,...,n-1'); $this->assertEquals(array(5, 6, 7), __::range(5, 8), 'range with two arguments a & b, a<b generates an array of elements a,a+1,a+2,...,b-2,b-1'); $this->assertEquals(array(), __::range(8, 5), 'range with two arguments a & b, b<a generates an empty array'); $this->assertEquals(array(3, 6, 9), __::range(3, 10, 3), 'range with three arguments a & b & c, c < b-a, a < b generates an array of elements a,a+c,a+2c,...,b - (multiplier of a) < c'); $this->assertEquals(array(3), __::range(3, 10, 15), 'range with three arguments a & b & c, c > b-a, a < b generates an array with a single element, equal to a'); $this->assertEquals(array(12, 10, 8), __::range(12, 7, -2), 'range with three arguments a & b & c, a > b, c < 0 generates an array of elements a,a-c,a-2c and ends with the number not less than b'); $this->assertEquals(array(0, -1, -2, -3, -4, -5, -6, -7, -8, -9), __::range(0, -10, -1), 'final example in the Python docs'); // extra $this->assertEquals(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), __::range(10)); $this->assertEquals(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), __::range(1, 11)); $this->assertEquals(array(0, 5, 10, 15, 20, 25), __::range(0, 30, 5)); $this->assertEquals(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), __(10)->range(), 'works in OO-style calls and 1 parameter'); $this->assertEquals(array(10, 11, 12), __(10)->range(13), 'works in OO-style calls and 2 parameters'); $this->assertEquals(array(3, 6, 9), __(3)->range(10, 3), 'works in OO-style calls and 3 parameters'); // docs $this->assertEquals(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9), __::range(10)); $this->assertEquals(array(1, 2, 3, 4), __::range(1, 5)); $this->assertEquals(array(0, 5, 10, 15, 20, 25), __::range(0, 30, 5)); $this->assertEquals(array(0, -1, -2, -3, -4), __::range(0, -5, -1)); $this->assertEquals(array(), __::range(0)); }
public function testTap() { // from js $intercepted = null; $interceptor = function ($obj) use(&$intercepted) { $intercepted = $obj; }; $returned = __::tap(1, $interceptor); $this->assertEquals(1, $intercepted, 'passed tapped object to interceptor'); $this->assertEquals(1, $returned, 'returns tapped object'); }
private function _exec($exec) { __::M('system/logs')->Log('exec.log', $exec); exec(self::_LIB_DIR . $exec, $output, $return); if (!empty($return) || !empty($output)) { return false; } return true; }
public function testSize() { // from js $items = (object) array('one' => 1, 'two' => 2, 'three' => 3); $this->assertEquals(3, __::size($items), 'can compute the size of an object'); // extra $this->assertEquals(0, __::size(array())); $this->assertEquals(1, __::size(array(1))); $this->assertEquals(3, __::size(array(1, 2, 3))); $this->assertEquals(6, __::size(array(null, false, array(), array(1, 2, array('a', 'b')), 1, 2))); $this->assertEquals(3, __(array(1, 2, 3))->size(), 'works with OO-style calls'); // docs $stooge = new StdClass(); $stooge->name = 'moe'; $stooge->age = 40; $this->assertEquals(2, __::size($stooge)); }
This script provides single phonetic transcriptions as downloads in textfiles. */ //Checking if all expected parameters are given: $params = array('word', 'language', 'study', 'n'); foreach ($params as $p) { if (!array_key_exists($p, $_GET)) { die('The following parameters must be supplied: ' . implode(', ', $params)); } } //Setup: chdir('..'); require_once 'config.php'; //Transcription to work with: $ts = DataProvider::getTranscriptions($_GET['study']); $ts = $ts[$_GET['language'] . $_GET['word']]; //The Phonetic: $ps = $ts['Phonetic']; if (__::isArray($ps)) { $n = preg_match('/^\\d+$/', $_GET['n']) ? $_GET['n'] : 0; if ($n >= count($ps)) { die('Sorry, cannot deliver n=' . $n . ' for values: ' . implode(', ', $ts)); } else { $ps = $ps[$n]; } } //Figuring out the filename: $file = preg_replace('/mp3/', 'txt', basename(current($ts['soundPaths']))); //Delivering the content: header('Content-Type: text/plain; charset=utf-8'); header('Content-Disposition: attachment;filename="' . $file . '"'); echo $ps;
public function testTap() { // from js $intercepted = null; $interceptor = function ($obj) use(&$intercepted) { $intercepted = $obj; }; $returned = __::tap(1, $interceptor); $this->assertEquals(1, $intercepted, 'passed tapped object to interceptor'); $this->assertEquals(1, $returned, 'returns tapped object'); $returned = __(array(1, 2, 3))->chain()->map(function ($n) { return $n * 2; })->max()->tap($interceptor)->value(); $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain'); $returned = __::chain(array(1, 2, 3))->map(function ($n) { return $n * 2; })->max()->tap($interceptor)->value(); $this->assertTrue($returned === 6 && $intercepted === 6, 'can use tapped objects in a chain with static call'); // docs $interceptor = function ($obj) { return $obj * 2; }; $result = __(array(1, 2, 3))->chain()->max()->tap($interceptor)->value(); $this->assertEquals(3, $result); }
header('LOCATION: index.php'); } if (!session_mayEdit($dbConnection)) { header('LOCATION: index.php'); } ?> <!DOCTYPE HTML> <html> <?php $title = "Import of .csv files."; $jsFiles = array('dbimport.js'); require_once 'head.php'; //<script type='application/javascript' src='js/main.js'></script> $max = ini_get_all(); $max = $max['max_file_uploads']; $max = __::min(array($max['global_value'], $max['local_value'])); ?> <body><?php require_once 'topmenu.php'; ?> <form class="form-inline"> <label> View the data for a LanguageFamily: <select name="languagefamily" id="select_languagefamily"></select> </label> </form> <div class="row-fluid"> <form class="form-horizontal span6"> <legend>Insert a new Languagefamily:</legend> <div class="control-group"> <label class="control-label" for="studyIx">StudyIx:</label>
// Set default variables for all new objects var $Host = "smtp.gmail.com"; var $Mailer = "smtp"; var $SMTPAuth = true; var $SMTPSecure = "ssl"; var $Port = 465; var $Username = "******"; var $Password = "******"; var $Subject = 'A Quote has been requested'; var $AltBody = 'To view the message, please use an HTML compatible email viewer!'; } __::templateSettings(array('evaluate' => '/\\{\\{(.+?)\\}\\}/', 'interpolate' => '/\\{\\{=(.+?)\\}\\}/', 'escape' => '/\\{\\{-(.+?)\\}\\}/')); $template = file_get_contents('./emailTemplate.php'); $compiled = __::template($template); $confirmation = file_get_contents("./confirmTemplate.php"); $compiledConfirmation = __::template($confirmation); if (isset($_POST)) { $mail = new SSPMailer(true); // the true param means it will throw exceptions on errors, which we need to catch try { $mail->AddAddress("*****@*****.**"); $mail->AddAddress("*****@*****.**"); $mail->AddReplyTo($_POST['email'], $_POST['fName'] . ' ' . $_POST['lName']); $mail->SetFrom($_POST['email'], $_POST['fName'] . ' ' . $_POST['lName']); $mail->MsgHTML($compiled($_POST)); foreach ($_POST['items'] as $item) { if (strpos($item['art'], '.zip') !== false) { $mail->AddAttachment($item['art']); } } $mail->Send();
/** @param $fs [[name => String, path => String]] @param $uId UserId for Edit_Importes table @param $merge Bool true if data should be merged/replaced rather than overwritten @return $log [String] of errors/warnings found by the Importer */ public static function processFiles($fs, $uId, $merge) { array_push(self::$log, "Importer::processFiles for uId {$uId}; merge={$merge}"); $qqs = array(); foreach ($fs as $f) { array_push($qqs, self::mkQueries($f['name'], file_get_contents($f['path']), $merge)); } self::execQueries(__::flatten($qqs), $uId); //Finish, cleaning the log: $log = self::$log; self::$log = array(); return $log; }
$projectFeedIds[] = $project->feed_id; } } $criteria = new CDbCriteria(); $criteria->addColumnCondition(array('type' => Post::RESOURCE)); if (null !== $resource_type) { $criteria->addColumnCondition(array('resource_type' => $resource_type)); } $criteria->addInCondition('feed_id', $projectFeedIds); $projectResources = Post::model()->findAll($criteria); $projectResources = __::map($projectResources, function ($post) { return array('post' => $post, 'scope' => 'project'); }); // All posts $resources = __::sortBy(array_merge($regionResources, $locationResources, $projectResources), function ($post) { return -strtotime($post['post']->creation_time); }); // Render the view $title = '<a href="' . $this->createUrl('list', array('region' => $region->id)) . '">'; $title .= Yii::t('app', 'Resources'); $title .= '</a>'; $title .= 'skill' === $resource_type ? '<a class="type selected" ' : '<a class="type" '; $title .= 'href="' . $this->createUrl('list', array('region' => $region->id, 'type' => 'skill')) . '">'; $title .= Yii::t('app', 'Skills'); $title .= '</a>'; $title .= 'material' === $resource_type ? '<a class="type selected" ' : '<a class="type" '; $title .= 'href="' . $this->createUrl('list', array('region' => $region->id, 'type' => 'material')) . '">'; $title .= Yii::t('app', 'Materials'); $title .= '</a>'; $title .= 'tool' === $resource_type ? '<a class="type selected" ' : '<a class="type" '; $title .= 'href="' . $this->createUrl('list', array('region' => $region->id, 'type' => 'tool')) . '">';
public function addTemple($data) { $type = $data->{"type"}; $template = ""; switch ($type) { case 1: $template = $this->tpl_diy_con_type1; break; case 2: $template = $this->tpl_diy_con_type2; break; case 3: $template = $this->tpl_diy_con_type3; break; case 4: $template = $this->tpl_diy_con_type4; break; case 5: $template = $this->tpl_diy_con_type5; break; case 6: $template = $this->tpl_diy_con_type6; break; case 7: $template = $this->tpl_diy_con_type7; break; case 8: $template = $this->tpl_diy_con_type8; break; case 9: $template = $this->tpl_diy_con_type9; break; case 10: $template = $this->tpl_diy_con_type10; break; case 11: $template = $this->tpl_diy_con_type11; break; case 12: $template = $this->tpl_diy_con_type12; break; case 13: $template = $this->tpl_diy_con_type13; break; case 14: $template = $this->tpl_diy_con_type14; break; case 15: $template = $this->tpl_diy_con_type15; break; case 16: $template = $this->tpl_diy_con_type16; break; case 17: $template = $this->tpl_diy_con_type17; break; } $basicTemplate = __::template($template); return $basicTemplate($data); }
public function testEscape() { // from js $this->assertEquals('Curly & Moe', __::escape('Curly & Moe')); $this->assertEquals('Curly &amp; Moe', __::escape('Curly & Moe')); // extra $this->assertEquals('Curly & Moe', __('Curly & Moe')->escape()); $this->assertEquals('Curly &amp; Moe', __('Curly & Moe')->escape()); }