Exemple #1
0
 function writeConfig()
 {
     $config = array('metas' => array('title' => null, 'author' => null, 'creation' => strftime('%Y'), 'subject' => 'scout,' . $this->data['site']['association']), 'system' => array('short_title' => null, 'association' => $this->data['site']['association'], 'realm' => $this->generateRealm(), 'duree_connexion' => 2678400, 'admin' => $this->data['admin']['adelec'], 'mail' => array('enable' => true, 'smtp' => ''), 'style' => 'joubert'));
     $config = new Strass_Config_Php('strass', $config);
     $config->write();
     Zend_Registry::set('config', $config);
 }
Exemple #2
0
 function offline()
 {
     if (file_exists('cache')) {
         rename('cache', 'private/cache');
     }
     // config
     Zend_Registry::set('config_basedir', 'config/');
     $config = array();
     $tmp = new Strass_Config_Php('knema/db');
     $newpath = 'private/strass.sqlite';
     rename($tmp->config->dbname, $newpath);
     $tmp->config->dbname = $newpath;
     $config['db'] = $tmp->toArray();
     $tmp = new Strass_Config_Php('knema/site');
     $config['site'] = $tmp->toArray();
     $tmp = new Strass_Config_Php('strass/inscription');
     $config['inscription'] = $tmp->toArray();
     $tmp = new Strass_Config_Php('knema/menu');
     $config['menu'] = $tmp->toArray();
     Zend_Registry::set('config_basedir', 'private/config/');
     $config = new Strass_Config_Php('strass', $config);
     $config->write();
     // Renommages
     rename("resources/styles/" . $config->site->style, "data/styles/" . $config->site->style);
     shell_exec("rsync -av data/statiques/ private/statiques/");
     self::rrmdir('data/statiques');
     rename("private/statiques/strass/unites", "private/unites");
     rename("data/images/strass/unites/", "data/unites");
     rename("data/images/strass/photos/", "data/photos");
     rename("data/images/strass/individus/", "data/avatars/");
     rename("data/images/strass/journaux/", "data/journaux");
     rename("data/intro.wiki", "private/unites/intro.wiki");
     // Nettoyages
     @unlink('resources/templates/.htaccess');
     self::rrmdir('resources/');
     @unlink('config/.htaccess');
     self::rrmdir('config/');
     @unlink('data/db/.htaccess');
     self::rrmdir('data/db/');
     self::rrmdir('data/images/');
     self::rrmdir('private/statiques/strass');
     @self::rrmdir('private/statiques/scout');
     Strass::setInstalled();
 }
Exemple #3
0
 function online($db)
 {
     $old = new Strass_Config_Php('strass');
     $new = new Strass_Config_Php('strass', array());
     $new->metas = $old->site->metas;
     $system = $old->site->toArray();
     if ($system['id'] == 'morel') {
         $mvt = 'fse';
     } else {
         $mvt = 'suf';
     }
     $system['mouvement'] = $mvt;
     unset($system['id']);
     unset($system['association']);
     unset($system['metas']);
     unset($system['rubrique']);
     unset($system['sauvegarder']);
     $new->system = $system;
     /* Plutôt que d'afficher un style pété, on se repli */
     $new->system->style = 'strass';
     $new->write();
     Zend_Registry::set('config', $new);
 }
Exemple #4
0
 function parametresAction()
 {
     static $blocs = array('branches' => 'Les branches', 'unites' => 'Les unités', 'photos' => 'Photos aléatoires', 'activites' => 'Activités marquantes', 'documents' => 'Documents');
     $this->view->unite = $u = $this->_helper->Unite();
     $this->assert(null, $u, null, "Vous n'avez pas le droit de modifier cette unité");
     $this->metas(array('DC.Title' => 'Paramètres ' . $u->getFullname()));
     $this->view->model = $m = new Wtk_Form_Model('parametres');
     $w = $u->getWiki(null, false);
     $m->addString('presentation', "Message d'accueil", is_readable($w) ? file_get_contents($w) : '');
     $config = new Strass_Config_Php($u->slug);
     $t = $m->addTable('blocs', "Blocs de la page d'accueil", array('id' => array('String'), 'nom' => array('String', 'Bloc', true), 'enable' => array('Bool', 'Actif')), true, false);
     $enabled = $config->blocs;
     if ($enabled) {
         $enabled = $enabled->toArray();
     } else {
         $enabled = array();
     }
     foreach ($enabled as $k) {
         $r = $t->addRow($k, $blocs[$k], true);
     }
     /* nouveau blocs */
     foreach ($blocs as $k => $v) {
         if (!in_array($k, $enabled)) {
             $r = $t->addRow($k, $v, false);
         }
     }
     $m->addNewSubmission('enregistrer', "Enregistrer");
     if ($m->validate()) {
         $u->storePresentation($m->presentation);
         $blocs = array();
         foreach ($m->blocs as $row) {
             if ($row['enable']) {
                 array_push($blocs, $row['id']);
             }
         }
         $config->blocs = $blocs;
         $config->write();
         $this->logger->info("Configuration de page d'accueil");
         $this->redirectSimple('index', 'unites', null, array('unite' => $u->slug));
     }
 }
Exemple #5
0
    function online($db)
    {
        error_log("Unicité des identifiants de photos");
        do {
            $slugs = $db->query("SELECT count(*) AS count, id AS slug FROM photos GROUP BY id HAVING count > 1");
            $count = 0;
            foreach ($slugs as $i => $row) {
                $count += 1;
                extract($row);
                $activites = $db->query("SELECT activite FROM photos WHERE id = '{$slug}' ORDER BY ROWID");
                foreach ($activites as $i => $arow) {
                    if (!$i) {
                        continue;
                    }
                    extract($arow);
                    $newslug = "{$slug}-{$i}";
                    error_log("Renommage de {$activite}/{$slug} en {$newslug}.");
                    rename("data/photos/{$activite}/{$slug}.jpeg", "data/photos/{$activite}/{$newslug}.jpeg");
                    rename("data/photos/{$activite}/{$slug}-vignette.jpeg", "data/photos/{$activite}/{$newslug}-vignette.jpeg");
                    $db->exec(<<<EOS
UPDATE photos SET id = '{$newslug}'
       WHERE id = '{$slug}' AND activite = '{$activite}';
UPDATE commentaires SET photo = '{$newslug}'
       WHERE photo = '{$slug}' AND activite = '{$activite}';
EOS
);
                }
            }
        } while ($count);
        error_log("Migration des photos");
        $db->exec(<<<'EOS'
--

CREATE TABLE `commentaire` (
	id		INTEGER		PRIMARY KEY,
	auteur		INTEGER		REFERENCES individu(id),
	parent		INTEGER		REFERENCES commentaire(id),
	`date`		DATETIME	DEFAULT CURRENT_TIMESTAMP,
	message		TEXT,
	-- Interdire les réponses multiples. Le site ne sert pas à discuter.
	UNIQUE(auteur, parent)
);

INSERT INTO commentaire
(`date`, message)
SELECT photos.`date`, photos.id
FROM photos
ORDER BY `date`;

CREATE TABLE `photo` (
	id		INTEGER		PRIMARY KEY,
	slug		CHAR(512)	UNIQUE,
	activite	INTEGER		NOT NULL REFERENCES activite(id),
	promotion	INTEGER		DEFAULT 0,
	`date`		DATETIME,
	titre		CHAR(512),
	commentaires	INTEGER		NOT NULL REFERENCES commentaire(id)
);


INSERT INTO photo
(slug, titre, activite, date, commentaires)
SELECT photos.id, titre, activite.id, photos.date, (
SELECT id FROM commentaire WHERE commentaire.message = photos.id)
FROM photos
JOIN activite ON activite.slug = photos.activite
ORDER BY activite.debut, photos.date;

UPDATE commentaire
SET message = (SELECT desc FROM photos WHERE photos.id = message);

DROP TABLE photos;

INSERT INTO commentaire
(auteur, parent, date, message)
SELECT individu.id, photo.commentaires, commentaires.date, commentaires.commentaire
FROM commentaires
JOIN individu ON individu.slug = commentaires.individu
JOIN activite ON activite.slug = commentaires.activite
JOIN photo ON photo.slug = commentaires.photo AND photo.activite = activite.id
ORDER BY commentaires.date;

DROP TABLE commentaires;


CREATE VIEW vphotos AS
SELECT
	photo.id, photo.slug,
	activite.slug AS activite,
	photo.titre
FROM photo
JOIN activite ON activite.id = photo.activite
ORDER BY activite.debut, photo.date;

CREATE VIEW vcommentaires AS
SELECT
	commentaire.id,
	activite.slug AS activite, photo.slug AS photo, individu.slug,
	commentaire.date, message
FROM commentaire
JOIN photo ON photo.commentaires = commentaire.parent
JOIN activite ON activite.id = photo.activite
LEFT JOIN individu ON individu.id = commentaire.auteur
ORDER BY photo.id, commentaire.date;

EOS
);
        error_log("Écriture de la configuration des photos.");
        $config = new Strass_Config_Php('strass');
        $config->photos = array('size' => 2048, 'quality' => 85, 'vignette' => 256);
        $config->write();
        error_log('Regénération des vignettes');
        $total = $db->query("SELECT count(*) FROM vphotos;")->fetchColumn();
        $stmt = $db->query("SELECT id, slug, activite FROM vphotos;");
        $top = microtime(true);
        foreach ($stmt as $i => $row) {
            $now = microtime(true);
            if (intval($now - $top) > 3) {
                $count = $i + 1;
                error_log("{$count} vignettes sur {$total} regénérées.");
                $top = microtime(true);
            }
            extract($row);
            $base = 'data/photos/' . $activite . '/' . $slug;
            $photo = $base . '.jpeg';
            $vignette = $base . '-vignette.jpeg';
            if (!file_exists($photo)) {
                error_log("Photo perdue : {$activite}/{$slug}");
                $db->exec("DELETE FROM photo WHERE id = " . $id . ";");
                continue;
            }
            $im = new Imagick($photo);
            $width = $im->getImageWidth();
            $height = $im->getImageHeight();
            $im->setImageCompressionQuality(85);
            $MAX = 256;
            if (min($width, $height) > $MAX) {
                $im->cropThumbnailImage($MAX, $MAX);
            }
            $im->writeImage($vignette);
        }
        $db->exec(<<<'EOS'
-- Supprimer les descriptions de photos supprimées
DELETE FROM commentaire
WHERE commentaire.parent IS NULL AND NOT EXISTS (
       SELECT * FROM photo WHERE commentaires = commentaire.id);

-- Supprimer les commentaires orphelins
DELETE FROM commentaire
WHERE commentaire.parent IS NOT NULL AND NOT EXISTS (
       SELECT * FROM commentaire AS parent WHERE parent.id = commentaire.id);

EOS
);
    }