GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — develop ( fdaf56...d74b32 )
by
unknown
9s
created

LocaliseControllerLanguage::copy()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 27
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 27
rs 8.8571
cc 3
eloc 15
nc 4
nop 0
1
<?php
2
/**
3
 * @package     Com_Localise
4
 * @subpackage  controller
5
 *
6
 * @copyright   Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
7
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
8
 */
9
10
defined('_JEXEC') or die;
11
12
/**
13
 * Language Controller class for the Localise component
14
 *
15
 * @package     Extensions.Components
16
 * @subpackage  Localise
17
 *
18
 * @since       1.0
19
 */
20
class LocaliseControllerLanguage extends JControllerForm
21
{
22
	/**
23
	 * Method to get a model object, loading it if required.
24
	 *
25
	 * @param   string  $name    The model name. Optional.
26
	 * @param   string  $prefix  The class prefix. Optional.
27
	 * @param   array   $config  Configuration array for model. Optional.
28
	 *
29
	 * @return  object  The model.
30
	 */
31
	public function getModel($name = 'Language', $prefix = 'LocaliseModel', $config = array('ignore_request' => true))
32
	{
33
		return parent::getModel($name, $prefix, array('ignore_request' => false));
34
	}
35
36
	/**
37
	 * Method to check if you can add a new record.
38
	 *
39
	 * Extended classes can override this if necessary.
40
	 *
41
	 * @param   array  $data  An array of input data.
42
	 *
43
	 * @return  boolean
44
	 */
45
	protected function allowAdd($data = array())
46
	{
47
		return JFactory::getUser()->authorise('localise.create', $this->option);
48
	}
49
50
	/**
51
	 * Method to check if you can add a new record.
52
	 *
53
	 * Extended classes can override this if necessary.
54
	 *
55
	 * @param   array   $data  An array of input data.
56
	 * @param   string  $key   The name of the key for the primary key.
57
	 *
58
	 * @return  boolean
59
	 */
60
	protected function allowEdit($data = array(), $key = 'id')
61
	{
62
		return JFactory::getUser()->authorise('localise.edit', $this->option . '.' . $data[$key]);
63
	}
64
65
	/**
66
	 * Gets the URL arguments to append to an item redirect.
67
	 *
68
	 * @param   int     $recordId  The primary key id for the item.
69
	 * @param   string  $urlVar    The name of the URL variable for the id.
70
	 *
71
	 * @return  string  The arguments to append to the redirect URL.
72
	 */
73
	protected function getRedirectToItemAppend($recordId = null, $urlVar = 'id')
74
	{
75
		// Get the infos
76
		$input = JFactory::getApplication()->input;
77
		$client = $input->get('client', '');
78
79
		if (empty($client))
80
		{
81
			$data = $input->get('jform', array(), 'array');
82
83
			if ($data)
84
			{
85
				$client = $data['client'];
86
			}
87
		}
88
89
		if (empty($client))
90
		{
91
			$select = $input->get('filters', array(), 'array');
92
			$client = isset($select['select']['client']) ? $select['select']['client'] : 'site';
93
		}
94
95
		$tag = $input->get('tag', '');
96
97
		if (empty($tag))
98
		{
99
			$tag = isset($data['tag']) ? $data['tag'] : '';
100
		}
101
102
		// Get the append string
103
		$append = parent::getRedirectToItemAppend($recordId, $urlVar);
104
		$append .= '&client=' . $client . '&tag=' . $tag;
105
106
		return $append;
107
	}
108
109
	/**
110
	 * Delete the language
111
	 *
112
	 * @return void
113
	 */
114
	public function delete()
115
	{
116
		// Check for request forgeries
117
		JSession::checkToken() or die(JText::_('JINVALID_TOKEN'));
118
119
		// Get the model.
120
		$model = $this->getModel();
121
122
		// Remove the items.
123
		if (!$model->delete())
124
		{
125
			$msg = implode("<br />", $model->getErrors());
126
			$type = 'error';
127
		}
128
		else
129
		{
130
			$msg = JText::_('COM_LOCALISE_MSG_LANGUAGES_REMOVED');
131
			$type = 'message';
132
		}
133
134
		$this->setRedirect(JRoute::_('index.php?option=com_localise&view=languages', false), $msg, $type);
135
	}
136
137
	/**
138
	 * Method for copying the language files from the reference language.
139
	 *
140
	 * @return  void
141
	 *
142
	 * @since   4.0.17
143
	 */
144
	public function copy()
145
	{
146
		// Check for request forgeries
147
		JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
148
149
		$app      = JFactory::getApplication();
150
		$model    = $this->getModel();
151
		$params   = JComponentHelper::getParams('com_localise');
152
		$data     = $app->input->get('jform', array(), 'array');
153
		$recordId = $app->input->getInt('id');
154
155
		$client  = $data['client'];
156
		$tag     = $data['tag'];
157
		$ref_tag = $params->get('reference', 'en-GB');
158
159
		$this->setRedirect(JRoute::_('index.php?option=com_localise&view=language' . $this->getRedirectToItemAppend($recordId), false));
160
161
		// Call model's copy method
162
		if (!$model->copy())
163
		{
164
			$app->enqueueMessage(JText::sprintf('COM_LOCALISE_ERROR_LANGUAGE_COULD_NOT_COPY_FILES', $client, $ref_tag, $tag), 'error');
165
166
			return false;
167
		}
168
169
		$this->setMessage(JText::sprintf('COM_LOCALISE_LANGUAGE_COPY_SUCCESS', $client, $ref_tag, $tag));
170
	}
171
}
172