Guest User

phpbb-umil_auto

a guest
Nov 8th, 2013
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.41 KB | None | 0 0
  1. <?php
  2. /**
  3. *
  4. * @author Nathan Guse (EXreaction) http://lithiumstudios.org
  5. * @author David Lewis (Highway of Life) [email protected]
  6. * @package umil
  7. * @copyright (c) 2008 phpBB Group
  8. * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
  9. *
  10. */
  11.  
  12. /**
  13. * Parameters which should be setup before calling this file:
  14. * @param string $mod_name The name of the mod to be displayed during installation.
  15. * @param string $language_file The language file which will be included when installing (should contain the $mod_name)
  16. * @param string $version_config_name The name of the config variable which will hold the currently installed version
  17. * @param array $versions The array of versions and actions within each.
  18. */
  19.  
  20. /**
  21. * Language entries that should exist in the $language_file that will be included:
  22. * $mod_name
  23. * 'INSTALL_' . $mod_name
  24. * 'INSTALL_' . $mod_name . '_CONFIRM'
  25. * 'UPDATE_' . $mod_name
  26. * 'UPDATE_' . $mod_name . '_CONFIRM'
  27. * 'UNINSTALL_' . $mod_name
  28. * 'UNINSTALL_' . $mod_name . '_CONFIRM'
  29. */
  30.  
  31. // You must run define('UMIL_AUTO', true) before calling this file.
  32. /**
  33. * @ignore
  34. */
  35. if (!defined('UMIL_AUTO'))
  36. {
  37. exit;
  38. }
  39.  
  40. /*
  41. * Do not include common.php, the MOD author is required to include this.
  42. */
  43. if (!defined('IN_PHPBB'))
  44. {
  45. trigger_error('UMIL doesn\'t support the missing IN_PHPBB anymore. Please visit <a href="http://www.phpbb.com/mods/umil/update/">http://www.phpbb.com/mods/umil/update</a> on how to update your UMIF files.', E_USER_ERROR);
  46. exit;
  47. }
  48.  
  49. // Add the language file if one was specified
  50. if (isset($language_file))
  51. {
  52. $user->add_lang($language_file);
  53. }
  54. if (!isset($user->lang[$mod_name]))
  55. {
  56. // Prevent errors if the language key doesn't exist.
  57. $user->lang[$mod_name] = $mod_name;
  58. }
  59.  
  60. // Use the Mod's logo if one was specified
  61. if (isset($logo_img))
  62. {
  63. $template->assign_var('LOGO_IMG', $phpbb_root_path . $logo_img);
  64. }
  65.  
  66. // Display a login box if they are not logged in
  67. if (!$user->data['is_registered'])
  68. {
  69. login_box();
  70. }
  71.  
  72. if (!class_exists('umil_frontend'))
  73. {
  74. if (!file_exists($phpbb_root_path . 'umil/umil_frontend.' . $phpEx))
  75. {
  76. trigger_error('Please download the latest UMIL (Unified MOD Install Library) from: <a href="http://www.phpbb.com/mods/umil/">phpBB.com/mods/umil</a>', E_USER_ERROR);
  77. }
  78.  
  79. include($phpbb_root_path . 'umil/umil_frontend.' . $phpEx);
  80. }
  81.  
  82. $force_display_results = request_var('display_results', (defined('DEBUG') ? true : false));
  83. $umil = new umil_frontend($mod_name, true, $force_display_results);
  84.  
  85. // Check after initiating UMIL.
  86. if ($user->data['user_type'] != USER_FOUNDER)
  87. {
  88. trigger_error('FOUNDERS_ONLY');
  89. }
  90.  
  91. // We will sort the actions to prevent issues from mod authors incorrectly listing the version numbers
  92. uksort($versions, 'version_compare');
  93.  
  94. // Find the current version to install
  95. $current_version = '0.0.0';
  96. foreach ($versions as $version => $actions)
  97. {
  98. $current_version = $version;
  99. }
  100.  
  101. $template->assign_var('L_TITLE_EXPLAIN', ((isset($user->lang[$mod_name . '_EXPLAIN'])) ? $user->lang[$mod_name . '_EXPLAIN'] . '<br /><br />' : '') . sprintf($user->lang['VERSIONS'], $current_version, ((isset($config[$version_config_name])) ? $config[$version_config_name] : $user->lang['NONE'])));
  102.  
  103. $submit = (isset($_POST['submit'])) ? true : false;
  104. $action = request_var('action', '');
  105. $version_select = request_var('version_select', '');
  106.  
  107. $current_page = (strpos($user->page['page'], '?') !== false) ? substr($user->page['page'], 0, strpos($user->page['page'], '?')) : $user->page['page'];
  108.  
  109. $stages = array(
  110. 'CONFIGURE' => array('url' => append_sid($phpbb_root_path . $current_page)),
  111. 'CONFIRM',
  112. 'ACTION',
  113. );
  114.  
  115. if (!isset($options) || !is_array($options))
  116. {
  117. $options = array();
  118. }
  119.  
  120. $options = array(
  121. 'legend1' => 'OPTIONS',
  122. 'action' => array('lang' => 'ACTION', 'type' => 'custom', 'function' => 'umil_install_update_uninstall_select', 'explain' => false),
  123. 'version_select' => array('lang' => 'VERSION_SELECT', 'type' => 'custom', 'function' => 'umil_version_select', 'explain' => true),
  124. 'display_results' => array('lang' => 'DISPLAY_RESULTS', 'type' => 'radio:yes_no', 'explain' => true, 'default' => $force_display_results),
  125. ) + $options;
  126.  
  127. if (!$submit && !$umil->confirm_box(true))
  128. {
  129. $umil->display_stages($stages);
  130.  
  131. $umil->display_options($options);
  132. $umil->done();
  133. }
  134. else if (!$umil->confirm_box(true))
  135. {
  136. $umil->display_stages($stages, 2);
  137.  
  138. $hidden = array();
  139. foreach ($options as $key => $data)
  140. {
  141. $hidden[$key] = request_var($key, '', true);
  142. }
  143.  
  144. switch ($action)
  145. {
  146. case 'install' :
  147. if (!isset($user->lang['INSTALL_' . $mod_name]))
  148. {
  149. $user->lang['INSTALL_' . $mod_name] = sprintf($user->lang['INSTALL_MOD'], $user->lang[$mod_name]);
  150. $user->lang['INSTALL_' . $mod_name . '_CONFIRM'] = sprintf($user->lang['INSTALL_MOD_CONFIRM'], $user->lang[$mod_name]);
  151. }
  152. $umil->confirm_box(false, 'INSTALL_' . $mod_name, $hidden);
  153. break;
  154.  
  155. case 'update' :
  156. if (!isset($user->lang['UPDATE_' . $mod_name]))
  157. {
  158. $user->lang['UPDATE_' . $mod_name] = sprintf($user->lang['UPDATE_MOD'], $user->lang[$mod_name]);
  159. $user->lang['UPDATE_' . $mod_name . '_CONFIRM'] = sprintf($user->lang['UPDATE_MOD_CONFIRM'], $user->lang[$mod_name]);
  160. }
  161. $umil->confirm_box(false, 'UPDATE_' . $mod_name, $hidden);
  162. break;
  163.  
  164. case 'uninstall' :
  165. if (!isset($user->lang['UNINSTALL_' . $mod_name]))
  166. {
  167. $user->lang['UNINSTALL_' . $mod_name] = sprintf($user->lang['UNINSTALL_MOD'], $user->lang[$mod_name]);
  168. $user->lang['UNINSTALL_' . $mod_name . '_CONFIRM'] = sprintf($user->lang['UNINSTALL_MOD_CONFIRM'], $user->lang[$mod_name]);
  169. }
  170. $umil->confirm_box(false, 'UNINSTALL_' . $mod_name, $hidden);
  171. break;
  172. }
  173. }
  174. else if ($umil->confirm_box(true))
  175. {
  176. $umil->display_stages($stages, 3);
  177.  
  178. $umil->run_actions($action, $versions, $version_config_name, $version_select);
  179. $umil->done();
  180. }
  181.  
  182. // Shouldn't get here.
  183. redirect($phpbb_root_path . $current_page);
  184.  
  185. function umil_install_update_uninstall_select($value, $key)
  186. {
  187. global $config, $current_version, $user, $version_config_name;
  188.  
  189. $db_version = (isset($config[$version_config_name])) ? $config[$version_config_name] : false;
  190.  
  191. if ($db_version === false)
  192. {
  193. return '<input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="install" checked="checked" /> ' . $user->lang['INSTALL'] . '&nbsp;&nbsp;
  194. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="update" disabled="disabled" /> ' . $user->lang['UPDATE'] . '&nbsp;&nbsp;
  195. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="uninstall" disabled="disabled" /> ' . $user->lang['UNINSTALL'];
  196. }
  197. else if ($current_version == $db_version)
  198. {
  199. return '<input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="install" disabled="disabled" /> ' . $user->lang['INSTALL'] . '&nbsp;&nbsp;
  200. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="update" disabled="disabled" /> ' . $user->lang['UPDATE'] . '&nbsp;&nbsp;
  201. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="uninstall" checked="checked" /> ' . $user->lang['UNINSTALL'];
  202. }
  203. else if (version_compare($current_version, $db_version, '>'))
  204. {
  205. return '<input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="install" disabled="disabled" /> ' . $user->lang['INSTALL'] . '&nbsp;&nbsp;
  206. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="update" checked="checked" /> ' . $user->lang['UPDATE'] . '&nbsp;&nbsp;
  207. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="uninstall" /> ' . $user->lang['UNINSTALL'];
  208. }
  209. else
  210. {
  211. // Shouldn't ever get here...but just in case.
  212. return '<input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="install" /> ' . $user->lang['INSTALL'] . '&nbsp;&nbsp;
  213. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="update" /> ' . $user->lang['UPDATE'] . '&nbsp;&nbsp;
  214. <input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="uninstall" /> ' . $user->lang['UNINSTALL'];
  215. }
  216. }
  217.  
  218. function umil_version_select($value, $key)
  219. {
  220. global $user, $versions;
  221.  
  222. $output = '<input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="" checked="checked" /> ' . $user->lang['IGNORE'] . ' &nbsp; ';
  223. $output .='<a href="#" onclick="if (document.getElementById(\'version_select_advanced\').style.display == \'none\') {document.getElementById(\'version_select_advanced\').style.display=\'block\'} else {document.getElementById(\'version_select_advanced\').style.display=\'none\'}">' . $user->lang['ADVANCED'] . '</a><br /><br />';
  224.  
  225. $cnt = 0;
  226. $output .= '<table id="version_select_advanced" style="display: none;" cellspacing="0" cellpadding="0"><tr>';
  227. foreach ($versions as $version => $actions)
  228. {
  229. $cnt++;
  230.  
  231. $output .= '<td><input id="' . $key . '" class="radio" type="radio" name="' . $key . '" value="' . $version . '" /> ' . $version . '</td>';
  232.  
  233. if ($cnt % 4 == 0)
  234. {
  235. $output .= '</tr><tr>';
  236. }
  237. }
  238. $output .= '</tr></table>';
  239.  
  240. return $output;
  241. }
  242. ?>
Advertisement
Add Comment
Please, Sign In to add comment