0251 / 590 837 15
info@a-coding-project.de
;

Seitentyp „Seite bearbeiten“ (CMS)

Heute wird der nächste und wichtigste Teil ins neue Backend übertragen: Das „Seite Bearbeiten“. Zuvor wurde diese Aufgabe von /admin/includes/site-edit.php erledigt. Die neue Datei heißt /system/classes/pageeditpage.php. Sie beinhaltet den alten Quelltext mit kleinen Änderungen:

<?PHP
  class PageEditPage extends Editor{
    function __construct($page){
      $this->page = $page;
    }

    public function display(){
      $template = new Template();
      $template->load("site_edit");
      $page = new Page();
      $page->loadProperties($GLOBALS['db']->EscapeString($_GET['site']));
      if($_POST['save']){
        $oldpage = $page;
        $page->title = $_POST['title'];
        $page->menu = $_POST['menu'];
        $page->meta->description = $_POST['meta-description'];
        $page->meta->keywords = $_POST['meta-keywords'];
        $page->meta->robots = $_POST['meta-robots'];
        $page->alias = $_POST['alias'];
        $page->save();
        $page->editor->save($page,$oldpage);
        Role::clearAccess($page);
        if($_POST['rights']){
          foreach($_POST['rights'] as $right){
            $role = new Role();
            $role->load($right);
            $role->allowAccess($page);
          }
        }
      }
      else if(isset($_POST['menu'])){
        $page->title = $_POST['title'];
        $page->alias = $_POST['alias'];
        $page->menu = $_POST['menu'];
        $page->editor->content = $_POST['content'];
      }
      $template->assign_var("PATH",getSetting("global","global","host")."admin/pageedit.html?site=".$page->alias);
      $template->assign_var("ALIAS",$page->alias);

      if(!isset($_POST['menu'])){
        foreach(Role::getAllRolls() as $role){
          $index = $template->add_loop_item("RIGHTS");
          $template->assign_loop_var("RIGHTS", $index, "LABEL","/");
          $template->assign_loop_var("RIGHTS", $index, "VALUE",$role->ID);
          $template->assign_loop_var("RIGHTS", $index, "NAME",$role->name);
          if($role->canAccess($page)){
            $template->assign_loop_var("RIGHTS", $index, "SELECTED", "selected="1" ");
          }
          else{
            $template->assign_loop_var("RIGHTS", $index, "SELECTED", "");
          }
        }
      }
      else{
        foreach(Role::getAllRolls() as $role){
          $index = $template->add_loop_item("RIGHTS");
          $template->assign_loop_var("RIGHTS", $index, "LABEL","/");
          $template->assign_loop_var("RIGHTS", $index, "VALUE",$role->ID);
          $template->assign_loop_var("RIGHTS", $index, "NAME",$role->name);
          if(isset($_POST['rights']) && in_array($role->ID,$_POST['rights'])){
            $template->assign_loop_var("RIGHTS", $index, "SELECTED", "selected="1" ");
          }
          else{
            $template->assign_loop_var("RIGHTS", $index, "SELECTED", "");
          }
        }
      }
      $index = $template->add_loop_item("MENU");
      $template->assign_loop_var("MENU", $index, "VALUE","0");
      $template->assign_loop_var("MENU", $index, "NAME","-- Kein Men&uuml; --");
      foreach(sys::getMenues($_SESSION['dir']) as $menu){
        $index = $template->add_loop_item("MENU");
        $template->assign_loop_var("MENU", $index, "VALUE",$menu->id);
        $template->assign_loop_var("MENU", $index, "NAME",$menu->name);
        if($_POST['menu'] == $menue->id){
          $template->assign_loop_var("MENU", $index, "SELECTED", "selected="1" ");
        }
        else if($page->menu == $menue->id && !$_POST['menu']){
          $template->assign_loop_var("MENU", $index, "SELECTED", "");
        }
      }
      if($_POST['menu']){
        $template->assign_var("MENUPREVIEW",Menu::getCode($_POST['menu'],"<ul>","</ul>","<li>","</li>",""));
      }
      else if($page->menu > 0){
        $template->assign_var("MENUPREVIEW",Menu::getCode($page->menu,"<ul>","</ul>","<li>","</li>",""));
      }
      else{
        $template->assign_var("MENUPREVIEW","");
      }
      $template->assign_var("METADESCRIPTION",$page->meta->description);
      $template->assign_var("METAKEYWORDS",$page->meta->keywords);
      $template->assign_var("METAROBOTS",$page->meta->robots);
      $template->assign_var("TITLE",$page->title);
      $template->assign_var("EDITOR",$page->editor->getEditableCode());
      $template->output();
    }

   function getHeader(){
    }

    public function getEditableCode(){
      return "<input name="save" type="submit" value="&Auml;ndern" onclick="form.action='".$_SERVER['PHP_SELF']."?".$_SERVER['QUERY_STRING']."' ; target='_self' ; return true" />";
    }

    public function save($newPage,$oldPage){
    }
}
?>

Neben dieser Änderung wurde die Klasse sys verschoben und ein Bug mit den Rechten gelöst. Alle Änderungen stehen in Revision 36.