Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public function display($tpl = null)

try
{
$messages_model = FOFModel::getTmpInstance('Messages', 'PostinstallModel')->eid(700);
$messages = $messages_model->getItemList();
JModelLegacy::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_postinstall/models');
$messages_model = JModelLegacy::getInstance('Messages', 'PostinstallModel', array('ignore_request' => true));

$messages = $messages_model->getItems();
}
catch (RuntimeException $e)
{
Expand All @@ -59,7 +61,6 @@ public function display($tpl = null)
// Still render the error message from the Exception object
JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
}

$this->postinstall_message_count = count($messages);

parent::display($tpl);
Expand Down
44 changes: 44 additions & 0 deletions administrator/components/com_postinstall/controller.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* @package Joomla.Administrator
* @subpackage com_postinstall
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* Postinstall display controller
*
* @since 3.6
*/

class PostinstallController extends JControllerLegacy
{
/**
* @var string The default view.
* @since 1.6
*/
protected $default_view = 'messages';

/**
* Method to display a view.
*
* @param boolean $cachable If true, the view output will be cached
* @param array $urlparams An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
*
* @return PostinstallController This object to support chaining.
*
* @since 1.5
*/
public function display($cachable = false, $urlparams = false)
{
$view = $this->input->get('view', 'messages');

parent::display();

return $this;
}
}
53 changes: 37 additions & 16 deletions administrator/components/com_postinstall/controllers/message.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*
* @since 3.2
*/
class PostinstallControllerMessage extends FOFController
class PostinstallControllerMessage extends JControllerLegacy
{
/**
* Resets all post-installation messages of the specified extension.
Expand All @@ -26,9 +26,9 @@ class PostinstallControllerMessage extends FOFController
public function reset()
{
/** @var PostinstallModelMessages $model */
$model = $this->getThisModel();
$model = $this->getModel('Messages', 'PostinstallModel', array('ignore_request' => true));

$eid = (int) $model->getState('eid', '700', 'int');
$eid = (int) $model->getState('eid', '700');

if (empty($eid))
{
Expand All @@ -41,28 +41,48 @@ public function reset()
}

/**
* Executes the action associated with an item.
* Unpublishes post-installation message of the specified extension.
*
* @return void
* @return void
*
* @since 3.2
*/
public function action()
public function unpublish()
{
// CSRF prevention.
if ($this->csrfProtection)
{
$this->_csrfProtection();
}
$model = $this->getModel('Messages', 'PostinstallModel', array('ignore_request' => true));

$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id');

$model = $this->getThisModel();
$eid = (int) $model->getState('eid', '700');

if (!$model->getId())
if (empty($eid))
{
$model->setIDsFromRequest();
$eid = 700;
}

$item = $model->getItem();
$model->setState('published', 0);
$model->unpublishMessage($id);

$this->setRedirect('index.php?option=com_postinstall&eid=' . $eid);
}

/**
* Executes the action associated with an item.
*
* @return void
*
* @since 3.2
*/
public function action()
{
require_once JPATH_ADMINISTRATOR . '/components/com_postinstall/helpers/postinstall.php';
$model = $this->getModel('Messages', 'PostinstallModel', array('ignore_request' => true));

$jinput = JFactory::getApplication()->input;
$id = $jinput->get('id');

$item = $model->getItem($id);

switch ($item->type)
{
Expand All @@ -76,7 +96,8 @@ public function action()
case 'action':
jimport('joomla.filesystem.file');

$file = FOFTemplateUtils::parsePath($item->action_file, true);
$helper = new PostinstallHelper;
$file = $helper->parsePath($item->action_file);

if (JFile::exists($file))
{
Expand Down
18 changes: 0 additions & 18 deletions administrator/components/com_postinstall/fof.xml

This file was deleted.

42 changes: 42 additions & 0 deletions administrator/components/com_postinstall/helpers/postinstall.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

/**
* @package Joomla.Administrator
* @subpackage com_postinstall
*
* @copyright Copyright (C) 2005 - 2016 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

/**
* Helper class for postinstall messages
*
* @since 3.6
*/
class PostinstallHelper
{
/**
* Method for parsing ini files.
*
* @param string $path Fancy path.
*
* @return string Parsed path.
*
* @since 3.6
*/
public function parsePath($path)
{
if (strpos($path, 'site://') !== false)
{
$path = JPATH_ROOT . str_replace('site://', '/', $path);
}
elseif (strpos($path, 'admin://') !== false)
{
$path = JPATH_ADMINISTRATOR . str_replace('admin://', '/', $path);
}

return $path;
}
}
112 changes: 101 additions & 11 deletions administrator/components/com_postinstall/models/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,37 +9,124 @@

defined('_JEXEC') or die;

require_once JPATH_ADMINISTRATOR . '/components/com_postinstall/helpers/postinstall.php';

/**
* Model class to manage postinstall messages
*
* @since 3.2
*/
class PostinstallModelMessages extends FOFModel
class PostinstallModelMessages extends JModelLegacy
{
/**
* Builds the SELECT query
* Gets an item with the given id from the database
*
* @param boolean $overrideLimits Are we requested to override the set limits?
* @param integer $id The item id
*
* @return JDatabaseQuery
* @return Object
*
* @since 3.2
*/
public function buildQuery($overrideLimits = false)
public function getItem($id)
{
$query = parent::buildQuery($overrideLimits);
$db = $this->getDbo();

$query = $db->getQuery(true);
$query->select(
$db->quoteName(
array
('postinstall_message_id',
'extension_id',
'title_key',
'description_key',
'action_key',
'language_extension',
'language_client_id',
'type',
'action_file',
'action',
'condition_file',
'condition_method',
'version_introduced',
'enabled')
)
)->from($db->quoteName('#__postinstall_messages'))->where($db->qn('postinstall_message_id') . ' = ' . $db->q($id));

$db->setQuery($query);

$result = $db->loadObject();

return $result;
}

/**
* Unpublishes specified post-install message
*
* @param integer $id The message id
*
* @return void
*/
public function unpublishMessage($id)
{
$db = $this->getDbo();

$query = $db->getQuery(true);
$query->update($db->quoteName('#__postinstall_messages'))
->set($db->qn('enabled') . ' = ' . $db->q(0))->where($db->qn('postinstall_message_id') . ' = ' . $db->q($id));
$db->setQuery($query);
$db->execute();
}

/**
* Returns a list of messages from the #__postinstall_messages table
*
* @return Object
*
* @since 3.2
*/
public function getItems()
{
$db = $this->getDbo();

$query = $db->getQuery(true);

$query->select(
$db->quoteName(
array
('postinstall_message_id',
'extension_id',
'title_key',
'description_key',
'action_key',
'language_extension',
'language_client_id',
'type',
'action_file',
'action',
'condition_file',
'condition_method',
'version_introduced',
'enabled')
)
);

// Add a forced extension filtering to the list
$eid = $this->getState('eid', 700);
$query->where($db->qn('extension_id') . ' = ' . $db->q($eid));

// Force filter only enabled messages
$published = $this->getState('published', 1, 'int');
$published = $this->getState('published', 1);
$query->where($db->qn('enabled') . ' = ' . $db->q($published));

return $query;
$query->from($db->quoteName('#__postinstall_messages'));

$db->setQuery($query);

$result = $db->loadObjectList();

$this->onProcessList($result);

return $result;
}

/**
Expand Down Expand Up @@ -136,7 +223,8 @@ protected function onProcessList(&$resultArray)
{
jimport('joomla.filesystem.file');

$file = FOFTemplateUtils::parsePath($item->condition_file, true);
$helper = new PostinstallHelper;
$file = $helper->parsePath($item->condition_file);

if (JFile::exists($file))
{
Expand Down Expand Up @@ -371,7 +459,8 @@ public function addPostInstallationMessage(array $options)
throw new Exception('Post-installation message definitions need an action file when they are of type "action"', 500);
}

$file_path = FOFTemplateUtils::parsePath($options['action_file'], true);
$helper = new PostinstallHelper;
$file_path = $helper->parsePath($options['action_file']);

if (!@is_file($file_path))
{
Expand Down Expand Up @@ -400,7 +489,8 @@ public function addPostInstallationMessage(array $options)
throw new Exception('Post-installation message definitions need a condition file when they are of type "' . $options['type'] . '"', 500);
}

$file_path = FOFTemplateUtils::parsePath($options['condition_file'], true);
$helper = new PostinstallHelper;
$file_path = $helper->parsePath($options['condition_file']);

if (!@is_file($file_path))
{
Expand Down
11 changes: 9 additions & 2 deletions administrator/components/com_postinstall/postinstall.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,12 @@

defined('_JEXEC') or die;

// Dispatch the component.
FOFDispatcher::getTmpInstance('com_postinstall')->dispatch();
// Access check.
if (!JFactory::getUser()->authorise('core.manage', 'com_postinstall'))
{
return JError::raiseWarning(404, JText::_('JERROR_ALERTNOAUTHOR'));
}

$controller = JControllerLegacy::getInstance('Postinstall');
$controller->execute(JFactory::getApplication()->input->get('task'));
$controller->redirect();
Loading