¶ VADß EThis file consists of binary data and should not be touched by hands!¶ STICKERß \6
¶ bookmark/sql/DET_Bookmark.sqlß ¬ø--
-- $Id: DET_Bookmark.sql,v 1.8 2006/08/14 17:02:13 virtdev Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
use DB
;
create function "bookmark_FIXNAME" (in mailname any) returns varchar
{
return
replace (
replace (
replace (
replace (
replace (
replace (
replace (mailname, '/', '_'), '\\', '_'), ':', '_'), '+', '_'), '\"', '_'), '[', '_'), ']', '_'); --"
}
;
create function "bookmark_COMPOSE_XBEL_NAME" (in title varchar, in id integer) returns varchar
{
if (title is null or title = '')
return "bookmark_FIXNAME"(sprintf('%d.xbel', id));
return "bookmark_FIXNAME"(sprintf('%s (%d).xbel', title, id));
}
;
create function "bookmark_ACCESS_PARAMS" (in detcol_id any, out access varchar, out gid integer, out uid integer)
{
declare access_tmp varchar;
whenever not found goto ret;
access := '100000000NN';
gid := http_nogroup_gid ();
uid := http_nobody_uid ();
if (isinteger (detcol_id))
{
select COL_PERMS, COL_GROUP, COL_OWNER into access_tmp, gid, uid from WS.WS.SYS_DAV_COL where COL_ID = detcol_id;
}
access[0] := access_tmp[0];
access[1] := access_tmp[1];
-- access[3] := access_tmp[3];
ret:
;
}
;
--| This matches DAV_AUTHENTICATE (in id any, in what char(1), in req varchar, in a_uname varchar, in a_pwd varchar, in a_uid integer := null)
--| The difference is that the DET function should not check whether the pair of name and password is valid; the auth_uid is not a null already.
create function "bookmark_DAV_AUTHENTICATE" (in id any, in what char(1), in req varchar, in auth_uname varchar, in auth_pwd varchar, in auth_uid integer)
{
--dbg_obj_princ ('bookmark_DAV_AUTHENTICATE (', id, what, req, auth_uname, auth_pwd, auth_uid, http_dav_uid(), ')');
if (auth_uid < 0)
return -12;
if (not ('100' like req))
{
--dbg_obj_princ ('a_uid2 is ', auth_uid, ', id[3] is ', id[2], ' mismatch');
return -13;
}
if ((auth_uid <> id[2]) and (auth_uid <> http_dav_uid()))
{
--dbg_obj_princ ('a_uid is ', auth_uid, ', id[3] is ', id[2], ' mismatch');
return -13;
}
return auth_uid;
}
;
--| This exactly matches DAV_AUTHENTICATE_HTTP (in id any, in what char(1), in req varchar, in can_write_http integer, inout a_lines any, inout a_uname varchar, inout a_pwd varchar, inout a_uid integer, inout a_gid integer, inout _perms varchar) returns integer
--| The function should fully check access because DAV_AUTHENTICATE_HTTP do nothing with auth data either before or after calling this DET function.
--| Unlike DAV_AUTHENTICATE, user name passed to DAV_AUTHENTICATE_HTTP header may not match real DAV user.
--| If DET call is successfull, DAV_AUTHENTICATE_HTTP checks whether the user have read permission on mount point collection.
--| Thus even if DET function allows anonymous access, the whole request may fail if mountpoint is not readable by public.
create function "bookmark_DAV_AUTHENTICATE_HTTP" (in id any, in what char(1), in req varchar, in can_write_http integer, inout a_lines any, inout a_uname varchar, inout a_pwd varchar, inout a_uid integer, inout a_gid integer, inout _perms varchar) returns integer
{
declare rc integer;
declare puid, pgid, ruid, rgid integer;
declare u_password, pperms varchar;
-- anon are never allowed for mails! declare allow_anon integer;
if (length (req) <> 3)
return -15;
whenever not found goto nf_col_or_res;
if ((what <> 'R') and (what <> 'C'))
return -14;
-- allow_anon := WS.WS.PERM_COMP (substring (cast (pperms as varchar), 7, 3), req);
if (a_uid is null)
{
-- if ((not allow_anon) or ('' <> WS.WS.FINDPARAM (a_lines, 'Authorization:')))
rc := WS.WS.GET_DAV_AUTH (a_lines, 0, can_write_http, a_uname, u_password, a_uid, a_gid, _perms);
if (rc < 0)
return rc;
}
if (isinteger (a_uid))
{
if (a_uid < 0)
return a_uid;
if (a_uid = 1) -- Anonymous FTP
{
a_uid := http_nobody_uid ();
a_gid := http_nogroup_gid ();
}
}
if ((a_uid <> id[2]) and (a_uid <> http_dav_uid()))
{
-- dbg_obj_princ ('a_uid is ', a_uid, ', id[3] is ', id[3], ' mismatch');
return -13;
}
if (not ('100' like req))
return -13;
return a_uid;
nf_col_or_res:
return -1;
}
;
--| This matches DAV_GET_PARENT (in id any, in st char(1), in path varchar) returns any
create function "bookmark_DAV_GET_PARENT" (in id any, in st char(1), in path varchar) returns any
{
-- dbg_obj_princ ('bookmark_DAV_GET_PARENT (', id, st, path, ')');
return -20;
}
;
--| When DAV_COL_CREATE_INT calls DET function, authentication, check for lock and check for overwrite are passed, uid and gid are translated from strings to IDs.
--| Check for overwrite, but the deletion of previously existing collection should be made by DET function.
create function "bookmark_DAV_COL_CREATE" (in detcol_id any, in path_parts any, in permissions varchar, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_COL_CREATE (', detcol_id, path_parts, permissions, uid, gid, auth_uid, ')');
return -20;
}
;
--| It looks like that this is redundand and should be removed at all.
create function "bookmark_DAV_COL_MOUNT" (in detcol_id any, in path_parts any, in full_mount_path varchar, in mount_det varchar, in permissions varchar, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_COL_MOUNT (', detcol_id, path_parts, full_mount_path, mount_det, permissions, uid, gid, auth_uid, ')');
return -20;
}
;
--| It looks like that this is redundand and should be removed at all.
create function "bookmark_DAV_COL_MOUNT_HERE" (in parent_id any, in full_mount_path varchar, in permissions varchar, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_COL_MOUNT_HERE (', parent_id, full_mount_path, permissions, uid, gid, auth_uid, ')');
return -20;
}
;
--| When DAV_DELETE_INT calls DET function, authentication and check for lock are passed.
create function "bookmark_DAV_DELETE" (in detcol_id any, in path_parts any, in what char(1), in silent integer, in auth_uid integer) returns integer
{
-- dbg_obj_princ ('bookmark_DAV_DELETE (', detcol_id, path_parts, what, silent, auth_uid, ')');
return -20;
}
;
--| When DAV_RES_UPLOAD_STRSES_INT calls DET function, authentication and check for locks are performed before the call.
--| There's a special problem, known as 'Transaction deadlock after reading from HTTP session'.
--| The DET function should do only one INSERT of the 'content' into the table and do it as late as possible.
--| The function should return -29 if deadlocked or otherwise broken after reading blob from HTTP.
create function "bookmark_DAV_RES_UPLOAD" (in detcol_id any, in path_parts any, inout content any, in type varchar, in permissions varchar, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_RES_UPLOAD (', detcol_id, path_parts, ', [content], ', content, type, permissions, uid, gid, auth_uid, ')');
return -20;
}
;
--| When DAV_PROP_REMOVE_INT calls DET function, authentication and check for locks are performed before the call.
--| The check whether it's a system name or not is _not_ permitted.
create function "bookmark_DAV_PROP_REMOVE" (in id any, in what char(0), in propname varchar, in silent integer, in auth_uid integer) returns integer
{
-- dbg_obj_princ ('bookmark_DAV_PROP_REMOVE (', id, what, propname, silent, auth_uid, ')');
return -20;
}
;
--| When DAV_PROP_SET_INT calls DET function, authentication and check for locks are performed before the call.
--| The check whether it's a system property or not is _not_ permitted and the function should return -16 for live system properties.
create function "bookmark_DAV_PROP_SET" (in id any, in what char(0), in propname varchar, in propvalue any, in overwrite integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_PROP_SET (', id, what, propname, propvalue, overwrite, auth_uid, ')');
if (propname[0] = 58)
{
return -16;
}
return -20;
}
;
--| When DAV_PROP_GET_INT calls DET function, authentication and check whether it's a system property are performed before the call.
create function "bookmark_DAV_PROP_GET" (in id any, in what char(0), in propname varchar, in auth_uid integer)
{
-- dbg_obj_princ ('bookmark_DAV_PROP_GET (', id, what, propname, auth_uid, ')');
return -11;
}
;
--| When DAV_PROP_LIST_INT calls DET function, authentication is performed before the call.
--| The returned list should contain only user properties.
create function "bookmark_DAV_PROP_LIST" (in id any, in what char(0), in propmask varchar, in auth_uid integer)
{
-- dbg_obj_princ ('bookmark_DAV_PROP_LIST (', id, what, propmask, auth_uid, ')');
return vector ();
}
;
--| When DAV_PROP_GET_INT or DAV_DIR_LIST_INT calls DET function, authentication is performed before the call.
create function "bookmark_DAV_DIR_SINGLE" (in id any, in what char(0), in path any, in auth_uid integer) returns any
{
declare sub_id, folder_id, domain_id integer;
declare colname, fullpath, rightcol, tag_id varchar;
declare maxrcvdate datetime;
--dbg_obj_princ ('bookmark_DAV_DIR_SINGLE (', id, what, path, auth_uid, ')');
sub_id := id[3];
domain_id := id[4];
folder_id := id[5];
tag_id := id[7];
fullpath := '';
rightcol := '';
if (folder_id <> 0)
{
if (sub_id = 1)
{
while (folder_id <> 0)
{
colname := (select "bookmark_FIXNAME" (F_NAME)
from BMK.WA.FOLDER
where F_DOMAIN_ID = domain_id and F_ID = folder_id);
if (DAV_HIDE_ERROR (colname) is null)
return -1;
if (rightcol = '')
rightcol := colname;
fullpath := colname || '/' || fullpath;
folder_id := coalesce((select F_PARENT_ID from BMK.WA.FOLDER where F_ID = folder_id), 0);
}
}
else if (sub_id = 2)
{
if (maxrcvdate is null)
maxrcvdate := coalesce ( (select max(BD_LAST_UPDATE) from BMK.WA.BOOKMARK_DOMAIN where year(BD_LAST_UPDATE) = domain_id),
cast ('1980-01-01' as datetime));
colname := (select monthname(D.BD_LAST_UPDATE)
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = id[2]
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and month(D.BD_LAST_UPDATE) = folder_id
and year(D.BD_LAST_UPDATE) = domain_id);
if (DAV_HIDE_ERROR (colname) is null)
return -1;
if (rightcol = '')
rightcol := colname;
fullpath := colname || '/' || fullpath;
}
}
if (domain_id <> 0)
{
if (sub_id = 1)
{
if (maxrcvdate is null)
maxrcvdate := coalesce ( (select max(BD_LAST_UPDATE) from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id),
cast ('1980-01-01' as datetime));
colname := (select "bookmark_FIXNAME"(C.WAI_NAME) as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = id[2]
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and C.WAI_ID = domain_id);
}
else if (sub_id = 2)
{
if (maxrcvdate is null)
maxrcvdate := coalesce ( (select max(BD_LAST_UPDATE) from BMK.WA.BOOKMARK_DOMAIN where year(BD_LAST_UPDATE) = domain_id),
cast ('1980-01-01' as datetime));
colname := (select cast(year(D.BD_LAST_UPDATE) as varchar)
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = id[2]
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and year(D.BD_LAST_UPDATE) = domain_id);
}
}
if (tag_id is not null)
{
if (sub_id = 3)
{
if (maxrcvdate is null)
maxrcvdate := coalesce ( (select max(T_LAST_UPDATE) from BMK.WA.TAGS where T_TAG = tag_id), cast ('1980-01-01' as datetime));
colname := (select T_TAG
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.TAGS T
where A.U_ID = id[2]
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and T.T_DOMAIN_ID = C.WAI_ID
and T.T_TAG = tag_id);
}
if (DAV_HIDE_ERROR (colname) is null)
return -1;
if (rightcol = '')
rightcol := colname;
fullpath := colname || '/' || fullpath;
}
if (sub_id <> 0)
{
if (sub_id = 1)
colname := 'bookmark';
else if (sub_id = 2)
colname := 'date';
else if (sub_id = 3)
colname := 'tags';
else
colname := 'bookmark';
if (DAV_HIDE_ERROR (colname) is null)
return -1;
if (rightcol = '')
rightcol := colname;
fullpath := colname || '/' || fullpath;
}
fullpath := DAV_CONCAT_PATH (DAV_SEARCH_PATH (id[1], 'C'), fullpath);
if ('C' = what)
{
if (id[6] >= 0)
return -1;
return vector (fullpath, 'C', 0, maxrcvdate, id, '100000000NN',
0, id[2], maxrcvdate, 'dav/unix-directory', rightcol );
}
for select "bookmark_COMPOSE_XBEL_NAME"(BD_NAME, BD_ID) as orig_mname,
BD_ID as m_id, BD_LAST_UPDATE
from BMK.WA.BOOKMARK_DOMAIN
where BD_ID = id[6]
do
{
return vector (fullpath || orig_mname, 'R', 1024, BD_LAST_UPDATE, id, '100000000NN',
0, id[2], BD_LAST_UPDATE, 'application/xbel+xml', orig_mname);
}
return -1;
}
;
--| When DAV_PROP_GET_INT or DAV_DIR_LIST_INT calls DET function, authentication is performed before the call.
create function "bookmark_DAV_DIR_LIST" (in detcol_id any, in path_parts any, in detcol_path varchar, in name_mask varchar, in recursive integer, in auth_uid integer) returns any
{
--dbg_obj_princ ('bookmark_DAV_DIR_LIST (', detcol_id, path_parts, detcol_path, name_mask, recursive, auth_uid, ')');
declare sub_id, folder_id, domain_id, ownergid, owner_uid integer;
declare top_davpath, access varchar;
declare res, grand_res any;
declare top_id, descnames any;
declare what char (1);
"bookmark_ACCESS_PARAMS" (detcol_id, access, ownergid, owner_uid);
if ((0 = length (path_parts)) or ('' = path_parts[length (path_parts) - 1]))
what := 'C';
else
what := 'R';
sub_id := 0;
domain_id := 0;
folder_id := 0;
grand_res := vector();
if ('C' = what and 1 = length(path_parts))
top_id := vector (UNAME'bookmark', detcol_id, owner_uid, 0, 0, 0, -1, null); -- may be a fake id because top_id[4] may be NULL
else
top_id := "bookmark_DAV_SEARCH_ID_IMPL" (detcol_id, path_parts, what, sub_id, owner_uid, domain_id, folder_id);
if (DAV_HIDE_ERROR (top_id) is null)
return vector();
top_davpath := DAV_CONCAT_PATH (detcol_path, path_parts);
if ('R' = what)
return vector ("bookmark_DAV_DIR_SINGLE" (top_id, what, top_davpath, auth_uid));
res := vector();
if ('C' = what)
{
if (top_id[3] = 0) -- top level
{
declare subs any;
declare cur varchar;
declare i integer;
i := 0;
subs := vector('bookmark', 'date', 'tags');
for (i := 0; i < 3; i := i + 1)
{
cur := cast(subs[i] as varchar);
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, cur) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, null, null, null, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', cur) ) );
}
return res;
}
if (top_id[3] = 1 and top_id[4] = 0) -- level of bookmarks, list of Bookmark instances
{
for select "bookmark_FIXNAME"(C.WAI_NAME) as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_name) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
return res;
}
if (top_id[3] = 2 and top_id[4] = 0) -- level of dates
{
for select distinct cast(year(D.BD_LAST_UPDATE) as varchar) as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_name) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
return res;
}
if (top_id[3] = 3 and top_id[4] = 0 and top_id[7] is null) -- level of tags, lists of keywords
{
for select distinct T_TAG as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.TAGS D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.T_DOMAIN_ID = C.WAI_ID
and T_TAG <> ''
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_name) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
return res;
}
if (top_id[3] = 2 and top_id[4] <> 0 and top_id[5] = 0) -- level of dates/years
{
for select distinct monthname(D.BD_LAST_UPDATE) as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and year(D.BD_LAST_UPDATE) = top_id[4]
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_name) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
}
if (top_id[3] = 1 and top_id[4] <> 0 and top_id[5] = 0) -- level of bookmaark instance, list of bookmark folders
{
for select F_ID, "bookmark_FIXNAME" (F_NAME) as orig_name
from BMK.WA.FOLDER
where F_DOMAIN_ID = top_id[4] and F_PARENT_ID = coalesce(top_id[5], 0)
order by 1, 2
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_name) || '/', 'C', 0, now(),
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], top_id[4], F_ID, -1, null),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
}
grand_res := res;
}
res := vector();
if (top_id[3] = 1)
{
for select "bookmark_COMPOSE_XBEL_NAME"(BD_NAME, BD_ID) as orig_mname, BD_ID as m_id, BD_LAST_UPDATE
from BMK.WA.BOOKMARK_DOMAIN
where BD_DOMAIN_ID = top_id[4] and
((BD_FOLDER_ID = top_id[5] and top_id[5] <> 0) or (BD_FOLDER_ID is null and top_id[5] = 0))
order by 1, 2
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_mname), 'R', 1024, BD_LAST_UPDATE,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], top_id[4], top_id[5], m_id, null),
'100000000NN', ownergid, owner_uid, BD_LAST_UPDATE, 'application/xbel+xml', orig_mname) ) );
}
}
else if (top_id[3] = 2)
{
for select distinct "bookmark_COMPOSE_XBEL_NAME"(BD_NAME, BD_ID) as orig_mname, BD_ID as m_id, BD_LAST_UPDATE
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and year(D.BD_LAST_UPDATE) = top_id[4] and month(D.BD_LAST_UPDATE) = top_id[5]
order by 1, 2
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_mname), 'R', 1024, BD_LAST_UPDATE,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], top_id[4], top_id[5], m_id, null),
'100000000NN', ownergid, owner_uid, BD_LAST_UPDATE, 'application/xbel+xml', orig_mname) ) );
}
}
else if (top_id[3] = 3)
{
for select distinct "bookmark_COMPOSE_XBEL_NAME"(D.BD_NAME, D.BD_ID) as orig_mname, D.BD_ID as m_id, D.BD_LAST_UPDATE, G.BD_TAGS as tags
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D,
BMK.WA.BOOKMARK_DATA G
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and D.BD_BOOKMARK_ID = G.BD_BOOKMARK_ID
and G.BD_TAGS is not null and G.BD_TAGS <> ''
order by 1, 2
do
{
declare tags2 any;
tags2 := split_and_decode (tags, 0, '\0\0,');
foreach (any tag in tags2) do
{
tag := trim(tag);
if (top_id[7] = tag)
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_mname), 'R', 1024, BD_LAST_UPDATE,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, m_id, tag),
'100000000NN', ownergid, owner_uid, BD_LAST_UPDATE, 'application/xbel+xml', orig_mname)));
}
}
}
}
grand_res := vector_concat (grand_res, res);
finalize_res:
return grand_res;
}
;
create procedure "bookmark_DAV_FC_PRED_METAS" (inout pred_metas any)
{
pred_metas := vector(
'BD_ID', vector ('BOOKMARK_DOMAIN' , 0, 'integer', 'BD_ID' ),
'BD_DOMAIN_ID', vector ('BOOKMARK_DOMAIN' , 0, 'integer', 'BD_DOMAIN_ID' ),
'BD_BOOKMARK_ID', vector ('BOOKMARK_DOMAIN' , 0, 'integer', 'BD_BOOKMARK_ID' ),
'BD_FOLDER_ID', vector ('BOOKMARK_DOMAIN' , 0, 'integer' , 'BD_FOLDER_ID' ),
'RES_NAME', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , '"bookmark_COMPOSE_XBEL_NAME" (_top.BD_NAME, _top.BD_ID)' ),
'RES_FULL_PATH', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , 'concat (DAV_CONCAT_PATH (_param.detcolpath, ''bookmark''), "bookmark_FIXNAME" (WAI_NAME), ''/'', "bookmark_COMPOSE_XBEL_NAME" (_top.BD_NAME, _top.BD_ID)' ),
'RES_TYPE', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , '(''application/xbel+xml'')' ),
'RES_OWNER_ID', vector ('SYS_USERS' , 0, 'integer' , 'U_ID' ),
'RES_OWNER_NAME', vector ('SYS_USERS' , 0, 'varchar' , 'U_NAME' ),
'RES_GROUP_ID', vector ('SYS_USERS' , 0, 'integer' , 'http_nogroup_gid()' ),
'RES_GROUP_NAME', vector ('SYS_USERS' , 0, 'varchar' , '(''nogroup'')' ),
'RES_COL_FULL_PATH', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , 'concat (DAV_CONCAT_PATH (_param.detcolpath, ''bookmark''), "bookmark_FIXNAME" (WAI_NAME), ''/'')' ),
'RES_COL_NAME', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , '"bookmark_FIXNAME" (WAI_NAME)' ),
'RES_CR_TIME', vector ('BOOKMARK_DOMAIN' , 0, 'datetime' , 'BD_LAST_UPDATE' ),
'RES_MOD_TIME', vector ('BOOKMARK_DOMAIN' , 0, 'datetime' , 'BD_LAST_UPDATE' ),
'RES_PERMS', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , '(''110000000RR'')' ),
'RES_CONTENT', vector ('BOOKMARK_DOMAIN' , 0, 'text' , 'BD_DESCRIPTION' ),
'PROP_NAME', vector ('BOOKMARK_DOMAIN' , 0, 'varchar' , '(''BD_DESCRIPTION'')' ),
'PROP_VALUE', vector ('SYS_DAV_PROP' , 1, 'text' , 'BD_DESCRIPTION' ),
'RES_TAGS', vector ('all-tags' , 0, 'varchar' , 'BD_TAGS' ), -- 'varchar', not 'text-tag' because there's no free-text on union
'RES_PUBLIC_TAGS', vector ('public-tags' , 0, 'varchar' , 'BD_TAGS' ), -- 'varchar', not 'text-tag' because there's no free-text in table!
'RES_PRIVATE_TAGS', vector ('private-tags' , 0, 'varchar' , 'BD_TAGS' ), -- 'varchar', not 'text-tag' because there's no free-text in table!
'RDF_PROP', vector ('fake-prop' , 1, 'varchar' , NULL ),
'RDF_VALUE', vector ('fake-prop' , 2, 'XML' , NULL ),
'RDF_OBJ_VALUE', vector ('fake-prop' , 3, 'XML' , NULL )
);
}
;
create procedure "bookmark_DAV_FC_TABLE_METAS" (inout table_metas any)
{
table_metas := vector (
'BOOKMARK_DOMAIN' , vector ( '' ,
'' ,
'BD_NAME' , 'BD_NAME' , '[__quiet] /' ),
'WA_INSTANCE' , vector ( '' ,
'' ,
'WAI_NAME' , 'WAI_NAME' , '[__quiet] /' ),
'WA_MEMBER' , vector ( '' ,
'' ,
'WAM_INST' , 'WAM_INST' , '[__quiet] /' ),
'SYS_USERS' , vector ( '' ,
'' ,
NULL , NULL , NULL ),
'public-tags' , vector ( '\n inner join BMK.WA.BOOKMARK_DATA as ^{alias}^ on ((^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (^{alias}^.BD_MODE = 0)^{andpredicates}^)' ,
'\n exists (select 1 from BMK.WA.BOOKMARK_DATA as ^{alias}^ where (^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (^{alias}^.BD_MODE = 0)^{andpredicates}^)' ,
'BD_TAGS' , 'BD_TAGS' , NULL ),
'private-tags' , vector ( '\n inner join BMK.WA.BOOKMARK_DATA as ^{alias}^ on ((^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (^{alias}^.BD_MODE = 1) and (^{alias}^.BD_OBJECT_ID = ^{uid}^)^{andpredicates}^)' ,
'\n exists (select 1 from BMK.WA.BOOKMARK_DATA as ^{alias}^ where (^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (^{alias}^.BD_MODE = 1) and (^{alias}^.BD_OBJECT_ID = ^{uid}^)^{andpredicates}^)' ,
'BD_TAGS' , 'BD_TAGS' , NULL ),
'all-tags' , vector ( '\n inner join BMK.WA.BOOKMARK_DATA as ^{alias}^ on ((^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (((^{alias}^.BD_MODE = 1) and (^{alias}^.BD_OBJECT_ID = ^{uid}^)) or (^{alias}^.BD_MODE = 0))^{andpredicates}^)' ,
'\n exists (select 1 from BMK.WA.BOOKMARK_DATA as ^{alias}^ where (^{alias}^.BD_BOOKMARK_ID = _top.BD_BOOKMARK_ID) and (((^{alias}^.BD_MODE = 1) and (^{alias}^.BD_OBJECT_ID = ^{uid}^)) or (^{alias}^.BD_MODE = 0))^{andpredicates}^)' ,
'BD_TAGS' , 'BD_TAGS' , NULL ),
'fake-prop' , vector ( '\n inner join WS.WS.SYS_DAV_PROP as ^{alias}^ on ((^{alias}^.PROP_PARENT_ID is null) and (^{alias}^.PROP_TYPE = ''R'')^{andpredicates}^)' ,
'\n exists (select 1 from WS.WS.SYS_DAV_PROP as ^{alias}^ where (^{alias}^.PROP_PARENT_ID is null) and (^{alias}^.PROP_TYPE = ''R'')^{andpredicates}^)' ,
'PROP_VALUE' , 'PROP_VALUE' , '[__quiet __davprop xmlns:virt="virt"] fakepropthatprobablyneverexists' )
);
}
;
create function "bookmark_DAV_FC_PRINT_WHERE" (inout filter any, in param_uid integer) returns varchar
{
declare pred_metas, cmp_metas, table_metas any;
declare used_tables any;
-- dbg_obj_princ ('Blog_POST_DAV_FC_PRINT_WHERE (', filter, param_uid, ')');
"bookmark_DAV_FC_PRED_METAS" (pred_metas);
DAV_FC_CMP_METAS (cmp_metas);
"bookmark_DAV_FC_TABLE_METAS" (table_metas);
used_tables := vector(
'BOOKMARK_DOMAIN', vector ('BOOKMARK_DOMAIN', '_top', null, vector (), vector (), vector ()),
'WA_INSTANCE', vector ('WA_INSTANCE', '_instances', null, vector (), vector (), vector ()),
'WA_MEMBER', vector ('WA_MEMBER', '_members', null, vector (), vector (), vector ()),
'SYS_USERS', vector ('SYS_USERS', '_users', null, vector (), vector (), vector ())
);
return DAV_FC_PRINT_WHERE_INT (filter, pred_metas, cmp_metas, table_metas, used_tables, param_uid);
}
;
--| When DAV_DIR_FILTER_INT calls DET function, authentication is performed before the call and compilation is initialized.
create function "bookmark_DAV_DIR_FILTER" (in detcol_id any, in path_parts any, in detcol_path any, inout compilation any, in recursive integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_DIR_FILTER (', detcol_id, path_parts, detcol_path, compilation, recursive, auth_uid, ')');
declare st, access, qry_text, execstate, execmessage varchar;
declare res any;
declare cond_list, execmeta, execrows any;
declare sub, post_id, condtext, cond_key varchar;
declare ownergid, owner_uid, domain_id integer;
"bookmark_ACCESS_PARAMS" (detcol_id, access, ownergid, owner_uid);
vectorbld_init (res);
sub := null;
post_id := null;
if (((length (path_parts) <= 1) and (recursive <> 1)) or (length (path_parts) > 2))
{
-- dbg_obj_princ ('\r\nGoto skip_post_level\r\n');
goto finalize;
}
if (length (path_parts) >= 2)
{
sub := path_parts[0];
if (sub = 'bookmark')
{
domain_id := coalesce ((select C.WAI_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and "bookmark_FIXNAME"(C.WAI_NAME) = path_parts[1]));
if (domain_id is null)
goto finalize;
}
else
goto finalize;
}
cond_key := sprintf ('Bookmark&%d', coalesce (domain_id, 0));
condtext := get_keyword (cond_key, compilation);
if (condtext is null)
{
cond_list := get_keyword ('', compilation);
if (sub is not null)
cond_list := vector_concat (cond_list, vector ( vector ('BD_DOMAIN_ID', '=', domain_id)));
condtext := "bookmark_DAV_FC_PRINT_WHERE" (cond_list, auth_uid);
compilation := vector_concat (compilation, vector (cond_key, condtext));
}
execstate := '00000';
qry_text := 'select concat (DAV_CONCAT_PATH (_param.detcolpath, ''bookmark''), ''/'', "bookmark_FIXNAME" (WAI_NAME), ''/'', "bookmark_COMPOSE_XBEL_NAME" (_top.BD_NAME, _top.BD_ID)),
''R'', 1024, _top.BD_LAST_UPDATE,
vector (UNAME_BOOKMARK(), ?, _users.U_ID, 3, _top.BD_DOMAIN_ID, _top.BD_FOLDER_ID, null, null),
''110000000RR'', http_nogroup_gid(), _users.U_ID, _top.BD_LAST_UPDATE, ''application/xbel+xml'', "bookmark_COMPOSE_XBEL_NAME" (_top.BD_NAME, _top.BD_ID)
from
(select top 1 ? as detcolpath from WS.WS.SYS_DAV_COL) as _param,
BMK.WA.BOOKMARK_DOMAIN as _top
join DB.DBA.WA_INSTANCE as _instances on (WAI_ID = BD_DOMAIN_ID and WAI_TYPE_NAME = ''Bookmark'')
join DB.DBA.WA_MEMBER as _members on (WAM_MEMBER_TYPE = 1 and WAM_INST = WAI_NAME)
join DB.DBA.SYS_USERS as _users on (WAM_USER = U_ID and U_ID = ?)
' || condtext;
exec (qry_text, execstate, execmessage,
vector (detcol_id, detcol_path, owner_uid),
100000000, execmeta, execrows );
if ('00000' <> execstate)
signal (execstate, execmessage || ' in ' || qry_text);
vectorbld_concat_acc (res, execrows);
finalize:
vectorbld_final (res);
return res;
}
;
create function UNAME_BOOKMARK() returns any
{
return UNAME'Bookmark';
}
;
create function "bookmark_DAV_SEARCH_ID_IMPL" (in detcol_id any, in path_parts any, in what char(1), inout sub_id integer, inout muser_id integer, inout domain_id integer, inout folder_id integer) returns any
{
--dbg_obj_princ ('bookmark_DAV_SEARCH_ID_IMPL (', detcol_id, path_parts, what, sub_id, muser_id, domain_id, folder_id, ')');
declare ownergid, owner_uid, ctr, len integer;
declare hitlist any;
declare access, colpath, tag_id, sub varchar;
tag_id := null;
"bookmark_ACCESS_PARAMS" (detcol_id, access, ownergid, owner_uid);
if (0 = length(path_parts))
{
if ('C' <> what)
return -1;
return vector (UNAME'bookmark', detcol_id, owner_uid, sub_id, domain_id, folder_id, -1, null);
}
if ('' = path_parts[length(path_parts) - 1])
{
if ('C' <> what)
return -1;
}
else
{
if ('R' <> what)
return -1;
}
len := length (path_parts) - 1;
ctr := 0;
sub := trim(cast(path_parts[0] as varchar));
while (ctr < len)
{
if (ctr = 0)
{
if (equ(sub, 'date'))
sub_id := 2;
else if (equ(sub, 'bookmark'))
sub_id := 1;
else if (equ(sub, 'tags'))
sub_id := 3;
else
sub_id := 1;
}
else if (ctr = 1)
{
hitlist := vector ();
if (sub_id = 1)
{
for select C.WAI_ID as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and "bookmark_FIXNAME"(C.WAI_NAME) = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
}
else if (sub_id = 2)
{
for select distinct year(D.BD_LAST_UPDATE) as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and year(D.BD_LAST_UPDATE) = atoi(path_parts[ctr])
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
}
else if (sub_id = 3)
{
for select distinct D.T_TAG as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.TAGS D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.T_DOMAIN_ID = C.WAI_ID
and D.T_TAG = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
if (length (hitlist) <> 1)
return -1;
tag_id := hitlist[0];
}
if (sub_id <> 3)
{
if (length (hitlist) <> 1)
return -1;
domain_id := hitlist[0];
}
}
else
{
if (sub_id <> 3)
{
hitlist := vector();
if (sub_id = 1)
{
for select F_ID
from BMK.WA.FOLDER
where "bookmark_FIXNAME"(F_NAME) = path_parts[ctr] and
F_DOMAIN_ID = domain_id and
((F_PARENT_ID = folder_id and folder_id <> 0) or (F_PARENT_ID = 0 and folder_id = 0))
do
{
hitlist := vector_concat (hitlist, vector (F_ID));
}
}
else if (sub_id = 2)
{
for select distinct month(D.BD_LAST_UPDATE) as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and monthname(D.BD_LAST_UPDATE) = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
}
if (length (hitlist) <> 1)
return -1;
folder_id := hitlist[0];
}
else
return -1;
}
ctr := ctr + 1;
}
if ('C' = what)
return vector (UNAME'bookmark', detcol_id, owner_uid, sub_id, domain_id, folder_id, -1, tag_id);
hitlist := vector ();
if (sub_id = 1)
{
for select distinct BD_ID
from BMK.WA.BOOKMARK_DOMAIN
where ((BD_FOLDER_ID = folder_id and folder_id <> 0) or (folder_id = 0 and BD_FOLDER_ID is null))and
"bookmark_COMPOSE_XBEL_NAME" (BD_NAME, BD_ID) = path_parts[ctr] and
BD_DOMAIN_ID = domain_id
do
{
hitlist := vector_concat (hitlist, vector (BD_ID));
}
}
else if (sub_id = 2)
{
for select distinct D.BD_ID as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and month(D.BD_LAST_UPDATE) = folder_id
and year(D.BD_LAST_UPDATE) = domain_id
and "bookmark_COMPOSE_XBEL_NAME" (D.BD_NAME, D.BD_ID) = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
}
else if (sub_id = 3)
{
for select distinct D.BD_ID as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.BOOKMARK_DOMAIN D
where A.U_ID = owner_uid
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_TYPE_NAME = 'Bookmark'
and D.BD_DOMAIN_ID = C.WAI_ID
and "bookmark_COMPOSE_XBEL_NAME" (D.BD_NAME, D.BD_ID) = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
}
if (length (hitlist) <> 1)
return -1;
return vector (UNAME'bookmark', detcol_id, owner_uid, sub_id, domain_id, folder_id, hitlist[0], tag_id);
}
;
--| When DAV_PROP_GET_INT or DAV_DIR_LIST_INT calls DET function, authentication is performed before the call.
create function "bookmark_DAV_SEARCH_ID" (in detcol_id any, in path_parts any, in what char(1)) returns any
{
declare sub_id, u_id, folder_id, domain_id integer;
--dbg_obj_princ ('bookmark_DAV_SEARCH_ID (', detcol_id, path_parts, what, ')');
return "bookmark_DAV_SEARCH_ID_IMPL" (detcol_id, path_parts, what, sub_id, u_id, domain_id, folder_id);
}
;
--| When DAV_SEARCH_PATH_INT calls DET function, authentication is performed before the call.
create function "bookmark_DAV_SEARCH_PATH" (in id any, in what char(1)) returns any
{
--dbg_obj_princ ('bookmark_DAV_SEARCH_PATH (', id, what, ')');
return NULL;
}
;
--| When DAV_COPY_INT calls DET function, authentication and check for locks are performed before the call, but no check for existing/overwrite.
create function "bookmark_DAV_RES_UPLOAD_COPY" (in detcol_id any, in path_parts any, in source_id any, in what char(1), in overwrite_flags integer, in permissions varchar, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_RES_UPLOAD_COPY (', detcol_id, path_parts, source_id, what, overwrite_flags, permissions, uid, gid, auth_uid, ')');
return -20;
}
;
--| When DAV_COPY_INT calls DET function, authentication and check for locks are performed before the call, but no check for existing/overwrite.
create function "bookmark_DAV_RES_UPLOAD_MOVE" (in detcol_id any, in path_parts any, in source_id any, in what char(1), in overwrite_flags integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_RES_UPLOAD_MOVE (', detcol_id, path_parts, source_id, what, overwrite_flags, auth_uid, ')');
return -20;
}
;
--| When DAV_RES_CONTENT or DAV_RES_COPY_INT or DAV_RES_MOVE_INT calls DET function, authentication is made.
--| If content_mode is 1 then content is a valid output stream before the call.
create function "bookmark_DAV_RES_CONTENT" (in id any, inout content any, out type varchar, in content_mode integer) returns integer
{
--dbg_obj_princ ('bookmark_DAV_RES_CONTENT (', id, ', [content], [type], ', content_mode, ')');
whenever not found goto endline;
if (id[6] is not null)
{
declare link, title, last_date varchar;
if (id[3] = 1)
{
select D.BD_NAME, cast(D.BD_LAST_UPDATE as varchar), B.B_URI into title, last_date, link
from BMK.WA.BOOKMARK_DOMAIN D, BMK.WA.BOOKMARK B
where D.BD_DOMAIN_ID = id[4] and
((D.BD_FOLDER_ID = id[5] and id[5] <> 0) or (D.BD_FOLDER_ID is null and id[5] = 0)) and
D.BD_ID = id[6] and
B.B_ID = D.BD_BOOKMARK_ID;
}
else if (id[3] = 2 or id[3] = 3)
{
select D.BD_NAME, cast(D.BD_LAST_UPDATE as varchar), B.B_URI into title, last_date, link
from BMK.WA.BOOKMARK_DOMAIN D,
BMK.WA.BOOKMARK B
where D.BD_ID = id[6] and B.B_ID = D.BD_BOOKMARK_ID;
}
type := 'application/xbel+xml';
content := '\n';
content := concat(content, '\n');
content := concat(content, '\n');
content := concat(content, sprintf(' \n', link));
content := concat(content, sprintf(' %s\n', title));
content := concat(content, ' \n');
content := concat(content, '\n');
}
endline:
return 0;
}
;
--| This adds an extra access path to the existing resource or collection.
create function "bookmark_DAV_SYMLINK" (in detcol_id any, in path_parts any, in source_id any, in what char(1), in overwrite integer, in uid integer, in gid integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_SYMLINK (', detcol_id, path_parts, source_id, overwrite, uid, gid, auth_uid, ')');
return -20;
}
;
--| This gets a list of resources and/or collections as it is returned by DAV_DIR_LIST and and writes the list of quads (old_id, 'what', old_full_path, dereferenced_id, dereferenced_full_path).
create function "bookmark_DAV_DEREFERENCE_LIST" (in detcol_id any, inout report_array any) returns any
{
-- dbg_obj_princ ('bookmark_DAV_DEREFERENCE_LIST (', detcol_id, report_array, ')');
return -20;
}
;
--| This gets one of reference quads returned by ..._DAV_REREFERENCE_LIST() and returns a record (new_full_path, new_dereferenced_full_path, name_may_vary).
create function "bookmark_DAV_RESOLVE_PATH" (in detcol_id any, inout reference_item any, inout old_base varchar, inout new_base varchar) returns any
{
-- dbg_obj_princ ('bookmark_DAV_RESOLVE_PATH (', detcol_id, reference_item, old_base, new_base, ')');
return -20;
}
;
--| There's no API function to lock for a while (do we need such?) The "LOCK" DAV method checks that all parameters are valid but does not check for existing locks.
create function "bookmark_DAV_LOCK" (in path any, in id any, in type char(1), inout locktype varchar, inout scope varchar, in token varchar, inout owner_name varchar, inout owned_tokens varchar, in depth varchar, in timeout_sec integer, in auth_uid integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_LOCK (', id, type, locktype, scope, token, owner_name, owned_tokens, depth, timeout_sec, owner_name, auth_uid, ')');
return -20;
}
;
--| There's no API function to unlock for a while (do we need such?) The "UNLOCK" DAV method checks that all parameters are valid but does not check for existing locks.
create function "bookmark_DAV_UNLOCK" (in id any, in type char(1), in token varchar, in auth_uid integer)
{
-- dbg_obj_princ ('bookmark_DAV_UNLOCK (', id, type, token, auth_uid, ')');
return -27;
}
;
--| The caller does not check if id is valid.
--| This returns -1 if id is not valid, 0 if all existing locks are listed in owned_tokens whitespace-delimited list, 1 for soft 2 for hard lock.
create function "bookmark_DAV_IS_LOCKED" (inout id any, inout type char(1), in owned_tokens varchar) returns integer
{
-- dbg_obj_princ ('bookmark_DAV_IS_LOCKED (', id, type, owned_tokens, ')');
return 0;
}
;
--| The caller does not check if id is valid.
--| This returns -1 if id is not valid, list of tuples (LOCK_TYPE, LOCK_SCOPE, LOCK_TOKEN, LOCK_TIMEOUT, LOCK_OWNER, LOCK_OWNER_INFO) otherwise.
create function "bookmark_DAV_LIST_LOCKS" (in id any, in type char(1), in recursive integer) returns any
{
-- dbg_obj_princ ('bookmark_DAV_LIST_LOCKS" (', id, type, recursive);
return vector ();
}
;
¶ bookmark/sql/bmk-a-code.sqlß ÑÛ--
-- $Id: bmk-a-code.sql,v 1.71 2007/04/17 11:37:25 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
-------------------------------------------------------------------------------
--
-- Request Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.validate_request(
inout pLines any,
in pMinVersion integer,
in pType varchar := 'WWW')
{
declare aResult any;
declare S,P,B varchar;
declare V any;
declare i,j,k,l integer;
-- Initialize variables
i := strstr(pLines[0],' '); -- Method/URI dividing space
if (isnull(i)) BMK.WA.http_response(400); -- Bad Request (can't happen!)
l := length(pLines[0]) - 2; -- total length.one for zero-based and one for ending LF!;
k := strrchr(pLines[0],' '); -- URI/Version dividing space ( k <- end of URL)
if (isnull(k) or (k = i)) k := l; -- if no version tag is presented k equals l
j := strstr(pLines[0],'?'); -- search for parameters in URI and ignore them!
if (isnull(j)) j := k; -- if no parameters j equals k (end of URI)
B := subseq(pLines[0],i+1,j); -- Buffer for resource path
-- Initialize result structure;
aResult := vector(subseq(pLines[0],0,i),vector('',''),vector(1,0),vector(),vector('bookmarks','vspx'), -2);
-- Determine host
S := http_request_header(pLines,'Host',null,'');
if (S <> '') {
i := strstr(S,':');
if (isnull(i))
aset(aResult,1,vector(S,''));
else
aset(aResult,1,vector(subseq(S,0,i),subseq(S,i+1)));
}
-- Determine request version
if (k + 1 < l) {
-- Check for version format
S := subseq(pLines[0],k+1,l);
i := strstr(S,'HTTP/');
if (isnull(i) or (i > 0)) BMK.WA.http_response(400); -- Bad Request
i := strstr(S,'.'); if (isnull(i)) BMK.WA.http_response(400); -- Bad Request
aset(aResult,2,vector(atoi(subseq(S,5,i)),atoi(subseq(S,i+1))));
}
if (aResult[2][0] <> 1) BMK.WA.http_response(505); -- HTTP Version Not Supported
if (aResult[2][1] < pMinVersion) BMK.WA.http_response(505); -- HTTP Version Not Supported
if ((pMinVersion > 0) and aResult[1] = '') BMK.WA.http_response(400); -- Host field required for HTTP/1.1
--check "File or Directory";
P := BMK.WA.mount_point();
S := either(equ(P,''),B,subseq(B,length(P))); -- Remove mount point from path
i := length(S) - 1; -- S is now like 'path/file.ext
if (i < 0)
http_redirect2(concat(P,'/'),vector()); -- S = ''. Redirect to '{Mount Point}/'
if (chr(S[i]) = '/')
{
j := i - 1;
while ((j >= 0) and (chr(S[j]) <> '/'))
{
if (chr(S[j]) = '.')
BMK.WA.http_response(404);
j := j - 1;
}
S := concat(S,'bookmarks.vspx');
}
else
{
j := i;
while ((j >= 0) and (chr(S[j]) <> '.'))
{
if (chr(S[j]) = '/')
http_redirect2(concat(P,S,'/'),vector());
j := j - 1;
}
}
-- Verify domain (only digits)
V := split_and_decode(ltrim(P,'/'),0,'\0\0/');
if (length(V) > 1) {
P := aref(V,length(V)-1);
regexp_match('^[0-9]+',P,1);
if (P = '')
aset(aResult,5,cast(aref(V,length(V)-1) as integer));
};
-- Verify path
P := S;
regexp_match('^[a-z_0-9/\.-]+',P,1);
if (P <> '')
BMK.WA.http_response(404);
-- Put path and file into result structure
V := split_and_decode(ltrim(S,'/'),0,'\0\0/');
aset(aResult,4,split_and_decode(V[length(V)-1],0,'\0\0.'));
if (length(V) > 1)
aset(aResult,3,subseq(V,i,Length(V) - 1));
else
aset(aResult,3,vector(''));
-- Return verified request information
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.mount_point(
in pURL varchar := null)
{
declare
sMPoint varchar;
sMPoint := http_map_get('domain');
if (sMPoint = '/')
sMPoint := '';
if (not isnull(pURL))
sMPoint := concat(sMPoint,'/',pURL);
return sMPoint;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.http_response(in pError integer,in pParams varchar := '')
{
signal ('90001', sprintf('%s', pError, BMK.WA.mount_point(), pParams));
}
;
-------------------------------------------------------------------------------
--
-- Session Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.session_restore (
inout request any,
inout params any,
inout lines any)
{
declare domain_id, user_id, user_name, user_role, sid, realm, options any;
declare exit handler for sqlstate '*' {
domain_id := -2;
goto _end;
};
sid := get_keyword('sid', params, '');
realm := get_keyword('realm', params, '');
options := http_map_get('options');
if (not is_empty_or_null(options))
domain_id := get_keyword('domain', options);
if (is_empty_or_null (domain_id))
domain_id := cast(request[5] as integer);
if (not exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = domain_id and domain_id <> -2))
domain_id := -1;
_end:
domain_id := cast(domain_id as integer);
user_id := -1;
for (select U.U_ID,
U.U_NAME,
U.U_FULL_NAME
from DB.DBA.VSPX_SESSION S,
WS.WS.SYS_DAV_USER U
where S.VS_REALM = realm
and S.VS_SID = sid
and S.VS_UID = U.U_NAME) do
{
user_id := U_ID;
user_name := BMK.WA.user_name(U_NAME, U_FULL_NAME);
user_role := BMK.WA.access_role(domain_id, U_ID);
}
if ((user_id = -1) and (domain_id >= 0) and (not exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = domain_id and WAI_IS_PUBLIC = 1)))
domain_id := -1;
if (user_id = -1)
if (domain_id = -1) {
user_role := 'expire';
user_name := 'Expire session';
} else if (domain_id = -2) {
user_role := 'public';
user_name := 'Public User';
} else {
user_role := 'guest';
user_name := 'Guest User';
}
return vector('domain_id', domain_id,
'user_id', user_id,
'user_name', user_name,
'user_role', user_role
);
}
;
-------------------------------------------------------------------------------
--
-- Freeze Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.frozen_check(in domain_id integer)
{
declare exit handler for not found { return 1; };
if (is_empty_or_null((select WAI_IS_FROZEN from DB.DBA.WA_INSTANCE where WAI_ID = domain_id)))
return 0;
declare user_id integer;
user_id := (select U_ID from SYS_USERS where U_NAME = connection_get ('vspx_user'));
if (BMK.WA.check_admin(user_id))
return 0;
user_id := (select U_ID from SYS_USERS where U_NAME = connection_get ('owner_user'));
if (BMK.WA.check_admin(user_id))
return 0;
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.frozen_page(in domain_id integer)
{
return (select WAI_FREEZE_REDIRECT from DB.DBA.WA_INSTANCE where WAI_ID = domain_id);
}
;
-------------------------------------------------------------------------------
--
-- User Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.check_admin(
in user_id integer) returns integer
{
declare group_id integer;
group_id := (select U_GROUP from SYS_USERS where U_ID = user_id);
if (user_id = 0)
return 1;
if (user_id = http_dav_uid ())
return 1;
if (group_id = 0)
return 1;
if (group_id = http_dav_uid ())
return 1;
if(group_id = http_dav_uid()+1)
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.check_grants(in domain_id integer, in user_id integer, in role_name varchar)
{
whenever not found goto _end;
if (BMK.WA.check_admin(user_id))
return 1;
if (role_name is null or role_name = '')
return 0;
if (role_name = 'admin')
return 0;
if (role_name = 'guest') {
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = user_id
and B.WAM_USER = A.U_ID
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 1;
}
if (role_name = 'owner')
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = user_id
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 1;
_end:
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.check_grants2 (in role_name varchar, in page_name varchar)
{
declare tree any;
tree := xml_tree_doc (BMK.WA.menu_tree ());
if (isnull (xpath_eval (sprintf ('//node[(@url = "%s") and contains(@allowed, "%s")]', page_name, role_name), tree, 1)))
return 0;
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.access_role(in domain_id integer, in user_id integer)
{
whenever not found goto _end;
if (BMK.WA.check_admin(user_id))
return 'admin';
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = user_id
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 1
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 'owner';
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = user_id
and B.WAM_USER = A.U_ID
and B.WAM_MEMBER_TYPE = 2
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 'author';
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = user_id
and B.WAM_USER = A.U_ID
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 'reader';
if (exists(select 1
from SYS_USERS A
where A.U_ID = user_id))
return 'guest';
_end:
return 'public';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.wa_home_link ()
{
return case when registry_get ('wa_home_link') = 0 then '/ods/' else registry_get ('wa_home_link') end;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.wa_home_title ()
{
return case when registry_get ('wa_home_title') = 0 then 'ODS Home' else registry_get ('wa_home_title') end;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.page_name ()
{
declare path, url, pageName varchar;
declare aPath any;
path := http_path ();
aPath := split_and_decode (path, 0, '\0\0/');
pageName := aPath [length (aPath) - 1];
if (pageName = 'error.vspx')
return pageName;
url := xpath_eval ('//*[@url = "'|| pageName ||'"]', xml_tree_doc (BMK.WA.menu_tree ()));
if ((url is not null))
return pageName;
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.menu_tree (
in access_role varchar := null)
{
declare S, T varchar;
S :=
'
';
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.navigation_root (
in path varchar)
{
declare domain_id, user_id integer;
declare access_role varchar;
declare aPath any;
aPath := split_and_decode(path,0,'\0\0/');
if (length(aPath) < 2)
return vector();
domain_id := cast(aPath[0] as integer);
user_id := cast(aPath[1] as integer);
access_role := BMK.WA.access_role(domain_id, user_id);
return xpath_eval (sprintf('/menu_tree/*[contains(@allowed, "%s")]', access_role), xml_tree_doc (BMK.WA.menu_tree (access_role)), 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.navigation_child (
in path varchar,
in node any)
{
path := concat (path, '[not @place]');
return xpath_eval (path, node, 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_owner_id (
inout domain_id integer)
{
return (select A.WAM_USER from WA_MEMBER A, WA_INSTANCE B where A.WAM_MEMBER_TYPE = 1 and A.WAM_INST = B.WAI_NAME and B.WAI_ID = domain_id);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_owner_name (
inout domain_id integer)
{
return (select C.U_NAME from WA_MEMBER A, WA_INSTANCE B, SYS_USERS C where A.WAM_MEMBER_TYPE = 1 and A.WAM_INST = B.WAI_NAME and B.WAI_ID = domain_id and C.U_ID = A.WAM_USER);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_gems_create (
inout domain_id integer,
inout account_id integer)
{
declare read_perm, exec_perm, content, home, path varchar;
home := BMK.WA.dav_home(account_id);
if (isnull(home))
return;
read_perm := '110100100N';
exec_perm := '111101101N';
home := home || 'BM/';
DB.DBA.DAV_MAKE_DIR (home, account_id, null, read_perm);
--path := home || 'channels/';
--DB.DBA.DAV_MAKE_DIR (path, account_id, null, read_perm);
--update WS.WS.SYS_DAV_COL set COL_DET = 'News3' where COL_ID = DAV_SEARCH_ID (path, 'C');
home := home || BMK.WA.domain_gems_name(domain_id) || '/';
DB.DBA.DAV_MAKE_DIR (home, account_id, null, read_perm);
-- RSS 2.0
path := home || 'BM.rss';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_rss_sqlx (domain_id, account_id);
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (path, content, 'text/xml', exec_perm, http_dav_uid (), http_dav_uid () + 1, null, null, 0);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-template', 'execute', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-encoding', 'utf-8', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-description', 'RSS based XML document generated by OpenLink Feed Manager', 'dav', null, 0, 0, 1);
-- ATOM
path := home || 'BM.atom';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_atom_sqlx (domain_id, account_id);
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (path, content, 'text/xml', exec_perm, http_dav_uid (), http_dav_uid () + 1, null, null, 0);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-template', 'execute', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-encoding', 'utf-8', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-description', 'ATOM based XML document generated by OpenLink Feed Manager', 'dav', null, 0, 0, 1);
-- RDF
path := home || 'BM.rdf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_rdf_sqlx (domain_id, account_id);
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (path, content, 'text/xml', exec_perm, http_dav_uid (), http_dav_uid () + 1, null, null, 0);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-template', 'execute', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-encoding', 'utf-8', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-description', 'RDF based XML document generated by OpenLink Feed Manager', 'dav', null, 0, 0, 1);
-- OCS
path := home || 'BM.ocs';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_ocs_sqlx (domain_id, account_id);
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (path, content, 'text/xml', exec_perm, http_dav_uid (), http_dav_uid () + 1, null, null, 0);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-template', 'execute', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-encoding', 'utf-8', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-description', 'OCS based XML document generated by OpenLink Feed Manager', 'dav', null, 0, 0, 1);
-- OPML
path := home || 'BM.opml';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_opml_sqlx (domain_id, account_id);
DB.DBA.DAV_RES_UPLOAD_STRSES_INT (path, content, 'text/xml', exec_perm, http_dav_uid (), http_dav_uid () + 1, null, null, 0);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-template', 'execute', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-encoding', 'utf-8', 'dav', null, 0, 0, 1);
DB.DBA.DAV_PROP_SET_INT (path, 'xml-sql-description', 'OPML based XML document generated by OpenLink Feed Manager', 'dav', null, 0, 0, 1);
-- FOAF
path := home || 'BM.foaf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_gems_delete(
in domain_id integer,
in account_id integer,
in appName varchar := 'BM',
in appGems varchar := null)
{
declare tmp, home, path varchar;
home := BMK.WA.dav_home(account_id);
if (isnull(home))
return;
if (isnull(appGems))
appGems := BMK.WA.domain_gems_name(domain_id);
home := home || appName || '/' || appGems || '/';
path := home || appName || '.rss';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || appName || '.rdf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || appName || '.atom';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || appName || '.ocs';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || appName || '.opml';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || appName || '.foaf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
declare auth_uid, auth_pwd varchar;
auth_uid := coalesce((SELECT U_NAME FROM WS.WS.SYS_DAV_USER WHERE U_ID = account_id), '');
auth_pwd := coalesce((SELECT U_PWD FROM WS.WS.SYS_DAV_USER WHERE U_ID = account_id), '');
if (auth_pwd[0] = 0)
auth_pwd := pwd_magic_calc(auth_uid, auth_pwd, 1);
tmp := DB.DBA.DAV_DIR_LIST (home, 0, auth_uid, auth_pwd);
if (not isinteger(tmp) and not length(tmp))
DB.DBA.DAV_DELETE_INT (home, 1, null, null, 0);
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_update (
inout domain_id integer,
inout account_id integer)
{
BMK.WA.domain_gems_delete (domain_id, account_id, 'BM');
BMK.WA.domain_gems_delete (domain_id, account_id, 'BM', cast(domain_id as varchar));
BMK.WA.domain_gems_create (domain_id, account_id);
BMK.WA.sfolder_create(domain_id, 'All bookmarks', '', 1);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_delete (
in domain_id integer)
{
DECLARE CONTINUE HANDLER FOR SQLSTATE '*' {return 0; };
BMK.WA.folder_delete_all(domain_id);
DELETE FROM BMK.WA.SFOLDER WHERE SF_DOMAIN_ID = domain_id;
DELETE FROM BMK.WA.BOOKMARK_DOMAIN WHERE BD_DOMAIN_ID = domain_id;
for (select WAM_USER from DB.DBA.WA_MEMBER, DB.DBA.WA_INSTANCE where WAI_TYPE_NAME = 'Bookmark' and WAI_ID = domain_id) do
BMK.WA.account_delete (domain_id, WAM_USER);
VHOST_REMOVE(lpath => concat('/bookmark/', cast(domain_id as varchar)));
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_name (
in domain_id integer)
{
return coalesce((select WAI_NAME from DB.DBA.WA_INSTANCE where WAI_ID = domain_id), 'Bookmark Instance');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_gems_name (
in domain_id integer)
{
return concat(BMK.WA.domain_name(domain_id), '_Gems');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_description (
in domain_id integer)
{
return coalesce((select coalesce(WAI_DESCRIPTION, WAI_NAME) from DB.DBA.WA_INSTANCE where WAI_ID = domain_id), 'Bookmark Instance');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_is_public (
in domain_id integer)
{
return coalesce((select WAI_IS_PUBLIC from DB.DBA.WA_INSTANCE where WAI_ID = domain_id), 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_ping (
in domain_id integer)
{
return;
for (select WAI_NAME, WAI_DESCRIPTION from DB.DBA.WA_INSTANCE where WAI_ID = domain_id and WAI_IS_PUBLIC = 1) do
ODS..APP_PING (WAI_NAME, coalesce (WAI_DESCRIPTION, WAI_NAME), BMK.WA.sioc_url (domain_id));
}
;
-------------------------------------------------------------------------------
--
-- Account Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.account ()
{
declare vspx_user varchar;
vspx_user := connection_get('owner_user');
if (isnull(vspx_user))
vspx_user := connection_get('vspx_user');
return vspx_user;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_access (
out auth_uid varchar,
out auth_pwd varchar)
{
auth_uid := BMK.WA.account ();
auth_pwd := coalesce((SELECT U_PWD FROM WS.WS.SYS_DAV_USER WHERE U_NAME = auth_uid), '');
if (auth_pwd[0] = 0)
auth_pwd := pwd_magic_calc(auth_uid, auth_pwd, 1);
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_delete(
in domain_id integer,
in account_id integer)
{
declare iCount any;
select count(WAM_USER) into iCount
from WA_MEMBER,
WA_INSTANCE
where WAI_NAME = WAM_INST
and WAI_TYPE_NAME = 'Bookmark'
and WAM_USER = account_id;
if (iCount = 0) {
delete from BMK.WA.SETTINGS where S_ACCOUNT_ID = account_id;
delete from BMK.WA.GRANTS where G_GRANTER_ID = account_id or G_GRANTEE_ID = account_id;
}
BMK.WA.domain_gems_delete(domain_id, account_id);
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_name (
in account_id integer)
{
return coalesce((select U_NAME from DB.DBA.SYS_USERS where U_ID = account_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_fullName (
in account_id integer)
{
return coalesce((select coalesce(U_FULL_NAME, U_NAME) from DB.DBA.SYS_USERS where U_ID = account_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.user_name(
in u_name any,
in u_full_name any) returns varchar
{
if (not is_empty_or_null(trim(u_full_name)))
return u_full_name;
return u_name;
}
;
-------------------------------------------------------------------------------
--
-- Bookmarks
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_update (
in id integer,
in domain_id integer,
in uri any,
in name any,
in description any,
in folder_id integer)
{
declare bookmark_id integer;
bookmark_id := (select B_ID from BMK.WA.BOOKMARK where B_URI = uri);
if (is_empty_or_null(bookmark_id)) {
insert into BMK.WA.BOOKMARK (B_URI, B_NAME, B_DESCRIPTION, B_CREATED)
values (uri, name, description, now());
bookmark_id := identity_value ();
}
if (cast(folder_id as integer) <= 0)
folder_id := null;
if (id = -1)
id := coalesce((select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and coalesce(BD_FOLDER_ID, 0) = coalesce(folder_id, 0) and BD_BOOKMARK_ID = bookmark_id and BD_NAME = name), -1);
if (id = -1) {
insert into BMK.WA.BOOKMARK_DOMAIN (BD_DOMAIN_ID, BD_BOOKMARK_ID, BD_NAME, BD_DESCRIPTION, BD_LAST_UPDATE, BD_CREATED, BD_FOLDER_ID)
values (domain_id, bookmark_id, name, description, now(), now(), folder_id);
id := coalesce((select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and coalesce(BD_FOLDER_ID, 0) = coalesce(folder_id, 0) and BD_BOOKMARK_ID = bookmark_id and BD_NAME = name), -1);
} else {
update BMK.WA.BOOKMARK_DOMAIN
set BD_BOOKMARK_ID = bookmark_id,
BD_NAME = name,
BD_DESCRIPTION = description,
BD_LAST_UPDATE = now(),
BD_FOLDER_ID = folder_id
where BD_ID = id;
}
return id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_delete(
in domain_id integer,
in id integer)
{
declare bookmark_id integer;
bookmark_id := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id);
delete from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id;
if (not exists(select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and BD_BOOKMARK_ID = bookmark_id))
delete from BMK.WA.BOOKMARK_DATA where BD_MODE = 0 and BD_OBJECT_ID = domain_id and BD_BOOKMARK_ID = bookmark_id;
if (not exists(select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_BOOKMARK_ID = bookmark_id))
delete from BMK.WA.BOOKMARK where B_ID = bookmark_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_description(
in id integer)
{
return coalesce((select BD_DESCRIPTION from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_parent(
in id integer,
in folder_id integer)
{
if (is_empty_or_null(folder_id))
folder_id := null;
update BMK.WA.BOOKMARK_DOMAIN
set BD_FOLDER_ID = folder_id
where BD_ID = id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_import(
in S any,
in domain_id integer,
in account_id integer,
in folder_id integer,
in tags varchar,
in progress_id varchar)
{
declare V any;
-- check netscape format
if (isnull(strcasestr(S, '')))
goto _xbel;
S := replace(S, '
', '');
S := replace(S, '
', '');
S := replace(S, '
', '');
S := replace(S, 'FOLDED', '');
S := replace(S, ' ', ' ');
S := replace(S, '&', '&');
V := xtree_doc (S, 2);
V := xpath_eval ('//dl', V);
if (V is null)
goto _xbel;
BMK..bookmark_import_netscape (domain_id, account_id, folder_id, tags, xml_cut(V), progress_id);
goto _end;
_xbel:;
-- check xbel format
V := xtree_doc (S);
V := xpath_eval('/xbel', BMK.WA.string2xml(S));
if (V is null)
goto _delicious;
BMK..bookmark_import_xbel(domain_id, account_id, folder_id, tags, xml_cut(V), progress_id, 'xbel');
goto _end;
_delicious:;
V := xtree_doc (S);
V := xpath_eval('/posts', V);
if (V is null) {
signal ('BMK01', 'The content being imported was not of a format ODS-Bookmarks understands!<>');
goto _end;
}
BMK..bookmark_import_delicious(domain_id, account_id, folder_id, tags, xml_cut(V), progress_id);
_end:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_netscape(
in domain_id integer,
in account_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare tmp, T, Q any;
declare N, M integer;
if (V is null)
return;
N := 1;
while (1) {
--commit work;
T := xpath_eval('/dl/dt/a/text()', V, N);
if (T is null)
goto _folder;
Q := xpath_eval('/dl/dt/a/@href', V, N);
commit work;
tmp := BMK.WA.bookmark_update (-1, domain_id, cast (Q as varchar), cast (T as varchar), null, folder_id);
if (tags <> '') {
tmp := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = tmp);
BMK.WA.bookmark_tags (domain_id, account_id, tmp, tags, 0);
}
if (not is_empty_or_null (progress_id)) {
if (cast(registry_get ('bookmark_action_' || progress_id) as varchar) = 'stop')
return;
M := cast (registry_get('bookmark_index_' || progress_id) as integer) + 1;
registry_set ('bookmark_index_' || progress_id, cast (M as varchar));
}
N := N + 1;
}
_folder:
N := 1;
while (1) {
T := xpath_eval('/dl/dt/h3', V, N);
if (T is null)
goto _exit;
tmp := BMK.WA.folder_create2 (domain_id, folder_id, cast (T as varchar));
T := xpath_eval('/dl/dt/dl', V, N);
if (not (T is null))
BMK.WA.bookmark_import_netscape (domain_id, account_id, tmp, tags, xml_cut(T), progress_id);
N := N + 1;
}
_exit:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_xbel(
in domain_id integer,
in account_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar,
in tag varchar)
{
declare tmp, T, Q, D any;
declare N, M integer;
if (V is null)
return;
T := xpath_eval(sprintf('/%s/title/text()', tag), V, 1);
if (T is null)
return;
folder_id := BMK.WA.folder_create2 (domain_id, folder_id, cast(T as varchar));
N := 1;
while (1) {
Q := xpath_eval(sprintf('/%s/bookmark[%d]/@href', tag, N), V, 1);
if (Q is null)
goto _folder;
T := BMK.WA.wide2utf (xpath_eval (sprintf ('string(/%s/bookmark[%d]/title/text())', tag, N), V, 1));
D := BMK.WA.wide2utf (xpath_eval (sprintf ('string(/%s/bookmark[%d]/desc/text())', tag, N), V, 1));
commit work;
tmp := BMK.WA.bookmark_update (-1, domain_id, cast(Q as varchar), cast(T as varchar), D, folder_id);
if (tags <> '') {
tmp := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = tmp);
BMK.WA.bookmark_tags (domain_id, account_id, tmp, tags, 0);
}
if (not is_empty_or_null (progress_id)) {
if (cast(registry_get ('bookmark_action_' || progress_id) as varchar) = 'stop')
return;
M := cast (registry_get('bookmark_index_' || progress_id) as integer) + 1;
registry_set('bookmark_index_' || progress_id, cast (M as varchar));
}
N := N + 1;
}
_folder:
N := 1;
while (1) {
T := xpath_eval(sprintf('/%s/folder[%d]', tag, N), V, 1);
if (T is null)
goto _exit;
BMK.WA.bookmark_import_xbel (domain_id, account_id, folder_id, tags, xml_cut(T), progress_id, 'folder');
N := N + 1;
}
_exit:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_delicious(
in domain_id integer,
in account_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare tmp, T, Q, D, nTags, TG, TGA any;
declare N, M integer;
if (V is null)
return;
N := 1;
while (1) {
Q := xpath_eval(sprintf('//post[%d]/@href', N), V, 1);
if (Q is null)
goto _exit;
T := BMK.WA.wide2utf(xpath_eval(sprintf('string(//post[%d]/@description)', N), V, 1));
D := BMK.WA.wide2utf(xpath_eval(sprintf('string(//post[%d]/@extended)', N), V, 1));
commit work;
tmp := BMK.WA.bookmark_update (-1, domain_id, cast(Q as varchar), cast(T as varchar), D, folder_id);
tmp := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = tmp);
nTags := '';
TG := cast(xpath_eval(sprintf('string(//post[%d]/@tag)', N), V, 1) as varchar);
if (TG <> 'system:unfiled') {
TGA := split_and_decode(TG, 0, '\0\0 ');
foreach (any tag in TGA) do
if (BMK.WA.validate_tag (tag))
nTags := concat(nTags, tag, ',');
}
nTags := trim(tags || ',' || nTags, ',');
if (nTags <> '') {
BMK.WA.bookmark_tags (domain_id, account_id, tmp, nTags, 0);
}
if (not is_empty_or_null (progress_id)) {
if (cast(registry_get ('bookmark_action_' || progress_id) as varchar) = 'stop')
return;
M := cast (registry_get('bookmark_index_' || progress_id) as integer) + 1;
registry_set('bookmark_index_' || progress_id, cast (M as varchar));
}
N := N + 1;
}
_exit:
BMK.WA.tags_refresh (domain_id, account_id, 0);
return;
}
;
-------------------------------------------------------------------------------
--
CREATE PROCEDURE BMK.WA.bookmark_export(
in domain_id integer,
in folder_id integer)
{
declare retValue any;
retValue := string_output ();
http ('\n', retValue);
http (sprintf('', coalesce(folder_id, -1)), retValue);
BMK.WA.bookmark_export_tmp(domain_id, folder_id, retValue);
http ('', retValue);
return string_output_string (retValue);
}
;
-------------------------------------------------------------------------------
--
CREATE PROCEDURE BMK.WA.bookmark_export_tmp(
in domain_id integer,
in folder_id any,
inout retValue any)
{
declare id, type any;
-- http (sprintf('', BD_NAME, coalesce(BD_DESCRIPTION, ''), B_URI, BD_ID), retValue);
for (select a.*, b.B_URI from BMK.WA.BOOKMARK_DOMAIN a, BMK.WA.BOOKMARK b where a.BD_BOOKMARK_ID = b.B_ID and a.BD_DOMAIN_ID = domain_id and coalesce(a.BD_FOLDER_ID, -1) = coalesce(folder_id, -1) order by a.BD_NAME) do {
http (sprintf('', BMK.WA.utf2wide (BD_NAME), B_URI, BD_ID), retValue);
if (coalesce(BD_DESCRIPTION, '') <> '')
http (sprintf('%V', BD_DESCRIPTION), retValue);
http ('', retValue);
}
for (select F_ID, F_NAME from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and coalesce(F_PARENT_ID, -1) = coalesce(folder_id, -1) order by 2) do {
http (sprintf('', F_NAME, F_ID), retValue);
BMK.WA.bookmark_export_tmp(domain_id, F_ID, retValue);
http ('', retValue);
}
}
;
-------------------------------------------------------------------------------
--
-- Tags
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_tags (
inout domain_id integer,
inout account_id integer,
inout bookmark_id integer,
inout tags any,
in mode integer := 1)
{
if (mode)
BMK.WA.tags_delete (domain_id, account_id, bookmark_id);
if (BMK.WA.check_grants(domain_id, account_id, 'owner'))
if (not exists (select 1 from BMK.WA.BOOKMARK_DATA where BD_MODE = 0 and BD_OBJECT_ID = domain_id and BD_BOOKMARK_ID = bookmark_id)) {
insert into BMK.WA.BOOKMARK_DATA(BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID, BD_TAGS, BD_LAST_UPDATE)
values(0, domain_id, bookmark_id, tags, now());
} else {
update BMK.WA.BOOKMARK_DATA
set BD_TAGS = tags,
BD_LAST_UPDATE = now()
where BD_MODE = 0
and BD_OBJECT_ID = domain_id
and BD_BOOKMARK_ID = bookmark_id;
}
if (not exists (select 1 from BMK.WA.BOOKMARK_DATA where BD_MODE = 1 and BD_OBJECT_ID = account_id and BD_BOOKMARK_ID = bookmark_id)) {
insert into BMK.WA.BOOKMARK_DATA(BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID, BD_TAGS, BD_LAST_UPDATE)
values(1, account_id, bookmark_id, tags, now());
} else {
update BMK.WA.BOOKMARK_DATA
set BD_TAGS = tags,
BD_LAST_UPDATE = now()
where BD_MODE = 1
and BD_OBJECT_ID = account_id
and BD_BOOKMARK_ID = bookmark_id;
}
if (mode)
BMK.WA.tags_update (domain_id, account_id, bookmark_id);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_select (
inout domain_id integer,
inout account_id integer,
inout bookmark_id integer)
{
declare tags varchar;
tags := (select BD_TAGS from BMK.WA.BOOKMARK_DATA where BD_MODE = 1 and BD_OBJECT_ID = account_id and BD_BOOKMARK_ID = bookmark_id);
if (isnull(tags))
tags := (select BD_TAGS from BMK.WA.BOOKMARK_DATA where BD_MODE = 0 and BD_OBJECT_ID = domain_id and BD_BOOKMARK_ID = bookmark_id);
return tags;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_select2(
inout domain_id integer,
inout account_id integer,
inout id integer)
{
declare bookmark_id integer;
bookmark_id := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id);
return BMK.WA.tags_select (domain_id, account_id, bookmark_id);
}
;
-------------------------------------------------------------------------------
--
-- Flags
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_flag (
inout id integer,
inout account_id integer)
{
return coalesce((select a.BD_READ_FLAG from BMK.WA.BOOKMARK_DATA a, BMK.WA.BOOKMARK_DOMAIN b where a.BD_MODE = 1 and a.BD_OBJECT_ID = account_id and a.BD_BOOKMARK_ID = b.BD_BOOKMARK_ID and b.BD_ID = id), 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_flag_set (
in id integer,
in account_id integer,
in flag integer)
{
declare bookmark_id integer;
bookmark_id := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id);
if (not exists (select 1 from BMK.WA.BOOKMARK_DATA where BD_MODE = 1 and BD_OBJECT_ID = account_id and BD_BOOKMARK_ID = bookmark_id)) {
insert into BMK.WA.BOOKMARK_DATA (BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID, BD_LAST_UPDATE, BD_READ_FLAG)
values(1, account_id, bookmark_id, now(), flag);
} else {
update BMK.WA.BOOKMARK_DATA
set BD_READ_FLAG = flag,
BD_LAST_UPDATE = now()
where BD_MODE = 1
and BD_OBJECT_ID = account_id
and BD_BOOKMARK_ID = bookmark_id;
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_flag_set(
in id integer,
in account_id integer,
in flag integer)
{
-- delete childs
for (select F_ID from BMK.WA.FOLDER where F_PARENT_ID = id) do
BMK.WA.folder_flag_set (F_ID, account_id, flag);
-- delete bookmarks
for (select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_FOLDER_ID = id) do
BMK.WA.bookmark_flag_set (BD_ID, account_id, flag);
}
;
-------------------------------------------------------------------------------
--
-- Last access
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_last_visited (
inout id integer,
inout account_id integer)
{
declare bookmark_id integer;
bookmark_id := (select BD_BOOKMARK_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id);
if (not exists (select 1 from BMK.WA.BOOKMARK_DATA where BD_MODE = 1 and BD_OBJECT_ID = account_id and BD_BOOKMARK_ID = bookmark_id)) {
insert into BMK.WA.BOOKMARK_DATA (BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID, BD_LAST_UPDATE, BD_LAST_VISITED, BD_VISITED)
values(1, account_id, bookmark_id, now (), now (), 1);
} else {
update BMK.WA.BOOKMARK_DATA
set BD_LAST_VISITED = now (),
BD_VISITED = coalesce(BD_VISITED, 0) + 1,
BD_LAST_UPDATE = now ()
where BD_MODE = 1
and BD_OBJECT_ID = account_id
and BD_BOOKMARK_ID = bookmark_id;
}
}
;
-------------------------------------------------------------------------------
--
-- Folders
--
-------------------------------------------------------------------------------
create procedure BMK.WA.folder_id(
in domain_id integer,
in folder_name varchar)
{
declare i, folder_id integer;
declare aPath any;
folder_id := null;
if (not is_empty_or_null(folder_name)) {
aPath := split_and_decode(trim(folder_name, '/'),0,'\0\0/');
for (i := 0; i < length(aPath); i := i + 1) {
if (i = 0) {
if (not exists (select 1 from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = aPath[i] and F_PARENT_ID is null))
insert into BMK.WA.FOLDER (F_DOMAIN_ID, F_NAME, F_PATH) values (domain_id, aPath[i], '');
folder_id := (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = aPath[i] and F_PARENT_ID is null);
} else {
if (not exists (select 1 from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = aPath[i] and F_PARENT_ID = folder_id))
insert into BMK.WA.FOLDER (F_DOMAIN_ID, F_PARENT_ID, F_NAME, F_PATH) values (domain_id, folder_id, aPath[i], '');
folder_id := (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = aPath[i] and F_PARENT_ID = folder_id);
}
}
}
return folder_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_create(
inout domain_id varchar,
in folder_name any,
in folder_id any)
{
folder_name := trim(folder_name);
if (folder_name <> '') {
folder_id := BMK.WA.folder_id(domain_id, folder_name);
} else {
folder_id := cast(folder_id as integer);
}
if (folder_id = 0)
folder_id := null;
return folder_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_create2(
in domain_id varchar,
in parent_id varchar,
in folder_name any)
{
declare folder_id integer;
if (not exists (select 1 from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = folder_name and coalesce(F_PARENT_ID, -1) = coalesce(parent_id, -1)))
insert into BMK.WA.FOLDER (F_DOMAIN_ID, F_PARENT_ID, F_NAME, F_PATH) values (domain_id, parent_id, folder_name, '');
return (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = folder_name and coalesce(F_PARENT_ID, -1) = coalesce(parent_id, -1));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_parent(
in folder_id integer,
in parent_id integer)
{
update BMK.WA.FOLDER set F_PARENT_ID = parent_id where F_ID = folder_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_delete(
in domain_id integer,
in folder_id integer)
{
-- delete childs
for (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_PARENT_ID = folder_id) do
BMK.WA.folder_delete(domain_id, F_ID);
-- delete bookmarks
for (select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and BD_FOLDER_ID = folder_id) do
BMK.WA.bookmark_delete(domain_id, BD_ID);
-- delete folder at last
delete from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_ID = folder_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_delete_all(
in domain_id integer)
{
for (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and coalesce(F_PARENT_ID, -1) = -1) do
BMK.WA.folder_delete(domain_id, F_ID);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_name(
in domain_id integer,
in folder_id integer)
{
return coalesce((select F_NAME from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_ID = folder_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_path (
in folder_id integer)
{
return coalesce((select F_PATH from BMK.WA.FOLDER where F_ID = folder_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_path2 (
inout path varchar)
{
declare aPath varchar;
aPath := split_and_decode(path,0,'\0\0/');
return concat(repeat('~', length(aPath)-1), aPath[length(aPath)-1]);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_path3 (
in folder_id integer,
in grant_id integer)
{
declare parent_id integer;
declare path any;
if (grant_id = -1) {
path := coalesce(BMK.WA.folder_path (folder_id), '');
} else {
for (select G_OBJECT_TYPE, G_OBJECT_ID from BMK.WA.GRANTS where G_ID = grant_id) do {
path := '';
if (G_OBJECT_TYPE = 'F') {
parent_id := (select F_PARENT_ID from BMK.WA.FOLDER where F_ID = G_OBJECT_ID);
path := replace(coalesce(BMK.WA.folder_path (folder_id), ''), coalesce(BMK.WA.folder_path (parent_id), ''), '');
}
}
}
if (path <> '')
return path;
return '[Root Folder]';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_path4 (
in folder_name varchar,
in grant_id integer)
{
declare parent_id integer;
declare name any;
if (grant_id = -1) {
name := coalesce(folder_name, '');
} else {
for (select G_OBJECT_TYPE, G_OBJECT_ID from BMK.WA.GRANTS where G_ID = grant_id) do {
name := '';
if (G_OBJECT_TYPE = 'F')
name := coalesce(folder_name, '');
}
}
if (name <> '')
return name;
return '[Root Folder]';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_check_name(
in folder_name varchar,
in is_path integer := 0)
{
if (is_path) {
declare i integer;
declare aPath any;
aPath := split_and_decode(trim(folder_name, '/'),0,'\0\0/');
for (i := 0; i < length(aPath); i := i + 1)
if (not BMK.WA.validate('folder', aPath[i]))
return 0;
return 1;
} else {
return BMK.WA.validate('folder', folder_name);
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_check_unique(
in domain_id integer,
in parent_id integer,
in name varchar,
in folder_id integer := 0)
{
declare retValue integer;
retValue := coalesce((select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID=domain_id and coalesce(F_PARENT_ID, -1) = coalesce(parent_id, -1) and F_NAME=name), 0);
if (folder_id = 0)
return retValue;
if (retValue = 0)
return retValue;
if (retValue <> folder_id)
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_check_parent(
in domain_id integer,
in parent_id integer,
in folder_id integer)
{
declare new_id integer;
if (folder_id = parent_id)
return 1;
new_id := (select F_PARENT_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_ID = folder_id);
if (isnull(new_id)) {
if (isnull(parent_id))
return 1;
return 0;
}
if (new_id = parent_id)
return 1;
return BMK.WA.folder_check_parent(domain_id, parent_id, new_id);
}
;
-------------------------------------------------------------------------------
--
-- Smart folders
--
-------------------------------------------------------------------------------
create procedure BMK.WA.sfolder_sql (
inout domain_id integer,
inout account_id integer,
inout data varchar,
in maxRows varchar := '')
{
declare S, tmp, where2, delimiter2 varchar;
where2 := ' \n ';
delimiter2 := '\n and ';
if (is_empty_or_null(BMK.WA.xml_get('tags', data))) {
S :=
'select \n' ||
' distinct \n' ||
' 1 _TYPE, \n' ||
' a.BD_ID _ID, \n' ||
' BMK.WA.make_node (\'b\', a.BD_ID) _NODE, \n' ||
' a.BD_NAME _NAME, \n' ||
' b.B_URI _URI, \n' ||
' a.BD_LAST_UPDATE _LAST_UPDATE, \n' ||
' a.BD_CREATED _CREATED, \n' ||
' coalesce(c.BD_READ_FLAG, 0) BD_READ_FLAG, \n' ||
' a.BD_FOLDER_ID _FOLDER_ID, \n' ||
' d.F_NAME _FOLDER_NAME, \n' ||
' -1 _GRANT_ID \n' ||
'from BMK.WA.BOOKMARK_DOMAIN a \n' ||
' join BMK.WA.BOOKMARK b on b.B_ID = a.BD_BOOKMARK_ID \n' ||
' left join BMK.WA.BOOKMARK_DATA c on c.BD_MODE = 1 and c.BD_BOOKMARK_ID = b.B_ID and c.BD_OBJECT_ID = \n' ||
' left join BMK.WA.FOLDER d on d.F_ID = a.BD_FOLDER_ID \n' ||
'where a.BD_DOMAIN_ID = \n';
} else {
S :=
'select \n' ||
' distinct \n' ||
' 1 _TYPE, \n' ||
' a.BD_ID _ID, \n' ||
' BMK.WA.make_node (\'b\', a.BD_ID) _NODE, \n' ||
' a.BD_NAME _NAME, \n' ||
' b.B_URI _URI, \n' ||
' a.BD_LAST_UPDATE _LAST_UPDATE, \n' ||
' a.BD_CREATED _CREATED, \n' ||
' coalesce(c.BD_READ_FLAG, 0) BD_READ_FLAG, \n' ||
' a.BD_FOLDER_ID _FOLDER_ID, \n' ||
' d.F_NAME _FOLDER_NAME, \n' ||
' -1 _GRANT_ID \n' ||
'from \n' ||
' (select \n' ||
' BD_BOOKMARK_ID \n' ||
' from \n' ||
' BMK.WA.BOOKMARK_DATA \n' ||
' where contains(BD_TAGS, \'[__lang "x-ViDoc"] \') \n' ||
' \n' ||
' union \n' ||
' \n' ||
' select \n' ||
' BD_BOOKMARK_ID \n' ||
' from \n' ||
' BMK.WA.BOOKMARK_DATA \n' ||
' where contains(BD_TAGS, \'[__lang "x-ViDoc"] \')) x \n' ||
' join BMK.WA.BOOKMARK_DOMAIN a on a.BD_BOOKMARK_ID = x.BD_BOOKMARK_ID \n' ||
' join BMK.WA.BOOKMARK b on b.B_ID = a.BD_BOOKMARK_ID \n' ||
' left join BMK.WA.BOOKMARK_DATA c on c.BD_MODE = 1 and c.BD_OBJECT_ID = and c.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID \n' ||
' left join BMK.WA.FOLDER d on d.F_ID = a.BD_FOLDER_ID \n' ||
'where a.BD_DOMAIN_ID = \n';
}
tmp := BMK.WA.xml_get('keywords', data);
if (not is_empty_or_null(tmp)) {
S := replace(S, '', sprintf('and contains(a.BD_DESCRIPTION, \'[__lang "x-ViDoc"] %s\') \n', FTI_MAKE_SEARCH_STRING(tmp)));
} else {
tmp := BMK.WA.xml_get('expression', data);
if (not is_empty_or_null(tmp))
S := replace(S, '', sprintf('and contains(a.BD_DESCRIPTION, \'[__lang "x-ViDoc"] %s\') \n', tmp));
}
tmp := BMK.WA.xml_get('tags', data);
if (not is_empty_or_null(tmp)) {
tmp := BMK.WA.tags2search(tmp);
S := replace(S, '', tmp);
S := replace(S, '', sprintf('%s and "^R%s"', tmp, cast(domain_id as varchar)));
S := replace(S, '', sprintf('%s and "^UID%s"', tmp, cast(account_id as varchar)));
}
tmp := BMK.WA.xml_get('folder', data);
if (not is_empty_or_null(tmp)) {
tmp := cast(tmp as integer);
if (tmp > 0)
BMK.WA.sfolder_sql_where (where2, delimiter2, sprintf('d.F_PATH like \'%s%s\'', BMK.WA.folder_path (tmp), '%'));
}
tmp := BMK.WA.xml_get('bookmark', data);
if (not is_empty_or_null(tmp)) {
tmp := cast(tmp as integer);
if (tmp > 0)
BMK.WA.sfolder_sql_where (where2, delimiter2, sprintf('a.BD_ID = %d', tmp));
}
if (maxRows <> '')
maxRows := 'TOP ' || maxRows;
S := replace(S, '', maxRows);
S := replace(S, '', cast(domain_id as varchar));
S := replace(S, '', cast(account_id as varchar));
S := replace(S, '', '');
S := replace(S, '', '');
S := replace(S, '', '');
S := replace(S, '', '');
S := replace(S, '', where2);
--dbg_obj_print(S);
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.shared_sql(
inout domain_id integer,
inout account_id integer,
inout data varchar,
in maxRows varchar := '',
in own integer := 1,
in shared integer := 1,
in grants varchar := '')
{
declare N, gid, did, aid, fid, bid integer;
declare newData any;
declare c0 integer;
declare c1 integer;
declare c2 varchar;
declare c3 varchar;
declare c4 varchar;
declare c5 datetime;
declare c6 datetime;
declare c7 integer;
declare c8 integer;
declare c9 varchar;
declare c10 integer;
declare sql, state, msg, meta, rows any;
result_names(c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10);
-- search in my own
if (own = 1) {
state := '00000';
sql := BMK.WA.sfolder_sql(domain_id, account_id, data, maxRows);
exec(sql, state, msg, vector(), 0, meta, rows);
if (state = '00000')
foreach (any row in rows) do
result(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10]);
}
-- search in my shared
if (shared = 1) {
grants := split_and_decode(trim(grants, ','), 0, '\0\0,');
for (select G_ID, G_GRANTER_ID, G_OBJECT_TYPE, G_OBJECT_ID, U_NAME from BMK.WA.GRANTS, DB.DBA.SYS_USERS where G_GRANTEE_ID = account_id and G_GRANTER_ID = U_ID order by G_GRANTER_ID) do {
if (length(grants) and not BMK.WA.vector_contains(grants, U_NAME))
goto _skip;
newData := data;
gid := G_ID;
aid := G_GRANTER_ID;
fid := -1;
bid := 0;
if (G_OBJECT_TYPE = 'F') {
fid := G_OBJECT_ID;
did := (select F_DOMAIN_ID from BMK.WA.FOLDER where F_ID = fid);
} else {
bid := G_OBJECT_ID;
did := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bid);
}
BMK.WA.xml_set('folder', newData, fid);
BMK.WA.xml_set('bookmark', newData, bid);
state := '00000';
sql := BMK.WA.sfolder_sql(did, aid, newData, maxRows);
exec(sql, state, msg, vector(), 0, meta, rows);
if (state = '00000')
foreach (any row in rows) do {
fid := row[8];
if (bid <> 0)
fid := -1;
result(row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], fid, row[9], gid);
}
_skip:;
}
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sfolder_sql_where(
inout where2 varchar,
inout delimiter varchar,
in criteria varchar)
{
if (criteria <> '') {
if (where2 = '')
where2 := 'where ';
where2 := concat(where2, delimiter, criteria);
delimiter := '\n and ';
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sfolder_create(
in domain_id integer,
in name varchar,
in data varchar,
in test integer := 0)
{
declare id varchar;
if (test) {
id := coalesce((select SF_ID from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id and SF_NAME = name), '');
if (id <> '')
return id;
}
id := cast(sequence_next ('sfolder') as varchar);
insert into BMK.WA.SFOLDER(SF_ID, SF_DOMAIN_ID, SF_NAME, SF_DATA)
values(id, domain_id, name, data);
return id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sfolder_update(
in domain_id integer,
in id varchar,
in name varchar,
in data varchar)
{
update BMK.WA.SFOLDER
set SF_NAME = name,
SF_DATA = data
where SF_ID = id
and SF_DOMAIN_ID = domain_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sfolder_delete(
in domain_id integer,
in folder_id integer)
{
delete from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id and SF_ID = folder_id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tag_prepare(
inout tag varchar)
{
if (not is_empty_or_null(tag)) {
tag := trim(tag);
tag := replace(tag, ' ', ' ');
}
return tag;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tag_delete(
inout tags varchar,
inout T integer)
{
declare N integer;
declare tags2 any;
tags2 := BMK.WA.tags2vector(tags);
tags := '';
for (N := 0; N < length(tags2); N := N + 1)
if (N <> T)
tags := concat(tags, ',', tags2[N]);
return trim(tags, ',');
}
;
---------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_join(
inout tags varchar,
inout tags2 varchar)
{
declare resultTags any;
if (is_empty_or_null(tags))
tags := '';
if (is_empty_or_null(tags2))
tags2 := '';
resultTags := concat(tags, ',', tags2);
resultTags := BMK.WA.tags2vector(resultTags);
resultTags := BMK.WA.tags2unique(resultTags);
resultTags := BMK.WA.vector2tags(resultTags);
return resultTags;
}
;
---------------------------------------------------------------------------------
--
create procedure BMK.WA.tags2vector(
inout tags varchar)
{
return split_and_decode(trim(tags, ','), 0, '\0\0,');
}
;
---------------------------------------------------------------------------------
--
create procedure BMK.WA.tags2search(
in tags varchar)
{
declare S varchar;
declare V any;
S := '';
V := BMK.WA.tags2vector(tags);
foreach (any tag in V) do
S := concat(S, ' ', replace (replace (trim(lcase(tag)), ' ', '_'), '+', '_'));
return FTI_MAKE_SEARCH_STRING(trim(S, ','));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector2tags(
inout aVector any)
{
declare N integer;
declare aResult any;
aResult := '';
for (N := 0; N < length(aVector); N := N + 1)
if (N = 0) {
aResult := trim(aVector[N]);
} else {
aResult := concat(aResult, ',', trim(aVector[N]));
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags2unique(
inout aVector any)
{
declare aResult any;
declare N, M integer;
aResult := vector();
for (N := 0; N < length(aVector); N := N + 1) {
for (M := 0; M < length(aResult); M := M + 1)
if (trim(lcase(aResult[M])) = trim(lcase(aVector[N])))
goto _next;
aResult := vector_concat(aResult, vector(trim(aVector[N])));
_next:;
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_agregator ()
{
for (select WAI_ID, WAM_USER from DB.DBA.WA_MEMBER, DB.DBA.WA_INSTANCE where WAI_NAME = WAM_INST and WAI_TYPE_NAME = 'Bookmark') do
BMK.WA.tags_refresh (WAI_ID, WAM_USER, 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_refresh (
in domain_id integer,
in account_id integer,
in mode integer := 1)
{
declare ts_count, ts_max, N integer;
declare ts_last_update datetime;
declare tags, tags_dict, tags_vector, tag_object any;
declare exit handler for not found { goto _skip; };
ts_last_update := null;
ts_max := 1;
if (mode)
select T_LAST_UPDATE, T_COUNT into ts_last_update, ts_max from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id and T_TAG = '';
_skip:
tags_dict := dict_new();
for (select
x.BD_TAGS
from
(select
coalesce(c.BD_TAGS, b.BD_TAGS) BD_TAGS
from
BMK.WA.BOOKMARK_DOMAIN a
left join BMK.WA.BOOKMARK_DATA b on b.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and b.BD_MODE = 0 and b.BD_OBJECT_ID = domain_id
left join BMK.WA.BOOKMARK_DATA c on c.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and c.BD_MODE = 1 and c.BD_OBJECT_ID = account_id
where a.BD_DOMAIN_ID = domain_id
and (ts_last_update is null or b.BD_LAST_UPDATE > ts_last_update)
and (ts_last_update is null or c.BD_LAST_UPDATE > ts_last_update)) x) do
{
tags := split_and_decode (BD_TAGS, 0, '\0\0,');
foreach (any tag in tags) do {
tag_object := dict_get(tags_dict, lcase(tag), vector(lcase(tag), 0));
tag_object[1] := tag_object[1] + 1;
dict_put(tags_dict, lcase(tag), tag_object);
}
}
ts_last_update := now();
tags_vector := dict_to_vector(tags_dict, 1);
if (mode) {
for (N := 1; N < length(tags_vector); N := N + 2) {
ts_count := coalesce((select T_COUNT from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id and T_TAG = tags_vector[N][0]), 0);
insert replacing BMK.WA.TAGS(T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values(domain_id, account_id, ts_last_update, tags_vector[N][0], tags_vector[N][1]+ts_count);
if (ts_max < tags_vector[N][1]+ts_count)
ts_max := tags_vector[N][1] + ts_count;
}
} else {
delete from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id;
for (N := 1; N < length(tags_vector); N := N + 2) {
insert into BMK.WA.TAGS(T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values(domain_id, account_id, ts_last_update, tags_vector[N][0], tags_vector[N][1]);
if (ts_max < tags_vector[N][1])
ts_max := tags_vector[N][1];
}
}
insert replacing BMK.WA.TAGS(T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values(domain_id, account_id, ts_last_update, '', ts_max);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_delete (
in domain_id integer,
in account_id integer,
in bookmark_id integer)
{
declare ts_count, ts_max, N integer;
declare tags any;
tags := vector();
for (select
x.BD_TAGS
from
(select
coalesce(c.BD_TAGS, b.BD_TAGS) BD_TAGS
from
BMK.WA.BOOKMARK_DOMAIN a
left join BMK.WA.BOOKMARK_DATA b on b.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and b.BD_MODE = 0 and b.BD_OBJECT_ID = domain_id
left join BMK.WA.BOOKMARK_DATA c on c.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and c.BD_MODE = 1 and c.BD_OBJECT_ID = account_id
where a.BD_DOMAIN_ID = domain_id
and a.BD_BOOKMARK_ID = bookmark_id) x) do
{
tags := split_and_decode (BD_TAGS, 0, '\0\0,');
}
for (N := 0; N < length(tags); N := N + 1) {
ts_count := coalesce((select T_COUNT from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id and T_TAG = tags[N]), 0);
if (ts_count)
if (ts_count = 1) {
delete from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id and T_TAG = tags[N];
} else {
insert replacing BMK.WA.TAGS (T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values (domain_id, account_id, now (), tags[N], ts_count-1);
}
}
ts_count := coalesce((select max(T_COUNT) from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id), 0);
insert replacing BMK.WA.TAGS (T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values (domain_id, account_id, now (), '', ts_count);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_update (
in domain_id integer,
in account_id integer,
in bookmark_id integer)
{
declare ts_count, ts_max, N integer;
declare tags any;
tags := vector();
for (select
x.BD_TAGS
from
(select
coalesce(c.BD_TAGS, b.BD_TAGS) BD_TAGS
from
BMK.WA.BOOKMARK_DOMAIN a
left join BMK.WA.BOOKMARK_DATA b on b.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and b.BD_MODE = 0 and b.BD_OBJECT_ID = domain_id
left join BMK.WA.BOOKMARK_DATA c on c.BD_BOOKMARK_ID = a.BD_BOOKMARK_ID and c.BD_MODE = 1 and c.BD_OBJECT_ID = account_id
where a.BD_DOMAIN_ID = domain_id
and a.BD_BOOKMARK_ID = bookmark_id) x) do
{
tags := split_and_decode (BD_TAGS, 0, '\0\0,');
}
for (N := 0; N < length(tags); N := N + 1) {
ts_count := coalesce((select T_COUNT from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id and T_TAG = tags[N]), 0);
insert replacing BMK.WA.TAGS (T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values (domain_id, account_id, now (), tags[N], ts_count+1);
}
ts_count := coalesce((select max(T_COUNT) from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id), 0);
insert replacing BMK.WA.TAGS (T_DOMAIN_ID, T_ACCOUNT_ID, T_LAST_UPDATE, T_TAG, T_COUNT)
values (domain_id, account_id, now (), '', ts_count);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings (
inout account_id integer)
{
return coalesce((select deserialize(blob_to_string(S_DATA))
from BMK.WA.SETTINGS
where S_ACCOUNT_ID = account_id), vector());
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_chars (
inout account_id integer)
{
declare settings any;
settings := BMK.WA.settings(account_id);
return cast(get_keyword('chars', settings, '60') as integer);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_rows (
inout account_id integer)
{
declare settings any;
settings := BMK.WA.settings(account_id);
return cast(get_keyword('rows', settings, '10') as integer);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_atomVersion (
inout account_id integer)
{
declare settings any;
settings := BMK.WA.settings(account_id);
return get_keyword('atomVersion', settings, '1.0');
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dav_home(
inout account_id integer) returns varchar
{
declare name, home any;
declare cid integer;
name := coalesce((select U_NAME from DB.DBA.SYS_USERS where U_ID = account_id), -1);
if (isinteger(name))
return null;
home := BMK.WA.dav_home_create(name);
if (isinteger(home))
return null;
cid := DB.DBA.DAV_SEARCH_ID(home, 'C');
if (isinteger(cid) and (cid > 0))
return home;
return null;
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dav_home_create(
in user_name varchar) returns any
{
declare user_id, cid integer;
declare user_home varchar;
whenever not found goto _error;
if (is_empty_or_null(user_name))
goto _error;
user_home := DB.DBA.DAV_HOME_DIR(user_name);
if (isstring(user_home))
cid := DB.DBA.DAV_SEARCH_ID(user_home, 'C');
if (isinteger(cid) and (cid > 0))
return user_home;
user_home := '/DAV/home/';
DB.DBA.DAV_MAKE_DIR (user_home, http_dav_uid (), http_dav_uid () + 1, '110100100R');
user_home := user_home || user_name || '/';
user_id := (select U_ID from DB.DBA.SYS_USERS where U_NAME = user_name);
DB.DBA.DAV_MAKE_DIR (user_home, user_id, null, '110100000R');
USER_SET_OPTION(user_name, 'HOME', user_home);
return user_home;
_error:
return -18;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.host_url ()
{
declare ret varchar;
--return '';
if (is_http_ctx ()) {
ret := http_request_header (http_request_header ( ) , 'Host' , null , sys_connected_server_address ());
if (isstring (ret) and strchr (ret , ':') is null) {
declare hp varchar;
declare hpa any;
hp := sys_connected_server_address ();
hpa := split_and_decode ( hp , 0 , '\0\0:');
ret := ret || ':' || hpa [1];
}
} else {
ret := sys_connected_server_address ();
if (ret is null)
ret := sys_stat ('st_host_name') || ':' || server_http_port ();
}
return 'http://' || ret ;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_url (
in domain_id integer)
{
return concat(BMK.WA.host_url(), '/bookmark/', cast(domain_id as varchar), '/');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_url (
in domain_id integer)
{
declare home varchar;
home := BMK.WA.dav_home (BMK.WA.domain_owner_id (domain_id));
if (isnull (home))
return '';
return concat(BMK.WA.host_url(), home, 'BM/', BMK.WA.domain_gems_name(domain_id), '/');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_url2 (
in domain_id integer,
in account_id integer)
{
declare home varchar;
home := BMK.WA.dav_home(account_id);
if (isnull(home))
return '';
return replace(concat(home, 'BM/', BMK.WA.domain_gems_name(domain_id), '/'), ' ', '%20');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sioc_url (
in domain_id integer)
{
return sprintf('%s/dataspace/%U/bookmark/%U/sioc.rdf', BMK.WA.host_url (), BMK.WA.account (), replace (BMK.WA.domain_name (domain_id), '+', '%2B'));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.foaf_url (
in domain_id integer)
{
return sprintf('%s/dataspace/%s/about.rdf', BMK.WA.host_url (), BMK.WA.domain_owner_name (domain_id));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.geo_url (
in domain_id integer,
in account_id integer)
{
for (select WAUI_LAT, WAUI_LNG from WA_USER_INFO where WAUI_U_ID = account_id) do
if ((not isnull(WAUI_LNG)) and (not isnull(WAUI_LAT)))
return sprintf('\n ', WAUI_LNG, WAUI_LAT, BMK.WA.domain_name (domain_id));
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_content (
inout uri varchar)
{
declare content varchar;
declare hp any;
declare exit handler for sqlstate '*' {
--dbg_obj_print (__SQL_STATE, __SQL_MESSAGE);
return null;
};
declare N integer;
declare oldUri, newUri, reqHdr, resHdr varchar;
declare auth_uid, auth_pwd varchar;
newUri := uri;
reqHdr := null;
BMK.WA.account_access (auth_uid, auth_pwd);
reqHdr := sprintf ('Authorization: Basic %s', encode_base64 (auth_uid || ':' || auth_pwd));
_again:
N := N + 1;
oldUri := newUri;
commit work;
content := http_get (newUri, resHdr, 'GET', reqHdr);
if (resHdr[0] like 'HTTP/1._ 30_ %') {
newUri := http_request_header (resHdr, 'Location');
newUri := WS.WS.EXPAND_URL (oldUri, newUri);
if (N > 15)
return null;
if (newUri <> oldUri)
goto _again;
}
if (resHdr[0] like 'HTTP/1._ 4__ %' or resHdr[0] like 'HTTP/1._ 5__ %')
return null;
return (content);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.xslt_root()
{
declare sHost varchar;
sHost := cast(registry_get('_bookmark_path_') as varchar);
if (sHost = '0')
return 'file://apps/bookmark/xslt/';
if (isnull(strstr(sHost, '/DAV/VAD')))
return sprintf('file://%sxslt/', sHost);
return sprintf('virt://WS.WS.SYS_DAV_RES.RES_FULL_PATH.RES_CONTENT:%sxslt/', sHost);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.xslt_full(
in xslt_file varchar)
{
return concat(BMK.WA.xslt_root(), xslt_file);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_rss_sqlx_int(
in domain_id integer,
in account_id integer)
{
declare retValue any;
retValue := string_output ();
http ('\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
http ('))), \n', retValue);
http (' XMLELEMENT(\'description\', BMK.WA.utf2wide(BMK.WA.domain_description())), \n', retValue);
http (' XMLELEMENT(\'managingEditor\', U_E_MAIL), \n', retValue);
http (' XMLELEMENT(\'pubDate\', BMK.WA.dt_rfc1123(now())), \n', retValue);
http (' XMLELEMENT(\'generator\', \'Virtuoso Universal Server \' || sys_stat(\'st_dbms_ver\')), \n', retValue);
http (' XMLELEMENT(\'webMaster\', U_E_MAIL), \n', retValue);
http (' XMLELEMENT(\'link\', BMK.WA.bookmark_url()) \n', retValue);
http ('from DB.DBA.SYS_USERS where U_ID = \n', retValue);
http (']]>\n', retValue);
http (' and account_id = and item_id = B_ID), \n', retValue);
http (' XMLELEMENT(\'http://www.openlinksw.com/weblog/:modified\', BMK.WA.dt_iso8601 (BD_LAST_UPDATE)))) \n', retValue);
http ('from (select top 15 \n', retValue);
http (' BD_NAME, \n', retValue);
http (' BD_DESCRIPTION, \n', retValue);
http (' BD_LAST_UPDATE, \n', retValue);
http (' B_ID, \n', retValue);
http (' B_URI \n', retValue);
http (' from \n', retValue);
http (' BMK.WA.BOOKMARK, \n', retValue);
http (' BMK.WA.BOOKMARK_DOMAIN \n', retValue);
http (' where BD_BOOKMARK_ID = B_ID \n', retValue);
http (' and BD_DOMAIN_ID = \n', retValue);
http (' order by BD_LAST_UPDATE desc) x \n', retValue);
http (']]>\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
retValue := string_output_string (retValue);
retValue := replace(retValue, '', cast(account_id as varchar));
retValue := replace(retValue, '', cast(domain_id as varchar));
return retValue;
}
;
-- http (' XMLELEMENT(\'http://www.openlinksw.com/weblog/:modified\', BMK.WA.dt_iso8601 (EFI_PUBLISH_DATE)), \n', retValue);
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_rss_sqlx(
in domain_id integer,
in account_id integer)
{
declare retValue any;
retValue := BMK.WA.export_rss_sqlx_int(domain_id, account_id);
return replace (retValue, 'sql:xsl=""', '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_atom_sqlx(
in domain_id integer,
in account_id integer)
{
declare retValue, xsltTemplate any;
xsltTemplate := BMK.WA.xslt_full ('rss2atom03.xsl');
if (BMK.WA.settings_atomVersion (account_id) = '1.0')
xsltTemplate := BMK.WA.xslt_full ('rss2atom.xsl');
retValue := BMK.WA.export_rss_sqlx_int(domain_id, account_id);
return replace (retValue, 'sql:xsl=""', sprintf ('sql:xsl="%s"', xsltTemplate));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_rdf_sqlx(
in domain_id integer,
in account_id integer)
{
declare retValue any;
retValue := BMK.WA.export_rss_sqlx_int(domain_id, account_id);
return replace (retValue, 'sql:xsl=""', sprintf ('sql:xsl="%s"', BMK.WA.xslt_full ('rss2rdf.xsl')));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_ocs_sqlx(
in domain_id integer,
in account_id integer)
{
declare retValue any;
retValue := string_output ();
http ('\n', retValue);
http ('\n', retValue);
http ('', retValue);
http ('\n', retValue);
http (']]>\n', retValue);
http ('\n', retValue);
http (']]>\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
retValue := string_output_string (retValue);
retValue := replace(retValue, '', cast(account_id as varchar));
retValue := replace(retValue, '', cast(domain_id as varchar));
return retValue;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_opml_sqlx(
in domain_id integer,
in account_id integer)
{
declare retValue any;
retValue := string_output ();
http ('\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
http (']]>\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
http (']]>\n', retValue);
http ('\n', retValue);
http ('\n', retValue);
retValue := string_output_string (retValue);
retValue := replace(retValue, '', cast(account_id as varchar));
retValue := replace(retValue, '', cast(domain_id as varchar));
return retValue;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_opml_xml(
in domain_id integer,
in account_id integer)
{
declare aXML any;
aXML := (select XMLELEMENT ('opml', XMLATTRIBUTES('1.0' as 'version'), XMLELEMENT ('head'), XMLELEMENT ('body', XMLAGG (XMLELEMENT ('outline', XMLATTRIBUTES(BD_NAME as 'title', BD_NAME as 'text', 'rss' as 'type', B_URI as 'htmlUrl', B_URI as 'xmlUrl')))))
from BMK.WA.BOOKMARK_DOMAIN,
BMK.WA.BOOKMARK
where BD_BOOKMARK_ID = B_ID and BD_DOMAIN_ID = domain_id);
return aXML;
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.xml_set(
in id varchar,
inout pXml varchar,
in value varchar)
{
declare aEntity any;
{
declare exit handler for SQLSTATE '*' {
pXml := xtree_doc('');
goto _skip;
};
if (not isentity(pXml))
pXml := xtree_doc(pXml);
}
_skip:
aEntity := xpath_eval(sprintf ('/settings/entry[@ID = "%s"]', id), pXml);
if (not isnull(aEntity))
pXml := XMLUpdate(pXml, sprintf ('/settings/entry[@ID = "%s"]', id), null);
if (not is_empty_or_null(value)) {
aEntity := xpath_eval('/settings', pXml);
XMLAppendChildren(aEntity, xtree_doc(sprintf ('%s', id, BMK.WA.xml2string(value))));
}
return pXml;
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.xml_get(
in id varchar,
inout pXml varchar,
in defaultValue any := '')
{
declare value any;
declare exit handler for SQLSTATE '*' {return defaultValue;};
if (not isentity(pXml))
pXml := xtree_doc(pXml);
value := xpath_eval (sprintf ('string(/settings/entry[@ID = "%s"]/.)', id), pXml);
if (is_empty_or_null(value))
return defaultValue;
return BMK.WA.wide2utf(value);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.string2xml (
in content varchar,
in mode integer := 0)
{
if (mode = 0) {
declare exit handler for sqlstate '*' { goto _html; };
return xml_tree_doc (xml_tree (content, 0));
}
_html:;
return xml_tree_doc(xml_tree(content, 2, '', 'UTF-8'));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.xml2string(
in pXml any)
{
declare sStream any;
sStream := string_output();
http_value(pXml, null, sStream);
return string_output_string(sStream);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.normalize_space(
in S varchar)
{
return xpath_eval ('normalize-space (string(/a))', XMLELEMENT('a', S), 1);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.utfClear(
inout S varchar)
{
declare N integer;
declare retValue varchar;
retValue := '';
for (N := 0; N < length(S); N := N + 1) {
if (S[N] <= 31) {
retValue := concat(retValue, '?');
} else {
retValue := concat(retValue, chr(S[N]));
}
}
return retValue;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.utf2wide (
inout S any)
{
declare tmp any;
if (isstring (S)) {
tmp := charset_recode (S, 'UTF-8', '_WIDE_');
if (isinteger (tmp))
return S;
return tmp;
}
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.wide2utf (
in S any)
{
declare tmp any;
if (iswidestring (S)) {
tmp := charset_recode (S, '_WIDE_', 'UTF-8' );
if (isinteger (tmp))
return S;
return tmp;
}
return charset_recode (S, null, 'UTF-8' );
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.stringCut (
in S varchar,
in L integer := 60)
{
declare tmp any;
if (not L)
return S;
tmp := BMK.WA.utf2wide(S);
if (not iswidestring(tmp))
return S;
if (length(tmp) > L)
return BMK.WA.wide2utf(concat(subseq(tmp, 0, L-3), '...'));
return BMK.WA.wide2utf(tmp);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector_unique(
inout aVector any,
in minLength integer := 0)
{
declare aResult any;
declare N, M integer;
aResult := vector();
for (N := 0; N < length(aVector); N := N + 1) {
if ((minLength = 0) or (length(aVector[N]) >= minLength)) {
for (M := 0; M < length(aResult); M := M + 1)
if (trim(aResult[M]) = trim(aVector[N]))
goto _next;
aResult := vector_concat(aResult, vector(trim(aVector[N])));
}
_next:;
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector_except(
inout aVector any,
inout aExcept any)
{
declare aResult any;
declare N, M integer;
aResult := vector();
for (N := 0; N < length(aVector); N := N + 1) {
for (M := 0; M < length(aExcept); M := M + 1)
if (aExcept[M] = aVector[N])
goto _next;
aResult := vector_concat(aResult, vector(trim(aVector[N])));
_next:;
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector_contains(
inout aVector any,
in value varchar)
{
declare N integer;
for (N := 0; N < length(aVector); N := N + 1)
if (value = aVector[N])
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector_cut(
inout aVector any,
in value varchar)
{
declare N integer;
declare retValue any;
retValue := vector();
for (N := 0; N < length(aVector); N := N + 1)
if (value <> aVector[N])
retValue := vector_concat(retValue, vector(aVector[N]));
return retValue;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector_search(
in aVector any,
in value varchar,
in condition vrchar := 'AND')
{
declare N integer;
for (N := 0; N < length(aVector); N := N + 1)
if (value like concat('%', aVector[N], '%')) {
if (condition = 'OR')
return 1;
} else {
if (condition = 'AND')
return 0;
}
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector2str(
inout aVector any,
in delimiter varchar := ' ')
{
declare tmp, aResult any;
declare N integer;
aResult := '';
for (N := 0; N < length(aVector); N := N + 1) {
tmp := trim(aVector[N]);
if (strchr (tmp, ' ') is not null)
tmp := concat('''', tmp, '''');
if (N = 0) {
aResult := tmp;
} else {
aResult := concat(aResult, delimiter, tmp);
}
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector2rs(
inout aVector any)
{
declare N integer;
declare c0 varchar;
result_names(c0);
for (N := 0; N < length(aVector); N := N + 1)
result(aVector[N]);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tagsDictionary2rs(
inout aDictionary any)
{
declare N integer;
declare c0 varchar;
declare c1 integer;
declare V any;
V := dict_to_vector(aDictionary, 1);
result_names(c0, c1);
for (N := 1; N < length(V); N := N + 2)
result(V[N][0], V[N][1]);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.vector2src(
inout aVector any)
{
declare N integer;
declare aResult any;
aResult := 'vector(';
for (N := 0; N < length(aVector); N := N + 1) {
if (N = 0)
aResult := concat(aResult, '''', trim(aVector[N]), '''');
if (N <> 0)
aResult := concat(aResult, ', ''', trim(aVector[N]), '''');
}
return concat(aResult, ')');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.ft2vector(
in S any)
{
declare w varchar;
declare aResult any;
aResult := vector();
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', S, 1);
while (w is not null) {
w := trim (w, '"'' ');
if (upper(w) not in ('AND', 'NOT', 'NEAR', 'OR') and length (w) > 1 and not vt_is_noise (BMK.WA.wide2utf(w), 'utf-8', 'x-ViDoc'))
aResult := vector_concat(aResult, vector(w));
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', S, 1);
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.set_keyword(
in name varchar,
inout params any,
in value any)
{
declare N integer;
for (N := 0; N < length(params); N := N + 2)
if (params[N] = name) {
aset(params, N + 1, value);
goto _end;
}
params := vector_concat(params, vector(name, value));
_end:
return params;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bmk_tree2(
in domain_id integer,
in user_id integer,
in node varchar,
in path varchar)
{
declare node_type, node_id any;
node_id := BMK.WA.node_id(node);
node_type := BMK.WA.node_type(node);
if (node_type = 'r') {
if (node_id = 0)
return vector('Last Bookmarks', BMK.WA.make_node ('f', -1), BMK.WA.make_path('', 'f', -1));
if (node_id = 1)
return vector('Bookmarks', BMK.WA.make_node ('f', -1), BMK.WA.make_path(path, 'f', -1), 'Smart Folders', BMK.WA.make_node ('s', -1), BMK.WA.make_path(path, 's', -1));
if (node_id = 2)
return vector('Shared Bookmarks By', BMK.WA.make_node ('u', -1), BMK.WA.make_path(path, 'u', -1));
}
declare retValue any;
retValue := vector ();
if ((node_type = 'u') and (node_id = -1))
for (select distinct U_ID, U_NAME from BMK.WA.GRANTS, DB.DBA.SYS_USERS where G_GRANTEE_ID = user_id and G_GRANTER_ID = U_ID order by 2) do
retValue := vector_concat(retValue, vector(U_NAME, BMK.WA.make_node ('u', U_ID), BMK.WA.make_path(path, 'u', U_ID)));
if (node_type = 'f')
for (select F_ID, F_NAME from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and coalesce(F_PARENT_ID, -1) = coalesce(node_id, -1) order by 2) do
retValue := vector_concat(retValue, vector(F_NAME, BMK.WA.make_node ('f', F_ID), BMK.WA.make_path(path, 'f', F_ID)));
if ((node_type = 's') and (node_id = -1))
for (select SF_ID, SF_NAME from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id order by 2) do
retValue := vector_concat(retValue, vector(SF_NAME, BMK.WA.make_node ('s', SF_ID), BMK.WA.make_path(path, 's', SF_ID)));
if ((node_type = 'u') and (node_id >= 0))
for (select distinct F_ID, F_NAME from BMK.WA.FOLDER, BMK.WA.GRANTS where G_OBJECT_TYPE = 'F' and F_ID = G_OBJECT_ID and G_GRANTEE_ID = user_id and G_GRANTER_ID = node_id order by 2) do
retValue := vector_concat(retValue, vector(F_NAME, BMK.WA.make_node ('F', F_ID), BMK.WA.make_path(path, 'F', F_ID)));
if (node_type = 'F')
for (select F_ID, F_NAME from BMK.WA.FOLDER where F_PARENT_ID = node_id order by 2) do
retValue := vector_concat(retValue, vector(F_NAME, BMK.WA.make_node ('F', F_ID), BMK.WA.make_path(path, 'F', F_ID)));
return retValue;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bmk_node_has_childs (
in domain_id integer,
in user_id integer,
in node varchar,
in path varchar)
{
declare node_type, node_id any;
node_id := BMK.WA.node_id(node);
node_type := BMK.WA.node_type(node);
if ((node_type = 'u') and (node_id = -1))
if (exists (select 1 from BMK.WA.GRANTS, DB.DBA.SYS_USERS where G_GRANTEE_ID = user_id and G_GRANTER_ID = U_ID))
return 1;
if (node_type = 'f')
if (exists (select 1 from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and coalesce(F_PARENT_ID, -1) = coalesce(node_id, -1)))
return 1;
if ((node_type = 's') and (node_id = -1))
if (exists (select 1 from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id))
return 1;
if ((node_type = 'u') and (node_id >= 0))
if (exists (select 1 from BMK.WA.FOLDER, BMK.WA.GRANTS where G_OBJECT_TYPE = 'F' and F_ID = G_OBJECT_ID and G_GRANTEE_ID = user_id and G_GRANTER_ID = node_id))
return 1;
if (node_type = 'F')
if (exists (select 1 from BMK.WA.FOLDER where F_PARENT_ID = node_id))
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bmk_path2_int(
in node varchar,
in root_id integer,
inout path varchar)
{
declare node_type, node_id any;
node_id := BMK.WA.node_id(node);
node_type := BMK.WA.node_type(node);
if ((lcase(node_type) = 'f') and (node_id <> 0))
for (select F_PARENT_ID from BMK.WA.FOLDER where F_ID = node_id) do {
path := sprintf('%s/%s', BMK.WA.make_node (node_type, coalesce(F_PARENT_ID, -1)), path);
if (coalesce(F_PARENT_ID, 0) <> root_id)
BMK.WA.bmk_path2_int(BMK.WA.make_node (node_type, coalesce(F_PARENT_ID, -1)), root_id, path);
}
if ((node_type = 's') and (node_id >= 0))
path := sprintf('%s/%s', BMK.WA.make_node (node_type, -1), path);
if ((node_type = 'u') and (node_id >= 0))
path := sprintf('%s/%s', BMK.WA.make_node (node_type, -1), path);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bmk_path2 (
in node varchar,
in grant_id integer)
{
declare user_id, root_id any;
declare path any;
path := node;
root_id := 0;
for (select G_GRANTER_ID, G_OBJECT_TYPE, G_OBJECT_ID from BMK.WA.GRANTS where G_ID = grant_id) do {
if (G_OBJECT_TYPE = 'F')
root_id := G_OBJECT_ID;
user_id := G_GRANTER_ID;
}
BMK.WA.bmk_path2_int(node, root_id, path);
if (root_id)
path := BMK.WA.make_node ('u', -1) || '/' || BMK.WA.make_node ('u', user_id) || '/' || path;
return '/' || path;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.make_node (
in node_type varchar,
in node_id any)
{
return node_type || '#' || cast(node_id as varchar);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.make_path (
in path varchar,
in node_type varchar,
in node_id any)
{
return path || '/' || BMK.WA.make_node (node_type, node_id);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.node_type(
in code varchar)
{
if ((length(code) > 1) and (substring(code,2,1) = '#'))
return left(code, 1);
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.node_id (
in node varchar)
{
declare exit handler for sqlstate '*' { return -1; };
if ((length(node) > 2) and (substring(node,2,1) = '#'))
return cast(subseq(node, 2) as integer);
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.node_suffix (
in node varchar)
{
if ((length(node) > 2) and (substring(node,2,1) = '#'))
return subseq(node, 2);
return '';
}
;
-------------------------------------------------------------------------------
--
-- Show functions
--
-------------------------------------------------------------------------------
--
create procedure BMK.WA.show_text(
in S any,
in S2 any)
{
if (isstring(S))
S := trim(S);
if (is_empty_or_null(S))
return sprintf('~ no %s ~', S2);
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.show_title(
in S any)
{
return BMK.WA.show_text(S, 'title');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.show_author(
in S any)
{
return BMK.WA.show_text(S, 'author');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.show_description(
in S any)
{
return BMK.WA.show_text(S, 'description');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.show_excerpt(
in S varchar,
in words varchar)
{
return coalesce(search_excerpt (words, cast(S as varchar)), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dashboard_get(
in domain_id integer,
in user_id integer)
{
declare ses any;
ses := string_output ();
http ('', ses);
for select top 10 *
from (select a.BD_NAME,
b.B_URI,
a.BD_LAST_UPDATE
from BMK.WA.BOOKMARK_DOMAIN a,
BMK.WA.BOOKMARK b,
DB.DBA.WA_INSTANCE c,
DB.DBA.WA_MEMBER d
where a.BD_BOOKMARK_ID = b.B_ID
and a.BD_DOMAIN_ID = domain_id
and d.WAM_USER = user_id
and d.WAM_INST = C.WAI_NAME
and c.WAI_ID = a.BD_DOMAIN_ID
order by BD_LAST_UPDATE desc
) x do {
declare uname, full_name varchar;
uname := (select coalesce (U_NAME, '') from DB.DBA.SYS_USERS where U_ID = user_id);
full_name := (select coalesce (coalesce (U_FULL_NAME, U_NAME), '') from DB.DBA.SYS_USERS where U_ID = user_id);
http ('', ses);
http (sprintf ('
%s
', date_iso8601 (BD_LAST_UPDATE)), ses);
http (sprintf ('', BD_NAME), ses);
http (sprintf ('', B_URI), ses);
http (sprintf ('', full_name), ses);
http (sprintf ('%s', uname), ses);
http ('', ses);
}
http ('', ses);
return string_output_string (ses);
}
;
-------------------------------------------------------------------------------
--
-- Date / Time functions
--
-------------------------------------------------------------------------------
-- returns system time in GMT
--
create procedure BMK.WA.dt_current_time()
{
return dateadd('minute', - timezone(now()),now());
}
;
-------------------------------------------------------------------------------
--
-- convert from GMT date to user timezone;
--
create procedure BMK.WA.dt_gmt2user(
in pDate datetime,
in pUser varchar := null)
{
declare tz integer;
if (isnull(pDate))
return null;
if (isnull(pUser))
pUser := connection_get('owner_user');
if (isnull(pUser))
pUser := connection_get('vspx_user');
if (isnull(pUser))
return pDate;
tz := cast(coalesce(USER_GET_OPTION(pUser, 'TIMEZONE'), timezone(now())/60) as integer) * 60;
return dateadd('minute', tz, pDate);
}
;
-------------------------------------------------------------------------------
--
-- convert from the user timezone to GMT date
--
create procedure BMK.WA.dt_user2gmt(
in pDate datetime,
in pUser varchar := null)
{
declare tz integer;
if (isnull(pDate))
return null;
if (isnull(pUser))
pUser := connection_get('owner_user');
if (isnull(pUser))
pUser := connection_get('vspx_user');
if (isnull(pUser))
return pDate;
tz := cast(coalesce(USER_GET_OPTION(pUser, 'TIMEZONE'), 0) as integer) * 60;
return dateadd('minute', -tz, pDate);
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dt_value(
in pDate datetime,
in pUser datetime := null)
{
if (isnull(pDate))
return pDate;
pDate := BMK.WA.dt_gmt2user(pDate, pUser);
if (BMK.WA.dt_format(pDate, 'D.M.Y') = BMK.WA.dt_format(now(), 'D.M.Y'))
return concat('today ', BMK.WA.dt_format(pDate, 'H:N'));
return BMK.WA.dt_format(pDate, 'D.M.Y H:N');
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dt_format(
in pDate datetime,
in pFormat varchar := 'd.m.Y')
{
declare
N integer;
declare
ch,
S varchar;
S := '';
N := 1;
while (N <= length(pFormat))
{
ch := substring(pFormat, N, 1);
if (ch = 'M')
{
S := concat(S, xslt_format_number(month(pDate), '00'));
} else {
if (ch = 'm')
{
S := concat(S, xslt_format_number(month(pDate), '##'));
} else
{
if (ch = 'Y')
{
S := concat(S, xslt_format_number(year(pDate), '0000'));
} else
{
if (ch = 'y')
{
S := concat(S, substring(xslt_format_number(year(pDate), '0000'),3,2));
} else {
if (ch = 'd')
{
S := concat(S, xslt_format_number(dayofmonth(pDate), '##'));
} else
{
if (ch = 'D')
{
S := concat(S, xslt_format_number(dayofmonth(pDate), '00'));
} else
{
if (ch = 'H')
{
S := concat(S, xslt_format_number(hour(pDate), '00'));
} else
{
if (ch = 'h')
{
S := concat(S, xslt_format_number(hour(pDate), '##'));
} else
{
if (ch = 'N')
{
S := concat(S, xslt_format_number(minute(pDate), '00'));
} else
{
if (ch = 'n')
{
S := concat(S, xslt_format_number(minute(pDate), '##'));
} else
{
if (ch = 'S')
{
S := concat(S, xslt_format_number(second(pDate), '00'));
} else
{
if (ch = 's')
{
S := concat(S, xslt_format_number(second(pDate), '##'));
} else
{
S := concat(S, ch);
};
};
};
};
};
};
};
};
};
};
};
};
N := N + 1;
};
return S;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.dt_deformat(
in pString varchar,
in pFormat varchar := 'd.m.Y')
{
declare
y,
m,
d integer;
declare
N,
I integer;
declare
ch varchar;
N := 1;
I := 0;
d := 0;
m := 0;
y := 0;
while (N <= length(pFormat)) {
ch := upper(substring(pFormat, N, 1));
if (ch = 'M')
m := BMK.WA.dt_deformat_tmp(pString, I);
if (ch = 'D')
d := BMK.WA.dt_deformat_tmp(pString, I);
if (ch = 'Y') {
y := BMK.WA.dt_deformat_tmp(pString, I);
if (y < 50)
y := 2000 + y;
if (y < 100)
y := 1900 + y;
};
N := N + 1;
};
return stringdate(concat(cast(m as varchar), '.', cast(d as varchar), '.', cast(y as varchar)));
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dt_deformat_tmp(
in S varchar,
inout N varchar)
{
declare
V any;
V := regexp_parse('[0-9]+', S, N);
if (length(V) > 1) {
N := aref(V,1);
return atoi(subseq(S, aref(V, 0), aref(V,1)));
};
N := N + 1;
return 0;
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.dt_reformat(
in pString varchar,
in pInFormat varchar := 'd.m.Y',
in pOutFormat varchar := 'm.d.Y')
{
return BMK.WA.dt_format(BMK.WA.dt_deformat(pString, pInFormat), pOutFormat);
};
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.dt_convert(
in pString varchar,
in pDefault any := null)
{
declare exit handler for sqlstate '*' { goto _next; };
return stringdate(pString);
_next:
declare exit handler for sqlstate '*' { goto _end; };
return http_string_date(pString);
_end:
return pDefault;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.dt_rfc1123 (
in dt datetime)
{
return soap_print_box (dt, '', 1);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.dt_iso8601 (
in dt datetime)
{
return soap_print_box (dt, '', 0);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.data (
in data any)
{
--data := deserialize(blob_to_string(data));
--if (is_empty_or_null(data))
-- return vector();
return data;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.test_clear (
in S any)
{
declare N integer;
return substring(S, 1, coalesce(strstr(S, '<>'), length(S)));
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.test (
in value any,
in params any := null)
{
declare valueType, valueClass, valueName, valueMessage, tmp any;
declare exit handler for SQLSTATE '*' {
if (not is_empty_or_null(valueMessage))
signal ('TEST', valueMessage);
if (__SQL_STATE = 'EMPTY')
signal ('TEST', sprintf('Field ''%s'' cannot be empty!<>', valueName));
if (__SQL_STATE = 'CLASS') {
if (valueType in ('free-text', 'tags')) {
signal ('TEST', sprintf('Field ''%s'' contains invalid characters or noise words!<>', valueName));
} else {
signal ('TEST', sprintf('Field ''%s'' contains invalid characters!<>', valueName));
}
}
if (__SQL_STATE = 'TYPE')
signal ('TEST', sprintf('Field ''%s'' contains invalid characters for \'%s\'!<>', valueName, valueType));
if (__SQL_STATE = 'MIN')
signal ('TEST', sprintf('''%s'' value should be greater then %s!<>', valueName, cast(tmp as varchar)));
if (__SQL_STATE = 'MAX')
signal ('TEST', sprintf('''%s'' value should be less then %s!<>', valueName, cast(tmp as varchar)));
if (__SQL_STATE = 'MINLENGTH')
signal ('TEST', sprintf('The length of field ''%s'' should be greater then %s characters!<>', valueName, cast(tmp as varchar)));
if (__SQL_STATE = 'MAXLENGTH')
signal ('TEST', sprintf('The length of field ''%s'' should be less then %s characters!<>', valueName, cast(tmp as varchar)));
signal ('TEST', 'Unknown validation error!<>');
--resignal;
};
value := trim(value);
if (is_empty_or_null(params))
return value;
valueClass := coalesce(get_keyword('class', params), get_keyword('type', params));
valueType := coalesce(get_keyword('type', params), get_keyword('class', params));
valueName := get_keyword('name', params, 'Field');
valueMessage := get_keyword('message', params, '');
tmp := get_keyword('canEmpty', params);
if (isnull(tmp)) {
if (not isnull(get_keyword('minValue', params))) {
tmp := 0;
} else if (get_keyword('minLength', params, 0) <> 0) {
tmp := 0;
}
}
if (not isnull(tmp) and (tmp = 0) and is_empty_or_null(value)) {
signal('EMPTY', '');
} else if (is_empty_or_null(value)) {
return value;
}
value := BMK.WA.validate2 (valueClass, value);
if (valueType = 'integer') {
tmp := get_keyword('minValue', params);
if ((not isnull(tmp)) and (value < tmp))
signal('MIN', cast(tmp as varchar));
tmp := get_keyword('maxValue', params);
if (not isnull(tmp) and (value > tmp))
signal('MAX', cast(tmp as varchar));
} else if (valueType = 'float') {
tmp := get_keyword('minValue', params);
if (not isnull(tmp) and (value < tmp))
signal('MIN', cast(tmp as varchar));
tmp := get_keyword('maxValue', params);
if (not isnull(tmp) and (value > tmp))
signal('MAX', cast(tmp as varchar));
} else if (valueType = 'varchar') {
tmp := get_keyword('minLength', params);
if (not isnull(tmp) and (length(BMK.WA.utf2wide(value)) < tmp))
signal('MINLENGTH', cast(tmp as varchar));
tmp := get_keyword('maxLength', params);
if (not isnull(tmp) and (length(BMK.WA.utf2wide(value)) > tmp))
signal('MAXLENGTH', cast(tmp as varchar));
}
return value;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate2 (
in propertyType varchar,
in propertyValue varchar)
{
declare exit handler for SQLSTATE '*' {
if (__SQL_STATE = 'CLASS')
resignal;
signal('TYPE', propertyType);
return;
};
if (propertyType = 'boolean') {
if (propertyValue not in ('Yes', 'No'))
goto _error;
} else if (propertyType = 'integer') {
if (isnull(regexp_match('^[0-9]+\$', propertyValue)))
goto _error;
return cast(propertyValue as integer);
} else if (propertyType = 'float') {
if (isnull(regexp_match('^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?\$', propertyValue)))
goto _error;
return cast(propertyValue as float);
} else if (propertyType = 'dateTime') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
goto _error;
return cast(propertyValue as datetime);
} else if (propertyType = 'dateTime2') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
goto _error;
return cast(propertyValue as datetime);
} else if (propertyType = 'date') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])\$', propertyValue)))
goto _error;
return cast(propertyValue as datetime);
} else if (propertyType = 'date2') {
if (isnull(regexp_match('^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((?:19|20)[0-9][0-9])\$', propertyValue)))
goto _error;
return stringdate(BMK.WA.dt_reformat(propertyValue, 'd.m.Y', 'Y-M-D'));
} else if (propertyType = 'time') {
if (isnull(regexp_match('^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
goto _error;
return cast(propertyValue as time);
} else if (propertyType = 'folder') {
if (isnull(regexp_match('^[^\\\/\?\*\"\'\>\<\:\|]*\$', propertyValue)))
goto _error;
} else if ((propertyType = 'uri') or (propertyType = 'anyuri')) {
if (isnull(regexp_match('^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_=:]*)?\$', propertyValue)))
goto _error;
} else if (propertyType = 'email') {
if (isnull(regexp_match('^([a-zA-Z0-9_\-])+(\.([a-zA-Z0-9_\-])+)*@((\[(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5])))\.(((([0-1])?([0-9])?[0-9])|(2[0-4][0-9])|(2[0-5][0-5]))\]))|((([a-zA-Z0-9])+(([\-])+([a-zA-Z0-9])+)*\.)+([a-zA-Z])+(([\-])+([a-zA-Z0-9])+)*))\$', propertyValue)))
goto _error;
} else if (propertyType = 'free-text') {
if (length(propertyValue))
if (not BMK.WA.validate_freeTexts(propertyValue))
goto _error;
} else if (propertyType = 'free-text-expression') {
if (length(propertyValue))
if (not BMK.WA.validate_freeText(propertyValue))
goto _error;
} else if (propertyType = 'tags') {
if (not BMK.WA.validate_tags(propertyValue))
goto _error;
}
return propertyValue;
_error:
signal('CLASS', propertyType);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate (
in propertyType varchar,
in propertyValue varchar,
in propertyEmpty integer := 1)
{
if (is_empty_or_null(propertyValue))
return propertyEmpty;
declare tmp any;
declare exit handler for SQLSTATE '*' {return 0;};
if (propertyType = 'boolean') {
if (propertyValue not in ('Yes', 'No'))
return 0;
} else if (propertyType = 'integer') {
if (isnull(regexp_match('^[0-9]+\$', propertyValue)))
return 0;
tmp := cast(propertyValue as integer);
} else if (propertyType = 'float') {
if (isnull(regexp_match('^[-+]?([0-9]*\.)?[0-9]+([eE][-+]?[0-9]+)?\$', propertyValue)))
return 0;
tmp := cast(propertyValue as float);
} else if (propertyType = 'dateTime') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
return 0;
} else if (propertyType = 'dateTime2') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]) ([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
return 0;
} else if (propertyType = 'date') {
if (isnull(regexp_match('^((?:19|20)[0-9][0-9])[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])\$', propertyValue)))
return 0;
} else if (propertyType = 'date2') {
if (isnull(regexp_match('^(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((?:19|20)[0-9][0-9])\$', propertyValue)))
return 0;
} else if (propertyType = 'time') {
if (isnull(regexp_match('^([01]?[0-9]|[2][0-3])(:[0-5][0-9])?\$', propertyValue)))
return 0;
} else if (propertyType = 'folder') {
if (isnull(regexp_match('^[^\\\/\?\*\"\'\>\<\:\|]*\$', propertyValue)))
return 0;
} else if (propertyType = 'uri') {
if (isnull(regexp_match('^(ht|f)tp(s?)\:\/\/[0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*(:(0-9)*)*(\/?)([a-zA-Z0-9\-\.\?\,\'\/\\\+&%\$#_]*)?\$', propertyValue)))
return 0;
}
return 1;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate_freeText (
in S varchar)
{
declare st, msg varchar;
if (upper(S) in ('AND', 'NOT', 'NEAR', 'OR'))
return 0;
if (length (S) < 2)
return 0;
if (vt_is_noise (BMK.WA.wide2utf(S), 'utf-8', 'x-ViDoc'))
return 0;
st := '00000';
exec ('vt_parse (?)', st, msg, vector (S));
if (st <> '00000')
return 0;
return 1;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate_freeTexts (
in S any)
{
declare w varchar;
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', S, 1);
while (w is not null) {
w := trim (w, '"'' ');
if (not BMK.WA.validate_freeText(w))
return 0;
w := regexp_match ('["][^"]+["]|[''][^'']+['']|[^"'' ]+', S, 1);
}
return 1;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate_tag (
in S varchar)
{
S := replace(trim(S), '+', '_');
S := replace(trim(S), ' ', '_');
if (not BMK.WA.validate_freeText(S))
return 0;
if (not isnull(strstr(S, '"')))
return 0;
if (not isnull(strstr(S, '''')))
return 0;
if (length(S) < 2)
return 0;
if (length(S) > 50)
return 0;
return 1;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.validate_tags (
in S varchar)
{
declare N integer;
declare V any;
if (is_empty_or_null(S))
return 1;
V := BMK.WA.tags2vector(S);
if (is_empty_or_null(V))
return 0;
if (length(V) <> length(BMK.WA.tags2unique(V)))
return 0;
for (N := 0; N < length(V); N := N + 1)
if (not BMK.WA.validate_tag(V[N]))
return 0;
return 1;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.version_update()
{
for (select WAI_ID, WAM_USER
from DB.DBA.WA_MEMBER
join DB.DBA.WA_INSTANCE on WAI_NAME = WAM_INST
where WAI_TYPE_NAME = 'Bookmark'
and WAM_MEMBER_TYPE = 1) do {
BMK.WA.domain_update(WAI_ID, WAM_USER);
}
}
;
-----------------------------------------------------------------------------------------
--
BMK.WA.version_update()
;
¶ bookmark/sql/bmk-a-ods.sqlß ã--
-- $Id: bmk-a-ods.sql,v 1.1 2006/10/18 11:05:05 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
create function DB.DBA.wa_search_bmk_get_excerpt_html (
in _current_user_id integer,
in _BD_BOOKMARK_ID int,
in _BD_DOMAIN_ID int,
in _BD_NAME varchar,
in _BD_DESCRIPTION varchar,
in words any) returns varchar
{
declare url varchar;
declare res varchar;
select B_URI into url from BMK.WA.BOOKMARK where B_ID = _BD_BOOKMARK_ID;
res := sprintf ('%s %s ', WA_SEARCH_ADD_APATH ('images/icons/web_16.png'), url, _BD_NAME, _BD_NAME);
res := res ||
' ' ||
left (
search_excerpt (
words,
subseq (coalesce (_BD_DESCRIPTION, ''), 0, 200000)
), 900) ||
'';
return res;
}
;
create procedure DB.DBA.wa_collect_bmk_tags (in id integer)
{
for (select BD_TAGS from BMK.WA.BOOKMARK_DATA) do
wa_add_tag_to_count (BD_TAGS, id);
}
;
¶ bookmark/sql/bmk-a-table.sqlß =f--
-- $Id: bmk-a-table.sql,v 1.19 2007/02/14 10:45:13 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
-------------------------------------------------------------------------------
--
-- Conatins all subscribed feeds
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.BOOKMARK (
B_ID integer identity,
B_URI varchar not null,
B_NAME varchar,
B_DESCRIPTION varchar,
B_CREATED datetime,
B_LAST_VISITED datetime,
primary key (B_ID)
)
');
BMK.WA.exec_no_error(
'alter table BMK.WA.BOOKMARK add B_CREATED datetime', 'C', 'BMK.WA.BOOKMARK', 'B_CREATED'
);
BMK.WA.exec_no_error('
create unique index SK_BOOKMARK_01 on BMK.WA.BOOKMARK(B_URI)
');
-------------------------------------------------------------------------------
--
-- Conatins folders structure. Structure is domain specific.
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.FOLDER (
F_ID integer identity,
F_DOMAIN_ID integer not null,
F_PARENT_ID integer,
F_NAME varchar not null,
F_PATH varchar(1000) not null,
primary key (F_ID)
)
');
BMK.WA.exec_no_error(
'alter table BMK.WA.FOLDER add F_PATH varchar(1000)', 'C', 'BMK.WA.FOLDER', 'F_PATH'
);
BMK.WA.exec_no_error('
create unique index SK_FOLDER_01 on BMK.WA.FOLDER(F_DOMAIN_ID, F_PARENT_ID, F_NAME)
');
BMK.WA.exec_no_error('
create index SK_FOLDER_02 on BMK.WA.FOLDER(F_DOMAIN_ID, F_PATH)
');
BMK.WA.exec_no_error('
create trigger FOLDER_AI after insert on BMK.WA.FOLDER referencing new as N {
declare domain_id, folder_id integer;
declare path varchar;
domain_id := N.F_DOMAIN_ID;
folder_id := N.F_ID;
path := coalesce((select F_PATH from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_ID = N.F_PARENT_ID), \'\');
path := path || \'/\' || N.F_NAME;
set triggers off;
update BMK.WA.FOLDER
set F_PATH = path
where F_DOMAIN_ID = domain_id
and F_ID = folder_id;
BMK.WA.folder_paths (domain_id, folder_id, path);
set triggers on;
}
');
BMK.WA.exec_no_error('
create trigger FOLDER_AU after update on BMK.WA.FOLDER referencing old as O, new as N {
if ((N.F_NAME <> O.F_NAME) or isnull(O.F_PATH)) {
declare domain_id, folder_id integer;
declare path varchar;
domain_id := N.F_DOMAIN_ID;
folder_id := N.F_ID;
path := coalesce((select F_PATH from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_ID = N.F_PARENT_ID), \'\');
path := path || \'/\' || N.F_NAME;
set triggers off;
update BMK.WA.FOLDER
set F_PATH = path
where F_DOMAIN_ID = domain_id
and F_ID = folder_id;
BMK.WA.folder_paths (domain_id, folder_id, path);
set triggers on;
}
}
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_paths(
in domain_id integer,
in parent_id integer,
in path varchar)
{
declare folder_id integer;
declare name varchar;
for (select F_NAME, F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_PARENT_ID = parent_id) do {
folder_id := F_ID;
name := F_NAME;
update BMK.WA.FOLDER
set F_PATH = path || '/' || name
where F_DOMAIN_ID = domain_id
and F_ID = folder_id;
BMK.WA.folder_paths(domain_id, folder_id, path || '/' || name);
}
}
;
-------------------------------------------------------------------------------
--
-- Conatins smart folders structure. Structure is domain specific.
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.SFOLDER (
SF_ID integer identity,
SF_DOMAIN_ID integer not null,
SF_NAME varchar not null,
SF_DATA long varchar,
primary key (SF_ID)
)
');
BMK.WA.exec_no_error('
create unique index SK_SFOLDER_01 on BMK.WA.SFOLDER(SF_DOMAIN_ID, SF_NAME)
');
-------------------------------------------------------------------------------
--
-- Conatins domain feeds.
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.BOOKMARK_DOMAIN (
BD_ID integer identity,
BD_DOMAIN_ID integer not null,
BD_BOOKMARK_ID integer not null,
BD_FOLDER_ID integer,
BD_NAME varchar,
BD_DESCRIPTION varchar,
BD_CREATED datetime,
BD_LAST_UPDATE datetime,
constraint FK_BOOKMARK_DOMAIN_01 FOREIGN KEY (BD_BOOKMARK_ID) references BMK.WA.BOOKMARK (B_ID) on delete cascade,
constraint FK_BOOKMARK_DOMAIN_02 FOREIGN KEY (BD_FOLDER_ID) references BMK.WA.FOLDER (F_ID) on delete set null,
primary key (BD_ID)
)
');
BMK.WA.exec_no_error(
'alter table BMK.WA.BOOKMARK_DOMAIN add BD_CREATED datetime', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_CREATED'
);
BMK.WA.exec_no_error('
drop index SK_BOOKMARK_DOMAIN_01 BMK.WA.BOOKMARK_DOMAIN
');
BMK.WA.exec_no_error('
create index SK_BOOKMARK_DOMAIN_01 on BMK.WA.BOOKMARK_DOMAIN(BD_DOMAIN_ID, BD_BOOKMARK_ID)
');
BMK.WA.exec_no_error ('
create trigger BOOKMARK_DOMAIN_WA_AI after insert on BMK.WA.BOOKMARK_DOMAIN referencing new as N {
BMK.WA.domain_ping (N.BD_DOMAIN_ID);
if (__proc_exists (\'DB.DBA.WA_NEW_BOOKMARKS_IN\'))
if (exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = N.BD_DOMAIN_ID and WAI_IS_PUBLIC = 1))
DB.DBA.WA_NEW_BOOKMARKS_IN (N.BD_NAME, sprintf(\'/bookmark/bookmarks.vspx?location=%d\', N.BD_ID), N.BD_ID);
}
');
BMK.WA.exec_no_error ('
create trigger BOOKMARK_DOMAIN_WA_AU after update on BMK.WA.BOOKMARK_DOMAIN referencing new as N {
BMK.WA.domain_ping (N.BD_DOMAIN_ID);
if (__proc_exists (\'DB.DBA.WA_NEW_BOOKMARKS_IN\'))
if (exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = N.BD_DOMAIN_ID and WAI_IS_PUBLIC = 1))
DB.DBA.WA_NEW_BOOKMARKS_IN (N.BD_NAME, sprintf(\'/bookmark/bookmarks.vspx?location=%d\', N.BD_ID), N.BD_ID);
}
');
BMK.WA.exec_no_error ('
create trigger BOOKMARK_DOMAIN_WA_AD after delete on BMK.WA.BOOKMARK_DOMAIN referencing old as O {
if (__proc_exists (\'DB.DBA.WA_NEW_BOOKMARKS_RM\'))
DB.DBA.WA_NEW_BOOKMARKS_RM (O.BD_ID);
}
');
-------------------------------------------------------------------------------
--
-- Conatins specific data for feed items and domain/user - flags, tags and etc.
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.BOOKMARK_DATA (
BD_ID integer identity,
BD_MODE integer,
BD_OBJECT_ID integer,
BD_BOOKMARK_ID integer not null,
BD_READ_FLAG integer,
BD_TAGS varchar,
BD_LAST_UPDATE datetime,
BD_VISITED integer default 0,
BD_LAST_VISITED datetime,
constraint FK_BOOKMARK_DATA_01 FOREIGN KEY (BD_BOOKMARK_ID) references BMK.WA.BOOKMARK (B_ID) on delete cascade,
primary key (BD_ID)
)
');
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DATA add BD_READ_FLAG integer', 'C', 'BMK.WA.BOOKMARK_DATA', 'BD_READ_FLAG'
);
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DATA add BD_VISITED integer default 0', 'C', 'BMK.WA.BOOKMARK_DATA', 'BD_VISITED'
);
BMK.WA.exec_no_error('
create index SK_BOOKMARK_DATA_01 on BMK.WA.BOOKMARK_DATA(BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID)
');
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error('
create table BMK.WA.TAGS (
T_DOMAIN_ID integer not null,
T_ACCOUNT_ID integer not null,
T_TAG varchar,
T_COUNT integer,
T_LAST_UPDATE datetime,
primary key (T_DOMAIN_ID, T_ACCOUNT_ID, T_TAG)
)
');
create procedure BMK.WA.TAGS_STATISTICS (
in domain_id integer,
in account_id integer)
{
declare ts_tag varchar;
declare ts_count integer;
BMK.WA.tags_refresh (domain_id, account_id, 1);
result_names (ts_tag, ts_count);
for (select T_TAG, T_COUNT FROM BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_ACCOUNT_ID = account_id) do
result (T_TAG, T_COUNT);
}
;
BMK.WA.exec_no_error('
create procedure view BMK..TAGS_STATISTICS as BMK.WA.TAGS_STATISTICS (domain_id, account_id) (TS_TAG varchar, TS_COUNT integer)
');
-------------------------------------------------------------------------------
--
-- Conatins settings
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.SETTINGS (
S_ACCOUNT_ID integer not null,
S_DATA varchar,
primary key(S_ACCOUNT_ID)
)
');
-------------------------------------------------------------------------------
--
-- Conatins sharings
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error ('
create table BMK.WA.GRANTS (
G_ID integer identity,
G_GRANTER_ID integer not null,
G_GRANTEE_ID integer not null,
G_TYPE char(1) not null,
G_OBJECT_TYPE char(1) not null,
G_OBJECT_ID integer not null,
PRIMARY KEY (G_ID)
)
');
BMK.WA.exec_no_error('
create index SK_GRANTS_01 on BMK.WA.GRANTS (G_GRANTER_ID, G_OBJECT_TYPE, G_OBJECT_ID)
');
BMK.WA.exec_no_error('
create index SK_GRANTS_02 on BMK.WA.GRANTS (G_GRANTEE_ID, G_OBJECT_TYPE, G_OBJECT_ID)
');
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error('
drop table BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_WORDS
');
BMK.WA.exec_no_error('
create text index on BMK.WA.BOOKMARK_DOMAIN(BD_DESCRIPTION) with key BD_ID not insert clustered with (BD_ID) using function
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_index_hook (inout vtb any, inout d_id any)
{
return BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_int (vtb, d_id, 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_unindex_hook (inout vtb any, inout d_id any)
{
return BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_int (vtb, d_id, 1);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_int (inout vtb any, inout d_id any, in mode any)
{
for (select BD_DOMAIN_ID, BD_BOOKMARK_ID, BD_NAME, BD_DESCRIPTION from BMK.WA.BOOKMARK_DOMAIN where BD_ID = d_id) do {
vt_batch_feed (vtb, sprintf('^R%d', BD_DOMAIN_ID), mode);
vt_batch_feed (vtb, coalesce(BD_NAME, ''), mode);
vt_batch_feed (vtb, coalesce(BD_DESCRIPTION, ''), mode);
if (exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = BD_DOMAIN_ID and WAI_TYPE_NAME = 'bookmark' and WAI_IS_PUBLIC = 1))
vt_batch_feed (vtb, '^public', mode);
vt_batch_feed_offband (vtb, serialize (vector (d_id, BD_BOOKMARK_ID)), mode);
}
return 1;
}
;
BMK.WA.vt_index_BMK_WA_BOOKMARK_DOMAIN();
DB.DBA.vt_batch_update('BMK.WA.BOOKMARK_DOMAIN', 'off', null);
BMK.WA.exec_no_error('
drop table BMK.WA.BOOKMARK_DATA_BD_TAGS_WORDS
');
BMK.WA.exec_no_error('
create text index on BMK.WA.BOOKMARK_DATA (BD_TAGS) with key BD_ID not insert clustered with (BD_ID, BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID) using function language \'x-ViDoc\'
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DATA_BD_TAGS_index_hook (inout vtb any, inout d_id any)
{
return BMK.WA.BOOKMARK_DATA_BD_TAGS_int(vtb, d_id, 0);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DATA_BD_TAGS_unindex_hook (inout vtb any, inout d_id any)
{
return BMK.WA.BOOKMARK_DATA_BD_TAGS_int(vtb, d_id, 1);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.BOOKMARK_DATA_BD_TAGS_int (inout vtb any, inout d_id any, in mode any)
{
declare tags any;
for (select BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID, BD_TAGS from BMK.WA.BOOKMARK_DATA where BD_ID = d_id) do {
tags := split_and_decode (BD_TAGS, 0, '\0\0,');
foreach (any tag in tags) do {
tag := trim(tag);
tag := replace (tag, ' ', '_');
tag := replace (tag, '+', '_');
vt_batch_feed (vtb, tag, mode);
}
if (BD_MODE = 0) {
if (exists(select 1 from DB.DBA.WA_INSTANCE where WAI_ID = BD_OBJECT_ID and WAI_TYPE_NAME = 'bookmark' and WAI_IS_PUBLIC = 1))
vt_batch_feed (vtb, '^public', mode);
vt_batch_feed (vtb, sprintf ('^R%d', BD_OBJECT_ID), mode);
} else {
vt_batch_feed (vtb, sprintf ('^UID%d', BD_OBJECT_ID), mode);
}
vt_batch_feed (vtb, sprintf ('^I%d', BD_BOOKMARK_ID), mode);
vt_batch_feed_offband (vtb, serialize (vector (d_id, BD_MODE, BD_OBJECT_ID, BD_BOOKMARK_ID)), mode);
}
return 1;
}
;
BMK.WA.vt_index_BMK_WA_BOOKMARK_DATA();
DB.DBA.vt_batch_update('BMK.WA.BOOKMARK_DATA', 'off', null);
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error('
create trigger WA_MEMBER_AU_BMK AFTER UPDATE ON DB.DBA.WA_MEMBER order 20 referencing old as O, new as N {
declare domain_id, account_id integer;
if ((O.WAM_INST <> N.WAM_INST) and (N.WAM_MEMBER_TYPE = 1)) {
account_id := N.WAM_USER;
domain_id := (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = N.WAM_INST);
BMK.WA.domain_gems_delete(domain_id, account_id, \'BM\', O.WAM_INST || \'_Gems\');
BMK.WA.domain_gems_create(domain_id, account_id);
}
}
');
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error('
insert replacing DB.DBA.SYS_SCHEDULED_EVENT (SE_NAME, SE_START, SE_SQL, SE_INTERVAL)
values(\'BM tags aggregator\', now(), \'BMK.WA.tags_agregator()\', 1440)
')
;
create procedure BMK.WA.tags_procedure (
in domain_id any,
in account_id any,
in item_id any)
{
declare tag varchar;
declare tags any;
result_names (tag);
tags := BMK.WA.tags_select (domain_id, account_id, item_id);
tags := split_and_decode (tags, 0, '\0\0,');
foreach (any tag in tags) do
result (trim (tag));
}
;
BMK.WA.exec_no_error ('
create procedure view BMK..TAGS_VIEW as BMK.WA.tags_procedure (domain_id, account_id, item_id) (BTV_TAG varchar)
')
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.path_update()
{
update BMK.WA.FOLDER
set F_PARENT_ID = -1
where F_PARENT_ID = 0;
if (registry_get ('bmk_path_update') <> '1')
update BMK.WA.FOLDER
set F_NAME = F_NAME
where coalesce(F_PARENT_ID, -1) = -1;
}
;
BMK.WA.path_update()
;
registry_set ('bmk_path_update', '1')
;
BMK.WA.exec_no_error ('
create trigger VSPX_SESSION_BOOKMARK_AD after delete on DB.DBA.VSPX_SESSION referencing old as O {
DB.DBA.DAV_DELETE_INT (\'/DAV/VAD/Bookmarks/Import/\' || O.VS_SID, 1, null, null, 0);
}
');
¶ bookmark/sql/bmk-a-wa.sqlß 0Û--
-- $Id: bmk-a-wa.sql,v 1.14 2007/02/05 17:34:16 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
-- ---------------------------------------------------
-- BM 'Users' code generation file.
-- ---------------------------------------------------
------------------------------------------------------------------------------
create procedure BMK.WA.exec_no_error(in expr varchar, in execType varchar := '', in execTable varchar := '', in execColumn varchar := '')
{
declare
state,
message,
meta,
result any;
log_enable(1);
if (execType = 'C') {
if (coalesce((select 1 from DB.DBA.SYS_COLS where (0=casemode_strcmp("COLUMN", execColumn)) and (0=casemode_strcmp ("TABLE", execTable))), 0))
return;
}
if (execType = 'D') {
if (not coalesce((select 1 from DB.DBA.SYS_COLS where (0=casemode_strcmp("COLUMN", execColumn)) and (0=casemode_strcmp ("TABLE", execTable))), 0))
return;
}
if (execType = 'S') {
declare S varchar;
declare maxID integer;
S := sprintf('select max(%s) from %s', execColumn, execTable);
maxID := 1000;
state := '00000';
exec(S, state, message, vector(), 0, meta, result);
if (state = '00000')
if (not isnull(result[0][0]))
maxID := result[0][0] + 1;
expr := sprintf(expr, maxID);
}
exec(expr, state, message, vector(), 0, meta, result);
}
;
------------------------------------------------------------------------------
--
create procedure BMK.WA.vhost()
{
declare
iIsDav integer;
declare
sHost varchar;
-- Add a virtual directory for Bookmark - public www -------------------------
sHost := registry_get('_bookmark_path_');
if (cast(sHost as varchar) = '0')
sHost := '/apps/bookmark/';
iIsDav := 1;
if (isnull(strstr(sHost, '/DAV')))
iIsDav := 0;
VHOST_REMOVE(lpath => '/bookmark');
VHOST_DEFINE(lpath => '/bookmark',
ppath => concat(sHost, 'www/'),
is_dav => iIsDav,
is_brws => 0,
vsp_user => 'dba',
realm => 'wa',
def_page => 'bookmarks.vspx'
);
}
;
BMK.WA.vhost();
-------------------------------------------------------------------------------
--
-- Insert data
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('insert replacing WA_TYPES(WAT_NAME, WAT_TYPE, WAT_REALM, WAT_DESCRIPTION) values (\'Bookmark\', \'db.dba.wa_bookmark\', \'wa\', \'Bookmark Manager Application\')')
;
BMK.WA.exec_no_error('insert replacing WA_MEMBER_TYPE (WMT_APP, WMT_NAME, WMT_ID, WMT_IS_DEFAULT) values (\'Bookmark\', \'owner\', 1, 0)')
;
BMK.WA.exec_no_error('insert replacing WA_MEMBER_TYPE (WMT_APP, WMT_NAME, WMT_ID, WMT_IS_DEFAULT) values (\'Bookmark\', \'author\', 2, 0)')
;
BMK.WA.exec_no_error('insert replacing WA_MEMBER_TYPE (WMT_APP, WMT_NAME, WMT_ID, WMT_IS_DEFAULT) values (\'Bookmark\', \'reader\', 3, 0)')
;
-------------------------------------------------------------------------------
--
-- create new BM Application in WA
--
-- BM class
--
BMK.WA.exec_no_error('
create type wa_bookmark under web_app as (
BookmarkID varchar,
owner integer
)
constructor method wa_bookmark(stream any),
overriding method wa_id_string() returns any,
overriding method wa_new_inst(login varchar) returns any,
overriding method wa_front_page(stream any) returns any,
overriding method wa_state_edit_form(stream any) returns any,
overriding method wa_home_url() returns varchar,
overriding method wa_drop_instance() returns any,
overriding method wa_notify_member_changed(account int, otype int, ntype int, odata any, ndata any, ostatus any, nstatus any) returns any,
overriding method wa_class_details() returns varchar,
overriding method wa_front_page_as_user(inout stream any, in user_name varchar) returns any,
method wa_vhost_options () returns any,
method get_param (in param varchar) returns any
'
)
;
BMK.WA.exec_no_error(
'alter type wa_bookmark add method wa_dashboard_last_item () returns any'
)
;
BMK.WA.exec_no_error (
'alter type wa_bookmark add overriding method wa_rdf_url (in vhost varchar, in lhost varchar) returns varchar'
)
;
-------------------------------------------------------------------------------
--
-- wa_bookmark methods
--
-------------------------------------------------------------------------------
--
create constructor method wa_bookmark (inout stream any) for wa_bookmark
{
return;
}
;
-------------------------------------------------------------------------------
--
create method wa_id_string() for wa_bookmark
{
return self.BookmarkID;
}
;
-------------------------------------------------------------------------------
--
create method wa_drop_instance () for wa_bookmark
{
BMK.WA.domain_delete(self.BookmarkID);
VHOST_REMOVE(lpath => concat('/bookmark/', self.BookmarkID));
(self as web_app).wa_drop_instance();
}
;
-------------------------------------------------------------------------------
--
create method wa_notify_member_changed(in account int, in otype int, in ntype int, in odata any, in ndata any, in ostatus any, in nstatus any) for wa_bookmark
{
if (isnull(ntype))
BMK.WA.account_delete(self.BookmarkID, account);
return (self as web_app).wa_notify_member_changed(account, otype, ntype, odata, ndata, ostatus, nstatus);
}
;
-------------------------------------------------------------------------------
--
-- owner makes a new BM
--
create method wa_new_inst (in login varchar) for wa_bookmark
{
declare iUserID, iWaiID integer;
iUserID := (select U_ID from DB.DBA.SYS_USERS where U_NAME = login);
if (isnull(iUserID))
signal('EN001', 'Not an ODS user');
if (self.wa_member_model is null)
self.wa_member_model := 0;
self.owner := iUserID;
insert into WA_INSTANCE (WAI_NAME, WAI_TYPE_NAME, WAI_INST, WAI_DESCRIPTION)
values (self.wa_name, 'Bookmark', self, 'Description');
select WAI_ID into iWaiID from WA_INSTANCE where WAI_NAME = self.wa_name;
self.BookmarkID := cast(iWaiID as varchar);
update WA_INSTANCE set WAI_INST = self where WAI_ID = iWaiID;
declare path varchar;
path := sprintf ('/DAV/home/%s/Bookmarks/', login);
DB.DBA.DAV_MAKE_DIR (path, iUserID, null, '110100000N');
update WS.WS.SYS_DAV_COL set COL_DET = 'Bookmark' where COL_ID = DAV_SEARCH_ID (path, 'C');
-- Add a virtual directory for BM - public www -------------------------
VHOST_REMOVE(lpath => concat('/bookmark/', self.BookmarkID));
VHOST_DEFINE(lpath => concat('/bookmark/', self.BookmarkID),
ppath => concat(self.get_param('host'), 'www/'),
ses_vars => 1,
is_dav => self.get_param('isDAV'),
is_brws => 0,
vsp_user => 'dba',
realm => 'wa',
def_page => 'bookmarks.vspx',
opts => vector ('domain', self.BookmarkID)
);
BMK.WA.domain_update (iWaiID, iUserID);
return (self as web_app).wa_new_inst(login);
}
;
-------------------------------------------------------------------------------
--
create method wa_class_details() for wa_bookmark
{
return 'The Virtuoso Bookmark Application allows you to create and maintain bookmarks.';
}
;
-------------------------------------------------------------------------------
--
create method wa_front_page(inout stream any) for wa_bookmark
{
declare sSid varchar;
sSid := (select VS_SID from VSPX_SESSION where VS_REALM = 'wa' and VS_UID = connection_get('vspx_user'));
http_request_status ('HTTP/1.1 302 Found');
http_header(sprintf('Location: %s?sid=%s&realm=%s\r\n', self.wa_home_url(), sSid, 'wa'));
return;
}
;
-------------------------------------------------------------------------------
--
create method wa_state_edit_form(inout stream any) for wa_bookmark
{
declare sSid varchar;
if (exists(select 1
from SYS_USERS A,
WA_MEMBER B
where A.U_NAME = connection_get('vspx_user')
and B.WAM_USER = A.U_ID
and B.WAM_INST= self.wa_name
and B.WAM_MEMBER_TYPE = 1))
{
sSid := (select VS_SID from VSPX_SESSION where VS_REALM = 'wa' and VS_UID = connection_get('vspx_user'));
http_request_status ('HTTP/1.1 302 Found');
http_header(sprintf('Location: %s?sid=%s&realm=%s\r\n', WS.WS.EXPAND_URL(self.wa_home_url(), 'settings.vspx'), sSid, 'wa'));
} else {
signal('42001', 'Not a owner');
}
return;
}
;
-------------------------------------------------------------------------------
--
create method wa_home_url () for wa_bookmark
{
return concat('/bookmark/', self.BookmarkID, '/bookmarks.vspx');
}
;
-------------------------------------------------------------------------------
--
create method wa_front_page_as_user (inout stream any, in user_name varchar) for wa_bookmark
{
declare sSid, sOwner varchar;
sOwner := (select TOP 1 U_NAME from SYS_USERS A, WA_MEMBER B where B.WAM_USER = A.U_ID and B.WAM_INST= self.wa_name and B.WAM_MEMBER_TYPE = 1);
sSid := md5 (concat (datestring (now ()), http_client_ip (), http_path ()));
insert into DB.DBA.VSPX_SESSION (VS_REALM, VS_SID, VS_UID, VS_STATE, VS_EXPIRY)
values ('wa', sSid, sOwner, serialize ( vector ('vspx_user', user_name, 'owner_user', sOwner)), now());
http_request_status ('HTTP/1.1 302 Found');
http_header(sprintf('Location: %s?sid=%s&realm=%s\r\n', self.wa_home_url(), sSid, 'wa'));
return;
}
;
-------------------------------------------------------------------------------
--
create method wa_vhost_options () for wa_bookmark
{
return vector (
self.get_param('host') || 'www/', -- physical home
'bookmarks.vspx', -- default page
'dba', -- user for execution
0, -- directory browsing enabled (flag 0/1)
self.get_param('isDAV'), -- WebDAV repository (flag 0/1)
vector ('domain', self.BookmarkID), -- virtual directory options, empty is not applicable
null, -- post-processing function (null is not applicable)
null -- pre-processing (authentication) function
);
}
;
-------------------------------------------------------------------------------
--
create method get_param (in param varchar) for wa_bookmark
{
declare retValue any;
retValue := null;
if (param = 'host') {
retValue := registry_get('_bookmark_path_');
if (cast(retValue as varchar) = '0')
retValue := '/apps/bookmark/';
} if (param = 'isDAV') {
retValue := 1;
if (isnull(strstr(self.get_param('host'), '/DAV')))
retValue := 0;
}
return retValue;
}
;
-------------------------------------------------------------------------------
--
create method wa_dashboard_last_item () for wa_bookmark
{
declare domainID, userID integer;
domainID := (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = self.wa_name);
userID := (select WAM_USER from WA_MEMBER B where WAM_INST = self.wa_name and WAM_MEMBER_TYPE = 1);
return BMK.WA.dashboard_get(domainID, userID);
}
;
-------------------------------------------------------------------------------
--
create method wa_rdf_url (in vhost varchar, in lhost varchar) for wa_bookmark
{
declare domainID, userID integer;
domainID := (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = self.wa_name);
userID := (select WAM_USER from WA_MEMBER B where WAM_INST= self.wa_name and WAM_MEMBER_TYPE = 1);
return concat(BMK.WA.dav_url2(domainID, userID), 'BM.rdf');
}
;
¶ bookmark/sql/bmk-d.sqlß
Š--
-- $Id: bmk-d.sql,v 1.10 2007/03/08 06:30:07 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
------------------------------------------------------------------------------
-- bmk-d.sql
-- script for cleaning wa instalation.
-- Copyright (C) 2004 OpenLink Software
------------------------------------------------------------------------------
-- Scheduler
BMK.WA.exec_no_error('DELETE FROM DB.DBA.SYS_SCHEDULED_EVENT WHERE SE_NAME = \'BM tags aggregator\'');
-- Triggers
BMK.WA.exec_no_error('DROP TDRIGGER WA_MEMBER_AU_BMK');
-- Tables
BMK.WA.exec_no_error('DROP VIEW BMK.DBA.TAGS_STATISTICS');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.SETTINGS');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.TAGS');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.GRANTS');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.BOOKMARK_DATA');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.BOOKMARK_DOMAIN');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.SFOLDER');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.FOLDER');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.BOOKMARK');
-- Types
BMK.WA.exec_no_error('delete from WA_TYPES where WAT_NAME = \'Bookmark\'');
BMK.WA.exec_no_error('drop type wa_bookmark');
-- Views
BMK.WA.exec_no_error('drop view BMK..TAGS_VIEW');
-- Registry
registry_remove ('_bookmark_path_');
registry_remove ('_bookmark_version_');
registry_remove ('_bookmark_build_');
registry_remove ('bmk_path_update');
registry_remove ('__ods_bookmark_sioc_init');
-- Procedures
create procedure BMK.WA.drop_procedures()
{
for (select P_NAME from DB.DBA.SYS_PROCEDURES where P_NAME like 'BMK.WA.%') do {
if (P_NAME not in ('BMK.WA.exec_no_error', 'BMK.WA.drop_procedures'))
BMK.WA.exec_no_error(sprintf('drop procedure %s', P_NAME));
}
}
;
-- dropping procedures for BMK
BMK.WA.drop_procedures();
BMK.WA.exec_no_error('DROP procedure BMK.WA.drop_procedures');
-- dropping SIOC procs
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_post_iri');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_links_to');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.fill_ods_bookmark_sioc');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_domain_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_domain_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_tags_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_tags_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.ods_bookmark_sioc_init');
-- dropping ODS procs
BMK.WA.exec_no_error('DROP procedure DB.DBA.wa_search_bmk_get_excerpt_html');
BMK.WA.exec_no_error('DROP procedure DB.DBA.wa_collect_bmk_tags');
-- final proc
BMK.WA.exec_no_error('DROP procedure BMK.WA.exec_no_error');
¶ bookmark/sql/sioc_bmk.sqlß .ö--
-- $Id: sioc_bmk.sql,v 1.23 2007/03/16 13:37:52 virtdev Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
use sioc;
create procedure bmk_post_iri (in domain_id int, in bmk_id int)
{
declare _member, _inst varchar;
declare exit handler for not found { return null; };
select U_NAME, WAI_NAME into _member, _inst
from DB.DBA.SYS_USERS, DB.DBA.WA_INSTANCE, DB.DBA.WA_MEMBER
where WAI_ID = domain_id and WAI_NAME = WAM_INST and WAM_MEMBER_TYPE = 1 and WAM_USER = U_ID;
return sprintf ('http://%s%s/%U/bookmark/%U/%d', get_cname(), get_base_path (), _member, _inst, bmk_id);
}
;
create procedure bmk_links_to (inout content any)
{
declare xt, retValue any;
if (content is null)
return null;
else if (isentity (content))
xt := content;
else
xt := xtree_doc (content, 2, '', 'UTF-8');
xt := xpath_eval ('//a[starts-with (@href,"http") and not(img)]', xt, 0);
retValue := vector ();
foreach (any x in xt) do
retValue := vector_concat (retValue, vector (vector (cast (xpath_eval ('string()', x) as varchar), cast (xpath_eval ('@href', x) as varchar))));
return retValue;
}
;
create procedure fill_ods_bookmark_sioc (in graph_iri varchar, in site_iri varchar, in _wai_name varchar := null)
{
declare bookmark_id integer;
declare iri, c_iri, creator_iri, t_iri varchar;
declare tags, linksTo any;
{
declare deadl, cnt any;
declare _domain, _b_id any;
_domain := _b_id := -1;
deadl := 3;
cnt := 0;
declare exit handler for sqlstate '40001' {
if (deadl <= 0)
resignal;
rollback work;
deadl := deadl - 1;
goto l0;
};
l0:
for (select B_ID, WAI_NAME, BD_DOMAIN_ID, BD_BOOKMARK_ID as _BD_BOOKMARK_ID, BD_NAME, BD_DESCRIPTION, BD_LAST_UPDATE, BD_CREATED, B_URI, WAM_USER
from DB.DBA.WA_INSTANCE,
BMK..BOOKMARK_DOMAIN,
BMK..BOOKMARK,
DB.DBA.WA_MEMBER
where
B_ID > _b_id and BD_DOMAIN_ID > _domain
and BD_DOMAIN_ID = WAI_ID
and BD_BOOKMARK_ID = B_ID
and WAM_INST = WAI_NAME
and ((WAM_IS_PUBLIC = 1 and _wai_name is null) or WAI_NAME = _wai_name)) do
{
c_iri := bmk_iri (WAI_NAME);
iri := bmk_post_iri (BD_DOMAIN_ID, _BD_BOOKMARK_ID);
creator_iri := user_iri (WAM_USER);
-- maker
for (select coalesce(U_FULL_NAME, U_NAME) full_name, U_E_MAIL e_mail from DB.DBA.SYS_USERS where U_ID = WAM_USER) do
foaf_maker (graph_iri, person_iri (creator_iri), full_name, e_mail);
linksTo := bmk_links_to (BD_DESCRIPTION);
ods_sioc_post (graph_iri, iri, c_iri, creator_iri, BD_NAME, BD_CREATED, BD_LAST_UPDATE, B_URI, BD_DESCRIPTION, null, linksTo);
-- tags
bookmark_id := _BD_BOOKMARK_ID;
for (select BD_TAGS from BMK.WA.BOOKMARK_DATA where BD_OBJECT_ID = BD_DOMAIN_ID and BD_MODE = 0 and BD_BOOKMARK_ID = bookmark_id and not DB.DBA.is_empty_or_null (BD_TAGS)) do
ods_sioc_tags (graph_iri, iri, BD_TAGS);
cnt := cnt + 1;
if (mod (cnt, 500) = 0)
{
commit work;
_b_id := B_ID;
_domain := BD_DOMAIN_ID;
}
}
commit work;
}
}
;
create procedure bookmark_domain_insert (
inout domain_id integer,
inout bookmark_id integer,
inout name varchar,
inout created datetime,
inout updated datetime,
inout description varchar)
{
declare graph_iri, iri, c_iri, creator_iri varchar;
declare linksTo any;
declare exit handler for sqlstate '*' {
sioc_log_message (__SQL_MESSAGE);
return;
};
graph_iri := get_graph ();
iri := bmk_post_iri (domain_id, bookmark_id);
for (select B_URI, WAM_USER, WAI_NAME
from DB.DBA.WA_INSTANCE,
BMK..BOOKMARK,
DB.DBA.WA_MEMBER
where WAI_ID = domain_id
and B_ID = bookmark_id
and WAM_INST = WAI_NAME
and WAI_IS_PUBLIC = 1) do
{
c_iri := bmk_iri (WAI_NAME);
creator_iri := user_iri (WAM_USER);
-- maker
for (select coalesce(U_FULL_NAME, U_NAME) full_name, U_E_MAIL e_mail from DB.DBA.SYS_USERS where U_ID = WAM_USER) do
foaf_maker (graph_iri, person_iri (creator_iri), full_name, e_mail);
linksTo := bmk_links_to (description);
ods_sioc_post (graph_iri, iri, c_iri, creator_iri, name, created, updated, B_URI, description, null, linksTo);
}
return;
}
;
create procedure bookmark_domain_delete (
inout domain_id integer,
inout bookmark_id integer)
{
declare graph_iri, iri varchar;
declare exit handler for sqlstate '*' {
sioc_log_message (__SQL_MESSAGE);
return;
};
graph_iri := get_graph ();
iri := bmk_post_iri (domain_id, bookmark_id);
delete_quad_s_or_o (graph_iri, iri, iri);
}
;
create trigger BOOKMARK_DOMAIN_SIOC_I after insert on BMK.WA.BOOKMARK_DOMAIN referencing new as N
{
bookmark_domain_insert (N.BD_DOMAIN_ID, N.BD_BOOKMARK_ID, N.BD_NAME, N.BD_CREATED, N.BD_LAST_UPDATE, N.BD_DESCRIPTION);
}
;
create trigger BOOKMARK_DOMAIN_SIOC_U after update on BMK.WA.BOOKMARK_DOMAIN referencing old as O, new as N
{
bookmark_domain_delete (O.BD_DOMAIN_ID, O.BD_BOOKMARK_ID);
bookmark_domain_insert (N.BD_DOMAIN_ID, N.BD_BOOKMARK_ID, N.BD_NAME, N.BD_CREATED, N.BD_LAST_UPDATE, N.BD_DESCRIPTION);
}
;
create trigger BOOKMARK_DOMAIN_SIOC_D before delete on BMK.WA.BOOKMARK_DOMAIN referencing old as O
{
bookmark_domain_delete (O.BD_DOMAIN_ID, O.BD_BOOKMARK_ID);
}
;
create procedure bookmark_tags_insert (
in domain_id integer,
in bookmark_id integer,
in tags varchar)
{
if (isnull(domain_id))
return;
if (DB.DBA.is_empty_or_null (tags))
return;
declare graph_iri, iri, post_iri, home varchar;
declare exit handler for sqlstate '*' {
sioc_log_message (__SQL_MESSAGE);
return;
};
home := '/bookmarks/' || cast(domain_id as varchar);
graph_iri := get_graph ();
post_iri := bmk_post_iri (domain_id, bookmark_id);
ods_sioc_tags (graph_iri, post_iri, tags);
}
;
create procedure bookmark_tags_delete (
in domain_id integer,
in bookmark_id integer,
in tags any)
{
if (isnull(domain_id))
return;
if (DB.DBA.is_empty_or_null (tags))
return;
declare graph_iri, post_iri varchar;
declare exit handler for sqlstate '*' {
sioc_log_message (__SQL_MESSAGE);
return;
};
graph_iri := get_graph ();
post_iri := bmk_post_iri (domain_id, bookmark_id);
ods_sioc_tags_delete (graph_iri, post_iri, tags);
}
;
create trigger BOOKMARK_DATA_SIOC_I after insert on BMK.WA.BOOKMARK_DATA referencing new as N
{
if (N.BD_MODE = 0)
bookmark_tags_insert (N.BD_OBJECT_ID, N.BD_BOOKMARK_ID, N.BD_TAGS);
}
;
create trigger BOOKMARK_DATA_SIOC_U after update on BMK.WA.BOOKMARK_DATA referencing old as O, new as N
{
if (O.BD_MODE = 0)
bookmark_tags_delete (O.BD_OBJECT_ID, O.BD_BOOKMARK_ID, O.BD_TAGS);
if (N.BD_MODE = 0)
bookmark_tags_insert (N.BD_OBJECT_ID, N.BD_BOOKMARK_ID, N.BD_TAGS);
}
;
create trigger BOOKMARK_DATA_SIOC_D before delete on BMK.WA.BOOKMARK_DATA referencing old as O
{
if (O.BD_MODE = 0)
bookmark_tags_delete (O.BD_OBJECT_ID, O.BD_BOOKMARK_ID, O.BD_TAGS);
}
;
create procedure ods_bookmark_sioc_init ()
{
declare sioc_version any;
sioc_version := registry_get ('__ods_sioc_version');
if (registry_get ('__ods_sioc_init') <> sioc_version)
return;
if (registry_get ('__ods_bookmark_sioc_init') = sioc_version)
return;
fill_ods_bookmark_sioc (get_graph (), get_graph ());
registry_set ('__ods_bookmark_sioc_init', sioc_version);
return;
}
;
--BMK.WA.exec_no_error('ods_bookmark_sioc_init ()');
use DB;
use DB;
-- BOOKMARK
wa_exec_no_error ('drop view ODS_BMK_POSTS');
create view ODS_BMK_POSTS as select
WAI_NAME,
BD_DOMAIN_ID,
BD_BOOKMARK_ID,
BD_NAME,
BD_DESCRIPTION,
sioc..sioc_date (BD_LAST_UPDATE) as BD_LAST_UPDATE,
sioc..sioc_date (BD_CREATED) as BD_CREATED,
sioc..post_iri (U_NAME, 'bookmark', WAI_NAME, cast (BD_BOOKMARK_ID as varchar)) || '/sioc.rdf' as SEE_ALSO,
B_URI,
U_NAME
from
DB.DBA.WA_INSTANCE,
BMK..BOOKMARK_DOMAIN,
BMK..BOOKMARK,
DB.DBA.WA_MEMBER,
DB.DBA.SYS_USERS
where
BD_DOMAIN_ID = WAI_ID and
BD_BOOKMARK_ID = B_ID and
WAM_INST = WAI_NAME and
WAM_IS_PUBLIC = 1 and
WAM_USER = U_ID and
WAM_MEMBER_TYPE = 1;
create procedure ODS_BMK_TAGS ()
{
declare inst, uname, item_id, tag any;
result_names (inst, uname, item_id, tag);
for select WAM_INST, U_NAME, BD_TAGS, BD_BOOKMARK_ID from
BMK.WA.BOOKMARK_DATA, WA_MEMBER, WA_INSTANCE, SYS_USERS where
WAM_INST = WAI_NAME and WAM_MEMBER_TYPE = 1 and WAM_USER = U_ID and BD_OBJECT_ID = WAI_ID and BD_MODE = 0
do
{
if (length (BD_TAGS))
{
declare arr any;
arr := split_and_decode (BD_TAGS, 0, '\0\0,');
foreach (any t in arr) do
{
t := trim(t);
if (length (t))
{
result (WAM_INST, U_NAME, BD_BOOKMARK_ID, t);
}
}
}
}
};
wa_exec_no_error ('drop view ODS_BMK_TAGS');
create procedure view ODS_BMK_TAGS as ODS_BMK_TAGS () (WAM_INST varchar, U_NAME varchar, ITEM_ID int, BD_TAG varchar);
create procedure sioc.DBA.rdf_bookmark_view_str ()
{
return
'
#Post
sioc:bmk_post_iri (DB.DBA.ODS_BMK_POSTS.U_NAME, DB.DBA.ODS_BMK_POSTS.WAI_NAME, DB.DBA.ODS_BMK_POSTS.BD_BOOKMARK_ID)
a bm:Bookmark option (EXCLUSIVE) ;
dc:title BD_NAME;
dct:created BD_CREATED ;
dct:modified BD_LAST_UPDATE ;
dc:date BD_LAST_UPDATE ;
ann:created BD_CREATED ;
dc:creator U_NAME ;
bm:recalls sioc:proxy_iri (B_URI) ;
sioc:link sioc:proxy_iri (B_URI) ;
sioc:content BD_DESCRIPTION ;
sioc:has_creator sioc:user_iri (U_NAME) ;
foaf:maker foaf:person_iri (U_NAME) ;
rdfs:seeAlso sioc:proxy_iri (SEE_ALSO) ;
sioc:has_container sioc:bmk_forum_iri (U_NAME, WAI_NAME) .
sioc:bmk_forum_iri (DB.DBA.ODS_BMK_POSTS.U_NAME, DB.DBA.ODS_BMK_POSTS.WAI_NAME)
sioc:container_of
sioc:bmk_post_iri (U_NAME, WAI_NAME, BD_BOOKMARK_ID) .
sioc:user_iri (DB.DBA.ODS_BMK_POSTS.U_NAME)
sioc:creator_of
sioc:bmk_post_iri (U_NAME, WAI_NAME, BD_BOOKMARK_ID) .
# Post tags
sioc:bmk_post_iri (DB.DBA.ODS_BMK_TAGS.U_NAME, DB.DBA.ODS_BMK_TAGS.WAM_INST, DB.DBA.ODS_BMK_TAGS.ITEM_ID)
sioc:topic
sioc:tag_iri (U_NAME, BD_TAG) .
sioc:tag_iri (DB.DBA.ODS_BMK_TAGS.U_NAME, DB.DBA.ODS_BMK_TAGS.BD_TAG) a skos:Concept ;
skos:prefLabel BD_TAG ;
skos:isSubjectOf sioc:bmk_post_iri (U_NAME, WAM_INST, ITEM_ID) .
sioc:bmk_post_iri (DB.DBA.ODS_BMK_POSTS.U_NAME, DB.DBA.ODS_BMK_POSTS.WAI_NAME, DB.DBA.ODS_BMK_POSTS.BD_BOOKMARK_ID)
a atom:Entry ;
atom:title BD_NAME ;
atom:source sioc:bmk_forum_iri (U_NAME, WAI_NAME) ;
atom:author foaf:person_iri (U_NAME) ;
atom:published BD_CREATED ;
atom:updated BD_LAST_UPDATE ;
atom:content sioc:bmk_post_text_iri (U_NAME, WAI_NAME, BD_BOOKMARK_ID) .
sioc:bmk_post_iri (DB.DBA.ODS_BMK_POSTS.U_NAME, DB.DBA.ODS_BMK_POSTS.WAI_NAME, DB.DBA.ODS_BMK_POSTS.BD_BOOKMARK_ID)
a atom:Content ;
atom:type "text/plain" ;
atom:lang "en-US" ;
atom:body BD_DESCRIPTION .
sioc:bmk_forum_iri (DB.DBA.ODS_BMK_POSTS.U_NAME, DB.DBA.ODS_BMK_POSTS.WAI_NAME)
atom:contains
sioc:bmk_post_iri (U_NAME, WAI_NAME, BD_BOOKMARK_ID) .
'
;
};
grant select on ODS_BMK_POSTS to "SPARQL";
grant select on ODS_BMK_TAGS to "SPARQL";
-- END BOOKMARK
ODS_RDF_VIEW_INIT ();
¶ bookmark/www/.cvsignoreß *.vspx-m *.vspx-m0 *.vspx-sql¶ bookmark/www/ajax.vspß
');
http(sprintf('%s', cast (progressID as varchar)));
http('');
connection_set('stop_execution', '1');
return (0);
}
-- stop
if (subAction = 'stop') {
registry_set ('bookmark_action_' || progressID, 'stop');
connection_set('stop_execution', '1');
return (0);
}
-- state
if (subAction = 'state') {
http_rewrite ();
http_header ('Content-Type: text/xml\r\n');
http('');
if (not isinteger (progressIndex))
http(sprintf('%s', progressIndex));
http('');
connection_set('stop_execution','1');
return (0);
}
-- clear
--
if (subAction = 'init') {
declare folder_id, folder_name, tags, R, S, T any;
registry_set ('bookmark_index_' || progressID, '0');
R := DAV_RES_CONTENT_INT (DAV_SEARCH_ID ('/DAV/VAD/Bookmarks/Import/' || sid, 'R'), S, T, 0, 0);
S := blob_to_string (S);
DB.DBA.DAV_DELETE_INT ('/DAV/VAD/Bookmarks/Import/' || sid, 1, null, null, 0);
-- flush and continue
http_flush ();
-- check / create folder
folder_id := cast (get_keyword ('folder_id', params, '0') as integer);
folder_name := trim (get_keyword ('folder_name', params, ''));
folder_id := BMK.WA.folder_create (domain_id, folder_name, folder_id);
tags := trim (get_keyword ('tags', params, ''));
-- import
{
declare exit handler for sqlstate '*'
{
goto _end;
};
BMK.WA.bookmark_import (S, domain_id, account_id, folder_id, tags, progressID);
}
_end:;
registry_remove ('bookmark_max_' || progressID);
registry_remove ('bookmark_index_' || progressID);
registry_remove ('bookmark_action_' || progressID);
connection_set('stop_execution', '1');
return (0);
}
}
?>¶ bookmark/www/back.vspxß F
'' order by TS_TAG) do {
http (sprintf ('%s ', TS_TAG, TS_TAG));
_done := 1;
}
if (not _done)
http ('no tags');
?>
= 0)
S := BMK.WA.folder_path (self.v_id);
(control as vspx_select_list).vsl_items:= vector ();
(control as vspx_select_list).vsl_item_values:= vector ();
(control as vspx_select_list).vsl_selected_inx := 0;
(control as vspx_select_list).vsl_items := vector_concat ((control as vspx_select_list).vsl_items, vector ('Select folder ...'));
(control as vspx_select_list).vsl_item_values := vector_concat ((control as vspx_select_list).vsl_item_values, vector ('-1'));
for (select F_ID, BMK.WA.folder_path2(F_PATH) as F_PATH2, F_PATH from BMK.WA.FOLDER where F_DOMAIN_ID = self.domain_id order by F_PATH) do {
if (F_PATH like concat (S, '%'))
goto _skip;
(control as vspx_select_list).vsl_items := vector_concat ((control as vspx_select_list).vsl_items, vector (F_PATH2));
(control as vspx_select_list).vsl_item_values := vector_concat ((control as vspx_select_list).vsl_item_values, vector (cast (F_ID as varchar)));
_skip:;
}
]]>
An error has occured during processing of the "" page.
SQL State
SQL Message
¶ bookmark/www/export.vspß
Browser
No frames support
This application uses frames. Unfortunately your browser does not support them.
The application is designed run on Mozilla %gt; 0.9,
Netscape > 4 and
Microsoft Internet Explorer > 4.