/**
  * Constructor
  *
  * @param   string  $basepath       Base Path of the adapters
  * @param   string  $classprefix    Class prefix of adapters
  * @param   string  $adapterfolder  Name of folder to append to base path
  *
  * @since   11.1
  */
 public function __construct($basepath, $classprefix = null, $adapterfolder = null)
 {
     $this->_basepath = $basepath;
     $this->_classprefix = $classprefix ? $classprefix : 'J';
     $this->_adapterfolder = $adapterfolder ? $adapterfolder : 'adapters';
     $this->_db = Factory::getDBO();
 }
 /**
  * Constructor.
  *
  * @param   array  &$options  Log object options.
  *
  * @since   11.1
  */
 public function __construct(array &$options)
 {
     // Call the parent constructor.
     parent::__construct($options);
     // If both the database object and driver options are empty we want to use the system database connection.
     if (empty($this->options['db_driver'])) {
         $this->dbo = Factory::getDBO();
         $this->driver = null;
         $this->host = null;
         $this->user = null;
         $this->password = null;
         $this->database = null;
         $this->prefix = null;
     } else {
         $this->dbo = null;
         $this->driver = empty($this->options['db_driver']) ? 'mysqli' : $this->options['db_driver'];
         $this->host = empty($this->options['db_host']) ? '127.0.0.1' : $this->options['db_host'];
         $this->user = empty($this->options['db_user']) ? 'root' : $this->options['db_user'];
         $this->password = empty($this->options['db_pass']) ? '' : $this->options['db_pass'];
         $this->database = empty($this->options['db_database']) ? 'logging' : $this->options['db_database'];
         $this->prefix = empty($this->options['db_prefix']) ? 'jos_' : $this->options['db_prefix'];
     }
     // The table name is independent of how we arrived at the connection object.
     $this->table = empty($this->options['db_table']) ? '#__log_entries' : $this->options['db_table'];
 }
 /**
  * Method to get the custom field options.
  * Use the query attribute to supply a query to generate the list.
  *
  * @return  array  The field option objects.
  *
  * @since   11.1
  */
 protected function getOptions()
 {
     $options = array();
     // Initialize some field attributes.
     $key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
     $value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
     $translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
     $query = (string) $this->element['query'];
     // Get the database object.
     $db = Factory::getDBO();
     // Set the query and get the result list.
     $db->setQuery($query);
     $items = $db->loadObjectlist();
     // Build the field options.
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($translate == true) {
                 $options[] = Html::_('select.option', $item->{$key}, JText::_($item->{$value}));
             } else {
                 $options[] = Html::_('select.option', $item->{$key}, $item->{$value});
             }
         }
     }
     // Merge any additional options in the XML definition.
     $options = array_merge(parent::getOptions(), $options);
     return $options;
 }
 /**
  * Constructor
  *
  * @param   JAdapter         $parent   Parent object
  * @param   JDatabaseDriver  $db       Database object
  * @param   array            $options  Configuration Options
  *
  * @since   11.1
  */
 public function __construct(Adapter $parent, Driver $db, array $options = array())
 {
     // Set the properties from the options array that is passed in
     $this->setProperties($options);
     // Set the parent and db in case $options for some reason overrides it.
     $this->parent = $parent;
     // Pull in the global dbo in case something happened to it.
     $this->db = $db ?: Factory::getDBO();
 }
 /**
  * Method to test the email address and optionally check for uniqueness.
  *
  * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  * @param   mixed             $value    The form field value to validate.
  * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  *                                      For example if the field has name="foo" and the group value is set to "bar" then the
  *                                      full field name would end up being "bar[foo]".
  * @param   JRegistry         $input    An optional JRegistry object with the entire data set to validate against the entire form.
  * @param   JForm             $form     The form object for which the field is being tested.
  *
  * @return  boolean  True if the value is valid, false otherwise.
  *
  * @since   11.1
  */
 public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
 {
     // If the field is empty and not required, the field is valid.
     $required = (string) $element['required'] == 'true' || (string) $element['required'] == 'required';
     if (!$required && empty($value)) {
         return true;
     }
     // If the tld attribute is present, change the regular expression to require at least 2 characters for it.
     $tld = (string) $element['tld'] == 'tld' || (string) $element['tld'] == 'required';
     if ($tld) {
         $this->regex = '^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\\.[a-zA-Z0-9-]{2,})$';
     }
     // Determine if the multiple attribute is present
     $multiple = (string) $element['multiple'] == 'true' || (string) $element['multiple'] == 'multiple';
     if ($multiple) {
         $values = explode(',', $value);
     }
     if (!$multiple) {
         // Test the value against the regular expression.
         if (!parent::test($element, $value, $group, $input, $form)) {
             return false;
         }
     } else {
         foreach ($values as $value) {
             // Test the value against the regular expression.
             if (!parent::test($element, $value, $group, $input, $form)) {
                 return false;
             }
         }
     }
     // Check if we should test for uniqueness. This only can be used if multiple is not true
     $unique = (string) $element['unique'] == 'true' || (string) $element['unique'] == 'unique';
     if ($unique && !$multiple) {
         // Get the database object and a new query object.
         $db = Factory::getDBO();
         $query = $db->getQuery(true);
         // Build the query.
         $query->select('COUNT(*)');
         $query->from('#__users');
         $query->where('email = ' . $db->quote($value));
         // Get the extra field check attribute.
         $userId = $form instanceof Form ? $form->getValue('id') : '';
         $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
         // Set and query the database.
         $db->setQuery($query);
         $duplicate = (bool) $db->loadResult();
         if ($duplicate) {
             return false;
         }
     }
     return true;
 }
 /**
  * Get a list of users.
  *
  * @return  string
  *
  * @since   11.4
  */
 public static function userlist()
 {
     // Get the database object and a new query object.
     $db = Factory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('a.id AS value, a.name AS text');
     $query->from('#__users AS a');
     $query->where('a.block = 0');
     $query->order('a.name');
     // Set the query and load the options.
     $db->setQuery($query);
     $items = $db->loadObjectList();
     return $items;
 }
 /**
  * Method to test the username for uniqueness.
  *
  * @param   SimpleXMLElement  $element  The SimpleXMLElement object representing the <field /> tag for the form field object.
  * @param   mixed             $value    The form field value to validate.
  * @param   string            $group    The field name group control value. This acts as as an array container for the field.
  *                                      For example if the field has name="foo" and the group value is set to "bar" then the
  *                                      full field name would end up being "bar[foo]".
  * @param   JRegistry         $input    An optional JRegistry object with the entire data set to validate against the entire form.
  * @param   JForm             $form     The form object for which the field is being tested.
  *
  * @return  boolean  True if the value is valid, false otherwise.
  *
  * @since   11.1
  */
 public function test(SimpleXMLElement $element, $value, $group = null, Registry $input = null, Form $form = null)
 {
     // Get the database object and a new query object.
     $db = Factory::getDBO();
     $query = $db->getQuery(true);
     // Build the query.
     $query->select('COUNT(*)');
     $query->from('#__users');
     $query->where('username = '******'id') : '';
     $query->where($db->quoteName('id') . ' <> ' . (int) $userId);
     // Set and query the database.
     $db->setQuery($query);
     $duplicate = (bool) $db->loadResult();
     if ($duplicate) {
         return false;
     }
     return true;
 }
 /**
  * Get a list of the user groups.
  *
  * @return  array
  *
  * @since   11.1
  */
 protected function getUserGroups()
 {
     $db = Factory::getDBO();
     $query = $db->getQuery(true);
     $query->select('a.id AS value, a.title AS text, COUNT(DISTINCT b.id) AS level, a.parent_id')->from('#__usergroups AS a')->leftJoin($db->quoteName('#__usergroups') . ' AS b ON a.lft > b.lft AND a.rgt < b.rgt')->group('a.id, a.title, a.lft, a.rgt, a.parent_id')->order('a.lft ASC');
     $db->setQuery($query);
     $options = $db->loadObjectList();
     return $options;
 }
 /**
  * Get the user groups
  *
  * @return  array  Array of user groups
  *
  * @since   11.1
  */
 protected static function _getUserGroups()
 {
     // Get a database object.
     $db = Factory::getDBO();
     // Get the user groups from the database.
     $db->setQuery('SELECT a.id AS value, a.title AS text, b.id as parent' . ' FROM #__usergroups AS a' . ' LEFT JOIN #__usergroups AS b ON a.lft >= b.lft AND a.rgt <= b.rgt' . ' ORDER BY a.lft ASC, b.lft ASC');
     $result = $db->loadObjectList();
     $options = array();
     // Pre-compute additional values.
     foreach ($result as $option) {
         $end = end($options);
         if ($end === false || $end->value != $option->value) {
             $end = $option;
             $end->level = 0;
             $options[] = $end;
         } else {
             $end->level++;
         }
         $end->identities[] = $option->parent;
     }
     return $options;
 }
 /**
  * Get available languages
  *
  * @param   string  $key  Array key
  *
  * @return  array  An array of published languages
  *
  * @since   11.1
  */
 public static function getLanguages($key = 'default')
 {
     static $languages;
     if (empty($languages)) {
         // Installation uses available languages
         if (Factory::getApplication()->getClientId() == 2) {
             $languages[$key] = array();
             $knownLangs = Language::getKnownLanguages(JPATH_BASE);
             foreach ($knownLangs as $metadata) {
                 // Take off 3 letters iso code languages as they can't match browsers' languages and default them to en
                 $obj = new stdClass();
                 $obj->lang_code = $metadata['tag'];
                 $languages[$key][] = $obj;
             }
         } else {
             $cache = Factory::getCache('com_languages', '');
             if (!($languages = $cache->get('languages'))) {
                 $db = Factory::getDBO();
                 $query = $db->getQuery(true);
                 $query->select('*')->from('#__languages')->where('published=1')->order('ordering ASC');
                 $db->setQuery($query);
                 $languages['default'] = $db->loadObjectList();
                 $languages['sef'] = array();
                 $languages['lang_code'] = array();
                 if (isset($languages['default'][0])) {
                     foreach ($languages['default'] as $lang) {
                         $languages['sef'][$lang->sef] = $lang;
                         $languages['lang_code'][$lang->lang_code] = $lang;
                     }
                 }
                 $cache->store($languages, 'languages');
             }
         }
     }
     return $languages[$key];
 }
 /**
  * Method to return a list of view levels for which the user is authorised.
  *
  * @param   integer  $userId  Id of the user for which to get the list of authorised view levels.
  *
  * @return  array    List of view levels for which the user is authorised.
  *
  * @since   11.1
  */
 public static function getAuthorisedViewLevels($userId)
 {
     // Get all groups that the user is mapped to recursively.
     $groups = self::getGroupsByUser($userId);
     // Only load the view levels once.
     if (empty(self::$viewLevels)) {
         // Get a database object.
         $db = Factory::getDBO();
         // Build the base query.
         $query = $db->getQuery(true);
         $query->select('id, rules');
         $query->from($query->qn('#__viewlevels'));
         // Set the query for execution.
         $db->setQuery((string) $query);
         // Build the view levels array.
         foreach ($db->loadAssocList() as $level) {
             self::$viewLevels[$level['id']] = (array) json_decode($level['rules']);
         }
     }
     // Initialise the authorised array.
     $authorised = array(1);
     // Find the authorised levels.
     foreach (self::$viewLevels as $level => $rule) {
         foreach ($rule as $id) {
             if ($id < 0 && $id * -1 == $userId) {
                 $authorised[] = $level;
                 break;
             } elseif ($id >= 0 && in_array($id, $groups)) {
                 $authorised[] = $level;
                 break;
             }
         }
     }
     return $authorised;
 }
 /**
  * Method to determine if a row is checked out and therefore uneditable by
  * a user. If the row is checked out by the same user, then it is considered
  * not checked out -- as the user can still edit it.
  *
  * @param   integer  $with     The userid to preform the match with, if an item is checked
  *                             out by this user the function will return false.
  * @param   integer  $against  The userid to perform the match against when the function
  *                             is used as a static function.
  *
  * @return  boolean  True if checked out.
  *
  * @link    http://docs.joomla.org/JTable/isCheckedOut
  * @since   11.1
  */
 public function isCheckedOut($with = 0, $against = null)
 {
     // Handle the non-static case.
     if (isset($this) && $this instanceof Table && is_null($against)) {
         $against = $this->get('checked_out');
     }
     // The item is not checked out or is checked out by the same user.
     if (!$against || $against == $with) {
         return false;
     }
     $db = Factory::getDBO();
     $db->setQuery('SELECT COUNT(userid)' . ' FROM ' . $db->quoteName('#__session') . ' WHERE ' . $db->quoteName('userid') . ' = ' . (int) $against);
     $checkedOut = (bool) $db->loadResult();
     // If a session exists for the user then it is checked out.
     return $checkedOut;
 }
 /**
  * Returns a published state on a grid
  *
  * @param   integer       $value         The state value.
  * @param   integer       $i             The row index
  * @param   string|array  $prefix        An optional task prefix or an array of options
  * @param   boolean       $enabled       An optional setting for access control on the action.
  * @param   string        $checkbox      An optional prefix for checkboxes.
  * @param   string        $publish_up    An optional start publishing date.
  * @param   string        $publish_down  An optional finish publishing date.
  *
  * @return  string  The Html code
  *
  * @see     JHtmlJGrid::state
  * @since   11.1
  */
 public static function published($value, $i, $prefix = '', $enabled = true, $checkbox = 'cb', $publish_up = null, $publish_down = null)
 {
     if (is_array($prefix)) {
         $options = $prefix;
         $enabled = array_key_exists('enabled', $options) ? $options['enabled'] : $enabled;
         $checkbox = array_key_exists('checkbox', $options) ? $options['checkbox'] : $checkbox;
         $prefix = array_key_exists('prefix', $options) ? $options['prefix'] : '';
     }
     $states = array(1 => array('unpublish', 'JPUBLISHED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JPUBLISHED', false, 'publish', 'publish'), 0 => array('publish', 'JUNPUBLISHED', 'JLIB_HTML_PUBLISH_ITEM', 'JUNPUBLISHED', false, 'unpublish', 'unpublish'), 2 => array('unpublish', 'JARCHIVED', 'JLIB_HTML_UNPUBLISH_ITEM', 'JARCHIVED', false, 'archive', 'archive'), -2 => array('publish', 'JTRASHED', 'JLIB_HTML_PUBLISH_ITEM', 'JTRASHED', false, 'trash', 'trash'));
     // Special state for dates
     if ($publish_up || $publish_down) {
         $nullDate = Factory::getDBO()->getNullDate();
         $nowDate = Factory::getDate()->toUnix();
         $tz = new DateTimeZone(Factory::getUser()->getParam('timezone', Factory::getConfig()->get('offset')));
         $publish_up = $publish_up != $nullDate ? Factory::getDate($publish_up, 'UTC')->setTimeZone($tz) : false;
         $publish_down = $publish_down != $nullDate ? Factory::getDate($publish_down, 'UTC')->setTimeZone($tz) : false;
         // Create tip text, only we have publish up or down settings
         $tips = array();
         if ($publish_up) {
             $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_START', $publish_up->format(Date::$format, true));
         }
         if ($publish_down) {
             $tips[] = Text::sprintf('JLIB_HTML_PUBLISHED_FINISHED', $publish_down->format(Date::$format, true));
         }
         $tip = empty($tips) ? false : implode('<br/>', $tips);
         // Add tips and special titles
         foreach ($states as $key => $state) {
             // Create special titles for published items
             if ($key == 1) {
                 $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_ITEM';
                 if ($publish_up > $nullDate && $nowDate < $publish_up->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_PENDING_ITEM';
                     $states[$key][5] = $states[$key][6] = 'pending';
                 }
                 if ($publish_down > $nullDate && $nowDate > $publish_down->toUnix()) {
                     $states[$key][2] = $states[$key][3] = 'JLIB_HTML_PUBLISHED_EXPIRED_ITEM';
                     $states[$key][5] = $states[$key][6] = 'expired';
                 }
             }
             // Add tips to titles
             if ($tip) {
                 $states[$key][1] = Text::_($states[$key][1]);
                 $states[$key][2] = Text::_($states[$key][2]) . '::' . $tip;
                 $states[$key][3] = Text::_($states[$key][3]) . '::' . $tip;
                 $states[$key][4] = true;
             }
         }
         return self::state($states, $value, $i, array('prefix' => $prefix, 'translate' => !$tip), $enabled, true, $checkbox);
     }
     return self::state($states, $value, $i, $prefix, $enabled, true, $checkbox);
 }