public
Description: Git mirror of the CMS Made Simple 2.0 rewrite
Homepage: http://cmsmadesimple.org
Clone URL: git://github.com/tedkulp/cmsmadesimple-2-0.git
cmsmadesimple-2-0 / lib / classes / class.cms_admin_tree.php
100644 159 lines (138 sloc) 3.696 kb
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?php // -*- mode:php; tab-width:4; indent-tabs-mode:t; c-basic-offset:4; -*-
#CMS - CMS Made Simple
#(c)2004-2008 by Ted Kulp (ted@cmsmadesimple.org)
#This project's homepage is: http://cmsmadesimple.org
#
#This program is free software; you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation; either version 2 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
#GNU General Public License for more details.
#You should have received a copy of the GNU General Public License
#along with this program; if not, write to the Free Software
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#$Id$
 
/**
* Classes for storing the admin menu. Includes methods to load
* the structure from an xml file and properly create the admin
* menu structure.
*
* @author Ted Kulp
* @since 2.0
* @version $Revision$
* @modifiedby $LastChangedBy$
* @lastmodified $Date$
* @license GPL
**/
class CmsAdminTree extends CmsTree
{
  static private $instance = NULL;
 
  function __construct()
  {
    parent::__construct();
    $this->root = new CmsAdminNode();
    $this->root->tree = $this;
  }
  
  static public function get_instance()
  {
    if (self::$instance == NULL)
    {
      self::$instance = new CmsAdminTree();
    }
    return self::$instance;
  }
  
  function create_node()
  {
    $node = new CmsAdminNode();
    $node->tree = $this;
    return $node;
  }
  
  static public function find_node_by_title($title)
  {
    $flatlist = self::get_instance()->get_flat_list();
    foreach ($flatlist as &$onenode)
    {
      if ($title == $onenode->title)
      {
        return $onenode;
      }
    }
    return null;
  }
  
    static public function fill_from_file(&$admin_theme)
    {
    $xml = simplexml_load_file(cms_join_path(ROOT_DIR,'admin','adminmenu.xml'));
    
    $root = self::get_instance()->get_root_node();
    
    foreach ($xml as $node)
    {
      self::create_admin_node($node, $root, $admin_theme);
    }
    
    //print_r($root->tree);
    }
 
  static public function create_admin_node(&$xml, &$node, &$admin_theme)
  {
    $newnode = new CmsAdminNode();
    $newnode->tree = $node->tree;
    
    if (isset($xml->name))
      $newnode->name = (string)$xml->name;
 
    if (isset($xml->title))
    {
      $newnode->title = lang((string)$xml->title);
      $newnode->english_title = (string)$xml->title;
    }
 
    if (isset($xml->url))
      $newnode->url = (string)$xml->url;
      
    if (isset($xml->target))
      $newnode->target = (string)$xml->target;
 
    if (isset($xml->description))
    {
      if ((string)$xml->description != '')
        $newnode->description = lang((string)$xml->description);
    }
 
    if (isset($xml->show_in_menu))
    {
      if (isset($xml->show_in_menu->permission))
      {
        $newnode->show_in_menu = $admin_theme->has_permission((string)$xml->show_in_menu->permission);
      }
      else
      {
        $newnode->show_in_menu = ((string)$xml->show_in_menu == 'true' ? true : false);
      }
    }
    
    $node->add_child($newnode);
    
    if (isset($xml->children))
    {
      foreach ($xml->children->node as $child)
      {
        self::create_admin_node($child, $newnode, $admin_theme);
      }
    }
  }
}
 
class CmsAdminNode extends CmsNode
{
  var $name = '';
  var $title = '';
  var $english_title = '';
  var $url = '';
  var $description = '';
  var $target = '';
  var $icon_url = '';
  var $show_in_menu = true;
  var $first_module = false;
  var $selected = false;
  var $external = false;
  var $module = false;
 
  function __construct()
  {
    parent::__construct();
  }
}
 
# vim:ts=4 sw=4 noet
?>