diff options
author | vincent-peugnet <v.peugnet@free.fr> | 2019-01-02 19:50:28 +0100 |
---|---|---|
committer | vincent-peugnet <v.peugnet@free.fr> | 2019-01-02 19:50:28 +0100 |
commit | afeeafc2a691b661ba2c92250f883fda6bd33392 (patch) | |
tree | 6f596f3cf31c1f62e0463ceff4e17e3541762da5 /app | |
parent | d5a2af69c6d62475c26dc7e9812f9a977e9dfa12 (diff) | |
download | wcms-afeeafc2a691b661ba2c92250f883fda6bd33392.tar.gz wcms-afeeafc2a691b661ba2c92250f883fda6bd33392.zip |
render path check
Diffstat (limited to 'app')
-rw-r--r-- | app/class/application.php | 8 | ||||
-rw-r--r-- | app/class/controllerart.php | 29 | ||||
-rw-r--r-- | app/class/modelart.php | 27 | ||||
-rw-r--r-- | app/fn/fn.php | 45 | ||||
-rw-r--r-- | app/view/templates/backtopbar.php | 2 | ||||
-rw-r--r-- | app/view/templates/edit.php | 4 | ||||
-rw-r--r-- | app/view/templates/editleftbar.php | 3 | ||||
-rw-r--r-- | app/view/templates/updatemerge.php | 9 |
8 files changed, 112 insertions, 15 deletions
diff --git a/app/class/application.php b/app/class/application.php index f4b2a84..926db20 100644 --- a/app/class/application.php +++ b/app/class/application.php @@ -19,6 +19,9 @@ class Application } else { Config::hydrate($_POST['configinit']); } + if(!is_dir(Model::RENDER_DIR)) { + mkdir(Model::RENDER_DIR); + } if(!Config::savejson()) { echo 'Cant write config file'; exit; @@ -37,7 +40,7 @@ class Application } else { if(Config::readconfig()) { - if(!Config::checkbasepath() || empty(Config::arttable())) { + if(!Config::checkbasepath() || empty(Config::arttable()) || !is_dir(Model::RENDER_DIR)) { echo '<ul>'; if(!Config::checkbasepath()) { echo '<li>Wrong path</li>'; @@ -45,6 +48,9 @@ class Application if(empty(Config::arttable())) { echo '<li>Unset table name</li>'; } + if(!is_dir(Model::RENDER_DIR)) { + echo '<li>Render path not existing</li>'; + } echo '</ul>'; $this->configform(); exit; diff --git a/app/class/controllerart.php b/app/class/controllerart.php index f292975..0ef82da 100644 --- a/app/class/controllerart.php +++ b/app/class/controllerart.php @@ -9,6 +9,8 @@ class Controllerart extends Controller protected $fontmanager; protected $mediamanager; + const COMBINE = true; + public function __construct($router) { parent::__construct($router); @@ -124,8 +126,8 @@ class Controllerart extends Controller $faviconlist = $this->mediamanager->listfavicon(); $idlist = $this->artmanager->list(); - - $artlist = $this->artmanager->getlister(); + + $artlist = $this->artmanager->getlister(); $tagartlist = $this->artmanager->tagartlist($this->art->tag('array'), $artlist); $lasteditedartlist = $this->artmanager->lasteditedartlist(5, $artlist); @@ -165,7 +167,7 @@ class Controllerart extends Controller $defaultbody = $defaultart->body(); } } - if(empty(Config::defaultart()) || $defaultart === false) { + if (empty(Config::defaultart()) || $defaultart === false) { $defaultbody = Config::defaultbody(); } $this->art->setbody($defaultbody); @@ -204,7 +206,7 @@ class Controllerart extends Controller $_SESSION['workspace']['showrightpanel'] = isset($_POST['workspace']['showrightpanel']); $_SESSION['workspace']['showleftpanel'] = isset($_POST['workspace']['showleftpanel']); - if(!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { + if (!empty($_POST['fontsize']) && $_POST['fontsize'] !== Config::fontsize()) { Config::setfontsize($_POST['fontsize']); Config::savejson(); } @@ -215,18 +217,27 @@ class Controllerart extends Controller $date = ['date' => $date]; if ($this->importart() && $this->canedit()) { + + $oldart = clone $this->art; $this->art->hydrate($_POST); + + if (self::COMBINE) { + if ($_POST['thisdatemodif'] === $oldart->datemodif('string')) { + $compare = $this->artmanager->combine($this->art, $oldart); + if (!empty($compare['diff'])) { + $this->art->hydrate($compare['mergeart']); + } + } + } $this->art->hydrate($date); $this->art->updateedited(); $this->art->addauthor($this->user->id()); $this->artmanager->update($this->art); + $this->routedirect('artedit', ['art' => $this->art->id()]); + + //$this->showtemplate('updatemerge', $compare); } - - $this->routedirect('artedit', ['art' => $this->art->id()]); - - - } public function artdirect($id) diff --git a/app/class/modelart.php b/app/class/modelart.php index f80826a..0cb9b1c 100644 --- a/app/class/modelart.php +++ b/app/class/modelart.php @@ -99,6 +99,33 @@ class Modelart extends Modeldb $this->repo->store($artdata); } + public function combine(Art2 $arta, Art2 $artb) + { + $mergeart = $arta; + $merge = []; + $diff = []; + foreach ($arta::TABS as $element) { + if($arta->$element() !== $artb->$element()) { + $merge[$element] = compare($arta->$element(), $artb->$element()); + $diff[] = $element; + } + } + $mergeart->hydrate($merge); + + return ['diff' => $diff, 'mergeart' => $mergeart]; + } + + // public function diffartelement(Art2 $arta, Art2 $artb) + // { + // $diff = []; + // foreach ($arta::TABS as $element) { + // if($arta->$element() !== $artb->$element()) { + // $diff[] = $element; + // } + // } + // return $diff; + // } + public function artcompare($art1, $art2, $method = 'id', $order = 1) { $result = ($art1->$method('sort') <=> $art2->$method('sort')); diff --git a/app/fn/fn.php b/app/fn/fn.php index 99e1bc0..dfee01d 100644 --- a/app/fn/fn.php +++ b/app/fn/fn.php @@ -133,5 +133,50 @@ function changekey($array, $oldkey, $newkey) +function compare($stringa, $stringb) +{ + $arraya = explode(PHP_EOL, $stringa); + $arrayb = explode(PHP_EOL, $stringb); + + $lnb = -1; + $commonlines = []; + foreach ($arraya as $na => $linea) { + $found = false; + foreach ($arrayb as $nb => $lineb) { + if($linea === $lineb && $nb > $lnb && !$found && !empty($linea)) { + $commonlines[$na] = $nb; + $merge[] = $arrayb[$nb]; + $lnb = $nb; + $found = true; + } + } + } + + + $merge = []; + $lnb = 0; + foreach ($arraya as $na => $linea) { + if(array_key_exists($na, $commonlines)) { + for ($j=$lnb; $j <= $commonlines[$na]; $j++) { + $merge[] = $arrayb[$j]; + } + $lnb = $j; + } else { + $merge[] = $arraya[$na]; + } + } + for ($k=$lnb; ; $k++) { + if(array_key_exists($k, $arrayb)) { + $merge[] = $arrayb[$k]; + } else { + break; + } + } + + return implode(PHP_EOL, $merge); +} + + + ?>
\ No newline at end of file diff --git a/app/view/templates/backtopbar.php b/app/view/templates/backtopbar.php index 1243a17..91a2a2c 100644 --- a/app/view/templates/backtopbar.php +++ b/app/view/templates/backtopbar.php @@ -22,7 +22,7 @@ <?php } else { ?> <span> -<?= $user->level() ?> +<?= $user->id() ?> <i><?= $user->level() ?></i> </span> diff --git a/app/view/templates/edit.php b/app/view/templates/edit.php index 415fcce..c220678 100644 --- a/app/view/templates/edit.php +++ b/app/view/templates/edit.php @@ -10,10 +10,6 @@ <body> <main class="editor"> - <!-- <?php $this->insert('navart', ['user' => $user, 'art' => $art, 'artexist' => $artexist]) ?> --> - - - <?php $this->insert('edittopbar', ['art' => $art, 'user' => $user]) ?> <div id="workspace"> diff --git a/app/view/templates/editleftbar.php b/app/view/templates/editleftbar.php index 8cd6509..3cc747a 100644 --- a/app/view/templates/editleftbar.php +++ b/app/view/templates/editleftbar.php @@ -2,6 +2,9 @@ <input id="showleftpanel" name="workspace[showleftpanel]" value="1" class="toggle" type="checkbox" <?= $showleftpanel == true ? 'checked' : '' ?>> <label for="showleftpanel" class="toogle">◧</label> <div id="leftbarpanel" class="panel"> + + <input type="hidden" name="thisdatemodif" value="<?= $art->datemodif('string') ?>"> + <details id="editinfo" open> <summary>Infos</summary> <fieldset> diff --git a/app/view/templates/updatemerge.php b/app/view/templates/updatemerge.php new file mode 100644 index 0000000..f9d29bf --- /dev/null +++ b/app/view/templates/updatemerge.php @@ -0,0 +1,9 @@ +<?php + + +foreach ($diff as $element) { + echo '<h2>' . $element . '</h2>'; + echo '<textarea style="width: 100%; max-width: 600px; height: 300px;">' . $mergeart->$element() . '</textarea>'; +} + +?>
\ No newline at end of file |