function edit() { if (!Core::isTry()) { $page = new Page(); $page->template = "simple"; View::assign("page", $page); } $quickhelp = !Core::lib("CMS")->expert; View::assign("quickhelp", $quickhelp); return View::template("cms_pageinfo"); }
public function testConvert() { setlocale(LC_NUMERIC, 'en_US.utf-8'); \PHPPE\Core::validate("obj.phone", "phone", false); \PHPPE\Core::validate("obj.chk.me", "check", true); \PHPPE\Core::validate("obj.file", "file", false); $_FILES['obj_file']['error'] = 1; $_REQUEST['obj_phone'] = "+361234567"; $obj = \PHPPE\Core::req2obj("obj"); $this->assertInstanceOf("stdClass", $obj, "req2obj"); $this->assertFalse(\PHPPE\Core::isError("obj.phone"), "validator"); $_REQUEST['obj_phone'] = "abc"; $obj2 = \PHPPE\Core::req2arr("obj"); $this->assertInternalType("array", $obj2, "req2arr"); $this->assertTrue(\PHPPE\Core::isError("obj.chk.me"), "validator"); $obj = new \stdClass(); $obj->field1 = "field1"; $obj->field2 = "field2's"; $obj->field3 = 3; $obj->field4 = 1.2; $this->assertEmpty(\PHPPE\Core::arr2str("aaa"), "arr2str str"); $this->assertEquals("field1='field1' field2='field2\\'s' field3='3' field4='1.2'", \PHPPE\Core::arr2str($obj), "arr2str"); $this->assertEquals("field1='field1' field2='field2\\'s' field3='3' field4='1.2'", \PHPPE\Core::obj2str($obj), "obj2str space"); $this->assertEquals("field1='field1',field2='field2\\'s',field3='3',field4='1.2'", str_replace("''", "\\'", \PHPPE\Core::obj2str($obj, "", ",")), "obj2str comma"); $this->assertEquals("field1='field1' field4='1.2'", \PHPPE\Core::obj2str($obj, "field2,field3"), "obj2str skip"); $obj2 = new \stdClass(); $obj2->test = "a:b:c"; $obj2->test2 = ["a", "b", "c"]; \PHPPE\View::assign("obj2", $obj2); $this->assertEquals("[\"a:b:c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test")), "val2arr #1"); $this->assertEquals("[\"a\",\"b\",\"c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test2")), "val2arr #2"); $this->assertEquals("[1,2]", json_encode(\PHPPE\Core::val2arr([1, 2])), "val2arr #3"); $this->assertEquals("[\"a\",\"b\",\"c\"]", json_encode(\PHPPE\Core::val2arr("obj2.test", ":")), "val2arr #4"); $this->assertEquals("[]", json_encode(\PHPPE\Core::val2arr("")), "val2arr #5"); $tree = [["id" => 1, "name" => "1"], ["id" => 2, "name" => "2", "_" => [["id" => 21, "name" => "21"], ["id" => 22, "name" => "22", "_" => [["id" => 221, "name" => "221"], ["id" => 222, "name" => "222"]]], ["id" => 23, "name" => "23"], ["id" => 24, "name" => "24"]]]]; $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":21,"name":" 21"},{"id":22,"name":" 22"},{"id":221,"name":" 221"},{"id":222,"name":" 222"},{"id":23,"name":" 23"},{"id":24,"name":" 24"}]', json_encode(\PHPPE\Core::tre2arr($tree)), "tre2arr selectbox #1"); $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":21,"name":" 21"},{"id":22,"name":" 22"},{"id":221,"name":" 221"},{"id":222,"name":" 222"},{"id":23,"name":" 23"},{"id":24,"name":" 24"}]', json_encode(\PHPPE\Core::tre2arr($tree, " ")), "tre2arr selectbox #2"); $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2\\n<div id=\'tree2_1\' style=\'padding-left:10px;\'>"},{"id":21,"name":"21"},{"id":22,"name":"22\\n<div id=\'tree2_3\' style=\'padding-left:10px;\'>"},{"id":221,"name":"221"},{"id":222,"name":"222\\n<\\/div>"},{"id":23,"name":"23"},{"id":24,"name":"24\\n<\\/div>"}]', json_encode(\PHPPE\Core::tre2arr($tree, "<div id='tree2_%d' style='padding-left:10px;'>", "</div>")), "tre2arr DOM"); $tree = json_decode('[{"id":1,"name":"1"},{"id":2,"name":"2","_":[{"id":3,"name":"3"}]}]'); $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2"},{"id":3,"name":" 3"}]', json_encode(\PHPPE\Core::tre2arr($tree)), "tre2arr stdClass selectbox"); $this->assertEquals('[{"id":1,"name":"1"},{"id":2,"name":"2\\n<div id=\'tree2_1\' style=\'padding-left:10px;\'>"},{"id":3,"name":"3\\n<\\/div>"}]', json_encode(\PHPPE\Core::tre2arr($tree, "<div id='tree2_%d' style='padding-left:10px;'>", "</div>")), "tre2arr stdClass DOM"); }
function edit() { $quickhelp = !Core::lib("CMS")->expert; View::assign("quickhelp", $quickhelp); return View::template("cms_layoutadd"); }
/** * default action */ function action($item) { //! omit frame and panel and disable cache Core::$core->noframe = true; Core::$core->nopanel = true; Core::$core->nocache = true; //! if not called as it should, return if (empty($item) || $item != sha1("pageadd_") && (empty($_SESSION['cms_url']) || empty($_SESSION['cms_param'][$item]))) { Core::$core->template = "403"; return; } //! get height $this->height = intval(@$_REQUEST['height']); $this->adjust = intval(@$_REQUEST['adjust']); //! save current scroll position to session so that on next //! page load pe.cms.init() will use it if (isset($_REQUEST['scrx'])) { $_SESSION['cms_scroll'] = [$_REQUEST['scrx'], $_REQUEST['scry']]; } //! get available access control entries $this->ace = ClassMap::ace(); foreach ($this->ace as $k => $v) { $this->ace[$k] = "@" . $v; } $this->ace[] = "@siteadm|webadm"; $this->ace[] = "loggedin"; $this->ace[] = "csrf"; $this->ace[] = "get"; $this->ace[] = "post"; //! get the field we're editing $F = clone $_SESSION["cms_param"][$item]; $F->fld = "page_value"; if (get_class($F) == "PHPPE\\AddOn\\wyswyg") { $F->args = [0, "pe.cms.image"]; } if (method_exists($F, 'init')) { $F->init(); } $this->fieldTitle = $F->name; $this->heightClass = @$F->heightClass; $this->boxHeight = $this->height - @$F->headerHeight; //! get the page we're editing //! if parameter name starts with "frame", load frame page instead $page = new Page(substr($F->name, 0, 6) == "frame." ? "frame" : @$_SESSION['cms_url']); $this->editable = $page->lock(); View::assign("page", $page); $n = substr($F->name, 0, 6) == "frame." ? substr($F->name, 6) : (substr($F->name, 0, 4) == "app." ? substr($F->name, 4) : $F->name); if (!empty($page->data[$n])) { $F->value = $page->data[$n]; } //! load extra data if any if (method_exists($F, 'load')) { $F->load($this); } //! save page parameter $param = Core::req2arr("page"); if (!empty($param) && $this->editable) { //! if there was no validation error if (!Core::isError()) { if (method_exists($F, "save")) { //! if it's a special field with it's own save mechanism $param['pageid'] = $page->id; if (!$F->save($param)) { Core::error(L("Unable to save page!")); } } else { //! otherwise standard page parameter $page->setParameter($F->name, $param['value']); if (!$page->save()) { Core::error(L("Unable to save page!")); } } //! close the modal if save was successful if (!Core::isError()) { //! release the page lock $page->release(); die("<html><script>parent.pe.cms.close(true);</script></html>"); } } //! copy the form data. normally you don't need to do that //! but here form name and object name differs, so it's not automatic foreach ($param as $k => $v) { $page->{$k} = $v; } } //! get the input(s) if (method_exists($F, 'edit')) { $this->field = $F->edit(); } else { //! fallback to a simple input field. Should never happen $this->field = "<input type='text' class='input" . (Core::isError("page.value") ? " errinput" : "") . "' name='page_value' value=\"" . htmlspecialchars($F->value) . "\">"; } //! focus first input View::js("init()", "var inp=document.querySelector('.reqinput,.input');if(inp!=null){inp.focus();inp.selectionStart=inp.selectionEnd=(inp.value!=null?inp.value:inp.innerHTML).length;}", true); }
public function testTemplater() { $this->assertNotFalse(strpos(\PHPPE\View::template("test1"), "TOOMNY"), "Template #1"); $this->assertNotEmpty(\PHPPE\View::template("404"), "Template #2"); $this->assertEmpty(\PHPPE\View::template("nosuchtemplate"), "Template #3"); $obj = new \stdClass(); $obj->dynamicname = "dyntest"; $obj->arr = ["a", "b", "c"]; $obj->arr2 = [["A" => "a"], ["A" => "b"], ["A" => "c"]]; $obj->now = time(); $obj->singlearr = ["a"]; $obj->arrs = unserialize('a:2:{i:0;a:2:{s:2:"id";s:5:"frame";s:4:"name";s:7:"Default";}i:1;a:2:{s:2:"id";s:6:"simple";s:4:"name";s:6:"Simple";}}'); $obj->objs = unserialize('a:2:{i:0;O:8:"stdClass":2:{s:2:"id";s:5:"frame";s:4:"name";s:5:"Frame";}i:1;O:8:"stdClass":2:{s:2:"id";s:6:"simple";s:4:"name";s:6:"Simple";}}'); $obj->spec[0] = new \stdClass(); $obj->spec[0]->id = 1; $obj->spec[0]->name = [1, 2, 3]; $obj->emptyStr = ""; \PHPPE\View::assign("obj", $obj); \PHPPE\View::assign("app", $obj); \PHPPE\View::assign("core", \PHPPE\Core::$core); $this->assertEquals("dynamic name", \PHPPE\View::_t("<!include dynamicname>"), "Dynamic name"); $this->assertEquals("<!-- not removed -->test", \PHPPE\View::_t("<!-- not removed -->test"), "Comment"); $this->assertEquals("<!app>", \PHPPE\View::_t("<!app>"), "App tag"); $this->assertEquals(\PHPPE\Core::$core->now . "", \PHPPE\View::_t("<!=core.now>"), "Expression #1"); $this->assertNotFalse(strpos(\PHPPE\View::_t("<!=core.now=1>"), "INP"), "Expression #2"); $this->assertEquals("aa\"bb", \PHPPE\View::_t('<!="aa\\"bb">'), "Expression #3"); $this->assertFalse(strpos(\PHPPE\View::_t("<!=sprintf('aaabbb')>"), "BADFNC"), "Expression #4"); \PHPPE\View::$C = []; \PHPPE\Core::$core->allowed = ["number_format"]; $this->assertNotFalse(strpos(\PHPPE\View::_t("<!=sprintf('aaabbb')>"), "BADFNC"), "Expression #5"); \PHPPE\Core::$core->allowed = []; unset(\PHPPE\Core::$l['aaa_bbb']); $this->assertEquals("aaa bbb", \PHPPE\View::_t('<!L aaa_bbb>'), "Language"); $this->assertNotFalse(strpos(\PHPPE\View::_t("<!notag>"), "UNKTAG"), "Unknown tag"); $this->assertNotFalse(strpos(\PHPPE\View::_t('<!var noSuchAddon>'), "UNKADDON"), "Unknown AddOn"); \PHPPE\Core::$l['min'] = "m"; \PHPPE\Core::$l['mins'] = "ms"; \PHPPE\Core::$l['hour'] = "h"; \PHPPE\Core::$l['hours'] = "hs"; \PHPPE\Core::$l['day'] = "d"; \PHPPE\Core::$l['days'] = "ds"; $this->assertEquals("0 m", \PHPPE\View::_t('<!difftime 1>'), "Difftime #1"); $this->assertEquals("1 m", \PHPPE\View::_t('<!difftime 60>'), "Difftime #2"); $this->assertEquals("2 ms", \PHPPE\View::_t('<!difftime 120>'), "Difftime #3"); $this->assertEquals("1 h", \PHPPE\View::_t('<!difftime 3600>'), "Difftime #4"); $this->assertEquals("1 h, 1 m", \PHPPE\View::_t('<!difftime 3660>'), "Difftime #5"); $this->assertEquals("2 hs, 2 ms", \PHPPE\View::_t('<!difftime 3660*2>'), "Difftime #6"); $this->assertEquals("1 d", \PHPPE\View::_t('<!difftime 3600*24>'), "Difftime #7"); $this->assertEquals("2 ds", \PHPPE\View::_t('<!difftime 3600*48>'), "Difftime #8"); $this->assertEquals("2 ds", \PHPPE\View::_t('<!difftime 3600*50>'), "Difftime #9"); $this->assertEquals("- 2 ms", \PHPPE\View::_t('<!difftime -120>'), "Difftime #10"); $this->assertEquals("1 m", \PHPPE\View::_t('<!difftime 3660 3600>'), "Difftime #11"); $this->assertEquals("-", \PHPPE\View::_t('<!difftime obj.emptyStr 10>'), "Difftime #12"); $this->assertEquals("aaa", \PHPPE\View::_t("<!template>aaa<!/template>"), "Reentrant #1"); $this->assertEquals(\PHPPE\Core::$core->now, \PHPPE\View::_t("<!template><%=core.now><!/template>"), "Reentrant #2"); $this->assertEquals("011a120b231c", \PHPPE\View::_t("<!foreach arr><!=KEY><!=IDX><!=ODD><!=VALUE><!/foreach>"), "Foreach #1"); $this->assertEquals("abc", \PHPPE\View::_t("<!foreach obj.arr2><!=A><!/foreach>"), "Foreach #2"); $this->assertNotFalse(strpos(\PHPPE\View::_t("!foreach obj.arr2><!=A><!/foreach>"), "UNCLS"), "Foreach #3"); $this->assertEquals("0a0b0c1a1b1c2a2b2c", \PHPPE\View::_t("<!foreach arr><!foreach obj.arr2><!=parent.KEY><!=A><!/foreach><!/foreach>"), "Foreach #4"); $this->assertEquals("01101a00102b01103c11001a10002b11003c21101a20102b21103c01111a00112b01113c11011a10012b11013c21111a20112b21113c01121a00122b01123c11021a10022b11023c21121a20122b21123c", \PHPPE\View::_t("<!foreach arr><!foreach obj.arr><!foreach obj.arr2><!=parent.KEY><!=ODD><!=parent.ODD><!=parent.parent.KEY><!=IDX><!=A><!/foreach><!/foreach><!/foreach>"), "Foreach #5"); $this->assertEquals("a0framea0framea1simplea1simple", \PHPPE\View::_t("<!foreach obj.arrs><!foreach VALUE>a<!=parent.KEY><!=parent.id><!/foreach><!/foreach>"), "Foreach #6"); $this->assertEquals("frameFramesimpleSimple", \PHPPE\View::_t("<!foreach obj.objs><!=id><!=name><!=none><!/foreach>"), "Foreach #7"); $this->assertEquals("A", \PHPPE\View::_t("<!if true>A<!else>B<!/if>"), "If true"); $this->assertEquals("B", \PHPPE\View::_t("<!if false>A<!else>B<!/if>"), "If false"); $this->assertEquals(1, preg_match("|<form name='a' action='[^']+' class='form-vertical' method='post' enctype='multipart/form-data'><input type='hidden' name='MAX_FILE_SIZE' value='[0-9]+'><input type='hidden' name='pe_s' value='[a-fA-F0-9]*'><input type='hidden' name='pe_f' value='a'>|ims", \PHPPE\View::_t("<!form a>")), "Form #1"); $this->assertEquals(1, preg_match("|<form name='a' action='([^']+)' class='form-vertical' method='post' enctype='multipart/form-data'><input type='hidden' name='MAX_FILE_SIZE' value='[0-9]+'><input type='hidden' name='pe_s' value='[a-fA-F0-9]*'><input type='hidden' name='pe_f' value='a'>|ims", \PHPPE\View::_t("<!form a form-vertical b/c>"), $m), "Form #2"); $this->assertEquals("b/c/", substr($m[1], -4), "Form #2 url"); $this->assertEquals(1, preg_match("|<form role='form' name='a' action='([^']+)' class='form-vertical' method='post' enctype='multipart/form-data' onsubmit=\"d\\(\\)\"><input type='hidden' name='MAX_FILE_SIZE' value='[0-9]+'><input type='hidden' name='pe_s' value='[a-fA-F0-9]*'><input type='hidden' name='pe_f' value='a'>|ims", \PHPPE\View::_t("<!form a - b/c d() role>"), $m), "Form #3"); $this->assertEquals("b/c/", substr($m[1], -4), "Form #3 url"); $this->assertEquals(1, preg_match("|<form name='a' action='([^']+)' class='form-vertical' method='post' enctype='multipart/form-data' onsubmit=\"d\\(\\)\"><input type='hidden' name='MAX_FILE_SIZE' value='[0-9]+'><input type='hidden' name='pe_s' value='[a-fA-F0-9]*'><input type='hidden' name='pe_f' value='a'>|ims", \PHPPE\View::_t("<!form a - - d()>")), "Form #4"); $_SESSION['pe_c'] = $_SESSION['pe_e'] = false; $this->assertEquals("show1", \PHPPE\View::_t('<!var test1 test>'), "var tag (pe_c=0,pe_e=0,show)"); $this->assertEquals("show1", \PHPPE\View::_t('<!widget test1 test>'), "widget tag (pe_c=0,pe_e=0,show)"); $this->assertEquals("edit1", \PHPPE\View::_t('<!field test1 test>'), "field tag (pe_c=0,pe_e=0,edit)"); $_SESSION['pe_c'] = true; $this->assertEquals("show1", \PHPPE\View::_t('<!var test1 test>'), "var tag (pe_c=1,pe_e=0,show)"); $this->assertEquals("edit1", \PHPPE\View::_t('<!widget test1 test>'), "widget tag (pe_c=1,pe_e=0,edit)"); $this->assertEquals("edit1", \PHPPE\View::_t('<!field test1 test>'), "field tag (pe_c=1,pe_e=0,edit)"); $_SESSION['pe_c'] = false; $_SESSION['pe_e'] = true; $this->assertEquals("edit1", \PHPPE\View::_t('<!var test1 test>'), "var tag (pe_c=0,pe_e=1,edit)"); $this->assertEquals("show1", \PHPPE\View::_t('<!widget test1 test>'), "widget tag (pe_c=0,pe_e=1,show)"); $this->assertEquals("edit1", \PHPPE\View::_t('<!field test1 test>'), "field tag (pe_c=0,pe_e=1,edit)"); $_SESSION['pe_c'] = $_SESSION['pe_e'] = false; $this->assertNotFalse(strpos(\PHPPE\View::_t('<!field *text test>'), "required"), "field tag (required)"); \PHPPE\Core::$user->id = 1; $this->assertEmpty(\PHPPE\View::_t('<!var @noacl test1 test>'), "var tag (noacl)"); $this->assertEmpty(\PHPPE\View::_t('<!field @noacl test1 test>'), "field tag (noacl)"); \PHPPE\Core::$user->id = -1; $this->assertEquals("show1", \PHPPE\View::_t('<!var @noacl test1 test>'), "var tag (noacl admin)"); $this->assertEquals("edit1", \PHPPE\View::_t('<!field @noacl test1 test>'), "field tag (noacl admin)"); $u = \PHPPE\Core::$user->id; \PHPPE\Core::$user->id = 0; $this->assertEquals("", \PHPPE\View::_t('<!cms test1 test>'), "cms tag #1"); $this->assertEquals("show1", \PHPPE\View::_t('<!cms *test1 test>'), "cms tag #2"); \PHPPE\Core::$user->id = -1; $app = new \PHPPE\Content(); \PHPPE\View::assign("app", $app); $this->assertNotFalse(strpos(\PHPPE\View::_t('<!cms test1 test>'), "cms.edit"), "cms tag #3"); \PHPPE\Core::$user->id = $u; $this->assertEquals("show3", \PHPPE\View::_t('<!var test3 test>'), "Addon init"); \PHPPE\Core::$l['dateformat'] = "Y-m-d"; \PHPPE\Core::$l['testdate'] = "2001-02-03 04:05:06"; date_default_timezone_set("UTC"); $this->assertEquals("2001-02-03", \PHPPE\View::_t('<!date L("testdate")>'), "Date #1"); $this->assertEquals("2001-02-03 04:05:06", \PHPPE\View::_t('<!time L("testdate")>'), "Time #1"); $this->assertEquals("1970-01-01", \PHPPE\View::_t('<!date 1>'), "Date #2"); $this->assertEquals(1, preg_match("/1970-01-01 [0-9]+:00:01/", \PHPPE\View::_t("<!time 1>")), "Time #2"); \PHPPE\Core::$core->runlevel = 0; $this->assertEmpty(\PHPPE\View::_t('<!dump obj>'), "Dump #1"); \PHPPE\Core::$core->runlevel = 1; $this->assertEquals(1, preg_match("/stdClass Object/", \PHPPE\View::_t("<!dump obj>")), "Dump #2"); \PHPPE\Core::$core->runlevel = 2; $d = \PHPPE\View::_t("<!dump obj>"); $this->assertEquals(1, preg_match("/string\\(7\\) \"dyntest\"/", $d) || preg_match("/var\\-dump/", $d), "Dump #3"); $this->assertEquals(0, preg_match("/pe_u/", \PHPPE\View::_t("<!dump _SESSION>")), "Dump #4"); \PHPPE\Core::$core->noframe = false; \PHPPE\Core::$core->output = "html"; \PHPPE\Core::$user->id = -1; $this->assertEquals(1, preg_match("/bbb/", \PHPPE\View::generate("test1", "t_" . sha1(\PHPPE\Core::$core->base . "_test1"))), "Generate"); \PHPPE\Cache::$mc = null; ob_start(); $txt = "TEST"; @\PHPPE\View::output($txt); $this->assertEquals(1, preg_match("/TEST/", ob_get_clean()), "Output #1"); \PHPPE\Cache::$mc = new \PHPPE\Cache\Files("files"); \PHPPE\Core::$core->nocache = false; \PHPPE\Core::$core->noaggr = false; $obj->favicon = "favicon.png"; $_SESSION['pe_ls'] = ["en" => "en"]; \PHPPE\View::menu("aaa", "aaa/bbb"); \PHPPE\View::menu("ccc", ["ccc" => "ccc/ddd"]); //save it to cache $sha = \PHPPE\Core::$core->base . \PHPPE\Core::$core->url . "/" . \PHPPE\Core::$user->id . "/" . \PHPPE\Core::$client->lang; \PHPPE\Cache::set("c_" . sha1($sha . "_css"), ""); \PHPPE\Cache::set("c_" . sha1($sha . "_js"), ""); ob_start(); @\PHPPE\View::output($txt); $this->assertEquals(1, preg_match("/div class='menu'/", ob_get_clean()), "Output #2"); //read from cache ob_start(); @\PHPPE\View::output($txt); $this->assertEquals(1, preg_match("/div class='menu'/", ob_get_clean()), "Output #3"); ob_start(); @\PHPPE\View::output($txt, "aaa"); $this->assertEquals(1, preg_match("/<\\/span><span class='menu_a'>/", ob_get_clean()), "Active menu #1"); ob_start(); @\PHPPE\View::output($txt, "ccc"); $this->assertEquals(1, preg_match("/class='menu_a' onclick/", ob_get_clean()), "Active menu #2"); }
/** * default action */ function action($item) { //! check access rights if (!Core::$user->has("siteadm|webadm")) { Http::redirect("403"); } //! if we have to delete a page version if (isset($_REQUEST['pagedel'])) { if (!empty($_REQUEST['created'])) { Page::delete($item, $_REQUEST['created']); } Http::redirect($item); } //! revert to an old version of the page if (isset($_REQUEST['revert'])) { if (!empty($_REQUEST['created'])) { Core::log('A', sprintf("Page %s reverted to %s by %s", $item, $_REQUEST['created'], Core::$user->name), "cmsaudit"); DS::exec("UPDATE pages set created=CURRENT_TIMESTAMP,modifyd=CURRENT_TIMESTAMP,modifyid=? WHERE id=? AND (lang='' OR lang=?) AND created=?", [Core::$user->id, $item, Core::$client->lang, $_REQUEST['created']]); } Http::redirect($item); } //! get the latest public version's date if (empty($_REQUEST['created'])) { $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND publishid!=0", "", "id DESC,created DESC", [$item, $item, Core::$client->lang]); if (empty($_REQUEST['created'])) { $_REQUEST['created'] = DS::field("created", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?)", "", "id DESC,created ASC", [$item, $item, Core::$client->lang]); } } //! load frame page for page parameters and dds $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND created<=?", "", "", [Core::$client->lang, $_REQUEST['created']]); $frame['dss'] = @json_decode($frame['dds'], true); $frame['data'] = @json_decode($frame['data'], true); View::assign("frame", $frame['data']); //! load archive version //! normally you would use Model, but that would only return the latest version $page = DS::fetch("*", "pages", "(id=? OR ? LIKE id||'/%') AND (lang='' OR lang=?) AND created=?", "", "id DESC,created DESC", [$item, $item, Core::$client->lang, $_REQUEST['created']]); $this->title = $page['name']; $title = L("ARCHIVE") . " " . $page['name']; if (is_string($page['data'])) { $page['data'] = @json_decode($page['data'], true); } if (is_array($page['data'])) { foreach ($page['data'] as $k => $v) { $this->{$k} = $v; } } foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) { $this->{$k} = $page[$k]; } $p = @array_merge($frame['dds'], @json_decode($page['dds'], true)); if (is_array($p)) { foreach ($p as $k => $c) { if ($k != "dds") { try { $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6])); } catch (\Exception $e) { Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds"); } } } } $old = View::template($this->template); //! if we have to compare to an older (or the latest) version if (isset($_REQUEST['diff'])) { include_once "vendor/phppe/CMS/libs/simplediff.php"; //! load current version $frame = DS::fetch("data,dds", "pages", "id='frame' AND (lang='' OR lang=?) AND publishid!=0", "", "created DESC", [Core::$client->lang]); $frame['dss'] = @json_decode($frame['dds'], true); $frame['data'] = @json_decode($frame['data'], true); View::assign("frame", $frame['data']); $page = DS::fetch("*", "pages", "id=? OR ? LIKE id||'/%'", "", "id DESC,created DESC", [$item, $item]); if (is_string($page['data'])) { $page['data'] = @json_decode($page['data'], true); } if (is_array($page['data'])) { foreach ($page['data'] as $k => $v) { $this->{$k} = $v; } } foreach (["id", "name", "lang", "filter", "template", "pubd", "expd", "dds", "ownerid", "created"] as $k) { $this->{$k} = $page[$k]; } $p = @array_merge($frame['dds'], @json_decode($page['dds'], true)); if (is_array($p)) { foreach ($p as $k => $c) { if ($k != "dds") { try { $this->{$k} = DS::query($c[0], $c[1], @$c[2], @$c[3], @$c[4], @$c[5], View::getval(@$c[6])); } catch (\Exception $e) { Core::log("E", $item . " " . $e->getMessage() . " " . implode(" ", $c), "dds"); } } } } $this->title = $page['name']; $curr = View::template($this->template); //! make sure diff splits on tag end $this->result = htmlDiff(preg_replace("/>([^\\ \t\n])/m", "> \\1", $old), preg_replace("/>([^\\ \t\n])/m", "> \\1", $curr)); //! remove diff inside tags $this->result = preg_replace("/(<[^<>]+)<ins>.*?<\\/ins>([^<>]*>)/ims", "\\1\\2", $this->result); $this->result = preg_replace("/(<[^<>]+)<del>(.*?)<\\/del>([^<>]*>)/ims", "\\1\\2\\3", $this->result); } else { $this->result = $old; } $this->title = $title; }