PageRenderTime 27ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/adm/xs_uninstall.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 233 lines | 186 code | 15 blank | 32 comment | 24 complexity | f401371ab0dffdd5191c74d3d2000d63 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Vjacheslav Trushkin (http://www.stsoftware.biz)
  14. *
  15. */
  16. define('IN_ICYPHOENIX', true);
  17. if (!defined('IP_ROOT_PATH')) define('IP_ROOT_PATH', './../');
  18. if (!defined('PHP_EXT')) define('PHP_EXT', substr(strrchr(__FILE__, '.'), 1));
  19. $no_page_header = true;
  20. require('pagestart.' . PHP_EXT);
  21. define('IN_XS', true);
  22. include_once('xs_include.' . PHP_EXT);
  23. function remove_all($dir)
  24. {
  25. $res = opendir($dir);
  26. if(!$res)
  27. {
  28. return false;
  29. }
  30. while(($file = readdir($res)) !== false)
  31. {
  32. if($file !== '.' && $file !== '..')
  33. {
  34. $str = $dir . '/' . $file;
  35. if(is_dir($str))
  36. {
  37. remove_all($str);
  38. @rmdir($str);
  39. }
  40. else
  41. {
  42. @unlink($str);
  43. }
  44. }
  45. }
  46. closedir($res);
  47. }
  48. $template->assign_block_vars('nav_left',array('ITEM' => '&raquo; <a href="' . append_sid('xs_uninstall.' . PHP_EXT) . '">' . $lang['xs_uninstall_styles'] . '</a>'));
  49. $lang['xs_uninstall_back'] = str_replace('{URL}', append_sid('xs_uninstall.' . PHP_EXT), $lang['xs_uninstall_back']);
  50. $lang['xs_goto_default'] = str_replace('{URL}', append_sid('xs_styles.' . PHP_EXT), $lang['xs_goto_default']);
  51. // uninstall style
  52. $remove_id = request_var('remove', 0);
  53. $remove_dir = request_get_var('dir', '');
  54. $remove_tpl = request_post_var('remove', '');
  55. $nocfg = request_get_var('nocfg', '');
  56. if(!empty($remove_id) && !defined('DEMO_MODE'))
  57. {
  58. if($config['default_style'] == $remove_id)
  59. {
  60. xs_error(str_replace('{URL}', append_sid('xs_styles.' . PHP_EXT), $lang['xs_uninstall_default']) . '<br /><br />' . $lang['xs_uninstall_back']);
  61. }
  62. $sql = "SELECT themes_id, template_name, style_name FROM " . THEMES_TABLE . " WHERE themes_id='{$remove_id}'";
  63. $db->sql_return_on_error(true);
  64. $result = $db->sql_query($sql);
  65. $db->sql_return_on_error(false);
  66. if(!$result)
  67. {
  68. xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_uninstall_back'], __LINE__, __FILE__);
  69. }
  70. $row = $db->sql_fetchrow($result);
  71. if(empty($row['themes_id']))
  72. {
  73. xs_error($lang['xs_no_style_info'] . '<br /><br />' . $lang['xs_uninstall_back'], __LINE__, __FILE__);
  74. }
  75. $sql = "UPDATE " . USERS_TABLE . " SET user_style = '" . $config['default_style'] . "' WHERE user_style = '{$remove_id}'";
  76. $db->sql_query($sql);
  77. $sql = "DELETE FROM " . THEMES_TABLE . " WHERE themes_id = '{$remove_id}'";
  78. $db->sql_query($sql);
  79. $template->assign_block_vars('removed', array());
  80. // clear cache
  81. $db->clear_cache('styles_');
  82. $cache->destroy_datafiles(array('_styles'), MAIN_CACHE_FOLDER, 'data', false);
  83. // remove files
  84. if(!empty($remove_dir))
  85. {
  86. $remove_tpl = $row['template_name'];
  87. }
  88. // remove config
  89. if(empty($nocfg) && isset($config['xs_style_'.$row['template_name']]))
  90. {
  91. $sql = "DELETE FROM " . CONFIG_TABLE . " WHERE config_name='" . $db->sql_escape("xs_style_{$row['template_name']}") . "'";
  92. $db->sql_query($sql);
  93. $template->assign_block_vars('left_refresh', array(
  94. 'ACTION' => append_sid('index.' . PHP_EXT . '?pane=left')
  95. )
  96. );
  97. }
  98. }
  99. // remove files
  100. if(!empty($remove_tpl) && !defined('DEMO_MODE'))
  101. {
  102. $remove = $remove_tpl;
  103. $params = array('remove' => $remove);
  104. if(!get_ftp_config(append_sid('xs_uninstall.' . PHP_EXT), $params, true))
  105. {
  106. xs_exit();
  107. }
  108. xs_ftp_connect(append_sid('xs_uninstall.' . PHP_EXT), $params, true);
  109. $write_local = false;
  110. if($ftp === XS_FTP_LOCAL)
  111. {
  112. $write_local = true;
  113. $write_local_dir = '../templates/';
  114. }
  115. if(!$write_local)
  116. {
  117. // Generate actions list
  118. $actions = array();
  119. // chdir to templates directory
  120. $actions[] = array(
  121. 'command' => 'chdir',
  122. 'dir' => 'templates'
  123. );
  124. // chdir to template
  125. $actions[] = array(
  126. 'command' => 'chdir',
  127. 'dir' => $remove
  128. );
  129. // remove all files
  130. $actions[] = array(
  131. 'command' => 'removeall',
  132. 'ignore' => true
  133. );
  134. $actions[] = array(
  135. 'command' => 'cdup'
  136. );
  137. $actions[] = array(
  138. 'command' => 'rmdir',
  139. 'dir' => $remove
  140. );
  141. $ftp_log = array();
  142. $ftp_error = '';
  143. $res = ftp_myexec($actions);
  144. /*
  145. echo "<!--\n\n";
  146. echo "\$actions dump:\n\n";
  147. print_r($actions);
  148. echo "\n\n\$ftp_log dump:\n\n";
  149. print_r($ftp_log);
  150. echo "\n\n -->";
  151. */
  152. }
  153. else
  154. {
  155. remove_all('../templates/'.$remove);
  156. @rmdir('../templates/'.$remove);
  157. }
  158. $template->assign_block_vars('removed', array());
  159. }
  160. // get list of installed styles
  161. $sql = 'SELECT themes_id, template_name, style_name FROM ' . THEMES_TABLE . ' ORDER BY template_name, style_name';
  162. $db->sql_return_on_error(true);
  163. $result = $db->sql_query($sql);
  164. $db->sql_return_on_error(false);
  165. if(!$result)
  166. {
  167. xs_error($lang['xs_no_style_info'], __LINE__, __FILE__);
  168. }
  169. $style_rowset = $db->sql_fetchrowset($result);
  170. $tpl = array();
  171. for($i = 0; $i < sizeof($style_rowset); $i++)
  172. {
  173. $item = $style_rowset[$i];
  174. $tpl[$item['template_name']][] = $item;
  175. }
  176. $j = 0;
  177. foreach($tpl as $tpl => $styles)
  178. {
  179. $row_class = $xs_row_class[$j % 2];
  180. $j++;
  181. $template->assign_block_vars('styles', array(
  182. 'ROW_CLASS' => $row_class,
  183. 'TPL' => htmlspecialchars($tpl),
  184. 'ROWS' => sizeof($styles),
  185. )
  186. );
  187. if(sizeof($styles) > 1)
  188. {
  189. for($i = 0; $i < sizeof($styles); $i++)
  190. {
  191. $template->assign_block_vars('styles.item', array(
  192. 'ID' => $styles[$i]['themes_id'],
  193. 'THEME' => htmlspecialchars($styles[$i]['style_name']),
  194. 'U_DELETE' => append_sid('xs_uninstall.' . PHP_EXT . '?remove=' . $styles[$i]['themes_id'] . '&amp;nocfg=1'),
  195. )
  196. );
  197. $template->assign_block_vars('styles.item.nodelete', array());
  198. }
  199. }
  200. else
  201. {
  202. $i = 0;
  203. $template->assign_block_vars('styles.item', array(
  204. 'ID' => $styles[$i]['themes_id'],
  205. 'THEME' => htmlspecialchars($styles[$i]['style_name']),
  206. 'U_DELETE' => append_sid('xs_uninstall.' . PHP_EXT . '?remove=' . $styles[$i]['themes_id']),
  207. )
  208. );
  209. $template->assign_block_vars('styles.item.delete', array(
  210. 'U_DELETE' => append_sid('xs_uninstall.' . PHP_EXT . '?dir=1&amp;remove=' . $styles[$i]['themes_id']),
  211. )
  212. );
  213. }
  214. }
  215. $template->set_filenames(array('body' => XS_TPL_PATH . 'uninstall.tpl'));
  216. $template->pparse('body');
  217. xs_exit();
  218. ?>