diff --git a/admin/images.php b/admin/images.php index c4b064e..b8443d4 100644 --- a/admin/images.php +++ b/admin/images.php @@ -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 diff --git a/class/ImagesHandler.php b/class/ImagesHandler.php index 2a5d8d8..9b7321d 100644 --- a/class/ImagesHandler.php +++ b/class/ImagesHandler.php @@ -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; } @@ -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; + } } diff --git a/docs/changelog.txt b/docs/changelog.txt index 5c1b140..3d56e2b 100644 --- a/docs/changelog.txt +++ b/docs/changelog.txt @@ -1,3 +1,7 @@ +
1.2.0 RC2
[2022/09/27] +
+- added support of tag module (alain01/goffy) +
1.2.0 RC1
[2021/04/19]
- semantic versioning (mamba/goffy) diff --git a/images.php b/images.php index d3b53c8..86d9e5c 100644 --- a/images.php +++ b/images.php @@ -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); @@ -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&alb_id=' . $imgAlbId . '&alb_pid=' . $imgAlbPid . '#image_' . $imgId, 2, \_CO_WGGALLERY_FORM_OK); } else { diff --git a/include/plugin.tag.php b/include/plugin.tag.php new file mode 100644 index 0000000..6dacc1d --- /dev/null +++ b/include/plugin.tag.php @@ -0,0 +1,117 @@ + - Website: + * @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&img_id=' . $itemId . '&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; +} diff --git a/language/english/modinfo.php b/language/english/modinfo.php index e8a7444..1357c29 100644 --- a/language/english/modinfo.php +++ b/language/english/modinfo.php @@ -137,6 +137,8 @@ \define('_MI_WGGALLERY_STORE_ORIGINAL_DESC', 'Define, whether you want to store the original image.
Advantage: all images can be reproduced later including new water marks
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
- The module 'TAG' musst be installed
- 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'); diff --git a/language/german/modinfo.php b/language/german/modinfo.php index 6fe2267..cf4fa37 100644 --- a/language/german/modinfo.php +++ b/language/german/modinfo.php @@ -137,6 +137,8 @@ \define('_MI_WGGALLERY_STORE_ORIGINAL_DESC', 'Definieren Sie, ob sie das Originalbild zusätzlich speichern wollen.
Vorteil: alle Bilder sind später in neuen Größen und mit neuen Wasserzeichen reproduzierbar
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
- Das Modul 'Tag' muss installiert sein
- 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'); diff --git a/sql/wggallery_1.2.0_migrate.yml b/sql/wggallery_1.2.0_migrate.yml index 748e011..08f661f 100644 --- a/sql/wggallery_1.2.0_migrate.yml +++ b/sql/wggallery_1.2.0_migrate.yml @@ -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'' ' @@ -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'' ' @@ -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 '''''''' ' @@ -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 '''''''' ' diff --git a/sql/wggallery_1_2_0_migrate.yml b/sql/wggallery_1_2_0_migrate.yml new file mode 100644 index 0000000..08f661f --- /dev/null +++ b/sql/wggallery_1_2_0_migrate.yml @@ -0,0 +1,301 @@ +wggallery_albums: + options: 'ENGINE=InnoDB' + columns: + - + name: alb_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: alb_pid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: alb_iscoll + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: alb_name + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: alb_desc + attributes: ' TEXT NULL ' + - + name: alb_weight + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: alb_imgtype + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: alb_image + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: alb_imgid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: alb_state + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: alb_wmid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: alb_cats + attributes: ' TEXT NULL ' + - + name: alb_tags + attributes: ' TEXT NULL ' + - + name: alb_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: alb_submitter + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: alb_id + unique: true +wggallery_images: + options: 'ENGINE=InnoDB' + columns: + - + name: img_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: img_title + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: img_desc + attributes: ' TEXT NULL ' + - + name: img_name + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: img_namelarge + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: img_nameorig + attributes: ' VARCHAR(200) NOT NULL DEFAULT '''''''' ' + - + name: img_mimetype + attributes: ' VARCHAR(50) NOT NULL DEFAULT '''''''' ' + - + name: img_size + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_resx + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_resy + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_downloads + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_ratinglikes + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_votes + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_weight + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_views + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_albid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_state + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_cats + attributes: ' TEXT NULL ' + - + name: img_tags + attributes: ' TEXT NULL ' + - + name: img_exif + attributes: ' TEXT NULL ' + - + name: img_ip + attributes: ' VARCHAR(50) NOT NULL DEFAULT '''''''' ' + - + name: img_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: img_submitter + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: img_id + unique: true +wggallery_gallerytypes: + options: 'ENGINE=InnoDB DEFAULT CHARSET=utf8' + columns: + - + name: gt_id + attributes: ' int(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: gt_primary + attributes: ' int(1) NOT NULL DEFAULT ''0'' ' + - + name: gt_name + attributes: ' varchar(100) NOT NULL DEFAULT '''''''' ' + - + name: gt_credits + attributes: ' varchar(100) NOT NULL DEFAULT '''''''' ' + - + name: gt_template + attributes: ' varchar(100) NOT NULL DEFAULT '''''''' ' + - + name: gt_options + attributes: ' text NULL ' + - + name: gt_date + attributes: ' int(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: gt_id + unique: true + gt_template: + columns: gt_template + unique: true +wggallery_albumtypes: + options: 'ENGINE=InnoDB' + columns: + - + name: at_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: at_primary + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: at_name + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: at_credits + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: at_template + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: at_options + attributes: ' TEXT NULL ' + - + name: at_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: at_id + unique: true + at_template: + columns: at_template + unique: true +wggallery_watermarks: + options: 'ENGINE=InnoDB' + columns: + - + name: wm_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: wm_name + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: wm_type + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_position + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_marginlr + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_margintb + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_image + attributes: ' VARCHAR(255) NOT NULL DEFAULT '''''''' ' + - + name: wm_text + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: wm_font + attributes: ' VARCHAR(255) NOT NULL DEFAULT '''''''' ' + - + name: wm_fontsize + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_color + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: wm_usage + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: wm_target + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: wm_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: wm_submitter + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: wm_id + unique: true +wggallery_categories: + options: 'ENGINE=InnoDB' + columns: + - + name: cat_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: cat_text + attributes: ' VARCHAR(100) NOT NULL DEFAULT '''''''' ' + - + name: cat_album + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: cat_image + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: cat_search + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: cat_weight + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: cat_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: cat_submitter + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: cat_id + unique: true +wggallery_ratings: + options: 'ENGINE=InnoDB' + columns: + - + name: rate_id + attributes: ' INT(8) UNSIGNED NOT NULL AUTO_INCREMENT ' + - + name: rate_source + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: rate_itemid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: rate_value + attributes: ' INT(1) NOT NULL DEFAULT ''0'' ' + - + name: rate_uid + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + - + name: rate_ip + attributes: ' VARCHAR(60) NOT NULL DEFAULT '''''''' ' + - + name: rate_date + attributes: ' INT(8) NOT NULL DEFAULT ''0'' ' + keys: + PRIMARY: + columns: rate_id + unique: true diff --git a/xoops_version.php b/xoops_version.php index 0b3c200..31ab964 100644 --- a/xoops_version.php +++ b/xoops_version.php @@ -26,7 +26,7 @@ // ------------------- Informations ------------------- // $modversion = [ 'version' => '1.2.0', - 'module_status' => 'RC1', + 'module_status' => 'RC2', 'release_date' => '2021/04/19', 'name' => \_MI_WGGALLERY_NAME, 'description' => \_MI_WGGALLERY_DESC, @@ -669,6 +669,15 @@ 'category' => 'group_header', ]; +$modversion['config'][] = [ + 'name' => 'usetagmodule', + 'title' => '_MI_WGGALLERY_TAGMODULE', + 'description' => '_MI_WGGALLERY_TAGMODULE_DESC', + 'formtype' => 'yesno', + 'valuetype' => 'int', + 'default' => 0, +]; + // Editor desc \xoops_load('xoopseditorhandler'); $editorHandlerDesc = \XoopsEditorHandler::getInstance();