<?xml version="1.0" encoding="utf-8"?>
<modification>
	<name>Modification Manager</name>
	<code>modification_manager</code>
	<version>3.0.4</version>
	<author>Opencart-templates</author>
	<link>http://www.opencart-templates.co.uk/modification-manager</link>

	<file path="admin/language/en-gb/marketplace/modification.php">
		<operation>
			<search index="0"><![CDATA[<?php]]></search>
			<add position="after"><![CDATA[
$_['tab_error'] = 'Error';
$_['tab_files'] = 'Files';

$_['text_add'] = 'Add Modification';
$_['text_edit'] = 'Edit Modification: %s';

$_['text_enabled'] = 'Enabled';
$_['text_disabled'] = 'Disabled';

$_['entry_author'] = 'Author';
$_['entry_name'] = 'Name';
$_['entry_xml'] = 'XML';

$_['button_filter'] = 'Filter';
$_['button_reset'] = 'Reset';
$_['button_download'] = 'Download';

$_['column_date_modified'] = 'Last Modified';

$_['error_warning'] = 'There has been an error. Please check your data and try again';
$_['error_required'] = 'This field is required';
$_['error_name'] = 'Missing name tag';
$_['error_code'] = 'Missing code tag';
$_['error_exists'] = 'Modification \'%s\' is already using the same code: %s!';]]></add>
		</operation>
	</file>

	<file path="admin/controller/marketplace/modification.php">
	    <operation>
			<search index="0"><![CDATA[public function index() {]]></search>
			<add position="after"><![CDATA[      	$this->load->model('extension/module/modification_manager');

		$this->model_extension_module_modification_manager->install();
]]></add>
		</operation>
	    <operation>
			<search><![CDATA[$this->model_setting_modification]]></search>
			<add position="before"><![CDATA[$this->load->model('extension/module/modification_manager');
]]></add>
		</operation>
	    <operation>
			<search><![CDATA[$this->model_setting_modification->]]></search>
			<add position="replace"><![CDATA[$this->model_extension_module_modification_manager->]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$sort = 'name';]]></search>
			<add position="replace"><![CDATA[$sort = 'date_modified';]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$order = 'ASC';]]></search>
			<add position="replace"><![CDATA[$order = 'DESC';]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$handle = fopen(DIR_LOGS . 'ocmod.log', 'w+');]]></search>
			<add position="before"><![CDATA[      	fclose($handle);
			
					$handle = fopen(DIR_LOGS . 'ocmod_error.log', 'w+');]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$maintenance = $this->config->get('config_maintenance');]]></search>
			<add position="after"><![CDATA[
			// Clear logs on refresh
			$handle = fopen(DIR_LOGS . 'ocmod.log', 'w+');
			fclose($handle);

			$handle = fopen(DIR_LOGS . 'ocmod_error.log', 'w+');
			fclose($handle);
]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$data['breadcrumbs'] = array();]]></search>
			<add position="before"><![CDATA[      	$this->load->model('extension/module/modification_manager');

		if (isset($this->request->get['filter_name'])) {
			$filter_name = $this->request->get['filter_name'];
		} else {
			$filter_name = null;
		}

      	if (isset($this->request->get['filter_xml'])) {
			$filter_xml = $this->request->get['filter_xml'];
		} else {
			$filter_xml = null;
		}

		if (isset($this->request->get['filter_author'])) {
			$filter_author = $this->request->get['filter_author'];
		} else {
			$filter_author = null;
		}

		$url = $this->getListUrlParams();

		$data['add'] = $this->url->link('marketplace/modification/add', 'user_token=' . $this->session->data['user_token'] . $url, true);
		$data['clear_log'] = $this->url->link('marketplace/modification/clearlog', 'user_token=' . $this->session->data['user_token'] . $url, true);
		$data['filter_action'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'], true);
		$data['reset_url'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'], true);

		$data['tab_files'] = $this->language->get('tab_files');
		$data['tab_error'] = $this->language->get('tab_error');]]></add>
		</operation>
		
		<operation>
			<search index="0"><![CDATA[$data['sort_name'] =]]></search>
			<add position="before"><![CDATA[      	if (isset($this->request->get['filter_name'])) {
			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_author'])) {
			$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_xml'])) {
			$url .= '&filter_xml=' . urlencode(html_entity_decode($this->request->get['filter_xml'], ENT_QUOTES, 'UTF-8'));
		}

		$data['sort_date_modified'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . '&sort=date_modified' . $url, true);]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$filter_data = array(]]></search>
			<add position="after"><![CDATA[      	'filter_name'	  => $filter_name,
			'filter_author'	  => $filter_author,
			'filter_xml'	  => $filter_xml,]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$data['modifications'][] = array(]]></search>
			<add position="after"><![CDATA[				'date_modified'      => $result['date_modified'] && $result['date_modified'] != '0000-00-00 00:00:00' ? date(date('Ymd') == date('Ymd', strtotime($result['date_modified'])) ? 'G:i' : $this->language->get('date_format_short'), strtotime($result['date_modified'])) : null,
				'edit'			     => $this->url->link('marketplace/modification/edit', 'user_token=' . $this->session->data['user_token'] . '&modification_id=' . $result['modification_id'] . $url, true),
				'download'			 => $this->url->link('marketplace/modification/download', 'user_token=' . $this->session->data['user_token'] . '&modification_id=' . $result['modification_id'] , true),]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$pagination = new Pagination();]]></search>
			<add position="before"><![CDATA[      	if (isset($this->request->get['filter_name'])) {
			$url .= '&filter_name=' . urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_author'])) {
			$url .= '&filter_author=' . urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($this->request->get['filter_xml'])) {
			$url .= '&filter_xml=' . urlencode(html_entity_decode($this->request->get['filter_xml'], ENT_QUOTES, 'UTF-8'));
		}]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$data['clear_log'] =]]></search>
			<add position="before"><![CDATA[		$data['filter_name'] = $filter_name;
		$data['filter_author'] = $filter_author;
		$data['filter_xml'] = $filter_xml;

		$data['modified_files'] = array();

		$modified_files = self::modifiedFiles(DIR_MODIFICATION);

		$modification_files = $this->getModificationXmlFiles();

		foreach($modified_files as $modified_file) {
			if(isset($modification_files[$modified_file])){
				$modifications = $modification_files[$modified_file];
			} else {
				$modifications = array();
			}

			$data['modified_files'][] = array(
				'file' => $modified_file,
				'modifications' => $modifications
			);
		}

		// Error log
		$error_file = DIR_LOGS . 'ocmod_error.log';

		if (file_exists($error_file)) {
			$data['error_log'] = htmlentities(file_get_contents($error_file, FILE_USE_INCLUDE_PATH, null));
		} else {
			$data['error_log'] = '';
		}
		]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$this->load->view('marketplace/modification']]></search>
			<add position="replace"><![CDATA[$this->load->view('extension/module/modification_manager/list']]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[$this->response->redirect($this->url->link(!empty($data['redirect']) ? $data['redirect'] : 'marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true));]]></search>
			<ignoreif position="replace"><![CDATA[if (!empty($data['redirect'])) {]]></ignoreif>
			<add position="replace"><![CDATA[$url = $this->getListUrlParams();

			if (!empty($data['redirect'])) {
				$redirect = $data['redirect'];
			} elseif (!empty($this->request->get['redirect'])) {
				$redirect = $this->request->get['redirect'];
			} else {
				$redirect = 'marketplace/modification';
			}

			$this->response->redirect($this->url->link($redirect, 'user_token=' . $this->session->data['user_token'] . $url, true));]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[if ($this->validate()) {]]></search>
			<add position="after"><![CDATA[				$error_log = array();

			// Clear vqmod cache
			$vqmod_path = substr(DIR_SYSTEM, 0, -7) . 'vqmod/';

			if (file_exists($vqmod_path)) {
				$vqmod_cache = glob($vqmod_path.'vqcache/vq*');

				if ($vqmod_cache) {
					foreach ($vqmod_cache as $file) {
						if (file_exists($file)) {
							@unlink($file);
						}
					}
				}

				if (file_exists($vqmod_path.'mods.cache')) {
					@unlink($vqmod_path.'mods.cache');
				}

				if (file_exists($vqmod_path.'checked.cache')) {
					@unlink($vqmod_path.'checked.cache');
				}
			}
]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$log[] = 'MOD:]]></search>
			<add position="after"><![CDATA[				$error_log_mod = 'MOD: ' . $dom->getElementsByTagName('name')->item(0)->textContent;
]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$operations = $file->getElementsByTagName('operation');]]></search>
			<add position="after"><![CDATA[				
					$file_error = $file->getAttribute('error');]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$files = glob($path, GLOB_BRACE);]]></search>
			<add position="after"><![CDATA[							if (!$files) {
								if ($file_error != 'skip') {
									$error_log[] = '----------------------------------------------------------------';
									$error_log[] = $error_log_mod;
									$error_log[] = 'MISSING FILE!';
									$error_log[] = $path;									
								}
							}]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[if (!$status) {]]></search>
			<add position="after"><![CDATA[											if ($error != 'skip') {
												$error_log[] = "\n";
												$error_log[] = $error_log_mod;
												$error_log[] = 'NOT FOUND!';
												$error_log[] = 'CODE: ' . $search;
												$error_log[] = 'FILE: ' . $key;
											}]]></add>
		</operation>
	    <operation>
			<search index="0"><![CDATA[$ocmod->write(implode("\n", $log));]]></search>
			<add position="after"><![CDATA[
			if ($error_log) {
				$ocmod = new Log('ocmod_error.log');
				$ocmod->write(implode("\n", $error_log));
			}]]></add>
		</operation>
		<operation>
			<search index="0"><![CDATA[protected function validate(]]></search>
			<add position="before"><![CDATA[

public function add() {
		$this->load->language('marketplace/modification');

		$this->load->model('extension/module/modification_manager');

		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
			$xml = html_entity_decode($this->request->post['xml'], ENT_QUOTES, 'UTF-8');

			$dom = new DOMDocument('1.0', 'UTF-8');
			$dom->preserveWhiteSpace = false;
			$dom->loadXml($xml);

			$data = array(
				'version' => '',
				'author' => '',
				'link' => '',
				'status' => 1
			);

			$data['xml'] = $xml;

			$data['name'] = $dom->getElementsByTagName('name')->item(0)->textContent;

			$data['code'] = $dom->getElementsByTagName('code')->item(0)->textContent;

			if ($dom->getElementsByTagName('version')->length) {
				$data['version'] = $dom->getElementsByTagName('version')->item(0)->textContent;
			}

			if ($dom->getElementsByTagName('author')->length) {
				$data['author'] = $dom->getElementsByTagName('author')->item(0)->textContent;
			}

			$this->model_extension_module_modification_manager->addModification($data);

			$modification_id = $this->db->getLastId();

			$this->session->data['success'] = $this->language->get('text_success');

			$this->response->redirect($this->url->link('marketplace/modification/edit', 'user_token=' . $this->session->data['user_token'] . $this->getListUrlParams(array('modification_id' => $modification_id)), true));
		}

		$this->getForm();
	}

	public function edit() {
		$this->load->language('marketplace/modification');

		$this->load->model('extension/module/modification_manager');
		
		if (($this->request->server['REQUEST_METHOD'] == 'POST') && !empty($this->request->get['modification_id']) && $this->validateForm()) {
			$modification_id = $this->request->get['modification_id'];

			$xml = html_entity_decode($this->request->post['xml'], ENT_QUOTES, 'UTF-8');

			$dom = new DOMDocument('1.0', 'UTF-8');
			$dom->preserveWhiteSpace = false;
			$dom->loadXml($xml);

			$data = array();

			$data['xml'] = $xml;

			$data['name'] = $dom->getElementsByTagName('name')->item(0)->textContent;

			$data['code'] = $dom->getElementsByTagName('code')->item(0)->textContent;

			if ($dom->getElementsByTagName('version')->length) {
				$data['version'] = $dom->getElementsByTagName('version')->item(0)->textContent;
			} else {
				$data['version'] = '';
			}

			if ($dom->getElementsByTagName('author')->length) {
				$data['author'] = $dom->getElementsByTagName('author')->item(0)->textContent;
			} else {
				$data['author'] = '';
			}

			if ($dom->getElementsByTagName('link')->length) {
				$data['link'] = $dom->getElementsByTagName('link')->item(0)->textContent;
			} else {
				$data['link'] = '';
			}

			$this->model_extension_module_modification_manager->editModification($modification_id, $data);

			$url = $this->getListUrlParams(array('modification_id' => $modification_id));

			if (isset($this->request->get['refresh'])) {
				$this->response->redirect($this->url->link('marketplace/modification/refresh', 'user_token=' . $this->session->data['user_token'] . $url, true));
			}

			if ($this->db->countAffected()) {
				$this->session->data['success'] = $this->language->get('text_success');

				$this->response->redirect($this->url->link('marketplace/modification/edit', 'user_token=' . $this->session->data['user_token'] . $url, true));
			}
		}

		$this->getForm();
	}
	
	public function download() {
		
        if (!$this->user->hasPermission('modify', 'marketplace/modification')) {
            $this->response->redirect($this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'], true));
        }

        if (isset($this->request->get['modification_id'])) {
            $modification_id = $this->request->get['modification_id'];
        } else {
            $modification_id = 0;
        }
		
		$this->load->model('extension/module/modification_manager');
        $modification = $this->model_extension_module_modification_manager->getModification($modification_id);

        if ($modification) {
            $filename = $modification['code'] . '.ocmod.xml';
            $file = $modification['xml'];

            ob_start();
            echo $file;
            $download = ob_get_contents();
            $size = ob_get_length();
            ob_end_clean();
            
            if (!headers_sent()) {
                if (!empty($modification['xml'])) {
                    header('Content-Type: application/octet-stream');
                    header('Content-Disposition: attachment; filename="' . $filename . '"');
                    header('Content-Transfer-Encoding: binary');
                    header('Expires: 0');
                    header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
                    header('Pragma: public');
                    header('Content-Length: ' . $size);

                    if (ob_get_level()) {
                        ob_end_clean();
                    }

                    echo $download;

                    exit();
                } else {
                    exit($this->language->get('error_file'));
                }
            } else {
                exit($this->language->get('error_headers'));
            }
        } else {
			$this->response->redirect($this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $url, true));
        }
    }
	
	public function getForm() {
		$data['heading_title'] = $this->language->get('heading_title');

		$data['text_enabled'] = $this->language->get('text_enabled');
		$data['text_disabled'] = $this->language->get('text_disabled');

		$data['button_save'] = $this->language->get('button_save');
		$data['button_download'] = $this->language->get('button_download');
		$data['button_refresh'] = $this->language->get('button_refresh');
		$data['button_cancel'] = $this->language->get('button_cancel');

		if (isset($this->error['warning'])) {
			$data['error_warning'] = $this->error['warning'];
		} elseif (!empty($this->error)) {
			$data['error_warning'] = $this->language->get('error_warning');
		} else {
			$data['error_warning'] = '';
		}

		if (isset($this->session->data['success'])) {
			$data['success'] = $this->session->data['success'];

			unset($this->session->data['success']);
		} else {
			$data['success'] = false;
		}

		if (isset($this->error['xml'])) {
			$data['error_xml'] = $this->error['xml'];
		}

		$data['breadcrumbs'] = array();

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('text_home'),
			'href' => $this->url->link('common/dashboard', 'user_token=' . $this->session->data['user_token'], true)
		);

		$data['breadcrumbs'][] = array(
			'text' => $this->language->get('heading_title'),
			'href' => $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $this->getListUrlParams(), true)
		);

		if (isset($this->request->get['modification_id'])) {
			$this->load->model('extension/module/modification_manager');

			$modification_info = $this->model_extension_module_modification_manager->getModification($this->request->get['modification_id']);
			if (!$modification_info) exit;

			$data['text_form'] = sprintf($this->language->get('text_edit'), $modification_info['name']);

			$data['action'] = $this->url->link('marketplace/modification/edit', '&modification_id=' . $modification_info['modification_id'] . '&user_token=' . $this->session->data['user_token'], true);

			$data['refresh'] = $this->url->link('marketplace/modification/edit', '&modification_id=' . $modification_info['modification_id'] . '&refresh=1&user_token=' . $this->session->data['user_token'], true);

			$this->document->setTitle($modification_info['name'] . ' ? ' . $data['heading_title']);
		} else {
			$data['text_form'] = $this->language->get('text_add');

			$data['refresh'] = false;

			$data['action'] = $this->url->link('marketplace/modification/add', 'user_token=' . $this->session->data['user_token'], true);

			$this->document->setTitle($data['heading_title']);
		}

		$data['cancel'] = $this->url->link('marketplace/modification', 'user_token=' . $this->session->data['user_token'] . $this->getListUrlParams(), true);

		$data['modification'] = array();

		if (!empty($modification_info)) {
			$data['modification']['status'] = $modification_info['status'];
		} else {
			$data['modification']['status'] = 0;
		}

		if (isset($this->request->post['xml'])) {
			$data['modification']['xml'] = html_entity_decode($this->request->post['xml'], ENT_QUOTES, 'UTF-8');
		} elseif (!empty($modification_info)) {
			$data['modification']['xml'] = $modification_info['xml'];
		} else {
			$data['modification']['xml'] = '';
		}

		$this->document->addStyle('view/javascript/codemirror/lib/codemirror.css');
		$this->document->addScript('view/javascript/codemirror/lib/codemirror.js');
		$this->document->addScript('view/javascript/codemirror/mode/xml/xml.js');

		$data['header'] = $this->load->controller('common/header');
		$data['column_left'] = $this->load->controller('common/column_left');
		$data['footer'] = $this->load->controller('common/footer');

		$this->response->setOutput($this->load->view('extension/module/modification_manager/form', $data));
	}

	private function validateForm() {
		if (!$this->user->hasPermission('modify', 'marketplace/modification')) {
			$this->error['warning'] = $this->language->get('error_permission');
		}

		$error = false;

		// Required
		if (empty($this->request->post['xml'])) {
			$error = $this->language->get('error_required');
		}

		// 2. Validate XML
		if (!$error) {
			libxml_use_internal_errors(true);

			$dom = new DOMDocument('1.0', 'UTF-8');

			if(!$dom->loadXml(html_entity_decode($this->request->post['xml'], ENT_QUOTES, 'UTF-8'))){

			    foreach (libxml_get_errors() as $error) {
			        $msg = '';

			        switch ($error->level) {
			            case LIBXML_ERR_WARNING :
			                $msg .= "Warning $error->code: ";
			                break;
			            case LIBXML_ERR_ERROR :
			                $msg .= "Error $error->code: ";
			                break;
			            case LIBXML_ERR_FATAL :
			                $msg .= "Fatal Error $error->code: ";
			                break;
			        }

			        $msg .= trim ( $error->message ) . "\nLine: $error->line";

			        $error = $msg;
			    }

			    libxml_clear_errors();
			}

			libxml_use_internal_errors(false);
		}

		// 3. Required tags
		if (!$error && (!$dom->getElementsByTagName('name') || $dom->getElementsByTagName('name')->length == 0 || $dom->getElementsByTagName('name')->item(0)->textContent == '')) {
			$error = $this->language->get('error_name');
		}

		if (!$error && (!$dom->getElementsByTagName('code') || $dom->getElementsByTagName('code')->length == 0 || $dom->getElementsByTagName('code')->item(0)->textContent == '')) {
			$error = $this->language->get('error_code');
		}

		// 4. Check code isn't duplicate
		if (!$error) {
			$code = $dom->getElementsByTagName('code')->item(0)->textContent;

			$this->load->model('extension/module/modification_manager');
			
			$modification_info = $this->model_extension_module_modification_manager->getModificationByCode($code);

			if ($modification_info && (!isset($this->request->get['modification_id']) || $modification_info['modification_id'] != $this->request->get['modification_id'])) {
				$error = sprintf($this->language->get('error_exists'), $modification_info['name'], $modification_info['code']);
			}
		}

		if ($error) {
			$this->error['xml'] = $error;
		}

		return !$this->error;
	}

	static function modifiedFiles($dir, $dirLen = 0) {
		$tree = glob(rtrim($dir, '/') . '/*');
		if (!$dirLen) {
			$dirLen = strlen($dir);
		}
		$files = array();

	    if (is_array($tree)) {
	        foreach($tree as $file) {
	        	if ($file == $dir . 'index.html') {
					continue;
				} elseif (is_file($file)) {
	                $files[] = substr($file, $dirLen);
	            } elseif (is_dir($file)) {
	                $files = array_merge($files, self::modifiedFiles($file, $dirLen));
	            }
	        }
	    }

	    return $files;
	}

	protected function getListUrlParams(array $params = array()) {
		if (isset($params['sort'])) {
			$params['sort'] = $params['sort'];
		} elseif (isset($this->request->get['sort'])) {
			$params['sort'] = $this->request->get['sort'];
		}

		if (isset($params['order'])) {
			$params['order'] = $params['order'];
		} elseif (isset($this->request->get['order'])) {
			$params['order'] = $this->request->get['order'];
		}

		if (isset($params['filter_name'])) {
			$params['filter_name'] = urlencode(html_entity_decode($params['filter_name'], ENT_QUOTES, 'UTF-8'));
		} elseif (isset($this->request->get['filter_name'])) {
			$params['filter_name'] = urlencode(html_entity_decode($this->request->get['filter_name'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($params['filter_author'])) {
			$params['filter_author'] = urlencode(html_entity_decode($params['filter_author'], ENT_QUOTES, 'UTF-8'));
		} elseif (isset($this->request->get['filter_author'])) {
			$params['filter_author'] = urlencode(html_entity_decode($this->request->get['filter_author'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($params['filter_xml'])) {
			$params['filter_xml'] = urlencode(html_entity_decode($params['filter_xml'], ENT_QUOTES, 'UTF-8'));
		} elseif (isset($this->request->get['filter_xml'])) {
			$params['filter_xml'] = urlencode(html_entity_decode($this->request->get['filter_xml'], ENT_QUOTES, 'UTF-8'));
		}

		if (isset($params['page'])) {
			$params['page'] = $params['page'];
		} elseif (isset($this->request->get['page'])) {
			$params['page'] = $this->request->get['page'];
		}

		$paramsJoined = array();

		foreach($params as $param => $value) {
			$paramsJoined[] = "$param=$value";
		}

		return '&' . implode('&', $paramsJoined);
	}

	protected function getModificationXmlFiles() {
		$return = array();

		$baseLen = strlen(substr(DIR_SYSTEM, 0, -7));

		$xml = array();

		$xml[] = file_get_contents(DIR_SYSTEM . 'modification.xml');

		$files = glob(DIR_SYSTEM . '*.ocmod.xml');

		if ($files) {
			foreach ($files as $file) {
				$xml[] = file_get_contents($file);
			}
		}

		$results = $this->model_extension_module_modification_manager->getModifications();

		foreach ($results as $result) {
			if ($result['status']) {
				$xml[] = $result['xml'];
			}
		}

		foreach ($xml as $xml) {
			if (empty($xml)){
				continue;
			}

			$dom = new DOMDocument('1.0', 'UTF-8');
			$dom->preserveWhiteSpace = false;
			$dom->loadXml($xml);

			$files = $dom->getElementsByTagName('modification')->item(0)->getElementsByTagName('file');

			foreach ($files as $file) {
				$operations = $file->getElementsByTagName('operation');

				$files = explode(',', $file->getAttribute('path'));

				foreach ($files as $file) {
					$path = '';

					// Get the full path of the files that are going to be used for modification
					if (substr($file, 0, 7) == 'catalog') {
						$path = DIR_CATALOG . str_replace('../', '', substr($file, 8));
					}

					if (substr($file, 0, 5) == 'admin') {
						$path = DIR_APPLICATION . str_replace('../', '', substr($file, 6));
					}

					if (substr($file, 0, 6) == 'system') {
						$path = DIR_SYSTEM . str_replace('../', '', substr($file, 7));
					}

					if ($path) {
						$files = glob($path, GLOB_BRACE);

						if ($files) {
							foreach ($files as $file) {
								$file = substr($file, $baseLen);

								if (!isset($return[$file])) {
									$return[$file] = array();
								}

								if ($dom->getElementsByTagName('code')->length) {
									$code = $dom->getElementsByTagName('code')->item(0)->textContent;
								} else {
									continue;
								}

								if (!empty($return[$file])) {
									foreach ($return[$file] as $return_file) {
										if ($return_file['code'] == $code) {
											continue 2;
										}
									}
								}

								if ($dom->getElementsByTagName('name')->length) {
									$name = $dom->getElementsByTagName('name')->item(0)->textContent;
								} else {
									continue;
								}

								if ($dom->getElementsByTagName('author')->length) {
									$author = $dom->getElementsByTagName('author')->item(0)->textContent;
								} else {
									$author = '';
								}

								$return[$file][] = array(
									'code' => $code,
									'name' => $name,
									'author' => $author
								);
							}
						}
					}
				}
			}
		}

		return $return;
	}

]]></add>
		</operation>
	</file>
</modification>