Skip to content

Commit

Permalink
Merge pull request #90 from mambax7/master
Browse files Browse the repository at this point in the history
updates/cosmetics
  • Loading branch information
ggoffy authored Oct 30, 2021
2 parents 796a84c + 6291726 commit 1960987
Show file tree
Hide file tree
Showing 59 changed files with 1,082 additions and 470 deletions.
3 changes: 0 additions & 3 deletions class/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
*/

use Xmf\Module\Helper\Permission;
use XoopsModules\Tdmdownloads\{
Helper
};

/** @var Helper $helper */

Expand Down
26 changes: 17 additions & 9 deletions class/Common/Breadcrumb.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@
* @copyright XOOPS Project (https://xoops.org)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author lucio <lucio.rota@gmail.com>
* @package pedigree
* @since 3.23
* @version $Id: breadcrumb.php 12865 2014-11-22 07:03:35Z beckmi $
*
* Example:
* $breadcrumb = new \Breadcrumb();
Expand All @@ -36,6 +33,9 @@
*/
class Breadcrumb
{
/**
* @var string
*/
public $dirname;
private $bread = [];

Expand All @@ -47,10 +47,8 @@ public function __construct()
/**
* Add link to breadcrumb
*
* @param string $title
* @param string $link
*/
public function addLink($title = '', $link = '')
public function addLink(string $title = '', string $link = ''): void
{
$this->bread[] = [
'link' => $link,
Expand All @@ -61,17 +59,27 @@ public function addLink($title = '', $link = '')
/**
* Render BreadCrumb
*/
public function render()
public function render(): void
{
/*
TODO if you want to use the render code below,
1) create ./templates/chess_common_breadcrumb.tpl)
2) add declaration to xoops_version.php
*/
/*
if (!isset($GLOBALS['xoTheme']) || !\is_object($GLOBALS['xoTheme'])) {
require_once $GLOBALS['xoops']->path('class/theme.php');
require $GLOBALS['xoops']->path('class/theme.php');
$GLOBALS['xoTheme'] = new \xos_opal_Theme();
}
require_once $GLOBALS['xoops']->path('class/template.php');
require $GLOBALS['xoops']->path('class/template.php');
$breadcrumbTpl = new \XoopsTpl();
$breadcrumbTpl->assign('breadcrumb', $this->bread);
$html = $breadcrumbTpl->fetch('db:' . $this->dirname . '_common_breadcrumb.tpl');
unset($breadcrumbTpl);
return $html;
*/
}
}
4 changes: 1 addition & 3 deletions class/Common/Configurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
* @copyright XOOPS Project (https://xoops.org)
* @license http://www.fsf.org/copyleft/gpl.html GNU public license
* @author XOOPS Development Team
* @package Publisher
* @since 1.05
*/

/**
Expand Down Expand Up @@ -49,7 +47,7 @@ public function __construct()
{
$config = require \dirname(__DIR__, 2) . '/config/config.php';
$this->name = $config->name;
$this->paths = $config->paths;
// $this->paths = $config->paths;
$this->uploadFolders = $config->uploadFolders;
$this->copyBlankFiles = $config->copyBlankFiles;
$this->copyTestFolders = $config->copyTestFolders;
Expand Down
36 changes: 11 additions & 25 deletions class/Common/FilesManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,8 @@ trait FilesManagement
* Function responsible for checking if a directory exists, we can also write in and create an index.html file
*
* @param string $folder The full path of the directory to check
*
* @throws \RuntimeException
*/
public static function createFolder($folder)
public static function createFolder(string $folder): void
{
try {
if (!\is_dir($folder)) {
Expand All @@ -37,30 +35,21 @@ public static function createFolder($folder)
}
file_put_contents($folder . '/index.html', '<script>history.go(-1);</script>');
}
} catch (\Throwable $e) {
} catch (\Exception $e) {
echo 'Caught exception: ', $e->getMessage(), "\n", '<br>';
}
}

/**
* @param $file
* @param $folder
* @return bool
*/
public static function copyFile($file, $folder)
public static function copyFile(string $file, string $folder): bool
{
return \copy($file, $folder);
}

/**
* @param $src
* @param $dst
* @throws \RuntimeException
*/
public static function recurseCopy($src, $dst)
public static function recurseCopy(string $src, string $dst): void
{
$dir = \opendir($src);
if (!\mkdir($dst) && !\is_dir($dst)) {
// @mkdir($dst);
if (!@\mkdir($dst) && !\is_dir($dst)) {
throw new \RuntimeException('The directory ' . $dst . ' could not be created.');
}
while (false !== ($file = \readdir($dir))) {
Expand All @@ -85,7 +74,7 @@ public static function recurseCopy($src, $dst)
*
* @uses \Xmf\Module\Helper::getHelper()
*/
public static function deleteDirectory($src)
public static function deleteDirectory(string $src): bool
{
// Only continue if user is a 'global' Admin
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
Expand All @@ -104,13 +93,10 @@ public static function deleteDirectory($src)
if (!$success = self::deleteDirectory($fileInfo->getRealPath())) {
break;
}
} else {
// delete the file
if (!($success = \unlink($fileInfo->getRealPath()))) {
} elseif (!($success = \unlink($fileInfo->getRealPath()))) {
break;
}
}
}
// now delete this (sub)directory if all the files are gone
if ($success) {
$success = \rmdir($dirInfo->getRealPath());
Expand All @@ -131,7 +117,7 @@ public static function deleteDirectory($src)
*
* @return bool true on success
*/
public static function rrmdir($src)
public static function rrmdir(string $src): bool
{
// Only continue if user is a 'global' Admin
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
Expand Down Expand Up @@ -168,7 +154,7 @@ public static function rrmdir($src)
*
* @return bool true on success
*/
public static function rmove($src, $dest)
public static function rmove(string $src, string $dest): bool
{
// Only continue if user is a 'global' Admin
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
Expand Down Expand Up @@ -208,7 +194,7 @@ public static function rmove($src, $dest)
*
* @uses \Xmf\Module\Helper::getHelper()
*/
public static function rcopy($src, $dest)
public static function rcopy(string $src, string $dest): bool
{
// Only continue if user is a 'global' Admin
if (!($GLOBALS['xoopsUser'] instanceof \XoopsUser) || !$GLOBALS['xoopsUser']->isAdmin()) {
Expand Down
1 change: 1 addition & 0 deletions class/Common/FineimpuploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ private function handleImageDB()
global $xoopsUser;
$this->getImageDim();
$helper = Helper::getInstance();
/** @var \XoopsModules\Tdmdownloads\Common\ImagesHandler $imagesHandler */
$imagesHandler = $helper->getHandler('Images');
// $imagesHandler = new \XoopsModules\Tdmdownloads\Common\ImagesHandler();
$imagesObj = $imagesHandler->create();
Expand Down
1 change: 1 addition & 0 deletions class/Common/Images.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public function getFormImages($action = false)
$imgWeight = $this->isNew() ? '0' : $this->getVar('img_weight');
$form->addElement(new \XoopsFormText(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_WEIGHT'), 'img_weight', 20, 150, $imgWeight));
// Form Table albums
/** @var \XoopsModules\Tdmdownloads\Common\ImagesHandler $albumsHandler */
$albumsHandler = $helper->getHandler('Albums');
$imgAlbidSelect = new \XoopsFormSelect(\constant('CO_' . $moduleDirNameUpper . '_' . 'IMAGE_ALBID'), 'img_albid', $this->getVar('img_albid'));
$imgAlbidSelect->addOptionArray($albumsHandler->getList());
Expand Down
79 changes: 72 additions & 7 deletions class/Common/Migrate.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
*/
class Migrate extends \Xmf\Database\Migrate
{
private $renameTables;
private $moduleDirName;
private $renameColumns;
private $renameTables;

/**
* Migrate constructor.
Expand All @@ -41,14 +42,70 @@ public function __construct()
}
$configurator = new $class();
$this->renameTables = $configurator->renameTables;
$moduleDirName = \basename(\dirname(__DIR__, 2));
parent::__construct($moduleDirName);
$this->renameColumns = $configurator->renameColumns;

$this->moduleDirName = \basename(\dirname(__DIR__, 2));
parent::__construct($this->moduleDirName);
}

/**
* change table prefix if needed
*/
private function changePrefix(): void
{
// foreach ($this->renameTables as $oldName => $newName) {
// if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
// $this->tableHandler->renameTable($oldName, $newName);
// }
// }
}

/**
* Change integer IPv4 column to varchar IPv6 capable
*
* @param string $tableName table to convert
* @param string $columnName column with IP address
*/
private function convertIPAddresses(string $tableName, string $columnName): void
{
// if ($this->tableHandler->useTable($tableName)) {
// $attributes = $this->tableHandler->getColumnAttributes($tableName, $columnName);
// if (false !== \mb_strpos($attributes, ' int(')) {
// if (false === \mb_strpos($attributes, 'unsigned')) {
// $this->tableHandler->alterColumn($tableName, $columnName, " bigint(16) NOT NULL DEFAULT '0' ");
// $this->tableHandler->update($tableName, [$columnName => "4294967296 + $columnName"], "WHERE $columnName < 0", false);
// }
// $this->tableHandler->alterColumn($tableName, $columnName, " varchar(45) NOT NULL DEFAULT '' ");
// $this->tableHandler->update($tableName, [$columnName => "INET_NTOA($columnName)"], '', false);
// }
// }
}

/**
* @deprecated (just as an example here)
* Move do* columns from newbb_posts to newbb_posts_text table
*/
private function moveDoColumns(): void
{
// $tableName = 'newbb_posts_text';
// $srcTableName = 'newbb_posts';
// if ($this->tableHandler->useTable($tableName)
// && $this->tableHandler->useTable($srcTableName)) {
// $attributes = $this->tableHandler->getColumnAttributes($tableName, 'dohtml');
// if (false === $attributes) {
// $this->synchronizeTable($tableName);
// $updateTable = $GLOBALS['xoopsDB']->prefix($tableName);
// $joinTable = $GLOBALS['xoopsDB']->prefix($srcTableName);
// $sql = "UPDATE `$updateTable` t1 INNER JOIN `$joinTable` t2 ON t1.post_id = t2.post_id \n" . "SET t1.dohtml = t2.dohtml, t1.dosmiley = t2.dosmiley, t1.doxcode = t2.doxcode\n" . ' , t1.doimage = t2.doimage, t1.dobr = t2.dobr';
// $this->tableHandler->addToQueue($sql);
// }
// }
}

/**
* rename table if needed
*/
private function renameTable()
private function renameTable(): void
{
foreach ($this->renameTables as $oldName => $newName) {
if ($this->tableHandler->useTable($oldName) && !$this->tableHandler->useTable($newName)) {
Expand All @@ -60,14 +117,14 @@ private function renameTable()
/**
* rename columns if needed
*/
private function renameColumns()
private function renameColumns(): void
{
foreach ($this->renameColumns as $tableName) {
if ($this->tableHandler->useTable($tableName)) {
$oldName = $tableName['from'];
$newName = $tableName['to'];
$attributes = $this->tableHandler->getColumnAttributes($tableName, $oldName);
if (false !== \strpos($attributes, ' int(')) {
if (\is_string($attributes) && false !== \strpos($attributes, ' int(')) {
$this->tableHandler->alterColumn($tableName, $oldName, $attributes, $newName);
}
}
Expand All @@ -81,8 +138,16 @@ private function renameColumns()
* table and column renames
* data conversions
*/
protected function preSyncActions()
protected function preSyncActions(): void
{
// change 'bb' table prefix to 'newbb'
$this->changePrefix();
// columns dohtml, dosmiley, doxcode, doimage and dobr moved between tables as some point
$this->moveDoColumns();
// Convert IP address columns from int to readable varchar(45) for IPv6
// $this->convertIPAddresses('newbb_posts', 'poster_ip');
// $this->convertIPAddresses('newbb_report', 'reporter_ip');

// rename table
if ($this->renameTables && \is_array($this->renameTables)) {
$this->renameTable();
Expand Down
9 changes: 3 additions & 6 deletions class/Common/ServerStats.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ trait ServerStats
{
/**
* serverStats()
*
* @return string
*/
public static function getServerStats()
public static function getServerStats(): string
{
//mb $wfdownloads = WfdownloadsWfdownloads::getInstance();
$moduleDirName = \basename(\dirname(__DIR__, 2));
Expand All @@ -47,13 +45,12 @@ public static function getServerStats()
$html .= "<ul>\n";
$gdlib = \function_exists('gd_info') ? '<span style="color: #008000;">' . \constant('CO_' . $moduleDirNameUpper . '_GDON') . '</span>' : '<span style="color: #ff0000;">' . \constant('CO_' . $moduleDirNameUpper . '_GDOFF') . '</span>';
$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBSTATUS') . $gdlib;
if (\function_exists('gd_info')) {
if (true === $gdlib = gd_info()) {
if (\function_exists('gd_info') && true === ($gdlib = gd_info())) {
$html .= '<li>' . \constant('CO_' . $moduleDirNameUpper . '_GDLIBVERSION') . '<b>' . $gdlib['GD Version'] . '</b>';
}
}
// $safemode = ini_get('safe_mode') ? constant('CO_' . $moduleDirNameUpper . '_ON') . constant('CO_' . $moduleDirNameUpper . '_SAFEMODEPROBLEMS : constant('CO_' . $moduleDirNameUpper . '_OFF');
// $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_SAFEMODESTATUS . $safemode;
//
// $registerglobals = (!ini_get('register_globals')) ? "<span style=\"color: green;\">" . constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>' : "<span style=\"color: red;\">" . constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>';
// $html .= '<li>' . constant('CO_' . $moduleDirNameUpper . '_REGISTERGLOBALS . $registerglobals;
$downloads = \ini_get('file_uploads') ? '<span style="color: #008000;">' . \constant('CO_' . $moduleDirNameUpper . '_ON') . '</span>' : '<span style="color: #ff0000;">' . \constant('CO_' . $moduleDirNameUpper . '_OFF') . '</span>';
Expand Down
Loading

0 comments on commit 1960987

Please sign in to comment.