fix PSR coding style
This commit is contained in:
parent
d5d1f9bb1a
commit
f5493d6544
11 changed files with 187 additions and 132 deletions
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
$this->registerModule(
|
||||
'Noodles',
|
||||
'Add users gravatars everywhere',
|
||||
|
|
32
_install.php
32
_install.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -21,23 +20,46 @@ $old_version = $core->getVersion('noodles');
|
|||
if (version_compare($old_version, $new_version, '>=')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$core->blog->settings->addNamespace('noodles');
|
||||
$core->blog->settings->noodles->put(
|
||||
'noodles_active', false, 'boolean', 'Enable extension', false, true
|
||||
'noodles_active',
|
||||
false,
|
||||
'boolean',
|
||||
'Enable extension',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$core->blog->settings->noodles->put(
|
||||
'noodles_api', 'http://www.gravatar.com/', 'string', 'external API to use', false, true
|
||||
'noodles_api',
|
||||
'http://www.gravatar.com/',
|
||||
'string',
|
||||
'external API to use',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$core->blog->settings->noodles->put(
|
||||
'noodles_image', '', 'string', 'Image filename', false, true
|
||||
'noodles_image',
|
||||
'',
|
||||
'string',
|
||||
'Image filename',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$core->blog->settings->noodles->put(
|
||||
'noodles_object', '', 'string', 'Noodles behaviors', false, true
|
||||
'noodles_object',
|
||||
'',
|
||||
'string',
|
||||
'Noodles behaviors',
|
||||
false,
|
||||
true
|
||||
);
|
||||
$core->setVersion('noodles', $new_version);
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
$core->error->add($e->getMessage());
|
||||
}
|
||||
|
||||
return false;
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
|
25
_public.php
25
_public.php
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -35,7 +34,7 @@ if ($__noodles->isEmpty()) {
|
|||
|
||||
//$GLOBALS['__noodles'] =& $__noodles;
|
||||
|
||||
foreach($__noodles->noodles() AS $noodle) {
|
||||
foreach ($__noodles->noodles() as $noodle) {
|
||||
if ($noodle->active && $noodle->hasPhpCallback()) {
|
||||
$noodle->phpCallback($core);
|
||||
}
|
||||
|
@ -47,7 +46,7 @@ class publicNoodles
|
|||
{
|
||||
echo
|
||||
dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) .
|
||||
dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") .
|
||||
dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . '/js/jquery.noodles.js') .
|
||||
dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs'));
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +58,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
global $core, $__noodles;
|
||||
|
||||
$css = '';
|
||||
foreach($__noodles->noodles() AS $noodle) {
|
||||
foreach ($__noodles->noodles() as $noodle) {
|
||||
if (!$noodle->active || !$noodle->hasJsCallback()) {
|
||||
continue;
|
||||
}
|
||||
|
@ -78,12 +77,11 @@ class urlNoodles extends dcUrlHandlers
|
|||
global $core, $__noodles;
|
||||
|
||||
$targets = [];
|
||||
foreach($__noodles->noodles() AS $noodle) {
|
||||
foreach ($__noodles->noodles() as $noodle) {
|
||||
if (!$noodle->active || !$noodle->hasJsCallback()) {
|
||||
continue;
|
||||
}
|
||||
$targets[] =
|
||||
'$(\'' . html::escapeJS($noodle->target) . '\').noodles({' .
|
||||
$targets[] = '$(\'' . html::escapeJS($noodle->target) . '\').noodles({' .
|
||||
' imgId:\'' . html::escapeJS($noodle->id()) . '\',' .
|
||||
' imgPlace:\'' . html::escapeJS($noodle->place) . '\'' .
|
||||
'});';
|
||||
|
@ -116,12 +114,14 @@ class urlNoodles extends dcUrlHandlers
|
|||
$rsp->status = 'failed';
|
||||
$rsp->message(__('noodles is disabled on this blog'));
|
||||
echo $rsp->toXML(1);
|
||||
|
||||
return false;
|
||||
}
|
||||
if ($i === null || $c === null) {
|
||||
$rsp->status = 'failed';
|
||||
$rsp->message(__('noodles failed because of missing informations'));
|
||||
echo $rsp->toXML(1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
$rsp->status = 'failed';
|
||||
$rsp->message(__('Failed to load default noodles'));
|
||||
echo $rsp->toXML(1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -142,6 +143,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
$rsp->status = 'failed';
|
||||
$rsp->message(__('Failed to load noodle'));
|
||||
echo $rsp->toXML(1);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -182,11 +184,13 @@ class urlNoodles extends dcUrlHandlers
|
|||
|
||||
if (!$core->blog->settings->noodles->noodles_active) {
|
||||
self::p404();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!preg_match('#^(.*?)$#', $args, $m)) {
|
||||
self::p404();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -194,12 +198,14 @@ class urlNoodles extends dcUrlHandlers
|
|||
|
||||
if (!($f = self::searchTplFiles($f))) {
|
||||
self::p404();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$allowed_types = ['png', 'jpg', 'jpeg', 'gif', 'css', 'js', 'swf'];
|
||||
if (!in_array(files::getExtension($f), $allowed_types)) {
|
||||
self::p404();
|
||||
|
||||
return;
|
||||
}
|
||||
$type = files::getMimeType($f);
|
||||
|
@ -207,7 +213,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
header('Content-Type: ' . $type . '; charset=UTF-8');
|
||||
header('Content-Length: ' . filesize($f));
|
||||
|
||||
if ($type != "text/css" || $core->blog->settings->system->url_scan == 'path_info') {
|
||||
if ($type != 'text/css' || $core->blog->settings->system->url_scan == 'path_info') {
|
||||
readfile($f);
|
||||
} else {
|
||||
echo preg_replace(
|
||||
|
@ -222,7 +228,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
# Search noodles files like JS, CSS in default-templates subdirectories
|
||||
private static function searchTplFiles($file)
|
||||
{
|
||||
if (strstr($file,"..") !== false) {
|
||||
if (strstr($file, '..') !== false) {
|
||||
return false;
|
||||
}
|
||||
$paths = $GLOBALS['core']->tpl->getPath();
|
||||
|
@ -235,6 +241,7 @@ class urlNoodles extends dcUrlHandlers
|
|||
return $path . '/' . $file;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -10,35 +10,50 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'settings',
|
||||
/* action */ 'delete_all',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ __('delete all settings')
|
||||
/* type */
|
||||
'settings',
|
||||
/* action */
|
||||
'delete_all',
|
||||
/* ns */
|
||||
'noodles',
|
||||
/* description */
|
||||
__('delete all settings')
|
||||
);
|
||||
|
||||
$this->addUserAction(
|
||||
/* type */ 'plugins',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ __('delete plugin files')
|
||||
/* type */
|
||||
'plugins',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'noodles',
|
||||
/* description */
|
||||
__('delete plugin files')
|
||||
);
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'settings',
|
||||
/* action */ 'delete_all',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ sprintf(__('delete all %s settings'), 'noodles')
|
||||
/* type */
|
||||
'settings',
|
||||
/* action */
|
||||
'delete_all',
|
||||
/* ns */
|
||||
'noodles',
|
||||
/* description */
|
||||
sprintf(__('delete all %s settings'), 'noodles')
|
||||
);
|
||||
|
||||
$this->addDirectAction(
|
||||
/* type */ 'plugins',
|
||||
/* action */ 'delete',
|
||||
/* ns */ 'noodles',
|
||||
/* description */ sprintf(__('delete %s plugin files'), 'noodles')
|
||||
/* type */
|
||||
'plugins',
|
||||
/* action */
|
||||
'delete',
|
||||
/* ns */
|
||||
'noodles',
|
||||
/* description */
|
||||
sprintf(__('delete %s plugin files'), 'noodles')
|
||||
);
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -18,7 +17,7 @@ if (!defined('DC_RC_PATH')) {
|
|||
require dirname(__FILE__) . '/class.noodles.php';
|
||||
|
||||
global $__default_noodles;
|
||||
$__default_noodles = new noodles;
|
||||
$__default_noodles = new noodles();
|
||||
|
||||
# Posts (by public behavior)
|
||||
$__default_noodles
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -31,6 +30,7 @@ class genericNoodles
|
|||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $rs->user_email;
|
||||
}
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ class widgetsNoodles
|
|||
if (!$rs->isEmpty()) {
|
||||
return $rs->comment_email;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
@ -130,6 +131,7 @@ class authormodeNoodles
|
|||
if ($rs->isEmpty()) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $rs->user_email;
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -25,7 +24,8 @@ class noodles
|
|||
if ($o instanceof noodles) {
|
||||
return $o;
|
||||
}
|
||||
return new self;
|
||||
|
||||
return new self();
|
||||
}
|
||||
|
||||
public function encode()
|
||||
|
@ -36,12 +36,13 @@ class noodles
|
|||
public function add($id, $name, $js_callback, $php_callback = null)
|
||||
{
|
||||
$this->noodles[$id] = new noodle($id, $name, $js_callback, $php_callback);
|
||||
|
||||
return $this->noodles[$id];
|
||||
}
|
||||
|
||||
public function get($id)
|
||||
{
|
||||
return isset($this->noodles[$id]) ? $this->noodles[$id] : null;
|
||||
return $this->noodles[$id] ?? null;
|
||||
}
|
||||
|
||||
public function __get($id)
|
||||
|
@ -112,6 +113,7 @@ class noodle
|
|||
if (!is_callable($this->js_callback)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return call_user_func($this->js_callback, $g, $content);
|
||||
}
|
||||
|
||||
|
@ -125,6 +127,7 @@ class noodle
|
|||
if (!is_callable($this->php_callback)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return call_user_func($this->php_callback, $core, $this);
|
||||
}
|
||||
|
||||
|
@ -137,29 +140,36 @@ class noodle
|
|||
{
|
||||
switch ($type) {
|
||||
case 'active':
|
||||
$this->settings['active'] = abs((integer) $value);
|
||||
$this->settings['active'] = abs((int) $value);
|
||||
|
||||
break;
|
||||
|
||||
case 'rating':
|
||||
$this->settings['rating'] = in_array($value, ['g', 'pg', 'r', 'x']) ? $value : 'g';
|
||||
|
||||
break;
|
||||
|
||||
case 'size':
|
||||
$this->settings['size'] = in_array($value, [16, 24, 32, 48, 56, 64, 92, 128, 256]) ? $value : 16;
|
||||
|
||||
break;
|
||||
|
||||
case 'css':
|
||||
$this->settings['css'] = (string) $value;
|
||||
|
||||
break;
|
||||
|
||||
case 'target':
|
||||
$this->settings['target'] = (string) $value;
|
||||
|
||||
break;
|
||||
|
||||
case 'place':
|
||||
$this->settings['place'] = in_array($value, ['append', 'prepend', 'before', 'after']) ? $value : 'prepend';
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
@ -200,7 +210,7 @@ class noodle
|
|||
|
||||
public function get($type)
|
||||
{
|
||||
return isset($this->settings[$type]) ? $this->settings[$type] : null;
|
||||
return $this->settings[$type] ?? null;
|
||||
}
|
||||
|
||||
public function __get($type)
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_RC_PATH')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -51,9 +50,11 @@ class noodlesLibImagePath
|
|||
{
|
||||
$files = self::getArray($core, $m);
|
||||
foreach ($files as $k => $file) {
|
||||
if (file_exists($files[$k]['dir']))
|
||||
if (file_exists($files[$k]['dir'])) {
|
||||
return $files[$k]['url'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -61,19 +62,21 @@ class noodlesLibImagePath
|
|||
{
|
||||
$files = self::getArray($core, $m);
|
||||
foreach ($files as $k => $file) {
|
||||
if (file_exists($files[$k]['dir']))
|
||||
if (file_exists($files[$k]['dir'])) {
|
||||
return $files[$k]['dir'];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function getSize($core, $m = '')
|
||||
{
|
||||
if (!($img = self::getPath($core, $m)))
|
||||
if (!($img = self::getPath($core, $m))) {
|
||||
return ['w' => 16, 'h' => 16];
|
||||
else {
|
||||
}
|
||||
$info = getimagesize($img);
|
||||
|
||||
return ['w' => $info[0], 'h' => floor($info[1] / 3)];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,7 +10,6 @@
|
|||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
|
||||
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||
return null;
|
||||
}
|
||||
|
@ -26,7 +25,7 @@ if ($__noodles->isEmpty()) {
|
|||
$__noodles = $__default_noodles;
|
||||
} else {
|
||||
$default_noodles_array = $__default_noodles->noodles();
|
||||
foreach($default_noodles_array AS $id => $noodle) {
|
||||
foreach ($default_noodles_array as $id => $noodle) {
|
||||
if ($__noodles->exists($id)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -165,7 +164,7 @@ if (!empty($public_path)) {
|
|||
echo '<div class="one-box">';
|
||||
sort($default_images);
|
||||
$i = 0;
|
||||
foreach($default_images AS $f) {
|
||||
foreach ($default_images as $f) {
|
||||
if (!preg_match('/gravatar-[0-9]+.png/', $f)) {
|
||||
continue;
|
||||
}
|
||||
|
@ -247,7 +246,8 @@ foreach($__noodles->noodles() as $noodle) {
|
|||
<td class="nowrap" scope="row"><label for="ck_' . $noodle->id() . '">' . $noodle->name() . '</label></td>
|
||||
<td>' . form::combo(['noodle[' . $noodle->id() . '][size]'], $combo_size, $noodle->size) . '</td>
|
||||
<td>' . form::combo(['noodle[' . $noodle->id() . '][rating]'], $combo_rating, $noodle->rating) . '</td>
|
||||
<td>' . ($noodle->hasPhpCallback() ?
|
||||
<td>' . (
|
||||
$noodle->hasPhpCallback() ?
|
||||
'<img alt="ok" src="images/check-on.png" />' :
|
||||
'<img alt="nok" src="images/check-off.png" />'
|
||||
) . '</td>
|
||||
|
|
Loading…
Reference in a new issue