You've already forked joomla_test
							
							first commit
This commit is contained in:
		
							
								
								
									
										157
									
								
								administrator/components/com_messages/models/config.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										157
									
								
								administrator/components/com_messages/models/config.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,157 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Message configuration model. | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class MessagesModelConfig extends JModelForm | ||||
| { | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function populateState() | ||||
| 	{ | ||||
| 		$user	= JFactory::getUser(); | ||||
|  | ||||
| 		$this->setState('user.id', $user->get('id')); | ||||
|  | ||||
| 		// Load the parameters. | ||||
| 		$params	= JComponentHelper::getParams('com_messages'); | ||||
| 		$this->setState('params', $params); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a single record. | ||||
| 	 * | ||||
| 	 * @param   integer	The id of the primary key. | ||||
| 	 * | ||||
| 	 * @return  mixed  Object on success, false on failure. | ||||
| 	 */ | ||||
| 	public function &getItem() | ||||
| 	{ | ||||
| 		$item = new JObject; | ||||
|  | ||||
| 		$db = $this->getDbo(); | ||||
| 		$query = $db->getQuery(true) | ||||
| 			->select('cfg_name, cfg_value') | ||||
| 			->from('#__messages_cfg') | ||||
| 			->where('user_id = '.(int) $this->getState('user.id')); | ||||
|  | ||||
| 		$db->setQuery($query); | ||||
|  | ||||
| 		try | ||||
| 		{ | ||||
| 			$rows = $db->loadObjectList(); | ||||
| 		} | ||||
| 		catch (RuntimeException $e) | ||||
| 		{ | ||||
| 			$this->setError($e->getMessage()); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		foreach ($rows as $row) | ||||
| 		{ | ||||
| 			$item->set($row->cfg_name, $row->cfg_value); | ||||
| 		} | ||||
|  | ||||
| 		$this->preprocessData('com_messages.config', $item); | ||||
|  | ||||
| 		return $item; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the record 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  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_messages.config', 'config', array('control' => 'jform', 'load_data' => $loadData)); | ||||
| 		if (empty($form)) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		return $form; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to save the form data. | ||||
| 	 * | ||||
| 	 * @param   array  The form data. | ||||
| 	 * @return  boolean  True on success. | ||||
| 	 */ | ||||
| 	public function save($data) | ||||
| 	{ | ||||
| 		$db = $this->getDbo(); | ||||
|  | ||||
| 		if ($userId = (int) $this->getState('user.id')) | ||||
| 		{ | ||||
| 			$db->setQuery( | ||||
| 				'DELETE FROM #__messages_cfg'. | ||||
| 				' WHERE user_id = '. $userId | ||||
| 			); | ||||
|  | ||||
| 			try | ||||
| 			{ | ||||
| 				$db->execute(); | ||||
| 			} | ||||
| 			catch (RuntimeException $e) | ||||
| 			{ | ||||
| 				$this->setError($e->getMessage()); | ||||
| 				return false; | ||||
| 			} | ||||
|  | ||||
| 			$tuples = array(); | ||||
| 			foreach ($data as $k => $v) | ||||
| 			{ | ||||
| 				$tuples[] = '(' . $userId.', ' . $db->quote($k) . ', ' . $db->quote($v) . ')'; | ||||
| 			} | ||||
|  | ||||
| 			if ($tuples) | ||||
| 			{ | ||||
| 				$db->setQuery( | ||||
| 					'INSERT INTO #__messages_cfg'. | ||||
| 					' (user_id, cfg_name, cfg_value)'. | ||||
| 					' VALUES '.implode(',', $tuples) | ||||
| 				); | ||||
|  | ||||
| 				try | ||||
| 				{ | ||||
| 				$db->execute(); | ||||
| 				} | ||||
| 				catch (RuntimeException $e) | ||||
| 				{ | ||||
| 					$this->setError($e->getMessage()); | ||||
| 					return false; | ||||
| 				} | ||||
| 			} | ||||
| 			return true; | ||||
| 		} | ||||
| 		else | ||||
| 		{ | ||||
| 			$this->setError('COM_MESSAGES_ERR_INVALID_USER'); | ||||
| 			return false; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1 @@ | ||||
| <!DOCTYPE html><title></title> | ||||
| @ -0,0 +1,86 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| JFormHelper::loadFieldClass('user'); | ||||
|  | ||||
| /** | ||||
|  * Supports an modal select of user that have access to com_messages | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class JFormFieldUserMessages extends JFormFieldUser | ||||
| { | ||||
| 	/** | ||||
| 	 * The form field type. | ||||
| 	 * | ||||
| 	 * @var		string | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public $type = 'UserMessages'; | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the filtering groups (null means no filtering) | ||||
| 	 * | ||||
| 	 * @return  array|null	array of filtering groups or null. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getGroups() | ||||
| 	{ | ||||
| 		// Compute usergroups | ||||
| 		$db = JFactory::getDbo(); | ||||
| 		$query = $db->getQuery(true) | ||||
| 			->select('id') | ||||
| 			->from('#__usergroups'); | ||||
| 		$db->setQuery($query); | ||||
|  | ||||
| 		try | ||||
| 		{ | ||||
| 			$groups = $db->loadColumn(); | ||||
| 		} | ||||
| 		catch (RuntimeException $e) | ||||
| 		{ | ||||
| 			JError::raiseNotice(500, $e->getMessage()); | ||||
| 			return null; | ||||
| 		} | ||||
|  | ||||
| 		foreach ($groups as $i => $group) | ||||
| 		{ | ||||
| 			if (JAccess::checkGroup($group, 'core.admin')) | ||||
| 			{ | ||||
| 				continue; | ||||
| 			} | ||||
| 			if (!JAccess::checkGroup($group, 'core.manage', 'com_messages')) | ||||
| 			{ | ||||
| 				unset($groups[$i]); | ||||
| 				continue; | ||||
| 			} | ||||
| 			if (!JAccess::checkGroup($group, 'core.login.admin')) | ||||
| 			{ | ||||
| 				unset($groups[$i]); | ||||
| 				continue; | ||||
| 			} | ||||
| 		} | ||||
| 		return array_values($groups); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the users to exclude from the list of users | ||||
| 	 * | ||||
| 	 * @return  array|null array of users to exclude or null to to not exclude them | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function getExcluded() | ||||
| 	{ | ||||
| 		return array(JFactory::getUser()->id); | ||||
| 	} | ||||
| } | ||||
| @ -0,0 +1,39 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <form> | ||||
| 	<fieldset> | ||||
| 		<field | ||||
| 			name="lock" | ||||
| 			type="radio" | ||||
| 			class="btn-group" | ||||
| 			label="COM_MESSAGES_FIELD_LOCK_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_LOCK_DESC" | ||||
| 			default="0"> | ||||
| 			<option | ||||
| 				value="1">JYES</option> | ||||
| 			<option | ||||
| 				value="0">JNO</option> | ||||
| 		</field> | ||||
|  | ||||
| 		<field | ||||
| 			name="mail_on_new" | ||||
| 			type="radio" | ||||
| 			class="btn-group" | ||||
| 			label="COM_MESSAGES_FIELD_MAIL_ON_NEW_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_MAIL_ON_NEW_DESC" | ||||
| 			default="1"> | ||||
| 			<option | ||||
| 				value="1">JYES</option> | ||||
| 			<option | ||||
| 				value="0">JNO</option> | ||||
| 		</field> | ||||
|  | ||||
| 		<field | ||||
| 			name="auto_purge" | ||||
| 			type="text" | ||||
| 			class="inputbox" | ||||
| 			size="6" | ||||
| 			default="7" | ||||
| 			label="COM_MESSAGES_FIELD_AUTO_PURGE_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_AUTO_PURGE_DESC" /> | ||||
| 	</fieldset> | ||||
| </form> | ||||
| @ -0,0 +1 @@ | ||||
| <!DOCTYPE html><title></title> | ||||
| @ -0,0 +1,30 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <form> | ||||
| 	<fieldset> | ||||
| 		<field | ||||
| 			name="user_id_to" | ||||
| 			type="usermessages" | ||||
| 			label="COM_MESSAGES_FIELD_USER_ID_TO_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_USER_ID_TO_DESC" | ||||
| 			default="0" | ||||
| 			required="true" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="subject" | ||||
| 			type="text" | ||||
| 			label="COM_MESSAGES_FIELD_SUBJECT_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_SUBJECT_DESC" | ||||
| 			required="true" /> | ||||
|  | ||||
| 		<field | ||||
| 			name="message" | ||||
| 			type="editor" | ||||
| 			class="inputbox" | ||||
| 			label="COM_MESSAGES_FIELD_MESSAGE_LABEL" | ||||
| 			description="COM_MESSAGES_FIELD_MESSAGE_DESC" | ||||
| 			required="true" | ||||
| 			filter="JComponentHelper::filterText" | ||||
| 			buttons="true" | ||||
| 			hide="readmore,pagebreak,image,article" /> | ||||
| 	</fieldset> | ||||
| </form> | ||||
							
								
								
									
										1
									
								
								administrator/components/com_messages/models/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1
									
								
								administrator/components/com_messages/models/index.html
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1 @@ | ||||
| <!DOCTYPE html><title></title> | ||||
							
								
								
									
										325
									
								
								administrator/components/com_messages/models/message.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										325
									
								
								administrator/components/com_messages/models/message.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,325 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Private Message model. | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class MessagesModelMessage extends JModelAdmin | ||||
| { | ||||
| 	/** | ||||
| 	 * message | ||||
| 	 */ | ||||
| 	protected $item; | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function populateState() | ||||
| 	{ | ||||
| 		parent::populateState(); | ||||
|  | ||||
| 		$input = JFactory::getApplication()->input; | ||||
|  | ||||
| 		$user = JFactory::getUser(); | ||||
| 		$this->setState('user.id', $user->get('id')); | ||||
|  | ||||
| 		$messageId = (int) $input->getInt('message_id'); | ||||
| 		$this->setState('message.id', $messageId); | ||||
|  | ||||
| 		$replyId = (int) $input->getInt('reply_id'); | ||||
| 		$this->setState('reply.id', $replyId); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Check that recipient user is the one trying to delete and then call parent delete method | ||||
| 	 * | ||||
| 	 * @param   array  &$pks  An array of record primary keys. | ||||
| 	 * | ||||
| 	 * @return  boolean  True if successful, false if an error occurs. | ||||
| 	 * | ||||
| 	 * @since  3.1 | ||||
| 	 */ | ||||
| 	public function delete(&$pks) | ||||
| 	{ | ||||
| 		$pks = (array) $pks; | ||||
| 		$table = $this->getTable(); | ||||
| 		$user = JFactory::getUser(); | ||||
|  | ||||
| 		// Iterate the items to delete each one. | ||||
| 		foreach ($pks as $i => $pk) | ||||
| 		{ | ||||
| 			if ($table->load($pk)) | ||||
| 			{ | ||||
| 				if ($table->user_id_to !== $user->id) | ||||
| 				{ | ||||
| 					// Prune items that you can't change. | ||||
| 					unset($pks[$i]); | ||||
| 					JLog::add(JText::_('JLIB_APPLICATION_ERROR_DELETE_NOT_PERMITTED'), JLog::WARNING, 'jerror'); | ||||
| 					return false; | ||||
| 				} | ||||
| 			} | ||||
| 			else | ||||
| 			{ | ||||
| 				$this->setError($table->getError()); | ||||
| 				return false; | ||||
| 			} | ||||
| 		} | ||||
| 		return parent::delete($pks); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Returns a Table object, always creating it. | ||||
| 	 * | ||||
| 	 * @param   type	The table type to instantiate | ||||
| 	 * @param   string	A prefix for the table class name. Optional. | ||||
| 	 * @param   array  Configuration array for model. Optional. | ||||
| 	 * @return  JTable	A database object | ||||
| 	 * @since   1.6 | ||||
| 	*/ | ||||
| 	public function getTable($type = 'Message', $prefix = 'MessagesTable', $config = array()) | ||||
| 	{ | ||||
| 		return JTable::getInstance($type, $prefix, $config); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a single record. | ||||
| 	 * | ||||
| 	 * @param   integer	The id of the primary key. | ||||
| 	 * @return  mixed  Object on success, false on failure. | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function getItem($pk = null) | ||||
| 	{ | ||||
| 		if (!isset($this->item)) | ||||
| 		{ | ||||
| 			if ($this->item = parent::getItem($pk)) | ||||
| 			{ | ||||
| 				// Prime required properties. | ||||
| 				if (empty($this->item->message_id)) | ||||
| 				{ | ||||
| 					// Prepare data for a new record. | ||||
| 					if ($replyId = $this->getState('reply.id')) | ||||
| 					{ | ||||
| 						// If replying to a message, preload some data. | ||||
| 						$db		= $this->getDbo(); | ||||
| 						$query	= $db->getQuery(true) | ||||
| 							->select('subject, user_id_from') | ||||
| 							->from('#__messages') | ||||
| 							->where('message_id = '.(int) $replyId); | ||||
|  | ||||
| 						try | ||||
| 						{ | ||||
| 							$message = $db->setQuery($query)->loadObject(); | ||||
| 						} | ||||
| 						catch (RuntimeException $e) | ||||
| 						{ | ||||
| 							$this->setError($e->getMessage()); | ||||
| 							return false; | ||||
| 						} | ||||
|  | ||||
| 						$this->item->set('user_id_to', $message->user_id_from); | ||||
| 						$re = JText::_('COM_MESSAGES_RE'); | ||||
| 						if (stripos($message->subject, $re) !== 0) | ||||
| 						{ | ||||
| 							$this->item->set('subject', $re.$message->subject); | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 				elseif ($this->item->user_id_to != JFactory::getUser()->id) | ||||
| 				{ | ||||
| 					$this->setError(JText::_('JERROR_ALERTNOAUTHOR')); | ||||
| 					return false; | ||||
| 				} | ||||
| 				else { | ||||
| 					// Mark message read | ||||
| 					$db		= $this->getDbo(); | ||||
| 					$query	= $db->getQuery(true) | ||||
| 						->update('#__messages') | ||||
| 						->set('state = 1') | ||||
| 						->where('message_id = '.$this->item->message_id); | ||||
| 					$db->setQuery($query)->execute(); | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 			// Get the user name for an existing messasge. | ||||
| 			if ($this->item->user_id_from && $fromUser = new JUser($this->item->user_id_from)) | ||||
| 			{ | ||||
| 				$this->item->set('from_user_name', $fromUser->name); | ||||
| 			} | ||||
| 		} | ||||
| 		return $this->item; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get the record 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  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_messages.message', 'message', array('control' => 'jform', 'load_data' => $loadData)); | ||||
| 		if (empty($form)) | ||||
| 		{ | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		return $form; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * 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_messages.edit.message.data', array()); | ||||
|  | ||||
| 		if (empty($data)) | ||||
| 		{ | ||||
| 			$data = $this->getItem(); | ||||
| 		} | ||||
|  | ||||
| 		$this->preprocessData('com_messages.message', $data); | ||||
|  | ||||
| 		return $data; | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Checks that the current user matches the message recipient and calls the parent publish method | ||||
| 	 * | ||||
| 	 * @param   array    &$pks   A list of the primary keys to change. | ||||
| 	 * @param   integer  $value  The value of the published state. | ||||
| 	 * | ||||
| 	 * @return  boolean  True on success. | ||||
| 	 * | ||||
| 	 * @since   3.1 | ||||
| 	 */ | ||||
| 	public function publish(&$pks, $value = 1) | ||||
| 	{ | ||||
| 		$user = JFactory::getUser(); | ||||
| 		$table = $this->getTable(); | ||||
| 		$pks = (array) $pks; | ||||
|  | ||||
| 		// Check that the recipient matches the current user | ||||
| 		foreach ($pks as $i => $pk) | ||||
| 		{ | ||||
| 			$table->reset(); | ||||
|  | ||||
| 			if ($table->load($pk)) | ||||
| 			{ | ||||
| 				if ($table->user_id_to !== $user->id) | ||||
| 				{ | ||||
| 					// Prune items that you can't change. | ||||
| 					unset($pks[$i]); | ||||
| 					JLog::add(JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'), JLog::WARNING, 'jerror'); | ||||
| 					return false; | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
| 		} | ||||
|  | ||||
| 		return parent::publish($pks, $value); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to save the form data. | ||||
| 	 * | ||||
| 	 * @param   array  The form data. | ||||
| 	 * | ||||
| 	 * @return  boolean  True on success. | ||||
| 	 */ | ||||
| 	public function save($data) | ||||
| 	{ | ||||
| 		$table = $this->getTable(); | ||||
|  | ||||
| 		// Bind the data. | ||||
| 		if (!$table->bind($data)) | ||||
| 		{ | ||||
| 			$this->setError($table->getError()); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Assign empty values. | ||||
| 		if (empty($table->user_id_from)) | ||||
| 		{ | ||||
| 			$table->user_id_from = JFactory::getUser()->get('id'); | ||||
| 		} | ||||
| 		if ((int) $table->date_time == 0) | ||||
| 		{ | ||||
| 			$table->date_time = JFactory::getDate()->toSql(); | ||||
| 		} | ||||
|  | ||||
| 		// Check the data. | ||||
| 		if (!$table->check()) | ||||
| 		{ | ||||
| 			$this->setError($table->getError()); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Load the recipient user configuration. | ||||
| 		$model = JModelLegacy::getInstance('Config', 'MessagesModel', array('ignore_request' => true)); | ||||
| 		$model->setState('user.id', $table->user_id_to); | ||||
| 		$config = $model->getItem(); | ||||
| 		if (empty($config)) | ||||
| 		{ | ||||
| 			$this->setError($model->getError()); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		if ($config->get('locked', false)) | ||||
| 		{ | ||||
| 			$this->setError(JText::_('COM_MESSAGES_ERR_SEND_FAILED')); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		// Store the data. | ||||
| 		if (!$table->store()) | ||||
| 		{ | ||||
| 			$this->setError($table->getError()); | ||||
| 			return false; | ||||
| 		} | ||||
|  | ||||
| 		if ($config->get('mail_on_new', true)) | ||||
| 		{ | ||||
| 			// Load the user details (already valid from table check). | ||||
| 			$fromUser = JUser::getInstance($table->user_id_from); | ||||
| 			$toUser = JUser::getInstance($table->user_id_to); | ||||
| 			$debug = JFactory::getConfig()->get('debug_lang'); | ||||
| 			$default_language = JComponentHelper::getParams('com_languages')->get('administrator'); | ||||
| 			$lang = JLanguage::getInstance($toUser->getParam('admin_language', $default_language), $debug); | ||||
| 			$lang->load('com_messages', JPATH_ADMINISTRATOR); | ||||
|  | ||||
| 			$siteURL  = JUri::root() . 'administrator/index.php?option=com_messages&view=message&message_id='.$table->message_id; | ||||
| 			$sitename = JFactory::getApplication()->getCfg('sitename'); | ||||
|  | ||||
| 			$subject = sprintf($lang->_('COM_MESSAGES_NEW_MESSAGE_ARRIVED'), $sitename); | ||||
| 			$msg     = sprintf($lang->_('COM_MESSAGES_PLEASE_LOGIN'), $siteURL); | ||||
| 			JFactory::getMailer()->sendMail($fromUser->email, $fromUser->name, $toUser->email, $subject, $msg); | ||||
| 		} | ||||
|  | ||||
| 		return true; | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										138
									
								
								administrator/components/com_messages/models/messages.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										138
									
								
								administrator/components/com_messages/models/messages.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,138 @@ | ||||
| <?php | ||||
| /** | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * | ||||
|  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved. | ||||
|  * @license     GNU General Public License version 2 or later; see LICENSE.txt | ||||
|  */ | ||||
|  | ||||
| defined('_JEXEC') or die; | ||||
|  | ||||
| /** | ||||
|  * Messages Component Messages Model | ||||
|  * | ||||
|  * @package     Joomla.Administrator | ||||
|  * @subpackage  com_messages | ||||
|  * @since       1.6 | ||||
|  */ | ||||
| class MessagesModelMessages extends JModelList | ||||
| { | ||||
| 	/** | ||||
| 	 * Constructor. | ||||
| 	 * | ||||
| 	 * @param   array  An optional associative array of configuration settings. | ||||
| 	 * @see     JController | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	public function __construct($config = array()) | ||||
| 	{ | ||||
| 		if (empty($config['filter_fields'])) | ||||
| 		{ | ||||
| 			$config['filter_fields'] = array( | ||||
| 				'message_id', 'a.id', | ||||
| 				'subject', 'a.subject', | ||||
| 				'state', 'a.state', | ||||
| 				'user_id_from', 'a.user_id_from', | ||||
| 				'user_id_to', 'a.user_id_to', | ||||
| 				'date_time', 'a.date_time', | ||||
| 				'priority', 'a.priority', | ||||
| 			); | ||||
| 		} | ||||
|  | ||||
| 		parent::__construct($config); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to auto-populate the model state. | ||||
| 	 * | ||||
| 	 * Note. Calling getState in this method will result in recursion. | ||||
| 	 * | ||||
| 	 * @since   1.6 | ||||
| 	 */ | ||||
| 	protected function populateState($ordering = null, $direction = null) | ||||
| 	{ | ||||
| 		// Load the filter state. | ||||
| 		$search = $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search'); | ||||
| 		$this->setState('filter.search', $search); | ||||
|  | ||||
| 		$state = $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'string'); | ||||
| 		$this->setState('filter.state', $state); | ||||
|  | ||||
| 		// List state information. | ||||
| 		parent::populateState('a.date_time', 'desc'); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Method to get a store id based on model configuration state. | ||||
| 	 * | ||||
| 	 * This is necessary because the model is used by the component and | ||||
| 	 * different modules that might need different sets of data or different | ||||
| 	 * ordering requirements. | ||||
| 	 * | ||||
| 	 * @param   string    A prefix for the store id. | ||||
| 	 * | ||||
| 	 * @return  string    A store id. | ||||
| 	 */ | ||||
| 	protected function getStoreId($id = '') | ||||
| 	{ | ||||
| 		// Compile the store id. | ||||
| 		$id .= ':' . $this->getState('filter.search'); | ||||
| 		$id .= ':' . $this->getState('filter.state'); | ||||
|  | ||||
| 		return parent::getStoreId($id); | ||||
| 	} | ||||
|  | ||||
| 	/** | ||||
| 	 * Build an SQL query to load the list data. | ||||
| 	 * | ||||
| 	 * @return  JDatabaseQuery | ||||
| 	 */ | ||||
| 	protected function getListQuery() | ||||
| 	{ | ||||
| 		// Create a new query object. | ||||
| 		$db = $this->getDbo(); | ||||
| 		$query = $db->getQuery(true); | ||||
| 		$user = JFactory::getUser(); | ||||
|  | ||||
| 		// Select the required fields from the table. | ||||
| 		$query->select( | ||||
| 			$this->getState( | ||||
| 				'list.select', | ||||
| 				'a.*, ' . | ||||
| 					'u.name AS user_from' | ||||
| 			) | ||||
| 		); | ||||
| 		$query->from('#__messages AS a'); | ||||
|  | ||||
| 		// Join over the users for message owner. | ||||
| 		$query->join('INNER', '#__users AS u ON u.id = a.user_id_from') | ||||
| 			->where('a.user_id_to = ' . (int) $user->get('id')); | ||||
|  | ||||
| 		// Filter by published state. | ||||
| 		$state = $this->getState('filter.state'); | ||||
| 		if (is_numeric($state)) | ||||
| 		{ | ||||
| 			$query->where('a.state = ' . (int) $state); | ||||
| 		} | ||||
| 		elseif ($state === '') | ||||
| 		{ | ||||
| 			$query->where('(a.state IN (0, 1))'); | ||||
| 		} | ||||
|  | ||||
| 		// Filter by search in subject or message. | ||||
| 		$search = $this->getState('filter.search'); | ||||
|  | ||||
| 		if (!empty($search)) | ||||
| 		{ | ||||
| 			$search = $db->quote('%' . $db->escape($search, true) . '%', false); | ||||
| 			$query->where('a.subject LIKE ' . $search . ' OR a.message LIKE ' . $search); | ||||
| 		} | ||||
|  | ||||
| 		// Add the list ordering clause. | ||||
| 		$query->order($db->escape($this->getState('list.ordering', 'a.date_time')) . ' ' . $db->escape($this->getState('list.direction', 'DESC'))); | ||||
|  | ||||
| 		//echo nl2br(str_replace('#__','jos_',$query)); | ||||
| 		return $query; | ||||
| 	} | ||||
| } | ||||
		Reference in New Issue
	
	Block a user
	 alazhar
					alazhar