1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ajax\lib; |
4
|
|
|
|
5
|
|
|
use Ajax\service\PhalconUtils; |
6
|
|
|
|
7
|
|
|
class CDNGuiGen extends CDNBase { |
8
|
|
|
protected $theme; |
9
|
|
|
protected $cssUrl; |
10
|
|
|
protected $localCss; |
11
|
|
|
|
12
|
|
|
public function __construct($version, $theme=NULL, $provider="Google") { |
13
|
|
|
parent::__construct($version, $provider); |
14
|
|
|
$this->data=$this->data ["JQueryUI"]; |
15
|
|
|
if (is_int($theme)) { |
16
|
|
|
$themes=$this->getThemes(); |
17
|
|
|
if (sizeof($themes)>$theme-1) |
18
|
|
|
$this->theme=$themes [$theme-1]; |
19
|
|
|
else |
20
|
|
|
throw new \Exception("CDNGuiGen : Le numéro de thème demandé n'existe pas"); |
21
|
|
|
} |
22
|
|
|
$this->theme=$theme; |
23
|
|
|
$this->cssUrl=null; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
public function getCssUrl() { |
27
|
|
|
return $this->cssUrl; |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function getThemes($provider=NULL) { |
31
|
|
|
if (isset($provider)) |
32
|
|
|
return $this->data [$provider] ["themes"]; |
33
|
|
|
else |
34
|
|
|
return $this->data [$this->provider] ["themes"]; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function getFirstTheme($provider=NULL) { |
38
|
|
|
$themes=$this->getThemes($provider); |
39
|
|
|
if (sizeof($themes)>0) |
40
|
|
|
return $themes [0]; |
41
|
|
|
return ""; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getUrl() { |
45
|
|
|
return $this->getUrlOrCss($this->jsUrl, "core"); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function getCss() { |
49
|
|
|
if (isset($this->cssUrl)) |
50
|
|
|
return $this->cssUrl; |
51
|
|
|
$version=$this->version; |
52
|
|
|
if (array_search($version, $this->getVersions())===false) |
53
|
|
|
$version=$this->getLastVersion(); |
54
|
|
|
$theme=$this->theme; |
55
|
|
|
if (array_search($theme, $this->getThemes())===false) |
56
|
|
|
$theme=$this->getFirstTheme(); |
57
|
|
|
return $this->replaceVersionAndTheme($this->data [$this->provider] ["css"], $version, $theme); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function __toString() { |
61
|
|
|
$url=$this->getUrl(); |
62
|
|
|
$css=$this->getCss(); |
63
|
|
|
return PhalconUtils::javascriptInclude($url, $this->local)."\n".PhalconUtils::stylesheetLink($css, $this->localCss); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
View Code Duplication |
public function setCssUrl($cssUrl, $local=null) { |
|
|
|
|
67
|
|
|
$this->cssUrl=$cssUrl; |
68
|
|
|
if (isset($local)===false) { |
69
|
|
|
$local=PhalconUtils::startsWith($cssUrl, "http")===false; |
70
|
|
|
} |
71
|
|
|
$this->setLocalCss($local); |
72
|
|
|
return $this; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getLocalCss() { |
76
|
|
|
return $this->localCss; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
public function setLocalCss($localCss) { |
80
|
|
|
$this->localCss=$localCss; |
81
|
|
|
return $this; |
82
|
|
|
} |
83
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.