/** * _mapping method * * @param int $start * @param int $end * @return array */ protected function _mapping($start = 0, $end = 0) { $mapping = array(); for ($i = 1; $i <= 10; $i++) { $mapping[$i] = array('version' => $i, 'name' => "00{$i}_schema_dump", 'class' => 'M4af9d151e1484b74ad9d007058157726', 'type' => 'mocks', 'migrated' => null); if ($i >= $start && $i <= $end) { $mapping[$i]['migrated'] = CakeTime::nice(); } } return $mapping; }
/** * Returns a nicely formatted date string for given Datetime string. * * @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object * @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object * @param string $format The format to use. If null, `CakeTime::$niceFormat` is used * * @return string Formatted date string * @see CakeTime::nice() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function nice($dateString = NULL, $timezone = NULL, $format = NULL) { return $this->_engine->nice($dateString, $timezone, $format); }
/** * Shows a list of available migrations * * @param array $mapping Migration mapping * @param string $type Can be 'app' or a plugin name * @return void */ protected function _showInfo($mapping, $type = null) { if ($type === null) { $type = $this->type; } $version = $this->Version->getVersion($type); if ($version != 0) { $info = $mapping[$version]; $this->out(__d('migrations', 'Current migration version:')); $this->out(' #' . sprintf("%'.03d", $version) . ' ' . $info['name']); $this->hr(); } $this->out(__d('migrations', 'Available migrations:')); foreach ($mapping as $version => $info) { $this->out(' [' . sprintf("%'.03d", $version) . '] ' . $info['name']); $this->out(' ', false); if ($info['migrated'] !== null) { $this->out(__d('migrations', 'applied') . ' ' . CakeTime::nice(strtotime($info['migrated']))); } else { $this->out(__d('migrations', 'not applied')); } } }
/** * Returns a nicely formatted date string for given Datetime string. * * @param int|string|DateTime $dateString UNIX timestamp, strtotime() valid string or DateTime object * @param string|DateTimeZone $timezone User's timezone string or DateTimeZone object * @param string $format The format to use. If null, `CakeTime::$niceFormat` is used * @return string Formatted date string * @see CakeTime::nice() * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#formatting */ public function nice($dateString = null, $timezone = null, $format = null) { return $this->_engine->nice($dateString, $timezone, $format); }
public function testRenderCell() { $data = array('User' => array('id' => 1, 'first_name' => 'John', 'last_name' => 'Doe', 'email' => '*****@*****.**', 'created' => date('Y-m-d H:i:s')), 'Comment' => array(array('id' => 1, 'text' => 'foo bar'), array('id' => 2, 'text' => 'FOO BAR'))); $result = $this->Table->renderCell('[time][User.created][/time]', $data); $expected = CakeTime::nice($data['User']['created']); $this->assertEqual($result, $expected); $result = $this->Table->renderCell('[truncate length=9 ellipsis=..][Comment.{n, }.text][/truncate]', $data); $expected = 'foo bar..'; $this->assertEqual($result, $expected); $result = $this->Table->renderCell('[truncate length=9 ellipsis=..][Comment.{n}.invalid][/truncate]', $data); $expected = ''; $this->assertEqual($result, $expected); $result = $this->Table->renderCell('[url]/users/email/[User.email][/url]', $data); $expected = $this->Table->url('/users/email/john@doe.com'); $this->assertEqual($result, $expected); $result = $this->Table->renderCell('[image][url full]/users/email/[User.email][/url][/image]', $data); $expected = $this->Table->Html->image($this->Table->url('/users/email/john@doe.com', true)); $this->assertEqual($result, $expected); $result = $this->Table->renderCell('[User.[php]return "first_name";[/php]]', $data); $expected = 'John'; $this->assertEqual($result, $expected); $txt = <<<TEXT [php] if ("[User.id]" == "1") { \techo ' <div class="btn-group pull-right"> <button type="button" class="btn btn-xs btn-default"><a href="[php]return Router::url(array_merge(array('plugin' => null, 'controller' => 'properties'), array("action" => "view", "[User.id]")));[/php]">[__d|dashboard]Details[/__d]</a></button> </div> \t'; }[/php] TEXT; $expected = <<<TEXT <div class="btn-group pull-right"> <button type="button" class="btn btn-xs btn-default"><a href="/properties/view/1">Details</a></button> </div> \t TEXT; $result = $this->Table->renderCell($txt, $data); $this->assertEqual($result, $expected); $txt = <<<TEXT [php] if ("[User.id]" == "1") { \techo ' <div class="btn-group pull-right"> <button type="button" class="btn btn-xs btn-default"><a href="[php]return Router::url(array_merge(array('plugin' => null, 'controller' => 'properties'), array("action" => "view", "[User.id]")));[/php]">[__d|dashboard]Details[/__d]</a></button> <button type="button" class="btn btn-xs btn-default"><a href="[php]return Router::url(array_merge(array('plugin' => null, 'controller' => 'properties'), array("action" => "view", "[User.id]")));[/php]">[__d|dashboard]Details[/__d]</a></button> </div> \t'; }[/php] TEXT; $expected = <<<TEXT <div class="btn-group pull-right"> <button type="button" class="btn btn-xs btn-default"><a href="/properties/view/1">Details</a></button> <button type="button" class="btn btn-xs btn-default"><a href="/properties/view/1">Details</a></button> </div> \t TEXT; $result = $this->Table->renderCell($txt, $data); $this->assertEqual($result, $expected); }
public function upload() { $this->layout = 'ajax'; $this->render(false); if ($this->request->is('POST')) { if (!empty($this->request->data['Post']['file'])) { if (!$this->request->data['Post']['file']['error']) { $extension = pathinfo($this->request->data['Post']['file']['name'], PATHINFO_EXTENSION); if (!in_array($extension, array('jpg', 'jpeg', 'JPG', 'JPEG'))) { echo json_encode(array('error' => __('We only accept JPG or JPEG photo!'))); return; } if (!file_exists(IMAGES . 'photos')) { App::uses('Folder', 'Utility'); new Folder(IMAGES . 'photos', true, 0775); } $filename = md5(microtime()) . '.jpg'; if (@move_uploaded_file($this->request->data['Post']['file']['tmp_name'], IMAGES . 'photos' . DS . $filename)) { if (@exif_read_data(IMAGES . 'photos' . DS . $filename)) { App::uses('CakeTime', 'Utility'); $exif = exif_read_data(IMAGES . 'photos' . DS . $filename); $coordinates = $this->_getCoordinates($exif); $datetime_original = isset($exif['DateTimeOriginal']) ? CakeTime::nice($exif['DateTimeOriginal']) : CakeTime::nice(); echo json_encode(array('coordinates' => $coordinates, 'photo' => $filename, 'datetime_original' => $datetime_original)); return; } else { echo json_encode(array('error' => __('Unable to analyze your photo.'))); return; } } else { echo json_encode(array('error' => __('Unable to upload your photo.'))); return; } } else { echo json_encode(array('error' => $this->request->data['Post']['file']['error'])); return; } } } echo json_encode(array('photo' => null)); }