/**
  * Handles the request to execute a task.
  *
  * Responsible for parsing the tasks to execute & also any config items that
  * should be passed to the tasks
  */
 public function action_execute()
 {
     if (empty($this->_task)) {
         return $this->action_help();
     }
     $task = $this->_retrieve_task();
     $defaults = $task->get_config_options();
     if (!empty($defaults)) {
         if (Arr::is_assoc($defaults)) {
             $options = array_keys($defaults);
             $options = call_user_func_array(array('CLI', 'options'), $options);
             $config = Arr::merge($defaults, $options);
         } else {
             // Old behavior
             $config = call_user_func_array(array('CLI', 'options'), $defaults);
         }
     } else {
         $config = array();
     }
     // Validate $config
     $validation = Validation::factory($config);
     $validation = $task->build_validation($validation);
     if (!$validation->check()) {
         echo View::factory('minion/error/validation')->set('errors', $validation->errors($task->get_errors_file()));
     } else {
         // Finally, run the task
         echo $task->execute($config);
     }
 }
 function __call($name, $arguments)
 {
     $iconvArguments = array();
     foreach ($arguments as $eachArgument) {
         $iconvArguments[] = iconv("utf-8", $this->_dataCharset, $eachArgument);
     }
     $result = call_user_func_array(array($this->_data, $name), $iconvArguments);
     if (is_string($result)) {
         return iconv($this->_dataCharset, "utf-8", $result);
     } else {
         if ($result instanceof \Doctrine\Common\Collections\Collection) {
             $result2 = new Arr();
             foreach ($result as $eachResultItem) {
                 $result2->add(new IconvWrapper($eachResultItem));
             }
             return $result2;
         } else {
             if ($result instanceof \Doctrine\ORM\Proxy\Proxy) {
                 return new IconvWrapper($result);
             } else {
                 return $result;
             }
         }
     }
 }
Exemple #3
0
 /**
  *  @since  11-7-11
  */
 public function testCreate()
 {
     $arr = new Arr('one', 'two', 'three');
     $narr = $arr->getArrayCopy();
     $this->assertEquals(array('one', 'two', 'three'), $narr);
     $arr = new Arr(array('one', 'two', 'three'));
     $narr = $arr->getArrayCopy();
     $this->assertEquals(array('one', 'two', 'three'), $narr);
     $arr[] = 'four';
     \out::e($arr->getArrayCopy());
 }
Exemple #4
0
 public function before()
 {
     if (!User::current()) {
         $this->redirect('/login');
     }
     $url = str_replace('.', '_', URL::base() . $this->request->uri());
     if (isset($_GET[$url])) {
         unset($_GET[$url]);
     }
     if (isset($_GET[$url . '/'])) {
         unset($_GET[$url . '/']);
     }
     if (Group::current('is_admin') || Group::current('show_all_jobs') && Group::current('allow_finance')) {
         Pager::$counts[] = 2500;
     }
     if (Arr::get($_GET, 'limit') && in_array($_GET['limit'], Pager::$counts)) {
         DB::update('users')->set(array('list_items' => intval($_GET['limit'])))->where('id', '=', User::current('id'))->execute();
         die(json_encode(array('success' => 'true')));
     }
     if (Arr::get($_GET, 'dismiss')) {
         DB::delete('notifications')->where('user_id', '=', User::current('id'))->and_where('id', '=', intval($_GET['dismiss']))->execute();
         die(json_encode(array('success' => 'true')));
     }
     if (!Group::current('allow_assign')) {
         Enums::$statuses[Enums::STATUS_UNALLOC] = 'Not active';
     }
     View::set_global('notifications', DB::select()->from('notifications')->where('user_id', '=', User::current('id'))->order_by('id', 'desc')->execute());
 }
Exemple #5
0
 public function get_available_langs()
 {
     $langs = I18n::available_langs();
     $system_default = Arr::get($langs, Config::get('site', 'default_locale'));
     $langs[Model_User::DEFAULT_LOCALE] = __('System default (:locale)', array(':locale' => $system_default));
     return $langs;
 }
Exemple #6
0
 public function action_add()
 {
     if (!$this->user->id) {
         $this->redirect('/');
     }
     $comment = new Model_Comment();
     $comment->article_id = Arr::get($_POST, 'article_id');
     $comment->text = Arr::get($_POST, 'text');
     $comment->parent_id = Arr::get($_POST, 'parent_id', '0');
     $comment->user_id = $this->user->id;
     if (preg_match('(^[0-9]{1,})', $comment->article_id) != true) {
         $this->redirect('/');
     }
     if ($comment->text == '') {
         $this->redirect('/article/' . $comment->article_id);
     }
     if ($comment->parent_id != 0) {
         $parent_comment = Model_Comment::get($comment->parent_id);
         if ($parent_comment->parent_id != 0) {
             $comment->root_id = $parent_comment->root_id;
         } else {
             $comment->root_id = $parent_comment->id;
         }
     } else {
         $comment->root_id = 0;
     }
     $comment->insert();
     $this->redirect('/article/' . $comment->article_id);
 }
Exemple #7
0
 public static function setup_configs_template_body($configs)
 {
     foreach ($configs as $type => $types) {
         foreach ($types as $module => $modules) {
             foreach ($modules as $item_key => $items) {
                 if (!isset($items['body'])) {
                     continue;
                 }
                 if (!is_array($items['body'])) {
                     continue;
                 }
                 if (!empty($items['body']['default']['file'])) {
                     $ext = !empty($items['format']) ? $items['format'] : 'php';
                     $body = file_get_contents(sprintf('%sviews/%s.%s', APPPATH, $items['body']['default']['file'], $ext));
                 } elseif (!empty($items['body']['default']['value'])) {
                     $body = $items['body']['default']['value'];
                 } else {
                     continue;
                 }
                 $key = implode('.', array($type, $module, $item_key, 'body'));
                 Arr::set($configs, $key, $body);
             }
         }
     }
     return $configs;
 }
Exemple #8
0
 /**
  * 保存账号
  */
 public function action_save()
 {
     $this->_autoRender = FALSE;
     $givenName = Arr::get($_POST, 'given_name', '');
     $name = Arr::get($_POST, 'name', '');
     $password = Arr::get($_POST, 'password', '');
     $email = Arr::get($_POST, 'email', '');
     $mobile = Arr::get($_POST, 'mobile', '');
     $phone = Arr::get($_POST, 'phone', '');
     if ($givenName == '') {
         return Prompt::jsonWarning('姓名不能为空');
     }
     if ($name == '') {
         return Prompt::jsonWarning('用户名不能为空');
     }
     if ($password == '') {
         return Prompt::jsonWarning('密码不能为空');
     }
     if ($email == '') {
         return Prompt::jsonWarning('邮箱不能为空');
     }
     $values = array('given_name' => $givenName, 'name' => $name, 'password' => md5($password), 'email' => $email, 'mobile' => $mobile, 'phone' => $phone);
     try {
         $result = Model::factory('Account')->create($values)->getArray();
         if (!$result[0]) {
             //TODO 日志
             return Prompt::jsonError('添加账号失败');
         }
     } catch (Exception $e) {
         //TODO 日志
         return Prompt::jsonError('添加账号失败');
     }
     //TODO 日志
     return Prompt::jsonSuccess('添加账号成功', URL::site('account/add'));
 }
Exemple #9
0
 public function action_show()
 {
     $id = Arr::get($_GET, 'id');
     $state = intval(Arr::get($_GET, 'state'));
     DB::update('job_columns')->set(array('show_reports' => $state))->where('id', '=', $id)->execute();
     die(json_encode(array('success' => true)));
 }
Exemple #10
0
 public function action_delete()
 {
     $dispute = ORM::factory('admin_dispute', $this->request->param('id', NULL));
     if (!$dispute->loaded()) {
         Message::set(Message::ERROR, 'Такое дополнение не найдено');
         $this->request->redirect('admin/development');
     }
     $task_url = 'admin/development/task/view/' . $dispute->task->id;
     if ($_POST) {
         $actions = Arr::extract($_POST, array('submit', 'cancel'), FALSE);
         /*
         if ($actions['cancel'])
             $this->request->redirect('admin/development/task/view/'.$dispute->task->id);
         */
         if ($actions['submit']) {
             $dispute->delete();
             Message::set(Message::SUCCESS, 'Дополнение к задаче удалено');
         }
         $this->request->redirect($task_url);
     }
     $this->view = View::factory('backend/delete')->set('url', $this->request->uri())->set('from_url', $task_url)->set('title', 'Удаление дополнения к задаче')->set('text', 'Вы действительно хотите удалить дополнение к задаче "' . $dispute->task->title . '"');
     $this->template->title = 'Удаление дополнения к задаче';
     $this->template->bc['#'] = $this->template->title;
     $this->template->content = $this->view;
 }
Exemple #11
0
 public static function get_fieid_attribute(Validation $val, $name, $default_value = null, $is_textarea = false, $optional_attr = array())
 {
     $field = $val->fieldset()->field($name);
     $label = '';
     $input_attr = array();
     $is_required = false;
     if (is_callable(array($field, 'get_attribute'))) {
         $input_attr = $field->get_attribute();
         $input_attr = Arr::filter_keys($input_attr, array('validation', 'label'), true);
         if ((is_null($default_value) || empty($default_value) && !strlen($default_value)) && !is_null($field->get_attribute('value'))) {
             $default_value = $field->get_attribute('value');
         }
         $is_required = $field->get_attribute('required') == 'required';
         $label = $field->get_attribute('label');
     }
     if (!is_array($optional_attr)) {
         $optional_attr = (array) $optional_attr;
     }
     if ($optional_attr) {
         $input_attr += $optional_attr;
     }
     if (empty($input_attr['id'])) {
         $input_attr['id'] = Site_Form::get_field_id($name);
     }
     if (empty($input_attr['class'])) {
         $input_attr['class'] = 'form-control';
     }
     return array($default_value, $label, $is_required, $input_attr);
 }
Exemple #12
0
 public function get_options()
 {
     $uid = $this->param('uid', NULL, TRUE);
     $options = ORM::factory('email_type', (int) $uid)->data();
     $options = Arr::merge($options, Config::get('email', 'default_template_data', array()));
     $this->response($options);
 }
Exemple #13
0
	/**
	 * Retrieve posts.
	 *
	 *		Blogger::factory('posts')->read($consumer, $token, $blog_id, NULL, array('orderby' => 'updated'));
	 *
	 * IMPORTANT: define categories in parameters like this: array('categories' => '/Fritz/Laurie')
	 *
	 * @param   OAuth_Consumer	consumer
	 * @param   OAuth_Token		token
	 * @param   string			blog ID
	 * @param   string			post ID for a single post, if set to NULL all posts are retrieved
	 * @param   array			optional query parameters for search: http://code.google.com/apis/blogger/docs/2.0/developers_guide_protocol.html#RetrievingWithQuery
	 * @return  mixed
	 */
	public function read(OAuth_Consumer $consumer, OAuth_Token $token, $blog_id, $post_id = NULL, array $params = NULL)
	{
		// Look for categories in params
		if ($categories = Arr::get($params, 'categories'))
		{
			// Set post_id to '-' if categories are found
			$post_id = '-';
		}

		// Categories must not in query parameters
		unset($params['categories']);

		// Create a new GET request with the required parameters
		$request = OAuth_Request::factory('resource', 'GET', $this->url($blog_id, "posts/default/{$post_id}{$categories}"), array(
				'oauth_consumer_key' => $consumer->key,
				'oauth_token' => $token->token,
			));

		if ($params)
		{
			// Load user parameters
			$request->params($params);
		}

		// Sign the request using the consumer and token
		$request->sign($this->signature, $consumer, $token);

		// Create a response from the request
		$response = $request->execute();

		return $this->parse($response);
	}
Exemple #14
0
 public function action_save()
 {
     $data = Arr::extract($_POST, array('sitename', 'description', 'session', 'keywords', 'robots', 'email', 'author', 'copyright', 'page404', 'status', 'debug', 'cache'));
     foreach ($data as $key => $value) {
         Kohana::$config->_write_config('site', $key, $value);
     }
 }
Exemple #15
0
 protected function init()
 {
     $module_config = Helper_Module::load_config('blog');
     $helper_acl = new Helper_ACL($this->acl);
     $helper_acl->inject(Arr::get($module_config, 'a2'));
     $this->blog_group = Arr::get($this->params, 'group');
 }
Exemple #16
0
 protected function submit($task, $id, $type)
 {
     $item = Jelly::select($type, $id);
     $redirect = HTML::uri(array('action' => Inflector::plural($type)));
     switch ($task) {
         case 'apply':
             $item->set($_POST)->save();
             $redirect = HTML::uri(array('action' => $type, 'task' => 'edit', 'id' => $item->id));
             $this->request->redirect($redirect);
             break;
         case 'save':
             $item->set($_POST)->save();
             $this->request->redirect($redirect);
             break;
         case 'cancel':
             $this->request->redirect($redirect);
             break;
         case 'delete':
             if ($ids = Arr::get($_POST, 'cid', NULL)) {
                 $items = Jelly::delete($item)->where(':primary_key', 'IN', $ids)->execute();
             }
             $this->request->redirect($redirect);
             break;
         case 'default':
             if (!$item->loaded()) {
                 $this->request->redirect($redirect);
             }
             break;
     }
     return $item;
 }
Exemple #17
0
 /**
  * Получение access token для авторизации
  * @return bool
  * @throws Kohana_Exception
  */
 private function get_access_token()
 {
     $params = Arr::get($_SERVER, 'QUERY_STRING');
     parse_str($params, $params);
     if (empty($params['code'])) {
         Controller::redirect($this->login_query());
     }
     if (!$params) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('NO QUERY PARAMS');
     }
     if (isset($params['error'])) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('Error: ' . $params['error'] . ' Description: ' . $params['error_description']);
     }
     $params = array('client_id' => self::$config['APP_ID'], 'code' => $params['code'], 'client_secret' => self::$config['APP_SECRET'], 'redirect_uri' => self::$config['REDIRECT_URI']);
     $resp = Request::factory(self::$config['GET_TOKEN_URI'])->method(Request::GET)->query($params)->execute();
     parse_str($resp);
     if (!isset($access_token)) {
         # TODO: Throw custom Exception for GitHub
         throw new Kohana_Exception('Error: ' . $resp->error . ' Description: ' . $resp->error_description);
     }
     $this->token = $access_token;
     //Session::instance()->set('gh_token', $access_token); #TODO: Why is it commented?
     return true;
 }
Exemple #18
0
 public function save()
 {
     $data = $this->getData();
     unset($data['name']);
     if ($id = $this->getData('id')) {
         $data['id'] = $id;
     }
     if ($new = \Arr::get($data, 'since_new', null)) {
         if ($id) {
             $_date = new \DateTime($new);
             $_date->sub(new \DateInterval('P1D'));
             $close = ['id' => $id];
             $close['till'] = $_date->format('Y-m-d');
             $this->model('ManagerTimeSheet')->upsert($close);
             $id = 0;
             $data['since'] = $new;
             unset($data['id']);
         }
     }
     unset($data['since_new']);
     unset($data['till']);
     if (empty($data['id'])) {
         if (isset($data['id'])) {
             unset($data['id']);
         }
     }
     $_id = $this->model('ManagerTimeSheet')->upsert($data);
     $id = $id ? $id : $_id;
     return $this->model('ManagerTimeSheet')->getById($id);
 }
Exemple #19
0
 /**
  * Verify the login result and do whatever is needed to access the user data from this provider.
  * @return bool
  */
 public function verify()
 {
     // create token
     $request_token = OAuth_Token::factory('request', array('token' => Session::instance()->get('oauth_token'), 'secret' => Session::instance()->get('oauth_token_secret')));
     // Store the verifier in the token
     $verifier = Arr::get($_REQUEST, 'oauth_verifier');
     if (empty($verifier)) {
         return false;
     }
     $request_token->verifier($verifier);
     // Exchange the request token for an access token
     $access_token = $this->provider->access_token($this->consumer, $request_token);
     if ($access_token and $access_token->name === 'access') {
         $request = OAuth_Request::factory('resource', 'GET', 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,email-address)?format=json', array('oauth_consumer_key' => $this->consumer->key, 'oauth_signature_method' => "HMAC-SHA1", 'oauth_token' => $access_token->token));
         // Sign the request using only the consumer, no token is available yet
         $request->sign(new OAuth_Signature_HMAC_SHA1(), $this->consumer, $access_token);
         // decode and store data
         $data = json_decode($request->execute(), true);
         $this->uid = $data['id'];
         $this->data = $data;
         return true;
     } else {
         return false;
     }
 }
Exemple #20
0
 /**
  * Creates a new instance.
  *
  * @param $data New instance data.
  *
  * @return bool
  */
 public function create(array $data)
 {
     $customer_gateway_id = Service_Customer_Gateway::external_id($this->driver->customer, $this->driver->gateway);
     if (!$customer_gateway_id) {
         return false;
     }
     if (!($payment_method = Arr::get($data, 'payment_method'))) {
         return false;
     }
     if (!($amount = Arr::get($data, 'amount'))) {
         return false;
     }
     $request = new AuthorizeNetCIM();
     $transaction = new AuthorizeNetTransaction();
     $transaction->amount = $amount;
     $transaction->customerProfileId = $customer_gateway_id;
     $transaction->customerPaymentProfileId = $payment_method->external_id;
     // AuthOnly or AuthCapture
     $response = $request->createCustomerProfileTransaction('AuthCapture', $transaction);
     if (!$response->isOk()) {
         Log::error('Unable to create Authorize.net transaction.');
         return false;
     }
     $response = $response->getTransactionResponse();
     if (empty($response->transaction_id)) {
         return false;
     }
     return $response->transaction_id;
 }
 /**
  * Set a value based on an id. Optionally add tags.
  * 
  * @param   string   id 
  * @param   mixed    data 
  * @param   integer  lifetime [Optional]
  * @return  boolean
  */
 public function set($id, $data, $lifetime = NULL)
 {
     if ($lifetime === NULL) {
         $lifetime = time() + Arr::get($this->_config, 'default_expire', Cache::DEFAULT_EXPIRE);
     }
     return eaccelerator_put($this->_sanitize_id($id), $data, $lifetime);
 }
Exemple #22
0
 /**
  * Add one or multiple routes
  *
  * @param  string
  * @param  string|array|Route  either the translation for $path, an array for verb routing or an instance of Route
  * @param  bool                whether to prepend the route(s) to the routes array
  */
 public static function add($path, $options = null, $prepend = false, $case_sensitive = null)
 {
     if (is_array($path)) {
         // Reverse to keep correct order in prepending
         $prepend and $path = array_reverse($path, true);
         foreach ($path as $p => $t) {
             static::add($p, $t, $prepend);
         }
         return;
     } elseif ($options instanceof Route) {
         static::$routes[$path] = $options;
         return;
     }
     $name = $path;
     if (is_array($options) and array_key_exists('name', $options)) {
         $name = $options['name'];
         unset($options['name']);
         if (count($options) == 1 and !is_array($options[0])) {
             $options = $options[0];
         }
     }
     if ($prepend) {
         \Arr::prepend(static::$routes, $name, new \Route($path, $options, $case_sensitive));
         return;
     }
     static::$routes[$name] = new \Route($path, $options, $case_sensitive);
 }
Exemple #23
0
 public function display()
 {
     //parse image uri
     $preset = $this->uri->segment(2);
     $fileId = $this->uri->segment(3);
     $file = new File($fileId);
     if (!$file->isFileOfUser($this->c_user->id)) {
         return false;
     }
     $imageFile = $file->image->get();
     $updated = (string) $file->image->updated;
     $manipulator = $this->get('core.image.manipulator');
     if ($this->input->post()) {
         $this->cropParamUpdate($file);
         echo 'images/' . $preset . '/' . $fileId . '/' . $imageFile->updated . '?prev=' . $updated;
     } else {
         $path = FCPATH . $file->path . '/' . $file->fullname;
         $output = $manipulator->getImagePreset($path, $preset, $imageFile, Arr::get($_GET, 'prev', null));
         if ($output) {
             $info = getimagesize($output);
             header("Content-Disposition: filename={$output};");
             header("Content-Type: {$info["mime"]}");
             header('Content-Transfer-Encoding: binary');
             header('Last-Modified: ' . gmdate('D, d M Y H:i:s', time()) . ' GMT');
             readfile($output);
         }
     }
 }
Exemple #24
0
 public function action_delete()
 {
     $district = $this->get_orm_model('district', $this->_base_url);
     $services = $district->services->find_all();
     if ($_POST) {
         if (Arr::get($_POST, 'submit')) {
             $msg = __(Kohana::message('admin', 'district.delete_success'), array(':name' => $district->name));
             $query = DB::update('services')->set(array('district_id' => NULL))->where('district_id', '=', $district->id)->execute();
             $district->content->delete();
             $district->delete();
             if (count($services) > 0) {
                 $msg .= __(Kohana::message('admin', 'metro.delete_success_services'), array(':count' => count($services)));
             }
             Message::set(Message::SUCCESS, $msg);
         }
         $this->request->redirect($this->_base_url);
     }
     $text = __(Kohana::message('admin', 'district.delete_question'), array(':name' => $district->name));
     if (count($services) > 0) {
         $text .= __(Kohana::message('admin', 'metro.delete_question_services'), array(':count' => count($services)));
     }
     $this->template->title = 'Удаление округа "' . $district->name . '"';
     $this->template->bc['#'] = $this->template->title;
     $this->view = View::factory('backend/delete')->set('from_url', $this->_base_url)->set('title', $this->template->title)->set('text', $text);
     $this->template->content = $this->view;
 }
Exemple #25
0
 public function action_index()
 {
     $data_pages = ORM::factory('Page')->where('title_en', '=', 'contacts')->find()->as_array();
     $id = $data_pages['id'];
     $data_contacts = ORM::factory('Setting', 1)->as_array();
     if (isset($_POST['submit'])) {
         $data_pages = Arr::extract($_POST, array('seo_snippet', 'keywords', 'title_head'));
         $data_contacts = Arr::extract($_POST, array('main_adress', 'branch_adress'));
         try {
             $page = ORM::factory('Page', $id);
             $page->values($data_pages);
             $page->save();
             $contacts = ORM::factory('Setting', 1);
             $contacts->values($data_contacts);
             $contacts->save();
             Controller::redirect('admin/contacts');
         } catch (ORM_Validation_Exception $e) {
             $errors = $e->errors('validation');
         }
     }
     $content = View::factory('admin/contacts/v_contacts_edit');
     $content->bind('errors', $errors);
     $content->bind('data_pages', $data_pages);
     $content->bind('data_contacts', $data_contacts);
     $this->template->page_title = 'Контакты';
     $this->template->block_center = array($content);
 }
Exemple #26
0
 /**
  * Factory for loading minion tasks
  *
  * @param  array An array of command line options. It should contain the 'task' key
  * @throws Minion_Exception_InvalidTask
  * @return Minion_Task The Minion task
  */
 public static function factory($options)
 {
     if (($task = Arr::get($options, 'task')) !== NULL) {
         unset($options['task']);
     } else {
         if (($task = Arr::get($options, 0)) !== NULL) {
             // The first positional argument (aka 0) may be the task name
             unset($options[0]);
         } else {
             // If we didn't get a valid task, generate the help
             $task = 'help';
         }
     }
     $class = Minion_Task::convert_task_to_class_name($task);
     if (!class_exists($class)) {
         throw new Minion_Exception_InvalidTask("Task ':task' is not a valid minion task", array(':task' => $class));
     }
     $class = new $class();
     if (!$class instanceof Minion_Task) {
         throw new Minion_Exception_InvalidTask("Task ':task' is not a valid minion task", array(':task' => $class));
     }
     $class->set_options($options);
     // Show the help page for this task if requested
     if (array_key_exists('help', $options)) {
         $class->_method = '_help';
     }
     return $class;
 }
Exemple #27
0
 /**
  * Override of the set_cache method, works in exactly the same way except
  * the check for the max-age header in the response has been removed so that
  * Codebase API responses will always be cached, this breaks HTTP Cache
  * rules but is the cleanest way of enabling caching for all responses
  * within Kohana.
  *
  * @param	Response	$response
  * @return	boolean
  */
 public function set_cache(Response $response)
 {
     $headers = $response->headers()->getArrayCopy();
     if ($cache_control = Arr::get($headers, 'cache-control')) {
         // Parse the cache control
         $cache_control = HTTP_Header::parse_cache_control($cache_control);
         // If the no-cache or no-store directive is set, return
         if (array_intersect($cache_control, array('no-cache', 'no-store'))) {
             return FALSE;
         }
         // Check for private cache and get out of here if invalid
         if (!$this->_allow_private_cache and in_array('private', $cache_control)) {
             if (!isset($cache_control['s-maxage'])) {
                 return FALSE;
             }
             // If there is a s-maxage directive we can use that
             $cache_control['max-age'] = $cache_control['s-maxage'];
         }
     }
     /**
      * if the max-age cache control header is set to 0 in the response, set
      * it to 1 hour so the reponse will be cacheable
      */
     $cache_control_header = $response->headers('Cache-Control');
     $response->headers('Cache-Control', str_replace('max-age=0', 'max-age=3600', $cache_control_header));
     if ($expires = Arr::get($headers, 'expires') and !isset($cache_control['max-age'])) {
         // Can't cache things that have expired already
         if (strtotime($expires) <= time()) {
             return FALSE;
         }
     }
     return TRUE;
 }
 public static function input($name, $value = NULL, array $attributes = NULL)
 {
     if (static::$model) {
         if (isset(static::$model->table_columns()[$name])) {
             if ($value === NULL) {
                 switch (Arr::get($attributes, 'type')) {
                     case 'checkbox':
                     case 'radio':
                         $attributes['checked'] = static::$model->{$name} == $value;
                         break;
                     case '':
                     case 'text':
                     case 'hidden':
                     case 'email':
                     case 'url':
                     case 'search':
                     case 'date':
                     case 'datetime':
                     case 'time':
                     case 'month':
                     case 'week':
                     case 'color':
                     case 'number':
                     case 'range':
                         $value = static::$model->{$name};
                         break;
                 }
             }
             $attributes['id'] = static::$model_name . '_' . URL::title($name);
             $name = static::$model_name . '[' . $name . ']';
         }
     }
     return parent::input($name, $value, $attributes);
 }
Exemple #29
0
 /**
  * Gets a property from instance data.
  *
  * @param string $key     The key to get from data.
  * @param mixed  $default The default value to use if key not found.
  *
  * @return mixed
  */
 public function data($key = null, $default = null)
 {
     if (!empty($key)) {
         return Arr::get($this->data, $key, $default);
     }
     return $this->data;
 }
Exemple #30
-1
 public function action_discrepancies()
 {
     if (!Group::current('is_admin')) {
         throw new HTTP_Exception_403('Forbidden');
     }
     $list = Database_Mongo::collection('jobs')->find(array('discrepancies' => array('$nin' => array(NULL, '', 0))));
     $ids = array();
     foreach ($list as $job) {
         $discr = Database_Mongo::collection('discrepancies')->find(array('job_key' => $job['_id']))->sort(array('update_time' => -1))->getNext();
         $fl = true;
         foreach ($discr['data'] as $key => $value) {
             if ($key == 44) {
                 $status = preg_replace('/[^a-z]/i', '', strtolower($value['old_value']));
                 $status2 = preg_replace('/[^a-z]/i', '', strtolower($value['new_value']));
                 $status0 = preg_replace('/[^a-z]/i', '', strtolower(Arr::get($job['data'], $key, '')));
                 if ($status == $status0) {
                     continue;
                 }
                 if ($status == 'tested' && $status2 != 'tested' || $status == 'built' && ($status2 != 'built' && $status2 != 'tested') || $status != $status2 && in_array($status2, array('deferred', 'dirty', 'heldnbn'), true)) {
                     $fl = false;
                     continue;
                 }
             } elseif ($value['old_value'] != Arr::get($job['data'], $key, '')) {
                 $fl = false;
                 continue;
             }
         }
         if ($fl) {
             $ids[] = $job['_id'];
         }
     }
     Database_Mongo::collection('jobs')->update(array('_id' => array('$in' => $ids)), array('$unset' => array('discrepancies' => 1)), array('multiple' => 1));
     header('Content-type: application/json');
     die(json_encode(array('success' => true)));
 }