check() публичный Метод

Check the data for validity. By default it only checks for fields declared as NOT NULL
public check ( ) : static
Результат static Self, for chaining
Пример #1
0
 public function check()
 {
     if (empty($this->published)) {
         $this->published = 0;
     }
     return parent::check();
 }
Пример #2
0
 /**
  * Overrides the automated table checks to handle the 'hash' column for faster searching
  *
  * @return $this|DataModel
  */
 public function check()
 {
     // Create a slug if there is a title and an empty slug
     if ($this->hasField('title') && $this->hasField('slug') && !$this->slug) {
         $this->slug = \JApplicationHelper::stringURLSafe($this->title);
     }
     // Create the SHA-1 hash of the slug for faster searching (make sure the hash column is CHAR(64) to take
     // advantage of MySQL's optimised searching for fixed size CHAR columns)
     if ($this->hasField('hash') && $this->hasField('slug')) {
         $this->hash = sha1($this->slug);
     }
     // Reset cached values
     $this->resetTreeCache();
     // Run the parent checks
     parent::check();
     return $this;
 }
Пример #3
0
 public function check()
 {
     $this->assertNotEmpty($this->title, 'COM_ARS_CATEGORY_ERR_NEEDS_TITLE');
     // If the alias is missing, auto-create a new one
     if (!$this->alias) {
         \JLoader::import('joomla.filter.input');
         $alias = str_replace(' ', '-', strtolower($this->title));
         $this->alias = (string) preg_replace('/[^A-Z0-9_-]/i', '', $alias);
     }
     // If no alias could be auto-generated, fail
     $this->assertNotEmpty($this->alias, 'COM_ARS_CATEGORY_ERR_NEEDS_SLUG');
     // Check alias for uniqueness
     $db = $this->getDBO();
     $query = $db->getQuery(true)->select($db->qn('alias'))->from($db->qn('#__ars_categories'));
     if ($this->id) {
         $query->where('NOT(' . $db->qn('id') . ' = ' . $db->q($this->id) . ')');
     }
     $db->setQuery($query);
     $aliases = $db->loadColumn();
     $this->assertNotInArray($this->alias, $aliases, 'COM_ARS_CATEGORY_ERR_NEEDS_UNIQUE_SLUG');
     // Check directory
     \JLoader::import('joomla.filesystem.folder');
     $this->directory = rtrim($this->directory, '/');
     if ($this->directory == 's3:') {
         $this->directory = 's3://';
     }
     $check = trim($this->directory);
     $this->assertNotEmpty($check, 'COM_ARS_CATEGORY_ERR_NEEDS_DIRECTORY');
     $potentialPrefix = substr($check, 0, 5);
     $potentialPrefix = strtolower($potentialPrefix);
     if ($potentialPrefix == 's3://') {
         $check = substr($check, 5);
         if (!empty($check)) {
             $check .= '/';
         }
         $s3 = AmazonS3::getInstance();
         $items = $s3->getBucket('', $check);
         $this->assertNotEmpty($items, 'COM_ARS_CATEGORY_ERR_S3_DIRECTORY_NOT_EXISTS');
     } else {
         if (!\JFolder::exists($this->directory)) {
             $directory = JPATH_SITE . '/' . $this->directory;
             $this->assert(\JFolder::exists($directory), 'COM_ARS_CATEGORY_ERR_DIRECTORY_NOT_EXISTS');
         }
     }
     // Automaticaly fix the type
     if (!in_array($this->type, array('normal', 'bleedingedge'))) {
         $this->type = 'normal';
     }
     // Set the access to registered if there are subscriptions groups defined
     if (empty($this->access)) {
         $this->access = 1;
     }
     if (!empty($this->groups) && $this->access == 1) {
         $this->access = 2;
     }
     if (empty($this->published) && $this->published !== 0) {
         $this->published = 0;
     }
     parent::check();
     return $this;
 }
Пример #4
0
 public function check()
 {
     if ($this->container->platform->isFrontend()) {
         $this->user_id = $this->container->platform->getUser()->id;
     }
     $db = $this->getDbo();
     // Should this be a primary or a secondary DLID?
     if (is_null($this->primary)) {
         // Do I have another primary?
         $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__ars_dlidlabels'))->where($db->qn('user_id') . ' = ' . $db->q($this->user_id))->where($db->qn('primary') . ' = ' . $db->q(1));
         if ($this->ars_dlidlabel_id) {
             $query->where('NOT(' . $db->qn('ars_dlidlabel_id') . ' = ' . $db->q($this->ars_dlidlabel_id) . ')');
         }
         $hasPrimary = $db->setQuery($query)->loadResult();
         $this->primary = $hasPrimary ? 0 : 1;
     }
     if ($this->primary) {
         // You can never disable a primary Download ID
         $this->enabled = 1;
         // The primary Download ID title is fixed
         $this->label = '_MAIN_';
     }
     // Do I need to generate a download ID?
     if (empty($this->dlid)) {
         while (empty($this->dlid)) {
             $this->dlid = md5(\JCrypt::genRandomBytes(64));
             // Do I have another primary?
             $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__ars_dlidlabels'))->where($db->qn('dlid') . ' = ' . $db->q($this->dlid))->where($db->qn('user_id') . ' = ' . $db->q($this->user_id))->where($db->qn('primary') . ' = ' . $db->q($this->primary));
             if ($this->ars_dlidlabel_id) {
                 $query->where('NOT(' . $db->qn('ars_dlidlabel_id') . ' = ' . $db->q($this->ars_dlidlabel_id) . ')');
             }
             $dlidColission = $db->setQuery($query)->loadResult();
             if ($dlidColission) {
                 $this->dlid = null;
             }
         }
     }
     return parent::check();
 }
Пример #5
0
 public function check()
 {
     $this->assertNotEmpty($this->release_id, 'ERR_ITEM_NEEDS_CATEGORY');
     // Get some useful info
     $db = $this->getDBO();
     $query = $db->getQuery(true)->select(array($db->qn('title'), $db->qn('alias')))->from($db->qn('#__ars_items'))->where($db->qn('release_id') . ' = ' . $db->q($this->release_id));
     if ($this->id) {
         $query->where('NOT(' . $db->qn('id') . '=' . $db->q($this->id) . ')');
     }
     $db->setQuery($query);
     $info = $db->loadAssocList();
     $titles = array();
     $aliases = array();
     foreach ($info as $infoitem) {
         $titles[] = $infoitem['title'];
         $aliases[] = $infoitem['alias'];
     }
     // Let's get automatic item title/description records
     $subQuery = $db->getQuery(true)->select($db->qn('category_id'))->from($db->qn('#__ars_releases'))->where($db->qn('id') . ' = ' . $db->q($this->release_id));
     $query = $db->getQuery(true)->select('*')->from($db->qn('#__ars_autoitemdesc'))->where($db->qn('category') . ' IN (' . $subQuery . ')')->where('NOT(' . $db->qn('published') . '=' . $db->q(0) . ')');
     $db->setQuery($query);
     $autoitems = $db->loadObjectList();
     $auto = (object) array('title' => '', 'description' => '', 'environments' => '');
     if (!empty($autoitems)) {
         $fname = basename($this->type == 'file' ? $this->filename : $this->url);
         foreach ($autoitems as $autoitem) {
             $pattern = $autoitem->packname;
             if (empty($pattern)) {
                 continue;
             }
             if (fnmatch($pattern, $fname)) {
                 $auto = $autoitem;
                 break;
             }
         }
     }
     // Added environment ID
     if (!empty($this->environments) && is_array($this->environments)) {
         // Filter out empty environments
         $temp = array();
         foreach ($this->environments as $eid) {
             if ($eid) {
                 $temp[] = $eid;
             }
         }
         $this->environments = $temp;
     }
     // Check if a title exists
     if (!$this->title) {
         // No, try the automatic rule-based title
         $this->title = $auto->title;
         if (!$this->title) {
             // No, try to get the filename
             switch ($this->type) {
                 case 'file':
                     if ($this->filename) {
                         $this->title = basename($this->filename);
                     }
                     break;
                 case 'link':
                     if ($this->url) {
                         $this->title = basename($this->url);
                     }
                     break;
             }
             $this->assertNotEmpty($this->title, 'ERR_ITEM_NEEDS_TITLE');
         }
     }
     $this->assertNotInArray($this->title, $titles, 'ERR_ITEM_NEEDS_TITLE_UNIQUE');
     $stripDesc = strip_tags($this->description);
     $stripDesc = trim($stripDesc);
     if (empty($this->description) || empty($stripDesc)) {
         $this->description = $auto->description;
     }
     // If the alias is missing, auto-create a new one
     if (!$this->alias) {
         $source = $this->title;
         switch ($this->type) {
             case 'file':
                 if ($this->filename) {
                     $source = basename($this->filename);
                 }
                 break;
             case 'link':
                 if ($this->url) {
                     $source = basename($this->url);
                 }
                 break;
         }
         $this->alias = str_replace('.', '-', $source);
         // Create a smart alias
         $alias = strtolower($source);
         $alias = str_replace(' ', '-', $alias);
         $alias = str_replace('.', '-', $alias);
         $this->alias = (string) preg_replace('/[^A-Z0-9_-]/i', '', $alias);
     }
     $this->assertNotEmpty($this->alias, 'ERR_ITEM_NEEDS_ALIAS');
     $this->assertNotInArray($this->alias, $aliases, 'ERR_ITEM_NEEDS_ALIAS_UNIQUE');
     $this->assertInArray($this->type, ['link', 'file'], 'ERR_ITEM_NEEDS_TYPE');
     switch ($this->type) {
         case 'file':
             $this->assertNotEmpty($this->filename, 'ERR_ITEM_NEEDS_FILENAME');
             break;
         case 'link':
             $this->assertNotEmpty($this->url, 'ERR_ITEM_NEEDS_LINK');
             break;
     }
     \JLoader::import('joomla.filter.filterinput');
     $filter = \JFilterInput::getInstance(null, null, 1, 1);
     // Filter the description using a safe HTML filter
     if (!empty($this->description)) {
         $this->description = $filter->clean($this->description);
     }
     // Set the access to registered if there are subscription groups defined
     if (!empty($this->groups) && $this->access == 1) {
         $this->access = 2;
     }
     if (is_null($this->published) || $this->published == '') {
         $this->published = 0;
     }
     // Apply an update stream, if possible
     if (empty($this->updatestream)) {
         $db = $this->getDBO();
         $subquery = $db->getQuery(true)->select($db->qn('category_id'))->from('#__ars_releases')->where($db->qn('id') . ' = ' . $db->q($this->release_id));
         $query = $db->getQuery(true)->select('*')->from($db->qn('#__ars_updatestreams'))->where($db->qn('category') . ' IN (' . $subquery . ')');
         $db->setQuery($query);
         $streams = $db->loadObjectList();
         if (!empty($streams)) {
             $fname = basename($this->type == 'file' ? $this->filename : $this->url);
             foreach ($streams as $stream) {
                 $pattern = $stream->packname;
                 $element = $stream->element;
                 if (empty($pattern) && !empty($element)) {
                     $pattern = $element . '*';
                 }
                 if (empty($pattern)) {
                     continue;
                 }
                 if (fnmatch($pattern, $fname)) {
                     $this->updatestream = $stream->id;
                     break;
                 }
             }
         }
     }
     // Check for MD5 and SHA1 existence
     if (empty($this->md5) || empty($this->sha1) || empty($this->filesize)) {
         if ($this->type == 'file') {
             $target = null;
             $folder = null;
             $filename = $this->filename;
             /** @var Releases $releaseModel */
             $releaseModel = $this->container->factory->model('Releases')->tmpInstance();
             /** @var Releases $release */
             $release = $releaseModel->find($this->release_id);
             if ($release->id) {
                 if ($release->category->id) {
                     $folder = $release->category->directory;
                 }
             }
             $url = null;
             if (!empty($folder)) {
                 $potentialPrefix = substr($folder, 0, 5);
                 $potentialPrefix = strtolower($potentialPrefix);
                 if ($potentialPrefix == 's3://') {
                     $check = substr($folder, 5);
                     $s3 = AmazonS3::getInstance();
                     $items = $s3->getBucket('', $check);
                     if (empty($items)) {
                         $folder = null;
                         return false;
                     } else {
                         // Get a signed URL
                         $s3 = Amazons3::getInstance();
                         $url = $s3->getAuthenticatedURL(rtrim(substr($folder, 5), '/') . '/' . ltrim($filename, '/'));
                     }
                 } else {
                     \JLoader::import('joomla.filesystem.folder');
                     if (!\JFolder::exists($folder)) {
                         $folder = JPATH_ROOT . '/' . $folder;
                         if (!\JFolder::exists($folder)) {
                             $folder = null;
                         }
                     }
                     if (!empty($folder)) {
                         $filename = $folder . '/' . $filename;
                     }
                 }
             }
         }
         if (!isset($url)) {
             $url = null;
         }
         if ($this->type == 'link' || !is_null($url)) {
             if (is_null($url)) {
                 $url = $this->url;
             }
             $config = \JFactory::getConfig();
             $target = $config->get('tmp_path') . '/temp.dat';
             if (function_exists('curl_exec')) {
                 // By default, try using cURL
                 $process = curl_init($url);
                 curl_setopt($process, CURLOPT_HEADER, 0);
                 // Pretend we are IE7, so that webservers play nice with us
                 curl_setopt($process, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.0.3705; .NET CLR 1.1.4322; Media Center PC 4.0)');
                 curl_setopt($process, CURLOPT_TIMEOUT, 5);
                 curl_setopt($process, CURLOPT_RETURNTRANSFER, 1);
                 curl_setopt($process, CURLOPT_SSL_VERIFYPEER, false);
                 // The @ sign allows the next line to fail if open_basedir is set or if safe mode is enabled
                 @curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1);
                 @curl_setopt($process, CURLOPT_MAXREDIRS, 20);
                 $data = curl_exec($process);
                 if ($data !== false) {
                     \JLoader::import('joomla.filesystem.file');
                     $result = \JFile::write($target, $data);
                 }
                 curl_close($process);
             } else {
                 // Use Joomla!'s download helper
                 \JLoader::import('joomla.installer.helper');
                 \JInstallerHelper::downloadPackage($url, $target);
             }
             $filename = $target;
         }
         if (!empty($filename) && is_file($filename)) {
             \JLoader::import('joomla.filesystem.file');
             if (!\JFile::exists($filename)) {
                 $filename = null;
             }
         }
         if (!empty($filename) && is_file($filename)) {
             if (function_exists('hash_file')) {
                 if (empty($this->md5)) {
                     $this->md5 = hash_file('md5', $filename);
                 }
                 if (empty($this->sha1)) {
                     $this->sha1 = hash_file('sha1', $filename);
                 }
             } else {
                 if (function_exists('md5_file') && empty($this->md5)) {
                     $this->md5 = md5_file($filename);
                 }
                 if (function_exists('sha1_file') && empty($this->sha1)) {
                     $this->sha1 = sha1_file($filename);
                 }
             }
             if (empty($this->filesize)) {
                 $filesize = @filesize($filename);
                 if ($filesize !== false) {
                     $this->filesize = $filesize;
                 }
             }
         }
         if (!empty($filename) && is_file($filename) && $this->type == 'link') {
             if (!@unlink($filename)) {
                 \JFile::delete($filename);
             }
         }
     }
     return parent::check();
 }
Пример #6
0
 public function check()
 {
     $this->assertNotEmpty($this->category_id, 'COM_RELEASE_ERR_NEEDS_CATEGORY');
     // Get some useful info
     $db = $this->getDBO();
     $query = $db->getQuery(true)->select(array($db->qn('version'), $db->qn('alias')))->from($db->qn('#__ars_releases'))->where($db->qn('category_id') . ' = ' . $db->q($this->category_id));
     if ($this->id) {
         $query->where('NOT(' . $db->qn('id') . '=' . $db->q($this->id) . ')');
     }
     $db->setQuery($query);
     $info = $db->loadAssocList();
     $versions = array();
     $aliases = array();
     foreach ($info as $infoitem) {
         $versions[] = $infoitem['version'];
         $aliases[] = $infoitem['alias'];
     }
     $this->assertNotEmpty($this->version, 'COM_RELEASE_ERR_NEEDS_VERSION');
     $this->assertNotInArray($this->version, $versions, 'COM_RELEASE_ERR_NEEDS_VERSION_UNIQUE');
     // If the alias is missing, auto-create a new one
     if (!$this->alias) {
         \JLoader::import('joomla.filter.input');
         // Get the category title
         /** @var Categories $catModel */
         $catModel = $this->container->factory->model('Categories')->tmpInstance();
         $catItem = $catModel->find($this->category_id);
         // Create a smart alias
         $alias = strtolower($catItem->alias . '-' . $this->version);
         $alias = str_replace(' ', '-', $alias);
         $alias = str_replace('.', '-', $alias);
         $this->alias = (string) preg_replace('/[^A-Z0-9_-]/i', '', $alias);
     }
     $this->assertNotEmpty($this->alias, 'COM_RELEASE_ERR_NEEDS_ALIAS');
     $this->assertNotInArray($this->alias, $aliases, 'COM_RELEASE_ERR_NEEDS_ALIAS_UNIQUE');
     // Automaticaly fix the maturity
     if (!in_array($this->maturity, array('alpha', 'beta', 'rc', 'stable'))) {
         $this->maturity = 'beta';
     }
     \JLoader::import('joomla.filter.filterinput');
     $filter = \JFilterInput::getInstance(null, null, 1, 1);
     // Filter the description using a safe HTML filter
     if (!empty($this->description)) {
         $this->description = $filter->clean($this->description);
     }
     // Filter the notes using a safe HTML filter
     if (!empty($this->notes)) {
         $this->notes = $filter->clean($this->notes);
     }
     // Set the access to registered if there are subscriptions defined
     if (!empty($this->groups) && $this->access == 1) {
         $this->access = 2;
     }
     if (empty($this->published) && $this->published !== 0) {
         $this->published = 0;
     }
     return parent::check();
 }
Пример #7
0
 public function check()
 {
     $this->assertNotEmpty($this->name, 'ERR_USTREAM_NEEDS_NAME');
     // If the alias is missing, auto-create a new one
     if (!$this->alias) {
         \JLoader::import('joomla.filter.input');
         $alias = str_replace(' ', '-', strtolower($this->name));
         $this->alias = (string) preg_replace('/[^A-Z0-9_-]/i', '', $alias);
     }
     // If no alias could be auto-generated, fail
     $this->assertNotEmpty($this->alias, 'ERR_USTREAM_NEEDS_ALIAS');
     // Check alias for uniqueness
     $db = $this->getDBO();
     $query = $db->getQuery(true)->select($db->qn('alias'))->from($db->qn('#__ars_updatestreams'));
     if ($this->id) {
         $query->where('NOT(' . $db->qn('id') . '=' . $db->q($this->id) . ')');
     }
     $db->setQuery($query);
     $aliases = $db->loadColumn();
     $this->assertNotInArray($this->alias, $aliases, 'ERR_USTREAM_NEEDS_UNIQUE_ALIAS');
     // Automaticaly fix the type
     if (!in_array($this->type, array('components', 'libraries', 'modules', 'packages', 'plugins', 'files', 'templates'))) {
         $this->type = 'components';
     }
     // Require an element name
     $this->assertNotEmpty($this->element, 'ERR_USTREAM_NEEDS_ELEMENT');
     if (empty($this->published) && $this->published !== 0) {
         $this->published = 0;
     }
     return parent::check();
 }
Пример #8
0
 public function check()
 {
     if (empty($this->user_id)) {
         $user = $this->container->platform->getUser();
         $this->user_id = $user->id;
     }
     if (empty($this->item_id)) {
         // Yeah, I know, the Model shouldn't access the input directly but this saves us a lot of code in the
         // front-end models where we're logging downloads.
         $this->item_id = $this->input->getInt('id', 0);
     }
     if (empty($this->accessed_on) || $this->accessed_on == '0000-00-00 00:00:00') {
         \JLoader::import('joomla.utilities.date');
         $date = new \JDate();
         $this->accessed_on = $date->toSql();
     }
     if (empty($this->referer)) {
         if (isset($_SERVER['HTTP_REFERER'])) {
             $this->referer = $_SERVER['HTTP_REFERER'];
         }
     }
     if (empty($this->ip)) {
         $this->ip = Ip::getIp();
         if (class_exists('\\AkeebaGeoipProvider')) {
             $geoip = new \AkeebaGeoipProvider();
             $this->country = $geoip->getCountryCode($this->ip);
         }
     }
     return parent::check();
 }
Пример #9
0
 public function check()
 {
     $this->assertNotEmpty($this->title, 'ERR_VGROUP_NEEDS_TITLE');
     if (empty($this->ordering)) {
         $this->ordering = $this->getNextOrder();
     }
     if (empty($this->published) && $this->published !== 0) {
         $this->published = 0;
     }
     return parent::check();
 }