commit 223edca104d3ed6dd064b713625ce68e4db5267e
Author: Jean-Christian Denis
Date: Sun Dec 4 16:32:11 2022 +0100
first commit from filesAlias 0.6
diff --git a/_admin.php b/_admin.php
new file mode 100644
index 0000000..a7635f3
--- /dev/null
+++ b/_admin.php
@@ -0,0 +1,32 @@
+addItem(__('Medias sharing'),
+ $core->adminurl->get('admin.plugin.filesAlias'),
+ dcPage::getPF('filesAlias/icon.png'),
+ preg_match('/plugin.php(.*)$/',$_SERVER['REQUEST_URI']) && !empty($_REQUEST['p']) && $_REQUEST['p']=='filesAlias',
+ $core->auth->check('contentadmin',$core->blog->id));
+
+$core->addBehavior('adminDashboardFavorites','filesAliasDashboardFavorites');
+
+function filesAliasDashboardFavorites($core,$favs)
+{
+ $favs->register('filesAlias', array(
+ 'title' => __('Medias sharing'),
+ 'url' => $core->adminurl->get('admin.plugin.filesAlias'),
+ 'small-icon' => dcPage::getPF('filesAlias/icon.png'),
+ 'large-icon' => dcPage::getPF('filesAlias/icon_b.png'),
+ 'permissions' => 'usage,contentadmin'
+ ));
+}
diff --git a/_define.php b/_define.php
new file mode 100644
index 0000000..ec2ce4b
--- /dev/null
+++ b/_define.php
@@ -0,0 +1,27 @@
+registerModule(
+ /* Name */ 'filesAlias',
+ /* Description*/ "Manage aliases of your blog's medias",
+ /* Author */ "Osku & Pierre Van Glabeke",
+ /* Version */ '0.6',
+ array(
+ 'permissions' => 'contentadmin',
+ 'type' => 'plugin',
+ 'dc_min' => '2.7',
+ 'support' => 'http://forum.dotclear.org/viewtopic.php?id=42317',
+ 'details' => 'http://plugins.dotaddict.org/dc2/details/filesAlias'
+ )
+);
\ No newline at end of file
diff --git a/_install.php b/_install.php
new file mode 100644
index 0000000..f65ac81
--- /dev/null
+++ b/_install.php
@@ -0,0 +1,44 @@
+plugins->moduleInfo('filesAlias','version');
+
+if (version_compare($core->getVersion('filesAlias'),$version,'>=')) {
+ return;
+}
+
+/* Database schema
+-------------------------------------------------------- */
+$s = new dbStruct($core->con,$core->prefix);
+
+$s->filesalias
+ ->blog_id('varchar',32,false)
+ ->filesalias_url('varchar',255,false)
+ ->filesalias_destination('varchar',255,false)
+ ->filesalias_password('varchar',32,true,null)
+ ->filesalias_disposable('smallint',0,false,0)
+
+ ->primary('pk_filesalias','blog_id','filesalias_url')
+
+ ->index('idx_filesalias_blog_id','btree','blog_id')
+
+ ->reference('fk_filesalias_blog','blog_id','blog','blog_id','cascade','cascade')
+ ;
+
+# Schema installation
+$si = new dbStruct($core->con,$core->prefix);
+$changes = $si->synchronize($s);
+
+$core->setVersion('filesAlias',$version);
+return true;
\ No newline at end of file
diff --git a/_prepend.php b/_prepend.php
new file mode 100644
index 0000000..350728c
--- /dev/null
+++ b/_prepend.php
@@ -0,0 +1,25 @@
+filealias = new filesAliases($core);
+
+$core->url->register('filesalias',
+ 'pub',
+ '^pub/(.+)$',
+ array('urlFilesAlias','alias')
+);
\ No newline at end of file
diff --git a/_public.php b/_public.php
new file mode 100644
index 0000000..040d0a7
--- /dev/null
+++ b/_public.php
@@ -0,0 +1,102 @@
+tpl->setPath($core->tpl->getPath(), dirname(__FILE__).'/default-templates');
+$core->tpl->addValue('fileAliasURL',array('templateAlias','fileAliasURL'));
+
+class templateAlias
+{
+ public static function fileAliasURL($attr)
+ {
+ global $core, $_ctx;
+
+ $f = $GLOBALS['core']->tpl->getFilters($attr);
+ return 'blog->url.$core->url->getBase("filesalias")."/".$_ctx->filealias->filesalias_url').'; ?>';
+ }
+}
+
+class urlFilesAlias extends dcUrlHandlers
+{
+ public static function alias($args)
+ {
+ $_ctx =& $GLOBALS['_ctx'];
+ $core =& $GLOBALS['core'];
+ $delete = false;
+
+ $_ctx->filealias = $core->filealias->getAlias($args);
+
+ if ($_ctx->filealias->isEmpty()) {
+ self::p404();
+ }
+
+ if ($_ctx->filealias->filesalias_disposable) {
+ $delete = true;
+ }
+
+ if ($_ctx->filealias->filesalias_password) {
+
+ # Check for match
+ if (!empty($_POST['filepassword']) && $_POST['filepassword'] == $_ctx->filealias->filesalias_password)
+ {
+ self::servefile($_ctx->filealias->filesalias_destination,$args,$delete);
+ }
+ else
+ {
+ self::serveDocument('file-password-form.html','text/html',false);
+ return;
+ }
+ }
+ else
+ {
+ self::servefile($_ctx->filealias->filesalias_destination,$args,$delete);
+ }
+ }
+
+ public static function servefile($target,$alias,$delete=false)
+ {
+ $core =& $GLOBALS['core'];
+
+ $a= new aliasMedia($core);
+ $media = $a->getMediaId($target);
+
+ if (empty($media))
+ {
+ self::p404();
+ }
+
+ $file = $core->media->getFile($media);
+
+ if (empty($file->file))
+ {
+ self::p404();
+ }
+
+ header('Content-type: '.$file->type);
+ header('Content-Length: '.$file->size);
+ header('Content-Disposition: attachment; filename="'.$file->basename.'"');
+
+ if (ob_get_length() > 0) {
+ ob_end_clean();
+ }
+ flush();
+
+ readfile($file->file);
+ if ($delete) {
+ $core->filealias->deleteAlias($alias);
+ }
+
+ return;
+ }
+}
\ No newline at end of file
diff --git a/changelog b/changelog
new file mode 100644
index 0000000..b93a4ed
--- /dev/null
+++ b/changelog
@@ -0,0 +1,2 @@
+v0.6 - 19-06-2015 - Osku & Pierre Van Glabeke
+* première version publique
\ No newline at end of file
diff --git a/default-templates/file-password-form.html b/default-templates/file-password-form.html
new file mode 100644
index 0000000..fbecb53
--- /dev/null
+++ b/default-templates/file-password-form.html
@@ -0,0 +1,42 @@
+
+
+
+
+
+
+ {{tpl:lang Password needed}} - {{tpl:BlogName encode_html="1"}}
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/icon.png b/icon.png
new file mode 100644
index 0000000..81a2044
Binary files /dev/null and b/icon.png differ
diff --git a/icon_b.png b/icon_b.png
new file mode 100644
index 0000000..4d54dc9
Binary files /dev/null and b/icon_b.png differ
diff --git a/inc/class.files.alias.php b/inc/class.files.alias.php
new file mode 100644
index 0000000..68d9f91
--- /dev/null
+++ b/inc/class.files.alias.php
@@ -0,0 +1,130 @@
+core =& $core;
+ }
+
+ public function getAliases()
+ {
+ if (is_array($this->aliases)) {
+ return $this->aliases;
+ }
+
+ $this->aliases = array();
+ $sql = 'SELECT filesalias_url, filesalias_destination, filesalias_password, filesalias_disposable '.
+ 'FROM '.$this->core->prefix.'filesalias '.
+ "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
+ 'ORDER BY filesalias_url ASC ';
+ $this->aliases = $this->core->con->select($sql)->rows();
+ return $this->aliases;
+ }
+
+ public function getAlias($url)
+ {
+ $strReq = 'SELECT filesalias_url, filesalias_destination, filesalias_password, filesalias_disposable '.
+ 'FROM '.$this->core->prefix.'filesalias '.
+ "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
+ "AND filesalias_url = '".$this->core->con->escape($url)."' ".
+ 'ORDER BY filesalias_url ASC ';
+
+ $rs = $this->core->con->select($strReq);
+ return $rs;
+ }
+
+ public function updateAliases($aliases)
+ {
+ $this->core->con->begin();
+ try
+ {
+ $this->deleteAliases();
+ foreach ($aliases as $k => $v)
+ {
+ if (!empty($v['filesalias_url']) && !empty($v['filesalias_destination']))
+ {
+ $v['filesalias_disposable'] = isset($v['filesalias_disposable']) ? true : false;
+ $this->createAlias($v['filesalias_url'],$v['filesalias_destination'],$v['filesalias_disposable'],$v['filesalias_password']);
+ }
+ }
+
+ $this->core->con->commit();
+ }
+ catch (Exception $e)
+ {
+ $this->core->con->rollback();
+ throw $e;
+ }
+ }
+
+ public function createAlias($url,$destination,$disposable=0,$password=null)
+ {
+ if (!$url) {
+ throw new Exception(__('File URL is empty.'));
+ }
+
+ if (!$destination) {
+ throw new Exception(__('File destination is empty.'));
+ }
+
+ $cur = $this->core->con->openCursor($this->core->prefix.'filesalias');
+ $cur->blog_id = (string) $this->core->blog->id;
+ $cur->filesalias_url = (string) $url;
+ $cur->filesalias_destination = (string) $destination;
+ $cur->filesalias_password = $password;
+ $cur->filesalias_disposable = abs((integer) $disposable);
+ $cur->insert();
+ }
+
+ public function deleteAliases()
+ {
+ $this->core->con->execute(
+ 'DELETE FROM '.$this->core->prefix.'filesalias '.
+ "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' "
+ );
+ }
+
+ public function deleteAlias($url)
+ {
+ $this->core->con->execute(
+ 'DELETE FROM '.$this->core->prefix.'filesalias '.
+ "WHERE blog_id = '".$this->core->con->escape($this->core->blog->id)."' ".
+ "AND filesalias_url = '".$this->core->con->escape($url)."' "
+ );
+ }
+}
+
+class aliasMedia extends dcMedia
+{
+ public function __construct($core)
+ {
+ parent::__construct($core);
+ }
+
+ public function getMediaId($target)
+ {
+ $strReq =
+ 'SELECT media_id '.
+ 'FROM '.$this->table.' '.
+ "WHERE media_path = '".$this->path."' ".
+ "AND media_file = '".$this->con->escape($target)."' ";
+
+ $rs = $this->core->con->select($strReq);
+ return $rs->media_id;
+ }
+}
diff --git a/inc/lib.files.alias.tools.php b/inc/lib.files.alias.tools.php
new file mode 100644
index 0000000..3e1121b
--- /dev/null
+++ b/inc/lib.files.alias.tools.php
@@ -0,0 +1,54 @@
+= 0; $t--) {
+ $bcp = pow($base, $t);
+ $a = floor($in / $bcp) % $base;
+ $out = $out . substr($index, $a, 1);
+ $in = $in - ($a * $bcp);
+ }
+ $out = strrev($out);
+
+ return $out;
+ }
+}
diff --git a/index.php b/index.php
new file mode 100644
index 0000000..4290c19
--- /dev/null
+++ b/index.php
@@ -0,0 +1,178 @@
+filealias;
+$aliases = $o->getAliases();
+$media = new dcMedia($core);
+$a= new aliasMedia($core);
+
+# 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['filesalias_url']))
+{
+ $url = empty($_POST['filesalias_url']) ? PallazzoTools::rand_uniqid() : $_POST['filesalias_url'];
+
+ $target = $_POST['filesalias_destination'];
+ $totrash = isset ($_POST['filesalias_disposable']) ? true : false;
+ $password = empty($_POST['filesalias_password'])? '' : $_POST['filesalias_password'];
+
+ if (preg_match('/^'.preg_quote($media->root_url,'/').'/',$target)) {
+ $target = preg_replace('/^'.preg_quote($media->root_url,'/').'/','',$target);
+ $media = $a->getMediaId($target);
+
+ if (!empty($media))
+ {
+ try {
+ $o->createAlias($url,$target,$totrash,$password);
+ http::redirect($p_url.'&created=1');
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ }
+ else
+ {
+ $core->error->add(__('Target is not in medias manager.'));
+ }
+ }
+ else
+ {
+ $media = $a->getMediaId($target);
+
+ if (!empty($media))
+ {
+ try {
+ $o->createAlias($url,$target,$totrash,$password);
+ http::redirect($p_url.'&created=1');
+ } catch (Exception $e) {
+ $core->error->add($e->getMessage());
+ }
+ }
+ else
+ {
+ $core->error->add(__('Target is not in medias manager.'));
+ }
+ }
+}
+?>
+
+
+
+
+
+
+blog->name) => '',
+ __('Medias sharing') => ''
+ )).
+ dcPage::notices();
+
+?>
+'.__('No alias').'
';
+}
+else
+{
+ $root_url = html::escapeHTML($media->root_url);
+ echo
+ '';
+}
+
+echo
+'';
+
+dcPage::helpBlock('filesAlias');
+?>
+
+
\ No newline at end of file
diff --git a/locales/en/help/filesAlias.html b/locales/en/help/filesAlias.html
new file mode 100644
index 0000000..3cac7b3
--- /dev/null
+++ b/locales/en/help/filesAlias.html
@@ -0,0 +1,26 @@
+
+
+
+ Help for filesAlias
+
+
+ Aliases allow you to set any URL that returns the contents of any resource
+ available in the /public
for your blog.
+ The target of the alias must be an element of the media manager's blog.
+ The URL alias will deliver the target without revealing the real media URL.
+ Otherwise, it's a classic redirect to the destination of the alias.
+ And if in addition you have chosen to create an alias disposable, it
+ self-delete after the first access to the URL in your browser.
+
+
+ - Destination
+ - The destination of the alias is an existing item in the library of blog.
+ This field is required.
+
+ - URL (alias)
+ - The alias is the URL that you create, not the blog URL. URL aliases
+ called "about" will be recognized when someone called http://yourblog/about.
+
+
+
+
\ No newline at end of file
diff --git a/locales/en/resources.php b/locales/en/resources.php
new file mode 100644
index 0000000..459abb3
--- /dev/null
+++ b/locales/en/resources.php
@@ -0,0 +1,17 @@
+
+
+
+ Aide filesAlias
+
+
+ Les alias vous permettent de définir n'importe quelle URL renvoyant le
+ contenu de n'importe quelle ressource disponible dans le dossier /public
de votre blog.
+ La cible de l'alias doit être un élément de la médiathèque du blog.
+ L'URL de l'alias délivrera la cible sans révéler l'URL réelle du média.
+ Sinon, c'est une redirection classique vers la destination de l'alias.
+ Et si en plus vous avez choisi de créer un alias jetable, celui-ci
+ s'auto-supprimera après le premier accès à l'URL dans votre navigateur.
+
+
+ - Destination
+ - La destination de l'alias est un élément existant dans la médiathèque du
+ blog. Ce champ est obligatoire.
+
+ - URL (alias)
+ - L'alias est l'URL que vous créez, sans l'URL du blog. Une URL
+ d'alias appelée "a-propos" sera reconnue quand quelqu'un appellera la page
+ http://votreblog/a-propos.
+
+
+
+
\ No newline at end of file
diff --git a/locales/fr/main.po b/locales/fr/main.po
new file mode 100644
index 0000000..fd8235d
--- /dev/null
+++ b/locales/fr/main.po
@@ -0,0 +1,101 @@
+# Language: Français
+# Module: filesAlias - 0.6beta
+# Date: 2015-06-16 17:26:03
+# Translated with translater 2015.03.02
+
+msgid ""
+msgstr ""
+"Content-Type: text/plain; charset=UTF-8\n"
+"Project-Id-Version: filesAlias 0.6beta\n"
+"POT-Creation-Date: \n"
+"PO-Revision-Date: 2015-06-16T17:26:03+00:00\n"
+"Last-Translator: brol\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: _admin.php:15
+#: _admin.php:24
+#: index.php:15
+#: index.php:91
+msgid "Medias sharing"
+msgstr "Partage de médias"
+
+#: inc/class.files.alias.php:78
+msgid "File URL is empty."
+msgstr "L'URL du fichier est vide."
+
+#: inc/class.files.alias.php:82
+msgid "File destination is empty."
+msgstr "La destination du fichier est vide."
+
+#: index.php:57
+#: index.php:75
+msgid "Target is not in medias manager."
+msgstr "La cible n'est pas dans le gestionnaire de médias."
+
+#: index.php:98
+msgid "Aliases successfully updated."
+msgstr "Les alias ont été mis à jour avec succès."
+
+#: index.php:102
+msgid "Alias for this media created."
+msgstr "L'alias pour votre fichier a été créé."
+
+#: index.php:111
+msgid "No alias"
+msgstr "Aucun alias"
+
+#: index.php:120
+msgid "Aliases list"
+msgstr "Liste des alias"
+
+#: index.php:122
+msgid "Destination"
+msgstr "Destination"
+
+#: index.php:123
+msgid "Alias"
+msgstr "Alias"
+
+#: index.php:124
+#: index.php:166
+msgid "Disposable"
+msgstr "Jetable"
+
+#: index.php:132
+#: index.php:137
+msgid "link"
+msgstr "lien"
+
+#: index.php:144
+msgid "To remove a link, empty its alias or destination."
+msgstr "Pour supprimer un lien, vider son alias ou sa destination."
+
+#: index.php:154
+msgid "New alias"
+msgstr "Nouvel alias"
+
+#: index.php:157
+msgid "Destination:"
+msgstr "Destination :"
+
+#: index.php:159
+msgid "Destination file must be in media manager."
+msgstr "Le fichier de destination doit se trouver dans la médiathèque."
+
+#: index.php:160
+msgid "Root URL \"%s
\" will be automatically removed."
+msgstr "La racine URL '%s
' sera automatiquement supprimée."
+
+#: index.php:162
+msgid "URL (alias):"
+msgstr "URL (alias) :"
+
+#: index.php:164
+msgid "Leave empty to get a randomize alias."
+msgstr "Laisser vide pour obtenir un alias aléatoire."
+
+msgid "Manage aliases of your blog's medias"
+msgstr "Gérer les alias des médias de votre blog"
+
diff --git a/locales/fr/resources.php b/locales/fr/resources.php
new file mode 100644
index 0000000..459abb3
--- /dev/null
+++ b/locales/fr/resources.php
@@ -0,0 +1,17 @@
+