diff --git a/attributes/fileset/controller.php b/attributes/fileset/controller.php index 74e5b03..7a362ad 100755 --- a/attributes/fileset/controller.php +++ b/attributes/fileset/controller.php @@ -1,4 +1,4 @@ -select($this->field('value'), $input,$selected); else echo t('No file sets found.'); - } + } -} +} diff --git a/blocks/autonav/templates/supermint_dropdown.php b/blocks/autonav/templates/supermint_dropdown.php index b69881b..e773368 100755 --- a/blocks/autonav/templates/supermint_dropdown.php +++ b/blocks/autonav/templates/supermint_dropdown.php @@ -89,7 +89,7 @@ endif; // Maintenant on va déterminer les classes pour le dropdown - if($ni->cObj->getAttribute('display_multi_columns_drop') || count($ni->blocks)) : + if($ni->cObj->getAttribute('display_multi_columns_drop') || (is_array($ni->blocks) && count($ni->blocks))) : // On prend la valeur de l'option full_width_mega ou si on est en multicolumn, l'option full_width_multicolumn if($ni->cObj->getAttribute('display_multi_columns_drop')) $ni->full_width_mega = $o->full_width_multicolumn; diff --git a/src/Helper/Upgrade.php b/src/Helper/Upgrade.php index 0695553..a0802d8 100644 --- a/src/Helper/Upgrade.php +++ b/src/Helper/Upgrade.php @@ -25,7 +25,7 @@ function upgradePageListTemplates () { if ($block->getBlockTypeHandle() == 'page_list') { $templateName = $block->getBlockFilename(); preg_match("/supermint_(\w+)_(\w+)\.php/",$templateName,$matches); - if (count($matches)) { + if (is_array($matches) && count($matches)) { if ($matches[1] == 'carousel') $this->setBlockClass($block,'is-carousel',$matches[2]); if ($matches[1] == 'static' && $matches[2] == 'block') $this->setBlockClass($block,'',$matches[2]); if ($templateName == 'supermint_recent_post.php') $this->setBlockClass($block,'1-column',false); diff --git a/src/Models/ThemeSupermintOptions.php b/src/Models/ThemeSupermintOptions.php index 4e04c19..02ee5e1 100755 --- a/src/Models/ThemeSupermintOptions.php +++ b/src/Models/ThemeSupermintOptions.php @@ -1,317 +1,326 @@ -init($c); - } - - static function get () { - $session = \Core::make('session'); - return $session->get('supermint.options'); - } - - function init ($c) { - - $this->pkg = Package::getByHandle("theme_supermint"); - $this->pID = $this->get_active_pID(); - - } - function set_collection_object($c) { - $this->init($c); - } - function set_toggle_option_name($name) { - $this->option_name = $name; - } - - function get_presets_list() { - $all = Loader::db()->getAll("SELECT pID, name FROM SupermintOptionsPreset"); - if(is_array($all)) return $all; else return false; - } - function get_preset_by_id ($pID) { - $row = Loader::db()->getRow("SELECT pID, name FROM SupermintOptionsPreset WHERE pID=?", array($pID)); - if(is_array($row)) return $row; else return false; - } - function get_preset_id_from_handle ($pHandle) { - $row = Loader::db()->getRow("SELECT pID FROM SupermintOptionsPreset WHERE name=?", array($pHandle)); - if(isset($row['pID'])) return (int)$row['pID']; else return false; - } - - function output_presets_list ($echo = false, $selected=null, $name = 'preset_id', $before = array()) { - - $list = $this->get_presets_list (); - - if ($list) : - $r[] = ''; - $r = implode("\r" , $r); - - if ($echo) echo $r; - else return $r; - - else: - return false; - endif; - - } - - function update () { - - } - - function save_preset($name, $based_on = false, $active = false, $returnID = false) { - - Loader::db()->query("INSERT INTO SupermintOptionsPreset (name,active) VALUES (?,?)", array($name, $active ? 1 : 0)); - - if ($returnID) return Loader::db()->Insert_ID(); - if ($based_on) : - // Recupere le nouvel ID - $pID = Loader::db()->Insert_ID(); - // Duplique toutes les options qui ont comme presetID $based_on et leur donne un nouvel ID base sur celui qui vient d'etre cr�� - Loader::db()->query("INSERT INTO SupermintOptions (option_key, option_value, pID) - SELECT option_key, option_value, ? - FROM SupermintOptions - WHERE pID=?", - array($pID, $based_on )); - endif; - - } - function delete_preset ($pID) { - /* Ne fonctione pas quand les options d'un preset sont vides - Loader::db()->query("DELETE SupermintOptions, SupermintOptionsPreset - FROM SupermintOptions, SupermintOptionsPreset - WHERE SupermintOptions.pID = SupermintOptionsPreset.pID - AND SupermintOptionsPreset.pID = ? - ", array($pID)); - */ - - Loader::db()->query("DELETE SupermintOptions FROM SupermintOptions WHERE pID = ?", array($pID)); - Loader::db()->query("DELETE SupermintOptionsPreset FROM SupermintOptionsPreset WHERE pID = ?", array($pID)); - - if ($pID == $this->get_default_pID()) $this->set_default_pID(1); - - } - - function rename_preset ($name, $pID) { - Loader::db()->query("UPDATE SupermintOptionsPreset - SET name = ? - WHERE pID = ?", - array( $name, $pID)); - - } - - function set_default_pID ($pID) { - Config::save('concrete.misc.default_supermint_preset_id', $pID); - } - function get_default_pID () { - return Config::get('concrete.misc.default_supermint_preset_id'); - } - function get_default_preset_title() { - $p = $this->get_preset_by_id($this->get_default_pID()); - return $p['name']; - } - function get_preset_title($pID) { - $p = $this->get_preset_by_id($pID); - return $p['name']; - } - function get_active_pID ($c = null) { - if ($_GET['pID']) return $_GET['pID']; - // On regarde quel objet page prendre - $page = $c ? $c : Page::getCurrentPage(); - // On tente de re�cup�rer la valeur de l'attribut - if (is_object($page)) : - if (get_class($page) == 'Concrete\Core\Page\Page') { - $cpID = $page->getAttribute('supermint_theme_preset_options'); - }; - endif; - // On retourne la valeur de l'attribut, sinon le preset par d�fault - return $cpID ? $cpID : self::get_default_pID(); - } - - /******************************* - * Options - * *****************************/ - - static function get_options_from_preset_ID ($pID) { - $all = Loader::db()->getAll("SELECT option_key, option_value FROM SupermintOptions WHERE pID=?", array($pID)); - if(is_array($all)) { - $r = new stdClass(); - foreach($all as $o) { - $r->{$o['option_key']} = $o['option_value']; - } - $r->pID = $pID; - return $r; - } - return false; - } - static function get_options_from_active_preset_ID () { - return self::get_options_from_preset_ID(self::get_active_pID()); - } - - function save_options ($data, $pID, $updateOnly = false) { - - foreach ($data as $k => $v): - if ($k == 'pID') continue; - $test = Loader::db()->GetOne("SELECT * FROM SupermintOptions WHERE option_key = ? AND pID= ?", array($k, $pID)); - if ($test): - if ($updateOnly === false) : - Loader::db()->query("UPDATE SupermintOptions - SET option_value=? - WHERE option_key = ? AND pID= ?", - array( $v, $k, $pID)); - endif; - else : - Loader::db()->query("INSERT INTO SupermintOptions - (option_key, option_value, pID) - VALUES(?,?,?) - ", array( $k, $v, $pID)); - endif; - endforeach; - } - - function getXML_from_pid ($pID){ - - $pkg = Package::getByHandle('theme_supermint'); - $export = array('config' => - array( 'theme' => $pkg->getPackageHandle(), - 'version' => $pkg->getPackageVersion(), - 'name' => $this->get_preset_title($pID) - )); - $export['options'] = (array)$this->get_options_from_preset_ID($pID); - $exportDOM = SmArrayToXml::createXML('mcl_preset', $export); - return $exportDOM->saveHTML(); - } - - function importXML_preset ($file, $pID = false, $updateOnly = false) { - - $content = file_get_contents($file); - // On teste si le fichier est un XML valide - if (!$this->is_valid_xml($content)) return array ('error' => true, 'message' => t('This is not a valid preset format')); - // On cree un STRING du fichier qu'on envoie au transformateur - $p = SmXmlToArray::createArray($content); - // On tyest si on a un tableau et qu'il n'est pas vide - if (is_array($p) && count($p)) : - // On teste les different conteneurs - if(count($p['mcl_preset']) && count($p['mcl_preset']['config'] && count($p['mcl_preset']['options']))) : - $pp = $p['mcl_preset']; - if ($this->pkg->getPackageHandle() != $pp['config']['theme']) return array ('error' => true, 'message' => t('This preset in not compatible with this theme')); - if (!$pID) : - // On cree un nouveau preset et recup�re son ID - $pID = $this->save_preset($pp['config']['name'], false, false, true); - endif; - // Si on a pu avoir un ID - if ($pID) : - // On sauve les options pour cet ID - if ($updateOnly) - $this->save_options ($pp['options'], $pID, true); - else - $this->save_options ($pp['options'], $pID, false); - - return array ('error' => false, 'message' => t('Preset imported')); - else : - return array ('error' => true, 'message' => t('Can�t create new preset')); - endif; - else : - return array ('error' => true, 'message' => t('This file seems to be not a mcl theme preset')); - endif; - endif; - } - - function is_valid_xml ( $xml ) { - libxml_use_internal_errors( true ); - - $doc = new DOMDocument('1.0', 'utf-8'); - - $doc->loadXML( $xml ); - - $errors = libxml_get_errors(); - - return empty( $errors ); - } - - /******************************* - * Options Reset & install - * *****************************/ - - function reset_options ($pID = 1) { - - $path = Package::getByHandle('theme_supermint')->getPackagePath(); - return $this->importXML_preset ($path . '/models/theme_presets/base.mcl',1); - } - - function update_db () { - $this->install_db(false,true); - } - - function install_db ($pHandle = '', $updateOnly = false) { - - $path = Package::getByHandle('theme_supermint')->getPackagePath() . '/src/Models/theme_presets/'; - $presets_files = ThemeFileHelper::dir_walk($path , array('mcl')); - - if (is_array($presets_files) && count($presets_files)) : - foreach ($presets_files as $p) : - if($updateOnly) : - $_pID = $this->get_preset_id_from_handle(str_replace('.mcl', '', $p)); - // On update les valeurs - if ($_pID) $this->importXML_preset ($path . $p, $_pID, true); - // On importe le xml - else $this->importXML_preset ($path . $p); - else : - $this->importXML_preset ($path . $p); - endif; - endforeach; - endif; - - // Set as default - if ($pHandle) $pID = $this->get_preset_id_from_handle($pHandle); - else $pID = 1; - - // Si la function est appellé avec pHandle === false, on update, donc on ne change pas le pID actif - if ($pID && !$updateOnly) - $this->set_default_pID($pID); - - } - -} - -?> +init($c); + } + + static function get () { + $session = \Core::make('session'); + return $session->get('supermint.options'); + } + + function init ($c) { + + $this->pkg = Package::getByHandle("theme_supermint"); + $this->pID = $this->get_active_pID(); + + } + function set_collection_object($c) { + $this->init($c); + } + function set_toggle_option_name($name) { + $this->option_name = $name; + } + + function get_presets_list() { + $all = Loader::db()->getAll("SELECT pID, name FROM SupermintOptionsPreset"); + if(is_array($all)) return $all; else return false; + } + function get_preset_by_id ($pID) { + $row = Loader::db()->getRow("SELECT pID, name FROM SupermintOptionsPreset WHERE pID=?", array($pID)); + if(is_array($row)) return $row; else return false; + } + function get_preset_id_from_handle ($pHandle) { + $row = Loader::db()->getRow("SELECT pID FROM SupermintOptionsPreset WHERE name=?", array($pHandle)); + if(isset($row['pID'])) return (int)$row['pID']; else return false; + } + + function output_presets_list ($echo = false, $selected=null, $name = 'preset_id', $before = array()) { + + $list = $this->get_presets_list (); + + if ($list) : + $r[] = ''; + $r = implode("\r" , $r); + + if ($echo) echo $r; + else return $r; + + else: + return false; + endif; + + } + + function update () { + + } + + function save_preset($name, $based_on = false, $active = false, $returnID = false) { + + Loader::db()->query("INSERT INTO SupermintOptionsPreset (name,active) VALUES (?,?)", array($name, $active ? 1 : 0)); + + if ($returnID) return Loader::db()->Insert_ID(); + if ($based_on) : + // Recupere le nouvel ID + $pID = Loader::db()->Insert_ID(); + // Duplique toutes les options qui ont comme presetID $based_on et leur donne un nouvel ID base sur celui qui vient d'etre cr�� + Loader::db()->query("INSERT INTO SupermintOptions (option_key, option_value, pID) + SELECT option_key, option_value, ? + FROM SupermintOptions + WHERE pID=?", + array($pID, $based_on )); + endif; + + } + function delete_preset ($pID) { + /* Ne fonctione pas quand les options d'un preset sont vides + Loader::db()->query("DELETE SupermintOptions, SupermintOptionsPreset + FROM SupermintOptions, SupermintOptionsPreset + WHERE SupermintOptions.pID = SupermintOptionsPreset.pID + AND SupermintOptionsPreset.pID = ? + ", array($pID)); + */ + + Loader::db()->query("DELETE SupermintOptions FROM SupermintOptions WHERE pID = ?", array($pID)); + Loader::db()->query("DELETE SupermintOptionsPreset FROM SupermintOptionsPreset WHERE pID = ?", array($pID)); + + if ($pID == $this->get_default_pID()) $this->set_default_pID(1); + + } + + function rename_preset ($name, $pID) { + Loader::db()->query("UPDATE SupermintOptionsPreset + SET name = ? + WHERE pID = ?", + array( $name, $pID)); + + } + + function set_default_pID ($pID) { + Config::save('concrete.misc.default_supermint_preset_id', $pID); + } + function get_default_pID () { + return Config::get('concrete.misc.default_supermint_preset_id'); + } + function get_default_preset_title() { + $p = $this->get_preset_by_id($this->get_default_pID()); + return $p['name']; + } + function get_preset_title($pID) { + $p = $this->get_preset_by_id($pID); + return $p['name']; + } + function get_active_pID ($c = null) { + if ($_GET['pID']) return $_GET['pID']; + // On regarde quel objet page prendre + $page = $c ? $c : Page::getCurrentPage(); + // On tente de re�cup�rer la valeur de l'attribut + if (is_object($page)) : + if (get_class($page) == 'Concrete\Core\Page\Page') { + $cpID = $page->getAttribute('supermint_theme_preset_options'); + }; + endif; + // On retourne la valeur de l'attribut, sinon le preset par d�fault + return $cpID ? $cpID : self::get_default_pID(); + } + + /******************************* + * Options + * *****************************/ + + static function get_options_from_preset_ID ($pID) { + $all = Loader::db()->getAll("SELECT option_key, option_value FROM SupermintOptions WHERE pID=?", array($pID)); + if(is_array($all)) { + $r = new stdClass(); + foreach($all as $o) { + $r->{$o['option_key']} = $o['option_value']; + } + $r->pID = $pID; + return $r; + } + return false; + } + static function get_options_from_active_preset_ID () { + return self::get_options_from_preset_ID(self::get_active_pID()); + } + + function save_options ($data, $pID, $updateOnly = false) { + + foreach ($data as $k => $v): + if ($k == 'pID') continue; + $test = Loader::db()->GetOne("SELECT * FROM SupermintOptions WHERE option_key = ? AND pID= ?", array($k, $pID)); + if ($test): + if ($updateOnly === false) : + Loader::db()->query("UPDATE SupermintOptions + SET option_value=? + WHERE option_key = ? AND pID= ?", + array( $v, $k, $pID)); + endif; + else : + Loader::db()->query("INSERT INTO SupermintOptions + (option_key, option_value, pID) + VALUES(?,?,?) + ", array( $k, $v, $pID)); + endif; + endforeach; + } + + function getXML_from_pid ($pID){ + + $pkg = Package::getByHandle('theme_supermint'); + $export = array('config' => + array( 'theme' => $pkg->getPackageHandle(), + 'version' => $pkg->getPackageVersion(), + 'name' => $this->get_preset_title($pID) + )); + $export['options'] = (array)$this->get_options_from_preset_ID($pID); + $exportDOM = SmArrayToXml::createXML('mcl_preset', $export); + return $exportDOM->saveHTML(); + } + + function safecount($val){ + if (is_array($val)) { + return count($val); + } + else { + return false; + } + } + + function importXML_preset ($file, $pID = false, $updateOnly = false) { + + $content = file_get_contents($file); + // On teste si le fichier est un XML valide + if (!$this->is_valid_xml($content)) return array ('error' => true, 'message' => t('This is not a valid preset format')); + // On cree un STRING du fichier qu'on envoie au transformateur + $p = SmXmlToArray::createArray($content); + // On tyest si on a un tableau et qu'il n'est pas vide + if (is_array($p) && count($p)) : + // On teste les different conteneurs + if($this->safecount($p['mcl_preset']) && $this->safecount($p['mcl_preset']['config'] && $this->safecount($p['mcl_preset']['options']))) : + $pp = $p['mcl_preset']; + if ($this->pkg->getPackageHandle() != $pp['config']['theme']) return array ('error' => true, 'message' => t('This preset in not compatible with this theme')); + if (!$pID) : + // On cree un nouveau preset et recup�re son ID + $pID = $this->save_preset($pp['config']['name'], false, false, true); + endif; + // Si on a pu avoir un ID + if ($pID) : + // On sauve les options pour cet ID + if ($updateOnly) + $this->save_options ($pp['options'], $pID, true); + else + $this->save_options ($pp['options'], $pID, false); + + return array ('error' => false, 'message' => t('Preset imported')); + else : + return array ('error' => true, 'message' => t('Can�t create new preset')); + endif; + else : + return array ('error' => true, 'message' => t('This file seems to be not a mcl theme preset')); + endif; + endif; + } + + function is_valid_xml ( $xml ) { + libxml_use_internal_errors( true ); + + $doc = new DOMDocument('1.0', 'utf-8'); + + $doc->loadXML( $xml ); + + $errors = libxml_get_errors(); + + return empty( $errors ); + } + + /******************************* + * Options Reset & install + * *****************************/ + + function reset_options ($pID = 1) { + + $path = Package::getByHandle('theme_supermint')->getPackagePath(); + return $this->importXML_preset ($path . '/models/theme_presets/base.mcl',1); + } + + function update_db () { + $this->install_db(false,true); + } + + function install_db ($pHandle = '', $updateOnly = false) { + + $path = Package::getByHandle('theme_supermint')->getPackagePath() . '/src/Models/theme_presets/'; + $presets_files = ThemeFileHelper::dir_walk($path , array('mcl')); + + if (is_array($presets_files) && count($presets_files)) : + foreach ($presets_files as $p) : + if($updateOnly) : + $_pID = $this->get_preset_id_from_handle(str_replace('.mcl', '', $p)); + // On update les valeurs + if ($_pID) $this->importXML_preset ($path . $p, $_pID, true); + // On importe le xml + else $this->importXML_preset ($path . $p); + else : + $this->importXML_preset ($path . $p); + endif; + endforeach; + endif; + + // Set as default + if ($pHandle) $pID = $this->get_preset_id_from_handle($pHandle); + else $pID = 1; + + // Si la function est appellé avec pHandle === false, on update, donc on ne change pas le pID actif + if ($pID && !$updateOnly) + $this->set_default_pID($pID); + + } + +} + +?> diff --git a/themes/supermint/elements/backstretch.php b/themes/supermint/elements/backstretch.php index 379cc89..9ec3f29 100755 --- a/themes/supermint/elements/backstretch.php +++ b/themes/supermint/elements/backstretch.php @@ -14,7 +14,7 @@ foreach ($files as $key => $file) $bgurls[] = $file->getRelativePath(); endif; -if (count($bgurls)) : ?> +if (!isnull($bgurls) && count($bgurls)) : ?>