Completed
Push — master ( 122868...c4a29e )
by Charles
02:55 queued 48s
created
protected/commands/CiiMessageCommand.php 1 patch
Indentation   +332 added lines, -332 removed lines patch added patch discarded remove patch
@@ -6,336 +6,336 @@  discard block
 block discarded – undo
6 6
 class CiiMessageCommand extends CiiConsoleCommand
7 7
 {
8 8
 
9
-	/**
10
-	 * The configuration object
11
-	 * @var array _$config
12
-	 */
13
-	private $_config = array();
14
-
15
-	/**
16
-	 * The messages that should be translated
17
-	 * @var array $_messages
18
-	 */
19
-	private $_messages = array();
20
-
21
-	/**
22
-	 * The stirng that should be used for translations
23
-	 * @var string $_translator
24
-	 */
25
-	private $_translator = 'Yii::t';
26
-
27
-	/**
28
-	 * Default args
29
-	 * @return array
30
-	 */
31
-	private function getArgs()
32
-	{
33
-		return array(
34
-			'type'			=> 'core',
35
-			'sourcePath'	=> Yii::getPathOfAlias('application').DS,
36
-			'messagePath'	=> Yii::getPathOfAlias('application.messages').DS,
37
-			'languages'		=> array('en_us'),
38
-			'fileTypes'		=> array('php'),
39
-			'overwrite'		=> true,
40
-			'sort'			=> true,
41
-			'removeOld'		=> false,
42
-			'exclude'		=> array(
43
-				'assets',
44
-				'css',
45
-				'js',
46
-				'images',
47
-				'.svn',
48
-				'.gitignore',
49
-				'.git',
50
-				'yiilite.php',
51
-				'yiit.php',
52
-				'i18n/data',
53
-				'messages',
54
-				'vendor',
55
-				'tests',
56
-				'runtime'
57
-			)
58
-		);
59
-	}
60
-
61
-	/**
62
-	 * Init method
63
-	 */
64
-	public function init()
65
-	{
66
-		$this->_config = $this->getArgs();
67
-	}
68
-
69
-	/**
70
- 	 * Generates translation files for a given mtheme
71
-	 * @param string $name 	The name of the theme to generate translations for
72
-	 */
73
-	public function actionThemes($name=NULL)
74
-	{
75
-		if ($name === NULL)
76
-			$this->usageError('A theme was not specified for translations');
77
-
78
-		$this->_config['type'] = 'theme';
79
-		array_push($this->_config['exclude'], 'modules');
80
-		$this->_config['sourcePath'] .= '..'.DS.'themes' . DS . $name . DS;
81
-		$this->_config['messagePath'] = $this->_config['sourcePath'].'messages';
82
-		$this->execute();
83
-	}
84
-
85
-	/**
86
- 	 * Generates translation files for a given module
87
-	 * @param string $name 	The name of the module to generate translations for
88
-	 */
89
-	public function actionModules($name=NULL)
90
-	{
91
-		if ($name === NULL)
92
-			$this->usageError('A module was not specified for translations');
93
-
94
-		$this->_config['type'] = 'module';
95
-		array_push($this->_config['exclude'], 'themes');
96
-		unset($this->_config['exclude']['modules']);
97
-		$this->_config['sourcePath'] = Yii::getPathOfAlias('application.modules') . DS . $name . DS;
98
-		$this->_config['messagePath'] = $this->_config['sourcePath'].'messages';
99
-		$this->execute($this->_config);
100
-	}
101
-
102
-	/**
103
- 	 * Defualt action
104
-	 */
105
-	public function actionIndex()
106
-	{
107
-		array_push($this->_config['exclude'], 'modules');
108
-		array_push($this->_config['exclude'], 'themes');
109
-		return $this->execute();
110
-	}
111
-
112
-	/**
113
-	 * Execute the action.
114
-	 */
115
-	private function execute()
116
-	{
117
-		// Validate the configuration
118
-		extract($this->_config);
119
-		$this->validateConfig();
120
-
121
-		// Determine the messages
122
-		foreach($this->getFiles() as $file)
123
-			$this->_messages = array_merge_recursive($this->_messages,$this->extractMessages($file,$this->_translator));
124
-
125
-		foreach($languages as $language)
126
-		{
127
-			$dir = $messagePath.DS.$language;
128
-
129
-			$this->createDirectory($dir);
130
-
131
-			foreach ($this->_messages as $category=>$msgs)
132
-			{
133
-				$msgs = array_values(array_unique($msgs));
134
-
135
-				$dir = $this->_config['messagePath'].DS.$language;
136
-
137
-				if ($this->_config['type']  == 'theme')
138
-				{
139
-					$data = explode('.', $category);
140
-					unset($data[0]);
141
-					$dirPath = implode(DS, $data);
142
-				}
143
-				else if ($this->_config['type'] == 'module')
144
-				{
145
-					$data = explode('.', $category);
146
-					unset($data[0]);
147
-					unset($data[1]);
148
-					$dirPath = implode(DS, $data);
149
-				}
150
-				else
151
-					$dirPath = implode(DS, explode('.', $category));
152
-
153
-				if (empty($dirPath))
154
-					continue;
155
-
156
-				$this->createDirectory($dir . DS . $dirPath);
157
-				$this->createDirectory($dir . DS . $language);
158
-
159
-				$this->generateMessageFile($msgs,$dir.DS.$dirPath.'.php',$overwrite,$removeOld,$sort);
160
-			}
161
-		}
162
-	}
163
-
164
-	/**
165
-	 * Creates a directory at the given path
166
-	 * @param string $directory
167
-	 * @return boolean
168
-	 */
169
-	private function createDirectory($directory)
170
-	{
171
-		if (!is_dir($directory)) 
172
-		{
173
-			if (!mkdir($directory, 0777, true))
174
-				$this->usageError('The directory ' . $directory .' could not be created. Please make sure this process has write access to this directory.');
175
-		}
176
-
177
-		return true;
178
-	}
179
-
180
-	/**
181
-	 * Retrieves the files that should be translated
182
-	 * @return array $files
183
-	 */
184
-	private function getFiles()
185
-	{
186
-		extract($this->_config);
187
-		$files = CFileHelper::findFiles(realpath($sourcePath),array(
188
-					'fileTypes' => $fileTypes,
189
-					'exclude'	=> $exclude
190
-				 ));
191
-
192
-		// Strip out all extensions
193
-		foreach ($files as $k=>$file)
194
-		{
195
-			if (strpos($file, 'extensions') !== false)
196
-				unset($files[$k]);
197
-		}
198
-
199
-		reset($files);
200
-
201
-		return $files;
202
-	}
203
-
204
-	/**
205
-	 * Does basic validation on the configuration options
206
-	 */
207
-	private function validateConfig()
208
-	{
209
-		extract($this->_config);
210
-
211
-		if(!isset($sourcePath,$messagePath,$languages))
212
-			$this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
213
-
214
-		if(!is_dir($sourcePath))
215
-			$this->usageError("The source path $sourcePath is not a valid directory.");
216
-
217
-		if(!is_dir($messagePath))
218
-			$this->usageError("The message path $messagePath is not a valid directory.");
219
-
220
-		if(empty($languages))
221
-			$this->usageError("Languages cannot be empty.");
222
-	}
223
-
224
-	/**
225
-	 * @param string $translator
226
-	 */
227
-	protected function extractMessages($fileName,$translator)
228
-	{
229
-		$subject=file_get_contents($fileName);
230
-		$messages=array();
231
-		if(!is_array($translator))
232
-			$translator=array($translator);
233
-
234
-		foreach ($translator as $currentTranslator)
235
-		{
236
-			$n=preg_match_all('/\b'.$currentTranslator.'\s*\(\s*(\'[\w.\/]*?(?<!\.)\'|"[\w.]*?(?<!\.)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',$subject,$matches,PREG_SET_ORDER);
237
-
238
-			for($i=0; $i<$n; ++$i)
239
-			{
240
-				if(($pos=strpos($matches[$i][1],'.'))!==false)
241
-				{
242
-					if (strpos($matches[$i][1],'Dashboard')!==false || strpos($matches[$i][1],'Hybridauth')!==false || strpos($matches[$i][1],'Install')!==false)
243
-						$category='module.'.substr($matches[$i][1],1,-1);
244
-					else if (strpos($matches[$i][1],'Theme')!==false)
245
-						$category=$matches[$i][1];
246
-					else
247
-						$category=substr($matches[$i][1],$pos+1,-1);
248
-				}
249
-				else
250
-					$category=substr($matches[$i][1],1,-1);
251
-
252
-
253
-				$message=$matches[$i][2];
254
-
255
-				$category = str_replace("'", '', $category);
256
-
257
-				// This is how Yii does it
258
-				$messages[$category][]=eval("return $message;");  // use eval to eliminate quote escape
259
-			}
260
-		}
261
-
262
-		return $messages;
263
-	}
264
-
265
-	/**
266
-	 * @param string $fileName
267
-	 * @param boolean $overwrite
268
-	 * @param boolean $removeOld
269
-	 * @param boolean $sort
270
-	 */
271
-	protected function generateMessageFile($messages,$fileName,$overwrite,$removeOld,$sort)
272
-	{
273
-		echo "Saving messages to $fileName...";
274
-		if(is_file($fileName))
275
-		{
276
-			$translated=require($fileName);
277
-			sort($messages);
278
-			ksort($translated);
279
-			if(array_keys($translated)==$messages)
280
-			{
281
-				echo "nothing new...skipped.\n";
282
-				return;
283
-			}
284
-
285
-			$merged=array();
286
-			$untranslated=array();
287
-
288
-			foreach($messages as $message)
289
-			{
290
-				if(array_key_exists($message,$translated) && strlen($translated[$message])>0)
291
-					$merged[$message]=$translated[$message];
292
-				else
293
-					$untranslated[]=$message;
294
-			}
295
-
296
-			ksort($merged);
297
-			sort($untranslated);
298
-			$todo=array();
299
-
300
-			foreach($untranslated as $message)
301
-				$todo[$message]='';
302
-
303
-			ksort($translated);
304
-
305
-			foreach($translated as $message=>$translation)
306
-			{
307
-				if(!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld)
308
-				{
309
-					if(substr($translation,0,2)==='@@' && substr($translation,-2)==='@@')
310
-						$todo[$message]=$translation;
311
-					else if ($translation == '')
312
-						$todo[$message] = '';
313
-					else
314
-						$todo[$message]='@@'.$translation.'@@';
315
-				}
316
-			}
317
-
318
-			$merged=array_merge($todo,$merged);
319
-
320
-			if($sort)
321
-				ksort($merged);
322
-
323
-			if($overwrite === false)
324
-				$fileName.='.merged';
325
-
326
-			echo "translation merged.\n";
327
-		}
328
-		else
329
-		{
330
-			$merged=array();
331
-			foreach($messages as $message)
332
-				$merged[$message]='';
333
-
334
-			ksort($merged);
335
-			echo "saved.\n";
336
-		}
337
-		$array=str_replace("\r",'',var_export($merged,true));
338
-		$content=<<<EOD
9
+    /**
10
+     * The configuration object
11
+     * @var array _$config
12
+     */
13
+    private $_config = array();
14
+
15
+    /**
16
+     * The messages that should be translated
17
+     * @var array $_messages
18
+     */
19
+    private $_messages = array();
20
+
21
+    /**
22
+     * The stirng that should be used for translations
23
+     * @var string $_translator
24
+     */
25
+    private $_translator = 'Yii::t';
26
+
27
+    /**
28
+     * Default args
29
+     * @return array
30
+     */
31
+    private function getArgs()
32
+    {
33
+        return array(
34
+            'type'			=> 'core',
35
+            'sourcePath'	=> Yii::getPathOfAlias('application').DS,
36
+            'messagePath'	=> Yii::getPathOfAlias('application.messages').DS,
37
+            'languages'		=> array('en_us'),
38
+            'fileTypes'		=> array('php'),
39
+            'overwrite'		=> true,
40
+            'sort'			=> true,
41
+            'removeOld'		=> false,
42
+            'exclude'		=> array(
43
+                'assets',
44
+                'css',
45
+                'js',
46
+                'images',
47
+                '.svn',
48
+                '.gitignore',
49
+                '.git',
50
+                'yiilite.php',
51
+                'yiit.php',
52
+                'i18n/data',
53
+                'messages',
54
+                'vendor',
55
+                'tests',
56
+                'runtime'
57
+            )
58
+        );
59
+    }
60
+
61
+    /**
62
+     * Init method
63
+     */
64
+    public function init()
65
+    {
66
+        $this->_config = $this->getArgs();
67
+    }
68
+
69
+    /**
70
+     * Generates translation files for a given mtheme
71
+     * @param string $name 	The name of the theme to generate translations for
72
+     */
73
+    public function actionThemes($name=NULL)
74
+    {
75
+        if ($name === NULL)
76
+            $this->usageError('A theme was not specified for translations');
77
+
78
+        $this->_config['type'] = 'theme';
79
+        array_push($this->_config['exclude'], 'modules');
80
+        $this->_config['sourcePath'] .= '..'.DS.'themes' . DS . $name . DS;
81
+        $this->_config['messagePath'] = $this->_config['sourcePath'].'messages';
82
+        $this->execute();
83
+    }
84
+
85
+    /**
86
+     * Generates translation files for a given module
87
+     * @param string $name 	The name of the module to generate translations for
88
+     */
89
+    public function actionModules($name=NULL)
90
+    {
91
+        if ($name === NULL)
92
+            $this->usageError('A module was not specified for translations');
93
+
94
+        $this->_config['type'] = 'module';
95
+        array_push($this->_config['exclude'], 'themes');
96
+        unset($this->_config['exclude']['modules']);
97
+        $this->_config['sourcePath'] = Yii::getPathOfAlias('application.modules') . DS . $name . DS;
98
+        $this->_config['messagePath'] = $this->_config['sourcePath'].'messages';
99
+        $this->execute($this->_config);
100
+    }
101
+
102
+    /**
103
+     * Defualt action
104
+     */
105
+    public function actionIndex()
106
+    {
107
+        array_push($this->_config['exclude'], 'modules');
108
+        array_push($this->_config['exclude'], 'themes');
109
+        return $this->execute();
110
+    }
111
+
112
+    /**
113
+     * Execute the action.
114
+     */
115
+    private function execute()
116
+    {
117
+        // Validate the configuration
118
+        extract($this->_config);
119
+        $this->validateConfig();
120
+
121
+        // Determine the messages
122
+        foreach($this->getFiles() as $file)
123
+            $this->_messages = array_merge_recursive($this->_messages,$this->extractMessages($file,$this->_translator));
124
+
125
+        foreach($languages as $language)
126
+        {
127
+            $dir = $messagePath.DS.$language;
128
+
129
+            $this->createDirectory($dir);
130
+
131
+            foreach ($this->_messages as $category=>$msgs)
132
+            {
133
+                $msgs = array_values(array_unique($msgs));
134
+
135
+                $dir = $this->_config['messagePath'].DS.$language;
136
+
137
+                if ($this->_config['type']  == 'theme')
138
+                {
139
+                    $data = explode('.', $category);
140
+                    unset($data[0]);
141
+                    $dirPath = implode(DS, $data);
142
+                }
143
+                else if ($this->_config['type'] == 'module')
144
+                {
145
+                    $data = explode('.', $category);
146
+                    unset($data[0]);
147
+                    unset($data[1]);
148
+                    $dirPath = implode(DS, $data);
149
+                }
150
+                else
151
+                    $dirPath = implode(DS, explode('.', $category));
152
+
153
+                if (empty($dirPath))
154
+                    continue;
155
+
156
+                $this->createDirectory($dir . DS . $dirPath);
157
+                $this->createDirectory($dir . DS . $language);
158
+
159
+                $this->generateMessageFile($msgs,$dir.DS.$dirPath.'.php',$overwrite,$removeOld,$sort);
160
+            }
161
+        }
162
+    }
163
+
164
+    /**
165
+     * Creates a directory at the given path
166
+     * @param string $directory
167
+     * @return boolean
168
+     */
169
+    private function createDirectory($directory)
170
+    {
171
+        if (!is_dir($directory)) 
172
+        {
173
+            if (!mkdir($directory, 0777, true))
174
+                $this->usageError('The directory ' . $directory .' could not be created. Please make sure this process has write access to this directory.');
175
+        }
176
+
177
+        return true;
178
+    }
179
+
180
+    /**
181
+     * Retrieves the files that should be translated
182
+     * @return array $files
183
+     */
184
+    private function getFiles()
185
+    {
186
+        extract($this->_config);
187
+        $files = CFileHelper::findFiles(realpath($sourcePath),array(
188
+                    'fileTypes' => $fileTypes,
189
+                    'exclude'	=> $exclude
190
+                    ));
191
+
192
+        // Strip out all extensions
193
+        foreach ($files as $k=>$file)
194
+        {
195
+            if (strpos($file, 'extensions') !== false)
196
+                unset($files[$k]);
197
+        }
198
+
199
+        reset($files);
200
+
201
+        return $files;
202
+    }
203
+
204
+    /**
205
+     * Does basic validation on the configuration options
206
+     */
207
+    private function validateConfig()
208
+    {
209
+        extract($this->_config);
210
+
211
+        if(!isset($sourcePath,$messagePath,$languages))
212
+            $this->usageError('The configuration file must specify "sourcePath", "messagePath" and "languages".');
213
+
214
+        if(!is_dir($sourcePath))
215
+            $this->usageError("The source path $sourcePath is not a valid directory.");
216
+
217
+        if(!is_dir($messagePath))
218
+            $this->usageError("The message path $messagePath is not a valid directory.");
219
+
220
+        if(empty($languages))
221
+            $this->usageError("Languages cannot be empty.");
222
+    }
223
+
224
+    /**
225
+     * @param string $translator
226
+     */
227
+    protected function extractMessages($fileName,$translator)
228
+    {
229
+        $subject=file_get_contents($fileName);
230
+        $messages=array();
231
+        if(!is_array($translator))
232
+            $translator=array($translator);
233
+
234
+        foreach ($translator as $currentTranslator)
235
+        {
236
+            $n=preg_match_all('/\b'.$currentTranslator.'\s*\(\s*(\'[\w.\/]*?(?<!\.)\'|"[\w.]*?(?<!\.)")\s*,\s*(\'.*?(?<!\\\\)\'|".*?(?<!\\\\)")\s*[,\)]/s',$subject,$matches,PREG_SET_ORDER);
237
+
238
+            for($i=0; $i<$n; ++$i)
239
+            {
240
+                if(($pos=strpos($matches[$i][1],'.'))!==false)
241
+                {
242
+                    if (strpos($matches[$i][1],'Dashboard')!==false || strpos($matches[$i][1],'Hybridauth')!==false || strpos($matches[$i][1],'Install')!==false)
243
+                        $category='module.'.substr($matches[$i][1],1,-1);
244
+                    else if (strpos($matches[$i][1],'Theme')!==false)
245
+                        $category=$matches[$i][1];
246
+                    else
247
+                        $category=substr($matches[$i][1],$pos+1,-1);
248
+                }
249
+                else
250
+                    $category=substr($matches[$i][1],1,-1);
251
+
252
+
253
+                $message=$matches[$i][2];
254
+
255
+                $category = str_replace("'", '', $category);
256
+
257
+                // This is how Yii does it
258
+                $messages[$category][]=eval("return $message;");  // use eval to eliminate quote escape
259
+            }
260
+        }
261
+
262
+        return $messages;
263
+    }
264
+
265
+    /**
266
+     * @param string $fileName
267
+     * @param boolean $overwrite
268
+     * @param boolean $removeOld
269
+     * @param boolean $sort
270
+     */
271
+    protected function generateMessageFile($messages,$fileName,$overwrite,$removeOld,$sort)
272
+    {
273
+        echo "Saving messages to $fileName...";
274
+        if(is_file($fileName))
275
+        {
276
+            $translated=require($fileName);
277
+            sort($messages);
278
+            ksort($translated);
279
+            if(array_keys($translated)==$messages)
280
+            {
281
+                echo "nothing new...skipped.\n";
282
+                return;
283
+            }
284
+
285
+            $merged=array();
286
+            $untranslated=array();
287
+
288
+            foreach($messages as $message)
289
+            {
290
+                if(array_key_exists($message,$translated) && strlen($translated[$message])>0)
291
+                    $merged[$message]=$translated[$message];
292
+                else
293
+                    $untranslated[]=$message;
294
+            }
295
+
296
+            ksort($merged);
297
+            sort($untranslated);
298
+            $todo=array();
299
+
300
+            foreach($untranslated as $message)
301
+                $todo[$message]='';
302
+
303
+            ksort($translated);
304
+
305
+            foreach($translated as $message=>$translation)
306
+            {
307
+                if(!isset($merged[$message]) && !isset($todo[$message]) && !$removeOld)
308
+                {
309
+                    if(substr($translation,0,2)==='@@' && substr($translation,-2)==='@@')
310
+                        $todo[$message]=$translation;
311
+                    else if ($translation == '')
312
+                        $todo[$message] = '';
313
+                    else
314
+                        $todo[$message]='@@'.$translation.'@@';
315
+                }
316
+            }
317
+
318
+            $merged=array_merge($todo,$merged);
319
+
320
+            if($sort)
321
+                ksort($merged);
322
+
323
+            if($overwrite === false)
324
+                $fileName.='.merged';
325
+
326
+            echo "translation merged.\n";
327
+        }
328
+        else
329
+        {
330
+            $merged=array();
331
+            foreach($messages as $message)
332
+                $merged[$message]='';
333
+
334
+            ksort($merged);
335
+            echo "saved.\n";
336
+        }
337
+        $array=str_replace("\r",'',var_export($merged,true));
338
+        $content=<<<EOD
339 339
 <?php
340 340
 /**
341 341
  * Message translations.
@@ -357,6 +357,6 @@  discard block
 block discarded – undo
357 357
 return $array;
358 358
 
359 359
 EOD;
360
-		file_put_contents($fileName, $content);
361
-	}
360
+        file_put_contents($fileName, $content);
361
+    }
362 362
 }
Please login to merge, or discard this patch.
protected/config/install.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -1,62 +1,62 @@
 block discarded – undo
1 1
 <?php return array(
2
-	'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
3
-	'name' => 'CiiMS Installer',
4
-	'preload' => array(
5
-		'cii'
6
-	),
7
-	'import' => array(
8
-		'application.components.*',
9
-		'application.modules.install.*'
10
-	),
11
-	'modules' => array(
12
-		'install'
13
-	),
14
-	'components' => array(
15
-		'cii' => array(
16
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiBase'
17
-		),
18
-		'errorHandler' => array(
19
-			'errorAction' => '/install/default/error',
20
-		),
21
-		'session' => array(
22
-			'autoStart' => true,
23
-			'sessionName'   => 'CiiMS_Installer',
24
-			'cookieMode'    => 'only',
25
-		),
26
-		'cache' => array(
27
-			'class' => 'CFileCache'
28
-		),
29
-		'urlManager' => array(
30
-			'urlFormat' => 'path',
31
-			'showScriptName' => false,
32
-			'rules' => array(
33
-				'' => '/install/default/index',
34
-				'/migrate' => '/install/default/migrate',
35
-				'/runmigrations' => '/install/default/runmigrations',
36
-				'/createadmin' => '/install/default/createadmin',
37
-				'/admin' => '/install/default/admin'
38
-			),
39
-		),
40
-		'log' => array(
41
-			'class' => 'CLogRouter',
42
-			'routes' => array(
43
-				array(
44
-					'class' => 'CWebLogRoute',
45
-					'levels' => 'error, warning, trace, info',
46
-					'enabled' => true
47
-				),
48
-				array(
49
-					'class'=>'CProfileLogRoute',
50
-					'report'=>'summary',
51
-					'enabled' => true
52
-				)
53
-			)
54
-		),
55
-	),
56
-	'params' => array(
57
-		'stage' => 0,
58
-		'debug' => true,
59
-		'trace' => 3
60
-	),
2
+    'basePath' => dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
3
+    'name' => 'CiiMS Installer',
4
+    'preload' => array(
5
+        'cii'
6
+    ),
7
+    'import' => array(
8
+        'application.components.*',
9
+        'application.modules.install.*'
10
+    ),
11
+    'modules' => array(
12
+        'install'
13
+    ),
14
+    'components' => array(
15
+        'cii' => array(
16
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiBase'
17
+        ),
18
+        'errorHandler' => array(
19
+            'errorAction' => '/install/default/error',
20
+        ),
21
+        'session' => array(
22
+            'autoStart' => true,
23
+            'sessionName'   => 'CiiMS_Installer',
24
+            'cookieMode'    => 'only',
25
+        ),
26
+        'cache' => array(
27
+            'class' => 'CFileCache'
28
+        ),
29
+        'urlManager' => array(
30
+            'urlFormat' => 'path',
31
+            'showScriptName' => false,
32
+            'rules' => array(
33
+                '' => '/install/default/index',
34
+                '/migrate' => '/install/default/migrate',
35
+                '/runmigrations' => '/install/default/runmigrations',
36
+                '/createadmin' => '/install/default/createadmin',
37
+                '/admin' => '/install/default/admin'
38
+            ),
39
+        ),
40
+        'log' => array(
41
+            'class' => 'CLogRouter',
42
+            'routes' => array(
43
+                array(
44
+                    'class' => 'CWebLogRoute',
45
+                    'levels' => 'error, warning, trace, info',
46
+                    'enabled' => true
47
+                ),
48
+                array(
49
+                    'class'=>'CProfileLogRoute',
50
+                    'report'=>'summary',
51
+                    'enabled' => true
52
+                )
53
+            )
54
+        ),
55
+    ),
56
+    'params' => array(
57
+        'stage' => 0,
58
+        'debug' => true,
59
+        'trace' => 3
60
+    ),
61 61
 );
62 62
 
Please login to merge, or discard this patch.
protected/config/main.default.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -20,145 +20,145 @@
 block discarded – undo
20 20
 */
21 21
 $import = function($default=false) {
22 22
 
23
-	$modules = (require __DIR__ . DS . 'modules.php');
23
+    $modules = (require __DIR__ . DS . 'modules.php');
24 24
 
25
-	if ($default === true)
26
-		return $modules;
25
+    if ($default === true)
26
+        return $modules;
27 27
 
28
-	$m = array(
29
-		'application.models.*',
30
-		'application.models.forms.*',
31
-		'application.models.settings.*'
32
-	);
28
+    $m = array(
29
+        'application.models.*',
30
+        'application.models.forms.*',
31
+        'application.models.settings.*'
32
+    );
33 33
 
34
-	foreach ($modules as $k=>$v) {
35
-		$m[] = 'application.modules.'.$v.'.*';
36
-	}
34
+    foreach ($modules as $k=>$v) {
35
+        $m[] = 'application.modules.'.$v.'.*';
36
+    }
37 37
 
38
-	return $m;
38
+    return $m;
39 39
 };
40 40
 
41 41
 $ciimsCoreConfig = array(
42
-	'basePath' => __DIR__.DS.'..',
43
-	'name' => NULL,
44
-	'sourceLanguage' => 'en_US',
45
-	'preload' => array(
46
-		'cii',
47
-		'analytics'
48
-	),
49
-	'import' => $import(),
50
-	'modules' => $import(true),
51
-	'behaviors' => array(
52
-		'onBeginRequest' => array(
53
-			'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicWebAppBehavior',
54
-		),
55
-	),
56
-	'components' => array(
57
-		'themeManager' => array(
58
-			'basePath' => (__DIR__ . DS . '..' . DS . '..' . DS . 'themes')
59
-		),
60
-		'messages' => array(
61
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiPHPMessageSource'
62
-		),
63
-			'newRelic' => array(
64
-			'class' => 'vendor.charlesportwoodii.yii-newrelic.YiiNewRelic',
65
-			'setAppNameToYiiName' => false
66
-		),
67
-		'cii' => array(
68
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiBase'
69
-		),
70
-		'analytics' => array(
71
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiAnalytics',
72
-			'lowerBounceRate' => true,
73
-			'options' => array(),
74
-		),
75
-		'assetManager' => array(
76
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiAssetManager',
77
-		),
78
-		'clientScript' => array(
79
-			'class' => 'vendor.charlesportwoodii.cii.components.CiiClientScript',
80
-		),
81
-		'errorHandler' => array(
82
-			'errorAction' => 'site/error',
83
-		),
84
-		'session' => array(
85
-			'autoStart'     => true,
86
-			'sessionName'   => '_ciims',
87
-			'cookieMode'    => 'only',
88
-			'cookieParams'  => array(
89
-				'httponly' => true,
90
-				'secure' => (
91
-					(!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || 
92
-					(!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) || 
93
-					(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
94
-				)
95
-			)
96
-		),
97
-		'urlManager' => array(
98
-			'class'          => 'vendor.charlesportwoodii.cii.components.CiiURLManager',
99
-			'urlFormat'      => 'path',
100
-			'showScriptName' => false
101
-		),
102
-		'user' => array(
103
-			'authTimeout'    		=> 900,
104
-			'absoluteAuthTimeout' 	=> 1900,
105
-			'autoRenewCookie' 		=> true
106
-		),
107
-		'db' => array(
108
-			'class'                 => 'CDbConnection',
109
-			'connectionString'      => NULL,
110
-			'emulatePrepare'        => true,
111
-			'username'              => NULL,
112
-			'password'              => NULL,
113
-			'charset'               => 'utf8',
114
-			'schemaCachingDuration' => 3600,
115
-			'enableProfiling'       => false,
116
-			'enableParamLogging'    => false
117
-		),
118
-		'log' => array(
119
-			'class' => 'CLogRouter',
120
-			'routes' => array(
121
-				array(
122
-					'class'=>'CFileLogRoute',
123
-					'levels'=>'error, warning',
124
-				)
125
-			)
126
-		),
127
-		'cache' => array(
128
-			'class' => 'CFileCache',
129
-		)
130
-	),
131
-	'params' => array(
132
-		'encryptionKey'       => NULL,
133
-		'debug'               => false,
134
-		'trace'               => 0,
135
-		'NewRelicAppName'     => null,
136
-		'max_fileupload_size' => (10 * 1024 * 1024),
137
-		'cards' => 'https://cards.ciims.io/1.0.0',
138
-	)
42
+    'basePath' => __DIR__.DS.'..',
43
+    'name' => NULL,
44
+    'sourceLanguage' => 'en_US',
45
+    'preload' => array(
46
+        'cii',
47
+        'analytics'
48
+    ),
49
+    'import' => $import(),
50
+    'modules' => $import(true),
51
+    'behaviors' => array(
52
+        'onBeginRequest' => array(
53
+            'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicWebAppBehavior',
54
+        ),
55
+    ),
56
+    'components' => array(
57
+        'themeManager' => array(
58
+            'basePath' => (__DIR__ . DS . '..' . DS . '..' . DS . 'themes')
59
+        ),
60
+        'messages' => array(
61
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiPHPMessageSource'
62
+        ),
63
+            'newRelic' => array(
64
+            'class' => 'vendor.charlesportwoodii.yii-newrelic.YiiNewRelic',
65
+            'setAppNameToYiiName' => false
66
+        ),
67
+        'cii' => array(
68
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiBase'
69
+        ),
70
+        'analytics' => array(
71
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiAnalytics',
72
+            'lowerBounceRate' => true,
73
+            'options' => array(),
74
+        ),
75
+        'assetManager' => array(
76
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiAssetManager',
77
+        ),
78
+        'clientScript' => array(
79
+            'class' => 'vendor.charlesportwoodii.cii.components.CiiClientScript',
80
+        ),
81
+        'errorHandler' => array(
82
+            'errorAction' => 'site/error',
83
+        ),
84
+        'session' => array(
85
+            'autoStart'     => true,
86
+            'sessionName'   => '_ciims',
87
+            'cookieMode'    => 'only',
88
+            'cookieParams'  => array(
89
+                'httponly' => true,
90
+                'secure' => (
91
+                    (!empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off') || 
92
+                    (!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443) || 
93
+                    (!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
94
+                )
95
+            )
96
+        ),
97
+        'urlManager' => array(
98
+            'class'          => 'vendor.charlesportwoodii.cii.components.CiiURLManager',
99
+            'urlFormat'      => 'path',
100
+            'showScriptName' => false
101
+        ),
102
+        'user' => array(
103
+            'authTimeout'    		=> 900,
104
+            'absoluteAuthTimeout' 	=> 1900,
105
+            'autoRenewCookie' 		=> true
106
+        ),
107
+        'db' => array(
108
+            'class'                 => 'CDbConnection',
109
+            'connectionString'      => NULL,
110
+            'emulatePrepare'        => true,
111
+            'username'              => NULL,
112
+            'password'              => NULL,
113
+            'charset'               => 'utf8',
114
+            'schemaCachingDuration' => 3600,
115
+            'enableProfiling'       => false,
116
+            'enableParamLogging'    => false
117
+        ),
118
+        'log' => array(
119
+            'class' => 'CLogRouter',
120
+            'routes' => array(
121
+                array(
122
+                    'class'=>'CFileLogRoute',
123
+                    'levels'=>'error, warning',
124
+                )
125
+            )
126
+        ),
127
+        'cache' => array(
128
+            'class' => 'CFileCache',
129
+        )
130
+    ),
131
+    'params' => array(
132
+        'encryptionKey'       => NULL,
133
+        'debug'               => false,
134
+        'trace'               => 0,
135
+        'NewRelicAppName'     => null,
136
+        'max_fileupload_size' => (10 * 1024 * 1024),
137
+        'cards' => 'https://cards.ciims.io/1.0.0',
138
+    )
139 139
 );
140 140
 
141 141
 // CLI specific data
142 142
 if (php_sapi_name() == "cli")
143 143
 {
144
-	$ciimsCoreConfig['behaviors'] = array(
145
-		'onBeginRequest' => array(
146
-			'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicConsoleAppBehavior',
147
-		),
148
-		'onEndRequest' => array(
149
-			'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicConsoleAppBehavior',
150
-		)
151
-	);
144
+    $ciimsCoreConfig['behaviors'] = array(
145
+        'onBeginRequest' => array(
146
+            'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicConsoleAppBehavior',
147
+        ),
148
+        'onEndRequest' => array(
149
+            'class' => 'vendor.charlesportwoodii.yii-newrelic.behaviors.YiiNewRelicConsoleAppBehavior',
150
+        )
151
+    );
152 152
 }
153 153
 
154 154
 if (php_sapi_name() != "cli" && YII_DEBUG)
155 155
 {
156
-	$ciimsCoreConfig['preload'][] = 'debug';
157
-	$ciimsCoreConfig['components']['debug'] = array(
158
-		'class' => 'vendor.zhuravljov.yii2-debug.Yii2Debug',
159
-		'enabled' => YII_DEBUG,
160
-		'allowedIPs' => array('*')
161
-	);
156
+    $ciimsCoreConfig['preload'][] = 'debug';
157
+    $ciimsCoreConfig['components']['debug'] = array(
158
+        'class' => 'vendor.zhuravljov.yii2-debug.Yii2Debug',
159
+        'enabled' => YII_DEBUG,
160
+        'allowedIPs' => array('*')
161
+    );
162 162
 }
163 163
 
164 164
 return $ciimsCoreConfig;
Please login to merge, or discard this patch.
protected/config/modules.php 1 patch
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -6,30 +6,30 @@
 block discarded – undo
6 6
 
7 7
 // Attempt to load the cached file if it exists
8 8
 if (file_exists($cachedConfig))
9
-	return require($cachedConfig);
9
+    return require($cachedConfig);
10 10
 else
11 11
 {
12
-	// Otherwise generate one, and return it
13
-	$response = array();
12
+    // Otherwise generate one, and return it
13
+    $response = array();
14 14
 
15
-	// Find all the modules currently installed, and preload them
16
-	foreach (new IteratorIterator(new DirectoryIterator($directory)) as $filename)
17
-	{
18
-		// Don't import dot files
19
-		if (!$filename->isDot() && strpos($filename->getFileName(), ".") === false)
20
-		{
21
-			$path = $filename->getPathname();
15
+    // Find all the modules currently installed, and preload them
16
+    foreach (new IteratorIterator(new DirectoryIterator($directory)) as $filename)
17
+    {
18
+        // Don't import dot files
19
+        if (!$filename->isDot() && strpos($filename->getFileName(), ".") === false)
20
+        {
21
+            $path = $filename->getPathname();
22 22
 
23
-			if (file_exists($path.DS.'config'.DS.'main.php'))
24
-				$response[$filename->getFilename()] = require($path.DS.'config'.DS.'main.php');
25
-			else
26
-				array_push($response, $filename->getFilename());
27
-		}
28
-	}
23
+            if (file_exists($path.DS.'config'.DS.'main.php'))
24
+                $response[$filename->getFilename()] = require($path.DS.'config'.DS.'main.php');
25
+            else
26
+                array_push($response, $filename->getFilename());
27
+        }
28
+    }
29 29
 
30
-	$encoded = serialize($response);
31
-	file_put_contents($cachedConfig, '<?php return unserialize(\''.$encoded.'\');');
30
+    $encoded = serialize($response);
31
+    file_put_contents($cachedConfig, '<?php return unserialize(\''.$encoded.'\');');
32 32
 
33
-	// return the response
34
-	return $response;
33
+    // return the response
34
+    return $response;
35 35
 }
Please login to merge, or discard this patch.
protected/controllers/CategoriesController.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -2,126 +2,126 @@
 block discarded – undo
2 2
 
3 3
 class CategoriesController extends CiiController
4 4
 {
5
-	/**
6
-	 * Base filter, allows logged in and non-logged in users to cache the page
7
-	 */
8
-	public function filters()
9
-	{
10
-		$id = Yii::app()->getRequest()->getQuery('id');
11
-
12
-		if ($id == NULL || $id === false)
13
-			throw new CHttpException(400, Yii::t('ciims.controllers.Categories', 'Invalid routing'));
14
-
15
-		return CMap::mergeArray(parent::filters(), array(
16
-			array(
17
-				'CHttpCacheFilter + index',
18
-				'cacheControl'=>Cii::get(Yii::app()->user->id) == NULL ? 'public' : 'private' .', no-cache, must-revalidate',
19
-				'etagSeed'=>$id
20
-			),
21
-			array(
22
-				'COutputCache + list',
23
-				'duration' => YII_DEBUG ? 1 : 86400,
24
-				'varyByParam' => array('page'),
25
-				'varyByLanguage' => true,
26
-				'dependency' => array(
27
-					'class'=>'CDbCacheDependency',
28
-					'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
29
-					'params' => array(':id' => $id)
30
-				)
31
-			),
32
-			array(
33
-				'COutputCache + rss',
34
-				'duration' => YII_DEBUG ? 1 : 86400,
35
-				'dependency' => array(
36
-					'class'=>'CDbCacheDependency',
37
-					'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
38
-					'params' => array(':id' => $id)
39
-				)
40
-			)
41
-		));
42
-	}
43
-
44
-	/**
45
-	 * Handles all incoming requests for the entire site that are not previous defined in CUrlManager
46
-	 * Requests come in, are verified, and then pulled from the database dynamically
47
-	 * Shows all blog posts for a particular category_id
48
-	 * @param $id	- The content ID that we want to pull from the database
49
-	 **/
50
-	public function actionIndex($id=NULL)
51
-	{
52
-		// Run a pre check of our data
53
-		$this->beforeCiiAction($id);
54
-
55
-		// Retrieve the data
56
-		$category = Categories::model()->findByPk($id);
57
-
58
-		// Set the layout
59
-		$this->setLayout('default');
60
-
61
-		$this->setPageTitle(Yii::t('ciims.controllers.Categories', '{{app_name}} | {{label}}', array(
62
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
63
-			'{{label}}'    => $category->name
64
-		)));
65
-
66
-		$pageSize = Cii::getConfig('categoryPaginationSize', 10);
67
-
68
-		$criteria = Content::model()
69
-					->getBaseCriteria()
70
-					->addCondition('type_id >= 2')
71
-					->addCondition("category_id = " . $id)
72
-					->addCondition('password = ""');
73
-
74
-		$criteria->limit = $pageSize;
75
-		$criteria->order = 'created DESC';
76
-
77
-		$itemCount = Content::model()->count($criteria);
78
-		$pages=new CPagination($itemCount);
79
-		$pages->pageSize=$pageSize;
80
-
81
-
82
-		$criteria->offset = $criteria->limit*($pages->getCurrentPage());
83
-		$data = Content::model()->findAll($criteria);
84
-
85
-		$pages->applyLimit($criteria);
86
-
87
-		$this->render('index', array(
88
-			'id'		=> $id,
89
-			'category' 	=> $category,
90
-			'data' 		=> $data,
91
-			'itemCount' => $itemCount,
92
-			'pages' 	=> $pages,
93
-			'meta' 		=> array(
94
-				'description' => $category->getDescription()
95
-		)));
96
-	}
97
-
98
-	/**
99
-	 * Displays either all posts or all posts for a particular category_id if an $id is set in RSS Format
100
-	 * So that RSS Readers can access the website
101
-	 * @param  int $id
102
-	 */
103
-	public function actionRss($id=NULL)
104
-	{
105
-		Yii::app()->log->routes[0]->enabled = false;
106
-		ob_end_clean();
107
-		header('Content-type: text/xml; charset=utf-8');
108
-		$url = 'http://'.Yii::app()->request->serverName . Yii::app()->baseUrl;
109
-		$this->setLayout(null);
110
-		$criteria = Content::model()
111
-					->getBaseCriteria()
112
-					->addCondition('type_id >= 2')
113
-					->addCondition('password = ""');
114
-
115
-		if ($id !== NULL)
116
-			$criteria->addCondition("category_id = " . $id);
117
-
118
-		$criteria->order = 'created DESC';
119
-		$data = Content::model()->findAll($criteria);
120
-
121
-		$this->renderPartial('application.views.site/rss', array(
122
-			'data' 	=> $data, 
123
-			'url'	=> $url
124
-		));
125
-		return;
126
-	}
5
+    /**
6
+     * Base filter, allows logged in and non-logged in users to cache the page
7
+     */
8
+    public function filters()
9
+    {
10
+        $id = Yii::app()->getRequest()->getQuery('id');
11
+
12
+        if ($id == NULL || $id === false)
13
+            throw new CHttpException(400, Yii::t('ciims.controllers.Categories', 'Invalid routing'));
14
+
15
+        return CMap::mergeArray(parent::filters(), array(
16
+            array(
17
+                'CHttpCacheFilter + index',
18
+                'cacheControl'=>Cii::get(Yii::app()->user->id) == NULL ? 'public' : 'private' .', no-cache, must-revalidate',
19
+                'etagSeed'=>$id
20
+            ),
21
+            array(
22
+                'COutputCache + list',
23
+                'duration' => YII_DEBUG ? 1 : 86400,
24
+                'varyByParam' => array('page'),
25
+                'varyByLanguage' => true,
26
+                'dependency' => array(
27
+                    'class'=>'CDbCacheDependency',
28
+                    'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
29
+                    'params' => array(':id' => $id)
30
+                )
31
+            ),
32
+            array(
33
+                'COutputCache + rss',
34
+                'duration' => YII_DEBUG ? 1 : 86400,
35
+                'dependency' => array(
36
+                    'class'=>'CDbCacheDependency',
37
+                    'sql'=>'SELECT MAX(updated) FROM content WHERE category_id = :id',
38
+                    'params' => array(':id' => $id)
39
+                )
40
+            )
41
+        ));
42
+    }
43
+
44
+    /**
45
+     * Handles all incoming requests for the entire site that are not previous defined in CUrlManager
46
+     * Requests come in, are verified, and then pulled from the database dynamically
47
+     * Shows all blog posts for a particular category_id
48
+     * @param $id	- The content ID that we want to pull from the database
49
+     **/
50
+    public function actionIndex($id=NULL)
51
+    {
52
+        // Run a pre check of our data
53
+        $this->beforeCiiAction($id);
54
+
55
+        // Retrieve the data
56
+        $category = Categories::model()->findByPk($id);
57
+
58
+        // Set the layout
59
+        $this->setLayout('default');
60
+
61
+        $this->setPageTitle(Yii::t('ciims.controllers.Categories', '{{app_name}} | {{label}}', array(
62
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
63
+            '{{label}}'    => $category->name
64
+        )));
65
+
66
+        $pageSize = Cii::getConfig('categoryPaginationSize', 10);
67
+
68
+        $criteria = Content::model()
69
+                    ->getBaseCriteria()
70
+                    ->addCondition('type_id >= 2')
71
+                    ->addCondition("category_id = " . $id)
72
+                    ->addCondition('password = ""');
73
+
74
+        $criteria->limit = $pageSize;
75
+        $criteria->order = 'created DESC';
76
+
77
+        $itemCount = Content::model()->count($criteria);
78
+        $pages=new CPagination($itemCount);
79
+        $pages->pageSize=$pageSize;
80
+
81
+
82
+        $criteria->offset = $criteria->limit*($pages->getCurrentPage());
83
+        $data = Content::model()->findAll($criteria);
84
+
85
+        $pages->applyLimit($criteria);
86
+
87
+        $this->render('index', array(
88
+            'id'		=> $id,
89
+            'category' 	=> $category,
90
+            'data' 		=> $data,
91
+            'itemCount' => $itemCount,
92
+            'pages' 	=> $pages,
93
+            'meta' 		=> array(
94
+                'description' => $category->getDescription()
95
+        )));
96
+    }
97
+
98
+    /**
99
+     * Displays either all posts or all posts for a particular category_id if an $id is set in RSS Format
100
+     * So that RSS Readers can access the website
101
+     * @param  int $id
102
+     */
103
+    public function actionRss($id=NULL)
104
+    {
105
+        Yii::app()->log->routes[0]->enabled = false;
106
+        ob_end_clean();
107
+        header('Content-type: text/xml; charset=utf-8');
108
+        $url = 'http://'.Yii::app()->request->serverName . Yii::app()->baseUrl;
109
+        $this->setLayout(null);
110
+        $criteria = Content::model()
111
+                    ->getBaseCriteria()
112
+                    ->addCondition('type_id >= 2')
113
+                    ->addCondition('password = ""');
114
+
115
+        if ($id !== NULL)
116
+            $criteria->addCondition("category_id = " . $id);
117
+
118
+        $criteria->order = 'created DESC';
119
+        $data = Content::model()->findAll($criteria);
120
+
121
+        $this->renderPartial('application.views.site/rss', array(
122
+            'data' 	=> $data, 
123
+            'url'	=> $url
124
+        ));
125
+        return;
126
+    }
127 127
 }
Please login to merge, or discard this patch.
protected/controllers/ContentController.php 1 patch
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -2,212 +2,212 @@  discard block
 block discarded – undo
2 2
 
3 3
 class ContentController extends CiiController
4 4
 {
5
-	/**
6
-	 * Base filter, allows logged in and non-logged in users to cache the page
7
-	 */
8
-	public function filters()
9
-	{
10
-		$id = Yii::app()->getRequest()->getQuery('id');
11
-
12
-		if ($id != NULL)
13
-		{
14
-			$vid =  Yii::app()->getRequest()->getQuery('vid');
15
-			return array(
16
-				'accessControl',
17
-				array(
18
-					'CHttpCacheFilter + index',
19
-					'cacheControl'=>Cii::get(Yii::app()->user->id) == NULL ? 'public' : 'private' .', no-cache, must-revalidate',
20
-					'etagSeed' => $id.$vid
21
-				),
22
-				array(
23
-					'COutputCache + index',
24
-					'duration' => YII_DEBUG ? 1 : 86400, // 24 hour cache duration
25
-					'varyByParam' => array('id', 'vid'),
26
-					'varyByLanguage' => true,
27
-					'varyByExpression' => 'Yii::app()->user->isGuest'
28
-				)
29
-			);
30
-		}
31
-
32
-		return CMap::mergeArray(parent::filters(), array(array(
33
-			'COutputCache + list',
34
-			'duration' => YII_DEBUG ? 1 : 86400,
35
-			'varyByParam' => array('page'),
36
-			'varyByLanguage' => true,
37
-			'dependency' => array(
38
-				'class'=>'CDbCacheDependency',
39
-				'sql'=>'SELECT MAX(updated) FROM content',
40
-			)
41
-		)));
42
-	}
43
-
44
-
45
-	/**
46
-	 * Specifies the access control rules.
47
-	 * This method is used by the 'accessControl' filter.
48
-	 * @return array access control rules
49
-	 */
50
-	public function accessRules()
51
-	{
52
-		return array(
53
-			array('allow',  // Allow all users to any section
54
-				'actions' => array('index', 'password', 'list'),
55
-				'users'=>array('*'),
56
-			),
57
-			array('deny',  // deny all users
58
-				'users'=>array('*'),
59
-			),
60
-		);
61
-	}
62
-
63
-	/**
64
-	 * Handles all incoming requests for the entire site that are not previous defined in CUrlManager
65
-	 * Requests come in, are verified, and then pulled from the database dynamically
66
-	 * @param $id	- The content ID that we want to pull from the database
67
-	 **/
68
-	public function actionIndex($id=NULL, $vid=NULL)
69
-	{
70
-		// Set the ReturnURL to this page so that the user can be redirected back to here after login
71
-		Yii::app()->user->setReturnUrl($this->beforeCiiAction($id));
72
-
73
-		// Retrieve the data
74
-		$content = Content::model()->findByPk($id);
75
-
76
-		if ($content->status != 1 || !$content->isPublished())
77
-			throw new CHttpException(404, Yii::t('ciims.controllers.Content', 'The article you specified does not exist. If you bookmarked this page, please delete it.'));
78
-
79
-		// Check for a password
80
-		if (!empty($content->password))
81
-		{
82
-			// Check SESSION to see if a password is set
83
-			$tmpPassword = Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'password', NULL);
84
-
85
-			if ($tmpPassword != $content->password)
86
-				$this->redirect(Yii::app()->createUrl('/content/password/' . $id));
87
-		}
88
-
89
-		// Parse Metadata
90
-		$this->setLayout($content->layout);
91
-
92
-		$this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
93
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
94
-			'{{label}}'    => $content->title
95
-		)));
96
-
97
-		$this->params['meta']['description'] = $content->extract;
98
-		$this->render($content->view, array(
99
-			'id' 	=> $content->id,
100
-			'data' 	=> $content,
101
-			'meta' 	=> $content->parseMeta($content->id)
102
-		));
103
-	}
104
-
105
-	/**
106
-	 * Forces a password to be assigned before the user can proceed to the previous page
107
-	 * @param $id - ID of the content we want to investigate
108
-	 **/
109
-	public function actionPassword($id=NULL)
110
-	{
111
-		$this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
112
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
113
-			'{{label}}'    => Yii::t('ciims.controllers.Content', 'Password Required')
114
-		)));
115
-
116
-		if ($id == NULL)
117
-			$this->redirect(Yii::app()->user->returnUrl);
118
-
119
-		// Set some default data
120
-		if (Cii::get(Cii::get($_SESSION, 'password', array()), $id, NULL) == NULL)
121
-			$_SESSION['password'][$id] = array('tries'=>0, 'expires' => time() + 300);
122
-
123
-		// If the number of attempts is >= 3
124
-		if (Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'tries', 0) >= 3)
125
-		{
126
-			// If the expires time has already passed, unlock the account
127
-			if (Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'expires', 0) <= time())
128
-			{
129
-				$_SESSION['password'][$id] = array('tries'=>0, 'expires' => time() + 300);
130
-			}
131
-			else
132
-			{
133
-				// Otherwise prevent access to it
134
-				Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Content', 'Too many password attempts. Please try again in 5 minutes'));
135
-				unset($_POST['password']);
136
-				$_SESSION['password'][$id]['expires'] 	= time() + 300;
137
-			}
138
-		}
139
-
140
-		if (Cii::get($_POST, 'password', NULL) !== NULL)
141
-		{
142
-			$content = Content::model()->findByPk($id);
143
-
144
-			$encrypted = Cii::encrypt(Cii::get($_POST, 'password'));
145
-
146
-			if ($encrypted == $content->attributes['password'])
147
-			{
148
-				$_SESSION['password'][$id]['password'] = $encrypted;
149
-				$_SESSION['password'][$id]['tries'] = 0;
150
-				$this->redirect(Yii::app()->createUrl($content->attributes['slug']));
151
-			}
152
-			else
153
-			{
154
-				Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Content', 'Incorrect password'));
155
-				$_SESSION['password'][$id]['tries'] 	= $_SESSION['password'][$id]['tries'] + 1;
156
-				$_SESSION['password'][$id]['expires'] 	= time() + 300;
157
-			}
158
-
159
-		}
160
-
161
-		$this->layout = 'password';
162
-		$this->render('password', array(
163
-			'id' => $id
164
-		));
165
-	}
166
-
167
-	/*
168
-	 * Displays a listing of all blog posts for all time in all categories
169
-	 * Is used as a generic catch all behavior
170
-	 */
171
-	public function actionList()
172
-	{
173
-		$this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
174
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
175
-			'{{label}}'    => Yii::t('ciims.controllers.Content', 'All Content')
176
-		)));
177
-
178
-		$this->setLayout('default');
179
-
180
-		$pageSize = Cii::getConfig('contentPaginationSize', 10);
5
+    /**
6
+     * Base filter, allows logged in and non-logged in users to cache the page
7
+     */
8
+    public function filters()
9
+    {
10
+        $id = Yii::app()->getRequest()->getQuery('id');
11
+
12
+        if ($id != NULL)
13
+        {
14
+            $vid =  Yii::app()->getRequest()->getQuery('vid');
15
+            return array(
16
+                'accessControl',
17
+                array(
18
+                    'CHttpCacheFilter + index',
19
+                    'cacheControl'=>Cii::get(Yii::app()->user->id) == NULL ? 'public' : 'private' .', no-cache, must-revalidate',
20
+                    'etagSeed' => $id.$vid
21
+                ),
22
+                array(
23
+                    'COutputCache + index',
24
+                    'duration' => YII_DEBUG ? 1 : 86400, // 24 hour cache duration
25
+                    'varyByParam' => array('id', 'vid'),
26
+                    'varyByLanguage' => true,
27
+                    'varyByExpression' => 'Yii::app()->user->isGuest'
28
+                )
29
+            );
30
+        }
181 31
 
182
-		$criteria = Content::model()
183
-					->getBaseCriteria()
184
-					->addCondition('type_id >= 2')
185
-					->addCondition('password = ""');
32
+        return CMap::mergeArray(parent::filters(), array(array(
33
+            'COutputCache + list',
34
+            'duration' => YII_DEBUG ? 1 : 86400,
35
+            'varyByParam' => array('page'),
36
+            'varyByLanguage' => true,
37
+            'dependency' => array(
38
+                'class'=>'CDbCacheDependency',
39
+                'sql'=>'SELECT MAX(updated) FROM content',
40
+            )
41
+        )));
42
+    }
43
+
44
+
45
+    /**
46
+     * Specifies the access control rules.
47
+     * This method is used by the 'accessControl' filter.
48
+     * @return array access control rules
49
+     */
50
+    public function accessRules()
51
+    {
52
+        return array(
53
+            array('allow',  // Allow all users to any section
54
+                'actions' => array('index', 'password', 'list'),
55
+                'users'=>array('*'),
56
+            ),
57
+            array('deny',  // deny all users
58
+                'users'=>array('*'),
59
+            ),
60
+        );
61
+    }
62
+
63
+    /**
64
+     * Handles all incoming requests for the entire site that are not previous defined in CUrlManager
65
+     * Requests come in, are verified, and then pulled from the database dynamically
66
+     * @param $id	- The content ID that we want to pull from the database
67
+     **/
68
+    public function actionIndex($id=NULL, $vid=NULL)
69
+    {
70
+        // Set the ReturnURL to this page so that the user can be redirected back to here after login
71
+        Yii::app()->user->setReturnUrl($this->beforeCiiAction($id));
72
+
73
+        // Retrieve the data
74
+        $content = Content::model()->findByPk($id);
75
+
76
+        if ($content->status != 1 || !$content->isPublished())
77
+            throw new CHttpException(404, Yii::t('ciims.controllers.Content', 'The article you specified does not exist. If you bookmarked this page, please delete it.'));
78
+
79
+        // Check for a password
80
+        if (!empty($content->password))
81
+        {
82
+            // Check SESSION to see if a password is set
83
+            $tmpPassword = Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'password', NULL);
186 84
 
187
-		$criteria->order = 'published DESC';
85
+            if ($tmpPassword != $content->password)
86
+                $this->redirect(Yii::app()->createUrl('/content/password/' . $id));
87
+        }
188 88
 
189
-		$criteria->limit = $pageSize;
89
+        // Parse Metadata
90
+        $this->setLayout($content->layout);
91
+
92
+        $this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
93
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
94
+            '{{label}}'    => $content->title
95
+        )));
96
+
97
+        $this->params['meta']['description'] = $content->extract;
98
+        $this->render($content->view, array(
99
+            'id' 	=> $content->id,
100
+            'data' 	=> $content,
101
+            'meta' 	=> $content->parseMeta($content->id)
102
+        ));
103
+    }
104
+
105
+    /**
106
+     * Forces a password to be assigned before the user can proceed to the previous page
107
+     * @param $id - ID of the content we want to investigate
108
+     **/
109
+    public function actionPassword($id=NULL)
110
+    {
111
+        $this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
112
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
113
+            '{{label}}'    => Yii::t('ciims.controllers.Content', 'Password Required')
114
+        )));
115
+
116
+        if ($id == NULL)
117
+            $this->redirect(Yii::app()->user->returnUrl);
118
+
119
+        // Set some default data
120
+        if (Cii::get(Cii::get($_SESSION, 'password', array()), $id, NULL) == NULL)
121
+            $_SESSION['password'][$id] = array('tries'=>0, 'expires' => time() + 300);
122
+
123
+        // If the number of attempts is >= 3
124
+        if (Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'tries', 0) >= 3)
125
+        {
126
+            // If the expires time has already passed, unlock the account
127
+            if (Cii::get(Cii::get(Cii::get($_SESSION, 'password', array()), $id, array()), 'expires', 0) <= time())
128
+            {
129
+                $_SESSION['password'][$id] = array('tries'=>0, 'expires' => time() + 300);
130
+            }
131
+            else
132
+            {
133
+                // Otherwise prevent access to it
134
+                Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Content', 'Too many password attempts. Please try again in 5 minutes'));
135
+                unset($_POST['password']);
136
+                $_SESSION['password'][$id]['expires'] 	= time() + 300;
137
+            }
138
+        }
190 139
 
191
-		$itemCount = Content::model()->count($criteria);
192
-		$pages = new CPagination($itemCount);
193
-		$pages->pageSize=$pageSize;
140
+        if (Cii::get($_POST, 'password', NULL) !== NULL)
141
+        {
142
+            $content = Content::model()->findByPk($id);
143
+
144
+            $encrypted = Cii::encrypt(Cii::get($_POST, 'password'));
145
+
146
+            if ($encrypted == $content->attributes['password'])
147
+            {
148
+                $_SESSION['password'][$id]['password'] = $encrypted;
149
+                $_SESSION['password'][$id]['tries'] = 0;
150
+                $this->redirect(Yii::app()->createUrl($content->attributes['slug']));
151
+            }
152
+            else
153
+            {
154
+                Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Content', 'Incorrect password'));
155
+                $_SESSION['password'][$id]['tries'] 	= $_SESSION['password'][$id]['tries'] + 1;
156
+                $_SESSION['password'][$id]['expires'] 	= time() + 300;
157
+            }
194 158
 
195
-		$criteria->offset = $criteria->limit*($pages->getCurrentPage());
196
-		$data = Content::model()->findAll($criteria);
197
-		$pages->applyLimit($criteria);
159
+        }
198 160
 
199
-		$this->render('all', array(
200
-			'data'		=> $data,
201
-			'itemCount' => $itemCount,
202
-			'pages' 	=> $pages
203
-		));
204
-	}
161
+        $this->layout = 'password';
162
+        $this->render('password', array(
163
+            'id' => $id
164
+        ));
165
+    }
205 166
 
206
-	/**
207
-	 * No routing action
167
+    /*
168
+	 * Displays a listing of all blog posts for all time in all categories
169
+	 * Is used as a generic catch all behavior
208 170
 	 */
209
-	public function actionNR()
210
-	{
171
+    public function actionList()
172
+    {
173
+        $this->setPageTitle(Yii::t('ciims.controllers.Content', '{{app_name}} | {{label}}', array(
174
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
175
+            '{{label}}'    => Yii::t('ciims.controllers.Content', 'All Content')
176
+        )));
177
+
178
+        $this->setLayout('default');
179
+
180
+        $pageSize = Cii::getConfig('contentPaginationSize', 10);
181
+
182
+        $criteria = Content::model()
183
+                    ->getBaseCriteria()
184
+                    ->addCondition('type_id >= 2')
185
+                    ->addCondition('password = ""');
186
+
187
+        $criteria->order = 'published DESC';
188
+
189
+        $criteria->limit = $pageSize;
190
+
191
+        $itemCount = Content::model()->count($criteria);
192
+        $pages = new CPagination($itemCount);
193
+        $pages->pageSize=$pageSize;
194
+
195
+        $criteria->offset = $criteria->limit*($pages->getCurrentPage());
196
+        $data = Content::model()->findAll($criteria);
197
+        $pages->applyLimit($criteria);
198
+
199
+        $this->render('all', array(
200
+            'data'		=> $data,
201
+            'itemCount' => $itemCount,
202
+            'pages' 	=> $pages
203
+        ));
204
+    }
205
+
206
+    /**
207
+     * No routing action
208
+     */
209
+    public function actionNR()
210
+    {
211 211
         $themeName = Cii::getConfig('theme', 'default');
212 212
         if (file_exists(Yii::getPathOfAlias('webroot.themes.') . DS . $themeName .  DS . 'Theme.php'))
213 213
         {
@@ -215,9 +215,9 @@  discard block
 block discarded – undo
215 215
             $theme = new Theme;
216 216
         }
217 217
 
218
-		if ($theme->noRouting !== false)
219
-			$this->render('index');
220
-		else
221
-			throw new CHttpException(404);
222
-	}
218
+        if ($theme->noRouting !== false)
219
+            $this->render('index');
220
+        else
221
+            throw new CHttpException(404);
222
+    }
223 223
 }
Please login to merge, or discard this patch.
protected/controllers/ProfileController.php 1 patch
Indentation   +122 added lines, -122 removed lines patch added patch discarded remove patch
@@ -3,126 +3,126 @@
 block discarded – undo
3 3
 class ProfileController extends CiiController
4 4
 {
5 5
 
6
-	/**
7
-	 * The layout to use for this controller
8
-	 * @var string
9
-	 */
10
-	public $layout = '//layouts/main';
11
-
12
-	/**
13
-	 * @return array action filters
14
-	 */
15
-	public function filters()
16
-	{
17
-		return CMap::mergeArray(parent::filters(), array('accessControl'));
18
-	}
19
-
20
-	/**
21
-	 * Specifies the access control rules.
22
-	 * This method is used by the 'accessControl' filter.
23
-	 * @return array access control rules
24
-	 */
25
-	public function accessRules()
26
-	{
27
-		return array(
28
-			array('allow',  // Allow all users to any section
29
-				'actions' => array('index'),
30
-				'users'=>array('*'),
31
-			),
32
-			array('allow',  // deny all users
33
-				'actions' => array('edit', 'resend'),
34
-				'users'=>array('@'),
35
-			),
36
-			array('deny',  // deny all users
37
-				'users'=>array('*'),
38
-			),
39
-		);
40
-	}
41
-
42
-	/**
43
-	 * Provides functionality to view a given profile
44
-	 * @param  int 	  $id          The ID belonging to the user
45
-	 * @param  string $username    The user's display name. This isn't super necessary, it just is better for SEO
46
-	 */
47
-	public function actionIndex($id=NULL, $username=NULL)
48
-	{
49
-		// If an ID isn't provided, throw an error
50
-		if ($id === NULL)
51
-			throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
52
-
53
-		// For SEO, if the display name isn't in the url, reroute it
54
-		if ($id !== NULL && $username === NULL)
55
-		{
56
-			$model = Users::model()->findByPk($id);
57
-			if ($model === NULL || $model->status == 0)
58
-				throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
59
-			else
60
-				$this->redirect('/profile/' . $model->id . '/' . preg_replace('/[^\da-z]/i', '', $model->username));
61
-		}
62
-
63
-		$model = Users::model()->findByPk($id);
64
-
65
-		// Don't allow null signings or invalidated users to pollute our site
66
-		if($model->status == 0)
67
-			throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
68
-
69
-		$this->pageTitle = Yii::t('ciims.controllers.Profile', 'User {{user}} - CiiMS | {{sitename}}', array('{{user}}' => $model->name, '{{sitename}}' => Cii::getConfig('name', Yii::app()->name)));
70
-		$this->render('index', array(
71
-			'model' => $model,
72
-			'md' => new CMarkdownParser
73
-		));
74
-	}
75
-
76
-	/**
77
-	 * Provides functionality for a user to edit their profile
78
-	 */
79
-	public function actionEdit()
80
-	{
81
-		$model = new ProfileForm;
82
-		$model->load(Yii::app()->user->id);
83
-
84
-		if (Cii::get($_POST, 'ProfileForm', NULL) !== NULL)
85
-		{
86
-			$model->attributes = $_POST['ProfileForm'];
87
-			$model->password_repeat = $_POST['ProfileForm']['password_repeat'];
88
-
89
-			if ($model->save())
90
-			{
91
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'Your profile has been updated!'));
92
-				$this->redirect($this->createUrl('profile/index', array(
93
-					'id' => $model->id,
94
-					'username' => $model->username
95
-				)));
96
-			}
97
-			else
98
-				Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There were errors saving your profile. Please correct them before trying to save again.'));
99
-		}
100
-
101
-		$this->render('edit', array(
102
-			'model' => $model
103
-		));
104
-	}
105
-
106
-	/**
107
-	 * Send a new verification email to the user
108
-	 */
109
-	public function actionResend()
110
-	{
111
-		$model = new ProfileForm;
112
-		$model->load(Yii::app()->user->id);
113
-
114
-		// If we don't have one on file, then someone the user got to a page they shouldn't have gotten to
115
-		// Seamlessly redirect them back
116
-		if ($model->getNewEmail() == NULL)
117
-			$this->redirect(Yii::app()->user->returnUrl);
118
-
119
-		if ($model->sendVerificationEmail())
120
-			Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'A new verification email has been resent to {{user}}. Please check your email address.', array(
121
-				'{{user}}' => $model->getNewEmail()
122
-			)));
123
-		else
124
-			Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There was an error resending the verification email. Please try again later.'));
125
-
126
-		$this->redirect($this->createUrl('profile/edit'));
127
-	}
6
+    /**
7
+     * The layout to use for this controller
8
+     * @var string
9
+     */
10
+    public $layout = '//layouts/main';
11
+
12
+    /**
13
+     * @return array action filters
14
+     */
15
+    public function filters()
16
+    {
17
+        return CMap::mergeArray(parent::filters(), array('accessControl'));
18
+    }
19
+
20
+    /**
21
+     * Specifies the access control rules.
22
+     * This method is used by the 'accessControl' filter.
23
+     * @return array access control rules
24
+     */
25
+    public function accessRules()
26
+    {
27
+        return array(
28
+            array('allow',  // Allow all users to any section
29
+                'actions' => array('index'),
30
+                'users'=>array('*'),
31
+            ),
32
+            array('allow',  // deny all users
33
+                'actions' => array('edit', 'resend'),
34
+                'users'=>array('@'),
35
+            ),
36
+            array('deny',  // deny all users
37
+                'users'=>array('*'),
38
+            ),
39
+        );
40
+    }
41
+
42
+    /**
43
+     * Provides functionality to view a given profile
44
+     * @param  int 	  $id          The ID belonging to the user
45
+     * @param  string $username    The user's display name. This isn't super necessary, it just is better for SEO
46
+     */
47
+    public function actionIndex($id=NULL, $username=NULL)
48
+    {
49
+        // If an ID isn't provided, throw an error
50
+        if ($id === NULL)
51
+            throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
52
+
53
+        // For SEO, if the display name isn't in the url, reroute it
54
+        if ($id !== NULL && $username === NULL)
55
+        {
56
+            $model = Users::model()->findByPk($id);
57
+            if ($model === NULL || $model->status == 0)
58
+                throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
59
+            else
60
+                $this->redirect('/profile/' . $model->id . '/' . preg_replace('/[^\da-z]/i', '', $model->username));
61
+        }
62
+
63
+        $model = Users::model()->findByPk($id);
64
+
65
+        // Don't allow null signings or invalidated users to pollute our site
66
+        if($model->status == 0)
67
+            throw new CHttpException(404, Yii::t('ciims.controllers.Profile', "Oops! That user doesn't exist on our network!"));
68
+
69
+        $this->pageTitle = Yii::t('ciims.controllers.Profile', 'User {{user}} - CiiMS | {{sitename}}', array('{{user}}' => $model->name, '{{sitename}}' => Cii::getConfig('name', Yii::app()->name)));
70
+        $this->render('index', array(
71
+            'model' => $model,
72
+            'md' => new CMarkdownParser
73
+        ));
74
+    }
75
+
76
+    /**
77
+     * Provides functionality for a user to edit their profile
78
+     */
79
+    public function actionEdit()
80
+    {
81
+        $model = new ProfileForm;
82
+        $model->load(Yii::app()->user->id);
83
+
84
+        if (Cii::get($_POST, 'ProfileForm', NULL) !== NULL)
85
+        {
86
+            $model->attributes = $_POST['ProfileForm'];
87
+            $model->password_repeat = $_POST['ProfileForm']['password_repeat'];
88
+
89
+            if ($model->save())
90
+            {
91
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'Your profile has been updated!'));
92
+                $this->redirect($this->createUrl('profile/index', array(
93
+                    'id' => $model->id,
94
+                    'username' => $model->username
95
+                )));
96
+            }
97
+            else
98
+                Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There were errors saving your profile. Please correct them before trying to save again.'));
99
+        }
100
+
101
+        $this->render('edit', array(
102
+            'model' => $model
103
+        ));
104
+    }
105
+
106
+    /**
107
+     * Send a new verification email to the user
108
+     */
109
+    public function actionResend()
110
+    {
111
+        $model = new ProfileForm;
112
+        $model->load(Yii::app()->user->id);
113
+
114
+        // If we don't have one on file, then someone the user got to a page they shouldn't have gotten to
115
+        // Seamlessly redirect them back
116
+        if ($model->getNewEmail() == NULL)
117
+            $this->redirect(Yii::app()->user->returnUrl);
118
+
119
+        if ($model->sendVerificationEmail())
120
+            Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Profile', 'A new verification email has been resent to {{user}}. Please check your email address.', array(
121
+                '{{user}}' => $model->getNewEmail()
122
+            )));
123
+        else
124
+            Yii::app()->user->setFlash('error', Yii::t('ciims.controllers.Profile', 'There was an error resending the verification email. Please try again later.'));
125
+
126
+        $this->redirect($this->createUrl('profile/edit'));
127
+    }
128 128
 }
Please login to merge, or discard this patch.
protected/models/Categories.php 1 patch
Indentation   +315 added lines, -315 removed lines patch added patch discarded remove patch
@@ -19,319 +19,319 @@
 block discarded – undo
19 19
  */
20 20
 class Categories extends CiiModel
21 21
 {
22
-	public $pageSize = 15;
23
-
24
-	public $description = NULL;
25
-
26
-	public $keywords = array();
27
-
28
-	/**
29
-	 * Returns the static model of the specified AR class.
30
-	 * @param string $className active record class name.
31
-	 * @return Categories the static model class
32
-	 */
33
-	public static function model($className=__CLASS__)
34
-	{
35
-		return parent::model($className);
36
-	}
37
-
38
-	/**
39
-	 * @return string the associated database table name
40
-	 */
41
-	public function tableName()
42
-	{
43
-		return 'categories';
44
-	}
45
-
46
-	/**
47
-	 * @return array validation rules for model attributes.
48
-	 */
49
-	public function rules()
50
-	{
51
-		// NOTE: you should only define rules for those attributes that
52
-		// will receive user inputs.
53
-		return array(
54
-			array('parent_id, name', 'required'),
55
-			array('parent_id', 'numerical', 'integerOnly'=>true),
56
-			array('name, slug', 'length', 'max'=>150),
57
-			// The following rule is used by search().
58
-			// Please remove those attributes that should not be searched.
59
-			array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
-		);
61
-	}
62
-
63
-	/**
64
-	 * @return array relational rules.
65
-	 */
66
-	public function relations()
67
-	{
68
-		// NOTE: you may need to adjust the relation name and the related
69
-		// class name for the relations automatically generated below.
70
-		return array(
71
-			'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
-			'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
-			'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
-		);
75
-	}
76
-
77
-	/**
78
-	 * @return array customized attribute labels (name=>label)
79
-	 */
80
-	public function attributeLabels()
81
-	{
82
-		return array(
83
-			'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
-			'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
-			'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
-			'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
-			'description' => Yii::t('ciims.models.Categories', 'Description'),
88
-			'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
-			'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
-		);
91
-	}
92
-
93
-	public function getDescription()
94
-	{
95
-		$this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
-		if ($this->description == null || $this->description == false)
97
-			return NULL;
98
-
99
-		$this->description = $this->description->value;
100
-		return $this->description;
101
-	}
102
-
103
-	/**
104
-	 * Retrieves a list of models based on the current search/filter conditions.
105
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
-	 */
107
-	public function search()
108
-	{
109
-		$criteria=new CDbCriteria;
110
-
111
-		$criteria->compare('id',$this->id);
112
-		$criteria->compare('parent_id',$this->parent_id);
113
-		$criteria->compare('name',$this->name,true);
114
-		$criteria->compare('slug',$this->slug,true);
115
-		$criteria->compare('created',$this->created,true);
116
-		$criteria->compare('updated',$this->updated,true);
117
-		$criteria->order = "id DESC";
118
-
119
-		return new CActiveDataProvider($this, array(
120
-			'criteria' => $criteria,
121
-			'pagination' => array(
122
-				'pageSize' => $this->pageSize
123
-			)
124
-		));
125
-	}
126
-
127
-	/**
128
-	 * Gets keyword tags for this entry
129
-	 * @return array
130
-	 */
131
-	public function getKeywords()
132
-	{
133
-		$tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
-		return $tags === NULL ? array() : CJSON::decode($tags->value);
135
-	}
136
-
137
-	/**
138
-	 * Adds a tag to the model
139
-	 * @param string $tag	The tag to add
140
-	 * @return bool			If the insert was successful or not
141
-	 */
142
-	public function addKeyword($tag)
143
-	{
144
-		$tags = $this->keywords;
145
-		if (in_array($tag, $tags)  || $tag == "")
146
-			return false;
147
-
148
-		$tags[] = $tag;
149
-		$tags = CJSON::encode($tags);
150
-		$metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
-		if ($metaTag == false || $metaTag == NULL)
152
-		{
153
-			$metaTag = new CategoriestMetadata;
154
-			$metaTag->content_id = $this->id;
155
-			$metaTag->key = 'keywords';
156
-		}
157
-
158
-		$metaTag->value = $tags;
159
-		return $metaTag->save();
160
-	}
161
-
162
-	/**
163
-	 * Removes a tag from the model
164
-	 * @param string $tag	The tag to remove
165
-	 * @return bool			If the removal was successful
166
-	 */
167
-	public function removeKeyword($tag)
168
-	{
169
-		$tags = $this->keywords;
170
-		if (!in_array($tag, $tags) || $tag == "")
171
-			return false;
172
-
173
-		$key = array_search($tag, $tags);
174
-		unset($tags[$key]);
175
-		$tags = CJSON::encode($tags);
176
-
177
-		$metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
-		$metaTag->value = $tags;
179
-		return $metaTag->save();
180
-	}
181
-
182
-	/**
183
-	 * Verifies the slug before validating the model
184
-	 */
185
-	public function beforeValidate()
186
-	{
187
-		$this->slug = $this->verifySlug($this->slug, $this->name);
188
-
189
-		return parent::beforeValidate();
190
-	}
191
-
192
-	/**
193
-	 * Flushes URL data from the cache before the model is updated
194
-	 */
195
-	public function afterSave()
196
-	{
197
-		$meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
-		if ($meta == NULL)
199
-			$meta = new CategoriesMetadata;
200
-
201
-		$meta->category_id = $this->id;
202
-		$meta->key = 'description';
203
-		$meta->value  = $this->description;
204
-
205
-		$meta->save();
206
-
207
-		Yii::app()->cache->delete('CiiMS::Content::list');
208
-		Yii::app()->cache->delete('CiiMS::Routes');
209
-		Yii::app()->cache->delete('categories-pid');
210
-
211
-		return parent::afterSave();
212
-	}
213
-
214
-	/**
215
-	 * Automatically corrects parent tree issues that arise when a parent category node
216
-	 * is deleted.
217
-	 * @return boolean
218
-	 */
219
-	public function beforeDelete()
220
-	{
221
-		// Prevents the main "uncategorized category from being deleted"
222
-		if ($this->id == 1)
223
-		{
224
-			Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
-			return false;
226
-		}
227
-
228
-		Yii::app()->cache->delete('CiiMS::Content::list');
229
-		Yii::app()->cache->delete('CiiMS::Routes');
230
-		Yii::app()->cache->delete('categories-pid');
231
-
232
-		$parent = $this->parent_id;
233
-		$id = $this->id;
234
-
235
-		// Reassign all posts to the parent category
236
-		Yii::app()->db
237
-				->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
-				->bindParam(':parent_id', $parent)
239
-				->bindParam(':id', $id)
240
-				->execute();
241
-
242
-		// Reassign all child categories to the parent category
243
-		$data = $this->findAllByAttributes(array('parent_id' => $id));
244
-
245
-		foreach ($data as $row)
246
-		{
247
-			$id = $row->id;
248
-			Yii::app()->db
249
-					->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
-					->bindParam(':parent_id', $parent)
251
-					->bindParam(':id', $id)
252
-					->execute();
253
-		}
254
-
255
-		return parent::beforeDelete();
256
-	}
257
-
258
-	/**
259
-	 * Retrieves the parent categories for a given category_id
260
-	 * @param  int $id
261
-	 * @return array
262
-	 */
263
-	public function getParentCategories($id)
264
-	{
265
-		// Retrieve the data from cache if necessary
266
-		$response = Yii::app()->cache->get('categories-pid');
267
-		if ($response == NULL)
268
-		{
269
-			$response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
-			Yii::app()->cache->set('categories-pid', $response);
271
-		}
272
-
273
-		return $this->_getParentCategories($response, $id);
274
-	}
275
-
276
-	/**
277
-	 * Recursive callback for retrieving parent categories
278
-	 * @param  int  $id      The category we're seeking
279
-	 * @param  array  $stack A stack to hold the entire tree
280
-	 * @return array
281
-	 */
282
-	private function _getParentCategories($all_categories, $id, array $stack = array())
283
-	{
284
-		if ($id == 1)
285
-			return array_reverse($stack);
286
-
287
-		foreach ($all_categories as $k=>$v)
288
-		{
289
-			if ($v['id'] == $id)
290
-			{
291
-				$stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
-				return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
-			}
294
-		}
295
-	}
296
-
297
-	/**
298
-	 * checkSlug - Recursive method to verify that the slug can be used
299
-	 * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
-	 * @param string $slug - the slug to be checked
301
-	 * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
-	 * @return string $slug - the final slug to be used
303
-	 */
304
-	public function checkSlug($slug, $id=NULL)
305
-	{
306
-		$content = false;
307
-
308
-		// Find the number of items that have the same slug as this one
309
-		$count = $this->countByAttributes(array('slug'=>$slug . $id));
310
-
311
-		if ($count == 0)
312
-		{
313
-			$content = true;
314
-			$count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
-		}
316
-
317
-		// If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
-		// in which case we don't need to alter the slug
319
-		if ($count >= 1)
320
-		{
321
-			if ($content)
322
-				return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
-
324
-			// Pull the data that matches
325
-			$data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
-
327
-			// Check the pulled data id to the current item
328
-			if ($data !== NULL && $data->id == $this->id)
329
-				return $slug;
330
-		}
331
-
332
-		if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
-			return $slug . $id;
334
-		else
335
-			return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
-	}
22
+    public $pageSize = 15;
23
+
24
+    public $description = NULL;
25
+
26
+    public $keywords = array();
27
+
28
+    /**
29
+     * Returns the static model of the specified AR class.
30
+     * @param string $className active record class name.
31
+     * @return Categories the static model class
32
+     */
33
+    public static function model($className=__CLASS__)
34
+    {
35
+        return parent::model($className);
36
+    }
37
+
38
+    /**
39
+     * @return string the associated database table name
40
+     */
41
+    public function tableName()
42
+    {
43
+        return 'categories';
44
+    }
45
+
46
+    /**
47
+     * @return array validation rules for model attributes.
48
+     */
49
+    public function rules()
50
+    {
51
+        // NOTE: you should only define rules for those attributes that
52
+        // will receive user inputs.
53
+        return array(
54
+            array('parent_id, name', 'required'),
55
+            array('parent_id', 'numerical', 'integerOnly'=>true),
56
+            array('name, slug', 'length', 'max'=>150),
57
+            // The following rule is used by search().
58
+            // Please remove those attributes that should not be searched.
59
+            array('id, parent_id, name, slug', 'safe', 'on'=>'search'),
60
+        );
61
+    }
62
+
63
+    /**
64
+     * @return array relational rules.
65
+     */
66
+    public function relations()
67
+    {
68
+        // NOTE: you may need to adjust the relation name and the related
69
+        // class name for the relations automatically generated below.
70
+        return array(
71
+            'parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
72
+            'metadata' => array(self::HAS_MANY, 'CategoriesMetadata', 'category_id'),
73
+            'content' => array(self::HAS_MANY, 'Content', 'category_id'),
74
+        );
75
+    }
76
+
77
+    /**
78
+     * @return array customized attribute labels (name=>label)
79
+     */
80
+    public function attributeLabels()
81
+    {
82
+        return array(
83
+            'id' 		=> Yii::t('ciims.models.Categories', 'ID'),
84
+            'parent_id' => Yii::t('ciims.models.Categories', 'Parent'),
85
+            'name'      => Yii::t('ciims.models.Categories', 'Name'),
86
+            'slug'      => Yii::t('ciims.models.Categories', 'Slug'),
87
+            'description' => Yii::t('ciims.models.Categories', 'Description'),
88
+            'created'   => Yii::t('ciims.models.Categories', 'Created'),
89
+            'updated'   => Yii::t('ciims.models.Categories', 'Updated'),
90
+        );
91
+    }
92
+
93
+    public function getDescription()
94
+    {
95
+        $this->description = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
96
+        if ($this->description == null || $this->description == false)
97
+            return NULL;
98
+
99
+        $this->description = $this->description->value;
100
+        return $this->description;
101
+    }
102
+
103
+    /**
104
+     * Retrieves a list of models based on the current search/filter conditions.
105
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
106
+     */
107
+    public function search()
108
+    {
109
+        $criteria=new CDbCriteria;
110
+
111
+        $criteria->compare('id',$this->id);
112
+        $criteria->compare('parent_id',$this->parent_id);
113
+        $criteria->compare('name',$this->name,true);
114
+        $criteria->compare('slug',$this->slug,true);
115
+        $criteria->compare('created',$this->created,true);
116
+        $criteria->compare('updated',$this->updated,true);
117
+        $criteria->order = "id DESC";
118
+
119
+        return new CActiveDataProvider($this, array(
120
+            'criteria' => $criteria,
121
+            'pagination' => array(
122
+                'pageSize' => $this->pageSize
123
+            )
124
+        ));
125
+    }
126
+
127
+    /**
128
+     * Gets keyword tags for this entry
129
+     * @return array
130
+     */
131
+    public function getKeywords()
132
+    {
133
+        $tags = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
134
+        return $tags === NULL ? array() : CJSON::decode($tags->value);
135
+    }
136
+
137
+    /**
138
+     * Adds a tag to the model
139
+     * @param string $tag	The tag to add
140
+     * @return bool			If the insert was successful or not
141
+     */
142
+    public function addKeyword($tag)
143
+    {
144
+        $tags = $this->keywords;
145
+        if (in_array($tag, $tags)  || $tag == "")
146
+            return false;
147
+
148
+        $tags[] = $tag;
149
+        $tags = CJSON::encode($tags);
150
+        $metaTag = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
151
+        if ($metaTag == false || $metaTag == NULL)
152
+        {
153
+            $metaTag = new CategoriestMetadata;
154
+            $metaTag->content_id = $this->id;
155
+            $metaTag->key = 'keywords';
156
+        }
157
+
158
+        $metaTag->value = $tags;
159
+        return $metaTag->save();
160
+    }
161
+
162
+    /**
163
+     * Removes a tag from the model
164
+     * @param string $tag	The tag to remove
165
+     * @return bool			If the removal was successful
166
+     */
167
+    public function removeKeyword($tag)
168
+    {
169
+        $tags = $this->keywords;
170
+        if (!in_array($tag, $tags) || $tag == "")
171
+            return false;
172
+
173
+        $key = array_search($tag, $tags);
174
+        unset($tags[$key]);
175
+        $tags = CJSON::encode($tags);
176
+
177
+        $metaTag = CategoryMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'keywords'));
178
+        $metaTag->value = $tags;
179
+        return $metaTag->save();
180
+    }
181
+
182
+    /**
183
+     * Verifies the slug before validating the model
184
+     */
185
+    public function beforeValidate()
186
+    {
187
+        $this->slug = $this->verifySlug($this->slug, $this->name);
188
+
189
+        return parent::beforeValidate();
190
+    }
191
+
192
+    /**
193
+     * Flushes URL data from the cache before the model is updated
194
+     */
195
+    public function afterSave()
196
+    {
197
+        $meta = CategoriesMetadata::model()->findByAttributes(array('category_id' => $this->id, 'key' => 'description'));
198
+        if ($meta == NULL)
199
+            $meta = new CategoriesMetadata;
200
+
201
+        $meta->category_id = $this->id;
202
+        $meta->key = 'description';
203
+        $meta->value  = $this->description;
204
+
205
+        $meta->save();
206
+
207
+        Yii::app()->cache->delete('CiiMS::Content::list');
208
+        Yii::app()->cache->delete('CiiMS::Routes');
209
+        Yii::app()->cache->delete('categories-pid');
210
+
211
+        return parent::afterSave();
212
+    }
213
+
214
+    /**
215
+     * Automatically corrects parent tree issues that arise when a parent category node
216
+     * is deleted.
217
+     * @return boolean
218
+     */
219
+    public function beforeDelete()
220
+    {
221
+        // Prevents the main "uncategorized category from being deleted"
222
+        if ($this->id == 1)
223
+        {
224
+            Yii::app()->user->setFlash('error', Yii::t('ciims.models.Categories', 'This category cannot be deleted'));
225
+            return false;
226
+        }
227
+
228
+        Yii::app()->cache->delete('CiiMS::Content::list');
229
+        Yii::app()->cache->delete('CiiMS::Routes');
230
+        Yii::app()->cache->delete('categories-pid');
231
+
232
+        $parent = $this->parent_id;
233
+        $id = $this->id;
234
+
235
+        // Reassign all posts to the parent category
236
+        Yii::app()->db
237
+                ->createCommand('UPDATE content SET category_id = :parent_id WHERE category_id = :id')
238
+                ->bindParam(':parent_id', $parent)
239
+                ->bindParam(':id', $id)
240
+                ->execute();
241
+
242
+        // Reassign all child categories to the parent category
243
+        $data = $this->findAllByAttributes(array('parent_id' => $id));
244
+
245
+        foreach ($data as $row)
246
+        {
247
+            $id = $row->id;
248
+            Yii::app()->db
249
+                    ->createCommand('UPDATE categories SET parent_id = :parent_id WHERE id = :id')
250
+                    ->bindParam(':parent_id', $parent)
251
+                    ->bindParam(':id', $id)
252
+                    ->execute();
253
+        }
254
+
255
+        return parent::beforeDelete();
256
+    }
257
+
258
+    /**
259
+     * Retrieves the parent categories for a given category_id
260
+     * @param  int $id
261
+     * @return array
262
+     */
263
+    public function getParentCategories($id)
264
+    {
265
+        // Retrieve the data from cache if necessary
266
+        $response = Yii::app()->cache->get('categories-pid');
267
+        if ($response == NULL)
268
+        {
269
+            $response = Yii::app()->db->createCommand('SELECT id, parent_id, name, slug FROM categories')->queryAll();
270
+            Yii::app()->cache->set('categories-pid', $response);
271
+        }
272
+
273
+        return $this->_getParentCategories($response, $id);
274
+    }
275
+
276
+    /**
277
+     * Recursive callback for retrieving parent categories
278
+     * @param  int  $id      The category we're seeking
279
+     * @param  array  $stack A stack to hold the entire tree
280
+     * @return array
281
+     */
282
+    private function _getParentCategories($all_categories, $id, array $stack = array())
283
+    {
284
+        if ($id == 1)
285
+            return array_reverse($stack);
286
+
287
+        foreach ($all_categories as $k=>$v)
288
+        {
289
+            if ($v['id'] == $id)
290
+            {
291
+                $stack[$v['name']] = array(str_replace(Yii::app()->baseUrl, NULL, Yii::app()->createUrl($v['slug'])));
292
+                return $this->_getParentCategories($all_categories, $v['parent_id'], $stack);
293
+            }
294
+        }
295
+    }
296
+
297
+    /**
298
+     * checkSlug - Recursive method to verify that the slug can be used
299
+     * This method is purposfuly declared here to so that Content::findByPk is used instead of CiiModel::findByPk
300
+     * @param string $slug - the slug to be checked
301
+     * @param int $id - the numeric id to be appended to the slug if a conflict exists
302
+     * @return string $slug - the final slug to be used
303
+     */
304
+    public function checkSlug($slug, $id=NULL)
305
+    {
306
+        $content = false;
307
+
308
+        // Find the number of items that have the same slug as this one
309
+        $count = $this->countByAttributes(array('slug'=>$slug . $id));
310
+
311
+        if ($count == 0)
312
+        {
313
+            $content = true;
314
+            $count = Content::model()->countByAttributes(array('slug'=>$slug . $id));
315
+        }
316
+
317
+        // If we found an item that matched, it's possible that it is the current item (or a previous version of it)
318
+        // in which case we don't need to alter the slug
319
+        if ($count >= 1)
320
+        {
321
+            if ($content)
322
+                return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
323
+
324
+            // Pull the data that matches
325
+            $data = $this->findByPk($this->id === NULL ? -1 : $this->id);
326
+
327
+            // Check the pulled data id to the current item
328
+            if ($data !== NULL && $data->id == $this->id)
329
+                return $slug;
330
+        }
331
+
332
+        if ($count == 0 && !in_array($slug, $this->forbiddenRoutes))
333
+            return $slug . $id;
334
+        else
335
+            return $this->checkSlug($slug, ($id === NULL ? 1 : ($id+1)));
336
+    }
337 337
 }
Please login to merge, or discard this patch.
protected/models/CategoriesMetadata.php 1 patch
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -16,83 +16,83 @@
 block discarded – undo
16 16
  */
17 17
 class CategoriesMetadata extends CiiModel
18 18
 {
19
-	/**
20
-	 * Returns the static model of the specified AR class.
21
-	 * @param string $className active record class name.
22
-	 * @return CategoriesMetadata the static model class
23
-	 */
24
-	public static function model($className=__CLASS__)
25
-	{
26
-		return parent::model($className);
27
-	}
19
+    /**
20
+     * Returns the static model of the specified AR class.
21
+     * @param string $className active record class name.
22
+     * @return CategoriesMetadata the static model class
23
+     */
24
+    public static function model($className=__CLASS__)
25
+    {
26
+        return parent::model($className);
27
+    }
28 28
 
29
-	/**
30
-	 * @return string the associated database table name
31
-	 */
32
-	public function tableName()
33
-	{
34
-		return 'categories_metadata';
35
-	}
29
+    /**
30
+     * @return string the associated database table name
31
+     */
32
+    public function tableName()
33
+    {
34
+        return 'categories_metadata';
35
+    }
36 36
 
37
-	/**
38
-	 * @return array validation rules for model attributes.
39
-	 */
40
-	public function rules()
41
-	{
42
-		// NOTE: you should only define rules for those attributes that
43
-		// will receive user inputs.
44
-		return array(
45
-			array('category_id, key, value', 'required'),
46
-			array('category_id', 'numerical', 'integerOnly'=>true),
47
-			array('key, value', 'length', 'max'=>50),
48
-			// The following rule is used by search().
49
-			// Please remove those attributes that should not be searched.
50
-			array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
-		);
52
-	}
37
+    /**
38
+     * @return array validation rules for model attributes.
39
+     */
40
+    public function rules()
41
+    {
42
+        // NOTE: you should only define rules for those attributes that
43
+        // will receive user inputs.
44
+        return array(
45
+            array('category_id, key, value', 'required'),
46
+            array('category_id', 'numerical', 'integerOnly'=>true),
47
+            array('key, value', 'length', 'max'=>50),
48
+            // The following rule is used by search().
49
+            // Please remove those attributes that should not be searched.
50
+            array('id, category_id, key, value, created, updated', 'safe', 'on'=>'search'),
51
+        );
52
+    }
53 53
 
54
-	/**
55
-	 * @return array relational rules.
56
-	 */
57
-	public function relations()
58
-	{
59
-		// NOTE: you may need to adjust the relation name and the related
60
-		// class name for the relations automatically generated below.
61
-		return array(
62
-			'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
-		);
64
-	}
54
+    /**
55
+     * @return array relational rules.
56
+     */
57
+    public function relations()
58
+    {
59
+        // NOTE: you may need to adjust the relation name and the related
60
+        // class name for the relations automatically generated below.
61
+        return array(
62
+            'category' => array(self::BELONGS_TO, 'Categories', 'category_id'),
63
+        );
64
+    }
65 65
 
66
-	/**
67
-	 * @return array customized attribute labels (name=>label)
68
-	 */
69
-	public function attributeLabels()
70
-	{
71
-		return array(
72
-			'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
-			'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
-			'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
-			'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
-			'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
-		);
78
-	}
66
+    /**
67
+     * @return array customized attribute labels (name=>label)
68
+     */
69
+    public function attributeLabels()
70
+    {
71
+        return array(
72
+            'category_id' => Yii::t('ciims.models.CategoriesMetadata', 'Category ID'),
73
+            'key' 	      => Yii::t('ciims.models.CategoriesMetadata', 'Key'),
74
+            'value'       => Yii::t('ciims.models.CategoriesMetadata', 'Value'),
75
+            'created'	  => Yii::t('ciims.models.CategoriesMetadata', 'Created'),
76
+            'updated' 	  => Yii::t('ciims.models.CategoriesMetadata', 'Updated'),
77
+        );
78
+    }
79 79
 
80
-	/**
81
-	 * Retrieves a list of models based on the current search/filter conditions.
82
-	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
-	 */
84
-	public function search()
85
-	{
86
-		$criteria=new CDbCriteria;
80
+    /**
81
+     * Retrieves a list of models based on the current search/filter conditions.
82
+     * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
83
+     */
84
+    public function search()
85
+    {
86
+        $criteria=new CDbCriteria;
87 87
 
88
-		$criteria->compare('category_id',$this->category_id);
89
-		$criteria->compare('t.key',$this->key,true);
90
-		$criteria->compare('value',$this->value,true);
91
-		$criteria->compare('created',$this->created,true);
92
-		$criteria->compare('updated',$this->updated,true);
88
+        $criteria->compare('category_id',$this->category_id);
89
+        $criteria->compare('t.key',$this->key,true);
90
+        $criteria->compare('value',$this->value,true);
91
+        $criteria->compare('created',$this->created,true);
92
+        $criteria->compare('updated',$this->updated,true);
93 93
 
94
-		return new CActiveDataProvider($this, array(
95
-			'criteria'=>$criteria,
96
-		));
97
-	}
94
+        return new CActiveDataProvider($this, array(
95
+            'criteria'=>$criteria,
96
+        ));
97
+    }
98 98
 }
Please login to merge, or discard this patch.