Skip to content

Commit

Permalink
Merge pull request #94 from ggoffy/master
Browse files Browse the repository at this point in the history
added support of tag module
  • Loading branch information
ggoffy authored Sep 27, 2022
2 parents 83456e3 + 3b1dc67 commit 38bd240
Show file tree
Hide file tree
Showing 10 changed files with 478 additions and 11 deletions.
8 changes: 6 additions & 2 deletions admin/images.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,17 +151,21 @@
$imagesObj->setVar('img_ratinglikes', Request::getInt('img_ratinglikes'));
$imagesObj->setVar('img_votes', Request::getInt('img_votes'));
$imagesObj->setVar('img_weight', Request::getInt('img_weight'));
$imagesObj->setVar('img_albid', Request::getInt('img_albid'));
$imgAlbid = Request::getInt('img_albid');
$imagesObj->setVar('img_albid', $imgAlbid);
$imagesObj->setVar('img_state', Request::getInt('img_state'));
$imagesObj->setVar('img_exif', Request::getString('img_exif'));
$imagesObj->setVar('img_cats', serialize(Request::getArray('img_cats')));
$imagesObj->setVar('img_tags', Request::getString('img_tags'));
$imgTags = Request::getString('img_tags');
$imagesObj->setVar('img_tags', $imgTags);
$imageDate = date_create_from_format(_SHORTDATESTRING, $_POST['img_date']);
$imagesObj->setVar('img_date', $imageDate->getTimestamp());
$imagesObj->setVar('img_submitter', Request::getInt('img_submitter'));
$imagesObj->setVar('img_ip', $_SERVER['REMOTE_ADDR']);
// Insert Data
if ($imagesHandler->insert($imagesObj)) {
$newImgId = $imgId > 0 ? $imgId : $imagesObj->getNewInsertedIdImages();
$imagesHandler->handleTagsForTagmodule($imgTags, $newImgId, $imgAlbid);
\redirect_header('images.php?op=list&start=' . $start . '&limit=' . $limit . '&alb_id=' . $albId, 2, \_CO_WGGALLERY_FORM_OK);
}
// Get Form
Expand Down
22 changes: 22 additions & 0 deletions class/ImagesHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ private function handleImageDB()
// Insert Data
if ($this->insert($imagesObj)) {
$this->imageId = $this->getInsertId();
$this->handleTagsForTagmodule($this->imageTags, $this->imageId, $this->albumId);

return true;
}
Expand Down Expand Up @@ -604,4 +605,25 @@ public function getFormBatchUpload($files, $action = false)
$form->addElement(new \XoopsFormButtonTray('', \_SUBMIT, 'submit', '', false));
return $form;
}

/**
* @public function to handle tags for tag module
* @param string $tags
* @param int $id
* @param int $catid
* @return bool
*/
public function handleTagsForTagmodule($tags, $id, $catid = 0)
{
$helper = \XoopsModules\Wggallery\Helper::getInstance();
$moduleDirName = basename(dirname(__DIR__));
//check whether tag module is installed and wggallery config is set usetagmodule = 1
if (1 == $helper->getConfig('usetagmodule') && in_array($moduleDirName, xoops_getActiveModules())) {
//wggallery use # as tag separator, tag module doesn't use #
$cleanTags = \str_replace('#', ' ', $tags);
$tagHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Tag'); // xoops_getModuleHandler('tag', 'tag');
$tagHandler->updateByItem($cleanTags, $id, $moduleDirName, $catid);
}
return true;
}
}
4 changes: 4 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<h5>1.2.0 RC2</h5> [2022/09/27]
<hr>
- added support of tag module (alain01/goffy)

<h5>1.2.0 RC1</h5> [2021/04/19]
<hr>
- semantic versioning (mamba/goffy)
Expand Down
8 changes: 7 additions & 1 deletion images.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@
$imagesObj->setVar('img_views', Request::getInt('img_views'));
$imagesObj->setVar('img_weight', Request::getInt('img_weight'));
$imagesObj->setVar('img_cats', serialize(Request::getArray('img_cats')));
$imagesObj->setVar('img_tags', Request::getString('img_tags'));
$imgTags = Request::getString('img_tags');
$imagesObj->setVar('img_tags', $imgTags);
$albumsObj = $albumsHandler->get($albId);
$imgAlbPid = $albumsObj->getVar('alb_pid');
$imagesObj->setVar('img_albid', $imgAlbId);
Expand All @@ -257,6 +258,11 @@
$notificationHandler->triggerEvent('albums', $albId, 'image_new', $tags);
}
}

//handle tags for module TAG
$newImgId = $imgId > 0 ? $imgId : $imagesObj->getNewInsertedIdImages();
$imagesHandler->handleTagsForTagmodule($imgTags, $newImgId, $imgAlbId);

if ('manage' === $redir_op) {
\redirect_header('images.php?op=manage&amp;alb_id=' . $imgAlbId . '&amp;alb_pid=' . $imgAlbPid . '#image_' . $imgId, 2, \_CO_WGGALLERY_FORM_OK);
} else {
Expand Down
117 changes: 117 additions & 0 deletions include/plugin.tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

declare(strict_types=1);
/*
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.
*/

/**
* wgGallery module for xoops
*
* @package wggallery
* @author Wedega - Email:<[email protected]> - Website:<https://wedega.com>
* @copyright module for xoops
* @license GPL 2.0 or later
*/

use Xmf\Request;
use XoopsModules\Wggallery\{
Common,
Helper,
Images,
ImagesHandler,
Utility
};
use XoopsModules\Tag;

/** Get item fields: title, content, time, link, uid, tags
*
* @param array $items pass-by-ref
* @return bool true - items found | false - nothing found/created
*/
function wggallery_tag_iteminfo(&$items)
{
if (empty($items) || !is_array($items)) {
return false;
}

$itemsIds = [];
foreach (array_keys($items) as $cat_id) {
// Some handling here to build the link upon cat_id
// if cat_id is not used, just skip it
foreach (array_keys($items[$cat_id]) as $itemId) {
// In article, the item_id is "art_id"
$itemsIds[] = (int)$itemId;
}
}
$itemsIds = array_unique($itemsIds); // remove duplicate ids

$helper = Helper::getInstance();
$imagesHandler = $helper->getHandler('Images');
$criteria = new \Criteria('img_id', '(' . implode(', ', $itemsIds) . ')', 'IN');
$imagesObj = $imagesHandler->getObjects($criteria, 'img_id');

//make sure Tag module tag_parse_tag() can be found
if (method_exists(XoopsModules\Tag\Utility::class, 'tag_parse_tag')) {
// this will be used for Tag >= v2.35
$parse_function = 'XoopsModules\Tag\Utility::tag_parse_tag';
} else {
// allows this plugin to work with Tag <= v2.34
require_once $GLOBALS['xoops']->path('modules/tag/include/functions.php');
$parse_function = 'tag_parse_tag';
}

foreach (array_keys($items) as $cat_id) {
foreach (array_keys($items[$cat_id]) as $itemId) {
$imgObj = $imagesObj[$itemId];
$items[$cat_id][$itemId] = [
'title' => $imgObj->getVar('img_title'),
'uid' => $imgObj->getVar('img_submitter'),
'link' => 'images.php?op=show&redir=list&amp;img_id=' . $itemId . '&amp;alb_id=' . $imgObj->getVar('img_albid'),
'time' => $imgObj->getVar('img_date'),
'tags' => $parse_function($imgObj->getVar('img_tags', 'n')), // optional
'content' => '',
];
}
}
unset($items_obj);

return true;
}

/** Remove orphan tag-item links *
* @param int $mid
* @return bool
*/
function wggallery_tag_synchronization($mid)
{
// Optional
$itemHandler = Helper::getInstance()->getHandler('Images');

/** @var \XoopsModules\Tag\LinkHandler $linkHandler */
$linkHandler = \XoopsModules\Tag\Helper::getInstance()->getHandler('Link');

//$mid = Request::getInt('mid');

/* clear tag-item links */
$sql = " DELETE FROM {$linkHandler->table}"
. ' WHERE '
. " tag_modid = {$mid}"
. ' AND '
. ' ( tag_itemid NOT IN '
. " ( SELECT DISTINCT {$itemHandler->keyName} "
. " FROM {$itemHandler->table} "
. " WHERE {$itemHandler->table}.img_state > 0 "
. ' ) '
. ' )';

$result = $linkHandler->db->queryF($sql);

return (bool)$result;
}
2 changes: 2 additions & 0 deletions language/english/modinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
\define('_MI_WGGALLERY_STORE_ORIGINAL_DESC', 'Define, whether you want to store the original image.
<br>Advantage: all images can be reproduced later including new water marks
<br>Disadvantage: the used server space will increase corresponding the allowed upload file size');
define('_MI_WGGALLERY_TAGMODULE', 'Use TAG module to generate tags');
define('_MI_WGGALLERY_TAGMODULE_DESC', "Define whether your image tags should be shown also in TAG module<br>- The module 'TAG' musst be installed<br>- The option 'Use Tags' musst be activated");
// Notifications
\define('_MI_WGGALLERY_GLOBAL_NOTIFY', 'Global notification');
\define('_MI_WGGALLERY_GLOBAL_ALB_NEW_ALL_NOTIFY', 'Send notification when a new album was created');
Expand Down
2 changes: 2 additions & 0 deletions language/german/modinfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@
\define('_MI_WGGALLERY_STORE_ORIGINAL_DESC', 'Definieren Sie, ob sie das Originalbild zusätzlich speichern wollen.
<br>Vorteil: alle Bilder sind später in neuen Größen und mit neuen Wasserzeichen reproduzierbar
<br>Nachteil: der Speicherbedarf wird entsprechend der zulässigen Größe für Uploads ansteigen');
define('_MI_WGGALLERY_TAGMODULE', 'Tags auch in TAG Modul anzeigen');
define('_MI_WGGALLERY_TAGMODULE_DESC', "Definieren die Bilder-Tags auch im Modul TAG angezeigt werden sollen<br>- Das Modul 'Tag' muss installiert sein<br>- Die Option 'Tags verwenden' muss aktiviert sein");
// Notifications
\define('_MI_WGGALLERY_GLOBAL_NOTIFY', 'Globale Benachrichtigungen');
\define('_MI_WGGALLERY_GLOBAL_ALB_NEW_ALL_NOTIFY', 'Sende Benachrichtigung wenn ein neues Album erstellt wird');
Expand Down
14 changes: 7 additions & 7 deletions sql/wggallery_1.2.0_migrate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ wggallery_albums:
attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' '
-
name: alb_desc
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: alb_weight
attributes: ' INT(8) NOT NULL DEFAULT ''0'' '
Expand All @@ -36,10 +36,10 @@ wggallery_albums:
attributes: ' INT(8) NOT NULL DEFAULT ''0'' '
-
name: alb_cats
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: alb_tags
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: alb_date
attributes: ' INT(8) NOT NULL DEFAULT ''0'' '
Expand All @@ -61,7 +61,7 @@ wggallery_images:
attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' '
-
name: img_desc
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: img_name
attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' '
Expand Down Expand Up @@ -106,13 +106,13 @@ wggallery_images:
attributes: ' INT(8) NOT NULL DEFAULT ''0'' '
-
name: img_cats
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: img_tags
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: img_exif
attributes: ' TEXT NULL '
attributes: ' TEXT NULL '
-
name: img_ip
attributes: ' VARCHAR(50) NOT NULL DEFAULT '''''''' '
Expand Down
Loading

0 comments on commit 38bd240

Please sign in to comment.