forked from myWebDev/MenuLinks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.php
111 lines (93 loc) · 3.1 KB
/
plugin.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
// Copyright 2014 borowicz.info'
if(!defined('IN_ESOTALK')) exit;
ET::$pluginInfo['MenuLinks'] = array(
'name' => 'MenuLinks',
'description' => 'Configure a header and/or footer menu',
'version' => '0.3',
'author' => 'Tristan van Bokkem (original code by borowicz.info)',
'authorEmail' => 'tristanvanbokkem@gmail.com',
'authorURL' => 'http://www.esotalk.org',
'license' => 'GPLv2'
);
class ETPlugin_MenuLinks extends ETPlugin {
var $c = array(); //config
var $out = array();
public function handler_init($sender)
{
$this->conf();
if ( !empty($this->c['linksBottomMenu']) ) $this->generateMenu($sender, $this->c['linksBottomMenu'], 'meta');
if ( !empty($this->c['linksTopMenu']) ) $this->generateMenu($sender, $this->c['linksTopMenu'], 'main');
if ( !empty($this->c['headSection']) ) $sender->addToHead($this->c['headSection']);
}
public function generateMenu($sender, $data, $menu)
{
if ( !empty($data) )
{
$items = array();
$items = explode("\n",$data);
if ( count($items) )
{
foreach ($items as $item)
{
$currentItem = '';
if ( stristr($item,';') )
{
$currentItem = explode(';',$item);
$currentItem[0] = trim($currentItem[0]);
$currentItem[1] = trim($currentItem[1]);
if ( isset($currentItem[0]) && isset($currentItem[1]) )
{
if ( !stristr($currentItem[1],'http://') )
{
$currentItem[1] = 'http://'.$currentItem[1];
}
$sender->addToMenu($menu, $currentItem[1], '<a href="'.$currentItem[1].'">'.$currentItem[0].'</a>', 'top');
}
}
}
}
}
}
public function conf()
{
$this->c = array();
$this->c['linksBottomMenu'] = C('plugin.MenuLinks.linksBottomMenu');
$this->c['linksTopMenu'] = C('plugin.MenuLinks.linksTopMenu');
$this->c['beforeBody'] = C('plugin.MenuLinks.beforeBody');
$this->c['headSection'] = C('plugin.MenuLinks.headSection');
}
public function handler_pageEnd($sender)
{
if ( !empty($this->c['beforeBody']) ) echo "\r\n".$this->c['beforeBody'];
}
/**
* Setting form on admin panel
*/
public function settings($sender)
{
$form = ETFactory::make('form');
$form->action = URL('admin/plugins');
$form->setValue('linksBottomMenu', $this->c['linksBottomMenu']);
$form->setValue('linksTopMenu', $this->c['linksTopMenu']);
$form->setValue('beforeBody', $this->c['beforeBody']);
$form->setValue('headSection', $this->c['headSection']);
if ($form->validPostBack("MenuLinksSave"))
{
$config = array();
$config['plugin.MenuLinks.linksBottomMenu'] = $form->getValue('linksBottomMenu');
$config['plugin.MenuLinks.linksTopMenu'] = $form->getValue('linksTopMenu');
$config['plugin.MenuLinks.beforeBody'] = $form->getValue('beforeBody');
$config['plugin.MenuLinks.headSection'] = $form->getValue('headSection');
if (!$form->errorCount()) // if no errors save config.
{
ET::writeConfig($config);
$sender->message(T("message.changesSaved"), "success autoDismiss");
$sender->redirect(URL("admin/plugins"));
}
}
$sender->data("MenuLinks", $form);
return $this->getView("settings");
}
}
?>