<commit_before><?php
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//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;
}

class BookmarkLib extends TikiLib
{
	function get_folder_path($folderId, $user) {
		$path = '';

		$info = $this->get_folder($folderId, $user);
		$path = '<a class="link" href=tiki-user_bookmarks.php?parentId="' . $info["folderId"] . '">' . htmlspecialchars($info["name"]) . '</a>';

		while ($info["parentId"] != 0) {
			$info = $this->get_folder($info["parentId"], $user);

			$path
				= $path = '<a class="link" href=tiki-user_bookmarks.php?parentId="' . $info["folderId"] . '">' . htmlspecialchars($info["name"]) . '</a>' . '>' . $path;
		}

		return $path;
	}

	function get_folder($folderId, $user) {
		$query = "select * from `tiki_user_bookmarks_folders` where `folderId`=? and `user`=?";

		$result = $this->query($query,array($folderId,$user));

		if (!$result->numRows())
			return false;

		$res = $result->fetchRow();
		return $res;
	}

	function get_url($urlId) {
		$query = "select * from `tiki_user_bookmarks_urls` where `urlId`=?";

		$result = $this->query($query,array($urlId));

		if (!$result->numRows())
			return false;

		$res = $result->fetchRow();
		return $res;
	}

	function remove_url($urlId, $user) {
		$query = "delete from `tiki_user_bookmarks_urls` where `urlId`=? and `user`=?";

		$result = $this->query($query,array($urlId,$user));
		return true;
	}

	function remove_folder($folderId, $user) {
		// Delete the category
		$query = "delete from `tiki_user_bookmarks_folders` where `folderId`=? and `user`=?";

		$result = $this->query($query,array($folderId,$user));
		// Remove objects for this category
		$query = "delete from `tiki_user_bookmarks_urls` where `folderId`=? and `user`=?";
		$result = $this->query($query,array($folderId,$user));
		// SUbfolders
		$query = "select `folderId` from `tiki_user_bookmarks_folders` where `parentId`=? and `user`=?";
		$result = $this->query($query,array($folderId,$user));

		while ($res = $result->fetchRow()) {
			// Recursively remove the subcategory
			$this->remove_folder($res["folderId"], $user);
		}

		return true;
	}

	function update_folder($folderId, $name, $user) {

		$query = "update `tiki_user_bookmarks_folders` set `name`=? where `folderId`=? and `user`=?";
		$result = $this->query($query,array($name,$folderId,$user));
	}

	function add_folder($parentId, $name, $user) {
		// Don't allow empty/blank folder names.
		if (empty($name))
			return false;

		// Find the next folderId
		$query = "select max(folderId) from `tiki_user_bookmarks_folders`";
		$maxId = $this->getOne($query);
		if( intval($maxId) == 0 ) {
			$maxId = 0;
		}
		$maxId += 1;
		
		$query = "insert into `tiki_user_bookmarks_folders`(`folderId`, `name`,`parentId`,`user`) values(?,?,?,?)";
		$result = $this->query($query,array($maxId,$name,$parentId,$user));
	}

	function replace_url($urlId, $folderId, $name, $url, $user) {
		if ($urlId) {<commit_msg>Bookmarklib: Calculate the maximum folderId for the current user only in add_folder()<commit_after><?php
// (c) Copyright 2002-2011 by authors of the Tiki Wiki CMS Groupware Project
// 
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
// $Id$

//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;
}

class BookmarkLib extends TikiLib
{
	function get_folder_path($folderId, $user) {
		$path = '';

		$info = $this->get_folder($folderId, $user);
		$path = '<a class="link" href=tiki-user_bookmarks.php?parentId="' . $info["folderId"] . '">' . htmlspecialchars($info["name"]) . '</a>';

		while ($info["parentId"] != 0) {
			$info = $this->get_folder($info["parentId"], $user);

			$path
				= $path = '<a class="link" href=tiki-user_bookmarks.php?parentId="' . $info["folderId"] . '">' . htmlspecialchars($info["name"]) . '</a>' . '>' . $path;
		}

		return $path;
	}

	function get_folder($folderId, $user) {
		$query = "select * from `tiki_user_bookmarks_folders` where `folderId`=? and `user`=?";

		$result = $this->query($query,array($folderId,$user));

		if (!$result->numRows())
			return false;

		$res = $result->fetchRow();
		return $res;
	}

	function get_url($urlId) {
		$query = "select * from `tiki_user_bookmarks_urls` where `urlId`=?";

		$result = $this->query($query,array($urlId));

		if (!$result->numRows())
			return false;

		$res = $result->fetchRow();
		return $res;
	}

	function remove_url($urlId, $user) {
		$query = "delete from `tiki_user_bookmarks_urls` where `urlId`=? and `user`=?";

		$result = $this->query($query,array($urlId,$user));
		return true;
	}

	function remove_folder($folderId, $user) {
		// Delete the category
		$query = "delete from `tiki_user_bookmarks_folders` where `folderId`=? and `user`=?";

		$result = $this->query($query,array($folderId,$user));
		// Remove objects for this category
		$query = "delete from `tiki_user_bookmarks_urls` where `folderId`=? and `user`=?";
		$result = $this->query($query,array($folderId,$user));
		// SUbfolders
		$query = "select `folderId` from `tiki_user_bookmarks_folders` where `parentId`=? and `user`=?";
		$result = $this->query($query,array($folderId,$user));

		while ($res = $result->fetchRow()) {
			// Recursively remove the subcategory
			$this->remove_folder($res["folderId"], $user);
		}

		return true;
	}

	function update_folder($folderId, $name, $user) {

		$query = "update `tiki_user_bookmarks_folders` set `name`=? where `folderId`=? and `user`=?";
		$result = $this->query($query,array($name,$folderId,$user));
	}

	function add_folder($parentId, $name, $user) {
		// Don't allow empty/blank folder names.
		if (empty($name))
			return false;

		// Find the next folderId
		$query = "select max(`folderId`) from `tiki_user_bookmarks_folders` WHERE `user`=?";
		$maxId = $this->getOne($query, array($user));
		if( intval($maxId) == 0 ) {
			$maxId = 0;
		}
		
		$query = "insert into `tiki_user_bookmarks_folders`(`folderId`, `name`,`parentId`,`user`) values(?,?,?,?)";
		$result = $this->query($query,array($maxId + 1,$name,$parentId,$user));
	}

	function replace_url($urlId, $folderId, $name, $url, $user) {
		if ($urlId) {
{'fraction_non_alphanumeric': 0.19157202630005976, 'fraction_numerical': 0.0035863717872086074, 'mean_word_length': 4.691326530612245, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 47, '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': '4901751', 'n_tokens_mistral': 2563, 'n_tokens_neox': 2352, 'n_words': 541}