| 44 | | function elggadmin_actions() { |
|---|
| 45 | | // do actions |
|---|
| 46 | | $page = elggadmin_currentpage(); |
|---|
| 47 | | |
|---|
| 48 | | if (pages_is_submitted()) { |
|---|
| 49 | | elggadmin_save($page); |
|---|
| 50 | | } |
|---|
| 51 | | } |
|---|
| 52 | | |
|---|
| 53 | | function elggadmin_page($page_name=null) { |
|---|
| 54 | | // this must go somewhere else! |
|---|
| 55 | | global $metatags; |
|---|
| 56 | | $metatags .= "\n<style type=\"text/css\">\n"; |
|---|
| 57 | | $metatags .= file_get_contents('./elggadmin.css'); |
|---|
| 58 | | $metatags .= "</style>"; |
|---|
| 59 | | |
|---|
| 60 | | if ($page_name == 'theme') { |
|---|
| 61 | | $page = elggadmin_page_theme(); |
|---|
| 62 | | elggadmin_currentpage('theme'); |
|---|
| 63 | | } elseif ($page_name == 'frontpage') { |
|---|
| 64 | | $page = elggadmin_page_frontpage(); |
|---|
| 65 | | elggadmin_currentpage('frontpage'); |
|---|
| 66 | | } else { |
|---|
| 67 | | $page = elggadmin_page_config(); |
|---|
| 68 | | elggadmin_currentpage('config'); |
|---|
| 69 | | } |
|---|
| 70 | | |
|---|
| 71 | | return $page; |
|---|
| 72 | | |
|---|
| 73 | | } |
|---|
| 74 | | |
|---|
| 75 | | function elggadmin_page_before($c=null, $args=null) { |
|---|
| 76 | | require_login('admin'); |
|---|
| 77 | | context('elggadmin'); |
|---|
| 78 | | $page = (isset($args[1])) ? $args[1] : 'config'; |
|---|
| 79 | | elggadmin_currentpage($page); |
|---|
| 80 | | } |
|---|
| 81 | | |
|---|
| 82 | | function elggadmin_sidebar() { |
|---|
| 83 | | $output = ''; |
|---|
| 84 | | if (elggadmin_currentpage() == 'frontpage' || elggadmin_currentpage() == 'pageshell') { |
|---|
| 85 | | $output .= "<h2>" . __gettext("Special keywords") . "</h2>"; |
|---|
| 86 | | $output .= "<p>" . __gettext("You can insert these into your pageshell for special functionality:") . "</p>"; |
|---|
| 87 | | $output .= "<p><b>{{url}}</b> " . __gettext("The address of your site.") . "</p>"; |
|---|
| 88 | | $output .= "<p><b>{{sitename}}</b> " . __gettext("The name of your site.") . "</p>"; |
|---|
| 89 | | $output .= "<p><b>{{tagline}}</b> " . __gettext("Your site's tagline.") . "</p>"; |
|---|
| 90 | | $output .= "<p><b>{{username}}</b> " . __gettext("The current user's username.") . "</p>"; |
|---|
| 91 | | $output .= "<p><b>{{userfullname}}</b> " . __gettext("The current user's full name.") . "</p>"; |
|---|
| 92 | | $output .= "<p><b>{{populartags}}</b> " . __gettext("A list of the most popular tags.") . "</p>"; |
|---|
| 93 | | $output .= "<p><b>{{randomusers}}</b> " . __gettext("A list of random users who have filled in their profiles, if some exist.") . "</p>"; |
|---|
| 94 | | $output .= "<p><b>{{people:interests:foo:5}}</b> " . __gettext("Lists five people interested in 'foo' in a horizontal table.") . "</p>"; |
|---|
| 95 | | $output .= "<p><b>{{toptags:town}}</b> " . __gettext("Lists the top tags of type 'town' (or select weblog, file or the profile field of your choice).") . "</p>"; |
|---|
| 96 | | } |
|---|
| 97 | | |
|---|
| 98 | | return $output; |
|---|
| 99 | | } |
|---|
| 100 | | |
|---|
| 101 | | function elggadmin_save($page) { |
|---|
| 102 | | switch ($page) { |
|---|
| 103 | | case 'config': |
|---|
| 104 | | $defcfg = elggadmin_get_defconfig(); |
|---|
| 105 | | $allowed = array(); |
|---|
| 106 | | foreach ($defcfg as $name => $obj) { |
|---|
| 107 | | if (!isset($obj->noteditable)) { |
|---|
| 108 | | $allowed[] = $name; |
|---|
| 109 | | } |
|---|
| 110 | | } |
|---|
| 111 | | |
|---|
| 112 | | $config = optional_param('config'); |
|---|
| 113 | | foreach ($config as $name => $value) { |
|---|
| 114 | | if (in_array($name, $allowed)) { |
|---|
| 115 | | set_config($name, $value); |
|---|
| 116 | | elgg_messages_add(sprintf(__gettext('Configuration option <code>%s</code> updated'), $name)); |
|---|
| 117 | | } |
|---|
| 118 | | } |
|---|
| 119 | | } |
|---|
| 120 | | } |
|---|
| 121 | | |
|---|
| 122 | | function elggadmin_currentpage($page_name=null) { |
|---|
| 123 | | static $name; |
|---|
| 124 | | |
|---|
| 125 | | if (!isset($name) && !empty($page_name)) { |
|---|
| 126 | | $name = $page_name; |
|---|
| 127 | | } else { |
|---|
| 128 | | if (!isset($name)) { |
|---|
| 129 | | $name = null; |
|---|
| 130 | | } |
|---|
| 131 | | } |
|---|
| 132 | | |
|---|
| 133 | | return $name; |
|---|
| 134 | | } |
|---|
| 135 | | |
|---|
| 136 | | function elggadmin_page_frontpage() { |
|---|
| 137 | | |
|---|
| 138 | | $page = new StdClass; |
|---|
| 139 | | $page->title = __gettext('Front page'); |
|---|
| 140 | | $page->body .= elggadmin_tpltextarea('frontpage_loggedout', __gettext('Front page (when logged out)')); |
|---|
| 141 | | $page->body .= elggadmin_tpltextarea('frontpage_loggedin', __gettext('Front page (when logged in)')); |
|---|
| 142 | | |
|---|
| 143 | | return $page; |
|---|
| 144 | | } |
|---|
| 145 | | |
|---|
| 146 | | function elggadmin_page_theme() { |
|---|
| 147 | | $page = new StdClass; |
|---|
| 148 | | $page->title = __gettext('Site theme'); |
|---|
| 149 | | $page->body .= elggadmin_tpltextarea('pageshell', __gettext('Main pageshell')); |
|---|
| 150 | | $page->body .= elggadmin_tpltextarea('css', __gettext('CSS styles')); |
|---|
| 151 | | // wrap into form |
|---|
| 152 | | $page->body = pages_html_form('elggtheme', $page->body); |
|---|
| 153 | | |
|---|
| 154 | | return $page; |
|---|
| 155 | | } |
|---|
| 156 | | |
|---|
| 157 | | function elggadmin_page_config() { |
|---|
| 158 | | |
|---|
| 159 | | $show_all = optional_param('view'); |
|---|
| 160 | | |
|---|
| 161 | | $_config = elggadmin_get_defconfig(); |
|---|
| 162 | | $page = new StdClass; |
|---|
| 163 | | $page->title = __gettext('Configuration manager'); |
|---|
| 164 | | $page->body = null; |
|---|
| 165 | | |
|---|
| 166 | | if (empty($show_all)) { |
|---|
| 167 | | $view_all = pages_html_a(get_url_query(1, 'elggadmin::', 'view=all'), __gettext('View all options')); |
|---|
| 168 | | $page->body .= pages_html_wrap('div', pages_html_wrap('label', $view_all), array('class'=>'')); |
|---|
| 169 | | } |
|---|
| 170 | | |
|---|
| 171 | | $note = __gettext('Note: some fields are disabled because the value is forced by your <code>config.php</code>.'); |
|---|
| 172 | | $note .= __gettext('To change you must hand edit your <code>config.php</code>.'); |
|---|
| 173 | | $page->body .= pages_html_wrap('p', $note); |
|---|
| 174 | | |
|---|
| 175 | | foreach ($_config as $c => $obj) { |
|---|
| 176 | | if ((isset($obj->noteditable) || isset($obj->hidden)) && !$show_all) { |
|---|
| 177 | | continue; |
|---|
| 178 | | } |
|---|
| 179 | | |
|---|
| 180 | | $name = htmlspecialchars($obj->name, ENT_COMPAT, 'utf-8'); |
|---|
| 181 | | if (isset($obj->important)) { |
|---|
| 182 | | $name .= ': *'; |
|---|
| 183 | | } else { |
|---|
| 184 | | $name .= ': '; |
|---|
| 185 | | } |
|---|
| 186 | | |
|---|
| 187 | | $class = 'form-item ' . (isset($obj->important) ? ' important' : ''); |
|---|
| 188 | | $desc = (isset($obj->description)) ? $obj->description : ' '; |
|---|
| 189 | | |
|---|
| 190 | | $input = pages_html_wrap('label', $name); |
|---|
| 191 | | $input .= elggadmin_config_input($c, $obj); |
|---|
| 192 | | $input .= pages_html_wrap('span', $desc); |
|---|
| 193 | | |
|---|
| 194 | | $page->body .= pages_html_wrap('div', $input, array('class'=>$class)); |
|---|
| 195 | | } |
|---|
| 196 | | |
|---|
| 197 | | $page->body = pages_html_form('elggconfig', $page->body); |
|---|
| 198 | | |
|---|
| 199 | | return $page; |
|---|
| 200 | | } |
|---|
| 201 | | |
|---|
| 202 | | function elggadmin_config_input($c, $obj) { |
|---|
| 203 | | global $CFG; |
|---|
| 204 | | |
|---|
| 205 | | $value = (isset($CFG->$c)) ? $CFG->$c : null; |
|---|
| 206 | | $input_name = "config[$c]"; |
|---|
| 207 | | |
|---|
| 208 | | $attrs = array(); |
|---|
| 209 | | $attrs['name'] = $input_name; |
|---|
| 210 | | $attrs['value'] = $value; |
|---|
| 211 | | |
|---|
| 212 | | if (isset($obj->noteditable)) { |
|---|
| 213 | | $attrs['disabled'] = 'disabled'; |
|---|
| 214 | | } |
|---|
| 215 | | |
|---|
| 216 | | $result = pages_html_input('text', $attrs); |
|---|
| 217 | | |
|---|
| 218 | | return $result; |
|---|
| 219 | | } |
|---|
| 220 | | |
|---|
| 221 | | function elggadmin_get_defconfig() { |
|---|
| 222 | | if (!is_readable('./configdef.php')) { |
|---|
| 223 | | trigger_error(__FUNCTION__.': can not locate <code>configdef.php</code> file, perhaps your installation is corrupted.', E_USER_ERROR); |
|---|
| 224 | | } |
|---|
| 225 | | |
|---|
| 226 | | $DEFCFG = new StdClass; |
|---|
| 227 | | require('./configdef.php'); |
|---|
| 228 | | |
|---|
| 229 | | $current = elggadmin_get_currentconfig(); |
|---|
| 230 | | $defined = get_object_vars($current); |
|---|
| 231 | | foreach ($defined as $name => $value) { |
|---|
| 232 | | if (isset($DEFCFG->config[$name])) { |
|---|
| 233 | | $DEFCFG->config[$name]->noteditable = true; |
|---|
| 234 | | } |
|---|
| 235 | | } |
|---|
| 236 | | |
|---|
| 237 | | return $DEFCFG->config; |
|---|
| 238 | | } |
|---|
| 239 | | |
|---|
| 240 | | function elggadmin_get_currentconfig() { |
|---|
| 241 | | $CFG = new StdClass; |
|---|
| 242 | | @include('../../config.php'); |
|---|
| 243 | | |
|---|
| 244 | | return $CFG; |
|---|
| 245 | | } |
|---|
| 246 | | |
|---|
| 247 | | function elggadmin_tpltextarea($tplname, $title=null) { |
|---|
| 248 | | $output = ''; |
|---|
| 249 | | if (is_string($title)) { |
|---|
| 250 | | $output .= pages_html_wrap('h2', $title); |
|---|
| 251 | | } |
|---|
| 252 | | |
|---|
| 253 | | if (!$tpl = elggadmin_loadtpl($tplname)) { |
|---|
| 254 | | elgg_messages_add(__gettext("Can't load <code>$tplname</code> file.")); |
|---|
| 255 | | } |
|---|
| 256 | | |
|---|
| 257 | | $output .= pages_html_wrap('textarea', empty($tpl) ? ' ' : $tpl, array('name' => $tplname, 'style' => 'width:95%;height:300px;margin:0px 10px 20px 10px;')); |
|---|
| 258 | | |
|---|
| 259 | | return $output; |
|---|
| 260 | | } |
|---|
| 261 | | |
|---|