26if (!defined(
'NOTOKENRENEWAL')) {
27 define(
'NOTOKENRENEWAL',
'1');
29if (!defined(
'NOREQUIREMENU')) {
30 define(
'NOREQUIREMENU',
'1');
32if (!defined(
'NOREQUIREAJAX')) {
33 define(
'NOREQUIREAJAX',
'1');
35if (!defined(
'NOREQUIRESOC')) {
36 define(
'NOREQUIRESOC',
'1');
40require
'../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.
'/website/class/website.class.php';
49require_once DOL_DOCUMENT_ROOT.
'/website/class/websitepage.class.php';
50require_once DOL_DOCUMENT_ROOT.
'/core/lib/website2.lib.php';
52$action =
GETPOST(
'action',
'alpha');
53$website_ref =
GETPOST(
'website_ref');
55$content =
GETPOST(
'content',
'restricthtml');
57$element_type =
GETPOST(
'element_type',
'aZ09');
59$usercanmodify = $user->hasRight(
'website',
'write');
61 http_response_code(403);
62 print
"You don't have permission for this action.";
73if (!empty($action) && $action ===
'updatedElementContent' && $usercanmodify && !empty($content) && !empty($element_id) && !empty($website_ref) && !empty($page_id)) {
75 $objectpage =
new WebsitePage($db);
76 $res = $objectpage->fetch((
int) $page_id);
78 print
"Cannot find page with ID = " . $page_id .
".";
83 $objectwebsite =
new Website($db);
84 $res = $objectwebsite->fetch($objectpage->fk_website);
86 print
"Cannot find website with REF " . $objectpage->fk_website .
".";
93 $oldContent = $objectpage->content;
97 $objectpage->content = preg_replace(
'/<' . preg_quote($element_type,
'/') .
'[^>]*\bid="' . $element_id .
'"[^>]*>\K(.*?)(?=<\/' . preg_quote($element_type,
'/') .
'>)/s', $content, $objectpage->content, 1);
106 $res = $objectpage->update($user);
108 global $dolibarr_main_data_root;
109 $pathofwebsite = $dolibarr_main_data_root.($conf->entity > 1 ?
'/'.$conf->entity :
'').
'/website/'.$website_ref;
110 $filetpl = $pathofwebsite.
'/page'.$objectpage->id.
'.tpl.php';
114 print
"Failed to write file " . $filetpl .
".";
118 print
"Failed to save changes error " . $objectpage->error .
".";
125 print
"Changes are saved for " . $element_type .
" with id " . $element_id;
dolKeepOnlyPhpCode($str)
Keep only PHP code part from a HTML string page.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
checkPHPCode(&$phpfullcodestringold, &$phpfullcodestring)
Check that the new string $phpfullcodestring contains only php code (including <php tag)
dolSavePageContent($filetpl, Website $object, WebsitePage $objectpage, $backupold=0)
Save content of a page on disk (page name is generally ID_of_page.php).