From 223edca104d3ed6dd064b713625ce68e4db5267e Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 4 Dec 2022 16:32:11 +0100 Subject: [PATCH] first commit from filesAlias 0.6 --- _admin.php | 32 ++++ _define.php | 27 ++++ _install.php | 44 ++++++ _prepend.php | 25 +++ _public.php | 102 +++++++++++++ changelog | 2 + default-templates/file-password-form.html | 42 +++++ icon.png | Bin 0 -> 442 bytes icon_b.png | Bin 0 -> 1606 bytes inc/class.files.alias.php | 130 ++++++++++++++++ inc/lib.files.alias.tools.php | 54 +++++++ index.php | 178 ++++++++++++++++++++++ locales/en/help/filesAlias.html | 26 ++++ locales/en/resources.php | 17 +++ locales/fr/help/filesAlias.html | 27 ++++ locales/fr/main.po | 101 ++++++++++++ locales/fr/resources.php | 17 +++ 17 files changed, 824 insertions(+) create mode 100644 _admin.php create mode 100644 _define.php create mode 100644 _install.php create mode 100644 _prepend.php create mode 100644 _public.php create mode 100644 changelog create mode 100644 default-templates/file-password-form.html create mode 100644 icon.png create mode 100644 icon_b.png create mode 100644 inc/class.files.alias.php create mode 100644 inc/lib.files.alias.tools.php create mode 100644 index.php create mode 100644 locales/en/help/filesAlias.html create mode 100644 locales/en/resources.php create mode 100644 locales/fr/help/filesAlias.html create mode 100644 locales/fr/main.po create mode 100644 locales/fr/resources.php 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"}} + + + + + + +
+

{{tpl:lang Password needed}}

+ +

{{tpl:lang You must give a password to access this area.}}

+

+ +
+ + + \ No newline at end of file diff --git a/icon.png b/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..81a2044b2175920806fd0337ce971ff78febe13c GIT binary patch literal 442 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`EX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4H%pvNSB~8r!Bge2*kbx0 z<}jB%-fsE42RPJa%=7-^wFqesl%gf12H}MNubYWY! z;F*fg`&||$PFQKCJVCDEdy4Sn)X5Uz?Q0KTj##5|KZx1mi;HaSwp0EL4WgQslV=+; z?oNteyY> literal 0 HcmV?d00001 diff --git a/icon_b.png b/icon_b.png new file mode 100644 index 0000000000000000000000000000000000000000..4d54dc9e91652bc1692bd9eedc9b39755b9ffdce GIT binary patch literal 1606 zcmV-M2D$l(P)Z5e)tbhHb=zXco3r zk!XBSq6zWO3y2AZ7o+a$tQ+kReNkiLpJ+sb34sUkf27-jiixt$h?rpHK@$vM>6jQL z*}C52!met=|zwexT&ON>Ne&?R=yP~S(;_}YDq3nohvd}0Z4WNy{{G1Ba z!EunJsty=Pdi=KkL^PbrB`lK#KsF5cf}tTtm3F{4o!*v#j4JU{>AG%xy&?18o96`} z(;tlVK6cLa z@evSm5;t3s16=$=ekw8^lWiIw2?oaId{)eMW`5@Ze52O;j%*n4!Px)=LqpC?9QL^o zbXhPodh1 zq`{m`Z)+57G*o|XKb_1sQ_IY3yp?uf3JwGBB9asI z9*G`#dG+vw>)!!y2A#xPh`bG4>DG`0oJ8(|K;?KX9c$fqA%S|QZ@G&72A4TZHLd|i zjnDhUR6-}?tG)xaxiwaG0Z`RXQ_<$X@{tua@4K~EbpgPb{(ME#{=pxC^Qt@rnRBCD zTI5$jH_kmhvLkPmW7jC)Y7MJ~r@+ssZXNV{cWAU_v=GJ6y!7>1>+!oWUdaF)5|!?> zfB!CxMr|<-WUX1_)`?04Ac;tPFxK*cDhe${H4exX%ofkm@PU0Rgj-U;d+>8_xfHzKdg$If; zCTn+lf=lMC4LH&ca-+)}rX&;`07bqmR7W-p_~wR&)&-W-J*}{~Q2pto-~bpg-{&hU zYj=AB*VU~L)bk`t&c|9MDLfCb_KIonqhb`12<2Zz)?N2y(_30!9rSsxMfDNj=fdqx zF9ioch4l+MKfbgeooMrDI^MQ@(D(IHQF#D3RH)tQqS!p(m2|9iQ_)5R2{=7>qc{jn z#kNxlicW=9bZ5rv+w^C&IX&@usB_tD7O~lhg)3k1!M@- zFMy;P&Y&z6xDS|(@(~`1rMp`4s_=v&dvCKC2M8DMPvMlKD!kWVqIq_#g`!Rb|8~IQXfe?y7=+WF3DGM=*a2Az!^8jt04eq(W@1C z_0(+ty1Z3xs25!Jp^5@9hG_nKjZk*@23#(JRTltYb-sIzto7XM)>t(LV9{`9)(cY! z)jNI5fhXM>tHuBTYz%hvK9_4j3_6Jx6}yKLeBW5DA4rT-v!BR}vlQ5hDk_SU`lSHX zI|a&y0ghMNi3)PufFvvJMdgsBQPrYea?Au&b-);?*%4qMX*_=0kIN5@E>bcczwI|C zqT!SX-IeyH+=$S9A{tH^fOM)ZuE@culx7Nw989O`;&3(((AOI>9<>is8&e_UHKPxW zpCbJ?5lY3|z6aUN%nm{ZWb?$+qcwkY_W#4vwSIj5AHIxC*gfL=EC2ui07*qoM6N<$ Ef*4}_egFUf literal 0 HcmV?d00001 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.')); + } + } +} +?> + + + <?php echo $page_title; ?> + + + +blog->name) => '', + __('Medias sharing') => '' + )). + dcPage::notices(); + +?> +'.__('No alias').'

'; +} +else +{ + $root_url = html::escapeHTML($media->root_url); + echo + '
'. + '
'. + ' + + '. + ''. + ''. + ''. + ''. + ''; + + foreach ($aliases as $k => $v) + { + $url = $core->blog->url.$core->url->getBase('filesalias').'/'.html::escapeHTML($v['filesalias_url']); + + $link = ''.__('link').''; + $v['filesalias_disposable'] = isset ($v['filesalias_disposable']) ? $v['filesalias_disposable'] : false; + echo + ''. + ''. + ''. + ''. + ''. + ''; + } + + echo '
'.__('Aliases list').'
'.__('Destination').' - '.$root_url.'(-?-)'.__('Alias').' - '.$core->blog->url.$core->url->getBase('filesalias').'/'.'(-?-)'.__('Disposable').''.__('Password').'
'.form::field(array('a['.$k.'][filesalias_destination]'),40,255,html::escapeHTML($v['filesalias_destination'])).''.form::field(array('a['.$k.'][filesalias_url]'),20,255,html::escapeHTML($v['filesalias_url'])).''.__('link').''.form::checkbox(array('a['.$k.'][filesalias_disposable]'),1,$v['filesalias_disposable']).''.form::field(array('a['.$k.'][filesalias_password]'),10,255,html::escapeHTML($v['filesalias_password'])).'
'. + '

'.__('To remove a link, empty its alias or destination.').'

'. + '

'.$core->formNonce(). + '

'. + '
'. + '
'; +} + +echo +'
+
+

'.__('New alias').'

+

'.form::field('filesalias_destination',70,255).' +

+

'.__('Destination file must be in media manager.').'

+

'.sprintf(__('Root URL "%s" will be automatically removed.'),$media->root_url).'

+

+

'.__('Leave empty to get a randomize alias.').'

+

'.form::checkbox('filesalias_disposable',1).'

+

+

'.$core->formNonce().'

+
+
'; + +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 @@ +