PageRenderTime 68ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 2ms

/system/cp/cp.utilities.php

https://github.com/danboy/Croissierd
PHP | 5636 lines | 3811 code | 1272 blank | 553 comment | 490 complexity | 26e0bc0fa448a1550a0a0c14d0e6633d MD5 | raw file

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /*
  3. =====================================================
  4. ExpressionEngine - by EllisLab
  5. -----------------------------------------------------
  6. http://expressionengine.com/
  7. -----------------------------------------------------
  8. Copyright (c) 2003 - 2010 EllisLab, Inc.
  9. =====================================================
  10. THIS IS COPYRIGHTED SOFTWARE
  11. PLEASE READ THE LICENSE AGREEMENT
  12. http://expressionengine.com/docs/license.html
  13. =====================================================
  14. File: cp.utilities.php
  15. -----------------------------------------------------
  16. Purpose: Utilities
  17. =====================================================
  18. */
  19. if ( ! defined('EXT'))
  20. {
  21. exit('Invalid file request');
  22. }
  23. class Utilities {
  24. /** -------------------------------------------
  25. /** Extensions Manager
  26. /** -------------------------------------------*/
  27. function extensions_manager($message = '')
  28. {
  29. global $DSP, $IN, $PREFS, $LANG, $DB, $FNS, $EXT;
  30. $debug = TRUE;
  31. $extension_files = array();
  32. $extensions_installed = array();
  33. /** ---------------------------------------
  34. /** Extensions Available
  35. /** ---------------------------------------*/
  36. $i = 0;
  37. if ($fp = @opendir(PATH_EXT))
  38. {
  39. while (false !== ($file = readdir($fp)))
  40. {
  41. if (substr($file, -strlen(EXT)) == EXT && substr($file, 0, 4) == 'ext.')
  42. {
  43. $extension_files[$i] = substr($file, 4, -strlen(EXT));
  44. $i++;
  45. }
  46. }
  47. closedir($fp);
  48. }
  49. /** ---------------------------------------
  50. /** Extensions Enabled
  51. /** ---------------------------------------*/
  52. $query = $DB->query("SELECT class, version FROM exp_extensions WHERE enabled = 'y'");
  53. if ($query->num_rows > 0)
  54. {
  55. foreach($query->result as $row) $extensions_installed[strtolower($row['class'])] = $row['version'];
  56. }
  57. /** ---------------------------------------
  58. /** Create Output
  59. /** ---------------------------------------*/
  60. $DSP->crumbline = FALSE;
  61. if ($PREFS->ini('allow_extensions') == 'y')
  62. {
  63. $DSP->right_crumb($LANG->line('disable_extensions'), BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=toggle_extension_confirm'.AMP.'which=disable');
  64. }
  65. else
  66. {
  67. $DSP->right_crumb($LANG->line('enable_extensions'), BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=toggle_extension_confirm'.AMP.'which=enable');
  68. }
  69. $r = $DSP->qdiv('tableHeading', $LANG->line('extensions_manager'));
  70. if ($message != '')
  71. {
  72. $r .= $DSP->qdiv('success', $message);
  73. }
  74. // List of Extensions Table
  75. $r .= $DSP->table('tableBorder', '0', '0', '100%');
  76. if (count($extension_files) == 0)
  77. {
  78. $r .= $DSP->tr().
  79. $DSP->td('tableCellTwo', '', '2').
  80. '<b>'.$LANG->line('no_extensions_exist').'</b>'.
  81. $DSP->td_c().
  82. $DSP->tr_c();
  83. }
  84. else
  85. {
  86. $r .= $DSP->tr().
  87. $DSP->td('tableHeadingAlt', '55%').
  88. $LANG->line('extension_name').
  89. $DSP->td_c().
  90. $DSP->td('tableHeadingAlt', '15%').
  91. $LANG->line('documentation').
  92. $DSP->td_c().
  93. $DSP->td('tableHeadingAlt', '15%').
  94. $LANG->line('settings').
  95. $DSP->td_c().
  96. $DSP->td('tableHeadingAlt', '15%').
  97. $LANG->line('status').
  98. $DSP->td_c().
  99. $DSP->tr_c();
  100. }
  101. $i = 0;
  102. if (count($extension_files) > 0)
  103. {
  104. $extension_meta = array('description', 'settings_exist', 'docs_url', 'name', 'version');
  105. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  106. foreach ($extension_files as $extension_name)
  107. {
  108. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  109. /** ------------------------------------
  110. /** Load Extension and Fetch Metadata
  111. /** ------------------------------------*/
  112. $meta = array();
  113. $class_name = ucfirst($extension_name);
  114. if ( ! class_exists($class_name))
  115. {
  116. if ($debug === TRUE)
  117. {
  118. include(PATH_EXT.'ext.'.$extension_name.EXT);
  119. }
  120. else
  121. {
  122. @include(PATH_EXT.'ext.'.$extension_name.EXT);
  123. }
  124. if ( ! class_exists($class_name)) continue;
  125. }
  126. $OBJ = new $class_name();
  127. foreach($extension_meta as $meta_item)
  128. {
  129. ${$meta_item} = ( ! isset($OBJ->{$meta_item})) ? '' : $OBJ->{$meta_item};
  130. }
  131. if ($name == '')
  132. {
  133. $name = ucwords(str_replace('_',' ',$extension_name));
  134. }
  135. /** ------------------------------------
  136. /** Different Output depending on current status
  137. /** ------------------------------------*/
  138. if ($PREFS->ini('allow_extensions') == 'y' && isset($extensions_installed[$extension_name]))
  139. {
  140. // Double check that the extension is up to date
  141. // If not, then quickly run the update script to make
  142. // sure that we are up to date before changing any settings
  143. if ($OBJ->version > $EXT->version_numbers[$class_name] && method_exists($OBJ, 'update_extension') === TRUE)
  144. {
  145. $update = $OBJ->update_extension($EXT->version_numbers[$class_name]);
  146. $EXT->version_numbers[$class_name] = $OBJ->version;
  147. }
  148. $installed = $LANG->line('extension_enabled') . ' ('.$DSP->anchor(BASE.AMP.'C=admin'.
  149. AMP.'M=utilities'.
  150. AMP.'P=toggle_extension'.
  151. AMP.'which=disable'.
  152. AMP.'name='.$extension_name,
  153. $LANG->line('disable_extension'),
  154. "onclick='if(!confirm(\"".
  155. $LANG->line('toggle_extension_confirmation').
  156. "\")) return false;'").')';
  157. $link = $DSP->qspan('defaultBold', $name).' (v.'.$version.')';
  158. if ($description != '' && $description != '')
  159. {
  160. $link .= NL.$DSP->br().NL.$description;
  161. }
  162. $settings_link = $DSP->anchor(BASE.AMP.'C=admin'.
  163. AMP.'M=utilities'.
  164. AMP.'P=extension_settings'.
  165. AMP.'name='.$extension_name,
  166. $LANG->line('settings'));
  167. }
  168. else
  169. {
  170. $link = $DSP->qspan('defaultLight', $name.' (v.'.$version.')');
  171. if ($PREFS->ini('allow_extensions') == 'y')
  172. {
  173. $installed = $LANG->line('extension_disabled') . ' ('.$DSP->anchor(BASE.AMP.'C=admin'.
  174. AMP.'M=utilities'.
  175. AMP.'P=toggle_extension'.
  176. AMP.'which=enable'.
  177. AMP.'name='.$extension_name,
  178. $LANG->line('enable_extension'),
  179. "onclick='if(!confirm(\"".
  180. $LANG->line('toggle_extension_confirmation').
  181. "\")) return false;'").')';
  182. }
  183. else
  184. {
  185. $installed = $LANG->line('extension_disabled');
  186. }
  187. $settings_link = $DSP->qspan('defaultLight', $LANG->line('settings'));
  188. }
  189. if ($docs_url != '')
  190. {
  191. $docs_url = $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.urlencode($docs_url), $LANG->line('documentation'), '', TRUE);
  192. }
  193. $r .= $DSP->tr()
  194. . $DSP->table_qcell($style, $link, '55%')
  195. . $DSP->table_qcell($style, ($docs_url == '') ? '--' : $docs_url, '15%')
  196. . $DSP->table_qcell($style, ($settings_exist != 'y') ? '--' : $settings_link, '15%')
  197. . $DSP->table_qcell($style, $installed, '15%')
  198. .$DSP->tr_c();
  199. unset($OBJ);
  200. }
  201. }
  202. $r .= $DSP->table_c();
  203. $DSP->title = $LANG->line('extensions_manager');
  204. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  205. $DSP->crumb_item($LANG->line('extensions_manager'));
  206. $DSP->body = $r;
  207. }
  208. /* END */
  209. /** -------------------------------------------
  210. /** Extension Settings Form
  211. /** -------------------------------------------*/
  212. function extension_settings($message = '')
  213. {
  214. global $DSP, $IN, $PREFS, $LANG, $DB, $FNS, $REGX;
  215. if ($PREFS->ini('allow_extensions') != 'y')
  216. {
  217. return $DSP->no_access_message();
  218. }
  219. if ($IN->GBL('name') === FALSE OR ! preg_match("/^[a-z0-9][\w.-]*$/i",$IN->GBL('name'))) return false;
  220. $class_name = ucfirst($IN->GBL('name'));
  221. $current = array();
  222. /** ---------------------------------------
  223. /** Extensions Enabled
  224. /** ---------------------------------------*/
  225. $query = $DB->query("SELECT settings FROM exp_extensions
  226. WHERE enabled = 'y' AND class = '".$DB->escape_str($class_name)."'
  227. LIMIT 1");
  228. if ($query->num_rows > 0 && $query->row['settings'] != '')
  229. {
  230. $current = $REGX->array_stripslashes(unserialize($query->row['settings']));
  231. }
  232. /** -----------------------------
  233. /** Call Extension File
  234. /** -----------------------------*/
  235. if ( ! class_exists($class_name))
  236. {
  237. @include(PATH_EXT.'ext.'.$IN->GBL('name').EXT);
  238. if ( ! class_exists($class_name)) return false;
  239. }
  240. $OBJ = new $class_name();
  241. foreach(array('description', 'settings_exist', 'docs_url', 'name', 'version') as $meta_item)
  242. {
  243. ${$meta_item} = ( ! isset($OBJ->{$meta_item})) ? '' : $OBJ->{$meta_item};
  244. }
  245. if ($name == '')
  246. {
  247. $name = ucwords(str_replace('_',' ',$extension_name));
  248. }
  249. // -----------------------------------
  250. // Fetch Extension Language file
  251. //
  252. // If there are settings, then there is a language file
  253. // because we need to know all the various variable names in the settings
  254. // form. I was tempted to give these language files a prefix but I
  255. // decided against it for the sake of simplicity and the fact that
  256. // a module might have extension's bundled with them and it would make
  257. // sense to have the same language file for both.
  258. // -----------------------------------
  259. $LANG->fetch_language_file($IN->GBL('name'));
  260. /** ---------------------------------------
  261. /** Creating Their Own Settings Form?
  262. /** ---------------------------------------*/
  263. if (method_exists($OBJ, 'settings_form') === TRUE)
  264. {
  265. return $OBJ->settings_form($current);
  266. }
  267. /** ---------------------------------------
  268. /** Right Crumb Tab
  269. /** ---------------------------------------*/
  270. $DSP->crumbline = TRUE;
  271. $DSP->right_crumb($LANG->line('disable_extension'), BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=toggle_extension_confirm'.AMP.'which=disable'.AMP.'name='.$IN->GBL('name'));
  272. /** -----------------------------
  273. /** Create Page's Content
  274. /** -----------------------------*/
  275. $r = $DSP->table('', '', '', '100%')
  276. .$DSP->tr()
  277. .$DSP->td('default', '', '', '', 'top')
  278. .$DSP->heading($LANG->line('extension_settings'));
  279. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  280. $docs = ($docs_url == '') ? '' : ' ['.$DSP->anchor($FNS->fetch_site_index().$qm.'URL='.urlencode($docs_url), $LANG->line('documentation'), '', TRUE).']';
  281. $r .= $DSP->td_c()
  282. .$DSP->td('default', '', '', '', 'middle')
  283. .$DSP->qdiv('defaultRight', '<strong>'.$docs.'</strong>'.NBS.NBS)
  284. .$DSP->td_c()
  285. .$DSP->tr_c()
  286. .$DSP->tr()
  287. .$DSP->td('default', '100%', '2', '', 'top');
  288. $r .= Utilities::extension_settings_form($name, $IN->GBL('name'), $OBJ->settings(), $current);
  289. $r .= $DSP->td_c()
  290. .$DSP->tr_c()
  291. .$DSP->table_c()
  292. .$DSP->td_c()
  293. .$DSP->tr_c()
  294. .$DSP->table_c();
  295. $DSP->title = $LANG->line('extension_settings');
  296. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  297. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=extensions_manager', $LANG->line('extensions_manager')));
  298. $DSP->crumb .= $DSP->crumb_item($name);
  299. $DSP->body = $r;
  300. }
  301. /* END */
  302. /** -----------------------------
  303. /** Store Extension Settings
  304. /** -----------------------------*/
  305. function save_extension_settings()
  306. {
  307. global $IN, $DB, $FNS;
  308. // Basic security check
  309. if ( ! preg_match("/^[a-z0-9][\w.-]*$/i",$IN->GBL('name'))) return false;
  310. if ( ! class_exists(ucfirst($IN->GBL('name'))))
  311. {
  312. include(PATH_EXT.'ext.'.strtolower($IN->GBL('name')).EXT);
  313. }
  314. // Ok, I admit that we should be able to simply unset the 'name' value
  315. // from the $_POST array and simply insert that into the database.
  316. // I, Paul Burdick of the Sinister House geeks, am slowly becoming
  317. // anal retentive in my young age and decided to make sure only those
  318. // settings specified by the extension are inserted AND that there is
  319. // always an empty string in the really rare chance that one is not
  320. // specified.
  321. if (class_exists(ucfirst($IN->GBL('name'))))
  322. {
  323. $class_name = ucfirst($IN->GBL('name'));
  324. $OBJ = new $class_name();
  325. /** ---------------------------------------
  326. /** Processing Their Own Settings Form?
  327. /** ---------------------------------------*/
  328. if (method_exists($OBJ, 'settings_form') === TRUE)
  329. {
  330. $OBJ->save_settings();
  331. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=extensions_manager');
  332. exit;
  333. }
  334. if (method_exists($OBJ, 'settings') === TRUE)
  335. {
  336. $settings = $OBJ->settings();
  337. }
  338. $insert = array();
  339. foreach($settings as $key => $value)
  340. {
  341. if ( ! is_array($value))
  342. {
  343. $insert[$key] = ($IN->GBL($key, 'POST') !== FALSE) ? $IN->GBL($key, 'POST') : $value;
  344. }
  345. elseif (is_array($value) && isset($value['1']) && is_array($value['1']))
  346. {
  347. if(is_array($IN->GBL($key, 'POST')) OR $value[0] == 'ms')
  348. {
  349. $data = (is_array($IN->GBL($key, 'POST'))) ? $IN->GBL($key, 'POST') : array();
  350. $data = array_intersect($data, array_keys($value['1']));
  351. }
  352. else
  353. {
  354. if ($IN->GBL($key, 'POST') === FALSE)
  355. {
  356. $data = ( ! isset($value['2'])) ? '' : $value['2'];
  357. }
  358. else
  359. {
  360. $data = $IN->GBL($key, 'POST');
  361. }
  362. }
  363. $insert[$key] = $data;
  364. }
  365. else
  366. {
  367. $insert[$key] = ($IN->GBL($key, 'POST') !== FALSE) ? $IN->GBL($key, 'POST') : '';
  368. }
  369. }
  370. $DB->query("UPDATE exp_extensions SET settings = '".addslashes(serialize($insert))."' WHERE class = '".$DB->escape_str($IN->GBL('name'))."'");
  371. }
  372. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=extensions_manager');
  373. exit;
  374. }
  375. /* END */
  376. /** -----------------------------
  377. /** Create Form Automagically
  378. /** -----------------------------*/
  379. function extension_settings_form($extension_name, $name, $fdata, $data)
  380. {
  381. global $DSP, $LANG;
  382. $r = $DSP->form_open(
  383. array(
  384. 'action' => 'C=admin'.AMP.'M=utilities'.AMP.'P=save_extension_settings',
  385. 'name' => 'settings_'.$name,
  386. 'id' => 'settings_'.$name
  387. ),
  388. array('name' => $name)
  389. );
  390. $r .= $DSP->table('tableBorder', '0', '', '100%');
  391. $r .= $DSP->tr();
  392. $r .= $DSP->td('tableHeadingAlt', '', '2');
  393. $r .= $extension_name;
  394. $r .= $DSP->td_c();
  395. $r .= $DSP->tr_c();
  396. $i = 0;
  397. /** -----------------------------
  398. /** Blast through the array
  399. /** -----------------------------*/
  400. foreach ($fdata as $key => $val)
  401. {
  402. $style = ($i % 2) ? 'tableCellOne' : 'tableCellTwo'; $i++;
  403. $default_data = (is_array($val)) ? '' : $val;
  404. $data[$key] = ( ! isset($data[$key])) ? $default_data : $data[$key];
  405. if (!is_array($val) || $val['0'] != 'sf')
  406. {
  407. $r .= $DSP->tr();
  408. // If the form type is a textarea, we'll align the text at the top, otherwise, we'll center it
  409. if (is_array($val) && ($val['0'] == 't' OR $val['0'] == 'ms' OR ($val['0'] == 'c' && sizeof($val['1']) > 1)))
  410. {
  411. $r .= $DSP->td($style, '50%', '', '', 'top');
  412. }
  413. else
  414. {
  415. $r .= $DSP->td($style, '50%', '');
  416. }
  417. /** -----------------------------
  418. /** Preference heading
  419. /** -----------------------------*/
  420. $r .= $DSP->div('defaultBold');
  421. $label = ( ! is_array($val)) ? $key : '';
  422. // Fix for array form variables like cat_id[]
  423. // Such names to do no work well with the
  424. // translation utility sadly.
  425. if (($LANG->line($key) === false || $LANG->line($key) == '') && strpos($key, '[]') !== false)
  426. {
  427. if ($LANG->line(str_replace('[]','',$key)) === FALSE)
  428. {
  429. $r .= '<label for="'.$key.'">'.ucwords(str_replace('_', ' ', $key))."</label>";
  430. }
  431. else
  432. {
  433. $r .= $LANG->line(str_replace('[]','',$key), $label);
  434. }
  435. }
  436. else
  437. {
  438. $r .= $LANG->line($key, $label);
  439. }
  440. $r .= $DSP->div_c();
  441. /** -----------------------------
  442. /** Preference sub-heading
  443. /** -----------------------------*/
  444. $r .= $DSP->td_c();
  445. /** -----------------------------
  446. /** Preference value
  447. /** -----------------------------*/
  448. $r .= $DSP->td($style, '50%', '');
  449. }
  450. if (is_array($val))
  451. {
  452. /** -----------------------------
  453. /** Drop-down menus
  454. /** -----------------------------*/
  455. if ($val['0'] == 's' || $val['0'] == 'ms')
  456. {
  457. $multi = ($val['0'] == 'ms') ? "class='multiselect' size='8' multiple='multiple'" : "class='select'";
  458. $nkey = ($val['0'] == 'ms') ? $key.'[]' : $key;
  459. if (isset($val['2']))
  460. {
  461. $r .= "<select name='{$nkey}' $multi ".$val['2'].">\n";
  462. }
  463. else
  464. {
  465. $r .= "<select name='{$nkey}' $multi >\n";
  466. }
  467. $data[$key] = ($data[$key] == '') ? $val['2'] : $data[$key];
  468. foreach ($val['1'] as $k => $v)
  469. {
  470. if ($val['0'] == 's' || ! is_array($data[$key]))
  471. {
  472. $selected = ($k == $data[$key]) ? 1 : '';
  473. }
  474. elseif(is_array($data[$key]))
  475. {
  476. $selected = (in_array($k,$data[$key])) ? 1 : '';
  477. }
  478. $name = ($LANG->line($v) == false OR $key == 'weblog_id') ? $v : $LANG->line($v);
  479. $r .= $DSP->input_select_option($k, $name, $selected);
  480. }
  481. $r .= $DSP->input_select_footer();
  482. }
  483. elseif ($val['0'] == 'r')
  484. {
  485. /** -----------------------------
  486. /** Radio buttons
  487. /** -----------------------------*/
  488. if ( ! isset($val['2']))
  489. {
  490. $val['2'] = '';
  491. }
  492. $data[$key] = ($data[$key] == '') ? $val['2'] : $data[$key];
  493. foreach ($val['1'] as $k => $v)
  494. {
  495. $selected = ($k == $data[$key]) ? 1 : '';
  496. $r .= $LANG->line($v).$DSP->nbs();
  497. $r .= $DSP->input_radio($key, $k, $selected, ( ! isset($val['3'])) ? '' : $val['3']).$DSP->nbs(3);
  498. }
  499. }
  500. elseif ($val['0'] == 'c')
  501. {
  502. /** -----------------------------
  503. /** Checkboxes
  504. /** -----------------------------*/
  505. if ( ! isset($val['2']))
  506. {
  507. $val['2'] = '';
  508. }
  509. $data[$key] = ($data[$key] == '') ? $val['2'] : $data[$key];
  510. foreach ($val['1'] as $k => $v)
  511. {
  512. $selected = ($k == $data[$key]) ? 1 : '';
  513. if (sizeof($val['1']) == 1)
  514. {
  515. $r .= $DSP->input_checkbox($key, $k, $selected);
  516. }
  517. else
  518. {
  519. $r .= $DSP->qdiv('publishPad', $DSP->input_checkbox($key, $k, $selected).' '.$LANG->line($v));
  520. }
  521. }
  522. }
  523. elseif ($val['0'] == 't')
  524. {
  525. /** -----------------------------
  526. /** Textarea fields
  527. /** -----------------------------*/
  528. // The "kill_pipes" index instructs us to
  529. // turn pipes into newlines
  530. $data[$key] = ($data[$key] == '') ? $val['1'] : $data[$key];
  531. if (isset($val['2']['kill_pipes']) AND $val['2']['kill_pipes'] === TRUE)
  532. {
  533. $text = '';
  534. foreach (explode('|', $data[$key]) as $exp)
  535. {
  536. $text .= $exp.NL;
  537. }
  538. }
  539. else
  540. {
  541. $text = $data[$key];
  542. }
  543. $rows = (isset($val['2']['rows'])) ? $val['2']['rows'] : '15';
  544. $r .= $DSP->input_textarea($key, $text, $rows);
  545. }
  546. elseif ($val['0'] == 'f' || $val['0'] == 'sf')
  547. {
  548. switch($val['1'])
  549. {
  550. case 'new_table' :
  551. $i = 0;
  552. // Close current tables
  553. $r .= $DSP->table_c();
  554. $r .= $DSP->div_c();
  555. // Open new table
  556. $r .= $DSP->div('', '', $key);
  557. $r .= $DSP->table('tableBorder', '0', '', '100%');
  558. $r .= $DSP->tr();
  559. $r .= $DSP->td('tableHeadingAlt', '', '2');
  560. $r .= $LANG->line($val['2']);
  561. $r .= $DSP->td_c();
  562. $r .= $DSP->tr_c();
  563. break;
  564. }
  565. }
  566. }
  567. else
  568. {
  569. /** -----------------------------
  570. /** Text input fields
  571. /** -----------------------------*/
  572. $r .= $DSP->input_text($key, $data[$key], '20', '120', 'input', '100%');
  573. }
  574. $r .= $DSP->td_c();
  575. $r .= $DSP->tr_c();
  576. }
  577. $r .= $DSP->table_c();
  578. $r .= $DSP->div_c();
  579. $r .= $DSP->qdiv('itemWrapperTop', $DSP->input_submit($LANG->line('submit'), 'submit'));
  580. return $r;
  581. }
  582. /* END */
  583. /** -------------------------------------------
  584. /** Plugin Manager
  585. /** -------------------------------------------*/
  586. // Helper function used to sort plugins
  587. function _plugin_title_sorter($a, $b)
  588. {
  589. return strnatcasecmp($a['title'], $b['title']);
  590. }
  591. function plugin_manager($message = '')
  592. {
  593. global $DSP, $IN, $PREFS, $LANG, $FNS;
  594. if ( ! @include_once(PATH_LIB.'pclzip.lib.php'))
  595. {
  596. return $DSP->no_access_message('PclZip Library does not appear to be installed. It is required.');
  597. }
  598. $is_writable = (is_writable(PATH_PI) && $PREFS->ini('demo_date') == FALSE) ? TRUE : FALSE;
  599. $plugins = array();
  600. $info = array();
  601. if ($fp = @opendir(PATH_PI))
  602. {
  603. while (false !== ($file = readdir($fp)))
  604. {
  605. if ( preg_match("/^pi\.[a-z\_0-9]+?".preg_quote(EXT, '/')."$/", $file))
  606. {
  607. if ( ! @include_once(PATH_PI.$file))
  608. {
  609. continue;
  610. }
  611. $name = str_replace('pi.', '', $file);
  612. $name = str_replace(EXT, '', $name);
  613. $plugins[] = $name;
  614. $info[$name] = $plugin_info;
  615. }
  616. }
  617. closedir($fp);
  618. }
  619. if ( in_array('magpie', $plugins) && $PREFS->ini('demo_date') == FALSE)
  620. $r = '<div style="float: left; width: 69%; margin-right: 2%;">';
  621. else
  622. $r = '<div style="float: left; width: 100%;">';
  623. if ($is_writable)
  624. {
  625. $r .= $DSP->form_open(
  626. array(
  627. 'action' => 'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_remove_conf',
  628. 'name' => 'target',
  629. 'id' => 'target'
  630. )
  631. );
  632. $r .= $DSP->toggle();
  633. }
  634. if ($message != '')
  635. {
  636. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $message));
  637. }
  638. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  639. $DSP->tr().
  640. $DSP->td('tableHeading', ($is_writable) ? '97%' : '100%', '').
  641. count($plugins).' '.$LANG->line('plugin_installed').
  642. $DSP->td_c();
  643. if ($is_writable)
  644. {
  645. $r .= $DSP->td('tableHeading', '3%', '').
  646. $DSP->input_checkbox('toggleflag', '', '', "onclick=\"toggle(this);\"").
  647. $DSP->td_c();
  648. }
  649. $r .= $DSP->tr_c();
  650. if (count($plugins) == 0)
  651. {
  652. $r .= $DSP->tr().
  653. $DSP->td('tableCellTwo', '', '2').
  654. '<b>'.$LANG->line('no_plugins_exist').'</b>'.
  655. $DSP->td_c().
  656. $DSP->tr_c();
  657. }
  658. $i = 0;
  659. if (count($plugins) > 0)
  660. {
  661. foreach ($plugins as $plugin)
  662. {
  663. $version = '(v.'.trim($info[$plugin]['pi_version']).')';
  664. $update = '';
  665. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  666. $name = $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_info'.AMP.'name='.$plugin, $info[$plugin]['pi_name']));
  667. $description = $info[$plugin]['pi_description'];
  668. $r .= $DSP->tr();
  669. $r .= $DSP->table_qcell($style, $name.' '.$version.' '.$update.$DSP->br().$description, ($is_writable) ? '85%' : '100%');
  670. if ($is_writable)
  671. {
  672. $r .= $DSP->table_qcell($style, $DSP->input_checkbox('toggle[]', $plugin), '15%');
  673. }
  674. $r .= $DSP->tr_c();
  675. }
  676. }
  677. $r .= $DSP->table_c();
  678. if ($is_writable)
  679. {
  680. $r .= $DSP->div('itemWrapper', 'right')
  681. .$DSP->input_submit($LANG->line('plugin_remove'))
  682. .$DSP->div_c()
  683. .$DSP->form_close();
  684. }
  685. $r .= $DSP->div_c();
  686. /** -------------------------------------------
  687. /** Latest Plugin Table
  688. /** -------------------------------------------*/
  689. // Do we have the Magpie plugin so we can parse the EE plugin RSS feed?
  690. if (in_array('magpie', $plugins) && $PREFS->ini('demo_date') == FALSE)
  691. {
  692. $request = 'http://expressionengine.com/feeds/pluginlist/';
  693. $target = parse_url($request);
  694. $fp = @fsockopen($target['host'], 80, $errno, $errstr, 15);
  695. $code = '';
  696. if (is_resource($fp))
  697. {
  698. fputs ($fp,"GET " . $request . " HTTP/1.0\r\n" );
  699. fputs ($fp,"Host: " . $target['host'] . "\r\n" );
  700. fputs ($fp,"User-Agent: EE/EllisLab PHP/" . phpversion() . "\r\n\r\n");
  701. $getting_headers = true;
  702. while ( ! feof($fp))
  703. {
  704. $line = fgets($fp, 4096);
  705. if ($getting_headers == false)
  706. {
  707. $code .= $line;
  708. }
  709. elseif (trim($line) == '')
  710. {
  711. $getting_headers = false;
  712. }
  713. }
  714. @fclose($fp);
  715. }
  716. $plugins = new MagpieRSS($code);
  717. $i = 0;
  718. if (count($plugins->items) > 0)
  719. {
  720. // Example pagination: &perpage=10&page=10&sortby=alpha
  721. $paginate = '';
  722. $extra = ''; // Will hold sort method
  723. $total_rows = count($plugins->items);
  724. $perpage = ( ! $IN->GBL('perpage')) ? 10 : $IN->GBL('perpage');
  725. $page = ( ! $IN->GBL('page')) ? 0 : $IN->GBL('page');
  726. $sortby = ( ! $IN->GBL('sortby')) ? '' : $IN->GBL('sortby');
  727. $base = BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_manager';
  728. if ($sortby == 'alpha')
  729. {
  730. usort($plugins->items, array('Utilities', '_plugin_title_sorter'));
  731. $extra = AMP.'sortby=alpha';
  732. $link = $DSP->anchor($base, $LANG->line('plugin_by_date'));
  733. $title = $LANG->line('plugins').$DSP->qspan('defaultSmall', $LANG->line('plugin_by_letter').' : '.$link);
  734. }
  735. else
  736. {
  737. $link = $DSP->anchor($base.AMP.'sortby=alpha', $LANG->line('plugin_by_letter'));
  738. $title = $LANG->line('plugins').$DSP->qspan('defaultSmall', $LANG->line('plugin_by_date').' : '.$link);
  739. }
  740. $ten_plugins = array_slice($plugins->items, $page, $perpage-1);
  741. // Latest Plugins Table
  742. $r .= '<div style="float: left; width: 29%; clear: right;">';
  743. $r .= $DSP->table('tableBorder', '0', '10', '100%').
  744. $DSP->tr().
  745. $DSP->td('tableHeadingAlt', '', '').
  746. $title.
  747. $DSP->td_c().
  748. $DSP->tr_c();
  749. $curl_installed = ( ! extension_loaded('curl') || ! function_exists('curl_init')) ? FALSE : TRUE;
  750. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  751. foreach ($ten_plugins as $item)
  752. {
  753. $attr = explode('|', $item['dc']['subject']);
  754. $dl = $attr[0];
  755. $version = '(v.'.$attr[1].')';
  756. $require = ( ! $attr[2] ) ? '' : $DSP->br().$DSP->qspan('highlight', $LANG->line('plugin_requires').': '.$attr[2]);
  757. $name = $DSP->qspan('defaultBold', $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.$item['link'], $item['title']));
  758. $description = $FNS->word_limiter($item['description'], '20');
  759. $install = ( ! class_exists('PclZip') || ! $is_writable || ! $curl_installed) ? '' : $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_install'.AMP.'file='.$dl, '<span style=\'color:#009933;\'>'.$LANG->line('plugin_install').'</span>');
  760. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  761. $r .= $DSP->tr();
  762. $r .= $DSP->table_qcell($style, $name.' '.$version.$DSP->nbs().$require.$DSP->qdiv('itemWrapper', $description).$install, '60%');
  763. $r .= $DSP->tr_c();
  764. }
  765. $r .= $DSP->table_c();
  766. if ($total_rows > $perpage)
  767. {
  768. $paginate = $DSP->pager( BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_manager'.$extra.AMP.'perpage='.$perpage,
  769. $total_rows,
  770. $perpage,
  771. $page,
  772. 'page'
  773. );
  774. }
  775. $r .= $DSP->qdiv('itemWrapper', $paginate.BR.BR);
  776. $r .= $DSP->div_c();
  777. }
  778. }
  779. $DSP->title = $LANG->line('plugin_manager');
  780. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  781. $DSP->crumb_item($LANG->line('plugin_manager'));
  782. $DSP->body = $r;
  783. }
  784. /* END */
  785. /** -------------------------------------------
  786. /** Plugin Info
  787. /** -------------------------------------------*/
  788. function plugin_info()
  789. {
  790. global $IN, $DSP, $LANG, $FNS, $PREFS;
  791. // Basic security check
  792. if ( ! preg_match("/^[a-z0-9][\w.-]*$/i",$IN->GBL('name'))) return false;
  793. $name = $IN->GBL('name');
  794. if ( ! @include(PATH_PI.'pi.'.$name.EXT))
  795. {
  796. return $DSP->error_message('Unable to load the following plugin: '.$name.EXT);
  797. }
  798. $qm = ($PREFS->ini('force_query_string') == 'y') ? '' : '?';
  799. $DSP->title = ucwords(str_replace("_", " ", $name));
  800. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  801. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_manager', $LANG->line('plugin_manager'))).
  802. $DSP->crumb_item(ucwords(str_replace("_", " ", $name)));
  803. $i = 0;
  804. $r = $DSP->table('tableBorder', '0', '10', '100%').
  805. $DSP->tr().
  806. $DSP->td('tableHeading', '', '2').
  807. $LANG->line('plugin_information').
  808. $DSP->td_c().
  809. $DSP->tr_c();
  810. if ( ! isset($plugin_info) OR ! is_array($plugin_info))
  811. {
  812. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  813. $name = ucwords(str_replace("_", " ", $name));
  814. $r .= $DSP->tr();
  815. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $LANG->line('pi_name')), '30%');
  816. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $name), '70%');
  817. $r .= $DSP->tr_c();
  818. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  819. $r .= $DSP->tr();
  820. $r .= $DSP->td($style, '', '2').$DSP->qspan('default', $LANG->line('no_additional_info'));
  821. $r .= $DSP->td_c();
  822. $r .= $DSP->tr_c();
  823. }
  824. else
  825. {
  826. foreach ($plugin_info as $key => $val)
  827. {
  828. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  829. $item = ($LANG->line($key) != FALSE) ? $LANG->line($key) : ucwords(str_replace("_", " ", $key));
  830. if ($key == 'pi_author_url')
  831. {
  832. if (substr($val, 0, 4) != "http")
  833. $val = "http://".$val;
  834. $val = $DSP->anchor($FNS->fetch_site_index().$qm.'URL='.$val, $val, '', 1);
  835. }
  836. if ($key == 'pi_usage')
  837. $val = nl2br(htmlspecialchars($val));
  838. $r .= $DSP->tr();
  839. $r .= $DSP->table_qcell($style, $DSP->qspan('defaultBold', $item), '30%', 'top');
  840. $r .= $DSP->table_qcell($style, $DSP->qspan('default', $val), '70%');
  841. $r .= $DSP->tr_c();
  842. }
  843. }
  844. $r .= $DSP->table_c();
  845. $DSP->body = $r;
  846. }
  847. /* END */
  848. /** -------------------------------------------
  849. /** Plugin Extraction from ZIP file
  850. /** -------------------------------------------*/
  851. function plugin_install()
  852. {
  853. global $IN, $DSP, $LANG, $PREFS;
  854. if ($PREFS->ini('demo_date') != FALSE)
  855. {
  856. return $DSP->no_access_message();
  857. }
  858. if ( ! @include_once(PATH_LIB.'pclzip.lib.php'))
  859. {
  860. return $DSP->error_message($LANG->line('plugin_zlib_missing'));
  861. }
  862. if ( ! is_writable(PATH_PI))
  863. {
  864. return $DSP->error_message($LANG->line('plugin_folder_not_writable'));
  865. }
  866. if ( ! extension_loaded('curl') || ! function_exists('curl_init'))
  867. {
  868. return $DSP->error_message($LANG->line('plugin_no_curl_support'));
  869. }
  870. $file = $IN->GBL('file');
  871. $local_name = basename($file);
  872. $local_file = PATH_PI.$local_name;
  873. // Get the remote file
  874. $c = curl_init($file);
  875. curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
  876. // prevent a PHP warning on certain servers
  877. if (! ini_get('safe_mode') && ! ini_get('open_basedir'))
  878. {
  879. curl_setopt($c, CURLOPT_FOLLOWLOCATION, 1);
  880. }
  881. $code = curl_exec($c);
  882. curl_close($c);
  883. $file_info = pathinfo($local_file);
  884. if ($file_info['extension'] == 'txt' ) // Get rid of any notes/headers in the TXT file
  885. {
  886. $code = strstr($code, '<?php');
  887. }
  888. if ( ! $fp = fopen($local_file, 'wb'))
  889. {
  890. return $DSP->error_message($LANG->line('plugin_problem_creating_file'));
  891. }
  892. flock($fp, LOCK_EX);
  893. fwrite($fp, $code);
  894. flock($fp, LOCK_UN);
  895. fclose($fp);
  896. @chmod($local_file, 0777);
  897. // Check file information so we know what to do with it
  898. if ($file_info['extension'] == 'txt' ) // We've got a TXT file!
  899. {
  900. $new_file = basename($local_file, '.txt');
  901. if ( ! rename($local_file, PATH_PI.$new_file))
  902. {
  903. $message = $LANG->line('plugin_install_other');
  904. }
  905. else
  906. {
  907. @chmod($new_file, 0777);
  908. $message = $LANG->line('plugin_install_success');
  909. }
  910. }
  911. else if ($file_info['extension'] == 'zip' ) // We've got a ZIP file!
  912. {
  913. // Unzip and install plugin
  914. if (class_exists('PclZip'))
  915. {
  916. $zip = new PclZip($local_file);
  917. chdir(PATH_PI);
  918. $ok = @$zip->extract('');
  919. if ($ok)
  920. {
  921. $message = $LANG->line('plugin_install_success');
  922. unlink($local_file);
  923. }
  924. else
  925. {
  926. $message = $LANG->line('plugin_error_uncompress');
  927. }
  928. chdir(PATH);
  929. }
  930. else
  931. {
  932. $message = $LANG->line('plugin_error_no_zlib');
  933. }
  934. }
  935. else
  936. {
  937. $message = $LANG->line('plugin_install_other');
  938. }
  939. return Utilities::plugin_manager($message);
  940. }
  941. /* END */
  942. /** -------------------------------------------
  943. /** Plugin Removal Confirmation
  944. /** -------------------------------------------*/
  945. function plugin_remove_confirm()
  946. {
  947. global $IN, $DSP, $LANG, $PREFS;
  948. if ($PREFS->ini('demo_date') != FALSE)
  949. {
  950. return $DSP->no_access_message();
  951. }
  952. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_remove'));
  953. $i = 0;
  954. foreach ($_POST as $key => $val)
  955. {
  956. if (strstr($key, 'toggle') AND ! is_array($val))
  957. {
  958. $r .= $DSP->input_hidden('deleted[]', $val);
  959. $i++;
  960. }
  961. }
  962. $message = ($i == 1) ? 'plugin_single_confirm' : 'plugin_multiple_confirm';
  963. $r .= $DSP->qdiv('alertHeading', $LANG->line('plugin_delete_confirm'))
  964. .$DSP->div('box')
  965. .$DSP->qdiv('itemWrapper', '<b>'.$LANG->line($message).'</b>');
  966. $r .= $DSP->qdiv('itemWrapper', $DSP->qdiv('alert', $LANG->line('action_can_not_be_undone')))
  967. .$DSP->qdiv('itemWrapper', BR.$DSP->input_submit($LANG->line('deinstall')).BR)
  968. .$DSP->div_c()
  969. .$DSP->form_close();
  970. $DSP->title = $LANG->line('plugin_delete_confirm');
  971. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  972. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_manager', $LANG->line('plugin_manager'))).
  973. $DSP->crumb_item($LANG->line('plugin_delete_confirm'));
  974. $DSP->body = $r;
  975. }
  976. /** -------------------------------------------
  977. /** Plugin Removal
  978. /** -------------------------------------------*/
  979. function plugin_remove()
  980. {
  981. global $IN, $DSP, $LANG, $PREFS;
  982. if ($PREFS->ini('demo_date') != FALSE)
  983. {
  984. return $DSP->no_access_message();
  985. }
  986. $deleted = $IN->GBL('deleted');
  987. $message = '';
  988. $style = '';
  989. $i = 0;
  990. $DSP->title = $LANG->line('plugin_removal');
  991. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  992. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=plugin_manager', $LANG->line('plugin_manager'))).
  993. $DSP->crumb_item($LANG->line('plugin_removal'));
  994. $r = $DSP->table('tableBorder', '0', '10', '100%').
  995. $DSP->tr().
  996. $DSP->td('tableHeading', '', '').
  997. $LANG->line('plugin_removal_status').
  998. $DSP->td_c().
  999. $DSP->tr_c();
  1000. foreach ( $deleted as $name )
  1001. {
  1002. $style = ($i++ % 2) ? 'tableCellOne' : 'tableCellTwo';
  1003. if (unlink(PATH_PI.'pi.'.$name.'.php'))
  1004. $message = $LANG->line('plugin_removal_success').' '.ucwords(str_replace("_", " ", $name));
  1005. else
  1006. $message = $LANG->line('plugin_removal_error').' '.ucwords(str_replace("_", " ", $name)).'.';
  1007. $r .= $DSP->tr();
  1008. $r .= $DSP->table_qcell($style, $DSP->qdiv('itemWrapper', $DSP->qdiv('highlight', $message)), '100%');
  1009. $r .= $DSP->tr_c();
  1010. }
  1011. $r .= $DSP->table_c();
  1012. $DSP->body = $r;
  1013. }
  1014. /* END */
  1015. /** -------------------------------------------
  1016. /** Disable Extensions Confirmation
  1017. /** -------------------------------------------*/
  1018. function toggle_extension_confirm()
  1019. {
  1020. global $IN, $DSP, $LANG;
  1021. // Basic security check
  1022. if ($IN->GBL('name') !== FALSE && ! preg_match("/^[a-z0-9][\w.-]*$/i",$IN->GBL('name'))) return false;
  1023. $r = $DSP->form_open(array('action' => 'C=admin'.AMP.'M=utilities'.AMP.'P=toggle_extension'));
  1024. if ($IN->GBL('which') == 'enable')
  1025. {
  1026. $message = ($IN->GBL('name') !== FALSE) ? 'enable_extension_conf' : 'enable_extensions_conf';
  1027. $r .= $DSP->input_hidden('which', 'enable');
  1028. }
  1029. else
  1030. {
  1031. $message = ($IN->GBL('name') !== FALSE) ? 'disable_extension_conf' : 'disable_extensions_conf';
  1032. $r .= $DSP->input_hidden('which', 'disable');
  1033. }
  1034. $r .= $DSP->input_hidden('name', ($IN->GBL('name') !== FALSE) ? $IN->GBL('name') : '');
  1035. $r .= $DSP->qdiv('alertHeading', $LANG->line($message))
  1036. .$DSP->div('box')
  1037. .$DSP->qdiv('itemWrapper', '<b>'.$LANG->line('toggle_extension_confirmation').'</b>');
  1038. $r .= $DSP->qdiv('itemWrapper', BR.$DSP->input_submit($LANG->line('submit')).BR)
  1039. .$DSP->div_c()
  1040. .$DSP->form_close();
  1041. $DSP->title = $LANG->line('extensions_manager');
  1042. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  1043. $DSP->crumb_item($DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=extensions_manager', $LANG->line('extensions_manager'))).
  1044. $DSP->crumb_item($LANG->line($message));
  1045. $DSP->body = $r;
  1046. }
  1047. /** -------------------------------------------
  1048. /** Toggle Extension/s
  1049. /** -------------------------------------------*/
  1050. function toggle_extension()
  1051. {
  1052. global $IN, $FNS, $DB, $PREFS;
  1053. $message = '';
  1054. if ($IN->GBL('name') !== FALSE && $IN->GBL('name') != '')
  1055. {
  1056. // Basic security check
  1057. if ( ! preg_match("/^[a-z0-9][\w.-]*$/i",$IN->GBL('name'))) return false;
  1058. // Disable/Enable Single Extension
  1059. if ($IN->GBL('which') == 'enable')
  1060. {
  1061. // Check if the Extension is already installed and just disabled
  1062. // If so we just turn it back on. If not, we have to activate
  1063. // the extension. We have the enabled field so that if someone
  1064. // disables a parameter we can still have the extension's settings
  1065. // in the database and not lost to the ether.
  1066. $query = $DB->query("SELECT COUNT(*) AS count FROM exp_extensions WHERE class = '".$DB->escape_str(ucfirst($IN->GBL('name')))."'");
  1067. if ($query->row['count'] == 0)
  1068. {
  1069. if ( ! class_exists(ucfirst($IN->GBL('name'))))
  1070. {
  1071. include(PATH_EXT.'ext.'.$IN->GBL('name').EXT);
  1072. }
  1073. if (class_exists(ucfirst($IN->GBL('name'))))
  1074. {
  1075. $class_name = ucfirst($IN->GBL('name'));
  1076. $OBJ = new $class_name();
  1077. if (method_exists($OBJ, 'activate_extension') === TRUE)
  1078. {
  1079. $activate = $OBJ->activate_extension();
  1080. }
  1081. }
  1082. }
  1083. else
  1084. {
  1085. $DB->query("UPDATE exp_extensions SET enabled = 'y' WHERE class = '".$DB->escape_str(ucfirst($IN->GBL('name')))."'");
  1086. }
  1087. }
  1088. else
  1089. {
  1090. $DB->query("UPDATE exp_extensions SET enabled = 'n' WHERE class = '".$DB->escape_str(ucfirst($IN->GBL('name')))."'");
  1091. if ( ! class_exists(ucfirst($IN->GBL('name'))))
  1092. {
  1093. include(PATH_EXT.'ext.'.$IN->GBL('name').EXT);
  1094. }
  1095. if (class_exists(ucfirst($IN->GBL('name'))))
  1096. {
  1097. $class_name = ucfirst($IN->GBL('name'));
  1098. $OBJ = new $class_name();
  1099. if (method_exists($OBJ, 'disable_extension') === TRUE)
  1100. {
  1101. $disable = $OBJ->disable_extension();
  1102. }
  1103. }
  1104. }
  1105. }
  1106. else
  1107. {
  1108. // Disable/Enable All Extensions
  1109. if ($IN->GBL('which') == 'enable')
  1110. {
  1111. Admin::update_config_file(array('allow_extensions' => "y"));
  1112. }
  1113. else
  1114. {
  1115. Admin::update_config_file(array('allow_extensions' => "n"));
  1116. }
  1117. }
  1118. $FNS->redirect(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=extensions_manager');
  1119. exit;
  1120. }
  1121. /* END */
  1122. /** -------------------------------------------
  1123. /** SQL Manager
  1124. /** -------------------------------------------*/
  1125. function sql_info()
  1126. {
  1127. global $DB, $DSP, $PREFS, $LOC, $LANG;
  1128. $i = 0;
  1129. $style_one = 'tableCellOne';
  1130. $style_two = 'tableCellTwo';
  1131. $query = $DB->query("SELECT version() AS ver");
  1132. $DSP->title = $LANG->line('utilities');
  1133. $DSP->crumb = $DSP->anchor(BASE.AMP.'C=admin'.AMP.'area=utilities', $LANG->line('utilities')).
  1134. $DSP->crumb_item($LANG->line('sql_manager'));
  1135. $DSP->body = $DSP->qdiv('tableHeading', $LANG->line('sql_manager'));
  1136. /** -----------------------------
  1137. /** Table Header
  1138. /** -----------------------------*/
  1139. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  1140. $DSP->tr().
  1141. $DSP->table_qcell('tableHeadingAlt',
  1142. array(
  1143. $LANG->line('sql_info'),
  1144. $LANG->line('value')
  1145. )
  1146. ).
  1147. $DSP->tr_c();
  1148. /** -------------------------------------------
  1149. /** Database Type
  1150. /** -------------------------------------------*/
  1151. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1152. array(
  1153. $DSP->qspan('defaultBold', $LANG->line('database_type')),
  1154. $PREFS->ini('db_type')
  1155. )
  1156. );
  1157. /** -------------------------------------------
  1158. /** SQL Version
  1159. /** -------------------------------------------*/
  1160. $query = $DB->query("SELECT version() AS ver");
  1161. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1162. array(
  1163. $DSP->qspan('defaultBold', $LANG->line('sql_version')),
  1164. $query->row['ver']
  1165. )
  1166. );
  1167. $DB->fetch_fields = TRUE;
  1168. $query = $DB->query("SHOW TABLE STATUS FROM `".$PREFS->ini('db_name')."`");
  1169. $totsize = 0;
  1170. $records = 0;
  1171. $prelen = strlen($DB->prefix);
  1172. foreach ($query->result as $val)
  1173. {
  1174. if (strncmp($val['Name'], $DB->prefix, $prelen) != 0)
  1175. {
  1176. continue;
  1177. }
  1178. $totsize += ($val['Data_length'] + $val['Index_length']);
  1179. $records += $val['Rows'];
  1180. }
  1181. /** -------------------------------------------
  1182. /** Database Records
  1183. /** -------------------------------------------*/
  1184. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1185. array(
  1186. $DSP->qspan('defaultBold', $LANG->line('records')),
  1187. $records
  1188. )
  1189. );
  1190. /** -------------------------------------------
  1191. /** Database Size
  1192. /** -------------------------------------------*/
  1193. $size = Utilities::byte_format($totsize);
  1194. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1195. array(
  1196. $DSP->qspan('defaultBold', $LANG->line('database_size')),
  1197. $size['0'].' '.$size['1']
  1198. )
  1199. );
  1200. /** -------------------------------------------
  1201. /** Database Uptime
  1202. /** -------------------------------------------*/
  1203. $query = $DB->query("SHOW STATUS");
  1204. $uptime = '';
  1205. $queries = '';
  1206. foreach ($query->result as $key => $val)
  1207. {
  1208. foreach ($val as $v)
  1209. {
  1210. if (preg_match("#^uptime#i", $v))
  1211. {
  1212. $uptime = $key;
  1213. }
  1214. if (preg_match("#^questions#i", $v))
  1215. {
  1216. $queries = $key;
  1217. }
  1218. }
  1219. }
  1220. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1221. array(
  1222. $DSP->qspan('defaultBold', $LANG->line('database_uptime')),
  1223. $LOC->format_timespan($query->result[$uptime]['Value'])
  1224. )
  1225. );
  1226. /** -------------------------------------------
  1227. /** Total Server Queries
  1228. /** -------------------------------------------*/
  1229. /*
  1230. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1231. array(
  1232. $DSP->qspan('defaultBold', $LANG->line('total_queries')),
  1233. number_format($query->result[$queries]['Value'])
  1234. )
  1235. );
  1236. */
  1237. $DSP->body .= $DSP->table_c();
  1238. /** -------------------------------------------
  1239. /** SQL Utilities
  1240. /** -------------------------------------------*/
  1241. $DSP->body .= $DSP->table('tableBorder', '0', '0', '100%').
  1242. $DSP->tr().
  1243. $DSP->table_qcell('tableHeading',
  1244. array(
  1245. $LANG->line('sql_utilities'),
  1246. )
  1247. ).
  1248. $DSP->tr_c();
  1249. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1250. array(
  1251. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=view_database', $LANG->line('view_database')))
  1252. )
  1253. );
  1254. /*
  1255. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1256. array(
  1257. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=sql_backup', $LANG->line('sql_backup')))
  1258. )
  1259. );
  1260. */
  1261. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1262. array(
  1263. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=sql_query', $LANG->line('sql_query')))
  1264. )
  1265. );
  1266. $DSP->body .= $DSP->table_qrow( ($i++ % 2) ? $style_one : $style_two,
  1267. array(
  1268. $DSP->qspan('defaultBold', $DSP->anchor(BASE.AMP.'C=admin'.AMP.'M=utilities'.AMP.'P=sql_status', $LANG->line('sql_status')))
  1269. )
  1270. );
  1271. $DSP->body .= $DSP->table_qrow( ($

Large files files are truncated, but you can click here to view the full file