Skip to content

Commit

Permalink
Merge pull request #4 from mambax7/master
Browse files Browse the repository at this point in the history
updates/cleanup
  • Loading branch information
ggoffy committed Jun 23, 2021
2 parents c5b9c9e + 39df2cd commit 4f0041d
Show file tree
Hide file tree
Showing 26 changed files with 801 additions and 537 deletions.
16 changes: 8 additions & 8 deletions class/smarty/xoops_plugins/block.xoBlkTpl.php
Expand Up @@ -9,12 +9,12 @@
* how to use
* The following code inserted in the template
*
* @param module string module dirname
* @param file string block function file
* @param show_func string show block function
* @param options= string show block function's option
* @param cachetime int cachetime Unit for seconds
* @param user mix Generate cache solution
* @param string $module module dirname
* @param string $file block function file
* @param string $show_func show block function
* @param string $options show block function's option
* @param int $cachetime cachetime Unit for seconds
* @param mixed $user Generate cache solution
<{xoBlkTpl module="ilog" file="ilog_block_tag.php" show_func="ilog_tag_block_cloud_show" options="100|0|100|80" cachetime=5 userid=$xoops_userid}>
<link rel="stylesheet" href="<{$xoops_url}>/modules/tag/templates/style.css" />
Expand All @@ -34,12 +34,12 @@ function smarty_block_xoBlkTpl ($params, $content, $smarty, &$repeat) {
xoops_load('xoopscache');
$cache_key = 'xoBlkTpl_'.md5(var_export($params, true));
if (!isset($params['cachetime']) || (!$var = XoopsCache::read($cache_key))) {
$myBlock = array(
$myBlock = [
'dirname' => $params['module'],
'func_file' => $params['file'],
'show_func' => $params['show_func'],
'options' => $params['options'],
);
];
$xoBlk = new XoopsBlock($myBlock);
$var = $xoBlk->buildBlock();
}
Expand Down
19 changes: 9 additions & 10 deletions class/smarty/xoops_plugins/function.xoBlk.php
Expand Up @@ -9,13 +9,12 @@
* how to use
* The following code inserted in the template
*
* @param module string module dirname
* @param file string block function file
* @param show_func string show block function
* @param options= string show block function's option
* @param template string show block function's template
* @param cachetime int cachetime Unit for seconds
* @param user mix Generate cache solution
* @param string $module module dirname
* @param string $file block function file
* @param string $show_func show block function
* @param string $options show block function's option
* @param int $cachetime cachetime Unit for seconds
* @param mixed $user Generate cache solution
<{xoBlk
module="ilog"
Expand All @@ -39,14 +38,14 @@ function smarty_function_xoBlk( $params, $smarty )
$smarty->caching = 0;
}
$tplName = 'db:' . $params['template'];
$params['cacheid'] = isset($params['cacheid']) ? $params['cacheid'] : 'xoBlk_'.md5(var_export($params, true));
$params['cacheid'] = $params['cacheid'] ?? ('xoBlk_' . md5(var_export($params, true)));
if (!isset($params['cachetime']) || !$smarty->is_cached($tplName, $params['cacheid'])) {
$myBlock = array(
$myBlock = [
'dirname' => $params['module'],
'func_file' => $params['file'],
'show_func' => $params['show_func'],
'options' => $params['options'],
);
];
$xoBlk = new XoopsBlock($myBlock);
$var = $xoBlk->buildBlock();
$old_block = $smarty->get_template_vars('block');
Expand Down
17 changes: 17 additions & 0 deletions modules/tools/.gitattributes
@@ -0,0 +1,17 @@
# Auto detect text files and perform LF normalization
* text=auto

# Custom for Visual Studio
*.cs diff=csharp

# Standard to msysgit
*.doc diff=astextplain
*.DOC diff=astextplain
*.docx diff=astextplain
*.DOCX diff=astextplain
*.dot diff=astextplain
*.DOT diff=astextplain
*.pdf diff=astextplain
*.PDF diff=astextplain
*.rtf diff=astextplain
*.RTF diff=astextplain
5 changes: 5 additions & 0 deletions modules/tools/.gitignore
@@ -0,0 +1,5 @@
# no backup files, editor temp
*~
\#*
*.bak
.idea/
24 changes: 24 additions & 0 deletions modules/tools/.scrutinizer.yml
@@ -0,0 +1,24 @@
# language: php
build:
nodes:
tests: true
analysis:
dependencies:
after:
# The following installs the most recent XOOPS CMS version, you might want
# to install a specific release tag or branch instead.
- git clone --depth=1 https://github.com/XOOPS/XoopsCore25
- git clone --depth=1 https://github.com/mambax7/tag
project_setup:
override: true
tests:
override:
- php-scrutinizer-run --enable-security-analysis
environment:
php:
version: "7.2"
filter:
dependency_paths:
- XoopsCore25/*
- tag/*

1 change: 0 additions & 1 deletion modules/tools/admin/admin_header.php
Expand Up @@ -28,7 +28,6 @@

$moduleDirName = \basename(\dirname(__DIR__));

/** @var Helper $helper */
$helper = Helper::getInstance();

/** @var Admin $adminObject */
Expand Down
218 changes: 111 additions & 107 deletions modules/tools/admin/main.php
@@ -1,107 +1,111 @@
<?php

/**
* tools Module for XOOPS
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright XOOPS Project (https://xoops.org)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package tools
* @since 2.00
* @author Susheng Yang <ezskyyoung@gmail.com>
*/

use Xmf\Module\Admin;

require_once __DIR__ . '/admin_header.php';
xoops_cp_header();

//loadModuleAdminMenu(1, '');

/** @var Admin $adminObject */
$adminObject->displayNavigation(basename(__FILE__));

$op = $_REQUEST['op'] ?? 'main';
switch ($op) {
default:
case 'main':
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
$form = new \XoopsThemeForm(_AM_TOOLS_INDEX, 'updatecache', 'main.php', 'post', true);
$form->addElement(new \XoopsFormLabel(_AM_TOOLS_TIP, _AM_TOOLS_TIPS));
$checkbox_options = [
'updatexoopscache' => _AM_TOOLS_UPDATEXOOPSCACHE,
'updatesmartycache' => _AM_TOOLS_UPDATESMARTYCACHE,
'updatesmartycompile' => _AM_TOOLS_UPDATESMARTYCOMPILE,
];
$checkbox = new \XoopsFormCheckBox(_AM_TOOLS_OPTIONS, 'options', array_keys($checkbox_options));
$checkbox->addOptionArray($checkbox_options);
$form->addElement($checkbox);
$form->addElement(new \XoopsFormHidden('op', 'updatecache'));
$form->addElement(new \XoopsFormHidden('step', '1'));
$form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
$form->display();
break;
case 'updatecache':
if (1 == $_REQUEST['step']) {
$options = implode('_', $_REQUEST['options']);
$url = XOOPS_URL . "/modules/tools/admin/main.php?op=updatecache&step=2&options={$options}";
$updating = _AM_TOOLS_UPDATING;
$msg = <<<EOF
<div class="loading" style="text-align:center">
<img src="../assets/images/loader.gif">
<p>{$updating}</P>
</div>
<script type="text/javascript" language="javascript">
function redirect(url)
{
location.replace(url);
}
</script>
<script type="text/JavaScript">setTimeout("redirect('{$url}');", 2000);</script>
EOF;

echo $msg;
} elseif (2 == $_REQUEST['step']) {
$options = explode('_', $_REQUEST['options']);
foreach ($options as $k) {
if ('updatexoopscache' === $k) {
$d = XOOPS_VAR_PATH . '/caches/xoops_cache';
updatecache($d, 'php');
updatecache($d, 'html');
updatecache($d, 'tmp');
}
if ('updatesmartycache' === $k) {
$d = XOOPS_VAR_PATH . '/caches/smarty_cache';
updatecache($d, 'html');
updatecache($d, 'tmp');
}
if ('updatesmartycompile' === $k) {
$d = XOOPS_VAR_PATH . '/caches/smarty_compile';
updatecache($d, 'php');
}
}

redirect_header('main.php', 3, _AM_TOOLS_UPDATECACHESUCCESS);
}

break;
}

function updatecache($cacheDir, $type)
{
$d = dir($cacheDir);
while (false !== ($entry = $d->read())) {
if (preg_match("/.*\.{$type}$/", $entry)) {
unlink($cacheDir . '/' . $entry);
}
}
$d->close();
}

require_once __DIR__ . '/admin_footer.php';
<?php

/**
* tools Module for XOOPS
*
* You may not change or alter any portion of this comment or credits
* of supporting developers from this source code or any supporting source code
* which is considered copyrighted (c) material of the original comment or credit authors.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* @copyright XOOPS Project (https://xoops.org)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @package tools
* @since 2.00
* @author Susheng Yang <ezskyyoung@gmail.com>
*/

use Xmf\Module\Admin;

require_once __DIR__ . '/admin_header.php';
xoops_cp_header();

//loadModuleAdminMenu(1, '');

/** @var Admin $adminObject */
$adminObject->displayNavigation(basename(__FILE__));

$op = $_REQUEST['op'] ?? 'main';
switch ($op) {
default:
case 'main':
require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php';
$form = new \XoopsThemeForm(_AM_TOOLS_INDEX, 'updatecache', 'main.php', 'post', true);
$form->addElement(new \XoopsFormLabel(_AM_TOOLS_TIP, _AM_TOOLS_TIPS));
$checkbox_options = [
'updatexoopscache' => _AM_TOOLS_UPDATEXOOPSCACHE,
'updatesmartycache' => _AM_TOOLS_UPDATESMARTYCACHE,
'updatesmartycompile' => _AM_TOOLS_UPDATESMARTYCOMPILE,
];
$checkbox = new \XoopsFormCheckBox(_AM_TOOLS_OPTIONS, 'options', array_keys($checkbox_options));
$checkbox->addOptionArray($checkbox_options);
$form->addElement($checkbox);
$form->addElement(new \XoopsFormHidden('op', 'updatecache'));
$form->addElement(new \XoopsFormHidden('step', '1'));
$form->addElement(new \XoopsFormButton('', 'submit', _SUBMIT, 'submit'));
$form->display();
break;
case 'updatecache':
if (1 == $_REQUEST['step']) {
$options = implode('_', $_REQUEST['options']);
$url = XOOPS_URL . "/modules/tools/admin/main.php?op=updatecache&step=2&options={$options}";
$updating = _AM_TOOLS_UPDATING;
$msg = <<<EOF
<div class="loading" style="text-align:center">
<img src="../assets/images/loader.gif">
<p>{$updating}</P>
</div>
<script type="text/javascript" language="javascript">
function redirect(url)
{
location.replace(url);
}
</script>
<script type="text/JavaScript">setTimeout("redirect('{$url}');", 2000);</script>
EOF;

echo $msg;
} elseif (2 == $_REQUEST['step']) {
$options = explode('_', $_REQUEST['options']);
foreach ($options as $k) {
if ('updatexoopscache' === $k) {
$d = XOOPS_VAR_PATH . '/caches/xoops_cache';
updatecache($d, 'php');
updatecache($d, 'html');
updatecache($d, 'tmp');
}
if ('updatesmartycache' === $k) {
$d = XOOPS_VAR_PATH . '/caches/smarty_cache';
updatecache($d, 'html');
updatecache($d, 'tmp');
}
if ('updatesmartycompile' === $k) {
$d = XOOPS_VAR_PATH . '/caches/smarty_compile';
updatecache($d, 'php');
}
}

redirect_header('main.php', 3, _AM_TOOLS_UPDATECACHESUCCESS);
}

break;
}

/**
* @param $cacheDir
* @param $type
*/
function updatecache($cacheDir, $type)
{
$d = dir($cacheDir);
while (false !== ($entry = $d->read())) {
if (preg_match("/.*\.{$type}$/", $entry)) {
unlink($cacheDir . '/' . $entry);
}
}
$d->close();
}

require_once __DIR__ . '/admin_footer.php';
2 changes: 1 addition & 1 deletion modules/tools/admin/menu.php
Expand Up @@ -24,7 +24,7 @@
/** @var Tools\Helper $helper */

$moduleDirName = basename(dirname(__DIR__));
$moduleDirNameUpper = mb_strtoupper($moduleDirName);
$moduleDirNameUpper = \mb_strtoupper($moduleDirName);

$helper = Tools\Helper::getInstance();
$helper->loadLanguage('common');
Expand Down

0 comments on commit 4f0041d

Please sign in to comment.