This repository has been archived by the owner. It is now read-only.

Joomla CMS [#27415] Missing platform change for update notification #657

Merged
merged 19 commits into from Dec 20, 2011
Jump to file or symbol
Failed to load files and symbols.
+761 −40
Split
@@ -1225,7 +1225,7 @@ public function loadRowList($key = null)
* Method to quote and optionally escape a string to database requirements for insertion into the database.
*
* @param string $text The string to quote.
- * @param boolean $escape True to escape the string, false to leave it unchanged.
+ * @param boolean $escape True (default) to escape the string, false to leave it unchanged.
*
* @return string The quoted input string.
*
@@ -1240,32 +1240,39 @@ public function quote($text, $escape = true)
* Wrap an SQL statement identifier name such as column, table or database names in quotes to prevent injection
* risks and reserved word conflicts.
*
- * @param string $name The identifier name to wrap in quotes.
+ * @param mixed $name The identifier name to wrap in quotes, or an array of parts to quote with dot-notation.
*
* @return string The quote wrapped name.
*
* @since 11.1
*/
public function quoteName($name)
{
- // Don't quote names with dot-notation.
- if (strpos($name, '.') !== false)
+ if (is_string($name))
{
- return $name;
+ $name = explode('.', $name);
}
- else
+ elseif (!is_array($name))
{
- $q = $this->nameQuote;
+ settype($name, 'array');
+ }
+ $parts = array();
+ $q = $this->nameQuote;
+
+ foreach ($name as $part)
+ {
if (strlen($q) == 1)
{
- return $q . $name . $q;
+ $parts[] = $q . $part . $q;
}
else
{
- return $q{0} . $name . $q{1};
+ $parts[] = $q{0} . $part . $q{1};
}
}
+
+ return implode('.', $parts);
}
/**
@@ -136,7 +136,7 @@ public function __clone()
abstract class JDatabaseQuery
{
/**
- * @var resource The database connection resource.
+ * @var JDatabase The database connection resource.
* @since 11.1
*/
protected $db = null;
@@ -81,7 +81,7 @@ protected function getInput()
// Create a dummy text field with the user name.
$html[] = '<div class="fltlft">';
- $html[] = ' <input type="text" id="' . $this->id . '_name"' . ' value="' . htmlspecialchars($table->username, ENT_COMPAT, 'UTF-8') . '"'
+ $html[] = ' <input type="text" id="' . $this->id . '_name"' . ' value="' . htmlspecialchars($table->name, ENT_COMPAT, 'UTF-8') . '"'
. ' disabled="disabled"' . $attr . ' />';
$html[] = '</div>';
@@ -1236,6 +1236,57 @@ protected function filterField($element, $value)
}
break;
+ // Ensures a protocol is present in the saved field. Only use when
+ // the only permitted protocols requre '://'. See JFormRuleUrl for list of these.
+
+ case 'URL':
+ if (empty($value))
+ {
+ return;
+ }
+ $value = JFilterInput::getInstance()->clean($value, 'html');
+ $value = trim($value);
+
+ // Check for a protocol
+ $protocol = parse_url($value, PHP_URL_SCHEME);
+
+ // If there is no protocol and the relative option is not specified,
+ // we assume that it is an external URL and prepend http://.
+ if (($element['type'] == 'url' && !$protocol && !$element['relative'])
+ || (!$element['type'] == 'url' && !$protocol))
+ {
+ $protocol = 'http';
+ // If it looks like an internal link, then add the root.
+ if (substr($value, 0) == 'index.php')
+ {
+ $value = JURI::root() . $value;
+ }
+
+ // Otherwise we treat it is an external link.
+ // Put the url back together.
+ $value = $protocol . '://' . ltrim($value, $protocol);
+ }
+
+ // If relative URLS are allowed we assume that URLs without protocols are internal.
+ elseif (!$protocol && $element['relative'])
+ {
+ $host = JURI::getInstance('SERVER')->gethost();
+
+ // If it starts with the host string, just prepend the protocol.
+ if (substr($value, 0) == $host)
+ {
+ $value = 'http://' . $value;
+ }
+ // Otherwise prepend the root.
+ else
+ {
+ $value = JURI::root() . $value;
+ }
+ }
+
+ $return = $value;
+ break;
+
case 'TEL':
$value = trim($value);
// Does it match the NANP pattern?
@@ -62,13 +62,14 @@ public static function &getInstance()
/**
* Finds an update for an extension
*
- * @param integer $eid Extension Identifier; if zero use all sites
+ * @param integer $eid Extension Identifier; if zero use all sites
+ * @param integer $cacheTimeout How many seconds to cache update information; if zero, force reload the update information
*
* @return boolean True if there are updates
*
* @since 11.1
*/
- public function findUpdates($eid = 0)
+ public function findUpdates($eid = 0, $cacheTimeout = 0)
{
// Check if fopen is allowed
$result = ini_get('allow_url_fopen');
@@ -83,17 +84,18 @@ public function findUpdates($eid = 0)
// Push it into an array
if (!is_array($eid))
{
- $query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites WHERE enabled = 1';
+ $query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites WHERE enabled = 1';
}
else
{
- $query = 'SELECT DISTINCT update_site_id, type, location FROM #__update_sites' .
+ $query = 'SELECT DISTINCT update_site_id, type, location, last_check_timestamp FROM #__update_sites' .
' WHERE update_site_id IN' .
' (SELECT update_site_id FROM #__update_sites_extensions WHERE extension_id IN (' . implode(',', $eid) . '))';
}
$dbo->setQuery($query);
$results = $dbo->loadAssocList();
$result_count = count($results);
+ $now = time();
for ($i = 0; $i < $result_count; $i++)
{
$result = &$results[$i];
@@ -103,6 +105,16 @@ public function findUpdates($eid = 0)
// Ignore update sites requiring adapters we don't have installed
continue;
}
+ if ($cacheTimeout > 0)
+ {
+ if ($now - $result['last_check_timestamp'] <= $cacheTimeout)
+ {
+ // Ignore update sites whose information we have fetched within
+ // the cache time limit
+ $retval = true;
+ continue;
+ }
+ }
$update_result = $this->_adapters[$result['type']]->findUpdate($result);
if (is_array($update_result))
{
@@ -172,6 +184,14 @@ public function findUpdates($eid = 0)
{
$update_result = true;
}
+
+ // Finally, update the last update check timestamp
+ $query = $dbo->getQuery(true);
+ $query->update($dbo->quoteName('#__update_sites'));
+ $query->set($dbo->quoteName('last_check_timestamp') . ' = ' . $dbo->quote($now));
+ $query->where($dbo->quoteName('update_site_id') . ' = ' . $dbo->quote($result['update_site_id']));
+ $dbo->setQuery($query);
+ $dbo->query();
}
return $retval;
}
@@ -192,7 +212,7 @@ public function findUpdates($eid = 0)
*/
public function arrayUnique($myArray)
{
- JLog::add('JUpdater::arrayUnique() is deprecated. See JArrayHelper::arrayUnique().', JLog::WARNING, 'deprecated');
+ JLog::add('JUpdater::arrayUnique() is deprecated. See JArrayHelper::arrayUnique() . ', JLog::WARNING, 'deprecated');
return JArrayHelper::arrayUnique($myArray);
}
Oops, something went wrong.