Exemplo n.º 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);
 }
Exemplo n.º 2
0
 function load(&$app)
 {
     //! load global dds as well from frame
     $frame = new Page("frame");
     $page = View::getval("page");
     $page->gdds = $frame->dds;
 }
Exemplo n.º 3
0
 function load(&$app)
 {
     if (!is_array($this->value)) {
         $page = View::getval("page");
         if (!empty($page->data['meta'])) {
             $this->value = $page->data['meta'];
         }
     }
     if (!is_array($this->value)) {
         $this->value = [];
     }
 }
Exemplo n.º 4
0
 public function edit()
 {
     $t = $this;
     $a = $t->attrs;
     $b = $t->args;
     $opts = !empty($a[0]) && $a[0] != '-' ? View::getval($a[0]) : [];
     if (is_string($opts)) {
         $opts = str_getcsv($opts, ',');
     }
     $skip = !empty($a[1]) && $a[1] != '-' ? View::getval($a[1]) : [];
     if (is_string($skip)) {
         $skip = str_getcsv($skip, ',');
     }
     if (!is_array($skip)) {
         $skip = [];
     } else {
         $skip = array_flip($skip);
     }
     if (!empty($b[1])) {
         $t->name .= '[]';
     }
     $r = '<select' . @View::v($t, $a[3], $a[2], [], '', '', !empty($b[1]) ? '[]' : '') . (!empty($b[1]) ? ' multiple' : '') . (!empty($b[0]) && $b[0] > 0 ? " size='" . intval($b[0]) . "'" : '') . " onfocus='this.className=this.className.replace(\" errinput\",\"\")'>";
     if (is_array($opts)) {
         foreach ($opts as $k => $v) {
             $o = is_array($v) && isset($v['id']) ? $v['id'] : (is_object($v) && isset($v->id) ? $v->id : $k);
             $n = is_array($v) && !empty($v['name']) ? $v['name'] : (is_object($v) && !empty($v->name) ? $v->name : (is_string($v) ? $v : $k));
             if (!isset($skip[$o]) && !empty($n)) {
                 $r .= '<option value="' . htmlspecialchars($o) . '"' . (is_array($t->value) && in_array($o . '', $t->value) || $o == $t->value ? ' selected' : '') . '>' . $n . '</option>';
             }
         }
     }
     $r .= '</select>';
     return $r;
 }
Exemplo n.º 5
0
 function show()
 {
     return View::_t(substr($this->name, 0, 6) == "frame." ? @View::getval("frame")[substr($this->name, 6)] : $this->value);
 }
Exemplo n.º 6
0
 function save($params)
 {
     $page = View::getval("page");
     $page->setParameter($this->name, str_getcsv($params['value'], ',')[0]);
     return $page->save();
 }
Exemplo n.º 7
0
 function edit()
 {
     View::jslib("setsel.js", "pe.setsel.search('" . addslashes($this->fld) . "');");
     View::css("setsel.css");
     $out = [0 => "", 1 => ""];
     $a = $this->attrs;
     $opts = !empty($a[0]) && $a[0] != "-" ? View::getval($a[0]) : [];
     if (is_string($opts)) {
         $opts = str_getcsv($opts, ",");
     }
     if (!is_array($opts)) {
         $opts = "";
     }
     if (is_string($this->value)) {
         $val = explode(",", $this->value);
     } elseif (isset($this->value[0]['id'])) {
         $val = [];
         foreach ($this->value as $k => $v) {
             $val[$k] = $v['id'];
         }
     } else {
         $val = $this->value;
     }
     if (empty($val)) {
         $val = [];
     }
     $i = @array_flip($val);
     $b = [];
     if (!empty($this->args[2])) {
         if (!is_array($this->args[2])) {
             $f = @array_flip(explode(",", $this->args[2]));
         } else {
             $f = $this->args[2];
         }
     } else {
         $f = [];
     }
     $flt = [];
     $filters = [];
     $idx = [];
     foreach ($f as $k => $v) {
         $d = explode(":", $k);
         if (!empty($d[1])) {
             $filters[$d[0]] = $v;
             $idx[$d[0]] = $d[1];
         } else {
             $filters[$d[0]] = $v;
         }
     }
     foreach ($opts as $k => $v) {
         $id = $k;
         $name = $v;
         $title = "";
         $blk = "<div";
         $rep = !empty($this->args[3]) ? $this->args[3] : "%name%";
         $rep = str_ireplace("%KEY%", $k, $rep);
         if (is_array($v) || is_object($v)) {
             foreach ($v as $K => $V) {
                 if (isset($filters[$K])) {
                     $flt[$K][$V] = !empty($idx[$K]) && !empty($v[$idx[$K]]) ? $v[$idx[$K]] : $V;
                 }
                 if (!is_scalar($V)) {
                     continue;
                 }
                 $rep = str_ireplace("%" . $K . "%", $V . "", $rep);
                 if (!empty($this->args[5]) && $K == trim($this->args[5])) {
                     $title = $V;
                 }
                 if ($K == "name") {
                     $name = $V;
                 } else {
                     if ($K == "id") {
                         $id = $V;
                     } else {
                         $blk .= " data-" . $K . "=\"" . htmlspecialchars($V) . "\"";
                     }
                 }
             }
         } else {
             $rep = str_ireplace("%VALUE%", $v, $rep);
         }
         $blk .= " class='setsel_item" . (!empty($this->args[0]) && isset($i[$id]) ? " setsel_itemactive" : "") . (!empty($a[2]) && $a[2] != "-" ? " " . $a[2] : "") . "'";
         if ($title) {
             $blk .= " title='" . htmlspecialchars($title) . "'";
         }
         $blk .= " data-id='" . htmlspecialchars($id) . "' draggable='false' onmousedown='return pe.setsel." . (empty($this->args[0]) ? "drag" : "select") . "(event,\"" . $this->fld . "\");':display>" . $rep . "</div>";
         if (isset($i[$id])) {
             $b[$i[$id]] = str_replace(":display", "", $blk);
         }
         $blk = str_replace(":display", empty($this->args[0]) && isset($i[$id]) ? " data-inlist='1' style='display:none;'" : "", $blk);
         if (empty($this->args[0]) || !isset($i[$id])) {
             $out[1] .= $blk;
         } else {
             $out[1] = $blk . $out[1];
         }
     }
     if (empty($this->args[0])) {
         ksort($b);
     } else {
         $out[1] .= "<div class='setsel_item" . (!empty($this->args[0]) && empty($b) ? " setsel_itemactive" : "") . (!empty($a[2]) && $a[2] != "-" ? " " . $a[2] : "") . "' data-id='' onmousedown='return pe.setsel.select(event,\"" . $this->fld . "\");' style='text-align:center;font-style:italic;'>&nbsp;*&nbsp;" . L("None") . "&nbsp;*</div>";
     }
     if (isset($flt['lang'])) {
         unset($flt['lang']);
         foreach ($_SESSION['pe_ls'] as $l => $v) {
             $flt['lang'][$l] = $l . " " . L($l);
         }
     }
     $flthtml = !empty($a[3]) ? $a[3] : "";
     foreach ($filters as $f => $v) {
         if ($f) {
             $flthtml .= "<select class='setsel_input' name='" . $f . "' onchange='pe.setsel.search(\"" . $this->fld . "\");' style='margin-right:5px;'><option value=''>*</option>";
             if (is_array($flt[$f])) {
                 foreach ($flt[$f] as $F => $V) {
                     if (!empty($F) && !empty($V)) {
                         $flthtml .= "<option value=\"" . htmlspecialchars($F) . "\"" . (@$_REQUEST['setsel_' . $f] == $F ? " selected" : "") . ">" . L($V) . "</option>";
                     }
                 }
             }
             $flthtml .= "</select>";
         }
     }
     $out[0] = implode("", $b);
     return "<div class='setsel'><input type='hidden' id='" . $this->fld . "' name='" . $this->fld . "' value='" . htmlspecialchars(@implode(",", $val)) . "'>" . "<div id='" . $this->fld . ":filters' class='setsel_filters'>" . (!empty($this->args[4]) ? "<span class='setsel_title' style='float:left;line-height:22px !important;'>" . $this->args[4] . "</span>" : "") . $flthtml . "<input name='search' class='setsel_input' type='text' placeholder='" . L("Search") . "' onchange='pe.setsel.search(\"" . $this->fld . "\");' onkeyup='pe.setsel.search(\"" . $this->fld . "\");'>" . "<span style='font-size:20px;padding-left:5px;padding-right:5px;'>⌕</span><br style='clear:both;'/></div>\n" . "<div class='" . $this->css . " " . (!empty($a[1]) && $a[1] != "-" ? $a[1] : "") . " setsel_box' onmouseup=\"pe.dnd.drop(event,pe.setsel.remove);\" id='" . $this->fld . ":all' style='height:" . intval(!empty($this->args[1]) ? $this->args[1] : 128) . "px;" . (!empty($this->args[0]) ? "width:100% !important;" : "") . "box-sizing:border-box;overflow:auto;'>" . $out[1] . "</div>" . (empty($this->args[0]) ? "<div class='" . $this->css . " " . (!empty($a[1]) && $a[1] != "-" ? $a[1] : "") . " setsel_box' onmouseover='pe.setsel.droparea(event);' onmouseup=\"pe.dnd.drop(event,pe.setsel.add);\" id='" . $this->fld . ":inlist' style='height:" . intval(!empty($this->args[1]) ? $this->args[1] : 128) . "px;padding-bottom:64px;box-sizing:border-box;overflow:auto;'>" . $out[0] . "</div>" : "") . "</div>";
 }
Exemplo n.º 8
0
 /**
  * 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;
 }