public function store($updateNulls = false)
 {
     $isNew = false;
     if (!$this->id) {
         // New document
         $this->downloaded = 0;
         $isNew = true;
     }
     if (isset($this->alias) && isset($this->name) && $this->alias == "") {
         $this->alias = preg_replace("/ /", "-", strtolower($this->name));
     }
     if (version_compare(JVERSION, '3.0', '>=')) {
         $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     } else {
         $this->alias = JApplication::stringURLSafe($this->alias);
     }
     // Trigger events to osdownloads plugins
     $dispatcher = $this->getDispatcher();
     $pluginResults = $dispatcher->trigger('onOSDownloadsBeforeSaveFile', array(&$this, $isNew));
     $result = false;
     if ($pluginResults !== false) {
         $result = parent::store($updateNulls);
         $dispatcher->trigger('onOSDownloadsAfterSaveFile', array($result, &$this));
     }
     return $result;
 }
Пример #2
0
 /**
  * Method to perform sanity checks on the JTable instance properties to ensure
  * they are safe to store in the database.  Child classes should override this
  * method to make sure the data they are storing in the database is safe and
  * as expected before storage.
  *
  * @return  boolean  True if the instance is sane and able to be stored in the database.
  *
  * @since   2.5
  */
 public function check()
 {
     try {
         parent::check();
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     if (trim($this->alias) == '') {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     $params = new Registry($this->params);
     $nullDate = $this->_db->getNullDate();
     $d1 = $params->get('d1', $nullDate);
     $d2 = $params->get('d2', $nullDate);
     // Check the end date is not earlier than the start date.
     if ($d2 > $nullDate && $d2 < $d1) {
         // Swap the dates.
         $params->set('d1', $d2);
         $params->set('d2', $d1);
         $this->params = (string) $params;
     }
     return true;
 }
Пример #3
0
 /**
  * Overloaded check function
  *
  * @return  boolean
  *
  * @see     JTable::check
  * @since   1.5
  */
 public function check()
 {
     // Set name
     $this->name = htmlspecialchars_decode($this->name, ENT_QUOTES);
     // Set alias
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (empty($this->alias)) {
         $this->alias = JApplicationHelper::stringURLSafe($this->name);
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
         $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
         return false;
     }
     // Set ordering
     if ($this->state < 0) {
         // Set ordering to 0 if state is archived or trashed
         $this->ordering = 0;
     } elseif (empty($this->ordering)) {
         // Set ordering to last if ordering was 0
         $this->ordering = self::getNextOrder($this->_db->quoteName('catid') . '=' . $this->_db->quote($this->catid) . ' AND state>=0');
     }
     if (empty($this->publish_up)) {
         $this->publish_up = $this->getDbo()->getNullDate();
     }
     if (empty($this->publish_down)) {
         $this->publish_down = $this->getDbo()->getNullDate();
     }
     if (empty($this->modified)) {
         $this->modified = $this->getDbo()->getNullDate();
     }
     return true;
 }
Пример #4
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     try {
         parent::check();
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     $this->menutype = JApplicationHelper::stringURLSafe($this->menutype);
     if (empty($this->menutype)) {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENUTYPE_EMPTY'));
         return false;
     }
     // Sanitise data.
     if (trim($this->title) == '') {
         $this->title = $this->menutype;
     }
     // Check for unique menutype.
     $query = $this->_db->getQuery(true)->select('COUNT(id)')->from($this->_db->quoteName('#__menu_types'))->where($this->_db->quoteName('menutype') . ' = ' . $this->_db->quote($this->menutype))->where($this->_db->quoteName('id') . ' <> ' . (int) $this->id);
     $this->_db->setQuery($query);
     if ($this->_db->loadResult()) {
         $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENUTYPE_EXISTS', $this->menutype));
         return false;
     }
     return true;
 }
 /**
  * @see https://www.warcraftlogs.com/v1/docs#!/Reports/
  * @throws RuntimeException
  *
  * @return stdClass
  */
 public function getData($api_key)
 {
     $uri = new JUri();
     $this->params->set('realm', str_replace("'", '', $this->params->get('realm')));
     $this->params->set('guild', str_replace(' ', '+', $this->params->get('guild')));
     $uri->setPath('/v1/reports/guild/' . $this->params->get('guild') . '/' . JApplicationHelper::stringURLSafe($this->params->get('realm')) . '/' . $this->params->get('region'));
     $uri->setVar('api_key', $api_key);
     return $this->getRemote($uri);
 }
Пример #6
0
 /**
  * Convert a string into a slug (alias), suitable for use in URLs. Please
  * note that transliteration support is rudimentary at this stage.
  *
  * @param   string  $value  A string to convert to slug
  *
  * @return  string  The slug
  *
  * @deprecated  3.0  Use \JApplicationHelper::stringURLSafe instead
  *
  * @codeCoverageIgnore
  */
 public static function toSlug($value)
 {
     if (class_exists('\\JLog')) {
         \JLog::add('FOF30\\Utils\\String::toSlug is deprecated. Use \\JApplicationHelper::stringURLSafe instead', \JLog::WARNING, 'deprecated');
     }
     if (!class_exists('\\JApplicationHelper')) {
         \JLoader::import('cms.application.helper');
     }
     return \JApplicationHelper::stringURLSafe($value);
 }
Пример #7
0
 public function check()
 {
     if (trim($this->alias) == '') {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     return true;
 }
Пример #8
0
 /**
  * @return mixed
  */
 public function getData()
 {
     $this->url = 'http://guildox.com/api/guild/' . $this->params->get('region') . '/' . JApplicationHelper::stringURLSafe($this->params->get('realm')) . '/' . $this->params->get('guild');
     $result = $this->getRemote($this->url);
     $result->body = json_decode($result->body);
     if ($result->code != 200) {
         $msg = JText::sprintf('Server Error: %s', JHtml::_('link', $this->url, $result->code, array('target' => '_blank')));
         throw new RuntimeException($msg);
     }
     return $result;
 }
 /**
  * @return mixed
  */
 public function getData()
 {
     $this->url = 'http://www.wowprogress.com/guild/' . $this->params->get('region') . '/' . JApplicationHelper::stringURLSafe($this->params->get('realm')) . '/' . $this->params->get('guild') . '/json_rank';
     $result = $this->getRemote($this->url);
     $result->body = json_decode($result->body);
     if (empty($result->body) || $result->code != 200) {
         $msg = JText::sprintf('invalid response: %s', JHtml::_('link', $this->url, $result->code, array('target' => '_blank')));
         throw new RuntimeException($msg);
     }
     return $result;
 }
Пример #10
0
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return  boolean  True on success.
  */
 public function check()
 {
     try {
         parent::check();
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Check for valid name.
     if (trim($this->name) == '') {
         $this->setError(JText::_('COM_NEWSFEEDS_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->name;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
         $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
         return false;
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string if not empty
     if (!empty($this->metakey)) {
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     // Clean up description -- eliminate quotes and <> brackets
     if (!empty($this->metadesc)) {
         // Only process if not empty
         $bad_characters = array("\"", "<", ">");
         $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
     }
     return true;
 }
Пример #11
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   3.1
  */
 public function check()
 {
     if (trim($this->core_title) == '') {
         $this->setError(JText::_('JLIB_CMS_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (trim($this->core_alias) == '') {
         $this->core_alias = $this->core_title;
     }
     $this->core_alias = JApplicationHelper::stringURLSafe($this->core_alias);
     if (trim(str_replace('-', '', $this->core_alias)) == '') {
         $this->core_alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     // Not Null sanity check
     if (empty($this->core_images)) {
         $this->core_images = '{}';
     }
     if (empty($this->core_urls)) {
         $this->core_urls = '{}';
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->core_publish_down > $this->_db->getNullDate() && $this->core_publish_down < $this->core_publish_up) {
         // Swap the dates.
         $temp = $this->core_publish_up;
         $this->core_publish_up = $this->core_publish_down;
         $this->core_publish_down = $temp;
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string
     if (!empty($this->core_metakey)) {
         // Only process if not empty
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = StringHelper::str_ireplace($bad_characters, "", $this->core_metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->core_metakey = implode(", ", $clean_keys);
     }
     return true;
 }
Пример #12
0
 /**
  * Returns an array of all components with configuration options.
  * Optionally return only those components for which the current user has 'core.manage' rights.
  *
  * @param   boolean  $authCheck  True to restrict to components where current user has 'core.manage' rights.
  *
  * @return  array
  *
  * @since   3.0
  */
 public static function getComponentsWithConfig($authCheck = true)
 {
     $result = array();
     $components = self::getAllComponents();
     $user = JFactory::getUser();
     // Remove com_config from the array as that may have weird side effects
     $components = array_diff($components, array('com_config'));
     foreach ($components as $component) {
         if (self::hasComponentConfig($component) && (!$authCheck || $user->authorise('core.manage', $component))) {
             self::loadLanguageForComponent($component);
             $result[$component] = JApplicationHelper::stringURLSafe(JText::_($component)) . '_' . $component;
         }
     }
     asort($result);
     return array_keys($result);
 }
Пример #13
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;
 }
Пример #14
0
 /**
  * Method to perform sanity checks on the JTable instance properties to ensure
  * they are safe to store in the database.  Child classes should override this
  * method to make sure the data they are storing in the database is safe and
  * as expected before storage.
  *
  * @return  boolean  True if the instance is sane and able to be stored in the database.
  *
  * @since   2.5
  */
 public function check()
 {
     if (trim($this->alias) == '') {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     // Check the end date is not earlier than start up.
     if ($this->d2 > $this->_db->getNullDate() && $this->d2 < $this->d1) {
         // Swap the dates.
         $temp = $this->d1;
         $this->d1 = $this->d2;
         $this->d2 = $temp;
     }
     return true;
 }
Пример #15
0
 /**
  * Overloaded check function
  *
  * @return  boolean
  *
  * @see     JTable::check
  * @since   1.5
  */
 public function check()
 {
     try {
         parent::check();
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Set name
     $this->name = htmlspecialchars_decode($this->name, ENT_QUOTES);
     // Set alias
     if (trim($this->alias) == '') {
         $this->alias = $this->name;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
         $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
         return false;
     }
     // Set ordering
     if ($this->state < 0) {
         // Set ordering to 0 if state is archived or trashed
         $this->ordering = 0;
     } elseif (empty($this->ordering)) {
         // Set ordering to last if ordering was 0
         $this->ordering = self::getNextOrder($this->_db->quoteName('catid') . '=' . $this->_db->quote($this->catid) . ' AND state>=0');
     }
     if (empty($this->publish_up)) {
         $this->publish_up = $this->getDbo()->getNullDate();
     }
     if (empty($this->publish_down)) {
         $this->publish_down = $this->getDbo()->getNullDate();
     }
     if (empty($this->modified)) {
         $this->modified = $this->getDbo()->getNullDate();
     }
     return true;
 }
Пример #16
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     if (trim($this->title) == '') {
         $this->setError(JText::_('COM_CONTENT_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     if (trim($this->alias) == '') {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     if (trim(str_replace('&nbsp;', '', $this->fulltext)) == '') {
         $this->fulltext = '';
     }
     /**
      * Ensure any new items have compulsory fields set. This is needed for things like
      * frontend editing where we don't show all the fields or using some kind of API
      */
     if (!$this->id) {
         // Images can be an empty json string
         if (!isset($this->images)) {
             $this->images = '{}';
         }
         // URLs can be an empty json string
         if (!isset($this->urls)) {
             $this->urls = '{}';
         }
         // Attributes (article params) can be an empty json string
         if (!isset($this->attribs)) {
             $this->attribs = '{}';
         }
         // Metadata can be an empty json string
         if (!isset($this->metadata)) {
             $this->metadata = '{}';
         }
         // If we don't have any access rules set at this point just use an empty JAccessRules class
         if (!$this->getRules()) {
             $rules = $this->getDefaultAssetValues('com_content');
             $this->setRules($rules);
         }
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
         // Swap the dates.
         $temp = $this->publish_up;
         $this->publish_up = $this->publish_down;
         $this->publish_down = $temp;
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string
     if (!empty($this->metakey)) {
         // Only process if not empty
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     return true;
 }
Пример #17
0
 /**
  * This method transliterates a string into an URL
  * safe string or returns a URL safe UTF-8 string
  * based on the global configuration
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   11.1
  * @deprecated  4.0  Use JApplicationHelper::stringURLSafe instead
  */
 public static function stringURLSafe($string)
 {
     return JApplicationHelper::stringURLSafe($string);
 }
Пример #18
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success, false on failure
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     if (trim($this->slug) == '') {
         $this->slug = $this->title;
     }
     if (version_compare(JVERSION, '3.0', 'ge')) {
         $this->slug = JApplicationHelper::stringURLSafe($this->slug);
     } else {
         $this->slug = JFactory::getApplication()->stringURLSafe($this->slug);
     }
     if (trim(str_replace('-', '', $this->slug)) == '') {
         $this->slug = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     return true;
 }
Пример #19
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param   object $table
  *
  * @throws Exception
  *
  * @since    1.6
  */
 protected function prepareTable(&$table, $data)
 {
     $userId = JFactory::getUser()->get("id");
     if (!$table->get("id")) {
         // Get maximum order number
         // Set ordering to the last item if not set
         if (!$table->get("ordering")) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select("MAX(ordering)")->from($db->quoteName("#__crowdf_projects"));
             $db->setQuery($query, 0, 1);
             $max = $db->loadResult();
             $table->set("ordering", $max + 1);
         }
         // Set published
         $table->set("published", 0);
         // Set user ID
         $table->set("user_id", $userId);
     } else {
         if ($userId != $table->get("user_id")) {
             throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_INVALID_USER"));
         }
     }
     // If an alias does not exist, I will generate the new one using the title.
     if (!$table->get("alias")) {
         $table->set("alias", $table->get("title"));
     }
     $table->set("alias", JApplicationHelper::stringURLSafe($table->get("alias")));
 }
Пример #20
0
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return  boolean  True on success.
  *
  * @since   1.5
  */
 public function check()
 {
     if (JFilterInput::checkAttribute(array('href', $this->url))) {
         $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_PROVIDE_URL'));
         return false;
     }
     // check for valid name
     if (trim($this->title) == '') {
         $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_TITLE'));
         return false;
     }
     // Check for existing name
     $db = $this->getDbo();
     $query = $db->getQuery(true)->select($db->quoteName('id'))->from($db->quoteName('#__weblinks'))->where($db->quoteName('title') . ' = ' . $db->quote($this->title))->where($db->quoteName('catid') . ' = ' . (int) $this->catid);
     $db->setQuery($query);
     $xid = (int) $db->loadResult();
     if ($xid && $xid != (int) $this->id) {
         $this->setError(JText::_('COM_WEBLINKS_ERR_TABLES_NAME'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ($this->publish_down > $db->getNullDate() && $this->publish_down < $this->publish_up) {
         $this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
         return false;
     }
     /*
      * Clean up keywords -- eliminate extra spaces between phrases
      * and cr (\r) and lf (\n) characters from string
      */
     if (!empty($this->metakey)) {
         // Array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             // Ignore blank keywords
             if (trim($key)) {
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     return true;
 }
Пример #21
0
 /**
  * Prepare and sanitise the table data prior to saving.
  *
  * @param   JTable  $table  A reference to a JTable object.
  *
  * @return  void
  *
  * @since   1.6
  */
 protected function prepareTable($table)
 {
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     $table->title = htmlspecialchars_decode($table->title, ENT_QUOTES);
     $table->alias = JApplicationHelper::stringURLSafe($table->alias);
     if (empty($table->alias)) {
         $table->alias = JApplicationHelper::stringURLSafe($table->title);
     }
     if (empty($table->id)) {
         // Set the values
         // Set ordering to the last item if not set
         if (empty($table->ordering)) {
             $db = $this->getDbo();
             $query = $db->getQuery(true)->select('MAX(ordering)')->from($db->quoteName('#__htraininglogs'));
             $db->setQuery($query);
             $max = $db->loadResult();
             $table->ordering = $max + 1;
         } else {
             // Set the values
             $table->modified = $date->toSql();
             $table->modified_by = $user->id;
         }
     }
     // Increment the htraininglog version number.
     $table->version++;
 }
Пример #22
0
 /**
  * Prepare project images before saving.
  *
  * @param   object $table
  * @param   array  $data
  *
  * @throws Exception
  *
  * @since    1.6
  */
 protected function prepareTableData($table, $data)
 {
     // Set order value
     if (!$table->get("id") and !$table->get("ordering")) {
         $db = $this->getDbo();
         $query = $db->getQuery(true);
         $query->select("MAX(ordering)")->from($db->quoteName("#__crowdf_projects"));
         $db->setQuery($query, 0, 1);
         $max = $db->loadResult();
         $table->set("ordering", $max + 1);
     }
     // Prepare image.
     if (!empty($data["image"])) {
         // Delete old image if I upload a new one
         if (!empty($table->image)) {
             $params = JComponentHelper::getParams($this->option);
             /** @var  $params Joomla\Registry\Registry */
             $imagesFolder = $params->get("images_directory", "images/crowdfunding");
             // Remove an image from the filesystem
             $fileImage = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $imagesFolder . DIRECTORY_SEPARATOR . $table->image);
             $fileSmall = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $imagesFolder . DIRECTORY_SEPARATOR . $table->image_small);
             $fileSquare = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $imagesFolder . DIRECTORY_SEPARATOR . $table->image_square);
             if (is_file($fileImage)) {
                 JFile::delete($fileImage);
             }
             if (is_file($fileSmall)) {
                 JFile::delete($fileSmall);
             }
             if (is_file($fileSquare)) {
                 JFile::delete($fileSquare);
             }
         }
         $table->set("image", $data["image"]);
         $table->set("image_small", $data["image_small"]);
         $table->set("image_square", $data["image_square"]);
     }
     // Prepare pitch image.
     if (!empty($data["pitch_image"])) {
         // Delete old image if I upload a new one
         if (!empty($table->pitch_image)) {
             $params = JComponentHelper::getParams($this->option);
             $imagesFolder = $params->get("images_directory", "images/crowdfunding");
             // Remove an image from the filesystem
             $pitchImage = JPath::clean(JPATH_ROOT . DIRECTORY_SEPARATOR . $imagesFolder . DIRECTORY_SEPARATOR . $table->pitch_image);
             if (is_file($pitchImage)) {
                 JFile::delete($pitchImage);
             }
         }
         $table->set("pitch_image", $data["pitch_image"]);
     }
     // If an alias does not exist, I will generate the new one using the title.
     if (!$table->alias) {
         $table->alias = $table->title;
     }
     $table->alias = JApplicationHelper::stringURLSafe($table->alias);
     // Prepare funding duration
     $durationType = JArrayHelper::getValue($data, "duration_type");
     $fundingStart = JArrayHelper::getValue($data, "funding_start");
     $fundingEnd = JArrayHelper::getValue($data, "funding_end");
     $fundingDays = JArrayHelper::getValue($data, "funding_days");
     jimport("itprism.validator.date");
     // Prepare funding start date.
     $fundingStartValidator = new ITPrismValidatorDate($fundingStart);
     if (!$fundingStartValidator->isValid()) {
         $table->funding_start = "0000-00-00";
     } else {
         $date = new JDate($fundingStart);
         $table->funding_start = $date->toSql();
     }
     switch ($durationType) {
         case "days":
             // Set funding day.
             $table->funding_days = $fundingDays;
             // Calculate end date
             $fundingStartValidator = new ITPrismValidatorDate($table->funding_start);
             if (!$fundingStartValidator->isValid()) {
                 $table->funding_end = "0000-00-00";
             } else {
                 $fundingStartDate = new CrowdFundingDate($table->funding_start);
                 $fundingEndDate = $fundingStartDate->calculateEndDate($table->funding_days);
                 $table->funding_end = $fundingEndDate->toSql();
             }
             break;
         case "date":
             $fundingEndValidator = new ITPrismValidatorDate($fundingEnd);
             if (!$fundingEndValidator->isValid()) {
                 throw new Exception(JText::_("COM_CROWDFUNDING_ERROR_INVALID_DATE"));
             }
             $date = new JDate($fundingEnd);
             $table->funding_days = 0;
             $table->funding_end = $date->toSql();
             break;
         default:
             $table->funding_days = 0;
             $table->funding_end = "0000-00-00";
             break;
     }
 }
Пример #23
0
 /**
  * Scan a bleeding edge category
  *
  * @param   Categories  $category  The category to scan
  *
  * @return  void
  */
 public function scanCategory(Categories $category)
 {
     $this->setCategory($category);
     // Can't proceed without a category
     if (empty($this->category)) {
         return;
     }
     // Can't proceed without a folder
     if (empty($this->folder)) {
         return;
     }
     // Can't proceed if it's not a bleedingedge category
     if ($this->category->type != 'bleedingedge') {
         return;
     }
     // Check for possible use of Amazon S3
     $potentialPrefix = substr($this->category->directory, 0, 5);
     $potentialPrefix = strtolower($potentialPrefix);
     $useS3 = $potentialPrefix == 's3://';
     \JLoader::import('joomla.filesystem.folder');
     $known_folders = array();
     // Make sure published releases do exist
     if (!empty($category->releases)) {
         foreach ($category->releases as $release) {
             if (!$release->published) {
                 continue;
             }
             $mustScanFolder = true;
             $folder = null;
             if ($useS3) {
                 $folder = $this->folder . '/' . $release->version;
                 $known_folders[] = $release->version;
             } else {
                 $folderName = $this->getReleaseFolder($this->folder, $release->version, $release->alias, $release->maturity);
                 if ($folderName === false) {
                     $mustScanFolder = false;
                 } else {
                     $known_folders[] = $folderName;
                     $folder = $this->folder . '/' . $folderName;
                 }
             }
             $exists = false;
             if ($mustScanFolder) {
                 if ($useS3) {
                     $check = substr($folder, 5);
                     $s3 = AmazonS3::getInstance();
                     $items = $s3->getBucket('', $check . '/');
                     $exists = !empty($items);
                 } else {
                     $exists = \JFolder::exists($folder);
                 }
             }
             if (!$exists) {
                 $release->published = 0;
                 $tmp = $release->tmpInstance();
                 $tmp->load($release->id);
                 $tmp->save($release);
             } else {
                 $tmpRelease = $release->tmpInstance();
                 $tmpRelease->bind($release);
                 $this->checkFiles($tmpRelease);
             }
         }
         /** @var Collection $category->releases */
         $first_release = $category->releases->first();
     } else {
         $first_release = null;
     }
     \JLoader::import('joomla.filesystem.file');
     $first_changelog = array();
     /** @var Releases $first_release */
     if (is_object($first_release)) {
         $changelog = $this->folder . '/' . $first_release->alias . '/CHANGELOG';
         $hasChangelog = false;
         if ($useS3) {
             $s3 = AmazonS3::getInstance();
             $response = $s3->getObject(substr($changelog, 5));
             $hasChangelog = $response !== false;
             if ($hasChangelog) {
                 $first_changelog = $response;
             }
         } else {
             if (\JFile::exists($changelog)) {
                 $hasChangelog = true;
                 $first_changelog = @file_get_contents($changelog);
             }
         }
         if ($hasChangelog) {
             if (!empty($first_changelog)) {
                 $first_changelog = explode("\n", str_replace("\r\n", "\n", $first_changelog));
             } else {
                 $first_changelog = array();
             }
         }
     }
     // Get a list of all folders
     if ($useS3) {
         $allFolders = array();
         $everything = $this->_listS3Contents($this->folder);
         $dirLength = strlen($this->folder) - 5;
         if (count($everything)) {
             foreach ($everything as $path => $info) {
                 if (!array_key_exists('size', $info) && substr($path, -1) == '/') {
                     if (substr($path, 0, $dirLength) == substr($this->folder, 5)) {
                         $path = substr($path, $dirLength);
                     }
                     $path = trim($path, '/');
                     $allFolders[] = $path;
                 }
             }
         }
     } else {
         $allFolders = \JFolder::folders($this->folder);
     }
     if (!empty($allFolders)) {
         foreach ($allFolders as $folder) {
             if (!in_array($folder, $known_folders)) {
                 // Create a new entry
                 $notes = '';
                 $changelog = $this->folder . '/' . $folder . '/' . 'CHANGELOG';
                 $hasChangelog = false;
                 $this_changelog = '';
                 if ($useS3) {
                     $s3 = AmazonS3::getInstance();
                     $response = $s3->getObject(substr($changelog, 5));
                     $hasChangelog = $response !== false;
                     if ($hasChangelog) {
                         $this_changelog = $response;
                     }
                 } else {
                     if (\JFile::exists($changelog)) {
                         $hasChangelog = true;
                         $this_changelog = @file_get_contents($changelog);
                     }
                 }
                 if ($hasChangelog) {
                     if (!empty($this_changelog)) {
                         $notes = $this->coloriseChangelog($this_changelog, $first_changelog);
                     }
                 } else {
                     $this_changelog = '';
                 }
                 \JLoader::import('joomla.utilities.date');
                 $jNow = new \JDate();
                 $alias = \JApplicationHelper::stringURLSafe($folder);
                 $data = array('id' => 0, 'category_id' => $this->category_id, 'version' => $folder, 'alias' => $alias, 'maturity' => 'alpha', 'description' => '', 'notes' => $notes, 'groups' => $this->category->groups, 'access' => $this->category->access, 'published' => 1, 'created' => $jNow->toSql());
                 // Before saving the release, call the onNewARSBleedingEdgeRelease()
                 // event of ars plugins so that they have the chance to modify
                 // this information.
                 // -- Load plugins
                 \JLoader::import('joomla.plugin.helper');
                 \JPluginHelper::importPlugin('ars');
                 // -- Setup information data
                 $infoData = array('folder' => $folder, 'category_id' => $this->category_id, 'category' => $this->category, 'has_changelog' => $hasChangelog, 'changelog_file' => $changelog, 'changelog' => $this_changelog, 'first_changelog' => $first_changelog);
                 // -- Trigger the plugin event
                 $app = \JFactory::getApplication();
                 $jResponse = $app->triggerEvent('onNewARSBleedingEdgeRelease', array($infoData, $data));
                 // -- Merge response
                 if (is_array($jResponse)) {
                     foreach ($jResponse as $response) {
                         if (is_array($response)) {
                             $data = array_merge($data, $response);
                         }
                     }
                 }
                 // -- Create the BE release
                 /** @var Releases $table */
                 $table = $this->container->factory->model('Releases')->tmpInstance();
                 try {
                     $table->create($data);
                     $this->checkFiles($table);
                 } catch (\Exception $e) {
                 }
             }
         }
     }
 }
Пример #24
0
 /**
  * Prepare and sanitise the table prior to saving.
  * @since    1.6
  */
 protected function prepareTable(&$table)
 {
     // get maximum order number
     if (empty($table->id)) {
         // Set ordering to the last item if not set
         if (empty($table->ordering)) {
             $db = $this->getDbo();
             $query = $db->getQuery(true);
             $query->select("MAX(a.ordering)")->from($db->quoteName("#__uideas_items", "a"));
             $db->setQuery($query, 0, 1);
             $max = $db->loadResult();
             $table->ordering = $max + 1;
         }
     }
     // Fix magic quotes
     if (get_magic_quotes_gpc()) {
         $table->alias = stripcslashes($table->title);
         $table->description = stripcslashes($table->description);
     }
     // If does not exist alias, I will generate the new one from the title
     if (!$table->alias) {
         $table->alias = $table->title;
     }
     $table->alias = JApplicationHelper::stringURLSafe($table->alias);
 }
Пример #25
0
 /**
  * Override check function
  *
  * @return  boolean
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     // Check for a title.
     if (trim($this->title) == '') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_CATEGORY'));
         return false;
     }
     $this->alias = trim($this->alias);
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     return true;
 }
Пример #26
0
 /**
  * 
  * @param type $string
  * @return string
  */
 public static function getAlias($string)
 {
     $string = JText::_($string);
     $string = JApplicationHelper::stringURLSafe($string);
     return $string;
 }
 /**
  * Overloaded check function
  *
  * @return boolean
  *
  * @see   JTable::check
  * @since 1.7.0
  */
 public function check()
 {
     if (JFilterInput::checkAttribute(['href', $this->webpage])) {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_PROVIDE_VALID_URL'));
         return false;
     }
     // Check for http, https, ftp on webpage
     if (strlen($this->webpage) > 0 && stripos($this->webpage, 'http://') === false && stripos($this->webpage, 'https://') === false && stripos($this->webpage, 'ftp://') === false) {
         $this->webpage = 'http://' . $this->webpage;
     }
     /** check for valid name */
     if (trim($this->name) == '') {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_PROVIDE_VALID_NAME'));
         return false;
     }
     /** check for existing name */
     $query = 'SELECT id FROM #__churchdirectory_familyunit WHERE name = ' . $this->_db->q($this->name);
     $this->_db->setQuery($query);
     $xid = intval($this->_db->loadResult());
     if ($xid && $xid != intval($this->id)) {
         $this->setError(JText::_('COM_CHURCHDIRECTORY_WARNING_SAME_NAME'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->name;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if (intval($this->publish_down) > 0 && $this->publish_down < $this->publish_up) {
         // Swap the dates.
         $temp = $this->publish_up;
         $this->publish_up = $this->publish_down;
         $this->publish_down = $temp;
     }
     return true;
 }
Пример #28
0
 /**
  * Overloaded check function
  *
  * @return  boolean  True on success
  *
  * @see     JTable::check()
  * @since   11.1
  */
 public function check()
 {
     // Check for a title.
     if (trim($this->title) == '') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MUSTCONTAIN_A_TITLE_MENUITEM'));
         return false;
     }
     // Set correct component id to ensure proper 404 messages with separator items
     if ($this->type == "separator") {
         $this->component_id = 0;
     }
     // If the alias field is empty, set it to the title.
     $this->alias = trim($this->alias);
     if (empty($this->alias) && ($this->type != 'alias' && $this->type != 'url')) {
         $this->alias = $this->title;
     }
     // Check for a path.
     if (trim($this->path) == '') {
         $this->path = $this->alias;
     }
     // Check for params.
     if (trim($this->params) == '') {
         $this->params = '{}';
     }
     // Check for img.
     if (trim($this->img) == '') {
         $this->img = ' ';
     }
     // Make the alias URL safe.
     $this->alias = JApplicationHelper::stringURLSafe($this->alias);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
     }
     // Cast the home property to an int for checking.
     $this->home = (int) $this->home;
     // Verify that a first level menu item alias is not 'component'.
     if ($this->parent_id == 1 && $this->alias == 'component') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_COMPONENT'));
         return false;
     }
     // Verify that a first level menu item alias is not the name of a folder.
     jimport('joomla.filesystem.folder');
     if ($this->parent_id == 1 && in_array($this->alias, JFolder::folders(JPATH_ROOT))) {
         $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_MENU_ROOT_ALIAS_FOLDER', $this->alias, $this->alias));
         return false;
     }
     // Verify that the home item a component.
     if ($this->home && $this->type != 'component') {
         $this->setError(JText::_('JLIB_DATABASE_ERROR_MENU_HOME_NOT_COMPONENT'));
         return false;
     }
     return true;
 }
Пример #29
0
 /**
  * Overloaded check method to ensure data integrity.
  *
  * @return  boolean  True on success.
  *
  * @since   3.1
  * @throws  UnexpectedValueException
  */
 public function check()
 {
     try {
         parent::check();
     } catch (\Exception $e) {
         $this->setError($e->getMessage());
         return false;
     }
     // Check for valid name.
     if (trim($this->title) == '') {
         throw new UnexpectedValueException(sprintf('The title is empty'));
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = JApplicationHelper::stringURLSafe($this->alias, $this->language);
     if (trim(str_replace('-', '', $this->alias)) == '') {
         $this->alias = JFactory::getDate()->format("Y-m-d-H-i-s");
     }
     // Check the publish down date is not earlier than publish up.
     if ((int) $this->publish_down > 0 && $this->publish_down < $this->publish_up) {
         throw new UnexpectedValueException(sprintf('End publish date is before start publish date.'));
     }
     // Clean up keywords -- eliminate extra spaces between phrases
     // and cr (\r) and lf (\n) characters from string
     if (!empty($this->metakey)) {
         // Only process if not empty
         // Define array of characters to remove
         $bad_characters = array("\n", "\r", "\"", "<", ">");
         // Remove bad characters
         $after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
         // Create array using commas as delimiter
         $keys = explode(',', $after_clean);
         $clean_keys = array();
         foreach ($keys as $key) {
             if (trim($key)) {
                 // Ignore blank keywords
                 $clean_keys[] = trim($key);
             }
         }
         // Put array back together delimited by ", "
         $this->metakey = implode(", ", $clean_keys);
     }
     // Clean up description -- eliminate quotes and <> brackets
     if (!empty($this->metadesc)) {
         // Only process if not empty
         $bad_characters = array("\"", "<", ">");
         $this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
     }
     // Not Null sanity check
     $date = JFactory::getDate();
     if (empty($this->params)) {
         $this->params = '{}';
     }
     if (empty($this->metadesc)) {
         $this->metadesc = '';
     }
     if (empty($this->metakey)) {
         $this->metakey = '';
     }
     if (empty($this->metadata)) {
         $this->metadata = '{}';
     }
     if (empty($this->urls)) {
         $this->urls = '{}';
     }
     if (empty($this->images)) {
         $this->images = '{}';
     }
     if (!(int) $this->checked_out_time) {
         $this->checked_out_time = $date->toSql();
     }
     if (!(int) $this->modified_time) {
         $this->modified_time = $date->toSql();
     }
     if (!(int) $this->modified_time) {
         $this->modified_time = $date->toSql();
     }
     if (!(int) $this->publish_up) {
         $this->publish_up = $date->toSql();
     }
     if (!(int) $this->publish_down) {
         $this->publish_down = $date->toSql();
     }
     return true;
 }
Пример #30
0
 /**
  * Prepare and sanitise the table prior to saving.
  *
  * @param UserIdeasTableItem $table
  *
  * @since    1.6
  */
 protected function prepareTable($table)
 {
     // get maximum order number
     if (!$table->get('id') and !$table->get('ordering')) {
         // Set ordering to the last item if not set
         $db = JFactory::getDbo();
         $query = $db->getQuery(true);
         $query->select('MAX(a.ordering)')->from($db->quoteName('#__uideas_items', 'a'))->where('a.catid = ' . (int) $table->catid);
         $db->setQuery($query, 0, 1);
         $max = (int) $db->loadResult();
         $table->set('ordering', $max + 1);
     }
     // Fix magic quotes.
     if (get_magic_quotes_gpc()) {
         $table->set('title', stripcslashes($table->get('title')));
         $table->set('description', stripcslashes($table->get('description')));
     }
     // If does not exist alias, I will generate the new one from the title
     if (!$table->get('alias')) {
         $table->set('alias', $table->get('title'));
     }
     $table->set('alias', JApplicationHelper::stringURLSafe($table->get('alias')));
 }