XOOPS  2.6.0
CountryFlagProvider.php
Go to the documentation of this file.
1 <?php
2 /*
3  You may not change or alter any portion of this comment or credits
4  of supporting developers from this source code or any supporting source code
5  which is considered copyrighted (c) material of the original comment or credit authors.
6 
7  This program is distributed in the hope that it will be useful,
8  but WITHOUT ANY WARRANTY; without even the implied warranty of
9  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 */
11 
15 use Xoops\Html\Img;
16 
29 {
31  protected $flagSource = 'media/xoops/images/flags/';
32 
39  public function getName()
40  {
41  return 'system';
42  }
43 
49  public function getDescription()
50  {
51  return 'Built in CountryFlag provider';
52  }
53 
54 
63  private function getFlagUrl($countryCode, $size)
64  {
65  $size = strtolower(substr($size, 0, 1));
66  $sizeDir = '64';
67  switch ($size) {
68  case 's':
69  $sizeDir = '16';
70  break;
71  case 'm':
72  $sizeDir = '32';
73  break;
74  }
75 
77  $flagDir = $this->flagSource . $sizeDir . '/';
78  $flagFile = $flagDir . $countryCode . '.png';
79 
80  $file = $xoops->path($flagFile);
81  // switch to unknown if file is not readable
82  if (!is_readable($file)) {
83  $flagFile = $flagDir . '_unknown.png';
84  }
85  $url = $xoops->url($flagFile);
86  return $url;
87  }
88 
98  public function getImgUrl(Response $response, $countryCode, $size = 'large')
99  {
100  $response->setValue($this->getFlagUrl($countryCode, $size));
101  }
102 
113  public function getImgTag(
115  $countryCode,
116  $attributes = array(),
117  $size = 'large'
118  ) {
119  $url = $this->getFlagUrl($countryCode, $size);
120 
121  $imgTag = new Img(array('src' => $url, 'alt' => $countryCode));
122  $imgTag->setAttributes($attributes);
123  $response->setValue($imgTag->render());
124  }
125 }
getImgTag(Response $response, $countryCode, $attributes=array(), $size= 'large')
static getInstance()
Definition: Xoops.php:160
if(!isset($xoops->paths[$path_type])) if($path_type== 'var') $file
Definition: browse.php:55
$xoops
Definition: admin.php:25
getFlagUrl($countryCode, $size)
getImgUrl(Response $response, $countryCode, $size= 'large')
$url
Definition: register.php:72
if($xoops->isUser()&&$isAdmin) $response
Definition: userinfo.php:83