0byt3m1n1-V2
Path:
/
home
/
a
/
c
/
a
/
academiac
/
www
/
[
Home
]
File: contact.php.tar
home/academiac/www/administrator/components/com_contact/contact.php 0000644 00000001052 15137207033 0021710 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; // Access check. if (!JFactory::getUser()->authorise('core.manage', 'com_contact')) { return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR')); } $controller = JControllerLegacy::getInstance('contact'); $controller->execute(JRequest::getCmd('task')); $controller->redirect(); home/academiac/www/administrator/components/com_contact/helpers/contact.php 0000644 00000003470 15137210631 0023356 0 ustar 00 <?php /** * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; /** * Contact component helper. * * @package Joomla.Administrator * @subpackage com_contact * @since 1.6 */ class ContactHelper { /** * Configure the Linkbar. * * @param string $vName The name of the active view. * * @return void * @since 1.6 */ public static function addSubmenu($vName) { JSubMenuHelper::addEntry( JText::_('COM_CONTACT_SUBMENU_CONTACTS'), 'index.php?option=com_contact&view=contacts', $vName == 'contacts' ); JSubMenuHelper::addEntry( JText::_('COM_CONTACT_SUBMENU_CATEGORIES'), 'index.php?option=com_categories&extension=com_contact', $vName == 'categories' ); if ($vName=='categories') { JToolBarHelper::title( JText::sprintf('COM_CATEGORIES_CATEGORIES_TITLE', JText::_('com_contact')), 'contact-categories'); } } /** * Gets a list of the actions that can be performed. * * @param int The category ID. * @param int The contact ID. * * @return JObject * @since 1.6 */ public static function getActions($categoryId = 0, $contactId = 0) { $user = JFactory::getUser(); $result = new JObject; if (empty($contactId) && empty($categoryId)) { $assetName = 'com_contact'; $level = 'component'; } elseif (empty($contactId)) { $assetName = 'com_contact.category.'.(int) $categoryId; $level = 'category'; } else { $assetName = 'com_contact.contact.'.(int) $contactId; $level = 'category'; } $actions = JAccess::getActions('com_contact', $level); foreach ($actions as $action) { $result->set($action->name, $user->authorise($action->name, $assetName)); } return $result; } } home/academiac/www/components/com_contact/contact.php 0000644 00000000671 15137211640 0017035 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; require_once JPATH_COMPONENT . '/helpers/route.php'; $controller = JControllerLegacy::getInstance('Contact'); $controller->execute(JRequest::getCmd('task')); $controller->redirect(); home/academiac/www/administrator/components/com_contact/models/contact.php 0000644 00000027271 15137362343 0023214 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modeladmin'); /** * Item Model for a Contact. * * @package Joomla.Administrator * @subpackage com_contact * @since 1.6 */ class ContactModelContact extends JModelAdmin { /** * Method to perform batch operations on an item or a set of items. * * @param array $commands An array of commands to perform. * @param array $pks An array of item ids. * @param array $contexts An array of item contexts. * * @return boolean Returns true on success, false on failure. * * @since 2.5 */ public function batch($commands, $pks, $contexts) { // Sanitize user ids. $pks = array_unique($pks); JArrayHelper::toInteger($pks); // Remove any values of zero. if (array_search(0, $pks, true)) { unset($pks[array_search(0, $pks, true)]); } if (empty($pks)) { $this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED')); return false; } $done = false; if (!empty($commands['category_id'])) { $cmd = JArrayHelper::getValue($commands, 'move_copy', 'c'); if ($cmd == 'c') { $result = $this->batchCopy($commands['category_id'], $pks, $contexts); if (is_array($result)) { $pks = $result; } else { return false; } } elseif ($cmd == 'm' && !$this->batchMove($commands['category_id'], $pks, $contexts)) { return false; } $done = true; } if (!empty($commands['assetgroup_id'])) { if (!$this->batchAccess($commands['assetgroup_id'], $pks, $contexts)) { return false; } $done = true; } if (!empty($commands['language_id'])) { if (!$this->batchLanguage($commands['language_id'], $pks, $contexts)) { return false; } $done = true; } if (strlen($commands['user_id']) > 0) { if (!$this->batchUser($commands['user_id'], $pks, $contexts)) { return false; } $done = true; } if (!$done) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION')); return false; } // Clear the cache $this->cleanCache(); return true; } /** * Batch copy items to a new category or current. * * @param integer $value The new category. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return mixed An array of new IDs on success, boolean false on failure. * * @since 11.1 */ protected function batchCopy($value, $pks, $contexts) { $categoryId = (int) $value; $table = $this->getTable(); $i = 0; // Check that the category exists if ($categoryId) { $categoryTable = JTable::getInstance('Category'); if (!$categoryTable->load($categoryId)) { if ($error = $categoryTable->getError()) { // Fatal error $this->setError($error); return false; } else { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); return false; } } } if (empty($categoryId)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_MOVE_CATEGORY_NOT_FOUND')); return false; } // Check that the user has create permission for the component $user = JFactory::getUser(); if (!$user->authorise('core.create', 'com_contact.category.' . $categoryId)) { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE')); return false; } // Parent exists so we let's proceed while (!empty($pks)) { // Pop the first ID off the stack $pk = array_shift($pks); $table->reset(); // Check that the row actually exists if (!$table->load($pk)) { if ($error = $table->getError()) { // Fatal error $this->setError($error); return false; } else { // Not fatal error $this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_BATCH_MOVE_ROW_NOT_FOUND', $pk)); continue; } } // Alter the title & alias $data = $this->generateNewTitle($categoryId, $table->alias, $table->name); $table->name = $data['0']; $table->alias = $data['1']; // Reset the ID because we are making a copy $table->id = 0; // New category ID $table->catid = $categoryId; // TODO: Deal with ordering? //$table->ordering = 1; // Check the row. if (!$table->check()) { $this->setError($table->getError()); return false; } // Store the row. if (!$table->store()) { $this->setError($table->getError()); return false; } // Get the new item ID $newId = $table->get('id'); // Add the new ID to the array $newIds[$i] = $newId; $i++; } // Clean the cache $this->cleanCache(); return $newIds; } /** * Batch change a linked user. * * @param integer $value The new value matching a User ID. * @param array $pks An array of row IDs. * @param array $contexts An array of item contexts. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 2.5 */ protected function batchUser($value, $pks, $contexts) { // Set the variables $user = JFactory::getUser(); $table = $this->getTable(); foreach ($pks as $pk) { if ($user->authorise('core.edit', $contexts[$pk])) { $table->reset(); $table->load($pk); $table->user_id = (int) $value; if (!$table->store()) { $this->setError($table->getError()); return false; } } else { $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT')); return false; } } // Clean the cache $this->cleanCache(); return true; } /** * Method to test whether a record can be deleted. * * @param object $record A record object. * * @return boolean True if allowed to delete the record. Defaults to the permission set in the component. * @since 1.6 */ protected function canDelete($record) { if (!empty($record->id)) { if ($record->published != -2) { return ; } $user = JFactory::getUser(); return $user->authorise('core.delete', 'com_contact.category.'.(int) $record->catid); } } /** * Method to test whether a record can have its state edited. * * @param object $record A record object. * * @return boolean True if allowed to change the state of the record. Defaults to the permission set in the component. * @since 1.6 */ protected function canEditState($record) { $user = JFactory::getUser(); // Check against the category. if (!empty($record->catid)) { return $user->authorise('core.edit.state', 'com_contact.category.'.(int) $record->catid); } // Default to component settings if category not known. else { return parent::canEditState($record); } } /** * Returns a Table object, always creating it * * @param type $type The table type to instantiate * @param string $prefix A prefix for the table class name. Optional. * @param array $config Configuration array for model. Optional. * * @return JTable A database object * @since 1.6 */ public function getTable($type = 'Contact', $prefix = 'ContactTable', $config = array()) { return JTable::getInstance($type, $prefix, $config); } /** * Method to get the row form. * * @param array $data Data for the form. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * * @return mixed A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { JForm::addFieldPath('JPATH_ADMINISTRATOR/components/com_users/models/fields'); // Get the form. $form = $this->loadForm('com_contact.contact', 'contact', array('control' => 'jform', 'load_data' => $loadData)); if (empty($form)) { return false; } // Modify the form based on access controls. if (!$this->canEditState((object) $data)) { // Disable fields for display. $form->setFieldAttribute('featured', 'disabled', 'true'); $form->setFieldAttribute('ordering', 'disabled', 'true'); $form->setFieldAttribute('published', 'disabled', 'true'); // Disable fields while saving. // The controller has already verified this is a record you can edit. $form->setFieldAttribute('featured', 'filter', 'unset'); $form->setFieldAttribute('ordering', 'filter', 'unset'); $form->setFieldAttribute('published', 'filter', 'unset'); } return $form; } /** * Method to get a single record. * * @param integer $pk The id of the primary key. * * @return mixed Object on success, false on failure. * @since 1.6 */ public function getItem($pk = null) { if ($item = parent::getItem($pk)) { // Convert the params field to an array. $registry = new JRegistry; $registry->loadString($item->metadata); $item->metadata = $registry->toArray(); } return $item; } /** * Method to get the data that should be injected in the form. * * @return mixed The data for the form. * @since 1.6 */ protected function loadFormData() { // Check the session for previously entered form data. $data = JFactory::getApplication()->getUserState('com_contact.edit.contact.data', array()); if (empty($data)) { $data = $this->getItem(); // Prime some default values. if ($this->getState('contact.id') == 0) { $app = JFactory::getApplication(); $data->set('catid', JRequest::getInt('catid', $app->getUserState('com_contact.contacts.filter.category_id'))); } } return $data; } /** * Prepare and sanitise the table prior to saving. * * @param JTable $table * * @return void * @since 1.6 */ protected function prepareTable(&$table) { $date = JFactory::getDate(); $user = JFactory::getUser(); $table->name = htmlspecialchars_decode($table->name, ENT_QUOTES); $table->alias = JApplication::stringURLSafe($table->alias); if (empty($table->alias)) { $table->alias = JApplication::stringURLSafe($table->name); } if (empty($table->id)) { // Set the values //$table->created = $date->toSql(); // Set ordering to the last item if not set if (empty($table->ordering)) { $db = JFactory::getDbo(); $db->setQuery('SELECT MAX(ordering) FROM #__contact_details'); $max = $db->loadResult(); $table->ordering = $max+1; } } else { // Set the values //$table->modified = $date->toSql(); //$table->modified_by = $user->get('id'); } } /** * A protected method to get a set of ordering conditions. * * @param JTable $table A record object. * * @return array An array of conditions to add to add to ordering queries. * @since 1.6 */ protected function getReorderConditions($table) { $condition = array(); $condition[] = 'catid = '.(int) $table->catid; return $condition; } /** * Method to toggle the featured setting of contacts. * * @param array $pks The ids of the items to toggle. * @param int $value The value to toggle to. * * @return boolean True on success. * @since 1.6 */ public function featured($pks, $value = 0) { // Sanitize the ids. $pks = (array) $pks; JArrayHelper::toInteger($pks); if (empty($pks)) { $this->setError(JText::_('COM_CONTACT_NO_ITEM_SELECTED')); return false; } $table = $this->getTable(); try { $db = $this->getDbo(); $db->setQuery( 'UPDATE #__contact_details' . ' SET featured = '.(int) $value. ' WHERE id IN ('.implode(',', $pks).')' ); if (!$db->query()) { throw new Exception($db->getErrorMsg()); } } catch (Exception $e) { $this->setError($e->getMessage()); return false; } $table->reorder(); // Clean component's cache $this->cleanCache(); return true; } } home/academiac/www/components/com_contact/controllers/contact.php 0000644 00000012700 15137362535 0021411 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage Contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); class ContactControllerContact extends JControllerForm { public function getModel($name = '', $prefix = '', $config = array('ignore_request' => true)) { return parent::getModel($name, $prefix, array('ignore_request' => false)); } public function submit() { // Check for request forgeries. JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Initialise variables. $app = JFactory::getApplication(); $model = $this->getModel('contact'); $params = JComponentHelper::getParams('com_contact'); $stub = JRequest::getString('id'); $id = (int) $stub; // Get the data from POST $data = JRequest::getVar('jform', array(), 'post', 'array'); $contact = $model->getItem($id); $params->merge($contact->params); // Check for a valid session cookie if ($params->get('validate_session', 0)) { if (JFactory::getSession()->getState() != 'active') { JError::raiseWarning(403, JText::_('COM_CONTACT_SESSION_INVALID')); // Save the data in the session. $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)); return false; } } // Contact plugins JPluginHelper::importPlugin('contact'); $dispatcher = JDispatcher::getInstance(); // Validate the posted data. $form = $model->getForm(); if (!$form) { JError::raiseError(500, $model->getError()); return false; } $validate = $model->validate($form, $data); if ($validate === false) { // Get the validation messages. $errors = $model->getErrors(); // Push up to three validation messages out to the user. for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++) { if ($errors[$i] instanceof Exception) { $app->enqueueMessage($errors[$i]->getMessage(), 'warning'); } else { $app->enqueueMessage($errors[$i], 'warning'); } } // Save the data in the session. $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)); return false; } // Validation succeeded, continue with custom handlers $results = $dispatcher->trigger('onValidateContact', array(&$contact, &$data)); foreach ($results as $result) { if ($result instanceof Exception) { return false; } } // Passed Validation: Process the contact plugins to integrate with other applications $results = $dispatcher->trigger('onSubmitContact', array(&$contact, &$data)); // Send the email $sent = false; if (!$params->get('custom_reply')) { $sent = $this->_sendEmail($data, $contact, $params->get('show_email_copy')); } // Set the success message if it was a success if (!($sent instanceof Exception)) { $msg = JText::_('COM_CONTACT_EMAIL_THANKS'); } else { $msg = ''; } // Flush the data from the session $app->setUserState('com_contact.contact.data', null); // Redirect if it is set in the parameters, otherwise redirect back to where we came from if ($contact->params->get('redirect')) { $this->setRedirect($contact->params->get('redirect'), $msg); } else { $this->setRedirect(JRoute::_('index.php?option=com_contact&view=contact&id=' . $stub, false), $msg); } return true; } private function _sendEmail($data, $contact, $copy_email_activated) { $app = JFactory::getApplication(); $params = JComponentHelper::getParams('com_contact'); if ($contact->email_to == '' && $contact->user_id != 0) { $contact_user = JUser::getInstance($contact->user_id); $contact->email_to = $contact_user->get('email'); } $mailfrom = $app->getCfg('mailfrom'); $fromname = $app->getCfg('fromname'); $sitename = $app->getCfg('sitename'); $copytext = JText::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename); $name = $data['contact_name']; $email = $data['contact_email']; $subject = $data['contact_subject']; $body = $data['contact_message']; // Prepare email body $prefix = JText::sprintf('COM_CONTACT_ENQUIRY_TEXT', JURI::base()); $body = $prefix . "\n" . $name . ' <' . $email . '>' . "\r\n\r\n" . stripslashes($body); $mail = JFactory::getMailer(); $mail->addRecipient($contact->email_to); $mail->addReplyTo(array($email, $name)); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject($sitename . ': ' . $subject); $mail->setBody($body); $sent = $mail->Send(); // If we are supposed to copy the sender, do so. // Check whether email copy function activated if ($copy_email_activated == true && isset($data['contact_email_copy'])) { $copytext = JText::sprintf('COM_CONTACT_COPYTEXT_OF', $contact->name, $sitename); $copytext .= "\r\n\r\n" . $body; $copysubject = JText::sprintf('COM_CONTACT_COPYSUBJECT_OF', $subject); $mail = JFactory::getMailer(); $mail->addRecipient($email); $mail->addReplyTo(array($email, $name)); $mail->setSender(array($mailfrom, $fromname)); $mail->setSubject($copysubject); $mail->setBody($copytext); $sent = $mail->Send(); } return $sent; } } home/academiac/www/administrator/components/com_contact/helpers/html/contact.php 0000644 00000002420 15137370627 0024330 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // no direct access defined('_JEXEC') or die; /** * @package Joomla.Administrator * @subpackage com_contact */ abstract class JHtmlContact { /** * @param int $value The featured value * @param int $i * @param bool $canChange Whether the value can be changed or not * * @return string The anchor tag to toggle featured/unfeatured contacts. * @since 1.6 */ static function featured($value = 0, $i, $canChange = true) { // Array of image, task, title, action $states = array( 0 => array('disabled.png', 'contacts.featured', 'COM_CONTACT_UNFEATURED', 'COM_CONTACT_TOGGLE_TO_FEATURE'), 1 => array('featured.png', 'contacts.unfeatured', 'JFEATURED', 'COM_CONTACT_TOGGLE_TO_UNFEATURE'), ); $state = JArrayHelper::getValue($states, (int) $value, $states[1]); $html = JHtml::_('image', 'admin/'.$state[0], JText::_($state[2]), NULL, true); if ($canChange) { $html = '<a href="#" onclick="return listItemTask(\'cb'.$i.'\',\''.$state[1].'\')" title="'.JText::_($state[3]).'">' . $html .'</a>'; } return $html; } } home/academiac/www/administrator/components/com_contact/controllers/contact.php 0000644 00000005145 15137447416 0024300 0 ustar 00 <?php /** * @package Joomla.Administrator * @subpackage com_contact * * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.controllerform'); /** * @package Joomla.Administrator * @subpackage com_contact * @since 1.6 */ class ContactControllerContact extends JControllerForm { /** * Method override to check if you can add a new record. * * @param array $data An array of input data. * * @return boolean * * @since 1.6 */ protected function allowAdd($data = array()) { // Initialise variables. $user = JFactory::getUser(); $categoryId = JArrayHelper::getValue($data, 'catid', JRequest::getInt('filter_category_id'), 'int'); $allow = null; if ($categoryId) { // If the category has been passed in the URL check it. $allow = $user->authorise('core.create', $this->option . '.category.' . $categoryId); } if ($allow === null) { // In the absense of better information, revert to the component permissions. return parent::allowAdd($data); } else { return $allow; } } /** * Method override to check if you can edit an existing record. * * @param array $data An array of input data. * @param string $key The name of the key for the primary key. * * @return boolean * * @since 1.6 */ protected function allowEdit($data = array(), $key = 'id') { // Initialise variables. $recordId = (int) isset($data[$key]) ? $data[$key] : 0; $categoryId = 0; if ($recordId) { $categoryId = (int) $this->getModel()->getItem($recordId)->catid; } if ($categoryId) { // The category has been set. Check the category permissions. return JFactory::getUser()->authorise('core.edit', $this->option . '.category.' . $categoryId); } else { // Since there is no asset tracking, revert to the component permissions. return parent::allowEdit($data, $key); } } /** * Method to run batch operations. * * @param object $model The model. * * @return boolean True if successful, false otherwise and internal error is set. * * @since 2.5 */ public function batch($model = null) { JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN')); // Set the model $model = $this->getModel('Contact', '', array()); // Preset the redirect $this->setRedirect(JRoute::_('index.php?option=com_contact&view=contacts' . $this->getRedirectToListAppend(), false)); return parent::batch($model); } } home/academiac/www/components/com_contact/models/contact.php 0000644 00000026135 15140235641 0020324 0 ustar 00 <?php /** * @package Joomla.Site * @subpackage com_contact * @copyright Copyright (C) 2005 - 2014 Open Source Matters, Inc. All rights reserved. * @license GNU General Public License version 2 or later; see LICENSE.txt */ // No direct access defined('_JEXEC') or die; jimport('joomla.application.component.modelform'); jimport('joomla.event.dispatcher'); /** * @package Joomla.Site * @subpackage com_contact * @since 1.5 */ class ContactModelContact extends JModelForm { /** * @since 1.6 */ protected $view_item = 'contact'; protected $_item = null; /** * Model context string. * * @var string */ protected $_context = 'com_contact.contact'; /** * Method to auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @since 1.6 */ protected function populateState() { $app = JFactory::getApplication('site'); // Load state from the request. $pk = JRequest::getInt('id'); $this->setState('contact.id', $pk); // Load the parameters. $params = $app->getParams(); $this->setState('params', $params); $user = JFactory::getUser(); if ((!$user->authorise('core.edit.state', 'com_contact')) && (!$user->authorise('core.edit', 'com_contact'))){ $this->setState('filter.published', 1); $this->setState('filter.archived', 2); } } /** * Method to get the contact form. * * The base form is loaded from XML and then an event is fired * * * @param array $data An optional array of data for the form to interrogate. * @param boolean $loadData True if the form is to load its own data (default case), false if not. * @return JForm A JForm object on success, false on failure * @since 1.6 */ public function getForm($data = array(), $loadData = true) { // Get the form. $form = $this->loadForm('com_contact.contact', 'contact', array('control' => 'jform', 'load_data' => true)); if (empty($form)) { return false; } $id = $this->getState('contact.id'); $params = $this->getState('params'); $contact = $this->_item[$id]; $params->merge($contact->params); if(!$params->get('show_email_copy', 0)){ $form->removeField('contact_email_copy'); } return $form; } protected function loadFormData() { $data = (array)JFactory::getApplication()->getUserState('com_contact.contact.data', array()); return $data; } /** * Gets a list of contacts * @param array * @return mixed Object or null */ public function &getItem($pk = null) { // Initialise variables. $pk = (!empty($pk)) ? $pk : (int) $this->getState('contact.id'); if ($this->_item === null) { $this->_item = array(); } if (!isset($this->_item[$pk])) { try { $db = $this->getDbo(); $query = $db->getQuery(true); //sqlsrv changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id.' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id.' END as catslug'; $query->select($this->getState('item.select', 'a.*') . ','.$case_when.','.$case_when1); $query->from('#__contact_details AS a'); // Join on category table. $query->select('c.title AS category_title, c.alias AS category_alias, c.access AS category_access'); $query->join('LEFT', '#__categories AS c on c.id = a.catid'); // Join over the categories to get parent category titles $query->select('parent.title as parent_title, parent.id as parent_id, parent.path as parent_route, parent.alias as parent_alias'); $query->join('LEFT', '#__categories as parent ON parent.id = c.parent_id'); $query->where('a.id = ' . (int) $pk); // Filter by start and end dates. $nullDate = $db->Quote($db->getNullDate()); $nowDate = $db->Quote(JFactory::getDate()->toSql()); // Filter by published state. $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('(a.published = ' . (int) $published . ' OR a.published =' . (int) $archived . ')'); $query->where('(a.publish_up = ' . $nullDate . ' OR a.publish_up <= ' . $nowDate . ')'); $query->where('(a.publish_down = ' . $nullDate . ' OR a.publish_down >= ' . $nowDate . ')'); } $db->setQuery($query); $data = $db->loadObject(); if ($error = $db->getErrorMsg()) { throw new JException($error); } if (empty($data)) { throw new JException(JText::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404); } // Check for published state if filter set. if (((is_numeric($published)) || (is_numeric($archived))) && (($data->published != $published) && ($data->published != $archived))) { JError::raiseError(404, JText::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND')); } // Convert parameter fields to objects. $registry = new JRegistry; $registry->loadString($data->params); $data->params = clone $this->getState('params'); $data->params->merge($registry); $registry = new JRegistry; $registry->loadString($data->metadata); $data->metadata = $registry; // Compute access permissions. if ($access = $this->getState('filter.access')) { // If the access filter has been set, we already know this user can view. $data->params->set('access-view', true); } else { // If no access filter is set, the layout takes some responsibility for display of limited information. $user = JFactory::getUser(); $groups = $user->getAuthorisedViewLevels(); if ($data->catid == 0 || $data->category_access === null) { $data->params->set('access-view', in_array($data->access, $groups)); } else { $data->params->set('access-view', in_array($data->access, $groups) && in_array($data->category_access, $groups)); } } $this->_item[$pk] = $data; } catch (JException $e) { $this->setError($e); $this->_item[$pk] = false; } } if ($this->_item[$pk]) { if ($extendedData = $this->getContactQuery($pk)) { $this->_item[$pk]->articles = $extendedData->articles; $this->_item[$pk]->profile = $extendedData->profile; } } return $this->_item[$pk]; } protected function getContactQuery($pk = null) { // TODO: Cache on the fingerprint of the arguments $db = $this->getDbo(); $user = JFactory::getUser(); $pk = (!empty($pk)) ? $pk : (int) $this->getState('contact.id'); $query = $db->getQuery(true); if ($pk) { //sqlsrv changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id.' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('cc.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('cc.id'); $case_when1 .= $query->concatenate(array($c_id, 'cc.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id.' END as catslug'; $query->select('a.*, cc.access as category_access, cc.title as category_name, ' .$case_when.','.$case_when1); $query->from('#__contact_details AS a'); $query->join('INNER', '#__categories AS cc on cc.id = a.catid'); $query->where('a.id = ' . (int) $pk); $published = $this->getState('filter.published'); $archived = $this->getState('filter.archived'); if (is_numeric($published)) { $query->where('a.published IN (1,2)'); $query->where('cc.published IN (1,2)'); } $groups = implode(',', $user->getAuthorisedViewLevels()); $query->where('a.access IN ('.$groups.')'); try { $db->setQuery($query); $result = $db->loadObject(); if ($error = $db->getErrorMsg()) { throw new Exception($error); } if (empty($result)) { throw new JException(JText::_('COM_CONTACT_ERROR_CONTACT_NOT_FOUND'), 404); } // If we are showing a contact list, then the contact parameters take priority // So merge the contact parameters with the merged parameters if ($this->getState('params')->get('show_contact_list')) { $registry = new JRegistry; $registry->loadString($result->params); $this->getState('params')->merge($registry); } } catch (Exception $e) { $this->setError($e); return false; } if ($result) { $user = JFactory::getUser(); $groups = implode(',', $user->getAuthorisedViewLevels()); //get the content by the linked user $query = $db->getQuery(true); $query->select('a.id'); $query->select('a.title'); $query->select('a.state'); $query->select('a.access'); $query->select('a.created'); // SQL Server changes $case_when = ' CASE WHEN '; $case_when .= $query->charLength('a.alias'); $case_when .= ' THEN '; $a_id = $query->castAsChar('a.id'); $case_when .= $query->concatenate(array($a_id, 'a.alias'), ':'); $case_when .= ' ELSE '; $case_when .= $a_id.' END as slug'; $case_when1 = ' CASE WHEN '; $case_when1 .= $query->charLength('c.alias'); $case_when1 .= ' THEN '; $c_id = $query->castAsChar('c.id'); $case_when1 .= $query->concatenate(array($c_id, 'c.alias'), ':'); $case_when1 .= ' ELSE '; $case_when1 .= $c_id.' END as catslug'; $query->select($case_when1 . ',' . $case_when); $query->from('#__content as a'); $query->leftJoin('#__categories as c on a.catid=c.id'); $query->where('a.created_by = '.(int)$result->user_id); $query->where('a.access IN ('. $groups.')'); $query->order('a.state DESC, a.created DESC'); // filter per language if plugin published if (JLanguageMultilang::isEnabled()) { $query->where(('a.created_by = ' . (int) $result->user_id) . ' AND ' . ('a.language='.$db->quote(JFactory::getLanguage()->getTag()).' OR a.language='.$db->quote('*'))); } if (is_numeric($published)) { $query->where('a.state IN (1,2)'); } $db->setQuery($query, 0, 10); $articles = $db->loadObjectList(); $result->articles = $articles; //get the profile information for the linked user require_once JPATH_ADMINISTRATOR.'/components/com_users/models/user.php'; $userModel = JModelLegacy::getInstance('User', 'UsersModel', array('ignore_request' => true)); $data = $userModel->getItem((int)$result->user_id); JPluginHelper::importPlugin('user'); $form = new JForm('com_users.profile'); // Get the dispatcher. $dispatcher = JDispatcher::getInstance(); // Trigger the form preparation event. $dispatcher->trigger('onContentPrepareForm', array($form, $data)); // Trigger the data preparation event. $dispatcher->trigger('onContentPrepareData', array('com_users.profile', $data)); // Load the data into the form after the plugins have operated. $form->bind($data); $result->profile = $form; $this->contact = $result; return $result; } } } }
©
2018.