/
Flag.php
80 lines (70 loc) · 2.75 KB
/
Flag.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
namespace Concrete\Core\Multilingual\Service\UserInterface;
use Concrete\Core\Entity\Site\Locale;
use Concrete\Core\Localization\Locale\LocaleInterface;
use Concrete\Core\Multilingual\Page\Section\Section;
use Database;
use HtmlObject\Image;
defined('C5_EXECUTE') or die("Access Denied.");
class Flag
{
/**
* Returns a flag for a passed country/region.
*/
public static function getFlagIcon($region, $filePathOnly = false)
{
$val = \Core::make('helper/validation/strings');
if ($val->alphanum($region, false, true)) {
$region = h(strtolower($region));
} else {
$region = false;
}
if ($region) {
$v = \View::getInstance();
if ($v->getThemeDirectory() != '' && file_exists(
$v->getThemeDirectory() . '/' . DIRNAME_IMAGES . '/' . DIRNAME_IMAGES_LANGUAGES . '/' . $region . '.png'
)) {
$icon = $v->getThemePath() . '/' . DIRNAME_IMAGES . '/' . DIRNAME_IMAGES_LANGUAGES . '/' . $region . '.png';
} elseif (file_exists(
DIR_APPLICATION . '/' . DIRNAME_IMAGES . '/' . DIRNAME_IMAGES_LANGUAGES . '/' . $region . '.png'
)) {
$icon = REL_DIR_APPLICATION . '/' . DIRNAME_IMAGES . '/' . DIRNAME_IMAGES_LANGUAGES . '/' . $region . '.png';
} else {
$icon = ASSETS_URL . '/' . DIRNAME_IMAGES . '/' . DIRNAME_IMAGES_LANGUAGES . '/' . $region . '.png';
}
if (isset($icon)) {
if ($filePathOnly) {
return $icon;
} else {
$img = new Image($icon, $region, ['id' => 'ccm-region-flag-' . $region, 'class' => 'ccm-region-flag']);
return $img;
}
}
}
}
public static function getSectionFlagIcon($page, $filePathOnly = false)
{
$db = Database::get();
$section = Section::getBySectionOfSite($page);
$icon = $section->getCountry();
return self::getFlagIcon($icon, $filePathOnly);
}
public static function getLocaleFlagIcon(LocaleInterface $locale, $filePathOnly = false)
{
$icon = $locale->getCountry();
return self::getFlagIcon($icon, $filePathOnly);
}
public static function getDashboardSitemapIconSRC($page)
{
if ($page->getPageTypeHandle() == STACK_CATEGORY_PAGE_TYPE) {
$section = Section::getByLocale($page->getCollectionName());
if (is_object($section)) {
return self::getSectionFlagIcon($section, true);
}
}
$ids = Section::getIDList();
if (in_array($page->getCollectionID(), $ids)) {
return self::getSectionFlagIcon($page, true);
}
}
}