diff --git a/config/services.yml b/config/services.yml index a50b5ab81..463f03d55 100644 --- a/config/services.yml +++ b/config/services.yml @@ -302,24 +302,12 @@ services: - '%core.root_path%' - '%core.php_ext%' - phpbb.titania.mod.prevalidator: - class: phpbb\titania\contribution\mod\prevalidator - arguments: - - '@phpbb.titania.config' - - '@user' - - '@template' - - '@phpbb.titania.contribution.prevalidator_helper' - - '%core.root_path%' - - '%phpbb.titania.root_path%' - - '%core.php_ext%' - phpbb.titania.mod.type: class: phpbb\titania\contribution\mod\type arguments: - '@phpbb.titania.config' - '@user' - '@auth' - - '@phpbb.titania.mod.prevalidator' tags: - { name: titania.contribution.type } diff --git a/contribution/bbcode/type.php b/contribution/bbcode/type.php index 362a041e0..ff7d89cc4 100644 --- a/contribution/bbcode/type.php +++ b/contribution/bbcode/type.php @@ -24,9 +24,9 @@ class type extends base /** @var demo\demo */ protected $demo; - const ID = 7; - const NAME = 'bbcode'; - const URL = 'bbcode'; + public const ID = 7; + public const NAME = 'bbcode'; + public const URL = 'bbcode'; /** * Constructor diff --git a/contribution/bridge/type.php b/contribution/bridge/type.php index fcca0090b..81a3c3f35 100644 --- a/contribution/bridge/type.php +++ b/contribution/bridge/type.php @@ -17,9 +17,9 @@ class type extends base { - const ID = 5; - const NAME = 'bridge'; - const URL = 'bridge'; + public const ID = 5; + public const NAME = 'bridge'; + public const URL = 'bridge'; /** * @{inheritDoc} diff --git a/contribution/converter/type.php b/contribution/converter/type.php index 19246000d..40e92aff3 100644 --- a/contribution/converter/type.php +++ b/contribution/converter/type.php @@ -17,9 +17,9 @@ class type extends base { - const ID = 3; - const NAME = 'converter'; - const URL = 'converter'; + public const ID = 3; + public const NAME = 'converter'; + public const URL = 'converter'; /** * @{inheritDoc} diff --git a/contribution/extension/type.php b/contribution/extension/type.php index 4ae327b78..b43450bb3 100644 --- a/contribution/extension/type.php +++ b/contribution/extension/type.php @@ -26,9 +26,9 @@ class type extends base /** @var prevalidator */ protected $prevalidator; - const ID = 8; - const NAME = 'extension'; - const URL = 'extension'; + public const ID = 8; + public const NAME = 'extension'; + public const URL = 'extension'; /** * Constructor diff --git a/contribution/mod/prevalidator.php b/contribution/mod/prevalidator.php deleted file mode 100644 index 349a55f60..000000000 --- a/contribution/mod/prevalidator.php +++ /dev/null @@ -1,211 +0,0 @@ - - * @license GNU General Public License, version 2 (GPL-2.0) - * - * For full copyright and license information, please see - * the docs/CREDITS.txt file. - * - */ - -namespace phpbb\titania\contribution\mod; - -class prevalidator -{ - /** @var \phpbb\titania\config\config */ - protected $ext_config; - - /** @var \phpbb\user */ - protected $user; - - /** @var \phpbb\template\template */ - protected $template; - - /** @var \phpbb\titania\contribution\prevalidator_helper */ - protected $helper; - - /** @var string */ - protected $phpbb_root_path; - - /** @var string */ - protected $ext_root_path; - - /** @var string */ - protected $php_ext; - - /** @var array */ - protected $errors = array(); - - /** - * Constructor. - * - * @param \phpbb\titania\config\config $ext_config - * @param \phpbb\user $user - * @param \phpbb\template\template $template - * @param \phpbb\titania\contribution\prevalidator_helper $helper - * @param string $phpbb_root_path - * @param string $ext_root_path - * @param string $php_ext - */ - public function __construct(\phpbb\titania\config\config $ext_config, \phpbb\user $user, \phpbb\template\template $template, \phpbb\titania\contribution\prevalidator_helper $helper, $phpbb_root_path, $ext_root_path, $php_ext) - { - $this->ext_config = $ext_config; - $this->user = $user; - $this->template = $template; - $this->helper = $helper; - $this->phpbb_root_path = $phpbb_root_path; - $this->ext_root_path = $ext_root_path; - $this->php_ext = $php_ext; - } - - /** - * Get helper. - * - * @return \phpbb\titania\contribution\prevalidator_helper - */ - public function get_helper() - { - return $this->helper; - } - - /** - * Get errors. - * - * @return array - */ - public function get_errors() - { - return $this->errors; - } - - /** - * Run the prevalidator. - * @param string $download_location Revision download URL. - * @return bool|mixed - */ - public function run_mpv($download_location) - { - $server_list = $this->ext_config->__get('mpv_server_list'); - - $server = $server_list[array_rand($server_list)]; - - $downloader = new \phpbb\file_downloader; - $mpv_result = $downloader->get( - $server['host'], - $server['directory'], - $server['file'] . '?titania-' . $download_location - ); - - if ($mpv_result === false) - { - $this->errors[] = $this->user->lang['MPV_TEST_FAILED']; - return false; - } - else - { - $mpv_result = str_replace('
', "\n", $mpv_result); - set_var($mpv_result, $mpv_result, 'string', true); - $mpv_result = utf8_normalize_nfc($mpv_result); - - return $mpv_result; - } - } - - /** - * Run AutoMOD test. - * - * @param \phpbb\titania\entity\package $package - * @param string $phpbb_path Path to phpBB files we run the test on - * @param string $details Will hold the details of the mod - * @param string $results Will hold the results for output - * @param string $bbcode_results Will hold the results for storage - * @return bool true on success, false on failure - */ - public function run_automod_test($package, $phpbb_path, &$details, &$results, &$bbcode_results) - { - require($this->phpbb_root_path . 'includes/functions_transfer.' . $this->php_ext); - require($this->phpbb_root_path . 'includes/functions_admin.' . $this->php_ext); - require($this->ext_root_path . 'includes/library/automod/acp_mods.' . $this->php_ext); - require($this->ext_root_path . 'includes/library/automod/editor.' . $this->php_ext); - require($this->ext_root_path . 'includes/library/automod/mod_parser.' . $this->php_ext); - require($this->ext_root_path . 'includes/library/automod/functions_mods.' . $this->php_ext); - - $this->user->add_lang_ext('phpbb/titania', 'automod'); - - // Find the main modx file - $modx_root = $package->find_directory(array('files' => array('required' => 'install*.xml'))); - - if ($modx_root === null) - { - $this->user->add_lang_ext('phpbb/titania', 'contributions'); - - $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT']; - return false; - } - - $modx_root = $package->get_temp_path() . '/' . $modx_root . '/'; - $modx_file = false; - - if (file_exists($modx_root . 'install.xml')) - { - $modx_file = $modx_root . 'install.xml'; - } - else - { - $finder = new \Symfony\Component\Finder\Finder; - $finder - ->name('install*.xml') - ->depth(0) - ->in($modx_root) - ; - - if ($finder->count()) - { - foreach ($finder as $file) - { - $modx_file = $file->getPathname(); - break; - } - } - } - - if (!$modx_file) - { - $this->user->add_lang_ext('phpbb/titania', 'contributions'); - - $this->errors[] = $this->user->lang['COULD_NOT_FIND_ROOT']; - return false; - } - - // HAX - global $phpbb_root_path; - $phpbb_root_path = $phpbb_path; - - // The real stuff - $acp_mods = new \acp_mods; - $acp_mods->mods_dir = $this->ext_config->__get('contrib_temp_path'); - $acp_mods->mod_root = $modx_root; - $editor = new \editor_direct; - $details = $acp_mods->mod_details($modx_file, false); - $actions = $acp_mods->mod_actions($modx_file); - $installed = $acp_mods->process_edits($editor, $actions, $details, false, true, false); - - // Reverse HAX - $phpbb_root_path = $this->phpbb_root_path; - - $this->template->set_filenames(array( - 'automod' => 'contributions/automod.html', - 'automod_bbcode' => 'contributions/automod_bbcode.html', - )); - - $this->template->assign_var('S_AUTOMOD_SUCCESS', $installed); - - $results = $this->template->assign_display('automod'); - $bbcode_results = $this->template->assign_display('automod_bbcode'); - - return $installed; - } -} diff --git a/contribution/mod/type.php b/contribution/mod/type.php index baf510e9a..22e1fd238 100644 --- a/contribution/mod/type.php +++ b/contribution/mod/type.php @@ -13,88 +13,43 @@ namespace phpbb\titania\contribution\mod; -use phpbb\auth\auth; -use phpbb\template\template; -use phpbb\titania\attachment\attachment; -use phpbb\titania\config\config as ext_config; use phpbb\titania\contribution\type\base; -use phpbb\titania\entity\package; -use phpbb\user; class type extends base { - /** @var prevalidator */ - protected $prevalidator; - - const ID = 1; - const NAME = 'mod'; - const URL = 'mod'; - - /** - * Constructor - * - * @param ext_config $ext_config - * @param user $user - * @param auth $auth - * @param prevalidator $prevalidator - */ - public function __construct(ext_config $ext_config, user $user, auth $auth, prevalidator $prevalidator) - { - parent::__construct($ext_config, $user, $auth); - - $this->prevalidator = $prevalidator; - } + public const ID = 1; + public const NAME = 'mod'; + public const URL = 'mod'; /** * {@inheritDoc} */ protected function configure() { - $this->allowed_branches = array('<=', 30); + $this->allowed_branches = ['<=', 30]; - $this->mpv_test = true; - $this->automod_test = true; $this->restore_root = true; $this->clean_package = true; - $this->root_search = array( - 'files' => array( + $this->root_search = [ + 'files' => [ 'required' => 'install*.xml', - ), - ); + ], + ]; $this->forum_database = $this->ext_config->forum_mod_database; $this->forum_robot = $this->ext_config->forum_mod_robot; - if ($this->ext_config->use_queue && $this->use_queue) - { - if ($this->mpv_test) - { - $this->upload_steps[] = array( - 'name' => 'MPV_TEST', - 'function' => array($this, 'mpv_test'), - ); - } - - if ($this->automod_test) - { - $this->upload_steps[] = array( - 'name' => 'AUTOMOD_TEST', - 'function' => array($this, 'automod_test'), - ); - } - } - $this->author_count = 'author_mods'; // Language strings - $this->lang = array( - 'lang' => $this->user->lang('MODIFICATION'), - 'langs' => $this->user->lang('MODIFICATIONS'), - 'new' => $this->user->lang('MOD_CONTRIB_NEW'), - 'cleaned' => $this->user->lang('MOD_CONTRIB_CLEANED'), - 'hidden' => $this->user->lang('MOD_CONTRIB_HIDDEN'), - 'disabled' => $this->user->lang('MOD_CONTRIB_DISABLED'), - ); + $this->lang = [ + 'lang' => $this->user->lang('MODIFICATION'), + 'langs' => $this->user->lang('MODIFICATIONS'), + 'new' => $this->user->lang('MOD_CONTRIB_NEW'), + 'cleaned' => $this->user->lang('MOD_CONTRIB_CLEANED'), + 'hidden' => $this->user->lang('MOD_CONTRIB_HIDDEN'), + 'disabled' => $this->user->lang('MOD_CONTRIB_DISABLED'), + ]; $this->validation_subject = 'MOD_VALIDATION'; $this->validation_message_approve = 'MOD_VALIDATION_MESSAGE_APPROVE'; $this->validation_message_deny = 'MOD_VALIDATION_MESSAGE_DENY'; @@ -133,156 +88,13 @@ public function acl_get($action) // Can moderate mods case 'moderate' : - return $this->auth->acl_gets(array( + return $this->auth->acl_gets([ 'u_titania_mod_modification_moderate', 'u_titania_mod_contrib_mod', - )); + ]); break; } return false; } - - /** - * Prevalidator test. - * - * @param \titania_contribution $contrib - * @param \titania_revision $revision - * @param attachment $attachment - * @param string $download_package - * @param package $package - * @param template $template - * @return array - */ - public function mpv_test(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $download_package, package $package, template $template) - { - // Run MPV - $prevalidator = $this->get_prevalidator(); - $mpv_results = $prevalidator->run_mpv($download_package); - - if ($mpv_results === false) - { - return array( - 'notice' => $prevalidator->get_errors(), - ); - } - else - { - $uid = $bitfield = $flags = false; - generate_text_for_storage($mpv_results, $uid, $bitfield, $flags, true, true, true); - - // Add the MPV Results to the queue - $queue = $revision->get_queue(); - $queue->mpv_results = $mpv_results; - $queue->mpv_results_bitfield = $bitfield; - $queue->mpv_results_uid = $uid; - $queue->submit(); - - $mpv_results = generate_text_for_display($mpv_results, $uid, $bitfield, $flags); - $template->assign_var('PV_RESULTS', $mpv_results); - - $template->assign_var('S_AUTOMOD_TEST', $this->automod_test); - } - } - - /** - * AutoMOD Test. - * - * @param \titania_contribution $contrib - * @param \titania_revision $revision - * @param attachment $attachment - * @param string $download_package - * @param package $package - * @param template $template - * @return array - */ - public function automod_test(\titania_contribution $contrib, \titania_revision $revision, attachment $attachment, $download_package, package $package, template $template) - { - $package->ensure_extracted(); - $prevalidator = $this->get_prevalidator(); - - // Automod testing time - $details = ''; - $error = $html_results = $bbcode_results = array(); - - if (!$revision->phpbb_versions) - { - $revision->load_phpbb_versions(); - } - - foreach ($revision->phpbb_versions as $row) - { - $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' .$row['phpbb_version_revision']; - $phpbb_path = $prevalidator->get_helper()->prepare_phpbb_test_directory($version_string); - - if ($phpbb_path === false) - { - $error = array_merge($error, $prevalidator->get_helper()->get_errors()); - continue; - } - - $template->assign_vars(array( - 'PHPBB_VERSION' => $version_string, - 'TEST_ID' => $row['row_id'], - )); - - $html_result = $bbcode_result = ''; - $installed = $prevalidator->run_automod_test( - $package, - $phpbb_path, - $details, - $html_result, - $bbcode_result - ); - - $html_results[] = $html_result; - $bbcode_results[] = $bbcode_result; - } - - if (is_array($details)) - { - $revision->install_time = $details['INSTALLATION_TIME']; - - switch ($details['INSTALLATION_LEVEL']) - { - case 'easy' : - $revision->install_level = 1; - break; - - case 'intermediate' : - $revision->install_level = 2; - break; - - case 'advanced' : - $revision->install_level = 3; - break; - } - - $revision->submit(); - } - - $html_results = implode('

', $html_results); - $bbcode_results = implode("\n\n", $bbcode_results); - - // Update the queue with the results - $queue = $revision->get_queue(); - $queue->automod_results = $bbcode_results; - $queue->submit(); - - $template->assign_var('AUTOMOD_RESULTS', $html_results); - - return array( - 'error' => $error, - ); - } - - /** - * Get prevalidator - * - * @return prevalidator - */ - public function get_prevalidator() - { - return $this->prevalidator; - } } diff --git a/contribution/official_tool/type.php b/contribution/official_tool/type.php index 1ba1202dd..e33c675a5 100644 --- a/contribution/official_tool/type.php +++ b/contribution/official_tool/type.php @@ -17,9 +17,9 @@ class type extends base { - const ID = 4; - const NAME = 'official_tool'; - const URL = 'official_tool'; + public const ID = 4; + public const NAME = 'official_tool'; + public const URL = 'official_tool'; /** * @{inheritDoc} diff --git a/contribution/style/type.php b/contribution/style/type.php index 907e0a0e6..c151f2f29 100644 --- a/contribution/style/type.php +++ b/contribution/style/type.php @@ -30,9 +30,9 @@ class type extends base /** @var demo\manager */ protected $demo_manager; - const ID = 2; - const NAME = 'style'; - const URL = 'style'; + public const ID = 2; + public const NAME = 'style'; + public const URL = 'style'; /** * Constructor diff --git a/contribution/translation/type.php b/contribution/translation/type.php index 7918122db..fdf5cbbf0 100644 --- a/contribution/translation/type.php +++ b/contribution/translation/type.php @@ -26,11 +26,11 @@ class type extends base /** @var prevalidator */ protected $prevalidator; - const ID = 6; - const NAME = 'translation'; - const URL = 'translation'; + public const ID = 6; + public const NAME = 'translation'; + public const URL = 'translation'; - const PHPBB_LATEST_VERSION = '3.2'; + public const PHPBB_LATEST_VERSION = '3.2'; /** * Constructor diff --git a/contribution/type/base.php b/contribution/type/base.php index 11cdf2072..1197c785c 100644 --- a/contribution/type/base.php +++ b/contribution/type/base.php @@ -129,12 +129,10 @@ class base implements type_interface public $extra_upload = true; /** - * Run MPV/Automod Test for this type? + * Run prevalidator Test for this type? * * @var bool */ - public $mpv_test = false; - public $automod_test = false; public $epv_test = false; /** @@ -223,9 +221,9 @@ class base implements type_interface */ public $contribution_fields = array(); - const ID = 0; - const NAME = 'contribution'; - const URL = 'contribution'; + public const ID = 0; + public const NAME = 'contribution'; + public const URL = 'contribution'; /** * Constructor diff --git a/controller/manage/queue/tools.php b/controller/manage/queue/tools.php index 28d4e7e11..6ea359efa 100644 --- a/controller/manage/queue/tools.php +++ b/controller/manage/queue/tools.php @@ -86,7 +86,7 @@ public function __construct(\phpbb\user $user, \phpbb\template\template $templat */ public function run_tool($tool, $id) { - if (!in_array($tool, array('automod', 'mpv', 'epv'))) + if ($tool != 'epv') { return $this->helper->error('INVALID_TOOL', 404); } @@ -131,103 +131,11 @@ protected function epv() redirect($post->get_url()); } - /** - * Run MOD PreValidator. - * - * @return \Symfony\Component\HttpFoundation\Response - */ - protected function mpv() - { - if (!$this->contrib->type->mpv_test) - { - return $this->helper->error('INVALID_TOOl'); - } - - // Run MPV - $prevalidator = $this->contrib->type->get_prevalidator(); - $results = $prevalidator->run_mpv($this->attachment->get_url()); - $errors = $prevalidator->get_errors(); - - if ($results === false) - { - return $this->helper->error('MPV_TEST_FAILED'); - } - else - { - $results = $this->get_result_post('VALIDATION_PV', $results); - $post = $this->queue->topic_reply($results); - } - - if (!empty($errors)) - { - return $this->helper->error(implode('
', $errors)); - } - - redirect($post->get_url()); - } - - /** - * Run AutoMOD Tests. - * - * @return \Symfony\Component\HttpFoundation\Response - */ - protected function automod() - { - if (!$this->contrib->type->automod_test) - { - return $this->helper->error('INVALID_TOOl'); - } - $this->package->ensure_extracted(); - - // Start up the machine - $prevalidator = $this->contrib->type->get_prevalidator(); - - // Automod testing time - $details = ''; - $html_results = $bbcode_results = array(); - $this->revision->load_phpbb_versions(); - - foreach ($this->revision->phpbb_versions as $row) - { - $version_string = $row['phpbb_version_branch'][0] . '.' . $row['phpbb_version_branch'][1] . '.' . $row['phpbb_version_revision']; - $phpbb_path = $prevalidator->get_helper()->prepare_phpbb_test_directory($version_string); - - if ($phpbb_path === false) - { - continue; - } - - $this->template->assign_vars(array( - 'PHPBB_VERSION' => $version_string, - 'TEST_ID' => $row['row_id'], - )); - - $html_result = $bbcode_result = ''; - $prevalidator->run_automod_test( - $this->package, - $phpbb_path, - $details, - $html_result, - $bbcode_result - ); - - $bbcode_results[] = $bbcode_result; - } - - $bbcode_results = $this->get_result_post('VALIDATION_AUTOMOD', implode("\n\n", $bbcode_results)); - - // Update the queue with the results - $post = $this->queue->topic_reply($bbcode_results); - $this->package->cleanup(); - - redirect($post->get_url()); - } - /** * Load objects needed to run a tool. * * @param int $id Revision id. - * @return null + * @return void */ protected function load_objects($id) { @@ -242,7 +150,7 @@ protected function load_objects($id) * Load revision. * * @throws \Exception Throws exception if no revision found. - * @return null + * @return void */ protected function load_revision($id) { @@ -259,7 +167,7 @@ protected function load_revision($id) * Load revision's parent contribution. * * @throws \Exception Throws exception if no contrib found. - * @return null + * @return void */ protected function load_contrib() { @@ -275,7 +183,7 @@ protected function load_contrib() /** * Load revision's corresponding queue item. * - * @return null + * @return void */ protected function load_queue() { @@ -286,7 +194,7 @@ protected function load_queue() * Load revision attachment. * * @throws \Exception Throws exception if no attachment found. - * @return null + * @return void */ protected function load_attachment() { diff --git a/includes/library/automod/acp_mods.php b/includes/library/automod/acp_mods.php deleted file mode 100644 index 350ad5a08..000000000 --- a/includes/library/automod/acp_mods.php +++ /dev/null @@ -1,2955 +0,0 @@ -add_lang(array('install', 'acp/mods')); - - $this->tpl_name = 'acp_mods'; - $this->page_title = 'ACP_CAT_MODS'; - $this->store_dir = $phpbb_root_path . 'store'; - $this->mods_dir = $phpbb_root_path . 'store/mods'; - - // get any url vars - $action = request_var('action', ''); - $mod_id = request_var('mod_id', 0); - $mod_url = request_var('mod_url', ''); - $parent = request_var('parent', 0); - - //sort keys - $sort_key = request_var('sk','t'); - $sort_dir = request_var('sd', 'a'); - - - $mod_path = request_var('mod_path', ''); - - if ($mod_path) - { - $mod_path = htmlspecialchars_decode($mod_path); // "/my_mod/install.xml" or "/./contrib/blah.xml" - $mod_dir = substr($mod_path, 1, strpos($mod_path, '/', 1)); // "my_mod/" - - $this->mod_root = $this->mods_dir . '/' . $mod_dir; // "./../store/mods/my_mod/" - $this->backup_root = "{$this->mod_root}_backups/"; // "./../store/mods/my_mod/_backups/" - $this->edited_root = "{$this->mod_root}_edited/"; // "./../store/mods/my_mod/_edited/" - } - - switch ($mode) - { - case 'config': - $ftp_method = request_var('ftp_method', $config['ftp_method']); - if (!$ftp_method || !class_exists($ftp_method)) - { - $ftp_method = 'ftp'; - $ftp_methods = transfer::methods(); - - if (!in_array('ftp', $ftp_methods)) - { - $ftp_method = $ftp_methods[0]; - } - } - - if (isset($_POST['submit']) && check_form_key('acp_mods')) - { - $ftp_host = request_var('host', ''); - $ftp_username = request_var('username', ''); - $ftp_password = request_var('password', ''); // not stored, used to test connection - $ftp_root_path = request_var('root_path', ''); - $ftp_port = request_var('port', 21); - $ftp_timeout = request_var('timeout', 10); - $write_method = request_var('write_method', 0); - $file_perms = request_var('file_perms', '0644'); - $dir_perms = request_var('dir_perms', '0755'); - $compress_method = request_var('compress_method', ''); - $preview_changes = request_var('preview_changes', 0); - - - $error = ''; - if ($write_method == WRITE_DIRECT) - { - // the very best method would be to check every file for is_writable - if (!is_writable("{$phpbb_root_path}common.$phpEx") || !is_writable("{$phpbb_root_path}adm/style/acp_groups.html")) - { - $error = 'FILESYSTEM_NOT_WRITABLE'; - } - } - else if ($write_method == WRITE_FTP) - { - // check the correctness of FTP infos - $test_ftp_connection = true; - $test_connection = false; - test_ftp_connection($ftp_method, $test_ftp_connection, $test_connection); - - if ($test_connection !== true) - { - $error = $test_connection; - } - } - else if ($write_method == WRITE_MANUAL) - { - // the compress class requires write access to the store/ dir - if (!is_writable($this->store_dir)) - { - $error = 'STORE_NOT_WRITABLE'; - } - } - - if (empty($error)) - { - set_config('ftp_method', $ftp_method); - set_config('ftp_host', $ftp_host); - set_config('ftp_username', $ftp_username); - set_config('ftp_root_path', $ftp_root_path); - set_config('ftp_port', $ftp_port); - set_config('ftp_timeout', $ftp_timeout); - set_config('write_method', $write_method); - set_config('compress_method', $compress_method); - set_config('preview_changes', $preview_changes); - set_config('am_file_perms', $file_perms); - set_config('am_dir_perms', $dir_perms); - - trigger_error($user->lang['MOD_CONFIG_UPDATED'] . adm_back_link($this->u_action)); - } - else - { - $template->assign_var('ERROR', $user->lang[$error]); - } - } - else if (isset($_POST['submit']) && !check_form_key('acp_mods')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - add_form_key('acp_mods'); - - // implicit else - include("{$phpbb_root_path}includes/functions_compress.$phpEx"); - foreach (compress::methods() as $compress_method) - { - $template->assign_block_vars('compress', array( - 'METHOD' => $compress_method, - )); - } - - $requested_data = call_user_func(array($ftp_method, 'data')); - foreach ($requested_data as $data => $default) - { - $default = (!empty($config['ftp_' . $data])) ? $config['ftp_' . $data] : $default; - $template->assign_block_vars('data', array( - 'DATA' => $data, - 'NAME' => $user->lang[strtoupper($ftp_method . '_' . $data)], - 'EXPLAIN' => $user->lang[strtoupper($ftp_method . '_' . $data) . '_EXPLAIN'], - 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default - )); - } - - $template->assign_vars(array( - 'S_CONFIG' => true, - 'U_CONFIG' => $this->u_action . '&mode=config', - - 'UPLOAD_METHOD_FTP' => ($config['ftp_method'] == 'ftp') ? ' checked="checked"' : '', - 'UPLOAD_METHOD_FSOCK'=> ($config['ftp_method'] == 'ftp_fsock') ? ' checked="checked"' : '', - 'WRITE_DIRECT' => ($config['write_method'] == WRITE_DIRECT) ? ' checked="checked"' : '', - 'WRITE_FTP' => ($config['write_method'] == WRITE_FTP) ? ' checked="checked"' : '', - 'WRITE_MANUAL' => ($config['write_method'] == WRITE_MANUAL) ? ' checked="checked"' : '', - - 'WRITE_METHOD_DIRECT' => WRITE_DIRECT, - 'WRITE_METHOD_FTP' => WRITE_FTP, - 'WRITE_METHOD_MANUAL' => WRITE_MANUAL, - - 'AUTOMOD_VERSION' => $config['automod_version'], - 'COMPRESS_METHOD' => $config['compress_method'], - 'DIR_PERMS' => $config['am_dir_perms'], - 'FILE_PERMS' => $config['am_file_perms'], - 'PREVIEW_CHANGES_YES' => ($config['preview_changes']) ? ' checked="checked"' : '', - 'PREVIEW_CHANGES_NO' => (!$config['preview_changes']) ? ' checked="checked"' : '', - 'S_HIDE_FTP' => ($config['write_method'] == WRITE_FTP) ? false : true, - )); - break; - - case 'frontend': - if ($config['write_method'] == WRITE_FTP) - { - $ftp_method = basename(request_var('method', $config['ftp_method'])); - if (!$ftp_method || !class_exists($ftp_method)) - { - $ftp_method = 'ftp'; - $ftp_methods = transfer::methods(); - - if (!in_array('ftp', $ftp_methods)) - { - $ftp_method = $ftp_methods[0]; - } - } - - $test_connection = false; - $test_ftp_connection = request_var('test_connection', ''); - if (!empty($test_ftp_connection) || in_array($action, array('install', 'uninstall', 'upload_mod', 'delete_mod'))) - { - test_ftp_connection($ftp_method, $test_ftp_connection, $test_connection); - - // Make sure the login details are correct before continuing - if ($test_connection !== true || !empty($test_ftp_connection)) - { - $action = 'pre_' . $action; - } - } - } - - // store/ needs to be world-writable even when FTP is the write method, - // for extracting uploaded mod zip files - if (!is_writable($this->store_dir)) - { - $template->assign_var('S_STORE_WRITABLE_WARN', true); - } - // Otherwise, store/mods/ needs to be writable - else if ($config['write_method'] != WRITE_FTP && !is_writable($this->mods_dir)) - { - $template->assign_var('S_MODS_WRITABLE_WARN', true); - } - - switch ($action) - { - case 'pre_install': - case 'install': - $this->install($action, $mod_path, $parent); - break; - - case 'pre_uninstall': - case 'uninstall': - $this->uninstall($action, $mod_id, $parent); - break; - - case 'details': - $mod_ident = ($mod_id) ? $mod_id : $mod_path; - $this->list_details($mod_ident); - break; - - case 'pre_delete_mod': - case 'delete_mod': - $this->delete_mod($action, $mod_path); - break; - - case 'pre_upload_mod': - case 'upload_mod': - default: - $action = (isset($action)) ? $action : ''; - if (!$this->upload_mod($action)) - { - $this->list_installed(); - $this->list_uninstalled(); - } - break; - - case 'download': - include ($phpbb_root_path . "includes/functions_compress.$phpEx"); - $editor = new editor_manual(); - - $time = request_var('time', 0); - - // if for some reason the MOD isn't found in the DB... - $download_name = 'mod_' . $time; - $sql = 'SELECT mod_name FROM ' . MODS_TABLE . ' - WHERE mod_time = ' . $time; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - // Always use the English name except for showing the user. - $mod_name = localize_title($row['mod_name'], 'en'); - $download_name = str_replace(' ', '_', $mod_name); - } - - $editor->compress->download("{$this->store_dir}/mod_$time", $download_name); - exit; - break; - } - - return; - - break; - - } - } - - /** - * List all the installed mods - */ - function list_installed() - { - global $db, $template, $user, $sort_key, $sort_dir; - $sort_by_text = array('u' => $user->lang['SORT_NAME'], 't' => $user->lang['SORT_DATE']); - - ($sort_key == 't')? $sort='mod_time' & $s_sort_key='mod_time': $sort='mod_name' & $s_sort_key='mod_name'; - ($sort_dir == 'd') ? $dir='DESC' & $s_sort_dir='DESC' : $dir='ASC' & $s_sort_dir='ASC'; - $limit_days = array(); - $s_limit_days=$sort_days=$s_limit_days = $u_sort_param = ''; - gen_sort_selects($limit_days, $sort_by_text, $sort_days, $sort_key, $sort_dir, $s_limit_days, $s_sort_key, $s_sort_dir, $u_sort_param); - - $template->assign_vars(array( - 'S_SORT_KEY' => $s_sort_key, - 'S_SORT_DIR' => $s_sort_dir, - 'U_SORT_ACTION' => $this->u_action ."&$u_sort_param" - )); - // The MOD name is a array so it can't be used as sort key directly. - $sql_sort = ($sort_key == 't') ? " ORDER BY mod_time $dir" : ''; - $sql = 'SELECT mod_name, mod_id, mod_time - FROM ' . MODS_TABLE . - $sql_sort; - $result = $db->sql_query($sql); - $mod_ary = $db->sql_fetchrowset($result); - $db->sql_freeresult($result); - - foreach ($mod_ary as $key => $row) - { - if (($name_ary = @unserialize($row['mod_name'])) === false) - { - $name_ary['en'] = $row['mod_name']; - } - - $mod_ary[$key]['mod_name'] = $name_ary; - } - - if ($sort_key != 't') - { - $sort_ary = array(); - foreach ($mod_ary as $key => $row) - { - $sort_ary[$key] = $row['mod_name']['en']; - } - - if ($sort_dir == 'd') - { - arsort($sort_ary, SORT_STRING); - } - else - { - asort($sort_ary, SORT_STRING); - } - - foreach ($sort_ary as $key => $name) - { - $sort_ary[$key] = $mod_ary[$key]; - } - - $mod_ary = $sort_ary; - unset($sort_ary); - } - - foreach ($mod_ary as $row) - { - $mod_name = localize_title($row['mod_name'], $user->data['user_lang']); - $template->assign_block_vars('installed', array( - 'MOD_ID' => $row['mod_id'], - 'MOD_NAME' => htmlspecialchars($mod_name), - - 'MOD_TIME' => $user->format_date($row['mod_time']), - - 'U_DETAILS' => $this->u_action . '&action=details&mod_id=' . $row['mod_id'], - 'U_UNINSTALL' => $this->u_action . '&action=pre_uninstall&mod_id=' . $row['mod_id']) - ); - } - - return; - } - - /** - * List all mods available locally - */ - function list_uninstalled() - { - global $phpbb_root_path, $db, $template, $config, $user; - - // get available MOD paths - $available_mods = $this->find_mods($this->mods_dir, 1); - - if (!sizeof($available_mods['main'])) - { - return; - } - - // get installed MOD paths - $installed_paths = array(); - $sql = 'SELECT mod_path - FROM ' . MODS_TABLE; - $result = $db->sql_query($sql); - while ($row = $db->sql_fetchrow($result)) - { - $installed_paths[] = $row['mod_path']; - } - $db->sql_freeresult($result); - - $mod_paths = array(); - foreach ($available_mods['main'] as $mod_info) - { - $mod_paths[] = $mod_info['href']; - } - - // we don't care about any xml files not in the main directory - $available_mods = array_diff($mod_paths, $installed_paths); - unset($installed_paths); - unset($mod_paths); - - // show only available MODs that paths aren't in the DB - foreach ($available_mods as $file) - { - $details = $this->mod_details($file, false); - $short_path = urlencode(str_replace($this->mods_dir, '', $details['MOD_PATH'])); - $mod_name = localize_title($details['MOD_NAME'], $user->data['user_lang']); - - $template->assign_block_vars('uninstalled', array( - 'MOD_NAME' => htmlspecialchars($mod_name), - 'MOD_PATH' => $short_path, - - 'PHPBB_VERSION' => $details['PHPBB_VERSION'], - 'S_PHPBB_VESION' => ($details['PHPBB_VERSION'] != $config['version']) ? true : false, - - 'U_INSTALL' => $this->u_action . "&action=pre_install&mod_path=$short_path", - 'U_DELETE' => $this->u_action . "&action=pre_delete_mod&mod_path=$short_path", - 'U_DETAILS' => $this->u_action . "&action=details&mod_path=$short_path", - )); - } - - return; - } - - /** - * Lists mod details - */ - function list_details($mod_ident) - { - global $template, $config, $user; - - $template->assign_vars(array( - 'S_DETAILS' => true, - 'U_BACK' => $this->u_action, - )); - - $details = $this->mod_details($mod_ident, true); - - if (!is_int($mod_ident) && $details['PHPBB_VERSION'] != $config['version']) - { - $version_warnig = sprintf($user->lang['VERSION_WARNING'], $details['PHPBB_VERSION'], $config['version']); - - $template->assign_vars(array( - 'VERSION_WARNING' => $version_warnig, - 'S_PHPBB_VESION' => true, - )); - } - - if (!empty($details['AUTHOR_DETAILS'])) - { - foreach ($details['AUTHOR_DETAILS'] as $author_details) - { - $template->assign_block_vars('author_list', $author_details); - } - unset($details['AUTHOR_DETAILS']); - } - - // Display Do-It-Yourself Actions...per the MODX spec, - // Need to handle the languag later, but it's not saved for now. - if (!empty($details['DIY_INSTRUCTIONS'])) - { - $template->assign_var('S_DIY', true); - - if (!is_array($details['DIY_INSTRUCTIONS'])) - { - $details['DIY_INSTRUCTIONS'] = array($details['DIY_INSTRUCTIONS']); - } - - foreach ($details['DIY_INSTRUCTIONS'] as $instruction) - { - $template->assign_block_vars('diy_instructions', array( - 'DIY_INSTRUCTION' => nl2br($instruction), - )); - } - } - - if (!empty($details['MOD_HISTORY'])) - { - $template->assign_var('S_CHANGELOG', true); - - foreach ($details['MOD_HISTORY'] as $mod_version) - { - $template->assign_block_vars('changelog', array( - 'VERSION' => $mod_version['VERSION'], - 'DATE' => $mod_version['DATE'], - )); - - foreach ($mod_version['CHANGES'] as $changes) - { - $template->assign_block_vars('changelog.changes', array( - 'CHANGE' => $changes, - )); - } - } - } - - unset($details['MOD_HISTORY']); - - $details['MOD_NAME'] = localize_title($details['MOD_NAME'], $user->data['user_lang']); - $details['MOD_NAME'] = htmlspecialchars($details['MOD_NAME']); - - $template->assign_vars($details); - - if (!empty($details['AUTHOR_NOTES'])) - { - $template->assign_var('S_AUTHOR_NOTES', true); - } - if (!empty($details['MOD_INSTALL_TIME'])) - { - $template->assign_var('S_INSTALL_TIME', true); - } - - return; - } - - /** - * Returns array of mod information - */ - function mod_details($mod_ident, $find_children = true, $uninstall = false) - { - global $phpbb_root_path, $phpEx, $user, $template, $parent_id; - - if (is_int($mod_ident)) - { - global $db, $user; - - $mod_id = (int) $mod_ident; - - $sql = 'SELECT * - FROM ' . MODS_TABLE . " - WHERE mod_id = $mod_id"; - $result = $db->sql_query($sql); - if ($row = $db->sql_fetchrow($result)) - { - // TODO: Yuck, get rid of this. - $author_details = array(); - $author_details[0] = array( - 'AUTHOR_NAME' => $row['mod_author_name'], - 'AUTHOR_EMAIL' => $row['mod_author_email'], - 'AUTHOR_WEBSITE' => $row['mod_author_url'], - ); - - $actions = unserialize($row['mod_actions']); - - $details = array( - 'MOD_ID' => $row['mod_id'], - 'MOD_PATH' => $row['mod_path'], - 'MOD_INSTALL_TIME' => $user->format_date($row['mod_time']), -// 'MOD_DEPENDENCIES' => unserialize($row['mod_dependencies']), // ? - 'MOD_NAME' => $row['mod_name'], - 'MOD_DESCRIPTION' => nl2br($row['mod_description']), - 'MOD_VERSION' => $row['mod_version'], - - 'DIY_INSTRUCTIONS' => (!empty($actions['DIY_INSTRUCTIONS'])) ? $actions['DIY_INSTRUCTIONS'] : '', - - 'AUTHOR_NOTES' => nl2br($row['mod_author_notes']), - 'AUTHOR_DETAILS' => $author_details, - ); - - // This is a check for any further XML files to go with this MOD. - // Obviously, the files must not have been removed for this to work. - if (($find_children || $uninstall) && file_exists($row['mod_path'])) - { - $parent_id = $mod_id; - $mod_path = $row['mod_path']; - - $actions = array(); - - $mod_dir = dirname($mod_path); - $this->mod_root = $mod_dir . '/'; - - $ext = substr(strrchr($mod_path, '.'), 1); - $this->parser = new parser($ext); - $this->parser->set_file($mod_path); - - // Find and display the available MODX files - $children = $this->find_children($mod_path); - - $elements = array('language' => array(), 'template' => array()); - $found_prosilver = false; - - if (!$uninstall) - { - $this->handle_contrib($children); - $this->handle_language_prompt($children, $elements, 'details'); - $this->handle_template_prompt($children, $elements, 'details'); - - // Now offer to install additional templates - if (isset($children['template']) && sizeof($children['template'])) - { - // These are the instructions included with the MOD - foreach ($children['template'] as $template_name) - { - if (!is_array($template_name)) - { - continue; - } - - if ($template_name['realname'] == 'prosilver') - { - $found_prosilver = true; - } - - if (file_exists($this->mod_root . $template_name['href'])) - { - $xml_file = $template_name['href']; - } - else - { - $xml_file = str_replace($this->mods_dir, '', $mod_dir) . '/' . $template_name['href']; - } - - $template->assign_block_vars('avail_templates', array( - 'TEMPLATE_NAME' => $template_name['realname'], - 'XML_FILE' => urlencode($xml_file), - )); - } - } - } - else - { - if (isset($children['uninstall']) && sizeof($children['uninstall'])) - { - // Override already exising actions with the ones - global $rev_actions; - $xml_file = $mod_dir . '/' . ltrim($children['uninstall'][0]['href'], './'); - $this->parser->set_file($xml_file); - $rev_actions = $this->parser->get_actions(); - } - } - - if (!$found_prosilver) - { - $template->assign_block_vars('avail_templates', array( - 'TEMPLATE_NAME' => 'prosilver', - 'XML_FILE' => basename($mod_path), - )); - } - - $processed_templates = array('prosilver'); - $processed_templates += explode(',', $row['mod_template']); - -/* - // now grab the templates that have not already been processed - $sql = 'SELECT template_id, template_path FROM ' . STYLES_TEMPLATE_TABLE . ' - WHERE ' . $db->sql_in_set('template_name', $processed_templates, true); - $result = $db->sql_query($sql); - - while ($row = $db->sql_fetchrow($result)) - { - $template->assign_block_vars('board_templates', array( - 'TEMPLATE_ID' => $row['template_id'], - 'TEMPLATE_NAME' => $row['template_path'], - )); - } -*/ - - $s_hidden_fields = build_hidden_fields(array( - 'action' => 'install', - 'parent' => $parent_id, - )); - - $template->assign_vars(array( - 'S_FORM_ACTION' => $this->u_action, - 'S_HIDDEN_FIELDS' => $s_hidden_fields, - )); - - add_form_key('acp_mods'); - } - } - else - { - trigger_error($user->lang['NO_MOD'] . adm_back_link($this->u_action), E_USER_WARNING); - } - $db->sql_freeresult($result); - } - else - { - $parent = request_var('parent', 0); - if ($parent) - { - global $db; - // reset the class parameters to refelect the proper directory - $sql = 'SELECT mod_path FROM ' . MODS_TABLE . ' - WHERE mod_id = ' . (int) $parent; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $this->mod_root = dirname($row['mod_path']) . '/'; - } - } - - if (strpos($mod_ident, $this->mods_dir) === false) - { - $mod_ident = $this->mods_dir . $mod_ident; - } - - if (!file_exists($mod_ident)) - { - $mod_ident = str_replace($this->mods_dir, $this->mod_root, $mod_ident); - } - - $mod_path = $mod_ident; - $mod_parent = 0; - - $ext = substr(strrchr($mod_path, '.'), 1); - - $this->parser = new parser($ext); - $this->parser->set_file($mod_path); - - $details = $this->parser->get_details(); - - if ($find_children) - { - $actions = array(); - $children = $this->find_children($mod_path); - - $elements = array('language' => array(), 'template' => array()); - - $this->handle_contrib($children); - $this->handle_language_prompt($children, $elements, 'details'); - $this->handle_template_prompt($children, $elements, 'details'); - } - } - - return $details; - } - - /** - * Returns complex array of all mod actions - */ - function mod_actions($mod_ident) - { - global $phpbb_root_path, $phpEx; - - if (is_int($mod_ident)) - { - global $db, $user; - - $sql = 'SELECT mod_actions, mod_name - FROM ' . MODS_TABLE . " - WHERE mod_id = $mod_ident"; - $result = $db->sql_query($sql); - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if ($row) - { - $mod_actions = unserialize($row['mod_actions']); - - if (@unserialize($row['mod_name']) === false) - { - // On version 1.0.1 and later the mod name is a serialized array. - // Earlier it was a string so unserialize will fail. - $mod_actions['EDITS'] = $this->update_edits($mod_actions['EDITS']); - } - - return($mod_actions); - } - else - { - trigger_error($user->lang['NO_MOD'] . adm_back_link($this->u_action), E_USER_WARNING); - } - } - else - { - if (strpos($mod_ident, $this->mods_dir) === false) - { - $mod_ident = $this->mods_dir . $mod_ident; - } - - if (!file_exists($mod_ident)) - { - $mod_ident = str_replace($this->mods_dir, $this->mod_root, $mod_ident); - } - - $this->parser->set_file($mod_ident); - $actions = $this->parser->get_actions(); - } - - return $actions; - - } - - /** - * Updates inline edits for MODs installed before AutoMOD 1.0.1. - * - * @param array $mod_edits, MOD actions directly from the DB. - * @return mixed uppdated array or false on error. - */ - function update_edits($mod_edits) - { - if (empty($mod_edits)) - { - return(false); - } - - $updated_ary = array(); - - foreach ($mod_edits as $file => $edits) - { - $updated_ary[$file] = array(); - $inline = false; - $key = 0; - $old_find = $find_line = ''; - - foreach ($edits as $edit) - { - foreach ($edit as $find => $action) - { - $first_key = key($action); // The first key contains the action or "in-line-edit". - - if ($first_key != 'in-line-edit') - { - if ($inline) - { - $updated_ary[$file][$key++][$find_line] = array('in-line-edit' => $inline_edit); - $inline_edit = array(); - $inline = false; - $old_find = $find_line = ''; - } - - $updated_ary[$file][$key++][$find] = $action; - $inline = false; - continue; - } - - $inline = true; - $inline_edit = (empty($inline_edit)) ? array() : $inline_edit; - - if (!empty($old_find) && !$this->same_line($old_find, $find, $action['in-line-edit'])) - { - $updated_ary[$file][$key++][$find_line] = array('in-line-edit' => $inline_edit); - $inline_edit = array(); - } - - $find_line = $find; - $old_find = $find; - $inline_edit[] = $action['in-line-edit']; - } - } - - if ($inline && !empty($inline_edit)) - { - $updated_ary[$file][$key++][$find_line] = array('in-line-edit' => $inline_edit); - $inline = false; - $inline_edit = array(); - $old_find = $find_line = ''; - } - } - - return($updated_ary); - } - - /** - * Tries to check if two inline edits are editing the same line. - * - * @param string $prev, the find from the previous in-line-edit. - * @param string $find, the find for the current in-line-edit. - * @param array $action, the current edit array. - * @return bool true for identical lines, otherwise false - */ - function same_line($prev_find, $find, $action) - { - if (empty($prev_find) || empty($find)) - { - // If both are empty something is wrong. - return(false); - } - - // The first key in $action is the in-line-find string - $edit_ary = reset($action); // Array with what to do and what to remove. - $inline_find = key($action); // String to find in $find. - - $add_ary = reset($edit_ary); // $add_ary[0] contains the string to remove from $find - $add_str = $add_ary[0]; - $inline_action = key($edit_ary); // What to do. - - // The actions currently supported are in-line-before-add and in-line-after-add. - // replace and delete will be added later. - switch ($inline_action) - { - case 'in-line-replace': - // There are no positions stored in the DB so we can not be sure that there - // is only one occasion of the string added instead of the search string. - // Keeping count on the previous edits still don't give a 100% guaranty that - // we are in the right place in the string. - $compare = str_replace($add_str, $inline_find, $find); - break; - - case 'in-line-before-add': - $pos = strpos($find, $inline_find); - $len = strlen($add_str); - $start = $pos - $len; - $compare = substr_replace($find, '', $start, $len); - break; - - case 'in-line-after-add': - $pos = strpos($find, $inline_find); - $start = $pos + strlen($inline_find); - $compare = substr_replace($find, '', $start, strlen($add_str)); - break; - - case 'inline-remove': - default: - // inline-remove don't yet work to install with AutoMOD so I assume nobody - // is trying to remove it either in MODs installed with 1.0.0.1 or earlier. - return(false); - break; - } - - $check = ($compare == $prev_find) ? true : false; - return($check); - } - - /** - * Install/pre-install a mod - * Preforms all Edits, Copies, and SQL queries - */ - function install($action, $mod_path, $parent = 0) - { - global $phpbb_root_path, $phpEx, $db, $template, $user, $config, $cache, $dest_template; - global $force_install, $mod_installed; - - // Are we forcing a template install? - $dest_template = $mod_contribs = $mod_language = ''; - if (isset($_POST['template_submit'])) - { - if (!check_form_key('acp_mods')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $mod_path = urldecode(request_var('source', '')); - $dest_template = request_var('dest', ''); - - if (preg_match('#.*install.*xml$#i', $mod_path)) - { - $src_template = 'prosilver'; - } - else - { - preg_match('#([a-z0-9]+)$#i', core_basename($mod_path), $match); - $src_template = $match[1]; - unset ($match); - } - } - - if (empty($mod_path)) - { - return false; // ERROR - } - - $details = $this->mod_details($mod_path, false); - - if (!$parent) - { - // $details['MOD_NAME'] is a array and not knowing what language was used when the MOD was installed, - // if it was installed with AutoMOD 1.0.0. So need to check all. - $sql_where = ''; - foreach ($details['MOD_NAME'] as $mod_name) - { - $sql_where .= (($sql_where == '') ? ' mod_name ' : ' OR mod_name ') . $db->sql_like_expression($db->any_char . $mod_name . $db->any_char); - } - - $sql = 'SELECT mod_name FROM ' . MODS_TABLE . " - WHERE $sql_where"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - trigger_error('AM_MOD_ALREADY_INSTALLED'); - } - } - else if ($dest_template) // implicit && $parent - { - // Has this template already been processed? - $sql = 'SELECT mod_name - FROM ' . MODS_TABLE . " - WHERE mod_id = $parent - AND mod_template " . $db->sql_like_expression($db->any_char . $dest_template . $db->any_char); - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - trigger_error('AM_MOD_ALREADY_INSTALLED'); - } - $db->sql_freeresult($result); - } - // NB: There could and should be cases to check for duplicated MODs and contribs - // However, there is not appropriate book-keeping in place for those in 1.0.x - // grab installed contrib and language items from the database - if ($parent) - { - $modx_type = request_var('type', ''); - if ($modx_type == 'lang') - { - $sql = 'SELECT mod_name - FROM ' . MODS_TABLE . " - WHERE mod_id = $parent - AND mod_languages " . $db->sql_like_expression($db->any_char . $mod_path . $db->any_char); - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - trigger_error('AM_MOD_ALREADY_INSTALLED'); - } - else - { - $mod_language = $mod_path; - } - $db->sql_freeresult($result); - } - elseif ($modx_type == 'contrib') - { - $sql = 'SELECT mod_name - FROM ' . MODS_TABLE . " - WHERE mod_id = $parent - AND mod_contribs " . $db->sql_like_expression($db->any_char . $mod_path . $db->any_char); - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - trigger_error('AM_MOD_ALREADY_INSTALLED'); - } - else - { - $mod_contribs = $mod_path; - } - $db->sql_freeresult($result); - } - } - - $execute_edits = ($action == 'pre_install') ? false : true; - $write_method = 'editor_' . determine_write_method(!$execute_edits); - $editor = new $write_method(); - - // get FTP information if we need it (or initialize array $hidden_ary) - $hidden_ary = get_connection_info(!$execute_edits); - - $actions = $this->mod_actions($mod_path); - - if ($dest_template) - { - $sql = 'SELECT template_inherit_path FROM ' . STYLES_TEMPLATE_TABLE . " - WHERE template_path = '" . $db->sql_escape($dest_template) . "'"; - $result = $db->sql_query($sql); - - global $dest_inherits; - $dest_inherits = ''; - if ($row = $db->sql_fetchrow($result)) - { - $dest_inherits = $row['template_inherit_path']; - } - $db->sql_freeresult($result); - - if (!empty($actions['EDITS'])) - { - foreach ($actions['EDITS'] as $file => $edits) - { - if (strpos($file, 'styles/') === false) - { - unset($actions['EDITS'][$file]); - } - else if ($src_template != $dest_template) - { - $file_new = str_replace($src_template, $dest_template, $file); - $actions['EDITS'][$file_new] = $edits; - unset($actions['EDITS'][$file]); - } - } - } - - if (!empty($actions['NEW_FILES'])) - { - foreach ($actions['NEW_FILES'] as $src_file => $dest_file) - { - if (strpos($src_file, 'styles/') === false) - { - unset($actions['NEW_FILES']); - } - else - { - $actions['NEW_FILES'][$src_file] = str_replace($src_template, $dest_template, $dest_file); - } - } - } - } - - // only supporting one level of hierarchy here - if (!$parent) - { - // check for "child" MODX files and attempt to decide which ones we need - $children = $this->find_children($mod_path); - - $elements = array('language' => array(), 'template' => array()); - - if ($execute_edits) - { - global $mode; - $this->handle_dependency($children, $mode, $mod_path); - } - $this->handle_language_prompt($children, $elements, $action); - $this->handle_merge('language', $actions, $children, $elements['language']); - $this->handle_template_prompt($children, $elements, $action); - $this->handle_merge('template', $actions, $children, $elements['template']); - } - else - { - if ($dest_template) - { - $elements['template'] = array($dest_template); - } - elseif ($mod_language) - { - $elements['language'] = array($mod_path); - } - else - { - $elements['contrib'] = array($mod_path); - } - } - - $template->assign_vars(array( - 'S_INSTALL' => $execute_edits, - 'S_PRE_INSTALL' => !$execute_edits, - 'MOD_PATH' => str_replace($this->mod_root, '', $mod_path), - 'U_INSTALL' => $this->u_action . '&action=install' . ($parent ? "&parent=$parent" : ''), - 'U_RETURN' => $this->u_action, - 'U_BACK' => $this->u_action, - )); - - if ($execute_edits) - { - $editor->create_edited_root($this->edited_root); - $force_install = request_var('force', false); - } - - $display = ($execute_edits || $config['preview_changes']) ? true : false; - - // process the actions - $mod_installed = $this->process_edits($editor, $actions, $details, $execute_edits, $display, false); - - if (!$execute_edits) - { - $s_hidden_fields = array('dependency_confirm' => !empty($_REQUEST['dependency_confirm'])); - - if ($dest_template) - { - $s_hidden_fields['dest'] = $dest_template; - $s_hidden_fields['source'] = $mod_path; - $s_hidden_fields['template_submit'] = true; - } - - if ($parent) - { - $s_hidden_fields['type'] = $modx_type; - } - - $template->assign_var('S_HIDDEN_FIELDS', build_hidden_fields($s_hidden_fields)); - add_form_key('acp_mods'); - - return; - } // end pre_install - - // Display Do-It-Yourself Actions...per the MODX spec, these should be displayed last - if (!empty($actions['DIY_INSTRUCTIONS'])) - { - $template->assign_var('S_DIY', true); - - if (!is_array($actions['DIY_INSTRUCTIONS'])) - { - $actions['DIY_INSTRUCTIONS'] = array($actions['DIY_INSTRUCTIONS']); - } - - foreach ($actions['DIY_INSTRUCTIONS'] as $instruction) - { - $template->assign_block_vars('diy_instructions', array( - 'DIY_INSTRUCTION' => nl2br($instruction), - )); - } - } - - if (!empty($actions['PHP_INSTALLER'])) - { - $template->assign_vars(array( - 'U_PHP_INSTALLER' => $phpbb_root_path . $actions['PHP_INSTALLER'], - )); - } - - if ($mod_installed || $force_install) - { - // Move edited files back - $status = $editor->commit_changes($this->edited_root, ''); - - if (is_string($status)) - { - $mod_installed = false; - - $template->assign_block_vars('error', array( - 'ERROR' => $status, - )); - } - } - - // The editor class provides more pertinent information regarding edits - // so we store that as the canonical version, used for uninstalling - $actions['EDITS'] = $editor->mod_actions; - $editor->clear_actions(); - - // if MOD installed successfully, make a record. - if (($mod_installed || $force_install) && !$parent) - { - $mod_name = (is_array($details['MOD_NAME'])) ? serialize($details['MOD_NAME']) : $details['MOD_NAME']; - - // Insert database data - $sql = 'INSERT INTO ' . MODS_TABLE . ' ' . $db->sql_build_array('INSERT', array( - 'mod_time' => (int) $editor->install_time, - // @todo: Are dependencies part of the MODX Spec? - 'mod_dependencies' => '', //(string) serialize($details['MOD_DEPENDENCIES']), - 'mod_name' => (string) $mod_name, - 'mod_description' => (string) $details['MOD_DESCRIPTION'], - 'mod_version' => (string) $details['MOD_VERSION'], - 'mod_path' => (string) $details['MOD_PATH'], - 'mod_author_notes' => (string) $details['AUTHOR_NOTES'], - 'mod_author_name' => (string) $details['AUTHOR_DETAILS'][0]['AUTHOR_NAME'], - 'mod_author_email' => (string) $details['AUTHOR_DETAILS'][0]['AUTHOR_EMAIL'], - 'mod_author_url' => (string) $details['AUTHOR_DETAILS'][0]['AUTHOR_WEBSITE'], - 'mod_actions' => (string) serialize($actions), - 'mod_languages' => (string) (isset($elements['language']) && sizeof($elements['language'])) ? implode(',', $elements['language']) : '', - 'mod_template' => (string) (isset($elements['template']) && sizeof($elements['template'])) ? implode(',', $elements['template']) : '', - 'mod_contribs' => (string) (isset($elements['contrib']) && sizeof($elements['contrib'])) ? implode(',', $elements['contrib']) : '', - )); - $db->sql_query($sql); - - $cache->purge(); - - // Add log - $mod_name = localize_title($details['MOD_NAME'], 'en'); - add_log('admin', 'LOG_MOD_ADD', $mod_name); - } - // in this case, we are installing an additional template or language - else if (($mod_installed || $force_install) && $parent) - { - $sql = 'SELECT * FROM ' . MODS_TABLE . " WHERE mod_id = $parent"; - $result = $db->sql_query($sql); - - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error($user->lang['NO_MOD'] . adm_back_link($this->u_action)); - } - - $sql_ary = array( - 'mod_version' => $details['MOD_VERSION'], - ); - - if (!empty($elements['language'])) - { - $sql_ary['mod_languages'] = (!empty($row['mod_languages'])) ? $row['mod_languages'] . ',' : ''; - $sql_ary['mod_languages'] .= implode(',', $elements['language']); - } - else - { - $sql_ary['mod_languages'] = $row['mod_languages']; - } - - if (!empty($elements['template'])) - { - $sql_ary['mod_template'] = $row['mod_template'] . ',' . implode(',', $elements['template']); - } - else - { - $sql_ary['mod_template'] = $row['mod_template']; - } - - if (!empty($elements['contrib'])) - { - $sql_ary['mod_contribs'] = (!empty($row['mod_contribs'])) ? $row['mod_contribs'] . ',' : ''; - $sql_ary['mod_contribs'] .= implode(',', $elements['contrib']); - } - else - { - $sql_ary['mod_contribs'] = $row['mod_contribs']; - } - - $sql_ary['mod_time'] = $editor->install_time; - - $prior_mod_actions = unserialize($row['mod_actions']); - $sql_ary['mod_actions'] = serialize(array_merge_recursive($prior_mod_actions, $actions)); - unset($prior_mod_actions); - - $sql = 'UPDATE ' . MODS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE mod_id = $parent"; - $db->sql_query($sql); - - add_log('admin', 'LOG_MOD_CHANGE', htmlspecialchars_decode($row['mod_name'])); - } - // there was an error we need to tell the user about - else - { - add_form_key('acp_mods'); - - if ($parent) - { - $hidden_ary['parent'] = $parent; - } - - if ($dest_template) - { - $hidden_ary['dest'] = $dest_template; - $hidden_ary['source'] = $mod_path; - $hidden_ary['template_submit'] = true; - } - - if ($mod_language || $mod_contribs) - { - $hidden_ary['type'] = $modx_type; - } - - $template->assign_vars(array( - 'S_ERROR' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary), - 'U_RETRY' => $this->u_action . '&action=install&mod_path=' . $mod_path, - )); - } - - // if we forced the install of the MOD, we need to let the user know their board could be broken - if ($force_install) - { - $template->assign_var('S_FORCE', true); - } - - if ($mod_installed || $force_install) - { - // $editor->commit_changes_final don't do anything ATM, but to be compatible with future versions - $mod_name = localize_title($details['MOD_NAME'], 'en'); - $editor->commit_changes_final('mod_' . $editor->install_time, str_replace(' ', '_', $mod_name)); - } - } - - /** - * Uninstall/pre uninstall a mod - */ - function uninstall($action, $mod_id, $parent) - { - global $phpbb_root_path, $phpEx, $db, $template, $user, $config; - global $force_install, $mod_uninstalled; - - if (!$mod_id && !$parent) - { - return false; // ERROR - } - - // the MOD is more important than additional MODx files - if ($parent == $mod_id) - { - $parent = 0; - } - - if ($parent) - { - // grab installed contrib and language items from the database - $sql = 'SELECT mod_languages, mod_contribs - FROM ' . MODS_TABLE . " - WHERE mod_id = $parent"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $mod_path = request_var('mod_path', ''); - if (in_array($mod_path, explode(',', $row['mod_languages']))) - { - $elements['languages'] = $mod_path; - } - elseif (in_array($mod_path, explode(',', $row['mod_contribs']))) - { - $elements['contrib'] = $mod_path; - } - else - { - trigger_error('AM_MOD_NOT_INSTALLED'); - } - - } - else - { - return false; - } - } - - // set the class parameters to reflect the proper directory - $sql = 'SELECT mod_path FROM ' . MODS_TABLE . ' - WHERE mod_id = ' . (($mod_id) ? $mod_id : $parent); - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $this->mod_root = dirname($row['mod_path']) . '/'; - $this->edited_root = "{$this->mod_root}_edited/"; - } - else - { - return false; // ERROR - } - - $execute_edits = ($action == 'pre_uninstall') ? false : true; - $write_method = 'editor_' . determine_write_method(!$execute_edits); - $editor = new $write_method(); - - // get FTP information if we need it (or initialize array $hidden_ary) - $hidden_ary = get_connection_info(!$execute_edits); - - if ($parent) - { - $hidden_ary['parent'] = $parent; - $hidden_ary['mod_path'] = $mod_path; - } - - $template->assign_vars(array( - 'S_UNINSTALL' => $execute_edits, - 'S_PRE_UNINSTALL' => !$execute_edits, - 'L_FORCE_INSTALL' => $user->lang['FORCE_UNINSTALL'], - 'MOD_ID' => $mod_id, - 'U_UNINSTALL' => ($parent) ? $this->u_action . "&action=uninstall&parent=$parent&mod_path=$mod_path" : $this->u_action . '&action=uninstall&mod_id=' . $mod_id, - 'U_RETURN' => $this->u_action, - 'U_BACK' => $this->u_action, - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary), - )); - - // grab actions and details - if (!$parent) - { - $details = $this->mod_details($mod_id, false, true); - $actions = $this->mod_actions($mod_id); - } - else - { - $details = $this->mod_details($mod_path, false); - $actions = $this->mod_actions($mod_path); - } - - if ($execute_edits) - { - $editor->create_edited_root($this->edited_root); - $force_install = $force_uninstall = request_var('force', false); - } - - $display = ($execute_edits || $config['preview_changes']) ? true : false; - - // cleanup edits if we forced the install on a contrib or language - if ($parent) - { - if (isset($actions['EDITS'])) - { - foreach ($actions['EDITS'] as $file => $edit_ary) - { - foreach ($edit_ary as $edit_id => $edit) - { - foreach ($edit as $find => $action_ary) - { - if (empty($action_ary)) - { - unset($actions['EDITS'][$file][$edit_id][$find]); - } - } - } - } - } - } - - // process the actions - $mod_uninstalled = $this->process_edits($editor, $actions, $details, $execute_edits, $display, true); - - if (!$execute_edits) - { - return; - } // end pre_uninstall - - if (($mod_uninstalled || $force_uninstall) && !$parent) - { - // Move edited files back - $status = $editor->commit_changes($this->edited_root, ''); - - if (is_string($status)) - { - $mod_uninstalled = false; - - $template->assign_block_vars('error', array( - 'ERROR' => $status, - )); - } - } -/* - elseif (($mod_uninstalled || $force_uninstall) && $parent) - { - // Only update the database entries and don't move any files back - $sql = 'SELECT * FROM ' . MODS_TABLE . " WHERE mod_id = $parent"; - $result = $db->sql_query($sql); - - $row = $db->sql_fetchrow($result); - $db->sql_freeresult($result); - - if (!$row) - { - trigger_error($user->lang['NO_MOD'] . adm_back_link($this->u_action)); - } - - $sql_ary = array( - 'mod_version' => $details['MOD_VERSION'], - ); - - if (!empty($elements['languages'])) - { - $sql_ary['mod_languages'] = explode(',', $row['mod_languages']); - foreach ($sql_ary['mod_languages'] as $key => $value) - { - if ($value != $elements['languages']); - { - unset($sql_ary['mod_languages'][$key]); - } - } - $sql_ary['mod_languages'] = implode(',', $sql_ary['mod_languages']); - } - else - { - $sql_ary['mod_languages'] = $row['mod_languages']; - } - - // let's just not support uninstalling styles edits - $sql_ary['mod_template'] = $row['mod_template']; - - if (!empty($elements['contrib'])) - { - $sql_ary['mod_contribs'] = explode(',', $row['mod_contribs']); - foreach ($sql_ary['mod_contribs'] as $key => $value) - { - if ($value != $elements['contrib']); - { - unset($sql_ary['mod_contribs'][$key]); - } - } - $sql_ary['mod_contribs'] = implode(',', $sql_ary['mod_contribs']); - } - else - { - $sql_ary['mod_contribs'] = $row['mod_contribs']; - } - - $sql_ary['mod_time'] = $row['mod_time']; - - //$prior_mod_actions = unserialize($row['mod_actions']); - //$sql_ary['mod_actions'] = serialize(array_merge_recursive($prior_mod_actions, $actions)); - $sql_ary['mod_actions'] = $row['mod_actions']; - //unset($prior_mod_actions); - - $sql = 'UPDATE ' . MODS_TABLE . ' SET ' . $db->sql_build_array('UPDATE', $sql_ary) . " - WHERE mod_id = $parent"; - $db->sql_query($sql); - - $mod_name = localize_title($row['mod_name'], $user->data['user_lang']); - add_log('admin', 'LOG_MOD_CHANGE', htmlspecialchars_decode($mod_name)); - } -*/ - // if we forced uninstall of the MOD, we need to let the user know their board could be broken - if ($force_uninstall) - { - $template->assign_var('S_FORCE', true); - } -/* - else if (!$mod_uninstalled) - { - add_form_key('acp_mods'); - - $template->assign_vars(array( - 'S_ERROR' => true, - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary), - 'U_RETRY' => $this->u_action . '&action=uninstall&mod_id=' . $mod_id, - )); - } -*/ - - if ($mod_uninstalled || $force_uninstall) - { - // Delete from DB - $sql = 'DELETE FROM ' . MODS_TABLE . ' - WHERE mod_id = ' . $mod_id; - $db->sql_query($sql); - - // Add log - $mod_name = localize_title($details['MOD_NAME'], 'en'); - $mod_name = htmlspecialchars_decode($mod_name); - add_log('admin', 'LOG_MOD_REMOVE', $mod_name); - - $mod_name = localize_title($details['MOD_NAME'], 'en'); - $editor->commit_changes_final('mod_' . $editor->install_time, str_replace(' ', '_', $mod_name)); - } - } - - /** - * Returns array of available mod install files in dir (Recursive) - * @param $dir string - dir to search - * @param $recurse int - number of levels to recurse - */ - function find_mods($dir, $recurse = false) - { - global $user; - - if ($recurse === false) - { - $mods = array('main' => array(), 'contrib' => array(), 'template' => array(), 'language' => array()); - $recurse = 0; - } - else - { - static $mods = array('main' => array(), 'contrib' => array(), 'template' => array(), 'language' => array()); - } - - // ltrim shouldn't be needed, but some users had problems. See #44305 - $dir = ltrim($dir, '/'); - - if (!file_exists($dir)) - { - return array(); - } - - if (!is_readable($dir)) - { - trigger_error(sprintf($user->lang['NEED_READ_PERMISSIONS'], $dir), E_USER_WARNING); - } - - $dp = opendir($dir); - while (($file = readdir($dp)) !== false) - { - if ($file[0] != '.' && strpos("$dir/$file", '_edited') === false && strpos("$dir/$file", '_backups') === false) - { - // recurse - we don't want anything within the MODX "root" though - if ($recurse && !is_file("$dir/$file") && strpos("$dir/$file", 'root') === false) - { - $mods = array_merge($mods, $this->find_mods("$dir/$file", $recurse - 1)); - } - // this might be better as an str function, especially being in a loop - else if (preg_match('#.*install.*xml$#i', $file) || (preg_match('#(contrib|templates|languages)#i', $dir, $match)) || ($recurse === 0 && strpos($file, '.xml') !== false)) - { - // if this is an "extra" MODX file, make a record of it as such - // we are assuming the MOD follows MODX packaging standards here - if (strpos($file, '.xml') !== false && preg_match('#(contrib|templates|languages)#i', $dir, $match)) - { - // Get rid of the S. This is a side effect of understanding - // MODX 1.0.x and 1.2.x. - $match[1] = rtrim($match[1], 's'); - - $mods[$match[1]][] = array( - 'href' => "$dir/$file", - 'realname' => core_basename($file), - 'title' => core_basename($file), - ); - } - else - { - $check = end($mods['main']); - $check = $check['href']; - - // we take the first file alphabetically with install in the filename - if (!$check || dirname($check) == $dir) - { - if (preg_match('#.*install.*xml$#i', $file) && preg_match('#.*install.*xml$#i', $check) && strnatcasecmp(basename($check), $file) > 0) - { - - $index = max(0, sizeof($mods['main']) - 1); - $mods['main'][$index] = array( - 'href' => "$dir/$file", - 'realname' => core_basename($file), - 'title' => core_basename($file), - ); - - break; - } - else if (preg_match('#.*install.*xml$#i', $file) && !preg_match('#.*install.*xml$#i', $check)) - { - $index = max(0, sizeof($mods['main']) - 1); - $mods['main'][$index] = array( - 'href' => "$dir/$file", - 'realname' => core_basename($file), - 'title' => core_basename($file), - ); - - break; - } - } - else - { - if (strpos($file, '.xml') !== false) - { - $mods['main'][] = array( - 'href' => "$dir/$file", - 'realname' => core_basename($file), - 'title' => core_basename($file), - ); - } - } - } - } - } - } - closedir($dp); - - return $mods; - } - - function process_edits($editor, $actions, $details, $change = false, $display = true, $reverse = false) - { - global $template, $user, $db, $phpbb_root_path, $force_install, $mod_installed; - global $dest_inherits, $dest_template, $children, $config; - - $mod_installed = true; - - if ($reverse) - { - global $rev_actions; - - if (empty($rev_actions)) - { - // maybe should allow for potential extensions here - $actions = parser::reverse_edits($actions); - } - else - { - $actions = $rev_actions; - unset($rev_actions); - } - } - - $template->assign_vars(array( - 'S_DISPLAY_DETAILS' => (bool) $display, - 'S_CHANGE_FILES' => (bool) $change, - )); - -/* - if (!empty($details['PHPBB_VERSION']) && $details['PHPBB_VERSION'] != $config['version']) - { - $version_warnig = sprintf($user->lang['VERSION_WARNING'], $details['PHPBB_VERSION'], $config['version']); - - $template->assign_vars(array( - 'VERSION_WARNING' => $version_warnig, - 'S_PHPBB_VESION' => true, - )); - } -*/ - - if (!empty($details['AUTHOR_NOTES']) && $details['AUTHOR_NOTES'] != $user->lang['UNKNOWN_MOD_AUTHOR-NOTES']) - { - $template->assign_vars(array( - 'S_AUTHOR_NOTES' => true, - - 'AUTHOR_NOTES' => nl2br($details['AUTHOR_NOTES']), - )); - } - - // not all MODs will have edits (!) - if (isset($actions['EDITS'])) - { - $template->assign_var('S_EDITS', true); - - foreach ($actions['EDITS'] as $filename => $edits) - { - // see if the file to be opened actually exists - if (!file_exists("$phpbb_root_path$filename")) - { - $is_inherit = (strpos($filename, 'styles/') !== false && !empty($dest_inherits)) ? true : false; - - $template->assign_block_vars('edit_files', array( - 'S_MISSING_FILE' => ($is_inherit) ? false : true, - 'INHERIT_MSG' => ($is_inherit) ? sprintf($user->lang['INHERIT_NO_CHANGE'], $dest_template, $dest_inherits) : '', - 'FILENAME' => $filename, - )); - - $mod_installed = ($is_inherit) ? $mod_installed : false; - - continue; - } - else - { - $template->assign_block_vars('edit_files', array( - 'S_SUCCESS' => false, - 'FILENAME' => $filename, - )); - - // If installing - not pre_install nor (pre_)uninstall, backup the file - // This is to make sure it works with editor_ftp because write_method is - // forced to direct when in preview modes, and ignored in editor_manual! - if ($change && !$reverse) - { - $status = $editor->open_file($filename, $this->backup_root); - } - else - { - $status = $editor->open_file($filename); - } - - $edit_success = true; - - if (is_string($status)) - { - $template->assign_block_vars('error', array( - 'ERROR' => $status, - )); - - $mod_installed = false; - continue; - } - - $edit_success = true; - - foreach ($edits as $finds) - { - $comment = ''; - foreach ($finds as $find => $commands) - { - if (isset($finds['comment']) && !$comment && $finds['comment'] != $user->lang['UNKNOWN_MOD_COMMENT']) - { - $comment = $finds['comment']; - unset($finds['comment']); - } - - if ($find == 'comment') - { - continue; - } - - $find_tpl = array( - 'FIND_STRING' => htmlspecialchars($find), - 'COMMENT' => htmlspecialchars($comment), - ); - - $offset_ary = $editor->find($find); - - // special case for FINDs with no action associated - if (is_null($commands)) - { - continue; - } - - foreach ($commands as $type => $contents) - { - if (!$offset_ary) - { - $offset_ary['start'] = $offset_ary['end'] = false; - } - - $status = false; - $inline_template_ary = array(); - $contents_orig = $contents; - - switch (strtoupper($type)) - { - case 'AFTER ADD': - $status = $editor->add_string($find, $contents, 'AFTER', $offset_ary['start'], $offset_ary['end']); - break; - - case 'BEFORE ADD': - $status = $editor->add_string($find, $contents, 'BEFORE', $offset_ary['start'], $offset_ary['end']); - break; - - case 'INCREMENT': - case 'OPERATION': - //$contents = ""; - $status = $editor->inc_string($find, '', $contents); - break; - - case 'REPLACE WITH': - $status = $editor->replace_string($find, $contents, $offset_ary['start'], $offset_ary['end']); - break; - - case 'IN-LINE-EDIT': - // these aren't quite as straight forward. Still have multi-level arrays to sort through - $inline_comment = ''; - foreach ($contents as $inline_edit_id => $inline_edit) - { - if ($inline_edit_id === 'inline-comment') - { - // This is a special case for tucking comments in the array - if ($inline_edit != $user->lang['UNKNOWN_MOD_INLINE-COMMENT']) - { - $inline_comment = $inline_edit; - } - continue; - } - - foreach ($inline_edit as $inline_find => $inline_commands) - { - foreach ($inline_commands as $inline_action => $inline_contents) - { - // inline finds are pretty cantankerous, so do them in the loop - $line = $editor->inline_find($find, $inline_find, $offset_ary['start'], $offset_ary['end']); - if (!$line) - { - // find failed - $status = $mod_installed = false; - - $inline_template_ary[] = array( - 'FIND' => array( - - 'S_SUCCESS' => $status, - - 'NAME' => $user->lang[$type], - 'COMMAND' => htmlspecialchars($inline_find), - ), - 'ACTION' => array()); - - continue 2; - } - - $inline_contents = $inline_contents[0]; - $contents_orig = $inline_find; - - switch (strtoupper($inline_action)) - { - case 'IN-LINE-': - $editor->last_string_offset = $line['string_offset'] + $line['find_length'] - 1; - $status = true; - continue 2; - break; - - case 'IN-LINE-BEFORE-ADD': - $status = $editor->inline_add($find, $inline_find, $inline_contents, 'BEFORE', $line['array_offset'], $line['string_offset'], $line['find_length']); - break; - - case 'IN-LINE-AFTER-ADD': - $status = $editor->inline_add($find, $inline_find, $inline_contents, 'AFTER', $line['array_offset'], $line['string_offset'], $line['find_length']); - break; - - case 'IN-LINE-REPLACE': - case 'IN-LINE-REPLACE-WITH': - $status = $editor->inline_replace($find, $inline_find, $inline_contents, $line['array_offset'], $line['string_offset'], $line['find_length']); - break; - - case 'IN-LINE-OPERATION': - $status = $editor->inc_string($find, $inline_find, $inline_contents); - break; - - default: - $message = sprintf($user->lang['UNRECOGNISED_COMMAND'], $inline_action); - trigger_error($message, E_USER_WARNING); // ERROR! - break; - } - - $inline_template_ary[] = array( - 'FIND' => array( - - 'S_SUCCESS' => $status, - - 'NAME' => $user->lang[$type], - 'COMMAND' => (is_array($contents_orig)) ? $user->lang['INVALID_MOD_INSTRUCTION'] : htmlspecialchars($contents_orig), - ), - - 'ACTION' => array( - - 'S_SUCCESS' => $status, - - 'NAME' => $user->lang[$inline_action], - 'COMMAND' => (is_array($inline_contents)) ? $user->lang['INVALID_MOD_INSTRUCTION'] : htmlspecialchars($inline_contents), - // 'COMMENT' => $inline_comment, (inline comments aren't actually part of the MODX spec) - ), - ); - } - - if (!$status) - { - $mod_installed = false; - } - - $editor->close_inline_edit(); - } - } - break; - - default: - $message = sprintf($user->lang['UNRECOGNISED_COMMAND'], $type); - trigger_error($message, E_USER_WARNING); // ERROR! - break; - } - - $template->assign_block_vars('edit_files.finds', array_merge($find_tpl, array( - 'S_SUCCESS' => $status, - ))); - - if (!$status) - { - $edit_success = false; - $mod_installed = false; - } - - if (sizeof($inline_template_ary)) - { - foreach ($inline_template_ary as $inline_template) - { - // We must assign the vars for the FIND first - $template->assign_block_vars('edit_files.finds.actions', $inline_template['FIND']); - - // And now the vars for the ACTION - $template->assign_block_vars('edit_files.finds.actions.inline', $inline_template['ACTION']); - - } - $inline_template_ary = array(); - } - else if (!is_array($contents_orig)) - { - $template->assign_block_vars('edit_files.finds.actions', array( - 'S_SUCCESS' => $status, - - 'NAME' => $user->lang[$type], - 'COMMAND' => htmlspecialchars($contents_orig), - )); - } - } - } - - $editor->close_edit(); - } - - $template->alter_block_array('edit_files', array( - 'S_SUCCESS' => $edit_success, - ), true, 'change'); - } - - if ($change) - { - $status = $editor->close_file("{$this->edited_root}$filename"); - if (is_string($status)) - { - $template->assign_block_vars('error', array( - 'ERROR' => $status, - )); - - $mod_installed = false; - } - } - } - } // end foreach - - if (!$mod_installed) - { - $template->assign_var('S_DISPLAY_FILE_EDITS', true); - } - - // Move included files - if (isset($actions['NEW_FILES']) && !empty($actions['NEW_FILES'])) - { - $template->assign_var('S_NEW_FILES', true); - - // Because foreach operates on a copy of the specified array and not the array itself, - // we cannot rely on the array pointer while using it, so we use a while loop w/ each() - // We need array pointer to rewind the loop when is_array($target) (See Ticket #62341) - while (list($source, $target) = each($actions['NEW_FILES'])) - { - if (is_array($target)) - { - // If we've shifted off all targets, we're done w/ that element - if (empty($target)) - { - continue; - } - - // Shift off first target, then rewind array pointer to get next target - $target = array_shift($actions['NEW_FILES'][$source]); - prev($actions['NEW_FILES']); - } - -/* if ($change && ($mod_installed || $force_install)) - { -*/ $status = $editor->copy_content($this->mod_root . str_replace('*.*', '', $source), str_replace('*.*', '', $target)); - - if ($status !== true && !is_null($status)) - { - $mod_installed = false; - $template->assign_var('S_DISPLAY_NEW_FILES', true); - } - - $template->assign_block_vars('new_files', array( - 'S_SUCCESS' => ($status === true) ? true : false, - 'S_NO_COPY_ATTEMPT' => (is_null($status)) ? true : false, - 'SOURCE' => $source, - 'TARGET' => $target, - )); -/* } - else if ($display && !$change) - { - $template->assign_block_vars('new_files', array( - 'SOURCE' => $source, - 'TARGET' => $target, - )); - } - // To avoid "error" on install page when being asked to force install - else if ($change && $display && !$mod_installed && !$force_install) - { - $template->assign_block_vars('new_files', array( - 'S_NO_COPY_ATTEMPT' => true, - 'FILENAME' => $target, - )); - } -*/ } - } - - // Delete (or reverse-delete) installed files - if (!empty($actions['DELETE_FILES'])) - { - $template->assign_var('S_REMOVING_FILES', true); - - // Dealing with a reverse-delete, must heed to the dangers ahead! - if ($reverse) - { - $directories = array(); - $directories['src'] = array(); - $directories['dst'] = array(); - $directories['del'] = array(); - - // Because foreach operates on a copy of the specified array and not the array itself, - // we cannot rely on the array pointer while using it, so we use a while loop w/ each() - // We need array pointer to rewind the loop when is_array($target) (See Ticket #62341) - while (list($source, $target) = each($actions['DELETE_FILES'])) - { - if (is_array($target)) - { - // If we've shifted off all targets, we're done w/ that element - if (empty($target)) - { - continue; - } - - // Shift off first target, then rewind array pointer to get next target - $target = array_shift($actions['DELETE_FILES'][$source]); - prev($actions['DELETE_FILES']); - } - - // Some MODs include 'umil/', avoid deleting! - if (strpos($target, 'umil/') === 0) - { - unset($actions['DELETE_FILES'][$source]); - continue; - } - // MODX used '*.*' or 'dir/*.*' (Fun!) - else if (strpos($source, '*.*') !== false) - { - // This could be phpbb_root_path, if "Copy: root/*.* to: *.*" syntax was used - // or root/custom_dir if "Copy: root/custom/*.* to: custom/*.*", etc. - $source = $this->mod_root . str_replace('*.*', '', $source); - $target = str_replace('*.*', '', $target); - - // Get all of the files in the source directory - $files = find_files($source, '.*'); - // And translate into destination files - $files = str_replace($source, $target, $files); - - // Get all of the sub-directories in the source directory - $directories['src'] = find_files($source, '.*', 20, true); - // And translate it into destination sub-directories - $directories['dst'] = str_replace($source, $target, $directories['src']); - - // Compare source and destination subdirs, if any, in _reverse_ order! (array_pop) - for ($i=0, $cnt = count($directories['dst']); $i < $cnt; $i++) - { - $dir_source = array_pop($directories['src']); - $dir_target = array_pop($directories['dst']); - - // Some MODs include 'umil/', avoid deleting! - if (strpos($dir_target, 'umil/') === 0) - { - continue; - } - - $src_file_cnt = directory_num_files($dir_source, false, true); - $dst_file_cnt = directory_num_files($phpbb_root_path . $dir_target, false, true); - $src_dir_cnt = directory_num_files($dir_source, true, true); - $dst_dir_cnt = directory_num_files($phpbb_root_path . $dir_target, true, true); - - // Do we have a match in recursive file count and match in recursive subdir count? - // This could be vastly improved.. - if ($src_file_cnt == $dst_file_cnt && $src_dir_cnt == $dst_dir_cnt) - { - $directories['del'][] = $dir_target; - } - unset($dir_source, $dir_target, $src_file_cnt, $dst_file_cnt, $src_dir_cnt, $dst_dir_cnt); //cleanup - } - - foreach ($files as $file) - { - // Some MODs include 'umil/', avoid deleting! - if (strpos($file, 'umil/') === 0) - { - continue; - } - else if (!file_exists($phpbb_root_path . $file) && ($change || $display)) - { - $template->assign_block_vars('removing_files', array( - 'S_MISSING_FILE' => true, - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $file, - )); - } - else if ($change && ($mod_installed || $force_install)) - { - $status = $editor->remove($file); - - $template->assign_block_vars('removing_files', array( - 'S_SUCCESS' => ($status === true) ? true : false, - 'S_NO_DELETE_ATTEMPT' => (is_null($status)) ? true : false, - 'FILENAME' => $file, - )); - } - else if ($display && !$change) - { - $template->assign_block_vars('removing_files', array( - 'FILENAME' => $file, - )); - } - // To avoid "error" on uninstall page when being asked to force - else if ($change && $display && !$mod_installed && !$force_install) - { - $template->assign_block_vars('removing_files', array( - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $file, - )); - } - } - unset($files); //cleanup - } - else if (!file_exists($phpbb_root_path . $target) && ($change || $display)) - { - $template->assign_block_vars('removing_files', array( - 'S_MISSING_FILE' => true, - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $target, - )); - } - else if ($change && ($mod_installed || $force_install)) - { - $status = $editor->remove($target); - - $template->assign_block_vars('removing_files', array( - 'S_SUCCESS' => ($status === true) ? true : false, - 'S_NO_DELETE_ATTEMPT' => (is_null($status)) ? true : false, - 'FILENAME' => $target, - )); - } - else if ($display && !$change) - { - $template->assign_block_vars('removing_files', array( - 'FILENAME' => $target, - )); - } - // To avoid "error" on uninstall page when being asked to force - else if ($change && $display && !$mod_installed && !$force_install) - { - $template->assign_block_vars('removing_files', array( - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $target, - )); - } - } - - // Delete wildcard directories, if any, which should now be empty anyway (no recursive delete needed) - if ($cnt = count($directories['del'])) - { - for ($i=0; $i < $cnt; $i++) - { - if ($change && ($mod_installed || $force_install)) - { - $status = $editor->remove($directories['del'][$i]); - - $template->assign_block_vars('removing_files', array( - 'S_SUCCESS' => ($status === true) ? true : false, - 'S_NO_DELETE_ATTEMPT' => (is_null($status)) ? true : false, - 'FILENAME' => $directories['del'][$i], - )); - } - else if ($display && !$change) - { - $template->assign_block_vars('removing_files', array( - 'FILENAME' => $directories['del'][$i], - )); - } - // To avoid "error" on uninstall page when being asked to force - else if ($change && $display && !$mod_installed && !$force_install) - { - $template->assign_block_vars('removing_files', array( - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $directories['del'][$i], - )); - } - } - unset($directories['del']); //cleanup - } - } - // Normal deleting functionality (not in reverse edits mode) - else if ($mod_installed || $force_install) - { - foreach ($actions['DELETE_FILES'] as $file) - { - $wildcards = strpos($file, '*.*'); - $file = str_replace('*.*', '', $file); - - if (!file_exists($phpbb_root_path . $file) && ($change || $display)) - { - $template->assign_block_vars('removing_files', array( - 'S_MISSING_FILE' => true, - 'S_NO_DELETE_ATTEMPT' => true, - 'FILENAME' => $file, - )); - } - // purposely do not use !== false here, because we don't expect wildcards at position 0 - // if there's no wildcard, make sure it's a file to avoid recursively deleting a directory!!! - else if ($wildcards || is_file($phpbb_root_path . $file)) - { - if ($change) - { - // Delete, recursively if needed - $status = $editor->remove($file, true); - - $template->assign_block_vars('removing_files', array( - 'S_SUCCESS' => ($status === true) ? true : false, - 'S_NO_DELETE_ATTEMPT' => (is_null($status)) ? true : false, - 'FILENAME' => $file, - )); - } - else if ($display) - { - $template->assign_block_vars('removing_files', array( - 'FILENAME' => $file, - )); - } - } - } - } - } - - - // Perform SQL queries last -- Queries usually cannot be done a second - // time, so do them only if the edits were successful. Still complies - // with the MODX spec in this location - if (!empty($actions['SQL']) && ($mod_installed || $force_install || ($display && !$change))) - { - $template->assign_var('S_SQL', true); - - // parser::parse_sql($actions['SQL']); - - $db->sql_return_on_error(true); - - foreach ($actions['SQL'] as $query) - { - if ($change) - { - $query_success = $db->sql_query($query); - - if ($query_success) - { - $template->assign_block_vars('sql_queries', array( - 'S_SUCCESS' => true, - 'QUERY' => $query, - )); - } - else - { - $error = $db->sql_error(); - - $template->assign_block_vars('sql_queries', array( - 'S_SUCCESS' => false, - 'QUERY' => $query, - 'ERROR_MSG' => $error['message'], - 'ERROR_CODE'=> $error['code'], - )); - - $mod_installed = false; - } - } - else if ($display) - { - $template->assign_block_vars('sql_queries', array( - 'QUERY' => $query, - )); - } - } - - $db->sql_return_on_error(false); - } - else - { - $template->assign_var('S_SQL', false); - } - - return $mod_installed; - } - - /** - * Search on the file system for other .xml files that belong to this MOD - * @param string $mod_path - path to the "main" MODX file, relative to phpBB Root - */ - function find_children($mod_path) - { - $children = array(); - - if ($this->parser->get_modx_version() == 1.2) - { - // TODO: eww, yuck ... processing the XML again? - $details = $this->mod_details($mod_path, false); - - $children = $details['CHILDREN']; - - if (isset($children['template-lang'])) - { - if (isset($children['template'])) - { - $children['template'] = array_merge($children['template'], $children['template-lang']); - } - else - { - $children['template'] = $children['template-lang']; - } - - unset($children['template-lang']); - } - - $child_types = array('contrib', 'template', 'language', 'dependency', 'uninstall'); - - foreach ($child_types as $type) - { - if (empty($children[$type])) - { - continue; - } - $child_count = sizeof($children[$type]); - // Remove duplicate hrefs if they exist (links in multiple languages can cause this) - for ($i = 1; $i < $child_count; $i++) - { - if (isset($children[$type][$i - 1]) && $children[$type][$i - 1]['href'] == $children[$type][$i]['href']) - { - unset($children[$type][$i]); - } - } - } - } - else if ($this->parser->get_modx_version() == 1.0) - { - $search_dir = (strpos($mod_path, $this->mods_dir) === 0) ? dirname($mod_path) : $this->mods_dir . dirname($mod_path); - $children = $this->find_mods($search_dir, 5); - } - - return $children; - } - - function handle_dependency(&$children, $mode, $mod_path) - { - if (isset($children['dependency']) && sizeof($children['dependency'])) - { - // TODO: check for the chance that the MOD has been installed by AutoMOD - // previously - if (confirm_box(true)) - { - // do nothing - } - else if (empty($_REQUEST['dependency_confirm']) && empty($_REQUEST['force'])) - { - global $user, $id; - - $full_url_list = array(); - $message = ''; - $children['dependency'] = array_unique($children['dependency']); - foreach ($children['dependency'] as $dependency) - { - //$full_url_list[] = $dependency_url; - $message .= sprintf($user->lang['DEPENDENCY_INSTRUCTIONS'], $dependency['href'], $dependency['title']) . '

'; - } - - confirm_box(false, $message, build_hidden_fields(array( - 'dependency_confirm' => true, - 'mode' => $mode, - 'action' => 'install', - 'mod_path' => $mod_path, - ))); - } - } - } - - /** - * Get all contrib links for the selected language. - * This functions will be removed. - */ - function get_contrib_lang($contrib, $lang = 'en') - { - $ary = array(); - - foreach ($contrib as $element) - { - if (match_language($lang, $element['lang'])) - { - $ary[] = $element; - } - } - - return($ary); - } - - function handle_contrib(&$children) - { - global $template, $parent_id, $phpbb_root_path, $user, $db; - - if (isset($children['contrib']) && sizeof($children['contrib'])) - { - $template->assign_var('S_CONTRIB_AVAILABLE', true); - - // Do we have links in the users selected language. - // Start with getting the Enlgish links. - $contrib_en = $this->get_contrib_lang($children['contrib']); - - if ($user->data['user_lang'] == 'en' || sizeof($contrib_en) == sizeof($children['contrib'])) - { - // Our user has either English or there is only English links. - $children['contrib'] = $contrib_en; - } - else - { - // If there are any links in the users language, let's get them. - $contrib_lang = $this->get_contrib_lang($children['contrib'], $user->data['user_lang']); - - if (!sizeof($contrib_lang)) - { - // There is no links in the right language, give them the English links. - $children['contrib'] = $contrib_en; - } - else - { - $children['contrib'] = $contrib_lang; - } - } - - if (!empty($parent_id)) - { - // get installed contribs from the database - $sql = 'SELECT mod_contribs FROM ' . MODS_TABLE . ' - WHERE mod_id = ' . $parent_id; - $result = $db->sql_query($sql); - $mod_contribs = $db->sql_fetchfield('mod_contribs'); - $db->sql_freeresult(); - } - - $mod_contribs = (!empty($mod_contribs)) ? explode(',', $mod_contribs) : array(); - - // there are things like upgrades...we don't care unless the MOD has previously been installed. - foreach ($children['contrib'] as $xml_file) - { - // Another hack for supporting both versions of MODX - $xml_file = (is_array($xml_file)) ? $xml_file['href'] : str_replace($this->mod_root, '', $xml_file); - - $child_details = $this->mod_details($xml_file, false); - - // don't do the urlencode until after the file is looked up on the - // filesystem - $xml_file = urlencode('/' . $xml_file); - - if (in_array(urldecode($xml_file), $mod_contribs)) - { - $child_details['U_UNINSTALL'] = ($parent_id) ? $this->u_action . "&action=pre_uninstall&parent=$parent_id&mod_path=$xml_file&type=contrib" : ''; - } - else - { - $child_details['U_INSTALL'] = ($parent_id) ? $this->u_action . "&action=pre_install&parent=$parent_id&mod_path=$xml_file&type=contrib" : ''; - } - - $child_details['MOD_NAME'] = localize_title($child_details['MOD_NAME'], $user->data['user_lang']); - $template->assign_block_vars('contrib', $child_details); - } - } - } - - function handle_merge($type, &$actions, &$children, $process_files) - { - if (!isset($children[$type]) || !sizeof($process_files)) - { - return; - } - - // add the actions to our $actions array...give praise to array_merge_recursive - foreach ($process_files as $key => $name) - { - foreach ($children[$type] as $child_key => $child_data) - { - $root_position = strpos($child_data['href'], $this->mod_root); - if ($child_data['realname'] == $name && $root_position === false) - { - $child_filename = $this->mod_root . ltrim($child_data['href'], './'); - break; - } - else if ($child_data['realname'] == $name && $root_position === 0) - { - $child_filename = $child_data['href']; - } - - } - - $actions_ary = $this->mod_actions($child_filename); - - if (!isset($actions_ary['NEW_FILES'])) - { - $actions = array_merge_recursive($actions, $actions_ary); - continue; - } - - // perform some cleanup if the MOD author didn't specify the proper root directory - foreach ($actions_ary['NEW_FILES'] as $source => $destination) - { - // if the source file does not exist, and languages/ is not at the beginning - // this is probably only applicable with MODX 1.0. - if (!file_exists($this->mod_root . $source) && strpos("{$type}s/", $source) === false) - { - // and it does exist if we force a languages/ into the path - if (file_exists($this->mod_root . "{$type}s/" . $source)) - { - // change the array key to include languages - unset($actions_ary['NEW_FILES'][$source]); - $actions_ary['NEW_FILES']["{$type}s/$source"] = $destination; - } - - // else we let the error handling do its thing - } - } - - $actions = array_merge_recursive($actions, $actions_ary); - } - } - - function handle_language_prompt(&$children, &$elements, $action) - { - global $db, $template, $parent_id, $phpbb_root_path; - - if (isset($children['language']) && sizeof($children['language'])) - { - // additional languages are available...find out which ones we may want to apply - $sql = 'SELECT lang_id, lang_iso FROM ' . LANG_TABLE; - $result = $db->sql_query($sql); - - $installed_languages = array(); - while ($row = $db->sql_fetchrow($result)) - { - $installed_languages[$row['lang_id']] = $row['lang_iso']; - } - $db->sql_freeresult($result); - - foreach ($children['language'] as $key => $tag) - { - // remove useless title from MODX 1.2.0 tags - $children['language'][$tag['realname']] = is_array($tag) ? $tag['href'] : $tag; - } - - $available_languages = array_keys($children['language']); - $process_languages = $elements['language'] = array_intersect($available_languages, $installed_languages); - - // $unknown_languages are provided for by the MOD, but not installed on the board - $unknown_languages = array_diff($available_languages, $installed_languages); - - // Inform the user if there are languages provided for by the MOD - if (sizeof($children['language'])) - { - if (!empty($parent_id)) - { - // get installed languages from the database - $sql = 'SELECT mod_languages FROM ' . MODS_TABLE . ' - WHERE mod_id = ' . $parent_id; - $result = $db->sql_query($sql); - $mod_languages = $db->sql_fetchfield('mod_languages'); - $db->sql_freeresult(); - } - - $mod_languages = (!empty($mod_languages)) ? explode(',', $mod_languages) : array(); - foreach ($children['language'] as $row) - { - if (is_string($row)) - { - continue; - } - - $xml_file = (!empty($row['href'])) ? urlencode($row['href']) : ''; - - $template->assign_block_vars('unknown_lang', array( - 'ENGLISH_NAME' => $row['title'], - 'LOCAL_NAME' => $row['realname'], - 'U_INSTALL' => (!empty($xml_file) && !in_array($row['href'], $mod_languages) && $parent_id) ? $this->u_action . "&action=pre_install&parent=$parent_id&mod_path=$xml_file&type=lang" : '', - 'U_UNINSTALL' => (!empty($xml_file) && $parent_id) ? $this->u_action . "&action=pre_uninstall&parent=$parent_id&mod_path=$xml_file&type=lang" : '', - )); - unset($row); - } - } - - return $process_languages; - } - } - - function handle_template_prompt(&$children, &$elements, $action) - { - return; -/* - global $db, $template, $phpbb_root_path, $parent_id; - - if (isset($children['template']) && sizeof($children['template'])) - { - // additional styles are available for this MOD - $sql = 'SELECT template_id, template_name FROM ' . STYLES_TEMPLATE_TABLE; - $result = $db->sql_query($sql); - - $installed_templates = array(); - while ($row = $db->sql_fetchrow($result)) - { - $installed_templates[$row['template_id']] = $row['template_name']; - } - $db->sql_freeresult($result); - - foreach ($children['template'] as $key => $tag) - { - // remove useless title from MODX 1.2.0 tags - $children['template'][$tag['realname']] = is_array($tag) ? $tag['href'] : $tag; - } - - $available_templates = array_keys($children['template']); - - // $process_templates are those that are installed on the board and provided for by the MOD - $process_templates = $elements['template'] = array_intersect($available_templates, $installed_templates); - } -*/ - } - - function upload_mod($action) - { - global $phpbb_root_path, $phpEx, $template, $user; - - $can_upload = (@ini_get('file_uploads') == '0' || strtolower(@ini_get('file_uploads')) == 'off' || !@extension_loaded('zlib')) ? false : true; - - // get FTP information if we need it - $hidden_ary = get_connection_info(false); - - if (!isset($_FILES['modupload']) || $action != 'upload_mod') - { - $template->assign_vars(array( - 'S_FRONTEND' => true, - 'S_MOD_UPLOAD' => ($can_upload) ? true : false, - 'U_UPLOAD' => $this->u_action . '&action=upload_mod', - 'S_FORM_ENCTYPE' => ($can_upload) ? ' enctype="multipart/form-data"' : '', - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary), - )); - add_form_key('acp_mods_upload'); - - return false; - } // end pre_upload_mod - - if (!check_form_key('acp_mods_upload')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $user->add_lang('posting'); // For error messages - include($phpbb_root_path . 'includes/functions_upload.' . $phpEx); - $upload = new fileupload(); - $upload->set_allowed_extensions(array('zip')); // Only allow ZIP files - - $write_method = 'editor_' . determine_write_method(false); - - // For Direct & Manual write methods, make sure store/mods/ directory is writable - if ($write_method == 'editor_direct' || $write_method == 'editor_manual') - { - if (!is_writable($this->mods_dir)) - { - trigger_error($user->lang['MODS_NOT_WRITABLE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $write_method = 'editor_direct'; // Force Direct method, in the case of manual - $upload_dir = $this->mods_dir; - } - // FTP method: we still need a known world-writable directory (store/) for zip extraction - else if (is_writable($this->store_dir)) - { - $upload_dir = $this->store_dir; - } - else - { - trigger_error($user->lang['STORE_NOT_WRITABLE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $editor = new $write_method(); - - // Make sure the store/mods/ directory exists and if it doesn't, create it - if (!is_dir($this->mods_dir)) - { - $editor->recursive_mkdir($this->mods_dir); - } - - // Proceed with the upload - $file = $upload->form_upload('modupload'); - - if (empty($file->filename)) - { - trigger_error($user->lang['NO_UPLOAD_FILE'] . adm_back_link($this->u_action), E_USER_WARNING); - } - else if ($file->init_error || sizeof($file->error)) - { - $file->remove(); - trigger_error((sizeof($file->error) ? implode('
', $file->error) : $user->lang['MOD_UPLOAD_INIT_FAIL']) . adm_back_link($this->u_action), E_USER_WARNING); - } - - $file->clean_filename('real'); - $file->move_file(str_replace($phpbb_root_path, '', $upload_dir), true, true); - - if (sizeof($file->error)) - { - $file->remove(); - trigger_error(implode('
', $file->error) . adm_back_link($this->u_action), E_USER_WARNING); - } - - include($phpbb_root_path . 'includes/functions_compress.' . $phpEx); - $mod_dir = $upload_dir . '/' . str_replace('.zip', '', $file->get('realname')); - $compress = new compress_zip('r', $file->destination_file); - $compress->extract($mod_dir . '_tmp/'); - $compress->close(); - $folder_contents = scandir($mod_dir . '_tmp/', 1); // This ensures dir is at index 0 - - $folder_contents = array_diff($folder_contents, array('.', '..')); - - // We need to check if there's only one (main) directory inside the temp MOD directory - if (sizeof($folder_contents) == 1) - { - $folder_contents = implode(null, $folder_contents); - $from_dir = $mod_dir . '_tmp/' . $folder_contents; - $to_dir = $this->mods_dir . '/' . $folder_contents; - } - // Otherwise assume the temp directory is the main directroy, so change the directory - // name by moving to a directory without the '_tmp' suffix - else if (!is_dir($mod_dir)) - { - $from_dir = $mod_dir . '_tmp/'; - $to_dir = $mod_dir . '/'; - } - // We should never really get here, but you never know! - else - { - trigger_error($user->lang['MOD_UPLOAD_UNRECOGNIZED'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - // Copy that directory to the new path - $editor->copy_content($from_dir, $to_dir); - - // Finally remove the main tmp extraction directory, directly, just like we created it - recursive_unlink($mod_dir . '_tmp/'); - - $template->assign_vars(array( - 'S_MOD_SUCCESSBOX' => true, - 'MESSAGE' => $user->lang['MOD_UPLOAD_SUCCESS'], - 'U_RETURN' => $this->u_action, - )); - - // Remove the uploaded archive file - $file->remove(); - - return true; - } - - function delete_mod($action, $mod_path = '') - { - global $template, $user; - - if (!empty($mod_path)) - { - $mod_path = explode('/', str_replace('\\', '/', $mod_path)); - $mod_path = (!empty($mod_path[0])) ? $mod_path[0] : $mod_path[1]; - } - else - { - $mod_path = request_var('mod_delete', ''); - } - - if (empty($mod_path) || !is_dir($this->mods_dir . '/' . $mod_path)) - { - return false; // ERROR - } - - // get FTP information if we need it - $hidden_ary = get_connection_info(false); - - $hidden_ary['mod_delete'] = $mod_path; - - if ($action != 'delete_mod') - { - $template->assign_vars(array( - 'S_MOD_DELETE' => true, - 'U_DELETE' => $this->u_action . '&action=delete_mod', - 'S_HIDDEN_FIELDS' => build_hidden_fields($hidden_ary), - )); - add_form_key('acp_mods_delete'); - - return; - } // end pre_delete_mod - - $write_method = 'editor_' . determine_write_method(false); - // Force Direct method, in the case of manual - just like above in mod_upload() - $write_method = ($write_method == 'editor_manual') ? 'editor_direct' : $write_method; - $editor = new $write_method(); - - if (!check_form_key('acp_mods_delete')) - { - trigger_error($user->lang['FORM_INVALID'] . adm_back_link($this->u_action), E_USER_WARNING); - } - - $status = $editor->remove("{$this->mods_dir}/{$mod_path}", true); - - if ($status !== true) - { - trigger_error($user->lang['DELETE_ERROR'] . " $status" . adm_back_link($this->u_action), E_USER_WARNING); - } - - $template->assign_vars(array( - 'S_MOD_SUCCESSBOX' => true, - 'MESSAGE' => $user->lang['DELETE_SUCCESS'], - 'U_RETURN' => $this->u_action, - )); - } -} - -?> diff --git a/includes/library/automod/automod.diff b/includes/library/automod/automod.diff deleted file mode 100644 index 9b484154f..000000000 --- a/includes/library/automod/automod.diff +++ /dev/null @@ -1,258 +0,0 @@ ---- automod-1.0.2/root/includes/acp/acp_mods.php -+++ customisation-db/titania/includes/library/automod/acp_mods.php -@@ -669,6 +668,7 @@ - $processed_templates = array('prosilver'); - $processed_templates += explode(',', $row['mod_template']); - -+/* - // now grab the templates that have not already been processed - $sql = 'SELECT template_id, template_path FROM ' . STYLES_TEMPLATE_TABLE . ' - WHERE ' . $db->sql_in_set('template_name', $processed_templates, true); -@@ -681,9 +681,10 @@ - 'TEMPLATE_NAME' => $row['template_path'], - )); - } -+*/ - - $s_hidden_fields = build_hidden_fields(array( -- 'action' => ($uninstall) ? 'uninstall' : 'pre_install', -+ 'action' => 'install', - 'parent' => $parent_id, - )); - -@@ -1521,6 +1522,7 @@ - )); - } - } -+/* - elseif (($mod_uninstalled || $force_uninstall) && $parent) - { - // Only update the database entries and don't move any files back -@@ -1590,12 +1592,13 @@ - $mod_name = localize_title($row['mod_name'], $user->data['user_lang']); - add_log('admin', 'LOG_MOD_CHANGE', htmlspecialchars_decode($mod_name)); - } -- -+*/ - // if we forced uninstall of the MOD, we need to let the user know their board could be broken - if ($force_uninstall) - { - $template->assign_var('S_FORCE', true); - } -+/* - else if (!$mod_uninstalled) - { - add_form_key('acp_mods'); -@@ -1606,6 +1609,7 @@ - 'U_RETRY' => $this->u_action . '&action=uninstall&mod_id=' . $mod_id, - )); - } -+*/ - - if ($mod_uninstalled || $force_uninstall) - { -@@ -1763,6 +1767,7 @@ - 'S_CHANGE_FILES' => (bool) $change, - )); - -+/* - if (!empty($details['PHPBB_VERSION']) && $details['PHPBB_VERSION'] != $config['version']) - { - $version_warnig = sprintf($user->lang['VERSION_WARNING'], $details['PHPBB_VERSION'], $config['version']); -@@ -1772,6 +1777,7 @@ - 'S_PHPBB_VESION' => true, - )); - } -+*/ - - if (!empty($details['AUTHOR_NOTES']) && $details['AUTHOR_NOTES'] != $user->lang['UNKNOWN_MOD_AUTHOR-NOTES']) - { -@@ -1822,6 +1828,8 @@ - { - $status = $editor->open_file($filename); - } -+ -+ $edit_success = true; - - if (is_string($status)) - { -@@ -2062,6 +2070,11 @@ - } - } // end foreach - -+ if (!$mod_installed) -+ { -+ $template->assign_var('S_DISPLAY_FILE_EDITS', true); -+ } -+ - // Move included files - if (isset($actions['NEW_FILES']) && !empty($actions['NEW_FILES'])) - { -@@ -2085,13 +2098,14 @@ - prev($actions['NEW_FILES']); - } - -- if ($change && ($mod_installed || $force_install)) -- { -- $status = $editor->copy_content($this->mod_root . str_replace('*.*', '', $source), str_replace('*.*', '', $target)); -+/* if ($change && ($mod_installed || $force_install)) -+ { -+*/ $status = $editor->copy_content($this->mod_root . str_replace('*.*', '', $source), str_replace('*.*', '', $target)); - - if ($status !== true && !is_null($status)) - { - $mod_installed = false; -+ $template->assign_var('S_DISPLAY_NEW_FILES', true); - } - - $template->assign_block_vars('new_files', array( -@@ -2100,7 +2114,7 @@ - 'SOURCE' => $source, - 'TARGET' => $target, - )); -- } -+/* } - else if ($display && !$change) - { - $template->assign_block_vars('new_files', array( -@@ -2116,7 +2130,7 @@ - 'FILENAME' => $target, - )); - } -- } -+*/ } - } - - // Delete (or reverse-delete) installed files -@@ -2359,7 +2373,7 @@ - { - $template->assign_var('S_SQL', true); - -- parser::parse_sql($actions['SQL']); -+ // parser::parse_sql($actions['SQL']); - - $db->sql_return_on_error(true); - -@@ -2713,6 +2727,8 @@ - - function handle_template_prompt(&$children, &$elements, $action) - { -+ return; -+/* - global $db, $template, $phpbb_root_path, $parent_id; - - if (isset($children['template']) && sizeof($children['template'])) -@@ -2739,6 +2755,7 @@ - // $process_templates are those that are installed on the board and provided for by the MOD - $process_templates = $elements['template'] = array_intersect($available_templates, $installed_templates); - } -+*/ - } - - function upload_mod($action) - - ---- automod-1.0.2/root/includes/editor.php -+++ customisation-db/titania/includes/library/automod/editor.php -@@ -107,6 +106,11 @@ - { - global $phpbb_root_path, $db, $user; - -+ if (strpos($filename, '..') !== false) -+ { -+ return $user->lang['FILE_EMPTY']; -+ } -+ - $this->file_contents = @file($phpbb_root_path . $filename); - - if ($this->file_contents === false) -@@ -116,6 +120,7 @@ - - $this->file_contents = $this->normalize($this->file_contents); - -+/* - // Check for file contents in the database if this is a template file - // this will overwrite the @file call if it exists in the DB. - if (strpos($filename, 'template/') !== false) -@@ -149,6 +154,7 @@ - $this->template_id = 0; - } - } -+*/ - - /* - * If the file does not exist, or is empty, die. -@@ -800,7 +806,7 @@ - - if (strpos($from, $phpbb_root_path) !== 0) - { -- $from = $phpbb_root_path . $from; -+ //$from = $phpbb_root_path . $from; - } - - if (strpos($to, $phpbb_root_path) !== 0) -@@ -826,9 +832,21 @@ - { - return false; - } -+/* - else if (!is_dir($dirname_check) && $this->recursive_mkdir($dirname_check) === false) - { - return sprintf($user->lang['MODS_MKDIR_FAILED'], $dirname_check); -+ } -+*/ -+ -+ // We're only interested in finding out whether the file/directory exists for titania's checks -+ if (!file_exists($from)) -+ { -+ return false; -+ } -+ else -+ { -+ return true; - } - - foreach ($files as $file) - ---- automod-1.0.2/root/includes/functions_mods.php -+++ customisation-db/titania/includes/library/automod/functions_mods.php -@@ -288,6 +287,8 @@ - */ - function update_database_template($filename, $template_id, $file_contents, $install_time) - { -+ return; -+/* - global $db; - - // grab filename -@@ -306,6 +307,7 @@ - - // if something failed, sql_query will error out - return true; -+*/ - } - - function determine_write_method($preview = false) - ---- automod-1.0.2/root/includes/mod_parser.php -+++ customisation-db/titania/includes/library/automod/mod_parser.php -@@ -470,6 +469,9 @@ - 'MOD_VERSION' => htmlspecialchars(trim($version)), - // 'MOD_DEPENDENCIES' => (isset($header['TITLE'][0]['data'])) ? htmlspecialchars(trim($header['TITLE'][0]['data'])) : '', - -+ 'INSTALLATION_LEVEL' => (isset($header['INSTALLATION'][0]['children']['LEVEL'][0]['data'])) ? $header['INSTALLATION'][0]['children']['LEVEL'][0]['data'] : 0, -+ 'INSTALLATION_TIME' => (isset($header['INSTALLATION'][0]['children']['TIME'][0]['data'])) ? $header['INSTALLATION'][0]['children']['TIME'][0]['data'] : 0, -+ - 'AUTHOR_DETAILS' => $author_details, - 'AUTHOR_NOTES' => nl2br(localise_tags($header, 'AUTHOR-NOTES')), - 'MOD_HISTORY' => $mod_history, -@@ -496,7 +498,7 @@ - $sql_info = (!empty($xml_actions['SQL'])) ? $xml_actions['SQL'] : array(); - - $match_dbms = array(); -- switch ($db->sql_layer) -+ switch ($db->get_sql_layer()) - { - case 'firebird': - case 'oracle': - diff --git a/includes/library/automod/editor.php b/includes/library/automod/editor.php deleted file mode 100644 index 13bb60e67..000000000 --- a/includes/library/automod/editor.php +++ /dev/null @@ -1,1442 +0,0 @@ -lang['FILE_EMPTY']; - } - - $this->file_contents = @file($phpbb_root_path . $filename); - - if ($this->file_contents === false) - { - return $user->lang['FILE_EMPTY']; - } - - $this->file_contents = $this->normalize($this->file_contents); - -/* - // Check for file contents in the database if this is a template file - // this will overwrite the @file call if it exists in the DB. - if (strpos($filename, 'template/') !== false) - { - // grab template name and filename - preg_match('#styles/([a-z0-9_]+)/template/([a-z0-9_]+.[a-z]+)#i', $filename, $match); - - $sql = 'SELECT d.template_data, d.template_id - FROM ' . STYLES_TEMPLATE_DATA_TABLE . ' d, ' . STYLES_TEMPLATE_TABLE . " t - WHERE d.template_filename = '" . $db->sql_escape($match[2]) . "' - AND t.template_id = d.template_id - AND t.template_storedb = 1 - AND t.template_name = '" . $db->sql_escape($match[1]) . "'"; - $result = $db->sql_query($sql); - - if ($row = $db->sql_fetchrow($result)) - { - $this->file_contents = explode("\n", $this->normalize($row['template_data'])); - - // emulate the behavior of file() - $lines = sizeof($this->file_contents); - for ($i = 0; $i < $lines; $i++) - { - $this->file_contents[$i] .= "\n"; - } - - $this->template_id = $row['template_id']; - } - else - { - $this->template_id = 0; - } - } -*/ - - /* - * If the file does not exist, or is empty, die. - * Non existant files cannot be edited, and empty files will have no - * finds - */ - if (!sizeof($this->file_contents)) - { - global $user; - trigger_error(sprintf($user->lang['MOD_OPEN_FILE_FAIL'], "$phpbb_root_path$filename"), E_USER_WARNING); - } - - $this->start_index = 0; - $this->open_filename = $filename; - - // Should we backup this file? - if ($backup_path) - { - $this->backup_file($backup_path); - } - } - - /** - * Checks if a find is present - * Keep in mind partial finds and multi-line finds - * - * @param string $find - string to find - * @return mixed : array with position information if $find is found; false otherwise - */ - function find($find) - { - if ($find == '') - { - // Can't find a empty string, - return(false); - } - - $find_success = 0; - - $find = $this->normalize($find); - $find_ary = explode("\n", rtrim($find, "\n")); - - $total_lines = sizeof($this->file_contents); - $find_lines = sizeof($find_ary); - - $mode = array('', 'trim'); - - foreach ($mode as $function) - { - // we process the file sequentially ... so we keep track of indices - for ($i = $this->start_index; $i < $total_lines; $i++) - { - for ($j = 0; $j < $find_lines; $j++) - { - if ($function) - { - $find_ary[$j] = $function($find_ary[$j]); - } - - // if we've reached the EOF, the find failed. - if (!isset($this->file_contents[$i + $j])) - { - return false; - } - - if (!trim($find_ary[$j])) - { - // line is blank. Assume we can find a blank line, and continue on - $find_success += 1; - } - // using $this->file_contents[$i + $j] to keep the array pointer where I want it - // if the first line of the find (index 0) is being looked at, $i + $j = $i. - // if $j is > 0, we look at the next line of the file being inspected - // hopefully, this is a decent performer. - else if (strpos($this->file_contents[$i + $j], $find_ary[$j]) !== false) - { - // we found this part of the find - $find_success += 1; - } - // we might have an increment operator, which requires a regular expression match - else if (strpos($find_ary[$j], '{%:') !== false) - { - $regex = preg_replace('#{%:(\d+)}#', '(\d+)', $find_ary[$j]); - - if (preg_match('#' . $regex . '#is', $this->file_contents[$i + $j])) - { - $find_success += 1; - } - else - { - $find_success = 0; - } - } - else - { - // the find failed. Reset $find_success - $find_success = 0; - - // skip to next iteration of outer loop, that is, skip to the next line - break; - } - - if ($find_success == $find_lines) - { - // we found the proper number of lines - $this->start_index = $i; - - // return our array offsets - return array( - 'start' => $i, - 'end' => $i + $j, - ); - } - - } - } - } - - // if return has not been previously invoked, the find failed. - return false; - } - - /** - * This function is used to determine when an edit has ended, so we know that - * the current line will not be looked at again. This fixes some former bugs. - */ - function close_edit() - { - $this->start_index++; - $this->last_action = array(); - $this->last_string_offset = 0; - } - - /* - * In-line analog to close_edit(), above. - * Advance the pointer one character - */ - function close_inline_edit() - { - $this->last_string_offset++; - } - - /** - * Find a string within a given line - * - * @param string $find Complete find - narrows the scope of the inline search - * @param string $inline_find - the substring to find - * @param int $start_offset - the line number where $find starts - * @param int $end_offset - the line number where $find ends - * - * @return mixed array on success or false on failure of find - */ - function inline_find($find, $inline_find, $start_offset = false, $end_offset = false) - { - if ($inline_find == '') - { - // Can't find a empty string, - return(false); - } - - $find = $this->normalize($find); - - if ($start_offset === false || $end_offset === false) - { - $offsets = $this->find($find); - - if (!$offsets) - { - // the find failed, so no further action can occur. - return false; - } - - $start_offset = $offsets['start']; - $end_offset = $offsets['end']; - - unset($offsets); - } - - // cast is required in case someone tries to find a number - // Often done in colspan="7" type inline operations - $inline_find = (string) $inline_find; - - // similar method to find(). Just much more limited scope - for ($i = $start_offset; $i <= $end_offset; $i++) - { - if ($this->last_string_offset > 0 && ($this->last_inline_ary_offset == 0 || $this->last_inline_ary_offset == $i)) - { - $string_offset = strpos(substr($this->file_contents[$i], $this->last_string_offset), $inline_find); - - if ($string_offset !== false) - { - $string_offset += $this->last_string_offset; - } - } - else - { - $string_offset = strpos($this->file_contents[$i], $inline_find); - } - - if ($string_offset !== false) - { - $this->last_string_offset = $string_offset; - $this->last_inline_ary_offset = $i; - - // if we find something, return the line number, string offset, and find length - return array( - 'array_offset' => $i, - 'string_offset' => $string_offset, - 'find_length' => strlen($inline_find), - ); - } - } - - // if the previous failed, trim() the find and try again - for ($i = $start_offset; $i <= $end_offset; $i++) - { - $inline_find = trim($inline_find); - if ($this->last_string_offset > 0 && ($this->last_inline_ary_offset == 0 || $this->last_inline_ary_offset == $i)) - { - $string_offset = strpos(substr($this->file_contents[$i], $this->last_string_offset), $inline_find); - - if ($string_offset !== false) - { - $string_offset += $this->last_string_offset; - } - } - else - { - $string_offset = strpos($this->file_contents[$i], $inline_find); - } - - if ($string_offset !== false) - { - $this->last_string_offset = $string_offset; - - // if we find something, return the line number, string offset, and find length - return array( - 'array_offset' => $i, - 'string_offset' => $string_offset, - 'find_length' => strlen($inline_find), - ); - } - } - - return false; - } - - - /** - * Add a string to the file, BEFORE/AFTER the given find string - * @param string $find - Complete find - narrows the scope of the inline search - * @param string $add - The string to be added before or after $find - * @param string $pos - BEFORE or AFTER - * @param int $start_offset - First line in the FIND - * @param int $end_offset - Last line in the FIND - * - * @return bool success or failure of add - */ - function add_string($find, $add, $pos, $start_offset = false, $end_offset = false) - { - // this seems pretty simple...throughly test - $add = $this->normalize($add); - - if ($start_offset === false || $end_offset === false) - { - $offsets = $this->find($find); - - if (!$offsets) - { - // the find failed, so the add cannot occur. - return false; - } - - $start_offset = $offsets['start']; - $end_offset = $offsets['end']; - - unset($offsets); - } - - $full_find = array(); - for ($i = $start_offset; $i <= $end_offset; $i++) - { - $full_find[] = $this->file_contents[$i]; - } - - $full_find[0] = ltrim($full_find[0], "\n"); - $full_find[sizeof($full_find) - 1] = rtrim($full_find[sizeof($full_find) - 1], "\n"); - - // make sure our new lines are correct - $add = "\n" . trim($add, "\n") . "\n"; - - if ($pos == 'AFTER') - { - $this->file_contents[$end_offset] = rtrim($this->file_contents[$end_offset], "\n") . $add; - } - - if ($pos == 'BEFORE') - { - $this->file_contents[$start_offset] = $add . ltrim($this->file_contents[$start_offset], "\n"); - } - - $this->curr_action = func_get_args(); - $this->build_uninstall(implode("", $full_find), NULL, strtolower($pos) . ' add', $add); - - return true; - } - - /** - * Increment (or perform other mathematical operation) on the given wildcard - * Support multiple wildcards {%:1}, {%:2} etc... - * This method is a variation on the inline find and replace methods - * - * @param string $find - Complete find - contains $inline_find - * @param string $inline_find - contains tokens to be replaced - * @param string $operation - tokens to do some math - * @param int $start_offset - First line in the FIND - * @param int $end_offset - Last line in the FIND - * - * @return bool - */ - function inc_string($find, $inline_find, $operation, $start_offset = false, $end_offset = false) - { - if ($start_offset === false || $end_offset === false) - { - $offsets = $this->find($find); - - if (!$offsets) - { - // the find failed, so the add cannot occur. - return false; - } - - $start_offset = $offsets['start']; - $end_offset = $offsets['end']; - - unset($offsets); - } - - // $inline_find is optional - if (!$inline_find) - { - $inline_find = $find; - } - - // parse the MODX operator - // let's explain this regex a bit: - // - literal %: followed by a number. optional space - // - plus or minus operator. optional space - // - number to increment by. optional - preg_match('#{%:(\d+)} ?([+-]) ?(\d*)#', $operation, $action); - // make sure there is actually a number here - $action[2] = (isset($action[2])) ? $action[2] : '+'; - $action[3] = (isset($action[3])) ? $action[3] : 1; - - $matches = 0; - // $start_offset _should_ equal $end_offset, but we allow other cases - for ($i = $start_offset; $i <= $end_offset; $i++) - { - // This is intended. We turn the MODX token into something PCRE can - // understand. - $inline_find = preg_replace('#{%:(\d+)}#', '(\d+)', $inline_find); - - if (preg_match('#' . $inline_find . '#is', $this->file_contents[$i], $find_contents)) - { - // now we can do some math - // $find_contents[1] is the original number, $action[2] is the operator - $new_number = eval('return ' . ((int) $find_contents[1]) . $action[2] . ((int) $action[3]) . ';'); - - // now we replace - $new_contents = str_replace($find_contents[1], $new_number, $find_contents[0]); - - $this->file_contents[$i] = str_replace($find_contents[0], $new_contents, $this->file_contents[$i]); - - $matches += 1; - } - } - - if (!$matches) - { - return false; - } - - return true; - } - - - /** - * Replace a string - replaces the entirety of $find with $replace - * - * @param string $find - Complete find - contains $inline_find - * @param string $replace - Will replace $find - * @param int $start_offset - First line in the FIND - * @param int $end_offset - Last line in the FIND - * - * @return bool - */ - function replace_string($find, $replace, $start_offset = false, $end_offset = false) - { - $replace = $this->normalize($replace); - - if ($start_offset === false || $end_offset === false) - { - $offsets = $this->find($find); - - if (!$offsets) - { - return false; - } - - $start_offset = $offsets['start']; - $end_offset = $offsets['end']; - unset($offsets); - } - - // remove each line from the file, but add it to $full_find - $full_find = array(); - for ($i = $start_offset; $i <= $end_offset; $i++) - { - $full_find[] = $this->file_contents[$i]; - $this->file_contents[$i] = ''; - } - - $this->file_contents[$start_offset] = rtrim($replace) . "\n"; - - $this->curr_action = func_get_args(); - $this->build_uninstall(implode("", $full_find), NULL, 'replace-with', $replace); - - return true; - } - - /* - * Replace $inline_find with $inline_replace - * Arguments are very similar to inline_add, below - */ - function inline_replace($find, $inline_find, $inline_replace, $array_offset = false, $string_offset = false, $length = false) - { - if ($string_offset === false || $length === false) - { - // look for the inline find - $inline_offsets = $this->inline_find($find, $inline_find); - - if (!$inline_offsets) - { - return false; - } - - $array_offset = $inline_offsets['array_offset']; - $string_offset = $inline_offsets['string_offset']; - $length = $inline_offsets['find_length']; - unset($inline_offsets); - } - - $this->file_contents[$array_offset] = substr_replace($this->file_contents[$array_offset], $inline_replace, $string_offset, $length); - - $this->last_string_offset += strlen($inline_replace) - 1; - - $this->curr_action = func_get_args(); - - // This isn't a full find, but it is the closest we can get - $this->build_uninstall($this->file_contents[$array_offset], $inline_find, 'in-line-replace', $inline_replace); - - return true; - } - - /** - * Adds a string inline before or after a given find - * - * @param string $find Complete find - narrows the scope of the inline search - * @param string $inline_find - the string to add before or after - * @param string $inline_add - added before or after $inline_find - * @param string $pos - 'BEFORE' or 'AFTER' - * @param int $array_offset - line number where $inline_find may be found (optional) - * @param int $string_offset - location within the line where $inline_find begins (optional) - * @param int $length - essentially strlen($inline_find) (optional) - * - * @return bool success or failure of action - */ - function inline_add($find, $inline_find, $inline_add, $pos, $array_offset = false, $string_offset = false, $length = false) - { - if ($string_offset === false || $length === false) - { - // look for the inline find - $inline_offsets = $this->inline_find($find, $inline_find); - - if (!$inline_offsets) - { - return false; - } - - $array_offset = $inline_offsets['array_offset']; - $string_offset = $inline_offsets['string_offset']; - $length = $inline_offsets['find_length']; - unset($inline_offsets); - } - - if ($string_offset + $length > strlen($this->file_contents[$array_offset])) - { - // we have an invalid string offset. rats. - return false; - } - - if ($pos == 'AFTER') - { - $this->file_contents[$array_offset] = substr_replace($this->file_contents[$array_offset], $inline_add, $string_offset + $length, 0); - $this->last_string_offset += strlen($inline_add) + $length - 1; - } - else if ($pos == 'BEFORE') - { - $this->file_contents[$array_offset] = substr_replace($this->file_contents[$array_offset], $inline_add, $string_offset, 0); - $this->last_string_offset += (strlen($inline_add) - 1); - } - - $this->curr_action = func_get_args(); - - $this->build_uninstall($this->file_contents[$array_offset], $inline_find, 'in-line-' . strtolower($pos) . '-add', $inline_add); - - return true; - } - - /** - * Function to build full edits such that uninstall will work more often - * - * @param $find - The largest find we can put together -- sometimes this - * comes from the file itself, other times from the MODX file - * @param $inline_find - Subset of $find or NULL - * @param $action_type - Name of the MODX action being taken - * @param $action - The code which is being inserted into the file - * @return void - */ - function build_uninstall($find, $inline_find, $action_type, $action) - { - $find = trim($find, "\n"); - $inline_find = trim($inline_find, "\n"); - $action = trim($action, "\n"); - - /* - * This if statement finds out if we are in the special case where - * a MOD specifies a before action and an after action on the same - * find. If this is the case, the uninstaller must see a replace - * rather than an add - */ - if (!empty($this->last_action) && $this->last_action[0] == $this->curr_action[0] && - (($this->last_action[2] == 'AFTER' && $this->curr_action[2] == 'BEFORE') - || ($this->last_action[2] == 'BEFORE' && $this->curr_action[2] == 'AFTER'))) - { - array_pop($this->mod_actions[$this->open_filename]); - - $action_type = 'REPLACE'; - - // Remove the add from the find -- this is an effect of the way the - // add method works, putting the new lines in the same array element - // as the find - $find = str_replace(trim($this->last_action[1]), '', $find); - - if ($this->last_action[2] == 'AFTER') - { - $action = $this->curr_action[1] . "\n" . $this->curr_action[0] . "\n" . $this->last_action[1]; - } - else // implicit if ($this->last_action[2] == 'BEFORE') - { - $action = $this->last_action[1] . "\n" . $this->curr_action[0] . "\n" . $this->curr_action[1]; - } - } - - // Build another complex array of MOD Actions - // This approach is rather memory-intensive ... it might behoove us - // to think of something else - if (!$inline_find) - { - $this->mod_actions[$this->open_filename][] = array( - $find => array( - $action_type => $action, - ) - ); - } - else - { - // Do we have preceding in-line-edit(s) on the same complete find or line? - if (!empty($this->last_action) && $this->last_action[0] == $this->curr_action[0]) - { - $prev_inline_edits = array_pop($this->mod_actions[$this->open_filename]); - $prev_find = key($prev_inline_edits); - - // Add our current in-line-edit - $prev_inline_edits[$prev_find]['in-line-edit'][] = array( - $inline_find => array( - $action_type => array($action), - ), - ); - - // Add the new set of in-line-edit's to our MOD Actions array, w/ the updated $find - $this->mod_actions[$this->open_filename][] = array( - $find => $prev_inline_edits[$prev_find] - ); - } - else - { - $this->mod_actions[$this->open_filename][] = array( - $find => array( - 'in-line-edit' => array( - array( - $inline_find => array( - $action_type => array($action), - ), - ), - ), - ), - ); - } - } - - $this->last_action = $this->curr_action; - } - - function clear_actions() - { - // free some memory - $this->mod_actions = array(); - } -} - -/** -* @package automod -* class editor_direct will alter files by using the local file access functions -* such as fopen and fwrite. This is typically only useful in Windows environments -* due to permissions settings. -*/ -class editor_direct extends editor -{ - function editor_direct() - { - $this->write_method = WRITE_DIRECT; - $this->install_time = time(); - } - - /** - * Copies files or complete directories - * - * @param $from string Can be a file or a directory. Will copy either the file or all files within the directory - * @param $to string Where to copy the file(s) to. If not specified then will get copied to the phpbb root directory - * @return mixed: Bool true on success, error string on failure, NULL if no action was taken - * - * NOTE: function should preferably not return in case of failure on only one file. - * The current method makes error handling difficult - */ - function copy_content($from, $to = '') - { - global $phpbb_root_path, $user, $config; - - if (strpos($from, $phpbb_root_path) !== 0) - { - //$from = $phpbb_root_path . $from; - } - - if (strpos($to, $phpbb_root_path) !== 0) - { - $to = $phpbb_root_path . $to; - } - - $files = array(); - if (is_dir($from)) - { - $files = find_files($from, '.*'); - $dirname_check = $to; - $to_is_dir = true; - } - else if (is_file($from)) - { - $files = array($from); - $dirname_check = dirname($to); - $to_is_dir = false; - } - - if (empty($files)) - { - return false; - } -/* - else if (!is_dir($dirname_check) && $this->recursive_mkdir($dirname_check) === false) - { - return sprintf($user->lang['MODS_MKDIR_FAILED'], $dirname_check); - } -*/ - - // We're only interested in finding out whether the file/directory exists for titania's checks - if (!file_exists($from)) - { - return false; - } - else - { - return true; - } - - foreach ($files as $file) - { - if ($to_is_dir) - { - $dest = str_replace($from, $to, $file); - - $dest_parent_dir = dirname($dest); - if (!file_exists($dest_parent_dir)) - { - $this->recursive_mkdir($dest_parent_dir); - } - } - else - { - $dest = $to; - } - - if (!@copy($file, $dest)) - { - return sprintf($user->lang['MODS_COPY_FAILURE'], $dest); - } - @chmod($dest, octdec($config['am_file_perms'])); - } - - return true; - } - - function close_file($new_filename) - { - global $phpbb_root_path, $config, $mod_installed, $mod_uninstalled, $force_install; - global $db, $user; - - if (!is_dir($new_filename) && !file_exists(dirname($new_filename))) - { - if ($this->recursive_mkdir(dirname($new_filename)) === false) - { - return sprintf($user->lang['MODS_MKDIR_FAILED'], dirname($new_filename)); - } - } - - $file_contents = implode('', $this->file_contents); - - if (file_exists($new_filename) && !is_writable($new_filename)) - { - return sprintf($user->lang['WRITE_DIRECT_FAIL'], $new_filename); - } - - if ($this->template_id && ($mod_installed || $mod_uninstalled || $force_install)) - { - update_database_template($new_filename, $this->template_id, $file_contents, $this->install_time); - } - - // If we are not looking at a file stored in the database, use local file functions - $fr = @fopen($new_filename, 'wb'); - $length_written = @fwrite($fr, $file_contents); - @chmod($new_filename, octdec($config['am_file_perms'])); - - // This appears to be correct even with multibyte encodings. strlen and - // fwrite both return the number of bytes written, not the number of chars - if ($length_written < strlen($file_contents)) - { - return sprintf($user->lang['WRITE_DIRECT_TOO_SHORT'], $new_filename); - } - - if (!@fclose($fr)) - { - return sprintf($user->lang['WRITE_DIRECT_FAIL'], $new_filename); - } - - return true; - } - - /** - * Creates a backup of the currently open file before AutoMOD makes any changes - */ - function backup_file($backup_dir) - { - return $this->close_file($backup_dir . $this->open_filename); - } - - /** - * @author Michal Nazarewicz (from the php manual) - * Creates all non-existant directories in a path - * @param $path - path to create - * @param $mode - CHMOD the new dir to these permissions - * @return bool - */ - function recursive_mkdir($path, $mode = false) - { - if (!$mode) - { - global $config; - $mode = octdec($config['am_dir_perms']); - } - - $dirs = explode('/', $path); - $count = sizeof($dirs); - $path = '.'; - for ($i = 0; $i < $count; $i++) - { - $path .= '/' . $dirs[$i]; - - if (!is_dir($path)) - { - @mkdir($path, $mode); - @chmod($path, $mode); - - if (!is_dir($path)) - { - return false; - } - } - } - return true; - } - - function commit_changes($source, $destination) - { - return $this->copy_content($source, $destination); - } - - function commit_changes_final($source, $destination) - { - return NULL; - } - - function create_edited_root($dir) - { - return $this->recursive_mkdir($dir); - } - - /** - * Removes a file or a directory (optionally recursively) - * - * @param $path string (required) - Filename/Directory path to remove - * @param $recursive bool (optional) - Recursively delete directories - * @author jasmineaura - */ - function remove($path, $recursive = false) - { - global $phpbb_root_path, $user; - - if (strpos($path, $phpbb_root_path) !== 0) - { - $path = $phpbb_root_path . $path; - } - - if (is_dir($path)) - { - if ($recursive) - { - // recursively delete (in functions_mod.php) - return recursive_unlink($path); - } - else - { - if (check_empty_dir($path)) - { - // No error message. - // If the directory is not empty it is probably not an error. - - if (!rmdir($path)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path); - } - } - } - } - else - { - if (!unlink($path)) - { - return sprintf($user->lang['MODS_RMFILE_FAILURE'], $path); - } - } - - return true; - } -} - -class editor_ftp extends editor -{ - var $transfer; - - function editor_ftp() - { - global $config, $user; - - $this->write_method = WRITE_FTP; - $this->install_time = time(); - - if (!class_exists('transfer')) - { - global $phpbb_root_path, $phpEx; - include($phpbb_root_path . 'includes/functions_transfer.' . $phpEx); - } - - $this->transfer = new $config['ftp_method']($config['ftp_host'], $config['ftp_username'], request_var('password', ''), $config['ftp_root_path'], $config['ftp_port'], $config['ftp_timeout']); - $error = $this->transfer->open_session(); - - // Use the permissions settings specified in the AutoMOD configuration - $this->transfer->dir_perms = octdec($config['am_dir_perms']); - $this->transfer->file_perms = octdec($config['am_file_perms']); - - if (is_string($error)) - { - // FTP login failed - trigger_error(sprintf($user->lang['MODS_FTP_CONNECT_FAILURE'], $user->lang[$error]), E_USER_ERROR); - } - } - - /** - * Copies files or complete directories - * - * @param $from string Can be a file or a directory. Will copy either the file or all files within the directory - * @param $to string Where to copy the file(s) to. If not specified then will get copied to the phpbb root directory - * @return mixed: Bool true on success, error string on failure, NULL if no action was taken - * - * NOTE: function should preferably not return in case of failure on only one file. - * The current method makes error handling difficult - */ - function copy_content($from, $to = '') - { - global $phpbb_root_path, $user; - - // Prefix $from with $phpbb_root_path - if (strpos($from, $phpbb_root_path) !== 0) - { - $from = $phpbb_root_path . $from; - } - - if (strpos($to, $phpbb_root_path) !== 0) - { - $to = $phpbb_root_path . $to; - } - - $files = array(); - if (is_dir($from)) - { - $files = find_files($from, '.*'); - $dirname_check = $to; - $to_is_dir = true; - } - else if (is_file($from)) - { - $files = array($from); - $dirname_check = dirname($to); - $to_is_dir = false; - } - - if (empty($files)) - { - return false; - } - else if (!is_dir($dirname_check) && $this->recursive_mkdir($dirname_check) === false) - { - return sprintf($user->lang['MODS_MKDIR_FAILED'], $dirname_check); - } - - foreach ($files as $file) - { - if ($to_is_dir) - { - $dest = str_replace($from, $to, $file); - - $dest_parent_dir = dirname($dest); - if (!file_exists($dest_parent_dir)) - { - $this->recursive_mkdir($dest_parent_dir); - } - } - else - { - $dest = $to; - } - - // Per functions_transfer.php, overwrite_file() (which we'll use here) is the only - // transfer method that doesn't strip out phpbb_root_path, because it is called - // by other methods (write_file, copy_file) that already do so before calling it. - // The ftp class prepends the real (ftp) $root_path ! - $dest = str_replace($phpbb_root_path, '', $dest); - - if (!$this->transfer->overwrite_file($file, $dest)) - { - return sprintf($user->lang['MODS_FTP_FAILURE'], $dest); - } - } - - return true; - } - - /** - * Write & close file - */ - function close_file($new_filename) - { - global $phpbb_root_path, $edited_root, $mod_installed, $mod_uninstalled, $force_install; - global $db, $user; - - if (!is_dir($new_filename) && !file_exists(dirname($new_filename))) - { - if ($this->recursive_mkdir(dirname($new_filename)) === false) - { - return sprintf($user->lang['MODS_MKDIR_FAILED'], dirname($new_filename)); - } - } - - $file_contents = implode('', $this->file_contents); - - if ($this->template_id && ($mod_installed || $mod_uninstalled || $force_install)) - { - update_database_template($new_filename, $this->template_id, $file_contents, $this->install_time); - } - - if (!$this->transfer->write_file($new_filename, $file_contents)) - { - return sprintf($user->lang['MODS_FTP_FAILURE'], $new_filename); - } - - return true; - } - - /** - * Creates a backup of the currently open file before AutoMOD makes any changes - */ - function backup_file($backup_dir) - { - return $this->close_file($backup_dir . $this->open_filename); - } - - /** - * @ignore - */ - function recursive_mkdir($path, $mode = false) - { - if ($mode) - { - $this->transfer->dir_perms = $mode; - } - - return $this->transfer->make_dir($path); - } - - function commit_changes($source, $destination) - { - // Move edited files back - return $this->copy_content($source, $destination); - } - - function commit_changes_final($source, $destionation) - { - return NULL; - } - - function create_edited_root($dir) - { - return $this->recursive_mkdir($dir); - } - - /** - * Removes a file or a directory (optionally recursively) - * - * @param $path string (required) - Filename/Directory path to remove - * @param $recursive bool (optional) - Recursively delete directories - * @author jasmineaura - */ - function remove($path, $recursive = false) - { - global $phpbb_root_path, $phpEx, $user; - - // No need to strip phpbb_root_path afterwards, as the transfer class - // functions - remove_dir() and delete_file() - already do that for us - if (strpos($path, $phpbb_root_path) !== 0) - { - $path = $phpbb_root_path . $path; - } - - if (is_dir($path)) - { - // Recursive delete: - // remove_dir() in functions_transfer.php still says "todo remove child directories?" - // It's really easy to recursively delete in ftp, but unfortunately what exposes access to - // ftp_nlist() (or NLST); "_ls", is private to the transfer class, so we can't use it yet - if ($recursive) - { - // Insurance - this should never really happen - if ($path == $phpbb_root_path || is_file("$path/common.$phpEx")) - { - return false; - } - - // Get all of the files in the source directory - $files = find_files($path, '.*'); - // Get all of the sub-directories in the source directory - $subdirs = find_files($path, '.*', 20, true); - - // Delete all the files - foreach ($files as $file) - { - if (!$this->transfer->delete_file($file)) - { - return sprintf($user->lang['MODS_RMFILE_FAILURE'], $file); - } - } - - // Delete all the sub-directories, in _reverse_ order (array_pop) - for ($i=0, $cnt = count($subdirs); $i < $cnt; $i++) - { - $subdir = array_pop($subdirs); - if (!$this->transfer->remove_dir($subdir)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $subdir); - } - } - - // Finally, delete the directory itself - if (!$this->transfer->remove_dir($path)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path); - } - } - else if (!$this->transfer->remove_dir($path)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path); - } - } - else if (!$this->transfer->delete_file($path)) - { - return sprintf($user->lang['MODS_RMFILE_FAILURE'], $path); - } - - return true; - } -} - -class editor_manual extends editor -{ - function editor_manual() - { - global $config, $phpbb_root_path; - - $this->write_method = WRITE_MANUAL; - $this->install_time = time(); - - if (!class_exists('compress')) - { - global $phpEx; - include($phpbb_root_path . 'includes/functions_compress.' . $phpEx); - } - - // Ugly regular expression to extract "tar" from "tar.gz" or "tar.bz2" - // Made ugly because it does nothing with "zip" - preg_match('#\.(\w{3})\.?.*#', $config['compress_method'], $match); - $class = 'compress_' . $match[1]; - - $this->compress = new $class('w', $phpbb_root_path . 'store/mod_' . $this->install_time . $config['compress_method'], $config['compress_method']); - } - - function copy_content($from, $to = '') - { - global $phpbb_root_path, $user; - - if (strpos($from, $phpbb_root_path) !== 0) - { - $from = $phpbb_root_path . $from; - } - - if (strpos($to, $phpbb_root_path) !== 0) - { - $to = $phpbb_root_path . $to; - } - - // Note: phpBB's compression class does support adding a whole directory at a time. - // However, I chose not to use that function because it would not allow AutoMOD's - // error handling to work the same as for FTP & Direct methods. - $files = array(); - if (is_dir($from)) - { - $files = find_files($from, '.*'); - $to_is_dir = true; - } - else if (is_file($from)) - { - $files = array($from); - $to_is_dir = false; - } - - if (empty($files)) - { - return false; - } - - foreach ($files as $file) - { - if ($to_is_dir) - { - $dest = str_replace($from, $to, $file); - } - else - { - $dest = $to; - } - - // Replace root path with the "files/" directory that goes in the zip - $dest = str_replace($phpbb_root_path, 'files/', $dest); - - if (!$this->compress->add_custom_file($file, $dest)) - { - return sprintf($user->lang['WRITE_MANUAL_FAIL'], $dest); - } - } - - // return true since we are now taking an action - NULL implies no action - return true; - } - - /** - * Write & close file - */ - function close_file($new_filename) - { - global $phpbb_root_path, $edited_root, $mod_installed, $mod_uninstalled, $force_install; - global $db, $user; - - $file_contents = implode('', $this->file_contents); - - if ($this->template_id && ($mod_installed || $mod_uninstalled || $force_install)) - { - update_database_template($new_filename, $this->template_id, $file_contents, $this->install_time); - } - - // don't include extra dirs in zip file - $strip_position = strpos($new_filename, '_edited') + 8; // want the end of the string - - $new_filename = 'files/' . substr($new_filename, $strip_position); - - if (!$this->compress->add_data($file_contents, $new_filename)) - { - return sprintf($user->lang['WRITE_MANUAL_FAIL'], $new_filename); - } - - return true; - } - - /** - * Backup is undefined when creating a compressed file. - */ - function backup_file($backup_dir) - { - return NULL; - } - - function recursive_mkdir($path, $mode = 0777) - { - return NULL; - } - - function commit_changes($source, $destination) - { - global $template, $user, $phpbb_admin_path; - - $download_url = append_sid("{$phpbb_admin_path}index.php", 'i=mods&mode=frontend&action=download&time=' . $this->install_time); - - $template->assign_vars(array( - 'S_MANUAL_INSTRUCTIONS' => true, - 'L_AM_MANUAL_INSTRUCTIONS' => sprintf($user->lang['AM_MANUAL_INSTRUCTIONS'], '', ''), - )); - - meta_refresh(3, $download_url); - - $this->compress->close(); - return true; - } - - function commit_changes_final($source, $destination) - { - return NULL; - } - - function create_edited_root($dir) - { - return NULL; - } - - function remove($file, $recursive = false) - { - return NULL; - } -} - -?> diff --git a/includes/library/automod/functions_mods.php b/includes/library/automod/functions_mods.php deleted file mode 100644 index 83ea5c687..000000000 --- a/includes/library/automod/functions_mods.php +++ /dev/null @@ -1,580 +0,0 @@ -open_session(); - - // Make sure that the directory is correct by checking for the existence of common.php - if ($test_connection === true) - { - // Check for common.php file - if (!$transfer->file_exists($phpbb_root_path, 'common.' . $phpEx)) - { - $test_connection = 'ERR_WRONG_PATH_TO_PHPBB'; - } - } - - $transfer->close_session(); - - // Make sure the login details are correct before continuing - if ($test_connection !== true) - { - $test_ftp_connection = true; - } - - return; -} - -/** -* Helper function -* Runs basename() on $path, then trims the extension from it -* @param string $path - path to be basenamed -*/ -function core_basename($path) -{ - $path = basename($path); - $path = substr($path, 0, strrpos($path, '.')); - - $parts = explode('-', $path); - return end($parts); -} - -/** -* Helper function for matching languages -* This is a fairly dumb function because it ignores dialects. But I have -* not seen any MODs that specify more than one dialect of the same language -* @param string $user_language - ISO language code of the current user -* @param string $xml_language - ISO language code of the MODX tag -* @return bool Whether or not this is a match -*/ -function match_language($user_language, $xml_language) -{ - return strtolower(substr($user_language, 0, 2)) == strtolower(substr($xml_language, 0, 2)); -} - -/** -* Grab MOD titles -* -* @param $header - variable holding all relevant tag information -* @return array(language iso => MOD name) -*/ -function get_title($header) -{ - if (is_string($header['TITLE'])) - { - return($header['TITLE']); - } - - $return = array(); - foreach ($header['TITLE'] as $row) - { - if (!is_array($row)) - { - continue; - } - - $return[$row['attrs']['LANG']] = trim($row['data']); - } - - return($return); -} - -/** - * Get localized MOD title or English title - * - * @param $titles, string or a serialized array containing the MOD name(s) - * @param $lang, string language ISO. - * @return string with MOD name in users selected language or English. - */ -function localize_title($title, $lang = 'en') -{ - $name_ary = array(); - - if (!is_array($title)) - { - if (($name_ary = @unserialize($title)) === false) - { - // Before AutoMOD 1.0.1 the title was a string with only the MOD name. - return($title); - } - } - else - { - $name_ary = $title; - } - - // If we get here the MOD is installed with AutoMOD 1.0.1+ - // And the stored title is a serialized array. - if (!empty($name_ary[$lang])) - { - return($name_ary[$lang]); - } - else if (!empty($name_ary['en'])) - { - // Default to English if the selected language is not found. - return($name_ary['en']); - } - - // Something went wrong. - // We have a array that neither contain the selected language nor English. - // Return the first array element. - return(array_shift($name_ary)); -} - -/** -* Easy method to grab localisable tags from the XML array -* @param $header - variable holding all relevant tag information -* @param $tagname - tag name to fetch -* @param $index - Index number to pull. Not required. -* @return $output - Localised contents of the tag in question -*/ -function localise_tags($header, $tagname, $index = false) -{ - global $user; - - $output = ''; - - if (isset($header[$tagname]) && is_array($header[$tagname])) - { - foreach ($header[$tagname] as $i => $void) - { - // Ugly. - if ($index !== false && $index != $i) - { - continue; - } - - if (!isset($header[$tagname][$i]['attrs']['LANG'])) - { - // avoid notice...although, if we get here, MODX is invalid. - continue; - } - - if (match_language($user->data['user_lang'], $header[$tagname][$i]['attrs']['LANG'])) - { - $output = isset($header[$tagname][$i]['data']) ? htmlspecialchars(trim($header[$tagname][$i]['data'])) : ''; - } - else if (match_language('en', $header[$tagname][$i]['attrs']['LANG'])) - { - $output = isset($header[$tagname][$i]['data']) ? htmlspecialchars(trim($header[$tagname][$i]['data'])) : ''; - } - } - - // If there was no language match, put something out there - // This is probably fairly common for non-English users of the MODs Manager - if (!$output) - { - $output = isset($header[$tagname][0]['data']) ? htmlspecialchars(trim($header[$tagname][0]['data'])) : ''; - } - } - - if (!$output) - { - // Should never happen. If it does, either the MOD is not valid MODX - // or the tag being localised is optional - $output = isset($user->lang['UNKNOWN_MOD_' . $tagname]) ? $user->lang['UNKNOWN_MOD_' . $tagname] : 'UNKNOWN_MOD_' .$tagname; - } - - return $output; -} - -/** -* List files matching specified PCRE pattern. -* -* @access public -* @param string Relative or absolute path to the directory to be scanned. -* @param string Search pattern (perl compatible regular expression). -* @param integer Number of subdirectory levels to scan (set to 1 to scan only current). -* @param boolean List sub-directories only instead of files -* @param integer This one is used internally to control recursion level. -* @return array List of all files found matching the specified pattern. -*/ -function find_files($directory, $pattern, $max_levels = 20, $subdirs_only = false, $_current_level = 1) -{ - if ($_current_level <= 1) - { - if (strpos($directory, '\\') !== false) - { - $directory = str_replace('\\', '/', $directory); - } - if (empty($directory)) - { - $directory = './'; - } - else if (substr($directory, -1) != '/') - { - $directory .= '/'; - } - } - - $files = array(); - $subdir = array(); - if (is_dir($directory)) - { - $handle = @opendir($directory); - while (($file = @readdir($handle)) !== false) - { - if ($file == '.' || $file == '..') - { - continue; - } - - $fullname = $directory . $file; - - if (is_dir($fullname)) - { - if ($_current_level < $max_levels) - { - if ($subdirs_only) - { - $subdir[] = $fullname . '/'; - $subdir = array_merge($subdir, find_files($fullname . '/', $pattern, $max_levels, true, $_current_level + 1)); - } - else - { - $subdir = array_merge($subdir, find_files($fullname . '/', $pattern, $max_levels, false, $_current_level + 1)); - } - } - } - else - { - if (!$subdirs_only && preg_match('/^' . $pattern . '$/i', $file)) - { - $files[] = $fullname; - } - } - } - @closedir($handle); - sort($files); - } - - return array_merge($files, $subdir); -} - -/** -* This function is common to all editor classes, so it is pulled out from them -* @param $filename - The filename to update -* @param $template_id - The template set to update -* @param $file_contents - The data to write -* @param $install_time - Essentially the current time -* @return bool true -*/ -function update_database_template($filename, $template_id, $file_contents, $install_time) -{ - return; -/* - global $db; - - // grab filename - preg_match('#styles/[a-z0-9_]+/template/([a-z0-9_]+.html)#i', $filename, $match); - - if (empty($match[1])) - { - return false; - } - - $sql = 'UPDATE ' . STYLES_TEMPLATE_DATA_TABLE . " - SET template_data = '" . $db->sql_escape($file_contents) . "', template_mtime = " . (int) $install_time . ' - WHERE template_id = ' . (int) $template_id . " - AND template_filename = '" . $db->sql_escape($match[1]) . "'"; - $db->sql_query($sql); - - // if something failed, sql_query will error out - return true; -*/ -} - -function determine_write_method($preview = false) -{ - global $phpbb_root_path, $config; - - // to be truly correct, we should scan all files ... - if (($config['write_method'] == WRITE_DIRECT && is_writable($phpbb_root_path)) || $preview) - { - $write_method = 'direct'; - } - // FTP Method is now auto-detected - else if ($config['write_method'] == WRITE_FTP) - { - $write_method = 'ftp'; - } - // or zip or tarballs - else if ($config['compress_method']) - { - $write_method = 'manual'; - } - else - { - // We cannot go on without a write method set up. - trigger_error('MODS_SETUP_INCOMPLETE', E_USER_ERROR); - } - - return $write_method; -} - -function handle_ftp_details($method, $test_ftp_connection, $test_connection) -{ - global $config, $template, $user; - - $s_hidden_fields = build_hidden_fields(array('method' => $method)); - - if (!class_exists($method)) - { - trigger_error('Method does not exist.', E_USER_ERROR); - } - - $requested_data = call_user_func(array($method, 'data')); - foreach ($requested_data as $data => $default) - { - $default = (!empty($config['ftp_' . $data])) ? $config['ftp_' . $data] : $default; - - $template->assign_block_vars('data', array( - 'DATA' => $data, - 'NAME' => $user->lang[strtoupper($method . '_' . $data)], - 'EXPLAIN' => $user->lang[strtoupper($method . '_' . $data) . '_EXPLAIN'], - 'DEFAULT' => (!empty($_REQUEST[$data])) ? request_var($data, '') : $default - )); - } - - $template->assign_vars(array( - 'S_CONNECTION_SUCCESS' => ($test_ftp_connection && $test_connection === true) ? true : false, - 'S_CONNECTION_FAILED' => ($test_ftp_connection && $test_connection !== true) ? true : false, - 'ERROR_MSG' => ($test_ftp_connection && $test_connection !== true) ? $user->lang[$test_connection] : '', - - 'S_FTP_UPLOAD' => true, - 'UPLOAD_METHOD' => $method, - 'S_HIDDEN_FIELDS_FTP' => $s_hidden_fields, - )); -} - -/** -* Gets FTP information if we need it -* -* @param $preview bool true if in pre_(install|uninstall), false otherwise -* @return array and array of connection info (currently only ftp) -*/ -function get_connection_info($preview = false) -{ - global $config, $ftp_method, $test_ftp_connection, $test_connection; - - $conn_info_ary = array(); - - // using $config instead of $editor because write_method is forced to direct - // when in preview mode - if ($config['write_method'] == WRITE_FTP) - { - if (!$preview && isset($_POST['password'])) - { - $conn_info_ary['method'] = $config['ftp_method']; - - if (empty($config['ftp_method'])) - { - trigger_error('FTP_METHOD_ERROR'); - } - - $requested_data = call_user_func(array($config['ftp_method'], 'data')); - - foreach ($requested_data as $data => $default) - { - if ($data == 'password') - { - $config['ftp_password'] = request_var('password', ''); - } - $default = (!empty($config['ftp_' . $data])) ? $config['ftp_' . $data] : $default; - - $conn_info_ary[$data] = $default; - } - } - - handle_ftp_details($ftp_method, $test_ftp_connection, $test_connection); - } - - return $conn_info_ary; -} - -/** - * Recursively delete a directory - * - * @param string $path (required) Directory path to recursively delete - * @author jasmineaura - */ -function recursive_unlink($path) -{ - global $phpbb_root_path, $phpEx, $user; - - // Insurance - this should never really happen - if ($path == $phpbb_root_path || is_file("$path/common.$phpEx")) - { - return false; - } - - // Get all of the files in the source directory - $files = find_files($path, '.*'); - // Get all of the sub-directories in the source directory - $subdirs = find_files($path, '.*', 20, true); - - // Delete all the files - foreach ($files as $file) - { - if (!unlink($file)) - { - return sprintf($user->lang['MODS_RMFILE_FAILURE'], $file); - } - } - - // Delete all the sub-directories, in _reverse_ order (array_pop) - for ($i=0, $cnt = count($subdirs); $i < $cnt; $i++) - { - $subdir = array_pop($subdirs); - if (!rmdir($subdir)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $subdir); - } - } - - // Finally, delete the directory itself - if (!rmdir($path)) - { - return sprintf($user->lang['MODS_RMDIR_FAILURE'], $path); - } - - return true; -} - -/** -* PHP 5 Wrapper - simulate scandir, but only those features that we actually need -* NB: The third parameter of PHP5 native scandir is _not_ present in this wrapper -*/ -if (!function_exists('scandir')) -{ - function scandir($directory, $sorting_order = false) - { - $files = array(); - - $dp = opendir($directory); - while (($filename = readdir($dp)) !== false) - { - $files[] = $filename; - } - - if ($sorting_order) - { - rsort($files); - } - else - { - sort($files); - } - - return $files; - } -} - -/** -* Return the number of files (optionally including sub-directories) in a directory, optionally recursively. -* -* @param $dir string (required) - The directory you want to count files in -* @param $subdirs boolean (optional) - Count subdirectories instead of files -* @param $recurse boolean (optional) - Recursive count into sub-directories -* @param $count int (optional) - Initial value of file (or subdirs) count -* @return int - Count of files (or count of subdirectories) -* @author jasmineaura -*/ -function directory_num_files($dir, $subdirs = false, $recurse = false, $count = 0) -{ - if (is_dir($dir)) - { - if($handle = opendir($dir)) - { - while (($file = readdir($handle)) !== false) - { - if ($file == '.' || $file == '..') - { - continue; - } - else if (is_dir($dir."/".$file)) - { - if ($subdirs) - { - $count++; - } - else if ($recurse) - { - $count = directory_num_files($dir."/".$file, $subdirs, $recurse, $count); - } - } - else if (!$subdirs) - { - $count++; - } - } - - closedir($handle); - } - } - - return $count; -} - -/** -* Check if a directory is empty. -* -* @param $dir, string - directory to check -* @return bool, true if directory is empty. -*/ -function check_empty_dir($dir) -{ - if (!is_dir($dir) || !is_readable($dir)) - { - return(false); - } - - if(!$handle = opendir($dir)) - { - return(false); - } - - while (($file = readdir($handle)) !== false) - { - if ($file == '.' || $file == '..') - { - continue; - } - - // If we get here the directory is not empty - closedir($handle); - return(false); - } - - // The directory is empty - closedir($handle); - return(true); -} - -?> diff --git a/includes/library/automod/mod_parser.php b/includes/library/automod/mod_parser.php deleted file mode 100644 index 377f9a70e..000000000 --- a/includes/library/automod/mod_parser.php +++ /dev/null @@ -1,855 +0,0 @@ -parser = new parser_xml(); - break; - default: - } - } - - function set_file($file) - { - $this->parser->set_file($file); - } - - function get_details() - { - return $this->parser->get_details(); - } - - function get_actions() - { - return $this->parser->get_actions(); - } - - function get_modx_version() - { - if (!$this->parser->modx_version) - { - $this->get_details(); - } - - return $this->parser->modx_version; - } - - /** - * Returns the needed sql query to reverse the actions taken by the given query - * @todo: Add more - */ - function reverse_query($orig_query) - { - if (preg_match('#ALTER TABLE\s([a-z_]+)\sADD(?:\sCOLUMN)?\s([a-z_]+)#i', $orig_query, $matches)) - { - return "ALTER TABLE {$matches[1]} DROP COLUMN {$matches[2]};"; - } - else if (preg_match('#CREATE TABLE\s([a-z_]+)#i', $orig_query, $matches)) - { - return "DROP TABLE {$matches[1]};"; - } - - return false; - } - - /** - * Parse sql - * - * @param array $sql_query - */ - function parse_sql(&$sql_query) - { - global $dbms, $table_prefix; - - if (!function_exists('get_available_dbms')) - { - global $phpbb_root_path, $phpEx; - - include($phpbb_root_path . 'includes/functions_install.' . $phpEx); - } - - static $available_dbms; - - if (!isset($available_dbms)) - { - $available_dbms = get_available_dbms($dbms); - } - - $remove_remarks = $available_dbms[$dbms]['COMMENTS']; - $delimiter = $available_dbms[$dbms]['DELIM']; - - if (sizeof($sql_query) == 1) - { - // do some splitting here - $sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query); - $remove_remarks($sql_query[0]); - $sql_query = split_sql_file($sql_query[0], $delimiter); - } - else - { - $query_count = sizeof($sql_query); - for ($i = 0; $i < $query_count; $i++) - { - $sql_query[$i] = preg_replace('#phpbb_#i', $table_prefix, $sql_query[$i]); - $remove_remarks($sql_query[$i]); - } - } - - //return $sql_query; - } - - /** - * Returns the edits array, but now filled with edits to reverse the given array - * @todo: Add more - */ - function reverse_edits($actions) - { - $reverse_edits = array(); - - if (!empty($actions['EDITS'])) - { - foreach ($actions['EDITS'] as $file => $edit_ary) - { - foreach ($edit_ary as $edit_id => $edit) - { - foreach ($edit as $find => $action_ary) - { - foreach ($action_ary as $type => $command) - { - // it is possible for a single edit in the install process - // to become more than one in the uninstall process - while (isset($reverse_edits['EDITS'][$file][$edit_id])) - { - $edit_id++; - } - - switch (strtoupper($type)) - { - // for before and after adds, we use the find as a tool for more precise finds - // this isn't perfect, but it seems better than having - // finds of only a couple characters, like "/*" - case 'AFTER ADD': - $total_find = rtrim($find, "\n") . "\n" . trim($command, "\n"); - - $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find; - break; - - case 'BEFORE ADD': - $total_find = rtrim($command, "\n") . "\n" . trim($find, "\n"); - - // replace with the find - $reverse_edits['EDITS'][$file][$edit_id][$total_find]['replace with'] = $find; - break; - - case 'REPLACE WITH': - case 'REPLACE, WITH': - case 'REPLACE-WITH': - case 'REPLACE': - // replace $command (new code) with $find (original code) - $reverse_edits['EDITS'][$file][$edit_id][$command]['replace with'] = $find; - break; - - case 'IN-LINE-EDIT': - // build the reverse just like the normal action - foreach ($command as $action_id => $inline_edit) - { - foreach ($inline_edit as $inline_find => $inline_action_ary) - { - foreach ($inline_action_ary as $inline_action => $inline_command) - { - $inline_command = $inline_command[0]; - - switch (strtoupper($inline_action)) - { - case 'IN-LINE-AFTER-ADD': - case 'IN-LINE-BEFORE-ADD': - // Replace with a blank string - $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command]['in-line-replace'][] = ''; - break; - - case 'IN-LINE-REPLACE': - // replace with the inline find - $reverse_edits['EDITS'][$file][$edit_id][$find]['in-line-edit'][$action_id][$inline_command][$inline_action][] = $inline_find; - break; - - default: - // For the moment, we do nothing. What about increment? - break; - } - - $action_id++; - } - } - } - break; - - default: - // again, increment - break; - } - } - } - } - } - } - - if (!empty($actions['NEW_FILES'])) - { - foreach ($actions['NEW_FILES'] as $source => $target) - { - $reverse_edits['DELETE_FILES'][$source] = $target; - } - } - - if (empty($actions['SQL'])) - { - return $reverse_edits; - } - - if (sizeof($actions['SQL']) == 1) - { - $actions['SQL'] = explode("\n", $actions['SQL'][0]); - } - - foreach ($actions['SQL'] as $query) - { - $reverse_edits['SQL'][] = parser::reverse_query($query); - } - - return $reverse_edits; - } -} - -/** -* XML parser -* @package automod -*/ -class parser_xml -{ - var $data; - var $file; - var $modx_version; - - /** - * set data to read from - */ - function set_file($file) - { - // Shouldn't ever happen since the master class reads file names from - // the file system and lists them - if (!file_exists($file)) - { - trigger_error('Cannot locate File: ' . $file); - } - - $this->file = $file; - $this->data = trim(@file_get_contents($file)); - $this->data = str_replace(array("\r\n", "\r"), "\n", $this->data); - - $XML = new xml_array(); - $this->data = $XML->parse($this->file, $this->data); - - return; - } - - /** - * return array of the basic MOD details - */ - function get_details() - { - global $user; - - if (empty($this->data)) - { - $this->set_file($this->file); - } - - $header = array( - 'MOD-VERSION' => array(0 => array('children' => array())), - 'INSTALLATION' => array(0 => array('children' => array('TARGET-VERSION' => array(0 => array('data' => ''))))), - 'AUTHOR-GROUP' => array(0 => array('children' => array('AUTHOR' => array()))), - 'HISTORY' => array(0 => array('children' => array('ENTRY' => array()))), - ); - - $version = $phpbb_version = ''; - - $header = $this->data[0]['children']['HEADER'][0]['children']; - - // get MOD version information - // This is also our first opportunity to differentiate MODX 1.0.x from - // MODX 1.2.0. - if (isset($header['MOD-VERSION'][0]['children'])) - { - $this->modx_version = 1.0; - - $version_info = $header['MOD-VERSION'][0]['children']; - $version = (isset($version_info['MAJOR'][0]['data'])) ? trim($version_info['MAJOR'][0]['data']) : 0; - $version .= '.' . ((isset($version_info['MINOR'][0]['data'])) ? trim($version_info['MINOR'][0]['data']) : 0); - $version .= '.' . ((isset($version_info['REVISION'][0]['data'])) ? trim($version_info['REVISION'][0]['data']) : 0); - $version .= (isset($version_info['RELEASE'][0]['data'])) ? trim($version_info['RELEASE'][0]['data']) : ''; - } - else - { - $this->modx_version = 1.2; - - $version = trim($header['MOD-VERSION'][0]['data']); - } - - // get phpBB version recommendation - switch ($this->modx_version) - { - case 1.0: - if (isset($header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['children'])) - { - $version_info = $header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['children']; - - $phpbb_version = (isset($version_info['MAJOR'][0]['data'])) ? trim($version_info['MAJOR'][0]['data']) : 0; - $phpbb_version .= '.' . ((isset($version_info['MINOR'][0]['data'])) ? trim($version_info['MINOR'][0]['data']) : 0); - $phpbb_version .= '.' . ((isset($version_info['REVISION'][0]['data'])) ? trim($version_info['REVISION'][0]['data']) : 0); - $phpbb_version .= (isset($version_info['RELEASE'][0]['data'])) ? trim($version_info['RELEASE'][0]['data']) : ''; - } - break; - - case 1.2: - default: - $phpbb_version = (isset($header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['data'])) ? $header['INSTALLATION'][0]['children']['TARGET-VERSION'][0]['data'] : 0; - break; - } - - $author_info = $header['AUTHOR-GROUP'][0]['children']['AUTHOR']; - - $author_details = array(); - for ($i = 0; $i < sizeof($author_info); $i++) - { - $author_details[] = array( - 'AUTHOR_NAME' => isset($author_info[$i]['children']['USERNAME'][0]['data']) ? trim($author_info[$i]['children']['USERNAME'][0]['data']) : '', - 'AUTHOR_EMAIL' => isset($author_info[$i]['children']['EMAIL'][0]['data']) ? trim($author_info[$i]['children']['EMAIL'][0]['data']) : '', - 'AUTHOR_REALNAME' => isset($author_info[$i]['children']['REALNAME'][0]['data']) ? trim($author_info[$i]['children']['REALNAME'][0]['data']) : '', - 'AUTHOR_WEBSITE' => isset($author_info[$i]['children']['HOMEPAGE'][0]['data']) ? trim($author_info[$i]['children']['HOMEPAGE'][0]['data']) : '', - ); - } - - // history - $history_info = (!empty($header['HISTORY'][0]['children']['ENTRY'])) ? $header['HISTORY'][0]['children']['ENTRY'] : array(); - $history_size = sizeof($history_info); - - $mod_history = array(); - for ($i = 0; $i < $history_size; $i++) - { - $changes = array(); - $entry = $history_info[$i]['children']; - $changelog = isset($entry['CHANGELOG']) ? $entry['CHANGELOG'] : array(); - $changelog_size = sizeof($changelog); - $changelog_id = 0; - - for ($j = 0; $j < $changelog_size; $j++) - { - // Ignore changelogs in foreign languages except in the case that there is no - // match for the current user's language - // TODO: Look at modifying localise_tags() for use here. - if (match_language($user->data['user_lang'], $changelog[$j]['attrs']['LANG'])) - { - $changelog_id = $j; - } - } - - $change_count = isset($changelog[$changelog_id]['children']['CHANGE']) ? sizeof($changelog[$changelog_id]['children']['CHANGE']) : 0; - for ($j = 0; $j < $change_count; $j++) - { - $changes[] = $changelog[$changelog_id]['children']['CHANGE'][$j]['data']; - } - - switch ($this->modx_version) - { - case 1.0: - $changelog_version_ary = (isset($entry['REV-VERSION'][0]['children'])) ? $entry['REV-VERSION'][0]['children'] : array(); - - $changelog_version = (isset($changelog_version_ary['MAJOR'][0]['data'])) ? trim($changelog_version_ary['MAJOR'][0]['data']) : 0; - $changelog_version .= '.' . ((isset($changelog_version_ary['MINOR'][0]['data'])) ? trim($changelog_version_ary['MINOR'][0]['data']) : 0); - $changelog_version .= '.' . ((isset($changelog_version_ary['REVISION'][0]['data'])) ? trim($changelog_version_ary['REVISION'][0]['data']) : 0); - $changelog_version .= (isset($changelog_version_ary['RELEASE'][0]['data'])) ? trim($changelog_version_ary['RELEASE'][0]['data']) : ''; - break; - - case 1.2: - default: - $changelog_version = (isset($entry['REV-VERSION'][0]['data'])) ? $entry['REV-VERSION'][0]['data'] : '0.0.0'; - break; - } - - $mod_history[] = array( - 'DATE' => $entry['DATE'][0]['data'], - 'VERSION' => $changelog_version, - 'CHANGES' => $changes, - ); - } - - $children = array(); - - // Parse links - if ($this->modx_version == 1.2) - { - $link_group = (isset($header['LINK-GROUP'][0]['children'])) ? $header['LINK-GROUP'][0]['children'] : array(); - - if (isset($link_group['LINK'])) - { - for ($i = 0, $size = sizeof($link_group['LINK']); $i <= $size; $i++) - { - // do some stuff with attrs - // commented out due to a possible PHP bug. When using this, - // sizeof($link_group) changed each time ... - // $attrs = &$link_group[$i]['attrs']; - - if (!isset($link_group['LINK'][$i])) - { - continue; - } - - if ($link_group['LINK'][$i]['attrs']['TYPE'] == 'text') - { - continue; - } - - $children[$link_group['LINK'][$i]['attrs']['TYPE']][] = array( - 'href' => $link_group['LINK'][$i]['attrs']['HREF'], - 'realname' => isset($link_group['LINK'][$i]['attrs']['REALNAME']) ? $link_group['LINK'][$i]['attrs']['REALNAME'] : core_basename($link_group['LINK'][$i]['attrs']['HREF']), - 'title' => localise_tags($link_group, 'LINK', $i), - 'lang' => $link_group['LINK'][$i]['attrs']['LANG'], - ); - } - } - } - - // try not to hardcode schema? - $details = array( - 'MOD_PATH' => $this->file, - 'MOD_NAME' => get_title($header), -// 'MOD_NAME' => localise_tags($header, 'TITLE'), - 'MOD_DESCRIPTION' => nl2br(localise_tags($header, 'DESCRIPTION')), - 'MOD_VERSION' => htmlspecialchars(trim($version)), -// 'MOD_DEPENDENCIES' => (isset($header['TITLE'][0]['data'])) ? htmlspecialchars(trim($header['TITLE'][0]['data'])) : '', - - 'INSTALLATION_LEVEL' => (isset($header['INSTALLATION'][0]['children']['LEVEL'][0]['data'])) ? $header['INSTALLATION'][0]['children']['LEVEL'][0]['data'] : 0, - 'INSTALLATION_TIME' => (isset($header['INSTALLATION'][0]['children']['TIME'][0]['data'])) ? $header['INSTALLATION'][0]['children']['TIME'][0]['data'] : 0, - - 'AUTHOR_DETAILS' => $author_details, - 'AUTHOR_NOTES' => nl2br(localise_tags($header, 'AUTHOR-NOTES')), - 'MOD_HISTORY' => $mod_history, - 'PHPBB_VERSION' => $phpbb_version, - 'CHILDREN' => $children, - ); - - return $details; - } - - /** - * returns complex array containing all mod actions - */ - function get_actions() - { - global $db, $user; - - $actions = array(); - - $xml_actions = $this->data[0]['children']['ACTION-GROUP'][0]['children']; - - // sql - $actions['SQL'] = array(); - $sql_info = (!empty($xml_actions['SQL'])) ? $xml_actions['SQL'] : array(); - - $match_dbms = array(); - switch ($db->get_sql_layer()) - { - case 'firebird': - case 'oracle': - case 'postgres': - case 'sqlite': - case 'mssql': - case 'db2': - $match_dbms = array($db->sql_layer); - break; - - case 'mssql_odbc': - $match_dbms = array('mssql'); - break; - - // and now for the MySQL fun - // This will generate an array of things we can probably use, but - // will not have any priority - case 'mysqli': - $match_dbms = array('mysql_41', 'mysqli', 'mysql'); - break; - - case 'mysql4': - case 'mysql': - if (version_compare($db->sql_server_info(true), '4.1.3', '>=')) - { - $match_dbms = array('mysql_41', 'mysql4', 'mysql', 'mysqli'); - } - else if (version_compare($db->sql_server_info(true), '4.0.0', '>=')) - { - $match_dbms = array('mysql_40', 'mysql4', 'mysql', 'mysqli'); - } - else - { - $match_dbms = array('mysql'); - } - break; - - // Should never happen - default: - break; - } - - for ($i = 0; $i < sizeof($sql_info); $i++) - { - if ($this->modx_version == 1.0) - { - $actions['SQL'][] = (!empty($sql_info[$i]['data'])) ? trim($sql_info[$i]['data']) : ''; - } - else if ($this->modx_version == 1.2) - { - // Make a slightly shorter name. - $xml_dbms = &$sql_info[$i]['attrs']['DBMS']; - - if (!isset($sql_info[$i]['attrs']['DBMS']) || in_array($xml_dbms, $match_dbms)) - { - $actions['SQL'][] = (!empty($sql_info[$i]['data'])) ? trim($sql_info[$i]['data']) : ''; - } - else - { - // NOTE: skipped SQL is not currently useful - $sql_skipped = true; - } - } - } - - // new files - $new_files_info = (!empty($xml_actions['COPY'])) ? $xml_actions['COPY'] : array(); - for ($i = 0; $i < sizeof($new_files_info); $i++) - { - $new_files = $new_files_info[$i]['children']['FILE']; - for ($j = 0; $j < sizeof($new_files); $j++) - { - $from = str_replace('\\', '/', $new_files[$j]['attrs']['FROM']); - $to = str_replace('\\', '/', $new_files[$j]['attrs']['TO']); - $actions['NEW_FILES'][$from] = $to; - } - } - - $delete_files_info = (!empty($xml_actions['DELETE'])) ? $xml_actions['DELETE'] : array(); - for ($i = 0; $i < sizeof($delete_files_info); $i++) - { - $delete_files = $delete_files_info[$i]['children']['FILE']; - for ($j = 0; $j < sizeof($delete_files); $j++) - { - $name = str_replace('\\', '/', $delete_files[$j]['attrs']['NAME']); - $actions['DELETE_FILES'][] = $name; - } - } - - // open - $open_info = (!empty($xml_actions['OPEN'])) ? $xml_actions['OPEN'] : array(); - for ($i = 0; $i < sizeof($open_info); $i++) - { - $current_file = str_replace('\\', '/', trim($open_info[$i]['attrs']['SRC'])); - $actions['EDITS'][$current_file] = array(); - - $edit_info = (!empty($open_info[$i]['children']['EDIT'])) ? $open_info[$i]['children']['EDIT'] : array(); - // find, after add, before add, replace with - for ($j = 0; $j < sizeof($edit_info); $j++) - { - $action_info = (!empty($edit_info[$j]['children'])) ? $edit_info[$j]['children'] : array(); - - // store some array information to help decide what kind of operation we're doing - $action_count = $total_action_count = $remove_count = $find_count = 0; - if (isset($action_info['ACTION'])) - { - $action_count += sizeof($action_info['ACTION']); - } - - if (isset($action_info['INLINE-EDIT'])) - { - $total_action_count += sizeof($action_info['INLINE-EDIT']); - } - - if (isset($action_info['REMOVE'])) - { - $remove_count = sizeof($action_info['REMOVE']); // should be an integer bounded between zero and one - } - - if (isset($action_info['FIND'])) - { - $find_count = sizeof($action_info['FIND']); - } - - // the basic idea is to transform a "remove" tag into a replace-with action - if ($remove_count && !$find_count) - { - // but we still support it if $remove_count is > 1 - for ($k = 0; $k < $remove_count; $k++) - { - // if there is no find tag associated, handle it directly - $actions['EDITS'][$current_file][$j][trim($action_info['REMOVE'][$k]['data'], "\n\r")]['replace with'] = ''; - } - } - else if ($remove_count && $find_count) - { - // if there is a find and a remove, transform into a replace-with - // action, and let the logic below sort out the relationships. - for ($k = 0; $k < $remove_count; $k++) - { - $insert_index = (isset($action_info['ACTION'])) ? sizeof($action_info['ACTION']) : 0; - - $action_info['ACTION'][$insert_index] = array( - 'data' => '', - 'attrs' => array('TYPE' => 'replace with'), - ); - } - } - else if (!$find_count) - { - trigger_error(sprintf($user->lang['INVALID_MOD_NO_FIND'], htmlspecialchars($action_info['ACTION'][0]['data'])), E_USER_WARNING); - } - - // first we try all the possibilities for a FIND/ACTION combo, then look at inline possibilities. - - if (isset($action_info['ACTION'])) - { - for ($k = 0; $k < $find_count; $k++) - { - // is this anything but the last iteration of the loop? - if ($k < ($find_count - 1)) - { - // NULL has special meaning for an action ... no action to be taken; advance pointer - $actions['EDITS'][$current_file][$j][$action_info['FIND'][$k]['data']] = NULL; - } - else - { - // this is the last iteration, assign the action tags - - for ($l = 0; $l < $action_count; $l++) - { - $type = str_replace('-', ' ', $action_info['ACTION'][$l]['attrs']['TYPE']); - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$k]['data'], "\n\r")][$type] = (isset($action_info['ACTION'][$l]['data'])) ? preg_replace("#^(\s)+\n#", '', rtrim(trim($action_info['ACTION'][$l]['data'], "\n"))) : ''; - } - } - } - } - else - { - if (!$remove_count && !$total_action_count) - { - trigger_error(sprintf($user->lang['INVALID_MOD_NO_ACTION'], htmlspecialchars($action_info['FIND'][0]['data'])), E_USER_WARNING); - } - } - - // add comment to the actions array - $actions['EDITS'][$current_file][$j]['comment'] = localise_tags($action_info, 'COMMENT'); - - // inline - if (isset($action_info['INLINE-EDIT'])) - { - $inline_info = (!empty($action_info['INLINE-EDIT'])) ? $action_info['INLINE-EDIT'] : array(); - - if (isset($inline_info[0]['children']['INLINE-REMOVE']) && sizeof($inline_info[0]['children']['INLINE-REMOVE'])) - { - // overwrite the existing array with the new one - $inline_info[0]['children'] = array( - 'INLINE-FIND' => $inline_info[0]['children']['INLINE-REMOVE'], - 'INLINE-ACTION' => array( - 0 => array( - 'attrs' => array('TYPE' => 'replace-with'), - 'data' => '', - ), - ), - ); - } - if ($find_count > $total_action_count) - { - // Yeah, $k is used more than once for different information - for ($k = 0; $k < $find_count; $k++) - { - // is this anything but the last iteration of the loop? - if ($k < ($find_count - 1)) - { - // NULL has special meaning for an action ... no action to be taken; advance pointer - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$k]['data'], "\r\n")] = NULL; - } - } - } - - /* - * This loop attaches the in-line information to the _last - * find_ in the tag. This is the intended behavior - * Any additional finds ought to be in a different edit tag - */ - for ($k = 0; $k < sizeof($inline_info); $k++) - { - $inline_data = (!empty($inline_info[$k]['children'])) ? $inline_info[$k]['children'] : array(); - - $inline_find_count = (isset($inline_data['INLINE-FIND'])) ? sizeof($inline_data['INLINE-FIND']) : 0; - - $inline_comment = localise_tags($inline_data, 'INLINE-COMMENT'); - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit']['inline-comment'] = $inline_comment; - - $inline_actions = (!empty($inline_data['INLINE-ACTION'])) ? $inline_data['INLINE-ACTION'] : array(); - - if (empty($inline_actions)) - { - trigger_error(sprintf($user->lang['INVALID_MOD_NO_ACTION'], htmlspecialchars($inline_data['INLINE-FIND'][0]['data'])), E_USER_WARNING); - } - if (empty($inline_find_count)) - { - trigger_error(sprintf($user->lang['INVALID_MOD_NO_FIND'], htmlspecialchars($inline_actions[0]['data'])), E_USER_WARNING); - } - - for ($l = 0; $l < $inline_find_count; $l++) - { - $inline_find = $inline_data['INLINE-FIND'][$l]['data']; - - // trying to reduce the levels of arrays without impairing features. - // need to keep the "full" edit intact. - // - // inline actions must be trimmed in case the MOD author - // inserts a new line by mistake - if ($l < ($inline_find_count - 1)) - { - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-'][] = null; - } - else - { - for ($m = 0; $m < sizeof($inline_actions); $m++) - { - $type = str_replace(',', '-', str_replace(' ', '', $inline_actions[$m]['attrs']['TYPE'])); - if (!empty($inline_actions[$m]['data'])) - { - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-' . $type][] = trim($inline_actions[$m]['data'], "\n"); - } - else - { - $actions['EDITS'][$current_file][$j][trim($action_info['FIND'][$find_count - 1]['data'], "\r\n")]['in-line-edit'][$k][$inline_find]['in-line-' . $type][] = ''; - } - } - } - } - } - } - } - } - - if (!empty($xml_actions['PHP-INSTALLER'])) - { - $actions['PHP_INSTALLER'] = $xml_actions['PHP-INSTALLER'][0]['data']; - } - - if (!empty($xml_actions['DIY-INSTRUCTIONS'])) - { - $actions['DIY_INSTRUCTIONS'] = localise_tags($xml_actions, 'DIY-INSTRUCTIONS'); - } - - return $actions; - } -} - -/** -* XML processing -* @package automod -*/ -class xml_array -{ - var $output = array(); - var $parser; - var $XML; - - function parse($file, $XML) - { - $this->parser = xml_parser_create(); - xml_set_object($this->parser, $this); - xml_set_element_handler($this->parser, "tag_open", "tag_closed"); - xml_set_character_data_handler($this->parser, "tag_data"); - - $this->XML = xml_parse($this->parser, $XML); - if (!$this->XML) - { - die(sprintf("XML error: %s at line %d. View the file %s in a web browser for a more detailed error message.", - xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser), $file)); - } - - xml_parser_free($this->parser); - - return $this->output; - } - - function tag_open($parser, $name, $attrs) - { - $tag = array("name" => $name, "attrs" => $attrs); - array_push($this->output, $tag); - } - - function tag_data($parser, $tag_data) - { - // Should be a string but' let's make sure. - $tag_data = (string) $tag_data; - - if ($tag_data !== '') - { - if (isset($this->output[sizeof($this->output) - 1]['data'])) - { - $this->output[sizeof($this->output) - 1]['data'] .= $tag_data; - } - else - { - $this->output[sizeof($this->output) - 1]['data'] = $tag_data; - } - } - } - - function tag_closed($parser, $name) - { - $this->output[sizeof($this->output) - 2]['children'][$name][] = $this->output[sizeof($this->output) - 1]; - array_pop($this->output); - } -} - -?> diff --git a/includes/objects/queue.php b/includes/objects/queue.php index 04e4020eb..89241ea22 100644 --- a/includes/objects/queue.php +++ b/includes/objects/queue.php @@ -212,12 +212,6 @@ public function update_first_queue_post($post_subject = false) $post->post_text .= '[quote="' . phpbb::$user->lang['VALIDATION_TV'] . '"][code]' . $this->tv_results . "[/code][/quote]\n"; } - // Add the Automod results - if ($this->automod_results) - { - $post->post_text .= '[quote="' . phpbb::$user->lang['VALIDATION_AUTOMOD'] . '"]' . $this->automod_results . "[/quote]\n"; - } - // Prevent errors from different configurations phpbb::$config['min_post_chars'] = 1; phpbb::$config['max_post_chars'] = 0; @@ -688,7 +682,7 @@ public function get_url($action = false, $params = array(), $tag = false) } } - else + else { // Link back to the correct type if the tag is shown $type_name = array_key_first($tag); diff --git a/includes/objects/revision.php b/includes/objects/revision.php index 3f03256d9..ca80bee86 100644 --- a/includes/objects/revision.php +++ b/includes/objects/revision.php @@ -516,7 +516,7 @@ public function repack($old_revision, $old_queue) throw new exception('Old queue missing. Revision ID: ' . $old_revision->revision_id); } - // Reply to the queue topic to say that it's been repacked and have the old mpv/automod results listed in it as well + // Reply to the queue topic to say that it's been repacked $repack_message = phpbb::$user->lang['REVISION_REPACKED'] . "\n\n"; // Add the MPV results @@ -526,12 +526,6 @@ public function repack($old_revision, $old_queue) $repack_message .= '[quote="' . $this->user->lang['VALIDATION_PV'] . '"]' . $queue->mpv_results . "[/quote]\n"; } - // Add the Automod results - if ($queue->automod_results) - { - $repack_message .= '[quote="' . phpbb::$user->lang['VALIDATION_AUTOMOD'] . '"]' . $queue->automod_results . "[/quote]\n"; - } - // Repack diff titania::_include('tools/diff', false, 'titania_diff'); diff --git a/includes/overlords/queue.php b/includes/overlords/queue.php index 7002681f1..c25ba59e4 100644 --- a/includes/overlords/queue.php +++ b/includes/overlords/queue.php @@ -286,21 +286,11 @@ public static function display_queue_item($queue_id) // Misc actions $misc_actions = array( - array( - 'RETEST_PV', - $queue->get_tool_url('mpv', $row['revision_id'], $hash), - $contrib->type->mpv_test, - ), array( 'RETEST_PV', $queue->get_tool_url('epv', $row['revision_id'], $hash), $contrib->type->epv_test, ), - array( - 'RETEST_AUTOMOD', - $queue->get_tool_url('automod', $row['revision_id'], $hash), - $contrib->type->automod_test, - ), ); // Some quick-actions diff --git a/language/en/automod.php b/language/en/automod.php deleted file mode 100644 index 3f7287e5b..000000000 --- a/language/en/automod.php +++ /dev/null @@ -1,222 +0,0 @@ - 'Available Changes', - 'AM_MANUAL_INSTRUCTIONS' => 'AutoMOD is sending a compressed file to your computer. Because of the AutoMOD configuration, files cannot be written to your site automatically. You will need to extract the file and upload the files to your server manually, using an FTP client or similar method. If you did not receive this file automatically, click %shere%s.', - 'AM_MOD_ALREADY_INSTALLED' => 'AutoMOD has detected this MOD is already installed and cannot proceed.', - 'APPLY_TEMPLATESET' => 'to this template', - 'APPLY_THESE_CHANGES' => 'Apply these changes', - 'AUTHOR_EMAIL' => 'Author Email', - 'AUTHOR_INFORMATION' => 'Author Information', - 'AUTHOR_NAME' => 'Author Name', - 'AUTHOR_NOTES' => 'Author Notes', - 'AUTHOR_URL' => 'Author URL', - 'AUTOMOD' => 'AutoMOD', - 'AUTOMOD_CANNOT_INSTALL_OLD_VERSION' => 'The version of AutoMOD you are trying to install has already been installed. Please delete this install/ directory.', - 'AUTOMOD_INSTALLATION' => 'AutoMOD Installation', - 'AUTOMOD_INSTALLATION_EXPLAIN' => 'Welcome to the AutoMOD Installation. You will need your FTP details if AutoMOD detects that is the best way to write files. The requirements test results are below.', - 'AUTOMOD_UNKNOWN_VERSION' => 'AutoMOD was not able to update because it could not determine the version currently installed. The version listed for your installation is %s.', - 'AUTOMOD_VERSION' => 'AutoMOD Version', - - 'CAT_INSTALL_AUTOMOD' => 'AutoMOD', - 'CHANGES' => 'Changes', - 'CHANGE_DATE' => 'Release Date', - 'CHANGE_VERSION' => 'Version Number', - 'CHECK_AGAIN' => 'Check again', - 'COMMENT' => 'Comment', - 'CREATE_TABLE' => 'Database Alterations', - 'CREATE_TABLE_EXPLAIN' => 'AutoMOD has successfully made its database alterations, including a permission which has been assigned to the “Full Administrator” role.', - - 'DELETE' => 'Delete', - 'DELETE_CONFIRM' => 'Are you sure you want to delete this MOD?', - 'DELETE_ERROR' => 'There was an error deleting the selected MOD.', - 'DELETE_SUCCESS' => 'MOD has been successfully deleted.', - 'DEPENDENCY_INSTRUCTIONS' => 'The MOD you are trying to install depends on another MOD. AutoMOD cannot detect if this MOD has been installed. Please verify that you have installed %2$s before installing your MOD.', - 'DESCRIPTION' => 'Description', - 'DETAILS' => 'Details', - 'DIR_PERMS' => 'Directory Permissions', - 'DIR_PERMS_EXPLAIN' => 'Some systems require directories to have certain permissions to work properly. Normally the default 0755 is correct. This setting has no impact on Windows systems.', - 'DIY_INSTRUCTIONS' => 'Do It Yourself Instructions', - - 'EDITED_ROOT_CREATE_FAIL' => 'AutoMOD was unable to create the directory where the edited files will be stored.', - 'ERROR' => 'Error', - - 'FILESYSTEM_NOT_WRITABLE' => 'AutoMOD has determined the filesystem is not writable, so the direct write method cannot be used.', - 'FILE_EDITS' => 'File edits', - 'FILE_EMPTY' => 'File empty', - 'FILE_MISSING' => 'Cannot locate file', - 'FILE_PERMS' => 'File Permissions', - 'FILE_PERMS_EXPLAIN' => 'Some systems require files to have certain permissions to work properly. Normally the default 0644 is correct. This setting has no impact on Windows systems.', - 'FILE_TYPE' => 'Compressed File Type', - 'FILE_TYPE_EXPLAIN' => 'This is only valid with the “Compressed File Download” write method', - 'FIND' => 'Find', - 'FIND_MISSING' => 'The Find specified by the MOD could not be found', - 'FORCE_CONFIRM' => 'The Force Install feature means the MOD is not fully installed. You will need to make some manual fixes to your board to finish installation. Continue?', - 'FORCE_INSTALL' => 'Force Install', - 'FORCE_UNINSTALL' => 'Force Uninstall', - 'FTP_INFORMATION' => 'FTP Information', - 'FTP_METHOD_ERROR' => 'There is no FTP method found, please check under autoMOD configuration if there is set a correct FTP method.', - 'FTP_METHOD_EXPLAIN' => 'If you experience problems with the default "FTP", you may try "Simple Socket" as an alternate way to connect to the FTP server.', - 'FTP_METHOD_FSOCK' => 'Simple Socket', - 'FTP_METHOD_FTP' => 'FTP', - 'FTP_NOT_USABLE' => 'The FTP function can\'t be used as this has been disabled by your hosting.', - - 'GO_PHP_INSTALLER' => 'The MOD requires an external installer to finish installation. Click here to continue to that step.', - - 'INHERIT_NO_CHANGE' => 'No changes can be made to this file because the template %1$s depends on %2$s.', - 'INLINE_EDIT_ERROR' => 'Error, an inline edit in the MODX install file is missing all the required elements', - 'INLINE_FIND_MISSING' => 'The In-Line Find specified by the MOD could not be found.', - 'INSTALLATION_SUCCESSFUL' => 'AutoMOD installed successfully. You can now manage phpBB MODifications through the AutoMOD tab in the Administration Control Panel.', - 'INSTALLED' => 'MOD installed', - 'INSTALLED_EXPLAIN' => 'Your MOD has been installed! Here you can view some of the results from the installation. Please note any errors, and seek support at phpBB.com', - 'INSTALLED_MODS' => 'Installed MODs', - 'INSTALL_AUTOMOD' => 'AutoMOD Installation', - 'INSTALL_AUTOMOD_CONFIRM' => 'Are you sure you want to install AutoMOD?', - 'INSTALL_ERROR' => 'One or more install actions failed. Please review the actions below, make any adjustments and retry. You may continue with the installation even though some of the actions failed. This is not recommended and may cause your board to not function correctly.', - 'INSTALL_FORCED' => 'You forced the installation of this MOD even though there were errors installing the MOD. Your board may be broken. Please note the actions that failed below and correct them.', - 'INSTALL_MOD' => 'Install this MOD', - 'INSTALL_TIME' => 'Installation time', - 'INVALID_MOD_INSTRUCTION' => 'This MOD has an invalid instruction, or an in-line find operation failed.', - 'INVALID_MOD_NO_ACTION' => 'The MOD is missing an action matching the find ‘%s’', - 'INVALID_MOD_NO_FIND' => 'The MOD is missing a find matching the action ‘%s’', - - 'LANGUAGE_NAME' => 'Language Name', - - 'MANUAL_COPY' => 'Copy not attempted', - 'MODS_CONFIG_EXPLAIN' => 'You can select how AutoMOD adjusts your files here. The most basic method is Compressed File Download. The others require additional permissions on the server.', - 'MODS_COPY_FAILURE' => 'The file %s could not be copied into place. Please check your permissions or use an alternate write method.', - 'MODS_EXPLAIN' => 'Here you can manage the available MODs on your board. AutoMODs allows you to customize your board by automatically installing modifications produced by the phpBB community. For further information on MODs and AutoMOD please visit the phpBB website. To add a MOD to this list, use the form at the bottom of this page. Alternatively, you may unzip it and upload the files to the /store/mods/ directory on your server.', - 'MODS_FTP_CONNECT_FAILURE' => 'AutoMOD was unable to connect to your FTP server. The error was %s', - 'MODS_FTP_FAILURE' => 'AutoMOD could not FTP the file %s into place', - 'MODS_MKDIR_FAILED' => 'The directory %s could not be created', - 'MODS_SETUP_INCOMPLETE' => 'A problem was found with your configuration, and AutoMOD cannot operate. This should only occur when settings (e.g. FTP username) have changed, and can be corrected in the AutoMOD configuration page.', - 'MOD_CONFIG' => 'AutoMOD Configuration', - 'MOD_CONFIG_UPDATED' => 'AutoMOD configuration has been updated.', - 'MOD_DETAILS' => 'MOD Details', - 'MOD_DETAILS_EXPLAIN' => 'Here you can view all known information about the MOD you selected.', - 'MOD_MANAGER' => 'AutoMOD', - 'MOD_NAME' => 'MOD Name', - 'MOD_OPEN_FILE_FAIL' => 'AutoMOD was unable to open %s.', - 'MOD_UPLOAD' => 'Upload MOD', - 'MOD_UPLOAD_EXPLAIN' => 'Here you can upload a zipped MOD package containing the necessary MODX files to perform installation. AutoMOD will then attempt to unzip the file and have it ready for installation.', - 'MOD_UPLOAD_INIT_FAIL' => 'There was an error initialising the MOD upload process.', - 'MOD_UPLOAD_SUCCESS' => 'MOD uploaded and prepared for installation.', - - 'NAME' => 'Name', - 'NEW_FILES' => 'New Files', - 'NO_ATTEMPT' => 'Not Attempted', - 'NO_INSTALLED_MODS' => 'No installed MODs detected', - 'NO_MOD' => 'The selected MOD could not be found.', - 'NO_UNINSTALLED_MODS' => 'No uninstalled MODs detected', - 'NO_UPLOAD_FILE' => 'No file specified.', - - 'ORIGINAL' => 'Original', - - 'PATH' => 'Path', - 'PREVIEW_CHANGES' => 'Preview Changes', - 'PREVIEW_CHANGES_EXPLAIN' => 'Displays the changes to be performed before executing them.', - 'PRE_INSTALL' => 'Preparing to Install', - 'PRE_INSTALL_EXPLAIN' => 'Here you can preview all the modifications to be made to your board, before they are carried out. WARNING!, once accepted, your phpBB base files will be edited and database alterations may occur. However, if the install is unsuccessful, assuming you can access AutoMOD, you will be given the option to restore to this point.', - 'PRE_UNINSTALL' => 'Preparing to Uninstall', - 'PRE_UNINSTALL_EXPLAIN' => 'Here you can preview all the modifications to be made to your board, in order to uninstall the MOD. WARNING!, once accepted, your phpBB base files will be edited and database alterations may occur. Also, this process uses reversing techniques that may not be 100% accurate. However, if the uninstall is unsuccessful, assuming you can access AutoMOD, you will be given the option to restore to this point.', - - 'REMOVING_FILES' => 'Files to be removed', - 'RETRY' => 'Retry', - 'RETURN_MODS' => 'Return to AutoMOD', - 'REVERSE' => 'Reverse', - 'ROOT_IS_READABLE' => 'The phpBB root directory is readable.', - 'ROOT_NOT_READABLE' => 'AutoMOD was not able to open phpBB\'s index.php for reading. This probably means that permissions are too restrictive on your phpBB root directory, which will prevent AutoMOD from working. Please adjust your permissions and try the check again.', - - 'SOURCE' => 'Source', - 'SQL_QUERIES' => 'SQL Queries', - 'STATUS' => 'Status', - 'STORE_IS_WRITABLE' => 'The store/ directory is writable.', - 'STORE_NOT_WRITABLE' => 'The store/ directory is not writable.', - 'STORE_NOT_WRITABLE_INST' => 'AutoMOD installation has detected that the store/ directory is not writable. This is required for AutoMOD to work properly. Please adjust your permissions and try again.', - 'STYLE_NAME' => 'Style name', - 'SUCCESS' => 'Success', - - 'TARGET' => 'Target', - - 'UNINSTALL' => 'Uninstall', - 'UNINSTALLED' => 'MOD uninstalled', - 'UNINSTALLED_EXPLAIN' => 'Your MOD has been uninstalled! Here you can view some of the results from the uninstallation. Please note any errors, and seek support at phpBB.com.', - 'UNINSTALLED_MODS' => 'Uninstalled MODs', - 'UNINSTALL_AUTOMOD' => 'AutoMOD Uninstallation', - 'UNINSTALL_AUTOMOD_CONFIRM' => 'Are you sure you wish to uninstall AutoMOD? This will NOT remove any MODs which have been installed with AutoMOD.', - 'UNKNOWN_MOD_AUTHOR-NOTES' => 'No Author Notes were specified.', - 'UNKNOWN_MOD_COMMENT' => '', - 'UNKNOWN_MOD_DESCRIPTION' => '', - 'UNKNOWN_MOD_DIY-INSTRUCTIONS' => '', - 'UNKNOWN_MOD_INLINE-COMMENT' => '', - 'UNKNOWN_QUERY_REVERSE' => 'Unknown reverse query', - 'UNRECOGNISED_COMMAND' => 'Error, unrecognised command %s', - 'UPDATE_AUTOMOD' => 'Update AutoMOD', - 'UPDATE_AUTOMOD_CONFIRM' => 'Please confirm you want to update AutoMOD.', - 'UPLOAD' => 'Upload', - - 'VERSION' => 'Version', - - 'WRITE_DIRECT_FAIL' => 'AutoMOD could not copy the file %s into place using the direct method. Please use another write method and try again.', - 'WRITE_DIRECT_TOO_SHORT' => 'AutoMOD was unable to finish writing the file %s. This can often be solved with the Retry button. If this does not work, try another write method.', - 'WRITE_MANUAL_FAIL' => 'AutoMOD could not add the file %s to a compressed archive. Please try another write method.', - 'WRITE_METHOD' => 'Write Method', - 'WRITE_METHOD_DIRECT' => 'Direct', - 'WRITE_METHOD_EXPLAIN' => 'You can set a preferred method to write files. The most compatible option is “Compressed File Download”.', - 'WRITE_METHOD_FTP' => 'FTP', - 'WRITE_METHOD_MANUAL' => 'Compressed File Download', - - 'after add' => 'Add After', - - 'before add' => 'Add Before', - - 'find' => 'Find', - - 'in-line-after-add' => 'In-Line After, Add', - 'in-line-before-add' => 'In-Line Before, Add', - 'in-line-edit' => 'In-Line Find', - 'in-line-operation' => 'In-Line Increment', - 'in-line-replace' => 'In-Line Replace', - 'in-line-replace-with' => 'In-Line Replace', - - 'operation' => 'Increment', - - 'replace' => 'Replace With', - 'replace with' => 'Replace With', -)); diff --git a/language/en/contributions.php b/language/en/contributions.php index bda5c69c3..b704695d3 100644 --- a/language/en/contributions.php +++ b/language/en/contributions.php @@ -44,8 +44,6 @@ 'ATTENTION_CONTRIB_CATEGORIES_CHANGED' => 'Contribution categories changed', 'ATTENTION_CONTRIB_DESC_CHANGED' => 'Contribution description changed', 'ATTENTION_CONTRIB_NAME_CHANGED' => 'Contribution name changed', - 'AUTOMOD_RESULTS' => 'Please check over the AutoMod install results and make sure that nothing needs to be fixed.

If an error comes up and you are certain that the error is incorrect, just hit continue below.
', - 'AUTOMOD_TEST' => 'The Mod will be tested against AutoMod and results will be shown (this may take a few moments, so please be patient).

Please hit continue when you are ready.', 'BAD_VERSION_SELECTED' => '%s is not a proper phpBB version.', 'BRANCH_ALREADY_IN_QUEUE' => 'There is already a revision in the queue in the process of being validated for %s.', @@ -145,9 +143,6 @@ 'LOGIN_EXPLAIN_CONTRIB' => 'In order to create a new contribution you need to be registered', 'MANAGE_CONTRIBUTION' => 'Manage Contribution', - 'MPV_TEST' => 'The Mod will be tested against MPV and results will be shown (this may take a few moments, so please be patient).

Please hit continue when you are ready.', - 'MPV_TEST_FAILED' => 'Sorry, the automatic MPV test failed and your MPV test results are not available. Please continue.', - 'MPV_TEST_FAILED_QUEUE_MSG' => 'Automated MPV test failed. [url=%s]Click here to attempt running MPV automatically again[/url]', 'MUST_SELECT_ONE_VERSION' => 'You must select at least one phpBB version.', 'NEW_CONTRIBUTION' => 'New Contribution', diff --git a/language/en/manage.php b/language/en/manage.php index 2130158fb..7e83d4309 100644 --- a/language/en/manage.php +++ b/language/en/manage.php @@ -81,8 +81,6 @@ 'NO_NOTES' => 'No Notes', 'NO_QUEUE_ITEM' => 'Queue item does not exist.', - 'OLD_VALIDATION_AUTOMOD' => 'Automod Test from pre-repack', - 'OLD_VALIDATION_MPV' => 'MPV Notes from pre-repack', 'OPEN_ITEMS' => 'Open Items', 'PLEASE_WAIT_FOR_TOOL' => 'Please wait for the tool to finish running.', @@ -111,7 +109,6 @@ 'REBUILD_FIRST_POST' => 'Rebuild first post', 'REPACK' => 'Repack', 'REPORTED' => 'Reported', - 'RETEST_AUTOMOD' => 'Re-test Automod', 'RETEST_PV' => 'Re-test prevalidator', 'REVISION_REPACKED' => 'This revision has been repacked.', @@ -123,7 +120,6 @@ 'UNKNOWN' => 'Unknown', 'VALIDATION' => 'Validation', - 'VALIDATION_AUTOMOD' => 'Automod Test', 'VALIDATION_MESSAGE' => 'Validation Message/Reason', 'VALIDATION_NOTES' => 'Validation Notes', 'VALIDATION_PV' => 'Prevalidator Notes', diff --git a/language/en/types/mod.php b/language/en/types/mod.php index d61aa485e..ab1383f83 100644 --- a/language/en/types/mod.php +++ b/language/en/types/mod.php @@ -41,7 +41,6 @@ // $lang = array_merge($lang, array( - 'AUTOMOD_TEST' => 'AutoMOD Test', 'MODIFICATION' => 'Modification', 'MODIFICATIONS' => 'Modifications', 'MOD_CONTRIB_CLEANED' => 'Cleaned', @@ -129,6 +128,4 @@ Thank you, phpBB Extension Customisations Team', - - 'MPV_TEST' => 'MOD Prevalidator Test', )); diff --git a/styles/prosilver/template/contributions/automod.html b/styles/prosilver/template/contributions/automod.html deleted file mode 100644 index 848ab05c1..000000000 --- a/styles/prosilver/template/contributions/automod.html +++ /dev/null @@ -1,62 +0,0 @@ -

{{ PHPBB_VERSION }}

- -{% if S_AUTOMOD_SUCCESS %} - {{ lang('SUCCESS') }} -{% else %} - -
-{% if S_DISPLAY_FILE_EDITS %} - -

{{ lang('FILE_EDITS') }}

-{% for edit_files in loops.edit_files %} - {% if not edit_files.S_SUCCESS %} -
- {{ edit_files.FILENAME }} - - {% if edit_files.S_MISSING_FILE %} - {{ lang('FILE_MISSING') }} - {% elseif edit_files.INHERIT_MSG %} - {{ edit_files.INHERIT_MSG }} - {% endif %} - - {% for finds in edit_files.finds %} - {% if not finds.S_SUCCESS %} -
-

{{ lang('FIND') }}

-
{{ finds.FIND_STRING }}
- {% if finds.S_MISSING_FIND %} - {{ lang('FIND_MISSING') }} - {% endif %} - {% for actions in finds.actions %} -
-
-

{{ actions.NAME }}

-
{{ actions.COMMAND }}
- {% for inline in actions.inline %} -
-

{{ inline.NAME }}

-
{{ inline.COMMAND }}
- {% if not inline.S_SUCCESS %}{{ lang('INLINE_FIND_MISSING') }}{% endif %} - {% endfor %} - {% if actions.S_SUCCESS %}{{ lang('SUCCESS') }}{% else %}{{ lang('FIND_MISSING') }}{% endif %} -
- {% endfor %} -
- {% endif %} - {% endfor %} -
- {% endif %} -{% endfor %} - -{% endif %} -{% if S_DISPLAY_NEW_FILES %} -

{{ lang('NEW_FILES') }}

- -{% endif %} -
- -{% endif %} diff --git a/styles/prosilver/template/contributions/automod_bbcode.html b/styles/prosilver/template/contributions/automod_bbcode.html deleted file mode 100644 index 201b4efc0..000000000 --- a/styles/prosilver/template/contributions/automod_bbcode.html +++ /dev/null @@ -1,46 +0,0 @@ -[size=160][color=#115098]{{ PHPBB_VERSION }}[/color][/size] -{% if S_AUTOMOD_SUCCESS %} - [size=150][color=#00BF40]{{ lang('SUCCESS') }}[/color][/size] -{% else %} - {% if S_DISPLAY_FILE_EDITS %} - [size=150][color=#115098]{{ lang('FILE_EDITS') }}[/color][/size] - {% for edit_files in loops.edit_files %} - {% if not edit_files.S_SUCCESS %} - {{ edit_files.FILENAME }} - {% if edit_files.S_MISSING_FILE %} - [color=#115098][b]{{ lang('FILE_MISSING') }}[/b][/color] - {% elseif edit_files.INHERIT_MSG %} - [b]{{ edit_files.INHERIT_MSG }}[/b] - {% endif %} - {% for finds in edit_files.finds %} - {% if not finds.S_SUCCESS %} - [size=160]{{ lang('FIND') }}[/size] - [code]{{ finds.FIND_STRING }}[/code] - {% if finds.S_MISSING_FIND %} - [color=#115098]{{ lang('FIND_MISSING') }}[/color] - {% endif %} - {% for actions in finds.actions %} - [size=160]{{ actions.NAME }}[/size] - [code]{{ actions.COMMAND }}[/code] - {% for inline in actions.inline %} - [size=160]{{ inline.NAME }}[/size] - [code]{{ inline.COMMAND }}[/code] - {% if not inline.S_SUCCESS %}[color=#115098]{{ lang('INLINE_FIND_MISSING') }}[/color]{% endif %} - {% endfor %} - {% if actions.S_SUCCESS %}[color=#00BF40]{{ lang('SUCCESS') }}[/color]{% else %}[color=#115098]{{ lang('FIND_MISSING') }}[/color]{% endif %} - {% endfor %} - {% endif %} - {% endfor %} - {% endif %} - {% endfor %} - {% endif %} - {% if S_DISPLAY_NEW_FILES %} - [size=150][color=#115098]{{ lang('NEW_FILES') }}[/color][/size] - {% for new_files in loops.new_files %} - {% if not (new_files.S_SUCCESS or new_files.S_NO_COPY_ATTEMPT) %} - {{ new_files.SOURCE }} - [color=#115098][b]{{ lang('FILE_MISSING') }}[/b][/color] - {% endif %} - {% endfor %} - {% endif %} -{% endif %} diff --git a/styles/prosilver/template/contributions/contribution_revision.html b/styles/prosilver/template/contributions/contribution_revision.html index 8cfdd81b6..f0a786def 100644 --- a/styles/prosilver/template/contributions/contribution_revision.html +++ b/styles/prosilver/template/contributions/contribution_revision.html @@ -132,25 +132,12 @@

{{ lang('AGREEMENT') }}

{{ STEP_MESSAGE }} {% endif %} - {% if MPV_TEST_WARNING %} -

{{ lang('MPV_TEST') }} - {% endif %} {% if PV_RESULTS %}

{{ lang('PV_RESULTS') }}


{{ PV_RESULTS }}
- {% if S_AUTOMOD_TEST %} -

-
- {{ lang('AUTOMOD_TEST') }} - {% endif %} - {% endif %} - {% if AUTOMOD_RESULTS %} -

{{ lang('AUTOMOD_RESULTS') }}

-
- {{ AUTOMOD_RESULTS }} {% endif %} {% if S_PASSED_TRANSLATION_VALIDATION %}