/** Get item fields: title, content, time, link, uid, uname, tags **/ function ilog_tag_iteminfo(&$items) { if (empty($items) || !is_array($items)) { return false; } $items_id = array(); /**/ foreach (array_keys($items) as $cat_id) { // Some handling here to build the link upon catid // If catid is not used, just skip it foreach (array_keys($items[$cat_id]) as $item_id) { // In article, the item_id is "art_id" $items_id[] = intval($item_id); } } $item_handler =& xoops_getmodulehandler("article", "ilog"); $items_obj = $item_handler->getObjects(new Criteria("id", "(" . implode(", ", $items_id) . ")", "IN"), true); foreach (array_keys($items) as $cat_id) { foreach (array_keys($items[$cat_id]) as $item_id) { $item_obj =& $items_obj[$item_id]; $items[$cat_id][$item_id] = array("title" => $item_obj->getVar("title"), "uid" => $item_obj->getVar("uid"), "link" => "view.php?id={$item_id}", "time" => $item_obj->getVar("time_publish"), "tags" => tag_parse_tag($item_obj->getVar("keywords", "n")), "content" => ""); } } unset($items_obj); }
function martin_tag_iteminfo(&$items) { if (empty($items) || !is_array($items)) { return false; } $items_id = array(); foreach (array_keys($items) as $cat_id) { // Some handling here to build the link upon catid // catid is not used in article, so just skip it foreach (array_keys($items[$cat_id]) as $item_id) { // In article, the item_id is "art_id" $items_id[] = intval($item_id); } } $item_handler =& xoops_getmodulehandler("hotel", 'martin'); $items_obj = $item_handler->getObjects(new Criteria("hotel_id", "(" . implode(", ", $items_id) . ")", "IN"), true); foreach (array_keys($items) as $cat_id) { foreach (array_keys($items[$cat_id]) as $item_id) { if (!($item_obj =& $items_obj[$item_id])) { continue; } $items[$cat_id][$item_id] = array("title" => $item_obj->getVar("hotel_name"), "link" => "short.php?hotel_id={$item_id}", "time" => $item_obj->getVar("hotel_add_time"), "tags" => tag_parse_tag($item_obj->getVar("hotel_tags", "n")), "content" => ""); } } unset($items_obj); }
/** * Get item fields: * title * content * time * link * uid * uname * tags * * @var array $items associative array of items: [modid][catid][itemid] * * @return boolean * */ function newbb_tag_iteminfo(&$items) { if (empty($items) || !is_array($items)) { return false; } $items_id = array(); foreach (array_keys($items) as $cat_id) { // Some handling here to build the link upon catid // catid is not used in newbb, so just skip it foreach (array_keys($items[$cat_id]) as $item_id) { // In newbb, the item_id is "topic_id" $items_id[] = intval($item_id); } } $item_handler =& xoops_getmodulehandler('topic', 'newbb'); $items_obj = $item_handler->getObjects(new Criteria("topic_id", "(" . implode(", ", $items_id) . ")", "IN"), true); foreach (array_keys($items) as $cat_id) { foreach (array_keys($items[$cat_id]) as $item_id) { if (!($item_obj =& $items_obj[$item_id])) { continue; } $items[$cat_id][$item_id] = array("title" => $item_obj->getVar("topic_title"), "uid" => $item_obj->getVar("topic_poster"), "link" => "viewtopic.php?topic_id={$item_id}", "time" => $item_obj->getVar("topic_time"), "tags" => tag_parse_tag($item_obj->getVar("topic_tags", "n")), "content" => ""); } } unset($items_obj); }
/** * Display tag list * * @var array $tags array of tag string * OR * @var integer $itemid * @var integer $catid * @var integer $modid * * @return array (subject language, array of linked tags) */ function tagBar($tags, $catid = 0, $modid = 0) { static $loaded, $delimiter; if (empty($tags)) { return array(); } if (!isset($loaded)) { include XOOPS_ROOT_PATH . "/modules/tag/include/vars.php"; include_once XOOPS_ROOT_PATH . "/modules/tag/include/functions.php"; tag_define_url_delimiter(); if (!is_object($GLOBALS["xoopsModule"]) || "tag" != $GLOBALS["xoopsModule"]->getVar("dirname")) { if (function_exists("xoops_load_lang_file")) { xoops_load_lang_file("main", "tag"); } else { $path = XOOPS_ROOT_PATH . "/modules/tag/language"; if (!@(include_once "{$path}/{$GLOBALS['xoopsConfig']['language']}/main.php")) { $ret = @(include_once "{$path}/english/main.php"); } } } $loaded = 1; $delimiter = @file_exists(XOOPS_ROOT_PATH . "/modules/tag/images/delimiter.gif") ? "<img src=\"" . XOOPS_URL . "/modules/tag/images/delimiter.gif\" alt=\"\" />" : "<img src=\"" . XOOPS_URL . "/images/pointer.gif\" alt=\"\" />"; } // itemid if (is_numeric($tags)) { if (empty($modid) && is_object($GLOBALS["xoopsModule"])) { $modid = $GLOBALS["xoopsModule"]->getVar("mid"); } $tag_handler =& xoops_getmodulehandler("tag", "tag"); if (!($tags = $tag_handler->getByItem($tags, $modid, $catid))) { return array(); } // if ready, do nothing } elseif (is_array($tags)) { // parse } elseif (!($tags = tag_parse_tag($tags))) { return array(); } $tags_data = array(); foreach ($tags as $tag) { $tags_data[] = "<a href=\"" . XOOPS_URL . "/modules/" . $GLOBALS["xoopsModule"]->getVar("dirname") . "/view.tag.php" . URL_DELIMITER . urlencode($tag) . "\" title=\"" . htmlspecialchars($tag) . "\">" . htmlspecialchars($tag) . "</a>"; } return array("title" => TAG_MD_TAGS, "delimiter" => $delimiter, "tags" => $tags_data); }
/** Get item fields: title, content, time, link, uid, uname, tags * * * @param $items */ function publisher_tag_iteminfo(&$items) { $itemsId = array(); foreach (array_keys($items) as $catId) { // Some handling here to build the link upon catid // if catid is not used, just skip it foreach (array_keys($items[$catId]) as $itemId) { // In article, the item_id is "art_id" $itemsId[] = (int) $itemId; } } $itemHandler =& xoops_getModuleHandler('item', 'publisher'); $criteria = new Criteria('itemid', '(' . implode(', ', $itemsId) . ')', 'IN'); $itemsObj = $itemHandler->getObjects($criteria, 'itemid'); foreach (array_keys($items) as $catId) { foreach (array_keys($items[$catId]) as $itemId) { $itemObj = $itemsObj[$itemId]; $items[$catId][$itemId] = array('title' => $itemObj->getVar('title'), 'uid' => $itemObj->getVar('uid'), 'link' => "item.php?itemid={$itemId}", 'time' => $itemObj->getVar('datesub'), 'tags' => tag_parse_tag($itemObj->getVar('item_tag', 'n')), 'content' => ''); } } unset($itemsObj); }
/** Get item fields: title, content, time, link, uid, uname, tags **/ function publisher_tag_iteminfo(&$items) { $items_id = array(); foreach (array_keys($items) as $cat_id) { // Some handling here to build the link upon catid // if catid is not used, just skip it foreach (array_keys($items[$cat_id]) as $item_id) { // In article, the item_id is "art_id" $items_id[] = intval($item_id); } } $item_handler = xoops_getmodulehandler("item", "publisher"); $criteria = new Criteria("itemid", "(" . implode(", ", $items_id) . ")", "IN"); $items_obj = $item_handler->getObjects($criteria, 'itemid'); foreach (array_keys($items) as $cat_id) { foreach (array_keys($items[$cat_id]) as $item_id) { $item_obj = $items_obj[$item_id]; $items[$cat_id][$item_id] = array("title" => $item_obj->getVar("title"), "uid" => $item_obj->getVar("uid"), "link" => "item.php?itemid={$item_id}", "time" => $item_obj->getVar("datesub"), "tags" => tag_parse_tag($item_obj->getVar("item_tag", "n")), "content" => ""); } } unset($items_obj); }
/** * Update tags linked to an item * * @param array $tags * @param integer $itemid item ID * @param integer $modid module ID or module dirname, optional * @param integer $catid id of corresponding category, optional * @return boolean */ function updateByItem($tags, $itemid, $modid = "", $catid = 0) { $catid = intval($catid); $itemid = intval($itemid); if (!empty($modid) && !is_numeric($modid)) { if (is_object($GLOBALS["xoopsModule"]) && $modid == $GLOBALS["xoopsModule"]->getVar("dirname")) { $modid = $GLOBALS["xoopsModule"]->getVar("mid"); } else { $module_handler =& xoops_gethandler("module"); if ($module_obj = $module_handler->getByDirname($modid)) { $modid = $module_obj->getVar("mid"); } else { $modid = 0; } } } elseif (is_object($GLOBALS["xoopsModule"])) { $modid = $GLOBALS["xoopsModule"]->getVar("mid"); } if (empty($itemid) || empty($modid)) { return false; } if (empty($tags)) { $tags = array(); } elseif (!is_array($tags)) { include_once XOOPS_ROOT_PATH . "/modules/tag/include/functions.php"; $tags = tag_parse_tag(addslashes(stripslashes($tags))); } $tags_existing = $this->getByItem($itemid, $modid, $catid); $tags_delete = array_diff(array_values($tags_existing), $tags); $tags_add = array_diff($tags, array_values($tags_existing)); $tags_update = array(); if (!empty($tags_delete)) { $tags_delete = array_map(array($this->db, "quoteString"), $tags_delete); if ($tags_id = $this->getIds(new Criteria("tag_term", "(" . implode(", ", $tags_delete) . ")", "IN"))) { $sql = "DELETE FROM {$this->table_link}" . " WHERE " . " {$this->keyName} IN (" . implode(", ", $tags_id) . ")" . " AND tag_modid = {$modid} AND tag_catid = {$catid} AND tag_itemid = {$itemid}"; if (($result = $this->db->queryF($sql)) == false) { } $sql = "DELETE FROM " . $this->table . " WHERE " . " tag_count < 2 AND " . " {$this->keyName} IN (" . implode(", ", $tags_id) . ")"; if (($result = $this->db->queryF($sql)) == false) { //xoops_error($this->db->error()); } $sql = "UPDATE " . $this->table . " SET tag_count = tag_count - 1" . " WHERE " . " {$this->keyName} IN (" . implode(", ", $tags_id) . ")"; if (($result = $this->db->queryF($sql)) == false) { //xoops_error($this->db->error()); } $tags_update = $tags_id; } } if (!empty($tags_add)) { $tag_link = array(); $tag_count = array(); foreach ($tags_add as $tag) { if ($tags_id = $this->getIds(new Criteria("tag_term", $tag))) { $tag_id = $tags_id[0]; $tag_count[] = $tag_id; } else { $tag_obj =& $this->create(); $tag_obj->setVar("tag_term", $tag); $tag_obj->setVar("tag_count", 1); $this->insert($tag_obj); $tag_id = $tag_obj->getVar("tag_id"); unset($tag_obj); } $tag_link[] = "({$tag_id}, {$itemid}, {$catid}, {$modid}, " . time() . ")"; $tags_update[] = $tag_id; } $sql = "INSERT INTO {$this->table_link}" . " (tag_id, tag_itemid, tag_catid, tag_modid, tag_time) " . " VALUES " . implode(", ", $tag_link); if (($result = $this->db->queryF($sql)) == false) { //xoops_error($this->db->error()); } if (!empty($tag_count)) { $sql = "UPDATE " . $this->table . " SET tag_count = tag_count+1" . " WHERE " . " {$this->keyName} IN (" . implode(", ", $tag_count) . ")"; if (($result = $this->db->queryF($sql)) == false) { //xoops_error($this->db->error()); } } } foreach ($tags_update as $tag_id) { $this->update_stats($tag_id, $modid, $catid); } return true; }