Ejemplo n.º 1
0
 /**
  * Read the data for a particular session identifier from the
  * SessionHandler backend.
  *
  * @param   string  $id  The session identifier.
  * @return  string  The session data.
  */
 public function read($session_id)
 {
     if ($this->files->exists($path = $this->path . DS . $session_id)) {
         return $this->files->get($path);
     }
     return '';
 }
Ejemplo n.º 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $c = strtolower($this->argument('controller'));
     $files = [];
     $files[] = mkny_models_path($c) . '.php';
     $files[] = mkny_model_config_path($c) . '.php';
     $files[] = mkny_presenters_path($c) . 'Presenter.php';
     $files[] = mkny_controllers_path($c) . 'Controller.php';
     $files[] = mkny_requests_path($c) . 'Request.php';
     $files[] = mkny_lang_path(\App::getLocale() . '/' . $c) . '.php';
     $errors = [];
     foreach ($files as $file) {
         if (!$this->files->exists($file)) {
             $errors[] = $file;
         }
     }
     if (!$this->option('force') && count($errors)) {
         $this->error("Nao foi possivel executar o delete-automatico!\nAlguns arquivos estao ausentes!");
     } else {
         if ($this->option('force') || $this->confirm("Deseja realmente remover os arquivos: \n'" . implode("',\n'", $files))) {
             foreach ($files as $file) {
                 $this->files->delete($file);
             }
             $this->info('Deleted!');
         }
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     if (is_null($this->argument('vendor')) or is_null($this->argument('name'))) {
         $this->info('Moving tests for all local packages');
         $composer = json_decode(file_get_contents('composer.json'), true);
         foreach ($composer['autoload']['psr-4'] as $package => $path) {
             if ($package !== 'App\\') {
                 $packages[] = [rtrim($package, '\\'), $path];
             }
         }
         foreach ($packages as $package) {
             $path = dirname(getcwd() . '/' . $package[1]) . '/tests';
             if ($this->files->exists($path)) {
                 $this->info('Moving tests for the package: ' . $package[0]);
                 $this->files->copyDirectory($path, getcwd() . '/tests/packages/' . $package[0]);
             } else {
                 $this->info('No tests found for: ' . $package[0]);
             }
         }
     } else {
         $vendor = $this->argument('vendor');
         $name = $this->argument('name');
         $path = getcwd() . '/packages/' . $vendor . '/' . $name . '/tests';
         if ($this->files->exists($path)) {
             $this->info('Moving tests for the package: ' . $vendor . '/' . $name);
             $r = $this->files->copyDirectory($path, getcwd() . '/tests/packages/' . $vendor . '/' . $name);
         } else {
             $this->info('No tests found for: ' . $vendor . '/' . $name);
         }
     }
     $this->info('Done!');
 }
Ejemplo n.º 4
0
 /**
  * Determines if file or folder identified in path exists
  *
  * @param   string $path
  *
  * @return  bool
  * @since   1.0
  * @throws  RuntimeException
  */
 public function exists($path)
 {
     try {
         return $this->adapter->exists($path);
     } catch (Exception $e) {
         throw new RuntimeException('Filesystem: Exists Exception ' . $e->getMessage());
     }
 }
Ejemplo n.º 5
0
 /**
  * prompts the user to login if it exists in the database, else it prompts for registration
  */
 public function auth()
 {
     if (!$this->user->isLoggedIn()) {
         if ($this->user->exists()) {
             // load the login template
             $view = 'admin/login';
             // users exist, set up the login verification process
             // if theres input
             if (Input::exists()) {
                 // get input values
                 $username = Input::get('username');
                 $password = Input::get('password');
                 // check if a unique token is set
                 if (Token::check(Input::get('token'))) {
                     // validate the form
                     $this->validator->validate(['username' => [$username, 'required'], 'password' => [$password, 'required']]);
                     if ($this->validator->passes()) {
                         // log the user in
                         if ($this->user->login($username, $password)) {
                             header('Location: /admin/index');
                         }
                     }
                 }
             }
             // delete the flash message that occurs after registering an account
             if (Session::exists('success')) {
                 $flash = Session::flash('success');
             }
         } else {
             // load the registration template
             $view = 'admin/register';
             // no users exist, set up the registration process
             // if theres input
             if (Input::exists()) {
                 // get input values
                 $username = Input::get('username');
                 $password = Input::get('password');
                 $password_confirmation = Input::get('password_confirmation');
                 // check if a unique token is set
                 if (Token::check(Input::get('token'))) {
                     // validate the form
                     $this->validator->validate(['username' => [$username, 'required|alnumDash|min(3)|max(25)'], 'password' => [$password, 'required|min(8)'], 'password_confirmation' => [$password_confirmation, 'required|matches(password)']]);
                     if ($this->validator->passes()) {
                         // validation passed, insert a new user to the database
                         $this->user->create($username, Hash::hashPassword($password));
                         Session::flash('success', 'Your account has been successfully created.');
                         header('Location: /admin/auth');
                     }
                 }
             }
         }
         // render the right view
         $this->view($view, ['flash_message' => isset($flash) ? $flash : '', 'validation_errors' => $this->validator->errors(), 'csrf_token' => Token::generate(), 'user_error' => $this->user->auth_error_message]);
     } else {
         // the user is already logged in
         header('Location: /admin/index');
     }
 }
Ejemplo n.º 6
0
 /**
  * 从注册器读取实例, 没有则注册
  *
  * @param string $name
  */
 public function instance($name)
 {
     if ($this->registry->exists($name)) {
         return $this->registry->get($name);
     }
     return $this->registry->instance($name);
 }
Ejemplo n.º 7
0
 /**
  * Verifica se o usuário está logado
  * @return boolean Status da autenticação
  */
 public function login_check()
 {
     if ($this->storage->exists('user_id') && $this->storage->exists('username') && $this->storage->exists('login_string')) {
         $login_string = hash('sha512', $this->storage->get('username') . $this->request->server('REMOTE_ADDR') . $this->request->server('HTTP_USER_AGENT'));
         return $login_string == $this->storage->get('login_string') ? true : false;
     }
 }
Ejemplo n.º 8
0
 /**
  * @covers  Molajo\Resource\Proxy::setNamespace
  * @covers  Molajo\Resource\Proxy::exists
  * @covers  Molajo\Resource\Proxy::get
  * @covers  Molajo\Resource\Proxy::getCollection
  * @covers  Molajo\Resource\Proxy\Scheme::__construct
  * @covers  Molajo\Resource\Proxy\Scheme::setScheme
  * @covers  Molajo\Resource\Proxy\Scheme::getScheme
  * @covers  Molajo\Resource\Proxy\Scheme::setAdapterNamespaces
  * @covers  Molajo\Resource\Proxy\Scheme::saveNamespaceArray
  * @covers  Molajo\Resource\Proxy\Scheme::locateScheme
  * @covers  Molajo\Resource\Proxy\Scheme::getUriScheme
  * @covers  Molajo\Resource\Proxy\Scheme::removeUriScheme
  * @covers  Molajo\Resource\Adapter\NamespaceHandler::setNamespace
  * @covers  Molajo\Resource\Adapter\NamespaceHandler::exists
  * @covers  Molajo\Resource\Adapter\NamespaceHandler::get
  * @covers  Molajo\Resource\Adapter\NamespaceHandler::getCollection
  * @covers  Molajo\Resource\Adapter\NamespaceHandler::locateResourceNamespace
  * @covers  Molajo\Resource\Adapter\SetNamespace::setNamespaceExists
  * @covers  Molajo\Resource\Adapter\SetNamespace::appendNamespace
  * @covers  Molajo\Resource\Adapter\SetNamespace::prependNamespace
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespacePrefixes
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespacePrefix
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespacePrefixDirectory
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespacePrepareNamespacePath
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespaceFilename
  * @covers  Molajo\Resource\Adapter\HandleNamespacePrefixes::searchNamespacePrefixFileExtensions
  * @covers  Molajo\Resource\Adapter\HandleResourceMap::searchResourceMap
  * @covers  Molajo\Resource\Adapter\HandleResourceMap::searchResourceMapInstance
  * @covers  Molajo\Resource\Adapter\HandleResourceMap::setResourceMapPaths
  * @covers  Molajo\Resource\Adapter\HandleResourceMap::searchResourceMapPaths
  * @covers  Molajo\Resource\Adapter\HandleResourceMap::searchResourceMapFileExtensions
  * @covers  Molajo\Resource\Adapter\Base::__construct
  * @covers  Molajo\Resource\Adapter\Base::initialiseCacheVariables
  * @covers  Molajo\Resource\Adapter\Base::setScheme
  * @covers  Molajo\Resource\Adapter\Base::setResourceNamespace
  * @covers  Molajo\Resource\Adapter\Cache::getConfigurationCache
  * @covers  Molajo\Resource\Adapter\Cache::setConfigurationCache
  * @covers  Molajo\Resource\Adapter\Cache::deleteConfigurationCache
  * @covers  Molajo\Resource\Adapter\Cache::useConfigurationCache
  * @covers  Molajo\Resource\Adapter\Cache::getCache
  * @covers  Molajo\Resource\Adapter\Cache::setCache
  * @covers  Molajo\Resource\Adapter\Cache::deleteCache
  * @covers  Molajo\Resource\Adapter\Cache::clearCache
  *
  * @return  $this
  * @since   1.0.0
  */
 public function testNotExistsNoMapValidExtensions()
 {
     $this->setAdapterValidExtensions();
     $this->setNs();
     $this->assertEquals(false, $this->proxy_instance->exists('xyz:\\\\molajo\\b\\bananarana'));
     return $this;
 }
Ejemplo n.º 9
0
 /**
  * Read a key from the cache
  *
  * @param string $key Identifier for the data
  * @return mixed The cached data, or false if the data doesn't exist, has expired, or if there was an error fetching it
  * @access public
  */
 function read($key)
 {
     if ($this->__setKey($key) === false || !$this->__init || !$this->__File->exists()) {
         return false;
     }
     if ($this->settings['lock']) {
         $this->__File->lock = true;
     }
     $time = time();
     $cachetime = intval($this->__File->read(11));
     if ($cachetime !== false && ($cachetime < $time || $time + $this->settings['duration'] < $cachetime)) {
         $this->__File->close();
         $this->__File->delete();
         return false;
     }
     $data = $this->__File->read(true);
     if ($data !== '' && !empty($this->settings['serialize'])) {
         if ($this->settings['isWindows']) {
             $data = str_replace('\\\\\\\\', '\\', $data);
         }
         $data = unserialize((string) $data);
     }
     $this->__File->close();
     return $data;
 }
Ejemplo n.º 10
0
 /**
  * key是否存在,存在返回ture
  *
  * @access public
  *
  * @param string $key KEY名称
  *
  * @return boolean
  */
 public function exists($key)
 {
     //参数分析
     if (!$key) {
         return false;
     }
     return $this->_Redis->exists($key);
 }
Ejemplo n.º 11
0
 /**
  * Handler for extracting the state of resource instances.
  *
  * @see Lead\Resource\Controller::state()
  *
  * @param  object $resource A resource instance.
  * @return array
  */
 protected function _state($resource)
 {
     $handlers = ['Chaos\\Collection' => function ($resource) {
         $exists = $resource->invoke('exists');
         $validates = $resource->invoke('validates');
         return ['exists' => $resource->exists(), 'valid' => $resource->validates()];
     }, 'Chaos\\Model' => function ($resource) {
         return ['exists' => $resource->exists(), 'valid' => $resource->validates()];
     }];
     if ($resource) {
         foreach ($handlers as $class => $handler) {
             if ($resource instanceof $class) {
                 return $handler($resource);
             }
         }
     }
     return [];
 }
Ejemplo n.º 12
0
 /**
  * Load a configuration file
  *
  * @param  $dotOrFilePath Absolute path to config file, or dot-notation path from basepath (default: app/config) (existing, or to-be)
  * @return $this
  */
 public function load($dotOrFilePath)
 {
     $this->setFilename($dotOrFilePath);
     // check if file already exists
     if ($this->filesystem->exists($this->filename)) {
         // require file and check that it returns an array
         try {
             if (is_array($config = $this->filesystem->getRequire($this->filename))) {
                 $this->configValues = $config;
             } else {
                 throw new \Exception('Existing configuration file could not be loaded (not valid array).');
             }
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage());
         }
     }
     return $this;
 }
Ejemplo n.º 13
0
 /**
  * Sets data to a specified offset and wraps all data array in its appropriate object type.
  *
  * @param  mixed  $data    An array or an entity instance to set.
  * @param  mixed  $offset  The offset. If offset is `null` data is simply appended to the set.
  * @param  array  $options Any additional options to pass to the `Entity`'s constructor.
  * @return object          Returns the inserted instance.
  */
 public function set($offset = null, $data = [])
 {
     $name = $this->_through;
     $parent = $this->_parent;
     $relThrough = $parent->schema()->relation($name);
     $through = $relThrough->to();
     $item = $through::create($this->_parent->exists() ? $relThrough->match($this->_parent) : []);
     $item->{$this->_using} = $data;
     return $this->_parent->{$name}->set($offset, $item);
 }
Ejemplo n.º 14
0
 /**
  * Adds the specified object to the `Collection` instance, and assigns associated metadata to
  * the added object.
  *
  * @param  string $offset The offset to assign the value to.
  * @param  mixed  $data   The entity object to add.
  * @return mixed          Returns the set `Entity` object.
  */
 public function offsetSet($offset, $data)
 {
     $name = $this->_through;
     $parent = $this->parent();
     $relThrough = $parent::relation($name);
     $through = $relThrough->to();
     $item = $through::create($this->_parent->exists() ? $relThrough->match($this->_parent) : []);
     $item->{$this->_using} = $data;
     return $offset !== null ? $this->_parent->{$name}[$offset] = $item : ($this->_parent->{$name}[] = $item);
 }
Ejemplo n.º 15
0
	public function testDelete()
	{
		global $g_ado_db;

		$this->articleType->delete();
		$this->assertFalse($this->articleType->exists());
		$tableName = $g_ado_db->GetOne("SHOW TABLES LIKE '%X".$this->testTypeName."'");
		$this->assertEquals('', $tableName);
		$count = $g_ado_db->GetOne("SELECT COUNT(*) FROM ArticleTypeMetadata WHERE type_name = '".$this->testTypeName."'");
		$this->assertEquals(0, $count);
	}
Ejemplo n.º 16
0
 /**
  * call the function
  *
  * @access	public
  * @param	array	parameters of the function (= attributes of the tag)
  * @param	string	content of the tag
  * @return	string	content to insert into the template
  */
 function call($params, $content)
 {
     $tmpl = $params['template'];
     unset($params['template']);
     if (!$this->_tmpl->exists($tmpl)) {
         return patErrorManager::raiseError(PATTEMPLATE_FUNCTION_CALL_ERROR_NO_TEMPLATE, 'Template ' . $tmpl . ' does not exist');
     }
     /**
      * clear template and all of its dependencies
      */
     $this->_tmpl->clearTemplate($tmpl, true);
     /**
      * add variables
      */
     $this->_tmpl->addVars($tmpl, $params);
     $this->_tmpl->addVar($tmpl, 'CONTENT', $content);
     /**
      * get content
      */
     return $this->_tmpl->getParsedTemplate($tmpl);
 }
Ejemplo n.º 17
0
 /**
  * call the function
  *
  * @access	public
  * @param	array	parameters of the function (= attributes of the tag)
  * @param	string	content of the tag
  * @return	string	content to insert into the template
  */
 function call($params, $content)
 {
     // get the name of the template to use
     if (isset($params['template'])) {
         $tmpl = $params['template'];
         unset($params['template']);
     } elseif (isset($params['_originalTag'])) {
         $tmpl = $params['_originalTag'];
         unset($params['_originalTag']);
     } else {
         return patErrorManager::raiseError(PATTEMPLATE_FUNCTION_CALL_ERROR_NO_TEMPLATE, 'No template for Call function specified.');
     }
     if (!$this->_tmpl->exists($tmpl)) {
         $tmpl = strtolower($tmpl);
         // try some autoloading magic
         $componentLocation = $this->_tmpl->getOption('componentFolder');
         $componentExtension = $this->_tmpl->getOption('componentExtension');
         $filename = $componentLocation . '/' . $tmpl . '.' . $componentExtension;
         $this->_tmpl->readTemplatesFromInput($filename);
         // still does not exist
         if (!$this->_tmpl->exists($tmpl)) {
             return patErrorManager::raiseError(PATTEMPLATE_FUNCTION_CALL_ERROR_NO_TEMPLATE, 'Template ' . $tmpl . ' does not exist');
         }
     }
     /**
      * clear template and all of its dependencies
      */
     $this->_tmpl->clearTemplate($tmpl, true);
     /**
      * add variables
      */
     $this->_tmpl->addVars($tmpl, $params);
     $this->_tmpl->addVar($tmpl, 'CONTENT', $content);
     /**
      * get content
      */
     return $this->_tmpl->getParsedTemplate($tmpl);
 }
Ejemplo n.º 18
0
 /**
  * Generate files based on templates.
  * 
  * @param  mixed  $filenames The file to be written to
  * @param  mixed  $paths     The Twig_Loader_Filesystem template path
  * @param  array  $options   The data to write into the file
  * @param  string $template  The template file
  * @return bool              Returns true if the file has been created
  */
 protected function make($filenames, $paths, array $options = array(), $template = 'Base.php.twig')
 {
     $loader = new Twig_Loader_Filesystem($paths);
     $twig = new Twig_Environment($loader);
     foreach ((array) $filenames as $filename) {
         if (!$this->getOption('force') && $this->_filesystem->exists($filename)) {
             throw new \RuntimeException("Cannot duplicate [{$filename}].");
         }
         $reflection = new \ReflectionClass(get_class($this));
         if ($reflection->getShortName() === 'Migration') {
             $function = new Twig_SimpleFunction('argument', function ($field = "") {
                 return array_combine(array('name', 'type'), explode(':', $field));
             });
             $twig->addFunction($function);
             foreach ($this->getArgument('options') as $option) {
                 list($key, $value) = explode(':', $option);
                 $options[$key] = $value;
             }
         }
         $this->_filesystem->dumpFile($filename, $twig->loadTemplate($template)->render($options));
     }
     return TRUE;
 }
Ejemplo n.º 19
0
 /**
  * Before save callback
  *
  * @param object $model Model using this behavior
  * @return boolean True if the operation should continue, false if it should abort
  * @access public
  */
 function beforeSave(&$model)
 {
     if ($this->settings[$model->alias]['has_created_by'] || $this->settings[$model->alias]['has_modified_by']) {
         $AuthSession = $this->settings[$model->alias]['auth_session'];
         $UserSession = $this->settings[$model->alias]['user_model'];
         $userId = Set::extract($_SESSION, $AuthSession . '.' . $UserSession . '.' . 'id');
         if ($userId) {
             $data = array($this->settings[$model->alias]['modified_by_field'] => $userId);
             if (!$model->exists()) {
                 $data[$this->settings[$model->alias]['created_by_field']] = $userId;
             }
             $model->set($data);
         }
     }
     return true;
 }
Ejemplo n.º 20
0
 /**
  * create a new template
  *
  * @access	private
  * @param	array		attributes
  * @return	boolean		true on success
  */
 function _initTemplate($attributes)
 {
     /**
      * build name for the template
      */
     if (!isset($attributes['name'])) {
         $name = $this->_buildTemplateName();
     } else {
         $name = strtolower($attributes['name']);
         unset($attributes['name']);
     }
     /**
      * name must be unique
      */
     if (isset($this->_templates[$name]) || $this->_tmpl->exists($name)) {
         patErrorManager::raiseNotice(PATTEMPLATE_READER_NOTICE_TEMPLATE_EXISTS, $this->_createErrorMessage("Template {$name} already exists"), $name);
     }
     /**
      * update the path
      */
     array_push($this->_path, $name);
     if (isset($attributes['maxloop'])) {
         if (!isset($attributes['parent'])) {
             $attributes['parent'] = $this->_getFromParentTemplate('name');
         }
     }
     $attributes = $this->_prepareTmplAttributes($attributes, $name);
     array_push($this->_inheritAtts, array('whitespace' => $attributes['whitespace'], 'unusedvars' => $attributes['unusedvars'], 'autoclear' => $attributes['autoclear']));
     /**
      * create a new template
      */
     $tmpl = array('type' => 'tmpl', 'name' => $name, 'attributes' => $attributes, 'content' => '', 'dependencies' => array(), 'varspecs' => array(), 'comments' => array(), 'loaded' => false, 'parsed' => false, 'input' => $this->_name . '://' . $this->_currentInput);
     if ($this->_root == null) {
         $this->_root = $name;
         $tmpl['isRoot'] = true;
     }
     /**
      * prepare subtemplates
      */
     switch ($attributes['type']) {
         case 'condition':
         case 'modulo':
             $tmpl['subtemplates'] = array();
             break;
     }
     return $tmpl;
 }
Ejemplo n.º 21
0
 /**
  * Do basic clean up and structuring of raw user input.
  *
  * @access	private
  * @param	string	Raw User Input
  * @return	array	Array of raw text parameter => option.
  */
 private function prepareUserInput($input)
 {
     //We replace double angle brackets with single angle brackets to avoid premature tag expansion in the input.
     //The ¦ symbol is an alias for |.
     //The combination '²{' and '}²'will be translated to double curly braces; this allows postponed template execution which is crucial for DPL queries which call other DPL queries.
     $input = str_replace(['«', '»', '¦', '²{', '}²'], ['<', '>', '|', '{{', '}}'], $input);
     //Standard new lines into the standard \n and clean up any hanging new lines.
     $input = str_replace(["\r\n", "\r"], "\n", $input);
     $input = trim($input, "\n");
     $rawParameters = explode("\n", $input);
     $parameters = false;
     foreach ($rawParameters as $parameterOption) {
         if (empty($parameterOption)) {
             //Softly ignore blank lines.
             continue;
         }
         if (strpos($parameterOption, '=') === false) {
             $this->logger->addMessage(\DynamicPageListHooks::WARN_PARAMNOOPTION, $parameterOption);
             continue;
         }
         list($parameter, $option) = explode('=', $parameterOption, 2);
         $parameter = trim($parameter);
         $option = trim($option);
         if (strpos($parameter, '<') !== false || strpos($parameter, '>') !== false) {
             //Having the actual less than and greater than symbols is nasty for programatic look up.  The old parameter is still supported along with the new, but we just fix it here before calling it.
             $parameter = str_replace('<', 'lt', $parameter);
             $parameter = str_replace('>', 'gt', $parameter);
         }
         if (empty($parameter) || substr($parameter, 0, 1) == '#' || $this->parameters->exists($parameter) && !$this->parameters->testRichness($parameter)) {
             continue;
         }
         if (!$this->parameters->exists($parameter)) {
             $this->logger->addMessage(\DynamicPageListHooks::WARN_UNKNOWNPARAM, $parameter, implode(', ', $this->parameters->getParametersForRichness()));
             continue;
         }
         //Ignore parameter settings without argument (except namespace and category).
         if (!strlen($option)) {
             if ($parameter != 'namespace' && $parameter != 'notnamespace' && $parameter != 'category' && $this->parameters->exists($parameter)) {
                 continue;
             }
         }
         $parameters[$parameter][] = $option;
     }
     return $parameters;
 }
Ejemplo n.º 22
0
 /**
  * 根据表前缀获取缓存数据(如果多个key,则获取所有key对应的值)
  * @param string|array $key
  * @param string $pre
  */
 public static function gets($key, $pre = '')
 {
     if (is_array($key)) {
         $arr = array();
         foreach ($key as $k) {
             if ($pre) {
                 $arr[] = $pre . $k;
             } else {
                 $arr[] = $k;
             }
         }
         return self::$instance->getMultiple($arr);
     } else {
         $pre && ($key = $pre . $key);
         if (!self::$instance->exists($key)) {
             return false;
         }
         return self::$instance->get($key);
     }
 }
Ejemplo n.º 23
0
 /**
  * Validates and stores the basic gallery settings
  *
  * @param  array  $input unsanitized POST data
  * @return void
  */
 public function vimeography_validate_basic_gallery_settings($input)
 {
     if (check_admin_referer('vimeography-basic-action', 'vimeography-basic-verification')) {
         try {
             global $wpdb;
             $input['vimeography_basic_settings']['video_limit'] = intval($input['vimeography_basic_settings']['video_limit']) <= 25 ? $input['vimeography_basic_settings']['video_limit'] : 25;
             if (!empty($input['vimeography_basic_settings']['gallery_width'])) {
                 preg_match('/(\\d*)(px|%?)/', $input['vimeography_basic_settings']['gallery_width'], $matches);
                 // If a number value is set...
                 if (!empty($matches[1])) {
                     // If a '%' or 'px' is set...
                     if (!empty($matches[2])) {
                         // Accept the valid matching string
                         $input['vimeography_basic_settings']['gallery_width'] = $matches[0];
                     } else {
                         // Append a 'px' value to the matching number
                         $input['vimeography_basic_settings']['gallery_width'] = $matches[1] . 'px';
                     }
                 } else {
                     // Not a valid width
                     $input['vimeography_basic_settings']['gallery_width'] = '';
                 }
             } else {
                 // blank setting
                 $input['vimeography_basic_settings']['gallery_width'] = '';
             }
             $result = $wpdb->update(VIMEOGRAPHY_GALLERY_META_TABLE, array('cache_timeout' => $input['vimeography_basic_settings']['cache_timeout'], 'video_limit' => $input['vimeography_basic_settings']['video_limit'], 'featured_video' => $input['vimeography_basic_settings']['featured_video'], 'gallery_width' => $input['vimeography_basic_settings']['gallery_width']), array('gallery_id' => $this->_gallery_id), array('%d', '%d', '%s', '%s'), array('%d'));
             if ($result === FALSE) {
                 throw new Exception(__('Your settings could not be updated.', 'vimeography'));
                 //$wpdb->print_error();
             }
             if ($this->_cache->exists()) {
                 $this->_cache->delete();
             }
             do_action('vimeography/reload-gallery');
             $this->messages[] = array('type' => 'updated', 'heading' => __('Settings updated.', 'vimeography'), 'message' => __('Nice work. You are pretty good at this.', 'vimeography'));
         } catch (Exception $e) {
             $this->messages[] = array('type' => 'error', 'heading' => __('Ruh roh.', 'vimeography'), 'message' => $e->getMessage());
         }
     }
 }
Ejemplo n.º 24
0
 /**
  * Before save callback
  *
  * @param object $model Model using this behavior
  * @return boolean True if the operation should continue, false if it should abort
  * @access public
  */
 function beforeSave(&$model)
 {
     if ($this->settings[$model->alias]['has_created_by'] || $this->settings[$model->alias]['has_modified_by']) {
         $userId = Set::extract($_SESSION, 'Zuluru.act_as_id');
         if (!$userId) {
             $AuthSession = $this->settings[$model->alias]['auth_session'];
             // Hardcoded, rather than using the model name. The model name is set *after*
             // the Auth component sets its session key name.
             $UserSession = 'User';
             $userId = Set::extract($_SESSION, $AuthSession . '.' . $UserSession . '.zuluru_person_id');
         }
         if ($userId) {
             $data = array($this->settings[$model->alias]['modified_by_field'] => $userId);
             if (!$model->exists()) {
                 $data[$this->settings[$model->alias]['created_by_field']] = $userId;
             }
             $model->set($data);
         }
     }
     return true;
 }
 function delete()
 {
     $cats_app = get_var('cats_app', array('GET', 'POST'));
     $extra = get_var('extra', array('GET', 'POST'));
     $global_cats = get_var('global_cats', array('GET', 'POST'));
     $cats_level = get_var('cats_level', array('GET', 'POST'));
     $cat_id = get_var('cat_id', array('GET', 'POST'));
     $link_data = array('menuaction' => 'preferences.uicategories.index', 'cats_app' => $cats_app, 'extra' => $extra, 'global_cats' => $global_cats, 'cats_level' => $cats_level, 'cat_id' => $cat_id);
     if (!$cat_id || $_POST['cancel']) {
         $GLOBALS['phpgw']->redirect_link('/index.php', $link_data);
     }
     if ($_POST['confirm']) {
         if ($_POST['subs']) {
             $this->bo->delete($cat_id, True);
         } else {
             $this->bo->delete($cat_id, False);
         }
         $GLOBALS['phpgw']->redirect_link('/index.php', $link_data);
     } else {
         $GLOBALS['phpgw']->template->set_file(array('category_delete' => 'delete.tpl'));
         $GLOBALS['phpgw_info']['flags']['app_header'] = lang('Delete Categories');
         $GLOBALS['phpgw']->common->phpgw_header();
         echo parse_navbar();
         $GLOBALS['phpgw']->template->set_var('deleteheader', lang('Are you sure you want to delete this category ?'));
         $exists = $this->bo->exists(array('type' => 'subs', 'cat_name' => '', 'cat_id' => $cat_id));
         if ($exists) {
             $GLOBALS['phpgw']->template->set_var('lang_subs', lang('Do you also want to delete all subcategories ?'));
             $GLOBALS['phpgw']->template->set_var('subs', '<input type="checkbox" name="subs" value="True" />');
         } else {
             $GLOBALS['phpgw']->template->set_var('lang_subs', '');
             $GLOBALS['phpgw']->template->set_var('subs', '');
         }
         $GLOBALS['phpgw']->template->set_var('lang_no', lang('No'));
         $link_data['menuaction'] = 'preferences.uicategories.delete';
         $GLOBALS['phpgw']->template->set_var('action_url', $GLOBALS['phpgw']->link('/index.php', $link_data));
         $GLOBALS['phpgw']->template->set_var('lang_yes', lang('Yes'));
         $GLOBALS['phpgw']->template->pfp('out', 'category_delete');
     }
 }
Ejemplo n.º 26
0
 /**
  * Marks a record as published and optionally change other fields.
  *
  * @param object $Model Model from where the method is being executed.
  * @param mixed $id ID of the publishable record.
  * @param $attributes Other fields to change (in the form of field => value)
  * @return boolean Result of the operation.
  */
 function publish(&$Model, $id = null, $attributes = array())
 {
     if ($Model->hasField($this->__settings[$Model->alias]['field'])) {
         if (empty($id)) {
             $id = $Model->id;
         }
         $data = array($Model->alias => array($Model->primaryKey => $id, $this->__settings[$Model->alias]['field'] => true));
         $Model->id = $id;
         if (isset($this->__settings[$Model->alias]['field_date']) && $Model->hasField($this->__settings[$Model->alias]['field_date'])) {
             if (!$Model->exists()) {
                 $data[$Model->alias][$this->__settings[$Model->alias]['field_date']] = date('Y-m-d');
             }
         }
         if (!empty($attributes)) {
             $data[$Model->alias] = array_merge($data[$Model->alias], $attributes);
         }
         $onFind = $this->__settings[$Model->alias]['find'];
         $this->enablePublishable($Model, false);
         $result = $Model->save($data, false, array_keys($data[$Model->alias]));
         $this->enablePublishable($Model, 'find', $onFind);
         return $result !== false;
     }
     return false;
 }
Ejemplo n.º 27
0
/**
 * Update all user caches
 *
 * @since 3.0.0
 *
 * @param object|WP_User $user User object to be cached
 * @return bool|null Returns false on failure.
 */
function update_user_caches($user)
{
    if ($user instanceof WP_User) {
        if (!$user->exists()) {
            return false;
        }
        $user = $user->data;
    }
    wp_cache_add($user->ID, $user, 'users');
    wp_cache_add($user->user_login, $user->ID, 'userlogins');
    wp_cache_add($user->user_email, $user->ID, 'useremail');
    wp_cache_add($user->user_nicename, $user->ID, 'userslugs');
}
Ejemplo n.º 28
0
 /**
  * Creates a default set of conditions from the model if $conditions is null/empty.
  * If conditions are supplied then they will be returned.  If a model doesn't exist and no conditions
  * were provided either null or false will be returned based on what was input.
  *
  * @param object $model
  * @param mixed $conditions Array of conditions, conditions string, null or false. If an array of conditions,
  *   or string conditions those conditions will be returned.  With other values the model's existance will be checked.
  *   If the model doesn't exist a null or false will be returned depending on the input value.
  * @param boolean $useAlias Use model aliases rather than table names when generating conditions
  * @return mixed Either null, false, $conditions or an array of default conditions to use.
  * @see DboSource::update()
  * @see DboSource::conditions()
  * @access public
  */
 function defaultConditions(&$model, $conditions, $useAlias = true)
 {
     if (!empty($conditions)) {
         return $conditions;
     }
     $exists = $model->exists();
     if (!$exists && $conditions !== null) {
         return false;
     } elseif (!$exists) {
         return null;
     }
     $alias = $model->alias;
     if (!$useAlias) {
         $alias = $this->fullTableName($model, false);
     }
     return array("{$alias}.{$model->primaryKey}" => $model->getID());
 }
Ejemplo n.º 29
0
/**
 * Sets the cookies used to store an unauthenticated commentator's identity. Typically used
 * to recall previous comments by this commentator that are still held in moderation.
 *
 * @param WP_Comment $comment Comment object.
 * @param object     $user    Comment author's object.
 *
 * @since 3.4.0
 */
function wp_set_comment_cookies($comment, $user)
{
    if ($user->exists()) {
        return;
    }
    /**
     * Filter the lifetime of the comment cookie in seconds.
     *
     * @since 2.8.0
     *
     * @param int $seconds Comment cookie lifetime. Default 30000000.
     */
    $comment_cookie_lifetime = apply_filters('comment_cookie_lifetime', 30000000);
    $secure = 'https' === parse_url(home_url(), PHP_URL_SCHEME);
    setcookie('comment_author_' . COOKIEHASH, $comment->comment_author, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_email_' . COOKIEHASH, $comment->comment_author_email, time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
    setcookie('comment_author_url_' . COOKIEHASH, esc_url($comment->comment_author_url), time() + $comment_cookie_lifetime, COOKIEPATH, COOKIE_DOMAIN, $secure);
}
Ejemplo n.º 30
0
 /**
  * Event call to get side content for main project page
  *
  * @param   object  $model
  * @return  string
  */
 public function onProjectMiniList($model)
 {
     if (!$model->exists() || !$model->access('content')) {
         return false;
     }
     $this->repo = new \Components\Projects\Models\Repo($model, 'local');
     $view = new \Hubzero\Plugin\View(array('folder' => 'projects', 'element' => 'files', 'name' => 'mini'));
     // Set params
     $view->params = array('limit' => $model->config()->get('sidebox_limit', 5), 'start' => 0, 'sortby' => 'modified', 'sortdir' => 'DESC', 'getParents' => false, 'getChildren' => false);
     // Retrieve items
     $view->files = $this->repo->filelist($view->params);
     $view->model = $model;
     return $view->loadTemplate();
 }