1 <?php
2 3 4 5 6 7 8 9
10
11 12 13 14 15 16 17
18 class P3MediaModule extends CWebModule
19 {
20 public $dataAlias = "application.data.p3media";
21 public $importAlias = "application.data.p3media-import";
22
23 public function init()
24 {
25
26
27
28
29 $this->setImport(array(
30 'p3media.models.*',
31 'p3media.components.*',
32 'ext.phundament.p3extensions.helpers.*',
33 ));
34
35 if (!is_writable(Yii::getPathOfAlias($this->dataAlias))) {
36 throw new CHttpException(500, "Directory with alias '{$this->dataAlias}' not writable.");
37 }
38 }
39
40 public function beforeControllerAction($controller, $action)
41 {
42 if(parent::beforeControllerAction($controller, $action))
43 {
44
45
46 return true;
47 }
48 else
49 return false;
50 }
51
52 public function getDataPath($relative = false){
53
54 $relativeDataPath = Yii::app()->user->id;
55 $fullDataPath = Yii::getPathOfAlias($this->dataAlias) . DIRECTORY_SEPARATOR . $relativeDataPath;
56
57 if (!is_dir($fullDataPath)) {
58 mkdir($fullDataPath);
59 chmod($fullDataPath, 0777);
60 }
61
62 if ($relative === false)
63 return $fullDataPath;
64 else
65 return $relativeDataPath;
66 }
67
68 69 70 71
72
73 public function resolveFilePath($fileName) {
74 $filePath = realpath(Yii::getPathOfAlias($this->importAlias) . DIRECTORY_SEPARATOR . $fileName);
75 if (is_file($filePath) && strstr($filePath, realpath(Yii::getPathOfAlias($this->importAlias)))) {
76 return $filePath;
77 } else {
78 return false;
79 }
80 }
81
82
83 }
84
85 ?>