| 
      1
     | 
    
      <?php
 
     | 
  
  
    | 
      2
     | 
    
      /**
 
     | 
  
  
    | 
      3
     | 
    
       *
 
     | 
  
  
    | 
      4
     | 
    
       * @category        admin
 
     | 
  
  
    | 
      5
     | 
    
       * @package         modules
 
     | 
  
  
    | 
      6
     | 
    
       * @author          WebsiteBaker Project
 
     | 
  
  
    | 
      7
     | 
    
       * @copyright       Ryan Djurovich
 
     | 
  
  
    | 
      8
     | 
    
       * @copyright       WebsiteBaker Org. e.V.
 
     | 
  
  
    | 
      9
     | 
    
       * @link            http://websitebaker.org/
 
     | 
  
  
    | 
      10
     | 
    
       * @license         http://www.gnu.org/licenses/gpl.html
 
     | 
  
  
    | 
      11
     | 
    
       * @platform        WebsiteBaker 2.8.3
 
     | 
  
  
    | 
      12
     | 
    
       * @requirements    PHP 5.3.6 and higher
 
     | 
  
  
    | 
      13
     | 
    
       * @version         $Id: uninstall.php 2 2017-07-02 15:14:29Z Manuela $
 
     | 
  
  
    | 
      14
     | 
    
       * @filesource      $HeadURL: svn://isteam.dynxs.de/wb/2.10.x/trunk/admin/modules/uninstall.php $
 
     | 
  
  
    | 
      15
     | 
    
       * @lastmodified    $Date: 2017-07-02 17:14:29 +0200 (Sun, 02 Jul 2017) $
 
     | 
  
  
    | 
      16
     | 
    
       *
 
     | 
  
  
    | 
      17
     | 
    
       */
 
     | 
  
  
    | 
      18
     | 
    
      
 
     | 
  
  
    | 
      19
     | 
    
      // Include config file and admin class file
 
     | 
  
  
    | 
      20
     | 
    
      if ( !defined( 'WB_PATH' ) ){ require( dirname(dirname((__DIR__))).'/config.php' ); }
     | 
  
  
    | 
      21
     | 
    
      if ( !class_exists('admin', false) ) { require(WB_PATH.'/framework/class.admin.php'); }
     | 
  
  
    | 
      22
     | 
    
      // Include the WB functions file
 
     | 
  
  
    | 
      23
     | 
    
      if ( !function_exists( 'get_modul_version' ) ) { require(WB_PATH.'/framework/functions.php'); }
     | 
  
  
    | 
      24
     | 
    
      
 
     | 
  
  
    | 
      25
     | 
    
      if (!function_exists("replace_all")) {
     | 
  
  
    | 
      26
     | 
    
          function replace_all ($aStr = "", &$aArray ) {
     | 
  
  
    | 
      27
     | 
    
              foreach($aArray as $k=>$v) $aStr = str_replace("{{".$k."}}", $v, $aStr);
     | 
  
  
    | 
      28
     | 
    
              return $aStr;
 
     | 
  
  
    | 
      29
     | 
    
          }
 
     | 
  
  
    | 
      30
     | 
    
      }
 
     | 
  
  
    | 
      31
     | 
    
      
 
     | 
  
  
    | 
      32
     | 
    
      $admin = new admin('Addons', 'modules_uninstall', false);
     | 
  
  
    | 
      33
     | 
    
      
 
     | 
  
  
    | 
      34
     | 
    
      $js_back = ADMIN_URL.'/modules/index.php';
 
     | 
  
  
    | 
      35
     | 
    
      
 
     | 
  
  
    | 
      36
     | 
    
          if (!$admin->checkFTAN() ){
     | 
  
  
    | 
      37
     | 
    
              $admin->print_header();
 
     | 
  
  
    | 
      38
     | 
    
              $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
 
     | 
  
  
    | 
      39
     | 
    
          }
 
     | 
  
  
    | 
      40
     | 
    
      // After check print the header
 
     | 
  
  
    | 
      41
     | 
    
          $admin->print_header();
 
     | 
  
  
    | 
      42
     | 
    
      
 
     | 
  
  
    | 
      43
     | 
    
          $sAddonsFile = '';
 
     | 
  
  
    | 
      44
     | 
    
      // Check if user selected template
 
     | 
  
  
    | 
      45
     | 
    
          if (!isset($_POST['file']) || $_POST['file'] == false) {
     | 
  
  
    | 
      46
     | 
    
              $iAddonId = 0;
 
     | 
  
  
    | 
      47
     | 
    
              $admin->print_error( $MESSAGE['GENERIC_FORGOT_OPTIONS'], $js_back );
 
     | 
  
  
    | 
      48
     | 
    
          } else {
     | 
  
  
    | 
      49
     | 
    
              $iAddonId = $admin->checkIDKEY('file',0);
     | 
  
  
    | 
      50
     | 
    
          }
 
     | 
  
  
    | 
      51
     | 
    
          if ($iAddonId == 0){
     | 
  
  
    | 
      52
     | 
    
              $admin->print_error($MESSAGE['GENERIC_SECURITY_ACCESS'], $js_back );
 
     | 
  
  
    | 
      53
     | 
    
          }
 
     | 
  
  
    | 
      54
     | 
    
      
 
     | 
  
  
    | 
      55
     | 
    
      // Get module directory
 
     | 
  
  
    | 
      56
     | 
    
          $sqlAddons = 'SELECT `directory` FROM `'.TABLE_PREFIX.'addons` '
 
     | 
  
  
    | 
      57
     | 
    
                     . 'WHERE `addon_id`='.(int)$iAddonId.' '
 
     | 
  
  
    | 
      58
     | 
    
                     . ''.'';
 
     | 
  
  
    | 
      59
     | 
    
          if ($sAddonsFile = $database->get_one($sqlAddons)) {
     | 
  
  
    | 
      60
     | 
    
              $sAddonsFile = preg_replace('/[^a-z0-9_-]/i', "", $sAddonsFile);  // fix secunia 2010-92-2
     | 
  
  
    | 
      61
     | 
    
          }
 
     | 
  
  
    | 
      62
     | 
    
      
 
     | 
  
  
    | 
      63
     | 
    
      // check whether the module is core
 
     | 
  
  
    | 
      64
     | 
    
      $aPreventFromUninstall = array ( 'captcha_control', 'jsadmin', 'output_filter', 'wysiwyg', 'menu_link' );
 
     | 
  
  
    | 
      65
     | 
    
      if(
 
     | 
  
  
    | 
      66
     | 
    
          preg_match('/'.$sAddonsFile.'/si', implode('|', $aPreventFromUninstall ))
     | 
  
  
    | 
      67
     | 
    
      ) {
     | 
  
  
    | 
      68
     | 
    
          $temp = array ('name' => $file );
     | 
  
  
    | 
      69
     | 
    
          $msg = replace_all( $MESSAGE['MEDIA_CANNOT_DELETE_DIR'], $temp );
 
     | 
  
  
    | 
      70
     | 
    
          $admin->print_error( $msg );
 
     | 
  
  
    | 
      71
     | 
    
      }
 
     | 
  
  
    | 
      72
     | 
    
      // Check if the module exists
 
     | 
  
  
    | 
      73
     | 
    
      if (!is_dir(WB_PATH.'/modules/'.$sAddonsFile) ) {
     | 
  
  
    | 
      74
     | 
    
          $admin->print_error($MESSAGE['GENERIC_NOT_INSTALLED'], $js_back );
 
     | 
  
  
    | 
      75
     | 
    
      }
 
     | 
  
  
    | 
      76
     | 
    
      $sql  = 'SELECT `section_id`, `page_id` FROM `'.TABLE_PREFIX.'sections` '
 
     | 
  
  
    | 
      77
     | 
    
            . 'WHERE `module`=\''.$database->escapeString($sAddonsFile).'\'';
 
     | 
  
  
    | 
      78
     | 
    
      if( $oAddon = $database->query($sql)) {
     | 
  
  
    | 
      79
     | 
    
      
 
     | 
  
  
    | 
      80
     | 
    
          if ($oAddon->numRows() > 0) {
     | 
  
  
    | 
      81
     | 
    
      
 
     | 
  
  
    | 
      82
     | 
    
              /**
 
     | 
  
  
    | 
      83
     | 
    
              *    Modul is in use, so we have to warn the user
 
     | 
  
  
    | 
      84
     | 
    
              */
 
     | 
  
  
    | 
      85
     | 
    
              if (!array_key_exists("CANNOT_UNINSTALL_IN_USE_TMPL", $MESSAGE['GENERIC'])) {
     | 
  
  
    | 
      86
     | 
    
                  $add = $oAddon->numRows() == 1 ? "this page" : "these pages";
 
     | 
  
  
    | 
      87
     | 
    
                  $msg_template_str  = "<br /><br />{{type}} <b>{{type_name}}</b> could not be uninstalled because it is still in use on {{pages}}";
     | 
  
  
    | 
      88
     | 
    
                  $msg_template_str .= ":<br /><i>click for editing.</i><br /><br />";
 
     | 
  
  
    | 
      89
     | 
    
              } else {
     | 
  
  
    | 
      90
     | 
    
                  $msg_template_str = $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL'];
 
     | 
  
  
    | 
      91
     | 
    
                  $temp = explode(";",$MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE_TMPL_PAGES']);
     | 
  
  
    | 
      92
     | 
    
                  $add = $oAddon->numRows() == 1 ? $temp[0] : $temp[1];
 
     | 
  
  
    | 
      93
     | 
    
              }
 
     | 
  
  
    | 
      94
     | 
    
              /**
 
     | 
  
  
    | 
      95
     | 
    
              *    The template-string for displaying the Page-Titles ... in this case as a link
 
     | 
  
  
    | 
      96
     | 
    
              */
 
     | 
  
  
    | 
      97
     | 
    
              $page_template_str = "- <b><a href='../pages/sections.php?page_id={{id}}'>{{title}}</a></b><br />";
     | 
  
  
    | 
      98
     | 
    
      
 
     | 
  
  
    | 
      99
     | 
    
              $values = array ('type' => 'Modul', 'type_name' => $sAddonsFile, 'pages' => $add );
     | 
  
  
    | 
      100
     | 
    
              $msg = replace_all ( $msg_template_str,  $values );
 
     | 
  
  
    | 
      101
     | 
    
      
 
     | 
  
  
    | 
      102
     | 
    
              $page_names = "";
 
     | 
  
  
    | 
      103
     | 
    
      
 
     | 
  
  
    | 
      104
     | 
    
              while ($data = $oAddon->fetchRow(MYSQLI_ASSOC) ) {
     | 
  
  
    | 
      105
     | 
    
                  $sql  = 'SELECT `page_title` FROM `'.TABLE_PREFIX.'pages` '
 
     | 
  
  
    | 
      106
     | 
    
                        . 'WHERE `page_id`= '.(int)$data['page_id'];
 
     | 
  
  
    | 
      107
     | 
    
                  $oPage = $database->query($sql);
 
     | 
  
  
    | 
      108
     | 
    
                  $aPage = $oPage->fetchRow( MYSQLI_ASSOC );
 
     | 
  
  
    | 
      109
     | 
    
                  $aPageInfo = array(
 
     | 
  
  
    | 
      110
     | 
    
                      'id'    => $data['page_id'],
 
     | 
  
  
    | 
      111
     | 
    
                      'title' => $aPage['page_title']
 
     | 
  
  
    | 
      112
     | 
    
                  );
 
     | 
  
  
    | 
      113
     | 
    
      
 
     | 
  
  
    | 
      114
     | 
    
                  $page_names .= replace_all ( $page_template_str, $aPageInfo );
 
     | 
  
  
    | 
      115
     | 
    
              }
 
     | 
  
  
    | 
      116
     | 
    
      
 
     | 
  
  
    | 
      117
     | 
    
              /**
 
     | 
  
  
    | 
      118
     | 
    
              *    Printing out the error-message and die().
 
     | 
  
  
    | 
      119
     | 
    
              */
 
     | 
  
  
    | 
      120
     | 
    
              $admin->print_error(str_replace ($TEXT['FILE'], "Modul", $MESSAGE['GENERIC_CANNOT_UNINSTALL_IN_USE']).$msg.$page_names);
 
     | 
  
  
    | 
      121
     | 
    
          }
 
     | 
  
  
    | 
      122
     | 
    
      } else {
     | 
  
  
    | 
      123
     | 
    
          $admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
 
     | 
  
  
    | 
      124
     | 
    
      }
 
     | 
  
  
    | 
      125
     | 
    
      // Check if we have permissions on the directory
 
     | 
  
  
    | 
      126
     | 
    
      if (!is_writable(WB_PATH.'/modules/'.$sAddonsFile)) {
     | 
  
  
    | 
      127
     | 
    
          $admin->print_error(' ('.$sAddonsFile.') '.$MESSAGE['GENERIC_CANNOT_UNINSTALL']);
     | 
  
  
    | 
      128
     | 
    
      }
 
     | 
  
  
    | 
      129
     | 
    
      
 
     | 
  
  
    | 
      130
     | 
    
      // Run the modules uninstall script if there is one
 
     | 
  
  
    | 
      131
     | 
    
      if(file_exists(WB_PATH.'/modules/'.$sAddonsFile.'/uninstall.php')) {
     | 
  
  
    | 
      132
     | 
    
          require(WB_PATH.'/modules/'.$sAddonsFile.'/uninstall.php');
 
     | 
  
  
    | 
      133
     | 
    
      }
 
     | 
  
  
    | 
      134
     | 
    
      
 
     | 
  
  
    | 
      135
     | 
    
      // Try to delete the module dir
 
     | 
  
  
    | 
      136
     | 
    
      if (!rm_full_dir(WB_PATH.'/modules/'.$sAddonsFile)) {
     | 
  
  
    | 
      137
     | 
    
          $admin->print_error($MESSAGE['GENERIC_CANNOT_UNINSTALL']);
 
     | 
  
  
    | 
      138
     | 
    
      } else {
     | 
  
  
    | 
      139
     | 
    
          // Remove entry from DB
 
     | 
  
  
    | 
      140
     | 
    
          $sql  = 'DELETE FROM `'.TABLE_PREFIX.'addons` '
 
     | 
  
  
    | 
      141
     | 
    
                . 'WHERE `type` = \'module\' '
 
     | 
  
  
    | 
      142
     | 
    
                .   'AND `directory` = \''.$database->escapeString($sAddonsFile).'\' ';
 
     | 
  
  
    | 
      143
     | 
    
          $database->query($sql);
 
     | 
  
  
    | 
      144
     | 
    
      }
 
     | 
  
  
    | 
      145
     | 
    
      // Print success message
 
     | 
  
  
    | 
      146
     | 
    
      $admin->print_success($MESSAGE['GENERIC_UNINSTALLED']);
 
     | 
  
  
    | 
      147
     | 
    
      
 
     | 
  
  
    | 
      148
     | 
    
      // Print admin footer
 
     | 
  
  
    | 
      149
     | 
    
      $admin->print_footer();
 
     |