From 24025612b3dbc15a14ef3cba9e02004896123596 Mon Sep 17 00:00:00 2001 From: elinw Date: Sat, 10 Mar 2012 10:16:55 -0500 Subject: [PATCH 01/98] Add detection of android tablets. --- libraries/joomla/application/web/client.php | 13 +++++++++++++ .../application/web/JApplicationWebClientTest.php | 4 +++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/application/web/client.php b/libraries/joomla/application/web/client.php index c44017766a..89ef113ae0 100644 --- a/libraries/joomla/application/web/client.php +++ b/libraries/joomla/application/web/client.php @@ -39,6 +39,7 @@ class JApplicationWebClient const CHROME = 19; const SAFARI = 20; const OPERA = 21; + const ANDROIDTABLET = 22; /** * @var integer The detected platform on which the web client runs. @@ -419,6 +420,18 @@ protected function detectPlatform($userAgent) { $this->mobile = true; $this->platform = self::ANDROID; + /** + * Attempt to distinguish between Android phones and tablets + * There is no totally foolproof method but certain rules almost always hold + * Android 3.x is only used for tablets + * Some devices and browsers encourage users to change their UA string to include Tablet. + * Google encourages manufacturers to exclude the string Mobile from tablet device UA strings. + * In some modes Kindle Android devices include the string Mobile but they include the string Silk. + */ + if (stripos($userAgent, 'Android 3') !== false || stripos($userAgent, 'Tablet') !== false || stripos($userAgent, 'Mobile') === false || stripos($userAgent, 'Silk') !== false ) + { + $this->platform = self::ANDROIDTABLET; + } } elseif (stripos($userAgent, 'Linux') !== false) { diff --git a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php index b801994082..52b99ec7b9 100644 --- a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php +++ b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php @@ -50,8 +50,10 @@ public static function getUserAgentData() array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::CHROME, '15.0.864.0', 'Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.864.0 Safari/535.2'), array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '6.0.0.546', 'Mozilla/5.0 (BlackBerry; U; BlackBerry 9700; pt) AppleWebKit/534.8+ (KHTML, like Gecko) Version/6.0.0.546 Mobile Safari/534.8+'), array(JApplicationWebClient::BLACKBERRY, true, JApplicationWebClient::WEBKIT, '', '', 'BlackBerry9700/5.0.0.862 Profile/MIDP-2.1 Configuration/CLDC-1.1 VendorID/120'), - array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'), + array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '999.9', 'Mozilla/5.0 (Linux; U; Android 2.3; en-us) AppleWebKit/999+ (KHTML, like Gecko) Safari/999.9'), array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'), + array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'), + array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false'), array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'), array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'), From 614e789d0ae1712224dbdefd5fda2f12a6f8d11a Mon Sep 17 00:00:00 2001 From: elinw Date: Sat, 10 Mar 2012 12:02:53 -0500 Subject: [PATCH 02/98] Add test case with Tablet in the string. --- .../unit/joomla/application/web/JApplicationWebClientTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php index 52b99ec7b9..2bf83cdaf7 100644 --- a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php +++ b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php @@ -54,6 +54,7 @@ public static function getUserAgentData() array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'), array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'), array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false'), + array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '12', ' Mozilla/5.0 (Android; Tablet; rv:12.0) Gecko/12.0 Firefox/12.0'), array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'), array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'), From 802ac35d6a361d84a29b0457a1ece4346668ff50 Mon Sep 17 00:00:00 2001 From: elinw Date: Sat, 10 Mar 2012 12:35:54 -0500 Subject: [PATCH 03/98] Add test for Opera Android tablet --- .../unit/joomla/application/web/JApplicationWebClientTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php index 2bf83cdaf7..f1e059edb4 100644 --- a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php +++ b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php @@ -55,6 +55,7 @@ public static function getUserAgentData() array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 3.0; en-us; Xoom Build/HRI39) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13'), array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Silk/1.1.0-84) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 Silk-Accelerated=false'), array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '12', ' Mozilla/5.0 (Android; Tablet; rv:12.0) Gecko/12.0 Firefox/12.0'), + array(JApplicationWebClient::ANDROIDTABLET, true, JApplicationWebClient::PRESTO, JApplicationWebClient::OPERA, '11.5', 'Opera/9.80 (Android 3.2.1; Linux; Opera Tablet/ADR-1111101157; U; en) Presto/2.9.201 Version/11.50'), array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'), array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'), From 5b9d3d6f2e2ebd6bba35fc374c767f1787103a62 Mon Sep 17 00:00:00 2001 From: elinw Date: Sat, 10 Mar 2012 17:55:57 -0500 Subject: [PATCH 04/98] Change the search for version for the case where there are more than 2 matches. --- libraries/joomla/application/web/client.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/application/web/client.php b/libraries/joomla/application/web/client.php index 89ef113ae0..4bd71f6d67 100644 --- a/libraries/joomla/application/web/client.php +++ b/libraries/joomla/application/web/client.php @@ -256,7 +256,7 @@ protected function detectBrowser($userAgent) if (preg_match_all($pattern, $userAgent, $matches)) { // Do we have both a Version and browser match? - if (count($matches['browser']) > 1) + if (count($matches['browser']) == 2) { // See whether Version or browser came first, and use the number accordingly. if (strripos($userAgent, 'Version') < strripos($userAgent, $patternBrowser)) @@ -268,6 +268,15 @@ protected function detectBrowser($userAgent) $this->browserVersion = $matches['version'][1]; } } + elseif (count($matches['browser']) > 2) + { + $key = array_search('Version',$matches['browser']); + if ($key) + { + $this->browserVersion = $matches['version'][$key]; + } + + } // We only have a Version or a browser so use what we have. else { From 38d0e469176b76c21a4e934a6ba05579e99bd976 Mon Sep 17 00:00:00 2001 From: elinw Date: Sat, 10 Mar 2012 18:10:50 -0500 Subject: [PATCH 05/98] Codestyle --- libraries/joomla/application/web/client.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libraries/joomla/application/web/client.php b/libraries/joomla/application/web/client.php index 4bd71f6d67..72cf5ca9b3 100644 --- a/libraries/joomla/application/web/client.php +++ b/libraries/joomla/application/web/client.php @@ -270,12 +270,11 @@ protected function detectBrowser($userAgent) } elseif (count($matches['browser']) > 2) { - $key = array_search('Version',$matches['browser']); + $key = array_search('Version', $matches['browser']); if ($key) { $this->browserVersion = $matches['version'][$key]; } - } // We only have a Version or a browser so use what we have. else From 24f3027286b7499f0d07a2bfccc127ddfd2e22b7 Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Wed, 28 Mar 2012 01:54:06 -0500 Subject: [PATCH 06/98] Rename protected members in JAuthentication --- libraries/joomla/user/authentication.php | 38 ++++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/libraries/joomla/user/authentication.php b/libraries/joomla/user/authentication.php index 2c164956cb..9416add511 100644 --- a/libraries/joomla/user/authentication.php +++ b/libraries/joomla/user/authentication.php @@ -69,25 +69,25 @@ class JAuthentication extends JObject * An array of Observer objects to notify * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_observers = array(); + protected $observers = array(); /** * The state of the observable object * * @var mixed - * @since 11.1 + * @since 12.1 */ - protected $_state = null; + protected $state = null; /** * A multi dimensional array of [function][] = key for observers * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_methods = array(); + protected $methods = array(); /** * @var JAuthentication JAuthentication instances container. @@ -137,7 +137,7 @@ public static function getInstance() */ public function getState() { - return $this->_state; + return $this->state; } /** @@ -159,7 +159,7 @@ public function attach($observer) } // Make sure we haven't already attached this array as an observer - foreach ($this->_observers as $check) + foreach ($this->observers as $check) { if (is_array($check) && $check['event'] == $observer['event'] && $check['handler'] == $observer['handler']) { @@ -167,8 +167,8 @@ public function attach($observer) } } - $this->_observers[] = $observer; - end($this->_observers); + $this->observers[] = $observer; + end($this->observers); $methods = array($observer['event']); } else @@ -181,7 +181,7 @@ public function attach($observer) // Make sure we haven't already attached this object as an observer $class = get_class($observer); - foreach ($this->_observers as $check) + foreach ($this->observers as $check) { if ($check instanceof $class) { @@ -189,22 +189,22 @@ public function attach($observer) } } - $this->_observers[] = $observer; + $this->observers[] = $observer; $methods = array_diff(get_class_methods($observer), get_class_methods('JPlugin')); } - $key = key($this->_observers); + $key = key($this->observers); foreach ($methods as $method) { $method = strtolower($method); - if (!isset($this->_methods[$method])) + if (!isset($this->methods[$method])) { - $this->_methods[$method] = array(); + $this->methods[$method] = array(); } - $this->_methods[$method][] = $key; + $this->methods[$method][] = $key; } } @@ -222,14 +222,14 @@ public function detach($observer) // Initialise variables. $retval = false; - $key = array_search($observer, $this->_observers); + $key = array_search($observer, $this->observers); if ($key !== false) { - unset($this->_observers[$key]); + unset($this->observers[$key]); $retval = true; - foreach ($this->_methods as &$method) + foreach ($this->methods as &$method) { $k = array_search($key, $method); From 07f70cf35b0b1ef5d6a3aa4a3c495de1dd7d89ec Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Wed, 28 Mar 2012 15:48:22 -0500 Subject: [PATCH 07/98] Rename protected members in JPagination --- libraries/joomla/html/pagination.php | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/joomla/html/pagination.php b/libraries/joomla/html/pagination.php index 29da5c01ec..9dd33d2de5 100644 --- a/libraries/joomla/html/pagination.php +++ b/libraries/joomla/html/pagination.php @@ -45,18 +45,18 @@ class JPagination extends JObject /** * @var boolean View all flag - * @since 11.1 + * @since 12.1 */ - protected $_viewall = false; + protected $viewall = false; /** * Additional URL parameters to be added to the pagination URLs generated by the class. These * may be useful for filters and extra values when dealing with lists and GET requests. * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_additionalUrlParams = array(); + protected $additionalUrlParams = array(); /** * Constructor. @@ -130,7 +130,7 @@ public function __construct($total, $limitstart, $limit, $prefix = '') // If we are viewing all records set the view all flag to true. if ($limit == 0) { - $this->_viewall = true; + $this->viewall = true; } } @@ -148,16 +148,16 @@ public function __construct($total, $limitstart, $limit, $prefix = '') public function setAdditionalUrlParam($key, $value) { // Get the old value to return and set the new one for the URL parameter. - $result = isset($this->_additionalUrlParams[$key]) ? $this->_additionalUrlParams[$key] : null; + $result = isset($this->additionalUrlParams[$key]) ? $this->additionalUrlParams[$key] : null; // If the passed parameter value is null unset the parameter, otherwise set it to the given value. if ($value === null) { - unset($this->_additionalUrlParams[$key]); + unset($this->additionalUrlParams[$key]); } else { - $this->_additionalUrlParams[$key] = $value; + $this->additionalUrlParams[$key] = $value; } return $result; @@ -175,7 +175,7 @@ public function setAdditionalUrlParam($key, $value) */ public function getAdditionalUrlParam($key) { - $result = isset($this->_additionalUrlParams[$key]) ? $this->_additionalUrlParams[$key] : null; + $result = isset($this->additionalUrlParams[$key]) ? $this->additionalUrlParams[$key] : null; return $result; } @@ -436,7 +436,7 @@ public function getLimitBox() $limits[] = JHtml::_('select.option', '100', JText::_('J100')); $limits[] = JHtml::_('select.option', '0', JText::_('JALL')); - $selected = $this->_viewall ? 0 : $this->limit; + $selected = $this->viewall ? 0 : $this->limit; // Build the select list. if ($app->isAdmin()) @@ -635,16 +635,16 @@ protected function _buildDataObject() // Build the additional URL parameters string. $params = ''; - if (!empty($this->_additionalUrlParams)) + if (!empty($this->additionalUrlParams)) { - foreach ($this->_additionalUrlParams as $key => $value) + foreach ($this->additionalUrlParams as $key => $value) { $params .= '&' . $key . '=' . $value; } } $data->all = new JPaginationObject(JText::_('JLIB_HTML_VIEW_ALL'), $this->prefix); - if (!$this->_viewall) + if (!$this->viewall) { $data->all->base = '0'; $data->all->link = JRoute::_($params . '&' . $this->prefix . 'limitstart='); @@ -692,7 +692,7 @@ protected function _buildDataObject() // @todo remove code: $offset = $offset == 0 ? '' : $offset; $data->pages[$i] = new JPaginationObject($i, $this->prefix); - if ($i != $this->get('pages.current') || $this->_viewall) + if ($i != $this->get('pages.current') || $this->viewall) { $data->pages[$i]->base = $offset; $data->pages[$i]->link = JRoute::_($params . '&' . $this->prefix . 'limitstart=' . $offset); From c66b318c7f29612a811a8fcd5cbb0dd49c1346dd Mon Sep 17 00:00:00 2001 From: Aaron Schmitz Date: Thu, 29 Mar 2012 02:58:35 -0500 Subject: [PATCH 08/98] Cause JForm to replace fields in place when a new definition is loaded to replace the old definition. Duplicate fields will now remain in their original location rather than being moved to the end of the document. --- libraries/joomla/form/form.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index 46b9d02349..707477dba5 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -712,11 +712,14 @@ public function load($data, $replace = true, $xpath = false) if ($current = $this->findField((string) $field['name'], implode('.', $groups))) { - // If set to replace found fields remove it from the current definition. + // If set to replace found fields, replace the data and remove the field so we don't add it twice. if ($replace) { - $dom = dom_import_simplexml($current); - $dom->parentNode->removeChild($dom); + $olddom = dom_import_simplexml($current); + $loadeddom = dom_import_simplexml($field); + $addeddom = $olddom->ownerDocument->importNode($loadeddom); + $olddom->parentNode->replaceChild($addeddom, $olddom); + $loadeddom->parentNode->removeChild($loadeddom); } else { From 4fba270b6df8bdf22c13aa52c386cbf1f3f0b4e2 Mon Sep 17 00:00:00 2001 From: Aaron Schmitz Date: Thu, 29 Mar 2012 20:32:10 -0500 Subject: [PATCH 09/98] Added unit test which checks to verify that when a form is loaded with replacement the first n name fields are in the same as those of the replaced form where n is the length of the replaced form. --- tests/suites/unit/joomla/form/JFormTest.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/suites/unit/joomla/form/JFormTest.php b/tests/suites/unit/joomla/form/JFormTest.php index 14d378f35d..9b48a122f2 100644 --- a/tests/suites/unit/joomla/form/JFormTest.php +++ b/tests/suites/unit/joomla/form/JFormTest.php @@ -1301,6 +1301,19 @@ public function testLoad() $this->equalTo(1), 'Line:'.__LINE__.' The show_title in the params group has been replaced by show_abstract.' ); + + $originalform = new JFormInspector('form1'); + $originalform->load(JFormDataHelper::$loadDocument); + $originalset = $originalform->getXML()->xpath('/form/fields/field'); + $set = $form->getXML()->xpath('/form/fields/field'); + for ($i = 0; $i < count($originalset); $i++) + { + $this->assertThat( + (string) ($originalset[$i]->attributes()->name) == (string) ($set[$i]->attributes()->name), + $this->isTrue(), + 'Line:'.__LINE__.' Replace should leave fields in the original order.' + ); + } } /** From 0b749c79b7c475bfe0d8ea058f0f0aee0695daf0 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Thu, 29 Mar 2012 22:59:19 -0500 Subject: [PATCH 10/98] Client Package: Change one return JError to Exception --- libraries/joomla/client/helper.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/client/helper.php b/libraries/joomla/client/helper.php index bc3d9826c9..7822d33835 100644 --- a/libraries/joomla/client/helper.php +++ b/libraries/joomla/client/helper.php @@ -201,6 +201,7 @@ public static function hasCredentials($client) * @return mixed True, if FTP settings should be shown or an exception * * @since 11.1 + * @throws InvalidArgumentException */ public static function setCredentialsFromRequest($client) { @@ -216,7 +217,7 @@ public static function setCredentialsFromRequest($client) } else { - $return = JError::raiseWarning('SOME_ERROR_CODE', JText::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED')); + throw new InvalidArgumentException('Invalid user credentials'); } } else From 9d04dc49103f0a28d40abbed7de9a4e4b507001f Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Thu, 29 Mar 2012 23:35:40 -0500 Subject: [PATCH 11/98] CMS Separation: Check if CMS constants are defined --- libraries/joomla/environment/uri.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/environment/uri.php b/libraries/joomla/environment/uri.php index 6f7b5db708..13fe53339f 100644 --- a/libraries/joomla/environment/uri.php +++ b/libraries/joomla/environment/uri.php @@ -226,9 +226,12 @@ public static function base($pathonly = false) self::$base['prefix'] = $uri->toString(array('scheme', 'host', 'port')); self::$base['path'] = rtrim($uri->toString(array('path')), '/\\'); - if (JPATH_BASE == JPATH_ADMINISTRATOR) + if (defined('JPATH_BASE') && defined('JPATH_ADMINISTRATOR')) { - self::$base['path'] .= '/administrator'; + if (JPATH_BASE == JPATH_ADMINISTRATOR) + { + self::$base['path'] .= '/administrator'; + } } } else From 8e6ca3975085b3162ffe995399969aeca95d2980 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 12:26:26 -0500 Subject: [PATCH 12/98] Crypt Package: Add Docblocks for Exceptions --- libraries/joomla/crypt/cipher/simple.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/joomla/crypt/cipher/simple.php b/libraries/joomla/crypt/cipher/simple.php index 5983bffef2..af875643cd 100644 --- a/libraries/joomla/crypt/cipher/simple.php +++ b/libraries/joomla/crypt/cipher/simple.php @@ -27,6 +27,7 @@ class JCryptCipherSimple implements JCryptCipher * @return string The decrypted data string. * * @since 12.1 + * @throws InvalidArgumentException */ public function decrypt($data, JCryptKey $key) { @@ -68,6 +69,7 @@ public function decrypt($data, JCryptKey $key) * @return string The encrypted data string. * * @since 12.1 + * @throws InvalidArgumentException */ public function encrypt($data, JCryptKey $key) { From 52fd3e38107c25a8d97559333566af729a08a49a Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 17:07:28 -0500 Subject: [PATCH 13/98] Document Package: Remove JText from Exceptions --- libraries/joomla/document/document.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/document/document.php b/libraries/joomla/document/document.php index 0241a1a7b6..4136614fad 100644 --- a/libraries/joomla/document/document.php +++ b/libraries/joomla/document/document.php @@ -258,7 +258,7 @@ public function __construct($options = array()) * @return object The document object. * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public static function getInstance($type = 'html', $attributes = array()) { @@ -289,7 +289,7 @@ public static function getInstance($type = 'html', $attributes = array()) } else { - throw new Exception(JText::_('JLIB_DOCUMENT_ERROR_UNABLE_LOAD_DOC_CLASS'), 500); + throw new RuntimeException('Invalid JDocument Class', 500); } } @@ -900,7 +900,7 @@ public function _getTab() * @return JDocumentRenderer Object or null if class does not exist * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function loadRenderer($type) { @@ -916,7 +916,7 @@ public function loadRenderer($type) } else { - throw new Exception(JText::_('Unable to load renderer class'), 500); + throw new RuntimeException('Unable to load renderer class', 500); } } From f7d00646d0c848dc75b701d22d4328bbc2b785a9 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 18:47:03 -0500 Subject: [PATCH 14/98] Filesystem Package: JText removal for Exceptions --- libraries/joomla/filesystem/folder.php | 18 +++++++++--------- libraries/joomla/filesystem/patcher.php | 12 ++++++------ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/joomla/filesystem/folder.php b/libraries/joomla/filesystem/folder.php index fd19b3d353..e9157bbf03 100644 --- a/libraries/joomla/filesystem/folder.php +++ b/libraries/joomla/filesystem/folder.php @@ -32,7 +32,7 @@ abstract class JFolder * @return mixed JError object on failure or boolean True on success. * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public static function copy($src, $dest, $path = '', $force = false, $use_streams = false) { @@ -53,17 +53,17 @@ public static function copy($src, $dest, $path = '', $force = false, $use_stream if (!self::exists($src)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_FIND_SOURCE_FOLDER'), -1); + throw new RuntimeException('Source folder not found', -1); } if (self::exists($dest) && !$force) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_EXISTS'), -1); + throw new RuntimeException('Destination folder not found', -1); } // Make sure the destination exists if (!self::create($dest)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_CREATE'), -1); + throw new RuntimeException('Cannot create destination folder', -1); } // If we're using ftp and don't have streams enabled @@ -74,7 +74,7 @@ public static function copy($src, $dest, $path = '', $force = false, $use_stream if (!($dh = @opendir($src))) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_OPEN'), -1); + throw new RuntimeException('Cannot open source folder', -1); } // Walk through the directory copying files and recursing into folders. while (($file = readdir($dh)) !== false) @@ -99,7 +99,7 @@ public static function copy($src, $dest, $path = '', $force = false, $use_stream $dfid = JPath::clean(str_replace(JPATH_ROOT, $FTPOptions['root'], $dfid), '/'); if (!$ftp->store($sfid, $dfid)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED'), -1); + throw new RuntimeException('Copy file failed', -1); } break; } @@ -109,7 +109,7 @@ public static function copy($src, $dest, $path = '', $force = false, $use_stream { if (!($dh = @opendir($src))) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_FOLDER_OPEN'), -1); + throw new RuntimeException('Cannot open source folder', -1); } // Walk through the directory copying files and recursing into folders. while (($file = readdir($dh)) !== false) @@ -135,14 +135,14 @@ public static function copy($src, $dest, $path = '', $force = false, $use_stream $stream = JFactory::getStream(); if (!$stream->copy($sfid, $dfid)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED') . ': ' . $stream->getError(), -1); + throw new RuntimeException('Cannot copy file: ' . $stream->getError(), -1); } } else { if (!@copy($sfid, $dfid)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_ERROR_COPY_FAILED'), -1); + throw new RuntimeException('Copy file failed', -1); } } break; diff --git a/libraries/joomla/filesystem/patcher.php b/libraries/joomla/filesystem/patcher.php index 356ccdae2b..e151b8b023 100644 --- a/libraries/joomla/filesystem/patcher.php +++ b/libraries/joomla/filesystem/patcher.php @@ -161,7 +161,7 @@ public function apply() // If no modifications were found, throw an exception if (!$done) { - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_INVALID_DIFF')); + throw new RuntimeException('Invalid Diff'); } } } @@ -294,13 +294,13 @@ protected static function findHeader(&$lines, &$src, &$dst) $line = next($lines); if ($line === false) { - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_UNEXPECTED_EOF')); + throw new RuntimeException('Unexpected EOF'); } // Search the destination file if (!preg_match(self::DST_FILE, $line, $m)) { - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_INVALID_DIFF')); + throw new RuntimeException('Invalid Diff file'); } // Set the destination file @@ -309,7 +309,7 @@ protected static function findHeader(&$lines, &$src, &$dst) // Advance to the next line if (next($lines) === false) { - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_UNEXPECTED_EOF')); + throw new RuntimeException('Unexpected EOF'); } return true; } @@ -357,7 +357,7 @@ protected static function findHunk(&$lines, &$src_line, &$src_size, &$dst_line, if (next($lines) === false) { - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_UNEXPECTED_EOF')); + throw new RuntimeException('Unexpected EOF'); } return true; @@ -474,7 +474,7 @@ protected function applyHunk(&$lines, $src, $dst, $src_line, $src_size, $dst_lin $line = next($lines); } while ($line !== false); - throw new RuntimeException(JText::_('JLIB_FILESYSTEM_PATCHER_UNEXPECTED_EOF')); + throw new RuntimeException('Unexpected EOF'); } /** From fef3070da5250ae4ea200da7b74836a97aad3e63 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 21:27:35 -0500 Subject: [PATCH 15/98] HTML Package: Exception, JError, ->getError --- libraries/joomla/html/html.php | 4 +-- libraries/joomla/html/html/access.php | 28 ------------------- .../joomla/html/html/contentlanguage.php | 6 ---- libraries/joomla/html/html/list.php | 7 ----- libraries/joomla/html/html/menu.php | 6 ---- libraries/joomla/html/html/select.php | 4 +-- libraries/joomla/html/html/user.php | 13 --------- 7 files changed, 4 insertions(+), 64 deletions(-) diff --git a/libraries/joomla/html/html.php b/libraries/joomla/html/html.php index 7293624c71..952647c347 100644 --- a/libraries/joomla/html/html.php +++ b/libraries/joomla/html/html.php @@ -209,7 +209,7 @@ public static function isRegistered($key) * * @see http://php.net/manual/en/function.call-user-func-array.php * @since 11.1 - * @throws Exception + * @throws InvalidArgumentException */ protected static function call($function, $args) { @@ -225,7 +225,7 @@ protected static function call($function, $args) } else { - throw new Exception(JText::_('JLIB_HTML_ERROR_FUNCTION_NOT_SUPPORTED'), 500); + throw new InvalidArgumentException('Function not supported', 500); } } diff --git a/libraries/joomla/html/html/access.php b/libraries/joomla/html/html/access.php index 071c4fac41..9529e92967 100644 --- a/libraries/joomla/html/html/access.php +++ b/libraries/joomla/html/html/access.php @@ -56,13 +56,6 @@ public static function level($name, $selected, $attribs = '', $params = true, $i $db->setQuery($query); $options = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - return null; - } - // If params is an array, push these options to the array if (is_array($params)) { @@ -112,13 +105,6 @@ public static function usergroup($name, $selected, $attribs = '', $allowAll = tr $db->setQuery($query); $options = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - return null; - } - for ($i = 0, $n = count($options); $i < $n; $i++) { $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; @@ -162,13 +148,6 @@ public static function usergroups($name, $selected, $checkSuperAdmin = false) $db->setQuery($query); $groups = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - return null; - } - $html = array(); $html[] = '
    '; @@ -273,13 +252,6 @@ public static function assetgroups() $db->setQuery($query); self::$asset_groups = $db->loadObjectList(); - - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - return false; - } } return self::$asset_groups; diff --git a/libraries/joomla/html/html/contentlanguage.php b/libraries/joomla/html/html/contentlanguage.php index 786bb4a579..32512dc8f6 100644 --- a/libraries/joomla/html/html/contentlanguage.php +++ b/libraries/joomla/html/html/contentlanguage.php @@ -59,12 +59,6 @@ public static function existing($all = false, $translate = false) { array_unshift(self::$items, new JObject(array('value' => '*', 'text' => $translate ? JText::alt('JALL', 'language') : 'JALL_LANGUAGE'))); } - - // Detect errors - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } } return self::$items; } diff --git a/libraries/joomla/html/html/list.php b/libraries/joomla/html/html/list.php index e5adecc567..09b7d92a7e 100644 --- a/libraries/joomla/html/html/list.php +++ b/libraries/joomla/html/html/list.php @@ -88,13 +88,6 @@ public static function genericordering($sql, $chop = 30) $items = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - return false; - } - if (empty($items)) { $options[] = JHtml::_('select.option', 1, JText::_('JOPTION_ORDER_FIRST')); diff --git a/libraries/joomla/html/html/menu.php b/libraries/joomla/html/html/menu.php index 6a3275d126..8a87b7969e 100644 --- a/libraries/joomla/html/html/menu.php +++ b/libraries/joomla/html/html/menu.php @@ -228,12 +228,6 @@ public static function linkoptions($all = false, $unassigned = false) $mitems = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - } - if (!$mitems) { $mitems = array(); diff --git a/libraries/joomla/html/html/select.php b/libraries/joomla/html/html/select.php index 7cb08da5fc..67d9510fc6 100644 --- a/libraries/joomla/html/html/select.php +++ b/libraries/joomla/html/html/select.php @@ -153,7 +153,7 @@ public static function genericlist($data, $name, $attribs = null, $optKey = 'val * * @since 11.1 * - * @throws JException If a group has unprocessable contents. + * @throws RuntimeException If a group has contents that cannot be processed. */ public static function groupedlist($data, $name, $options = array()) { @@ -241,7 +241,7 @@ public static function groupedlist($data, $name, $options = array()) } else { - throw new JException('Invalid group contents.', 1, E_WARNING); + throw new RuntimeException('Invalid group contents.', 1); } if ($noGroup) diff --git a/libraries/joomla/html/html/user.php b/libraries/joomla/html/html/user.php index 29da7bbf67..11592c8501 100644 --- a/libraries/joomla/html/html/user.php +++ b/libraries/joomla/html/html/user.php @@ -37,13 +37,6 @@ public static function groups() $db->setQuery($query); $options = $db->loadObjectList(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::NOTICE, 'jerror'); - return null; - } - for ($i = 0, $n = count($options); $i < $n; $i++) { $options[$i]->text = str_repeat('- ', $options[$i]->level) . $options[$i]->text; @@ -76,12 +69,6 @@ public static function userlist() $db->setQuery($query); $items = $db->loadObjectList(); - // Detect errors - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } - return $items; } } From 6b59411c071444074cfec1867bdd3002d0815ac6 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 21:43:49 -0500 Subject: [PATCH 16/98] Session Package: Exceptioins --- libraries/joomla/session/storage/apc.php | 4 ++-- libraries/joomla/session/storage/eaccelerator.php | 3 ++- libraries/joomla/session/storage/memcache.php | 4 ++-- libraries/joomla/session/storage/memcached.php | 3 ++- libraries/joomla/session/storage/wincache.php | 4 ++-- libraries/joomla/session/storage/xcache.php | 4 ++-- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/libraries/joomla/session/storage/apc.php b/libraries/joomla/session/storage/apc.php index e133850aad..c34ebe85d7 100644 --- a/libraries/joomla/session/storage/apc.php +++ b/libraries/joomla/session/storage/apc.php @@ -25,13 +25,13 @@ class JSessionStorageApc extends JSessionStorage * @param array $options Optional parameters * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_APC_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('APC Extension is not available', 404); } parent::__construct($options); diff --git a/libraries/joomla/session/storage/eaccelerator.php b/libraries/joomla/session/storage/eaccelerator.php index 46bd0b9106..eeff5a20ea 100644 --- a/libraries/joomla/session/storage/eaccelerator.php +++ b/libraries/joomla/session/storage/eaccelerator.php @@ -25,12 +25,13 @@ class JSessionStorageEaccelerator extends JSessionStorage * @param array $options Optional parameters. * * @since 11.1 + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_EACCELERATOR_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('Eaccelerator Extension is not available', 404); } parent::__construct($options); diff --git a/libraries/joomla/session/storage/memcache.php b/libraries/joomla/session/storage/memcache.php index 1d9efe207d..31880d5d7b 100644 --- a/libraries/joomla/session/storage/memcache.php +++ b/libraries/joomla/session/storage/memcache.php @@ -51,13 +51,13 @@ class JSessionStorageMemcache extends JSessionStorage * @param array $options Optional parameters. * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_MEMCACHE_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('Memcache Extension is not available', 404); } parent::__construct($options); diff --git a/libraries/joomla/session/storage/memcached.php b/libraries/joomla/session/storage/memcached.php index 488729036c..47eed1f120 100644 --- a/libraries/joomla/session/storage/memcached.php +++ b/libraries/joomla/session/storage/memcached.php @@ -51,12 +51,13 @@ class JSessionStorageMemcached extends JSessionStorage * @param array $options Optional parameters. * * @since 11.1 + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_MEMCACHE_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('Memcached Extension is not available', 404); } parent::__construct($options); diff --git a/libraries/joomla/session/storage/wincache.php b/libraries/joomla/session/storage/wincache.php index 26a5013e1c..0b979717c0 100644 --- a/libraries/joomla/session/storage/wincache.php +++ b/libraries/joomla/session/storage/wincache.php @@ -25,13 +25,13 @@ class JSessionStorageWincache extends JSessionStorage * @param array $options Optional parameters. * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_WINCACHE_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('Wincache Extension is not available', 404); } parent::__construct($options); diff --git a/libraries/joomla/session/storage/xcache.php b/libraries/joomla/session/storage/xcache.php index e8a536647a..d00250cf57 100644 --- a/libraries/joomla/session/storage/xcache.php +++ b/libraries/joomla/session/storage/xcache.php @@ -24,13 +24,13 @@ class JSessionStorageXcache extends JSessionStorage * @param array $options Optional parameters. * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function __construct($options = array()) { if (!self::isSupported()) { - throw new Exception(JText::_('JLIB_SESSION_XCACHE_EXTENSION_NOT_AVAILABLE'), 404); + throw new RuntimeException('XCache Extension is not available', 404); } parent::__construct($options); From 2620175b5ebebe2e644f1f8cb0a38c31d16edb73 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 17:37:34 -0500 Subject: [PATCH 17/98] Plugin Package: Remove one ->getErrorMsg --- libraries/joomla/plugin/helper.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/libraries/joomla/plugin/helper.php b/libraries/joomla/plugin/helper.php index cf52aee801..717976fb31 100644 --- a/libraries/joomla/plugin/helper.php +++ b/libraries/joomla/plugin/helper.php @@ -236,12 +236,6 @@ protected static function _load() self::$plugins = $db->setQuery($query)->loadObjectList(); - if ($error = $db->getErrorMsg()) - { - JLog::add($error, JLog::WARNING, 'jerror'); - return false; - } - $cache->store(self::$plugins, $levels); } From 0e9cd02d4624047d3f3a0131a7286433d37064d6 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 18:25:06 -0500 Subject: [PATCH 18/98] Installer Package: db->error removal --- .../joomla/installer/adapters/component.php | 21 +------------------ .../joomla/installer/adapters/language.php | 2 +- libraries/joomla/installer/installer.php | 4 ++-- 3 files changed, 4 insertions(+), 23 deletions(-) diff --git a/libraries/joomla/installer/adapters/component.php b/libraries/joomla/installer/adapters/component.php index c862959cb0..14717eea9a 100644 --- a/libraries/joomla/installer/adapters/component.php +++ b/libraries/joomla/installer/adapters/component.php @@ -1133,14 +1133,6 @@ public function uninstall($id) $db->setQuery($query); $db->execute(); - // Check for errors. - if ($db->getErrorNum()) - { - JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_UNINSTALL_FAILED_DELETE_CATEGORIES'), JLog::WARNING, 'jerror'); - $this->setError($db->getErrorMsg()); - $retval = false; - } - // Clobber any possible pending updates $update = JTable::getInstance('update'); $uid = $update->find(array('element' => $row->element, 'type' => 'component', 'client_id' => '', 'folder' => '')); @@ -1423,18 +1415,7 @@ protected function _removeAdminMenus(&$row) $ids = $db->loadColumn(); // Check for error - if ($error = $db->getErrorMsg()) - { - JLog::add(JText::_('JLIB_INSTALLER_ERROR_COMP_REMOVING_ADMIN_MENUS_FAILED'), JLog::WARNING, 'jerror'); - - if ($error && $error != 1) - { - JLog::add($error, JLog::WARNING, 'jerror'); - } - - return false; - } - elseif (!empty($ids)) + if (!empty($ids)) { // Iterate the items to delete each one. foreach ($ids as $menuid) diff --git a/libraries/joomla/installer/adapters/language.php b/libraries/joomla/installer/adapters/language.php index ca120be1f7..060b8f44d1 100644 --- a/libraries/joomla/installer/adapters/language.php +++ b/libraries/joomla/installer/adapters/language.php @@ -520,7 +520,7 @@ public function uninstall($eid) } if (!empty($count)) { - JError::raiseNotice(500, JText::plural('JLIB_INSTALLER_NOTICE_LANG_RESET_USERS', $count)); + JLog::add(JText::plural('JLIB_INSTALLER_NOTICE_LANG_RESET_USERS', $count), JLog::NOTICE, 'jerror'); } // All done! diff --git a/libraries/joomla/installer/installer.php b/libraries/joomla/installer/installer.php index 59a25a577e..1104d6c3df 100644 --- a/libraries/joomla/installer/installer.php +++ b/libraries/joomla/installer/installer.php @@ -306,7 +306,7 @@ public function pushStep($step) * @return boolean True if successful * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public function abort($msg = null, $type = null) { @@ -388,7 +388,7 @@ public function abort($msg = null, $type = null) if ($debug) { - throw new Exception(JText::_('JLIB_INSTALLER_ABORT_DEBUG') . $msg, 500); + throw new RuntimeException('Installation unexpectedly terminated: ' . $msg, 500); } return $retval; From ff5994a9a7510b0d4ee8049763bae10ef3ac0a62 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 18:49:53 -0500 Subject: [PATCH 19/98] Database Package: Exception JText --- libraries/joomla/database/driver.php | 10 +++++----- libraries/joomla/database/driver/mysql.php | 6 +++--- libraries/joomla/database/driver/mysqli.php | 6 +++--- libraries/joomla/database/driver/pdo.php | 4 ++-- libraries/joomla/database/driver/postgresql.php | 10 +++++----- libraries/joomla/database/driver/sqlsrv.php | 6 +++--- libraries/joomla/database/factory.php | 10 +++++----- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php index 9b318038de..8367a95dc3 100644 --- a/libraries/joomla/database/driver.php +++ b/libraries/joomla/database/driver.php @@ -249,7 +249,7 @@ public static function getInstance($options = array()) // If the class still doesn't exist we have nothing left to do but throw an exception. We did our best. if (!class_exists($class)) { - throw new RuntimeException(JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver'])); + throw new RuntimeException(sprintf('Unable to load Database Driver: %s', $options['driver'])); } // Create our new JDatabaseDriver connector based on the options given. @@ -259,7 +259,7 @@ public static function getInstance($options = array()) } catch (RuntimeException $e) { - throw new RuntimeException(JText::sprintf('JLIB_DATABASE_ERROR_CONNECT_DATABASE', $e->getMessage())); + throw new RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage())); } // Set the new connector to the global instances based on signature. @@ -607,7 +607,7 @@ public function getExporter() if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_EXPORTER')); + throw new RuntimeException('Database Exporter not found.'); } $o = new $class; @@ -633,7 +633,7 @@ public function getImporter() if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_IMPORTER')); + throw new RuntimeException('Database Importer not found'); } $o = new $class; @@ -663,7 +663,7 @@ public function getQuery($new = false) if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_QUERY')); + throw new RuntimeException('Database Query Class not found.'); } return new $class($this); diff --git a/libraries/joomla/database/driver/mysql.php b/libraries/joomla/database/driver/mysql.php index 59e5eb76fc..74da36e024 100644 --- a/libraries/joomla/database/driver/mysql.php +++ b/libraries/joomla/database/driver/mysql.php @@ -91,13 +91,13 @@ public function connect() // Make sure the MySQL extension for PHP is installed and enabled. if (!function_exists('mysql_connect')) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQL')); + throw new RuntimeException('Could not connect to MySQL.'); } // Attempt to connect to the server. if (!($this->connection = @ mysql_connect($this->options['host'], $this->options['user'], $this->options['password'], true))) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL')); + throw new RuntimeException('Could not connect to MySQL.'); } // Set sql_mode to non_strict mode @@ -534,7 +534,7 @@ public function select($database) if (!mysql_select_db($database, $this->connection)) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT')); + throw new RuntimeException('Could not connect to database'); } return true; diff --git a/libraries/joomla/database/driver/mysqli.php b/libraries/joomla/database/driver/mysqli.php index c581bfb186..4ba21ca070 100644 --- a/libraries/joomla/database/driver/mysqli.php +++ b/libraries/joomla/database/driver/mysqli.php @@ -105,7 +105,7 @@ public function connect() } else { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI')); + throw new RuntimeException('The MySQL adapter mysqli is not available'); } } @@ -116,7 +116,7 @@ public function connect() // Attempt to connect to the server. if (!$this->connection) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_CONNECT_MYSQL')); + throw new RuntimeException('Could not connect to MySQL.'); } // Set sql_mode to non_strict mode @@ -356,7 +356,7 @@ public function select($database) if (!mysqli_select_db($this->connection, $database)) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT')); + throw new RuntimeException('Could not connect to database.'); } return true; diff --git a/libraries/joomla/database/driver/pdo.php b/libraries/joomla/database/driver/pdo.php index b2c95801ad..4696497d68 100644 --- a/libraries/joomla/database/driver/pdo.php +++ b/libraries/joomla/database/driver/pdo.php @@ -271,7 +271,7 @@ public function connect() // Make sure the PDO extension for PHP is installed and enabled. if (!self::isSupported()) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_PDO'), 1); + throw new RuntimeException('PDO Extension is not available.', 1); } try @@ -285,7 +285,7 @@ public function connect() } catch (PDOException $e) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_CONNECT_PDO') . ': ' . $e->getMessage(), 2); + throw new RuntimeException('Could not connect to PDO' . ': ' . $e->getMessage(), 2); } } diff --git a/libraries/joomla/database/driver/postgresql.php b/libraries/joomla/database/driver/postgresql.php index c24b385f4e..38850984bb 100644 --- a/libraries/joomla/database/driver/postgresql.php +++ b/libraries/joomla/database/driver/postgresql.php @@ -92,10 +92,10 @@ public function connect() return; } - // Make sure the MySQL extension for PHP is installed and enabled. + // Make sure the postgresql extension for PHP is installed and enabled. if (!function_exists('pg_connect')) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_POSTGRESQL')); + throw new RuntimeException('PHP extension pg_connect is not available.'); } // Build the DSN for the connection. @@ -104,7 +104,7 @@ public function connect() // Attempt to connect to the server. if (!($this->connection = @pg_connect($dsn))) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_CONNECT_POSTGRESQL')); + throw new RuntimeException('Error connecting to PGSQL database.'); } pg_set_error_verbosity($this->connection, PGSQL_ERRORS_DEFAULT); @@ -263,7 +263,7 @@ public function getQuery($new = false, $asObj = false) // Make sure we have a query class for this driver. if (!class_exists('JDatabaseQueryPostgresql')) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_QUERY')); + throw new RuntimeException('JDatabaseQueryPostgresql Class not found.'); } $this->queryObject = new JDatabaseQueryPostgresql($this); @@ -678,7 +678,7 @@ public function renameTable($oldTable, $newTable, $backup = null, $prefix = null if ( !in_array($oldTable, $tableList) ) { // Origin Table not found - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_POSTGRESQL_TABLE_NOT_FOUND')); + throw new RuntimeException('Table not found in Postgresql database.'); } else { diff --git a/libraries/joomla/database/driver/sqlsrv.php b/libraries/joomla/database/driver/sqlsrv.php index 89ba61774d..3e5bb2eb72 100644 --- a/libraries/joomla/database/driver/sqlsrv.php +++ b/libraries/joomla/database/driver/sqlsrv.php @@ -111,13 +111,13 @@ public function connect() // Make sure the SQLSRV extension for PHP is installed and enabled. if (!function_exists('sqlsrv_connect')) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_ADAPTER_SQLSRV')); + throw new RuntimeException('PHP extension sqlsrv_connect is not available.'); } // Attempt to connect to the server. if (!($this->connection = @ sqlsrv_connect($this->options['host'], $config))) { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_CONNECT_SQLSRV')); + throw new RuntimeException('Database sqlsrv_connect failed'); } // Make sure that DB warnings are not returned as errors. @@ -750,7 +750,7 @@ public function select($database) } else { - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT')); + throw new RuntimeException('Could not connect to database'); } } diff --git a/libraries/joomla/database/factory.php b/libraries/joomla/database/factory.php index 83c808f299..49dac696be 100644 --- a/libraries/joomla/database/factory.php +++ b/libraries/joomla/database/factory.php @@ -56,7 +56,7 @@ public function getDriver($name = 'mysql', $options = array()) // If the class still doesn't exist we have nothing left to do but throw an exception. We did our best. if (!class_exists($class)) { - throw new RuntimeException(JText::sprintf('JLIB_DATABASE_ERROR_LOAD_DATABASE_DRIVER', $options['driver'])); + throw new RuntimeException(sprintf('Unable to load Database Driver: %s', $options['driver'])); } // Create our new JDatabaseDriver connector based on the options given. @@ -66,7 +66,7 @@ public function getDriver($name = 'mysql', $options = array()) } catch (RuntimeException $e) { - throw new RuntimeException(JText::sprintf('JLIB_DATABASE_ERROR_CONNECT_DATABASE', $e->getMessage())); + throw new RuntimeException(sprintf('Unable to connect to the Database: %s', $e->getMessage())); } return $instance; @@ -92,7 +92,7 @@ public function getExporter($name, JDatabaseDriver $db = null) if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_EXPORTER')); + throw new RuntimeException('Database Exporter not found.'); } $o = new $class; @@ -125,7 +125,7 @@ public function getImporter($name, JDatabaseDriver $db = null) if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_IMPORTER')); + throw new RuntimeException('Database importer not found.'); } $o = new $class; @@ -170,7 +170,7 @@ public function getQuery($name, JDatabaseDriver $db = null) if (!class_exists($class)) { // If it doesn't exist we are at an impasse so throw an exception. - throw new RuntimeException(JText::_('JLIB_DATABASE_ERROR_MISSING_QUERY')); + throw new RuntimeException('Database Query class not found'); } return new $class($db); From fe137274f1306a054eca570f0a2eb9ab0568dcae Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Sun, 1 Apr 2012 14:01:34 +0530 Subject: [PATCH 20/98] for issue #708 avoid division by zero Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 4bb423f6ee..c0c9b11887 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -671,9 +671,18 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: + if($width==0 && $height!=0){ // To avoid dividing by $width if it is zero + $rx = $this->getWidth() ; + $ry = $this->getHeight() / $height; + } + elseif ($width!=0 && $height==0) { // To avoid dividing by $height if it is zero + $rx = $this->getWidth() / $width; + $ry = $this->getHeight() ; + } + else{ // If both $width and $height are not equals to zero $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; - + } if ($scaleMethod == self::SCALE_INSIDE) { $ratio = ($rx > $ry) ? $rx : $ry; From 70f50dae411398b8cc9f89fa3b9d1b6160451e27 Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Sun, 1 Apr 2012 14:14:32 +0530 Subject: [PATCH 21/98] commit 2 for issue #708 Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index c0c9b11887..617e02b1b5 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -679,6 +679,10 @@ protected function prepareDimensions($width, $height, $scaleMethod) $rx = $this->getWidth() / $width; $ry = $this->getHeight() ; } + else if($width==0 && $height==0){ // Both $height and $width are zero + $rx = $this->getWidth() / $width; + $ry = $this->getHeight() ; + } else{ // If both $width and $height are not equals to zero $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; From ea996174c8d055dacc702d095ca5d2fafa9f5bbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 1 Apr 2012 10:38:46 +0200 Subject: [PATCH 22/98] Some small fixes to recent commits. --- libraries/joomla/mail/mail.php | 3 ++- libraries/joomla/user/helper.php | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/libraries/joomla/mail/mail.php b/libraries/joomla/mail/mail.php index bb2043f622..632340d0d0 100644 --- a/libraries/joomla/mail/mail.php +++ b/libraries/joomla/mail/mail.php @@ -271,6 +271,7 @@ public function addBCC($bcc, $name = '') * @return JMail Returns this object for chaining. * * @since 11.1 + * @throws InvalidArgumentException */ public function addAttachment($attachment, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { @@ -281,7 +282,7 @@ public function addAttachment($attachment, $name = '', $encoding = 'base64', $ty { if (!empty($name) && count($attachment) != count($name)) { - throw new RuntimeException("The number of attachments must be equal with the number of name"); + throw new InvalidArgumentException("The number of attachments must be equal with the number of name"); } foreach ($attachment as $key => $file) diff --git a/libraries/joomla/user/helper.php b/libraries/joomla/user/helper.php index 87d9a39a0c..eba1d9bd58 100644 --- a/libraries/joomla/user/helper.php +++ b/libraries/joomla/user/helper.php @@ -27,7 +27,7 @@ abstract class JUserHelper * @param integer $userId The id of the user. * @param integer $groupId The id of the group. * - * @return mixed Boolean true on success + * @return boolean True on success * * @since 11.1 * @throws RuntimeException @@ -81,7 +81,7 @@ public static function addUserToGroup($userId, $groupId) * * @param integer $userId The id of the user. * - * @return mixed Array on success + * @return array List of groups * * @since 11.1 */ @@ -99,7 +99,7 @@ public static function getUserGroups($userId) * @param integer $userId The id of the user. * @param integer $groupId The id of the group. * - * @return mixed Boolean true on success + * @return boolean True on success * * @since 11.1 */ @@ -139,7 +139,7 @@ public static function removeUserFromGroup($userId, $groupId) * @param integer $userId The id of the user. * @param array $groups An array of group ids to put the user in. * - * @return mixed Boolean true on success + * @return boolean True on success * * @since 11.1 */ From c2d2999599f4143fe83d1e09ae3ccbc57958571b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 1 Apr 2012 10:59:11 +0200 Subject: [PATCH 23/98] Remove a useless todo. --- libraries/joomla/table/table.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 242d7496f2..8239bd5e1f 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -995,7 +995,6 @@ public function hit($pk = null) * * @link http://docs.joomla.org/JTable/isCheckedOut * @since 11.1 - * @todo This either needs to be static or not. */ public function isCheckedOut($with = 0, $against = null) { From 6d8ea6cf0203756e2f07041df22179b4dc89506f Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Sun, 1 Apr 2012 17:27:17 +0530 Subject: [PATCH 24/98] comments are aligned and changes to one elseif Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 617e02b1b5..d880a4d0a0 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -671,19 +671,27 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: - if($width==0 && $height!=0){ // To avoid dividing by $width if it is zero + + // To avoid dividing by $width if it is zero + if($width==0 && $height!=0){ $rx = $this->getWidth() ; $ry = $this->getHeight() / $height; } - elseif ($width!=0 && $height==0) { // To avoid dividing by $height if it is zero + + // To avoid dividing by $height if it is zero + elseif ($width!=0 && $height==0) { $rx = $this->getWidth() / $width; $ry = $this->getHeight() ; } - else if($width==0 && $height==0){ // Both $height and $width are zero + + // Both $height and $width are zero + elseif($width==0 && $height==0){ $rx = $this->getWidth() / $width; $ry = $this->getHeight() ; } - else{ // If both $width and $height are not equals to zero + + // If both $width and $height are not equals to zero + else{ $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; } From d89baaa4342113f5f7904bff88c827f8b9249df1 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 15:29:25 -0500 Subject: [PATCH 25/98] Mail package: Exception and JError --- libraries/joomla/mail/mail.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/mail/mail.php b/libraries/joomla/mail/mail.php index bb2043f622..0d1eed8c58 100644 --- a/libraries/joomla/mail/mail.php +++ b/libraries/joomla/mail/mail.php @@ -67,23 +67,23 @@ public static function getInstance($id = 'Joomla') /** * Send the mail * - * @return mixed True if successful, a JError object otherwise + * @return boolean True if successful * * @since 11.1 + * @throws RuntimeException */ public function Send() { if (($this->Mailer == 'mail') && !function_exists('mail')) { - return JError::raiseNotice(500, JText::_('JLIB_MAIL_FUNCTION_DISABLED')); + throw new RuntimeException('Send function cancelled because mail is disabled.'); } @$result = parent::Send(); if ($result == false) { - // TODO: Set an appropriate error number - $result = JError::raiseNotice(500, JText::_($this->ErrorInfo)); + throw new RuntimeException('phpMail Send email failed'); } return $result; @@ -271,6 +271,7 @@ public function addBCC($bcc, $name = '') * @return JMail Returns this object for chaining. * * @since 11.1 + * @throws RuntimeException */ public function addAttachment($attachment, $name = '', $encoding = 'base64', $type = 'application/octet-stream') { From c732063b00ec037b4c56b1bcc4291aad1d7482b9 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Fri, 30 Mar 2012 15:00:10 -0500 Subject: [PATCH 26/98] Cache Package: return JError --- libraries/joomla/cache/cache.php | 1 - libraries/joomla/cache/controller.php | 4 ++-- libraries/joomla/cache/storage.php | 6 ++++-- libraries/joomla/cache/storage/memcache.php | 4 ++-- libraries/joomla/cache/storage/memcached.php | 4 ++-- 5 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libraries/joomla/cache/cache.php b/libraries/joomla/cache/cache.php index aedff439a7..8563fb1084 100644 --- a/libraries/joomla/cache/cache.php +++ b/libraries/joomla/cache/cache.php @@ -433,7 +433,6 @@ public function &_getStorage() } self::$_handler[$hash] = JCacheStorage::getInstance($this->_options['storage'], $this->_options); - return self::$_handler[$hash]; } diff --git a/libraries/joomla/cache/controller.php b/libraries/joomla/cache/controller.php index 4953c07f68..752e7de887 100644 --- a/libraries/joomla/cache/controller.php +++ b/libraries/joomla/cache/controller.php @@ -77,7 +77,7 @@ public function __call($name, $arguments) * @return JCache A JCache object * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ public static function getInstance($type = 'output', $options = array()) { @@ -98,7 +98,7 @@ public static function getInstance($type = 'output', $options = array()) } else { - throw new Exception('Unable to load Cache Controller: ' . $type, 500); + throw new RuntimeException('Unable to load Cache Controller: ' . $type, 500); } } diff --git a/libraries/joomla/cache/storage.php b/libraries/joomla/cache/storage.php index 556ed61a3d..06ac501b0e 100644 --- a/libraries/joomla/cache/storage.php +++ b/libraries/joomla/cache/storage.php @@ -101,6 +101,8 @@ public function __construct($options = array()) * @return JCacheStorage A JCacheStorage instance * * @since 11.1 + * @throws UnexpectedValueException + * @throws RuntimeException */ public static function getInstance($handler = null, $options = array()) { @@ -114,7 +116,7 @@ public static function getInstance($handler = null, $options = array()) $handler = $conf->get('cache_handler'); if (empty($handler)) { - return JError::raiseWarning(500, JText::_('JLIB_CACHE_ERROR_CACHE_HANDLER_NOT_SET')); + throw new UnexpectedValueException('Cache Storage Handler not set.'); } } @@ -139,7 +141,7 @@ public static function getInstance($handler = null, $options = array()) } else { - return JError::raiseWarning(500, JText::sprintf('JLIB_CACHE_ERROR_CACHE_STORAGE_LOAD', $handler)); + throw new RuntimeException(sprintf('Unable to load Cache Storage: %s', $handler)); } } diff --git a/libraries/joomla/cache/storage/memcache.php b/libraries/joomla/cache/storage/memcache.php index 68a81251ae..207e5ee90b 100644 --- a/libraries/joomla/cache/storage/memcache.php +++ b/libraries/joomla/cache/storage/memcache.php @@ -59,7 +59,7 @@ public function __construct($options = array()) * @return object memcache connection object * * @since 11.1 - * @throws Exception + * @throws RuntimeException */ protected function getConnection() { @@ -88,7 +88,7 @@ protected function getConnection() $memcachetest = @self::$_db->connect($server['host'], $server['port']); if ($memcachetest == false) { - throw new Exception('Could not connect to memcache server', 404); + throw new RuntimeException('Could not connect to memcache server', 404); } // Memcahed has no list keys, we do our own accounting, initialise key index diff --git a/libraries/joomla/cache/storage/memcached.php b/libraries/joomla/cache/storage/memcached.php index 65c8e9bfba..99dbba212c 100644 --- a/libraries/joomla/cache/storage/memcached.php +++ b/libraries/joomla/cache/storage/memcached.php @@ -59,7 +59,7 @@ public function __construct($options = array()) * @return object memcached connection object * * @since 12.1 - * @throws Exception + * @throws RuntimeException */ protected function getConnection() { @@ -95,7 +95,7 @@ protected function getConnection() if ($memcachedtest == false) { - throw new Exception('Could not connect to memcached server', 404); + throw new RuntimeException('Could not connect to memcached server', 404); } self::$_db->setOption(Memcached::OPT_COMPRESSION, $this->_compress); From 12a5671fa27680933a1de3bf197537f871ef0cf3 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 1 Apr 2012 19:32:57 +0200 Subject: [PATCH 27/98] Set JInputFiles constructor --- libraries/joomla/input/files.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/libraries/joomla/input/files.php b/libraries/joomla/input/files.php index 141965ea59..f1869578d1 100644 --- a/libraries/joomla/input/files.php +++ b/libraries/joomla/input/files.php @@ -20,6 +20,32 @@ class JInputFiles extends JInput { protected $decodedData = array(); + /** + * Constructor. + * + * @param array $source Ignored. + * @param array $options Array of configuration parameters (Optional) + * + * @since 12.1 + */ + public function __construct(array $source = null, array $options = array()) + { + if (isset($options['filter'])) + { + $this->filter = $options['filter']; + } + else + { + $this->filter = JFilterInput::getInstance(); + } + + // Set the data source. + $this->data = & $_FILES; + + // Set the options for the class. + $this->options = $options; + } + /** * Gets a value from the input data. * From 70212391c4b51640f2c77df8904267aaacb43faa Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 18:01:16 -0500 Subject: [PATCH 28/98] Form Package: db->error, Exception/JText modifications --- .../joomla/form/fields/componentlayout.php | 6 --- libraries/joomla/form/fields/modulelayout.php | 6 --- libraries/joomla/form/fields/plugins.php | 7 --- libraries/joomla/form/fields/rules.php | 5 -- libraries/joomla/form/fields/sql.php | 7 --- libraries/joomla/form/form.php | 47 +++++++++---------- libraries/joomla/form/rules/email.php | 7 --- libraries/joomla/form/rules/equals.php | 8 ++-- libraries/joomla/form/rules/username.php | 6 --- 9 files changed, 25 insertions(+), 74 deletions(-) diff --git a/libraries/joomla/form/fields/componentlayout.php b/libraries/joomla/form/fields/componentlayout.php index 8a8271886f..e2029ea97f 100644 --- a/libraries/joomla/form/fields/componentlayout.php +++ b/libraries/joomla/form/fields/componentlayout.php @@ -115,12 +115,6 @@ protected function getInput() $db->setQuery($query); $templates = $db->loadObjectList('element'); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } - // Build the search paths for component layouts. $component_path = JPath::clean($client->path . '/components/' . $extn . '/views/' . $view . '/tmpl'); diff --git a/libraries/joomla/form/fields/modulelayout.php b/libraries/joomla/form/fields/modulelayout.php index 9bd20700b7..d12894f0d6 100644 --- a/libraries/joomla/form/fields/modulelayout.php +++ b/libraries/joomla/form/fields/modulelayout.php @@ -108,12 +108,6 @@ protected function getInput() $db->setQuery($query); $templates = $db->loadObjectList('element'); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } - // Build the search paths for module layouts. $module_path = JPath::clean($client->path . '/modules/' . $module . '/tmpl'); diff --git a/libraries/joomla/form/fields/plugins.php b/libraries/joomla/form/fields/plugins.php index 0cb7b9f854..1fbd06c56c 100644 --- a/libraries/joomla/form/fields/plugins.php +++ b/libraries/joomla/form/fields/plugins.php @@ -65,13 +65,6 @@ protected function getOptions() || $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false); $options[$i]->text = JText::_($item->text); } - - if ($db->getErrorMsg()) - { - JLog::add(JText::_('JFRAMEWORK_FORM_FIELDS_PLUGINS_ERROR_FOLDER_EMPTY'), JLog::WARNING, 'jerror'); - return ''; - } - } else { diff --git a/libraries/joomla/form/fields/rules.php b/libraries/joomla/form/fields/rules.php index 20a432954a..31880ea7eb 100644 --- a/libraries/joomla/form/fields/rules.php +++ b/libraries/joomla/form/fields/rules.php @@ -71,11 +71,6 @@ protected function getInput() $query->where($db->quoteName('name') . ' = ' . $db->quote($component)); $db->setQuery($query); $assetId = (int) $db->loadResult(); - - if ($error = $db->getErrorMsg()) - { - JLog::add($error, JLog::WARNING, 'jerror'); - } } else { diff --git a/libraries/joomla/form/fields/sql.php b/libraries/joomla/form/fields/sql.php index b88f0a0fcf..bc53b3b13d 100644 --- a/libraries/joomla/form/fields/sql.php +++ b/libraries/joomla/form/fields/sql.php @@ -54,13 +54,6 @@ protected function getOptions() $db->setQuery($query); $items = $db->loadObjectlist(); - // Check for an error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - return $options; - } - // Build the field options. if (!empty($items)) { diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index 46b9d02349..bb81a5dfb8 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -301,15 +301,14 @@ public function getField($name, $group = null, $value = null) * @return mixed The attribute value for the field. * * @since 11.1 + * @throws UnexpectedValueException */ public function getFieldAttribute($name, $attribute, $default = null, $group = null) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - - return $default; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Find the form field element from the definition. @@ -782,14 +781,14 @@ public function loadFile($file, $reset = true, $xpath = false) * @return boolean True on success. * * @since 11.1 + * @throws UnexpectedValueException */ public function removeField($name, $group = null) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - return false; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Find the form field element from the definition. @@ -813,14 +812,14 @@ public function removeField($name, $group = null) * @return boolean True on success. * * @since 11.1 + * @throws UnexpectedValueException */ public function removeGroup($group) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - return false; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Get the fields elements for a given group. @@ -869,15 +868,14 @@ public function reset($xml = false) * @return boolean True on success. * * @since 11.1 + * @throws UnexpectedValueException */ public function setField(JXMLElement $element, $group = null, $replace = true) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - - return false; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Find the form field element from the definition. @@ -933,15 +931,14 @@ public function setField(JXMLElement $element, $group = null, $replace = true) * @return boolean True on success. * * @since 11.1 + * @throws UnexpectedValueException */ public function setFieldAttribute($name, $attribute, $value, $group = null) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - - return false; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Find the form field element from the definition. @@ -977,15 +974,14 @@ public function setFieldAttribute($name, $attribute, $value, $group = null) * @return boolean True on success. * * @since 11.1 + * @throws UnexpectedValueException */ public function setFields(&$elements, $group = null, $replace = true) { // Make sure there is a valid JForm XML document. if (!($this->xml instanceof JXMLElement)) { - // TODO: throw exception. - - return false; + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); } // Make sure the elements to set are valid. @@ -993,9 +989,7 @@ public function setFields(&$elements, $group = null, $replace = true) { if (!($element instanceof JXMLElement)) { - // TODO: throw exception. - - return false; + throw new RuntimeException('Element is not an instance of JXMLElement'); } } @@ -1829,13 +1823,15 @@ protected function syncPaths() * @return mixed Boolean true if field value is valid, JException on failure. * * @since 11.1 + * @throws RuntimeException + * @throws InvalidArgumentException */ protected function validateField($element, $group = null, $value = null, $input = null) { // Make sure there is a valid JXMLElement. if (!$element instanceof JXMLElement) { - return new JException(JText::_('JLIB_FORM_ERROR_VALIDATE_FIELD'), -1, E_ERROR); + throw new InvalidArgumentException('Form field validation error'); } // Initialise variables. @@ -1865,9 +1861,9 @@ protected function validateField($element, $group = null, $value = null, $input { $message = JText::_($element['name']); } - $message = JText::sprintf('JLIB_FORM_VALIDATE_FIELD_REQUIRED', $message); + $message = sprintf('Field required: %s', $message); } - return new JException($message, 2, E_WARNING); + throw new RuntimeException($message); } } @@ -1880,7 +1876,7 @@ protected function validateField($element, $group = null, $value = null, $input // If the object could not be loaded return an error message. if ($rule === false) { - return new JException(JText::sprintf('JLIB_FORM_VALIDATE_FIELD_RULE_MISSING', $type), -2, E_ERROR); + throw new InvalidArgumentException(sprintf('Validation Rule missing: %s', $type)); } // Run the field validation rule test. @@ -1902,11 +1898,11 @@ protected function validateField($element, $group = null, $value = null, $input if ($message) { - return new JException(JText::_($message), 1, E_WARNING); + throw new RuntimeException($message, 1, E_WARNING); } else { - return new JException(JText::sprintf('JLIB_FORM_VALIDATE_FIELD_INVALID', JText::_((string) $element['label'])), 1, E_WARNING); + throw new InvalidArgumentException((string) $element['label']); } } @@ -2020,7 +2016,6 @@ public static function getInstance($name, $data = null, $options = array(), $rep * @return void * * @since 11.1 - * @throws Exception if an error occurs. */ protected static function addNode(SimpleXMLElement $source, SimpleXMLElement $new) { diff --git a/libraries/joomla/form/rules/email.php b/libraries/joomla/form/rules/email.php index 4edceebb1e..6316566d8e 100644 --- a/libraries/joomla/form/rules/email.php +++ b/libraries/joomla/form/rules/email.php @@ -40,7 +40,6 @@ class JFormRuleEmail extends JFormRule * @return boolean True if the value is valid, false otherwise. * * @since 11.1 - * @throws JException on invalid rule. */ public function test($element, $value, $group = null, $input = null, $form = null) { @@ -79,12 +78,6 @@ public function test($element, $value, $group = null, $input = null, $form = nul $db->setQuery($query); $duplicate = (bool) $db->loadResult(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } - if ($duplicate) { return false; diff --git a/libraries/joomla/form/rules/equals.php b/libraries/joomla/form/rules/equals.php index 3f3c427331..cc0cd72cc7 100644 --- a/libraries/joomla/form/rules/equals.php +++ b/libraries/joomla/form/rules/equals.php @@ -34,9 +34,9 @@ class JFormRuleEquals extends JFormRule * @return boolean True if the value is valid, false otherwise. * * @since 11.1 - * @throws JException on invalid rule. + * @throws InvalidArgumentException */ - public function test($element, $value, $group = null, $input = null, $form = null) + public function test($element, $value, $group = null, $input = null, JForm $form = null) { // Initialize variables. $field = (string) $element['field']; @@ -44,13 +44,13 @@ public function test($element, $value, $group = null, $input = null, $form = nul // Check that a validation field is set. if (!$field) { - return new JException(JText::sprintf('JLIB_FORM_INVALID_FORM_RULE', get_class($this))); + throw new InvalidArgumentException(sprintf('Invalid Form Rule: :%s', get_class($this))); } // Check that a valid JForm object is given for retrieving the validation field value. if (!($form instanceof JForm)) { - return new JException(JText::sprintf('JLIB_FORM_INVALID_FORM_OBJECT', get_class($this))); + throw new InvalidArgumentException(sprintf('Invalid Form Object: :%s', get_class($this))); } // Test the two values against each other. diff --git a/libraries/joomla/form/rules/username.php b/libraries/joomla/form/rules/username.php index 68b216e7b1..28137525f1 100644 --- a/libraries/joomla/form/rules/username.php +++ b/libraries/joomla/form/rules/username.php @@ -52,12 +52,6 @@ public function test($element, $value, $group = null, $input = null, $form = nul $db->setQuery($query); $duplicate = (bool) $db->loadResult(); - // Check for a database error. - if ($db->getErrorNum()) - { - JLog::add($db->getErrorMsg(), JLog::WARNING, 'jerror'); - } - if ($duplicate) { return false; From abcc3e04b515a60f425a9527b3a775c3cef69752 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sat, 31 Mar 2012 14:57:13 -0500 Subject: [PATCH 29/98] Table Package: db error and Exception/JText changes --- libraries/joomla/table/asset.php | 16 +-- libraries/joomla/table/extension.php | 7 - libraries/joomla/table/menutype.php | 24 +--- libraries/joomla/table/session.php | 11 +- libraries/joomla/table/table.php | 189 +++++---------------------- libraries/joomla/table/user.php | 86 +----------- libraries/joomla/table/usergroup.php | 28 +--- 7 files changed, 50 insertions(+), 311 deletions(-) diff --git a/libraries/joomla/table/asset.php b/libraries/joomla/table/asset.php index e33eb107a5..00d61d8c84 100644 --- a/libraries/joomla/table/asset.php +++ b/libraries/joomla/table/asset.php @@ -87,12 +87,7 @@ public function loadByName($name) { return false; } - // Check for a database error. - if ($error = $this->_db->getErrorMsg()) - { - $this->setError($error); - return false; - } + return $this->load($assetId); } @@ -124,14 +119,7 @@ public function check() } else { - if ($error = $this->_db->getErrorMsg()) - { - $this->setError($error); - } - else - { - $this->setError(JText::_('JLIB_DATABASE_ERROR_INVALID_PARENT_ID')); - } + $this->setError('Invalid Parent ID'); return false; } } diff --git a/libraries/joomla/table/extension.php b/libraries/joomla/table/extension.php index f9f3b7d125..7af43f3fa0 100644 --- a/libraries/joomla/table/extension.php +++ b/libraries/joomla/table/extension.php @@ -168,13 +168,6 @@ public function publish($pks = null, $state = 1, $userId = 0) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - // If checkin is supported and all rows were adjusted, check them in. if ($checkin && (count($pks) == $this->_db->getAffectedRows())) { diff --git a/libraries/joomla/table/menutype.php b/libraries/joomla/table/menutype.php index 28acd6bd1e..a457c678ed 100644 --- a/libraries/joomla/table/menutype.php +++ b/libraries/joomla/table/menutype.php @@ -134,11 +134,7 @@ public function store($updateNulls = false) $query->set('menutype=' . $this->_db->quote($this->menutype)); $query->where('menutype=' . $this->_db->quote($table->menutype)); $this->_db->setQuery($query); - if (!$this->_db->execute()) - { - $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg())); - return false; - } + $this->_db->execute(); // Update the module items $query = $this->_db->getQuery(true); @@ -150,11 +146,7 @@ public function store($updateNulls = false) $query->where('module=' . $this->_db->quote('mod_menu')); $query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%')); $this->_db->setQuery($query); - if (!$this->_db->execute()) - { - $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg())); - return false; - } + $this->_db->execute(); } return parent::store($updateNulls); } @@ -221,11 +213,7 @@ public function delete($pk = null) $query->where('menutype=' . $this->_db->quote($table->menutype)); $query->where('client_id=0'); $this->_db->setQuery($query); - if (!$this->_db->execute()) - { - $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg())); - return false; - } + $this->_db->execute(); // Update the module items $query = $this->_db->getQuery(true); @@ -234,11 +222,7 @@ public function delete($pk = null) $query->where('module=' . $this->_db->quote('mod_menu')); $query->where('params LIKE ' . $this->_db->quote('%"menutype":' . json_encode($table->menutype) . '%')); $this->_db->setQuery($query); - if (!$this->_db->execute()) - { - $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg())); - return false; - } + $this->_db->execute(); } return parent::delete($pk); } diff --git a/libraries/joomla/table/session.php b/libraries/joomla/table/session.php index 0243973696..a07f55b970 100644 --- a/libraries/joomla/table/session.php +++ b/libraries/joomla/table/session.php @@ -189,14 +189,7 @@ public function delete($oid = null) $query->where($this->_db->quoteName($this->_tbl_key) . ' = ' . $this->_db->quote($this->$k)); $this->_db->setQuery($query); - if ($this->_db->execute()) - { - return true; - } - else - { - $this->setError($this->_db->getErrorMsg()); - return false; - } + $this->_db->execute(); + return true; } } diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 242d7496f2..adbf30fd52 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -131,6 +131,7 @@ public function __construct($table, $key, $db) * @return mixed An array of the field names, or false if an error occurs. * * @since 11.1 + * @throws UnexpectedValueException */ public function getFields() { @@ -144,9 +145,7 @@ public function getFields() if (empty($fields)) { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_COLUMNS_NOT_FOUND')); - $this->setError($e); - return false; + throw new UnexpectedValueException(sprintf('No columns found for %s table', $name)); } $cache = $fields; } @@ -426,15 +425,14 @@ public function reset() * * @link http://docs.joomla.org/JTable/bind * @since 11.1 + * @throws UnexpectedValueException */ public function bind($src, $ignore = array()) { // If the source value is not an array or object return false. if (!is_object($src) && !is_array($src)) { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_BIND_FAILED_INVALID_SOURCE_ARGUMENT', get_class($this))); - $this->setError($e); - return false; + throw new UnexpectedValueException(sprintf('%s: :bind failed. Invalid source argument.', get_class($this))); } // If the source value is an object, get its accessible properties. @@ -477,6 +475,8 @@ public function bind($src, $ignore = array()) * * @link http://docs.joomla.org/JTable/load * @since 11.1 + * @throws RuntimeException + * @throws UnexpectedValueException */ public function load($keys = null, $reset = true) { @@ -516,9 +516,7 @@ public function load($keys = null, $reset = true) // Check that $field is in the table. if (!in_array($field, $fields)) { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_IS_MISSING_FIELD', get_class($this), $field)); - $this->setError($e); - return false; + throw new UnexpectedValueException(sprintf('Missing field in the database: %s   %s.', get_class($this), $field)); } // Add the search tuple to the query. $query->where($this->_db->quoteName($field) . ' = ' . $this->_db->quote($value)); @@ -526,32 +524,12 @@ public function load($keys = null, $reset = true) $this->_db->setQuery($query); - try - { - $row = $this->_db->loadAssoc(); - } - catch (RuntimeException $e) - { - $je = new JException($e->getMessage()); - $this->setError($je); - return false; - } - - // Legacy error handling switch based on the JError::$legacy switch. - // @deprecated 12.1 - if (JError::$legacy && $this->_db->getErrorNum()) - { - $e = new JException($this->_db->getErrorMsg()); - $this->setError($e); - return false; - } + $row = $this->_db->loadAssoc(); // Check that we have a result. if (empty($row)) { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_EMPTY_ROW_RETURNED')); - $this->setError($e); - return false; + throw new RuntimeException('The database row is empty.'); } // Bind the object with the row and return. @@ -602,19 +580,11 @@ public function store($updateNulls = false) // If a primary key exists update the object, otherwise insert it. if ($this->$k) { - $stored = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); + $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); } else { - $stored = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key); - } - - // If the store failed return false. - if (!$stored) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - return false; + $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key); } // If the table is not set to track assets return true. @@ -683,12 +653,7 @@ public function store($updateNulls = false) $query->where($this->_db->quoteName($k) . ' = ' . (int) $this->$k); $this->_db->setQuery($query); - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED_UPDATE_ASSET_ID', $this->_db->getErrorMsg())); - $this->setError($e); - return false; - } + $this->_db->execute(); } return true; @@ -760,6 +725,7 @@ public function save($src, $orderingFilter = '', $ignore = '') * * @link http://docs.joomla.org/JTable/delete * @since 11.1 + * @throws UnexpectedValueException */ public function delete($pk = null) { @@ -770,9 +736,7 @@ public function delete($pk = null) // If no primary key is given, return false. if ($pk === null) { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY')); - $this->setError($e); - return false; + throw new UnexpectedValueException('Null primary key not allowed.'); } // If tracking assets, remove the asset first. @@ -806,12 +770,7 @@ public function delete($pk = null) $this->_db->setQuery($query); // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_DELETE_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - return false; - } + $this->_db->execute(); return true; } @@ -848,9 +807,7 @@ public function checkOut($userId, $pk = null) // If no primary key is given, return false. if ($pk === null) { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY')); - $this->setError($e); - return false; + throw new UnexpectedValueException('Null primary key not allowed.'); } // Get the current time in MySQL format. @@ -863,13 +820,7 @@ public function checkOut($userId, $pk = null) $query->set($this->_db->quoteName('checked_out_time') . ' = ' . $this->_db->quote($time)); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk)); $this->_db->setQuery($query); - - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CHECKOUT_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - return false; - } + $this->_db->execute(); // Set table values in the object. $this->checked_out = (int) $userId; @@ -904,9 +855,7 @@ public function checkIn($pk = null) // If no primary key is given, return false. if ($pk === null) { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_NULL_PRIMARY_KEY')); - $this->setError($e); - return false; + throw new UnexpectedValueException('Null primary key not allowed.'); } // Check the row in by primary key. @@ -918,12 +867,7 @@ public function checkIn($pk = null) $this->_db->setQuery($query); // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CHECKIN_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - return false; - } + $this->_db->execute(); // Set table values in the object. $this->checked_out = 0; @@ -966,14 +910,7 @@ public function hit($pk = null) $query->set($this->_db->quoteName('hits') . ' = (' . $this->_db->quoteName('hits') . ' + 1)'); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($pk)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_HIT_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - return false; - } + $this->_db->execute(); // Set table values in the object. $this->hits++; @@ -1035,9 +972,7 @@ public function getNextOrder($where = '') // If there is no ordering field set an error and return false. if (!property_exists($this, 'ordering')) { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this))); - $this->setError($e); - return false; + throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } // Get the largest ordering value for a given where clause. @@ -1053,15 +988,6 @@ public function getNextOrder($where = '') $this->_db->setQuery($query); $max = (int) $this->_db->loadResult(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_GET_NEXT_ORDER_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } - // Return the largest ordering value + 1. return ($max + 1); } @@ -1082,7 +1008,7 @@ public function reorder($where = '') // If there is no ordering field set an error and return false. if (!property_exists($this, 'ordering')) { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this))); + throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); $this->setError($e); return false; } @@ -1106,15 +1032,6 @@ public function reorder($where = '') $this->_db->setQuery($query); $rows = $this->_db->loadObjectList(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_REORDER_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } - // Compact the ordering values. foreach ($rows as $i => $row) { @@ -1130,17 +1047,7 @@ public function reorder($where = '') $query->set('ordering = ' . ($i + 1)); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($row->$k)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException( - JText::sprintf('JLIB_DATABASE_ERROR_REORDER_UPDATE_ROW_FAILED', get_class($this), $i, $this->_db->getErrorMsg()) - ); - $this->setError($e); - - return false; - } + $this->_db->execute(); } } } @@ -1160,15 +1067,14 @@ public function reorder($where = '') * * @link http://docs.joomla.org/JTable/move * @since 11.1 + * @throws UnexpectedValueException */ public function move($delta, $where = '') { // If there is no ordering field set an error and return false. if (!property_exists($this, 'ordering')) { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this))); - $this->setError($e); - return false; + throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this))); } // If the change is none, do nothing. @@ -1218,15 +1124,7 @@ public function move($delta, $where = '') $query->set('ordering = ' . (int) $row->ordering); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($this->$k)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_MOVE_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } + $this->_db->execute(); // Update the ordering field for the row to this instance's ordering value. $query = $this->_db->getQuery(true); @@ -1234,15 +1132,7 @@ public function move($delta, $where = '') $query->set('ordering = ' . (int) $this->ordering); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($row->$k)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_MOVE_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } + $this->_db->execute(); // Update the instance value. $this->ordering = $row->ordering; @@ -1255,15 +1145,7 @@ public function move($delta, $where = '') $query->set('ordering = ' . (int) $this->ordering); $query->where($this->_tbl_key . ' = ' . $this->_db->quote($this->$k)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_MOVE_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } + $this->_db->execute(); } return true; @@ -1303,10 +1185,7 @@ public function publish($pks = null, $state = 1, $userId = 0) // Nothing to set publishing state on, return false. else { - $e = new JException(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED')); - $this->setError($e); - - return false; + throw new UnexpectedValueException('No rows selected for publishing state'); } } @@ -1330,15 +1209,7 @@ public function publish($pks = null, $state = 1, $userId = 0) $query->where($k . ' = ' . implode(' OR ' . $k . ' = ', $pks)); $this->_db->setQuery($query); - - // Check for a database error. - if (!$this->_db->execute()) - { - $e = new JException(JText::sprintf('JLIB_DATABASE_ERROR_PUBLISH_FAILED', get_class($this), $this->_db->getErrorMsg())); - $this->setError($e); - - return false; - } + $this->_db->execute(); // If checkin is supported and all rows were adjusted, check them in. if ($checkin && (count($pks) == $this->_db->getAffectedRows())) diff --git a/libraries/joomla/table/user.php b/libraries/joomla/table/user.php index c2b561f170..75e70060a9 100644 --- a/libraries/joomla/table/user.php +++ b/libraries/joomla/table/user.php @@ -83,17 +83,11 @@ public function load($userId = null, $reset = true) $this->_db->setQuery($query); $data = (array) $this->_db->loadAssoc(); - // Check for an error message. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - if (!count($data)) { return false; } + // Bind the data to the table. $return = $this->bind($data); @@ -110,13 +104,6 @@ public function load($userId = null, $reset = true) // Add the groups to the user data. $this->groups = $this->_db->loadAssocList('id', 'id'); - - // Check for an error message. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } } return $return; @@ -161,12 +148,6 @@ public function bind($array, $ignore = '') // Set the titles for the user groups. $this->groups = $this->_db->loadAssocList('id', 'id'); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } } return $return; @@ -293,19 +274,12 @@ public function store($updateNulls = false) if ($key) { // Already have a table key, update the row. - $return = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); + $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls); } else { // Don't have a table key, insert the row. - $return = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key); - } - - // Handle error if it exists. - if (!$return) - { - $this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->getErrorMsg())); - return false; + $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key); } // Reset groups to the local object. @@ -313,7 +287,7 @@ public function store($updateNulls = false) unset($groups); // Store the group data if the user data was saved. - if ($return && is_array($this->groups) && count($this->groups)) + if (is_array($this->groups) && count($this->groups)) { // Delete the old user group maps. $query = $this->_db->getQuery(true); @@ -323,13 +297,6 @@ public function store($updateNulls = false) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - // Set the new user group maps. $query->clear(); $query->insert($this->_db->quoteName('#__user_usergroup_map')); @@ -343,13 +310,6 @@ public function store($updateNulls = false) $this->_db->setQuery($query); $this->_db->execute(); } - - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } } return true; @@ -381,13 +341,6 @@ public function delete($userId = null) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - // Delete the user group maps. $query->clear(); $query->delete(); @@ -396,13 +349,6 @@ public function delete($userId = null) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - /* * Clean Up Related Data. */ @@ -414,13 +360,6 @@ public function delete($userId = null) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - $query->clear(); $query->delete(); $query->from($this->_db->quoteName('#__messages')); @@ -428,13 +367,6 @@ public function delete($userId = null) $this->_db->setQuery($query); $this->_db->execute(); - // Check for a database error. - if ($this->_db->getErrorNum()) - { - $this->setError($this->_db->getErrorMsg()); - return false; - } - return true; } @@ -459,8 +391,7 @@ public function setLastVisit($timeStamp = null, $userId = null) } else { - // Do not translate - jexit(JText::_('JLIB_DATABASE_ERROR_SETLASTVISIT')); + jexit('No userid in setLastVisit'); } } @@ -476,13 +407,6 @@ public function setLastVisit($timeStamp = null, $userId = null) $db->setQuery($query); $db->execute(); - // Check for a database error. - if ($db->getErrorNum()) - { - $this->setError($db->getErrorMsg()); - return false; - } - return true; } } diff --git a/libraries/joomla/table/usergroup.php b/libraries/joomla/table/usergroup.php index c629eea21a..7aa54b54ad 100644 --- a/libraries/joomla/table/usergroup.php +++ b/libraries/joomla/table/usergroup.php @@ -143,6 +143,7 @@ public function store($updateNulls = false) * @return mixed Boolean or Exception. * * @since 11.1 + * @throws UnexpectedValueException */ public function delete($oid = null) { @@ -152,15 +153,15 @@ public function delete($oid = null) } if ($this->id == 0) { - return new JException(JText::_('JGLOBAL_CATEGORY_NOT_FOUND')); + throw new UnexpectedValueException('Global Category not found'); } if ($this->parent_id == 0) { - return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_ROOT_CATEGORIES')); + return new JException('Root categories cannot be deleted.'); } if ($this->lft == 0 || $this->rgt == 0) { - return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY')); + throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete category.'); } $db = $this->_db; @@ -175,7 +176,7 @@ public function delete($oid = null) $ids = $db->loadColumn(); if (empty($ids)) { - return new JException(JText::_('JLIB_DATABASE_ERROR_DELETE_CATEGORY')); + throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete category.'); } // Delete the category dependencies @@ -187,11 +188,7 @@ public function delete($oid = null) $query->from($db->quoteName($this->_tbl)); $query->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')'); $db->setQuery($query); - if (!$db->execute()) - { - $this->setError($db->getErrorMsg()); - return false; - } + $db->execute(); // Delete the usergroup in view levels $replace = array(); @@ -230,11 +227,7 @@ public function delete($oid = null) $query->update('#__viewlevels'); $query->where('id IN (' . implode(',', $match_ids) . ')'); $db->setQuery($query); - if (!$db->execute()) - { - $this->setError($db->getErrorMsg()); - return false; - } + $db->execute(); } // Delete the user to usergroup mappings for the group(s) from the database. @@ -245,13 +238,6 @@ public function delete($oid = null) $db->setQuery($query); $db->execute(); - // Check for a database error. - if ($db->getErrorNum()) - { - $this->setError($db->getErrorMsg()); - return false; - } - return true; } } From f8138ac464ab0f1bcfc1d810f3bc741af68caa85 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sun, 1 Apr 2012 16:48:57 -0500 Subject: [PATCH 30/98] Append message from phpMailer --- libraries/joomla/mail/mail.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/mail/mail.php b/libraries/joomla/mail/mail.php index f32e412fba..fd63e6a4be 100644 --- a/libraries/joomla/mail/mail.php +++ b/libraries/joomla/mail/mail.php @@ -76,14 +76,28 @@ public function Send() { if (($this->Mailer == 'mail') && !function_exists('mail')) { - throw new RuntimeException('Send function cancelled because mail is disabled.'); + if (class_exists('JError')) + { + return JError::raiseNotice(500, JText::_('JLIB_MAIL_FUNCTION_DISABLED')); + } + else + { + throw new RuntimeException('Send function cancelled because mail is disabled.'); + } } @$result = parent::Send(); if ($result == false) { - throw new RuntimeException('phpMail Send email failed'); + if (class_exists('JError')) + { + $result = JError::raiseNotice(500, JText::_($this->ErrorInfo)); + } + else + { + throw new RuntimeException('Send function cancelled because mail is disabled.'); + } } return $result; From 8487a9492dd26e61329d64de2666e4949832ea1f Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Sun, 1 Apr 2012 21:54:11 -0500 Subject: [PATCH 31/98] Log Package: remove ->error statement --- libraries/joomla/log/loggers/database.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/libraries/joomla/log/loggers/database.php b/libraries/joomla/log/loggers/database.php index ba016eeac3..d392cd1501 100644 --- a/libraries/joomla/log/loggers/database.php +++ b/libraries/joomla/log/loggers/database.php @@ -156,11 +156,6 @@ protected function connect() throw new LogException('Database Error: ' . (string) $db); } - if ($db->getErrorNum() > 0) - { - throw new LogException(JText::sprintf('JLIB_UTIL_ERROR_CONNECT_DATABASE', $db->getErrorNum(), $db->getErrorMsg())); - } - // Assign the database connector to the class. $this->dbo = $db; } From c2ee2d97aa02aacb1d98f0954dbfca9e70e6fd63 Mon Sep 17 00:00:00 2001 From: Piotr Konieczny Date: Mon, 2 Apr 2012 15:26:27 +0200 Subject: [PATCH 32/98] For each request method added variable $timeout with fallback to class options. Added $useragent string that's being read from class options. --- libraries/joomla/http/http.php | 79 +++++++++++++++++++++++++++------- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/libraries/joomla/http/http.php b/libraries/joomla/http/http.php index 8791098840..a17f67d6fb 100644 --- a/libraries/joomla/http/http.php +++ b/libraries/joomla/http/http.php @@ -83,12 +83,13 @@ public function setOption($key, $value) * * @param string $url Path to the resource. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function options($url, array $headers = null) + public function options($url, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -100,7 +101,13 @@ public function options($url, array $headers = null) } } - return $this->transport->request('OPTIONS', new JUri($url), null, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('OPTIONS', new JUri($url), null, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -108,12 +115,13 @@ public function options($url, array $headers = null) * * @param string $url Path to the resource. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function head($url, array $headers = null) + public function head($url, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -125,7 +133,13 @@ public function head($url, array $headers = null) } } - return $this->transport->request('HEAD', new JUri($url), null, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('HEAD', new JUri($url), null, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -133,12 +147,13 @@ public function head($url, array $headers = null) * * @param string $url Path to the resource. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function get($url, array $headers = null) + public function get($url, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -150,7 +165,13 @@ public function get($url, array $headers = null) } } - return $this->transport->request('GET', new JUri($url), null, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('GET', new JUri($url), null, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -158,13 +179,14 @@ public function get($url, array $headers = null) * * @param string $url Path to the resource. * @param mixed $data Either an associative array or a string to be sent with the request. - * @param array $headers An array of name-value pairs to include in the header of the request. + * @param array $headers An array of name-value pairs to include in the header of the request + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function post($url, $data, array $headers = null) + public function post($url, $data, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -176,7 +198,13 @@ public function post($url, $data, array $headers = null) } } - return $this->transport->request('POST', new JUri($url), $data, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('POST', new JUri($url), $data, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -185,12 +213,13 @@ public function post($url, $data, array $headers = null) * @param string $url Path to the resource. * @param mixed $data Either an associative array or a string to be sent with the request. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function put($url, $data, array $headers = null) + public function put($url, $data, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -202,7 +231,13 @@ public function put($url, $data, array $headers = null) } } - return $this->transport->request('PUT', new JUri($url), $data, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('PUT', new JUri($url), $data, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -210,12 +245,13 @@ public function put($url, $data, array $headers = null) * * @param string $url Path to the resource. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function delete($url, array $headers = null) + public function delete($url, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -227,7 +263,13 @@ public function delete($url, array $headers = null) } } - return $this->transport->request('DELETE', new JUri($url), null, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('DELETE', new JUri($url), null, $headers, $timeout, $this->options->get('userAgent', null)); } /** @@ -235,12 +277,13 @@ public function delete($url, array $headers = null) * * @param string $url Path to the resource. * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * * @since 11.3 */ - public function trace($url, array $headers = null) + public function trace($url, array $headers = null, $timeout = null) { // Look for headers set in the options. $temp = (array) $this->options->get('headers'); @@ -252,7 +295,13 @@ public function trace($url, array $headers = null) } } - return $this->transport->request('TRACE', new JUri($url), null, $headers); + // Look for timeout set in the options. + if ($timeout === null && $this->options->exists('timeout')) + { + $timeout = $this->options->get('timeout'); + } + + return $this->transport->request('TRACE', new JUri($url), null, $headers, $timeout, $this->options->get('userAgent', null)); } } From 9d1b53451b4bee67f5da0a066b758934f1e4e5a2 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Thu, 29 Mar 2012 21:08:49 -0500 Subject: [PATCH 33/98] Archive Package: Exception and JError updates --- libraries/joomla/archive/archive.php | 11 ++--- libraries/joomla/archive/bzip2.php | 31 ++++-------- libraries/joomla/archive/gzip.php | 33 +++++-------- libraries/joomla/archive/tar.php | 20 +++----- libraries/joomla/archive/zip.php | 71 ++++++++++----------------- libraries/joomla/installer/helper.php | 7 +-- 6 files changed, 63 insertions(+), 110 deletions(-) diff --git a/libraries/joomla/archive/archive.php b/libraries/joomla/archive/archive.php index 6f0c045ef1..45f4ffddad 100644 --- a/libraries/joomla/archive/archive.php +++ b/libraries/joomla/archive/archive.php @@ -27,6 +27,7 @@ class JArchive * @return boolean True for success * * @since 11.1 + * @throws InvalidArgumentException */ public static function extract($archivename, $extractdir) { @@ -149,9 +150,7 @@ public static function extract($archivename, $extractdir) break; default: - JLog::add(JText::_('JLIB_FILESYSTEM_UNKNOWNARCHIVETYPE'), JLog::WARNING, 'jerror'); - return false; - break; + throw new InvalidArgumentException('Unknown Archive Type'); } if (!$result || $result instanceof Exception) @@ -167,10 +166,10 @@ public static function extract($archivename, $extractdir) * * @param string $type The type of adapter (bzip2|gzip|tar|zip). * - * @return object JArchiveExtractable + * @return object JArchiveExtractable * * @since 11.1 - * @throws Exception + * @throws BadMethodCallException */ public static function getAdapter($type) { @@ -188,7 +187,7 @@ public static function getAdapter($type) if (!class_exists($class)) { - throw new Exception(JText::_('JLIB_FILESYSTEM_UNABLE_TO_LOAD_ARCHIVE'), 500); + throw new BadMethodCallException('Unable to load archive', 500); } $adapters[$type] = new $class; diff --git a/libraries/joomla/archive/bzip2.php b/libraries/joomla/archive/bzip2.php index 4b7ab21442..0dcf1c267f 100644 --- a/libraries/joomla/archive/bzip2.php +++ b/libraries/joomla/archive/bzip2.php @@ -45,9 +45,10 @@ public function __construct() * @param string $destination Path to extract archive to * @param array $options Extraction options [unused] * - * @return boolean True if successful + * @return boolean True if successful * * @since 11.1 + * @throws RuntimeException */ public function extract($archive, $destination, array $options = array ()) { @@ -56,9 +57,7 @@ public function extract($archive, $destination, array $options = array ()) if (!extension_loaded('bz2')) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_NOT_SUPPORTED')); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('The bz2 extension is not available.'); } if (!isset($options['use_streams']) || $options['use_streams'] == false) @@ -66,22 +65,19 @@ public function extract($archive, $destination, array $options = array ()) // Old style: read the whole file and then parse it if (!$this->_data = JFile::read($archive)) { - $this->set('error.message', 'Unable to read archive'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to read archive'); } $buffer = bzdecompress($this->_data); unset($this->_data); if (empty($buffer)) { - $this->set('error.message', 'Unable to decompress data'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to decompress data'); } if (JFile::write($destination, $buffer) === false) { - $this->set('error.message', 'Unable to write archive'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to write archive'); } } @@ -95,21 +91,15 @@ public function extract($archive, $destination, array $options = array ()) if (!$input->open($archive)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_READ')); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to read archive (bz2)'); } $output = JFactory::getStream(); if (!$output->open($destination, 'w')) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE')); - - // Close the previous file $input->close(); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to write archive (bz2)'); } do @@ -119,9 +109,8 @@ public function extract($archive, $destination, array $options = array ()) { if (!$output->write($this->_data)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_BZIP_UNABLE_TO_WRITE_FILE')); - - return JError::raiseWarning(100, $this->get('error.message')); + $input->close(); + throw new RuntimeException('Unable to write archive (bz2)'); } } } diff --git a/libraries/joomla/archive/gzip.php b/libraries/joomla/archive/gzip.php index ddd7b3953e..57f639ca1b 100644 --- a/libraries/joomla/archive/gzip.php +++ b/libraries/joomla/archive/gzip.php @@ -50,6 +50,7 @@ class JArchiveGzip implements JArchiveExtractable * @return boolean True if successful * * @since 11.1 + * @throws RuntimeException */ public function extract($archive, $destination, array $options = array ()) { @@ -58,31 +59,26 @@ public function extract($archive, $destination, array $options = array ()) if (!extension_loaded('zlib')) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_NOT_SUPPORTED')); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('The zlib extension is not available.'); } if (!isset($options['use_streams']) || $options['use_streams'] == false) { if (!$this->_data = JFile::read($archive)) { - $this->set('error.message', 'Unable to read archive'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to read archive'); } $position = $this->_getFilePosition(); $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position)); if (empty($buffer)) { - $this->set('error.message', 'Unable to decompress data'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to decompress data'); } if (JFile::write($destination, $buffer) === false) { - $this->set('error.message', 'Unable to write archive'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to write archive'); } } else @@ -95,21 +91,15 @@ public function extract($archive, $destination, array $options = array ()) if (!$input->open($archive)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_READ')); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to read archive (gz)'); } $output = JFactory::getStream(); if (!$output->open($destination, 'w')) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_WRITE')); - - // Close the previous file $input->close(); - - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to write archive (gz)'); } do @@ -119,9 +109,8 @@ public function extract($archive, $destination, array $options = array ()) { if (!$output->write($this->_data)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_WRITE_FILE')); - - return JError::raiseWarning(100, $this->get('error.message')); + $input->close(); + throw new RuntimeException('Unable to write file (gz)'); } } } @@ -151,6 +140,7 @@ public static function isSupported() * @return integer Data position marker for archive * * @since 11.1 + * @throws RuntimeException */ public function _getFilePosition() { @@ -160,8 +150,7 @@ public function _getFilePosition() if (!$info) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_GZIP_UNABLE_TO_DECOMPRESS')); - return false; + throw new RuntimeException('Unable to decompress data.'); } $position += 10; diff --git a/libraries/joomla/archive/tar.php b/libraries/joomla/archive/tar.php index 0e3c94ab42..de06d66b66 100644 --- a/libraries/joomla/archive/tar.php +++ b/libraries/joomla/archive/tar.php @@ -64,8 +64,9 @@ class JArchiveTar implements JArchiveExtractable * @param string $destination Path to extract archive into * @param array $options Extraction options [unused] * - * @return boolean True if successful + * @return boolean True if successful * + * @throws RuntimeException * @since 11.1 */ public function extract($archive, $destination, array $options = array()) @@ -76,14 +77,10 @@ public function extract($archive, $destination, array $options = array()) if (!$this->_data = JFile::read($archive)) { - $this->set('error.message', 'Unable to read archive'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to read archive'); } - if (!$this->_getTarInfo($this->_data)) - { - return JError::raiseWarning(100, $this->get('error.message')); - } + $this->_getTarInfo($this->_data); for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) { @@ -96,13 +93,11 @@ public function extract($archive, $destination, array $options = array()) // Make sure the destination folder exists if (!JFolder::create(dirname($path))) { - $this->set('error.message', 'Unable to create destination'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to create destination'); } if (JFile::write($path, $buffer) === false) { - $this->set('error.message', 'Unable to write entry'); - return JError::raiseWarning(100, $this->get('error.message')); + throw new RuntimeException('Unable to write entry'); } } } @@ -152,8 +147,7 @@ protected function _getTarInfo(& $data) ); if (!$info) { - $this->set('error.message', 'Unable to decompress data'); - return false; + throw new RuntimeException('Unable to decompress data'); } $position += 512; diff --git a/libraries/joomla/archive/zip.php b/libraries/joomla/archive/zip.php index d5d806ef80..1699855638 100644 --- a/libraries/joomla/archive/zip.php +++ b/libraries/joomla/archive/zip.php @@ -121,23 +121,22 @@ public function create($archive, $files, array $options = array()) * @return boolean True if successful * * @since 11.1 + * @throws RuntimeException */ public function extract($archive, $destination, array $options = array()) { if (!is_file($archive)) { - $this->set('error.message', 'Archive does not exist'); - - return false; + throw new RuntimeException('Archive does not exist'); } if ($this->hasNativeSupport()) { - return ($this->_extractNative($archive, $destination, $options)) ? true : JError::raiseWarning(100, $this->get('error.message')); + $this->_extractNative($archive, $destination, $options); } else { - return ($this->_extract($archive, $destination, $options)) ? true : JError::raiseWarning(100, $this->get('error.message')); + $this->_extract($archive, $destination, $options); } } @@ -193,9 +192,10 @@ public function checkZipData(&$data) * @param string $destination Path to extract archive into. * @param array $options Extraction options [unused]. * - * @return boolean True if successful + * @return mixed True if successful * * @since 11.1 + * @throws RuntimeException */ private function _extract($archive, $destination, array $options) { @@ -205,23 +205,17 @@ private function _extract($archive, $destination, array $options) if (!extension_loaded('zlib')) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_NOT_SUPPORTED')); - - return false; + throw new RuntimeException('Zlib not supported'); } if (!$this->_data = JFile::read($archive)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_READ')); - - return false; + throw new RuntimeException('Unable to read archive (zip)'); } if (!$this->_readZipInfo($this->_data)) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_INFO_FAILED')); - - return false; + throw new RuntimeException('Get ZIP Information failed'); } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) @@ -236,16 +230,12 @@ private function _extract($archive, $destination, array $options) // Make sure the destination folder exists if (!JFolder::create(dirname($path))) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_CREATE_DESTINATION')); - - return false; + throw new RuntimeException('Unable to create destination'); } if (JFile::write($path, $buffer) === false) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_WRITE_ENTRY')); - - return false; + throw new RuntimeException('Unable to write entry'); } } } @@ -256,13 +246,14 @@ private function _extract($archive, $destination, array $options) /** * Extract a ZIP compressed file to a given path using native php api calls for speed * - * @param string $archive Path to ZIP archive to extract - * @param string $destination Path to extract archive into - * @param array $options Extraction options [unused] + * @param string $archive Path to ZIP archive to extract + * @param string $destination Path to extract archive into + * @param array $options Extraction options [unused] * - * @return boolean True if successful + * @return boolean True on success * * @since 11.1 + * @throws RuntimeException */ private function _extractNative($archive, $destination, array $options) { @@ -272,8 +263,7 @@ private function _extractNative($archive, $destination, array $options) // Make sure the destination folder exists if (!JFolder::create($destination)) { - $this->set('error.message', 'Unable to create destination'); - return false; + throw new RuntimeException('Unable to create destination'); } // Read files in the archive @@ -287,8 +277,7 @@ private function _extractNative($archive, $destination, array $options) if (JFile::write($destination . '/' . zip_entry_name($file), $buffer) === false) { - $this->set('error.message', 'Unable to write entry'); - return false; + throw new RuntimeException('Unable to write entry'); } zip_entry_close($file); @@ -296,9 +285,7 @@ private function _extractNative($archive, $destination, array $options) } else { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_READ_ENTRY')); - - return false; + throw new RuntimeException('Unable to read entry'); } } @@ -306,9 +293,7 @@ private function _extractNative($archive, $destination, array $options) } else { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_UNABLE_TO_OPEN_ARCHIVE')); - - return false; + throw new RuntimeException('Unable to open archive'); } return true; @@ -329,11 +314,12 @@ private function _extractNative($archive, $destination, array $options) * 'type' -- File type * * - * @param string &$data The ZIP archive buffer. + * @param string &$data The ZIP archive buffer. * - * @return boolean True on success. + * @return boolean True on success * * @since 11.1 + * @throws RuntimeException */ private function _readZipInfo(&$data) { @@ -370,9 +356,7 @@ private function _readZipInfo(&$data) { if ($dataLength < $fhStart + 31) { - $this->set('error.message', JText::_('JLIB_FILESYSTEM_ZIP_INVALID_ZIP_DATA')); - - return false; + throw new RuntimeException('Invalid Zip Data'); } $info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength', substr($data, $fhStart + 10, 20)); @@ -402,8 +386,7 @@ private function _readZipInfo(&$data) if ($dataLength < $fhStart + 43) { - $this->set('error.message', 'Invalid ZIP data'); - return false; + throw new RuntimeException('Invalid ZIP data'); } $info = unpack('vInternal/VExternal/VOffset', substr($data, $fhStart + 36, 10)); @@ -418,9 +401,7 @@ private function _readZipInfo(&$data) if ($dataLength < $lfhStart + 34) { - $this->set('error.message', 'Invalid ZIP data'); - - return false; + throw new RuntimeException('Invalid Zip Data'); } $info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength/vExtraLength', substr($data, $lfhStart + 8, 25)); diff --git a/libraries/joomla/installer/helper.php b/libraries/joomla/installer/helper.php index 5bcc84052d..3e939704f1 100644 --- a/libraries/joomla/installer/helper.php +++ b/libraries/joomla/installer/helper.php @@ -104,9 +104,10 @@ public static function unpack($p_filename) $archivename = JPath::clean($archivename); // Do the unpacking of the archive - $result = JArchive::extract($archivename, $extractdir); - - if ($result === false) + try { + JArchive::extract($archivename, $extractdir); + } + catch (Exception $e) { return false; } From ddae73e37b1a3e15b6ef9b6594cb33e9f54b7837 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 21:06:23 -0700 Subject: [PATCH 34/98] A little cleanup and adding in JError checks for legacy reasons. --- libraries/joomla/archive/archive.php | 33 ++++--- libraries/joomla/archive/bzip2.php | 65 ++++++++++++-- libraries/joomla/archive/gzip.php | 76 +++++++++++++--- libraries/joomla/archive/tar.php | 36 +++++++- libraries/joomla/archive/zip.php | 125 +++++++++++++++++++++++---- 5 files changed, 278 insertions(+), 57 deletions(-) diff --git a/libraries/joomla/archive/archive.php b/libraries/joomla/archive/archive.php index 45f4ffddad..36e1fe9f96 100644 --- a/libraries/joomla/archive/archive.php +++ b/libraries/joomla/archive/archive.php @@ -9,6 +9,9 @@ defined('JPATH_PLATFORM') or die; +jimport('joomla.filesystem.file'); +jimport('joomla.filesystem.folder'); + /** * An Archive handling class * @@ -18,6 +21,12 @@ */ class JArchive { + /** + * @var array The array of instantiated archive adapters. + * @since 12.1 + */ + protected static $adapters = array(); + /** * Extract an archive file to a directory. * @@ -31,9 +40,6 @@ class JArchive */ public static function extract($archivename, $extractdir) { - jimport('joomla.filesystem.file'); - jimport('joomla.filesystem.folder'); - $untar = false; $result = false; $ext = JFile::getExt(strtolower($archivename)); @@ -72,7 +78,6 @@ public static function extract($archivename, $extractdir) case 'gzip': // This may just be an individual file (e.g. sql script) $adapter = self::getAdapter('gzip'); - if ($adapter) { $config = JFactory::getConfig(); @@ -166,33 +171,25 @@ public static function extract($archivename, $extractdir) * * @param string $type The type of adapter (bzip2|gzip|tar|zip). * - * @return object JArchiveExtractable + * @return object JArchiveExtractable * * @since 11.1 - * @throws BadMethodCallException + * @throws UnexpectedValueException */ public static function getAdapter($type) { - static $adapters; - - if (!isset($adapters)) - { - $adapters = array(); - } - - if (!isset($adapters[$type])) + if (!isset(self::$adapters[$type])) { // Try to load the adapter object $class = 'JArchive' . ucfirst($type); - if (!class_exists($class)) { - throw new BadMethodCallException('Unable to load archive', 500); + throw new UnexpectedValueException('Unable to load archive', 500); } - $adapters[$type] = new $class; + self::$adapters[$type] = new $class; } - return $adapters[$type]; + return self::$adapters[$type]; } } diff --git a/libraries/joomla/archive/bzip2.php b/libraries/joomla/archive/bzip2.php index 0dcf1c267f..b86b4ce1ce 100644 --- a/libraries/joomla/archive/bzip2.php +++ b/libraries/joomla/archive/bzip2.php @@ -45,7 +45,7 @@ public function __construct() * @param string $destination Path to extract archive to * @param array $options Extraction options [unused] * - * @return boolean True if successful + * @return boolean True if successful * * @since 11.1 * @throws RuntimeException @@ -57,7 +57,14 @@ public function extract($archive, $destination, array $options = array ()) if (!extension_loaded('bz2')) { - throw new RuntimeException('The bz2 extension is not available.'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'The bz2 extension is not available.'); + } + else + { + throw new RuntimeException('The bz2 extension is not available.'); + } } if (!isset($options['use_streams']) || $options['use_streams'] == false) @@ -65,19 +72,40 @@ public function extract($archive, $destination, array $options = array ()) // Old style: read the whole file and then parse it if (!$this->_data = JFile::read($archive)) { - throw new RuntimeException('Unable to read archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive'); + } + else + { + throw new RuntimeException('Unable to read archive'); + } } $buffer = bzdecompress($this->_data); unset($this->_data); if (empty($buffer)) { - throw new RuntimeException('Unable to decompress data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to decompress data'); + } + else + { + throw new RuntimeException('Unable to decompress data'); + } } if (JFile::write($destination, $buffer) === false) { - throw new RuntimeException('Unable to write archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write archive'); + } + else + { + throw new RuntimeException('Unable to write archive'); + } } } @@ -91,7 +119,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$input->open($archive)) { - throw new RuntimeException('Unable to read archive (bz2)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive (bz2)'); + } + else + { + throw new RuntimeException('Unable to read archive (bz2)'); + } } $output = JFactory::getStream(); @@ -99,7 +134,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$output->open($destination, 'w')) { $input->close(); - throw new RuntimeException('Unable to write archive (bz2)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write archive (bz2)'); + } + else + { + throw new RuntimeException('Unable to write archive (bz2)'); + } } do @@ -110,7 +152,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$output->write($this->_data)) { $input->close(); - throw new RuntimeException('Unable to write archive (bz2)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write archive (bz2)'); + } + else + { + throw new RuntimeException('Unable to write archive (bz2)'); + } } } } diff --git a/libraries/joomla/archive/gzip.php b/libraries/joomla/archive/gzip.php index 57f639ca1b..a16663db4c 100644 --- a/libraries/joomla/archive/gzip.php +++ b/libraries/joomla/archive/gzip.php @@ -50,7 +50,7 @@ class JArchiveGzip implements JArchiveExtractable * @return boolean True if successful * * @since 11.1 - * @throws RuntimeException + * @throws RuntimeException */ public function extract($archive, $destination, array $options = array ()) { @@ -59,26 +59,54 @@ public function extract($archive, $destination, array $options = array ()) if (!extension_loaded('zlib')) { - throw new RuntimeException('The zlib extension is not available.'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'The zlib extension is not available.'); + } + else + { + throw new RuntimeException('The zlib extension is not available.'); + } } if (!isset($options['use_streams']) || $options['use_streams'] == false) { if (!$this->_data = JFile::read($archive)) { - throw new RuntimeException('Unable to read archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive'); + } + else + { + throw new RuntimeException('Unable to read archive'); + } } $position = $this->_getFilePosition(); $buffer = gzinflate(substr($this->_data, $position, strlen($this->_data) - $position)); if (empty($buffer)) { - throw new RuntimeException('Unable to decompress data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to decompress data'); + } + else + { + throw new RuntimeException('Unable to decompress data'); + } } if (JFile::write($destination, $buffer) === false) { - throw new RuntimeException('Unable to write archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write archive'); + } + else + { + throw new RuntimeException('Unable to write archive'); + } } } else @@ -91,7 +119,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$input->open($archive)) { - throw new RuntimeException('Unable to read archive (gz)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive (gz)'); + } + else + { + throw new RuntimeException('Unable to read archive (gz)'); + } } $output = JFactory::getStream(); @@ -99,7 +134,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$output->open($destination, 'w')) { $input->close(); - throw new RuntimeException('Unable to write archive (gz)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write archive (gz)'); + } + else + { + throw new RuntimeException('Unable to write archive (gz)'); + } } do @@ -110,7 +152,14 @@ public function extract($archive, $destination, array $options = array ()) if (!$output->write($this->_data)) { $input->close(); - throw new RuntimeException('Unable to write file (gz)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write file (gz)'); + } + else + { + throw new RuntimeException('Unable to write file (gz)'); + } } } } @@ -140,7 +189,7 @@ public static function isSupported() * @return integer Data position marker for archive * * @since 11.1 - * @throws RuntimeException + * @throws RuntimeException */ public function _getFilePosition() { @@ -150,7 +199,14 @@ public function _getFilePosition() if (!$info) { - throw new RuntimeException('Unable to decompress data.'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to decompress data.'); + } + else + { + throw new RuntimeException('Unable to decompress data.'); + } } $position += 10; diff --git a/libraries/joomla/archive/tar.php b/libraries/joomla/archive/tar.php index de06d66b66..e99c6f8957 100644 --- a/libraries/joomla/archive/tar.php +++ b/libraries/joomla/archive/tar.php @@ -77,7 +77,14 @@ public function extract($archive, $destination, array $options = array()) if (!$this->_data = JFile::read($archive)) { - throw new RuntimeException('Unable to read archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive'); + } + else + { + throw new RuntimeException('Unable to read archive'); + } } $this->_getTarInfo($this->_data); @@ -93,11 +100,25 @@ public function extract($archive, $destination, array $options = array()) // Make sure the destination folder exists if (!JFolder::create(dirname($path))) { - throw new RuntimeException('Unable to create destination'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to create destination'); + } + else + { + throw new RuntimeException('Unable to create destination'); + } } if (JFile::write($path, $buffer) === false) { - throw new RuntimeException('Unable to write entry'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write entry'); + } + else + { + throw new RuntimeException('Unable to write entry'); + } } } } @@ -147,7 +168,14 @@ protected function _getTarInfo(& $data) ); if (!$info) { - throw new RuntimeException('Unable to decompress data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to decompress data'); + } + else + { + throw new RuntimeException('Unable to decompress data'); + } } $position += 512; diff --git a/libraries/joomla/archive/zip.php b/libraries/joomla/archive/zip.php index 1699855638..6b414b5891 100644 --- a/libraries/joomla/archive/zip.php +++ b/libraries/joomla/archive/zip.php @@ -127,7 +127,14 @@ public function extract($archive, $destination, array $options = array()) { if (!is_file($archive)) { - throw new RuntimeException('Archive does not exist'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Archive does not exist'); + } + else + { + throw new RuntimeException('Archive does not exist'); + } } if ($this->hasNativeSupport()) @@ -205,17 +212,38 @@ private function _extract($archive, $destination, array $options) if (!extension_loaded('zlib')) { - throw new RuntimeException('Zlib not supported'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Zlib not supported'); + } + else + { + throw new RuntimeException('Zlib not supported'); + } } if (!$this->_data = JFile::read($archive)) { - throw new RuntimeException('Unable to read archive (zip)'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read archive (zip)'); + } + else + { + throw new RuntimeException('Unable to read archive (zip)'); + } } if (!$this->_readZipInfo($this->_data)) { - throw new RuntimeException('Get ZIP Information failed'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Get ZIP Information failed'); + } + else + { + throw new RuntimeException('Get ZIP Information failed'); + } } for ($i = 0, $n = count($this->_metadata); $i < $n; $i++) @@ -230,12 +258,26 @@ private function _extract($archive, $destination, array $options) // Make sure the destination folder exists if (!JFolder::create(dirname($path))) { - throw new RuntimeException('Unable to create destination'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to create destination'); + } + else + { + throw new RuntimeException('Unable to create destination'); + } } if (JFile::write($path, $buffer) === false) { - throw new RuntimeException('Unable to write entry'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write entry'); + } + else + { + throw new RuntimeException('Unable to write entry'); + } } } } @@ -246,9 +288,9 @@ private function _extract($archive, $destination, array $options) /** * Extract a ZIP compressed file to a given path using native php api calls for speed * - * @param string $archive Path to ZIP archive to extract - * @param string $destination Path to extract archive into - * @param array $options Extraction options [unused] + * @param string $archive Path to ZIP archive to extract + * @param string $destination Path to extract archive into + * @param array $options Extraction options [unused] * * @return boolean True on success * @@ -263,7 +305,14 @@ private function _extractNative($archive, $destination, array $options) // Make sure the destination folder exists if (!JFolder::create($destination)) { - throw new RuntimeException('Unable to create destination'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to create destination'); + } + else + { + throw new RuntimeException('Unable to create destination'); + } } // Read files in the archive @@ -277,7 +326,14 @@ private function _extractNative($archive, $destination, array $options) if (JFile::write($destination . '/' . zip_entry_name($file), $buffer) === false) { - throw new RuntimeException('Unable to write entry'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to write entry'); + } + else + { + throw new RuntimeException('Unable to write entry'); + } } zip_entry_close($file); @@ -285,7 +341,14 @@ private function _extractNative($archive, $destination, array $options) } else { - throw new RuntimeException('Unable to read entry'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to read entry'); + } + else + { + throw new RuntimeException('Unable to read entry'); + } } } @@ -293,7 +356,14 @@ private function _extractNative($archive, $destination, array $options) } else { - throw new RuntimeException('Unable to open archive'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Unable to open archive'); + } + else + { + throw new RuntimeException('Unable to open archive'); + } } return true; @@ -314,7 +384,7 @@ private function _extractNative($archive, $destination, array $options) * 'type' -- File type * * - * @param string &$data The ZIP archive buffer. + * @param string &$data The ZIP archive buffer. * * @return boolean True on success * @@ -356,7 +426,14 @@ private function _readZipInfo(&$data) { if ($dataLength < $fhStart + 31) { - throw new RuntimeException('Invalid Zip Data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Invalid Zip Data'); + } + else + { + throw new RuntimeException('Invalid Zip Data'); + } } $info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength', substr($data, $fhStart + 10, 20)); @@ -386,7 +463,14 @@ private function _readZipInfo(&$data) if ($dataLength < $fhStart + 43) { - throw new RuntimeException('Invalid ZIP data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Invalid ZIP data'); + } + else + { + throw new RuntimeException('Invalid ZIP data'); + } } $info = unpack('vInternal/VExternal/VOffset', substr($data, $fhStart + 36, 10)); @@ -401,7 +485,14 @@ private function _readZipInfo(&$data) if ($dataLength < $lfhStart + 34) { - throw new RuntimeException('Invalid Zip Data'); + if (class_exists('JError')) + { + return JError::raiseWarning(100, 'Invalid Zip Data'); + } + else + { + throw new RuntimeException('Invalid Zip Data'); + } } $info = unpack('vMethod/VTime/VCRC32/VCompressed/VUncompressed/vLength/vExtraLength', substr($data, $lfhStart + 8, 25)); From 2dbf5ffbf6b24362eb12b1114735aa85bfbecedc Mon Sep 17 00:00:00 2001 From: eddieajau Date: Tue, 3 Apr 2012 14:18:36 +1000 Subject: [PATCH 35/98] Clean up form package exception handling. --- libraries/joomla/form/form.php | 50 +++++---------- libraries/joomla/form/rules/equals.php | 4 +- tests/suites/unit/joomla/form/JFormTest.php | 70 +++++++++------------ 3 files changed, 45 insertions(+), 79 deletions(-) diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index bb81a5dfb8..e9a6ae7d41 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -884,7 +884,6 @@ public function setField(JXMLElement $element, $group = null, $replace = true) // If an existing field is found and replace flag is false do nothing and return true. if (!$replace && !empty($old)) { - return true; } @@ -947,7 +946,6 @@ public function setFieldAttribute($name, $attribute, $value, $group = null) // If the element doesn't exist return false. if (!($element instanceof JXMLElement)) { - return false; } // Otherwise set the attribute and return true. @@ -989,7 +987,7 @@ public function setFields(&$elements, $group = null, $replace = true) { if (!($element instanceof JXMLElement)) { - throw new RuntimeException('Element is not an instance of JXMLElement'); + throw new UnexpectedValueException(sprintf('$element not JXmlElement in %s::setFields', get_class($this))); } } @@ -999,7 +997,6 @@ public function setFields(&$elements, $group = null, $replace = true) { if (!$this->setField($element, $group, $replace)) { - $return = false; } } @@ -1107,18 +1104,8 @@ public function validate($data, $group = null) // Check for an error. if ($valid instanceof Exception) { - switch ($valid->get('level')) - { - case E_ERROR: - JLog::add($valid->getMessage(), JLog::WARNING, 'jerror'); - return false; - break; - - default: - array_push($this->errors, $valid); - $return = false; - break; - } + array_push($this->errors, $valid); + $return = false; } } @@ -1818,22 +1805,16 @@ protected function syncPaths() * @param string $group The optional dot-separated form group path on which to find the field. * @param mixed $value The optional value to use as the default for the field. * @param JRegistry $input An optional JRegistry object with the entire data set to validate - * against the entire form. + * against the entire form. * - * @return mixed Boolean true if field value is valid, JException on failure. + * @return mixed Boolean true if field value is valid, Exception on failure. * * @since 11.1 - * @throws RuntimeException * @throws InvalidArgumentException + * @throws UnexpectedValueException */ - protected function validateField($element, $group = null, $value = null, $input = null) + protected function validateField(JXmlElement $element, $group = null, $value = null, JRegistry $input = null) { - // Make sure there is a valid JXMLElement. - if (!$element instanceof JXMLElement) - { - throw new InvalidArgumentException('Form field validation error'); - } - // Initialise variables. $valid = true; @@ -1845,7 +1826,6 @@ protected function validateField($element, $group = null, $value = null, $input // If the field is required and the value is empty return an error message. if (($value === '') || ($value === null)) { - // Does the field have a defined error message? if ($element['message']) { @@ -1863,7 +1843,8 @@ protected function validateField($element, $group = null, $value = null, $input } $message = sprintf('Field required: %s', $message); } - throw new RuntimeException($message); + + return new RuntimeException($message); } } @@ -1876,7 +1857,7 @@ protected function validateField($element, $group = null, $value = null, $input // If the object could not be loaded return an error message. if ($rule === false) { - throw new InvalidArgumentException(sprintf('Validation Rule missing: %s', $type)); + throw new UnexpectedValueException(sprintf('%s::validateField() rule `%s` missing.', get_class($this), $type)); } // Run the field validation rule test. @@ -1892,17 +1873,16 @@ protected function validateField($element, $group = null, $value = null, $input // Check if the field is valid. if ($valid === false) { - // Does the field have a defined error message? $message = (string) $element['message']; if ($message) { - throw new RuntimeException($message, 1, E_WARNING); + return new UnexpectedValueException($message); } else { - throw new InvalidArgumentException((string) $element['label']); + return new UnexpectedValueException((string) $element['label']); } } @@ -1981,7 +1961,7 @@ public static function getInstance($name, $data = null, $options = array(), $rep if (empty($data)) { - throw new InvalidArgumentException('No data passed to JForm::getInstance.'); + throw new InvalidArgumentException(sprintf('JForm::getInstance(name, *%s*)', gettype($data))); } // Instantiate the form. @@ -1992,14 +1972,14 @@ public static function getInstance($name, $data = null, $options = array(), $rep { if ($forms[$name]->load($data, $replace, $xpath) == false) { - throw new RuntimeException('JForm::getInstance could not load form.'); + throw new RuntimeException('JForm::getInstance could not load form'); } } else { if ($forms[$name]->loadFile($data, $replace, $xpath) == false) { - throw new RuntimeException('JForm::getInstance could not load file.'); + throw new RuntimeException('JForm::getInstance could not load file'); } } } diff --git a/libraries/joomla/form/rules/equals.php b/libraries/joomla/form/rules/equals.php index cc0cd72cc7..6bd1bbe4b4 100644 --- a/libraries/joomla/form/rules/equals.php +++ b/libraries/joomla/form/rules/equals.php @@ -44,13 +44,13 @@ public function test($element, $value, $group = null, $input = null, JForm $form // Check that a validation field is set. if (!$field) { - throw new InvalidArgumentException(sprintf('Invalid Form Rule: :%s', get_class($this))); + throw new UnexpectedValueException(sprintf('$field empty in %s::test', get_class($this))); } // Check that a valid JForm object is given for retrieving the validation field value. if (!($form instanceof JForm)) { - throw new InvalidArgumentException(sprintf('Invalid Form Object: :%s', get_class($this))); + throw new InvalidArgumentException(sprintf('%s::test(element, value, group, input, *%s*)', get_class($this), gettype($form))); } // Test the two values against each other. diff --git a/tests/suites/unit/joomla/form/JFormTest.php b/tests/suites/unit/joomla/form/JFormTest.php index 14d378f35d..cf23edb512 100644 --- a/tests/suites/unit/joomla/form/JFormTest.php +++ b/tests/suites/unit/joomla/form/JFormTest.php @@ -760,7 +760,7 @@ public function testGetErrors() ); $this->assertThat( - $errors[0] instanceof JException, + $errors[0] instanceof Exception, $this->isTrue(), 'Line:'.__LINE__.' The errors should be exception objects.' ); @@ -2104,6 +2104,11 @@ public function testValidate() /** * Test for JForm::validateField method. + * + * return void + * + * @covers JForm::validateField + * @since 11.1 */ public function testValidateField() { @@ -2119,61 +2124,22 @@ public function testValidateField() // Test error handling. - $result = $form->validateField('wrong'); - $this->assertThat( - $result instanceof Exception, - $this->isTrue(), - 'Line:'.__LINE__.' Passing a non-JXmlElement should return an exception.' - ); - - $this->assertThat( - $result->getCode(), - $this->equalTo(-1), - 'Line:'.__LINE__.' The correct exception should be returned.' - ); - - $field = array_pop($xml->xpath('fields/field[@name="missingrule"]')); - $result = $form->validateField($field, null, 'value'); - $this->assertThat( - $result instanceof Exception, - $this->isTrue(), - 'Line:'.__LINE__.' Having a missing validation rule should return an exception.' - ); - - $this->assertThat( - $result->getCode(), - $this->equalTo(-2), - 'Line:'.__LINE__.' The correct exception should be returned.' - ); - $field = array_pop($xml->xpath('fields/field[@name="boolean"]')); $result = $form->validateField($field); $this->assertThat( - $result instanceof Exception, + $result instanceof UnexpectedValueException, $this->isTrue(), 'Line:'.__LINE__.' A failed validation should return an exception.' ); - $this->assertThat( - $result->getCode(), - $this->equalTo(1), - 'Line:'.__LINE__.' The correct exception should be returned.' - ); - $field = array_pop($xml->xpath('fields/field[@name="required"]')); $result = $form->validateField($field); $this->assertThat( - $result instanceof Exception, + $result instanceof RuntimeException, $this->isTrue(), 'Line:'.__LINE__.' A required field missing a value should return an exception.' ); - $this->assertThat( - $result->getCode(), - $this->equalTo(2), - 'Line:'.__LINE__.' The correct exception should be returned.' - ); - // Test general usage. $field = array_pop($xml->xpath('fields/field[@name="boolean"]')); @@ -2197,4 +2163,24 @@ public function testValidateField() 'Line:'.__LINE__.' A required field with a value should return true.' ); } + + /** + * Test for JForm::validateField method for missing rule exception. + * + * return void + * + * @covers JForm::validateField + * @since 12.1 + * + * @expectedException UnexpectedValueException + */ + public function testValidateField_missingRule() + { + $form = new JFormInspector('form1'); + $form->load(JFormDataHelper::$validateFieldDocument); + $xml = $form->getXML(); + + $field = array_pop($xml->xpath('fields/field[@name="missingrule"]')); + $result = $form->validateField($field, null, 'value'); + } } From e03fee28838f0f281adca92318a013c346e13344 Mon Sep 17 00:00:00 2001 From: eddieajau Date: Tue, 3 Apr 2012 14:31:59 +1000 Subject: [PATCH 36/98] Format exception messages. --- libraries/joomla/mail/mail.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/mail/mail.php b/libraries/joomla/mail/mail.php index fd63e6a4be..380713da26 100644 --- a/libraries/joomla/mail/mail.php +++ b/libraries/joomla/mail/mail.php @@ -67,7 +67,7 @@ public static function getInstance($id = 'Joomla') /** * Send the mail * - * @return boolean True if successful + * @return mixed True if successful; JError if using legacy tree (no exception thrown in that case). * * @since 11.1 * @throws RuntimeException @@ -82,7 +82,7 @@ public function Send() } else { - throw new RuntimeException('Send function cancelled because mail is disabled.'); + throw new RuntimeException(sprintf('%s::Send mail not enabled.'), get_class($this)); } } @@ -96,7 +96,7 @@ public function Send() } else { - throw new RuntimeException('Send function cancelled because mail is disabled.'); + throw new RuntimeException(sprintf('%s::Send failed: "%s".'), get_class($this), $this->ErrorInfo); } } From fdb7a8521beafde97213f51d1591a948f25c3fc0 Mon Sep 17 00:00:00 2001 From: eddieajau Date: Tue, 3 Apr 2012 14:50:56 +1000 Subject: [PATCH 37/98] Tidy up exception messages. --- libraries/joomla/table/table.php | 12 ++++++------ libraries/joomla/table/usergroup.php | 9 +++++---- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libraries/joomla/table/table.php b/libraries/joomla/table/table.php index 28da8e016a..71c5691be8 100644 --- a/libraries/joomla/table/table.php +++ b/libraries/joomla/table/table.php @@ -432,7 +432,7 @@ public function bind($src, $ignore = array()) // If the source value is not an array or object return false. if (!is_object($src) && !is_array($src)) { - throw new UnexpectedValueException(sprintf('%s: :bind failed. Invalid source argument.', get_class($this))); + throw new InvalidArgumentException(sprintf('%s::bind(*%s*)', get_class($this), gettype($src))); } // If the source value is an object, get its accessible properties. @@ -471,7 +471,7 @@ public function bind($src, $ignore = array()) * set the instance property value is used. * @param boolean $reset True to reset the default values before loading the new row. * - * @return boolean True if successful. False if row not found or on error (internal error state set in that case). + * @return boolean True if successful. False if row not found. * * @link http://docs.joomla.org/JTable/load * @since 11.1 @@ -516,7 +516,7 @@ public function load($keys = null, $reset = true) // Check that $field is in the table. if (!in_array($field, $fields)) { - throw new UnexpectedValueException(sprintf('Missing field in the database: %s   %s.', get_class($this), $field)); + throw new UnexpectedValueException(sprintf('Missing field in database: %s   %s.', get_class($this), $field)); } // Add the search tuple to the query. $query->where($this->_db->quoteName($field) . ' = ' . $this->_db->quote($value)); @@ -529,7 +529,7 @@ public function load($keys = null, $reset = true) // Check that we have a result. if (empty($row)) { - throw new RuntimeException('The database row is empty.'); + return false; } // Bind the object with the row and return. @@ -1159,7 +1159,7 @@ public function move($delta, $where = '') * @param integer $state The publishing state. eg. [0 = unpublished, 1 = published] * @param integer $userId The user id of the user performing the operation. * - * @return boolean True on success. + * @return boolean True on success; false if $pks is empty. * * @link http://docs.joomla.org/JTable/publish * @since 11.1 @@ -1184,7 +1184,7 @@ public function publish($pks = null, $state = 1, $userId = 0) // Nothing to set publishing state on, return false. else { - throw new UnexpectedValueException('No rows selected for publishing state'); + return false; } } diff --git a/libraries/joomla/table/usergroup.php b/libraries/joomla/table/usergroup.php index 7aa54b54ad..cfb44ccd3d 100644 --- a/libraries/joomla/table/usergroup.php +++ b/libraries/joomla/table/usergroup.php @@ -143,7 +143,8 @@ public function store($updateNulls = false) * @return mixed Boolean or Exception. * * @since 11.1 - * @throws UnexpectedValueException + * @throws RuntimeException on database error. + * @throws UnexpectedValueException on data error. */ public function delete($oid = null) { @@ -157,11 +158,11 @@ public function delete($oid = null) } if ($this->parent_id == 0) { - return new JException('Root categories cannot be deleted.'); + throw new UnexpectedValueException('Root categories cannot be deleted.'); } if ($this->lft == 0 || $this->rgt == 0) { - throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete category.'); + throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete usergroup.'); } $db = $this->_db; @@ -176,7 +177,7 @@ public function delete($oid = null) $ids = $db->loadColumn(); if (empty($ids)) { - throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete category.'); + throw new UnexpectedValueException('Left-Right data inconsistency. Cannot delete usergroup.'); } // Delete the category dependencies From b11b608790eef305305d5f15c9cf463230ac155b Mon Sep 17 00:00:00 2001 From: eddieajau Date: Tue, 3 Apr 2012 14:57:25 +1000 Subject: [PATCH 38/98] Fix up B/C return. --- libraries/joomla/client/helper.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/client/helper.php b/libraries/joomla/client/helper.php index 7822d33835..4502f47c8a 100644 --- a/libraries/joomla/client/helper.php +++ b/libraries/joomla/client/helper.php @@ -198,10 +198,10 @@ public static function hasCredentials($client) * * @param string $client The name of the client. * - * @return mixed True, if FTP settings should be shown or an exception + * @return mixed True, if FTP settings; JError if using legacy tree. * * @since 11.1 - * @throws InvalidArgumentException + * @throws InvalidArgumentException if credentials invalid */ public static function setCredentialsFromRequest($client) { @@ -217,7 +217,14 @@ public static function setCredentialsFromRequest($client) } else { - throw new InvalidArgumentException('Invalid user credentials'); + if (class_exists('JError')) + { + $return = JError::raiseWarning('SOME_ERROR_CODE', JText::_('JLIB_CLIENT_ERROR_HELPER_SETCREDENTIALSFROMREQUEST_FAILED')); + } + else + { + throw new InvalidArgumentException('Invalid user credentials'); + } } } else From f744ed411f63ba8fb87739b9faf8a735a887ada3 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 22:09:39 -0700 Subject: [PATCH 39/98] Fixing a code style issue and PMD warning. --- libraries/joomla/installer/helper.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/joomla/installer/helper.php b/libraries/joomla/installer/helper.php index 3e939704f1..702ca1dbfa 100644 --- a/libraries/joomla/installer/helper.php +++ b/libraries/joomla/installer/helper.php @@ -104,7 +104,8 @@ public static function unpack($p_filename) $archivename = JPath::clean($archivename); // Do the unpacking of the archive - try { + try + { JArchive::extract($archivename, $extractdir); } catch (Exception $e) @@ -146,7 +147,8 @@ public static function unpack($p_filename) * Get the extension type and return the directory/type array on success or * false on fail. */ - if ($retval['type'] = self::detectType($extractdir)) + $retval['type'] = self::detectType($extractdir); + if ($retval['type']) { return $retval; } From b6db641a1de819f8cac7a4b2cf44a9aadfdd19cf Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 17:49:35 -0700 Subject: [PATCH 40/98] Moving the legacy tests into their own suite. --- build.xml | 200 +++++++++--------- legacy.xml.dist | 29 +++ phpunit.xml.dist | 30 +-- tests/bootstrap.legacy.php | 70 ++++++ tests/bootstrap.php | 2 +- tests/core/case/case.php | 48 +++-- tests/core/case/database.php | 53 ++++- .../application/JApplicationHelperTest.php | 0 .../legacy/application/JApplicationTest.php | 0 .../legacy/categories/JCategoriesTest.php | 0 .../legacy/categories/JCategoryNodeTest.php | 0 .../legacy/error/JErrorInspector.php | 0 .../{unit => }/legacy/error/JErrorTest.php | 0 .../legacy/exception/JExceptionTest.php | 0 .../form/field/JFormFieldHelpsiteTest.php | 12 +- .../legacy/form/field/JFormFieldMediaTest.php | 11 +- .../field/JFormFieldTemplateStyleTest.php | 8 - .../legacy/form/field/JFormFieldUserTest.php | 11 +- .../{unit => }/legacy/menu/JMenuTest.php | 0 .../legacy/pathway/JPathwayTest.php | 0 .../legacy/pathway/stubs/includes/pathway.php | 0 .../request/JFilterInput-mock-general.php | 0 .../request/JRequest-helper-dataset.php | 0 .../legacy/request/JRequestGetVarTest.php | 0 .../legacy/request/JRequestGetmethodTest.php | 0 .../legacy/request/JRequestTest.php | 0 .../legacy/table/JTableContentTest.php | 2 +- .../legacy/table/stubs/jos_content.csv | 0 .../legacy/toolbar/JToolbarButtonTest.php | 0 .../legacy/toolbar/JToolbarTest.php | 0 .../toolbar/button/JButtonConfirmTest.php | 0 .../toolbar/button/JButtonCustomTest.php | 0 .../legacy/toolbar/button/JButtonHelpTest.php | 0 .../legacy/toolbar/button/JButtonLinkTest.php | 0 .../toolbar/button/JButtonPopupTest.php | 0 .../toolbar/button/JButtonSeparatorTest.php | 0 .../toolbar/button/JButtonStandardTest.php | 0 37 files changed, 298 insertions(+), 178 deletions(-) create mode 100644 legacy.xml.dist create mode 100644 tests/bootstrap.legacy.php rename tests/suites/{unit => }/legacy/application/JApplicationHelperTest.php (100%) rename tests/suites/{unit => }/legacy/application/JApplicationTest.php (100%) rename tests/suites/{unit => }/legacy/categories/JCategoriesTest.php (100%) rename tests/suites/{unit => }/legacy/categories/JCategoryNodeTest.php (100%) rename tests/suites/{unit => }/legacy/error/JErrorInspector.php (100%) rename tests/suites/{unit => }/legacy/error/JErrorTest.php (100%) rename tests/suites/{unit => }/legacy/exception/JExceptionTest.php (100%) rename tests/suites/{unit => }/legacy/form/field/JFormFieldHelpsiteTest.php (80%) rename tests/suites/{unit => }/legacy/form/field/JFormFieldMediaTest.php (83%) rename tests/suites/{unit => }/legacy/form/field/JFormFieldTemplateStyleTest.php (88%) rename tests/suites/{unit => }/legacy/form/field/JFormFieldUserTest.php (84%) rename tests/suites/{unit => }/legacy/menu/JMenuTest.php (100%) rename tests/suites/{unit => }/legacy/pathway/JPathwayTest.php (100%) rename tests/suites/{unit => }/legacy/pathway/stubs/includes/pathway.php (100%) rename tests/suites/{unit => }/legacy/request/JFilterInput-mock-general.php (100%) rename tests/suites/{unit => }/legacy/request/JRequest-helper-dataset.php (100%) rename tests/suites/{unit => }/legacy/request/JRequestGetVarTest.php (100%) rename tests/suites/{unit => }/legacy/request/JRequestGetmethodTest.php (100%) rename tests/suites/{unit => }/legacy/request/JRequestTest.php (100%) rename tests/suites/{unit => }/legacy/table/JTableContentTest.php (98%) rename tests/suites/{unit => }/legacy/table/stubs/jos_content.csv (100%) rename tests/suites/{unit => }/legacy/toolbar/JToolbarButtonTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/JToolbarTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonConfirmTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonCustomTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonHelpTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonLinkTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonPopupTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonSeparatorTest.php (100%) rename tests/suites/{unit => }/legacy/toolbar/button/JButtonStandardTest.php (100%) diff --git a/build.xml b/build.xml index 1b864f5834..913360aac6 100644 --- a/build.xml +++ b/build.xml @@ -1,118 +1,114 @@ - - + + - - - - - - + + + + + + - - - - - - + + + + + + - - - + + + - - - - - - - - - - - - + + + + + - - - - - - - - + + + + + + + + + + + + - - - - - - - - - + + + + + + + + - - - - - - - + + + + + + + + + - - - - - - - + + + + + + + - - - - - - - - - + + + + + + + - - - - - - - - - - - - + + + + + + + + + - - - - - - - - - - + + + + + + + + + + + + - + + + + + + + + + + + + diff --git a/legacy.xml.dist b/legacy.xml.dist new file mode 100644 index 0000000000..eaf0d7a13c --- /dev/null +++ b/legacy.xml.dist @@ -0,0 +1,29 @@ + + + + + + + tests/suites/legacy + + + + + + + + + + + libraries/legacy + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 2dd052b7fc..fc4ce31eb9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,32 @@ - - - + + --> - - tests/suites - + + + tests/suites/database + + + tests/suites/unit + + - + - + - + libraries/joomla - libraries/legacy libraries/import.php libraries/loader.php libraries/platform.php diff --git a/tests/bootstrap.legacy.php b/tests/bootstrap.legacy.php new file mode 100644 index 0000000000..c785123450 --- /dev/null +++ b/tests/bootstrap.legacy.php @@ -0,0 +1,70 @@ +expectedErrors)) { $this->expectedErrors = array(); - JError::setErrorHandling(E_NOTICE, 'callback', array($this, 'expectedErrorCallback')); - JError::setErrorHandling(E_WARNING, 'callback', array($this, 'expectedErrorCallback')); - JError::setErrorHandling(E_ERROR, 'callback', array($this, 'expectedErrorCallback')); + + // Handle optional usage of JError until removed. + if (class_exists('JError')) + { + JError::setErrorHandling(E_NOTICE, 'callback', array($this, 'expectedErrorCallback')); + JError::setErrorHandling(E_WARNING, 'callback', array($this, 'expectedErrorCallback')); + JError::setErrorHandling(E_ERROR, 'callback', array($this, 'expectedErrorCallback')); + } } if (!is_null($error)) @@ -354,9 +359,14 @@ protected function restoreFactoryState() protected function saveErrorHandlers() { $this->_stashedErrorState = array(); - $this->_stashedErrorState[E_NOTICE] = JError::getErrorHandling(E_NOTICE); - $this->_stashedErrorState[E_WARNING] = JError::getErrorHandling(E_WARNING); - $this->_stashedErrorState[E_ERROR] = JError::getErrorHandling(E_ERROR); + + // Handle optional usage of JError until removed. + if (class_exists('JError')) + { + $this->_stashedErrorState[E_NOTICE] = JError::getErrorHandling(E_NOTICE); + $this->_stashedErrorState[E_WARNING] = JError::getErrorHandling(E_WARNING); + $this->_stashedErrorState[E_ERROR] = JError::getErrorHandling(E_ERROR); + } } /** @@ -396,13 +406,17 @@ protected function setErrorHandlers($errorHandlers) { $mode = $params['mode']; - if (isset($params['options'])) + // Handle optional usage of JError until removed. + if (class_exists('JError')) { - JError::setErrorHandling($type, $mode, $params['options']); - } - else - { - JError::setErrorHandling($type, $mode); + if (isset($params['options'])) + { + JError::setErrorHandling($type, $mode, $params['options']); + } + else + { + JError::setErrorHandling($type, $mode); + } } } } @@ -456,9 +470,13 @@ protected function tearDown() $this->fail('An expected error was not raised.'); } - JError::setErrorHandling(E_NOTICE, 'ignore'); - JError::setErrorHandling(E_WARNING, 'ignore'); - JError::setErrorHandling(E_ERROR, 'ignore'); + // Handle optional usage of JError until removed. + if (class_exists('JError')) + { + JError::setErrorHandling(E_NOTICE, 'ignore'); + JError::setErrorHandling(E_WARNING, 'ignore'); + JError::setErrorHandling(E_ERROR, 'ignore'); + } parent::tearDown(); } diff --git a/tests/core/case/database.php b/tests/core/case/database.php index 08be50b762..9405e3c692 100644 --- a/tests/core/case/database.php +++ b/tests/core/case/database.php @@ -389,9 +389,14 @@ protected function restoreFactoryState() protected function saveErrorHandlers() { $this->_stashedErrorState = array(); - $this->_stashedErrorState[E_NOTICE] = JError::getErrorHandling(E_NOTICE); - $this->_stashedErrorState[E_WARNING] = JError::getErrorHandling(E_WARNING); - $this->_stashedErrorState[E_ERROR] = JError::getErrorHandling(E_ERROR); + + // Handle optional usage of JError until removed. + if (class_exists('JError')) + { + $this->_stashedErrorState[E_NOTICE] = JError::getErrorHandling(E_NOTICE); + $this->_stashedErrorState[E_WARNING] = JError::getErrorHandling(E_WARNING); + $this->_stashedErrorState[E_ERROR] = JError::getErrorHandling(E_ERROR); + } } /** @@ -431,13 +436,17 @@ protected function setErrorHandlers($errorHandlers) { $mode = $params['mode']; - if (isset($params['options'])) - { - JError::setErrorHandling($type, $mode, $params['options']); - } - else + // Handle optional usage of JError until removed. + if (class_exists('JError')) { - JError::setErrorHandling($type, $mode); + if (isset($params['options'])) + { + JError::setErrorHandling($type, $mode, $params['options']); + } + else + { + JError::setErrorHandling($type, $mode); + } } } } @@ -479,4 +488,30 @@ protected function setUp() parent::setUp(); } + + /** + * Overrides the parent tearDown method. + * + * @return void + * + * @see PHPUnit_Framework_TestCase::tearDown() + * @since 11.1 + */ + protected function tearDown() + { + if (is_array($this->expectedErrors) && !empty($this->expectedErrors)) + { + $this->fail('An expected error was not raised.'); + } + + // Handle optional usage of JError until removed. + if (class_exists('JError')) + { + JError::setErrorHandling(E_NOTICE, 'ignore'); + JError::setErrorHandling(E_WARNING, 'ignore'); + JError::setErrorHandling(E_ERROR, 'ignore'); + } + + parent::tearDown(); + } } diff --git a/tests/suites/unit/legacy/application/JApplicationHelperTest.php b/tests/suites/legacy/application/JApplicationHelperTest.php similarity index 100% rename from tests/suites/unit/legacy/application/JApplicationHelperTest.php rename to tests/suites/legacy/application/JApplicationHelperTest.php diff --git a/tests/suites/unit/legacy/application/JApplicationTest.php b/tests/suites/legacy/application/JApplicationTest.php similarity index 100% rename from tests/suites/unit/legacy/application/JApplicationTest.php rename to tests/suites/legacy/application/JApplicationTest.php diff --git a/tests/suites/unit/legacy/categories/JCategoriesTest.php b/tests/suites/legacy/categories/JCategoriesTest.php similarity index 100% rename from tests/suites/unit/legacy/categories/JCategoriesTest.php rename to tests/suites/legacy/categories/JCategoriesTest.php diff --git a/tests/suites/unit/legacy/categories/JCategoryNodeTest.php b/tests/suites/legacy/categories/JCategoryNodeTest.php similarity index 100% rename from tests/suites/unit/legacy/categories/JCategoryNodeTest.php rename to tests/suites/legacy/categories/JCategoryNodeTest.php diff --git a/tests/suites/unit/legacy/error/JErrorInspector.php b/tests/suites/legacy/error/JErrorInspector.php similarity index 100% rename from tests/suites/unit/legacy/error/JErrorInspector.php rename to tests/suites/legacy/error/JErrorInspector.php diff --git a/tests/suites/unit/legacy/error/JErrorTest.php b/tests/suites/legacy/error/JErrorTest.php similarity index 100% rename from tests/suites/unit/legacy/error/JErrorTest.php rename to tests/suites/legacy/error/JErrorTest.php diff --git a/tests/suites/unit/legacy/exception/JExceptionTest.php b/tests/suites/legacy/exception/JExceptionTest.php similarity index 100% rename from tests/suites/unit/legacy/exception/JExceptionTest.php rename to tests/suites/legacy/exception/JExceptionTest.php diff --git a/tests/suites/unit/legacy/form/field/JFormFieldHelpsiteTest.php b/tests/suites/legacy/form/field/JFormFieldHelpsiteTest.php similarity index 80% rename from tests/suites/unit/legacy/form/field/JFormFieldHelpsiteTest.php rename to tests/suites/legacy/form/field/JFormFieldHelpsiteTest.php index 8334332c45..75b8615d99 100644 --- a/tests/suites/unit/legacy/form/field/JFormFieldHelpsiteTest.php +++ b/tests/suites/legacy/form/field/JFormFieldHelpsiteTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JForm. * @@ -15,16 +17,6 @@ */ class JFormFieldHelpsiteTest extends TestCase { - /** - * Sets up dependancies for the test. - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/legacy/help/help.php'; - require_once JPATH_PLATFORM . '/legacy/form/field/helpsite.php'; - include_once dirname(dirname(dirname(__DIR__))) . '/joomla/form/inspectors.php'; - } - /** * Test the getInput method. * @covers JFormFieldHelpsite::getOptions diff --git a/tests/suites/unit/legacy/form/field/JFormFieldMediaTest.php b/tests/suites/legacy/form/field/JFormFieldMediaTest.php similarity index 83% rename from tests/suites/unit/legacy/form/field/JFormFieldMediaTest.php rename to tests/suites/legacy/form/field/JFormFieldMediaTest.php index a98962574a..16dc95d36c 100644 --- a/tests/suites/unit/legacy/form/field/JFormFieldMediaTest.php +++ b/tests/suites/legacy/form/field/JFormFieldMediaTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JForm. * @@ -15,15 +17,6 @@ */ class JFormFieldMediaTest extends TestCase { - /** - * Sets up dependancies for the test. - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/legacy/form/field/media.php'; - include_once dirname(dirname(dirname(__DIR__))) . '/joomla/form/inspectors.php'; - } - /** * Test the getInput method. * @covers JFormFieldMedia::getInput diff --git a/tests/suites/unit/legacy/form/field/JFormFieldTemplateStyleTest.php b/tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php similarity index 88% rename from tests/suites/unit/legacy/form/field/JFormFieldTemplateStyleTest.php rename to tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php index b147ea3773..91f54fb97f 100644 --- a/tests/suites/unit/legacy/form/field/JFormFieldTemplateStyleTest.php +++ b/tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php @@ -15,14 +15,6 @@ */ class JFormFieldTemplateStyleTest extends TestCase { - /** - * Sets up dependancies for the test. - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/legacy/form/field/templatestyle.php'; - } - /** * Test the getInput method. * @covers JFormFieldTemplateStyle::getGroups diff --git a/tests/suites/unit/legacy/form/field/JFormFieldUserTest.php b/tests/suites/legacy/form/field/JFormFieldUserTest.php similarity index 84% rename from tests/suites/unit/legacy/form/field/JFormFieldUserTest.php rename to tests/suites/legacy/form/field/JFormFieldUserTest.php index 23d070a537..3bdd3cf6c8 100644 --- a/tests/suites/unit/legacy/form/field/JFormFieldUserTest.php +++ b/tests/suites/legacy/form/field/JFormFieldUserTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JForm. * @@ -15,15 +17,6 @@ */ class JFormFieldUserTest extends TestCase { - /** - * Sets up dependancies for the test. - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/legacy/form/field/user.php'; - include_once dirname(dirname(dirname(__DIR__))) . '/joomla/form/inspectors.php'; - } - /** * Test the getInput method. * @covers JFormFieldUser::getInput() diff --git a/tests/suites/unit/legacy/menu/JMenuTest.php b/tests/suites/legacy/menu/JMenuTest.php similarity index 100% rename from tests/suites/unit/legacy/menu/JMenuTest.php rename to tests/suites/legacy/menu/JMenuTest.php diff --git a/tests/suites/unit/legacy/pathway/JPathwayTest.php b/tests/suites/legacy/pathway/JPathwayTest.php similarity index 100% rename from tests/suites/unit/legacy/pathway/JPathwayTest.php rename to tests/suites/legacy/pathway/JPathwayTest.php diff --git a/tests/suites/unit/legacy/pathway/stubs/includes/pathway.php b/tests/suites/legacy/pathway/stubs/includes/pathway.php similarity index 100% rename from tests/suites/unit/legacy/pathway/stubs/includes/pathway.php rename to tests/suites/legacy/pathway/stubs/includes/pathway.php diff --git a/tests/suites/unit/legacy/request/JFilterInput-mock-general.php b/tests/suites/legacy/request/JFilterInput-mock-general.php similarity index 100% rename from tests/suites/unit/legacy/request/JFilterInput-mock-general.php rename to tests/suites/legacy/request/JFilterInput-mock-general.php diff --git a/tests/suites/unit/legacy/request/JRequest-helper-dataset.php b/tests/suites/legacy/request/JRequest-helper-dataset.php similarity index 100% rename from tests/suites/unit/legacy/request/JRequest-helper-dataset.php rename to tests/suites/legacy/request/JRequest-helper-dataset.php diff --git a/tests/suites/unit/legacy/request/JRequestGetVarTest.php b/tests/suites/legacy/request/JRequestGetVarTest.php similarity index 100% rename from tests/suites/unit/legacy/request/JRequestGetVarTest.php rename to tests/suites/legacy/request/JRequestGetVarTest.php diff --git a/tests/suites/unit/legacy/request/JRequestGetmethodTest.php b/tests/suites/legacy/request/JRequestGetmethodTest.php similarity index 100% rename from tests/suites/unit/legacy/request/JRequestGetmethodTest.php rename to tests/suites/legacy/request/JRequestGetmethodTest.php diff --git a/tests/suites/unit/legacy/request/JRequestTest.php b/tests/suites/legacy/request/JRequestTest.php similarity index 100% rename from tests/suites/unit/legacy/request/JRequestTest.php rename to tests/suites/legacy/request/JRequestTest.php diff --git a/tests/suites/unit/legacy/table/JTableContentTest.php b/tests/suites/legacy/table/JTableContentTest.php similarity index 98% rename from tests/suites/unit/legacy/table/JTableContentTest.php rename to tests/suites/legacy/table/JTableContentTest.php index 68c556c126..c57b5e81be 100644 --- a/tests/suites/unit/legacy/table/JTableContentTest.php +++ b/tests/suites/legacy/table/JTableContentTest.php @@ -56,7 +56,7 @@ protected function getDataSet() { $dataSet = new PHPUnit_Extensions_Database_DataSet_CsvDataSet(',', "'", '\\'); - $stubpath = dirname(dirname(__DIR__)) . '/joomla/table/stubs'; + $stubpath = JPATH_TESTS . '/suites/unit/joomla/table/stubs'; $dataSet->addTable('jos_assets', $stubpath . '/jos_assets.csv'); $dataSet->addTable('jos_categories', $stubpath . '/jos_categories.csv'); diff --git a/tests/suites/unit/legacy/table/stubs/jos_content.csv b/tests/suites/legacy/table/stubs/jos_content.csv similarity index 100% rename from tests/suites/unit/legacy/table/stubs/jos_content.csv rename to tests/suites/legacy/table/stubs/jos_content.csv diff --git a/tests/suites/unit/legacy/toolbar/JToolbarButtonTest.php b/tests/suites/legacy/toolbar/JToolbarButtonTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/JToolbarButtonTest.php rename to tests/suites/legacy/toolbar/JToolbarButtonTest.php diff --git a/tests/suites/unit/legacy/toolbar/JToolbarTest.php b/tests/suites/legacy/toolbar/JToolbarTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/JToolbarTest.php rename to tests/suites/legacy/toolbar/JToolbarTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonConfirmTest.php b/tests/suites/legacy/toolbar/button/JButtonConfirmTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonConfirmTest.php rename to tests/suites/legacy/toolbar/button/JButtonConfirmTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonCustomTest.php b/tests/suites/legacy/toolbar/button/JButtonCustomTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonCustomTest.php rename to tests/suites/legacy/toolbar/button/JButtonCustomTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonHelpTest.php b/tests/suites/legacy/toolbar/button/JButtonHelpTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonHelpTest.php rename to tests/suites/legacy/toolbar/button/JButtonHelpTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonLinkTest.php b/tests/suites/legacy/toolbar/button/JButtonLinkTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonLinkTest.php rename to tests/suites/legacy/toolbar/button/JButtonLinkTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonPopupTest.php b/tests/suites/legacy/toolbar/button/JButtonPopupTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonPopupTest.php rename to tests/suites/legacy/toolbar/button/JButtonPopupTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonSeparatorTest.php b/tests/suites/legacy/toolbar/button/JButtonSeparatorTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonSeparatorTest.php rename to tests/suites/legacy/toolbar/button/JButtonSeparatorTest.php diff --git a/tests/suites/unit/legacy/toolbar/button/JButtonStandardTest.php b/tests/suites/legacy/toolbar/button/JButtonStandardTest.php similarity index 100% rename from tests/suites/unit/legacy/toolbar/button/JButtonStandardTest.php rename to tests/suites/legacy/toolbar/button/JButtonStandardTest.php From ffc975121ebfed4511d6285e1c4121009f69670a Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 18:03:24 -0700 Subject: [PATCH 41/98] Move classes JComponentHelper, JController*, JModel*, JModuleHelper and JView to the legacy tree. --- libraries/{joomla/application => legacy}/component/helper.php | 0 .../component/controlleradmin.php => legacy/controller/admin.php} | 0 .../application/component => legacy/controller}/controller.php | 0 .../component/controllerform.php => legacy/controller/form.php} | 0 .../component/modeladmin.php => legacy/model/admin.php} | 0 .../application/component/modelform.php => legacy/model/form.php} | 0 .../application/component/modelitem.php => legacy/model/item.php} | 0 .../application/component/modellist.php => legacy/model/list.php} | 0 .../{joomla/application/component => legacy/model}/model.php | 0 libraries/{joomla/application => legacy}/module/helper.php | 0 libraries/{joomla/application/component => legacy/view}/view.php | 0 .../application => legacy}/component/JComponentHelperTest.php | 0 .../component => legacy/controller}/JControllerAdminTest.php | 0 .../component => legacy/controller}/JControllerFormTest.php | 0 .../component => legacy/controller}/JControllerTest.php | 0 .../controller}/stubs/component1/controller.json.php | 0 .../controller}/stubs/component2/controller.php | 0 .../component => legacy/controller}/stubs/controller.php | 0 .../component => legacy/controller}/stubs/controllerform.php | 0 .../application/component => legacy/model}/JModelAdminTest.php | 0 .../application/component => legacy/model}/JModelFormTest.php | 0 .../application/component => legacy/model}/JModelItemTest.php | 0 .../application/component => legacy/model}/JModelListTest.php | 0 .../joomla/application/component => legacy/model}/JModelTest.php | 0 .../joomla/application => legacy}/module/JModuleHelperTest.php | 0 .../joomla/application/component => legacy/view}/JViewTest.php | 0 26 files changed, 0 insertions(+), 0 deletions(-) rename libraries/{joomla/application => legacy}/component/helper.php (100%) rename libraries/{joomla/application/component/controlleradmin.php => legacy/controller/admin.php} (100%) rename libraries/{joomla/application/component => legacy/controller}/controller.php (100%) rename libraries/{joomla/application/component/controllerform.php => legacy/controller/form.php} (100%) rename libraries/{joomla/application/component/modeladmin.php => legacy/model/admin.php} (100%) rename libraries/{joomla/application/component/modelform.php => legacy/model/form.php} (100%) rename libraries/{joomla/application/component/modelitem.php => legacy/model/item.php} (100%) rename libraries/{joomla/application/component/modellist.php => legacy/model/list.php} (100%) rename libraries/{joomla/application/component => legacy/model}/model.php (100%) rename libraries/{joomla/application => legacy}/module/helper.php (100%) rename libraries/{joomla/application/component => legacy/view}/view.php (100%) rename tests/suites/{unit/joomla/application => legacy}/component/JComponentHelperTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/JControllerAdminTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/JControllerFormTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/JControllerTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/stubs/component1/controller.json.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/stubs/component2/controller.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/stubs/controller.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/controller}/stubs/controllerform.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/model}/JModelAdminTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/model}/JModelFormTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/model}/JModelItemTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/model}/JModelListTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/model}/JModelTest.php (100%) rename tests/suites/{unit/joomla/application => legacy}/module/JModuleHelperTest.php (100%) rename tests/suites/{unit/joomla/application/component => legacy/view}/JViewTest.php (100%) diff --git a/libraries/joomla/application/component/helper.php b/libraries/legacy/component/helper.php similarity index 100% rename from libraries/joomla/application/component/helper.php rename to libraries/legacy/component/helper.php diff --git a/libraries/joomla/application/component/controlleradmin.php b/libraries/legacy/controller/admin.php similarity index 100% rename from libraries/joomla/application/component/controlleradmin.php rename to libraries/legacy/controller/admin.php diff --git a/libraries/joomla/application/component/controller.php b/libraries/legacy/controller/controller.php similarity index 100% rename from libraries/joomla/application/component/controller.php rename to libraries/legacy/controller/controller.php diff --git a/libraries/joomla/application/component/controllerform.php b/libraries/legacy/controller/form.php similarity index 100% rename from libraries/joomla/application/component/controllerform.php rename to libraries/legacy/controller/form.php diff --git a/libraries/joomla/application/component/modeladmin.php b/libraries/legacy/model/admin.php similarity index 100% rename from libraries/joomla/application/component/modeladmin.php rename to libraries/legacy/model/admin.php diff --git a/libraries/joomla/application/component/modelform.php b/libraries/legacy/model/form.php similarity index 100% rename from libraries/joomla/application/component/modelform.php rename to libraries/legacy/model/form.php diff --git a/libraries/joomla/application/component/modelitem.php b/libraries/legacy/model/item.php similarity index 100% rename from libraries/joomla/application/component/modelitem.php rename to libraries/legacy/model/item.php diff --git a/libraries/joomla/application/component/modellist.php b/libraries/legacy/model/list.php similarity index 100% rename from libraries/joomla/application/component/modellist.php rename to libraries/legacy/model/list.php diff --git a/libraries/joomla/application/component/model.php b/libraries/legacy/model/model.php similarity index 100% rename from libraries/joomla/application/component/model.php rename to libraries/legacy/model/model.php diff --git a/libraries/joomla/application/module/helper.php b/libraries/legacy/module/helper.php similarity index 100% rename from libraries/joomla/application/module/helper.php rename to libraries/legacy/module/helper.php diff --git a/libraries/joomla/application/component/view.php b/libraries/legacy/view/view.php similarity index 100% rename from libraries/joomla/application/component/view.php rename to libraries/legacy/view/view.php diff --git a/tests/suites/unit/joomla/application/component/JComponentHelperTest.php b/tests/suites/legacy/component/JComponentHelperTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JComponentHelperTest.php rename to tests/suites/legacy/component/JComponentHelperTest.php diff --git a/tests/suites/unit/joomla/application/component/JControllerAdminTest.php b/tests/suites/legacy/controller/JControllerAdminTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JControllerAdminTest.php rename to tests/suites/legacy/controller/JControllerAdminTest.php diff --git a/tests/suites/unit/joomla/application/component/JControllerFormTest.php b/tests/suites/legacy/controller/JControllerFormTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JControllerFormTest.php rename to tests/suites/legacy/controller/JControllerFormTest.php diff --git a/tests/suites/unit/joomla/application/component/JControllerTest.php b/tests/suites/legacy/controller/JControllerTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JControllerTest.php rename to tests/suites/legacy/controller/JControllerTest.php diff --git a/tests/suites/unit/joomla/application/component/stubs/component1/controller.json.php b/tests/suites/legacy/controller/stubs/component1/controller.json.php similarity index 100% rename from tests/suites/unit/joomla/application/component/stubs/component1/controller.json.php rename to tests/suites/legacy/controller/stubs/component1/controller.json.php diff --git a/tests/suites/unit/joomla/application/component/stubs/component2/controller.php b/tests/suites/legacy/controller/stubs/component2/controller.php similarity index 100% rename from tests/suites/unit/joomla/application/component/stubs/component2/controller.php rename to tests/suites/legacy/controller/stubs/component2/controller.php diff --git a/tests/suites/unit/joomla/application/component/stubs/controller.php b/tests/suites/legacy/controller/stubs/controller.php similarity index 100% rename from tests/suites/unit/joomla/application/component/stubs/controller.php rename to tests/suites/legacy/controller/stubs/controller.php diff --git a/tests/suites/unit/joomla/application/component/stubs/controllerform.php b/tests/suites/legacy/controller/stubs/controllerform.php similarity index 100% rename from tests/suites/unit/joomla/application/component/stubs/controllerform.php rename to tests/suites/legacy/controller/stubs/controllerform.php diff --git a/tests/suites/unit/joomla/application/component/JModelAdminTest.php b/tests/suites/legacy/model/JModelAdminTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JModelAdminTest.php rename to tests/suites/legacy/model/JModelAdminTest.php diff --git a/tests/suites/unit/joomla/application/component/JModelFormTest.php b/tests/suites/legacy/model/JModelFormTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JModelFormTest.php rename to tests/suites/legacy/model/JModelFormTest.php diff --git a/tests/suites/unit/joomla/application/component/JModelItemTest.php b/tests/suites/legacy/model/JModelItemTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JModelItemTest.php rename to tests/suites/legacy/model/JModelItemTest.php diff --git a/tests/suites/unit/joomla/application/component/JModelListTest.php b/tests/suites/legacy/model/JModelListTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JModelListTest.php rename to tests/suites/legacy/model/JModelListTest.php diff --git a/tests/suites/unit/joomla/application/component/JModelTest.php b/tests/suites/legacy/model/JModelTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JModelTest.php rename to tests/suites/legacy/model/JModelTest.php diff --git a/tests/suites/unit/joomla/application/module/JModuleHelperTest.php b/tests/suites/legacy/module/JModuleHelperTest.php similarity index 100% rename from tests/suites/unit/joomla/application/module/JModuleHelperTest.php rename to tests/suites/legacy/module/JModuleHelperTest.php diff --git a/tests/suites/unit/joomla/application/component/JViewTest.php b/tests/suites/legacy/view/JViewTest.php similarity index 100% rename from tests/suites/unit/joomla/application/component/JViewTest.php rename to tests/suites/legacy/view/JViewTest.php From 2c7f109cfa85afc56239836d0b85778b42bfad5f Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 18:06:53 -0700 Subject: [PATCH 42/98] Remove unnecessary calls to jimport() for autoloadable classes. --- build/changelog.php | 2 -- libraries/joomla/document/html/html.php | 1 - libraries/legacy/application/application.php | 2 -- libraries/legacy/controller/admin.php | 2 -- libraries/legacy/controller/controller.php | 1 - libraries/legacy/controller/form.php | 2 -- libraries/legacy/model/admin.php | 2 -- libraries/legacy/model/form.php | 2 -- libraries/legacy/model/item.php | 2 -- libraries/legacy/model/list.php | 2 -- libraries/legacy/module/helper.php | 2 -- tests/suites/unit/joomla/access/JAccessTest.php | 2 -- tests/suites/unit/joomla/user/JUserTest.php | 3 --- 13 files changed, 25 deletions(-) diff --git a/build/changelog.php b/build/changelog.php index 509abe973e..2751a162d2 100755 --- a/build/changelog.php +++ b/build/changelog.php @@ -24,8 +24,6 @@ // Bootstrap the application. require realpath('../libraries/import.php'); -jimport('joomla.application.cli'); - /** * Joomla Platform Changelog builder. * diff --git a/libraries/joomla/document/html/html.php b/libraries/joomla/document/html/html.php index 37cd9762e1..8c69613407 100644 --- a/libraries/joomla/document/html/html.php +++ b/libraries/joomla/document/html/html.php @@ -9,7 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.module.helper'); jimport('joomla.utilities.utility'); /** diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index 22dc515d87..9211f1a1d6 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -878,7 +878,6 @@ public function getPathway($name = null, $options = array()) $name = $this->_name; } - jimport('joomla.application.pathway'); $pathway = JPathway::getInstance($name, $options); if ($pathway instanceof Exception) @@ -906,7 +905,6 @@ public function getMenu($name = null, $options = array()) $name = $this->_name; } - jimport('joomla.application.menu'); $menu = JMenu::getInstance($name, $options); if ($menu instanceof Exception) diff --git a/libraries/legacy/controller/admin.php b/libraries/legacy/controller/admin.php index fa1e413423..cdf7a34369 100644 --- a/libraries/legacy/controller/admin.php +++ b/libraries/legacy/controller/admin.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.controller'); - /** * Base class for a Joomla Administrator Controller * diff --git a/libraries/legacy/controller/controller.php b/libraries/legacy/controller/controller.php index cce8a3106b..00546a086b 100644 --- a/libraries/legacy/controller/controller.php +++ b/libraries/legacy/controller/controller.php @@ -143,7 +143,6 @@ class JController extends JObject */ public static function addModelPath($path, $prefix = '') { - jimport('joomla.application.component.model'); JModel::addIncludePath($path, $prefix); } diff --git a/libraries/legacy/controller/form.php b/libraries/legacy/controller/form.php index 723ec9ef07..33f935b3a5 100644 --- a/libraries/legacy/controller/form.php +++ b/libraries/legacy/controller/form.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.controller'); - /** * Controller tailored to suit most form-based admin operations. * diff --git a/libraries/legacy/model/admin.php b/libraries/legacy/model/admin.php index e5cb970256..6eef1e8f0e 100644 --- a/libraries/legacy/model/admin.php +++ b/libraries/legacy/model/admin.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.modelform'); - /** * Prototype admin model. * diff --git a/libraries/legacy/model/form.php b/libraries/legacy/model/form.php index e115bbc696..034e4ac989 100644 --- a/libraries/legacy/model/form.php +++ b/libraries/legacy/model/form.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.model'); - /** * Prototype form model. * diff --git a/libraries/legacy/model/item.php b/libraries/legacy/model/item.php index 90e13f3aaf..165db0d376 100644 --- a/libraries/legacy/model/item.php +++ b/libraries/legacy/model/item.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.model'); - /** * Prototype item model. * diff --git a/libraries/legacy/model/list.php b/libraries/legacy/model/list.php index 7e87d704db..4e110b4fda 100644 --- a/libraries/legacy/model/list.php +++ b/libraries/legacy/model/list.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.model'); - /** * Model class for handling lists of items. * diff --git a/libraries/legacy/module/helper.php b/libraries/legacy/module/helper.php index 274b5f187f..1f14f8360d 100644 --- a/libraries/legacy/module/helper.php +++ b/libraries/legacy/module/helper.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.application.component.helper'); - /** * Module helper class * diff --git a/tests/suites/unit/joomla/access/JAccessTest.php b/tests/suites/unit/joomla/access/JAccessTest.php index 09b7097408..de282f1b1f 100644 --- a/tests/suites/unit/joomla/access/JAccessTest.php +++ b/tests/suites/unit/joomla/access/JAccessTest.php @@ -441,8 +441,6 @@ public function testGetGroupsByUser() $this->equalTo(JAccess::getGroupsByUser(42, False)) ); - jimport('joomla.application.component.helper'); - $this->assertThat( JAccess::getGroupsByUser(null), $this->equalTo(array(1)) diff --git a/tests/suites/unit/joomla/user/JUserTest.php b/tests/suites/unit/joomla/user/JUserTest.php index c410ccaa6b..2bd642ee12 100644 --- a/tests/suites/unit/joomla/user/JUserTest.php +++ b/tests/suites/unit/joomla/user/JUserTest.php @@ -37,9 +37,6 @@ protected function setUp() parent::setUp(); $this->object = new JUser('42'); - - // Ensure we have JComponentHelper (needed in case class is tested in isolation) - jimport('joomla.application.component.helper'); } /** From 65ceccc773aaff82846e45f773276769bb3c0b02 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Mon, 2 Apr 2012 23:44:13 -0700 Subject: [PATCH 43/98] Fixing unit tests after re-organization. --- build.xml | 3 ++- libraries/joomla/access/access.php | 14 ++++++++-- libraries/joomla/database/driver/mysqli.php | 14 +--------- libraries/joomla/database/driver/sqlsrv.php | 14 +--------- libraries/joomla/filesystem/folder.php | 2 +- libraries/joomla/form/form.php | 2 +- libraries/joomla/log/log.php | 3 +-- libraries/joomla/object/object.php | 2 +- libraries/joomla/registry/format.php | 4 +-- libraries/joomla/session/session.php | 11 +++++++- libraries/joomla/session/storage.php | 2 +- libraries/joomla/utilities/date.php | 3 --- .../fields => legacy/form/field}/category.php | 0 .../form/field}/componentlayout.php | 2 +- .../fields => legacy/form/field}/menu.php | 0 .../form/field}/modulelayout.php | 2 +- tests/core/case/database.php | 26 ------------------- .../legacy/component/JComponentHelperTest.php | 2 -- .../controller/JControllerAdminTest.php | 2 -- .../legacy/controller/JControllerFormTest.php | 1 - .../legacy/controller/JControllerTest.php | 4 --- .../form/field}/JFormFieldCategoryTest.php | 17 +++--------- .../field}/JFormFieldComponentLayoutTest.php | 17 +++--------- .../field}/JFormFieldModuleLayoutTest.php | 17 +++--------- tests/suites/legacy/model/JModelAdminTest.php | 2 -- tests/suites/legacy/model/JModelFormTest.php | 2 -- tests/suites/legacy/model/JModelItemTest.php | 2 -- tests/suites/legacy/model/JModelListTest.php | 2 -- tests/suites/legacy/model/JModelTest.php | 2 -- .../legacy/module/JModuleHelperTest.php | 2 -- tests/suites/legacy/view/JViewTest.php | 1 - .../opensearch/JDocumentOpensearchTest.php | 21 ++------------- .../unit/joomla/html/html/JHtmlFormTest.php | 2 ++ 33 files changed, 48 insertions(+), 152 deletions(-) rename libraries/{joomla/form/fields => legacy/form/field}/category.php (100%) rename libraries/{joomla/form/fields => legacy/form/field}/componentlayout.php (99%) rename libraries/{joomla/form/fields => legacy/form/field}/menu.php (100%) rename libraries/{joomla/form/fields => legacy/form/field}/modulelayout.php (99%) rename tests/suites/{unit/joomla/form/fields => legacy/form/field}/JFormFieldCategoryTest.php (80%) rename tests/suites/{unit/joomla/form/fields => legacy/form/field}/JFormFieldComponentLayoutTest.php (80%) rename tests/suites/{unit/joomla/form/fields => legacy/form/field}/JFormFieldModuleLayoutTest.php (80%) diff --git a/build.xml b/build.xml index 913360aac6..86d49319b7 100644 --- a/build.xml +++ b/build.xml @@ -24,7 +24,8 @@ - + + diff --git a/libraries/joomla/access/access.php b/libraries/joomla/access/access.php index 781f9bb031..a4c7810090 100644 --- a/libraries/joomla/access/access.php +++ b/libraries/joomla/access/access.php @@ -282,10 +282,20 @@ public static function getGroupsByUser($userId, $recursive = true) if (!isset(self::$groupsByUser[$storeId])) { + // TODO: Uncouple this from JComponentHelper and allow for a configuration setting or value injection. + if (class_exists('JComponentHelper')) + { + $guestUsergroup = JComponentHelper::getParams('com_users')->get('guest_usergroup', 1); + } + else + { + $guestUsergroup = 1; + } + // Guest user (if only the actually assigned group is requested) if (empty($userId) && !$recursive) { - $result = array(JComponentHelper::getParams('com_users')->get('guest_usergroup', 1)); + $result = array($guestUsergroup); } // Registered user and guest if all groups are requested else @@ -298,7 +308,7 @@ public static function getGroupsByUser($userId, $recursive = true) if (empty($userId)) { $query->from('#__usergroups AS a'); - $query->where('a.id = ' . (int) JComponentHelper::getParams('com_users')->get('guest_usergroup', 1)); + $query->where('a.id = ' . (int) $guestUsergroup); } else { diff --git a/libraries/joomla/database/driver/mysqli.php b/libraries/joomla/database/driver/mysqli.php index 4ba21ca070..915fd72ffb 100644 --- a/libraries/joomla/database/driver/mysqli.php +++ b/libraries/joomla/database/driver/mysqli.php @@ -94,19 +94,7 @@ public function connect() // Make sure the MySQLi extension for PHP is installed and enabled. if (!function_exists('mysqli_connect')) { - - // Legacy error handling switch based on the JError::$legacy switch. - // @deprecated 12.1 - if (JError::$legacy) - { - $this->errorNum = 1; - $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_ADAPTER_MYSQLI'); - return; - } - else - { - throw new RuntimeException('The MySQL adapter mysqli is not available'); - } + throw new RuntimeException('The MySQL adapter mysqli is not available'); } $this->connection = @mysqli_connect( diff --git a/libraries/joomla/database/driver/sqlsrv.php b/libraries/joomla/database/driver/sqlsrv.php index 3e5bb2eb72..49f40e2ae0 100644 --- a/libraries/joomla/database/driver/sqlsrv.php +++ b/libraries/joomla/database/driver/sqlsrv.php @@ -739,19 +739,7 @@ public function select($database) if (!sqlsrv_query($this->connection, 'USE ' . $database, null, array('scrollable' => SQLSRV_CURSOR_STATIC))) { - - // Legacy error handling switch based on the JError::$legacy switch. - // @deprecated 12.1 - if (JError::$legacy) - { - $this->errorNum = 3; - $this->errorMsg = JText::_('JLIB_DATABASE_ERROR_DATABASE_CONNECT'); - return false; - } - else - { - throw new RuntimeException('Could not connect to database'); - } + throw new RuntimeException('Could not connect to database'); } return true; diff --git a/libraries/joomla/filesystem/folder.php b/libraries/joomla/filesystem/folder.php index e9157bbf03..aa045c8d37 100644 --- a/libraries/joomla/filesystem/folder.php +++ b/libraries/joomla/filesystem/folder.php @@ -29,7 +29,7 @@ abstract class JFolder * @param string $force Force copy. * @param boolean $use_streams Optionally force folder/file overwrites. * - * @return mixed JError object on failure or boolean True on success. + * @return boolean True on success. * * @since 11.1 * @throws RuntimeException diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index e9a6ae7d41..99a9bd375d 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -249,7 +249,7 @@ public function filter($data, $group = null) /** * Return all errors, if any. * - * @return array Array of error messages or JException objects. + * @return array Array of error messages or RuntimeException objects. * * @since 11.1 */ diff --git a/libraries/joomla/log/log.php b/libraries/joomla/log/log.php index 6925aa9709..e7f854ed0d 100644 --- a/libraries/joomla/log/log.php +++ b/libraries/joomla/log/log.php @@ -172,8 +172,7 @@ public static function add($entry, $priority = self::INFO, $category = '', $date } /** - * Method to set the way the JError will handle different error levels. - * Use this if you want to override the default settings. + * Add a logger to the JLog instance. Loggers route log entries to the correct files/systems to be logged. * * @param array $options The object configuration array. * @param integer $priorities Message priority diff --git a/libraries/joomla/object/object.php b/libraries/joomla/object/object.php index 348a22184e..61bb6eb535 100644 --- a/libraries/joomla/object/object.php +++ b/libraries/joomla/object/object.php @@ -22,7 +22,7 @@ class JObject { /** - * An array of error messages or JExceptions objects. + * An array of error messages or Exception objects. * * @var array * @since 11.1 diff --git a/libraries/joomla/registry/format.php b/libraries/joomla/registry/format.php index 6eb365cd58..09ad42f716 100644 --- a/libraries/joomla/registry/format.php +++ b/libraries/joomla/registry/format.php @@ -33,7 +33,7 @@ abstract class JRegistryFormat * @return JRegistryFormat Registry format handler * * @since 11.1 - * @throws JException + * @throws InvalidArgumentException */ public static function getInstance($type) { @@ -54,7 +54,7 @@ public static function getInstance($type) } else { - throw new JException(JText::_('JLIB_REGISTRY_EXCEPTION_LOAD_FORMAT_CLASS'), 500, E_ERROR); + throw new InvalidArgumentException('Unable to load format class.', 500); } } diff --git a/libraries/joomla/session/session.php b/libraries/joomla/session/session.php index e32256d8d3..5e270538b8 100644 --- a/libraries/joomla/session/session.php +++ b/libraries/joomla/session/session.php @@ -248,7 +248,16 @@ public static function getFormToken($forceNew = false) { $user = JFactory::getUser(); $session = JFactory::getSession(); - $hash = JApplication::getHash($user->get('id', 0) . $session->getToken($forceNew)); + + // TODO: Decouple from legacy JApplication class. + if (is_callable(array('JApplication', 'getHash'))) + { + $hash = JApplication::getHash($user->get('id', 0) . $session->getToken($forceNew)); + } + else + { + $hash = md5(JFactory::getApplication()->get('secret') . $user->get('id', 0) . $session->getToken($forceNew)); + } return $hash; } diff --git a/libraries/joomla/session/storage.php b/libraries/joomla/session/storage.php index 361fdd536b..9a26841b7b 100644 --- a/libraries/joomla/session/storage.php +++ b/libraries/joomla/session/storage.php @@ -65,7 +65,7 @@ public static function getInstance($name = 'none', $options = array()) } else { - // No call to JError::raiseError here, as it tries to close the non-existing session + // No attempt to die gracefully here, as it tries to close the non-existing session jexit('Unable to load session storage class: ' . $name); } } diff --git a/libraries/joomla/utilities/date.php b/libraries/joomla/utilities/date.php index 7efdb1d27a..31275e4ee0 100644 --- a/libraries/joomla/utilities/date.php +++ b/libraries/joomla/utilities/date.php @@ -77,8 +77,6 @@ class JDate extends DateTime * @param mixed $tz Time zone to be used for the date. Might be a string or a DateTimeZone object. * * @since 11.1 - * - * @throws JException */ public function __construct($date = 'now', $tz = null) { @@ -212,7 +210,6 @@ public function __toString() * @return JDate * * @since 11.3 - * @throws JException */ public static function getInstance($date = 'now', $tz = null) { diff --git a/libraries/joomla/form/fields/category.php b/libraries/legacy/form/field/category.php similarity index 100% rename from libraries/joomla/form/fields/category.php rename to libraries/legacy/form/field/category.php diff --git a/libraries/joomla/form/fields/componentlayout.php b/libraries/legacy/form/field/componentlayout.php similarity index 99% rename from libraries/joomla/form/fields/componentlayout.php rename to libraries/legacy/form/field/componentlayout.php index e2029ea97f..517ca36406 100644 --- a/libraries/joomla/form/fields/componentlayout.php +++ b/libraries/legacy/form/field/componentlayout.php @@ -20,7 +20,7 @@ * @subpackage Form * @since 11.1 */ -class JFormFieldComponentLayout extends JFormField +class JFormFieldComponentlayout extends JFormField { /** * The form field type. diff --git a/libraries/joomla/form/fields/menu.php b/libraries/legacy/form/field/menu.php similarity index 100% rename from libraries/joomla/form/fields/menu.php rename to libraries/legacy/form/field/menu.php diff --git a/libraries/joomla/form/fields/modulelayout.php b/libraries/legacy/form/field/modulelayout.php similarity index 99% rename from libraries/joomla/form/fields/modulelayout.php rename to libraries/legacy/form/field/modulelayout.php index d12894f0d6..dd962c4ecb 100644 --- a/libraries/joomla/form/fields/modulelayout.php +++ b/libraries/legacy/form/field/modulelayout.php @@ -19,7 +19,7 @@ * @subpackage Form * @since 11.1 */ -class JFormFieldModuleLayout extends JFormField +class JFormFieldModulelayout extends JFormField { /** * The form field type. diff --git a/tests/core/case/database.php b/tests/core/case/database.php index 9405e3c692..bc985fa4cd 100644 --- a/tests/core/case/database.php +++ b/tests/core/case/database.php @@ -488,30 +488,4 @@ protected function setUp() parent::setUp(); } - - /** - * Overrides the parent tearDown method. - * - * @return void - * - * @see PHPUnit_Framework_TestCase::tearDown() - * @since 11.1 - */ - protected function tearDown() - { - if (is_array($this->expectedErrors) && !empty($this->expectedErrors)) - { - $this->fail('An expected error was not raised.'); - } - - // Handle optional usage of JError until removed. - if (class_exists('JError')) - { - JError::setErrorHandling(E_NOTICE, 'ignore'); - JError::setErrorHandling(E_WARNING, 'ignore'); - JError::setErrorHandling(E_ERROR, 'ignore'); - } - - parent::tearDown(); - } } diff --git a/tests/suites/legacy/component/JComponentHelperTest.php b/tests/suites/legacy/component/JComponentHelperTest.php index 18af6d58c4..806e3bb193 100644 --- a/tests/suites/legacy/component/JComponentHelperTest.php +++ b/tests/suites/legacy/component/JComponentHelperTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/helper.php'; - /** * Test class for JComponentHelper. */ diff --git a/tests/suites/legacy/controller/JControllerAdminTest.php b/tests/suites/legacy/controller/JControllerAdminTest.php index cd15af337f..3ee26c3705 100644 --- a/tests/suites/legacy/controller/JControllerAdminTest.php +++ b/tests/suites/legacy/controller/JControllerAdminTest.php @@ -7,8 +7,6 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -include_once JPATH_PLATFORM . '/joomla/application/component/controlleradmin.php'; - /** * Test class for JControllerAdmin. * Generated by PHPUnit on 2011-10-26 at 19:37:59. diff --git a/tests/suites/legacy/controller/JControllerFormTest.php b/tests/suites/legacy/controller/JControllerFormTest.php index 03810a8a55..aaa01871ab 100644 --- a/tests/suites/legacy/controller/JControllerFormTest.php +++ b/tests/suites/legacy/controller/JControllerFormTest.php @@ -5,7 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/controllerform.php'; require_once __DIR__ . '/stubs/controllerform.php'; /** diff --git a/tests/suites/legacy/controller/JControllerTest.php b/tests/suites/legacy/controller/JControllerTest.php index e3d7dbd235..7abc67c43f 100644 --- a/tests/suites/legacy/controller/JControllerTest.php +++ b/tests/suites/legacy/controller/JControllerTest.php @@ -5,7 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/controller.php'; require_once __DIR__ . '/stubs/controller.php'; /** @@ -43,9 +42,6 @@ protected function setUp() */ public function testAddModelPath() { - // Include JModel as this method is a proxy for JModel::addIncludePath - require_once JPATH_PLATFORM . '/joomla/application/component/model.php'; - $path = JPath::clean(JPATH_ROOT . '/addmodelpath'); JController::addModelPath($path); diff --git a/tests/suites/unit/joomla/form/fields/JFormFieldCategoryTest.php b/tests/suites/legacy/form/field/JFormFieldCategoryTest.php similarity index 80% rename from tests/suites/unit/joomla/form/fields/JFormFieldCategoryTest.php rename to tests/suites/legacy/form/field/JFormFieldCategoryTest.php index b803648bcb..b1c61e32ec 100644 --- a/tests/suites/unit/joomla/form/fields/JFormFieldCategoryTest.php +++ b/tests/suites/legacy/form/field/JFormFieldCategoryTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JFormFieldCategory. * @@ -16,19 +18,6 @@ */ class JFormFieldCategoryTest extends TestCaseDatabase { - /** - * Sets up dependencies for the test. - * - * @return void - * - * @since 11.1 - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/joomla/form/fields/category.php'; - include_once dirname(__DIR__) . '/inspectors.php'; - } - /** * Gets the data set to be loaded into the database during setup * @@ -38,7 +27,7 @@ protected function setUp() */ protected function getDataSet() { - return $this->createXMLDataSet(__DIR__ . '/testfiles/JFormField.xml'); + return $this->createXMLDataSet(JPATH_TESTS . '/suites/unit/joomla/form/fields/testfiles/JFormField.xml'); } /** diff --git a/tests/suites/unit/joomla/form/fields/JFormFieldComponentLayoutTest.php b/tests/suites/legacy/form/field/JFormFieldComponentLayoutTest.php similarity index 80% rename from tests/suites/unit/joomla/form/fields/JFormFieldComponentLayoutTest.php rename to tests/suites/legacy/form/field/JFormFieldComponentLayoutTest.php index 5b83ad49da..7ed278446d 100644 --- a/tests/suites/unit/joomla/form/fields/JFormFieldComponentLayoutTest.php +++ b/tests/suites/legacy/form/field/JFormFieldComponentLayoutTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JFormFieldComponentLayout. * @@ -16,19 +18,6 @@ */ class JFormFieldComponentLayoutTest extends TestCase { - /** - * Sets up dependencies for the test. - * - * @return void - * - * @since 11.1 - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/joomla/form/fields/componentlayout.php'; - include_once dirname(__DIR__) . '/inspectors.php'; - } - /** * Test the getInput method. * @@ -46,7 +35,7 @@ public function testGetInput() 'Line:'.__LINE__.' XML string should load successfully.' ); - $field = new JFormFieldComponentLayout($form); + $field = new JFormFieldComponentlayout($form); $this->assertThat( $field->setup($form->getXml()->field, 'value'), diff --git a/tests/suites/unit/joomla/form/fields/JFormFieldModuleLayoutTest.php b/tests/suites/legacy/form/field/JFormFieldModuleLayoutTest.php similarity index 80% rename from tests/suites/unit/joomla/form/fields/JFormFieldModuleLayoutTest.php rename to tests/suites/legacy/form/field/JFormFieldModuleLayoutTest.php index accb6e7c2d..32da61932e 100644 --- a/tests/suites/unit/joomla/form/fields/JFormFieldModuleLayoutTest.php +++ b/tests/suites/legacy/form/field/JFormFieldModuleLayoutTest.php @@ -7,6 +7,8 @@ * @license GNU General Public License version 2 or later; see LICENSE */ +require_once JPATH_TESTS . '/suites/unit/joomla/form/inspectors.php'; + /** * Test class for JFormFieldModuleLayout. * @@ -15,19 +17,6 @@ */ class JFormFieldModuleLayoutTest extends TestCase { - /** - * Sets up dependencies for the test. - * - * @return void - * - * @since 11.1 - */ - protected function setUp() - { - require_once JPATH_PLATFORM . '/joomla/form/fields/modulelayout.php'; - include_once dirname(__DIR__) . '/inspectors.php'; - } - /** * Test the getInput method. * @@ -45,7 +34,7 @@ public function testGetInput() 'Line:'.__LINE__.' XML string should load successfully.' ); - $field = new JFormFieldModuleLayout($form); + $field = new JFormFieldModulelayout($form); $this->assertThat( $field->setup($form->getXml()->field, 'value'), diff --git a/tests/suites/legacy/model/JModelAdminTest.php b/tests/suites/legacy/model/JModelAdminTest.php index 34f016ad64..1e45fec378 100644 --- a/tests/suites/legacy/model/JModelAdminTest.php +++ b/tests/suites/legacy/model/JModelAdminTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/modeladmin.php'; - /** * Test class for JModelList. */ diff --git a/tests/suites/legacy/model/JModelFormTest.php b/tests/suites/legacy/model/JModelFormTest.php index 956a63437b..2a7767cf81 100644 --- a/tests/suites/legacy/model/JModelFormTest.php +++ b/tests/suites/legacy/model/JModelFormTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/modelform.php'; - /** * Test class for JModelForm. */ diff --git a/tests/suites/legacy/model/JModelItemTest.php b/tests/suites/legacy/model/JModelItemTest.php index 2c119e5e2d..aa7c6ca5c7 100644 --- a/tests/suites/legacy/model/JModelItemTest.php +++ b/tests/suites/legacy/model/JModelItemTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/modelitem.php'; - /** * Test class for JModelItem. */ diff --git a/tests/suites/legacy/model/JModelListTest.php b/tests/suites/legacy/model/JModelListTest.php index 3d47087428..5bad1677fc 100644 --- a/tests/suites/legacy/model/JModelListTest.php +++ b/tests/suites/legacy/model/JModelListTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/modellist.php'; - /** * Test class for JModelList. */ diff --git a/tests/suites/legacy/model/JModelTest.php b/tests/suites/legacy/model/JModelTest.php index 6a2aabf01d..f862489a70 100644 --- a/tests/suites/legacy/model/JModelTest.php +++ b/tests/suites/legacy/model/JModelTest.php @@ -5,8 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/model.php'; - /** * Test class for JModel. */ diff --git a/tests/suites/legacy/module/JModuleHelperTest.php b/tests/suites/legacy/module/JModuleHelperTest.php index d581fd3fa4..121c3955b7 100644 --- a/tests/suites/legacy/module/JModuleHelperTest.php +++ b/tests/suites/legacy/module/JModuleHelperTest.php @@ -7,8 +7,6 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -require_once JPATH_PLATFORM . '/joomla/application/module/helper.php'; - /** * Test class for JModuleHelper. * Generated by PHPUnit on 2009-10-08 at 21:24:07. diff --git a/tests/suites/legacy/view/JViewTest.php b/tests/suites/legacy/view/JViewTest.php index 97cd588742..dde4cb2c43 100644 --- a/tests/suites/legacy/view/JViewTest.php +++ b/tests/suites/legacy/view/JViewTest.php @@ -5,7 +5,6 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -require_once JPATH_PLATFORM . '/joomla/application/component/view.php'; require_once JPATH_PLATFORM . '/joomla/environment/uri.php'; /** diff --git a/tests/suites/unit/joomla/document/opensearch/JDocumentOpensearchTest.php b/tests/suites/unit/joomla/document/opensearch/JDocumentOpensearchTest.php index 8439822e46..5a269e8bfb 100644 --- a/tests/suites/unit/joomla/document/opensearch/JDocumentOpensearchTest.php +++ b/tests/suites/unit/joomla/document/opensearch/JDocumentOpensearchTest.php @@ -33,25 +33,8 @@ protected function setUp() $_SERVER['HTTP_HOST'] = 'localhost'; $_SERVER['SCRIPT_NAME'] = ''; - JFactory::$application = $this->getMock( - 'JApplication', - array( - 'get', - 'getCfg', - 'getRouter', - 'getTemplate', - ), - array( - array( - 'session' => false - ) - ) - ); - - JFactory::$config = $this->getMock( - 'JConfig', - array('get') - ); + JFactory::$application = $this->getMockApplication(); + JFactory::$config = $this->getMockConfig(); $this->object = new JDocumentOpensearch; } diff --git a/tests/suites/unit/joomla/html/html/JHtmlFormTest.php b/tests/suites/unit/joomla/html/html/JHtmlFormTest.php index 3920a254fa..742a375e44 100644 --- a/tests/suites/unit/joomla/html/html/JHtmlFormTest.php +++ b/tests/suites/unit/joomla/html/html/JHtmlFormTest.php @@ -58,6 +58,8 @@ protected function tearDown() */ public function testToken() { + JFactory::$application = $this->getMockWeb(); + $token = JSession::getFormToken(); $this->assertThat( From 0c096c5dfb93c5cec6bd4a38e8fcae13bc96bf9c Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 3 Apr 2012 08:47:33 +0200 Subject: [PATCH 44/98] DRY out JHtml::tooltip --- libraries/joomla/html/html.php | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/libraries/joomla/html/html.php b/libraries/joomla/html/html.php index 952647c347..0931d91c03 100644 --- a/libraries/joomla/html/html.php +++ b/libraries/joomla/html/html.php @@ -717,25 +717,12 @@ public static function tooltip($tooltip, $title = '', $image = 'tooltip.png', $t { if (is_array($title)) { - if (isset($title['image'])) + foreach(array('image', 'text', 'href', 'alt', 'class') as $param) { - $image = $title['image']; - } - if (isset($title['text'])) - { - $text = $title['text']; - } - if (isset($title['href'])) - { - $href = $title['href']; - } - if (isset($title['alt'])) - { - $alt = $title['alt']; - } - if (isset($title['class'])) - { - $class = $title['class']; + if (isset($title[$param])) + { + $$param = $title[$param]; + } } if (isset($title['title'])) { From b4354698c30f5ca5babff036c5b3939d2d1268c9 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 3 Apr 2012 08:53:24 +0200 Subject: [PATCH 45/98] Fixed my CodeSniff error --- libraries/joomla/html/html.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/html/html.php b/libraries/joomla/html/html.php index 0931d91c03..3ea5889244 100644 --- a/libraries/joomla/html/html.php +++ b/libraries/joomla/html/html.php @@ -717,7 +717,7 @@ public static function tooltip($tooltip, $title = '', $image = 'tooltip.png', $t { if (is_array($title)) { - foreach(array('image', 'text', 'href', 'alt', 'class') as $param) + foreach (array('image', 'text', 'href', 'alt', 'class') as $param) { if (isset($title[$param])) { From f90bcea340d16bd3289d5f865dd24f13abbe5157 Mon Sep 17 00:00:00 2001 From: Benjamin Date: Tue, 3 Apr 2012 09:04:24 +0200 Subject: [PATCH 46/98] Add test for code coverage --- tests/suites/unit/joomla/html/JHtmlTest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/suites/unit/joomla/html/JHtmlTest.php b/tests/suites/unit/joomla/html/JHtmlTest.php index 80001728ce..50968b627d 100644 --- a/tests/suites/unit/joomla/html/JHtmlTest.php +++ b/tests/suites/unit/joomla/html/JHtmlTest.php @@ -1145,6 +1145,11 @@ public function testTooltip() $this->equalTo('Tooltip'), 'Tooltip with title and content and class failed' ); + $this->assertThat( + JHtml::tooltip('Content',array()), + $this->equalTo('Tooltip'), + 'Basic tooltip (array version) failed' + ); // Remove our testfile unlink(JPATH_ROOT . '/media/system/images/tooltip.png'); From 657f39ce51c3c95912b40553cf5dd24a86b30a79 Mon Sep 17 00:00:00 2001 From: Christophe Demko Date: Tue, 3 Apr 2012 16:27:17 +0300 Subject: [PATCH 47/98] Correct code style --- libraries/joomla/http/http.php | 46 +++++++++++++++++----------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/libraries/joomla/http/http.php b/libraries/joomla/http/http.php index a17f67d6fb..003d28499a 100644 --- a/libraries/joomla/http/http.php +++ b/libraries/joomla/http/http.php @@ -81,9 +81,9 @@ public function setOption($key, $value) /** * Method to send the OPTIONS command to the server. * - * @param string $url Path to the resource. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -113,9 +113,9 @@ public function options($url, array $headers = null, $timeout = null) /** * Method to send the HEAD command to the server. * - * @param string $url Path to the resource. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -145,9 +145,9 @@ public function head($url, array $headers = null, $timeout = null) /** * Method to send the GET command to the server. * - * @param string $url Path to the resource. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -177,10 +177,10 @@ public function get($url, array $headers = null, $timeout = null) /** * Method to send the POST command to the server. * - * @param string $url Path to the resource. - * @param mixed $data Either an associative array or a string to be sent with the request. - * @param array $headers An array of name-value pairs to include in the header of the request - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param mixed $data Either an associative array or a string to be sent with the request. + * @param array $headers An array of name-value pairs to include in the header of the request + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -210,10 +210,10 @@ public function post($url, $data, array $headers = null, $timeout = null) /** * Method to send the PUT command to the server. * - * @param string $url Path to the resource. - * @param mixed $data Either an associative array or a string to be sent with the request. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param mixed $data Either an associative array or a string to be sent with the request. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -243,9 +243,9 @@ public function put($url, $data, array $headers = null, $timeout = null) /** * Method to send the DELETE command to the server. * - * @param string $url Path to the resource. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * @@ -275,9 +275,9 @@ public function delete($url, array $headers = null, $timeout = null) /** * Method to send the TRACE command to the server. * - * @param string $url Path to the resource. - * @param array $headers An array of name-value pairs to include in the header of the request. - * @param integer $timeout Read timeout in seconds. + * @param string $url Path to the resource. + * @param array $headers An array of name-value pairs to include in the header of the request. + * @param integer $timeout Read timeout in seconds. * * @return JHttpResponse * From 18c5dbbf131a0b20ccda6c8f5e71a1a6390a3170 Mon Sep 17 00:00:00 2001 From: Rob Schley Date: Mon, 2 Apr 2012 10:43:28 -0700 Subject: [PATCH 48/98] Added support to mock JApplicationWeb::getIdentity() --- tests/core/mock/application/web.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/core/mock/application/web.php b/tests/core/mock/application/web.php index 040f79425c..e847b66e80 100644 --- a/tests/core/mock/application/web.php +++ b/tests/core/mock/application/web.php @@ -36,8 +36,9 @@ public static function create($test, $options = array()) $methods = array( 'get', 'getDocument', + 'getIdentity', 'getLanguage', - 'getSession', + 'getSession' ); // Create the mock. From 37dcb016bcd8fa5f67a7212737c725c574cdd2cc Mon Sep 17 00:00:00 2001 From: Rob Schley Date: Tue, 3 Apr 2012 10:28:56 -0700 Subject: [PATCH 49/98] Added JApplicationBase::getIdentity to retrieve the application identity. --- libraries/joomla/application/base.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/joomla/application/base.php b/libraries/joomla/application/base.php index b372e538e0..21eb8024b9 100644 --- a/libraries/joomla/application/base.php +++ b/libraries/joomla/application/base.php @@ -59,6 +59,18 @@ public function close($code = 0) exit($code); } + /** + * Get the application identity. + * + * @return mixed A JUser object or null. + * + * @since 12.1 + */ + public function getIdentity() + { + return $this->identity; + } + /** * Registers a handler to a particular event group. * From 05484b4877436e466995bc775f8d35d686aa0f41 Mon Sep 17 00:00:00 2001 From: Rob Schley Date: Tue, 3 Apr 2012 10:30:04 -0700 Subject: [PATCH 50/98] Added getIdentity mock support to TestMockApplication. --- tests/core/mock/application.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/core/mock/application.php b/tests/core/mock/application.php index 69da288240..e6d2653506 100644 --- a/tests/core/mock/application.php +++ b/tests/core/mock/application.php @@ -29,6 +29,7 @@ public static function create($test) $methods = array( 'get', 'getCfg', + 'getIdentity', 'getRouter', 'getTemplate', ); From 30e842380441e4ed6e259536f544df85223ae20c Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Tue, 3 Apr 2012 14:08:31 -0500 Subject: [PATCH 51/98] Rename protected members in JInstaller --- libraries/joomla/installer/installer.php | 52 ++++++++++++------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/libraries/joomla/installer/installer.php b/libraries/joomla/installer/installer.php index 1104d6c3df..53588d222f 100644 --- a/libraries/joomla/installer/installer.php +++ b/libraries/joomla/installer/installer.php @@ -27,17 +27,17 @@ class JInstaller extends JAdapter * Array of paths needed by the installer * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_paths = array(); + protected $paths = array(); /** * True if package is an upgrade * * @var boolean - * @since 11.1 + * @since 12.1 */ - protected $_upgrade = null; + protected $upgrade = null; /** * The manifest trigger class @@ -50,18 +50,18 @@ class JInstaller extends JAdapter /** * True if existing files can be overwritten * @var boolean - * @since 11.1 + * @since 12.1 */ - protected $_overwrite = false; + protected $overwrite = false; /** * Stack of installation steps * - Used for installation rollback * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_stepStack = array(); + protected $stepStack = array(); /** * Extension Table Entry @@ -145,7 +145,7 @@ public static function getInstance() */ public function isOverwrite() { - return $this->_overwrite; + return $this->overwrite; } /** @@ -159,15 +159,15 @@ public function isOverwrite() */ public function setOverwrite($state = false) { - $tmp = $this->_overwrite; + $tmp = $this->overwrite; if ($state) { - $this->_overwrite = true; + $this->overwrite = true; } else { - $this->_overwrite = false; + $this->overwrite = false; } return $tmp; @@ -208,7 +208,7 @@ public function setRedirectURL($newurl) */ public function isUpgrade() { - return $this->_upgrade; + return $this->upgrade; } /** @@ -222,15 +222,15 @@ public function isUpgrade() */ public function setUpgrade($state = false) { - $tmp = $this->_upgrade; + $tmp = $this->upgrade; if ($state) { - $this->_upgrade = true; + $this->upgrade = true; } else { - $this->_upgrade = false; + $this->upgrade = false; } return $tmp; @@ -265,7 +265,7 @@ public function getManifest() */ public function getPath($name, $default = null) { - return (!empty($this->_paths[$name])) ? $this->_paths[$name] : $default; + return (!empty($this->paths[$name])) ? $this->paths[$name] : $default; } /** @@ -280,7 +280,7 @@ public function getPath($name, $default = null) */ public function setPath($name, $value) { - $this->_paths[$name] = $value; + $this->paths[$name] = $value; } /** @@ -294,7 +294,7 @@ public function setPath($name, $value) */ public function pushStep($step) { - $this->_stepStack[] = $step; + $this->stepStack[] = $step; } /** @@ -312,7 +312,7 @@ public function abort($msg = null, $type = null) { // Initialise variables. $retval = true; - $step = array_pop($this->_stepStack); + $step = array_pop($this->stepStack); // Raise abort warning if ($msg) @@ -380,7 +380,7 @@ public function abort($msg = null, $type = null) } // Get the next step and continue - $step = array_pop($this->_stepStack); + $step = array_pop($this->stepStack); } $conf = JFactory::getConfig(); @@ -1542,7 +1542,7 @@ public function copyFiles($files, $overwrite = null) if (is_null($overwrite) || !is_bool($overwrite)) { - $overwrite = $this->_overwrite; + $overwrite = $this->overwrite; } /* @@ -1615,7 +1615,7 @@ public function copyFiles($files, $overwrite = null) */ if (!$exists) { - $this->_stepStack[] = $step; + $this->stepStack[] = $step; } } } @@ -1851,14 +1851,14 @@ public function findManifest() // If the root method attribute is set to upgrade, allow file overwrite if ((string) $manifest->attributes()->method == 'upgrade') { - $this->_upgrade = true; - $this->_overwrite = true; + $this->upgrade = true; + $this->overwrite = true; } // If the overwrite option is set, allow file overwriting if ((string) $manifest->attributes()->overwrite == 'true') { - $this->_overwrite = true; + $this->overwrite = true; } // Set the manifest object and path From ff1ea752ba63905f9b76b7ecc6624546e30153bc Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Tue, 3 Apr 2012 14:35:38 -0500 Subject: [PATCH 52/98] Rename protected members in JUpdater, JUpdateadapter and extending classes --- .../joomla/updater/adapters/collection.php | 25 +++--- .../joomla/updater/adapters/extension.php | 26 +++--- libraries/joomla/updater/update.php | 80 +++++++++++-------- libraries/joomla/updater/updateadapter.php | 20 ++--- 4 files changed, 81 insertions(+), 70 deletions(-) diff --git a/libraries/joomla/updater/adapters/collection.php b/libraries/joomla/updater/adapters/collection.php index 348e058a39..11f643b766 100644 --- a/libraries/joomla/updater/adapters/collection.php +++ b/libraries/joomla/updater/adapters/collection.php @@ -65,8 +65,7 @@ class JUpdaterCollection extends JUpdateAdapter */ protected function _getStackLocation() { - - return implode('->', $this->_stack); + return implode('->', $this->stack); } /** @@ -94,7 +93,7 @@ protected function _getParent() */ public function _startElement($parser, $name, $attrs = array()) { - array_push($this->_stack, $name); + array_push($this->stack, $name); $tag = $this->_getStackLocation(); // Reset the data @@ -104,7 +103,7 @@ public function _startElement($parser, $name, $attrs = array()) case 'CATEGORY': if (isset($attrs['REF'])) { - $this->update_sites[] = array('type' => 'collection', 'location' => $attrs['REF'], 'update_site_id' => $this->_update_site_id); + $this->update_sites[] = array('type' => 'collection', 'location' => $attrs['REF'], 'update_site_id' => $this->updateSiteId); } else { @@ -114,8 +113,8 @@ public function _startElement($parser, $name, $attrs = array()) break; case 'EXTENSION': $update = JTable::getInstance('update'); - $update->set('update_site_id', $this->_update_site_id); - foreach ($this->_updatecols as $col) + $update->set('update_site_id', $this->updateSiteId); + foreach ($this->updatecols as $col) { // Reset the values if it doesn't exist if (!array_key_exists($col, $attrs)) @@ -183,7 +182,7 @@ public function _startElement($parser, $name, $attrs = array()) */ protected function _endElement($parser, $name) { - $lastcell = array_pop($this->_stack); + $lastcell = array_pop($this->stack); switch ($name) { case 'CATEGORY': @@ -210,7 +209,7 @@ protected function _endElement($parser, $name) public function findUpdate($options) { $url = $options['location']; - $this->_update_site_id = $options['update_site_id']; + $this->updateSiteId = $options['update_site_id']; if (substr($url, -4) != '.xml') { if (substr($url, -1) != '/') @@ -232,7 +231,7 @@ public function findUpdate($options) $query = $dbo->getQuery(true); $query->update('#__update_sites'); $query->set('enabled = 0'); - $query->where('update_site_id = ' . $this->_update_site_id); + $query->where('update_site_id = ' . $this->updateSiteId); $dbo->setQuery($query); $dbo->execute(); @@ -242,10 +241,10 @@ public function findUpdate($options) return false; } - $this->xml_parser = xml_parser_create(''); - xml_set_object($this->xml_parser, $this); - xml_set_element_handler($this->xml_parser, '_startElement', '_endElement'); - if (!xml_parse($this->xml_parser, $response->body)) + $this->xmlParser = xml_parser_create(''); + xml_set_object($this->xmlParser, $this); + xml_set_element_handler($this->xmlParser, '_startElement', '_endElement'); + if (!xml_parse($this->xmlParser, $response->body)) { JLog::add("Error parsing url: " . $url, JLog::WARNING, 'updater'); $app = JFactory::getApplication(); diff --git a/libraries/joomla/updater/adapters/extension.php b/libraries/joomla/updater/adapters/extension.php index 3582f7b69e..573c9295c5 100644 --- a/libraries/joomla/updater/adapters/extension.php +++ b/libraries/joomla/updater/adapters/extension.php @@ -32,7 +32,7 @@ class JUpdaterExtension extends JUpdateAdapter */ protected function _startElement($parser, $name, $attrs = array()) { - array_push($this->_stack, $name); + array_push($this->stack, $name); $tag = $this->_getStackLocation(); // Reset the data @@ -42,7 +42,7 @@ protected function _startElement($parser, $name, $attrs = array()) { case 'UPDATE': $this->current_update = JTable::getInstance('update'); - $this->current_update->update_site_id = $this->_update_site_id; + $this->current_update->update_site_id = $this->updateSiteId; $this->current_update->detailsurl = $this->_url; $this->current_update->folder = ""; $this->current_update->client_id = 1; @@ -52,7 +52,7 @@ protected function _startElement($parser, $name, $attrs = array()) case 'UPDATES': break; default: - if (in_array($name, $this->_updatecols)) + if (in_array($name, $this->updatecols)) { $name = strtolower($name); $this->current_update->$name = ''; @@ -77,7 +77,7 @@ protected function _startElement($parser, $name, $attrs = array()) */ protected function _endElement($parser, $name) { - array_pop($this->_stack); + array_pop($this->stack); // @todo remove code: echo 'Closing: '. $name .'
    '; switch ($name) @@ -132,7 +132,7 @@ protected function _characterData($parser, $data) * if(!isset($this->$tag->_data)) $this->$tag->_data = ''; * $this->$tag->_data .= $data; */ - if (in_array($tag, $this->_updatecols)) + if (in_array($tag, $this->updatecols)) { $tag = strtolower($tag); $this->current_update->$tag .= $data; @@ -152,7 +152,7 @@ public function findUpdate($options) { $url = $options['location']; $this->_url = &$url; - $this->_update_site_id = $options['update_site_id']; + $this->updateSiteId = $options['update_site_id']; if (substr($url, -4) != '.xml') { if (substr($url, -1) != '/') @@ -171,7 +171,7 @@ public function findUpdate($options) $query = $dbo->getQuery(true); $query->update('#__update_sites'); $query->set('enabled = 0'); - $query->where('update_site_id = ' . $this->_update_site_id); + $query->where('update_site_id = ' . $this->updateSiteId); $dbo->setQuery($query); $dbo->execute(); @@ -181,19 +181,19 @@ public function findUpdate($options) return false; } - $this->xml_parser = xml_parser_create(''); - xml_set_object($this->xml_parser, $this); - xml_set_element_handler($this->xml_parser, '_startElement', '_endElement'); - xml_set_character_data_handler($this->xml_parser, '_characterData'); + $this->xmlParser = xml_parser_create(''); + xml_set_object($this->xmlParser, $this); + xml_set_element_handler($this->xmlParser, '_startElement', '_endElement'); + xml_set_character_data_handler($this->xmlParser, '_characterData'); - if (!xml_parse($this->xml_parser, $response->data)) + if (!xml_parse($this->xmlParser, $response->data)) { JLog::add("Error parsing url: " . $url, JLog::WARNING, 'updater'); $app = JFactory::getApplication(); $app->enqueueMessage(JText::sprintf('JLIB_UPDATER_ERROR_EXTENSION_PARSE_URL', $url), 'warning'); return false; } - xml_parser_free($this->xml_parser); + xml_parser_free($this->xmlParser); if (isset($this->latest)) { if (isset($this->latest->client) && strlen($this->latest->client)) diff --git a/libraries/joomla/updater/update.php b/libraries/joomla/updater/update.php index f102f41352..6b1087a64b 100644 --- a/libraries/joomla/updater/update.php +++ b/libraries/joomla/updater/update.php @@ -110,21 +110,33 @@ class JUpdate extends JObject /** * @var string - * @since 11.1 + * @since 12.1 */ - protected $_xml_parser; + protected $xmlParser; /** * @var array - * @since 11.1 + * @since 12.1 */ - protected $_stack = array('base'); + protected $stack = array('base'); /** * @var array - * @since 11.1 + * @since 12.1 + */ + protected $stateStore = array(); + + /** + * @var stdClass + * @since 12.1 + */ + protected $currentUpdate; + + /** + * @var stdClass + * @since 12.1 */ - protected $_state_store = array(); + protected $latest; /** * Gets the reference to the current direct parent @@ -135,7 +147,7 @@ class JUpdate extends JObject */ protected function _getStackLocation() { - return implode('->', $this->_stack); + return implode('->', $this->stack); } /** @@ -147,7 +159,7 @@ protected function _getStackLocation() */ protected function _getLastTag() { - return $this->_stack[count($this->_stack) - 1]; + return $this->stack[count($this->stack) - 1]; } /** @@ -164,7 +176,7 @@ protected function _getLastTag() */ public function _startElement($parser, $name, $attrs = array()) { - array_push($this->_stack, $name); + array_push($this->stack, $name); $tag = $this->_getStackLocation(); // Reset the data @@ -174,7 +186,7 @@ public function _startElement($parser, $name, $attrs = array()) { // This is a new update; create a current update case 'UPDATE': - $this->_current_update = new stdClass; + $this->currentUpdate = new stdClass; break; // Don't do anything @@ -184,11 +196,11 @@ public function _startElement($parser, $name, $attrs = array()) // For everything else there's...the default! default: $name = strtolower($name); - $this->_current_update->$name->_data = ''; + $this->currentUpdate->$name->_data = ''; foreach ($attrs as $key => $data) { $key = strtolower($key); - $this->_current_update->$name->$key = $data; + $this->currentUpdate->$name->$key = $data; } break; } @@ -207,44 +219,44 @@ public function _startElement($parser, $name, $attrs = array()) */ public function _endElement($parser, $name) { - array_pop($this->_stack); + array_pop($this->stack); switch ($name) { // Closing update, find the latest version and check case 'UPDATE': $ver = new JVersion; $product = strtolower(JFilterInput::getInstance()->clean($ver->PRODUCT, 'cmd')); - if ($product == $this->_current_update->targetplatform->name - && preg_match('/' . $this->_current_update->targetplatform->version . '/', $ver->RELEASE)) + if ($product == $this->currentUpdate->targetplatform->name + && preg_match('/' . $this->currentUpdate->targetplatform->version . '/', $ver->RELEASE)) { - if (isset($this->_latest)) + if (isset($this->latest)) { - if (version_compare($this->_current_update->version->_data, $this->_latest->version->_data, '>') == 1) + if (version_compare($this->currentUpdate->version->_data, $this->latest->version->_data, '>') == 1) { - $this->_latest = $this->_current_update; + $this->latest = $this->currentUpdate; } } else { - $this->_latest = $this->_current_update; + $this->latest = $this->currentUpdate; } } break; case 'UPDATES': // If the latest item is set then we transfer it to where we want to - if (isset($this->_latest)) + if (isset($this->latest)) { - foreach (get_object_vars($this->_latest) as $key => $val) + foreach (get_object_vars($this->latest) as $key => $val) { $this->$key = $val; } - unset($this->_latest); - unset($this->_current_update); + unset($this->latest); + unset($this->currentUpdate); } - elseif (isset($this->_current_update)) + elseif (isset($this->currentUpdate)) { // The update might be for an older version of j! - unset($this->_current_update); + unset($this->currentUpdate); } break; } @@ -270,7 +282,7 @@ public function _characterData($parser, $data) // Throw the data for this item together $tag = strtolower($tag); - $this->_current_update->$tag->_data .= $data; + $this->currentUpdate->$tag->_data .= $data; } /** @@ -293,21 +305,21 @@ public function loadFromXML($url) return false; } - $this->xml_parser = xml_parser_create(''); - xml_set_object($this->xml_parser, $this); - xml_set_element_handler($this->xml_parser, '_startElement', '_endElement'); - xml_set_character_data_handler($this->xml_parser, '_characterData'); + $this->xmlParser = xml_parser_create(''); + xml_set_object($this->xmlParser, $this); + xml_set_element_handler($this->xmlParser, '_startElement', '_endElement'); + xml_set_character_data_handler($this->xmlParser, '_characterData'); - if (!xml_parse($this->xml_parser, $response->data)) + if (!xml_parse($this->xmlParser, $response->data)) { die( sprintf( - "XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xml_parser)), - xml_get_current_line_number($this->xml_parser) + "XML error: %s at line %d", xml_error_string(xml_get_error_code($this->xmlParser)), + xml_get_current_line_number($this->xmlParser) ) ); } - xml_parser_free($this->xml_parser); + xml_parser_free($this->xmlParser); return true; } } diff --git a/libraries/joomla/updater/updateadapter.php b/libraries/joomla/updater/updateadapter.php index b3e739301c..6c280d7876 100644 --- a/libraries/joomla/updater/updateadapter.php +++ b/libraries/joomla/updater/updateadapter.php @@ -22,31 +22,31 @@ class JUpdateAdapter extends JAdapterInstance { /** * @var resource - * @since 11.1 + * @since 12.1 */ - protected $xml_parser; + protected $xmlParser; /** * @var array - * @since 11.1 + * @since 12.1 */ - protected $_stack = array('base'); + protected $stack = array('base'); /** * ID of update site * * @var string - * @since 11.1 + * @since 12.1 */ - protected $_update_site_id = 0; + protected $updateSiteId = 0; /** * Columns in the extensions table to be updated * * @var array - * @since 11.1 + * @since 12.1 */ - protected $_updatecols = array('NAME', 'ELEMENT', 'TYPE', 'FOLDER', 'CLIENT', 'VERSION', 'DESCRIPTION', 'INFOURL'); + protected $updatecols = array('NAME', 'ELEMENT', 'TYPE', 'FOLDER', 'CLIENT', 'VERSION', 'DESCRIPTION', 'INFOURL'); /** * Gets the reference to the current direct parent @@ -57,7 +57,7 @@ class JUpdateAdapter extends JAdapterInstance */ protected function _getStackLocation() { - return implode('->', $this->_stack); + return implode('->', $this->stack); } /** @@ -69,6 +69,6 @@ protected function _getStackLocation() */ protected function _getLastTag() { - return $this->_stack[count($this->_stack) - 1]; + return $this->stack[count($this->stack) - 1]; } } From d3675f6adb6804a2d12d973fb1f5d20fe8c4da62 Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Tue, 3 Apr 2012 14:55:44 -0500 Subject: [PATCH 53/98] Rename a protected (and unused) member in JSessionStorageDatabase --- libraries/joomla/session/storage/database.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/session/storage/database.php b/libraries/joomla/session/storage/database.php index 3b5e30c3e2..c1603511a4 100644 --- a/libraries/joomla/session/storage/database.php +++ b/libraries/joomla/session/storage/database.php @@ -20,10 +20,10 @@ class JSessionStorageDatabase extends JSessionStorage { /** - * @var unknown No idea what this does. - * @since 11.1 + * @var unknown No idea what this does. Seems not to be used. + * @since 12.1 */ - protected $_data = null; + protected $data = null; /** * Open the SessionHandler backend. From 224390df1e083f70d88de4e11b522d9cfbd98101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 1 Apr 2012 22:18:42 +0200 Subject: [PATCH 54/98] The dl() function has been removed from most PHP SAPI's in 5.3. --- libraries/joomla/archive/bzip2.php | 35 ------------------------------ libraries/joomla/archive/zip.php | 15 +------------ libraries/joomla/client/ftp.php | 12 ---------- libraries/joomla/string/string.php | 4 ++-- 4 files changed, 3 insertions(+), 63 deletions(-) diff --git a/libraries/joomla/archive/bzip2.php b/libraries/joomla/archive/bzip2.php index b86b4ce1ce..e973afef75 100644 --- a/libraries/joomla/archive/bzip2.php +++ b/libraries/joomla/archive/bzip2.php @@ -28,16 +28,6 @@ class JArchiveBzip2 implements JArchiveExtractable */ private $_data = null; - /** - * Constructor tries to load the bz2 extension if not loaded - * - * @since 11.1 - */ - public function __construct() - { - self::loadExtension(); - } - /** * Extract a Bzip2 compressed file to a given path * @@ -181,31 +171,6 @@ public function extract($archive, $destination, array $options = array ()) */ public static function isSupported() { - self::loadExtension(); - return extension_loaded('bz2'); } - - /** - * Load the bzip2 extension - * - * @return void - * - * @since 11.3 - */ - private static function loadExtension() - { - // Is bz2 extension loaded? If not try to load it - if (!extension_loaded('bz2')) - { - if (JPATH_ISWIN) - { - @ dl('php_bz2.dll'); - } - else - { - @ dl('bz2.so'); - } - } - } } diff --git a/libraries/joomla/archive/zip.php b/libraries/joomla/archive/zip.php index 6b414b5891..1a227b7001 100644 --- a/libraries/joomla/archive/zip.php +++ b/libraries/joomla/archive/zip.php @@ -531,20 +531,7 @@ private function _getFileData($key) } elseif ($this->_metadata[$key]['_method'] == 0x12) { - // Is bz2 extension loaded? If not try to load it - if (!extension_loaded('bz2')) - { - if (JPATH_ISWIN) - { - @dl('php_bz2.dll'); - } - else - { - @dl('bz2.so'); - } - } - - // If bz2 extension is successfully loaded use it + // If bz2 extension is loaded use it if (extension_loaded('bz2')) { return bzdecompress(substr($this->_data, $this->_metadata[$key]['_dataStart'], $this->_metadata[$key]['csize'])); diff --git a/libraries/joomla/client/ftp.php b/libraries/joomla/client/ftp.php index 2743da02d3..3156c29e53 100644 --- a/libraries/joomla/client/ftp.php +++ b/libraries/joomla/client/ftp.php @@ -38,18 +38,6 @@ define("FTP_ASCII", 0); } -// Is FTP extension loaded? If not try to load it -if (!extension_loaded('ftp')) -{ - if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') - { - @ dl('php_ftp.dll'); - } - else - { - @ dl('ftp.so'); - } -} if (!defined('FTP_NATIVE')) { define('FTP_NATIVE', (function_exists('ftp_connect')) ? 1 : 0); diff --git a/libraries/joomla/string/string.php b/libraries/joomla/string/string.php index e7a818c231..bf92a7c34d 100644 --- a/libraries/joomla/string/string.php +++ b/libraries/joomla/string/string.php @@ -12,7 +12,7 @@ // PHP mbstring and iconv local configuration // Check if mbstring extension is loaded and attempt to load it if not present except for windows -if (extension_loaded('mbstring') || ((!strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && dl('mbstring.so')))) +if (extension_loaded('mbstring')) { // Make sure to suppress the output in case ini_set is disabled @ini_set('mbstring.internal_encoding', 'UTF-8'); @@ -21,7 +21,7 @@ } // Same for iconv -if (function_exists('iconv') || ((!strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' && dl('iconv.so')))) +if (function_exists('iconv'))) { // These are settings that can be set inside code iconv_set_encoding("internal_encoding", "UTF-8"); From ea7abfec2887aa71522ec0d1bf9d27d8ebc7afdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 27 Mar 2012 12:56:56 +0200 Subject: [PATCH 55/98] Remove dependency on the following classes from the database package: JObject JFolder JTable --- libraries/joomla/database/driver.php | 18 ++++++++++-------- .../joomla/database/driver/postgresql.php | 2 +- libraries/joomla/database/exporter/mysql.php | 6 +++--- .../joomla/database/exporter/postgresql.php | 6 +++--- libraries/joomla/database/factory.php | 18 ------------------ libraries/joomla/database/importer/mysql.php | 6 +++--- .../joomla/database/importer/postgresql.php | 6 +++--- 7 files changed, 23 insertions(+), 39 deletions(-) diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php index 8367a95dc3..384e413b39 100644 --- a/libraries/joomla/database/driver.php +++ b/libraries/joomla/database/driver.php @@ -180,20 +180,22 @@ public static function getConnectors() // Instantiate variables. $connectors = array(); - // Get a list of types. - $types = JFolder::files(__DIR__ . '/driver'); + // Get an iterator and loop trough the driver classes. + $iterator = new DirectoryIterator(__DIR__ . '/driver'); - // Loop through the types and find the ones that are available. - foreach ($types as $type) + foreach ($iterator as $file) { - // Ignore some files. - if (($type == 'index.html') || stripos($type, 'importer') || stripos($type, 'exporter') || stripos($type, 'query') || stripos($type, 'exception')) + $fileName = $file->getFilename(); + + // Only load for php files. + // Note: DirectoryIterator::getExtension only available PHP >= 5.3.6 + if (!$file->isFile() || substr($fileName, strrpos($fileName, '.') + 1) != 'php') { continue; } // Derive the class name from the type. - $class = str_ireplace('.php', '', 'JDatabaseDriver' . ucfirst(trim($type))); + $class = str_ireplace('.php', '', 'JDatabaseDriver' . ucfirst(trim($fileName))); // If the class doesn't exist we have nothing left to do but look at the next type. We did our best. if (!class_exists($class)) @@ -206,7 +208,7 @@ public static function getConnectors() if ($class::isSupported() || $class::test()) { // Connector names should not have file extensions. - $connectors[] = str_ireplace('.php', '', $type); + $connectors[] = str_ireplace('.php', '', $fileName); } } diff --git a/libraries/joomla/database/driver/postgresql.php b/libraries/joomla/database/driver/postgresql.php index 38850984bb..a5d7eb3905 100644 --- a/libraries/joomla/database/driver/postgresql.php +++ b/libraries/joomla/database/driver/postgresql.php @@ -1020,7 +1020,7 @@ public function getAlterDbCharacterSet( $dbName ) /** * Get the query string to create new Database in correct PostgreSQL syntax. * - * @param JObject $options JObject coming from "initialise" function to pass user + * @param object $options object coming from "initialise" function to pass user * and database name to database driver. * @param boolean $utf True if the database supports the UTF-8 character set, * not used in PostgreSQL "CREATE DATABASE" query. diff --git a/libraries/joomla/database/exporter/mysql.php b/libraries/joomla/database/exporter/mysql.php index ead63687b2..b7b9d9b49f 100644 --- a/libraries/joomla/database/exporter/mysql.php +++ b/libraries/joomla/database/exporter/mysql.php @@ -53,7 +53,7 @@ class JDatabaseExporterMysql extends JDatabaseExporter /** * An array of options for the exporter. * - * @var JObject + * @var object * @since 11.1 */ protected $options = null; @@ -67,7 +67,7 @@ class JDatabaseExporterMysql extends JDatabaseExporter */ public function __construct() { - $this->options = new JObject; + $this->options = new stdClass; $this->cache = array('columns' => array(), 'keys' => array()); @@ -292,7 +292,7 @@ public function setDbo(JDatabaseDriverMysql $db) */ public function withStructure($setting = true) { - $this->options->set('with-structure', (boolean) $setting); + $this->options->with-structure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/exporter/postgresql.php b/libraries/joomla/database/exporter/postgresql.php index d6588078ec..3592e730c5 100644 --- a/libraries/joomla/database/exporter/postgresql.php +++ b/libraries/joomla/database/exporter/postgresql.php @@ -53,7 +53,7 @@ class JDatabaseExporterPostgresql extends JDatabaseExporter /** * An array of options for the exporter. * - * @var JObject + * @var object * @since 12.1 */ protected $options = null; @@ -67,7 +67,7 @@ class JDatabaseExporterPostgresql extends JDatabaseExporter */ public function __construct() { - $this->options = new JObject; + $this->options = new stdClass; $this->cache = array('columns' => array(), 'keys' => array()); @@ -306,7 +306,7 @@ public function setDbo(JDatabasePostgresql $db) */ public function withStructure($setting = true) { - $this->options->set('with-structure', (boolean) $setting); + $this->options->with-structure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/factory.php b/libraries/joomla/database/factory.php index 49dac696be..236aa33b0e 100644 --- a/libraries/joomla/database/factory.php +++ b/libraries/joomla/database/factory.php @@ -176,24 +176,6 @@ public function getQuery($name, JDatabaseDriver $db = null) return new $class($db); } - /** - * 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. - * - * @since 12.1 - */ - public function getTable($type, $prefix = 'JTable', $config = array()) - { - return JTable::getInstance($type, $prefix, $config); - } - /** * Gets an instance of a factory object to return on subsequent calls of getInstance. * diff --git a/libraries/joomla/database/importer/mysql.php b/libraries/joomla/database/importer/mysql.php index ff399c2a15..548b6d66f3 100644 --- a/libraries/joomla/database/importer/mysql.php +++ b/libraries/joomla/database/importer/mysql.php @@ -51,7 +51,7 @@ class JDatabaseImporterMysql extends JDatabaseImporter /** * An array of options for the exporter. * - * @var JObject + * @var object * @since 11.1 */ protected $options = null; @@ -65,7 +65,7 @@ class JDatabaseImporterMysql extends JDatabaseImporter */ public function __construct() { - $this->options = new JObject; + $this->options = new stdClass; $this->cache = array('columns' => array(), 'keys' => array()); @@ -646,7 +646,7 @@ public function setDbo(JDatabaseDriverMysql $db) */ public function withStructure($setting = true) { - $this->options->set('with-structure', (boolean) $setting); + $this->options->with-structure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/importer/postgresql.php b/libraries/joomla/database/importer/postgresql.php index 6c545d958d..b932f879b5 100644 --- a/libraries/joomla/database/importer/postgresql.php +++ b/libraries/joomla/database/importer/postgresql.php @@ -51,7 +51,7 @@ class JDatabaseImporterPostgresql extends JDatabaseImporter /** * An array of options for the exporter. * - * @var JObject + * @var object * @since 12.1 */ protected $options = null; @@ -65,7 +65,7 @@ class JDatabaseImporterPostgresql extends JDatabaseImporter */ public function __construct() { - $this->options = new JObject; + $this->options = new stdClass; $this->cache = array('columns' => array(), 'keys' => array()); @@ -788,7 +788,7 @@ public function setDbo(JDatabasePostgresql $db) */ public function withStructure($setting = true) { - $this->options->set('with-structure', (boolean) $setting); + $this->options->with-structure = (boolean) $setting; return $this; } From 135f15a56314902a4d297373cfb8ab59379c49d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 27 Mar 2012 13:36:23 +0200 Subject: [PATCH 56/98] Fix the package tags in the legacy folder so the JDepend table becomes easier to read. --- libraries/legacy/categories/categories.php | 4 ++-- libraries/legacy/help/help.php | 4 ++-- libraries/legacy/menu/menu.php | 4 ++-- libraries/legacy/pathway/pathway.php | 4 ++-- libraries/legacy/request/request.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/libraries/legacy/categories/categories.php b/libraries/legacy/categories/categories.php index 90bfd06081..6bf62f60d7 100644 --- a/libraries/legacy/categories/categories.php +++ b/libraries/legacy/categories/categories.php @@ -1,7 +1,7 @@ Date: Tue, 27 Mar 2012 17:35:45 +0200 Subject: [PATCH 57/98] Make JDatabaseException a subclass of RuntimeException. --- libraries/joomla/database/driver/postgresql.php | 2 +- libraries/joomla/database/exception.php | 2 +- libraries/joomla/database/exporter/mysql.php | 2 +- libraries/joomla/database/exporter/postgresql.php | 2 +- libraries/joomla/database/importer/mysql.php | 2 +- libraries/joomla/database/importer/postgresql.php | 2 +- .../joomla/database/database/JDatabaseExporterMySqlTest.php | 6 +++--- .../database/database/JDatabaseExporterPostgresqlTest.php | 6 +++--- .../joomla/database/database/JDatabaseImporterMySqlTest.php | 6 +++--- .../database/database/JDatabaseImporterPostgresqlTest.php | 6 +++--- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/libraries/joomla/database/driver/postgresql.php b/libraries/joomla/database/driver/postgresql.php index a5d7eb3905..0ac5fc8dbd 100644 --- a/libraries/joomla/database/driver/postgresql.php +++ b/libraries/joomla/database/driver/postgresql.php @@ -1020,7 +1020,7 @@ public function getAlterDbCharacterSet( $dbName ) /** * Get the query string to create new Database in correct PostgreSQL syntax. * - * @param object $options object coming from "initialise" function to pass user + * @param object $options object coming from "initialise" function to pass user * and database name to database driver. * @param boolean $utf True if the database supports the UTF-8 character set, * not used in PostgreSQL "CREATE DATABASE" query. diff --git a/libraries/joomla/database/exception.php b/libraries/joomla/database/exception.php index a15bf2defb..a4c5c7dec6 100644 --- a/libraries/joomla/database/exception.php +++ b/libraries/joomla/database/exception.php @@ -20,6 +20,6 @@ * @since 11.1 * @deprecated 12.3 Use semantic exceptions instead */ -class JDatabaseException extends Exception +class JDatabaseException extends RuntimeException { } diff --git a/libraries/joomla/database/exporter/mysql.php b/libraries/joomla/database/exporter/mysql.php index b7b9d9b49f..e4c4858e6c 100644 --- a/libraries/joomla/database/exporter/mysql.php +++ b/libraries/joomla/database/exporter/mysql.php @@ -292,7 +292,7 @@ public function setDbo(JDatabaseDriverMysql $db) */ public function withStructure($setting = true) { - $this->options->with-structure = (boolean) $setting; + $this->options->withStructure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/exporter/postgresql.php b/libraries/joomla/database/exporter/postgresql.php index 3592e730c5..44edcf542c 100644 --- a/libraries/joomla/database/exporter/postgresql.php +++ b/libraries/joomla/database/exporter/postgresql.php @@ -306,7 +306,7 @@ public function setDbo(JDatabasePostgresql $db) */ public function withStructure($setting = true) { - $this->options->with-structure = (boolean) $setting; + $this->options->withStructure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/importer/mysql.php b/libraries/joomla/database/importer/mysql.php index 548b6d66f3..a16630912c 100644 --- a/libraries/joomla/database/importer/mysql.php +++ b/libraries/joomla/database/importer/mysql.php @@ -646,7 +646,7 @@ public function setDbo(JDatabaseDriverMysql $db) */ public function withStructure($setting = true) { - $this->options->with-structure = (boolean) $setting; + $this->options->withStructure = (boolean) $setting; return $this; } diff --git a/libraries/joomla/database/importer/postgresql.php b/libraries/joomla/database/importer/postgresql.php index b932f879b5..78b0c97d6c 100644 --- a/libraries/joomla/database/importer/postgresql.php +++ b/libraries/joomla/database/importer/postgresql.php @@ -788,7 +788,7 @@ public function setDbo(JDatabasePostgresql $db) */ public function withStructure($setting = true) { - $this->options->with-structure = (boolean) $setting; + $this->options->withStructure = (boolean) $setting; return $this; } diff --git a/tests/suites/unit/joomla/database/database/JDatabaseExporterMySqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseExporterMySqlTest.php index e17b54de19..37ea3d3b1f 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseExporterMySqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseExporterMySqlTest.php @@ -549,21 +549,21 @@ public function testWithStructure() ); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The default use of withStructure should result in true.' ); $instance->withStructure(true); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The explicit use of withStructure with true should result in true.' ); $instance->withStructure(false); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isFalse(), 'The explicit use of withStructure with false should result in false.' ); diff --git a/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php index 40a2eb1510..39413d124d 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php @@ -649,21 +649,21 @@ public function testWithStructure() ); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The default use of withStructure should result in true.' ); $instance->withStructure(true); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The explicit use of withStructure with true should result in true.' ); $instance->withStructure(false); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isFalse(), 'The explicit use of withStructure with false should result in false.' ); diff --git a/tests/suites/unit/joomla/database/database/JDatabaseImporterMySqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseImporterMySqlTest.php index 4bed18303f..53d479eb89 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseImporterMySqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseImporterMySqlTest.php @@ -825,21 +825,21 @@ public function testWithStructure() ); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The default use of withStructure should result in true.' ); $instance->withStructure(true); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The explicit use of withStructure with true should result in true.' ); $instance->withStructure(false); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isFalse(), 'The explicit use of withStructure with false should result in false.' ); diff --git a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php index e91f335597..6491a64cce 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php @@ -1036,21 +1036,21 @@ public function testWithStructure() ); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The default use of withStructure should result in true.' ); $instance->withStructure(true); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isTrue(), 'The explicit use of withStructure with true should result in true.' ); $instance->withStructure(false); $this->assertThat( - $instance->options->get('with-structure'), + $instance->options->withStructure, $this->isFalse(), 'The explicit use of withStructure with false should result in false.' ); From 65e8154e8820006bd728723521e1af3a012b938e Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Tue, 3 Apr 2012 19:06:22 -0500 Subject: [PATCH 58/98] Rename protected members in JStream and JStreamString --- libraries/joomla/filesystem/stream.php | 148 +++++++++--------- .../joomla/filesystem/streams/string.php | 62 ++++---- 2 files changed, 105 insertions(+), 105 deletions(-) diff --git a/libraries/joomla/filesystem/stream.php b/libraries/joomla/filesystem/stream.php index 957a385cd0..1df14a6be4 100644 --- a/libraries/joomla/filesystem/stream.php +++ b/libraries/joomla/filesystem/stream.php @@ -93,37 +93,37 @@ class JStream extends JObject /** * File Handle * @var array - * @since 11.1 + * @since 12.1 */ - protected $_fh; + protected $fh; /** * File size * @var integer - * @since 11.1 + * @since 12.1 */ - protected $_filesize; + protected $filesize; /** *Context to use when opening the connection * @var - * @since 11.1 + * @since 12.1 */ - protected $_context = null; + protected $context = null; /** * Context options; used to rebuild the context * @var - * @since 11.1 + * @since 12.1 */ - protected $_contextOptions; + protected $contextOptions; /** * The mode under which the file was opened * @var - * @since 11.1 + * @since 12.1 */ - protected $_openmode; + protected $openmode; /** * Constructor @@ -138,7 +138,7 @@ public function __construct($writeprefix = '', $readprefix = '', $context = arra { $this->writeprefix = $writeprefix; $this->readprefix = $readprefix; - $this->_contextOptions = $context; + $this->contextOptions = $context; $this->_buildContext(); } @@ -150,7 +150,7 @@ public function __construct($writeprefix = '', $readprefix = '', $context = arra public function __destruct() { // Attempt to close on destruction if there is a file handle - if ($this->_fh) + if ($this->fh) { @$this->close(); } @@ -186,7 +186,7 @@ public function open($filename, $mode = 'r', $use_include_path = false, $context } $this->filename = $filename; - $this->_openmode = $mode; + $this->openmode = $mode; $url = parse_url($filename); $retval = false; @@ -236,12 +236,12 @@ public function open($filename, $mode = 'r', $use_include_path = false, $context { // Gzip doesn't support contexts or streams case 'gz': - $this->_fh = gzopen($filename, $mode, $use_include_path); + $this->fh = gzopen($filename, $mode, $use_include_path); break; // Bzip2 is much like gzip except it doesn't use the include path case 'bz': - $this->_fh = bzopen($filename, $mode); + $this->fh = bzopen($filename, $mode); break; // Fopen can handle streams @@ -250,22 +250,22 @@ public function open($filename, $mode = 'r', $use_include_path = false, $context // One supplied at open; overrides everything if ($context) { - $this->_fh = fopen($filename, $mode, $use_include_path, $context); + $this->fh = fopen($filename, $mode, $use_include_path, $context); } // One provided at initialisation - elseif ($this->_context) + elseif ($this->context) { - $this->_fh = fopen($filename, $mode, $use_include_path, $this->_context); + $this->fh = fopen($filename, $mode, $use_include_path, $this->context); } // No context; all defaults else { - $this->_fh = fopen($filename, $mode, $use_include_path); + $this->fh = fopen($filename, $mode, $use_include_path); } break; } - if (!$this->_fh) + if (!$this->fh) { $this->setError($php_errormsg); } @@ -293,7 +293,7 @@ public function open($filename, $mode = 'r', $use_include_path = false, $context */ public function close() { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); return true; @@ -309,16 +309,16 @@ public function close() switch ($this->processingmethod) { case 'gz': - $res = gzclose($this->_fh); + $res = gzclose($this->fh); break; case 'bz': - $res = bzclose($this->_fh); + $res = bzclose($this->fh); break; case 'f': default: - $res = fclose($this->_fh); + $res = fclose($this->fh); break; } @@ -329,12 +329,12 @@ public function close() else { // Reset this - $this->_fh = null; + $this->fh = null; $retval = true; } // If we wrote, chmod the file after it's closed - if ($this->_openmode[0] == 'w') + if ($this->openmode[0] == 'w') { $this->chmod(); } @@ -355,7 +355,7 @@ public function close() */ public function eof() { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -370,13 +370,13 @@ public function eof() switch ($this->processingmethod) { case 'gz': - $res = gzeof($this->_fh); + $res = gzeof($this->fh); break; case 'bz': case 'f': default: - $res = feof($this->_fh); + $res = feof($this->fh); break; } @@ -444,13 +444,13 @@ public function filesize() } else { - $this->_filesize = $res; + $this->filesize = $res; $retval = $res; } } else { - $this->_filesize = $res; + $this->filesize = $res; $retval = $res; } @@ -472,7 +472,7 @@ public function filesize() */ public function gets($length = 0) { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -489,13 +489,13 @@ public function gets($length = 0) switch ($this->processingmethod) { case 'gz': - $res = $length ? gzgets($this->_fh, $length) : gzgets($this->_fh); + $res = $length ? gzgets($this->fh, $length) : gzgets($this->fh); break; case 'bz': case 'f': default: - $res = $length ? fgets($this->_fh, $length) : fgets($this->_fh); + $res = $length ? fgets($this->fh, $length) : fgets($this->fh); break; } @@ -529,23 +529,23 @@ public function gets($length = 0) */ public function read($length = 0) { - if (!$this->_filesize && !$length) + if (!$this->filesize && !$length) { // Get the filesize $this->filesize(); - if (!$this->_filesize) + if (!$this->filesize) { // Set it to the biggest and then wait until eof $length = -1; } else { - $length = $this->_filesize; + $length = $this->filesize; } } - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -566,16 +566,16 @@ public function read($length = 0) switch ($this->processingmethod) { case 'bz': - $res = ($remaining > 0) ? bzread($this->_fh, $remaining) : bzread($this->_fh, $this->chunksize); + $res = ($remaining > 0) ? bzread($this->fh, $remaining) : bzread($this->fh, $this->chunksize); break; case 'gz': - $res = ($remaining > 0) ? gzread($this->_fh, $remaining) : gzread($this->_fh, $this->chunksize); + $res = ($remaining > 0) ? gzread($this->fh, $remaining) : gzread($this->fh, $this->chunksize); break; case 'f': default: - $res = ($remaining > 0) ? fread($this->_fh, $remaining) : fread($this->_fh, $this->chunksize); + $res = ($remaining > 0) ? fread($this->fh, $remaining) : fread($this->fh, $this->chunksize); break; } @@ -632,7 +632,7 @@ public function read($length = 0) */ public function seek($offset, $whence = SEEK_SET) { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -649,13 +649,13 @@ public function seek($offset, $whence = SEEK_SET) switch ($this->processingmethod) { case 'gz': - $res = gzseek($this->_fh, $offset, $whence); + $res = gzseek($this->fh, $offset, $whence); break; case 'bz': case 'f': default: - $res = fseek($this->_fh, $offset, $whence); + $res = fseek($this->fh, $offset, $whence); break; } @@ -685,7 +685,7 @@ public function seek($offset, $whence = SEEK_SET) */ public function tell() { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -702,13 +702,13 @@ public function tell() switch ($this->processingmethod) { case 'gz': - $res = gztell($this->_fh); + $res = gztell($this->fh); break; case 'bz': case 'f': default: - $res = ftell($this->_fh); + $res = ftell($this->fh); break; } @@ -747,7 +747,7 @@ public function tell() */ public function write(&$string, $length = 0, $chunk = 0) { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); @@ -778,7 +778,7 @@ public function write(&$string, $length = 0, $chunk = 0) { // If the amount remaining is greater than the chunk size, then use the chunk $amount = ($remaining > $chunk) ? $chunk : $remaining; - $res = fwrite($this->_fh, $string, $amount); + $res = fwrite($this->fh, $string, $amount); // Returns false on error or the number of bytes written if ($res === false) @@ -887,14 +887,14 @@ public function chmod($filename = '', $mode = 0) */ public function get_meta_data() { - if (!$this->_fh) + if (!$this->fh) { $this->setError(JText::_('JLIB_FILESYSTEM_ERROR_STREAMS_FILE_NOT_OPEN')); return false; } - return stream_get_meta_data($this->_fh); + return stream_get_meta_data($this->fh); } /** @@ -908,13 +908,13 @@ public function get_meta_data() public function _buildContext() { // According to the manual this always works! - if (count($this->_contextOptions)) + if (count($this->contextOptions)) { - $this->_context = @stream_context_create($this->_contextOptions); + $this->context = @stream_context_create($this->contextOptions); } else { - $this->_context = null; + $this->context = null; } } @@ -932,7 +932,7 @@ public function _buildContext() */ public function setContextOptions($context) { - $this->_contextOptions = $context; + $this->contextOptions = $context; $this->_buildContext(); } @@ -951,7 +951,7 @@ public function setContextOptions($context) */ public function addContextEntry($wrapper, $name, $value) { - $this->_contextOptions[$wrapper][$name] = $value; + $this->contextOptions[$wrapper][$name] = $value; $this->_buildContext(); } @@ -969,19 +969,19 @@ public function addContextEntry($wrapper, $name, $value) public function deleteContextEntry($wrapper, $name) { // Check whether the wrapper is set - if (isset($this->_contextOptions[$wrapper])) + if (isset($this->contextOptions[$wrapper])) { // Check that entry is set for that wrapper - if (isset($this->_contextOptions[$wrapper][$name])) + if (isset($this->contextOptions[$wrapper][$name])) { // Unset the item - unset($this->_contextOptions[$wrapper][$name]); + unset($this->contextOptions[$wrapper][$name]); // Check that there are still items there - if (!count($this->_contextOptions[$wrapper])) + if (!count($this->contextOptions[$wrapper])) { // Clean up an empty wrapper context option - unset($this->_contextOptions[$wrapper]); + unset($this->contextOptions[$wrapper]); } } } @@ -1003,13 +1003,13 @@ public function applyContextToStream() { $retval = false; - if ($this->_fh) + if ($this->fh) { // Capture PHP errors $php_errormsg = 'Unknown error setting context option'; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); - $retval = @stream_context_set_option($this->_fh, $this->_contextOptions); + $retval = @stream_context_set_option($this->fh, $this->contextOptions); if (!$retval) { @@ -1040,14 +1040,14 @@ public function appendFilter($filtername, $read_write = STREAM_FILTER_READ, $par { $res = false; - if ($this->_fh) + if ($this->fh) { // Capture PHP errors $php_errormsg = ''; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); - $res = @stream_filter_append($this->_fh, $filtername, $read_write, $params); + $res = @stream_filter_append($this->fh, $filtername, $read_write, $params); if (!$res && $php_errormsg) { @@ -1081,13 +1081,13 @@ public function prependFilter($filtername, $read_write = STREAM_FILTER_READ, $pa { $res = false; - if ($this->_fh) + if ($this->fh) { // Capture PHP errors $php_errormsg = ''; $track_errors = ini_get('track_errors'); ini_set('track_errors', true); - $res = @stream_filter_prepend($this->_fh, $filtername, $read_write, $params); + $res = @stream_filter_prepend($this->fh, $filtername, $read_write, $params); if (!$res && $php_errormsg) { @@ -1182,10 +1182,10 @@ public function copy($src, $dest, $context = null, $use_prefix = true, $relative // Use the provided context $res = @copy($src, $dest, $context); } - elseif ($this->_context) + elseif ($this->context) { // Use the objects context - $res = @copy($src, $dest, $this->_context); + $res = @copy($src, $dest, $this->context); } else { @@ -1238,10 +1238,10 @@ public function move($src, $dest, $context = null, $use_prefix = true, $relative // Use the provided context $res = @rename($src, $dest, $context); } - elseif ($this->_context) + elseif ($this->context) { // Use the object's context - $res = @rename($src, $dest, $this->_context); + $res = @rename($src, $dest, $this->context); } else { @@ -1290,10 +1290,10 @@ public function delete($filename, $context = null, $use_prefix = true, $relative // Use the provided context $res = @unlink($filename, $context); } - elseif ($this->_context) + elseif ($this->context) { // Use the object's context - $res = @unlink($filename, $this->_context); + $res = @unlink($filename, $this->context); } else { @@ -1417,6 +1417,6 @@ public function _getFilename($filename, $mode, $use_prefix, $relative) */ public function getFileHandle() { - return $this->_fh; + return $this->fh; } } diff --git a/libraries/joomla/filesystem/streams/string.php b/libraries/joomla/filesystem/streams/string.php index 1cf4685932..3d264e6533 100644 --- a/libraries/joomla/filesystem/streams/string.php +++ b/libraries/joomla/filesystem/streams/string.php @@ -27,72 +27,72 @@ class JStreamString * The current string * * @var string - * @since 11.1 + * @since 12.1 */ - protected $_currentstring; + protected $currentString; /** * * The path * * @var string - * @since 11.1 + * @since 12.1 */ - protected $_path; + protected $path; /** * * The mode * * @var string - * @since 11.1 + * @since 12.1 */ - protected $_mode; + protected $mode; /** * * Enter description here ... * @var string * - * @since 11.1 + * @since 12.1 */ - protected $_options; + protected $options; /** * * Enter description here ... * @var string * - * @since 11.1 + * @since 12.1 */ - protected $_opened_path; + protected $openedPath; /** * Current position * * @var integer - * @since 11.1 + * @since 12.1 */ - protected $_pos; + protected $pos; /** * Length of the string * * @var string * - * @since 11.1 + * @since 12.1 */ - protected $_len; + protected $len; /** * Statistics for a file * * @var array - * @since 11.1 + * @since 12.1 * * @see http://us.php.net/manual/en/function.stat.php */ - protected $_stat; + protected $stat; /** * Method to open a file or URL. @@ -108,13 +108,13 @@ class JStreamString */ public function stream_open($path, $mode, $options, &$opened_path) { - $this->_currentstring = &JStringController::getRef(str_replace('string://', '', $path)); + $this->currentString = &JStringController::getRef(str_replace('string://', '', $path)); - if ($this->_currentstring) + if ($this->currentString) { - $this->_len = strlen($this->_currentstring); - $this->_pos = 0; - $this->_stat = $this->url_stat($path, 0); + $this->len = strlen($this->currentString); + $this->pos = 0; + $this->stat = $this->url_stat($path, 0); return true; } @@ -134,7 +134,7 @@ public function stream_open($path, $mode, $options, &$opened_path) */ public function stream_stat() { - return $this->_stat; + return $this->stat; } /** @@ -185,8 +185,8 @@ public function url_stat($path, $flags = 0) */ public function stream_read($count) { - $result = substr($this->_currentstring, $this->_pos, $count); - $this->_pos += $count; + $result = substr($this->currentString, $this->pos, $count); + $this->pos += $count; return $result; } @@ -216,7 +216,7 @@ public function stream_write($data) */ public function stream_tell() { - return $this->_pos; + return $this->pos; } /** @@ -228,7 +228,7 @@ public function stream_tell() */ public function stream_eof() { - if ($this->_pos > $this->_len) + if ($this->pos > $this->len) { return true; } @@ -249,7 +249,7 @@ public function stream_eof() public function stream_seek($offset, $whence) { // $whence: SEEK_SET, SEEK_CUR, SEEK_END - if ($offset > $this->_len) + if ($offset > $this->len) { // We can't seek beyond our len. return false; @@ -258,13 +258,13 @@ public function stream_seek($offset, $whence) switch ($whence) { case SEEK_SET: - $this->_pos = $offset; + $this->pos = $offset; break; case SEEK_CUR: - if (($this->_pos + $offset) < $this->_len) + if (($this->pos + $offset) < $this->len) { - $this->_pos += $offset; + $this->pos += $offset; } else { @@ -273,7 +273,7 @@ public function stream_seek($offset, $whence) break; case SEEK_END: - $this->_pos = $this->_len - $offset; + $this->pos = $this->len - $offset; break; } From 880c50ffdd9f0b73d94a11ea7f2a3262976c48a3 Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Tue, 3 Apr 2012 20:10:23 -0500 Subject: [PATCH 59/98] Fix a parse error from #1110 --- libraries/joomla/string/string.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/string/string.php b/libraries/joomla/string/string.php index bf92a7c34d..32b87b4040 100644 --- a/libraries/joomla/string/string.php +++ b/libraries/joomla/string/string.php @@ -21,7 +21,7 @@ } // Same for iconv -if (function_exists('iconv'))) +if (function_exists('iconv')) { // These are settings that can be set inside code iconv_set_encoding("internal_encoding", "UTF-8"); From fb453620908a5f2bdc10c01e2aae63f6c0f00ed2 Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Wed, 4 Apr 2012 20:29:32 +0530 Subject: [PATCH 60/98] changed to throw LogicException Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 33 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index d880a4d0a0..80c53882fc 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -654,6 +654,8 @@ protected function getFilterInstance($type) * * @return object * + * @throws LogicException If width,height or both given as zero + * * @since 11.3 * @throws InvalidArgumentException */ @@ -672,25 +674,24 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: - // To avoid dividing by $width if it is zero - if($width==0 && $height!=0){ - $rx = $this->getWidth() ; - $ry = $this->getHeight() / $height; - } + // To avoid dividing by $width if it is zero + if($width == 0 && $height != 0) + { + throw new LogicException(' Width cannot be zero '); + } - // To avoid dividing by $height if it is zero - elseif ($width!=0 && $height==0) { - $rx = $this->getWidth() / $width; - $ry = $this->getHeight() ; - } + // To avoid dividing by $height if it is zero + elseif ($width != 0 && $height == 0) + { + throw new LogicException(' Height cannot be zero '); + } - // Both $height and $width are zero - elseif($width==0 && $height==0){ - $rx = $this->getWidth() / $width; - $ry = $this->getHeight() ; - } + // Both $height and $width are zero + elseif($width == 0 && $height == 0){ + throw new LogicException(' Both height and width cannot be zero '); + } - // If both $width and $height are not equals to zero + // If both $width and $height are not equals to zero else{ $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; From 1ecbcfef39bfd1cb29349e52b4297bee8adf6d53 Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Fri, 6 Apr 2012 02:03:17 +0530 Subject: [PATCH 61/98] Add 2 elseif cases for iPad and iPod Signed-off-by: Buddhima Wijeweera --- libraries/joomla/application/web/client.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/libraries/joomla/application/web/client.php b/libraries/joomla/application/web/client.php index cf08e9c5d7..f01a52f9dc 100644 --- a/libraries/joomla/application/web/client.php +++ b/libraries/joomla/application/web/client.php @@ -417,6 +417,18 @@ protected function detectPlatform($userAgent) $this->platform = self::IPOD; } } + // In case where iPhone is not mentioed in iPad user agent string + elseif (stripos($userAgent, 'iPad') !== false) + { + $this->mobile = true; + $this->platform = self::IPAD; + } + // In case where iPhone is not mentioed in iPod user agent string + elseif (stripos($userAgent, 'iPod') !== false) + { + $this->mobile = true; + $this->platform = self::IPOD; + } // This has to come after the iPhone check because mac strings are also present in iOS devices. elseif (preg_match('/macintosh|mac os x/i', $userAgent)) { From c4b483387a06283d31459c8c824df76980e5ee54 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Fri, 23 Mar 2012 23:59:33 +0100 Subject: [PATCH 62/98] Deprecating JNode and JTree Disabling Code Coverage for these two classes Moving to legacy folder --- libraries/{joomla => legacy}/base/node.php | 23 +++++++++++++++++++ libraries/{joomla => legacy}/base/tree.php | 14 +++++++++++ .../{joomla => legacy}/base/JNodeTest.php | 0 .../{joomla => legacy}/base/JTreeTest.php | 0 4 files changed, 37 insertions(+) rename libraries/{joomla => legacy}/base/node.php (74%) rename libraries/{joomla => legacy}/base/tree.php (75%) rename tests/suites/unit/{joomla => legacy}/base/JNodeTest.php (100%) rename tests/suites/unit/{joomla => legacy}/base/JTreeTest.php (100%) diff --git a/libraries/joomla/base/node.php b/libraries/legacy/base/node.php similarity index 74% rename from libraries/joomla/base/node.php rename to libraries/legacy/base/node.php index f12227ff70..4d9672d39d 100644 --- a/libraries/joomla/base/node.php +++ b/libraries/legacy/base/node.php @@ -15,6 +15,8 @@ * @package Joomla.Platform * @subpackage Base * @since 11.1 + * @deprecated 12.1 + * @codeCoverageIgnore */ class JNode extends JObject { @@ -41,6 +43,9 @@ class JNode extends JObject */ public function __construct() { + // Deprecation warning. + JLog::add('JNode::__construct() is deprecated.', JLog::WARNING, 'deprecated'); + return true; } @@ -57,6 +62,9 @@ public function __construct() */ public function addChild(&$child) { + // Deprecation warning. + JLog::add('JNode::addChild() is deprecated.', JLog::WARNING, 'deprecated'); + if ($child instanceof Jnode) { $child->setParent($this); @@ -76,6 +84,9 @@ public function addChild(&$child) */ public function setParent(&$parent) { + // Deprecation warning. + JLog::add('JNode::setParent() is deprecated.', JLog::WARNING, 'deprecated'); + if ($parent instanceof JNode || is_null($parent)) { $hash = spl_object_hash($this); @@ -100,6 +111,9 @@ public function setParent(&$parent) */ public function &getChildren() { + // Deprecation warning. + JLog::add('JNode::getChildren() is deprecated.', JLog::WARNING, 'deprecated'); + return $this->_children; } @@ -112,6 +126,9 @@ public function &getChildren() */ public function &getParent() { + // Deprecation warning. + JLog::add('JNode::getParent() is deprecated.', JLog::WARNING, 'deprecated'); + return $this->_parent; } @@ -124,6 +141,9 @@ public function &getParent() */ public function hasChildren() { + // Deprecation warning. + JLog::add('JNode::hasChildren() is deprecated.', JLog::WARNING, 'deprecated'); + return (bool) count($this->_children); } @@ -136,6 +156,9 @@ public function hasChildren() */ public function hasParent() { + // Deprecation warning. + JLog::add('JNode::hasParent() is deprecated.', JLog::WARNING, 'deprecated'); + return $this->getParent() != null; } } diff --git a/libraries/joomla/base/tree.php b/libraries/legacy/base/tree.php similarity index 75% rename from libraries/joomla/base/tree.php rename to libraries/legacy/base/tree.php index 9ff5f553e7..f8424a3928 100644 --- a/libraries/joomla/base/tree.php +++ b/libraries/legacy/base/tree.php @@ -17,6 +17,8 @@ * @package Joomla.Platform * @subpackage Base * @since 11.1 + * @deprecated 12.1 + * @codeCoverageIgnore */ class JTree extends JObject { @@ -43,6 +45,9 @@ class JTree extends JObject */ public function __construct() { + // Deprecation warning. + JLog::add('JTree::__construct() is deprecated.', JLog::WARNING, 'deprecated'); + $this->_root = new JNode('ROOT'); $this->_current = & $this->_root; } @@ -59,6 +64,9 @@ public function __construct() */ public function addChild(&$node, $setCurrent = false) { + // Deprecation warning. + JLog::add('JTree::addChild() is deprecated.', JLog::WARNING, 'deprecated'); + $this->_current->addChild($node); if ($setCurrent) { @@ -75,6 +83,9 @@ public function addChild(&$node, $setCurrent = false) */ public function getParent() { + // Deprecation warning. + JLog::add('JTree::getParent() is deprecated.', JLog::WARNING, 'deprecated'); + $this->_current = &$this->_current->getParent(); } @@ -87,6 +98,9 @@ public function getParent() */ public function reset() { + // Deprecation warning. + JLog::add('JTree::reset() is deprecated.', JLog::WARNING, 'deprecated'); + $this->_current = &$this->_root; } } diff --git a/tests/suites/unit/joomla/base/JNodeTest.php b/tests/suites/unit/legacy/base/JNodeTest.php similarity index 100% rename from tests/suites/unit/joomla/base/JNodeTest.php rename to tests/suites/unit/legacy/base/JNodeTest.php diff --git a/tests/suites/unit/joomla/base/JTreeTest.php b/tests/suites/unit/legacy/base/JTreeTest.php similarity index 100% rename from tests/suites/unit/joomla/base/JTreeTest.php rename to tests/suites/unit/legacy/base/JTreeTest.php From 531d2926e3b93978635a956df64ef40a4a8586c8 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 24 Mar 2012 12:02:16 +0100 Subject: [PATCH 63/98] Fixing paths for JTree/JNode Tests --- tests/suites/unit/legacy/base/JNodeTest.php | 2 +- tests/suites/unit/legacy/base/JTreeTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/suites/unit/legacy/base/JNodeTest.php b/tests/suites/unit/legacy/base/JNodeTest.php index 90e713fe91..f493532885 100644 --- a/tests/suites/unit/legacy/base/JNodeTest.php +++ b/tests/suites/unit/legacy/base/JNodeTest.php @@ -7,7 +7,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -require_once JPATH_PLATFORM.'/joomla/base/tree.php'; +require_once JPATH_PLATFORM.'/legacy/base/tree.php'; /** * Test class for JNode. diff --git a/tests/suites/unit/legacy/base/JTreeTest.php b/tests/suites/unit/legacy/base/JTreeTest.php index 0636a01361..df08b1137f 100644 --- a/tests/suites/unit/legacy/base/JTreeTest.php +++ b/tests/suites/unit/legacy/base/JTreeTest.php @@ -7,7 +7,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -require_once JPATH_PLATFORM.'/joomla/base/tree.php'; +require_once JPATH_PLATFORM.'/legacy/base/tree.php'; /** * Test class for JTree. From 764dd3afa42173ba542104dea87e0dd5d7dfcc50 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 24 Mar 2012 13:07:40 +0100 Subject: [PATCH 64/98] Fixing JNode include --- tests/suites/unit/legacy/base/JNodeTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/unit/legacy/base/JNodeTest.php b/tests/suites/unit/legacy/base/JNodeTest.php index f493532885..2ead8b7b77 100644 --- a/tests/suites/unit/legacy/base/JNodeTest.php +++ b/tests/suites/unit/legacy/base/JNodeTest.php @@ -7,7 +7,7 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -require_once JPATH_PLATFORM.'/legacy/base/tree.php'; +require_once JPATH_PLATFORM.'/legacy/base/node.php'; /** * Test class for JNode. From a5d9318ad2f27458298cc81d7f89523a68593cb1 Mon Sep 17 00:00:00 2001 From: Hannes Papenberg Date: Sat, 24 Mar 2012 13:23:55 +0100 Subject: [PATCH 65/98] Registering JNode/JTree in import.legacy.php --- libraries/import.legacy.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libraries/import.legacy.php b/libraries/import.legacy.php index ee5687cdb8..9677a28869 100644 --- a/libraries/import.legacy.php +++ b/libraries/import.legacy.php @@ -64,3 +64,5 @@ class_exists('JLoader') or die; JLoader::register('JDatabaseQuerySQLAzure', JPATH_PLATFORM . '/joomla/database/query/sqlazure.php'); JLoader::register('JDatabaseQuerySQLSrv', JPATH_PLATFORM . '/joomla/database/query/sqlsrv.php'); JLoader::register('JToolBar', JPATH_PLATFORM . '/legacy/toolbar/toolbar.php'); +JLoader::register('JTree', JPATH_PLATFORM . '/legacy/base/tree.php'); +JLoader::register('JNode', JPATH_PLATFORM . '/legacy/base/node.php'); \ No newline at end of file From 8869de548d5f51039af0fe91cace28cd2a6b32ad Mon Sep 17 00:00:00 2001 From: eddieajau Date: Fri, 6 Apr 2012 14:14:31 +1000 Subject: [PATCH 66/98] Changed deprecated version to 12.3 (for permanent removal). --- libraries/legacy/base/node.php | 2 +- libraries/legacy/base/tree.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/legacy/base/node.php b/libraries/legacy/base/node.php index 4d9672d39d..479215f211 100644 --- a/libraries/legacy/base/node.php +++ b/libraries/legacy/base/node.php @@ -15,7 +15,7 @@ * @package Joomla.Platform * @subpackage Base * @since 11.1 - * @deprecated 12.1 + * @deprecated 12.3 * @codeCoverageIgnore */ class JNode extends JObject diff --git a/libraries/legacy/base/tree.php b/libraries/legacy/base/tree.php index f8424a3928..96e34e031a 100644 --- a/libraries/legacy/base/tree.php +++ b/libraries/legacy/base/tree.php @@ -17,7 +17,7 @@ * @package Joomla.Platform * @subpackage Base * @since 11.1 - * @deprecated 12.1 + * @deprecated 12.3 * @codeCoverageIgnore */ class JTree extends JObject From 7df127ceb7b029ec90c3b9d3dc0f94d38c7e230a Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Fri, 6 Apr 2012 10:38:33 +0530 Subject: [PATCH 67/98] Replace 3 if cases with one and corrected style mistakes Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 37 ++++++++++++-------------------- 1 file changed, 14 insertions(+), 23 deletions(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 80c53882fc..ad7614b3bb 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -673,29 +673,20 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: - - // To avoid dividing by $width if it is zero - if($width == 0 && $height != 0) - { - throw new LogicException(' Width cannot be zero '); - } - - // To avoid dividing by $height if it is zero - elseif ($width != 0 && $height == 0) - { - throw new LogicException(' Height cannot be zero '); - } - - // Both $height and $width are zero - elseif($width == 0 && $height == 0){ - throw new LogicException(' Both height and width cannot be zero '); - } - - // If both $width and $height are not equals to zero - else{ - $rx = $this->getWidth() / $width; - $ry = $this->getHeight() / $height; - } + + // Both $height or $width cannot be zero + if($width == 0 || $height == 0) + { + throw new LogicException(' Both height or width cannot be zero '); + } + + // If both $width and $height are not equals to zero + else + { + $rx = $this->getWidth() / $width; + $ry = $this->getHeight() / $height; + } + if ($scaleMethod == self::SCALE_INSIDE) { $ratio = ($rx > $ry) ? $rx : $ry; From 2cdd47f21c340ece0d6e60d468de83e53a561056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Fri, 6 Apr 2012 13:06:53 +0200 Subject: [PATCH 68/98] Fix and improve the docblocks in the legacy folder. --- libraries/legacy/application/application.php | 27 ---- libraries/legacy/application/helper.php | 3 +- libraries/legacy/categories/categories.php | 139 +------------------ libraries/legacy/component/helper.php | 13 +- libraries/legacy/menu/menu.php | 31 +---- libraries/legacy/model/admin.php | 4 +- libraries/legacy/model/form.php | 13 +- libraries/legacy/model/item.php | 22 +-- libraries/legacy/model/list.php | 4 +- libraries/legacy/model/model.php | 22 +-- libraries/legacy/module/helper.php | 4 +- libraries/legacy/pathway/pathway.php | 4 +- libraries/legacy/request/request.php | 6 +- libraries/legacy/view/view.php | 100 +------------ 14 files changed, 27 insertions(+), 365 deletions(-) diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index 9211f1a1d6..09b3bb0ee4 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -30,15 +30,6 @@ class JApplication extends JApplicationBase * @var integer * @since 11.1 */ - protected $clientId = null; - - /** - * The client identifier. - * - * @var integer - * @since 11.1 - * @deprecated use $clientId or declare as private - */ protected $_clientId = null; /** @@ -47,15 +38,6 @@ class JApplication extends JApplicationBase * @var array * @since 11.1 */ - protected $messageQueue = array(); - - /** - * The application message queue. - * - * @var array - * @since 11.1 - * @deprecated use $messageQueue or declare as private - */ protected $_messageQueue = array(); /** @@ -64,15 +46,6 @@ class JApplication extends JApplicationBase * @var array * @since 11.1 */ - protected $name = null; - - /** - * The name of the application. - * - * @var array - * @since 11.1 - * @deprecated use $name or declare as private - */ protected $_name = null; /** diff --git a/libraries/legacy/application/helper.php b/libraries/legacy/application/helper.php index 775f941fc0..d8e0f255cd 100644 --- a/libraries/legacy/application/helper.php +++ b/libraries/legacy/application/helper.php @@ -31,7 +31,6 @@ class JApplicationHelper * * @var array * @since 11.1 - * @deprecated use $clientsor declare as private */ protected static $_clients = null; @@ -175,7 +174,7 @@ public static function addClientInfo($client) * @return array XML metadata. * * @since 11.1 - * @deprecated 12.1 + * @deprecated 13.3 */ public static function parseXMLInstallFile($path) { diff --git a/libraries/legacy/categories/categories.php b/libraries/legacy/categories/categories.php index 90bfd06081..c114cffd49 100644 --- a/libraries/legacy/categories/categories.php +++ b/libraries/legacy/categories/categories.php @@ -1,7 +1,7 @@ array(), 'helper' => array()); - - /** - * The set of search directories for resources (templates) - * - * @var array - * @deprecated use $path declare as private - */ protected $_path = array('template' => array(), 'helper' => array()); /** @@ -145,14 +81,6 @@ class JView extends JObject * * @var string */ - protected $template = null; - - /** - * The name of the default template source file. - * - * @var string - * @deprecated use $template declare as private - */ protected $_template = null; /** @@ -160,14 +88,6 @@ class JView extends JObject * * @var string */ - protected $output = null; - - /** - * The output of the template script. - * - * @var string - * @deprecated use $output declare as private - */ protected $_output = null; /** @@ -175,14 +95,6 @@ class JView extends JObject * * @var string */ - protected $escape = 'htmlspecialchars'; - - /** - * Callback for escaping. - * - * @var string - * @deprecated use $escape declare as private - */ protected $_escape = 'htmlspecialchars'; /** @@ -190,14 +102,6 @@ class JView extends JObject * * @var string */ - protected $charset = 'UTF-8'; - - /** - * Charset to use in escaping mechanisms; defaults to urf8 (UTF-8) - * - * @var string - * @deprecated use $charset declare as private - */ protected $_charset = 'UTF-8'; /** From 00f569a128916cebc2097202796ea06bc0d06ae7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Fri, 6 Apr 2012 13:17:07 +0200 Subject: [PATCH 69/98] Remove JFormFieldTemplateStyle. --- libraries/legacy/form/field/templatestyle.php | 105 ------------------ .../field/JFormFieldTemplateStyleTest.php | 41 ------- 2 files changed, 146 deletions(-) delete mode 100644 libraries/legacy/form/field/templatestyle.php delete mode 100644 tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php diff --git a/libraries/legacy/form/field/templatestyle.php b/libraries/legacy/form/field/templatestyle.php deleted file mode 100644 index cdf960c49a..0000000000 --- a/libraries/legacy/form/field/templatestyle.php +++ /dev/null @@ -1,105 +0,0 @@ -element['client'] ? (string) $this->element['client'] : 'site'; - $client = JApplicationHelper::getClientInfo($clientName, true); - - // Get the template. - $template = (string) $this->element['template']; - - // Get the database object and a new query object. - $db = JFactory::getDBO(); - $query = $db->getQuery(true); - - // Build the query. - $query->select('s.id, s.title, e.name as name, s.template'); - $query->from('#__template_styles as s'); - $query->where('s.client_id = ' . (int) $client->id); - $query->order('template'); - $query->order('title'); - if ($template) - { - $query->where('s.template = ' . $db->quote($template)); - } - $query->join('LEFT', '#__extensions as e on e.element=s.template'); - $query->where($db->quoteName('e.type') . '=' . $db->quote('template')); - $query->where('e.enabled=1'); - - // Set the query and load the styles. - $db->setQuery($query); - $styles = $db->loadObjectList(); - - // Build the grouped list array. - if ($styles) - { - foreach ($styles as $style) - { - $template = $style->template; - $lang->load('tpl_' . $template . '.sys', $client->path, null, false, false) - || $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, null, false, false) - || $lang->load('tpl_' . $template . '.sys', $client->path, $lang->getDefault(), false, false) - || $lang->load('tpl_' . $template . '.sys', $client->path . '/templates/' . $template, $lang->getDefault(), false, false); - $name = JText::_($style->name); - - // Initialize the group if necessary. - if (!isset($groups[$name])) - { - $groups[$name] = array(); - } - - $groups[$name][] = JHtml::_('select.option', $style->id, $style->title); - } - } - - // Merge any additional groups in the XML definition. - $groups = array_merge(parent::getGroups(), $groups); - - return $groups; - } -} diff --git a/tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php b/tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php deleted file mode 100644 index 91f54fb97f..0000000000 --- a/tests/suites/legacy/form/field/JFormFieldTemplateStyleTest.php +++ /dev/null @@ -1,41 +0,0 @@ -assertThat($form->load('
    '), $this->isTrue(), - 'Line:' . __LINE__ . ' XML string should load successfully.'); - - $field = new JFormFieldTemplatestyle($form); - - $this->assertThat($field->setup(TestReflection::getValue($form, 'xml')->field, 'value'), $this->isTrue(), - 'Line:' . __LINE__ . ' The setup method should return true.'); - - $this->markTestIncomplete('Problems encountered in next assertion'); - - $this->assertThat(strlen($field->input), $this->greaterThan(0), - 'Line:' . __LINE__ . ' The getInput method should return something without error.'); - - // TODO: Should check all the attributes have come in properly. - } -} From af92150edd01daf10ffb49fca0287cd7b7fa8248 Mon Sep 17 00:00:00 2001 From: n3t Date: Fri, 6 Apr 2012 17:55:51 +0300 Subject: [PATCH 70/98] JImage PHP 5.2 JPG compatibility --- libraries/joomla/image/image.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 4bb423f6ee..4e24fdb128 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -78,7 +78,7 @@ public function __construct($source = null) if (!isset(self::$formats[IMAGETYPE_JPEG])) { $info = gd_info(); - self::$formats[IMAGETYPE_JPEG] = ($info['JPEG Support']) ? true : false; + self::$formats[IMAGETYPE_JPEG] = (isset($info['JPEG Support']) && $info['JPEG Support'] || isset($info['JPG Support']) && $info['JPG Support']) ? true : false; self::$formats[IMAGETYPE_PNG] = ($info['PNG Support']) ? true : false; self::$formats[IMAGETYPE_GIF] = ($info['GIF Read Support']) ? true : false; } From 81d3bf060edfa3da7d52798fcb0d51bb4c83cb0d Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Sat, 7 Apr 2012 02:12:40 +0530 Subject: [PATCH 71/98] Changed tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php by adding iPod,iPad to array Signed-off-by: Buddhima Wijeweera --- .../unit/joomla/application/web/JApplicationWebClientTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php index b801994082..be5ef255b9 100644 --- a/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php +++ b/tests/suites/unit/joomla/application/web/JApplicationWebClientTest.php @@ -54,6 +54,8 @@ public static function getUserAgentData() array(JApplicationWebClient::ANDROID, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4', 'Mozilla/5.0 (Linux; U; Android 2.2.1; en-ca; LG-P505R Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1'), array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU iPhone OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), array(JApplicationWebClient::IPHONE, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.5', 'Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_1 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8B5097d Safari/6531.22.7'), + array(JApplicationWebClient::IPAD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), + array(JApplicationWebClient::IPOD, true, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '4.0.4', 'Mozilla/5.0(iPod; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B314 Safari/531.21.10gin_lib.cc'), array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.4', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'), array(JApplicationWebClient::MAC, false, JApplicationWebClient::WEBKIT, JApplicationWebClient::SAFARI, '5.0.3', 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_5; ar) AppleWebKit/533.19.4 (KHTML, like Gecko) Version/5.0.3 Safari/533.19.4'), array(JApplicationWebClient::WINDOWS, false, JApplicationWebClient::GECKO, JApplicationWebClient::FIREFOX, '3.6.9', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-GB; rv:1.9.2.9) Gecko/20100824 Firefox/3.6.9 ( .NET CLR 3.5.30729; .NET CLR 4.0.20506)'), From 65a4309fc3979344de4a0708c11fa2fdfed09141 Mon Sep 17 00:00:00 2001 From: Thomas Hunziker Date: Sat, 7 Apr 2012 19:12:11 +0300 Subject: [PATCH 72/98] The label for the language selector had a wrong "for" attribut, thus clicking on the label didn't select the inputbox. --- libraries/joomla/html/html/batch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/html/html/batch.php b/libraries/joomla/html/html/batch.php index 089389843a..87923863d2 100644 --- a/libraries/joomla/html/html/batch.php +++ b/libraries/joomla/html/html/batch.php @@ -80,7 +80,7 @@ public static function language() { // Create the batch selector to change the language on a selection list. $lines = array( - '', From b92c0808b6ede705386024b9dc3f0018236d261a Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sun, 8 Apr 2012 14:38:12 +0200 Subject: [PATCH 73/98] Add JDatabase::splitSql() for B/C --- libraries/joomla/database/database.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libraries/joomla/database/database.php b/libraries/joomla/database/database.php index 0a6099cc11..d32f2d1f64 100644 --- a/libraries/joomla/database/database.php +++ b/libraries/joomla/database/database.php @@ -115,6 +115,23 @@ public static function getInstance($options = array()) return JDatabaseDriver::getInstance($options); } + /** + * Splits a string of multiple queries into an array of individual queries. + * + * @param string $sql Input SQL string with which to split into individual queries. + * + * @return array The queries from the input string separated into an array. + * + * @since 11.1 + * @deprecated 13.1 + */ + public static function splitSql($sql) + { + JLog::add('JDatabase::splitSql() is deprecated, use JDatabaseDriver::splitSql() instead.', JLog::NOTICE, 'deprecated'); + + return JDatabaseDriver::splitSql($sql); + } + /** * Return the most recent error message for the database connector. * From 56a39b9e795924f1b29798fabd110189d5e5e84c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 8 Apr 2012 19:26:51 +0200 Subject: [PATCH 74/98] Fix overzealous code style fix in JLanguageStemmerPorteren. --- .../joomla/language/stemmer/porteren.php | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/libraries/joomla/language/stemmer/porteren.php b/libraries/joomla/language/stemmer/porteren.php index 9f1616e3a9..0fbb44f4eb 100644 --- a/libraries/joomla/language/stemmer/porteren.php +++ b/libraries/joomla/language/stemmer/porteren.php @@ -101,7 +101,7 @@ private static function _step1ab($word) } // Part b - if (substr($word, -2, 1) != 'e' || !self::_replace($word, 'eed', 'ee', 0)) + if (substr($word, -2, 1) != 'e' or !self::_replace($word, 'eed', 'ee', 0)) { // First rule $v = self::$_regex_vowel; @@ -112,14 +112,14 @@ private static function _step1ab($word) or preg_match("#$v+#", substr($word, 0, -2)) && self::_replace($word, 'ed', '')) { // If one of above two test successful - if (!self::_replace($word, 'at', 'ate') && !self::_replace($word, 'bl', 'ble') && !self::_replace($word, 'iz', 'ize')) + if (!self::_replace($word, 'at', 'ate') and !self::_replace($word, 'bl', 'ble') and !self::_replace($word, 'iz', 'ize')) { // Double consonant ending - if (self::_doubleConsonant($word) && substr($word, -2) != 'll' && substr($word, -2) != 'ss' && substr($word, -2) != 'zz') + if (self::_doubleConsonant($word) and substr($word, -2) != 'll' and substr($word, -2) != 'ss' and substr($word, -2) != 'zz') { $word = substr($word, 0, -1); } - elseif (self::_m($word) == 1 && self::_cvc($word)) + elseif (self::_m($word) == 1 and self::_cvc($word)) { $word .= 'e'; } @@ -280,7 +280,7 @@ private static function _step4($word) or self::_replace($word, 'ent', '', 1); break; case 'o': - if (substr($word, -4) == 'tion' || substr($word, -4) == 'sion') + if (substr($word, -4) == 'tion' or substr($word, -4) == 'sion') { self::_replace($word, 'ion', '', 1); } @@ -338,7 +338,7 @@ private static function _step5($word) } // Part b - if (self::_m($word) > 1 && self::_doubleConsonant($word) && substr($word, -1) == 'l') + if (self::_m($word) > 1 and self::_doubleConsonant($word) and substr($word, -1) == 'l') { $word = substr($word, 0, -1); } @@ -368,7 +368,7 @@ private static function _replace(&$str, $check, $repl, $m = null) if (substr($str, $len) == $check) { $substr = substr($str, 0, $len); - if (is_null($m) || self::_m($substr) > $m) + if (is_null($m) or self::_m($substr) > $m) { $str = $substr . $repl; } @@ -420,7 +420,7 @@ private static function _doubleConsonant($str) { $c = self::$_regex_consonant; - return preg_match("#$c{2}$#", $str, $matches) && $matches[0]{0} == $matches[0]{1}; + return preg_match("#$c{2}$#", $str, $matches) and $matches[0]{0} == $matches[0]{1}; } /** @@ -438,10 +438,11 @@ private static function _cvc($str) $v = self::$_regex_vowel; $result = preg_match("#($c$v$c)$#", $str, $matches) - && strlen($matches[1]) == 3 - && $matches[1]{2} != 'w' - && $matches[1]{2} != 'x' - && $matches[1]{2} != 'y'; + and strlen($matches[1]) == 3 + and $matches[1]{2} != 'w' + and $matches[1]{2} != 'x' + and $matches[1]{2} != 'y'; + return $result; } } From 8a4bdda0d8fee7586da36f94687f83712eafdba0 Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Mon, 9 Apr 2012 11:42:30 +0530 Subject: [PATCH 75/98] Changed to invalidArgException and indentings Signed-off-by: Buddhima Wijeweera --- libraries/joomla/image/image.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index ad7614b3bb..371f969170 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -654,8 +654,8 @@ protected function getFilterInstance($type) * * @return object * - * @throws LogicException If width,height or both given as zero - * + * @throws InvalidArgumentException If width,height or both given as zero + * * @since 11.3 * @throws InvalidArgumentException */ @@ -675,9 +675,9 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_OUTSIDE: // Both $height or $width cannot be zero - if($width == 0 || $height == 0) + if ($width == 0 || $height == 0) { - throw new LogicException(' Both height or width cannot be zero '); + throw new InvalidArgumentException(' Width or height cannot be zero with this scale method '); } // If both $width and $height are not equals to zero From 41125866e903fd7069faa14bc30eb546d1fada5a Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Tue, 3 Apr 2012 10:44:16 -0700 Subject: [PATCH 76/98] Adding foundational Model, View and Controller packages. --- libraries/joomla/controller/base.php | 137 +++++++++++ libraries/joomla/controller/controller.php | 51 +++++ libraries/joomla/model/base.php | 79 +++++++ libraries/joomla/model/database.php | 82 +++++++ libraries/joomla/model/model.php | 40 ++++ libraries/joomla/view/base.php | 66 ++++++ libraries/joomla/view/html.php | 186 +++++++++++++++ libraries/joomla/view/view.php | 41 ++++ .../joomla/controller/JControllerBaseTest.php | 186 +++++++++++++++ .../unit/joomla/controller/stubs/tbase.php | 31 +++ .../unit/joomla/model/JModelBaseTest.php | 101 +++++++++ .../unit/joomla/model/JModelDatabaseTest.php | 122 ++++++++++ .../suites/unit/joomla/model/stubs/tbase.php | 19 ++ .../unit/joomla/model/stubs/tdatabase.php | 19 ++ .../suites/unit/joomla/view/JViewBaseTest.php | 72 ++++++ .../suites/unit/joomla/view/JViewHtmlTest.php | 214 ++++++++++++++++++ .../joomla/view/layouts1/fringe/division.php | 1 + .../unit/joomla/view/layouts1/olivia.php | 1 + .../unit/joomla/view/layouts1/peter.php | 1 + .../unit/joomla/view/layouts2/fauxlivia.php | 1 + .../unit/joomla/view/layouts2/olivia.php | 1 + .../joomla/view/mocks/JControllerMock.php | 53 +++++ .../unit/joomla/view/mocks/JModelMock.php | 48 ++++ tests/suites/unit/joomla/view/stubs/tbase.php | 30 +++ tests/suites/unit/joomla/view/stubs/thtml.php | 19 ++ 25 files changed, 1601 insertions(+) create mode 100644 libraries/joomla/controller/base.php create mode 100644 libraries/joomla/controller/controller.php create mode 100644 libraries/joomla/model/base.php create mode 100644 libraries/joomla/model/database.php create mode 100644 libraries/joomla/model/model.php create mode 100644 libraries/joomla/view/base.php create mode 100644 libraries/joomla/view/html.php create mode 100644 libraries/joomla/view/view.php create mode 100644 tests/suites/unit/joomla/controller/JControllerBaseTest.php create mode 100644 tests/suites/unit/joomla/controller/stubs/tbase.php create mode 100644 tests/suites/unit/joomla/model/JModelBaseTest.php create mode 100644 tests/suites/unit/joomla/model/JModelDatabaseTest.php create mode 100644 tests/suites/unit/joomla/model/stubs/tbase.php create mode 100644 tests/suites/unit/joomla/model/stubs/tdatabase.php create mode 100644 tests/suites/unit/joomla/view/JViewBaseTest.php create mode 100644 tests/suites/unit/joomla/view/JViewHtmlTest.php create mode 100644 tests/suites/unit/joomla/view/layouts1/fringe/division.php create mode 100644 tests/suites/unit/joomla/view/layouts1/olivia.php create mode 100644 tests/suites/unit/joomla/view/layouts1/peter.php create mode 100644 tests/suites/unit/joomla/view/layouts2/fauxlivia.php create mode 100644 tests/suites/unit/joomla/view/layouts2/olivia.php create mode 100644 tests/suites/unit/joomla/view/mocks/JControllerMock.php create mode 100644 tests/suites/unit/joomla/view/mocks/JModelMock.php create mode 100644 tests/suites/unit/joomla/view/stubs/tbase.php create mode 100644 tests/suites/unit/joomla/view/stubs/thtml.php diff --git a/libraries/joomla/controller/base.php b/libraries/joomla/controller/base.php new file mode 100644 index 0000000000..7b591d6c20 --- /dev/null +++ b/libraries/joomla/controller/base.php @@ -0,0 +1,137 @@ +app = isset($app) ? $app : $this->loadApplication(); + $this->input = isset($input) ? $input : $this->loadInput(); + } + + /** + * Get the application object. + * + * @return JApplicationBase The application object. + * + * @since 12.1 + */ + public function getApplication() + { + return $this->app; + } + + /** + * Get the input object. + * + * @return JInput The input object. + * + * @since 12.1 + */ + public function getInput() + { + return $this->input; + } + + /** + * Serialize the controller. + * + * @return string The serialized controller. + * + * @since 12.1 + */ + public function serialize() + { + return serialize($this->input); + } + + /** + * Unserialize the controller. + * + * @param string $input The serialized controller. + * + * @return JController Supports chaining. + * + * @since 12.1 + * @throws UnexpectedValueException if input is not the right class. + */ + public function unserialize($input) + { + // Setup dependencies. + $this->app = $this->loadApplication(); + + // Unserialize the input. + $this->input = unserialize($input); + + if (!($this->input instanceof JInput)) + { + throw new UnexpectedValueException(sprintf('%s::unserialize would not accept a `%s`.', get_class($this), gettype($this->input))); + } + + return $this; + } + + /** + * Load the application object. + * + * @return JApplicationBase The application object. + * + * @since 12.1 + */ + protected function loadApplication() + { + return JFactory::getApplication(); + } + + /** + * Load the input object. + * + * @return JInput The input object. + * + * @since 12.1 + */ + protected function loadInput() + { + return $this->app->input; + } +} diff --git a/libraries/joomla/controller/controller.php b/libraries/joomla/controller/controller.php new file mode 100644 index 0000000000..f5bae240bf --- /dev/null +++ b/libraries/joomla/controller/controller.php @@ -0,0 +1,51 @@ +state = isset($state) ? $state : $this->loadState(); + } + + /** + * Get the model state. + * + * @return JRegistry The state object. + * + * @since 12.1 + */ + public function getState() + { + return $this->state; + } + + /** + * Set the model state. + * + * @param JRegistry $state The state object. + * + * @return void + * + * @since 12.1 + */ + public function setState(JRegistry $state) + { + $this->state = $state; + } + + /** + * Load the model state. + * + * @return JRegistry The state object. + * + * @since 12.1 + */ + protected function loadState() + { + return new JRegistry; + } +} diff --git a/libraries/joomla/model/database.php b/libraries/joomla/model/database.php new file mode 100644 index 0000000000..356f2235e6 --- /dev/null +++ b/libraries/joomla/model/database.php @@ -0,0 +1,82 @@ +db = isset($db) ? $db : $this->loadDb(); + } + + /** + * Get the database driver. + * + * @return JDatabaseDriver The database driver. + * + * @since 12.1 + */ + public function getDb() + { + return $this->db; + } + + /** + * Set the database driver. + * + * @param JDatabaseDriver $db The database driver. + * + * @return void + * + * @since 12.1 + */ + public function setDb(JDatabaseDriver $db) + { + $this->db = $db; + } + + /** + * Load the database driver. + * + * @return JDatabaseDriver The database driver. + * + * @since 12.1 + */ + protected function loadDb() + { + return JFactory::getDbo(); + } +} diff --git a/libraries/joomla/model/model.php b/libraries/joomla/model/model.php new file mode 100644 index 0000000000..6f96ed1c8b --- /dev/null +++ b/libraries/joomla/model/model.php @@ -0,0 +1,40 @@ +model = $model; + $this->controller = $controller; + } + + /** + * Method to escape output. + * + * @param string $output The output to escape. + * + * @return string The escaped output. + * + * @see JView::escape() + * @since 12.1 + */ + public function escape($output) + { + return $output; + } +} diff --git a/libraries/joomla/view/html.php b/libraries/joomla/view/html.php new file mode 100644 index 0000000000..332f5b4a8f --- /dev/null +++ b/libraries/joomla/view/html.php @@ -0,0 +1,186 @@ +paths = isset($paths) ? $paths : $this->loadPaths(); + } + + /** + * Method to escape output. + * + * @param string $output The output to escape. + * + * @return string The escaped output. + * + * @see JView::escape() + * @since 12.1 + */ + public function escape($output) + { + // Escape the output. + return htmlspecialchars($output, ENT_COMPAT, 'UTF-8'); + } + + /** + * Method to get the view layout. + * + * @return string The layout name. + * + * @since 12.1 + */ + public function getLayout() + { + return $this->layout; + } + + /** + * Method to get the layout path. + * + * @param string $layout The layout name. + * + * @return mixed The layout file name if found, false otherwise. + * + * @since 12.1 + */ + public function getPath($layout) + { + // Get the layout file name. + $file = JPath::clean($layout . '.php'); + + // Find the layout file path. + $path = JPath::find(clone($this->paths), $file); + + return $path; + } + + /** + * Method to get the view paths. + * + * @return SplPriorityQueue The paths queue. + * + * @since 12.1 + */ + public function getPaths() + { + return $this->paths; + } + + /** + * Method to render the view. + * + * @return string The rendered view. + * + * @since 12.1 + * @throws RuntimeException + */ + public function render() + { + // Get the layout path. + $path = $this->getPath($this->getLayout()); + + // Check if the layout path was found. + if (!$path) + { + throw new RuntimeException('Layout Path Not Found'); + } + + // Start an output buffer. + ob_start(); + + // Load the layout. + include $path; + + // Get the layout contents. + $output = ob_get_clean(); + + return $output; + } + + /** + * Method to set the view layout. + * + * @param string $layout The layout name. + * + * @return void + * + * @since 12.1 + */ + public function setLayout($layout) + { + $this->layout = $layout; + } + + /** + * Method to set the view paths. + * + * @param SplPriorityQueue $paths The paths queue. + * + * @return void + * + * @since 12.1 + */ + public function setPaths(SplPriorityQueue $paths) + { + $this->paths = $paths; + } + + /** + * Method to load the paths queue. + * + * @return SplPriorityQueue The paths queue. + * + * @since 12.1 + */ + protected function loadPaths() + { + return new SplPriorityQueue; + } +} diff --git a/libraries/joomla/view/view.php b/libraries/joomla/view/view.php new file mode 100644 index 0000000000..8b6d78e1c1 --- /dev/null +++ b/libraries/joomla/view/view.php @@ -0,0 +1,41 @@ +assertEquals('default', TestReflection::getValue($this->_instance, 'app')->input, 'Checks the mock application came from the factory.'); + $this->assertAttributeEquals('default', 'input', $this->_instance, 'Checks the input came from the application.'); + + // New controller with dependancies + $app = TestMockApplicationWeb::create($this); + $app->test = 'ok'; + + $class = new BaseController(new JInputCookie, $app); + $this->assertAttributeInstanceOf('JInputCookie', 'input', $class, 'Checks the type of the injected input.'); + $this->assertAttributeSame($app, 'app', $class, 'Checks the injected application.'); + } + + /** + * Tests the getApplication method. + * + * @return void + * + * @covers JControllerBase::getApplication + * @since 12.1 + */ + public function testGetApplication() + { + TestReflection::setValue($this->_instance, 'app', 'application'); + $this->assertEquals('application', $this->_instance->getApplication()); + } + + /** + * Tests the getInput method. + * + * @return void + * + * @covers JControllerBase::getInput + * @since 12.1 + */ + public function testGetInput() + { + TestReflection::setValue($this->_instance, 'input', 'input'); + $this->assertEquals('input', $this->_instance->getInput()); + } + + /** + * Tests the serialize method. + * + * @return void + * + * @covers JControllerBase::serialize + * @since 12.1 + */ + public function testSerialise() + { + $this->assertEquals('s:7:"default";', $this->_instance->serialize()); + } + + /** + * Tests the unserialize method. + * + * @return void + * + * @covers JControllerBase::unserialize + * @since 12.1 + */ + public function testUnserialise() + { + $input = serialize(new JInput); + + $this->assertSame($this->_instance, $this->_instance->unserialize($input), 'Checks chaining and target method.'); + $this->assertInstanceOf('JInput', $this->_instance->getInput()); + } + + /** + * Tests the unserialize method for an expected exception. + * + * @return void + * + * @covers JControllerBase::unserialize + * @since 12.1 + * + * @expectedException UnexpectedValueException + */ + public function testUnserialise_exception() + { + $this->_instance->unserialize('s:7:"default";'); + } + + /** + * Tests the loadApplication method. + * + * @return void + * + * @covers JControllerBase::loadApplication + * @since 12.1 + */ + public function testLoadApplication() + { + JFactory::$application = 'application'; + $this->assertEquals('application', TestReflection::invoke($this->_instance, 'loadApplication')); + } + + /** + * Tests the loadInput method. + * + * @return void + * + * @covers JControllerBase::loadInput + * @since 12.1 + */ + public function testLoadInput() + { + // Reset the input property so we know it changes based on the mock application. + TestReflection::setValue($this->_instance, 'input', null); + + $this->assertEquals('default', TestReflection::invoke($this->_instance, 'loadInput')); + } + + /** + * Setup the tests. + * + * @return void + * + * @since 12.1 + */ + protected function setUp() + { + parent::setUp(); + + $this->saveFactoryState(); + + $app = TestMockApplicationWeb::create($this); + $app->input = 'default'; + + JFactory::$application = $app; + + $this->_instance = new BaseController; + } + + /** + * Method to tear down whatever was set up before the test. + * + * @return void + * + * @since 12.1 + */ + protected function tearDown() + { + $this->restoreFactoryState(); + + parent::teardown(); + } +} diff --git a/tests/suites/unit/joomla/controller/stubs/tbase.php b/tests/suites/unit/joomla/controller/stubs/tbase.php new file mode 100644 index 0000000000..c322326bcd --- /dev/null +++ b/tests/suites/unit/joomla/controller/stubs/tbase.php @@ -0,0 +1,31 @@ +assertEquals(new JRegistry, $this->_instance->getState(), 'Checks default state.'); + + $state = new JRegistry(array('foo' => 'bar')); + $class = new BaseModel($state); + $this->assertEquals($state, $class->getState(), 'Checks state injection.'); + } + + /** + * Tests the getState method. + * + * @return void + * + * @covers JModelBase::getState + * @since 12.1 + */ + public function testGetState() + { + // Reset the state property to a known value. + TestReflection::setValue($this->_instance, 'state', 'foo'); + + $this->assertEquals('foo', $this->_instance->getState()); + } + + /** + * Tests the setState method. + * + * @return void + * + * @covers JModelBase::setState + * @since 12.1 + */ + public function testSetState() + { + $state = new JRegistry(array('foo' => 'bar')); + $this->_instance->setState($state); + $this->assertSame($state, $this->_instance->getState()); + } + + /** + * Tests the loadState method. + * + * @return void + * + * @covers JModelBase::loadState + * @since 12.1 + */ + public function testLoadState() + { + $this->assertInstanceOf('JRegistry', TestReflection::invoke($this->_instance, 'loadState')); + } + + /** + * Setup the tests. + * + * @return void + * + * @since 12.1 + */ + protected function setUp() + { + parent::setUp(); + + $this->_instance = new BaseModel; + } +} diff --git a/tests/suites/unit/joomla/model/JModelDatabaseTest.php b/tests/suites/unit/joomla/model/JModelDatabaseTest.php new file mode 100644 index 0000000000..f5bfb6ccd8 --- /dev/null +++ b/tests/suites/unit/joomla/model/JModelDatabaseTest.php @@ -0,0 +1,122 @@ +assertSame(JFactory::getDbo(), $this->_instance->getDb(), 'Checks default database driver.'); + + // Create a new datbase mock for injection. + $db = TestMockDatabaseDriver::create($this); + $class = new DatabaseModel(null, $db); + $this->assertSame($db, $class->getDb(), 'Checks injected database driver.'); + } + + /** + * Tests the getDb method. + * + * @return void + * + * @covers JModelDatabase::getDb + * @since 12.1 + */ + public function testGetDb() + { + // Reset the db property to a known value. + TestReflection::setValue($this->_instance, 'db', 'foo'); + + $this->assertEquals('foo', $this->_instance->getDb()); + } + + /** + * Tests the setDb method. + * + * @return void + * + * @covers JModelDatabase::setDb + * @since 12.1 + */ + public function testSetDb() + { + $db = TestMockDatabaseDriver::create($this); + $this->_instance->setDb($db); + + $this->assertAttributeSame($db, 'db', $this->_instance); + } + + /** + * Tests the loadDb method. + * + * @return void + * + * @covers JModelDatabase::loadDb + * @since 12.1 + */ + public function testLoadDb() + { + JFactory::$database = 'database'; + $this->assertEquals('database', TestReflection::invoke($this->_instance, 'loadDb')); + } + + /** + * Setup the tests. + * + * @return void + * + * @since 12.1 + */ + protected function setUp() + { + parent::setUp(); + + $this->saveFactoryState(); + + JFactory::$database = TestMockDatabaseDriver::create($this); + + $this->_instance = new DatabaseModel; + } + + /** + * Method to tear down whatever was set up before the test. + * + * @return void + * + * @since 12.1 + */ + protected function tearDown() + { + $this->restoreFactoryState(); + + parent::teardown(); + } +} diff --git a/tests/suites/unit/joomla/model/stubs/tbase.php b/tests/suites/unit/joomla/model/stubs/tbase.php new file mode 100644 index 0000000000..b9f2c752f4 --- /dev/null +++ b/tests/suites/unit/joomla/model/stubs/tbase.php @@ -0,0 +1,19 @@ +assertAttributeInstanceOf('JModel', 'model', $this->_instance); + $this->assertAttributeInstanceOf('JController', 'controller', $this->_instance); + } + + /** + * Tests the escape method. + * + * @return void + * + * @covers JViewBase::escape + * @since 12.1 + */ + public function testEscape() + { + $this->assertEquals('foo', $this->_instance->escape('foo')); + } + + /** + * Setup the tests. + * + * @return void + * + * @since 12.1 + */ + protected function setUp() + { + parent::setUp(); + + $model = JModelMock::create($this); + $controller = JControllerMock::create($this); + + $this->_instance = new BaseView($model, $controller); + } +} diff --git a/tests/suites/unit/joomla/view/JViewHtmlTest.php b/tests/suites/unit/joomla/view/JViewHtmlTest.php new file mode 100644 index 0000000000..ea3ef9df0c --- /dev/null +++ b/tests/suites/unit/joomla/view/JViewHtmlTest.php @@ -0,0 +1,214 @@ +assertAttributeEquals(new SplPriorityQueue, 'paths', $this->_instance, 'Check default paths.'); + + $model = JModelMock::create($this); + $controller = JControllerMock::create($this); + $paths = new SplPriorityQueue; + $paths->insert('foo', 1); + + $this->_instance = new HtmlView($model, $controller, $paths); + $this->assertAttributeSame($paths, 'paths', $this->_instance, 'Check default paths.'); + } + + /** + * Tests the escape method. + * + * @return void + * + * @covers JViewHtml::escape + * @since 12.1 + */ + public function testEscape() + { + $this->assertEquals('"', $this->_instance->escape('"')); + } + + /** + * Tests the getLayout method. + * + * @return void + * + * @covers JViewHtml::getLayout + * @since 12.1 + */ + public function testGetLayout() + { + TestReflection::setValue($this->_instance, 'layout', 'foo'); + + $this->assertEquals('foo', $this->_instance->getLayout()); + } + + /** + * Tests the getPath method. + * + * @return void + * + * @covers JViewHtml::getPath + * @since 12.1 + */ + public function testGetPath() + { + // Set up a priority queue. + $paths = $this->_instance->getPaths(); + $paths->insert(__DIR__ . '/layouts1', 1); + $paths->insert(__DIR__ . '/layouts2', 2); + + $this->assertEquals(__DIR__ . '/layouts2/olivia.php', $this->_instance->getPath('olivia')); + $this->assertEquals(__DIR__ . '/layouts1/peter.php', $this->_instance->getPath('peter')); + $this->assertEquals(__DIR__ . '/layouts2/fauxlivia.php', $this->_instance->getPath('fauxlivia')); + $this->assertEquals(__DIR__ . '/layouts1/fringe/division.php', $this->_instance->getPath('fringe/division')); + $this->assertFalse($this->_instance->getPath('walter')); + + // Check dirty path. + $this->assertEquals(__DIR__ . '/layouts1/fringe/division.php', $this->_instance->getPath('fringe//\\division')); + } + + /** + * Tests the getPaths method. + * + * @return void + * + * @covers JViewHtml::getPaths + * @since 12.1 + */ + public function testGetPaths() + { + // Inject a known value into the property. + TestReflection::setValue($this->_instance, 'paths', 'paths'); + + // Check dirty path. + $this->assertEquals('paths', $this->_instance->getPaths()); + } + + /** + * Tests the render method. + * + * @return void + * + * @covers JViewHtml::render + * @since 12.1 + */ + public function testRender() + { + // Set up a priority queue. + $paths = $this->_instance->getPaths(); + $paths->insert(__DIR__ . '/layouts1', 1); + $paths->insert(__DIR__ . '/layouts2', 2); + + $this->_instance->setLayout('olivia'); + $this->assertEquals('Peter\'s Olivia', $this->_instance->render()); + } + + /** + * Tests the render method. + * + * @return void + * + * @covers JViewHtml::render + * @since 12.1 + * + * @expectedException RuntimeException + */ + public function testRender_exception() + { + $this->_instance->render(); + } + + /** + * Tests the setLayout method. + * + * @return void + * + * @covers JViewHtml::setLayout + * @since 12.1 + */ + public function testSetLayout() + { + $this->_instance->setLayout('fringe/division'); + $this->assertAttributeSame('fringe/division', 'layout', $this->_instance); + } + + /** + * Tests the setPaths method. + * + * @return void + * + * @covers JViewHtml::setPaths + * @since 12.1 + */ + public function testSetPaths() + { + $paths = new SplPriorityQueue; + $paths->insert('bar', 99); + + $this->_instance->setPaths($paths); + $this->assertAttributeSame($paths, 'paths', $this->_instance); + } + + /** + * Tests the loadPaths method. + * + * @return void + * + * @covers JViewHtml::loadPaths + * @since 12.1 + */ + public function testLoadPaths() + { + $this->assertEquals(new SplPriorityQueue, TestReflection::invoke($this->_instance, 'loadPaths')); + } + + /** + * Setup the tests. + * + * @return void + * + * @since 12.1 + */ + protected function setUp() + { + parent::setUp(); + + $model = JModelMock::create($this); + $controller = JControllerMock::create($this); + + $this->_instance = new HtmlView($model, $controller); + } +} diff --git a/tests/suites/unit/joomla/view/layouts1/fringe/division.php b/tests/suites/unit/joomla/view/layouts1/fringe/division.php new file mode 100644 index 0000000000..ea2d009645 --- /dev/null +++ b/tests/suites/unit/joomla/view/layouts1/fringe/division.php @@ -0,0 +1 @@ +Fringe Division \ No newline at end of file diff --git a/tests/suites/unit/joomla/view/layouts1/olivia.php b/tests/suites/unit/joomla/view/layouts1/olivia.php new file mode 100644 index 0000000000..f62735b961 --- /dev/null +++ b/tests/suites/unit/joomla/view/layouts1/olivia.php @@ -0,0 +1 @@ +Olivia Dunham \ No newline at end of file diff --git a/tests/suites/unit/joomla/view/layouts1/peter.php b/tests/suites/unit/joomla/view/layouts1/peter.php new file mode 100644 index 0000000000..c30ca5a8fd --- /dev/null +++ b/tests/suites/unit/joomla/view/layouts1/peter.php @@ -0,0 +1 @@ +Peter Bishop \ No newline at end of file diff --git a/tests/suites/unit/joomla/view/layouts2/fauxlivia.php b/tests/suites/unit/joomla/view/layouts2/fauxlivia.php new file mode 100644 index 0000000000..05924df4bd --- /dev/null +++ b/tests/suites/unit/joomla/view/layouts2/fauxlivia.php @@ -0,0 +1 @@ +Olivia Dunham (red hair) \ No newline at end of file diff --git a/tests/suites/unit/joomla/view/layouts2/olivia.php b/tests/suites/unit/joomla/view/layouts2/olivia.php new file mode 100644 index 0000000000..3ecdb2f9bf --- /dev/null +++ b/tests/suites/unit/joomla/view/layouts2/olivia.php @@ -0,0 +1 @@ +Peter's Olivia \ No newline at end of file diff --git a/tests/suites/unit/joomla/view/mocks/JControllerMock.php b/tests/suites/unit/joomla/view/mocks/JControllerMock.php new file mode 100644 index 0000000000..ea6ab8f739 --- /dev/null +++ b/tests/suites/unit/joomla/view/mocks/JControllerMock.php @@ -0,0 +1,53 @@ +getMock( + 'JControllerBase', + $methods, + // Constructor arguments. + array(), + // Mock class name. + '', + // Call original constructor. + false + ); + + // TODO Mock the input. + TestReflection::setValue($mockObject, 'input', new JInput); + + return $mockObject; + } +} diff --git a/tests/suites/unit/joomla/view/mocks/JModelMock.php b/tests/suites/unit/joomla/view/mocks/JModelMock.php new file mode 100644 index 0000000000..afc5fd741a --- /dev/null +++ b/tests/suites/unit/joomla/view/mocks/JModelMock.php @@ -0,0 +1,48 @@ +getMock( + 'JModel', + $methods, + // Constructor arguments. + array(), + // Mock class name. + '', + // Call original constructor. + false + ); + + return $mockObject; + } +} diff --git a/tests/suites/unit/joomla/view/stubs/tbase.php b/tests/suites/unit/joomla/view/stubs/tbase.php new file mode 100644 index 0000000000..fbf5ca6dd3 --- /dev/null +++ b/tests/suites/unit/joomla/view/stubs/tbase.php @@ -0,0 +1,30 @@ + Date: Tue, 3 Apr 2012 10:49:53 -0700 Subject: [PATCH 77/98] Adding manual documentation for the new Model, View and Controller packages. --- .../chapters/classes/jcontrollerbase.xml | 69 +++++++++++++++ .../en-US/chapters/classes/jmodelbase.xml | 51 ++++++++++++ .../en-US/chapters/classes/jmodeldatabase.xml | 73 ++++++++++++++++ .../en-US/chapters/classes/jviewbase.xml | 75 +++++++++++++++++ .../en-US/chapters/classes/jviewhtml.xml | 83 +++++++++++++++++++ .../en-US/chapters/interfaces/jcontroller.xml | 13 +++ .../en-US/chapters/interfaces/jmodel.xml | 12 +++ .../en-US/chapters/interfaces/jview.xml | 12 +++ docs/manual/en-US/chapters/packages.xml | 2 + docs/manual/en-US/chapters/packages/mvc.xml | 57 +++++++++++++ 10 files changed, 447 insertions(+) create mode 100644 docs/manual/en-US/chapters/classes/jcontrollerbase.xml create mode 100644 docs/manual/en-US/chapters/classes/jmodelbase.xml create mode 100644 docs/manual/en-US/chapters/classes/jmodeldatabase.xml create mode 100644 docs/manual/en-US/chapters/classes/jviewbase.xml create mode 100644 docs/manual/en-US/chapters/classes/jviewhtml.xml create mode 100644 docs/manual/en-US/chapters/interfaces/jcontroller.xml create mode 100644 docs/manual/en-US/chapters/interfaces/jmodel.xml create mode 100644 docs/manual/en-US/chapters/interfaces/jview.xml create mode 100644 docs/manual/en-US/chapters/packages/mvc.xml diff --git a/docs/manual/en-US/chapters/classes/jcontrollerbase.xml b/docs/manual/en-US/chapters/classes/jcontrollerbase.xml new file mode 100644 index 0000000000..778f8d01cc --- /dev/null +++ b/docs/manual/en-US/chapters/classes/jcontrollerbase.xml @@ -0,0 +1,69 @@ + + +%BOOK_ENTITIES; +]> +
    + JControllerBase + +
    + Construction + + The constructor for JControllerBase takes an optional JInput object and an + optional JApplciationBase object. If either is omitted, the constructor defers to the protected + loadInput and loadApplication methods respectively. These methods can be overriden in derived classes if the default + application and request input is not appropriate. +
    + +
    + Usage + + The JControllerBase class is abstract so cannot be used directly. The derived class must + implement the execute method to satisfy the interface requirements. Note that the execute method no longer takes a "task" + argument as each controller class. Multi-task controllers are still possible but not recommended. Each controller class should + do just one sort of 'thing', just as saving, deleting, checking in, checking out and so on. However, controllers, or even + models and views, have the liberty of invoking other controllers to allow for HMVC architectures. + + + Example controller + + /** + * My custom controller. + * + * @package Examples + * + * @since 12.1 + */ +class MyController extends JControllerBase +{ + /** + * Method to execute the controller. + * + * @return void + * + * @since 12.1 + * @throws RuntimeException + */ + public function execute() + { + echo time(); + } +} + +// Instantiate the controller. +$controller = new MyController; + +// Print the time. +$controller->execute(); + +
    + +
    + Serialization + + The JControllerBase class implements Serializable. When + serializing, only the input property is serialized. When unserializing, the input variable is unserialized and the internal + application property is loaded at runtime. +
    +
    diff --git a/docs/manual/en-US/chapters/classes/jmodelbase.xml b/docs/manual/en-US/chapters/classes/jmodelbase.xml new file mode 100644 index 0000000000..2934dfc4c6 --- /dev/null +++ b/docs/manual/en-US/chapters/classes/jmodelbase.xml @@ -0,0 +1,51 @@ + + +%BOOK_ENTITIES; +]> +
    + JModelBase + +
    + Construction + + The contructor for JModelBase takes an optional JRegistry object that + defines the state of the model. If omitted, the contructor defers to the protected loadState method. + This method can be overriden in a derived class and takes the place of the populateState method used + in the legacy model class. +
    + +
    + Usage + + The JModelBase class is abstract so cannot be used directly. All requirements of the interface + are already satisfied by the base class. + + + Example model + + /** + * My custom model. + * + * @pacakge Examples + * + * @since 12.1 + */ +class MyModel extends JModelBase +{ + /** + * Get the time. + * + * @return integer + * + * @since 12.1 + */ + public function getTime() + { + return time(); + } +} + +
    +
    diff --git a/docs/manual/en-US/chapters/classes/jmodeldatabase.xml b/docs/manual/en-US/chapters/classes/jmodeldatabase.xml new file mode 100644 index 0000000000..b9e53f3ef1 --- /dev/null +++ b/docs/manual/en-US/chapters/classes/jmodeldatabase.xml @@ -0,0 +1,73 @@ + + +%BOOK_ENTITIES; +]> +
    + JModelDatabase + +
    + Construction + + JModelDatabase is extended from JModelBase and the contructor takes an + optional JDatabaseDriver object and an optional JRegistry object (the same one + that JModelBase uses). If the database object is omitted, the contructor defers to the protected + loadDb method which loads the database object from the platform factory. +
    + +
    + Usage + + The JModelDatabase class is abstract so cannot be used directly. It forms a base for any model + that needs to interact with a database. + + + Example database model + + /** + * My custom database model. + * + * @package Examples + * + * @since 12.1 + */ +class MyDatabaseModel extends JModelDatabase +{ + /** + * Get the content count. + * + * @return integer + * + * @since 12.1 + * @throws RuntimeException on database error. + */ + public function getCount() + { + // Get the query builder from the internal database object. + $q = $this->db->getQuery(true); + + // Prepare the query to count the number of content records. + $q->select('COUNT(*)') + ->from($q->qn('#__content')); + + $this->db->setQuery($q); + + // Execute and return the result. + return $this->db->loadResult(); + } +} + +try +{ + $model = new MyDatabaseModel; + $count = $model->getCount(); +} +catch (RuntimeException $e) +{ + // Handle database error. +} + + +
    +
    diff --git a/docs/manual/en-US/chapters/classes/jviewbase.xml b/docs/manual/en-US/chapters/classes/jviewbase.xml new file mode 100644 index 0000000000..aba396eba3 --- /dev/null +++ b/docs/manual/en-US/chapters/classes/jviewbase.xml @@ -0,0 +1,75 @@ + + +%BOOK_ENTITIES; +]> +
    + JViewBase + +
    + Construction + + The contructor for JViewBase takes a JModel object and a + JController object. Both are mandatory. + + Note that these are interfaces so the objects do no necessarily have to extend from JModelBase or + JControllerBase classes. Given that, the view should only rely on the API that is exposed by the + interface and not concrete classes unless the contructor is changed in a derived class to take more explicit classes or + interaces as required by the developer. +
    + +
    + Usage + + The JViewBase class is abstract so cannot be used directly. It forms a simple base for rendering + any kind of data. The class already implements the escape method so only a + render method need to be added. Views derived from this class would be used to support very simple + cases, well suited to supporting web services returning JSON, XML or possibly binary data types. This class does not support + layouts. + + + Example view + + /** + * My custom view. + * + * @package Examples + * + * @since 12.1 + */ +class MyView extends JViewBase +{ + /** + * Render some data + * + * @return string The rendered view. + * + * @since 12.1 + * @throws RuntimeException on database error. + */ + public function render() + { + // Prepare some data from the model. + $data = array( + 'count' => $this->model->getCount() + ); + + // Convert the data to JSON format. + return json_encode($data); + } +} + +try +{ + $view = new MyView(new MyDatabaseModel, new MyController); + echo $view->render(); +} +catch (RuntimeException $e) +{ + // Handle database error. +} + + +
    +
    diff --git a/docs/manual/en-US/chapters/classes/jviewhtml.xml b/docs/manual/en-US/chapters/classes/jviewhtml.xml new file mode 100644 index 0000000000..a9a50ab167 --- /dev/null +++ b/docs/manual/en-US/chapters/classes/jviewhtml.xml @@ -0,0 +1,83 @@ + + +%BOOK_ENTITIES; +]> +
    + JViewHtml + +
    + Construction + + JViewHtml is extended from JViewBase. The constructor, in addition to the + model and controller arguments, take an optional SplPriorityQueue object that serves as a lookup for + layouts. If omitted, the view defers to the protected loadPaths method. +
    + +
    + Usage + + The JViewHtml class is abstract so cannot be used directly. This view class implements render. It + will try to find the layout, include it using output buffering and return the result. The following examples show a layout + file that is assumed to be stored in a generic layout folder not stored under the web-server root. + + + Example HTML layout + + <?php +/** + * Example layout "layouts/count.php". + * + * @package Examples + * @since 12.1 + */ + +// Declare variables to support type hinting. + +/** @var $this MyHtmlView */ +?> + +<dl> + <dt>Count</dt> + <dd><?php echo $this->model->getCount(); ?></dd> +</dl> + + + + Example HTML view + + /** + * My custom HTML view. + * + * @package Examples + * @since 12.1 + */ +class MyHtmlView extends JViewHtml +{ + /** + * Redefine the model so the correct type hinting is available in the layout. + * + * @var MyDatabaseModel + * @since 12.1 + */ + protected $model; +} + +try +{ + $paths = new SplPriorityQueue; + $paths->insert(__DIR__ . '/layouts'); + + $view = new MyView(new MyDatabaseModel, new MyController, $paths); + $view->setLayout('count'); + echo $view->render(); +} +catch (RuntimeException $e) +{ + // Handle database error. +} + + +
    +
    diff --git a/docs/manual/en-US/chapters/interfaces/jcontroller.xml b/docs/manual/en-US/chapters/interfaces/jcontroller.xml new file mode 100644 index 0000000000..22af74e95f --- /dev/null +++ b/docs/manual/en-US/chapters/interfaces/jcontroller.xml @@ -0,0 +1,13 @@ + + +%BOOK_ENTITIES; +]> +
    + JController + + JController is an interface that requires a class to be implemented with an + execute, a getApplication and a getInput + method. +
    diff --git a/docs/manual/en-US/chapters/interfaces/jmodel.xml b/docs/manual/en-US/chapters/interfaces/jmodel.xml new file mode 100644 index 0000000000..b38894034a --- /dev/null +++ b/docs/manual/en-US/chapters/interfaces/jmodel.xml @@ -0,0 +1,12 @@ + + +%BOOK_ENTITIES; +]> +
    + JModel + + JModel is an interface that requires a class to be implemented with a + getState and a setState method. +
    diff --git a/docs/manual/en-US/chapters/interfaces/jview.xml b/docs/manual/en-US/chapters/interfaces/jview.xml new file mode 100644 index 0000000000..c5fc678d9b --- /dev/null +++ b/docs/manual/en-US/chapters/interfaces/jview.xml @@ -0,0 +1,12 @@ + + +%BOOK_ENTITIES; +]> +
    + JView + + JView is an interface that requires a class to be implemented with an + escape and a render method. +
    diff --git a/docs/manual/en-US/chapters/packages.xml b/docs/manual/en-US/chapters/packages.xml index f5563c5b65..49cf8d1e0c 100644 --- a/docs/manual/en-US/chapters/packages.xml +++ b/docs/manual/en-US/chapters/packages.xml @@ -16,5 +16,7 @@ + + diff --git a/docs/manual/en-US/chapters/packages/mvc.xml b/docs/manual/en-US/chapters/packages/mvc.xml new file mode 100644 index 0000000000..caf157869f --- /dev/null +++ b/docs/manual/en-US/chapters/packages/mvc.xml @@ -0,0 +1,57 @@ + + +%BOOK_ENTITIES; +]> +
    + The Model-View-Controller Packages + +
    + Introduction + + Version 12.1 of the platform introduced a new format for model-view-controller paradigm. Principly, the classes + JModel, JView and JController are now interfaces and the + base abstract classes are now JModelBase, JViewBase and + JControllerBase respectively. In additional, all classes have been simplified removing a lot of + coupling with the Joomla CMS that is unnecessary for standalone Joomla Platform applications. + + All the API for controllers, models and views has moved from the Application package into separate Controller, Model and + View packages respectively. Much of the API previously devoted to adding include paths for each of the classes has been + removed because of improvements in the auto-loader or by registering or discovering classes explicitly using + JLoader. + + Controllers only support one executable task per class via the execute method. This differs from the legacy + JController class which mapped tasks to methods in a single class. Messages and redirection are not + always required so have been dropped in this base class. They can be provided in a downstream class to suit individual + applications. Likewise, methods to create models and views have been dropped in favor of using application or package factory + classes. + + Models have been greatly simplified in comparison to their legacy counterpart. The base model is nothing more than a + class to hold state. All database support methods have been dropped except for database object support in + JModelDatabase. Extended model classes such as JModelAdmin, + JModelForm, JModelItem and JModelList are part of the + legacy platform. Most of their function has been replaced by API availble in the Content package also new in 12.1. + + Views have also been greatly simplified. Views are now injected with a single model and a controller. Magic get methods + have been dropped in favor of using the model directly. Similarly, assignment methods have also been dropped in favor of + setting class properties explicitly. The JViewHtml class still implements layout support albeit in a + simplified manner. +
    + + + + + + + + + + + + + + + + +
    From 8be13ea71f65ba719446114d38eb609845e23269 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 10 Apr 2012 15:57:31 +0200 Subject: [PATCH 78/98] Fix failing unit tests in JView. --- libraries/legacy/view/view.php | 6 +++--- tests/suites/legacy/view/JViewTest.php | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/legacy/view/view.php b/libraries/legacy/view/view.php index cf857ba2fe..edc73a7026 100644 --- a/libraries/legacy/view/view.php +++ b/libraries/legacy/view/view.php @@ -446,7 +446,7 @@ public function getLayoutTemplate() */ public function getName() { - if (empty($this->name)) + if (empty($this->_name)) { $r = null; if (!preg_match('/View((view)*(.*(view)?.*))$/i', get_class($this), $r)) @@ -457,10 +457,10 @@ public function getName() { JLog::add(JText::_('JLIB_APPLICATION_ERROR_VIEW_GET_NAME_SUBSTRING'), JLog::WARNING, 'jerror'); } - $this->name = strtolower($r[3]); + $this->_name = strtolower($r[3]); } - return $this->name; + return $this->_name; } /** diff --git a/tests/suites/legacy/view/JViewTest.php b/tests/suites/legacy/view/JViewTest.php index dde4cb2c43..e5edbad58d 100644 --- a/tests/suites/legacy/view/JViewTest.php +++ b/tests/suites/legacy/view/JViewTest.php @@ -172,7 +172,7 @@ public function testGetName() { $this->assertEquals('', $this->class->getName()); - TestReflection::setValue($this->class, 'name', 'inspector2'); + TestReflection::setValue($this->class, '_name', 'inspector2'); $this->assertEquals('inspector2', $this->class->getName()); } From aef733ac291a71ab76cac6cb78a1fe1ae33f7c6c Mon Sep 17 00:00:00 2001 From: blueboar2 Date: Tue, 10 Apr 2012 19:58:59 +0600 Subject: [PATCH 79/98] Update libraries/joomla/html/html/grid.php --- libraries/joomla/html/html/grid.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/html/html/grid.php b/libraries/joomla/html/html/grid.php index b0a607ad4c..d9f3804174 100644 --- a/libraries/joomla/html/html/grid.php +++ b/libraries/joomla/html/html/grid.php @@ -146,7 +146,7 @@ public static function checkedOut(&$row, $i, $identifier = 'id') } else { - $result = JTable::isCheckedOut($userid, $row->checked_out); + $result = false; } $checked = ''; From 9b383e320ff092745e282c0dcfc362c7687ec5c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 10 Apr 2012 15:59:19 +0200 Subject: [PATCH 80/98] Don't rename members in the legacy folder. --- libraries/legacy/application/helper.php | 8 -------- libraries/legacy/pathway/pathway.php | 12 ------------ 2 files changed, 20 deletions(-) diff --git a/libraries/legacy/application/helper.php b/libraries/legacy/application/helper.php index d8e0f255cd..cafa8c4a18 100644 --- a/libraries/legacy/application/helper.php +++ b/libraries/legacy/application/helper.php @@ -18,14 +18,6 @@ */ class JApplicationHelper { - /** - * Client information array - * - * @var array - * @since 11.1 - */ - protected static $clients = null; - /** * Client information array * diff --git a/libraries/legacy/pathway/pathway.php b/libraries/legacy/pathway/pathway.php index 0f1548199b..b2e7697868 100644 --- a/libraries/legacy/pathway/pathway.php +++ b/libraries/legacy/pathway/pathway.php @@ -20,12 +20,6 @@ */ class JPathway extends JObject { - /** - * @var array Array to hold the pathway item objects - * @since 11.1 - */ - protected $pathway = array(); - /** * @var array Array to hold the pathway item objects * @since 11.1 @@ -33,12 +27,6 @@ class JPathway extends JObject */ protected $_pathway = array(); - /** - * @var integer Integer number of items in the pathway - * @since 11.1 - */ - protected $count = 0; - /** * @var integer Integer number of items in the pathway * @since 11.1 From 61c553b107ff2ac3ae742eb254340c9c02472fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 10 Apr 2012 16:06:02 +0200 Subject: [PATCH 81/98] Add missing @covers tags in the legacy folder. --- .../legacy/controller/JControllerFormTest.php | 1 + .../legacy/controller/JControllerTest.php | 20 +++++++++++ tests/suites/legacy/view/JViewTest.php | 36 ++++++++++++------- 3 files changed, 45 insertions(+), 12 deletions(-) diff --git a/tests/suites/legacy/controller/JControllerFormTest.php b/tests/suites/legacy/controller/JControllerFormTest.php index aaa01871ab..78f53f6c40 100644 --- a/tests/suites/legacy/controller/JControllerFormTest.php +++ b/tests/suites/legacy/controller/JControllerFormTest.php @@ -20,6 +20,7 @@ class JControllerFormTest extends PHPUnit_Framework_TestCase * @return void * * @since 11.1 + * @covers JControllerForm::__construct */ public function testConstructor() { diff --git a/tests/suites/legacy/controller/JControllerTest.php b/tests/suites/legacy/controller/JControllerTest.php index 7abc67c43f..e9cdeb4747 100644 --- a/tests/suites/legacy/controller/JControllerTest.php +++ b/tests/suites/legacy/controller/JControllerTest.php @@ -39,6 +39,8 @@ protected function setUp() * Test JController::addModelPath * * @since 11.3 + * + * @covers JController::addModelPath */ public function testAddModelPath() { @@ -54,6 +56,8 @@ public function testAddModelPath() /** * Test JController::createFileName(). + * + * @covers JController::createFileName */ public function testCreateFileName() { @@ -100,6 +104,8 @@ public function testGetInstance() * Test JController::__construct * * @since 11.3 + * + * @covers JController::__construct */ public function test__construct() { @@ -118,6 +124,8 @@ public function test__construct() * If execution halts for some reason, a bad path could be the culprit. * * @since 11.3 + * + * @covers JController::addPath */ public function testAddPath() { @@ -138,6 +146,8 @@ public function testAddPath() /** * Test JController::addViewPath + * + * @covers JController::addViewPath */ public function testAddViewPath() { @@ -228,6 +238,8 @@ public function testGetModel() /** * Test JController::getName + * + * @covers JController::getName */ public function testGetName() { @@ -244,6 +256,8 @@ public function testGetName() * @return void * * @since 11.3 + * + * @covers JController::getTask */ public function testGetTask() { @@ -254,6 +268,8 @@ public function testGetTask() /** * Test JController::getTasks + * + * @covers JController::getTasks */ public function testGetTasks() { @@ -337,6 +353,8 @@ public function testSetAccessControl() /** * Test JController::setMessage + * + * @covers JController::setMessage */ public function testSetMessage() { @@ -362,6 +380,8 @@ public function testSetPath() /** * Test JController::setRedirect + * + * @covers JController::setRedirect */ public function testSetRedirect() { diff --git a/tests/suites/legacy/view/JViewTest.php b/tests/suites/legacy/view/JViewTest.php index e5edbad58d..5936501465 100644 --- a/tests/suites/legacy/view/JViewTest.php +++ b/tests/suites/legacy/view/JViewTest.php @@ -86,7 +86,8 @@ public function testEscape() /** * Test JView::get() * - * @since 11.3 + * @since 11.3 + * @covers JView::get */ public function testGet() { @@ -106,7 +107,8 @@ public function testGet() /** * Test JView::getLayout() * - * @since 11.3 + * @since 11.3 + * @covers JView::getLayout */ public function testGetLayout() { @@ -120,7 +122,8 @@ public function testGetLayout() /** * Test JView::getModel() * - * @since 11.3 + * @since 11.3 + * @covers JView::getModel */ public function testGetModel() { @@ -152,7 +155,8 @@ public function testGetModel() /** * Test JView::getLayoutTemplate() * - * @since 11.3 + * @since 11.3 + * @covers JView::getLayoutTemplate */ public function testGetLayoutTemplate() { @@ -166,7 +170,8 @@ public function testGetLayoutTemplate() /** * Test JView::getName() * - * @since 11.3 + * @since 11.3 + * @covers JView::getName */ public function testGetName() { @@ -180,7 +185,8 @@ public function testGetName() /** * Test JView::setModel() * - * @since 11.3 + * @since 11.3 + * @covers JView::setModel */ public function testSetModel() { @@ -222,7 +228,8 @@ public function testSetModel() /** * Test JView::setLayout() * - * @since 11.3 + * @since 11.3 + * @covers JView::setLayout */ public function testSetLayout() { @@ -242,7 +249,8 @@ public function testSetLayout() /** * Test JView::setLayoutExt() * - * @since 11.3 + * @since 11.3 + * @covers JView::setLayoutExt */ public function testSetLayoutExt() { @@ -256,7 +264,8 @@ public function testSetLayoutExt() /** * Test JView::setEscape() * - * @since 11.3 + * @since 11.3 + * @covers JView::setEscape */ public function testSetEscape() { @@ -274,7 +283,8 @@ public function testSetEscape() /** * Test JView::addTemplatePath() * - * @since 11.3 + * @since 11.3 + * @covers JView::addTemplatePath */ public function testAddTemplatePath() { @@ -303,7 +313,8 @@ public function testAddTemplatePath() /** * Test JView::addHelperPath() * - * @since 11.3 + * @since 11.3 + * @covers JView::addHelperPath */ public function testAddHelperPath() { @@ -359,7 +370,8 @@ public function test_setPath() /** * Test JView::_addPath() * - * @since 11.3 + * @since 11.3 + * @covers JView::_addPath */ public function test_addPath() { From 8135508239747799313eefafc482275d64f81eb0 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Tue, 10 Apr 2012 18:19:52 +0200 Subject: [PATCH 82/98] Check for install method versus discover_install --- libraries/joomla/installer/adapters/component.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/joomla/installer/adapters/component.php b/libraries/joomla/installer/adapters/component.php index 14717eea9a..71e9a35051 100644 --- a/libraries/joomla/installer/adapters/component.php +++ b/libraries/joomla/installer/adapters/component.php @@ -1700,7 +1700,7 @@ public function discover_install() ob_start(); ob_implicit_flush(false); - if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'discover_install')) + if ($this->parent->manifestClass && method_exists($this->parent->manifestClass, 'install')) { if ($this->parent->manifestClass->install($this) === false) From e0bf106d80554c336fddd6c1d4b28dfef29a7c08 Mon Sep 17 00:00:00 2001 From: Amy Stephen Date: Tue, 10 Apr 2012 20:47:11 -0500 Subject: [PATCH 83/98] Corrected JDatabaseDriverPostgresql object name from JDatabasePostgresql --- libraries/joomla/database/exporter/postgresql.php | 8 ++++---- libraries/joomla/database/importer/postgresql.php | 8 ++++---- .../database/JDatabaseExporterPostgresqlTest.php | 2 +- .../database/JDatabaseImporterPostgresqlTest.php | 10 +++++----- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/libraries/joomla/database/exporter/postgresql.php b/libraries/joomla/database/exporter/postgresql.php index 44edcf542c..7edd729ee8 100644 --- a/libraries/joomla/database/exporter/postgresql.php +++ b/libraries/joomla/database/exporter/postgresql.php @@ -29,7 +29,7 @@ class JDatabaseExporterPostgresql extends JDatabaseExporter /** * The database connector to use for exporting structure and/or data. * - * @var JDatabasePostgresql + * @var JDatabaseDriverPostgresql * @since 12.1 */ protected $db = null; @@ -217,7 +217,7 @@ protected function buildXmlStructure() public function check() { // Check if the db connector has been set. - if (!($this->db instanceof JDatabasePostgresql)) + if (!($this->db instanceof JDatabaseDriverPostgresql)) { throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE'); } @@ -282,13 +282,13 @@ public function from($from) /** * Sets the database connector to use for exporting structure and/or data from PostgreSQL. * - * @param JDatabasePostgresql $db The database connector. + * @param JDatabaseDriverPostgresql $db The database connector. * * @return JDatabaseExporterPostgresql Method supports chaining. * * @since 12.1 */ - public function setDbo(JDatabasePostgresql $db) + public function setDbo(JDatabaseDriverPostgresql $db) { $this->db = $db; diff --git a/libraries/joomla/database/importer/postgresql.php b/libraries/joomla/database/importer/postgresql.php index 78b0c97d6c..2afee3a251 100644 --- a/libraries/joomla/database/importer/postgresql.php +++ b/libraries/joomla/database/importer/postgresql.php @@ -27,7 +27,7 @@ class JDatabaseImporterPostgresql extends JDatabaseImporter /** * The database connector to use for exporting structure and/or data. * - * @var JDatabasePostgresql + * @var JDatabaseDriverPostgresql * @since 12.1 */ protected $db = null; @@ -105,7 +105,7 @@ public function asXml() public function check() { // Check if the db connector has been set. - if (!($this->db instanceof JDatabasePostgresql)) + if (!($this->db instanceof JDatabaseDriverPostgresql)) { throw new Exception('JPLATFORM_ERROR_DATABASE_CONNECTOR_WRONG_TYPE'); } @@ -764,13 +764,13 @@ protected function mergeStructure() /** * Sets the database connector to use for exporting structure and/or data from PostgreSQL. * - * @param JDatabasePostgresql $db The database connector. + * @param JDatabaseDriverPostgresql $db The database connector. * * @return JDatabaseImporterPostgresql Method supports chaining. * * @since 12.1 */ - public function setDbo(JDatabasePostgresql $db) + public function setDbo(JDatabaseDriverPostgresql $db) { $this->db = $db; diff --git a/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php index 39413d124d..6f94501424 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseExporterPostgresqlTest.php @@ -49,7 +49,7 @@ public function setup() // Set up the database object mock. $this->dbo = $this->getMock( - 'JDatabasePostgresql', + 'JDatabaseDriverPostgresql', array( 'getErrorNum', 'getPrefix', diff --git a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php index 6491a64cce..975c2959cf 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlTest.php @@ -2,7 +2,7 @@ /** * @version $Id: JDatabaseImporterPostgresqlTest.php gpongelli $ * @package Joomla.UnitTest - * + * * @copyright Copyright (C) 2005 - 2012 Open Source Matters. All rights reserved. * @license GNU General Public License */ @@ -11,10 +11,10 @@ /** * Test the JDatabaseImporterPostgresql class. - * + * * @package Joomla.UnitTest * @subpackage Database - * + * * @since 12.1 */ class JDatabaseImporterPostgresqlTest extends PHPUnit_Framework_TestCase @@ -58,7 +58,7 @@ public function setup() // Set up the database object mock. $this->dbo = $this->getMock( - 'JDatabasePostgresql', + 'JDatabaseDriverPostgresql', array( 'getErrorNum', 'getPrefix', @@ -981,7 +981,7 @@ public function testSetDboWithBadInput() } $this->fail( - 'setDbo requires a JDatabasePostgresql object and should throw an exception.' + 'setDbo requires a JDatabaseDriverPostgresql object and should throw an exception.' ); } From 9487724b10127a9a9c90664fe9e36c309f45843e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 9 Apr 2012 23:54:29 +0200 Subject: [PATCH 84/98] Deprecate JXMLElement. --- libraries/joomla/factory.php | 1 + libraries/joomla/utilities/xmlelement.php | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/libraries/joomla/factory.php b/libraries/joomla/factory.php index f4501510c8..2a5c6468bf 100644 --- a/libraries/joomla/factory.php +++ b/libraries/joomla/factory.php @@ -378,6 +378,7 @@ public static function getFeedParser($url, $cache_time = 0) * * @see JXMLElement * @since 11.1 + * @note This method will return SimpleXMLElement object in the future. Do not rely on JXMLElement's methods. * @todo This may go in a separate class - error reporting may be improved. */ public static function getXML($data, $isFile = true) diff --git a/libraries/joomla/utilities/xmlelement.php b/libraries/joomla/utilities/xmlelement.php index 046133abab..9c51dad63e 100644 --- a/libraries/joomla/utilities/xmlelement.php +++ b/libraries/joomla/utilities/xmlelement.php @@ -15,6 +15,7 @@ * @package Joomla.Platform * @subpackage Utilities * @since 11.1 + * @deprecated 13.3 Use SimpleXMLElement instead. */ class JXMLElement extends SimpleXMLElement { @@ -24,9 +25,11 @@ class JXMLElement extends SimpleXMLElement * @return string * * @since 11.1 + * @deprecated 13.3 Use SimpleXMLElement::getName() instead. */ public function name() { + JLog::add('JXMLElement::name() is deprecated, use SimpleXMLElement::getName() instead.', self::WARNING, 'deprecated'); return (string) $this->getName(); } @@ -40,9 +43,11 @@ public function name() * @return string * * @since 11.1 + * @deprecated 13.3 Use SimpleXMLElement::asXML() instead. */ public function asFormattedXML($compressed = false, $indent = "\t", $level = 0) { + JLog::add('JXMLElement::asFormattedXML() is deprecated, use SimpleXMLElement::asXML() instead.', self::WARNING, 'deprecated'); $out = ''; // Start a new line, indent by the number indicated in $level From 5ee15cc8d8b7f02fcbfd871688691aa44752921b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 10 Apr 2012 00:07:46 +0200 Subject: [PATCH 85/98] Reduce coupling to JXMLElement since we don't actually use any of its methods in our code. Maintain backwards compatability. --- libraries/joomla/access/access.php | 6 +- libraries/joomla/form/field.php | 16 ++-- libraries/joomla/form/form.php | 94 +++++++++---------- libraries/joomla/form/rule.php | 14 +-- libraries/joomla/form/rules/color.php | 14 +-- libraries/joomla/form/rules/email.php | 14 +-- libraries/joomla/form/rules/equals.php | 14 +-- libraries/joomla/form/rules/options.php | 14 +-- libraries/joomla/form/rules/rules.php | 18 ++-- libraries/joomla/form/rules/tel.php | 14 +-- libraries/joomla/form/rules/url.php | 14 +-- libraries/joomla/form/rules/username.php | 14 +-- .../joomla/installer/adapters/module.php | 2 +- .../joomla/installer/adapters/template.php | 2 +- libraries/joomla/installer/extension.php | 6 +- libraries/joomla/installer/installer.php | 34 +++---- 16 files changed, 145 insertions(+), 145 deletions(-) diff --git a/libraries/joomla/access/access.php b/libraries/joomla/access/access.php index a4c7810090..4c175c5771 100644 --- a/libraries/joomla/access/access.php +++ b/libraries/joomla/access/access.php @@ -503,8 +503,8 @@ public static function getActionsFromFile($file, $xpath = "/access/section[@name /** * Method to return a list of actions from a string or from an xml for which permissions can be set. * - * @param string|JXMLElement $data The XML string or an XML element. - * @param string $xpath An optional xpath to search for the fields. + * @param string|SimpleXMLElement $data The XML string or an XML element. + * @param string $xpath An optional xpath to search for the fields. * * @return boolean|array False if case of error or the list of actions available. * @@ -513,7 +513,7 @@ public static function getActionsFromFile($file, $xpath = "/access/section[@name public static function getActionsFromData($data, $xpath = "/access/section[@name='component']/") { // If the data to load isn't already an XML element or string return false. - if ((!($data instanceof JXMLElement)) && (!is_string($data))) + if ((!($data instanceof SimpleXMLElement)) && (!is_string($data))) { return false; } diff --git a/libraries/joomla/form/field.php b/libraries/joomla/form/field.php index f441500966..80736d96e9 100644 --- a/libraries/joomla/form/field.php +++ b/libraries/joomla/form/field.php @@ -27,9 +27,9 @@ abstract class JFormField protected $description; /** - * The JXMLElement object of the XML element that describes the form field. + * The SimpleXMLElement object of the XML element that describes the form field. * - * @var JXMLElement + * @var SimpleXMLElement * @since 11.1 */ protected $element; @@ -288,11 +288,11 @@ public function setForm(JForm $form) /** * Method to attach a JForm object to the field. * - * @param JXmlElement $element The JXmlElement object representing the 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 SimpleXMLElement $element The SimpleXMLElement object representing the 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]". * * @return boolean True on success. * @@ -301,7 +301,7 @@ public function setForm(JForm $form) public function setup($element, $value, $group = null) { // Make sure there is a valid JFormField XML element. - if (!($element instanceof JXMLElement) || (string) $element->getName() != 'field') + if (!($element instanceof SimpleXMLElement) || (string) $element->getName() != 'field') { return false; } diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index 99a9bd375d..2e205981cc 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -101,7 +101,7 @@ public function __construct($name, array $options = array()) public function bind($data) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -196,7 +196,7 @@ protected function bindLevel($group, $data) public function filter($data, $group = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -272,7 +272,7 @@ public function getErrors() public function getField($name, $group = null, $value = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -306,16 +306,16 @@ public function getField($name, $group = null, $value = null) public function getFieldAttribute($name, $attribute, $default = null, $group = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findField($name, $group); // If the element exists and the attribute exists for the field return the attribute value. - if (($element instanceof JXMLElement) && ((string) $element[$attribute])) + if (($element instanceof SimpleXMLElement) && ((string) $element[$attribute])) { return (string) $element[$attribute]; } @@ -392,7 +392,7 @@ public function getFieldsets($group = null) $sets = array(); // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return $fieldsets; } @@ -642,7 +642,7 @@ public function getValue($name, $group = null, $default = null) public function load($data, $replace = true, $xpath = false) { // If the data to load isn't already an XML element or string return false. - if ((!($data instanceof JXMLElement)) && (!is_string($data))) + if ((!($data instanceof SimpleXMLElement)) && (!is_string($data))) { return false; } @@ -786,16 +786,16 @@ public function loadFile($file, $reset = true, $xpath = false) public function removeField($name, $group = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findField($name, $group); // If the element exists remove it from the form definition. - if ($element instanceof JXMLElement) + if ($element instanceof SimpleXMLElement) { $dom = dom_import_simplexml($element); $dom->parentNode->removeChild($dom); @@ -817,9 +817,9 @@ public function removeField($name, $group = null) public function removeGroup($group) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Get the fields elements for a given group. @@ -861,21 +861,21 @@ public function reset($xml = false) * the field will be set whether it already exists or not. If it isn't set, then the field * will not be replaced if it already exists. * - * @param JXMLElement $element The XML element object representation of the form field. - * @param string $group The optional dot-separated form group path on which to set the field. - * @param boolean $replace True to replace an existing field if one already exists. + * @param SimpleXMLElement $element The XML element object representation of the form field. + * @param string $group The optional dot-separated form group path on which to set the field. + * @param boolean $replace True to replace an existing field if one already exists. * * @return boolean True on success. * * @since 11.1 * @throws UnexpectedValueException */ - public function setField(JXMLElement $element, $group = null, $replace = true) + public function setField(SimpleXMLElement $element, $group = null, $replace = true) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. @@ -888,7 +888,7 @@ public function setField(JXMLElement $element, $group = null, $replace = true) } // If an existing field is found and replace flag is true remove the old field. - if ($replace && !empty($old) && ($old instanceof JXMLElement)) + if ($replace && !empty($old) && ($old instanceof SimpleXMLElement)) { $dom = dom_import_simplexml($old); $dom->parentNode->removeChild($dom); @@ -902,7 +902,7 @@ public function setField(JXMLElement $element, $group = null, $replace = true) $fields = &$this->findGroup($group); // If an appropriate fields element was found for the group, add the element. - if (isset($fields[0]) && ($fields[0] instanceof JXMLElement)) + if (isset($fields[0]) && ($fields[0] instanceof SimpleXMLElement)) { self::addNode($fields[0], $element); } @@ -935,16 +935,16 @@ public function setField(JXMLElement $element, $group = null, $replace = true) public function setFieldAttribute($name, $attribute, $value, $group = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Find the form field element from the definition. $element = $this->findField($name, $group); // If the element doesn't exist return false. - if (!($element instanceof JXMLElement)) + if (!($element instanceof SimpleXMLElement)) { return false; } @@ -977,17 +977,17 @@ public function setFieldAttribute($name, $attribute, $value, $group = null) public function setFields(&$elements, $group = null, $replace = true) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of JXMLElement', get_class($this))); + throw new UnexpectedValueException(sprint('%s::getFieldAttribute `xml` is not an instance of SimpleXMLElement', get_class($this))); } // Make sure the elements to set are valid. foreach ($elements as $element) { - if (!($element instanceof JXMLElement)) + if (!($element instanceof SimpleXMLElement)) { - throw new UnexpectedValueException(sprintf('$element not JXmlElement in %s::setFields', get_class($this))); + throw new UnexpectedValueException(sprintf('$element not SimpleXMLElement in %s::setFields', get_class($this))); } } @@ -1057,7 +1057,7 @@ public function setValue($name, $group = null, $value = null) public function validate($data, $group = null) { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -1124,8 +1124,8 @@ public function validate($data, $group = null) */ protected function filterField($element, $value) { - // Make sure there is a valid JXMLElement. - if (!($element instanceof JXMLElement)) + // Make sure there is a valid SimpleXMLElement. + if (!($element instanceof SimpleXMLElement)) { return false; } @@ -1377,7 +1377,7 @@ protected function findField($name, $group = null) $fields = array(); // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -1458,7 +1458,7 @@ protected function findField($name, $group = null) * * @param string $name The name of the fieldset. * - * @return mixed Boolean false on error or array of JXMLElement objects. + * @return mixed Boolean false on error or array of SimpleXMLElement objects. * * @since 11.1 */ @@ -1468,7 +1468,7 @@ protected function &findFieldsByFieldset($name) $false = false; // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return $false; } @@ -1492,7 +1492,7 @@ protected function &findFieldsByFieldset($name) * @param boolean $nested True to also include fields in nested groups that are inside of the * group for which to find fields. * - * @return mixed Boolean false on error or array of JXMLElement objects. + * @return mixed Boolean false on error or array of SimpleXMLElement objects. * * @since 11.1 */ @@ -1503,7 +1503,7 @@ protected function &findFieldsByGroup($group = null, $nested = false) $fields = array(); // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return $false; } @@ -1579,7 +1579,7 @@ protected function &findGroup($group) $tmp = array(); // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return $false; } @@ -1635,7 +1635,7 @@ protected function &findGroup($group) // Only include valid XML objects. foreach ($tmp as $element) { - if ($element instanceof JXMLElement) + if ($element instanceof SimpleXMLElement) { $groups[] = $element; } @@ -1658,8 +1658,8 @@ protected function &findGroup($group) */ protected function loadField($element, $group = null, $value = null) { - // Make sure there is a valid JXMLElement. - if (!($element instanceof JXMLElement)) + // Make sure there is a valid SimpleXMLElement. + if (!($element instanceof SimpleXMLElement)) { return false; } @@ -1757,7 +1757,7 @@ protected function loadRuleType($type, $new = true) protected function syncPaths() { // Make sure there is a valid JForm XML document. - if (!($this->xml instanceof JXMLElement)) + if (!($this->xml instanceof SimpleXMLElement)) { return false; } @@ -1801,11 +1801,11 @@ protected function syncPaths() /** * Method to validate a JFormField object based on field data. * - * @param string $element The XML element object representation of the form field. - * @param string $group The optional dot-separated form group path on which to find the field. - * @param mixed $value The optional value to use as the default for the field. - * @param JRegistry $input An optional JRegistry object with the entire data set to validate - * against the entire form. + * @param SimpleXMLElement $element The XML element object representation of the form field. + * @param string $group The optional dot-separated form group path on which to find the field. + * @param mixed $value The optional value to use as the default for the field. + * @param JRegistry $input An optional JRegistry object with the entire data set to validate + * against the entire form. * * @return mixed Boolean true if field value is valid, Exception on failure. * @@ -1813,7 +1813,7 @@ protected function syncPaths() * @throws InvalidArgumentException * @throws UnexpectedValueException */ - protected function validateField(JXmlElement $element, $group = null, $value = null, JRegistry $input = null) + protected function validateField(SimpleXMLElement $element, $group = null, $value = null, JRegistry $input = null) { // Initialise variables. $valid = true; diff --git a/libraries/joomla/form/rule.php b/libraries/joomla/form/rule.php index 7c8a7be9d6..d6c802ef68 100644 --- a/libraries/joomla/form/rule.php +++ b/libraries/joomla/form/rule.php @@ -43,13 +43,13 @@ class JFormRule /** * Method to test the value. * - * @param JXmlElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/color.php b/libraries/joomla/form/rules/color.php index 0632f7c032..4b67ea2e2c 100644 --- a/libraries/joomla/form/rules/color.php +++ b/libraries/joomla/form/rules/color.php @@ -21,13 +21,13 @@ class JFormRuleColor extends JFormRule /** * Method to test for a valid color in hexadecimal. * - * @param JXmlElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/email.php b/libraries/joomla/form/rules/email.php index 6316566d8e..fab5a9a2c9 100644 --- a/libraries/joomla/form/rules/email.php +++ b/libraries/joomla/form/rules/email.php @@ -29,13 +29,13 @@ class JFormRuleEmail extends JFormRule /** * Method to test the email address and optionally check for uniqueness. * - * @param JXMLElement $element The JXMLElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/equals.php b/libraries/joomla/form/rules/equals.php index 6bd1bbe4b4..a52bdbf7bf 100644 --- a/libraries/joomla/form/rules/equals.php +++ b/libraries/joomla/form/rules/equals.php @@ -23,13 +23,13 @@ class JFormRuleEquals extends JFormRule * XML needs a validate attribute of equals and a field attribute * that is equal to the field to test against. * - * @param JXMLElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/options.php b/libraries/joomla/form/rules/options.php index 8e27ce365a..5291e79511 100644 --- a/libraries/joomla/form/rules/options.php +++ b/libraries/joomla/form/rules/options.php @@ -21,13 +21,13 @@ class JFormRuleOptions extends JFormRule /** * Method to test the value. * - * @param JXMLElement $element The JXMLElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/rules.php b/libraries/joomla/form/rules/rules.php index 51454f2dae..6cdc17f038 100644 --- a/libraries/joomla/form/rules/rules.php +++ b/libraries/joomla/form/rules/rules.php @@ -21,13 +21,13 @@ class JFormRuleRules extends JFormRule /** * Method to test the value. * - * @param JXmlElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * @@ -77,8 +77,8 @@ protected function getValueActions($value) /** * Method to get the list of possible permission action names for the form field. * - * @param JXMLElement $element The JXMLElement object representing the tag for the - * form field object. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the tag for the + * form field object. * * @return array A list of permission action names from the form field element definition. * diff --git a/libraries/joomla/form/rules/tel.php b/libraries/joomla/form/rules/tel.php index 8ce35efa61..887fb89f03 100644 --- a/libraries/joomla/form/rules/tel.php +++ b/libraries/joomla/form/rules/tel.php @@ -21,13 +21,13 @@ class JFormRuleTel extends JFormRule /** * Method to test the url for a valid parts. * - * @param JXmlElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/url.php b/libraries/joomla/form/rules/url.php index e2fa819905..75bae8d6a5 100644 --- a/libraries/joomla/form/rules/url.php +++ b/libraries/joomla/form/rules/url.php @@ -21,13 +21,13 @@ class JFormRuleUrl extends JFormRule /** * Method to test an external url for a valid parts. * - * @param JXmlElement $element The JXmlElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/form/rules/username.php b/libraries/joomla/form/rules/username.php index 28137525f1..a2d95a0a9c 100644 --- a/libraries/joomla/form/rules/username.php +++ b/libraries/joomla/form/rules/username.php @@ -21,13 +21,13 @@ class JFormRuleUsername extends JFormRule /** * Method to test the username for uniqueness. * - * @param JXMLElement $element The JXMLElement object representing the 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. + * @param SimpleXMLElement $element The SimpleXMLElement object representing the 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. * diff --git a/libraries/joomla/installer/adapters/module.php b/libraries/joomla/installer/adapters/module.php index e86c41687b..fb3bd01319 100644 --- a/libraries/joomla/installer/adapters/module.php +++ b/libraries/joomla/installer/adapters/module.php @@ -801,7 +801,7 @@ public function uninstall($id) $msg = ob_get_contents(); ob_end_clean(); - if (!($this->manifest instanceof JXMLElement)) + if (!($this->manifest instanceof SimpleXMLElement)) { // Make sure we delete the folders JFolder::delete($this->parent->getPath('extension_root')); diff --git a/libraries/joomla/installer/adapters/template.php b/libraries/joomla/installer/adapters/template.php index 22aadcbb88..a319b0813e 100644 --- a/libraries/joomla/installer/adapters/template.php +++ b/libraries/joomla/installer/adapters/template.php @@ -390,7 +390,7 @@ public function uninstall($id) // We do findManifest to avoid problem when uninstalling a list of extensions: getManifest cache its manifest file $this->parent->findManifest(); $manifest = $this->parent->getManifest(); - if (!($manifest instanceof JXMLElement)) + if (!($manifest instanceof SimpleXMLElement)) { // Kill the extension entry $row->delete($row->extension_id); diff --git a/libraries/joomla/installer/extension.php b/libraries/joomla/installer/extension.php index d399b68592..938f9cfd73 100644 --- a/libraries/joomla/installer/extension.php +++ b/libraries/joomla/installer/extension.php @@ -86,13 +86,13 @@ class JExtension extends JObject /** * Constructor * - * @param JXMLElement $element A JXMLElement from which to load data from + * @param SimpleXMLElement $element A SimpleXMLElement from which to load data from * * @since 11.1 */ - public function __construct(JXMLElement $element = null) + public function __construct(SimpleXMLElement $element = null) { - if ($element && is_a($element, 'JXMLElement')) + if ($element) { $this->type = (string) $element->attributes()->type; $this->id = (string) $element->attributes()->id; diff --git a/libraries/joomla/installer/installer.php b/libraries/joomla/installer/installer.php index 53588d222f..35a7bf4d5c 100644 --- a/libraries/joomla/installer/installer.php +++ b/libraries/joomla/installer/installer.php @@ -805,7 +805,7 @@ public function setupInstall() * Backward compatible method to parse through a queries element of the * installation manifest file and take appropriate action. * - * @param JXMLElement $element The XML node to process + * @param SimpleXMLElement $element The XML node to process * * @return mixed Number of queries processed or False on error * @@ -943,8 +943,8 @@ public function parseSQLFiles($element) /** * Set the schema version for an extension by looking at its latest update * - * @param JXMLElement $schema Schema Tag - * @param integer $eid Extension ID + * @param SimpleXMLElement $schema Schema Tag + * @param integer $eid Extension ID * * @return void * @@ -1011,10 +1011,10 @@ public function setSchemaVersion($schema, $eid) /** * Method to process the updates for an item * - * @param JXMLElement $schema The XML node to process - * @param integer $eid Extension Identifier + * @param SimpleXMLElement $schema The XML node to process + * @param integer $eid Extension Identifier * - * @return boolean Result of the operations + * @return boolean Result of the operations * * @since 11.1 */ @@ -1141,10 +1141,10 @@ public function parseSchemaUpdates($schema, $eid) * Method to parse through a files element of the installation manifest and take appropriate * action. * - * @param JXMLElement $element The XML node to process - * @param integer $cid Application ID of application to install to - * @param array $oldFiles List of old files (JXMLElement's) - * @param array $oldMD5 List of old MD5 sums (indexed by filename with value as MD5) + * @param SimpleXMLElement $element The XML node to process + * @param integer $cid Application ID of application to install to + * @param array $oldFiles List of old files (SimpleXMLElement's) + * @param array $oldMD5 List of old MD5 sums (indexed by filename with value as MD5) * * @return boolean True on success * @@ -1201,7 +1201,7 @@ public function parseFiles($element, $cid = 0, $oldFiles = null, $oldMD5 = null) } // Work out what files have been deleted - if ($oldFiles && ($oldFiles instanceof JXMLElement)) + if ($oldFiles && ($oldFiles instanceof SimpleXMLElement)) { $oldEntries = $oldFiles->children(); @@ -1269,8 +1269,8 @@ public function parseFiles($element, $cid = 0, $oldFiles = null, $oldMD5 = null) * Method to parse through a languages element of the installation manifest and take appropriate * action. * - * @param JXMLElement $element The XML node to process - * @param integer $cid Application ID of application to install to + * @param SimpleXMLElement $element The XML node to process + * @param integer $cid Application ID of application to install to * * @return boolean True on success * @@ -1386,8 +1386,8 @@ public function parseLanguages($element, $cid = 0) * Method to parse through a media element of the installation manifest and take appropriate * action. * - * @param JXMLElement $element The XML node to process - * @param integer $cid Application ID of application to install to + * @param SimpleXMLElement $element The XML node to process + * @param integer $cid Application ID of application to install to * * @return boolean True on success * @@ -1956,8 +1956,8 @@ public function cleanDiscoveredExtension($type, $element, $folder = '', $client /** * Compares two "files" entries to find deleted files/folders * - * @param array $old_files An array of JXMLElement objects that are the old files - * @param array $new_files An array of JXMLElement objects that are the new files + * @param array $old_files An array of SimpleXMLElement objects that are the old files + * @param array $new_files An array of SimpleXMLElement objects that are the new files * * @return array An array with the delete files and folders in findDeletedFiles[files] and findDeletedFiles[folders] respectively * From c0f56db3211d86e81d760fa52b6405302427e95d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sat, 24 Mar 2012 23:47:07 +0100 Subject: [PATCH 86/98] Deal with some occurences of JRequest. --- libraries/joomla/cache/cache.php | 2 +- libraries/legacy/application/helper.php | 5 +++-- libraries/legacy/component/helper.php | 2 +- libraries/legacy/controller/admin.php | 6 ++++-- libraries/legacy/controller/controller.php | 15 ++++++++------ libraries/legacy/controller/form.php | 23 ++++++++++++---------- libraries/legacy/form/field/media.php | 3 +-- libraries/legacy/model/admin.php | 2 +- libraries/legacy/model/list.php | 5 +++-- libraries/legacy/model/model.php | 2 +- libraries/legacy/module/helper.php | 7 ++++--- tests/core/mock/application.php | 2 ++ 12 files changed, 43 insertions(+), 31 deletions(-) diff --git a/libraries/joomla/cache/cache.php b/libraries/joomla/cache/cache.php index 8563fb1084..0e3b248c70 100644 --- a/libraries/joomla/cache/cache.php +++ b/libraries/joomla/cache/cache.php @@ -645,7 +645,7 @@ public static function makeId() foreach ($registeredurlparams as $key => $value) { - $safeuriaddon->$key = JRequest::getVar($key, null, 'default', $value); + $safeuriaddon->$key = $app->input->get($key, null, $value); } return md5(serialize($safeuriaddon)); diff --git a/libraries/legacy/application/helper.php b/libraries/legacy/application/helper.php index cafa8c4a18..b1f47e16f9 100644 --- a/libraries/legacy/application/helper.php +++ b/libraries/legacy/application/helper.php @@ -44,14 +44,15 @@ public static function getComponentName($default = null) return $option; } - $option = strtolower(JRequest::getCmd('option')); + $input = JFactory::getApplication(); + $option = strtolower($input->get('option')); if (empty($option)) { $option = $default; } - JRequest::setVar('option', $option); + $input->get('option', $option); return $option; } diff --git a/libraries/legacy/component/helper.php b/libraries/legacy/component/helper.php index dc41e6a303..035630fbc9 100644 --- a/libraries/legacy/component/helper.php +++ b/libraries/legacy/component/helper.php @@ -327,7 +327,7 @@ public static function renderComponent($option, $params = array()) throw new Exception(JText::_('JLIB_APPLICATION_ERROR_COMPONENT_NOT_FOUND'), 404); } - $task = JRequest::getString('task'); + $task = $app->input->getString('task'); // Load common and local language files. $lang->load($option, JPATH_BASE, null, false, false) || $lang->load($option, JPATH_COMPONENT, null, false, false) diff --git a/libraries/legacy/controller/admin.php b/libraries/legacy/controller/admin.php index cdf7a34369..4a62383ec9 100644 --- a/libraries/legacy/controller/admin.php +++ b/libraries/legacy/controller/admin.php @@ -167,6 +167,8 @@ public function publish() // Check for request forgeries JSession::checkToken() or die(JText::_('JINVALID_TOKEN')); + $input = JFactory::getApplication()->input; + // Get items to publish from the request. $cid = JRequest::getVar('cid', array(), '', 'array'); $data = array('publish' => 1, 'unpublish' => 0, 'archive' => 2, 'trash' => -2, 'report' => -3); @@ -211,8 +213,8 @@ public function publish() $this->setMessage(JText::plural($ntext, count($cid))); } } - $extension = JRequest::getCmd('extension'); - $extensionURL = ($extension) ? '&extension=' . JRequest::getCmd('extension') : ''; + $extension = $input->get('extension'); + $extensionURL = ($extension) ? '&extension=' . $input->get('extension') : ''; $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $extensionURL, false)); } diff --git a/libraries/legacy/controller/controller.php b/libraries/legacy/controller/controller.php index 00546a086b..fc9ac90b9f 100644 --- a/libraries/legacy/controller/controller.php +++ b/libraries/legacy/controller/controller.php @@ -218,10 +218,12 @@ public static function getInstance($prefix, $config = array()) return self::$instance; } + $input = JFactory::getApplication()->input; + // Get the environment configuration. $basePath = array_key_exists('base_path', $config) ? $config['base_path'] : JPATH_COMPONENT; - $format = JRequest::getWord('format'); - $command = JRequest::getVar('task', 'display'); + $format = $input->getWord('format'); + $command = $input->get('task', 'display'); // Check for array format. $filter = JFilterInput::getInstance(); @@ -246,7 +248,7 @@ public static function getInstance($prefix, $config = array()) $path = $basePath . '/controllers/' . $file; // Reset the task without the controller context. - JRequest::setVar('task', $task); + $input->set('task', $task); } else { @@ -614,8 +616,9 @@ public function display($cachable = false, $urlparams = array()) { $document = JFactory::getDocument(); $viewType = $document->getType(); - $viewName = JRequest::getCmd('view', $this->default_view); - $viewLayout = JRequest::getCmd('layout', 'default'); + $input = JFactory::getApplication()->input; + $viewName = $input->get('view', $this->default_view); + $viewLayout = $input->get('layout', 'default'); $view = $this->getView($viewName, $viewType, '', array('base_path' => $this->basePath, 'layout' => $viewLayout)); @@ -633,7 +636,7 @@ public function display($cachable = false, $urlparams = array()) // Display the view if ($cachable && $viewType != 'feed' && $conf->get('caching') >= 1) { - $option = JRequest::getCmd('option'); + $option = $input->get('layout'); $cache = JFactory::getCache($option, 'view'); if (is_array($urlparams)) diff --git a/libraries/legacy/controller/form.php b/libraries/legacy/controller/form.php index 33f935b3a5..15ab959702 100644 --- a/libraries/legacy/controller/form.php +++ b/libraries/legacy/controller/form.php @@ -310,7 +310,7 @@ public function cancel($key = null) $key = $table->getKeyName(); } - $recordId = JRequest::getInt($key); + $recordId = $app->input->getInt($key); // Attempt to check-in the current record. if ($recordId) @@ -380,7 +380,8 @@ public function cancel($key = null) public function edit($key = null, $urlVar = null) { // Initialise variables. - $app = JFactory::getApplication(); + $app = JFactory::getApplication(); + $input = $app->input; $model = $this->getModel(); $table = $model->getTable(); $cid = JRequest::getVar('cid', array(), 'post', 'array'); @@ -399,7 +400,7 @@ public function edit($key = null, $urlVar = null) } // Get the previous record id (if any) and the current record id. - $recordId = (int) (count($cid) ? $cid[0] : JRequest::getInt($urlVar)); + $recordId = (int) (count($cid) ? $cid[0] : $input->getInt($urlVar)); $checkin = property_exists($table, 'checked_out'); // Access check. @@ -484,8 +485,9 @@ public function getModel($name = '', $prefix = '', $config = array('ignore_reque */ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') { - $tmpl = JRequest::getCmd('tmpl'); - $layout = JRequest::getCmd('layout', 'edit'); + $input = JFactory::getApplication()->input; + $tmpl = $input->get('tmpl'); + $layout = $input->get('layout', 'edit'); $append = ''; // Setup redirect info. @@ -516,7 +518,7 @@ protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id') */ protected function getRedirectToListAppend() { - $tmpl = JRequest::getCmd('tmpl'); + $tmpl = JFactory::getApplication()->input->get('tmpl'); $append = ''; // Setup redirect info. @@ -559,11 +561,12 @@ public function save($key = null, $urlVar = null) JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. - $app = JFactory::getApplication(); - $lang = JFactory::getLanguage(); + $app = JFactory::getApplication(); + $input = $app->input; + $lang = JFactory::getLanguage(); $model = $this->getModel(); $table = $model->getTable(); - $data = JRequest::getVar('jform', array(), 'post', 'array'); + $data = JRequest::getVar('jform', array(), 'post', 'array'); $checkin = property_exists($table, 'checked_out'); $context = "$this->option.edit.$this->context"; $task = $this->getTask(); @@ -580,7 +583,7 @@ public function save($key = null, $urlVar = null) $urlVar = $key; } - $recordId = JRequest::getInt($urlVar); + $recordId = $input->getInt($urlVar); if (!$this->checkEditId($context, $recordId)) { diff --git a/libraries/legacy/form/field/media.php b/libraries/legacy/form/field/media.php index 12bdcd7482..e7c34f6f6c 100644 --- a/libraries/legacy/form/field/media.php +++ b/libraries/legacy/form/field/media.php @@ -50,13 +50,12 @@ protected function getInput() $asset = $this->form->getValue($assetField) ? $this->form->getValue($assetField) : (string) $this->element['asset_id']; if ($asset == '') { - $asset = JRequest::getCmd('option'); + $asset = JFactory::getApplication()->input->get('option'); } $link = (string) $this->element['link']; if (!self::$initialised) { - // Load the modal behavior script. JHtml::_('behavior.modal'); diff --git a/libraries/legacy/model/admin.php b/libraries/legacy/model/admin.php index 2469f5c192..5c33f6670f 100644 --- a/libraries/legacy/model/admin.php +++ b/libraries/legacy/model/admin.php @@ -799,7 +799,7 @@ protected function populateState() $key = $table->getKeyName(); // Get the pk of the record from the request. - $pk = JRequest::getInt($key); + $pk = JFactory::getApplication()->input->getInt($key); $this->setState($this->getName() . '.id', $pk); // Load the parameters. diff --git a/libraries/legacy/model/list.php b/libraries/legacy/model/list.php index 6c27a78dc6..954973866c 100644 --- a/libraries/legacy/model/list.php +++ b/libraries/legacy/model/list.php @@ -347,13 +347,14 @@ protected function populateState($ordering = null, $direction = null) public function getUserStateFromRequest($key, $request, $default = null, $type = 'none', $resetPage = true) { $app = JFactory::getApplication(); + $input = $app->input; $old_state = $app->getUserState($key); $cur_state = (!is_null($old_state)) ? $old_state : $default; - $new_state = JRequest::getVar($request, null, 'default', $type); + $new_state = $input->get($request, null, $type); if (($cur_state != $new_state) && ($resetPage)) { - JRequest::setVar('limitstart', 0); + $input->set('limitstart', 0); } // Save the new value only if it is set in this request. diff --git a/libraries/legacy/model/model.php b/libraries/legacy/model/model.php index 512fb53cfb..331ef18e6d 100644 --- a/libraries/legacy/model/model.php +++ b/libraries/legacy/model/model.php @@ -496,7 +496,7 @@ protected function cleanCache($group = null, $client_id = 0) $dispatcher = JDispatcher::getInstance(); $options = array( - 'defaultgroup' => ($group) ? $group : (isset($this->option) ? $this->option : JRequest::getCmd('option')), + 'defaultgroup' => ($group) ? $group : (isset($this->option) ? $this->option : JFactory::getApplication()->input->get('option')), 'cachebase' => ($client_id) ? JPATH_ADMINISTRATOR . '/cache' : $conf->get('cache_path', JPATH_SITE . '/cache')); $cache = JCache::getInstance('callback', $options); diff --git a/libraries/legacy/module/helper.php b/libraries/legacy/module/helper.php index 4160a5cac3..9ac800cc10 100644 --- a/libraries/legacy/module/helper.php +++ b/libraries/legacy/module/helper.php @@ -80,6 +80,7 @@ public static function &getModules($position) { $position = strtolower($position); $result = array(); + $input = JFactory::getApplication()->input; $modules =& self::_load(); @@ -94,7 +95,7 @@ public static function &getModules($position) if (count($result) == 0) { - if (JRequest::getBool('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) + if ($input->getBool('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) { $result[0] = self::getModule('mod_' . $position); $result[0]->title = $position; @@ -202,7 +203,7 @@ public static function renderModule($module, $attribs = array()) } // Dynamically add outline style - if (JRequest::getBool('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) + if ($app->input->getBool('tp') && JComponentHelper::getParams('com_templates')->get('template_positions_display')) { $attribs['style'] .= ' outline'; } @@ -289,8 +290,8 @@ protected static function &_load() return $clean; } - $Itemid = JRequest::getInt('Itemid'); $app = JFactory::getApplication(); + $Itemid = $app->input->getInt('Itemid'); $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); $lang = JFactory::getLanguage()->getTag(); diff --git a/tests/core/mock/application.php b/tests/core/mock/application.php index e6d2653506..d0ebbd8877 100644 --- a/tests/core/mock/application.php +++ b/tests/core/mock/application.php @@ -46,6 +46,8 @@ public static function create($test) false ); + $mockObject->input = new JInput; + return $mockObject; } } From b740a8c0a14fffc0a6a7306a5ec2dfaff9ef75ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 10 Apr 2012 22:12:29 +0200 Subject: [PATCH 87/98] Since JApplication depends on JInput fail early if it doesn't exist. --- libraries/legacy/application/application.php | 5 +---- libraries/legacy/application/helper.php | 4 ++-- libraries/legacy/controller/admin.php | 2 +- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index 09b3bb0ee4..70c5176448 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -106,10 +106,7 @@ public function __construct($config = array()) } // Create the input object - if (class_exists('JInput')) - { - $this->input = new JInput; - } + $this->input = new JInput; // Set the session default name. if (!isset($config['session_name'])) diff --git a/libraries/legacy/application/helper.php b/libraries/legacy/application/helper.php index b1f47e16f9..e8028b1b88 100644 --- a/libraries/legacy/application/helper.php +++ b/libraries/legacy/application/helper.php @@ -44,7 +44,7 @@ public static function getComponentName($default = null) return $option; } - $input = JFactory::getApplication(); + $input = JFactory::getApplication()->input; $option = strtolower($input->get('option')); if (empty($option)) @@ -52,7 +52,7 @@ public static function getComponentName($default = null) $option = $default; } - $input->get('option', $option); + $input->set('option', $option); return $option; } diff --git a/libraries/legacy/controller/admin.php b/libraries/legacy/controller/admin.php index 4a62383ec9..0c50a8ee7a 100644 --- a/libraries/legacy/controller/admin.php +++ b/libraries/legacy/controller/admin.php @@ -214,7 +214,7 @@ public function publish() } } $extension = $input->get('extension'); - $extensionURL = ($extension) ? '&extension=' . $input->get('extension') : ''; + $extensionURL = ($extension) ? '&extension=' . $extension : ''; $this->setRedirect(JRoute::_('index.php?option=' . $this->option . '&view=' . $this->view_list . $extensionURL, false)); } From d3406ec31202148937d34380e844f5f18a2335c2 Mon Sep 17 00:00:00 2001 From: Nikolai Plath Date: Thu, 12 Apr 2012 17:13:42 -0500 Subject: [PATCH 88/98] Fix a docblock --- libraries/joomla/input/input.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/input/input.php b/libraries/joomla/input/input.php index f18525990e..8b65cf3e58 100644 --- a/libraries/joomla/input/input.php +++ b/libraries/joomla/input/input.php @@ -231,10 +231,10 @@ public function def($name, $value) /** * Magic method to get filtered input data. * - * @param mixed $name Name of the value to get. - * @param string $arguments Default value to return if variable does not exist. + * @param string $name Name of the filter type prefixed with 'get'. + * @param array $arguments [0] The name of the variable [1] The default value. * - * @return boolean The filtered boolean input value. + * @return mixed The filtered input value. * * @since 11.1 */ From ca5b8834a9802e9b6f1b4b6f37fcf8c9fb44b8aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 9 Apr 2012 22:14:27 +0200 Subject: [PATCH 89/98] Remove unnecessary jimport() calls. JRequest is now autoloadable and doesn't need to be registered. --- libraries/import.legacy.php | 5 +---- libraries/legacy/application/application.php | 2 -- libraries/legacy/base/tree.php | 2 -- libraries/legacy/error/error.php | 2 -- 4 files changed, 1 insertion(+), 10 deletions(-) diff --git a/libraries/import.legacy.php b/libraries/import.legacy.php index 9677a28869..b8db2cb167 100644 --- a/libraries/import.legacy.php +++ b/libraries/import.legacy.php @@ -50,9 +50,6 @@ class_exists('JLoader') or die; // Import the Joomla Factory. JLoader::import('joomla.factory'); -// Register JRequest for legacy reasons -JLoader::register('JRequest', JPATH_PLATFORM . '/joomla/environment/request.php'); - // Register classes that don't follow one file per class naming conventions. JLoader::register('JText', JPATH_PLATFORM . '/joomla/language/text.php'); JLoader::register('JRoute', JPATH_PLATFORM . '/joomla/application/route.php'); @@ -65,4 +62,4 @@ class_exists('JLoader') or die; JLoader::register('JDatabaseQuerySQLSrv', JPATH_PLATFORM . '/joomla/database/query/sqlsrv.php'); JLoader::register('JToolBar', JPATH_PLATFORM . '/legacy/toolbar/toolbar.php'); JLoader::register('JTree', JPATH_PLATFORM . '/legacy/base/tree.php'); -JLoader::register('JNode', JPATH_PLATFORM . '/legacy/base/node.php'); \ No newline at end of file +JLoader::register('JNode', JPATH_PLATFORM . '/legacy/base/node.php'); diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index 70c5176448..a827a74373 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -88,8 +88,6 @@ class JApplication extends JApplicationBase */ public function __construct($config = array()) { - jimport('joomla.error.profiler'); - // Set the view name. $this->_name = $this->getName(); diff --git a/libraries/legacy/base/tree.php b/libraries/legacy/base/tree.php index 96e34e031a..7972bb3c7d 100644 --- a/libraries/legacy/base/tree.php +++ b/libraries/legacy/base/tree.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.base.node'); - /** * Tree Class. * diff --git a/libraries/legacy/error/error.php b/libraries/legacy/error/error.php index b28301de8c..6ad4e1f0f4 100644 --- a/libraries/legacy/error/error.php +++ b/libraries/legacy/error/error.php @@ -150,8 +150,6 @@ public static function raise($level, $code, $msg, $info = null, $backtrace = fal // Deprecation warning. JLog::add('JError::raise() is deprecated.', JLog::WARNING, 'deprecated'); - jimport('joomla.error.exception'); - // Build error object $exception = new JException($msg, $code, $level, $info, $backtrace); return self::throwError($exception); From 170823879a764a32ad50d012fe989bebcbb7e075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 9 Apr 2012 22:25:32 +0200 Subject: [PATCH 90/98] Rename JDispatcher to JEventDispatcher to make it autoloadable. --- libraries/joomla/application/base.php | 14 ++--- libraries/joomla/application/cli.php | 4 +- libraries/joomla/application/daemon.php | 4 +- libraries/joomla/application/web.php | 2 +- libraries/joomla/event/dispatcher.php | 12 ++-- libraries/joomla/html/editor.php | 2 - libraries/joomla/html/html/content.php | 2 +- libraries/joomla/installer/installer.php | 8 +-- libraries/joomla/plugin/helper.php | 20 +++--- libraries/joomla/user/authentication.php | 4 +- libraries/joomla/user/helper.php | 2 +- libraries/joomla/user/user.php | 4 +- libraries/legacy/dispatcher/dispatcher.php | 32 ++++++++++ libraries/legacy/model/admin.php | 6 +- libraries/legacy/model/form.php | 2 +- libraries/legacy/model/model.php | 2 +- tests/core/case/case.php | 4 +- tests/core/case/database.php | 4 +- tests/core/mock/dispatcher.php | 8 +-- .../application/JApplicationBaseTest.php | 8 +-- .../application/JApplicationCliTest.php | 4 +- .../application/JApplicationWebTest.php | 14 ++--- ...ctor.php => JEventDispatcherInspector.php} | 6 +- ...tcherTest.php => JEventDispatcherTest.php} | 62 +++++++++---------- .../unit/joomla/event/JEventInspector.php | 6 +- tests/suites/unit/joomla/event/JEventTest.php | 6 +- .../joomla/language/JLanguageInspector.php | 2 +- .../unit/joomla/user/JAuthenticationTest.php | 8 +-- 28 files changed, 139 insertions(+), 113 deletions(-) create mode 100644 libraries/legacy/dispatcher/dispatcher.php rename tests/suites/unit/joomla/event/{JDispatcherInspector.php => JEventDispatcherInspector.php} (90%) rename tests/suites/unit/joomla/event/{JDispatcherTest.php => JEventDispatcherTest.php} (87%) diff --git a/libraries/joomla/application/base.php b/libraries/joomla/application/base.php index 21eb8024b9..2df3e82233 100644 --- a/libraries/joomla/application/base.php +++ b/libraries/joomla/application/base.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.event.dispatcher'); - /** * Joomla Platform Base Application Class * @@ -23,7 +21,7 @@ abstract class JApplicationBase extends JObject /** * The application dispatcher object. * - * @var JDispatcher + * @var JEventDispatcher * @since 12.1 */ protected $dispatcher; @@ -83,7 +81,7 @@ public function getIdentity() */ public function registerEvent($event, $handler) { - if ($this->dispatcher instanceof JDispatcher) + if ($this->dispatcher instanceof JEventDispatcher) { $this->dispatcher->register($event, $handler); } @@ -103,7 +101,7 @@ public function registerEvent($event, $handler) */ public function triggerEvent($event, array $args = null) { - if ($this->dispatcher instanceof JDispatcher) + if ($this->dispatcher instanceof JEventDispatcher) { return $this->dispatcher->trigger($event, $args); } @@ -118,15 +116,15 @@ public function triggerEvent($event, array $args = null) * but for many applications it will make sense to override this method and create event * dispatchers, if required, based on more specific needs. * - * @param JDispatcher $dispatcher An optional dispatcher object. If omitted, the factory dispatcher is created. + * @param JEventDispatcher $dispatcher An optional dispatcher object. If omitted, the factory dispatcher is created. * * @return JApplicationBase This method is chainable. * * @since 12.1 */ - public function loadDispatcher(JDispatcher $dispatcher = null) + public function loadDispatcher(JEventDispatcher $dispatcher = null) { - $this->dispatcher = ($dispatcher === null) ? JDispatcher::getInstance() : $dispatcher; + $this->dispatcher = ($dispatcher === null) ? JEventDispatcher::getInstance() : $dispatcher; return $this; } diff --git a/libraries/joomla/application/cli.php b/libraries/joomla/application/cli.php index 6813085082..ff5b595078 100644 --- a/libraries/joomla/application/cli.php +++ b/libraries/joomla/application/cli.php @@ -40,14 +40,14 @@ class JApplicationCli extends JApplicationBase * config object. If the argument is a JRegistry object that object will become * the application's config object, otherwise a default config object is created. * @param mixed $dispatcher An optional argument to provide dependency injection for the application's - * event dispatcher. If the argument is a JDispatcher object that object will become + * event dispatcher. If the argument is a JEventDispatcher object that object will become * the application's event dispatcher, if it is null then the default event dispatcher * will be created based on the application's loadDispatcher() method. * * @see loadDispatcher() * @since 11.1 */ - public function __construct(JInputCli $input = null, JRegistry $config = null, JDispatcher $dispatcher = null) + public function __construct(JInputCli $input = null, JRegistry $config = null, JEventDispatcher $dispatcher = null) { // Close the application if we are not executed from the command line. // @codeCoverageIgnoreStart diff --git a/libraries/joomla/application/daemon.php b/libraries/joomla/application/daemon.php index 9fc1a7c961..a9566b9998 100644 --- a/libraries/joomla/application/daemon.php +++ b/libraries/joomla/application/daemon.php @@ -100,14 +100,14 @@ class JApplicationDaemon extends JApplicationCli * config object. If the argument is a JRegistry object that object will become * the application's config object, otherwise a default config object is created. * @param mixed $dispatcher An optional argument to provide dependency injection for the application's - * event dispatcher. If the argument is a JDispatcher object that object will become + * event dispatcher. If the argument is a JEventDispatcher object that object will become * the application's event dispatcher, if it is null then the default event dispatcher * will be created based on the application's loadDispatcher() method. * * @since 11.1 * @throws RuntimeException */ - public function __construct(JInputCli $input = null, JRegistry $config = null, JDispatcher $dispatcher = null) + public function __construct(JInputCli $input = null, JRegistry $config = null, JEventDispatcher $dispatcher = null) { // Verify that the process control extension for PHP is available. // @codeCoverageIgnoreStart diff --git a/libraries/joomla/application/web.php b/libraries/joomla/application/web.php index dd1f772a69..d86f3a309a 100644 --- a/libraries/joomla/application/web.php +++ b/libraries/joomla/application/web.php @@ -195,7 +195,7 @@ public static function getInstance($name = null) * object, and if it is null then the default language object will be created based * on the application's loadLanguage() method. * @param mixed $dispatcher An optional argument to provide dependency injection for the application's - * event dispatcher. If the argument is a JDispatcher object that object will become + * event dispatcher. If the argument is a JEventDispatcher object that object will become * the application's event dispatcher, if it is null then the default event dispatcher * will be created based on the application's loadDispatcher() method. * diff --git a/libraries/joomla/event/dispatcher.php b/libraries/joomla/event/dispatcher.php index f149a94892..c79e75a17f 100644 --- a/libraries/joomla/event/dispatcher.php +++ b/libraries/joomla/event/dispatcher.php @@ -19,9 +19,9 @@ * @subpackage Event * @link http://docs.joomla.org/Tutorial:Plugins Plugin tutorials * @see JPlugin - * @since 11.1 + * @since 12.1 */ -class JDispatcher extends JObject +class JEventDispatcher extends JObject { /** * An array of Observer objects to notify @@ -50,7 +50,7 @@ class JDispatcher extends JObject /** * Stores the singleton instance of the dispatcher. * - * @var JDispatcher + * @var JEventDispatcher * @since 11.3 */ protected static $instance = null; @@ -59,7 +59,7 @@ class JDispatcher extends JObject * Returns the global Event Dispatcher object, only creating it * if it doesn't already exist. * - * @return JDispatcher The EventDispatcher object. + * @return JEventDispatcher The EventDispatcher object. * * @since 11.1 */ @@ -67,14 +67,14 @@ public static function getInstance() { if (self::$instance === null) { - self::$instance = new JDispatcher; + self::$instance = new static; } return self::$instance; } /** - * Get the state of the JDispatcher object + * Get the state of the JEventDispatcher object * * @return mixed The state of the object. * diff --git a/libraries/joomla/html/editor.php b/libraries/joomla/html/editor.php index 8a6b669e34..9d20c600e5 100644 --- a/libraries/joomla/html/editor.php +++ b/libraries/joomla/html/editor.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.event.dispatcher'); - /** * JEditor class to handle WYSIWYG editors * diff --git a/libraries/joomla/html/html/content.php b/libraries/joomla/html/html/content.php index b553f5baf4..7b058fdcc4 100644 --- a/libraries/joomla/html/html/content.php +++ b/libraries/joomla/html/html/content.php @@ -38,7 +38,7 @@ public static function prepare($text, $params = null, $context = 'text') $article = new stdClass; $article->text = $text; JPluginHelper::importPlugin('content'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onContentPrepare', array($context, &$article, &$params, 0)); return $article->text; diff --git a/libraries/joomla/installer/installer.php b/libraries/joomla/installer/installer.php index 35a7bf4d5c..e5883ba363 100644 --- a/libraries/joomla/installer/installer.php +++ b/libraries/joomla/installer/installer.php @@ -436,7 +436,7 @@ public function install($path = null) // Fire the onExtensionBeforeInstall event. JPluginHelper::importPlugin('extension'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger( 'onExtensionBeforeInstall', array('method' => 'install', 'type' => $type, 'manifest' => $this->manifest, 'extension' => 0) @@ -514,7 +514,7 @@ public function discover_install($eid = null) // Fire the onExtensionBeforeInstall event. JPluginHelper::importPlugin('extension'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger( 'onExtensionBeforeInstall', array( @@ -629,7 +629,7 @@ public function update($path = null) // Fire the onExtensionBeforeUpdate event. JPluginHelper::importPlugin('extension'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onExtensionBeforeUpdate', array('type' => $type, 'manifest' => $this->manifest)); // Run the update @@ -681,7 +681,7 @@ public function uninstall($type, $identifier, $cid = 0) // We don't load languages here, we get the extension adapter to work it out // Fire the onExtensionBeforeUninstall event. JPluginHelper::importPlugin('extension'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onExtensionBeforeUninstall', array('eid' => $identifier)); // Run the uninstall diff --git a/libraries/joomla/plugin/helper.php b/libraries/joomla/plugin/helper.php index 717976fb31..1cd1d77fb3 100644 --- a/libraries/joomla/plugin/helper.php +++ b/libraries/joomla/plugin/helper.php @@ -90,16 +90,16 @@ public static function isEnabled($type, $plugin = null) * Loads all the plugin files for a particular type if no specific plugin is specified * otherwise only the specific plugin is loaded. * - * @param string $type The plugin type, relates to the sub-directory in the plugins directory. - * @param string $plugin The plugin name. - * @param boolean $autocreate Autocreate the plugin. - * @param JDispatcher $dispatcher Optionally allows the plugin to use a different dispatcher. + * @param string $type The plugin type, relates to the sub-directory in the plugins directory. + * @param string $plugin The plugin name. + * @param boolean $autocreate Autocreate the plugin. + * @param JEventDispatcher $dispatcher Optionally allows the plugin to use a different dispatcher. * * @return boolean True on success. * * @since 11.1 */ - public static function importPlugin($type, $plugin = null, $autocreate = true, $dispatcher = null) + public static function importPlugin($type, $plugin = null, $autocreate = true, JEventDispatcher $dispatcher = null) { static $loaded = array(); @@ -141,15 +141,15 @@ public static function importPlugin($type, $plugin = null, $autocreate = true, $ /** * Loads the plugin file. * - * @param JPlugin $plugin The plugin. - * @param boolean $autocreate True to autocreate. - * @param JDispatcher $dispatcher Optionally allows the plugin to use a different dispatcher. + * @param JPlugin $plugin The plugin. + * @param boolean $autocreate True to autocreate. + * @param JEventDispatcher $dispatcher Optionally allows the plugin to use a different dispatcher. * * @return boolean True on success. * * @since 11.1 */ - protected static function _import($plugin, $autocreate = true, $dispatcher = null) + protected static function _import($plugin, $autocreate = true, JEventDispatcher $dispatcher = null) { static $paths = array(); @@ -177,7 +177,7 @@ protected static function _import($plugin, $autocreate = true, $dispatcher = nul // Makes sure we have an event dispatcher if (!is_object($dispatcher)) { - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); } $className = 'plg' . $plugin->type . $plugin->name; diff --git a/libraries/joomla/user/authentication.php b/libraries/joomla/user/authentication.php index 9416add511..5ffeae7126 100644 --- a/libraries/joomla/user/authentication.php +++ b/libraries/joomla/user/authentication.php @@ -9,8 +9,6 @@ defined('JPATH_PLATFORM') or die; -jimport('joomla.event.dispatcher'); - /** * Authentication class, provides an interface for the Joomla authentication system * @@ -331,7 +329,7 @@ public static function authorise($response, $options = array()) // Get plugins in case they haven't been loaded already JPluginHelper::getPlugin('user'); JPluginHelper::getPlugin('authentication'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onUserAuthorisation', array($response, $options)); return $results; } diff --git a/libraries/joomla/user/helper.php b/libraries/joomla/user/helper.php index eba1d9bd58..9223daaf05 100644 --- a/libraries/joomla/user/helper.php +++ b/libraries/joomla/user/helper.php @@ -202,7 +202,7 @@ public function getProfile($userId = 0) } // Get the dispatcher and load the user's plugins. - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); JPluginHelper::importPlugin('user'); $data = new JObject; diff --git a/libraries/joomla/user/user.php b/libraries/joomla/user/user.php index 0034692057..d34c8ebbd8 100644 --- a/libraries/joomla/user/user.php +++ b/libraries/joomla/user/user.php @@ -708,7 +708,7 @@ public function save($updateOnly = false) // Fire the onUserBeforeSave event. JPluginHelper::importPlugin('user'); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $result = $dispatcher->trigger('onUserBeforeSave', array($oldUser->getProperties(), $isNew, $this->getProperties())); if (in_array(false, $result, true)) @@ -758,7 +758,7 @@ public function delete() JPluginHelper::importPlugin('user'); // Trigger the onUserBeforeDelete event - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $dispatcher->trigger('onUserBeforeDelete', array($this->getProperties())); // Create the user table object diff --git a/libraries/legacy/dispatcher/dispatcher.php b/libraries/legacy/dispatcher/dispatcher.php new file mode 100644 index 0000000000..0aa3e5f5ab --- /dev/null +++ b/libraries/legacy/dispatcher/dispatcher.php @@ -0,0 +1,32 @@ +getTable(); @@ -834,7 +834,7 @@ protected function prepareTable($table) public function publish(&$pks, $value = 1) { // Initialise variables. - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $user = JFactory::getUser(); $table = $this->getTable(); $pks = (array) $pks; @@ -968,7 +968,7 @@ public function reorder($pks, $delta = 0) public function save($data) { // Initialise variables; - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $table = $this->getTable(); $key = $table->getKeyName(); $pk = (!empty($data[$key])) ? $data[$key] : (int) $this->getState($this->getName() . '.id'); diff --git a/libraries/legacy/model/form.php b/libraries/legacy/model/form.php index 82e845bebd..19421a0a50 100644 --- a/libraries/legacy/model/form.php +++ b/libraries/legacy/model/form.php @@ -222,7 +222,7 @@ protected function preprocessForm(JForm $form, $data, $group = 'content') JPluginHelper::importPlugin($group); // Get the dispatcher. - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); // Trigger the form preparation event. $results = $dispatcher->trigger('onContentPrepareForm', array($form, $data)); diff --git a/libraries/legacy/model/model.php b/libraries/legacy/model/model.php index 331ef18e6d..df3f00cacf 100644 --- a/libraries/legacy/model/model.php +++ b/libraries/legacy/model/model.php @@ -493,7 +493,7 @@ protected function cleanCache($group = null, $client_id = 0) { // Initialise variables; $conf = JFactory::getConfig(); - $dispatcher = JDispatcher::getInstance(); + $dispatcher = JEventDispatcher::getInstance(); $options = array( 'defaultgroup' => ($group) ? $group : (isset($this->option) ? $this->option : JFactory::getApplication()->input->get('option')), diff --git a/tests/core/case/case.php b/tests/core/case/case.php index d314532c8c..fcdfe0696b 100644 --- a/tests/core/case/case.php +++ b/tests/core/case/case.php @@ -197,14 +197,14 @@ class_exists('JDatabaseDriver'); * * @param boolean $defaults Add default register and trigger methods for testing. * - * @return JDispatcher + * @return JEventDispatcher * * @since 12.1 */ public function getMockDispatcher($defaults = true) { // Attempt to load the real class first. - class_exists('JDispatcher'); + class_exists('JEventDispatcher'); return TestMockDispatcher::create($this, $defaults); } diff --git a/tests/core/case/database.php b/tests/core/case/database.php index bc985fa4cd..1f3b6e18c8 100644 --- a/tests/core/case/database.php +++ b/tests/core/case/database.php @@ -224,14 +224,14 @@ class_exists('JDatabaseDriver'); * * @param boolean $defaults Add default register and trigger methods for testing. * - * @return JDispatcher + * @return JEventDispatcher * * @since 12.1 */ public function getMockDispatcher($defaults = true) { // Attempt to load the real class first. - class_exists('JDispatcher'); + class_exists('JEventDispatcher'); return TestMockDispatcher::create($this, $defaults); } diff --git a/tests/core/mock/dispatcher.php b/tests/core/mock/dispatcher.php index aec6cd6075..6a4aff617e 100644 --- a/tests/core/mock/dispatcher.php +++ b/tests/core/mock/dispatcher.php @@ -7,7 +7,7 @@ */ /** - * Class to mock JDispatcher. + * Class to mock JEventDispatcher. * * @package Joomla.Test * @since 12.1 @@ -54,7 +54,7 @@ public static function create($test, $defaults = true) // Create the mock. $mockObject = $test->getMock( - 'JDispatcher', + 'JEventDispatcher', $methods, // Constructor arguments. array(), @@ -88,7 +88,7 @@ public static function create($test, $defaults = true) } /** - * Callback for the JDispatcher register method. + * Callback for the JEventDispatcher register method. * * @param string $event Name of the event to register handler for. * @param string $handler Name of the event handler. @@ -109,7 +109,7 @@ public function mockRegister($event, $handler, $return = null) } /** - * Callback for the JDispatcher trigger method. + * Callback for the JEventDispatcher trigger method. * * @param string $event The event to trigger. * @param array $args An array of arguments. diff --git a/tests/suites/unit/joomla/application/JApplicationBaseTest.php b/tests/suites/unit/joomla/application/JApplicationBaseTest.php index 1f86056b27..05a5689089 100644 --- a/tests/suites/unit/joomla/application/JApplicationBaseTest.php +++ b/tests/suites/unit/joomla/application/JApplicationBaseTest.php @@ -52,7 +52,7 @@ public function setUp() protected function tearDown() { // Reset the dispatcher instance. - TestReflection::setValue('JDispatcher', 'instance', null); + TestReflection::setValue('JEventDispatcher', 'instance', null); parent::tearDown(); } @@ -70,14 +70,14 @@ public function testLoadDispatcher() $this->class->loadDispatcher($this->getMockDispatcher()); $this->assertAttributeInstanceOf( - 'JDispatcher', + 'JEventDispatcher', 'dispatcher', $this->class, 'Tests that the dispatcher object is the correct class.' ); - // Inject a mock value into the JDispatcher singleton. - TestReflection::setValue('JDispatcher', 'instance', 'foo'); + // Inject a mock value into the JEventDispatcher singleton. + TestReflection::setValue('JEventDispatcher', 'instance', 'foo'); $this->class->loadDispatcher(); $this->assertEquals('foo', TestReflection::getValue($this->class, 'dispatcher'), 'Tests that we got the dispatcher from the factory.'); diff --git a/tests/suites/unit/joomla/application/JApplicationCliTest.php b/tests/suites/unit/joomla/application/JApplicationCliTest.php index 01afe2c064..95ed0359c1 100644 --- a/tests/suites/unit/joomla/application/JApplicationCliTest.php +++ b/tests/suites/unit/joomla/application/JApplicationCliTest.php @@ -52,7 +52,7 @@ public function setUp() protected function tearDown() { // Reset the dispatcher instance. - TestReflection::setValue('JDispatcher', 'instance', null); + TestReflection::setValue('JEventDispatcher', 'instance', null); parent::tearDown(); } @@ -70,7 +70,7 @@ public function test__construct() $this->assertAttributeInstanceOf('JRegistry', 'config', $this->class, 'Checks config property'); - $this->assertAttributeInstanceOf('JDispatcher', 'dispatcher', $this->class, 'Checks dispatcher property'); + $this->assertAttributeInstanceOf('JEventDispatcher', 'dispatcher', $this->class, 'Checks dispatcher property'); // TODO Test that configuration data loaded. diff --git a/tests/suites/unit/joomla/application/JApplicationWebTest.php b/tests/suites/unit/joomla/application/JApplicationWebTest.php index f29508a540..d5634005bd 100644 --- a/tests/suites/unit/joomla/application/JApplicationWebTest.php +++ b/tests/suites/unit/joomla/application/JApplicationWebTest.php @@ -122,7 +122,7 @@ public function setUp() protected function tearDown() { // Reset the dispatcher instance. - TestReflection::setValue('JDispatcher', 'instance', null); + TestReflection::setValue('JEventDispatcher', 'instance', null); // Reset some web inspector static settings. JApplicationWebInspector::$headersSent = false; @@ -963,7 +963,7 @@ public function testInitialiseWithDefaults() ); $this->assertInstanceOf( - 'JDispatcher', + 'JEventDispatcher', TestReflection::getValue($this->class, 'dispatcher'), 'Test that deafult dispatcher was initialised.' ); @@ -1032,12 +1032,12 @@ public function testInitialiseWithInjection() $this->returnValue('JLanguage') ); - $mockDispatcher = $this->getMock('JDispatcher', array('test'), array(), '', false); + $mockDispatcher = $this->getMock('JEventDispatcher', array('test'), array(), '', false); $mockDispatcher ->expects($this->any()) ->method('test') ->will( - $this->returnValue('JDispatcher') + $this->returnValue('JEventDispatcher') ); $this->class->initialise($mockSession, $mockDocument, $mockLanguage, $mockDispatcher); @@ -1062,7 +1062,7 @@ public function testInitialiseWithInjection() $this->assertThat( TestReflection::getValue($this->class, 'dispatcher')->test(), - $this->equalTo('JDispatcher'), + $this->equalTo('JEventDispatcher'), 'Tests dispatcher injection.' ); } @@ -1114,8 +1114,8 @@ public function testLoadConfiguration() */ public function testLoadDocument() { - // Inject the mock dispatcher into the JDispatcher singleton. - TestReflection::setValue('JDispatcher', 'instance', $this->getMockDispatcher()); + // Inject the mock dispatcher into the JEventDispatcher singleton. + TestReflection::setValue('JEventDispatcher', 'instance', $this->getMockDispatcher()); $this->class->loadDocument(); diff --git a/tests/suites/unit/joomla/event/JDispatcherInspector.php b/tests/suites/unit/joomla/event/JEventDispatcherInspector.php similarity index 90% rename from tests/suites/unit/joomla/event/JDispatcherInspector.php rename to tests/suites/unit/joomla/event/JEventDispatcherInspector.php index aa1f37bf7f..9691af13fb 100644 --- a/tests/suites/unit/joomla/event/JDispatcherInspector.php +++ b/tests/suites/unit/joomla/event/JEventDispatcherInspector.php @@ -9,13 +9,13 @@ require_once JPATH_PLATFORM.'/joomla/event/dispatcher.php'; /** - * Inspector for the JDispatcher class. + * Inspector for the JEventDispatcher class. * * @package Joomla.UnitTest * @subpackage Event * @since 11.3 */ -class JDispatcherInspector extends JDispatcher +class JEventDispatcherInspector extends JEventDispatcher { /** * Method for inspecting protected variables. @@ -61,7 +61,7 @@ public function __call($name, $parameters = false) /** * Allows the internal singleton to be set and mocked. * - * @param JDispatcher $instance A dispatcher object. + * @param JEventDispatcher $instance A dispatcher object. * * @return void * diff --git a/tests/suites/unit/joomla/event/JDispatcherTest.php b/tests/suites/unit/joomla/event/JEventDispatcherTest.php similarity index 87% rename from tests/suites/unit/joomla/event/JDispatcherTest.php rename to tests/suites/unit/joomla/event/JEventDispatcherTest.php index 5115e0b6d0..7208d51916 100644 --- a/tests/suites/unit/joomla/event/JDispatcherTest.php +++ b/tests/suites/unit/joomla/event/JEventDispatcherTest.php @@ -7,21 +7,20 @@ * @license GNU General Public License version 2 or later; see LICENSE */ -require_once __DIR__ . '/JDispatcherInspector.php'; +require_once __DIR__ . '/JEventDispatcherInspector.php'; require_once __DIR__ . '/JEventInspector.php'; -jimport('joomla.plugin.plugin'); /** - * Test class for JDispatcher. + * Test class for JEventDispatcher. * * @package Joomla.UnitTest * @subpackage Event * @since 11.3 */ -class JDispatcherTest extends PHPUnit_Framework_TestCase +class JEventDispatcherTest extends PHPUnit_Framework_TestCase { /** - * @var JDispatcher + * @var JEventDispatcher */ protected $object; @@ -31,7 +30,7 @@ class JDispatcherTest extends PHPUnit_Framework_TestCase */ protected function setUp() { - $this->object = new JDispatcherInspector; + $this->object = new JEventDispatcherInspector; $this->object->setInstance($this->object); } @@ -45,51 +44,51 @@ protected function tearDown() } /** - * Tests the JDispatcher::getInstance method. + * Tests the JEventDispatcher::getInstance method. * * @return void * * @since 11.3 - * @covers JDispatcher::getInstance + * @covers JEventDispatcher::getInstance */ public function testGetInstance() { - $mock = JDispatcher::getInstance(); + $mock = JEventDispatcher::getInstance(); $this->assertInstanceOf( - 'JDispatcherInspector', + 'JEventDispatcherInspector', $mock ); $this->object->setInstance(null); - $instance = JDispatcher::getInstance(); + $instance = JEventDispatcher::getInstance(); $this->assertInstanceOf( - 'JDispatcher', + 'JEventDispatcher', $instance, - 'Tests that getInstance returns a JDispatcher object.' + 'Tests that getInstance returns a JEventDispatcher object.' ); // Push a new instance into the class. - JDispatcherInspector::setInstance('foo'); + JEventDispatcherInspector::setInstance('foo'); $this->assertThat( - JDispatcher::getInstance(), + JEventDispatcher::getInstance(), $this->equalTo('foo'), - 'Tests that a subsequent call to JDispatcher::getInstance returns the cached singleton.' + 'Tests that a subsequent call to JEventDispatcher::getInstance returns the cached singleton.' ); - JDispatcherInspector::setInstance($mock); + JEventDispatcherInspector::setInstance($mock); } /** - * Test JDispatcher::getState(). + * Test JEventDispatcher::getState(). * * @return void * * @since 11.3 - * @covers JDispatcher::getState + * @covers JEventDispatcher::getState */ public function testGetState() { @@ -107,10 +106,10 @@ public function testGetState() } /** - * Test JDispatcher::register(). + * Test JEventDispatcher::register(). * * @since 11.3 - * @covers JDispatcher::register + * @covers JEventDispatcher::register */ public function testRegister() { @@ -196,11 +195,11 @@ public function testRegister() } /** - * Test JDispatcher::register() with an error. + * Test JEventDispatcher::register() with an error. * * @since 12.1 * @expectedException InvalidArgumentException - * @covers JDispatcher::register + * @covers JEventDispatcher::register */ public function testRegisterException() { @@ -208,9 +207,10 @@ public function testRegisterException() } /** - * Test JDispatcher::trigger(). + * Test JEventDispatcher::trigger(). * - * @since 11.3 + * @since 11.3 + * @covers JEventDispatcher::trigger */ public function testTrigger() { @@ -228,7 +228,7 @@ public function testTrigger() $this->object->trigger('onTestEvent'), $this->equalTo( array( - 'JDispatcherMockFunction executed', + 'JEventDispatcherMockFunction executed', '' ) ) @@ -239,7 +239,7 @@ public function testTrigger() $this->object->trigger('onTestEvent', array('one', 'two')), $this->equalTo( array( - 'JDispatcherMockFunction executed', + 'JEventDispatcherMockFunction executed', 'onetwo' ) ) @@ -255,10 +255,10 @@ public function testTrigger() } /** - * Test JDispatcher::attach(). + * Test JEventDispatcher::attach(). * * @since 11.3 - * @covers JDispatcher::attach + * @covers JEventDispatcher::attach */ public function testAttach() { @@ -394,10 +394,10 @@ public function testAttach() } /** - * Test JDispatcher::detach(). + * Test JEventDispatcher::detach(). * * @since 11.3 - * @covers JDispatcher::detach + * @covers JEventDispatcher::detach */ public function testDetach() { diff --git a/tests/suites/unit/joomla/event/JEventInspector.php b/tests/suites/unit/joomla/event/JEventInspector.php index 4ec8608248..0f83f46c01 100644 --- a/tests/suites/unit/joomla/event/JEventInspector.php +++ b/tests/suites/unit/joomla/event/JEventInspector.php @@ -54,13 +54,13 @@ public function onTestEvent($var1 = null, $var2 = null) } /** - * Mock function to test event system in JDispatcher + * Mock function to test event system in JEventDispatcher * - * @return string Static string "JDispatcherMockFunction executed" + * @return string Static string "JEventDispatcherMockFunction executed" * * @since 11.3 */ function JEventMockFunction() { - return 'JDispatcherMockFunction executed'; + return 'JEventDispatcherMockFunction executed'; } \ No newline at end of file diff --git a/tests/suites/unit/joomla/event/JEventTest.php b/tests/suites/unit/joomla/event/JEventTest.php index 9f2f44eef7..7ceb2cae2b 100644 --- a/tests/suites/unit/joomla/event/JEventTest.php +++ b/tests/suites/unit/joomla/event/JEventTest.php @@ -8,7 +8,7 @@ */ require_once __DIR__ . '/JEventInspector.php'; -require_once __DIR__ . '/JDispatcherInspector.php'; +require_once __DIR__ . '/JEventDispatcherInspector.php'; /** * Test class for JEvent. @@ -26,7 +26,7 @@ class JEventTest extends PHPUnit_Framework_TestCase */ public function test__construct() { - $dispatcher = new JDispatcherInspector(); + $dispatcher = new JEventDispatcherInspector(); $event = new JEventInspector($dispatcher); $this->assertThat( @@ -42,7 +42,7 @@ public function test__construct() */ public function testUpdate() { - $dispatcher = new JDispatcherInspector(); + $dispatcher = new JEventDispatcherInspector(); $event = new JEventInspector($dispatcher); $args = array('event' => 'onTestEvent'); diff --git a/tests/suites/unit/joomla/language/JLanguageInspector.php b/tests/suites/unit/joomla/language/JLanguageInspector.php index deae124493..36b9fbd5e7 100644 --- a/tests/suites/unit/joomla/language/JLanguageInspector.php +++ b/tests/suites/unit/joomla/language/JLanguageInspector.php @@ -61,7 +61,7 @@ public function __call($name, $parameters = false) /** * Allows the internal singleton to be set and mocked. * - * @param JDispatcher $instance A dispatcher object. + * @param JLanguage $instance A language object. * * @return void * diff --git a/tests/suites/unit/joomla/user/JAuthenticationTest.php b/tests/suites/unit/joomla/user/JAuthenticationTest.php index 889830aef3..894c58fd5d 100644 --- a/tests/suites/unit/joomla/user/JAuthenticationTest.php +++ b/tests/suites/unit/joomla/user/JAuthenticationTest.php @@ -48,8 +48,8 @@ protected function setUp() ) ); - // Inject the mock dispatcher into the JDispatcher singleton. - TestReflection::setValue('JDispatcher', 'instance', $dispatcher); + // Inject the mock dispatcher into the JEventDispatcher singleton. + TestReflection::setValue('JEventDispatcher', 'instance', $dispatcher); // Mock the authentication plugin require_once __DIR__.'/stubs/FakeAuthenticationPlugin.php'; @@ -75,7 +75,7 @@ protected function setUp() protected function tearDown() { // Reset the dispatcher instance. - TestReflection::setValue('JDispatcher', 'instance', null); + TestReflection::setValue('JEventDispatcher', 'instance', null); // Reset the loaded plugins. TestReflection::setValue('JPluginHelper', 'plugins', null); @@ -84,7 +84,7 @@ protected function tearDown() } /** - * Callback for the JDispatcher trigger method. + * Callback for the JEventDispatcher trigger method. * * @param string $event The event to trigger. * @param array $args An array of arguments. From 78677f909f0c4dcf82e6b2e5f869e82310955bad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Mon, 9 Apr 2012 22:28:19 +0200 Subject: [PATCH 91/98] Move JDate to its own package to make it autoloadable. --- libraries/joomla/{utilities => date}/date.php | 4 ++-- libraries/joomla/factory.php | 1 - libraries/joomla/log/entry.php | 2 -- .../joomla/{utilities => date}/JDateTest.php | 20 +++++++++++++++---- 4 files changed, 18 insertions(+), 9 deletions(-) rename libraries/joomla/{utilities => date}/date.php (99%) rename tests/suites/unit/joomla/{utilities => date}/JDateTest.php (97%) diff --git a/libraries/joomla/utilities/date.php b/libraries/joomla/date/date.php similarity index 99% rename from libraries/joomla/utilities/date.php rename to libraries/joomla/date/date.php index 31275e4ee0..b5b6d5a78b 100644 --- a/libraries/joomla/utilities/date.php +++ b/libraries/joomla/date/date.php @@ -1,7 +1,7 @@ Date: Mon, 9 Apr 2012 22:33:10 +0200 Subject: [PATCH 92/98] Move Simplecrypt to legacy and make it autoloadable. --- libraries/import.legacy.php | 1 + libraries/legacy/application/application.php | 2 -- .../utilities => legacy/simplecrypt}/simplecrypt.php | 8 ++++---- .../simplecrypt}/JSimpleCryptTest.php | 10 ++++++---- 4 files changed, 11 insertions(+), 10 deletions(-) rename libraries/{joomla/utilities => legacy/simplecrypt}/simplecrypt.php (93%) rename tests/suites/{unit/joomla/utilities => legacy/simplecrypt}/JSimpleCryptTest.php (94%) diff --git a/libraries/import.legacy.php b/libraries/import.legacy.php index b8db2cb167..5be8c7ab5c 100644 --- a/libraries/import.legacy.php +++ b/libraries/import.legacy.php @@ -61,5 +61,6 @@ class_exists('JLoader') or die; JLoader::register('JDatabaseQuerySQLAzure', JPATH_PLATFORM . '/joomla/database/query/sqlazure.php'); JLoader::register('JDatabaseQuerySQLSrv', JPATH_PLATFORM . '/joomla/database/query/sqlsrv.php'); JLoader::register('JToolBar', JPATH_PLATFORM . '/legacy/toolbar/toolbar.php'); +JLoader::register('JSimpleCrypt', JPATH_PLATFORM . '/legacy/simplecrypt/simplecrypt.php'); JLoader::register('JTree', JPATH_PLATFORM . '/legacy/base/tree.php'); JLoader::register('JNode', JPATH_PLATFORM . '/legacy/base/node.php'); diff --git a/libraries/legacy/application/application.php b/libraries/legacy/application/application.php index a827a74373..dce5aa93df 100644 --- a/libraries/legacy/application/application.php +++ b/libraries/legacy/application/application.php @@ -668,8 +668,6 @@ public function login($credentials, $options = array()) // Set the remember me cookie if enabled. if (isset($options['remember']) && $options['remember']) { - jimport('joomla.utilities.simplecrypt'); - // Create the encryption key, apply extra hardening using the user agent string. $key = self::getHash(@$_SERVER['HTTP_USER_AGENT']); diff --git a/libraries/joomla/utilities/simplecrypt.php b/libraries/legacy/simplecrypt/simplecrypt.php similarity index 93% rename from libraries/joomla/utilities/simplecrypt.php rename to libraries/legacy/simplecrypt/simplecrypt.php index cadbf64425..9ddc6191ae 100644 --- a/libraries/joomla/utilities/simplecrypt.php +++ b/libraries/legacy/simplecrypt/simplecrypt.php @@ -1,7 +1,7 @@ Date: Sat, 14 Apr 2012 06:00:33 -0300 Subject: [PATCH 93/98] Fix up JForm docblocks --- libraries/joomla/form/form.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libraries/joomla/form/form.php b/libraries/joomla/form/form.php index 49ffcb0bed..70a8465908 100644 --- a/libraries/joomla/form/form.php +++ b/libraries/joomla/form/form.php @@ -502,7 +502,7 @@ public function getFormControl() * * @param string $group The dot-separated form group path for which to get the form fields. * @param boolean $nested True to also include fields in nested groups that are inside of the - * group for which to find fields. + * group for which to find fields. * * @return array The array of JFormField objects in the field group. * @@ -1051,7 +1051,7 @@ public function setValue($name, $group = null, $value = null) * * @param array $data An array of field values to validate. * @param string $group The optional dot-separated form group path on which to filter the - * fields to be validated. + * fields to be validated. * * @return mixed True on sucess. * @@ -1491,9 +1491,9 @@ protected function &findFieldsByFieldset($name) * in a control group by name. * * @param mixed $group The optional dot-separated form group path on which to find the fields. - * Null will return all fields. False will return fields not in a group. + * Null will return all fields. False will return fields not in a group. * @param boolean $nested True to also include fields in nested groups that are inside of the - * group for which to find fields. + * group for which to find fields. * * @return mixed Boolean false on error or array of SimpleXMLElement objects. * @@ -1943,7 +1943,7 @@ public static function addRulePath($new = null) * @param string $data The name of an XML file or string to load as the form definition. * @param array $options An array of form options. * @param string $replace Flag to toggle whether form fields should be replaced if a field - * already exists with the same group/name. + * already exists with the same group/name. * @param string $xpath An optional xpath to search for the fields. * * @return object JForm instance. From 20c41818223a54dcc88d1fa0bd2512931fc87289 Mon Sep 17 00:00:00 2001 From: Michael Babker Date: Sat, 14 Apr 2012 14:24:20 +0200 Subject: [PATCH 94/98] Allow media field to be disabled fully --- libraries/legacy/form/field/media.php | 43 ++++++++++++++------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/libraries/legacy/form/field/media.php b/libraries/legacy/form/field/media.php index e7c34f6f6c..e2e04a5aff 100644 --- a/libraries/legacy/form/field/media.php +++ b/libraries/legacy/form/field/media.php @@ -113,27 +113,30 @@ protected function getInput() $folder = ''; } // The button. - $html[] = '
    '; - $html[] = ' '; - $html[] = '
    '; + if ($this->element['disabled'] != true) + { + $html[] = '
    '; + $html[] = ' '; + $html[] = '
    '; - $html[] = '
    '; - $html[] = ' '; - $html[] = '
    '; + $html[] = '
    '; + $html[] = ' '; + $html[] = '
    '; + } return implode("\n", $html); } From 11c62fe6210c39c8d39abe95e064f61211c22a2a Mon Sep 17 00:00:00 2001 From: Buddhima Wijeweera Date: Sun, 15 Apr 2012 10:12:10 +0530 Subject: [PATCH 95/98] white spaces on 3 lines removed --- libraries/joomla/image/image.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/joomla/image/image.php b/libraries/joomla/image/image.php index 371f969170..7a8206081d 100644 --- a/libraries/joomla/image/image.php +++ b/libraries/joomla/image/image.php @@ -673,20 +673,20 @@ protected function prepareDimensions($width, $height, $scaleMethod) case self::SCALE_INSIDE: case self::SCALE_OUTSIDE: - + // Both $height or $width cannot be zero if ($width == 0 || $height == 0) { throw new InvalidArgumentException(' Width or height cannot be zero with this scale method '); } - + // If both $width and $height are not equals to zero else { $rx = $this->getWidth() / $width; $ry = $this->getHeight() / $height; } - + if ($scaleMethod == self::SCALE_INSIDE) { $ratio = ($rx > $ry) ? $rx : $ry; From 6addcd50e2bc7f4841b56615f1ea7e0b63c86561 Mon Sep 17 00:00:00 2001 From: Louis Landry Date: Sun, 15 Apr 2012 12:19:55 -0700 Subject: [PATCH 96/98] Removing unnecessary dependency from View package. --- libraries/joomla/view/base.php | 14 ++------------ libraries/joomla/view/html.php | 9 ++++----- .../mock/controller.php} | 15 ++++++++------- tests/suites/unit/joomla/view/JViewBaseTest.php | 5 +---- tests/suites/unit/joomla/view/JViewHtmlTest.php | 7 ++----- 5 files changed, 17 insertions(+), 33 deletions(-) rename tests/{suites/unit/joomla/view/mocks/JControllerMock.php => core/mock/controller.php} (72%) diff --git a/libraries/joomla/view/base.php b/libraries/joomla/view/base.php index 31092aab9a..bc70bca109 100644 --- a/libraries/joomla/view/base.php +++ b/libraries/joomla/view/base.php @@ -18,14 +18,6 @@ */ abstract class JViewBase implements JView { - /** - * The controller object. - * - * @var JController - * @since 12.1 - */ - protected $controller; - /** * The model object. * @@ -37,16 +29,14 @@ abstract class JViewBase implements JView /** * Method to instantiate the view. * - * @param JModel $model The model object. - * @param JController $controller The controller object. + * @param JModel $model The model object. * * @since 12.1 */ - public function __construct(JModel $model, JController $controller) + public function __construct(JModel $model) { // Setup dependencies. $this->model = $model; - $this->controller = $controller; } /** diff --git a/libraries/joomla/view/html.php b/libraries/joomla/view/html.php index 332f5b4a8f..cbb2ec8b27 100644 --- a/libraries/joomla/view/html.php +++ b/libraries/joomla/view/html.php @@ -39,15 +39,14 @@ abstract class JViewHtml extends JViewBase /** * Method to instantiate the view. * - * @param JModel $model The model object. - * @param JController $controller The controller object. - * @param SplPriorityQueue $paths The paths queue. + * @param JModel $model The model object. + * @param SplPriorityQueue $paths The paths queue. * * @since 12.1 */ - public function __construct(JModel $model, JController $controller, SplPriorityQueue $paths = null) + public function __construct(JModel $model, SplPriorityQueue $paths = null) { - parent::__construct($model, $controller); + parent::__construct($model); // Setup dependencies. $this->paths = isset($paths) ? $paths : $this->loadPaths(); diff --git a/tests/suites/unit/joomla/view/mocks/JControllerMock.php b/tests/core/mock/controller.php similarity index 72% rename from tests/suites/unit/joomla/view/mocks/JControllerMock.php rename to tests/core/mock/controller.php index ea6ab8f739..bc541ccc58 100644 --- a/tests/suites/unit/joomla/view/mocks/JControllerMock.php +++ b/tests/core/mock/controller.php @@ -1,17 +1,18 @@ assertAttributeInstanceOf('JModel', 'model', $this->_instance); - $this->assertAttributeInstanceOf('JController', 'controller', $this->_instance); } /** @@ -65,8 +63,7 @@ protected function setUp() parent::setUp(); $model = JModelMock::create($this); - $controller = JControllerMock::create($this); - $this->_instance = new BaseView($model, $controller); + $this->_instance = new BaseView($model); } } diff --git a/tests/suites/unit/joomla/view/JViewHtmlTest.php b/tests/suites/unit/joomla/view/JViewHtmlTest.php index ea3ef9df0c..4873e1c6c0 100644 --- a/tests/suites/unit/joomla/view/JViewHtmlTest.php +++ b/tests/suites/unit/joomla/view/JViewHtmlTest.php @@ -8,7 +8,6 @@ */ JLoader::register('HtmlView', __DIR__ . '/stubs/thtml.php'); -JLoader::register('JControllerMock', __DIR__ . '/mocks/JControllerMock.php'); JLoader::register('JModelMock', __DIR__ . '/mocks/JModelMock.php'); /** @@ -39,11 +38,10 @@ public function test__construct() $this->assertAttributeEquals(new SplPriorityQueue, 'paths', $this->_instance, 'Check default paths.'); $model = JModelMock::create($this); - $controller = JControllerMock::create($this); $paths = new SplPriorityQueue; $paths->insert('foo', 1); - $this->_instance = new HtmlView($model, $controller, $paths); + $this->_instance = new HtmlView($model, $paths); $this->assertAttributeSame($paths, 'paths', $this->_instance, 'Check default paths.'); } @@ -207,8 +205,7 @@ protected function setUp() parent::setUp(); $model = JModelMock::create($this); - $controller = JControllerMock::create($this); - $this->_instance = new HtmlView($model, $controller); + $this->_instance = new HtmlView($model); } } From bc72fe144fc686315042e837286e7b87aa9e7c01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Tue, 17 Apr 2012 19:35:48 +0200 Subject: [PATCH 97/98] Move remaining code from JDatabase to JDatabaseDriver. --- libraries/joomla/base/adapter.php | 4 ++-- libraries/joomla/database/driver.php | 8 ++++---- libraries/joomla/database/driver/mysql.php | 2 +- libraries/joomla/database/driver/oracle.php | 6 +++--- .../joomla/database/driver/postgresql.php | 6 +++--- libraries/joomla/database/driver/sqlite.php | 6 +++--- libraries/joomla/database/driver/sqlsrv.php | 6 +++--- libraries/joomla/date/date.php | 6 +++--- libraries/joomla/log/loggers/database.php | 20 ++++--------------- .../log/loggers/JLoggerDatabaseTest.php | 2 +- 10 files changed, 27 insertions(+), 39 deletions(-) diff --git a/libraries/joomla/base/adapter.php b/libraries/joomla/base/adapter.php index 4c5739c36e..e3d6915952 100644 --- a/libraries/joomla/base/adapter.php +++ b/libraries/joomla/base/adapter.php @@ -55,7 +55,7 @@ class JAdapter extends JObject /** * Database Connector Object * - * @var JDatabase + * @var JDatabaseDriver * @since 11.1 */ protected $_db; @@ -81,7 +81,7 @@ public function __construct($basepath, $classprefix = null, $adapterfolder = nul /** * Get the database connector object * - * @return JDatabase Database connector object + * @return JDatabaseDriver Database connector object * * @since 11.1 */ diff --git a/libraries/joomla/database/driver.php b/libraries/joomla/database/driver.php index 384e413b39..6ef4794e1f 100644 --- a/libraries/joomla/database/driver.php +++ b/libraries/joomla/database/driver.php @@ -402,7 +402,7 @@ abstract public function connected(); * @param string $table The name of the database table to drop. * @param boolean $ifExists Optionally specify that the table must exist before it is dropped. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriver Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException @@ -1260,7 +1260,7 @@ public function loadRowList($key = null) * * @param string $tableName The name of the table to unlock. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriver Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException @@ -1471,7 +1471,7 @@ public function replacePrefix($sql, $prefix = '#__') * @param string $backup Table prefix * @param string $prefix For the table - used to rename constraints in non-mysql databases * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriver Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException @@ -1668,7 +1668,7 @@ abstract public function execute(); /** * Unlocks tables in the database. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriver Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException diff --git a/libraries/joomla/database/driver/mysql.php b/libraries/joomla/database/driver/mysql.php index 74da36e024..bbe9ef8177 100644 --- a/libraries/joomla/database/driver/mysql.php +++ b/libraries/joomla/database/driver/mysql.php @@ -501,7 +501,7 @@ public function execute() * @param string $backup Not used by MySQL. * @param string $prefix Not used by MySQL. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverMysql Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException diff --git a/libraries/joomla/database/driver/oracle.php b/libraries/joomla/database/driver/oracle.php index 82358a0dbc..43fefa12bb 100644 --- a/libraries/joomla/database/driver/oracle.php +++ b/libraries/joomla/database/driver/oracle.php @@ -411,7 +411,7 @@ public function setUTF() * * @param string $table The name of the table to unlock. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverOracle Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -431,7 +431,7 @@ public function lockTable($table) * @param string $backup Not used by Oracle. * @param string $prefix Not used by Oracle. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverOracle Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -446,7 +446,7 @@ public function renameTable($oldTable, $newTable, $backup = null, $prefix = null /** * Unlocks tables in the database. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverOracle Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException diff --git a/libraries/joomla/database/driver/postgresql.php b/libraries/joomla/database/driver/postgresql.php index 0ac5fc8dbd..1a8afedbc0 100644 --- a/libraries/joomla/database/driver/postgresql.php +++ b/libraries/joomla/database/driver/postgresql.php @@ -556,7 +556,7 @@ public function insertid() * * @param string $tableName The name of the table to unlock. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverPostgresql Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException @@ -662,7 +662,7 @@ public function execute() * @param string $backup Not used by PostgreSQL. * @param string $prefix Not used by PostgreSQL. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverPostgresql Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException @@ -1148,7 +1148,7 @@ public function transactionSavepoint( $savepointName ) * Unlocks tables in the database, this command does not exist in PostgreSQL, * it is automatically done on commit or rollback. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverPostgresql Returns this object to support chaining. * * @since 11.4 * @throws RuntimeException diff --git a/libraries/joomla/database/driver/sqlite.php b/libraries/joomla/database/driver/sqlite.php index 2da29f1cbd..69d07964a3 100644 --- a/libraries/joomla/database/driver/sqlite.php +++ b/libraries/joomla/database/driver/sqlite.php @@ -325,7 +325,7 @@ public function setUTF() * * @param string $table The name of the table to unlock. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlite Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -343,7 +343,7 @@ public function lockTable($table) * @param string $backup Not used by Sqlite. * @param string $prefix Not used by Sqlite. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlite Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -358,7 +358,7 @@ public function renameTable($oldTable, $newTable, $backup = null, $prefix = null /** * Unlocks tables in the database. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlite Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException diff --git a/libraries/joomla/database/driver/sqlsrv.php b/libraries/joomla/database/driver/sqlsrv.php index 49f40e2ae0..26a82bdf49 100644 --- a/libraries/joomla/database/driver/sqlsrv.php +++ b/libraries/joomla/database/driver/sqlsrv.php @@ -927,7 +927,7 @@ protected function limit($sql, $limit, $offset) * @param string $backup Table prefix * @param string $prefix For the table - used to rename constraints in non-mysql databases * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlsrv Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -955,7 +955,7 @@ public function renameTable($oldTable, $newTable, $backup = null, $prefix = null * * @param string $tableName The name of the table to lock. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlsrv Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException @@ -968,7 +968,7 @@ public function lockTable($tableName) /** * Unlocks tables in the database. * - * @return JDatabase Returns this object to support chaining. + * @return JDatabaseDriverSqlsrv Returns this object to support chaining. * * @since 12.1 * @throws RuntimeException diff --git a/libraries/joomla/date/date.php b/libraries/joomla/date/date.php index b5b6d5a78b..a4512255ca 100644 --- a/libraries/joomla/date/date.php +++ b/libraries/joomla/date/date.php @@ -415,15 +415,15 @@ public function toISO8601($local = false) /** * Gets the date as an SQL datetime string. * - * @param boolean $local True to return the date string in the local time zone, false to return it in GMT. - * @param JDatabase $dbo The database driver or null to use JFactory::getDbo() + * @param boolean $local True to return the date string in the local time zone, false to return it in GMT. + * @param JDatabaseDriver $dbo The database driver or null to use JFactory::getDbo() * * @return string The date string in SQL datetime format. * * @link http://dev.mysql.com/doc/refman/5.0/en/datetime.html * @since 11.4 */ - public function toSql($local = false, JDatabase $dbo = null) + public function toSql($local = false, JDatabaseDriver $dbo = null) { if ($dbo === null) { diff --git a/libraries/joomla/log/loggers/database.php b/libraries/joomla/log/loggers/database.php index d392cd1501..19807fc4f1 100644 --- a/libraries/joomla/log/loggers/database.php +++ b/libraries/joomla/log/loggers/database.php @@ -134,7 +134,7 @@ public function addEntry(JLogEntry $entry) * @return void * * @since 11.1 - * @throws LogException + * @throws RuntimeException */ protected function connect() { @@ -147,21 +147,9 @@ protected function connect() 'database' => $this->database, 'prefix' => $this->prefix); - try - { - $db = JDatabase::getInstance($options); - - if ($db instanceof Exception) - { - throw new LogException('Database Error: ' . (string) $db); - } + $db = JDatabaseDriver::getInstance($options); - // Assign the database connector to the class. - $this->dbo = $db; - } - catch (RuntimeException $e) - { - throw new LogException($e->getMessage()); - } + // Assign the database connector to the class. + $this->dbo = $db; } } diff --git a/tests/suites/unit/joomla/log/loggers/JLoggerDatabaseTest.php b/tests/suites/unit/joomla/log/loggers/JLoggerDatabaseTest.php index d9a1a22cd5..1f7561c614 100644 --- a/tests/suites/unit/joomla/log/loggers/JLoggerDatabaseTest.php +++ b/tests/suites/unit/joomla/log/loggers/JLoggerDatabaseTest.php @@ -122,7 +122,7 @@ public function testConnect01() * * @since 11.3 * - * @expectedException LogException + * @expectedException RuntimeException */ public function testConnect02() { From 12bb2c199b37e28b1cdb6fdb44e254f8edaffeaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rouven=20We=C3=9Fling?= Date: Sun, 8 Apr 2012 21:20:42 +0200 Subject: [PATCH 98/98] Move JDatabaseException to legacy. --- libraries/{joomla => legacy}/database/exception.php | 0 .../database/database/JDatabaseImporterPostgresqlInspector.php | 1 - 2 files changed, 1 deletion(-) rename libraries/{joomla => legacy}/database/exception.php (100%) diff --git a/libraries/joomla/database/exception.php b/libraries/legacy/database/exception.php similarity index 100% rename from libraries/joomla/database/exception.php rename to libraries/legacy/database/exception.php diff --git a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlInspector.php b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlInspector.php index 9a601e0f44..cd5f4de46a 100644 --- a/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlInspector.php +++ b/tests/suites/unit/joomla/database/database/JDatabaseImporterPostgresqlInspector.php @@ -8,7 +8,6 @@ */ require_once JPATH_PLATFORM . '/joomla/database/importer/postgresql.php'; -require_once JPATH_PLATFORM . '/joomla/database/exception.php'; /** * Class to expose protected properties and methods in JDatabasePostgresqlImporter for testing purposes