/** * Method to get a list of options for a list input. * * @return array An array of JHtml options. * * @since 11.4 */ protected function getOptions() { $folder = $this->element['folder']; if (!empty($folder)) { // Get list of plugins $db = Factory::getDbo(); $query = $db->getQuery(true); $query->select('element AS value, name AS text'); $query->from('#__extensions'); $query->where('folder = ' . $db->q($folder)); $query->where('enabled = 1'); $query->order('ordering, name'); $db->setQuery($query); $options = $db->loadObjectList(); $lang = Factory::getLanguage(); foreach ($options as $i => $item) { $source = JPATH_PLUGINS . '/' . $folder . '/' . $item->value; $extension = 'plg_' . $folder . '_' . $item->value; $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false) || $lang->load($extension . '.sys', $source, null, false, false) || $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false) || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false); $options[$i]->text = Text::_($item->text); } } else { Log::add(Text::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), Log::WARNING, 'jerror'); } // Merge any additional options in the XML definition. $options = array_merge(parent::getOptions(), $options); return $options; }
/** * Return the most recent error message for the database connector. * * @param boolean $showSQL True to display the SQL statement sent to the database as well as the error. * * @return string The error message for the most recent query. * * @since 11.1 * @deprecated 13.3 */ public function stderr($showSQL = false) { Log::add('JDatabase::stderr() is deprecated.', Log::WARNING, 'deprecated'); if ($this->errorNum != 0) { return Text::sprintf('JLIB_DATABASE_ERROR_FUNCTION_FAILED', $this->errorNum, $this->errorMsg) . ($showSQL ? "<br />SQL = <pre>{$this->sql}</pre>" : ''); } else { return Text::_('JLIB_DATABASE_FUNCTION_NOERROR'); } }
/** * Class constructor. * * @param resource $handle The image resource on which to apply the filter. * * @since 11.3 * @throws InvalidArgumentException */ public function __construct($handle) { // Verify that image filter support for PHP is available. if (!function_exists('imagefilter')) { // @codeCoverageIgnoreStart Log::add('The imagefilter function for PHP is not available.', Log::ERROR); throw new RuntimeException('The imagefilter function for PHP is not available.'); // @codeCoverageIgnoreEnd } // Make sure the file handle is valid. if (!is_resource($handle) || get_resource_type($handle) != 'gd') { Log::add('The image handle is invalid for the image filter.', Log::ERROR); throw new InvalidArgumentException('The image handle is invalid for the image filter.'); } $this->handle = $handle; }
/** * Method to load a JUser object by user id number * * @param mixed $id The user id of the user to load * * @return boolean True on success * * @since 11.1 */ public function load($id) { // Create the user table object $table = $this->getTable(); // Load the JUserModel object based on the user id or throw a warning. if (!$table->load($id)) { // Reset to guest user $this->guest = 1; Log::add(Text::sprintf('JLIB_USER_ERROR_UNABLE_TO_LOAD_USER', $id), Log::WARNING, 'jerror'); return false; } /* * Set the user parameters using the default XML file. We might want to * extend this in the future to allow for the ability to have custom * user parameters, but for right now we'll leave it how it is. */ $this->_params->loadString($table->params); // Assuming all is well at this point let's bind the data $this->setProperties($table->getProperties()); // The user is no longer a guest if ($this->id != 0) { $this->guest = 0; } else { $this->guest = 1; } return true; }
/** * Determine if we are using a secure (SSL) connection. * * @return boolean True if using SSL, false if not. * * @since 11.1 * @deprecated 13.3 Use the isSSLConnection method on the application object. */ public function isSSLConnection() { Log::add('JBrowser::isSSLConnection() is deprecated. Use the isSSLConnection method on the application object instead.', Log::WARNING, 'deprecated'); return isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on' || getenv('SSL_PROTOCOL_VERSION'); }
/** * Method to find the loggers to use based on priority and category values. * * @param integer $priority Message priority. * @param string $category Type of entry * * @return array The array of loggers to use for the given priority and category values. * * @since 1.0 */ public function findLoggers($priority, $category) { return parent::findLoggers($priority, $category); }
/** * Static method to get an instance of a JTable class if it can be found in * the table include paths. To add include paths for searching for JTable * classes @see JTable::addIncludePath(). * * @param string $type The type (name) of the JTable class to get an instance of. * @param string $prefix An optional prefix for the table class name. * @param array $config An optional array of configuration values for the JTable object. * * @return mixed A JTable object if found or boolean false if one could not be found. * * @link http://docs.joomla.org/JTable/getInstance * @since 11.1 */ public static function getInstance($type, $prefix = 'JTable', $config = array()) { // Sanitize and prepare the table class name. $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type); $tableClass = $prefix . ucfirst($type); // Only try to load the class if it doesn't already exist. if (!class_exists($tableClass)) { // Search for the class file in the JTable include paths. $path = Path::find(self::addIncludePath(), strtolower($type) . '.php'); if ($path) { // Import the class file. include_once $path; // If we were unable to load the proper class, raise a warning and return false. if (!class_exists($tableClass)) { Log::add(Text::sprintf('JLIB_DATABASE_ERROR_CLASS_NOT_FOUND_IN_FILE', $tableClass), Log::WARNING, 'jerror'); return false; } } else { // If we were unable to find the class file in the JTable include paths, raise a warning and return false. Log::add(Text::sprintf('JLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND', $type), Log::WARNING, 'jerror'); return false; } } // If a database object was passed in the configuration array use it, otherwise get the global one from JFactory. $db = isset($config['dbo']) ? $config['dbo'] : Factory::getDbo(); // Instantiate a new table class and return it. return new $tableClass($db); }
/** * Execute the SQL statement. * * @return mixed A database cursor resource on success, boolean false on failure. * * @since 12.1 * @throws RuntimeException */ public function execute() { $this->connect(); if (!is_resource($this->connection)) { Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'database'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Take a local copy so that we don't modify the original query and cause issues later $sql = $this->replacePrefix((string) $this->sql); if ($this->limit > 0 || $this->offset > 0) { $sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit; } // Increment the query counter. $this->count++; // If debugging is enabled then let's log the query. if ($this->debug) { // Add the query to the object queue. $this->log[] = $sql; Log::add($sql, Log::DEBUG, 'databasequery'); } // Reset the error values. $this->errorNum = 0; $this->errorMsg = ''; // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost. $this->cursor = @mysql_query($sql, $this->connection); // If an error occurred handle it. if (!$this->cursor) { // Check if the server was disconnected. if (!$this->connected()) { try { // Attempt to reconnect. $this->connection = null; $this->connect(); } catch (RuntimeException $e) { // Get the error number and message. $this->errorNum = (int) mysql_errno($this->connection); $this->errorMsg = (string) mysql_error($this->connection) . ' SQL=' . $sql; // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Since we were able to reconnect, run the query again. return $this->execute(); } else { // Get the error number and message. $this->errorNum = (int) mysql_errno($this->connection); $this->errorMsg = (string) mysql_error($this->connection) . ' SQL=' . $sql; // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } } return $this->cursor; }
/** * Utility function to read the folders in a folder. * * @param string $path The path of the folder to read. * @param string $filter A filter for folder names. * @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth. * @param boolean $fullpath True to return the full path to the folders. * @param array $exclude Array with names of folders which should not be shown in the result. * @param array $excludefilter Array with regular expressions matching folders which should not be shown in the result. * * @return array Folders in the given folder. * * @since 11.1 */ protected function _folders($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\\..*')) { $arr = array(); // Check to make sure the path valid and clean $path = $this->_cleanPath($path); // Is the path a folder? if (!is_dir($path)) { Log::add('\\Joomla\\Cache\\Storage\\File::_folders' . Text::sprintf('JLIB_FILESYSTEM_ERROR_PATH_IS_NOT_A_FOLDER', $path), Log::WARNING, 'jerror'); return false; } // Read the source directory if (!($handle = @opendir($path))) { return $arr; } if (count($excludefilter)) { $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/'; } else { $excludefilter_string = ''; } while (($file = readdir($handle)) !== false) { if ($file != '.' && $file != '..' && !in_array($file, $exclude) && (empty($excludefilter_string) || !preg_match($excludefilter_string, $file))) { $dir = $path . '/' . $file; $isDir = is_dir($dir); if ($isDir) { // Removes filtered directories if (preg_match("/{$filter}/", $file)) { if ($fullpath) { $arr[] = $dir; } else { $arr[] = $file; } } if ($recurse) { if (is_int($recurse)) { $arr2 = $this->_folders($dir, $filter, $recurse - 1, $fullpath, $exclude, $excludefilter); } else { $arr2 = $this->_folders($dir, $filter, $recurse, $fullpath, $exclude, $excludefilter); } $arr = array_merge($arr, $arr2); } } } } closedir($handle); return $arr; }
/** * Set transfer mode * * @param integer $mode Integer representation of data transfer mode [1:Binary|0:Ascii] * Defined constants can also be used [FTP_BINARY|FTP_ASCII] * * @return boolean True if successful * * @since 12.1 */ protected function _mode($mode) { if ($mode == FTP_BINARY) { if (!$this->_putCmd("TYPE I", 200)) { Log::add(Text::sprintf('JLIB_CLIENT_ERROR_JFTP_MODE_BINARY', $this->_response), Log::WARNING, 'jerror'); return false; } } else { if (!$this->_putCmd("TYPE A", 200)) { Log::add(Text::sprintf('JLIB_CLIENT_ERROR_JFTP_MODE_ASCII', $this->_response), Log::WARNING, 'jerror'); return false; } } return true; }
/** * Utility function to read the folders in a folder. * * @param string $path The path of the folder to read. * @param string $filter A filter for folder names. * @param mixed $recurse True to recursively search into sub-folders, or an integer to specify the maximum depth. * @param boolean $full True to return the full path to the folders. * @param array $exclude Array with names of folders which should not be shown in the result. * @param array $excludefilter Array with regular expressions matching folders which should not be shown in the result. * * @return array Folders in the given folder. * * @since 1.0 */ public static function folders($path, $filter = '.', $recurse = false, $full = false, $exclude = array('.svn', 'CVS', '.DS_Store', '__MACOSX'), $excludefilter = array('^\\..*')) { // Check to make sure the path valid and clean $path = Path::clean($path); // Is the path a folder? if (!is_dir($path)) { Log::add(sprintf('%1$s: Path is not a folder. Path: %2$s', __METHOD__, $path), Log::WARNING, 'jerror'); return false; } // Compute the excludefilter string if (count($excludefilter)) { $excludefilter_string = '/(' . implode('|', $excludefilter) . ')/'; } else { $excludefilter_string = ''; } // Get the folders $arr = self::_items($path, $filter, $recurse, $full, $exclude, $excludefilter_string, false); // Sort the folders asort($arr); return array_values($arr); }
/** * Internal method to get a JavaScript object notation string from an array * * @param array $array The array to convert to JavaScript object notation * * @return string JavaScript object notation representation of the array * * @since 11.1 * @deprecated 13.3 Use JHtml::getJSObject() instead. */ protected static function _getJSObject($array = array()) { Log::add('JHtmlBehavior::_getJSObject() is deprecated. JHtml::getJSObject() instead..', Log::WARNING, 'deprecated'); Html::getJSObject($array); }
/** * Count the modules based on the given condition * * @param string $condition The condition to use * * @return integer Number of modules found * * @since 11.1 */ public function countModules($condition) { $operators = '(\\+|\\-|\\*|\\/|==|\\!=|\\<\\>|\\<|\\>|\\<=|\\>=|and|or|xor)'; $words = preg_split('# ' . $operators . ' #', $condition, null, PREG_SPLIT_DELIM_CAPTURE); if (count($words) === 1) { $name = strtolower($words[0]); $result = isset(parent::$_buffer['modules'][$name]) && parent::$_buffer['modules'][$name] === false ? 0 : count(\JModuleHelper::getModules($name)); return $result; } Log::add('Using an expression in JDocumentHtml::countModules() is deprecated.', Log::WARNING, 'deprecated'); for ($i = 0, $n = count($words); $i < $n; $i += 2) { // Odd parts (modules) $name = strtolower($words[$i]); $words[$i] = isset(parent::$_buffer['modules'][$name]) && parent::$_buffer['modules'][$name] === false ? 0 : count(\JModuleHelper::getModules($name)); } $str = 'return ' . implode(' ', $words) . ';'; return eval($str); }
/** * Finds out if a set of login credentials are valid by asking all observing * objects to run their respective authentication routines. * * @param array $credentials Array holding the user credentials. * @param array $options Array holding user options. * * @return AuthenticationResponse Response object with status variable filled in for last plugin or first successful plugin. * * @see AuthenticationResponse * @since 11.1 */ public function authenticate($credentials, $options = array()) { // Get plugins $plugins = Helper::getPlugin('authentication'); // Create authentication response $response = new AuthenticationResponse(); /* * Loop through the plugins and check of the credentials can be used to authenticate * the user * * Any errors raised in the plugin should be returned via the AuthenticationResponse * and handled appropriately. */ foreach ($plugins as $plugin) { $className = 'plg' . $plugin->type . $plugin->name; if (class_exists($className)) { $plugin = new $className($this, (array) $plugin); } else { // Bail here if the plugin can't be created Log::add(Text::sprintf('JLIB_USER_ERROR_AUTHENTICATION_FAILED_LOAD_PLUGIN', $className), Log::WARNING, 'jerror'); continue; } // Try to authenticate $plugin->onUserAuthenticate($credentials, $options, $response); // If authentication is successful break out of the loop if ($response->status === self::STATUS_SUCCESS) { if (empty($response->type)) { $response->type = isset($plugin->_name) ? $plugin->_name : $plugin->name; } break; } } if (empty($response->username)) { $response->username = $credentials['username']; } if (empty($response->fullname)) { $response->fullname = $credentials['username']; } if (empty($response->password)) { $response->password = $credentials['password']; } return $response; }
/** * Execute the SQL statement. * * @return mixed A database cursor resource on success, boolean false on failure. * * @since 12.1 * @throws RuntimeException * @throws Exception */ public function execute() { $this->connect(); if (!is_object($this->connection)) { Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'database'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Take a local copy so that we don't modify the original query and cause issues later $sql = $this->replacePrefix((string) $this->sql); if ($this->limit > 0 || $this->offset > 0) { // @TODO $sql .= ' LIMIT ' . $this->offset . ', ' . $this->limit; } // Increment the query counter. $this->count++; // If debugging is enabled then let's log the query. if ($this->debug) { // Add the query to the object queue. $this->log[] = $sql; Log::add($sql, Log::DEBUG, 'databasequery'); } // Reset the error values. $this->errorNum = 0; $this->errorMsg = ''; // Execute the query. $this->executed = false; if ($this->prepared instanceof PDOStatement) { // Bind the variables: if ($this->sql instanceof Preparable) { $bounded =& $this->sql->getBounded(); foreach ($bounded as $key => $obj) { $this->prepared->bindParam($key, $obj->value, $obj->dataType, $obj->length, $obj->driverOptions); } } $this->executed = $this->prepared->execute(); } // If an error occurred handle it. if (!$this->executed) { // Get the error number and message before we execute any more queries. $errorNum = (int) $this->connection->errorCode(); $errorMsg = (string) 'SQL: ' . implode(", ", $this->connection->errorInfo()); // Check if the server was disconnected. if (!$this->connected()) { try { // Attempt to reconnect. $this->connection = null; $this->connect(); } catch (RuntimeException $e) { // Get the error number and message. $this->errorNum = (int) $this->connection->errorCode(); $this->errorMsg = (string) 'SQL: ' . implode(", ", $this->connection->errorInfo()); // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Since we were able to reconnect, run the query again. return $this->execute(); } else { // Get the error number and message from before we tried to reconnect. $this->errorNum = $errorNum; $this->errorMsg = $errorMsg; // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } } return $this->prepared; }
/** * Moves an uploaded file to a destination folder * * @param string $src The name of the php (temporary) uploaded file * @param string $dest The path (including filename) to move the uploaded file to * @param boolean $use_streams True to use streams * * @return boolean True on success * * @since 1.0 */ public static function upload($src, $dest, $use_streams = false) { // Ensure that the path is valid and clean $dest = Path::clean($dest); // Create the destination directory if it does not exist $baseDir = dirname($dest); if (!file_exists($baseDir)) { Folder::create($baseDir); } if ($use_streams) { $stream = Stream::getStream(); if (!$stream->upload($src, $dest)) { Log::add(__METHOD__ . ': ' . $stream->getError(), Log::WARNING, 'jerror'); return false; } return true; } else { if (is_writeable($baseDir) && move_uploaded_file($src, $dest)) { // Short circuit to prevent file permission errors if (Path::setPermissions($dest)) { return true; } else { Log::add(__METHOD__ . ': Failed to change file permissions.', Log::WARNING, 'jerror'); } } else { Log::add(__METHOD__ . ': Failed to move file.', Log::WARNING, 'jerror'); } return false; } }
/** * Return a reference to the {@link JURI} object * * @param string $uri Uri name. * * @return Uri object * * @see JURI * @since 11.1 * @deprecated 13.3 Use JURI directly. */ public static function getURI($uri = 'SERVER') { Log::add(__METHOD__ . ' is deprecated. Use JURI directly.', Log::WARNING, 'deprecated'); return Uri::getInstance($uri); }
/** * Returns the global JRouter object, only creating it if it * doesn't already exist. * * @param string $client The name of the client * @param array $options An associative array of options * * @return JRouter A JRouter object. * * @since 11.1 * @throws RuntimeException */ public static function getInstance($client, $options = array()) { if (empty(self::$instances[$client])) { // Create a JRouter object $classname = '\\Joomla\\Router\\' . ucfirst($client); if (!class_exists($classname)) { Log::add('Non-autoloadable JRouter subclasses are deprecated.', Log::WARNING, 'deprecated'); // Load the router object $info = Helper::getClientInfo($client, true); if (is_object($info)) { $path = $info->path . '/includes/router.php'; if (file_exists($path)) { include_once $path; } } } if (class_exists($classname)) { self::$instances[$client] = new $classname($options); } else { throw new RuntimeException('Unable to load router: ' . $client, 500); } } return self::$instances[$client]; }
/** * Method to activate a user * * @param string $activation Activation string * * @return boolean True on success * * @since 11.1 */ public static function activateUser($activation) { // Initialize some variables. $db = Factory::getDbo(); $query = $db->getQuery(true); // Let's get the id of the user we want to activate $query->select($db->quoteName('id')); $query->from($db->quoteName('#__users')); $query->where($db->quoteName('activation') . ' = ' . $db->quote($activation)); $query->where($db->quoteName('block') . ' = 1'); $query->where($db->quoteName('lastvisitDate') . ' = ' . $db->quote('0000-00-00 00:00:00')); $db->setQuery($query); $id = (int) $db->loadResult(); // Is it a valid user to activate? if ($id) { $user = User::getInstance((int) $id); $user->set('block', '0'); $user->set('activation', ''); // Time to take care of business.... store the user. if (!$user->save()) { Log::add($user->getError(), Log::WARNING, 'jerror'); return false; } } else { Log::add(Text::_('JLIB_USER_ERROR_UNABLE_TO_FIND_USER'), Log::WARNING, 'jerror'); return false; } return true; }
/** * Returns the name, without any path. * * @param string $file File path * * @return string filename * * @since 11.1 * @deprecated 13.3 Use basename() instead. */ public static function getName($file) { Log::add(__METHOD__ . ' is deprecated. Use native basename() syntax.', Log::WARNING, 'deprecated'); // Convert back slashes to forward slashes $file = str_replace('\\', '/', $file); $slash = strrpos($file, '/'); if ($slash !== false) { return substr($file, $slash + 1); } else { return $file; } }
/** * Execute the SQL statement. * * @return mixed A database cursor resource on success, boolean false on failure. * * @since 12.1 * @throws RuntimeException * @throws Exception */ public function execute() { $this->connect(); if (!is_resource($this->connection)) { Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'database'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Take a local copy so that we don't modify the original query and cause issues later $sql = $this->replacePrefix((string) $this->sql); if ($this->limit > 0 || $this->offset > 0) { $sql = $this->limit($sql, $this->limit, $this->offset); } // Increment the query counter. $this->count++; // If debugging is enabled then let's log the query. if ($this->debug) { // Add the query to the object queue. $this->log[] = $sql; Log::add($sql, Log::DEBUG, 'databasequery'); } // Reset the error values. $this->errorNum = 0; $this->errorMsg = ''; // SQLSrv_num_rows requires a static or keyset cursor. if (strncmp(ltrim(strtoupper($sql)), 'SELECT', strlen('SELECT')) == 0) { $array = array('Scrollable' => SQLSRV_CURSOR_KEYSET); } else { $array = array(); } // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost. $this->cursor = @sqlsrv_query($this->connection, $sql, array(), $array); // If an error occurred handle it. if (!$this->cursor) { // Check if the server was disconnected. if (!$this->connected()) { try { // Attempt to reconnect. $this->connection = null; $this->connect(); } catch (RuntimeException $e) { // Get the error number and message. $errors = sqlsrv_errors(); $this->errorNum = $errors[0]['SQLSTATE']; $this->errorMsg = $errors[0]['message'] . 'SQL=' . $sql; // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } // Since we were able to reconnect, run the query again. return $this->execute(); } else { // Get the error number and message. $errors = sqlsrv_errors(); $this->errorNum = $errors[0]['SQLSTATE']; $this->errorMsg = $errors[0]['message'] . 'SQL=' . $sql; // Throw the normal query exception. Log::add(Text::sprintf('JLIB_DATABASE_QUERY_FAILED', $this->errorNum, $this->errorMsg), Log::ERROR, 'databasequery'); throw new RuntimeException($this->errorMsg, $this->errorNum); } } return $this->cursor; }
/** * Method to get the next row in the result set from the database query as an array. * * @return mixed The result of the query as an array, false if there are no more rows. * * @since 11.1 * @throws RuntimeException */ public function loadNextRow() { Log::add('JDatabase::loadNextRow() is deprecated. Use JDatabase::getIterator() instead.', Log::WARNING, 'deprecated'); $this->connect(); static $cursor = null; // Execute the query and get the result set cursor. if (is_null($cursor)) { if (!($cursor = $this->execute())) { return $this->errorNum ? null : false; } } // Get the next row from the result set as an object of type $class. if ($row = $this->fetchArray($cursor)) { return $row; } // Free up system resources and return. $this->freeResult($cursor); $cursor = null; return false; }
/** * Create a placeholder for an option group. * * @param string $text The text for the option * @param string $optKey The returned object property name for the value * @param string $optText The returned object property name for the text * * @return object * * @deprecated 12.1 Use JHtmlSelect::groupedList() * @see JHtmlSelect::groupedList() * @since 11.1 */ public static function optgroup($text, $optKey = 'value', $optText = 'text') { Log::add('JHtmlSelect::optgroup is deprecated.', Log::WARNING, 'deprecated'); // Set initial state static $state = 'open'; // Toggle between open and close states: switch ($state) { case 'open': $obj = new stdClass(); $obj->{$optKey} = '<OPTGROUP>'; $obj->{$optText} = $text; $state = 'close'; break; case 'close': $obj = new stdClass(); $obj->{$optKey} = '</OPTGROUP>'; $obj->{$optText} = $text; $state = 'open'; break; } return $obj; }
/** * Method to get an image filter instance of a specified type. * * @param string $type The image filter type to get. * * @return Filter * * @since 11.3 * @throws RuntimeException */ protected function getFilterInstance($type) { // Sanitize the filter type. $type = strtolower(preg_replace('#[^A-Z0-9_]#i', '', $type)); // Verify that the filter type exists. $className = '\\Joomla\\Image\\Filter\\' . ucfirst($type); if (!class_exists($className)) { Log::add('The ' . ucfirst($type) . ' image filter is not available.', Log::ERROR); throw new RuntimeException('The ' . ucfirst($type) . ' image filter is not available.'); } // Instantiate the filter object. $instance = new $className($this->handle); // Verify that the filter type is valid. if (!$instance instanceof Filter) { // @codeCoverageIgnoreStart Log::add('The ' . ucfirst($type) . ' image filter is not valid.', Log::ERROR); throw new RuntimeException('The ' . ucfirst($type) . ' image filter is not valid.'); // @codeCoverageIgnoreEnd } return $instance; }
/** * Method to add an entry to the log. * * @param mixed $entry The JLogEntry object to add to the log or the message for a new JLogEntry object. * @param integer $priority Message priority. * @param string $category Type of entry * @param string $date Date of entry (defaults to now if not specified or blank) * * @return void * * @since 11.1 */ public static function add($entry, $priority = self::INFO, $category = '', $date = null) { // Automatically instantiate the singleton object if not already done. if (empty(self::$instance)) { self::setInstance(new self()); } // If the entry object isn't a JLogEntry object let's make one. if (!$entry instanceof Entry) { $entry = new Entry((string) $entry, $priority, $category, $date); } self::$instance->addLogEntry($entry); }
/** * Returns a property of the object or the default value if the property is not set. * * @param string $property The name of the property. * @param mixed $default The default value. * * @return mixed The value of the property. * * @since 12.2 * @deprecated 13.3 Access the properties directly. */ public function get($property, $default = null) { Log::add('JPagination::get() is deprecated. Access the properties directly.', Log::WARNING, 'deprecated'); if (strpos($property, '.')) { $prop = explode('.', $property); $prop[1] = ucfirst($prop[1]); $property = implode($prop); } if (isset($this->{$property})) { return $this->{$property}; } return $default; }
/** * Test the Joomla\Log\Log::setInstance method to make sure that if we set a logger instance Joomla\Log\Log is actually going * to use it. We accomplish this by setting an instance of LogInspector and then performing some * operations using Joomla\Log\Log::addLogger() to alter the state of the internal instance. We then check that the * LogInspector instance we created (and set) has the same values we would expect for lookup and configuration * so we can assert that the operations we performed using Joomla\Log\Log::addLogger() were actually performed on our * instance of LogInspector that was set. * * @return void * * @since 1.0 */ public function testSetInstance() { $log = new LogInspector(); Log::setInstance($log); // Add a logger to the Log object. Log::addLogger(array('logger' => 'w3c')); // Get the expected configurations array after adding the single logger. $expectedConfigurations = array('55202c195e23298813df4292c827b241' => array('logger' => 'w3c')); // Get the expected lookup array after adding the single logger. $expectedLookup = array('55202c195e23298813df4292c827b241' => (object) array('priorities' => Log::ALL, 'categories' => array(), 'exclude' => false)); // Get the expected loggers array after adding the single logger (hasn't been instantiated yet so null). $expectedLoggers = null; $this->assertThat($log->configurations, $this->equalTo($expectedConfigurations), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->lookup, $this->equalTo($expectedLookup), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->loggers, $this->equalTo($expectedLoggers), 'Line: ' . __LINE__ . '.'); // Start over so we test that it actually sets the instance appropriately. $log = new LogInspector(); Log::setInstance($log); // Add a logger to the Log object. Log::addLogger(array('logger' => 'database', 'db_type' => 'mysql', 'db_table' => '#__test_table'), Log::ERROR); // Get the expected configurations array after adding the single logger. $expectedConfigurations = array('b67483f5ba61450d173aae527fa4163f' => array('logger' => 'database', 'db_type' => 'mysql', 'db_table' => '#__test_table')); // Get the expected lookup array after adding the single logger. $expectedLookup = array('b67483f5ba61450d173aae527fa4163f' => (object) array('priorities' => Log::ERROR, 'categories' => array(), 'exclude' => false)); // Get the expected loggers array after adding the single logger (hasn't been instantiated yet so null). $expectedLoggers = null; $this->assertThat($log->configurations, $this->equalTo($expectedConfigurations), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->lookup, $this->equalTo($expectedLookup), 'Line: ' . __LINE__ . '.'); $this->assertThat($log->loggers, $this->equalTo($expectedLoggers), 'Line: ' . __LINE__ . '.'); }
/** * Method to write the process id file out to disk. * * @return boolean * * @since 11.1 */ protected function writeProcessIdFile() { // Verify the process id is valid. if ($this->processId < 1) { Log::add('The process id is invalid.', Log::EMERGENCY); return false; } // Get the application process id file path. $file = $this->config->get('application_pid_file'); if (empty($file)) { Log::add('The process id file path is empty.', Log::ERROR); return false; } // Make sure that the folder where we are writing the process id file exists. $folder = dirname($file); if (!is_dir($folder) && !Folder::create($folder)) { Log::add('Unable to create directory: ' . $folder, Log::ERROR); return false; } // Write the process id file out to disk. if (!file_put_contents($file, $this->processId)) { Log::add('Unable to write proccess id file: ' . $file, Log::ERROR); return false; } // Make sure the permissions for the proccess id file are accurate. if (!chmod($file, 0644)) { Log::add('Unable to adjust permissions for the proccess id file: ' . $file, Log::ERROR); return false; } return true; }
/** * Set transfer mode * * @param integer $mode Integer representation of data transfer mode [1:Binary|0:Ascii] * Defined constants can also be used [FTP_BINARY|FTP_ASCII] * * @return boolean True if successful * * @since 1.0 */ protected function _mode($mode) { if ($mode == FTP_BINARY) { if (!$this->_putCmd("TYPE I", 200)) { Log::add(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 200]. Mode sent: Binary', __METHOD__, $this->response), Log::WARNING, 'jerror'); return false; } } else { if (!$this->_putCmd("TYPE A", 200)) { Log::add(sprintf('%1$s: Bad response. Server response: %2$s [Expected: 200]. Mode sent: ASCII', __METHOD__, $this->response), Log::WARNING, 'jerror'); return false; } } return true; }