1<?php 2/* 3 * e107 website system 4 * 5 * Copyright (C) 2008-2009 e107 Inc (e107.org) 6 * Released under the terms and conditions of the 7 * GNU General Public License (http://www.gnu.org/licenses/gpl.txt) 8 * 9 * Admin BootLoader 10 * 11*/ 12 13if (!defined('e107_INIT')) 14{ 15 exit; 16} 17 18e107::getDebug()->logTime('(Start boot.php)'); 19header('Content-type: text/html; charset=utf-8', TRUE); 20define('ADMINFEED', 'https://e107.org/adminfeed'); 21 22 23if(!empty($_GET['iframe'])) // global iframe support. 24{ 25 define('e_IFRAME', true); 26} 27 28// .e-sef-generate routine. 29if(e_AJAX_REQUEST && ADMIN && defset('e_ADMIN_UI') && varset($_POST['mode']) == 'sef' && !empty($_POST['source'])) 30{ 31 $d = array('converted'=> eHelper::title2sef($_POST['source'])); 32 echo json_encode($d); 33 exit; 34} 35 36if(e_AJAX_REQUEST && getperms('0') && varset($_GET['mode']) == 'core' && ($_GET['type'] == 'update')) 37{ 38 39 require_once(e_ADMIN.'update_routines.php'); 40 41 e107::getSession()->set('core-update-checked',false); 42 43 $status = (update_check() === true) ? true : false; 44 45 e107::getSession()->set('core-update-status',$status); 46 47 echo json_encode($status); 48 49 exit; 50 51} 52 53if(e_AJAX_REQUEST && getperms('0') && varset($_GET['mode']) == 'addons' && ($_GET['type'] == 'update')) 54{ 55 e107::getSession()->set('addons-update-checked',true); 56 57 /** @var admin_shortcodes $sc */ 58 $sc = e107::getScBatch('admin'); 59 60 $themes = $sc->getUpdateable('theme'); 61 $plugins = $sc->getUpdateable('plugin'); 62 63 $text = $sc->renderAddonUpdate($plugins); 64 $text .= $sc->renderAddonUpdate($themes); 65 66 67 if(empty($text)) 68 { 69 exit; 70 } 71 72 $ns = e107::getRender(); 73 74 $tp = e107::getParser(); 75 $ns->setUniqueId('e-addon-updates'); 76 $ns->setStyle('warning'); 77 $ret = $ns->tablerender($tp->toGlyph('fa-arrow-circle-o-down').LAN_UPDATE_AVAILABLE,$text,'default', true); 78 79 echo $ret; 80 81 e107::getSession()->set('addons-update-status',$ret); 82 83 exit; 84 85} 86 87 88if(e_AJAX_REQUEST && ADMIN && varset($_GET['mode']) == 'core' && ($_GET['type'] == 'feed')) 89{ 90 91 $limit = 3; 92 93 if($data = e107::getXml()->getRemoteFile(ADMINFEED,3)) 94 { 95 // print_a($data); 96 $rows = e107::getXml()->parseXml($data, 'advanced'); 97 $defaultImg = $rows['channel']['image']['url']; 98 99 $text = '<div style="margin-left:10px;margin-top:10px">'; 100 $count = 1; 101 foreach($rows['channel']['item'] as $row) 102 { 103 if($count > $limit){ break; } 104 105 $description = $tp->toText($row['description']); 106 $text .= ' 107 <div class="media"> 108 <div class="media-body"> 109 <h4 class="media-heading"><a target="_blank" href="'.$row['link'].'">'.$row['title'].'</a> <small>— '.$row['pubDate'].'</small></h4> 110 '.$tp->text_truncate($description,150).' 111 </div></div>'; 112 $count++; 113 } 114 $text .= '</div>'; 115 echo $text; 116 117 } 118 /*else 119 { 120 if(e_DEBUG) 121 { 122 echo "Feed failed: ".ADMINFEED; 123 } 124 }*/ 125 exit; 126} 127 128 129 130if(ADMIN && (e_AJAX_REQUEST || deftrue('e_DEBUG_FEEDS')) && varset($_GET['mode']) == 'addons' ) 131{ 132 $type = ($_GET['type'] == 'plugin') ? 'plugin' : 'theme'; 133 $tag = 'Infopanel_'.$type; 134 135 $cache = e107::getCache(); 136 137 $feed = 'https://e107.org/feed/?limit=3&type='.$type; 138 139 if($text = $cache->retrieve($tag,180,true, true)) // check every 3 hours. 140 { 141 echo $text; 142 143 if(e_DEBUG === true) 144 { 145 echo "<span class='label label-warning' title='".$feed."'>Cached</span>"; 146 } 147 exit; 148 } 149 150 151 if($data = e107::getXml()->getRemoteFile($feed,3)) 152 { 153 $rows = e107::getXml()->parseXml($data, 'advanced'); 154// print_a($rows); 155// exit; 156 $link = ($type == 'plugin') ? e_ADMIN."plugin.php?mode=online" : e_ADMIN."theme.php?mode=main&action=online"; 157 158 $text = "<div style='margin-top:10px'>"; 159 160 foreach($rows[$type] as $val) 161 { 162 $meta = $val['@attributes']; 163 $img = ($type == 'theme') ? $meta['thumbnail'] : $meta['icon']; 164 $text .= '<div class="media">'; 165 $text .= '<div class="media-left"> 166 <a href="'.$link.'"> 167 <img class="media-object img-rounded rounded" src="'.$img.'" style="width:100px" alt="" /> 168 </a> 169 </div> 170 <div class="media-body"> 171 <h4 class="media-heading"><a href="'.$link.'">'.$meta['name'].' v'.$meta['version'].'</a> <small>— '.$meta['author'].'</small></h4> 172 '.$val['description'].' 173 </div>'; 174 $text .= '</div>'; 175 } 176 177 $text .= "</div>"; 178 $text .= "<div class='right'><a href='".$link."'>".LAN_MORE."</a></div>"; 179 180 echo $text; 181 182 $cache->set($tag, $text, true, null, true); 183 184 } 185 exit; 186 187} 188 189 190### Language files 191e107::coreLan('header', true); 192e107::coreLan('footer', true); 193 194// DEPRECATED - plugins should load their lans manually 195// plugin autoload, will be removed in the future! 196// here mostly because of BC reasons 197//if(!deftrue('e_MINIMAL')) 198{ 199 $_globalLans = e107::pref('core', 'lan_global_list'); 200 $_plugins = e107::getPref('plug_installed'); 201 $plugDir = e107::getFolder('plugins'); 202 203 if(strpos(e_REQUEST_URI,$plugDir) !== false && !deftrue('e_ADMIN_UI') && !empty($_plugins) && !empty($_globalLans) && is_array($_plugins) && (count($_plugins) > 0)) 204 { 205 $_plugins = array_keys($_plugins); 206 207 foreach ($_plugins as $_p) 208 { 209 if(defset('e_CURRENT_PLUGIN') != $_p) 210 { 211 continue; 212 } 213 214 if(in_array($_p, $_globalLans)) // filter out those with globals unless we are in a plugin folder. 215 { 216 continue; 217 } 218 219 e107::getDebug()->logTime('[boot.php: Loading LANS for '.$_p.']'); 220 e107::loadLanFiles($_p, 'admin'); 221 } 222 } 223} 224 225 226// Get Icon constants, theme override (theme/templates/admin_icons_template.php) is allowed 227e107::getDebug()->logTime('[boot.php: Loading admin_icons]'); 228include_once(e107::coreTemplatePath('admin_icons')); 229 230 231if(!defset('e_ADMIN_UI') && !defset('e_PAGETITLE')) 232{ 233 $array_functions = e107::getNav()->adminLinks('legacy'); // replacement see e107_handlers/sitelinks.php 234 foreach($array_functions as $val) 235 { 236 $link = str_replace("../","",$val[0]); 237 //if(strpos(e_SELF,$link)!==FALSE) 238 // { 239 // define('e_PAGETITLE',$val[1]); 240 // } 241 } 242} 243 244 245if (!defined('ADMIN_WIDTH')) //BC Only 246{ 247 define('ADMIN_WIDTH', "width:100%;"); 248} 249 250 251 252/** 253 * Automate DB system messages DEPRECATED 254 * NOTE: default value of $output parameter will be changed to false (no output by default) in the future 255 * 256 * @param integer|bool $update return result of db::db_Query 257 * @param string $type update|insert|update 258 * @param string|bool $success forced success message 259 * @param string|bool $failed forced error message 260 * @param bool $output false suppress any function output 261 * @return integer|bool db::db_Query result 262 */ 263 // TODO - This function often needs to be available BEFORE header.php is loaded. 264 265 266 //XXX DEPRECATED It has been copied to message_handler.php as addAuto(); 267 268function admin_updXXate($update, $type = 'update', $success = false, $failed = false, $output = true) 269{ 270 e107::getMessage()->addDebug("Using deprecated admin_update () which has been replaced by \$mes->addAuto();"); 271 return e107::getMessage()->addAuto($update, $type, $success , $failed , $output); 272} 273 274 275function admin_purge_related($table, $id) 276{ 277 $ns = e107::getRender(); 278 $tp = e107::getParser(); 279 $msg = ""; 280 $tp->parseTemplate(""); 281 282 // Delete any related comments 283 require_once (e_HANDLER."comment_class.php"); 284 $_com = new comment; 285 $num = $_com->delete_comments($table, $id); 286 if ($num) 287 { 288 $msg .= $num." ".LAN_COMMENTS." ".LAN_DELETED."<br />"; 289 } 290 291 // Delete any related ratings 292 require_once (e_HANDLER."rate_class.php"); 293 $_rate = new rater; 294 $num = $_rate->delete_ratings($table, $id); 295 if ($num) 296 { 297 $msg .= LAN_RATING." ".LAN_DELETED."<br />"; 298 } 299 300 if ($msg) 301 { 302 $ns->tablerender(LAN_DELETE, $msg); 303 } 304} 305 306// legacy vars, will be removed soon 307$ns = e107::getRender(); 308$e107_var = array(); 309 310// Left in for BC for now. 311 312function e_admin_menu($title, $active_page, $e107_vars, $tmpl = array(), $sub_link = false, $sortlist = false) 313{ 314 315 global $E_ADMIN_MENU; 316 if (!$tmpl) 317 $tmpl = $E_ADMIN_MENU; 318 319 320 return e107::getNav()->admin($title, $active_page, $e107_vars, $tmpl, $sub_link , $sortlist ); 321} 322 323/* 324 * DEPRECATED - use e_adm/in_menu() e107::getNav()->admin 325 */ 326if (!function_exists('show_admin_menu')) 327{ 328 function show_admin_menu($title, $active_page, $e107_vars, $js = FALSE, $sub_link = FALSE, $sortlist = FALSE) 329 { 330 unset($js,$sub_link); 331 return e107::getNav()->admin($title, $active_page, $e107_vars, false, false, $sortlist); 332 } 333} 334 335if (!function_exists("parse_admin")) 336{ 337 function parse_admin($ADMINLAYOUT) 338 { 339 $sc = e107::getScBatch('admin'); 340 $tp = e107::getParser(); 341 342 $adtmp = explode("\n", $ADMINLAYOUT); 343 344 for ($a = 0; $a < count($adtmp); $a++) 345 { 346 if (preg_match("/{.+?}/", $adtmp[$a])) 347 { 348 echo $tp->parseTemplate($adtmp[$a], true, $sc); 349 } 350 else 351 { 352 echo $adtmp[$a]; 353 } 354 } 355 } 356} 357