Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manager for Language Overrides #31

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0a56caa
Initial Commit for Language Overrides Manager
Chraneco Dec 2, 2011
aabb258
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 4, 2011
ac704aa
Clean up - Small improvements - Code Style
Chraneco Dec 6, 2011
6436ed1
Accidentally commited file removed
Chraneco Dec 6, 2011
bd40599
'No Results' message added
Chraneco Dec 6, 2011
d8c945b
Undesired change in Mootools reverted - Key word static was missing in
Chraneco Dec 8, 2011
3ba5e01
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 8, 2011
c69156c
Clean Up - Small Improvements
Chraneco Dec 8, 2011
4de201b
JavaScript Error in Internet Explorer
Chraneco Dec 8, 2011
4d42ff9
Code Style - Small Improvements and additions
Chraneco Dec 10, 2011
ee3ce77
Button in edit view removed, description added, display of file added
Chraneco Dec 10, 2011
2d2e100
Code style improvement
Chraneco Dec 10, 2011
71490d5
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 10, 2011
f56b019
PHP notice while storing an entry
Chraneco Dec 10, 2011
9a5b3f0
Two filter boxes merged into one - Style improved
Chraneco Dec 11, 2011
635b4b1
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 11, 2011
cb5e792
Use default frontend language as default filter - Pagination did not
Chraneco Dec 11, 2011
ae23787
Try to translate select box contents only once
Chraneco Dec 12, 2011
3b939c6
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 12, 2011
2cb6f8a
Possibility to select search type ('constant', 'value', 'file')
Chraneco Dec 14, 2011
5686deb
Merge remote-tracking branch 'upstream/master'
Chraneco Dec 14, 2011
e6d6661
Removing third search type 'file' again
Chraneco Dec 14, 2011
3d90270
Go on using the same search string with 'more' link even if it was ch…
Chraneco Dec 14, 2011
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
195 changes: 195 additions & 0 deletions administrator/components/com_languages/controllers/override.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_languages
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;

jimport('joomla.application.component.controllerform');

/**
* Languages Override Controller
*
* @package Joomla.Administrator
* @subpackage com_languages
* @since 2.5
*/
class LanguagesControllerOverride extends JControllerForm
{
/**
* Method to edit an existing override
*
* @return void
*
* @since 2.5
*/
public function edit()
{
// Initialize variables
$app = JFactory::getApplication();
$cid = JRequest::getVar('cid', array(), 'post', 'array');
$context = "$this->option.edit.$this->context";

// Get the constant name
$recordId = (count($cid) ? $cid[0] : JRequest::getCmd('id'));

// Access check
if (!$this->allowEdit())
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_EDIT_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));

return;
}

$app->setUserState($context.'.data', null);
$this->setRedirect('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'));
}

/**
* Method to save an override
*
* @return void
*
* @since 2.5
*/
public function save()
{
// Check for request forgeries
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

// Initialize variables
$app = JFactory::getApplication();
$model = $this->getModel();
$data = JRequest::getVar('jform', array(), 'post', 'array');
$context = "$this->option.edit.$this->context";
$task = $this->getTask();

$recordId = JRequest::getCmd('id');
$data['id'] = $recordId;

// Access check
if (!$this->allowSave($data, 'id'))
{
$this->setError(JText::_('JLIB_APPLICATION_ERROR_SAVE_NOT_PERMITTED'));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));

return;
}

// Validate the posted data
$form = $model->getForm($data, false);
if (!$form)
{
$app->enqueueMessage($model->getError(), 'error');

return;
}

// Require helper for filter functions called by JForm
require_once JPATH_COMPONENT.'/helpers/languages.php';

// Test whether the data is valid.
$validData = $model->validate($form, $data);

// Check for validation errors.
if ($validData === 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($context.'.data', $data);

// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false));

return;
}

// Attempt to save the data
if (!$model->save($validData))
{
// Save the data in the session
$app->setUserState($context.'.data', $validData);

// Redirect back to the edit screen
$this->setError(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()));
$this->setMessage($this->getError(), 'error');
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($recordId, 'id'), false));

return;
}

// Add message of success
$this->setMessage(JText::_('COM_LANGUAGES_VIEW_OVERRIDE_SAVE_SUCCESS'));

// Redirect the user and adjust session state based on the chosen task
switch ($task)
{
case 'apply':
// Set the record data in the session
$recordId = $model->getState($this->context.'.id');
$app->setUserState($context.'.data', null);

// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend($validData['key'], 'id'), false));
break;

case 'save2new':
// Clear the record id and data from the session
$app->setUserState($context.'.data', null);

// Redirect back to the edit screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.$this->getRedirectToItemAppend(null, 'id'), false));
break;

default:
// Clear the record id and data from the session
$app->setUserState($context.'.data', null);

// Redirect to the list screen
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
break;
}
}

/**
* Method to cancel an edit
*
* @return void
*
* @since 2.5
*/
public function cancel()
{
JRequest::checkToken() or jexit(JText::_('JINVALID_TOKEN'));

// Initialize variables
$app = JFactory::getApplication();
$context = "$this->option.edit.$this->context";

$app->setUserState($context.'.data', null);
$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list.$this->getRedirectToListAppend(), false));
}
}
69 changes: 69 additions & 0 deletions administrator/components/com_languages/controllers/overrides.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_languages
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;

jimport('joomla.application.component.controlleradmin');

/**
* Languages Overrides Controller
*
* @package Joomla.Administrator
* @subpackage com_languages
* @since 2.5
*/
class LanguagesControllerOverrides extends JControllerAdmin
{
/**
* The prefix to use with controller messages
*
* @var string
* @since 2.5
*/
protected $text_prefix = 'COM_LANGUAGES_VIEW_OVERRIDES';

/**
* Method for deleting one or more overrides
*
* @return void
*
* @since 2.5
*/
public function delete()
{
// Check for request forgeries
JRequest::checkToken() or die(JText::_('JINVALID_TOKEN'));

// Get items to dlete from the request
$cid = JRequest::getVar('cid', array(), '', 'array');

if (!is_array($cid) || count($cid) < 1)
{
$this->setMessage(JText::_($this->text_prefix.'_NO_ITEM_SELECTED'), 'warning');
}
else
{
// Get the model
$model = $this->getModel('overrides');

// Remove the items
if ($model->delete($cid))
{
$this->setMessage(JText::plural($this->text_prefix.'_N_ITEMS_DELETED', count($cid)));
}
else
{
$this->setMessage($model->getError());
}
}

$this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_list, false));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* @version $Id$
* @package Joomla.Administrator
* @subpackage com_languages
* @copyright Copyright (C) 2005 - 2011 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die;

jimport('joomla.application.component.controlleradmin');

/**
* Languages Strings JSON Controller
*
* @package Joomla.Administrator
* @subpackage com_languages
* @since 2.5
*/
class LanguagesControllerStrings extends JControllerAdmin
{
/**
* Constructor
*
* @param array An optional associative array of configuration settings
*
* @return void
*
* @since 2.5
*/
public function __construct($config = array())
{
parent::__construct($config);

require_once JPATH_COMPONENT.DS.'helpers'.DS.'jsonresponse.php';
}

/**
* Method for refreshing the cache in the database with the known language strings
*
* @return void
*
* @since 2.5
*/
public function refresh()
{
echo new JJsonResponse($this->getModel('strings')->refresh());
}

/**
* Method for searching language strings
*
* @return void
*
* @since 2.5
*/
public function search()
{
echo new JJsonResponse($this->getModel('strings')->search());
}
}
Loading