2021-09-08 22:53:13 +00:00
|
|
|
<?php
|
2021-09-08 23:02:10 +00:00
|
|
|
/**
|
2021-09-08 23:05:05 +00:00
|
|
|
* @brief noodles, a plugin for Dotclear 2
|
2021-09-08 23:02:10 +00:00
|
|
|
*
|
|
|
|
* @package Dotclear
|
2021-09-08 23:05:05 +00:00
|
|
|
* @subpackage Plugin
|
2021-09-08 23:02:10 +00:00
|
|
|
*
|
2021-09-08 23:05:05 +00:00
|
|
|
* @author Jean-Christian Denis and contributors
|
2021-09-08 23:02:10 +00:00
|
|
|
*
|
|
|
|
* @copyright Jean-Christian Denis
|
|
|
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
|
|
|
*/
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-09-08 22:53:13 +00:00
|
|
|
|
|
|
|
dcPage::check('admin');
|
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
include dirname(__FILE__) . '/inc/_default_noodles.php';
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
$s = $core->blog->settings->noodles;
|
2021-09-08 22:53:13 +00:00
|
|
|
|
|
|
|
$__noodles = noodles::decode($s->noodles_object);
|
2021-09-09 20:30:34 +00:00
|
|
|
if ($__noodles->isEmpty()) {
|
2021-09-08 23:02:10 +00:00
|
|
|
$__noodles = $__default_noodles;
|
2021-09-09 20:30:34 +00:00
|
|
|
} else {
|
2021-09-08 23:02:10 +00:00
|
|
|
$default_noodles_array = $__default_noodles->noodles();
|
2021-11-01 09:28:22 +00:00
|
|
|
foreach ($default_noodles_array as $id => $noodle) {
|
2021-09-09 20:30:34 +00:00
|
|
|
if ($__noodles->exists($id)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$__noodles->set($id, $noodle);
|
2021-09-08 23:02:10 +00:00
|
|
|
}
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
$public_path = path::real($core->blog->public_path);
|
|
|
|
if (!is_dir($public_path) || !is_writable($public_path)) {
|
|
|
|
$public_path = false;
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
$default_images = files::scandir(dirname(__FILE__) . '/default-templates/img/');
|
|
|
|
if (!is_array($default_images)) {
|
|
|
|
$default_images = [];
|
|
|
|
}
|
|
|
|
$default_image = $s->noodles_image;
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-10-30 20:42:09 +00:00
|
|
|
$combo_api = [
|
2021-11-01 09:28:22 +00:00
|
|
|
'gravatar' => 'http://www.gravatar.com/',
|
2021-10-30 20:42:09 +00:00
|
|
|
'libravatar' => 'http://cdn.libravatar.org/'
|
|
|
|
];
|
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
$combo_place = [
|
2021-11-01 09:28:22 +00:00
|
|
|
__('Begin') => 'prepend',
|
|
|
|
__('End') => 'append',
|
2021-09-08 23:02:10 +00:00
|
|
|
__('Before') => 'before',
|
2021-11-01 09:28:22 +00:00
|
|
|
__('After') => 'after'
|
2021-09-09 20:30:34 +00:00
|
|
|
];
|
|
|
|
$combo_rating = [
|
2021-11-01 09:28:22 +00:00
|
|
|
'G' => 'g',
|
2021-09-09 20:30:34 +00:00
|
|
|
'PG' => 'pg',
|
2021-11-01 09:28:22 +00:00
|
|
|
'R' => 'r',
|
|
|
|
'X' => 'x'
|
2021-09-09 20:30:34 +00:00
|
|
|
];
|
|
|
|
$combo_size = [
|
2021-11-01 09:28:22 +00:00
|
|
|
'16px' => 16,
|
|
|
|
'24px' => 24,
|
|
|
|
'32px' => 32,
|
|
|
|
'48px' => 48,
|
|
|
|
'56px' => 56,
|
|
|
|
'64px' => 64,
|
|
|
|
'92px' => 92,
|
2021-09-09 20:30:34 +00:00
|
|
|
'128px' => 128,
|
|
|
|
'256px' => 256
|
|
|
|
];
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!empty($_POST['save'])) {
|
|
|
|
try {
|
|
|
|
$public_file = $public_path . '/noodles-default-image.png';
|
|
|
|
$s->put('noodles_active', !empty($_POST['noodles_active']), 'boolean');
|
2021-10-30 20:42:09 +00:00
|
|
|
$s->put('noodles_api', $_POST['noodles_api'], 'string');
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
// user upload image
|
|
|
|
if ($_POST['noodles_image'] == 'user' && !empty($public_path)) {
|
|
|
|
if (2 == $_FILES['noodlesuserfile']['error']) {
|
2021-09-08 23:02:10 +00:00
|
|
|
throw new Exception(__('Maximum file size exceeded'));
|
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
if (0 != $_FILES['noodlesuserfile']['error']) {
|
2021-09-08 23:02:10 +00:00
|
|
|
throw new Exception(__('Something went wrong while download file'));
|
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!in_array($_FILES['noodlesuserfile']['type'], ['image/png', 'image/x-png'])) {
|
2021-09-08 23:02:10 +00:00
|
|
|
throw new Exception(__('Image must be in png format'));
|
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
if (move_uploaded_file($_FILES['noodlesuserfile']['tmp_name'], $public_file)) {
|
|
|
|
$s->put('noodles_image', 1, 'boolean');
|
|
|
|
} else {
|
2021-09-09 20:46:00 +00:00
|
|
|
throw new Exception(__('Failed to save image'));
|
2021-09-08 23:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 09:28:22 +00:00
|
|
|
// Default gravatar.com avatar
|
2021-09-09 20:30:34 +00:00
|
|
|
} elseif ($_POST['noodles_image'] == 'gravatar.com') {
|
|
|
|
$s->put('noodles_image', 0, 'boolean');
|
|
|
|
|
|
|
|
// existsing noodles image on blog
|
|
|
|
} elseif ($_POST['noodles_image'] == 'existing') {
|
|
|
|
$s->put('noodles_image', 1, 'boolean');
|
|
|
|
|
|
|
|
// noodles image
|
|
|
|
} elseif (preg_match('/^gravatar-[0-9]+.png$/', $_POST['noodles_image']) && !empty($public_path)) {
|
|
|
|
$source = dirname(__FILE__) . '/default-templates/img/' . $_POST['noodles_image'];
|
|
|
|
if (!file_exists($source)) {
|
2021-09-08 23:02:10 +00:00
|
|
|
throw new Exception(__('Something went wrong while search file'));
|
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
if (files::putContent($public_file, file_get_contents($source))) {
|
|
|
|
$s->put('noodles_image', 1, 'boolean');
|
2021-09-08 23:02:10 +00:00
|
|
|
}
|
|
|
|
|
2021-11-01 09:28:22 +00:00
|
|
|
// Default gravatar.com avatar
|
2021-09-09 20:30:34 +00:00
|
|
|
} else { //if ($_POST['noodles_image'] == 'gravatar.com') {
|
|
|
|
$s->put('noodles_image', 0, 'boolean');
|
|
|
|
}
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
// behaviors
|
2021-11-01 09:28:22 +00:00
|
|
|
foreach ($_POST['noodle'] as $id => $bloc) {
|
2021-09-09 20:30:34 +00:00
|
|
|
$__noodles->get($id)
|
|
|
|
->set('active', !empty($bloc['active']))
|
|
|
|
->set('rating', $bloc['rating'] ?? 'g')
|
|
|
|
->set('size', $bloc['size'] ?? '16')
|
|
|
|
->set('css', $bloc['css'] ?? '')
|
|
|
|
->set('target', $bloc['target'] ?? '')
|
|
|
|
->set('place', $bloc['place'] ?? 'prepend')
|
|
|
|
;
|
2021-09-08 23:02:10 +00:00
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
$s->put('noodles_object', $__noodles->encode(), 'string');
|
2021-09-08 23:02:10 +00:00
|
|
|
|
|
|
|
$core->blog->triggerBlog();
|
2021-09-09 20:46:00 +00:00
|
|
|
dcPage::addSuccessNotice(__('Configuration successfully updated'));
|
2021-09-09 20:30:34 +00:00
|
|
|
$core->adminurl->redirect('admin.plugin.noodles');
|
|
|
|
} catch (Exception $e) {
|
2021-09-08 23:02:10 +00:00
|
|
|
$core->error->add($e->getMessage());
|
|
|
|
}
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '<html><head><title>' . __('Noodles') . '</title></head><body>' .
|
|
|
|
dcPage::breadcrumb([
|
2021-11-01 09:28:22 +00:00
|
|
|
html::escapeHTML($core->blog->name) => '',
|
|
|
|
__('Noodles') => '',
|
|
|
|
__('Plugin configuration') => ''
|
2021-09-09 20:30:34 +00:00
|
|
|
]) .
|
|
|
|
dcPage::notices() . '
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-11-01 09:28:22 +00:00
|
|
|
<form id="module_config" action="' .
|
|
|
|
$core->adminurl->get('admin.plugin.noodles') .
|
2021-09-09 20:30:34 +00:00
|
|
|
'" method="post" enctype="multipart/form-data">
|
|
|
|
<h3>' . sprintf(__('Configure "%s"'), __('Noodles')) . '</h3>
|
|
|
|
<div class="fieldset"><h4>' . __('Activation') . '</h4>
|
2021-11-01 09:28:22 +00:00
|
|
|
<p><label for="noodles_active">' .
|
|
|
|
form::checkbox('noodles_active', 1, $s->noodles_active) .
|
2021-10-30 20:42:09 +00:00
|
|
|
__('Enable plugin noodles on this blog') . '</label></p>
|
|
|
|
<p><label for="noodles_api" class="classic">' . __('API:') . ' </label>' .
|
|
|
|
form::combo('noodles_api', $combo_api, $s->noodles_api) . '</p>
|
2021-09-09 20:30:34 +00:00
|
|
|
</div>
|
|
|
|
<div class="fieldset"><h4>' . __('Avatar') . '</h4>
|
|
|
|
<p>' . __('Select default avatar to display on unknown users.') . '</p>';
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!empty($public_path)) {
|
|
|
|
echo '<div class="one-box">';
|
|
|
|
sort($default_images);
|
|
|
|
$i = 0;
|
2021-11-01 09:28:22 +00:00
|
|
|
foreach ($default_images as $f) {
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!preg_match('/gravatar-[0-9]+.png/', $f)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$i++;
|
2021-11-01 09:28:22 +00:00
|
|
|
$sz = getimagesize(dirname(__FILE__) . '/default-templates/img/' . $f);
|
2021-09-09 20:30:34 +00:00
|
|
|
$sz[2] = files::size(filesize(dirname(__FILE__) . '/default-templates/img/' . $f));
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '
|
|
|
|
<div class="fieldset box">
|
|
|
|
<p>' . form::radio(['noodles_image', 'noodles_image_' . $i], $f) . '
|
|
|
|
<label class="classic" for="noodles_image_' . $i . '">' . basename($f) . '</label></p>
|
|
|
|
<div class="two-box"><div class="box">
|
|
|
|
<p><img src="' . dcPage::getPF('noodles/default-templates/img/' . $f) . '" alt="" /></p>
|
|
|
|
</div><div class="box">
|
|
|
|
<p>' . $sz[0] . 'x' . $sz[1] . '<br />' . $sz[2] . '</p>
|
|
|
|
</div></div>
|
|
|
|
</div>';
|
2021-09-08 23:02:10 +00:00
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '</div>';
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '<div class="one-box">';
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
if (null !== ($default_image_path = noodlesLibImagePath::getPath($core, 'noodles'))) {
|
2021-11-01 09:28:22 +00:00
|
|
|
$sz = getimagesize($default_image_path);
|
2021-09-09 20:30:34 +00:00
|
|
|
$sz[2] = files::size(filesize($default_image_path));
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '
|
|
|
|
<div class="fieldset box">
|
|
|
|
<p>' . form::radio(['noodles_image', 'public_image'], 'existing', !empty($default_image)) . '
|
|
|
|
<label class="classic" for="public_image">' . __('Blog default image') . '</label></p>
|
|
|
|
<div class="two-box"><div class="box">
|
2021-10-31 22:29:20 +00:00
|
|
|
<p><img src="' . noodlesLibImagePath::getUrl($core, 'noodles') . '?' . rand() . '" alt="" /></p>
|
2021-09-09 20:30:34 +00:00
|
|
|
</div><div class="box">
|
|
|
|
<p>' . $sz[0] . 'x' . $sz[1] . '<br />' . $sz[2] . '</p>
|
|
|
|
</div></div>
|
|
|
|
</div>';
|
|
|
|
}
|
2021-09-08 23:02:10 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
if (!empty($public_path)) {
|
|
|
|
echo '
|
|
|
|
<div class="fieldset box">
|
|
|
|
<p>' . form::radio(['noodles_image', 'upload_image'], 'user') . '
|
|
|
|
<label class="classic" for="upload_image">' . __('Upload a new avatar') . '</label></p>
|
|
|
|
<p>' . form::hidden(['MAX_FILE_SIZE'], 30000) . '
|
|
|
|
<input type="file" name="noodlesuserfile" />
|
|
|
|
<p class="form-note">' . __('Image must be in "png" format and have a maximum file size of 30Ko') . '</p>
|
|
|
|
</div>';
|
|
|
|
}
|
|
|
|
echo '
|
|
|
|
<div class="fieldset box">
|
2021-11-01 09:28:22 +00:00
|
|
|
<p>' . form::radio(['noodles_image', 'com_image'], 'gravatar.com', empty($default_image)) . '
|
|
|
|
<label class="classic">' . __('API default image') . '</label></p>
|
2021-09-09 20:30:34 +00:00
|
|
|
</div>';
|
2021-09-08 23:02:10 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
if (empty($public_path)) {
|
|
|
|
echo '<p class="info">' . __('Public directory is not writable, you can not use custom gravatar.') . '</p>';
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '
|
|
|
|
</div></div>
|
|
|
|
<div class="fieldset"><h4>' . __('Behaviors') . '</h4>
|
|
|
|
<div class="table-outer">
|
|
|
|
<table><caption class="hidden">' . __('Behaviors list') . '</caption><tbody><tr>
|
2021-11-01 09:28:22 +00:00
|
|
|
<th colspan="2" class="first">' . __('Search area') . '</th>
|
|
|
|
<th scope="col">' . __('Size') . '</th>
|
|
|
|
<th scope="col">' . __('Rating') . '</th>
|
|
|
|
<th scope="col">' . __('PHP') . '</th>
|
|
|
|
<th scope="col">' . __('JS') . '</th>
|
|
|
|
<th scope="col">' . __('Target') . '</th>
|
|
|
|
<th scope="col">' . __('Place') . '</th>
|
|
|
|
<th colspan="2" scope="col">' . __('Adjust avatar CSS') . '</th>
|
2021-09-09 20:30:34 +00:00
|
|
|
</tr>';
|
2021-09-08 23:02:10 +00:00
|
|
|
|
2021-11-01 09:28:22 +00:00
|
|
|
foreach ($__noodles->noodles() as $noodle) {
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '
|
|
|
|
<tr class="line">
|
|
|
|
<td>' . form::checkbox(['noodle[' . $noodle->id() . '][active]', 'ck_' . $noodle->id()], 1, $noodle->active) . '</td>
|
2021-11-01 09:28:22 +00:00
|
|
|
<td class="nowrap" scope="row"><label for="ck_' . $noodle->id() . '">' . $noodle->name() . '</label></td>
|
2021-09-09 20:30:34 +00:00
|
|
|
<td>' . form::combo(['noodle[' . $noodle->id() . '][size]'], $combo_size, $noodle->size) . '</td>
|
|
|
|
<td>' . form::combo(['noodle[' . $noodle->id() . '][rating]'], $combo_rating, $noodle->rating) . '</td>
|
2021-11-01 09:28:22 +00:00
|
|
|
<td>' . (
|
|
|
|
$noodle->hasPhpCallback() ?
|
|
|
|
'<img alt="ok" src="images/check-on.png" />' :
|
2021-09-09 20:30:34 +00:00
|
|
|
'<img alt="nok" src="images/check-off.png" />'
|
|
|
|
) . '</td>
|
|
|
|
<td><img alt="ok" src="images/check-on.png" /></td>
|
|
|
|
<td>' . form::field(['noodle[' . $noodle->id() . '][target]'], 20, 255, $noodle->target) . '</td>
|
2021-11-01 09:28:22 +00:00
|
|
|
<td>' . form::combo(['noodle[' . $noodle->id() . '][place]'], $combo_place, $noodle->place) . '</td>
|
|
|
|
<td>' . form::field(['noodle[' . $noodle->id() . '][css]'], 50, 255, $noodle->css) . '</td>
|
2021-09-09 20:30:34 +00:00
|
|
|
<td> .noodles-' . $noodle->id() . '{}</td>
|
|
|
|
</tr>';
|
2021-09-08 22:53:13 +00:00
|
|
|
}
|
2021-09-09 20:30:34 +00:00
|
|
|
echo '
|
|
|
|
</tbody></table></div>
|
|
|
|
<p class="form-note">' . __('Target and Place are for javascript.') . '</p>
|
|
|
|
</div>
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-09 20:30:34 +00:00
|
|
|
<p class="clear">
|
|
|
|
<input type="submit" value="' . __('Save') . ' (s)" accesskey="s" name="save" /> ' .
|
|
|
|
$core->formNonce() . '</p>
|
|
|
|
</form>
|
2021-09-08 22:53:13 +00:00
|
|
|
|
2021-09-08 23:02:10 +00:00
|
|
|
</body></html>';
|