diff --git a/app/private/lib/SimpleConfigHelper.php b/app/private/lib/SimpleConfigHelper.php new file mode 100644 index 0000000..175417d --- /dev/null +++ b/app/private/lib/SimpleConfigHelper.php @@ -0,0 +1,71 @@ +memcached = new Memcached(); + $this->memcached->addServer('memcached', 11211); + $this->dao = GlobalVariables::get("dao"); + + $this->reload(); + } + + public function hasValue(string $name) : bool { + return property_exists($this->config, $name); + } + + public function getValue(string $name) { + return $this->config->$name; + } + + public function setValue(string $name, $val) { + $model = $this->dao->getFirst(SimpleConfig::class); + $model->details->$name = $val; + $this->dao->save($model); + $this->reload($model); + } + + + + private function reload($model = null) { + if (!is_null($model)) { + $this->memcached->set($this->getCacheKey(), json_encode($model->details, JSON_FORCE_OBJECT)); + } + else if ( !$this->isCached() ) { + $model = $this->dao->getFirst(SimpleConfig::class); + if (is_null($model)) { + $model = new SimpleConfig(); + $this->dao->save($model); + } + $this->memcached->set($this->getCacheKey(), json_encode($model->details, JSON_FORCE_OBJECT)); + } + + $rval = $this->memcached->get( + $this->getCacheKey() + ); + $this->config = json_decode($rval, false); + } + + private function getCacheKey() { + return 'glob.fdn2.simpleConfig'; + } + + private function isCached(): bool { + return $this->memcached->get( $this->getCacheKey() ) ? true : false; + } + + private function flush() { + $this->memcached->set( $this->getCacheKey(), false ); + } + + +} + + +?> \ No newline at end of file diff --git a/app/private/lib/dao/lib.inclusion.php b/app/private/lib/dao/lib.inclusion.php index a37a644..6bea8af 100644 --- a/app/private/lib/dao/lib.inclusion.php +++ b/app/private/lib/dao/lib.inclusion.php @@ -45,6 +45,8 @@ require_once(dirname(__FILE__)."/models/stats/ArticleStatsModel.php"); require_once(dirname(__FILE__)."/models/stats/BannerStatsModel.php"); require_once(dirname(__FILE__)."/models/stats/PageViewStatsModel.php"); +require_once(dirname(__FILE__)."/models/SimpleConfig.php"); + $dao = new GenericDao($database->dbName,$database->connectionString); GlobalVariables::set("dao", $dao); ?> diff --git a/app/private/lib/dao/models/NotiziaModel.php b/app/private/lib/dao/models/NotiziaModel.php index 0532d0b..fd7a846 100644 --- a/app/private/lib/dao/models/NotiziaModel.php +++ b/app/private/lib/dao/models/NotiziaModel.php @@ -47,6 +47,8 @@ class NotiziaModel extends HasMediaModel implements DaoSearchable{ const CATEGORY_CONSIGLI_ESPERTI = 18; const CATEGORY_MONDO_SPOSI = 19; + + const CATEGORY_VARIE = 99; public static $NOTIZIE_CATEGORY = array( self::CATEGORY_POLITICA=>array("label"=>"Politica","mainMenu"=>true,"hidden"=>false,"pages"=>array("list"=>"politica.php"),"color"=>"#3e3e3e","isSubmenu"=>null), @@ -69,6 +71,8 @@ class NotiziaModel extends HasMediaModel implements DaoSearchable{ self::CATEGORY_CONSIGLI_ESPERTI=>array("label"=>"I consigli degli esperti","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"consigliEsperti.php"),"color"=>"#3e3e3e","isSubmenu"=>null), self::CATEGORY_MONDO_SPOSI=>array("label"=>"Mondo Sposi","mainMenu"=>false, "hidden"=>false,"pages"=>array("list"=>"mondoSposi.php"),"color"=>"#dd603a","isSubmenu"=>null), + + self::CATEGORY_VARIE=>array("label"=>"Varie","mainMenu"=>false, "hidden"=>true,"pages"=>array("list"=>"varie.php"),"color"=>"#dd603a","isSubmenu"=>null), ); public function __construct($saveableObject = null){ diff --git a/app/private/lib/dao/models/SimpleConfig.php b/app/private/lib/dao/models/SimpleConfig.php new file mode 100644 index 0000000..ed4da7f --- /dev/null +++ b/app/private/lib/dao/models/SimpleConfig.php @@ -0,0 +1,26 @@ +hasProperty("data") || !is_object($this->details)) { + $this->details = new stdClass(); + } + } + + public static function getCollectionName(){ + return "simpleConfig"; + } + +} + + +?> \ No newline at end of file diff --git a/app/private/lib/gui/MenuGenerator.php b/app/private/lib/gui/MenuGenerator.php index 228241b..b48d7b3 100644 --- a/app/private/lib/gui/MenuGenerator.php +++ b/app/private/lib/gui/MenuGenerator.php @@ -47,7 +47,9 @@ class MenuGenerator { array("label"=>"Config","page"=>"editConfig.php","requires"=>AdminModel::ADMIN_TYPE_SUPERADMIN), array("label"=>"Logs","page"=>"logs.php","requires"=>AdminModel::ADMIN_TYPE_SUPERADMIN) )), - + + array("label"=>"Config","page"=>"simpleConfig.php"), + array("label"=>"Guida","page"=>"index.php"), array("label"=>"Logout","page"=>"logout.php") diff --git a/app/private/lib/lib.inclusions.php b/app/private/lib/lib.inclusions.php index e8b96e8..32be6d0 100644 --- a/app/private/lib/lib.inclusions.php +++ b/app/private/lib/lib.inclusions.php @@ -48,5 +48,8 @@ require_once(dirname(__FILE__)."/BannerHelper.php"); require_once(dirname(__FILE__)."/RSSHelper.php"); +require_once(dirname(__FILE__)."/SimpleConfigHelper.php"); + +GlobalVariables::set("cfg", new SimpleConfigHelper()); ?> \ No newline at end of file diff --git a/app/public/admin/simpleConfig.php b/app/public/admin/simpleConfig.php new file mode 100644 index 0000000..30555e4 --- /dev/null +++ b/app/public/admin/simpleConfig.php @@ -0,0 +1,69 @@ +hasRole(AdminModel::ADMIN_TYPE_NORMALADMIN)){ + GUIHandler::redirect("admin/index.php"); +} + +MenuGenerator::generateMenu(); + +HTMLHelper::generateAdminHead(); + +$saved = false; +$action = PostHandler::get("action"); +if (!is_null($action) && strcmp("", $action)!=0){ + if (strcmp("save", $action)==0){ + + if (PostHandler::get(SimpleConfig::VARIE_LABEL)) { + GlobalVariables::get("cfg")->setValue(SimpleConfig::VARIE_LABEL, PostHandler::get(SimpleConfig::VARIE_LABEL)); + } + + $saved = true; + } +} + +?> +