Completed
Push — master ( fffbfa...9fa4a1 )
by Charles
03:39
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/commands/CiiMigrateCommand.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -2,13 +2,13 @@
 block discarded – undo
2 2
 // Import System/Cli/Commands/MigrateCommand
3 3
 Yii::import('system.cli.commands.MigrateCommand');
4 4
 /**
5
- * This class is an injection container for CDbMigration which permits us to
6
- * directly access CDbMigrations from our web application without having
7
- * access to CLI or knowing before hand what our DSN is.
8
- *
9
- * Under no circumstances, should this be called directly from command line.
10
- *
11
- */
5
+     * This class is an injection container for CDbMigration which permits us to
6
+     * directly access CDbMigrations from our web application without having
7
+     * access to CLI or knowing before hand what our DSN is.
8
+     *
9
+     * Under no circumstances, should this be called directly from command line.
10
+     *
11
+     */
12 12
 class CiiMigrateCommand extends MigrateCommand
13 13
 {
14 14
     /**
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/controllers/SiteController.php 1 patch
Indentation   +425 added lines, -425 removed lines patch added patch discarded remove patch
@@ -2,430 +2,430 @@
 block discarded – undo
2 2
 
3 3
 class SiteController extends CiiController
4 4
 {
5
-	public function filters()
6
-	{
7
-		return CMap::mergeArray(parent::filters(), array('accessControl'));
8
-	}
9
-
10
-	/**
11
-	 * Setup access controls to prevent guests from changing their emaila ddress
12
-	 */
13
-	public function accessRules()
14
-	{
15
-		return array(
16
-		   array('deny',  // The user mut be authenticated to approve an email address change
17
-				'users'=>array('*'),
18
-				'expression'=>'Yii::app()->user->isGuest==true',
19
-				'actions' => array('emailchange')
20
-			)
21
-		);
22
-	}
23
-
24
-	/**
25
-	 * beforeAction method, performs operations before an action is presented
26
-	 * @param $action, the action being called
27
-	 * @see http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail
28
-	 */
29
-	public function beforeAction($action)
30
-	{
31
-		if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false))
32
-			$this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri);
33
-
34
-		return parent::beforeAction($action);
35
-	}
36
-
37
-	/**
38
-	 * This is the action to handle external exceptions.
39
-	 */
40
-	public function actionError($code=NULL)
41
-	{
42
-		$this->layout = '//layouts/main';
43
-
44
-		if($error=Yii::app()->errorHandler->error)
45
-		{
46
-			if(Yii::app()->request->isAjaxRequest)
47
-				echo $error['message'];
48
-			else
49
-			{
50
-				$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array(
51
-					'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
52
-					'{{label}}'    => Yii::t('ciims.controllers.Site', 'Error'),
53
-					'{{code}}'     => $error['code']
54
-				)));
55
-
56
-				$this->render('error', array(
57
-					'error' => $error
58
-				));
59
-			}
60
-		}
61
-		else
62
-		{
63
-			$message = Yii::app()->user->getFlash('error_code');
64
-			Yii::app()->user->setFlash('error_code', $message);
65
-			throw new CHttpException($code, $message);
66
-		}
67
-	}
68
-
69
-	/**
70
-	 * Provides basic sitemap functionality via XML
71
-	 */
72
-	public function actionSitemap()
73
-	{
74
-		ob_end_clean();
75
-		Yii::app()->log->routes[0]->enabled = false;
76
-		header('Content-type: text/xml; charset=utf-8');
77
-		$url = 'http://'.Yii::app()->request->serverName . Yii::app()->baseUrl;
78
-		$this->setLayout(null);
79
-		$content 	= Yii::app()->db
80
-								->createCommand('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();')
81
-								->queryAll();
82
-
83
-		$categories = Yii::app()->db
84
-								->createCommand('SELECT slug, updated FROM categories;')
85
-								->queryAll();
86
-
87
-		$this->renderPartial('sitemap', array(
88
-			'content' 	 => $content,
89
-			'categories' => $categories,
90
-			'url' 		 => $url
91
-		));
92
-
93
-		Yii::app()->end();
94
-	}
95
-
96
-	/**
97
-	 * Provides basic searching functionality
98
-	 * @param int $id   The search pagination id
99
-	 */
100
-	public function actionSearch($id=1)
101
-	{
102
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
103
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
104
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Search')
105
-		)));
106
-
107
-		$this->layout = '//layouts/default';
108
-		$data = array();
109
-		$pages = array();
110
-		$itemCount = 0;
111
-		$pageSize = Cii::getConfig('searchPaginationSize', 10);
112
-
113
-		if (Cii::get($_GET, 'q', false))
114
-		{
115
-			$criteria = new CDbCriteria;
116
-			$criteria->addCondition('status = 1')
117
-					 ->addCondition('published <= UTC_TIMESTAMP()');
118
-
119
-			if (strpos($_GET['q'], 'user_id') !== false)
120
-			{
121
-				$criteria->addCondition('author_id = :author_id')
122
-						 ->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)");
123
-				$criteria->params = array(
124
-					':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0))
125
-				);
126
-			}
127
-			else
128
-			{
129
-				$param = Cii::get($_GET, 'q', 0);
130
-				$criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))");
131
-				$criteria->params = array(
132
-					':param' 	=> '%' . $param . '%',
133
-					':param2'	=> '%' . $param . '%'
134
-				);
135
-			}
136
-
137
-			$criteria->addCondition('password = ""');
138
-			$criteria->limit = $pageSize;
139
-			$criteria->order = 'id DESC';
140
-			$itemCount = Content::model()->count($criteria);
141
-			$pages = new CPagination($itemCount);
142
-			$pages->pageSize=$pageSize;
143
-
144
-			$criteria->offset = $criteria->limit*($pages->getCurrentPage());
145
-			$data = Content::model()->findAll($criteria);
146
-			$pages->applyLimit($criteria);
147
-		}
148
-
149
-		$this->render('search', array(
150
-			'url' 		=> 'search',
151
-			'id' 		=> $id,
152
-			'data' 		=> $data,
153
-			'itemCount' => $itemCount,
154
-			'pages' 	=> $pages
155
-		));
156
-	}
157
-
158
-	/**
159
-	 * Provides functionality to log a user into the system
160
-	 */
161
-	public function actionLogin()
162
-	{
163
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
164
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
165
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Login to your account')
166
-		)));
167
-
168
-		$this->layout = '//layouts/main';
169
-		$model = new LoginForm;
170
-
171
-		if (Cii::get($_POST, 'LoginForm', false))
172
-		{
173
-			$model->attributes = Cii::get($_POST, 'LoginForm', array());
174
-			if ($model->login())
175
-				$this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl);
176
-		}
177
-
178
-		$this->render('login', array(
179
-			'model' => $model
180
-		));
181
-	}
182
-
183
-	/**
184
-	 * Provides functionality to log a user out
185
-	 */
186
-	public function actionLogout()
187
-	{
188
-		if (Yii::app()->request->getParam('next', false))
189
-			$redirect = $this->createUrl('site/login', array('next' => $this->_getNext()));
190
-		else
191
-			$redirect = Yii::app()->user->returnUrl;
192
-
193
-		// Purge the active sessions API Key
194
-		$apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key'));
195
-
196
-		if ($apiKey != NULL)
197
-			$apiKey->delete();
198
-
199
-
200
-		Yii::app()->user->logout();
201
-		$this->redirect($redirect);
202
-	}
203
-
204
-	/**
205
-	 * Handles resetting a users password should they forgot it
206
-	 */
207
-	public function actionForgot()
208
-	{
209
-		$this->layout = '//layouts/main';
210
-
211
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
212
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
213
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Forgot Your Password?')
214
-		)));
215
-
216
-		$model = new ForgotForm;
217
-
218
-		if (Cii::get($_POST, 'ForgotForm', false))
219
-		{
220
-			$model->attributes = $_POST['ForgotForm'];
221
-
222
-			if ($model->initPasswordResetProcess())
223
-			{
224
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'A password reset link has been sent to your email address'));
225
-				$this->redirect($this->createUrl('site/login'));
226
-			}
227
-		}
228
-
229
-		$this->render('forgot', array(
230
-			'model' => $model
231
-		));
232
-	}
233
-
234
-	/**
235
-	 * Alows a user to reset their password if they initiated a forgot password request
236
-	 * @param string $id
237
-	 */
238
-	public function actionResetPassword($id=NULL)
239
-	{
240
-		$this->layout = '//layouts/main';
241
-
242
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
243
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
244
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Reset Your password')
245
-		)));
246
-
247
-		$model = new PasswordResetForm;
248
-		$model->reset_key = $id;
249
-
250
-		if (!$model->validateResetKey())
251
-			throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid'));
252
-
253
-		if (Cii::get($_POST, 'PasswordResetForm', false))
254
-		{
255
-			$model->attributes = $_POST['PasswordResetForm'];
256
-
257
-			if ($model->save())
258
-			{
259
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password'));
260
-				$this->redirect($this->createUrl('site/login'));
261
-			}
262
-		}
263
-
264
-		$this->render('resetpassword', array(
265
-			'model' => $model
266
-		));
267
-	}
268
-
269
-	/**
270
-	 * Allows the user to securely change their email address
271
-	 * @param  string $key the user's secure key
272
-	 */
273
-	public function actionEmailChange($key=null)
274
-	{
275
-		$this->layout = '//layouts/main';
276
-
277
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
278
-		   '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
279
-		   '{{label}}'    => Yii::t('ciims.controllers.Site', 'Change Your Email Address')
280
-	   )));
281
-
282
-		$model = new EmailChangeForm;
283
-		$model->setUser(Users::model()->findByPk(Yii::app()->user->id));
284
-		$model->verificationKey = $key;
285
-
286
-		if (!$model->validateVerificationKey())
287
-			throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.'));
288
-
289
-		if (Cii::get($_POST, 'EmailChangeForm', false))
290
-		{
291
-			$model->attributes = $_POST['EmailChangeForm'];
292
-
293
-			if ($model->save())
294
-			{
295
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your new email address has been verified.'));
296
-
297
-				$loginForm = new LoginForm;
298
-				$loginForm->attributes = array(
299
-					'username' => Users::model()->findByPk(Yii::app()->user->id)->email,
300
-					'password' => $model->password,
301
-				);
302
-
303
-				if ($loginForm->login())
304
-					return $this->redirect(Yii::app()->homeUrl);
305
-
306
-				throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.'));
307
-			}
308
-		}
309
-
310
-		$this->render('emailchange', array(
311
-			'model' => $model
312
-		));
313
-	}
314
-
315
-	/**
316
-	 * Activates a new user's account
317
-	 * @param mixed $id 			The activation key
318
-	 */
319
-	public function actionActivation($id=NULL)
320
-	{
321
-		$this->layout = '//layouts/main';
322
-
323
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
324
-		   '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
325
-		   '{{label}}'    => Yii::t('ciims.controllers.Site', 'Activate Your Account')
326
-	   )));
327
-
328
-		$model = new ActivationForm;
329
-		$model->activationKey = $id;
330
-
331
-		if (!$model->validateKey())
332
-			throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
333
-
334
-		if (Cii::get($_POST, 'ActivationForm', false))
335
-		{
336
-			$model->attributes = $_POST['ActivationForm'];
337
-
338
-			if ($model->save())
339
-			{
340
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login'));
341
-				$this->redirect($this->createUrl('site/login'));
342
-			}
343
-		}
344
-
345
-		$this->render('activation', array(
346
-			'model' => $model
347
-		));
348
-	}
349
-
350
-	/**
351
-	 * Handles the registration of new users on the site
352
-	 */
353
-	public function actionRegister()
354
-	{
355
-		$this->layout = '//layouts/main';
356
-
357
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
358
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
359
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Sign Up')
360
-		)));
361
-
362
-		$model = new RegisterForm;
363
-
364
-		if (Cii::get($_POST, 'RegisterForm', false))
365
-		{
366
-			$model->attributes = $_POST['RegisterForm'];
367
-
368
-			// Save the user's information
369
-			if ($model->save())
370
-			{
371
-				// Set a flash message
372
-				Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions'));
373
-				$this->redirect($this->createUrl('site/login'));
374
-			}
375
-		}
376
-
377
-		$this->render('register', array(
378
-			'model'=>$model
379
-		));
380
-	}
381
-
382
-	/**
383
-	 * Enables users who have recieved an invitation to setup a new account
384
-	 * @param string $id	The activation id the of the user that we want to activate
385
-	 */
386
-	public function actionAcceptInvite($id=NULL)
387
-	{
388
-		$this->layout = '//layouts/main';
389
-
390
-		$this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
391
-			'{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
392
-			'{{label}}'    => Yii::t('ciims.controllers.Site', 'Accept Invitation')
393
-		)));
394
-
395
-		if ($id === NULL)
396
-			throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.'));
397
-
398
-		// Make sure we have a user first
399
-		$meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id));
400
-		if ($meta === NULL)
401
-			throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.'));
402
-
403
-		$model = new InviteForm;
404
-		$model->email = Users::model()->findByPk($meta->user_id)->email;
405
-
406
-		if (Cii::get($_POST, 'InviteForm', NULL) !== NULL)
407
-		{
408
-			$model->attributes = Cii::get($_POST, 'InviteForm', NULL);
409
-			$model->id = $meta->user_id;
410
-
411
-			if ($model->acceptInvite())
412
-			{
413
-				$meta->delete();
414
-				return $this->render('invitesuccess');
415
-			}
416
-		}
417
-
418
-		$this->render('acceptinvite', array(
419
-			'model' => $model
420
-		));
421
-	}
5
+    public function filters()
6
+    {
7
+        return CMap::mergeArray(parent::filters(), array('accessControl'));
8
+    }
9
+
10
+    /**
11
+     * Setup access controls to prevent guests from changing their emaila ddress
12
+     */
13
+    public function accessRules()
14
+    {
15
+        return array(
16
+            array('deny',  // The user mut be authenticated to approve an email address change
17
+                'users'=>array('*'),
18
+                'expression'=>'Yii::app()->user->isGuest==true',
19
+                'actions' => array('emailchange')
20
+            )
21
+        );
22
+    }
23
+
24
+    /**
25
+     * beforeAction method, performs operations before an action is presented
26
+     * @param $action, the action being called
27
+     * @see http://www.yiiframework.com/doc/api/1.1/CController#beforeAction-detail
28
+     */
29
+    public function beforeAction($action)
30
+    {
31
+        if (!Yii::app()->getRequest()->isSecureConnection && Cii::getConfig('forceSecureSSL', false))
32
+            $this->redirect('https://' . Yii::app()->getRequest()->serverName . Yii::app()->getRequest()->requestUri);
33
+
34
+        return parent::beforeAction($action);
35
+    }
36
+
37
+    /**
38
+     * This is the action to handle external exceptions.
39
+     */
40
+    public function actionError($code=NULL)
41
+    {
42
+        $this->layout = '//layouts/main';
43
+
44
+        if($error=Yii::app()->errorHandler->error)
45
+        {
46
+            if(Yii::app()->request->isAjaxRequest)
47
+                echo $error['message'];
48
+            else
49
+            {
50
+                $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}} {{code}}', array(
51
+                    '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
52
+                    '{{label}}'    => Yii::t('ciims.controllers.Site', 'Error'),
53
+                    '{{code}}'     => $error['code']
54
+                )));
55
+
56
+                $this->render('error', array(
57
+                    'error' => $error
58
+                ));
59
+            }
60
+        }
61
+        else
62
+        {
63
+            $message = Yii::app()->user->getFlash('error_code');
64
+            Yii::app()->user->setFlash('error_code', $message);
65
+            throw new CHttpException($code, $message);
66
+        }
67
+    }
68
+
69
+    /**
70
+     * Provides basic sitemap functionality via XML
71
+     */
72
+    public function actionSitemap()
73
+    {
74
+        ob_end_clean();
75
+        Yii::app()->log->routes[0]->enabled = false;
76
+        header('Content-type: text/xml; charset=utf-8');
77
+        $url = 'http://'.Yii::app()->request->serverName . Yii::app()->baseUrl;
78
+        $this->setLayout(null);
79
+        $content 	= Yii::app()->db
80
+                                ->createCommand('SELECT slug, password, type_id, updated FROM content AS t WHERE vid=(SELECT MAX(vid) FROM content WHERE id=t.id) AND status = 1 AND published <= UTC_TIMESTAMP();')
81
+                                ->queryAll();
82
+
83
+        $categories = Yii::app()->db
84
+                                ->createCommand('SELECT slug, updated FROM categories;')
85
+                                ->queryAll();
86
+
87
+        $this->renderPartial('sitemap', array(
88
+            'content' 	 => $content,
89
+            'categories' => $categories,
90
+            'url' 		 => $url
91
+        ));
92
+
93
+        Yii::app()->end();
94
+    }
95
+
96
+    /**
97
+     * Provides basic searching functionality
98
+     * @param int $id   The search pagination id
99
+     */
100
+    public function actionSearch($id=1)
101
+    {
102
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
103
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
104
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Search')
105
+        )));
106
+
107
+        $this->layout = '//layouts/default';
108
+        $data = array();
109
+        $pages = array();
110
+        $itemCount = 0;
111
+        $pageSize = Cii::getConfig('searchPaginationSize', 10);
112
+
113
+        if (Cii::get($_GET, 'q', false))
114
+        {
115
+            $criteria = new CDbCriteria;
116
+            $criteria->addCondition('status = 1')
117
+                        ->addCondition('published <= UTC_TIMESTAMP()');
118
+
119
+            if (strpos($_GET['q'], 'user_id') !== false)
120
+            {
121
+                $criteria->addCondition('author_id = :author_id')
122
+                            ->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id)");
123
+                $criteria->params = array(
124
+                    ':author_id' => str_replace('user_id:', '', Cii::get($_GET, 'q', 0))
125
+                );
126
+            }
127
+            else
128
+            {
129
+                $param = Cii::get($_GET, 'q', 0);
130
+                $criteria->addCondition("vid=(SELECT MAX(vid) FROM content AS v WHERE v.id=t.id) AND ((t.content LIKE :param) OR (t.title LIKE :param2))");
131
+                $criteria->params = array(
132
+                    ':param' 	=> '%' . $param . '%',
133
+                    ':param2'	=> '%' . $param . '%'
134
+                );
135
+            }
136
+
137
+            $criteria->addCondition('password = ""');
138
+            $criteria->limit = $pageSize;
139
+            $criteria->order = 'id DESC';
140
+            $itemCount = Content::model()->count($criteria);
141
+            $pages = new CPagination($itemCount);
142
+            $pages->pageSize=$pageSize;
143
+
144
+            $criteria->offset = $criteria->limit*($pages->getCurrentPage());
145
+            $data = Content::model()->findAll($criteria);
146
+            $pages->applyLimit($criteria);
147
+        }
148
+
149
+        $this->render('search', array(
150
+            'url' 		=> 'search',
151
+            'id' 		=> $id,
152
+            'data' 		=> $data,
153
+            'itemCount' => $itemCount,
154
+            'pages' 	=> $pages
155
+        ));
156
+    }
157
+
158
+    /**
159
+     * Provides functionality to log a user into the system
160
+     */
161
+    public function actionLogin()
162
+    {
163
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
164
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
165
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Login to your account')
166
+        )));
167
+
168
+        $this->layout = '//layouts/main';
169
+        $model = new LoginForm;
170
+
171
+        if (Cii::get($_POST, 'LoginForm', false))
172
+        {
173
+            $model->attributes = Cii::get($_POST, 'LoginForm', array());
174
+            if ($model->login())
175
+                $this->redirect($this->_getNext() ?: Yii::app()->user->returnUrl);
176
+        }
177
+
178
+        $this->render('login', array(
179
+            'model' => $model
180
+        ));
181
+    }
182
+
183
+    /**
184
+     * Provides functionality to log a user out
185
+     */
186
+    public function actionLogout()
187
+    {
188
+        if (Yii::app()->request->getParam('next', false))
189
+            $redirect = $this->createUrl('site/login', array('next' => $this->_getNext()));
190
+        else
191
+            $redirect = Yii::app()->user->returnUrl;
192
+
193
+        // Purge the active sessions API Key
194
+        $apiKey = UserMetadata::model()->findByAttributes(array('user_id' => Yii::app()->user->id, 'key' => 'api_key'));
195
+
196
+        if ($apiKey != NULL)
197
+            $apiKey->delete();
198
+
199
+
200
+        Yii::app()->user->logout();
201
+        $this->redirect($redirect);
202
+    }
203
+
204
+    /**
205
+     * Handles resetting a users password should they forgot it
206
+     */
207
+    public function actionForgot()
208
+    {
209
+        $this->layout = '//layouts/main';
210
+
211
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
212
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
213
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Forgot Your Password?')
214
+        )));
215
+
216
+        $model = new ForgotForm;
217
+
218
+        if (Cii::get($_POST, 'ForgotForm', false))
219
+        {
220
+            $model->attributes = $_POST['ForgotForm'];
221
+
222
+            if ($model->initPasswordResetProcess())
223
+            {
224
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'A password reset link has been sent to your email address'));
225
+                $this->redirect($this->createUrl('site/login'));
226
+            }
227
+        }
228
+
229
+        $this->render('forgot', array(
230
+            'model' => $model
231
+        ));
232
+    }
233
+
234
+    /**
235
+     * Alows a user to reset their password if they initiated a forgot password request
236
+     * @param string $id
237
+     */
238
+    public function actionResetPassword($id=NULL)
239
+    {
240
+        $this->layout = '//layouts/main';
241
+
242
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
243
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
244
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Reset Your password')
245
+        )));
246
+
247
+        $model = new PasswordResetForm;
248
+        $model->reset_key = $id;
249
+
250
+        if (!$model->validateResetKey())
251
+            throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The password reset key provided is invalid'));
252
+
253
+        if (Cii::get($_POST, 'PasswordResetForm', false))
254
+        {
255
+            $model->attributes = $_POST['PasswordResetForm'];
256
+
257
+            if ($model->save())
258
+            {
259
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your password has been reset, and you may now login with your new password'));
260
+                $this->redirect($this->createUrl('site/login'));
261
+            }
262
+        }
263
+
264
+        $this->render('resetpassword', array(
265
+            'model' => $model
266
+        ));
267
+    }
268
+
269
+    /**
270
+     * Allows the user to securely change their email address
271
+     * @param  string $key the user's secure key
272
+     */
273
+    public function actionEmailChange($key=null)
274
+    {
275
+        $this->layout = '//layouts/main';
276
+
277
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
278
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
279
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Change Your Email Address')
280
+        )));
281
+
282
+        $model = new EmailChangeForm;
283
+        $model->setUser(Users::model()->findByPk(Yii::app()->user->id));
284
+        $model->verificationKey = $key;
285
+
286
+        if (!$model->validateVerificationKey())
287
+            throw new CHttpException(403, Yii::t('ciims.controllers.Site', 'The verification key provided is invalid.'));
288
+
289
+        if (Cii::get($_POST, 'EmailChangeForm', false))
290
+        {
291
+            $model->attributes = $_POST['EmailChangeForm'];
292
+
293
+            if ($model->save())
294
+            {
295
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your new email address has been verified.'));
296
+
297
+                $loginForm = new LoginForm;
298
+                $loginForm->attributes = array(
299
+                    'username' => Users::model()->findByPk(Yii::app()->user->id)->email,
300
+                    'password' => $model->password,
301
+                );
302
+
303
+                if ($loginForm->login())
304
+                    return $this->redirect(Yii::app()->homeUrl);
305
+
306
+                throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'Unable to re-authenticated user.'));
307
+            }
308
+        }
309
+
310
+        $this->render('emailchange', array(
311
+            'model' => $model
312
+        ));
313
+    }
314
+
315
+    /**
316
+     * Activates a new user's account
317
+     * @param mixed $id 			The activation key
318
+     */
319
+    public function actionActivation($id=NULL)
320
+    {
321
+        $this->layout = '//layouts/main';
322
+
323
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
324
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
325
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Activate Your Account')
326
+        )));
327
+
328
+        $model = new ActivationForm;
329
+        $model->activationKey = $id;
330
+
331
+        if (!$model->validateKey())
332
+            throw new CHttpException(403, Yii::t('ciims.models.ActivationForm', 'The activation key you provided is invalid.'));
333
+
334
+        if (Cii::get($_POST, 'ActivationForm', false))
335
+        {
336
+            $model->attributes = $_POST['ActivationForm'];
337
+
338
+            if ($model->save())
339
+            {
340
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'Your account has successfully been activated. You may now login'));
341
+                $this->redirect($this->createUrl('site/login'));
342
+            }
343
+        }
344
+
345
+        $this->render('activation', array(
346
+            'model' => $model
347
+        ));
348
+    }
349
+
350
+    /**
351
+     * Handles the registration of new users on the site
352
+     */
353
+    public function actionRegister()
354
+    {
355
+        $this->layout = '//layouts/main';
356
+
357
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
358
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
359
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Sign Up')
360
+        )));
361
+
362
+        $model = new RegisterForm;
363
+
364
+        if (Cii::get($_POST, 'RegisterForm', false))
365
+        {
366
+            $model->attributes = $_POST['RegisterForm'];
367
+
368
+            // Save the user's information
369
+            if ($model->save())
370
+            {
371
+                // Set a flash message
372
+                Yii::app()->user->setFlash('success', Yii::t('ciims.controllers.Site', 'You have successfully registered an account. Before you can login, please check your email for activation instructions'));
373
+                $this->redirect($this->createUrl('site/login'));
374
+            }
375
+        }
376
+
377
+        $this->render('register', array(
378
+            'model'=>$model
379
+        ));
380
+    }
381
+
382
+    /**
383
+     * Enables users who have recieved an invitation to setup a new account
384
+     * @param string $id	The activation id the of the user that we want to activate
385
+     */
386
+    public function actionAcceptInvite($id=NULL)
387
+    {
388
+        $this->layout = '//layouts/main';
389
+
390
+        $this->setPageTitle(Yii::t('ciims.controllers.Site', '{{app_name}} | {{label}}', array(
391
+            '{{app_name}}' => Cii::getConfig('name', Yii::app()->name),
392
+            '{{label}}'    => Yii::t('ciims.controllers.Site', 'Accept Invitation')
393
+        )));
394
+
395
+        if ($id === NULL)
396
+            throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.'));
397
+
398
+        // Make sure we have a user first
399
+        $meta = UserMetadata::model()->findByAttributes(array('key' => 'invitationKey', 'value' => $id));
400
+        if ($meta === NULL)
401
+            throw new CHttpException(400, Yii::t('ciims.controllers.Site', 'There was an error fulfilling your request.'));
402
+
403
+        $model = new InviteForm;
404
+        $model->email = Users::model()->findByPk($meta->user_id)->email;
405
+
406
+        if (Cii::get($_POST, 'InviteForm', NULL) !== NULL)
407
+        {
408
+            $model->attributes = Cii::get($_POST, 'InviteForm', NULL);
409
+            $model->id = $meta->user_id;
410
+
411
+            if ($model->acceptInvite())
412
+            {
413
+                $meta->delete();
414
+                return $this->render('invitesuccess');
415
+            }
416
+        }
417
+
418
+        $this->render('acceptinvite', array(
419
+            'model' => $model
420
+        ));
421
+    }
422 422
 	
423
-	/**
424
-	 * Returns a sanitized $_GET['next'] URL if it is set.
425
-	 * @return mixed
426
-	 */
427
-	private function _getNext()
428
-	{
429
-		return str_replace('ftp://', '', str_replace('http://', '', str_replace('https://', '', Yii::app()->request->getParam('next', false))));
430
-	}
423
+    /**
424
+     * Returns a sanitized $_GET['next'] URL if it is set.
425
+     * @return mixed
426
+     */
427
+    private function _getNext()
428
+    {
429
+        return str_replace('ftp://', '', str_replace('http://', '', str_replace('https://', '', Yii::app()->request->getParam('next', false))));
430
+    }
431 431
 }
Please login to merge, or discard this patch.