From afeeafc2a691b661ba2c92250f883fda6bd33392 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Wed, 2 Jan 2019 19:50:28 +0100 Subject: render path check --- app/class/application.php | 8 ++++++- app/class/controllerart.php | 29 ++++++++++++++++-------- app/class/modelart.php | 27 +++++++++++++++++++++++ app/fn/fn.php | 45 ++++++++++++++++++++++++++++++++++++++ app/view/templates/backtopbar.php | 2 +- app/view/templates/edit.php | 4 ---- app/view/templates/editleftbar.php | 3 +++ app/view/templates/updatemerge.php | 9 ++++++++ 8 files changed, 112 insertions(+), 15 deletions(-) create mode 100644 app/view/templates/updatemerge.php 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 ''; $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 @@ -level() ?> +id() ?> level() ?> 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 @@
- - - - insert('edittopbar', ['art' => $art, 'user' => $user]) ?>
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 @@ >
+ + +
Infos
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 @@ +' . $element . ''; + echo ''; +} + +?> \ No newline at end of file -- cgit v1.2.3