public function beforeSave($options = array()) { if (!isset($this->data['Comment']['id'])) { $this->data['Comment']['hash'] = String::uuid(); } return true; }
/** * Format data so that it can be processed by MetaBehavior for saving */ public function onBeforeSaveNode(CakeEvent $event) { $data =& $event->data; if (isset($data['data']['SeoLite'])) { if (empty($data['data']['Meta'])) { $data['data']['Meta'] = array(); } $values = array_values($data['data']['SeoLite']); foreach ($values as $value) { if (strlen($value['id']) == 36) { unset($value['id']); } if (!empty($value['value'])) { $data['data']['Meta'][String::uuid()] = $value; } else { // mark empty records for deletion if (isset($value['id'])) { $data['delete'][] = $value['id']; } } } } unset($data['data']['SeoLite']); return $event; }
public function importKeywords() { $db = ConnectionManager::getDataSource('default'); $mysqli = new mysqli($db->config['host'], $db->config['login'], $db->config['password'], $db->config['database']); $sql = array('links', 'links_keywords'); foreach (glob('/home/kiang/public_html/news/cache/output/*.json') as $jsonFile) { $json = json_decode(file_get_contents($jsonFile), true); $newLinkId = String::uuid(); $json['title'] = $mysqli->real_escape_string(trim($json['title'])); $json['url'] = $mysqli->real_escape_string($json['url']); $json['created'] = date('Y-m-d H:i:s', $json['created_at']); $sql['links'][] = "('{$newLinkId}', '{$json['title']}', '{$json['url']}', '{$json['created']}')"; foreach ($json['keywords'] as $keywordId => $summary) { $lkId = String::uuid(); $summary = $mysqli->real_escape_string(trim($summary)); $sql['links_keywords'][] = "('{$lkId}', '{$newLinkId}', '{$keywordId}', '{$summary}')"; } unlink($jsonFile); } if (!empty($sql['links'])) { $linksSql = 'INSERT INTO links VALUES ' . implode(',', $sql['links']) . ";\n"; $lkSql = 'INSERT INTO links_keywords VALUES ' . implode(',', $sql['links_keywords']) . ';'; file_put_contents(TMP . 'keywords.sql', $linksSql . $lkSql); } }
public function __construct() { foreach ($this->records as &$row) { $row['id'] = String::uuid(); } parent::__construct(); }
/** * Turns byte64 submitted data into files * * @param Model $model * @param Array $options * @return void */ public function beforeSave(Model $model, $options = []) { foreach ($model->data[$model->alias] as $field => $value) { //for each result if (strrpos($field, 'asset_') === 0) { //if it's a asset field if (strrpos($value, 'data:') === 0) { //if the asset field has byte64 data $m = explode(':', $value); $m = array_pop($m); $r = $m = explode(';base64,', $m); $m = array_shift($m); $base64data = array_pop($r); if (isset($this->extensionMap[$m])) { $data = base64_decode($base64data); $name = String::uuid() . '.' . $this->extensionMap[$m]; file_put_contents($this->assetFolder . DS . $name, $data); $model->data[$model->alias][$field] = $name; } else { throw new exception('Unknow mime type (' . $m . ') for asset file, please add the mime type to the extension map'); } } } } }
public function beforeSave($options = array()) { if (isset($this->data['Candidate']['image']) && is_array($this->data['Candidate']['image'])) { if (!empty($this->data['Candidate']['image']['size'])) { $im = new Imagick($this->data['Candidate']['image']['tmp_name']); $im->resizeImage(512, 512, Imagick::FILTER_CATROM, 1, true); $path = WWW_ROOT . 'media'; $fileName = str_replace('-', '/', String::uuid()) . '.jpg'; if (!file_exists($path . '/' . dirname($fileName))) { mkdir($path . '/' . dirname($fileName), 0777, true); } $im->writeImage($path . '/' . $fileName); if (file_exists($path . '/' . $fileName)) { $this->data['Candidate']['image'] = $fileName; } else { unset($this->data['Candidate']['image']); } } else { unset($this->data['Candidate']['image']); } } if (isset($this->data['Candidate']['name'])) { $this->data['Candidate']['name'] = str_replace(array('•', '•', '‧', '.', '•', '..'), '.', $this->data['Candidate']['name']); } return parent::beforeSave($options); }
/** * After migration callback * * @param string $direction, up or down direction of migration process * @return boolean Should process continue * @access public */ public function after($direction) { if ($direction == 'up') { $Channel = ClassRegistry::init('Channel'); $User = ClassRegistry::init('User'); $User->create(); $user = $User->save(array( 'username' => 'test'.substr(md5(String::uuid()),0 ,5), 'password' => 'test1234', 'email' => strtolower('test').substr(md5(String::uuid()),0 ,5).'@5stars.vn', 'status' => 'active', 'role' => 'channel', 'fullname' => 'Test Channel' )); $Channel->save(array( 'id' => 100, 'user_id' => $user['User']['id'], 'status' => 'active', 'login_connection' => 1, 'payment_connection' => 1, 'exchange_rate' => 1 )); } return true; }
/** * Generate authorization hash. * * @return string Hash * @access public * @static */ function generateAuthKey() { if (!class_exists('String')) { App::import('Core', 'String'); } return Security::hash(String::uuid()); }
/** * testAddWithPreSpecifiedId method * * @return void */ public function testAddWithPreSpecifiedId() { extract($this->settings); $this->Tree = new $modelClass(); $this->Tree->initialize(2, 2); $data = $this->Tree->find('first', array( 'fields' => array('id'), 'conditions' => array($modelClass . '.name' => '1.1') )); $id = String::uuid(); $this->Tree->create(); $result = $this->Tree->save(array($modelClass => array( 'id' => $id, 'name' => 'testAddMiddle', $parentField => $data[$modelClass]['id']) )); $expected = array_merge( array($modelClass => array('id' => $id, 'name' => 'testAddMiddle', $parentField => '2')), $result ); $this->assertSame($expected, $result); $this->assertTrue($this->Tree->verify()); }
function main() { if (empty($this->args)) { return $this->err('Usage: ./cake uuidize <table>'); } if ($this->args[0] == '?') { return $this->out('Usage: ./cake uuidize <table> [-force] [-reindex]'); } $options = array('force' => false, 'reindex' => false); foreach ($this->params as $key => $val) { foreach ($options as $name => $option) { if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) { $options[$name] = true; } } } foreach ($this->args as $table) { $name = Inflector::classify($table); $Model = new AppModel(array('name' => $name, 'table' => $table)); $records = $Model->find('all'); foreach ($records as $record) { $Model->updateAll(array('id' => '"' . String::uuid() . '"'), array('id' => $record[$name]['id'])); } } }
/** * add method * * @return void */ public function add() { if ($this->request->is('post')) { $this->CustomerInfo->begin(); $this->CustomerInfo->create(); $this->request->data['CustomerInfo']['id'] = String::uuid(); if ($this->CustomerInfo->save($this->request->data)) { $this->CusRegAddr->begin(); $this->CusRegAddr->create(); $this->request->data['CusRegAddr']['customer_info_id'] = $this->request->data['CustomerInfo']['id']; if ($this->CusRegAddr->save($this->request->data)) { $this->CustomerInfo->commit(); $this->CusRegAddr->commit(); $this->Session->setFlash(__('The customer information has been saved'), 'flash_success'); $this->redirect(array('action' => 'index')); } else { $this->CusRegAddr->rollback(); $this->CustomerInfo->rollback(); } } else { $this->CustomerInfo->rollback(); $this->Session->setFlash(__('The customer information could not be saved. Please, try again.'), 'flash_fail'); } } $postCodes = $this->PostCode->find('list'); $towns = $this->Town->find('list'); $counties = $this->County->find('list'); $this->set(compact('postCodes', 'towns', 'counties')); }
private function request_id() { if (empty(self::$_request_id)) { self::$_request_id = String::uuid(); } return self::$_request_id; }
public function beforeSave(Model $model) { if (empty($model->id) && $model->hasField('uuid')) { $model->data[$model->alias]['uuid'] = String::uuid(); } return true; }
public function checkLogin() { $this->autoRender = false; if ($this->Session->check('Test.authId')) { die(json_encode(array('status' => true))); } else { if ($this->Session->check('Test.token')) { $result = $this->GameApi->resource('User')->request('/checkLogin',array( 'method' => 'POST', 'data' => array( 'channelId' => $this->Session->read('Test.channelId'), 'gameId' => $this->Session->read('Test.gameId'), 'token' => $this->Session->read('Test.token') ))); if (!empty($result['login_status']) && $result['login_status'] == 1) { $this->Session->write('Test.authId',$result['userId']); die(json_encode(array('status' => true))); } else { die(json_encode(array('status' => 'error'))); } } else { $this->Session->write('Test.token', String::uuid()); die(json_encode(array('status' => 'open', 'token' => $this->Session->read('Test.token')))); } } }
function main() { if (empty($this->args)) { return $this->err('Usage: ./cake fixturize <table>'); } if ($this->args[0] == '?') { return $this->out('Usage: ./cake fixturize <table> [-force] [-reindex]'); } $options = array('force' => false, 'reindex' => false); foreach ($this->params as $key => $val) { foreach ($options as $name => $option) { if (isset($this->params[$name]) || isset($this->params['-' . $name]) || isset($this->params[$name[0]])) { $options[$name] = true; } } } foreach ($this->args as $table) { $name = Inflector::classify($table); $Model = new AppModel(array('name' => $name, 'table' => $table)); $file = sprintf('%stests/fixtures/%s_fixture.php', APP, Inflector::underscore($name)); $File = new File($file); if ($File->exists() && !$options['force']) { $this->err(sprintf('File %s already exists, use --force option.', $file)); continue; } $records = $Model->find('all'); $out = array(); $out[] = '<?php'; $out[] = ''; $out[] = sprintf('class %sFixture extends CakeTestFixture {', $name); $out[] = sprintf(' var $name = \'%s\';', $name); $out[] = ' var $records = array('; $File->write(join("\n", $out)); foreach ($records as $record) { $out = array(); $out[] = ' array('; if ($options['reindex']) { foreach (array('old_id', 'vendor_id') as $field) { if ($Model->hasField($field)) { $record[$name][$field] = $record[$name]['id']; break; } } $record[$name]['id'] = String::uuid(); } foreach ($record[$name] as $field => $val) { $out[] = sprintf(' \'%s\' => \'%s\',', addcslashes($field, "'"), addcslashes($val, "'")); } $out[] = ' ),'; $File->write(join("\n", $out)); } $out = array(); $out[] = ' );'; $out[] = '}'; $out[] = ''; $out[] = '?>'; $File->write(join("\n", $out)); $this->out(sprintf('-> Create %sFixture with %d records (%d bytes) in "%s"', $name, count($records), $File->size(), $file)); } }
public function forgotPassword($data) { $saveData = array(); $email = $data['email']; $respone = array(); $options = array('conditions' => array('User.email' => $email)); $user = $this->find("first", $options); if ($user) { $resetCode = Security::hash(String::uuid(), 'sha1', true); $url = Router::url(array('controller' => 'users', 'action' => 'resetPassword'), true) . '?code=' . $resetCode; //Removing any previously generated $this->ResetPassword->deleteAll(array('ResetPassword.user_id' => $user['User']['id']), false); //saving validation code $saveData['ResetPassword'] = array('user_id' => $user['User']['id'], 'reset_code' => $resetCode); $status = $this->ResetPassword->saveAll($saveData, array('validate' => false)); if ($status) { $Email = new Email(); $message = 'Reset password'; $message .= "Copy and Paste following url in your browser:\n"; $message .= $url; if (SEND_EMAIL) { $emailStatus = $Email->sendEmail($email, $message, EMAIL_TPL_RESET_PASSWORD); } else { $emailStatus = true; } if ($emailStatus) { return array('status' => true, 'success_msg' => USER_RESET_PASSWORD_SUCCESS); } } else { return array('status' => false, 'errors' => USER_ERR_RESET_PASSWORD_FAILED); } } else { return array('status' => false, 'errors' => USER_ERR_EMAIL_NOT_REGISTERED); } }
/** * Meta field: with key/value fields * * @param string $key (optional) key * @param string $value (optional) value * @param integer $id (optional) ID of Meta * @param array $options (optional) options * @return string */ public function field($key = '', $value = null, $id = null, $options = array()) { $inputClass = $this->Layout->cssClass('formInput'); $_options = array('key' => array('label' => __d('croogo', 'Key'), 'value' => $key), 'value' => array('label' => __d('croogo', 'Value'), 'value' => $value, 'type' => 'textarea', 'rows' => 2)); if ($inputClass) { $_options['key']['class'] = $_options['value']['class'] = $inputClass; } $options = Hash::merge($_options, $options); $uuid = String::uuid(); $fields = ''; if ($id != null) { $fields .= $this->Form->input('Meta.' . $uuid . '.id', array('type' => 'hidden', 'value' => $id)); $this->Form->unlockField('Meta.' . $uuid . '.id'); } $fields .= $this->Form->input('Meta.' . $uuid . '.key', $options['key']); $fields .= $this->Form->input('Meta.' . $uuid . '.value', $options['value']); $this->Form->unlockField('Meta.' . $uuid . '.key'); $this->Form->unlockField('Meta.' . $uuid . '.value'); $fields = $this->Html->tag('div', $fields, array('class' => 'fields')); $id = is_null($id) ? $uuid : $id; $deleteUrl = $this->settings['deleteUrl']; $deleteUrl[] = $id; $actions = $this->Html->link(__d('croogo', 'Remove'), $deleteUrl, array('class' => 'remove-meta', 'rel' => $id)); $actions = $this->Html->tag('div', $actions, array('class' => 'actions')); $output = $this->Html->tag('div', $actions . $fields, array('class' => 'meta')); return $output; }
/** * Generate authorization hash. * * @return string Hash * @access public * @static */ public static function generateAuthKey() { if (!class_exists('String')) { App::import('Core', 'String'); } return self::hash(String::uuid()); }
function signup() { if ($this->data) { if ($this->data['User']['password'] == $this->Auth->password($this->data['User']['password_confirm'])) { $this->User->create(); if ($this->User->save($this->data)) { $this->User->saveField('uid', "u{$this->User->id}"); $this->User->saveField('activate_code', String::uuid()); if ($this->Auth->login($this->data)) { /* if($this->_sendMail($this->User->id)){ $this->Session->setFlash('email sent'); }else{ $this->Session->setFlash('email not sent'); }*/ $this->redirect("home"); } else { } } else { $this->data['User']['password'] = ''; $this->data['User']['password_confirm'] = ''; $this->Session->setFlash('something wrong!'); } } } }
/** * undocumented function * * @return void * @access public */ function testGiftsAddRedirectsIfNoValidAppealGiven() { $this->fakeRequest('get'); $this->Sut->params['named']['appeal_id'] = ''; $this->Sut->add(); $this->is($this->Sut->redirectUrl, '/'); // any non existant appeal id $this->Sut->redirectUrl = ''; $this->Sut->params['named']['appeal_id'] = String::uuid(); $this->Sut->add(); $this->is($this->Sut->redirectUrl, '/'); // valid appeal id $this->Sut->redirectUrl = false; $this->Sut->params['named']['appeal_id'] = $this->gpiAppealId; $this->Sut->add(); $this->false($this->Sut->redirectUrl); // setting appeal id allowed only at step 1 if different from session office id $this->Sut->redirectUrl = false; $this->Sut->params['named']['appeal_id'] = $this->gpiAppealId; $this->Sut->add(); $this->false($this->Sut->redirectUrl); $this->Sut->params['named']['appeal_id'] = $this->exampleAppealId; $this->Sut->add(2); $this->is($this->Sut->redirectUrl, '/'); $this->Sut->redirectUrl = false; $this->Sut->params['named']['appeal_id'] = $this->gpiAppealId; $this->Sut->add(); $this->false($this->Sut->redirectUrl); $this->Sut->params['named']['appeal_id'] = $this->gpiAppealId; $this->Sut->add(2); $this->false($this->Sut->redirectUrl); }
/** * undocumented function * * @return void * @author apple **/ function saveData($data, $uid, $id) { if (!$this->id) { $this->set('FCreatedate', date('Y-m-d H:i:s')); } $this->set('Id', $this->id ? $this->id : String::uuid()); $this->set('FUpdatedate', date('Y-m-d H:i:s')); $this->set('FWebchat', $id); $twj = array_filter($this->data['WxDataTw']['FTwj']); $this->data['WxDataTw']['FTwj'] = serialize(array_values($twj)); $twData = $this->data; $query = $this->save($this->data, FALSE); if ($query) { switch ($twData['WxDataTw']['FTwType']) { case 'events': $dbExtra = ClassRegistry::init('WxDataTwEvent'); $eData = $dbExtra->find('first', array('conditions' => array('FOwnerId' => $this->id), 'recursive' => 0)); if (isset($eData['WxDataTwEvent']['Id'])) { $dbExtra->id = $eData['WxDataTwEvent']['Id']; } else { $dbExtra->set('Id', String::uuid()); $dbExtra->set('FCreatedate', date('Y-m-d H:i:s')); } $dbExtra->set('FOwnerId', $this->id); $dbExtra->save(); break; default: } return $this->id; } }
/** * Save uploaded file * * @param array $data data as POSTed from form * @return array|boolean false for errors or array containing fields to save */ protected function _saveUploadedFile($data) { $file = $data[$this->alias]['file']; unset($data[$this->alias]['file']); // check if file with same path exists $destination = WWW_ROOT . $this->uploadsDir . DS . $file['name']; if (file_exists($destination)) { $newFileName = String::uuid() . '-' . $file['name']; $destination = WWW_ROOT . $this->uploadsDir . DS . $newFileName; } else { $newFileName = $file['name']; } // remove the extension for title if (explode('.', $file['name']) > 0) { $fileTitleE = explode('.', $file['name']); array_pop($fileTitleE); $fileTitle = implode('.', $fileTitleE); } else { $fileTitle = $file['name']; } $data[$this->alias]['title'] = $fileTitle; $data[$this->alias]['slug'] = $newFileName; $data[$this->alias]['body'] = ''; $data[$this->alias]['mime_type'] = $file['type']; $data[$this->alias]['type'] = $this->type; $data[$this->alias]['path'] = '/' . $this->uploadsDir . '/' . $newFileName; // move the file $moved = move_uploaded_file($file['tmp_name'], $destination); if ($moved) { return $data; } return false; }
/** * Meta field: with key/value fields * * @param string $key (optional) key * @param string $value (optional) value * @param integer $id (optional) ID of Meta * @param array $options (optional) options * @return string */ public function field($key = '', $value = null, $id = null, $options = array()) { $_options = array('key' => array('label' => __d('croogo', 'Key'), 'value' => $key, 'class' => 'span12'), 'value' => array('label' => __d('croogo', 'Value'), 'value' => $value, 'class' => 'span12', 'type' => 'textarea', 'rows' => 2)); $options = Hash::merge($_options, $options); $uuid = String::uuid(); $fields = ''; if ($id != null) { $fields .= $this->Form->input('Meta.' . $uuid . '.id', array('type' => 'hidden', 'value' => $id)); $this->Form->unlockField('Meta.' . $uuid . '.id'); } $fields .= $this->Form->input('Meta.' . $uuid . '.key', $options['key']); $fields .= $this->Form->input('Meta.' . $uuid . '.value', $options['value']); $this->Form->unlockField('Meta.' . $uuid . '.key'); $this->Form->unlockField('Meta.' . $uuid . '.value'); $fields = $this->Html->tag('div', $fields, array('class' => 'fields')); $id = is_null($id) ? $uuid : $id; $deleteUrl = array_intersect_key($this->request->params, array('admin' => null, 'plugin' => null, 'controller' => null, 'named' => null)); $deleteUrl['action'] = 'delete_meta'; $deleteUrl[] = $id; $deleteUrl = $this->url($deleteUrl); $actions = $this->Html->link(__d('croogo', 'Remove'), $deleteUrl, array('class' => 'remove-meta', 'rel' => $id)); $actions = $this->Html->tag('div', $actions, array('class' => 'actions')); $output = $this->Html->tag('div', $actions . $fields, array('class' => 'meta')); return $output; }
/** * Generates and outputs a list of $n (=10) UUIDs, useful for creating fixture records. * * @return void * @access public */ function uuid() { $n = isset($this->args[0]) ? (int) $this->args[0] : 10; for ($i = 0; $i < $n; $i++) { $this->out(String::uuid()); } }
/** * 写入Wxsess * * @return void * @author apple **/ function write($name, $data) { $id = $this->wxid; $wxdata = $this->find('first', array('conditions' => array('FWebchat' => $id), 'recursive' => 0)); $wxid = isset($wxdata['WxSession']['Id']) ? $wxdata['WxSession']['Id'] : ''; $this->id = $wxid; $data = array($name => $data); if ($this->id) { $wxdata_FData = unserialize($wxdata['WxSession']['FData']); $data = $wxdata_FData ? array_merge($wxdata_FData, $data) : $data; $data = $data ? serialize($data) : ''; } else { $this->set('FCreatedate', date('Y-m-d H:i:s')); $data = serialize($data); } $this->set('Id', $this->id ? $this->id : String::uuid()); $this->set('FUpdatedate', date('Y-m-d H:i:s')); $this->set('FWebchat', $id); $this->set('FData', $data); $this->set('FExpires', time() + $this->expires); // echo '<pre>';print_r($this->data);exit; $query = $this->save($this->data); if ($query) { return $this->id; } }
function register() { if ($this->data) { if (!preg_match('/[\\.][a-zA-Z]{2,4}/', $this->data['Site']['domain'])) { $this->Session->setFlash("请使用合法域名!"); $this->redirect('/sites/register'); exit; } if ($this->Site->findByDomain($this->data['Site']['domain']) > 0) { $this->Session->setFlash("该域名已经注册,请更换一个!"); $this->redirect('/sites/register'); exit; } $this->Site->create(); $this->data['Site']['apikey'] = String::uuid(); $this->Site->save($this->data); //$result = $this->Site->findByDomain($this->data['Site']['domain']); //$parent = $this->Acl->Aco->findByAlias('site'); //$this->Acl->Aco->create(array( // 'alias' => $this->data['Site']['domain'], // 'model' => 'Site', // 'foreign_key' => $result['Site']['id'], // 'parent_id' => $parent['Aco']['id'] // ) // ); //$this->Acl->Aco->save(); //$this->Acl->allow($_SESSION['Auth']['Account']['id'], $this->data['Site']['domain'], '*'); $this->redirect('/sites/view'); //}else{ // $this->Session->setFlash("注册时发生错误,请重试!"); // $this->redirect('/sites/register'); //} } }
function regenerateUuids() { $posts = $this->find('all', array('conditions' => "uuid IS NULL OR uuid = ''", 'fields' => array('id'), 'recursive' => -1)); foreach ($posts as $post) { $this->create($post); $this->saveField('uuid', sha1(String::uuid())); } }
/** * {@inheritdoc} */ public function init() { foreach ($this->records as $k => $data) { $record = array('id' => String::uuid(), 'created' => date('Y-m-d H:i:s')); $this->records[$k] = array_merge($record, $data); } parent::init(); }
public function destinatario($destinatarioId) { App::uses('String', 'Utility'); $spanId = String::uuid(); $url = $this->Html->url(array('action' => 'mensagens', $destinatarioId)); $this->Js->buffer("loadChatMessages('#{$spanId}', '{$url}');"); return $this->Html->tag('span', '', array('id' => $spanId)); }
/** * Create a new post, with title set, as a draft. * */ function wf_create() { $this->data[$this->modelClass]['draft'] = 1; $this->data[$this->modelClass]['uuid'] = sha1(String::uuid()); $this->WildPost->save($this->data); $this->set('data', array('id' => $this->WildPost->id)); $this->render('/elements/json'); }