----- SQL ----- --- CREATE TABLE `popot_tag` ( `tag_id` int NOT NULL AUTO_INCREMENT, `tag_name` varchar(100) NOT NULL, PRIMARY KEY (`tag_id`), UNIQUE KEY `tag_name` (`tag_name`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; --- ALTER TABLE `popot_mod` ADD COLUMN `tag1_id` int NOT NULL AFTER mod_description; ALTER TABLE `popot_mod` ADD COLUMN `tag2_id` int NOT NULL AFTER tag1_id; ALTER TABLE `popot_mod` ADD COLUMN `tag3_id` int NOT NULL AFTER tag2_id; --- ----- submit.php ----- --- (isset ($_POST['tag1_id'])) && (isset ($_POST['tag2_id'])) && (isset ($_POST['tag3_id'])) && --- $iTag1ID = intval ($_POST['tag1_id']); $iTag2ID = intval ($_POST['tag2_id']); $iTag3ID = intval ($_POST['tag3_id']); --- tag1_id='" . $iTag1ID . "', tag2_id='" . $iTag2ID . "', tag3_id='" . $iTag3ID . "', --- tag1_id='" . $iTag1ID . "', tag2_id='" . $iTag2ID . "', tag3_id='" . $iTag3ID . "', --- ----- popot_def.php ----- --- function TagsDDL ($sIdName, $sPickText, $iActiveID) /*****************************************************************************/ { /*** Returns the number of values, or FALSE. ***/ $query_ddl = "SELECT tag_id, tag_name FROM `popot_tag` ORDER BY tag_name"; $result_ddl = Query ($query_ddl); $iNrRows = mysqli_num_rows ($result_ddl); if ($iNrRows > 0) { print (''); return ($iNrRows); } else { return (FALSE); } } /*****************************************************************************/ function TagLink ($iTagID) /*****************************************************************************/ { /*** Returns a hyperlink, or FALSE. ***/ if ($iTagID != 0) { $query_name = "SELECT tag_name FROM `popot_tag` WHERE (tag_id='" . $iTagID . "')"; $result_name = Query ($query_name); if (mysqli_num_rows ($result_name) == 1) { $row_name = mysqli_fetch_assoc ($result_name); $sTagName = $row_name['tag_name']; return ('' . Sanitize ($sTagName) . ''); } else { return (FALSE); } } else { return (FALSE); } } /*****************************************************************************/ function TagMods ($iTagID) /*****************************************************************************/ { $query_nr = "SELECT COUNT(*) AS nr FROM `popot_mod` WHERE (tag1_id='" . $iTagID . "') OR (tag2_id='" . $iTagID . "') OR (tag3_id='" . $iTagID . "')"; $result_nr = Query ($query_nr); $row_nr = mysqli_fetch_assoc ($result_nr); return ($row_nr['nr']); } /*****************************************************************************/ --- ----- tags.php ----- --- Three tags can be added to each mod by their authors, and mod search allows filtering by tag. The available tags are limited to the controlled vocabulary listed alphabetically on this page. Tags must not contain spaces or more than two hyphenated words. You may contact us to suggest additional tags.

'); $query_list = "SELECT tag_id FROM `popot_tag` ORDER BY tag_name"; $result_list = Query ($query_list); $iNrRows = mysqli_num_rows ($result_list); if ($iNrRows > 0) { $iRow = 0; while ($row_list = mysqli_fetch_assoc ($result_list)) { $iTagID = $row_list['tag_id']; print ("\n" . TagLink ($iTagID) . ' (' . TagMods ($iTagID) . ')'); $iRow++; if ($iRow != $iNrRows) { print ('
'); } } } else { print ('No tags found.'); } } /*****************************************************************************/ function ShowAdd () /*****************************************************************************/ { print (' '); } /*****************************************************************************/ function ShowRemove () /*****************************************************************************/ { print (''); if (TagsDDL ('tag_remove', 'Select...', 0) !== FALSE) { print (''); } else { print ('No tags to remove.'); } print (''); } /*****************************************************************************/ function DoAdd () /*****************************************************************************/ { $sTag = $_POST['tag_add']; if ((strlen ($sTag) >= 1) && (strlen ($sTag) <= 100)) { $query_exists = "SELECT tag_id FROM `popot_tag` WHERE (tag_name='" . mysqli_real_escape_string ($GLOBALS['link'], $sTag) . "')"; $result_exists = Query ($query_exists); if (mysqli_num_rows ($result_exists) == 0) { $query_add = "INSERT INTO `popot_tag` SET tag_name='" . mysqli_real_escape_string ($GLOBALS['link'], $sTag) . "'"; $result_add = Query ($query_add); if (mysqli_affected_rows ($GLOBALS['link']) == 1) { $GLOBALS['top_text'] = 'Added "' . Sanitize ($sTag) . '".'; $GLOBALS['top_type'] = 'success'; } else { $GLOBALS['top_text'] = 'Could not add "' . Sanitize ($sTag) . '".'; $GLOBALS['top_type'] = 'error'; } } else { $GLOBALS['top_text'] = 'Tag "' . Sanitize ($sTag) . '" already exists.'; $GLOBALS['top_type'] = 'normal'; } } else { $GLOBALS['top_text'] = 'Tag has an invalid size.'; $GLOBALS['top_type'] = 'error'; } } /*****************************************************************************/ function DoRemove () /*****************************************************************************/ { $iTagID = intval ($_POST['tag_remove']); if ($iTagID != 0) { $query_hits = "SELECT COUNT(*) AS hits FROM `popot_mod` WHERE (tag1_id='" . $iTagID . "') OR (tag2_id='" . $iTagID . "') OR (tag3_id='" . $iTagID . "')"; $result_hits = Query ($query_hits); $row_hits = mysqli_fetch_assoc ($result_hits); if ($row_hits['hits'] == 0) { $query_remove = "DELETE FROM `popot_tag` WHERE (tag_id='" . $iTagID . "')"; $result_remove = Query ($query_remove); if (mysqli_affected_rows ($GLOBALS['link']) == 1) { $GLOBALS['top_text'] = 'Removed tag.'; $GLOBALS['top_type'] = 'success'; } else { $GLOBALS['top_text'] = 'Could not remove tag.'; $GLOBALS['top_type'] = 'error'; } } else { $GLOBALS['top_text'] = 'Tag is in use.'; $GLOBALS['top_type'] = 'error'; } } else { $GLOBALS['top_text'] = 'No tag selected.'; $GLOBALS['top_type'] = 'normal'; } } /*****************************************************************************/ if ((isset ($_POST['pressed'])) && (IsAdmin() === TRUE)) { $sPressed = $_POST['pressed']; switch ($sPressed) { case 'Add': DoAdd(); break; case 'Remove': DoRemove(); break; } } StartHTML ('Custom Levels', 'Tags', 'custom_levels.php', 'Play'); if (IsAdmin() === FALSE) { ShowOverview(); } else { AdminLinks(); print ('
'); ShowAdd(); ShowRemove(); print ('
'); } EndHTML(); ?> --- ----- custom_levels.php ----- --- if (isset ($_GET['tag_id'])) { $arSearch['tag_id'] = intval ($_GET['tag_id']); } --- if ($arSearch['tag_id'] != 0) { $sWhere = $sWhere . " AND ((tag1_id='" . $arSearch['tag_id'] . "') OR (tag2_id='" . $arSearch['tag_id'] . "') OR (tag3_id='" . $arSearch['tag_id'] . "'))"; } --- With Tag: '); TagsDDL ('tag_id', 'Any', $arSearch['tag_id']); print (' --- if (($row_get_mod['tag1_id'] != 0) || ($row_get_mod['tag2_id'] != 0) || ($row_get_mod['tag3_id'] != 0)) { print ('Tags: '); $arTags = array(); $sLink1 = TagLink ($row_get_mod['tag1_id']); if ($sLink1 !== FALSE) { array_push ($arTags, $sLink1); } $sLink2 = TagLink ($row_get_mod['tag2_id']); if ($sLink2 !== FALSE) { array_push ($arTags, $sLink2); } $sLink3 = TagLink ($row_get_mod['tag3_id']); if ($sLink3 !== FALSE) { array_push ($arTags, $sLink3); } print (implode (', ', $arTags)); print ('
'); } --- $arEdit['tag1_id'] = intval ($row_mod['tag1_id']); $arEdit['tag2_id'] = intval ($row_mod['tag2_id']); $arEdit['tag3_id'] = intval ($row_mod['tag3_id']); --- $arEdit['tag1_id'] = 0; $arEdit['tag2_id'] = 0; $arEdit['tag3_id'] = 0; ---

Tags

Optionally, you may select up to three tags below, that summarize your mod.

'); TagsDDL ('tag1_id', 'Select...', $arEdit['tag1_id']); TagsDDL ('tag2_id', 'Select...', $arEdit['tag2_id']); TagsDDL ('tag3_id', 'Select...', $arEdit['tag3_id']); print (' --- form_data.append ("tag1_id", $("#tag1_id").val()); form_data.append ("tag2_id", $("#tag2_id").val()); form_data.append ("tag3_id", $("#tag3_id").val()); --- $arSearch['tag_id'] = 0; ---