better config fields

This commit is contained in:
Jean-Christian Paul Denis 2021-11-02 23:53:06 +01:00
parent 2d2ce675f6
commit aa102cb260
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 48 additions and 18 deletions

View File

@ -32,11 +32,17 @@ if ($cinecturlink2_public_nbrpp < 1) {
$cinecturlink2_public_nbrpp = 10;
}
$combo_dirs = cinecturlink2::getPublicDirs($core);
if (!empty($_POST['save'])) {
try {
$cinecturlink2_active = !empty($_POST['cinecturlink2_active']);
$cinecturlink2_widthmax = abs((integer) $_POST['cinecturlink2_widthmax']);
$cinecturlink2_folder = (string) files::tidyFileName($_POST['cinecturlink2_folder']);
$cinecturlink2_newdir = (string) files::tidyFileName($_POST['cinecturlink2_newdir']);
$cinecturlink2_folder = empty($cinecturlink2_newdir) ?
(string) files::tidyFileName($_POST['cinecturlink2_folder']) :
$cinecturlink2_newdir;
$cinecturlink2_triggeronrandom = !empty($_POST['cinecturlink2_triggeronrandom']);
$cinecturlink2_public_active = !empty($_POST['cinecturlink2_public_active']);
$cinecturlink2_public_title = (string) $_POST['cinecturlink2_public_title'];
@ -48,7 +54,7 @@ if (!empty($_POST['save'])) {
if (empty($cinecturlink2_folder)) {
throw new Exception(__('You must provide a specific folder for images.'));
}
cinecturlink2::test_folder(
cinecturlink2::makePublicDir(
DC_ROOT . '/' . $core->blog->settings->system->public_path,
$cinecturlink2_folder,
true
@ -82,11 +88,14 @@ echo '
form::checkbox('cinecturlink2_active', 1, $cinecturlink2_active) .
__('Enable plugin') . '</label></p>
<p><label for="cinecturlink2_widthmax">' . __('Maximum width of images (in pixel):') . ' ' .
form::field('cinecturlink2_widthmax', 10, 4, $cinecturlink2_widthmax, 'maximal') . '</label></p>
<p><label for="cinecturlink2_folder">'.__('Public folder of images (under public folder of blog):') . '</label>' .
form::combo('cinecturlink2_folder', $combo_dirs, $cinecturlink2_folder) . '</p>
<p><label for="cinecturlink2_folder">'.__('Public folder of images (under public folder of blog):') . ' ' .
form::field('cinecturlink2_folder', 60, 64, $cinecturlink2_folder, 'maximal') . '</label></p>
<p><label for="cinecturlink2_newdir">'.__('Or create a new public folder of images:') . '</label>' .
form::field('cinecturlink2_newdir', 60, 64, '', 'maximal') . '</p>
<p><label for="cinecturlink2_widthmax">' . __('Maximum width of images (in pixel):') . '</label>' .
form::number('cinecturlink2_widthmax', 10, 512, $cinecturlink2_widthmax) . '</p>
</div>
@ -108,14 +117,14 @@ form::checkbox('cinecturlink2_public_active', 1, $cinecturlink2_public_active) .
__('Enable public page') . '</label></p>
<p class="form-note">' . sprintf(__('Public page has url: %s'), '<a href="' . $core->blog->url.$core->url->getBase('cinecturlink2') . '" title="public page">' . $core->blog->url . $core->url->getBase('cinecturlink2') . '</a>') . '</p>
<p><label for="cinecturlink2_public_title">' . __('Title of the public page:') . ' ' .
form::field('cinecturlink2_public_title', 60, 255, $cinecturlink2_public_title, 'maximal') . '</label></p>
<p><label for="cinecturlink2_public_title">' . __('Title of the public page:') . '</label>' .
form::field('cinecturlink2_public_title', 60, 255, $cinecturlink2_public_title, 'maximal') . '</p>
<p><label for="cinecturlink2_public_description">' . __('Description of the public page:') . ' ' .
form::field('cinecturlink2_public_description', 60, 255, $cinecturlink2_public_description, 'maximal') . '</label></p>
<p><label for="cinecturlink2_public_description">' . __('Description of the public page:') . '</label>' .
form::field('cinecturlink2_public_description', 60, 255, $cinecturlink2_public_description, 'maximal') . '</p>
<p><label for="cinecturlink2_public_nbrpp">' . __('Limit number of entries per page on pulic page to:') . ' ' .
form::field('cinecturlink2_public_nbrpp', 5, 10, $cinecturlink2_public_nbrpp, 'maximal') . '</label></p>
<p><label for="cinecturlink2_public_nbrpp">' . __('Limit number of entries per page on pulic page to:') . '</label>' .
form::number('cinecturlink2_public_nbrpp', 1, 100, $cinecturlink2_public_nbrpp) . '</p>
</div>

View File

@ -446,7 +446,7 @@ class cinecturlink2
* @param boolean $throw Throw exception or not
* @return boolean True if exists and writable
*/
public static function test_folder($root, $folder, $throw = false)
public static function makePublicDir($root, $folder, $throw = false)
{
if (!is_dir($root . '/' . $folder)) {
if (!is_dir($root) || !is_writable($root) || !mkdir($root . '/' . $folder)) {
@ -458,4 +458,22 @@ class cinecturlink2
}
return true;
}
/**
* Get list of public directories
*
* @param dcCore $core Core instance
* @return array Directories
*/
public static function getPublicDirs($core)
{
$dirs = [];
$all = files::getDirList($core->blog->public_path);
foreach($all['dirs'] as $dir) {
$dir = substr($dir, strlen($core->blog->public_path) + 1);
$dirs[$dir] = $dir;
}
return $dirs;
}
}

View File

@ -196,7 +196,7 @@ if ($part == 'link') {
if (!empty($_POST['save'])) {
try {
cinecturlink2::test_folder(
cinecturlink2::makePublicDir(
DC_ROOT . '/' .$core->blog->settings->system->public_path,
$core->blog->settings->cinecturlink2->cinecturlink2_folder
);

View File

@ -3,7 +3,7 @@ msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: cinecturlink2 0.9.1\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2021-10-24T22:24:00+00:00\n"
"PO-Revision-Date: 2021-11-02T22:51:46+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
@ -19,12 +19,15 @@ msgstr "Évaluation"
msgid "You must provide a specific folder for images."
msgstr "Vous devez fournir un dossier spécifique pour les images."
msgid "Maximum width of images (in pixel):"
msgstr "Largeur maximum des images (en pixels) :"
msgid "Public folder of images (under public folder of blog):"
msgstr "Dossier publique des images (dans le répertoire \"public\" du blog) :"
msgid "Or create a new public folder of images:"
msgstr "Ou créer un nouveau dossier public :"
msgid "Maximum width of images (in pixel):"
msgstr "Largeur maximum des images (en pixels) :"
msgid "Update cache when use \"Random\" or \"Number of view\" order on widget (Need reload of widgets on change)"
msgstr "Mettre à jour le cache lors de l'utilisation de l'ordre \"Aléatoire\" ou \"Nombre d'affichages\" dans le widget (Nécessite le rechargement du widget)"