<commit_before><?php
require_once("dbconnection.php");
require_once("users.php");
require_once("editors.php");
require_once("return_package.php");

require_once("tags.php");
require_once("requirements.php");

class tags extends dbconnection
{	
    //Takes in tag JSON, all fields optional except user_id + key
    public static function createTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::createTagPack($glob); }
    public static function createTagPack($pack)
    {
        $pack->auth->game_id = $pack->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $pack->tag_id = dbconnection::queryInsert(
            "INSERT INTO tags (".
            "game_id,".
            (isset($pack->tag)            ? "tag,"            : "").
            (isset($pack->media_id)       ? "media_id,"       : "").
            (isset($pack->visible)        ? "visible,"        : "").
            (isset($pack->sort_index)     ? "sort_index,"     : "").
            "created".
            ") VALUES (".
            "'".addslashes($pack->game_id)."',".
            (isset($pack->tag)            ? "'".addslashes($pack->tag)."',"            : "").
            (isset($pack->media_id)       ? "'".addslashes($pack->media_id)."',"       : "").
            (isset($pack->visible)        ? "'".addslashes($pack->visible)."',"        : "").
            (isset($pack->sort_index)     ? "'".addslashes($pack->sort_index)."',"     : "").
            "CURRENT_TIMESTAMP".
            ")"
        );

        return tags::getTagPack($pack);
    }

    //Takes in tag JSON, all fields optional except user_id + key
    public static function createObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::createObjectTagPack($glob); }
    public static function createObjectTagPack($pack)
    {
        $pack->auth->game_id = $pack->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $pack->object_tag_id = dbconnection::queryInsert(
            "INSERT INTO object_tags (".
            "game_id,".
            (isset($pack->object_type) ? "object_type," : "").
            (isset($pack->object_id)   ? "object_id,"   : "").
            (isset($pack->tag_id)      ? "tag_id,"      : "").
            "created".
            ") VALUES (".
            "'".addslashes($pack->game_id)."',".
            (isset($pack->object_type) ? "'".addslashes($pack->object_type)."'," : "").
            (isset($pack->object_id)   ? "'".addslashes($pack->object_id)."',"   : "").
            (isset($pack->tag_id)      ? "'".addslashes($pack->tag_id)."',"      : "").
            "CURRENT_TIMESTAMP".
            ")"
        );

        return tags::getObjectTagPack($pack);
    }

    public static function updateTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::updateTagPack($glob); }
    public static function updateTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query(
            "UPDATE tags SET ".
            (isset($pack->tag)            ? "tag            = '".addslashes($pack->tag)."', "            : "").
            (isset($pack->media_id)       ? "media_id       = '".addslashes($pack->media_id)."', "       : "").
            (isset($pack->visible)        ? "visible        = '".addslashes($pack->visible)."', "        : "").
            (isset($pack->sort_index)     ? "sort_index     = '".addslashes($pack->sort_index)."', "     : "").
            "last_active = CURRENT_TIMESTAMP ".
            "WHERE tag_id = '{$pack->tag_id}'"
        );

        return tags::getTagPack($pack);
    }

    private static function tagObjectFromSQL($sql_tag)
    {
        if(!$sql_tag) return $sql_tag;
        $tag = new stdClass();
        $tag->tag_id         = $sql_tag->tag_id;
        $tag->game_id        = $sql_tag->game_id;
        $tag->tag            = $sql_tag->tag;
        $tag->media_id       = $sql_tag->media_id;
        $tag->visible        = $sql_tag->visible;
        $tag->sort_index     = $sql_tag->sort_index;

        return $tag;
    }

    private static function objectTagObjectFromSQL($sql_object_tag)
    {
        if(!$sql_object_tag) return $sql_object_tag;
        $tag = new stdClass();
        $tag->object_tag_id = $sql_object_tag->object_tag_id;
        $tag->object_type   = $sql_object_tag->object_type;
        $tag->object_id     = $sql_object_tag->object_id;
        $tag->tag_id        = $sql_object_tag->tag_id;

        return $tag;
    }

    public static function getTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getTagPack($glob); }
    public static function getTagPack($pack)
    {
        $sql_tag = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}' LIMIT 1");
        if(!$sql_tag) return new return_package(2, NULL, "The tag you've requested does not exist");
        return new return_package(0,tags::tagObjectFromSQL($sql_tag));
    }

    public static function getObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagPack($glob); }
    public static function getObjectTagPack($pack)
    {
        $sql_object_tag = dbconnection::queryObject("SELECT * FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}' LIMIT 1");
        if(!$sql_object_tag) return new return_package(2, NULL, "The tag you've requested does not exist");
        return new return_package(0,tags::objectTagObjectFromSQL($sql_object_tag));
    }

    public static function getTagsForGame($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getTagsForGamePack($glob); }
    public static function getTagsForGamePack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_tags = dbconnection::queryArray("SELECT * FROM tags WHERE game_id = '{$pack->game_id}'");
        $tags = array();
        for($i = 0; $i < count($sql_tags); $i++)
            if($ob = tags::tagObjectFromSQL($sql_tags[$i])) $tags[] = $ob;

        return new return_package(0,$tags);

    }

    public static function getObjectTagsForGame($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagsForGamePack($glob); }
    public static function getObjectTagsForGamePack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_object_tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE game_id = '{$pack->game_id}'");
        $object_tags = array();
        for($i = 0; $i < count($sql_object_tags); $i++)
            if($ob = tags::objectTagObjectFromSQL($sql_object_tags[$i])) $object_tags[] = $ob;

        return new return_package(0,$object_tags);

    }

    public static function getObjectTagsForObject($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagsForObjectPack($glob); }
    public static function getObjectTagsForObjectPack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_object_tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE game_id = '{$pack->game_id}' AND object_type = '{$pack->object_type}' AND object_id = '{$pack->object_id}'");
        $object_tags = array();
        for($i = 0; $i < count($sql_object_tags); $i++)
            if($ob = tags::objectTagObjectFromSQL($sql_object_tags[$i])) $object_tags[] = $ob;

        return new return_package(0,$object_tags);

    }

    public static function deleteTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::deleteTagPack($glob); }
    public static function deleteTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query("DELETE FROM tags WHERE tag_id = '{$pack->tag_id}' LIMIT 1");
        //cleanup
        $tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE tag_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($tags); $i++)
        {
            $pack->object_tag_id = $tags[$i]->object_tag_id;
            tags::deleteObjectTagPack($pack);
        }

        $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_TAGGED_ITEM' AND content_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($reqAtoms); $i++)
        {
            $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id;
            requirements::deleteRequirementAtomPack($pack);
        }

        $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_NOTE_WITH_TAG' AND content_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($reqAtoms); $i++)
        {
            $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id;
            requirements::deleteRequirementAtomPack($pack);
        }

        return new return_package(0);
    }

    public static function deleteObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::deleteObjectTagPack($glob); }
    public static function deleteObjectTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query("DELETE FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}' LIMIT 1");
        return new return_package(0);
    }
}
?>
<commit_msg>tags have curated flag<commit_after><?php
require_once("dbconnection.php");
require_once("users.php");
require_once("editors.php");
require_once("return_package.php");

require_once("tags.php");
require_once("requirements.php");

class tags extends dbconnection
{	
    //Takes in tag JSON, all fields optional except user_id + key
    public static function createTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::createTagPack($glob); }
    public static function createTagPack($pack)
    {
        $pack->auth->game_id = $pack->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $pack->tag_id = dbconnection::queryInsert(
            "INSERT INTO tags (".
            "game_id,".
            (isset($pack->tag)            ? "tag,"            : "").
            (isset($pack->media_id)       ? "media_id,"       : "").
            (isset($pack->visible)        ? "visible,"        : "").
            (isset($pack->curated)        ? "curated,"        : "").
            (isset($pack->sort_index)     ? "sort_index,"     : "").
            "created".
            ") VALUES (".
            "'".addslashes($pack->game_id)."',".
            (isset($pack->tag)            ? "'".addslashes($pack->tag)."',"            : "").
            (isset($pack->media_id)       ? "'".addslashes($pack->media_id)."',"       : "").
            (isset($pack->visible)        ? "'".addslashes($pack->visible)."',"        : "").
            (isset($pack->curated)        ? "'".addslashes($pack->curated)."',"        : "").
            (isset($pack->sort_index)     ? "'".addslashes($pack->sort_index)."',"     : "").
            "CURRENT_TIMESTAMP".
            ")"
        );

        return tags::getTagPack($pack);
    }

    //Takes in tag JSON, all fields optional except user_id + key
    public static function createObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::createObjectTagPack($glob); }
    public static function createObjectTagPack($pack)
    {
        $pack->auth->game_id = $pack->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $pack->object_tag_id = dbconnection::queryInsert(
            "INSERT INTO object_tags (".
            "game_id,".
            (isset($pack->object_type) ? "object_type," : "").
            (isset($pack->object_id)   ? "object_id,"   : "").
            (isset($pack->tag_id)      ? "tag_id,"      : "").
            "created".
            ") VALUES (".
            "'".addslashes($pack->game_id)."',".
            (isset($pack->object_type) ? "'".addslashes($pack->object_type)."'," : "").
            (isset($pack->object_id)   ? "'".addslashes($pack->object_id)."',"   : "").
            (isset($pack->tag_id)      ? "'".addslashes($pack->tag_id)."',"      : "").
            "CURRENT_TIMESTAMP".
            ")"
        );

        return tags::getObjectTagPack($pack);
    }

    public static function updateTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::updateTagPack($glob); }
    public static function updateTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query(
            "UPDATE tags SET ".
            (isset($pack->tag)            ? "tag            = '".addslashes($pack->tag)."', "            : "").
            (isset($pack->media_id)       ? "media_id       = '".addslashes($pack->media_id)."', "       : "").
            (isset($pack->visible)        ? "visible        = '".addslashes($pack->visible)."', "        : "").
            (isset($pack->curated)        ? "curated        = '".addslashes($pack->curated)."', "        : "").
            (isset($pack->sort_index)     ? "sort_index     = '".addslashes($pack->sort_index)."', "     : "").
            "last_active = CURRENT_TIMESTAMP ".
            "WHERE tag_id = '{$pack->tag_id}'"
        );

        return tags::getTagPack($pack);
    }

    private static function tagObjectFromSQL($sql_tag)
    {
        if(!$sql_tag) return $sql_tag;
        $tag = new stdClass();
        $tag->tag_id         = $sql_tag->tag_id;
        $tag->game_id        = $sql_tag->game_id;
        $tag->tag            = $sql_tag->tag;
        $tag->media_id       = $sql_tag->media_id;
        $tag->visible        = $sql_tag->visible;
        $tag->curated        = $sql_tag->curated;
        $tag->sort_index     = $sql_tag->sort_index;

        return $tag;
    }

    private static function objectTagObjectFromSQL($sql_object_tag)
    {
        if(!$sql_object_tag) return $sql_object_tag;
        $tag = new stdClass();
        $tag->object_tag_id = $sql_object_tag->object_tag_id;
        $tag->object_type   = $sql_object_tag->object_type;
        $tag->object_id     = $sql_object_tag->object_id;
        $tag->tag_id        = $sql_object_tag->tag_id;

        return $tag;
    }

    public static function getTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getTagPack($glob); }
    public static function getTagPack($pack)
    {
        $sql_tag = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}' LIMIT 1");
        if(!$sql_tag) return new return_package(2, NULL, "The tag you've requested does not exist");
        return new return_package(0,tags::tagObjectFromSQL($sql_tag));
    }

    public static function getObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagPack($glob); }
    public static function getObjectTagPack($pack)
    {
        $sql_object_tag = dbconnection::queryObject("SELECT * FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}' LIMIT 1");
        if(!$sql_object_tag) return new return_package(2, NULL, "The tag you've requested does not exist");
        return new return_package(0,tags::objectTagObjectFromSQL($sql_object_tag));
    }

    public static function getTagsForGame($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getTagsForGamePack($glob); }
    public static function getTagsForGamePack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_tags = dbconnection::queryArray("SELECT * FROM tags WHERE game_id = '{$pack->game_id}'");
        $tags = array();
        for($i = 0; $i < count($sql_tags); $i++)
            if($ob = tags::tagObjectFromSQL($sql_tags[$i])) $tags[] = $ob;

        return new return_package(0,$tags);

    }

    public static function getObjectTagsForGame($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagsForGamePack($glob); }
    public static function getObjectTagsForGamePack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_object_tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE game_id = '{$pack->game_id}'");
        $object_tags = array();
        for($i = 0; $i < count($sql_object_tags); $i++)
            if($ob = tags::objectTagObjectFromSQL($sql_object_tags[$i])) $object_tags[] = $ob;

        return new return_package(0,$object_tags);

    }

    public static function getObjectTagsForObject($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::getObjectTagsForObjectPack($glob); }
    public static function getObjectTagsForObjectPack($pack)
    {
        $pack->auth->permission = "read_write";
        if(!users::authenticateUser($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        $sql_object_tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE game_id = '{$pack->game_id}' AND object_type = '{$pack->object_type}' AND object_id = '{$pack->object_id}'");
        $object_tags = array();
        for($i = 0; $i < count($sql_object_tags); $i++)
            if($ob = tags::objectTagObjectFromSQL($sql_object_tags[$i])) $object_tags[] = $ob;

        return new return_package(0,$object_tags);

    }

    public static function deleteTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::deleteTagPack($glob); }
    public static function deleteTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM tags WHERE tag_id = '{$pack->tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query("DELETE FROM tags WHERE tag_id = '{$pack->tag_id}' LIMIT 1");
        //cleanup
        $tags = dbconnection::queryArray("SELECT * FROM object_tags WHERE tag_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($tags); $i++)
        {
            $pack->object_tag_id = $tags[$i]->object_tag_id;
            tags::deleteObjectTagPack($pack);
        }

        $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_TAGGED_ITEM' AND content_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($reqAtoms); $i++)
        {
            $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id;
            requirements::deleteRequirementAtomPack($pack);
        }

        $reqAtoms = dbconnection::queryArray("SELECT * FROM requirement_atoms WHERE requirement = 'PLAYER_HAS_NOTE_WITH_TAG' AND content_id = '{$pack->tag_id}'");
        for($i = 0; $i < count($reqAtoms); $i++)
        {
            $pack->requirement_atom_id = $reqAtoms[$i]->requirement_atom_id;
            requirements::deleteRequirementAtomPack($pack);
        }

        return new return_package(0);
    }

    public static function deleteObjectTag($glob) { $data = file_get_contents("php://input"); $glob = json_decode($data); return tags::deleteObjectTagPack($glob); }
    public static function deleteObjectTagPack($pack)
    {
        $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}'")->game_id;
        $pack->auth->permission = "read_write";
        if(!editors::authenticateGameEditor($pack->auth)) return new return_package(6, NULL, "Failed Authentication");

        dbconnection::query("DELETE FROM object_tags WHERE object_tag_id = '{$pack->object_tag_id}' LIMIT 1");
        return new return_package(0);
    }
}
?>

{'fraction_non_alphanumeric': 0.16738512336054298, 'fraction_numerical': 0.002476382646977896, 'mean_word_length': 2.929897278788971, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 240, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4898953', 'n_tokens_mistral': 6675, 'n_tokens_neox': 6572, 'n_words': 1168}