Co2Module.php 5.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
<?php
/**
 * Communect Module
 *
 * @author Tibor Katelbach <oceatoon@mail.com>
 * @version 0.0.3
 *
*/

class Co2Module extends CWebModule {

Tibor Katelbach's avatar
Tibor Katelbach committed
12
13
	private $_assetsUrl;

Raph El's avatar
Modif    
Raph El committed
14
	private $_version = "v0.3.0";
Tibor Katelbach's avatar
Tibor Katelbach committed
15
16
17
18
	private $_versionDate = "10/12/2018";
	private $_keywords = "societal, reseau,opensource,CO,communecter";
	private $_description = "réseau social libre et citoyen";
	private $_pageTitle = "Communecter:libre et connecté";
Clément Damiens's avatar
   
Clément Damiens committed
19
	private $_image = "/images/1+1=3.jpg";
Clément Damiens's avatar
   
Clément Damiens committed
20
	private $_relCanonical = "https://www.communecter.org";
Clément Damiens's avatar
   
Clément Damiens committed
21
	private $_favicon = "/images/favicon";
Tibor Katelbach's avatar
tweaks    
Tibor Katelbach committed
22
	private $_author = "Pixel Humain";
Clément Damiens's avatar
   
Clément Damiens committed
23
	private $_share = null;
Tibor Katelbach's avatar
Tibor Katelbach committed
24
25
26
27
28
29

	public function getVersion(){return $this->_version;}
	public function getVersionDate(){return $this->_versionDate;}
	public function getKeywords(){return $this->_keywords;}
	public function getDescription(){return $this->_description;}
	public function getPageTitle(){return $this->_pageTitle;}
Clément Damiens's avatar
   
Clément Damiens committed
30
31
	public function getImage(){return $this->_image;}
	public function getFavicon(){return $this->_favicon;}
Clément Damiens's avatar
   
Clément Damiens committed
32
	public function getRelCanonical(){return $this->_relCanonical;}
Tibor Katelbach's avatar
tweaks    
Tibor Katelbach committed
33
	public function getAuthor(){return $this->_author;}
Clément Damiens's avatar
   
Clément Damiens committed
34
	public function getShare(){return $this->_share;}
Tibor Katelbach's avatar
Tibor Katelbach committed
35

Clément Damiens's avatar
   
Clément Damiens committed
36
37
38
39
40
41
42
	public function setPageTitle($title){ $this->_pageTitle = $title; }
	public function setAuthor($author){ $this->_author = $author; }
	public function setDescription($desc){ $this->_description = $desc; }
	public function setImage($image){ $this->_image = $image; }
	public function setKeywords($keywords){ $this->_keywords = $keywords; }
	public function setFavicon($favicon){ $this->_favicon = $favicon; }
	public function setRelCanonical($relCanonical){ $this->_relCanonical = $relCanonical; }
Clément Damiens's avatar
   
Clément Damiens committed
43
	public function setShare($share){ $this->_share = $share; }
Clément Damiens's avatar
   
Clément Damiens committed
44

45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
	public function init()
	{
		// this method is called when the module is being created
		// you may place code here to customize the module or the application

		Yii::app()->setComponents(array(
		    'errorHandler'=>array(
		        'errorAction'=>'/'.$this->id.'/error'
		    )
		));
		
		Yii::app()->homeUrl = Yii::app()->createUrl($this->id);
		
		//Apply theme
		$themeName = $this->getTheme();
		Yii::app()->theme = $themeName;
		
		//Retrieve network params in the url
		if(@$_GET["network"]) {
            Yii::app()->params['networkParams'] = $_GET["network"];
        }
Clément Damiens's avatar
Clément Damiens committed
66
       if(@Yii::app()->request->cookies['lang'] && !empty(Yii::app()->request->cookies['lang']->value))
Clément Damiens's avatar
   
Clément Damiens committed
67
        	Yii::app()->language = (string)Yii::app()->request->cookies['lang'];
Clément Damiens's avatar
Clément Damiens committed
68
        else 
Clément Damiens's avatar
   
Clément Damiens committed
69
			Yii::app()->language = (isset(Yii::app()->session["lang"])) ? Yii::app()->session["lang"] : 'fr';
70
		
Tibor Katelbach's avatar
Tibor Katelbach committed
71
72
73
74
75
76
77
78
79
		Yii::app()->params["module"] = array(
			"name" => self::getPageTitle(),
			"parent" => "co2",
			"overwrite" => array(
				"views" => array(),
				"assets" => array(),
				"controllers" => array(),
			));

80
81
82
		// import the module-level models and components
		$this->setImport(array(
			'citizenToolKit.models.*',
Clément Damiens's avatar
   
Clément Damiens committed
83
			'eco.models.*',
Raph El's avatar
Hotfix    
Raph El committed
84
			'costum.models.*',
Tibor Katelbach's avatar
Tibor Katelbach committed
85
			'places.models.*',
Tibor Katelbach's avatar
Tibor Katelbach committed
86
			'chat.models.*',
Raph El's avatar
Raph El committed
87
			'interop.models.*',
Raph El's avatar
Raph El committed
88
			'map.models.*',
Raph El's avatar
Raph El committed
89
			'news.models.*',
Raph El's avatar
Raph El committed
90
			'survey.models.*',
Tibor Katelbach's avatar
Tibor Katelbach committed
91
			'dda.models.*',
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
			$this->id.'.models.*',
			$this->id.'.components.*',
			$this->id.'.messages.*',
		));
		/*$this->components =  array(
            'class'=>'CPhpMessageSource',
            'basePath'=>'/messages'
        );*/
	}

	public function beforeControllerAction($controller, $action)
	{
		if (parent::beforeControllerAction($controller, $action))
		{
			// this method is called before any module controller action is performed
			// you may place customized code here
			return true;
		}
		else
			return false;
	}

Clément Damiens's avatar
   
Clément Damiens committed
114
	public function getAssetsUrl($noBase=null)
115
	{
Clément Damiens's avatar
   
Clément Damiens committed
116
		$baseAssets= ($noBase) ? "assets" : $this->id.'.assets';
117
118
		if ($this->_assetsUrl === null)
	        $this->_assetsUrl = Yii::app()->getAssetManager()->publish(
Clément Damiens's avatar
   
Clément Damiens committed
119
	            Yii::getPathOfAlias($baseAssets) );
120
121
122
	    return $this->_assetsUrl;
	}

Tibor Katelbach's avatar
Tibor Katelbach committed
123
124
125
126
127
	public function getParentAssetsUrl()
	{
		return ( @Yii::app()->params["module"]["parent"] ) ?  Yii::app()->getModule( Yii::app()->params["module"]["parent"] )->getAssetsUrl()  : self::getAssetsUrl();
	}

128
129
130
131
132
133
134
135
136
137
	/**
	 * Retourne le theme d'affichage de communecter.
	 * Si option "theme" dans paramsConfig.php : 
	 * Si aucune option n'est précisée, le thème par défaut est "ph-dori"
	 * Si option 'tpl' fixée dans l'URL avec la valeur "iframesig" => le theme devient iframesig
	 * Si option "network" fixée dans l'URL : theme est à network et la valeur du parametres fixe les filtres d'affichage
	 * @return type
	 */
	public function getTheme() {
		//$theme = "CO2";
138
		$theme = (@Yii::app()->session["theme"]) ? Yii::app()->session["theme"] : "CO2";
139
140
141
142
		//$theme = "notragora";
		if (!empty(Yii::app()->params['theme'])) {
			$theme = Yii::app()->params['theme'];
		} else if (empty(Yii::app()->theme)) {
143
			$theme = (@Yii::app()->session["theme"]) ? Yii::app()->session["theme"] : "CO2";
144
145
146
147
148
149
150
151
152
153
154
155
156
157
			//$theme = "CO2";
			//$theme = "notragora";
		}

		if(@$_GET["tpl"] == "iframesig"){ $theme = $_GET["tpl"]; }

		if(@$_GET["network"]) {
            $theme = "network";
            //Yii::app()->params['networkParams'] = $_GET["network"];
        }
        Yii::app()->session["theme"] = $theme;
		return $theme;
	}
}