Пример #1
0
 function load(&$app)
 {
     //! load languages
     $app->langs[''] = "*";
     foreach (!empty($_SESSION['pe_ls']) ? $_SESSION['pe_ls'] : ['en' => 1] as $l => $v) {
         $app->langs[$l] = L($l);
     }
     //! get views from database
     $rec = Views::find([], "sitebuild=''", "id", "id,name");
     foreach ($rec as $r) {
         $app->layouts[$r['id']] = $r['name'];
     }
     foreach (glob("app/views/*.tpl") as $view) {
         $w = str_replace(".tpl", "", basename($view));
         if ($w != "frame") {
             $app->layouts[$w] = ucfirst($w);
         }
     }
     unset($rec);
     //! add current template if it's not there
     $page = View::getval("page");
     if (empty($app->layouts[$page->template])) {
         $app->layouts[$page->template] = L($page->template) == $page->template ? ucfirst($page->template) : L($page->template);
     }
     ksort($app->layouts);
 }
Пример #2
0
 /**
  * default action
  */
 function action($item)
 {
     //! create a fake page parameter
     $name = "layoutadd";
     $_SESSION['cms_param'][sha1("layoutadd_")] = new \PHPPE\AddOn\layoutadd([], $name, $name);
     //! if layout not given
     if (empty($item)) {
         //! check if we have to activate a sitebuild
         if (!empty($_REQUEST['set'])) {
             DS::exec("UPDATE " . Views::$_table . " SET id=sitebuild WHERE sitebuild!='' AND id='frame'");
             DS::exec("UPDATE " . Views::$_table . " SET id='frame' WHERE sitebuild=?", trim($_REQUEST['set']));
             Http::redirect();
         }
         //! load layouts and sitebuilds
         $this->layouts = Views::find([], "sitebuild=''", "name");
         $this->sitebuilds = Views::find([], "sitebuild!=''", "name");
     } else {
         //! load layout
         $this->layout = new Views($item);
         if (!empty($this->layout->jslib)) {
             foreach ($this->layout->jslib as $j) {
                 View::jslib($j);
             }
         }
         if (!empty($this->layout->css)) {
             foreach ($this->layout->css as $c) {
                 View::css($c);
             }
         }
         $this->numPages = Page::getNum($item);
         //! get user input
         $layout = Core::req2arr("layout");
         //! merge the new data with the loaded layout's properties
         if (!empty($this->layout->sitebuild) && !empty($layout)) {
             Core::$core->noframe = 1;
             $layout['sitebuild'] = $layout['id'];
         }
         if (Core::isTry("layout")) {
             //! delete a layout
             if (!empty($layout['delete'])) {
                 $this->layout->delete();
             } else {
                 unset($layout['delete']);
                 //! renamed?
                 if ($this->layout->id != $layout['id']) {
                     DS::exec("UPDATE " . Views::$_table . " SET id=? WHERE id=?", [$layout['id'], $this->layout->id]);
                     Core::log('A', sprintf("Layout %s renamed to %s by %s", $this->layout->id, $layout['id'], Core::$user->name), "cmsaudit");
                 }
                 //! save new data
                 foreach ($layout as $k => $v) {
                     $this->layout->{$k} = $v;
                 }
                 $this->layout->save();
             }
             Http::redirect("cms/layouts");
         }
     }
 }
Пример #3
0
 /**
  * default action, loaded via AJAX
  */
 function action($item)
 {
     //! available tags
     $list = ["/form" => "*variable [url [onsubmitjs", "/if" => "*expression", "else" => "*", "/foreach" => "*dataset", "/template" => "*", "include" => "*view", "app" => "*", "dump" => "variable", "cms" => "*addon ) variable", "=" => "expression", "L" => "label", "date" => "expression", "time" => "expression", "difftime" => "expression", "var" => "*addon ) variable", "field" => "*addon ) variable", "widget" => "*addon ) variable"];
     //! Add-Ons
     $d = array_merge(get_declared_classes(), array_keys(ClassMap::$map));
     foreach ($d as $c) {
         if (strtolower(substr($c, 0, 12)) == "phppe\\addon\\") {
             $F = new $c([], "dummy", $c, []);
             if (isset($F->conf) && $F->conf != "*") {
                 $list["_" . strtolower(substr($c, 12))] = $F->conf;
             }
             unset($F);
         }
     }
     if (!empty($item)) {
         //! edit form
         $acl = $widget = "";
         $req = $needsel = 0;
         if (substr($item, 0, 2) != "<!") {
             die(View::e("E", L("Unknown tag")));
         } else {
             $d = "";
             $c = "";
             foreach ($list as $k => $v) {
                 if ($k[0] == "_") {
                     continue;
                 }
                 if (substr($item, 2, strlen($k)) == $k || "/" . substr($item, 2, strlen($k) - 1) == $k) {
                     $d = $k[0] == "/" ? substr($k, 1) : $k;
                     $c = $v[0] == '*' ? substr($v, 1) : $v;
                 }
             }
             if (empty($d)) {
                 die(View::e("E", L("Unknown tag")));
             }
             if ($d == "=") {
                 $d = "eval";
                 $a = [substr($item, 3, strlen($item) - 4)];
             } else {
                 $a = str_getcsv(preg_replace("/[\\ ]+/", " ", strtr(substr($item, 2, strlen($item) - 3), ["(," => " - ", "(" => " ", ")" => " )", ",," => " - ", "," => " "])), " ");
                 array_shift($a);
             }
             if (substr($c, 0, 5) == "addon") {
                 if (@$a[0][0] == "@") {
                     $acl = substr($a[0], 1);
                     array_shift($a);
                 }
                 if (@$a[0][0] == "*") {
                     $req = 1;
                     $a[0] = substr($a[0], 1);
                 }
                 $widget = array_shift($a);
                 if (empty($widget)) {
                     $widget = "hidden";
                 }
                 $needsel = 1;
             }
             echo "<b>" . L(!empty($widget) && !empty(Core::$l[$widget]) ? $widget : "help_" . $d) . "</b><br/>\n<div id='tageditor' style='padding:5px;'><input type='hidden' name='tag' value='" . htmlspecialchars($d) . "'>\n";
             if (substr($c, 0, 5) == "addon") {
                 $t = $d == "cms" ? L("Show value") : L("Required value");
                 echo "<input type='checkbox' class='input' name='required' onchange='pe.cms.settag(\"tageditor\");' title=\"" . htmlspecialchars($t) . "\" value='*'" . ($req ? " checked" : "") . ">\n";
                 echo "<select class='input' name='widget' onchange='pe.cms.settag(\"tageditor\");pe.wyswyg.popup(event,\"layout_data\",\"cms/tag?item=" . urlencode("<!" . $d . " " . ($req ? "*" : "")) . "\"+this.value+\">\",true);' onmouseover='pe_w();'>";
                 foreach ($list as $k => $v) {
                     if ($k[0] != "_") {
                         continue;
                     }
                     echo "<option value='" . htmlspecialchars(substr($k, 1)) . "'" . (substr($k, 1) == $widget ? " selected" : "") . " onmouseover='pe_w();'>" . L(substr($k, 1)) . "</option>\n";
                 }
                 echo "</select>\n<input type='text' class='input smallinput' name='acl' onkeydown='if(event.key==\"Enter\"){event.preventDefault();pe_p();}' onkeyup='pe.cms.settag(\"tageditor\");event.preventDefault();' onchange='pe.cms.settag(\"tageditor\");' title=\"" . L("Access filters") . "\" placeholder=\"" . L("Access filters") . "\" value=\"" . htmlspecialchars($acl) . "\" list='filters'>";
                 echo "<datalist id='filters'>";
                 foreach (ClassMap::ace() as $b) {
                     echo "<option value='" . $b . "'>" . L($b) . "</option>";
                 }
                 echo "<option value='siteadm|webadm'>" . L("Administrator") . "</option>";
                 echo "</datalist><br/>\n";
                 $c = @$list["_" . $widget];
             }
             if (empty($c) || @$item[2] == "/") {
                 die(L("Not configurable"));
             }
             if ($c[0] == "*") {
                 $c = substr($c, 1);
             }
             $c = str_getcsv(preg_replace("/[\\ ]+/", " ", strtr($c, ["(" => "( ", ")" => " ) ", "[" => " [ ", "]" => "", "," => " "])), " ");
             if (in_array(")", $c)) {
                 if (!in_array(")", $a)) {
                     array_unshift($a, ")");
                 }
                 array_shift($c);
             }
             if ($c[0] != ")" && in_array(")", $a)) {
                 echo "(<input type='hidden' value='('><br/><div style='padding-left:10px;'>";
             } elseif ($c[0] == ")") {
                 array_shift($c);
             }
             $i = 0;
             $optional = "";
             $f = 1;
             $js = 0;
             foreach ($c as $k => $v) {
                 if ($v == "[") {
                     $optional = " optional";
                     continue;
                 }
                 if ($v == ")") {
                     echo "</div>)<input type='hidden' value=')'><br/>\n";
                     while ($a[$i] != ")" && !empty($a[$i])) {
                         $i++;
                     }
                     $i++;
                     $optional = "";
                     continue;
                 }
                 if (empty($optional) && $f) {
                     $optional = " focus";
                     $f = 0;
                 }
                 switch ($v) {
                     case "":
                         $i++;
                         break;
                     case "view":
                         $views = Views::find([], "sitebuild=''", "id", "id,name");
                         foreach (array_merge(glob("app/views/*.tpl"), glob("vendor/phppe/Core/views/*.tpl")) as $view) {
                             $w = str_replace(".tpl", "", basename($view));
                             if ($w != "frame") {
                                 $views[] = ['id' => $w, 'name' => ucfirst($w)];
                             }
                         }
                         if ($a[$i] == ")") {
                             $i--;
                         }
                         echo "<select class='input" . $optional . "' name='arg" . $k . "' data-type='" . htmlspecialchars($v) . "' " . "onchange='pe.cms.settag(\"tageditor\");' title=\"" . L($v) . "\">";
                         $w = 0;
                         foreach ($views as $view) {
                             echo "<option value='" . htmlspecialchars($view['id']) . "'" . ($view['id'] == $a[$i] ? " selected" : "") . ">" . L($view['name'] ? $view['name'] : $view['id']) . "</option>";
                             if ($view['id'] == $a[$i]) {
                                 $w = 1;
                             }
                         }
                         if (!$w) {
                             echo "<option value='" . htmlspecialchars($a[$i]) . "' selected>" . (!empty($a[$i]) ? L($a[$i]) : "*") . "</option>";
                         }
                         echo "</select>\n";
                         $i++;
                         break;
                     case "min":
                     case "max":
                     case "maxlen":
                     case "rows":
                     case "size":
                     case "picturesize":
                     case "iconheight":
                     case "iconwidth":
                     case "itemheight":
                     case "itemwidth":
                     case "num":
                         echo "<input type='number' class='input" . $optional . "' name='arg" . $k . "' data-type='" . htmlspecialchars($v) . "' " . "onkeyup='pe.cms.settag(\"tageditor\");' onkeydown='if(event.key==\"Enter\"){event.preventDefault();pe_p();}' onchange='pe.cms.settag(\"tageditor\");' title=\"" . L($v) . "\" placeholder=\"" . L($v) . "\" " . "value=\"" . htmlspecialchars(@$a[$i] == ")" ? "" : @$a[$i++]) . "\"><br/>\n";
                         break;
                     default:
                         echo "<input type='text' class='input" . $optional . "' name='arg" . $k . "' data-type='" . htmlspecialchars($v) . "' " . "onkeyup='pe.cms.settag(\"tageditor\");' onkeydown='if(event.key==\"Enter\"){event.preventDefault();pe_p();}' onchange='pe.cms.settag(\"tageditor\");' title=\"" . L($v) . "\" placeholder=\"" . L($v) . "\" " . "value=\"" . htmlspecialchars(@$a[$i] == ")" ? "" : @$a[$i++]) . "\"" . ($v == "label" || $v == "cssclass" || $v == "dataset" || $v == "listopts" ? " list=\"" . ($v == "listopts" ? "dataset" : $v) . "s\"" : (substr($v, -2) == "js" ? " list='jss'" : "")) . "><br/>\n";
                         if (substr($v, -2) == "js" && $js == 0) {
                             //! filled in by JavaScript
                             echo "<datalist id=\"jss\"></datalist>\n";
                             $js = 1;
                         }
                         if ($v == "label" || $v == "cssclass") {
                             //! filled in by JavaScript
                             echo "<datalist id=\"" . $v . "s\"></datalist>\n";
                         }
                         if ($v == "dataset" || $v == "listopts") {
                             echo "<datalist id=\"datasets\">\n";
                             $pages = Page::find([], "", "created DESC", "dds", "id");
                             $dds = [];
                             foreach ($pages as $p) {
                                 $g = @json_decode(@$p['dds'], true);
                                 if (!empty($g) && is_array($g)) {
                                     foreach ($g as $G => $w) {
                                         $dds[$G] = $G;
                                     }
                                 }
                             }
                             ksort($dds);
                             foreach ($dds as $G) {
                                 echo "<option value=\"" . htmlspecialchars($G) . "\">" . L($G) . "</option>";
                             }
                             echo "</datalist>\n";
                         }
                 }
                 if ($optional == "focus") {
                     $optional = "";
                 }
             }
         }
         die("</div>\n<small>" . L(!empty(Core::$l['_' . $d]) ? '_' . $d : "") . "</small>");
     } else {
         // tag chooser
         $onlywidget = strpos($_SERVER['HTTP_REFERER'], "/cms/layouts/") === false;
         echo "<input type='text' style='width:98%;' placeholder='" . L("Search") . "' onkeyup='pe.wyswyg.search(this,this.nextSibling);'>";
         echo "<div class='wyswyg_tag wyswyg_scroll'>\n";
         foreach ($list as $tag => $cfg) {
             if ($cfg[0] == '*' && $onlywidget) {
                 continue;
             }
             if (substr($tag, 0, 1) == "_") {
                 $tag = ($onlywidget ? "widget" : "field") . " " . substr($tag, 1);
             } else {
                 if (substr($tag, 0, 1) == "/") {
                     echo "<img class='wyswyg_icon' src='js/wyswyg.js.php?item=" . urlencode("<!" . substr($tag, 1) . ">") . "' alt=\"" . strtr("<!" . substr($tag, 1) . ">", ["<" => "&lt;", ">" => "&gt;", "\"" => "&quot;"]) . "\">\n";
                 }
             }
             echo "<img class='wyswyg_icon' src='js/wyswyg.js.php?item=" . urlencode("<!" . $tag . ">") . "' alt=\"" . strtr("<!" . $tag . ">", ["<" => "&lt;", ">" => "&gt;", "\"" => "&quot;"]) . "\">\n";
         }
         die("</div>");
     }
 }
Пример #4
0
 /**
  * default action, loaded via AJAX
  */
 function action($item)
 {
     //! assets
     if (!empty($_REQUEST['assetn'])) {
         list($d, $f) = explode("/", $_REQUEST['assetn']);
         $fn = ".tmp/" . session_id() . "/" . $d . "/" . $f;
         if (file_exists($fn)) {
             header("Content-type: " . ($d == "i" ? "image/png" : ($d == "c" ? "text/css" : ($d == "j" ? "text/javascript" : "application/octet-stream"))));
             die(file_get_contents($fn) . "");
         }
     }
     //! sitebuild import
     Core::$core->noframe = true;
     $import = Core::req2arr("import");
     //! uncompress uploaded archive
     if (!empty($import['file']['tmp_name'])) {
         @Tools::rmdir(".tmp/" . session_id());
         @mkdir(".tmp/" . session_id() . "/i", 0750, true);
         @mkdir(".tmp/" . session_id() . "/c", 0750, true);
         @mkdir(".tmp/" . session_id() . "/j", 0750, true);
         @mkdir(".tmp/" . session_id() . "/f", 0750, true);
         @mkdir(".tmp/" . session_id() . "/h", 0750, true);
         Tools::untar($import['file']['tmp_name'], function ($name, $body) {
             $fn = "";
             if (substr($name, -4) == ".htm" || substr($name, -5) == ".html") {
                 self::$success = true;
                 $fn = "h/" . basename($name);
             } else {
                 if (in_array(substr($name, -4), [".gif", ".png", ".pnm", ".jpg", ".svg"])) {
                     $fn = "i/" . basename($name);
                 } else {
                     if (in_array(substr($name, -4), [".eot", ".ttf"]) || substr($name, -5) == ".woff" || substr($name, -6) == ".woff2") {
                         $fn = "f/" . basename($name);
                     } else {
                         if (substr($name, -4) == ".css") {
                             $fn = "c/" . basename($name);
                         } else {
                             if (substr($name, -3) == ".js") {
                                 $fn = "j/" . basename($name);
                             }
                         }
                     }
                 }
             }
             if (!empty($fn)) {
                 file_put_contents(".tmp/" . session_id() . "/" . $fn, $body);
             }
         });
         if (!self::$success) {
             Core::error("Bad archive");
             return;
         }
     }
     //! choose a html
     $this->htmls = glob(".tmp/" . session_id() . "/h/*");
     if (count($this->htmls) == 1) {
         $item = 1;
     }
     if (intval($item) > 0 && !empty($this->htmls[$item - 1])) {
         $html = $this->htmls[$item - 1];
         unset($this->htmls);
     }
     if (empty($html)) {
         if (intval($item) > 0) {
             Core::error("Bad archive");
         }
         return;
     }
     //! choose application area
     $data = preg_replace("/<script.*?\\/script>/ims", "", file_get_contents($html));
     $files = glob(".tmp/" . session_id() . "/*/*");
     $assets = ["i" => "images", "c" => "css", "j" => "js", "f" => "fonts"];
     //! replace urls with temporary ones for the uploaded files
     foreach ($files as $f) {
         if (!empty($assets[basename(dirname($f))])) {
             $data = preg_replace("/[^=\\ \t\r\n\\'\",\\(\\[]+" . basename($f) . "/ims", url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f), $data);
         }
         if (basename(dirname($f)) == "c") {
             View::css(url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f));
         } else {
             if (basename(dirname($f)) == "j") {
                 View::jslib(url("cms/sitebuild") . "?assetn=" . basename(dirname($f)) . "/" . basename($f));
             }
         }
     }
     //! get the main application tag
     $this->content = CMS::taghtml($data);
     if (empty($_REQUEST['chooseid']) && preg_match("/(<[^<>]*?id=[\\'\"]?content[^>]*?>)/ims", $this->content, $m) && !empty($m[0]) && preg_match("/data\\-chooseid=[\\'\"]?([0-9]+)/ims", $m[0], $M)) {
         $_REQUEST['chooseid'] = $M[1];
     }
     if (!empty($_REQUEST['chooseid'])) {
         //! replace with <!app>
         $t = CMS::splithtml($this->content, $_REQUEST['chooseid'], 0) . "<!app>" . CMS::splithtml($this->content, $_REQUEST['chooseid'], 2);
         //! replace temporary urls with final ones
         preg_match_all("/[^=\\ \t\r\n\\'\",\\(\\[]+\\?assetn=([a-z])\\/([^=\\ \t\r\n\\'\",\\)\\]]+)/ims", $t, $m, PREG_SET_ORDER);
         foreach ($m as $M) {
             $t = str_replace($M[0], $assets[$M[1]] . "/" . $M[2], $t);
         }
         //! figure out sitebuild name
         $name = strtr(basename($html), [".html" => "", ".htm" => ""]);
         if ($name == "index" || $name == "frame" || $name == "simple" || $name == "default") {
             $name = "sitebuild" . Core::$core->now;
         }
         $views = Views::find($name);
         if (!empty($views)) {
             $name .= Core::$core->now;
         }
         //! save sitebuild
         $view = new Views();
         $view->id = $name;
         $view->name = $name;
         $view->sitebuild = $name;
         $view->data = preg_replace("/<!\\-\\-.*?\\-\\->/ms", "", $t);
         $view->created = date("Y-m-d H:i:s", Core::$core->now);
         foreach ($files as $f) {
             if (empty($assets[basename(dirname($f))])) {
                 continue;
             }
             if (basename(dirname($f)) == "c") {
                 $view->css[] = basename($f);
             }
             if (basename(dirname($f)) == "j") {
                 $view->jslib[] = basename($f);
             }
         }
         if ($view->save(true)) {
             //! copy temporary files to public directory
             foreach ($assets as $k => $v) {
                 chdir(".tmp/" . session_id() . "/" . $k);
                 Tools::copy(glob("*"), "public/" . $v);
                 chdir("../../..");
             }
             //! clean up
             @Tools::rmdir(".tmp/" . session_id());
             //! redirect user to the fresh new sitebuild layout
             Http::redirect("cms/layouts/" . $name);
         }
         Core::error("Unable to save sitebuild!");
     }
 }