Skip to content

Commit

Permalink
[4.0]Namespace com_contact
Browse files Browse the repository at this point in the history
Namespace of frontend components. Broken down into one PR for each component so that hopefully it can now be merged more easily and without the need for daily having to resolve merge conflicts.
  • Loading branch information
brianteeman committed Jun 28, 2018
1 parent 1a2b5ac commit 0bc66c2
Show file tree
Hide file tree
Showing 31 changed files with 308 additions and 223 deletions.
34 changes: 20 additions & 14 deletions components/com_contact/Controller/ContactController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Controller\FormController;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\CMS\String\PunycodeHelper;
use Joomla\CMS\Router\Route;
use Joomla\CMS\User\User;
use Joomla\CMS\Uri\Uri;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Factory;

/**
* Controller for single contact view
Expand Down Expand Up @@ -49,7 +55,7 @@ public function submit()
// Check for request forgeries.
$this->checkToken();

$app = \JFactory::getApplication();
$app = Factory::getApplication();
$model = $this->getModel('contact');
$params = ComponentHelper::getParams('com_contact');
$stub = $this->input->getString('id');
Expand All @@ -64,15 +70,15 @@ public function submit()
// Check for a valid session cookie
if ($params->get('validate_session', 0))
{
if (\JFactory::getSession()->getState() !== 'active')
if (Factory::getSession()->getState() !== 'active')
{
$this->app->enqueueMessage(\JText::_('JLIB_ENVIRONMENT_SESSION_INVALID'), 'warning');
$this->app->enqueueMessage(Text::_('JLIB_ENVIRONMENT_SESSION_INVALID'), 'warning');

// Save the data in the session.
$this->app->setUserState('com_contact.contact.data', $data);

// Redirect back to the contact form.
$this->setRedirect(\JRoute::_('index.php?option=com_contact&view=contact&id=' . $stub, false));
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub, false));

return false;
}
Expand Down Expand Up @@ -109,7 +115,7 @@ public function submit()

$app->setUserState('com_contact.contact.data', $data);

$this->setRedirect(\JRoute::_('index.php?option=com_contact&view=contact&id=' . $stub, false));
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub, false));

return false;
}
Expand Down Expand Up @@ -139,7 +145,7 @@ public function submit()
// Set the success message if it was a success
if (!($sent instanceof \Exception))
{
$msg = \JText::_('COM_CONTACT_EMAIL_THANKS');
$msg = Text::_('COM_CONTACT_EMAIL_THANKS');
}
else
{
Expand All @@ -156,7 +162,7 @@ public function submit()
}
else
{
$this->setRedirect(\JRoute::_('index.php?option=com_contact&view=contact&id=' . $stub, false), $msg);
$this->setRedirect(Route::_('index.php?option=com_contact&view=contact&id=' . $stub, false), $msg);
}

return true;
Expand All @@ -179,7 +185,7 @@ private function _sendEmail($data, $contact, $copy_email_activated)

if ($contact->email_to == '' && $contact->user_id != 0)
{
$contact_user = \JUser::getInstance($contact->user_id);
$contact_user = User::getInstance($contact->user_id);
$contact->email_to = $contact_user->get('email');
}

Expand All @@ -188,12 +194,12 @@ private function _sendEmail($data, $contact, $copy_email_activated)
$sitename = $app->get('sitename');

$name = $data['contact_name'];
$email = \JStringPunycode::emailToPunycode($data['contact_email']);
$email = PunycodeHelper::emailToPunycode($data['contact_email']);
$subject = $data['contact_subject'];
$body = $data['contact_message'];

// Prepare email body
$prefix = \JText::sprintf('COM_CONTACT_ENQUIRY_TEXT', \JUri::base());
$prefix = Text::sprintf('COM_CONTACT_ENQUIRY_TEXT', Uri::base());
$body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body);

// Load the custom fields
Expand All @@ -215,7 +221,7 @@ private function _sendEmail($data, $contact, $copy_email_activated)
}
}

$mail = \JFactory::getMailer();
$mail = Factory::getMailer();
$mail->addRecipient($contact->email_to);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
Expand All @@ -228,11 +234,11 @@ private function _sendEmail($data, $contact, $copy_email_activated)
// Check whether email copy function activated
if ($copy_email_activated == true && !empty($data['contact_email_copy']))
{
$copytext = \JText::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
$copytext = Text::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename);
$copytext .= "\r\n\r\n" . $body;
$copysubject = \JText::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);
$copysubject = Text::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject);

$mail = \JFactory::getMailer();
$mail = Factory::getMailer();
$mail->addRecipient($email);
$mail->addReplyTo($email, $name);
$mail->setSender(array($mailfrom, $fromname));
Expand Down
8 changes: 5 additions & 3 deletions components/com_contact/Controller/DisplayController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\MVC\Controller\BaseController;
use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Factory;

/**
* Contact Component Controller
Expand All @@ -35,11 +37,11 @@ class DisplayController extends BaseController
public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
{
// Contact frontpage Editor contacts proxying:
$input = \JFactory::getApplication()->input;
$input = Factory::getApplication()->input;

if ($input->get('view') === 'contacts' && $input->get('layout') === 'modal')
{
\JHtml::_('stylesheet', 'system/adminlist.css', array(), true);
HTMLHelper::_('stylesheet', 'system/adminlist.css', array(), true);
$config['base_path'] = JPATH_COMPONENT_ADMINISTRATOR;
}

Expand All @@ -58,7 +60,7 @@ public function __construct($config = array(), MVCFactoryInterface $factory = nu
*/
public function display($cachable = false, $urlparams = array())
{
if (\JFactory::getApplication()->getUserState('com_contact.contact.data') === null)
if (Factory::getApplication()->getUserState('com_contact.contact.data') === null)
{
$cachable = true;
}
Expand Down
9 changes: 5 additions & 4 deletions components/com_contact/Helper/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
*/
namespace Joomla\Component\Contact\Site\Helper;

use Joomla\CMS\Language\Multilanguage;

defined('_JEXEC') or die;

use Joomla\CMS\Language\Multilanguage;
use Joomla\CMS\Categories\CategoryNode;

/**
* Contact Component Route Helper
*
Expand Down Expand Up @@ -54,7 +55,7 @@ public static function getContactRoute($id, $catid, $language = 0)
/**
* Get the URL route for a contact category from a contact category ID and language
*
* @param mixed $catid The id of the contact's category either an integer id or an instance of JCategoryNode
* @param mixed $catid The id of the contact's category either an integer id or an instance of CategoryNode
* @param mixed $language The id of the language being used.
*
* @return string The link to the contact
Expand All @@ -63,7 +64,7 @@ public static function getContactRoute($id, $catid, $language = 0)
*/
public static function getCategoryRoute($catid, $language = 0)
{
if ($catid instanceof \JCategoryNode)
if ($catid instanceof CategoryNode)
{
$id = $catid->id;
}
Expand Down
8 changes: 5 additions & 3 deletions components/com_contact/Model/CategoriesModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

use Joomla\CMS\MVC\Model\ListModel;
use Joomla\Registry\Registry;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Factory;

/**
* This models supports retrieving lists of contact categories.
Expand Down Expand Up @@ -52,7 +54,7 @@ class CategoriesModel extends ListModel
*/
protected function populateState($ordering = null, $direction = null)
{
$app = \JFactory::getApplication();
$app = Factory::getApplication();
$this->setState('filter.extension', $this->_extension);

// Get the parent id if defined.
Expand Down Expand Up @@ -97,7 +99,7 @@ public function getItems()
{
if ($this->_items === null)
{
$app = \JFactory::getApplication();
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new Registry;
Expand All @@ -109,7 +111,7 @@ public function getItems()

$options = array();
$options['countItems'] = $params->get('show_cat_items_cat', 1) || !$params->get('show_empty_categories_cat', 0);
$categories = \JCategories::getInstance('Contact', $options);
$categories = Categories::getInstance('Contact', $options);
$this->_parent = $categories->get($this->getState('filter.parentId', 'root'));

if (is_object($this->_parent))
Expand Down
18 changes: 10 additions & 8 deletions components/com_contact/Model/CategoryModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
use Joomla\Registry\Registry;
use Joomla\CMS\Categories\Categories;
use Joomla\CMS\Factory;

/**
* Single item model for a contact
Expand Down Expand Up @@ -126,7 +128,7 @@ public function getItems()
*/
protected function getListQuery()
{
$user = \JFactory::getUser();
$user = Factory::getUser();
$groups = implode(',', $user->getAuthorisedViewLevels());

// Create a new query object.
Expand Down Expand Up @@ -172,7 +174,7 @@ protected function getListQuery()

// Filter by start and end dates.
$nullDate = $db->quote($db->getNullDate());
$nowDate = $db->quote(\JFactory::getDate()->toSql());
$nowDate = $db->quote(Factory::getDate()->toSql());

if ($this->getState('filter.publish_date'))
{
Expand All @@ -192,7 +194,7 @@ protected function getListQuery()
// Filter by language
if ($this->getState('filter.language'))
{
$query->where('a.language in (' . $db->quote(\JFactory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
$query->where('a.language in (' . $db->quote(Factory::getLanguage()->getTag()) . ',' . $db->quote('*') . ')');
}

// Set sortname ordering if selected
Expand Down Expand Up @@ -224,7 +226,7 @@ protected function getListQuery()
*/
protected function populateState($ordering = null, $direction = null)
{
$app = \JFactory::getApplication();
$app = Factory::getApplication();
$params = ComponentHelper::getParams('com_contact');

// List state information
Expand Down Expand Up @@ -281,7 +283,7 @@ protected function populateState($ordering = null, $direction = null)
$id = $app->input->get('id', 0, 'int');
$this->setState('category.id', $id);

$user = \JFactory::getUser();
$user = Factory::getUser();

if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact')))
{
Expand Down Expand Up @@ -309,7 +311,7 @@ public function getCategory()
{
if (!is_object($this->_item))
{
$app = \JFactory::getApplication();
$app = Factory::getApplication();
$menu = $app->getMenu();
$active = $menu->getActive();
$params = new Registry;
Expand All @@ -321,7 +323,7 @@ public function getCategory()

$options = array();
$options['countItems'] = $params->get('show_cat_items', 1) || $params->get('show_empty_categories', 0);
$categories = \JCategories::getInstance('Contact', $options);
$categories = Categories::getInstance('Contact', $options);
$this->_item = $categories->get($this->getState('category.id', 'root'));

if (is_object($this->_item))
Expand Down Expand Up @@ -439,7 +441,7 @@ private function getSlugColumn($query, $id, $alias)
*/
public function hit($pk = 0)
{
$input = \JFactory::getApplication()->input;
$input = Factory::getApplication()->input;
$hitcount = $input->getInt('hitcount', 1);

if ($hitcount)
Expand Down

0 comments on commit 0bc66c2

Please sign in to comment.