forked from koala-framework/koala-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Component.php
92 lines (84 loc) · 3.13 KB
/
Component.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
81
82
83
84
85
86
87
88
89
90
91
92
<?php
class Kwc_Advanced_SocialBookmarks_Component extends Kwc_Abstract
{
public static function getSettings()
{
$ret = parent::getSettings();
$ret['componentName'] = trlKwfStatic('Social Bookmarks');
$ret['ownModel'] = 'Kwc_Advanced_SocialBookmarks_Model';
$ret['rootElementClass'] = 'kwfUp-webStandard';
$ret['iconSet'] = 'Flat';
$ret['flags']['hasAlternativeComponent'] = true;
$ret['extConfig'] = 'Kwc_Abstract_Composite_ExtConfigForm';
return $ret;
}
private function _getNetworks($currentPage)
{
$networks = array();
foreach (Kwf_Model_Abstract::getInstance('Kwc_Advanced_SocialBookmarks_AvaliableModel')->getRows() as $n) {
$networks[$n->id] = $n->toArray();
}
$s = new Kwf_Model_Select();
$s->order('pos');
$ret = array();
foreach ($this->getRow()->getChildRows('Networks', $s) as $net) {
if (isset($networks[$net->network_id])) {
$icon = '/Kwc/Advanced/SocialBookmarks/Icons/'.$this->_getSetting('iconSet').'/';
if (file_exists(KWF_PATH.$icon.$net->network_id.'.jpg')) {
$icon .= $net->network_id.'.jpg';
} else if (file_exists(KWF_PATH.$icon.$net->network_id.'.png')) {
$icon .= $net->network_id.'.png';
} else {
$icon = false;
}
if ($icon) $icon = '/assets/kwf'.$icon;
$url = str_replace('{0}', $currentPage->getAbsoluteUrl(), $networks[$net->network_id]['url']);
$ret[] = array(
'id' => $net->network_id,
'name' => $networks[$net->network_id]['name'],
'url' => $url,
'icon' => $icon
);
}
}
return $ret;
}
public function hasContent()
{
return count($this->_getNetworks($this->getData())) > 0;
}
public function getTemplateVarsWithNetworks($currentPage)
{
$ret = parent::getTemplateVars();
$ret['networks'] = $this->_getNetworks($currentPage);
$ret['iconSet'] = $this->_getSetting('iconSet');
return $ret;
}
public function getTemplateVars()
{
return $this->getTemplateVarsWithNetworks($this->getData()->parent);
}
public static function getAlternativeComponents()
{
return array(
'inherit'=>'Kwc_Advanced_SocialBookmarks_Inherit_Component'
);
}
public static function useAlternativeComponent($componentClass, $parentData, $generator)
{
$c = $parentData;
while (!$c->inherits) $c = $c->parent;
$c = $c->parent;
if (!$c) return false;
while (!$c->inherits) $c = $c->parent;
$instances = Kwf_Component_Generator_Abstract::getInstances($c, array(
'inherit' => true
));
if (in_array($generator, $instances, true)) {
//wir wurden geerbt weils über uns ein parentData mit dem gleichen generator gibt
return 'inherit';
} else {
return false;
}
}
}