Skip to content

Commit 087ebbf

Browse files
committed
first upload
0 parents  commit 087ebbf

20 files changed

+13029
-0
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
root = true
2+
3+
[*.php]
4+
indent_size = 4

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Open Saas Core

index.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
/**
3+
* 2007-2022 PrestaShop
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/afl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2022 PrestaShop SA
23+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*/
26+
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
27+
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
28+
29+
header('Cache-Control: no-store, no-cache, must-revalidate');
30+
header('Cache-Control: post-check=0, pre-check=0', false);
31+
header('Pragma: no-cache');
32+
33+
header('Location: ../');
34+
exit;

module_override.php

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
<?php
2+
/**
3+
* 2007-2022 PrestaShop
4+
*
5+
* NOTICE OF LICENSE
6+
*
7+
* This source file is subject to the Academic Free License (AFL 3.0)
8+
* that is bundled with this package in the file LICENSE.txt.
9+
* It is also available through the world-wide-web at this URL:
10+
* http://opensource.org/licenses/afl-3.0.php
11+
* If you did not receive a copy of the license and are unable to
12+
* obtain it through the world-wide-web, please send an email
13+
* to license@prestashop.com so we can send you a copy immediately.
14+
*
15+
* DISCLAIMER
16+
*
17+
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
18+
* versions in the future. If you wish to customize PrestaShop for your
19+
* needs please refer to http://www.prestashop.com for more information.
20+
*
21+
* @author PrestaShop SA <contact@prestashop.com>
22+
* @copyright 2007-2022 PrestaShop SA
23+
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
24+
* International Registered Trademark & Property of PrestaShop SA
25+
*/
26+
27+
if (!defined('_PS_VERSION_')) {
28+
exit;
29+
}
30+
31+
class Opensaas_core extends Module
32+
{
33+
protected $config_form = false;
34+
35+
public function __construct()
36+
{
37+
$this->name = 'module_override';
38+
$this->tab = 'front_office_features';
39+
$this->version = '1.0.0';
40+
$this->author = 'Marco Ingraiti';
41+
$this->need_instance = 0;
42+
43+
$this->bootstrap = true;
44+
45+
parent::__construct();
46+
47+
$this->displayName = $this->l('Module Override');
48+
$this->description = $this->l('Add overrides to Prestashop module php behaviours with a reversible management system');
49+
50+
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
51+
}
52+
53+
54+
public function install()
55+
{
56+
return parent::install() &&
57+
$this->registerHook('backOfficeHeader')
58+
}
59+
60+
61+
public function hookBackOfficeHeader()
62+
{
63+
if (Tools::getValue('configure') == $this->name) {
64+
$this->context->controller->addCSS($this->_path.'views/css/back.css');
65+
$this->context->controller->addJs($this->_path.'views/js/back.js');
66+
}
67+
}
68+
69+
public function getAvailableOverrides()
70+
{
71+
$override_folders = glob($this->local_path."module_overrides/*");
72+
$available_overrides = [];
73+
foreach($override_folders as $module_path){
74+
$module_name = explode("/", $module_path);
75+
$module_name = end($module_name);
76+
$is_installed = Module::isInstalled($module_name);
77+
if($is_installed === true){
78+
$module_instance = Module::getInstanceByName($module_name);
79+
$version_exist = is_dir($module_path."/".$module_instance->version);
80+
if($version_exist === true){
81+
$available_overrides[$module_name] = [
82+
"name" => $module_name,
83+
"version" => $module_instance->version,
84+
"is_overriden" => (bool)trim(file_get_contents($module_path."/".$module_instance->version."/.override"))
85+
];
86+
}
87+
}
88+
}
89+
return $available_overrides;
90+
}
91+
92+
93+
public function getContent()
94+
{
95+
if (((bool)Tools::isSubmit('toggle_override')) == true) {
96+
$this->toggleOverride();
97+
}
98+
$overrides = $this->getAvailableOverrides();
99+
$this->context->smarty->assign('available_overrides', $overrides);
100+
$output = $this->context->smarty->fetch($this->local_path.'views/templates/admin/configure.tpl');
101+
return $output;
102+
}
103+
104+
105+
protected function toggleOverride()
106+
{
107+
$ds = DIRECTORY_SEPARATOR;
108+
$module_name = $_POST["module_name"] ?? NULL;
109+
$module_version = $_POST["module_version"] ?? NULL;
110+
$module_path = $this->local_path."module_overrides$ds$module_name$ds$module_version$ds";
111+
$override_path = $module_path.".override";
112+
$is_overriden = (bool)trim(file_get_contents($override_path));
113+
$new_overriden = $is_overriden ? 0 : 1;
114+
$source = $module_path;
115+
$dest = _PS_CORE_DIR_.$ds."modules$ds$module_name$ds";
116+
foreach(
117+
$iterator = new \RecursiveIteratorIterator(
118+
new \RecursiveDirectoryIterator($source, \RecursiveDirectoryIterator::SKIP_DOTS),
119+
\RecursiveIteratorIterator::SELF_FIRST) as $item
120+
){
121+
if($item->isDir()){
122+
mkdir($dest . $ds . $iterator->getSubPathname());
123+
}else{
124+
$sub_path = $iterator->getSubPathname();
125+
if(strpos($item, ".override") !== false) continue;
126+
if($new_overriden){
127+
if(strpos($item, ".original") !== false) continue;
128+
}else{
129+
if(strpos($item, ".original") === false) continue;
130+
$sub_path = str_replace(".original", "", $sub_path);
131+
}
132+
copy($item, $dest . $sub_path);
133+
}
134+
}
135+
file_put_contents($override_path, $new_overriden);
136+
}
137+
138+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1

0 commit comments

Comments
 (0)