phpMv  -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
CDNBase.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Ajax\lib;
4 
5 
7 
8 abstract class CDNBase {
9  protected $version;
10  protected $provider;
11  protected $data;
12  protected $local;
13  protected $jsUrl;
14 
15  public function __construct($version, $provider) {
16  $this->data=include 'CDN.php';
17  $this->version=$version;
18  $this->provider=$provider;
19  $this->local=false;
20  $this->jsUrl=null;
21  }
22 
23  public function getJsUrl() {
24  return $this->jsUrl;
25  }
26 
27  public function setJsUrl($jsUrl, $local=null) {
28  $this->jsUrl=$jsUrl;
29  if (isset($local)===false) {
30  $local=JString::startsWith($jsUrl, "http")===false;
31  }
32  $this->setLocal($local);
33  return $this;
34  }
35 
36  protected function getUrlOrCss($element, $key) {
37  if (isset($element))
38  return $element;
40  if (array_search($version, $this->getVersions())===false)
41  $version=$this->getLastVersion();
42  return $this->replaceVersion($this->data [$this->provider] [$key], $version);
43  }
44 
45  public function isLocal() {
46  return $this->local;
47  }
48 
49  public function setLocal($local) {
50  $this->local=$local;
51  return $this;
52  }
53 
54  protected function replaceVersion($url, $version) {
55  return str_ireplace("%version%", $version, $url);
56  }
57 
58  protected function replaceTheme($url, $theme) {
59  return str_ireplace("%theme%", $theme, $url);
60  }
61 
62  protected function replaceVersionAndTheme($url, $version, $theme) {
63  if (isset($theme))
64  return str_ireplace(array (
65  "%theme%",
66  "%version%"
67  ), array (
68  $theme,
69  $version
70  ), $url);
71  else
72  return $this->replaceVersion($url, $version);
73  }
74 
75  public function getProviders() {
76  return array_keys($this->data);
77  }
78 
79  public function getVersions($provider=NULL) {
80  if (isset($provider))
81  return $this->data [$provider] ["versions"];
82  else
83  return $this->data [$this->provider] ["versions"];
84  }
85 
86  public function getLastVersion($provider=NULL) {
87  return $this->getVersions($provider)[0];
88  }
89 
90  abstract public function getUrl();
91 }
getUrlOrCss($element, $key)
Definition: CDNBase.php:36
getLastVersion($provider=NULL)
Definition: CDNBase.php:86
setLocal($local)
Definition: CDNBase.php:49
replaceTheme($url, $theme)
Definition: CDNBase.php:58
replaceVersion($url, $version)
Definition: CDNBase.php:54
__construct($version, $provider)
Definition: CDNBase.php:15
getVersions($provider=NULL)
Definition: CDNBase.php:79
replaceVersionAndTheme($url, $version, $theme)
Definition: CDNBase.php:62
setJsUrl($jsUrl, $local=null)
Definition: CDNBase.php:27