ossn.lib.menus.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Open Source Social Network
4  *
5  * @package (Informatikon.com).ossn
6  * @author OSSN Core Team <[email protected]>
7  * @copyright 2014 iNFORMATIKON TECHNOLOGIES
8  * @license General Public Licence http://www.opensource-socialnetwork.org/licence
9  * @link http://www.opensource-socialnetwork.org/licence
10  */
11 /**
12  * Register a menu;
13  * @params string $name Name of menu;
14  * @params string $text Text for menu;
15  * @params string $link Link for menu;
16  *
17  * @return void
18  */
19 function ossn_register_menu_link($name, $text, $link, $menutype = 'site') {
20  ossn_register_menu_item($menutype, array(
21  'name' => $name,
22  'text' => $text,
23  'href' => $link
24  ));
25 }
26 /**
27  * Register a menu item
28  *
29  * @params string $name menu name;
30  * @params array $options A link options;
31  * @params string $menutype A menu name
32  *
33  * @return void
34  */
35 function ossn_register_menu_item($menutype, array $options = array()) {
36  global $Ossn;
37  if(!empty($options['name'])) {
38  $name = $options['name'];
39  if(isset($options['parent']) && !empty($options['parent'])) {
40  $name = $options['parent'];
41  }
42  $Ossn->menu[$menutype][$name][] = $options;
43  }
44 }
45 
46 /**
47  * Unregister menu from system;
48  * @params string $menu Menu name
49  * @params string $menutype MenuType
50  *
51  * @return void;
52  *
53  */
54 function ossn_unregister_menu($menu, $menutype = 'site') {
55  global $Ossn;
56  unset($Ossn->menu[$menutype][$menu]);
57 }
58 
59 /**
60  * View a menu;
61  * @params string $menu Menu name
62  * @note This will fetch layout from defualt template that how menu should appear; check menu file for more info;
63  *
64  * @return string
65  */
66 function ossn_view_menu($menu, $custom = false) {
67  global $Ossn;
68  if(!isset($Ossn->menu[$menu])) {
69  return false;
70  }
71  $params['menu'] = $Ossn->menu[$menu];
72  if($custom == false) {
73  $params['menuname'] = $menu;
74  return ossn_plugin_view("menus/{$menu}", $params);
75  } elseif($custom !== false) {
76  $params['menuname'] = $menu;
77  return ossn_plugin_view($custom, $params);
78  }
79 }
80 
81 /**
82  * Register a section base menu;
83  * @params array $params array(type, section, url, text, icon, link)
84  * @param string $menu
85  *
86  * @return false|null
87  */
88 function ossn_register_sections_menu($menu, $params) {
89  global $Ossn;
90  if(!isset($params['type'])) {
91  $params['type'] = '';
92  }
93  if(!isset($params['url']) || !isset($params['text']) || !isset($params['type']) || !isset($params['icon'])) {
94  return false;
95  }
96  if(empty($params['params'])) {
97  $params['params'] = array();
98  }
99  $type = $params['type'];
100  $link = $params['url'];
101  $text = $params['text'];
102  $type = $params['type'];
103  $icon = $params['icon'];
104  $section = $params['section'];
105  if(empty($type)) {
106  $type = 'frontend';
107  }
108  $Ossn->sectionsmenu[$type][$menu][$section][$text] = array(
109  $link,
110  $icon,
111  $params['params']
112  );
113 }
114 
115 /**
116  * View section base menu;
117  * @param string $type (frontend or backend(
118  * @param string $menu
119  * @note This will fetch layout from defualt template that how menu should appear; check menu file for more info;
120  *
121  * @return mixed data
122  *
123  */
124 function ossn_view_sections_menu($menu, $type = 'frontend') {
125  global $Ossn;
126  if(isset($menu) && isset($Ossn->sectionsmenu[$type][$menu])) {
127  $params['menu'] = $Ossn->sectionsmenu[$type][$menu];
128  $params['menuname'] = $menu;
129  return ossn_plugin_view("menus/sections/{$menu}", $params);
130  }
131 }