plugins/SpecialAdmin.php
changeset 430 ec90736b9cb9
parent 407 35d94240a197
child 458 c433348f3628
equal deleted inserted replaced
426:f5718d7c2a6a 430:ec90736b9cb9
     8 Author URI: http://enanocms.org/
     8 Author URI: http://enanocms.org/
     9 */
     9 */
    10 
    10 
    11 /*
    11 /*
    12  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    12  * Enano - an open-source CMS capable of wiki functions, Drupal-like sidebar blocks, and everything in between
    13  * Version 1.1.1
    13  * Version 1.1.2 (Caoineag alpha 2)
    14  * Copyright (C) 2006-2007 Dan Fuhry
    14  * Copyright (C) 2006-2007 Dan Fuhry
    15  *
    15  *
    16  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    16  * This program is Free Software; you can redistribute and/or modify it under the terms of the GNU General Public License
    17  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    17  * as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
    18  *
    18  *
    45 require(ENANO_ROOT . '/plugins/admin/PageGroups.php');
    45 require(ENANO_ROOT . '/plugins/admin/PageGroups.php');
    46 require(ENANO_ROOT . '/plugins/admin/GroupManager.php');
    46 require(ENANO_ROOT . '/plugins/admin/GroupManager.php');
    47 require(ENANO_ROOT . '/plugins/admin/SecurityLog.php');
    47 require(ENANO_ROOT . '/plugins/admin/SecurityLog.php');
    48 require(ENANO_ROOT . '/plugins/admin/UserManager.php');
    48 require(ENANO_ROOT . '/plugins/admin/UserManager.php');
    49 require(ENANO_ROOT . '/plugins/admin/LangManager.php');
    49 require(ENANO_ROOT . '/plugins/admin/LangManager.php');
       
    50 require(ENANO_ROOT . '/plugins/admin/ThemeManager.php');
    50 
    51 
    51 // For convenience and nothing more.
    52 // For convenience and nothing more.
    52 function acp_start_form()
    53 function acp_start_form()
    53 {
    54 {
    54   global $db, $session, $paths, $template, $plugins; // Common objects
    55   global $db, $session, $paths, $template, $plugins; // Common objects
   935         $db->_die();
   936         $db->_die();
   936       setConfig('file_history', '0');
   937       setConfig('file_history', '0');
   937     }
   938     }
   938     if(file_exists($_POST['imagemagick_path']) && $_POST['imagemagick_path'] != getConfig('imagemagick_path'))
   939     if(file_exists($_POST['imagemagick_path']) && $_POST['imagemagick_path'] != getConfig('imagemagick_path'))
   939     {
   940     {
       
   941       if ( defined('ENANO_DEMO_MODE') )
       
   942         // Hackish but safe.
       
   943         $_POST['imagemagick_path'] = '/usr/bin/convert';
   940       $old = getConfig('imagemagick_path');
   944       $old = getConfig('imagemagick_path');
   941       $oldnew = "{$old}||{$_POST['imagemagick_path']}";
   945       $oldnew = "{$old}||{$_POST['imagemagick_path']}";
   942       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES(\'security\',\'magick_path\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\',\'' . $db->escape($oldnew) . '\');');
   946       $q = $db->sql_query('INSERT INTO '.table_prefix.'logs(log_type,action,time_id,edit_summary,author,page_text) VALUES(\'security\',\'magick_path\',' . time() . ',\'' . $db->escape($_SERVER['REMOTE_ADDR']) . '\',\'' . $db->escape($session->username) . '\',\'' . $db->escape($oldnew) . '\');');
   943       if ( !$q )
   947       if ( !$q )
   944         $db->_die();
   948         $db->_die();
  1391 
  1395 
  1392 /*
  1396 /*
  1393  * Admin:PageEditor sources are in /plugins/admin/PageEditor.php.
  1397  * Admin:PageEditor sources are in /plugins/admin/PageEditor.php.
  1394  */
  1398  */
  1395 
  1399 
  1396 function page_Admin_ThemeManager() 
  1400 /*
  1397 {
  1401  * Admin:ThemeManager sources are in /plugins/admin/ThemeManager.php.
  1398   
  1402  */
  1399   global $db, $session, $paths, $template, $plugins; // Common objects
       
  1400   global $lang;
       
  1401   if ( $session->auth_level < USER_LEVEL_ADMIN || $session->user_level < USER_LEVEL_ADMIN )
       
  1402   {
       
  1403     $login_link = makeUrlNS('Special', 'Login/' . $paths->nslist['Special'] . 'Administration', 'level=' . USER_LEVEL_ADMIN, true);
       
  1404     echo '<h3>' . $lang->get('adm_err_not_auth_title') . '</h3>';
       
  1405     echo '<p>' . $lang->get('adm_err_not_auth_body', array( 'login_link' => $login_link )) . '</p>';
       
  1406     return;
       
  1407   }
       
  1408   
       
  1409   
       
  1410   // Get the list of styles in the themes/ dir
       
  1411   $h = opendir('./themes');
       
  1412   $l = Array();
       
  1413   if(!$h) die('Error opening directory "./themes" for reading.');
       
  1414   while(false !== ($n = readdir($h))) {
       
  1415     if($n != '.' && $n != '..' && is_dir('./themes/'.$n))
       
  1416       $l[] = $n;
       
  1417   }
       
  1418   closedir($h);
       
  1419   echo('
       
  1420   <h3>Theme Management</h3>
       
  1421    <p>Install, uninstall, and manage Enano themes.</p>
       
  1422   ');
       
  1423   if(isset($_POST['disenable'])) {
       
  1424     $q = 'SELECT enabled FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
       
  1425     $s = $db->sql_query($q);
       
  1426     if(!$s) die('Error selecting enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1427     $r = $db->fetchrow_num($s);
       
  1428     $db->free_result();
       
  1429     if($r[0] == 1) $e = 0;
       
  1430     else $e = 1;
       
  1431     $s=true;
       
  1432     if($e==0)
       
  1433     {
       
  1434       $c = $db->sql_query('SELECT * FROM '.table_prefix.'themes WHERE enabled=1');
       
  1435       if(!$c) $db->_die('The backup check for having at least on theme enabled failed.');
       
  1436       if($db->numrows() <= 1) { echo '<div class="warning-box">You cannot disable the last remaining theme.</div>'; $s=false; }
       
  1437     }
       
  1438     $db->free_result();
       
  1439     if($s) {
       
  1440     $q = 'UPDATE '.table_prefix.'themes SET enabled='.$e.' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
       
  1441     $a = $db->sql_query($q);
       
  1442     if(!$a) die('Error updating enabled/disabled state value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1443     else echo('<div class="info-box">The theme "'.$_POST['theme_id'].'" has been  '. ( ( $e == '1' ) ? 'enabled' : 'disabled' ).'.</div>');
       
  1444     }
       
  1445   }
       
  1446   elseif(isset($_POST['edit'])) {
       
  1447     
       
  1448     $dir = './themes/'.$_POST['theme_id'].'/css/';
       
  1449     $list = Array();
       
  1450     // Open a known directory, and proceed to read its contents
       
  1451     if (is_dir($dir)) {
       
  1452       if ($dh = opendir($dir)) {
       
  1453         while (($file = readdir($dh)) !== false) {
       
  1454           if(preg_match('#^(.*?)\.css$#is', $file) && $file != '_printable.css') {
       
  1455             $list[$file] = capitalize_first_letter(substr($file, 0, strlen($file)-4));
       
  1456           }
       
  1457         }
       
  1458         closedir($dh);
       
  1459       }
       
  1460     }
       
  1461     $lk = array_keys($list);
       
  1462     
       
  1463     $q = 'SELECT theme_name,default_style FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
       
  1464     $s = $db->sql_query($q);
       
  1465     if(!$s) die('Error selecting name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1466     $r = $db->fetchrow_num($s);
       
  1467     $db->free_result();
       
  1468     acp_start_form();
       
  1469     echo('<div class="question-box">
       
  1470           Theme name displayed to users: <input type="text" name="name" value="'.$r[0].'" /><br /><br />
       
  1471           Default stylesheet: <select name="defaultcss">');
       
  1472     foreach ($lk as $l)
       
  1473     {
       
  1474       if($r[1] == $l) $v = ' selected="selected"';
       
  1475       else $v = '';
       
  1476       echo "<option value='{$l}'$v>{$list[$l]}</option>";
       
  1477     }
       
  1478     echo('</select><br /><br />
       
  1479           <input type="submit" name="editsave" value="OK" /><input type="hidden" name="theme_id" value="'.$_POST['theme_id'].'" />
       
  1480           </div>');
       
  1481     echo('</form>');
       
  1482   }
       
  1483   elseif(isset($_POST['editsave'])) {
       
  1484     $q = 'UPDATE '.table_prefix.'themes SET theme_name=\'' . $db->escape($_POST['name']) . '\',default_style=\''.$db->escape($_POST['defaultcss']).'\' WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
       
  1485     $s = $db->sql_query($q);
       
  1486     if(!$s) die('Error updating name value: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1487     else echo('<div class="info-box">Theme data updated.</div>');
       
  1488   }
       
  1489   elseif(isset($_POST['up'])) {
       
  1490     // If there is only one theme or if the selected theme is already at the top, do nothing
       
  1491     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
       
  1492     $s = $db->sql_query($q);
       
  1493     if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1494     $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
       
  1495     $sn = $db->sql_query($q);
       
  1496     if(!$sn) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1497     $r = $db->fetchrow_num($sn);
       
  1498     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == 1 /* ...and check if this theme is already at the top */ ) { echo('<div class="warning-box">This theme is already at the top of the list, or there is only one theme installed.</div>'); } else {
       
  1499       // Get the order IDs of the selected theme and the theme before it
       
  1500       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\'' . $db->escape($_POST['theme_id']) . '\'';
       
  1501       $s = $db->sql_query($q);
       
  1502       if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1503       $r = $db->fetchrow_num($s);
       
  1504       $r = $r[0];
       
  1505       $rb = $r - 1;
       
  1506       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
       
  1507       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1508       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1509       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1510       echo('<div class="info-box">Theme moved up.</div>');
       
  1511     }
       
  1512     $db->free_result($s);
       
  1513     $db->free_result($sn);
       
  1514   }
       
  1515   elseif(isset($_POST['down'])) {
       
  1516     // If there is only one theme or if the selected theme is already at the top, do nothing
       
  1517     $q = 'SELECT theme_order FROM '.table_prefix.'themes ORDER BY theme_order;';
       
  1518     $s = $db->sql_query($q);
       
  1519     if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1520     $r = $db->fetchrow_num($s);
       
  1521     if( /* check for only one theme... */ $db->numrows($s) < 2 || $r[0] == $db->numrows($s) /* ...and check if this theme is already at the bottom */ ) { echo('<div class="warning-box">This theme is already at the bottom of the list, or there is only one theme installed.</div>'); } else {
       
  1522       // Get the order IDs of the selected theme and the theme before it
       
  1523       $q = 'SELECT theme_order FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\'';
       
  1524       $s = $db->sql_query($q);
       
  1525       if(!$s) die('Error selecting order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1526       $r = $db->fetchrow_num($s);
       
  1527       $r = $r[0];
       
  1528       $rb = $r + 1;
       
  1529       // Thank God for jEdit's rectangular selection and the ablity to edit multiple lines at the same time ;)
       
  1530       $q = 'UPDATE '.table_prefix.'themes SET theme_order=0 WHERE theme_order='.$rb.'';      /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1531       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$rb.' WHERE theme_order='.$r.''; /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1532       $q = 'UPDATE '.table_prefix.'themes SET theme_order='.$r.' WHERE theme_order=0';       /* Check for errors... <sigh> */ $s = $db->sql_query($q); if(!$s) die('Error updating order information: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1533       echo('<div class="info-box">Theme moved down.</div>');
       
  1534     }
       
  1535   }
       
  1536   else if(isset($_POST['uninstall'])) 
       
  1537   {
       
  1538     $q = 'SELECT * FROM '.table_prefix.'themes;';
       
  1539     $s = $db->sql_query($q);
       
  1540     if ( !$s )
       
  1541     {
       
  1542       die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1543     }
       
  1544     $n = $db->numrows($s);
       
  1545     $db->free_result();
       
  1546     
       
  1547     if ( $_POST['theme_id'] == 'oxygen' )
       
  1548     {
       
  1549       echo '<div class="error-box">The Oxygen theme is used by Enano for installation, upgrades, and error messages, and cannot be uninstalled.</div>';
       
  1550     }
       
  1551     else
       
  1552     {
       
  1553       if($n < 2)
       
  1554       {
       
  1555         echo '<div class="error-box">The theme could not be uninstalled because it is the only theme left.</div>';
       
  1556       }
       
  1557       else
       
  1558       {
       
  1559         $q = 'DELETE FROM '.table_prefix.'themes WHERE theme_id=\''.$db->escape($_POST['theme_id']).'\' LIMIT 1;';
       
  1560         $s = $db->sql_query($q);
       
  1561         if ( !$s )
       
  1562         {
       
  1563           die('Error deleting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1564         }
       
  1565         else
       
  1566         {
       
  1567           echo('<div class="info-box">Theme uninstalled.</div>');
       
  1568         }
       
  1569       }
       
  1570     }
       
  1571   }
       
  1572   elseif(isset($_POST['install'])) {
       
  1573     $q = 'SELECT theme_id FROM '.table_prefix.'themes;';
       
  1574     $s = $db->sql_query($q);
       
  1575     if(!$s) die('Error getting theme count: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1576     $n = $db->numrows($s);
       
  1577     $n++;
       
  1578     $theme_id = $_POST['theme_id'];
       
  1579     $theme = Array();
       
  1580     include('./themes/'.$theme_id.'/theme.cfg');
       
  1581     if ( !isset($theme['theme_id']) )
       
  1582     {
       
  1583       echo '<div class="error-box">Could not load theme.cfg (theme metadata file)</div>';
       
  1584     }
       
  1585     else
       
  1586     {
       
  1587       $default_style = false;
       
  1588       if ( $dh = opendir('./themes/' . $theme_id . '/css') )
       
  1589       {
       
  1590         while ( $file = readdir($dh) )
       
  1591         {
       
  1592           if ( $file != '_printable.css' && preg_match('/\.css$/i', $file) )
       
  1593           {
       
  1594             $default_style = $file;
       
  1595             break;
       
  1596           }
       
  1597         }
       
  1598         closedir($dh);
       
  1599       }
       
  1600       else
       
  1601       {
       
  1602         die('The /css subdirectory could not be located in the theme\'s directory');
       
  1603       }
       
  1604       
       
  1605       if ( $default_style )
       
  1606       {
       
  1607         $q = 'INSERT INTO '.table_prefix.'themes(theme_id,theme_name,theme_order,enabled,default_style) VALUES(\''.$db->escape($theme['theme_id']).'\', \''.$db->escape($theme['theme_name']).'\', '.$n.', 1, \'' . $db->escape($default_style) . '\')';
       
  1608         $s = $db->sql_query($q);
       
  1609         if(!$s) die('Error inserting theme data: '.$db->get_error().'<br /><u>SQL:</u><br />'.$q);
       
  1610         else echo('<div class="info-box">Theme "'.$theme['theme_name'].'" installed.</div>');
       
  1611       }
       
  1612       else
       
  1613       {
       
  1614         echo '<div class="error-box">Could not determine the default style for the theme.</div>';
       
  1615       }
       
  1616     }
       
  1617   }
       
  1618   echo('
       
  1619   <h3>Currently installed themes</h3>
       
  1620     <form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post">
       
  1621     <p>
       
  1622       <select name="theme_id">
       
  1623         ');
       
  1624         $q = 'SELECT theme_id,theme_name,enabled FROM '.table_prefix.'themes ORDER BY theme_order';
       
  1625         $s = $db->sql_query($q);
       
  1626         if(!$s) die('Error selecting theme data: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
       
  1627         while ( $r = $db->fetchrow_num($s) ) {
       
  1628           if($r[2] < 1) $r[1] .= ' (disabled)';
       
  1629           echo('<option value="'.$r[0].'">'.$r[1].'</option>');
       
  1630         }
       
  1631         $db->free_result();
       
  1632         echo('
       
  1633         </select> <input type="submit" name="disenable" value="Enable/Disable" /> <input type="submit" name="edit" value="Change settings" /> <input type="submit" name="up" value="Move up" /> <input type="submit" name="down" value="Move down" /> <input type="submit" name="uninstall" value="Uninstall" style="color: #DD3300; font-weight: bold;" />
       
  1634       </p>
       
  1635     </form>
       
  1636     <h3>Install a new theme</h3>
       
  1637   ');
       
  1638     $theme = Array();
       
  1639     $obb = '';
       
  1640     for($i=0;$i<sizeof($l);$i++) {
       
  1641       if(is_file('./themes/'.$l[$i].'/theme.cfg') && file_exists('./themes/'.$l[$i].'/theme.cfg')) {
       
  1642         include('./themes/'.$l[$i].'/theme.cfg');
       
  1643         $q = 'SELECT * FROM '.table_prefix.'themes WHERE theme_id=\''.$theme['theme_id'].'\'';
       
  1644         $s = $db->sql_query($q);
       
  1645         if(!$s) die('Error selecting list of currently installed themes: '.$db->get_error().'<br /><u>Attempted SQL:</u><br />'.$q);
       
  1646         if($db->numrows($s) < 1) {
       
  1647           $obb .= '<option value="'.$theme['theme_id'].'">'.$theme['theme_name'].'</option>';
       
  1648         }
       
  1649         $db->free_result();
       
  1650       }
       
  1651     }
       
  1652     if($obb != '') {
       
  1653       echo('<form action="'.makeUrl($paths->nslist['Special'].'Administration', 'module='.$paths->cpage['module']).'" method="post"><p>');
       
  1654       echo('<select name="theme_id">');
       
  1655       echo($obb);
       
  1656       echo('</select>');
       
  1657       echo('
       
  1658       <input type="submit" name="install" value="Install this theme" />
       
  1659       </p></form>');
       
  1660     } else echo('<p>All themes are currently installed.</p>');
       
  1661 }
       
  1662 
  1403 
  1663 /*
  1404 /*
  1664  * Admin:GroupManager sources are in /plugins/admin/GroupManager.php.
  1405  * Admin:GroupManager sources are in /plugins/admin/GroupManager.php.
  1665  */
  1406  */
  1666 
  1407