/** * Add a rule to a column * * @return void * @author Justin Palmer **/ public function rule($column, Rule $rule) { //Make sure the property exists. $this->model->hasProperty($column); if ($rule instanceof RequiredRule) { $this->required[] = $column; } //Get the rules for this property. $rules = $this->rules->get($column); if ($rules === null) { $rules = array(); } $rules[] = $rule; $this->rules->set($column, $rules); }
public function get_opening_hours($data = []) { if (!$this->exists()) { throw new NotFoundException(__('Invalid Shop')); } if (empty($data)) { $opening_time = $this->field('opening_time'); $closing_time = $this->field('closing_time'); $opening_val = (int) str_replace(':', '', $opening_time); $closing_val = (int) str_replace(':', '', $closing_time); $now = time(); $today = date('Y-m-d', $now); if ($opening_val < 240000 && 0 < $closing_val % 12) { $closing_date = date('Y-m-d', strtotime('+1 day', $now)); } else { $closing_date = $today; } $closing_datetime = $closing_date . ' ' . $closing_time; $opening_datetime = $today . ' ' . $opening_time; } else { $keys = ['opening', 'closing']; foreach ($keys as $key) { $field = "{$key}_datetime"; $path = "Shop.{$field}"; $datetime = Hash::get($data, $path); ${$field} = $this->deconstruct($field, $datetime); } } return compact('opening_datetime', 'closing_datetime'); }
/** * Adds new task * * @param string $command * @param string $path * @param array $arguments * @param array $options * - `unique` - if true and found active duplicates wont add new task * - `dependsOn` - an array of task ids that must be done before this task starts * @return bool */ public function add($command, $path, array $arguments = array(), array $options = array()) { $dependsOn = (array) Hash::get($options, 'dependsOn'); $unique = (bool) Hash::get($options, 'unique'); unset($options['dependsOn'], $options['unique']); $task = compact('command', 'path', 'arguments') + $options; $task += array('timeout' => 60 * 60, 'status' => TaskType::UNSTARTED, 'code' => 0, 'stdout' => '', 'stderr' => '', 'details' => array(), 'server_id' => 0, 'scheduled' => null, 'hash' => $this->_hash($command, $path, $arguments)); $dependsOnIds = $this->find('list', array('fields' => array('id', 'id'), 'conditions' => array('hash' => $task['hash'], 'status' => array(TaskType::UNSTARTED, TaskType::DEFFERED, TaskType::RUNNING)))); if ($unique && $dependsOnIds) { return false; } elseif ($dependsOnIds) { $dependsOn = array_merge($dependsOn, $dependsOnIds); } $this->create(); if ($dependsOn) { $data = array($this->alias => $task, $this->DependsOnTask->alias => $dependsOn); $success = $this->saveAssociated($data); } else { $success = $this->save($task); } if (!$success) { return false; } else { return $this->read()[$this->alias]; } }
/** * UserAttributesRoleのデフォルト値 * * * パスワード=自分/他人とも読み取り不可 * * ラベル項目=自分/他人とも書き込み不可 * * 会員管理が使用可=上記以外、自分・他人とも自分/他人の読み・書き可 * * 会員管理が使用不可 * ** 管理者以外、読み取り不可項目とする=自分/他人の読み・書き不可。※読めないのに書けるはあり得ないため。 * ** 管理者以外、書き込み不可項目とする=自分/他人の書き込み不可。 * ** 上記以外 * *** ハンドル・アバター=自分は、読み・書き可。他人は、読み取り可/書き込み不可。 * *** それ以外=自分は、読み・書き可。他人は、読み・書き不可。 * * @param Model $model Model using this behavior * @param array|string $userAttrSetting 配列:ユーザ属性設定データ、文字列:ユーザ属性キー * @param bool $enableUserManager 有効かどうか * @return array ユーザ属性ロールデータ */ public function defaultUserAttributeRole(Model $model, $userAttrSetting, $enableUserManager) { $model->loadModels(['UserAttributeSetting' => 'UserAttributes.UserAttributeSetting']); $userAttrSetting = $model->UserAttributeSetting->create($userAttrSetting); $userAttributeRole = array(); $userAttributeRole['UserAttributesRole']['self_readable'] = true; $userAttributeRole['UserAttributesRole']['self_editable'] = true; $userAttributeKey = $userAttrSetting['UserAttributeSetting']['user_attribute_key']; if ($userAttributeKey === UserAttribute::PASSWORD_FIELD) { $userAttributeRole['UserAttributesRole']['self_readable'] = false; $userAttributeRole['UserAttributesRole']['other_readable'] = false; } elseif ($enableUserManager) { $userAttributeRole['UserAttributesRole']['other_readable'] = true; } elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_readable')) { $userAttributeRole['UserAttributesRole']['self_readable'] = false; $userAttributeRole['UserAttributesRole']['other_readable'] = false; $userAttrSetting['UserAttributeSetting']['only_administrator_editable'] = true; } else { $userAttributeRole['UserAttributesRole']['self_readable'] = true; $userAttributeRole['UserAttributesRole']['other_readable'] = in_array($userAttributeKey, $this->readableDefault, true); } $userAttributeRole['UserAttributesRole']['other_editable'] = false; if ($userAttrSetting['UserAttributeSetting']['data_type_key'] === DataType::DATA_TYPE_LABEL) { $userAttributeRole['UserAttributesRole']['self_editable'] = false; } elseif ($enableUserManager) { $userAttributeRole['UserAttributesRole']['other_editable'] = true; } elseif (Hash::get($userAttrSetting, 'UserAttributeSetting.only_administrator_editable')) { $userAttributeRole['UserAttributesRole']['self_editable'] = false; } return $userAttributeRole; }
/** * Resize a file uploaded * @param string $path Path of the data, for instance to upload the file in data['Movie']['picture'] path would be Movie.picture * @param string $dest Where to save the uploaded file * @param integer $width * @param integer $height * @return boolean True if the image is uploaded. */ public function move($path, $dest, $width = 0, $height = 0) { $file = Hash::get($this->controller->request->data, $path); if (empty($file['tmp_name'])) { return false; } $tmp = TMP . $file['name']; move_uploaded_file($file['tmp_name'], $tmp); $info = pathinfo($file['name']); $destinfo = pathinfo($dest); $directory = dirname(IMAGES . $dest); if (!file_exists($directory)) { mkdir($directory, 0777, true); } if ($info['extension'] == $destinfo['extension'] && $width == 0) { rename($tmp, IMAGES . $dest); return true; } if (!file_exists($dest_file)) { require_once APP . 'Plugin' . DS . 'Media' . DS . 'Vendor' . DS . 'imagine.phar'; $imagine = new Imagine\Gd\Imagine(); $imagine->open($tmp)->thumbnail(new Imagine\Image\Box($width, $height), Imagine\Image\ImageInterface::THUMBNAIL_OUTBOUND)->save(IMAGES . $dest, array('quality' => 90)); } return true; }
/** * @param mix $key * @return mixed */ public function user($key = null) { if (!is_null($key)) { return Hash::get((array) $this->_userData, $key); } return $this->_userData; }
/** * Test get() * * @return void */ public function testGet() { $data = array('abc', 'def'); $result = Hash::get($data, '0'); $this->assertEquals('abc', $result); $result = Hash::get($data, 0); $this->assertEquals('abc', $result); $result = Hash::get($data, '1'); $this->assertEquals('def', $result); $data = self::articleData(); $result = Hash::get(array(), '1.Article.title'); $this->assertNull($result); $result = Hash::get($data, ''); $this->assertNull($result); $result = Hash::get($data, '0.Article.title'); $this->assertEquals('First Article', $result); $result = Hash::get($data, '1.Article.title'); $this->assertEquals('Second Article', $result); $result = Hash::get($data, '5.Article.title'); $this->assertNull($result); $result = Hash::get($data, '1.Article.title.not_there'); $this->assertNull($result); $result = Hash::get($data, '1.Article'); $this->assertEquals($data[1]['Article'], $result); $result = Hash::get($data, array('1', 'Article')); $this->assertEquals($data[1]['Article'], $result); }
public function price($price) { if (is_array($price)) { $price = intval(Hash::get($price, 'Product.price')); } return Configure::read('Settings.price_prefix') . number_format($price, 0, '.', Configure::read('Settings.int_div')) . Configure::read('Settings.price_postfix'); }
public function deleteByUserId($id) { $favUser = $this->FavouriteUser->findByUserIdAndFavUserId($this->currUserID, $id); $favUser = Hash::get($favUser, 'FavouriteUser.id'); $this->FavouriteUser->delete($favUser); $this->redirect($this->referer()); }
/** * Get the temporary name of the file. * * @param $data The data from the request. * @return mixed String containing the temp path name if data is valid, otherwise false. */ public function getTmpName($data) { if (is_array($data)) { return Hash::get($data, 'FileUpload.filename.tmp_name'); } return false; }
/** * edit * * @return void */ public function edit() { //会員権限リストを取得する $userRoles = $this->UserRole->find('list', array('recursive' => -1, 'fields' => array('key', 'name'), 'conditions' => array('language_id' => Current::read('Language.id')), 'order' => array('id' => 'asc'))); $this->set('userRoles', $userRoles); //リクエストセット if ($this->request->is('post')) { $data = $this->request->data['SiteSetting']; $value = $data['Security.deny_ip_move']['0']['value']; if (is_array($value)) { $data['Security.deny_ip_move']['0']['value'] = implode('|', $value); } //登録処理 $this->request->data['SiteSetting'] = $data; $this->SiteSetting->userRoles = $userRoles; $this->SiteManager->saveData(); } else { $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('Upload.allow_extension', 'Security.deny_ip_move', 'Security.enable_bad_ips', 'Security.bad_ips', 'Security.enable_allow_system_plugin_ips', 'Security.allow_system_plugin_ips'))); $ips = $this->request->data['SiteSetting']['Security.allow_system_plugin_ips']['0']['value']; if (!$this->SiteSetting->hasCurrentIp($ips)) { $ips = Hash::get($_SERVER, 'REMOTE_ADDR'); $this->request->data['SiteSetting']['Security.allow_system_plugin_ips']['0']['value'] = $ips; } } }
/** * Checks if flag is on, required other fields * * @param object &$model use model * @param array $check check data array * @param mix $requireValue when check data value equal this value, then require other field * @param array $others require data field names * @param string $ope require condition AND or OR or XOR * @return bool */ public function requireOtherFields(&$model, $check, $requireValue, $others, $ope) { $checkPatterns = array('AND' => array('midstream' => array('chk' => true, 'ret' => false), 'end' => array('ret' => true)), 'OR' => array('midstream' => array('chk' => false, 'ret' => true), 'end' => array('ret' => false)), 'XOR' => array('midstream' => array('chk' => false, 'ret' => false), 'end' => array('ret' => true))); $ope = strtoupper($ope); $checkPattern = $checkPatterns[$ope]; $value = array_values($check); $value = $value[0]; if ($value != $requireValue) { return true; } foreach ($others as $other) { $checkData = Hash::get($model->data, $other); $otherFieldsName = explode('.', $other); // is_系のフィールドの場合、チェックボックスで実装され、OFFでも0という数値が入ってくる // そうすると「Blank」判定してほしいのに「ある」と判定されてしまう // なのでis_で始まるフィールドのデータの設定を確認するときだけは == falseで判定する if (strncmp('is_', $otherFieldsName[count($otherFieldsName) - 1], 3) === 0) { $ret = $checkData == false; } else { $ret = Validation::blank($checkData); } if ($ret == $checkPattern['midstream']['chk']) { return $checkPattern['midstream']['ret']; } } return $checkPattern['end']['ret']; }
/** * beforePaginate callback * * @param CakeEvent $e * @return void */ public function beforePaginate(CakeEvent $e) { $this->_checkRequiredPlugin(); $model = $this->_model(); $controller = $this->_controller(); $request = $this->_request(); $this->_ensureComponent($controller); $this->_ensureBehavior($model); $this->_commonProcess($controller, $model->name); $query = $request->query; if (!empty($request->query['_scope'])) { $config = $this->config('scope.' . $request->query['_scope']); if (empty($config)) { $config = $this->_action()->config('scope.' . $request->query['_scope']); } $query = Hash::get((array) $config, 'query'); if (!empty($config['filter'])) { $this->_setFilterArgs($model, $config['filter']); } } else { $filterArgs = $this->_action()->config('scope'); if (!empty($filterArgs)) { $this->_setFilterArgs($model, (array) $filterArgs); } } // Avoid notice if there is no filterArgs if (empty($model->filterArgs)) { $this->_setFilterArgs($model, array()); } $this->_setPaginationOptions($controller, $model, $query); }
/** * After migration callback * * @param string $direction Direction of migration process (up or down) * @return bool Should process continue */ public function after($direction) { if ($direction === 'down') { return true; } //UserAttributeSettingのdata_type_key変更 $update = array('data_type_key' => '\'select\''); $conditions = array('data_type_key' => 'language'); $UserAttributeSetting = $this->generateModel('UserAttributeSetting'); if (!$UserAttributeSetting->updateAll($update, $conditions)) { return false; } $UserAttribute = $this->generateModel('UserAttribute'); $userAttributes = $UserAttribute->find('list', array('recursive' => -1, 'fields' => array('language_id', 'id'), 'conditions' => array('key' => 'language'))); foreach ($this->records['UserAttributeChoice'] as $i => $record) { $record['user_attribute_id'] = Hash::get($userAttributes, $record['language_id']); $this->records['UserAttributeChoice'][$i] = $record; } foreach ($this->records as $model => $records) { if (!$this->updateRecords($model, $records)) { return false; } } return true; }
/** * Get all or a specific settings key * * @param string $path Hash::get() compatible path, NULL for everything * @return mixed */ public function getSettings($path = null) { if (empty($path)) { return $this->_settings; } return Hash::get($this->_settings, $path); }
public function render($form, $values, $offset = 0) { $html = ''; $_values = array(); if ($values) { $_values = array_combine(Hash::extract($values, '{n}.PMFormValue.field_id'), Hash::extract($values, '{n}.PMFormValue.value')); } $_ids = array(); if ($values) { $_ids = array_combine(Hash::extract($values, '{n}.PMFormValue.field_id'), Hash::extract($values, '{n}.PMFormValue.id')); } foreach ($form as $i => $row) { $field = $row['FormField']; $value = Hash::get($_values, $field['id']); /* if ($field['id'] == 6) { fdebug($field); fdebug(array_merge( $this->_options($i, 'value'), $this->_inputOptions($field), array('value' => $value) )); } */ $html .= $this->_renderInput($field, $value, $i + $offset); if (isset($_values[$field['id']])) { $html .= $this->PHForm->hidden('PMFormValue.id', array_merge($this->_options($i + $offset, 'id'), array('value' => Hash::get($_ids, $field['id'])))); } $html .= $this->PHForm->hidden('PMFormValue.field_id', array_merge($this->_options($i + $offset, 'field_id'), array('value' => $field['id']))); } return $html; }
/** * {@inheritdoc} * * @param string $command * @param array $argv * @return bool */ public function runCommand($command, $argv) { if (!empty($this->args[0]) && $this->hasMethod($this->args[0])) { $this->action = $this->args[0]; } else { $this->action = null; } $this->statisticsStart('AdvancedShell'); Configure::write('debug', (int) Hash::get($this->params, 'debug')); if ($this->isScheduled()) { if ($this->params['scheduled-no-split']) { $this->setScheduleSplitter(new ScheduleNoSplit()); } $this->schedule(); $out = null; } elseif ($this->action) { $out = $this->{$this->action}(); } else { $out = parent::runCommand($command, $argv); } $this->statisticsEnd('AdvancedShell'); $this->sqlDump(false, false); $this->hr(); return $out; }
public function mailer() { $this->loadModel('User'); // Check the action is being invoked by the cron dispatcher if (!defined('CRON_DISPATCHER')) { $this->redirect('/Mytime'); exit; } //no view //$this->autoRender = false; $this->layout = 'ajax'; $aUser = $this->User->find('all'); foreach ($aUser as $user) { $currTime = time(); $lastTime = strtotime(Hash::get($user, 'User.last_update')); $id = $user['User']['id']; $date1 = $lastTime > $currTime - 43200 ? date("Y-m-d H:i:s", $lastTime) : date("Y-m-d H:00:00", $currTime - 43200); $date2 = date("Y-m-d H:00:00", $currTime); $data = $this->User->getTimeline($id, $date1, $date2, 0, true); $this->set('data', $data); $this->set('timeFrom', strtotime($date1)); $this->set('timeTo', strtotime($date2)); if (count($data['events'])) { $Email = new CakeEmail('postmark'); $Email->template('updates_mailer', 'mail')->viewVars(array('data' => $this->User->getTimeline($id, $date1, $date2, 0), 'timeFrom' => strtotime($date1), 'timeTo' => strtotime($date2)))->to(Hash::get($user, 'User.username'))->subject('Last updates on Konstruktor.com')->send(); } } return; }
/** * Returns a formatted address excluding empty address fields. * * @param array $data array containing the address * @param array $fields array of field names to use for address * @param array $attributes options * @return string */ public function format($data, $fields = null, $attributes = array()) { $defaults = array('tag' => 'address'); $attributes = array_merge($defaults, $attributes); $address = array(); $fields = !empty($fields) && is_array($fields) ? $fields : $this->settings['fields']; foreach ($fields as $field) { if (is_array($field)) { $line = array(); foreach ($field as $item) { $val = Hash::get($data, $item); if (!empty($val)) { $line[] = $val; } } if (!empty($line)) { $address[] = implode(' ', $line); } } else { $val = Hash::get($data, $field); if (!empty($val)) { $address[] = $val; } } } $formattedAddress = implode('<br />', $address); if (!empty($attributes['tag'])) { $tag = $attributes['tag']; unset($attributes['tag']); $formattedAddress = $this->Html->tag($tag, $formattedAddress, $attributes); } return $formattedAddress; }
/** * Execution method always used for tasks * * @return void */ public function execute() { parent::execute(); //引数のセット $data = array(); // * login if (array_key_exists(self::KEY_USERNAME, $this->params)) { $data['User'][self::KEY_USERNAME] = Hash::get($this->params, self::KEY_USERNAME); } else { $data['User'][self::KEY_USERNAME] = $this->in(__d('install', 'NetCommons Login id?')); } // * password if (array_key_exists(self::KEY_PASSWORD, $this->params)) { $data['User'][self::KEY_PASSWORD] = Hash::get($this->params, self::KEY_PASSWORD); } else { $data['User'][self::KEY_PASSWORD] = $this->in(__d('install', 'NetCommons Login password?')); } $data['User'][self::KEY_PASSWORD . '_again'] = $data['User'][self::KEY_PASSWORD]; // * handlename $data['User'][self::KEY_HANDLENAME] = __d('install', 'System administrator'); //アカウント作成 if (!$this->InstallUtil->saveAdminUser($data)) { return $this->error(__d('install', 'The user could not be saved. Please try again.')); } }
/** * Serialize to array data from xml * * @return array Xml serialize array data */ public function serializeXmlToArray() { //後で修正する $xmlData = Xml::toArray(Xml::build(self::NOTIFICATION_URL)); // rssの種類によってタグ名が異なる if (isset($xmlData['feed'])) { $items = Hash::get($xmlData, 'feed.entry'); $dateKey = 'published'; $linkKey = 'link.@href'; $summaryKey = 'summary'; } elseif (Hash::get($xmlData, 'rss.@version') === '2.0') { $items = Hash::get($xmlData, 'rss.channel.item'); $dateKey = 'pubDate'; $linkKey = 'link'; $summaryKey = 'description'; } else { $items = Hash::get($xmlData, 'RDF.item'); $dateKey = 'dc:date'; $linkKey = 'link'; $summaryKey = 'description'; } if (!isset($items[0]) && is_array($items)) { $items = array($items); } $data = array(); foreach ($items as $item) { $date = new DateTime($item[$dateKey]); $summary = Hash::get($item, $summaryKey); $data[] = array('title' => $item['title'], 'link' => Hash::get($item, $linkKey), 'summary' => $summary ? strip_tags($summary) : '', 'last_updated' => $date->format('Y-m-d H:i:s'), 'key' => Security::hash(Hash::get($item, $linkKey), 'md5')); } return $data; }
public function addComment($data) { $this->loadModel('ChatMessage'); $this->loadModel('User'); $this->loadModel('Article'); $event_id = Hash::get($data, 'UserEventEvent.event_id'); $user_id = Hash::get($data, 'UserEventEvent.user_id'); $recepient_id = Hash::get($data, 'UserEventEvent.recepient_id'); $message = Hash::get($data, 'UserEventEvent.description'); if (!empty($message)) { if (!$this->ChatMessage->save($data = compact('message'))) { throw new Exception("Message cannot be saved\n" . print_r($data, true)); } $msg_id = $this->ChatMessage->id; } else { $msg_id = null; } $file_id = Hash::get($data, 'UserEventEvent.file_id'); if (!empty($file_id)) { /*if (!$this->ChatMessage->save($data = compact('message'))) { throw new Exception("Message cannot be saved\n".print_r($data, true)); } $file_id = $this->ChatMessage->id;*/ $file_id = null; } else { $file_id = null; } //$file_id = Hash::get($data, 'UserEventEvent.description'); $this->addEvent($event_id, $user_id, $recepient_id, $msg_id, $file_id); return true; }
/** * Configures servers to connect to. * * ## Example: * * ``WorkerQueue::config(array('servers' => array('some.server.com:4444', 'otherserver')));`` * * @param array $settings * @return void **/ public static function config($settings) { $servers = Hash::get($settings, 'servers'); if (!empty($servers)) { static::$_servers = $servers; } }
/** * Setup method * * Called when the listener is initialized * * Setup the default readers * * @return void */ public function setup() { $this->reader('request.key', function (CrudSubject $subject, $key = null) { if (!isset($subject->request->{$key})) { return null; } return $subject->request->{$key}; }); $this->reader('request.data', function (CrudSubject $subject, $key = null) { return $subject->request->data($key); }); $this->reader('request.query', function (CrudSubject $subject, $key = null) { return $subject->request->query($key); }); $this->reader('model.key', function (CrudSubject $subject, $key = null) { if (!isset($subject->model->{$key})) { return null; } return $subject->model->{$key}; }); $this->reader('model.data', function (CrudSubject $subject, $key = null) { return Hash::get($subject->model->data, $key); }); $this->reader('model.field', function (CrudSubject $subject, $key = null) { return $subject->model->field($key); }); $this->reader('subject.key', function (CrudSubject $subject, $key = null) { if (!isset($subject->{$key})) { return null; } return $subject->{$key}; }); }
/** * Get the message from an array of member email data. * * @param array $data The array of data to get the message from. * @return string The message, or null if it could not be found. */ public function getMessage($data) { if (isset($data) && is_array($data)) { return Hash::get($data, 'MemberEmail.message'); } return null; }
private function writeDBLog($method, $requestData, $responseType, $_response = '', $proxy_used = '', $curlStatus = '') { $this->loadModel('LogAutoxp')->clear(); $ip = $_SERVER['REMOTE_ADDR']; $proxy_type = $this->isBot($ip) ? 'Bot' : 'Site'; $this->loadModel('LogAutoxp')->save(array('ip_type' => $proxy_type, 'ip' => $ip, 'host' => gethostbyaddr($ip), 'ip_details' => json_encode($_SERVER), 'proxy_used' => $proxy_used, 'method' => $method, 'request' => $this->getRequestURL($requestData, $method), 'response_type' => $responseType, 'response_status' => $curlStatus ? json_encode($curlStatus) : '', 'response' => $_response, 'cache_id' => $responseType == 'CACHE' ? Hash::get(Cache::settings('autoxp'), 'data.id') : 0, 'cache' => $responseType == 'CACHE' ? Hash::get(Cache::settings('autoxp'), 'data.value') : '')); }
/** * edit * * @return void */ public function edit() { //事前準備 $this->__prepare(); //リクエストセット if ($this->request->is('post')) { $this->set('membershipTab', Hash::get($this->request->data['SiteSetting'], 'membershipTab', 'automatic-registration')); $this->request->data['SiteSetting'] = Hash::remove($this->request->data['SiteSetting'], 'membershipTab'); $automaticInputItems = Hash::get($this->request->data, '_siteManager.automaticInputItems', 'false'); $this->Session->write('automaticInputItems', $automaticInputItems); $this->__parseRequestData(); $this->SiteSetting->autoRegistRoles = $this->viewVars['userRoles']; //登録処理 $redirect = Router::parse($this->referer()); $redirect['?'] = array('membershipTab' => $this->viewVars['membershipTab']); $this->SiteManager->saveData($redirect); } else { $this->set('membershipTab', Hash::get($this->request->query, 'membershipTab', 'automatic-registration')); if ($this->Session->read('automaticInputItems')) { $automaticInputItems = $this->Session->read('automaticInputItems'); $this->Session->delete('automaticInputItems'); } else { $automaticInputItems = 'false'; } $this->request->data['SiteSetting'] = $this->SiteSetting->getSiteSettingForEdit(array('SiteSetting.key' => array('AutoRegist.use_automatic_register', 'AutoRegist.confirmation', 'AutoRegist.use_secret_key', 'AutoRegist.secret_key', 'AutoRegist.role_key', 'AutoRegist.prarticipate_default_room', 'AutoRegist.disclaimer', 'AutoRegist.approval_mail_subject', 'AutoRegist.approval_mail_body', 'AutoRegist.acceptance_mail_subject', 'AutoRegist.acceptance_mail_body', 'UserRegist.mail_subject', 'UserRegist.mail_body', 'UserCancel.use_cancel_feature', 'UserCancel.disclaimer', 'UserCancel.notify_administrators', 'UserCancel.mail_subject', 'UserCancel.mail_body'))); } $this->set('automaticInputItems', $automaticInputItems); }
public function img($data, $path, $url, $options = []) { if (!$this->scriptWritten) { $this->Html->script('AjaxImage.script', ['inline' => false]); $this->scriptWritten = true; } $src = Hash::get($options, 'src'); if ($src == null) { $src = $url; } $options['src'] = $src; $class = Hash::get($options, 'class'); if ($class === null) { $class = []; } else { if (is_string($class)) { $class = [$class]; } } $class[] = 'ai-image'; $options['class'] = $class; if (Hash::get($options, 'alt') === null) { $options['alt'] = __('Drag and drop image to upload.'); } return $this->Html->tag('div', $this->Html->tag('img', null, $options), ['data-src' => $src, 'data-name' => 'data' . join(array_map(function ($str) { return '[' . $str . ']'; }, explode('.', $path))), 'data-url' => $url, 'class' => 'ai-drop']); }
/** * ルール定義 * * @param Model $model モデル * @param array $options Options passed from Model::save(). * @return array */ public function rules(Model $model, $options = array()) { $rules = $this->__initValidate($model); $isFfmpegEnable = Hash::get($this->settings, $model->alias . '.' . self::IS_FFMPEG_ENABLE); if ($isFfmpegEnable) { // ffmpeg=ON $extension = Video::VIDEO_EXTENSION; $mimeType = Video::VIDEO_MIME_TYPE; } else { // ffmpeg=OFF $extension = 'mp4'; $mimeType = 'video/mp4'; } if (in_array('add', $options, true)) { // --- 登録時 if (!$isFfmpegEnable) { $rules = Hash::merge($rules, array(Video::THUMBNAIL_FIELD => array('upload-file' => array('rule' => array('uploadError'), 'message' => array(__d('files', 'Please specify the file'))), 'extension' => array('rule' => array('extension', explode(',', Video::THUMBNAIL_EXTENSION)), 'message' => array(__d('files', 'It is upload disabled file format'))), 'mimetype' => array('rule' => array('mimeType', explode(',', Video::THUMBNAIL_MIME_TYPE)), 'message' => array(__d('files', 'It is upload disabled file format')))))); } // 必須 $rules = Hash::merge($rules, array(Video::VIDEO_FILE_FIELD => array('upload-file' => array('rule' => array('uploadError'), 'message' => array(__d('files', 'Please specify the file'))), 'extension' => array('rule' => array('extension', explode(',', $extension)), 'message' => array(__d('files', 'It is upload disabled file format'))), 'mimetype' => array('rule' => array('mimeType', explode(',', $mimeType)), 'message' => array(__d('files', 'It is upload disabled file format')))))); } elseif (in_array('edit', $options, true)) { // --- 編集時 $rules = Hash::merge($rules, array(Video::VIDEO_FILE_FIELD => array('extension' => array('rule' => array('extension', explode(',', $extension)), 'message' => array(__d('files', 'It is upload disabled file format'))), 'mimetype' => array('rule' => array('mimeType', explode(',', $mimeType)), 'message' => array(__d('files', 'It is upload disabled file format')))), Video::THUMBNAIL_FIELD => array('extension' => array('rule' => array('extension', explode(',', Video::THUMBNAIL_EXTENSION)), 'message' => array(__d('files', 'It is upload disabled file format'))), 'mimetype' => array('rule' => array('mimeType', explode(',', Video::THUMBNAIL_MIME_TYPE)), 'message' => array(__d('files', 'It is upload disabled file format')))))); } return $rules; }
public function beforeSave($options = []) { $id = Hash::get($this->data, $this->name . '.id'); $updateRules = []; $readFields = []; foreach (Hash::extract($this->data, $this->name) as $field => $value) { foreach ($this->rules as $key => $rule) { if ($rule[3] == false && array_search($this->name . '.' . $field, $rule[1]) !== FALSE) { $this->rules[$key][3] = true; $readFields = array_merge($readFields, $rule[1]); } } } if (!empty($readFields)) { $this->save(null, ['callbacks' => false]); $id = $this->id; $this->read(array_unique($readFields), $id); foreach ($this->rules as $rule) { if ($rule[3]) { $values = []; foreach ($rule[1] as $depend) { $value = Hash::get($this->data, $depend); $values[] = $value; } $this->data = Hash::insert($this->data, $rule[0], $rule[2]($values)); } } } return true; }