Overview
SHA1:d4f28a592bf91f914d191f58e7b4705b8324f769
Date: 2015-01-07 17:50:18
User: bohwaz
Comment:Débuts version 0.7.0 : possibilité pour les plugins de gérer des nouveaux types de boucles
Timelines: family | ancestors | descendants | both | trunk
Downloads: Tarball | ZIP archive
Other Links: files | file ages | folders | manifest
Tags And Properties
Context
2015-01-15
01:23
[9417cb3788] Utiliser le répertoire de cache défini par XDG_CACHE_HOME (user: bohwaz, tags: trunk)
2015-01-07
17:50
[d4f28a592b] Débuts version 0.7.0 : possibilité pour les plugins de gérer des nouveaux types de boucles (user: bohwaz, tags: trunk)
2015-01-06
15:17
[93147add8c] Correction appel namespace (user: bohwaz, tags: trunk, stable)
Changes

Added src/include/data/0.7.0.sql version [4da22f7ea1].











>
>
>
>
>
1
2
3
4
5
CREATE TABLE plugins_skel_boucles
(
    plugin TEXT NOT NULL REFERENCES plugins (id),
    nom TEXT NOT NULL
);

Modified src/include/data/schema.sql from [4b228fc114] to [1a0ccb3ec8].

310
311
312
313
314
315
316






    description TEXT,
    auteur TEXT,
    url TEXT,
    version TEXT NOT NULL,
    menu INTEGER NOT NULL DEFAULT 0,
    config TEXT
);













>
>
>
>
>
>
310
311
312
313
314
315
316
317
318
319
320
321
322
    description TEXT,
    auteur TEXT,
    url TEXT,
    version TEXT NOT NULL,
    menu INTEGER NOT NULL DEFAULT 0,
    config TEXT
);

CREATE TABLE plugins_skel_boucles
(
    plugin TEXT NOT NULL REFERENCES plugins (id),
    nom TEXT NOT NULL
);

Modified src/include/lib/Garradin/Plugin.php from [290c0720a4] to [590cae23c9].

248
249
250
251
252
253
254





















255
256
257
258
259
260
261
		}

		$db = DB::getInstance();
		return $db->simpleUpdate('plugins', 
			'id = \''.$db->escapeString($this->id).'\'', 
			['version' => $infos['version']]);
	}






















	/**
	 * Liste des plugins installés (en DB)
	 * @return array Liste des plugins triés par nom
	 */
	static public function listInstalled()
	{







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
		}

		$db = DB::getInstance();
		return $db->simpleUpdate('plugins', 
			'id = \''.$db->escapeString($this->id).'\'', 
			['version' => $infos['version']]);
	}

	public function registerSkelLoopName($name)
	{
		$db = DB::getInstance();
		$registered = $db->simpleQuerySingle('SELECT plugin FROM plugins_skel_boucles WHERE nom = ?;', $name);

		if ($registered)
		{
			if ($registered != $this->id)
			{
				throw new \LogicException('La boucle ' . $name . ' est déjà associée au plugin "'.$registered.'"');
			}
			else
			{
				return true;
			}
		}

		return $db->simpleInsert('plugins_skel_boucles', 
			['nom' => $name, 'plugin' => $this->id]);
	}

	/**
	 * Liste des plugins installés (en DB)
	 * @return array Liste des plugins triés par nom
	 */
	static public function listInstalled()
	{

Modified src/include/lib/Garradin/Squelette.php from [735c329dc9] to [2b931bda50].

312
313
314
315
316
317
318
319
320
321
322

323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441























442
443
444
445
446
447
448
        $out->append(1, 'endif;');

        return $out;
    }

    protected function processLoop($loopName, $loopType, $loopCriterias, $loopContent, $preContent, $postContent, $altContent)
    {
        if ($loopType != 'articles' && $loopType != 'rubriques' && $loopType != 'pages')
        {
            throw new \KD2\MiniSkelMarkupException("Le type de boucle '".$loopType."' est inconnu.");
        }


        $loopStart = '';
        $query = $where = $order = '';
        $limit = $begin = 0;

        $query = 'SELECT w.*, strftime(\\\'%s\\\', w.date_creation) AS date_creation, strftime(\\\'%s\\\', w.date_modification) AS date_modification';

        if (trim($loopContent))
        {
            $query .= ', r.contenu AS texte FROM wiki_pages AS w LEFT JOIN wiki_revisions AS r ON (w.id = r.id_page AND w.revision = r.revision) ';
        }
        else
        {
            $query .= '\'\' AS texte ';
        }

        $where = 'WHERE w.droit_lecture = -1 ';

        if ($loopType == 'articles')
        {
            $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) = 0 ';
        }
        elseif ($loopType == 'rubriques')
        {
            $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) > 0 ';
        }

        $allowed_fields = ['id', 'uri', 'titre', 'date', 'date_creation', 'date_modification',
            'parent', 'rubrique', 'revision', 'points', 'recherche', 'texte'];
        $search = $search_rank = false;

        foreach ($loopCriterias as $criteria)
        {
            if (isset($criteria['field']))
            {
                if (!in_array($criteria['field'], $allowed_fields))
                {
                    throw new \KD2\MiniSkelMarkupException("Critère '".$criteria['field']."' invalide pour la boucle '$loopName' de type '$loopType'.");
                }
                elseif ($criteria['field'] == 'rubrique')
                {
                    $criteria['field'] = 'parent';
                }
                elseif ($criteria['field'] == 'date')
                {
                    $criteria['field'] = 'date_creation';
                }
                elseif ($criteria['field'] == 'points')
                {
                    if ($criteria['action'] != \KD2\MiniSkel::ACTION_ORDER_BY)
                    {
                        throw new \KD2\MiniSkelMarkupException("Le critère 'points' n\'est pas valide dans ce contexte.");
                    }

                    $search_rank = true;
                }
            }

            switch ($criteria['action'])
            {
                case \KD2\MiniSkel::ACTION_ORDER_BY:
                    if (!$order)
                        $order = 'ORDER BY '.$criteria['field'].'';
                    else
                        $order .= ', '.$criteria['field'].'';
                    break;
                case \KD2\MiniSkel::ACTION_ORDER_DESC:
                    if ($order)
                        $order .= ' DESC';
                    break;
                case \KD2\MiniSkel::ACTION_LIMIT:
                    $begin = $criteria['begin'];
                    $limit = $criteria['number'];
                    break;
                case \KD2\MiniSkel::ACTION_MATCH_FIELD_BY_VALUE:
                    $where .= ' AND '.$criteria['field'].' '.$criteria['comparison'].' \\\'\'.$db->escapeString(\''.$criteria['value'].'\').\'\\\'';
                    break;
                case \KD2\MiniSkel::ACTION_MATCH_FIELD:
                {
                    if ($criteria['field'] == 'recherche')
                    {
                        $query = 'SELECT w.*, r.contenu AS texte, rank(matchinfo(wiki_recherche), 0, 1.0, 1.0) AS points FROM wiki_pages AS w INNER JOIN wiki_recherche AS r ON (w.id = r.id) ';
                        $where .= ' AND wiki_recherche MATCH \\\'\'.$db->escapeString($this->getVariable(\''.$criteria['field'].'\')).\'\\\'';
                        $search = true;
                    }
                    else
                    {
                        if ($criteria['field'] == 'parent')
                            $field = 'id';
                        else
                            $field = $criteria['field'];

                        $where .= ' AND '.$criteria['field'].' = \\\'\'.$db->escapeString($this->getVariable(\''.$field.'\')).\'\\\'';
                    }
                    break;
                }
                default:
                    break;
            }
        }

        if ($search_rank && !$search)
        {
            throw new \KD2\MiniSkelMarkupException("Le critère par points n'est possible que dans les boucles de recherche.");
        }

        if (trim($loopContent))
        {
            $loopStart .= '$row[\'url\'] = WWW_URL . $row[\'uri\']; ';
        }

        $query .= $where . ' ' . $order;

        if (!$limit || $limit > 100)
            $limit = 100;

        if ($limit)
        {
            $query .= ' LIMIT '.(is_numeric($begin) ? (int) $begin : '\'.$this->variables[\'debut_liste\'].\'').','.(int)$limit;























        }

        $hash = sha1(uniqid(mt_rand(), true));
        $out = new Squelette_Snippet();
        $out->append(1, '$parent_hash = $this->current[\'_self_hash\'];');
        $out->append(1, '$this->parent =& $parent_hash ? $this->_vars[$parent_hash] : null;');








|
|
|
<
>
|
<
|
|

|

|
|
|
|
|
|
|
|

|

|
|
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|

|
|
|
|

|
|
|
|

|

|
|

|
|
|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







312
313
314
315
316
317
318
319
320
321

322
323

324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
        $out->append(1, 'endif;');

        return $out;
    }

    protected function processLoop($loopName, $loopType, $loopCriterias, $loopContent, $preContent, $postContent, $altContent)
    {
        $query = $loopStart = '';

        // Types de boucles natifs

        if ($loopType == 'articles' || $loopType == 'rubriques' || $loopType == 'pages')
        {

            $where = $order = '';
            $limit = $begin = 0;

            $query = 'SELECT w.*, strftime(\\\'%s\\\', w.date_creation) AS date_creation, strftime(\\\'%s\\\', w.date_modification) AS date_modification';

            if (trim($loopContent))
            {
                $query .= ', r.contenu AS texte FROM wiki_pages AS w LEFT JOIN wiki_revisions AS r ON (w.id = r.id_page AND w.revision = r.revision) ';
            }
            else
            {
                $query .= '\'\' AS texte ';
            }

            $where = 'WHERE w.droit_lecture = -1 ';

            if ($loopType == 'articles')
            {
                $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) = 0 ';
            }
            elseif ($loopType == 'rubriques')
            {
                $where .= 'AND (SELECT COUNT(id) FROM wiki_pages WHERE parent = w.id) > 0 ';
            }

            $allowed_fields = ['id', 'uri', 'titre', 'date', 'date_creation', 'date_modification',
                'parent', 'rubrique', 'revision', 'points', 'recherche', 'texte'];
            $search = $search_rank = false;

            foreach ($loopCriterias as $criteria)
            {
                if (isset($criteria['field']))
                {
                    if (!in_array($criteria['field'], $allowed_fields))
                    {
                        throw new \KD2\MiniSkelMarkupException("Critère '".$criteria['field']."' invalide pour la boucle '$loopName' de type '$loopType'.");
                    }
                    elseif ($criteria['field'] == 'rubrique')
                    {
                        $criteria['field'] = 'parent';
                    }
                    elseif ($criteria['field'] == 'date')
                    {
                        $criteria['field'] = 'date_creation';
                    }
                    elseif ($criteria['field'] == 'points')
                    {
                        if ($criteria['action'] != \KD2\MiniSkel::ACTION_ORDER_BY)
                        {
                            throw new \KD2\MiniSkelMarkupException("Le critère 'points' n\'est pas valide dans ce contexte.");
                        }

                        $search_rank = true;
                    }
                }

                switch ($criteria['action'])
                {
                    case \KD2\MiniSkel::ACTION_ORDER_BY:
                        if (!$order)
                            $order = 'ORDER BY '.$criteria['field'].'';
                        else
                            $order .= ', '.$criteria['field'].'';
                        break;
                    case \KD2\MiniSkel::ACTION_ORDER_DESC:
                        if ($order)
                            $order .= ' DESC';
                        break;
                    case \KD2\MiniSkel::ACTION_LIMIT:
                        $begin = $criteria['begin'];
                        $limit = $criteria['number'];
                        break;
                    case \KD2\MiniSkel::ACTION_MATCH_FIELD_BY_VALUE:
                        $where .= ' AND '.$criteria['field'].' '.$criteria['comparison'].' \\\'\'.$db->escapeString(\''.$criteria['value'].'\').\'\\\'';
                        break;
                    case \KD2\MiniSkel::ACTION_MATCH_FIELD:
                    {
                        if ($criteria['field'] == 'recherche')
                        {
                            $query = 'SELECT w.*, r.contenu AS texte, rank(matchinfo(wiki_recherche), 0, 1.0, 1.0) AS points FROM wiki_pages AS w INNER JOIN wiki_recherche AS r ON (w.id = r.id) ';
                            $where .= ' AND wiki_recherche MATCH \\\'\'.$db->escapeString($this->getVariable(\''.$criteria['field'].'\')).\'\\\'';
                            $search = true;
                        }
                        else
                        {
                            if ($criteria['field'] == 'parent')
                                $field = 'id';
                            else
                                $field = $criteria['field'];

                            $where .= ' AND '.$criteria['field'].' = \\\'\'.$db->escapeString($this->getVariable(\''.$field.'\')).\'\\\'';
                        }
                        break;
                    }
                    default:
                        break;
                }
            }

            if ($search_rank && !$search)
            {
                throw new \KD2\MiniSkelMarkupException("Le critère par points n'est possible que dans les boucles de recherche.");
            }

            if (trim($loopContent))
            {
                $loopStart .= '$row[\'url\'] = WWW_URL . $row[\'uri\']; ';
            }

            $query .= $where . ' ' . $order;

            if (!$limit || $limit > 100)
                $limit = 100;

            if ($limit)
            {
                $query .= ' LIMIT '.(is_numeric($begin) ? (int) $begin : '\'.$this->variables[\'debut_liste\'].\'').','.(int)$limit;
            }
        }
        else
        {
            $db = DB::getInstance();

            // Type de boucles gérés par des plugins
            if ($plugin = $db->simpleQuerySingle('SELECT plugin FROM plugins_skel_boucles WHERE nom = ? LIMIT 1;', false, $loopType))
            {
                $plugin = new \KD2\Plugin($plugin);

                if (!file_exists($plugin->path() . '/skel_loop.php'))
                {
                    throw new \KD2\MiniSkelMarkupException("Le type de boucle '".$loopType."' est géré par un plugin, mais celui-ci ne contient pas de fichier skel_loop.php.");
                }

                // Ici le plugin peut soit peupler $query et $loopStart lui-même, soit faire un return
                include $plugin->path() . '/skel_loop.php';
            }
            else
            {
                throw new \KD2\MiniSkelMarkupException("Le type de boucle '".$loopType."' est inconnu.");
            }
        }

        $hash = sha1(uniqid(mt_rand(), true));
        $out = new Squelette_Snippet();
        $out->append(1, '$parent_hash = $this->current[\'_self_hash\'];');
        $out->append(1, '$this->parent =& $parent_hash ? $this->_vars[$parent_hash] : null;');

Modified src/www/admin/upgrade.php from [99d1408582] to [dbfe19e493].

195
196
197
198
199
200
201










202
203
204
205
206
207
208
    $config->get('champs_membres')->save();

    // Possibilité de choisir l'identité et l'identifiant d'un membre
    $config->set('champ_identite', 'nom');
    $config->set('champ_identifiant', 'email');
    $config->save();
}











Utils::clearCaches();

$config->setVersion(garradin_version());

echo '<h2>Mise à jour terminée.</h2>
<p><a href="'.WWW_URL.'admin/">Retour</a></p>';







>
>
>
>
>
>
>
>
>
>







195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
    $config->get('champs_membres')->save();

    // Possibilité de choisir l'identité et l'identifiant d'un membre
    $config->set('champ_identite', 'nom');
    $config->set('champ_identifiant', 'email');
    $config->save();
}

if (version_compare($v, '0.7.0', '<'))
{
    $db->exec('PRAGMA foreign_keys = OFF; BEGIN;');

    // Mise à jour base de données
    $db->exec(file_get_contents(ROOT . '/include/data/0.7.0.sql'));

    $db->exec('END;');
}

Utils::clearCaches();

$config->setVersion(garradin_version());

echo '<h2>Mise à jour terminée.</h2>
<p><a href="'.WWW_URL.'admin/">Retour</a></p>';