<commit_before><?php
// CVS: $Id: objectlib.php,v 1.9 2007-08-10 13:34:06 guidoscherp Exp $
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

// this is an abstract class
class ObjectLib extends TikiLib {
	function ObjectLib($db) {
		$this->TikiLib($db);
	}

    function add_object($type, $itemId, $description = '', $name = '', $href = '') {

	$objectId = $this->get_object_id($type, $itemId);

	if ($objectId) {
	    if (!empty($description) || !empty($name) || !empty($href)) {
		$description = strip_tags($description);
		$name = strip_tags($name);
		$query = "update `tiki_objects` set `description`=?,`name`=?,`href`=? where `objectId`=?";
		$this->query($query,array($description,$name,$href,$objectId));
	    }
	} else {
	    $objectId = $this->insert_object($type, $itemId, $description, $name, $href);
	}
    return $objectId;
    }

    function insert_object($type, $itemId, $description = '', $name = '', $href = '') {
		$description = strip_tags($description);
		$name = strip_tags($name);
	
	    $query = "insert into `tiki_objects`(`type`,`itemId`,`description`,`name`,`href`,`created`,`hits`)
    values(?,?,?,?,?,?,?)";
	    $result = $this->query($query,array($type,(string) $itemId,$description,$name,$href,(int) $this->now,0));
	    $query = "select `objectId` from `tiki_objects` where `created`=? and `type`=? and `itemId`=?";
	    $objectId = $this->getOne($query,array((int) $this->now,$type,(string) $itemId));
	    return $objectId;
    }

    function get_object_id($type, $itemId) {
	$query = "select `objectId` from `tiki_objects` where `type`=? and `itemId`=?";
	return $this->getOne($query, array($type, $itemId));
    }

	function get_needed_perm($objectType, $action) {
		switch ($objectType) {
		case 'wiki page': case 'wiki':
			switch ($action) {
			case 'view': case 'read': return 'tiki_p_view';
			case 'edit': return 'tiki_p_edit';<commit_msg>[FIX]freetag: DIRTY patch: freetag is tagging the object without creating a valid tiki-object ((no href, no name) - so if freetaging occurs on object that does not exist in tiki_object, no way to delete the tagg after. usually tiki-edipage creates the object via the categorize stuff but if the page has been created with import - there is no tiki_object line ->TODO update freetag module + lib to transfer href+name+description<commit_after><?php
// CVS: $Id: objectlib.php,v 1.9.2.1 2007-12-25 17:22:56 sylvieg Exp $
//this script may only be included - so its better to die if called directly.
if (strpos($_SERVER["SCRIPT_NAME"],basename(__FILE__)) !== false) {
  header("location: index.php");
  exit;
}

// this is an abstract class
class ObjectLib extends TikiLib {
	function ObjectLib($db) {
		$this->TikiLib($db);
	}

    function add_object($type, $itemId, $description = '', $name = '', $href = '') {

	$objectId = $this->get_object_id($type, $itemId);

	if ($objectId) {
		if (!empty($description) || !empty($name) || !empty($href)) {
			$description = strip_tags($description);
			$name = strip_tags($name);
			$query = "update `tiki_objects` set `description`=?,`name`=?,`href`=? where `objectId`=?";
			$this->query($query,array($description,$name,$href,$objectId));
	    }
	} else {
		if (empty($href) || empty($name)) { //DIRTY patch: these information are needed in browse freetag even if the freetag module does not provide them: fix->freetag module must provide them
			if ($type == 'wiki page') {
				$href = "tiki-index.php?page=".urlencode($itemId);
				$name = $itemId;
			}
		}
	    $objectId = $this->insert_object($type, $itemId, $description, $name, $href);
	}
    return $objectId;
    }

    function insert_object($type, $itemId, $description = '', $name = '', $href = '') {
		$description = strip_tags($description);
		$name = strip_tags($name);
	
	    $query = "insert into `tiki_objects`(`type`,`itemId`,`description`,`name`,`href`,`created`,`hits`)
    values(?,?,?,?,?,?,?)";
	    $result = $this->query($query,array($type,(string) $itemId,$description,$name,$href,(int) $this->now,0));
	    $query = "select `objectId` from `tiki_objects` where `created`=? and `type`=? and `itemId`=?";
	    $objectId = $this->getOne($query,array((int) $this->now,$type,(string) $itemId));
	    return $objectId;
    }

    function get_object_id($type, $itemId) {
	$query = "select `objectId` from `tiki_objects` where `type`=? and `itemId`=?";
	return $this->getOne($query, array($type, $itemId));
    }

	function get_needed_perm($objectType, $action) {
		switch ($objectType) {
		case 'wiki page': case 'wiki':
			switch ($action) {
			case 'view': case 'read': return 'tiki_p_view';
			case 'edit': return 'tiki_p_edit';
{'fraction_non_alphanumeric': 0.190146750524109, 'fraction_numerical': 0.007547169811320755, 'mean_word_length': 4.72749099639856, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3357990', 'n_tokens_mistral': 1721, 'n_tokens_neox': 1605, 'n_words': 401}