function action() { if (isset($_REQUEST['clearbenchmark'])) { Benchmark::clear(); Http::redirect(); } $this->data = Benchmark::stats(); foreach ($this->data as $u => $v) { $this->urls[] = $u . " (" . sprintf(L("%d samples"), reset($v)['cnt']) . ")"; } View::js("choosediv(value)", "var divs=document.querySelectorAll('DIV.benchmark');for(var i in divs) divs[i].style.display=divs[i].id=='url'+value?'block':'none';"); }
function action($item) { //make lang happy: L("OK") L("FAIL") L("SKIP") L("None") if (Core::$core->output != "html") { printf(chr(27) . "[96m%-20s%-9s%-9s%-21s%s\n------------------- -------- -------- -------------------- ----------" . chr(27) . "[0m\n", L("Test boundle"), L("Avg.time"), L("#Tests"), L("Last run"), L("Result")); foreach ($this->testCases as $t) { printf("%-20s" . chr(27) . "[90m%0.4fs %3d /%3d %s " . chr(27) . "[%sm%s" . chr(27) . "[0m\n", $t['name'], $t['avg'], $t['executed'], $t['asserts'], date("Y-m-d H:i:s", $t['time']), $t['ret'] == "OK" ? "92" : ($t['ret'] == "None" ? "96" : "91"), L($t['ret'])); } die; } View::js("runtest(t)", "document.getElementById('testsdiv').style.display='none';document.getElementById('loadingdiv').style.display='block';document.location.href='" . url() . "run/'+t;"); View::css("test.css"); }
function edit() { $lists = ["pages_list" => L("Page list"), "img_list" => L("Picture list"), "doc_list" => L("Document list")]; $v = is_array($this->value) ? $this->value : json_decode($this->value, true); $r = "<input type='hidden' name='" . $this->fld . "'><table width='100%'><tr><td></td><td>" . L("SELECT") . "</td><td>" . L("FROM") . "</td><td>" . L("WHERE") . "</td><td>" . L("GROUP BY") . "</td><td>" . L("ORDER BY") . "</td></tr>"; if (!empty($v)) { foreach ($v as $k => $m) { $r .= "<tr><td width='1' style='min-width:100px;border:1px solid #202020;padding:2px;background:rgba(160,160,160,0.5);'>" . $k . "</td>"; $l = explode(" ", $m[1])[0]; $f = $h = ""; if (!empty($lists[$l])) { $f = "<select onchange='cms_listhide(this);' onblur='cms_listhide(this);' style='width:95%;margin-left:0px;' class='input form-control'><option value=''>*</option>"; foreach ($lists as $n => $li) { $f .= "<option value='" . htmlspecialchars($n) . "'" . ($l == $n ? " selected" : "") . ">" . $li . "</option>"; } $f .= "</select>"; $h = 1; } foreach ($m as $idx => $val) { $r .= "<td width='*' style='padding:0px;'>" . $f . "<input style='width:95%;margin-left:0px;" . ($h ? "display:none;" : "") . "' class='input form-control' name='" . $this->fld . "[" . $k . "][" . $idx . "]' value=\"" . htmlspecialchars(!empty($val) ? $val : '') . "\"" . ($f ? " onkeydown='cms_listshow(this);'" : "") . "></td>"; $f = ""; } $r .= "<td><nobr><img src='images/cms/pagedel.png' onclick='cms_cleardds(this);' style='cursor:pointer;padding:2px;'><img src='images/cms/pageadd.png' onclick='cms_clonedds(this);' style='cursor:pointer;padding:2px;'></nobr></td></tr>"; } } $r .= "<tr><td width='1' style='padding-right:3px;'><input style='min-width:100px;' class='input form-control' name='" . $this->fld . "[_][name]' value=''></td>"; for ($m = 0; $m < 5; $m++) { $r .= "<td width='*' style='padding:0px;'><input style='width:95%;margin-left:0px;' class='input form-control' name='" . $this->fld . "[_][" . $m . "]' value=''></td>"; } $r .= "<td style='width:37px;'> </td></tr>"; $r .= "</table>"; View::js("cms_cleardds(obj)", "obj.parentNode.parentNode.parentNode.getElementsByTagName('INPUT')[0].value='';" . "obj.parentNode.parentNode.parentNode.style.display='none';"); View::js("cms_clonedds(obj)", "var i,tbl=obj.parentNode;" . "while(tbl.tagName!='TABLE') tbl=tbl.parentNode;" . "var inps=tbl.rows[tbl.rows.length-1].getElementsByTagName('INPUT');" . "var orig=obj.parentNode.parentNode.parentNode.getElementsByTagName('INPUT');" . "for(i=0;i<orig.length;i++) inps[i+1].value=orig[i].value;" . "inps[0].value='New'; inps[0].select(); inps[0].focus();"); View::js("cms_listhide(obj)", "var i,orig=obj.parentNode.parentNode.getElementsByTagName('INPUT');console.log('value',obj.selectedIndex,obj.value);" . "if(obj.selectedIndex==0||obj.value==null||obj.value==''){" . "obj.setAttribute('style','display:none;');for(i=0;i<orig.length;i++) orig[i].style.display='block';" . "}else{" . "if(obj.value=='pages_list'){orig[0].value='b.*';orig[1].value='pages_list a left join pages b on a.page_id=b.id and b.created=(SELECT MAX(c.created) FROM pages c WHERE c.id=b.id)';orig[2].value=\"a.list_id='@ID'\";orig[3].value='';orig[4].value='ordering';}" . "if(obj.value=='img_list'){orig[0].value='id';orig[1].value='img_list';orig[2].value=\"list_id='@ID'\";orig[3].value='';orig[4].value='ordering';}" . "if(obj.value=='doc_list'){orig[0].value='id';orig[1].value='doc_list';orig[2].value=\"list_id='@ID'\";orig[3].value='';orig[4].value='ordering';}" . "}"); View::js("cms_listshow(obj)", "var i,orig=obj.parentNode.parentNode.getElementsByTagName('INPUT');" . "if(obj.value==null||obj.value==''){" . "obj.previousSibling.setAttribute('style','display:block;');for(i=0;i<orig.length;i++) orig[i].style.display='none';}"); return $r; }
public function testHelpers() { \PHPPE\Core::$core->nocache = true; \PHPPE\Core::$core->meta["test"] = "testing"; \PHPPE\Core::$core->link["apple-touch-icon"] = "testing"; \PHPPE\View::init([]); $dir = dirname(__DIR__); \PHPPE\View::setPath($dir); \PHPPE\View::assign("dir", $dir); \PHPPE\View::css("test.css"); \PHPPE\View::css("test2.css"); \PHPPE\View::css(url("css", "test.css")); $this->assertNotEmpty(\PHPPE\View::css(), "CSS"); \PHPPE\View::jslib("test.js", "testjs();"); \PHPPE\View::jslib("test2.js", "testjs();"); \PHPPE\View::jslib(url("js", "test.js"), "testjs();"); $this->assertNotEmpty(\PHPPE\View::jslib(), "JSLib"); \PHPPE\View::js("some()", "thing();"); \PHPPE\View::js("some2()", "thing();", true); \PHPPE\View::menu("a", "b"); \PHPPE\View::menu("c", ["d" => "e"]); $this->assertNotEmpty(\PHPPE\View::menu(), "Menu"); $o = \PHPPE\Core::$core->output; \PHPPE\Core::$core->output = "ncurses"; $o = trim(\PHPPE\View::e('D', "message", "module")); $this->assertEquals("module-D: message" . chr(27) . "[0m", $o, "error string #1"); \PHPPE\Core::$core->output = "html"; $this->assertEquals("<span style='background:#F00000;color:#FEA0A0;padding:3px;'>E-module: ["message"]</span>", trim(\PHPPE\View::e('E', ["message"], "module")), "error string #2"); \PHPPE\Core::$core->output = $o; $this->assertEquals("aaa\n<!include test2>\nbbb\n", \PHPPE\View::get("test1"), "Raw template file"); \PHPPE\DS::close(); $ds = new \PHPPE\DS("sqlite::memory:"); \PHPPE\DS::exec("UPDATE views SET css='[\"a.css\"]' WHERE id='simple'"); $this->assertNotEmpty(\PHPPE\View::get("simple"), "Raw template db"); \PHPPE\DS::exec("UPDATE views SET css='' WHERE id='simple'"); }
public function edit() { $t = $this; $a = $t->attrs; $b = 'o.className=o.className.replace(" errinput","")'; View::js('pe_oe(o)', "{$b};if(o.value!=''&&o.value.match(/^.+\\@(\\[?)[a-z0-9\\-\\.]+\\.([a-z]{2,3}|[0-9]{1,3})(\\]?)\$/i)==null)o.className+=' errinput';"); return '<input' . @View::v($t, $a[1], '', $t->args) . " type='email' onfocus='" . strtr($b, ['o.' => 'this.']) . "' onchange='pe_oe(this);" . (!empty($a[0]) && $a[0] != '-' ? $a[0] : '') . "' value=\"" . htmlspecialchars(trim($t->value)) . '">'; }
/** * 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); }
function action($item) { Core::$core->template = ""; View::js("init()", "pe.extensions.init();", true); }