initial commit from alias 1.2.1

This commit is contained in:
Jean-Christian Paul Denis 2022-11-27 13:57:51 +01:00
commit d16b47f02a
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
12 changed files with 565 additions and 0 deletions

90
_admin.php Normal file
View File

@ -0,0 +1,90 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
$core->addBehavior('exportFull',array('aliasBehaviors','exportFull'));
$core->addBehavior('exportSingle',array('aliasBehaviors','exportSingle'));
$core->addBehavior('importInit',array('aliasBehaviors','importInit'));
$core->addBehavior('importFull',array('aliasBehaviors','importFull'));
$core->addBehavior('importSingle',array('aliasBehaviors','importSingle'));
$_menu['Plugins']->addItem(__('Aliases'),'plugin.php?p=alias','index.php?pf=alias/icon.png',
preg_match('/plugin.php\?p=alias(&.*)?$/',$_SERVER['REQUEST_URI']),
$core->auth->check('admin',$core->blog->id));
if (!isset($__resources['help']['alias'])) {
$__resources['help']['alias'] = dirname(__FILE__).'/locales/en/help.html';
if (file_exists(dirname(__FILE__).'/locales/'.$_lang.'/help.html')) {
$__resources['help']['alias'] = dirname(__FILE__).'/locales/'.$_lang.'/help.html';
}
}
# Behaviors
class aliasBehaviors
{
public static function exportFull($core,$exp)
{
$exp->exportTable('alias');
}
public static function exportSingle($core,$exp,$blog_id)
{
$exp->export('alias',
'SELECT alias_url, alias_destination, alias_position '.
'FROM '.$core->prefix.'alias A '.
"WHERE A.blog_id = '".$blog_id."'"
);
}
public static function importInit($bk,$core)
{
$bk->cur_alias = $core->con->openCursor($core->prefix.'alias');
$bk->alias = new dcAliases($core);
$bk->aliases = $bk->alias->getAliases();
}
public static function importFull($line,$bk,$core)
{
if ($line->__name == 'alias')
{
$bk->cur_alias->clean();
$bk->cur_alias->blog_id = (string) $line->blog_id;
$bk->cur_alias->alias_url = (string) $line->alias_url;
$bk->cur_alias->alias_destination = (string) $line->alias_destination;
$bk->cur_alias->alias_position = (integer) $line->alias_position;
$bk->cur_alias->insert();
}
}
public static function importSingle($line,$bk,$core)
{
if ($line->__name == 'alias')
{
$found = false;
foreach ($bk->aliases as $v)
{
if ($v['alias_url'] == $line->alias_url) {
$found = true;
}
}
if ($found) {
$bk->alias->deleteAlias($line->alias_url);
}
$bk->alias->createAlias($line->alias_url,$line->alias_destination,$line->alias_position);
}
}
}
?>

21
_define.php Normal file
View File

@ -0,0 +1,21 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
$this->registerModule(
/* Name */ "alias",
/* Description*/ "Create aliases of your blog's URLs",
/* Author */ "Olivier Meunier and contributors",
/* Version */ '1.2.1',
/* Permissions */ 'admin'
);
?>

44
_install.php Normal file
View File

@ -0,0 +1,44 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_CONTEXT_ADMIN')) { return; }
$version = $core->plugins->moduleInfo('alias','version');
if (version_compare($core->getVersion('alias'),$version,'>=')) {
return;
}
/* Database schema
-------------------------------------------------------- */
$s = new dbStruct($core->con,$core->prefix);
$s->alias
->blog_id('varchar',32,false)
->alias_url('varchar',255,false)
->alias_destination('varchar',255,false)
->alias_position('smallint',0,false,1)
->primary('pk_alias','blog_id','alias_url')
->index('idx_alias_blog_id','btree','blog_id')
->index('idx_alias_blog_id_alias_position','btree','blog_id','alias_position')
->reference('fk_alias_blog','blog_id','blog','blog_id','cascade','cascade')
;
# Schema installation
$si = new dbStruct($core->con,$core->prefix);
$changes = $si->synchronize($s);
$core->setVersion('alias',$version);
return true;
?>

15
_prepend.php Normal file
View File

@ -0,0 +1,15 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
$GLOBALS['__autoload']['dcAliases'] = dirname(__FILE__).'/class.dc.aliases.php';
?>

51
_public.php Normal file
View File

@ -0,0 +1,51 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
if (!defined('DC_RC_PATH')) { return; }
$core->url->register('alias','','^(.*)$',array('urlAlias','alias'));
class urlAlias extends dcUrlHandlers
{
public static function alias($args)
{
$o = new dcAliases($GLOBALS['core']);
$aliases = $o->getAliases();
foreach ($aliases as $v)
{
if (@preg_match('#^/.*/$#',$v['alias_url']) && @preg_match($v['alias_url'],$args)) {
self::callAliasHandler(preg_replace($v['alias_url'],$v['alias_destination'],$args));
return;
} elseif ($v['alias_url'] == $args) {
self::callAliasHandler($v['alias_destination']);
return;
}
}
self::callAliasHandler($args);
}
public function callAliasHandler($part)
{
global $core;
$core->url->unregister('alias');
$core->url->getArgs($part,$type,$args);
global $core;
if (!$type) {
$core->url->callDefaultHandler($args);
} else {
$core->url->callHandler($type,$args);
}
}
}
?>

111
class.dc.aliases.php Normal file
View File

@ -0,0 +1,111 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
class dcAliases
{
protected $core;
protected $aliases;
public function __construct($core)
{
$this->core =& $core;
}
public function getAliases()
{
if (is_array($this->aliases)) {
return $this->aliases;
}
$this->aliases = array();
$sql = 'SELECT alias_url, alias_destination, alias_position '.
'FROM '.$this->core->prefix.'alias '.
"WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
'ORDER BY alias_position ASC ';
$this->aliases = $this->core->con->select($sql)->rows();
return $this->aliases;
}
public function updateAliases($aliases)
{
usort($aliases,array($this,'sortCallback'));
foreach ($aliases as $v) {
if (!isset($v['alias_url']) || !isset($v['alias_destination'])) {
throw new Exception(__('Invalid aliases definitions'));
}
}
$this->core->con->begin();
try
{
$this->deleteAliases();
foreach ($aliases as $k => $v)
{
if (!empty($v['alias_url']) && !empty($v['alias_destination']))
{
$this->createAlias($v['alias_url'],$v['alias_destination'],$k+1);
}
}
$this->core->con->commit();
}
catch (Exception $e)
{
$this->core->con->rollback();
throw $e;
}
}
public function createAlias($url,$destination,$position)
{
if (!$url) {
throw new Exception(__('Alias URL is empty.'));
}
if (!$destination) {
throw new Exception(__('Alias destination is empty.'));
}
$cur = $this->core->con->openCursor($this->core->prefix.'alias');
$cur->blog_id = (string) $this->core->blog->id;
$cur->alias_url = (string) $url;
$cur->alias_destination = (string) $destination;
$cur->alias_position = abs((integer) $position);
$cur->insert();
}
public function deleteAlias($url)
{
$this->core->con->execute(
'DELETE FROM '.$this->core->prefix.'alias '.
"WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
"AND alias_url = '".$this->core->con->escape($url)."' "
);
}
public function deleteAliases()
{
$this->core->con->execute(
'DELETE FROM '.$this->core->prefix.'alias '.
"WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' "
);
}
protected function sortCallback($a,$b)
{
if ($a['alias_position'] == $b['alias_position']) {
return 0;
}
return $a['alias_position'] < $b['alias_position'] ? -1 : 1;
}
}
?>

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 677 B

91
index.php Normal file
View File

@ -0,0 +1,91 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of Dotclear 2.
#
# Copyright (c) 2003-2008 Olivier Meunier and contributors
# Licensed under the GPL version 2.0 license.
# See LICENSE file or
# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# -- END LICENSE BLOCK ------------------------------------
$o = new dcAliases($core);
$aliases = $o->getAliases();
# Update aliases
if (isset($_POST['a']) && is_array($_POST['a']))
{
try {
$o->updateAliases($_POST['a']);
http::redirect($p_url.'&up=1');
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
# New alias
if (isset($_POST['alias_url']))
{
try {
$o->createAlias($_POST['alias_url'],$_POST['alias_destination'],count($aliases)+1);
http::redirect($p_url.'&created=1');
} catch (Exception $e) {
$core->error->add($e->getMessage());
}
}
?>
<html>
<head>
<title><?php echo __('Aliases'); ?></title>
</head>
<body>
<?php
echo
'<h2>'.html::escapeHTML($core->blog->name).' &rsaquo; '.__('Aliases').'</h2>'.
'<h3>'.__('Aliases list').'</h3>';
if (empty($aliases))
{
echo '<p>'.__('No alias').'</p>';
}
else
{
echo
'<form action="'.$p_url.'" method="post">'.
'<table><tr>'.
'<td>'.__('Alias URL').'</td>'.
'<td>'.__('Alias destination').'</td>'.
'<td>'.__('Alias position').'</td>'.
'</tr>';
foreach ($aliases as $k => $v)
{
echo
'<tr>'.
'<td>'.form::field(array('a['.$k.'][alias_url]'),30,255,html::escapeHTML($v['alias_url'])).'</td>'.
'<td>'.form::field(array('a['.$k.'][alias_destination]'),50,255,html::escapeHTML($v['alias_destination'])).'</td>'.
'<td>'.form::field(array('a['.$k.'][alias_position]'),3,5,html::escapeHTML($v['alias_position'])).'</td>'.
'</tr>';
}
echo '</table>'.
'<p>'.__('To remove an alias, empty its URL or destination.').'</p>'.
'<p>'.$core->formNonce().
'<input type="submit" value="'.__('Update').'" /></p>'.
'</form>';
}
echo
'<h3>'.__('New alias').'</h3>'.
'<form action="'.$p_url.'" method="post">'.
'<p class="field"><label>'.__('Alias URL:').' '.form::field('alias_url',50,255).'</label></p>'.
'<p class="field"><label>'.__('Alias destination:').' '.form::field('alias_destination',50,255).'</label></p>'.
'<p>'.$core->formNonce().'<input type="submit" value="'.__('Save').'" /></p>'.
'</form>';
dcPage::helpBlock('alias');
?>
</body>
</html>

73
locales/_pot/main.pot Normal file
View File

@ -0,0 +1,73 @@
# SOME DESCRIPTIVE TITLE.
# This file is put in the public domain.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: Dotclear 2 alias module\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2008-08-07 12:39+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"
#: plugins-test/alias//_admin.php:14 plugins-test/alias//index.php:41
#: plugins-test/alias//index.php:47
msgid "Aliases"
msgstr ""
#: plugins-test/alias//class.dc.aliases.php:43
msgid "Invalid aliases definitions"
msgstr ""
#: plugins-test/alias//class.dc.aliases.php:71
msgid "Alias URL is empty."
msgstr ""
#: plugins-test/alias//class.dc.aliases.php:75
msgid "Alias destination is empty."
msgstr ""
#: plugins-test/alias//index.php:48
msgid "Aliases list"
msgstr ""
#: plugins-test/alias//index.php:52
msgid "No alias"
msgstr ""
#: plugins-test/alias//index.php:59
msgid "Alias URL"
msgstr ""
#: plugins-test/alias//index.php:60
msgid "Alias destination"
msgstr ""
#: plugins-test/alias//index.php:61
msgid "Alias position"
msgstr ""
#: plugins-test/alias//index.php:75
msgid "To remove an alias, empty its URL or destination."
msgstr ""
#: plugins-test/alias//index.php:77
msgid "Update"
msgstr ""
#: plugins-test/alias//index.php:82
msgid "New alias"
msgstr ""
#: plugins-test/alias//index.php:84
msgid "Alias URL:"
msgstr ""
#: plugins-test/alias//index.php:85
msgid "Alias destination:"
msgstr ""

19
locales/en/help.html Normal file
View File

@ -0,0 +1,19 @@
<p>Aliases allow you to map any URLs you create to any available resource of
your blog.</p>
<dl>
<dt>Alias URL</dt>
<dd>Alias URL is the URL you create, without your blog URL. An alias URL
named "aboutme" will be caught when someone call http://yourblog/aboutme
page.</dd>
<dt>Alias destination</dt>
<dd>Alias destination is the resource your alias is pointing to. If you
create an alias called "aboutme" and want it to serve your static page
"aboutme", alias destination will be "pages/aboutme".</dd>
<dt>Regular expressions</dt>
<dd>You can use regular expression by wrapping alias URL with "/";
ie. "/^word\/(.+)?$/". You can use captures in destination; ie.
"tag/$1".</dd>
</dl>

20
locales/fr/help.html Normal file
View File

@ -0,0 +1,20 @@
<p>Les alias vous permettent de définir n'importe quelle URL renvoyant le
contenu de n'importe quelle ressource disponible de votre blog.</p>
<dl>
<dt>URL de l'alias</dt>
<dd>L'URL de l'alias est l'URL que vous créez, sans l'URL du blog. Une URL
d'alias appelée "a-propos" sera reconnu quand quelqu'un appellera la page
http://votreblog/a-propos.</dd>
<dt>Destination de l'alias</dt>
<dd>La destination de l'alias est la ressource dont le contenu sera
renvoyé par votre alias. Si vous créez un alias "a-propos" et souhaitez
le faire pointer sur la page statique "a-propos", la destination de
l'alias sera "pages/a-propos".</dd>
<dt>Expressions rationnelles</dt>
<dd>Vous pouvez utiliser des expressions rationnelles en encadrant l'URL
de l'alias par "/", par exemple : "/^word\/(.+)?$/". Vous pouvez utiliser
les captures dans la destination, par exemple : "tag/$1".</dd>
</dl>

30
locales/fr/main.lang.php Normal file
View File

@ -0,0 +1,30 @@
<?php
# -- BEGIN LICENSE BLOCK ----------------------------------
#
# This file is part of alias
#
# Copyright (c) 2010 julien mudry
#
# -- END LICENSE BLOCK ------------------------------------#
#
#
# DOT NOT MODIFY THIS FILE! (It is auto-generated)
$GLOBALS['__l10n']['Aliases'] = 'Alias';
$GLOBALS['__l10n']['Invalid aliases definitions'] = 'Définitions d\'alias invalides';
$GLOBALS['__l10n']['Alias URL is empty.'] = 'L\'URL de l\'alias est vide.';
$GLOBALS['__l10n']['Alias destination is empty.'] = 'La destination de l\'alias est vide.';
$GLOBALS['__l10n']['Aliases list'] = 'Liste des alias';
$GLOBALS['__l10n']['No alias'] = 'Aucun alias';
$GLOBALS['__l10n']['Alias URL'] = 'URL de l\'alias';
$GLOBALS['__l10n']['Alias destination'] = 'Destination de l\'alias';
$GLOBALS['__l10n']['Alias position'] = 'Position de l\'alias';
$GLOBALS['__l10n']['To remove an alias, empty its URL or destination.'] = 'Pour supprimer un alias, videz son URL ou sa destination.';
$GLOBALS['__l10n']['Update'] = 'Mettre à jour';
$GLOBALS['__l10n']['New alias'] = 'Nouvel alias';
$GLOBALS['__l10n']['Alias URL:'] = 'URL de l\'alias :';
$GLOBALS['__l10n']['Alias destination:'] = 'Destination de l\'alias :';
?>