¶ bookmark/sql/DET_Bookmark.sqlß Ý˜--
-- $Id: DET_Bookmark.sql,v 1.21 2009/01/08 19:40:06 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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_COMPOSE_FOLDERS_PATH" (in domain_id_ integer, in bd_id_ integer)
{
declare folder_id integer;
declare folder_path varchar;
folder_id := (select BD_FOLDER_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bd_id_ and BD_DOMAIN_ID = domain_id_);
if (folder_id is null)
return '';
else
folder_path := (select F_PATH from BMK.WA.FOLDER where F_ID = folder_id);
return folder_path;
}
;
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 successful, 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 redundant 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 redundant 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, smart_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];
smart_id := id[8];
fullpath := '';
rightcol := '';
if (folder_id <> 0)
{
if (sub_id = 1)
{
while (folder_id <> 0 and folder_id <> -1)
{
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_UPDATED) from BMK.WA.BOOKMARK_DOMAIN where year(BD_UPDATED) = domain_id),
cast ('1980-01-01' as datetime));
colname := (select monthname(D.BD_UPDATED)
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_UPDATED) = folder_id
and year(D.BD_UPDATED) = 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_UPDATED) 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_UPDATED) from BMK.WA.BOOKMARK_DOMAIN where year(BD_UPDATED) = domain_id),
cast ('1980-01-01' as datetime));
colname := (select cast(year(D.BD_UPDATED) 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_UPDATED) = domain_id);
}
if (DAV_HIDE_ERROR (colname) is null)
return -1;
if (rightcol = '')
rightcol := colname;
fullpath := colname || '/' || fullpath;
}
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 (smart_id > -1)
{
if (sub_id = 4)
{
if (maxrcvdate is null)
maxrcvdate := now();
colname := (select SF_NAME
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.SFOLDER 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.SF_DOMAIN_ID = C.WAI_ID
and T.SF_ID = smart_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 if (sub_id = 4)
colname := 'smart';
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_UPDATED
from BMK.WA.BOOKMARK_DOMAIN
where BD_ID = id[6]
do
{
return vector (fullpath || orig_mname, 'R', 1024, BD_UPDATED, id, '100000000NN',
0, id[2], BD_UPDATED, '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, -1); -- 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', 'smart');
for (i := 0; i < 4; 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, -1),
'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, -1),
'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_UPDATED) 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, -1),
'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, -1),
'100000000NN', ownergid, owner_uid, now(), 'dav/unix-directory', orig_name) ) );
}
return res;
}
if (top_id[3] = 4 and top_id[4] = 0 and top_id[8] = -1) -- level of tags, lists of keywords
{
for select distinct SF_NAME as orig_name
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.SFOLDER 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.SF_DOMAIN_ID = C.WAI_ID
and D.SF_ID > -1
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, -1),
'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_UPDATED) 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_UPDATED) = 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, -1),
'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 bookmark instance, list of bookmark folders
{
sub_id := top_id[5];
if (top_id[5] = 0)
sub_id := -1;
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 = sub_id
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, -1),
'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_UPDATED
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_UPDATED,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], top_id[4], top_id[5], m_id, null, -1),
'100000000NN', ownergid, owner_uid, BD_UPDATED, '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_UPDATED
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_UPDATED) = top_id[4] and month(D.BD_UPDATED) = top_id[5]
order by 1, 2
do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath, orig_mname), 'R', 1024, BD_UPDATED,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], top_id[4], top_id[5], m_id, null, -1),
'100000000NN', ownergid, owner_uid, BD_UPDATED, '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_UPDATED, D.BD_TAGS as tags
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 D.BD_TAGS is not null and D.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_UPDATED,
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, m_id, tag, -1),
'100000000NN', ownergid, owner_uid, BD_UPDATED, 'application/xbel+xml', orig_mname)));
}
}
}
}
else if (top_id[3] = 4)
{
declare sql, state, msg, meta, rows any;
if (exists (select 1 from BMK.WA.SFOLDER where SF_NAME = 'All bookmarks' and SF_ID = top_id[8]))
{
for select S.SF_DOMAIN_ID as cur_domain, S.SF_DATA as cur_data
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.SFOLDER S
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 S.SF_DOMAIN_ID = C.WAI_ID do
{
state := '00000';
sql := BMK.WA.sfolder_sql(cur_domain, owner_uid, cur_data);
exec(sql, state, msg, vector(), 0, meta, rows);
if (state = '00000')
{
foreach (any row in rows) do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath,
"bookmark_COMPOSE_XBEL_NAME"(row[3], row[1])), 'R', 1024, row[6],
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, row[1], null, top_id[8]),
'100000000NN', ownergid, owner_uid, row[5], 'application/xbel+xml',
"bookmark_COMPOSE_XBEL_NAME"(row[3], row[1]))));
}
}
}
}
else
{
for select SF_DATA, SF_DOMAIN_ID from BMK.WA.SFOLDER where top_id[8] = SF_ID do
{
state := '00000';
sql := BMK.WA.sfolder_sql(SF_DOMAIN_ID, owner_uid, SF_DATA);
exec(sql, state, msg, vector(), 0, meta, rows);
if (state = '00000')
{
foreach (any row in rows) do
{
res := vector_concat (res, vector (vector (DAV_CONCAT_PATH (top_davpath,
"bookmark_COMPOSE_XBEL_NAME"(row[3], row[1])), 'R', 1024, row[6],
vector (UNAME'bookmark', detcol_id, owner_uid, top_id[3], 0, 0, row[1], null, top_id[8]),
'100000000NN', ownergid, owner_uid, row[5], 'application/xbel+xml',
"bookmark_COMPOSE_XBEL_NAME"(row[3], row[1]))));
}
}
}
}
}
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_UPDATED' ),
'RES_MOD_TIME', vector ('BOOKMARK_DOMAIN' , 0, 'datetime' , 'BD_UPDATED' ),
'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 ( '' ,
'' ,
'BD_TAGS' , 'BD_TAGS' , NULL ),
'private-tags' , vector ( '' ,
'' ,
'BD_TAGS' , 'BD_TAGS' , NULL ),
'all-tags' , vector ( '' ,
'' ,
'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 and 0)
{
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_FOLDERS_PATH" (_top.BD_DOMAIN_ID, _top.BD_ID), ''/'', "bookmark_COMPOSE_XBEL_NAME" (_top.BD_NAME, _top.BD_ID)),
''R'', 1024, _top.BD_UPDATED,
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_UPDATED, ''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, smart_id integer;
declare hitlist any;
declare access, colpath, tag_id, sub varchar;
tag_id := null;
smart_id := -1;
"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, -1);
}
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 if (equ(sub, 'smart'))
sub_id := 4;
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_UPDATED) 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_UPDATED) = 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];
}
else if (sub_id = 4)
{
for select distinct D.SF_ID as D_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C,
BMK.WA.SFOLDER 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.SF_DOMAIN_ID = C.WAI_ID
and D.SF_NAME = path_parts[ctr]
do
{
hitlist := vector_concat (hitlist, vector (D_ID));
}
if (length (hitlist) < 1)
return -1;
smart_id := hitlist[0];
}
if (sub_id <> 3 and sub_id <> 4)
{
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 = -1 and folder_id = 0))
do
{
hitlist := vector_concat (hitlist, vector (F_ID));
}
}
else if (sub_id = 2)
{
for select distinct month(D.BD_UPDATED) 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_UPDATED) = 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, smart_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_UPDATED) = folder_id
and year(D.BD_UPDATED) = 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));
}
}
else if (sub_id = 4)
{
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, smart_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_UPDATED 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 or id[3] = 4)
{
select D.BD_NAME, cast(D.BD_UPDATED 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-api.sqlß ’I--
-- $Id: bmk-a-api.sql,v 1.20 2011/06/07 16:39:38 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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 ODS;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API.bookmark_setting_set (
inout settings any,
inout options any,
in settingName varchar,
in settingTest any := null)
{
declare aValue any;
aValue := get_keyword (settingName, options, get_keyword (settingName, settings));
if (not isnull (settingTest))
BMK.WA.test (cast (aValue as varchar), settingTest);
BMK.WA.set_keyword (settingName, settings, aValue);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API.bookmark_setting_xml (
in settings any,
in settingName varchar)
{
return sprintf ('<%s>%s%s>', settingName, cast (get_keyword (settingName, settings) as varchar), settingName);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API.bookmark_type_check (
in inType varchar,
in inSource varchar)
{
declare outType integer;
if (isnull (inType))
inType := case when (inSource like 'http://%') then 'url' else 'webdav' end;
if (lcase (inType) = 'webdav')
{
outType := 1;
}
else if (lcase (inType) = 'url')
{
outType := 2;
}
else
{
signal ('BMK106', 'The source type must be WebDAV or URL.');
}
return outType;
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.get" (
in bookmark_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname varchar;
declare inst_id integer;
inst_id := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
ods_describe_iri (SIOC..bmk_post_iri (inst_id, bookmark_id));
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.new" (
in inst_id integer,
in uri varchar,
in name varchar,
in description varchar := null,
in tags varchar := null,
in folder_id integer := null) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
rc := BMK.WA.bookmark_update (
-1,
inst_id,
uri,
name,
description,
tags,
folder_id);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.edit" (
in bookmark_id integer,
in uri varchar,
in name varchar,
in description varchar := null,
in tags varchar := null,
in folder_id integer := null) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
inst_id := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
rc := BMK.WA.bookmark_update (
bookmark_id,
inst_id,
uri,
name,
description,
tags,
folder_id);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.delete" (
in bookmark_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
inst_id := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.folder.new" (
in inst_id integer,
in path varchar) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
rc := BMK.WA.folder_id (inst_id, path);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.folder.delete" (
in inst_id integer,
in path varchar) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
if (not exists (select 1 from BMK.WA.FOLDER where F_DOMAIN_ID = inst_id and F_PATH = path))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.FOLDER where F_DOMAIN_ID = inst_id and F_PATH = path;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.import" (
in inst_id integer,
in source varchar,
in sourceType varchar,
in tags varchar := '') __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname, passwd varchar;
declare content varchar;
declare tmp any;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
-- get content
if (lcase (sourceType) = 'string')
{
content := source;
}
else if (lcase (sourceType) = 'webdav')
{
passwd := __user_password (uname);
content := BMK.WA.dav_content (BMK.WA.host_url () || source, uname, passwd);
}
else if (lcase (sourceType) = 'url')
{
content := BMK.WA.dav_content (source);
}
else
{
signal ('BMK04', 'The source type must be string, WebDAV or URL.');
}
tags := trim (tags);
BMK.WA.test (tags, vector ('name', 'Tags', 'class', 'tags'));
tmp := BMK.WA.tags2vector (tags);
tmp := BMK.WA.vector_unique (tmp);
tags := BMK.WA.vector2tags (tmp);
-- import content
if (DB.DBA.is_empty_or_null (content))
signal ('BMK04', 'Bad import source!');
BMK.WA.bookmark_import (content, inst_id, null, tags, null);
return ods_serialize_int_res (1);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.export" (
in inst_id integer,
in contentType varchar := 'Netscape') __soap_http 'text/plain'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname varchar;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
if (lcase (contentType) not in ('netscape', 'xbel'))
signal ('BMK05', 'The content type must be Netscape or XBEL.');
if (lcase (contentType) = 'netscape')
{
contentType := 'Netscape';
}
else if (lcase (contentType) = 'xbel')
{
contentType := 'XBEL';
}
http (BMK.WA.dav_content (sprintf('%s/bookmark/%d/export.vspx?did=%d&output=BMK&file=export&format=%s', BMK.WA.host_url (), inst_id, inst_id, contentType)));
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.annotation.get" (
in annotation_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare inst_id, bookmark_id integer;
declare uname varchar;
whenever not found goto _exit;
select A_DOMAIN_ID, A_OBJECT_ID into inst_id, bookmark_id from BMK.WA.ANNOTATIONS where A_ID = annotation_id;
if (not ods_check_auth (uname, inst_id, 'reader'))
return ods_auth_failed ();
ods_describe_iri (SIOC..bmk_annotation_iri (inst_id, bookmark_id, annotation_id));
_exit:
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.annotation.new" (
in bookmark_id integer,
in author varchar,
in body varchar) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, inst_id integer;
declare uname varchar;
rc := -1;
inst_id := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id);
if (isnull (inst_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
if (not ods_check_auth (uname, inst_id, 'reader'))
return ods_auth_failed ();
insert into BMK.WA.ANNOTATIONS (A_DOMAIN_ID, A_OBJECT_ID, A_BODY, A_AUTHOR, A_CREATED, A_UPDATED)
values (inst_id, bookmark_id, body, author, now (), now ());
rc := (select max (A_ID) from BMK.WA.ANNOTATIONS);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.annotation.claim" (
in annotation_id integer,
in claimIri varchar,
in claimRelation varchar,
in claimValue varchar) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, inst_id integer;
declare uname varchar;
declare claims any;
rc := -1;
inst_id := (select A_DOMAIN_ID from BMK.WA.ANNOTATIONS where A_ID = annotation_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.ANNOTATIONS where A_ID = annotation_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
claims := (select deserialize (A_CLAIMS) from BMK.WA.ANNOTATIONS where A_ID = annotation_id);
claims := vector_concat (claims, vector (vector (claimIri, claimRelation, claimValue)));
update BMK.WA.ANNOTATIONS
set A_CLAIMS = serialize (claims),
A_UPDATED = now ()
where A_ID = annotation_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.annotation.delete" (
in annotation_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, inst_id integer;
declare uname varchar;
rc := -1;
inst_id := (select A_DOMAIN_ID from BMK.WA.ANNOTATIONS where A_ID = annotation_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.ANNOTATIONS where A_ID = annotation_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.ANNOTATIONS where A_ID = annotation_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.comment.get" (
in comment_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname varchar;
declare inst_id, bookmark_id integer;
whenever not found goto _exit;
select BC_DOMAIN_ID, BC_BOOKMARK_ID into inst_id, bookmark_id from BMK.WA.BOOKMARK_COMMENT where BC_ID = comment_id;
if (not ods_check_auth (uname, inst_id, 'reader'))
return ods_auth_failed ();
ods_describe_iri (SIOC..bmk_comment_iri (inst_id, cast (bookmark_id as integer), comment_id));
_exit:
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.comment.new" (
in bookmark_id integer,
in parent_id integer := null,
in title varchar,
in text varchar,
in name varchar,
in email varchar,
in url varchar := null) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
rc := -1;
inst_id := (select BD_DOMAIN_ID from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id);
if (not ods_check_auth (uname, inst_id, 'reader'))
return ods_auth_failed ();
if (not (BMK.WA.discussion_check () and BMK.WA.conversation_enable (inst_id)))
return signal('API01', 'Discussions must be enabled for this instance');
if (isnull (parent_id))
{
-- get root comment;
parent_id := (select BC_ID from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = inst_id and BC_BOOKMARK_ID = bookmark_id and BC_PARENT_ID is null);
if (isnull (parent_id))
{
BMK.WA.nntp_root (inst_id, bookmark_id);
parent_id := (select BC_ID from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = inst_id and BC_BOOKMARK_ID = bookmark_id and BC_PARENT_ID is null);
}
}
BMK.WA.nntp_update_item (inst_id, bookmark_id);
insert into BMK.WA.BOOKMARK_COMMENT (BC_PARENT_ID, BC_DOMAIN_ID, BC_BOOKMARK_ID, BC_TITLE, BC_COMMENT, BC_U_NAME, BC_U_MAIL, BC_U_URL, BC_UPDATED)
values (parent_id, inst_id, bookmark_id, title, text, name, email, url, now ());
rc := (select max (BC_ID) from BMK.WA.BOOKMARK_COMMENT);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.comment.delete" (
in comment_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
rc := -1;
inst_id := (select BC_DOMAIN_ID from BMK.WA.BOOKMARK_COMMENT where BC_ID = comment_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.BOOKMARK_COMMENT where BC_ID = comment_id))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.BOOKMARK_COMMENT where BC_ID = comment_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.publication.new" (
in inst_id integer,
in name varchar,
in updateType varchar := 1,
in updatePeriod varchar := 'hourly',
in updateFreq integr := 1,
in destinationType varchar := null,
in destination varchar,
in userName varchar := null,
in userPassword varchar := null,
in folderPath varchar := '',
in tagsInclude varchar := '',
in tagsExclude varchar := '') __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare _type, options any;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
_type := ODS.ODS_API.bookmark_type_check (destinationType, destination);
options := vector ('type', _type, 'name', destination, 'user', userName, 'password', userPassword, 'folderPath', folderPath, 'tagsInclude', tagsInclude, 'tagsExclude', tagsExclude);
insert into BMK.WA.EXCHANGE (EX_DOMAIN_ID, EX_TYPE, EX_NAME, EX_UPDATE_TYPE, EX_UPDATE_PERIOD, EX_UPDATE_FREQ, EX_OPTIONS)
values (inst_id, 0, name, updateType, updatePeriod, updateFreq, serialize (options));
rc := (select max (EX_ID) from BMK.WA.EXCHANGE);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.publication.get" (
in publication_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, inst_id integer;
declare uname varchar;
declare options any;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = publication_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = publication_id and EX_TYPE = 0))
return ods_serialize_sql_error ('37000', 'The item is not found');
for (select * from BMK.WA.EXCHANGE where EX_ID = publication_id) do
{
options := deserialize (EX_OPTIONS);
http (sprintf ('\r\n', publication_id));
http (sprintf (' %V\r\n', EX_NAME));
if (EX_UPDATE_TYPE = 0)
{
http (' manually\r\n');
}
else if (EX_UPDATE_TYPE = 1)
{
http (' after any entry is changed\r\n');
}
else
{
http (sprintf (' %s\r\n', EX_UPDATE_PERIOD));
http (sprintf (' %s\r\n', cast (EX_UPDATE_FREQ as varchar)));
}
http (sprintf (' %V\r\n', get_keyword (get_keyword ('type', options, 1), vector (1, 'WebDAV', 2, 'URL'))));
http (sprintf (' %V\r\n', get_keyword ('name', options)));
if (get_keyword ('user', options, '') <> '')
{
http (sprintf (' %V\r\n', get_keyword ('user', options)));
http (' ******\r\n');
}
http (' \r\n');
if (get_keyword ('folderPath', options, '') <> '')
http (sprintf (' %s\r\n', cast (get_keyword ('folderPath', options) as varchar)));
if (get_keyword ('tagsInclude', options, '') <> '')
http (sprintf (' %s\r\n', cast (get_keyword ('tagsInclude', options) as varchar)));
if (get_keyword ('tagsExclude', options, '') <> '')
http (sprintf (' %s\r\n', cast (get_keyword ('tagsExclude', options) as varchar)));
http (' \r\n');
http ('');
}
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.publication.edit" (
in publication_id integer,
in name varchar,
in updateType varchar := 1,
in updatePeriod varchar := 'hourly',
in updateFreq integr := 1,
in destinationType varchar := null,
in destination varchar,
in userName varchar := null,
in userPassword varchar := null,
in folderPath varchar := '',
in tagsInclude varchar := '',
in tagsExclude varchar := '') __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
declare _type, options any;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = publication_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = publication_id and EX_TYPE = 0))
return ods_serialize_sql_error ('37000', 'The item is not found');
_type := ODS.ODS_API.bookmark_type_check (destinationType, destination);
options := vector ('type', _type, 'name', destination, 'user', userName, 'password', userPassword, 'folderPath', folderPath, 'tagsInclude', tagsInclude, 'tagsExclude', tagsExclude);
update BMK.WA.EXCHANGE
set EX_NAME = name,
EX_UPDATE_TYPE = updateType,
EX_UPDATE_PERIOD = updatePeriod,
EX_UPDATE_FREQ = updateFreq,
EX_OPTIONS = serialize (options)
where EX_ID = publication_id;
return ods_serialize_int_res (publication_id);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.publication.sync" (
in publication_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname, syncLog varchar;
declare inst_id integer;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = publication_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = publication_id and EX_TYPE = 0))
return ods_serialize_sql_error ('37000', 'The item is not found');
BMK.WA.exchange_exec (publication_id);
syncLog := (select EX_EXEC_LOG from BMK.WA.EXCHANGE where EX_ID = publication_id);
if (not DB.DBA.is_empty_or_null (syncLog))
return ods_serialize_sql_error ('ERROR', syncLog);
return ods_serialize_int_res (1);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.publication.delete" (
in publication_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = publication_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = publication_id and EX_TYPE = 0))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.EXCHANGE where EX_ID = publication_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.subscription.new" (
in inst_id integer,
in name varchar,
in updateType varchar := 2,
in updatePeriod varchar := 'daily',
in updateFreq integr := 1,
in sourceType varchar := null,
in source varchar,
in userName varchar := null,
in userPassword varchar := null,
in folderPath varchar := '',
in tags varchar := '') __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare _type, options any;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
_type := ODS.ODS_API.bookmark_type_check (sourceType, source);
options := vector ('type', _type, 'name', source, 'user', userName, 'password', userPassword, 'folderPath', folderPath, 'tags', tags);
insert into BMK.WA.EXCHANGE (EX_DOMAIN_ID, EX_TYPE, EX_NAME, EX_UPDATE_TYPE, EX_UPDATE_PERIOD, EX_UPDATE_FREQ, EX_OPTIONS)
values (inst_id, 1, name, updateType, updatePeriod, updateFreq, serialize (options));
rc := (select max (EX_ID) from BMK.WA.EXCHANGE);
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.subscription.get" (
in subscription_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, inst_id integer;
declare uname varchar;
declare options any;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = subscription_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = subscription_id and EX_TYPE = 1))
return ods_serialize_sql_error ('37000', 'The item is not found');
for (select * from BMK.WA.EXCHANGE where EX_ID = subscription_id) do
{
options := deserialize (EX_OPTIONS);
http (sprintf ('\r\n', subscription_id));
http (sprintf (' %V\r\n', EX_NAME));
if (EX_UPDATE_TYPE = 0)
{
http (' manually\r\n');
}
else if (EX_UPDATE_TYPE = 1)
{
http (' after any entry is changed\r\n');
}
else
{
http (sprintf (' %s\r\n', EX_UPDATE_PERIOD));
http (sprintf (' %s\r\n', cast (EX_UPDATE_FREQ as varchar)));
}
http (sprintf (' %V\r\n', get_keyword (get_keyword ('type', options, 1), vector (1, 'WebDAV', 2, 'URL'))));
http (sprintf (' \r\n', get_keyword ('name', options)));
if (get_keyword ('user', options, '') <> '')
{
http (sprintf (' %V\r\n', get_keyword ('user', options)));
http (' ******\r\n');
}
http (' \r\n');
if (get_keyword ('folderPath', options, '') <> '')
http (sprintf (' %s\r\n', cast (get_keyword ('folderPath', options) as varchar)));
if (get_keyword ('tags', options, '') <> '')
http (sprintf (' %s\r\n', cast (get_keyword ('tags', options) as varchar)));
http (' \r\n');
http ('');
}
return '';
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.subscription.edit" (
in subscription_id integer,
in name varchar,
in updateType varchar := 2,
in updatePeriod varchar := 'daily',
in updateFreq integr := 1,
in sourceType varchar := null,
in source varchar,
in userName varchar := null,
in userPassword varchar := null,
in folderPath varchar := '',
in tags varchar := '') __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
declare _type, options any;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = subscription_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = subscription_id and EX_TYPE = 1))
return ods_serialize_sql_error ('37000', 'The item is not found');
_type := ODS.ODS_API.bookmark_type_check (sourceType, source);
options := vector ('type', _type, 'name', source, 'user', userName, 'password', userPassword, 'folderPath', folderPath, 'tags', tags);
update BMK.WA.EXCHANGE
set EX_NAME = name,
EX_UPDATE_TYPE = updateType,
EX_UPDATE_PERIOD = updatePeriod,
EX_UPDATE_FREQ = updateFreq,
EX_OPTIONS = serialize (options)
where EX_ID = subscription_id;
return ods_serialize_int_res (subscription_id);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.subscription.sync" (
in subscription_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare uname, syncLog varchar;
declare inst_id integer;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = subscription_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = subscription_id and EX_TYPE = 1))
return ods_serialize_sql_error ('37000', 'The item is not found');
BMK.WA.exchange_exec (subscription_id);
syncLog := (select EX_EXEC_LOG from BMK.WA.EXCHANGE where EX_ID = subscription_id);
if (not DB.DBA.is_empty_or_null (syncLog))
return ods_serialize_sql_error ('ERROR', syncLog);
return ods_serialize_int_res (1);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.subscription.delete" (
in subscription_id integer) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare inst_id integer;
inst_id := (select EX_DOMAIN_ID from BMK.WA.EXCHANGE where EX_ID = subscription_id);
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from BMK.WA.EXCHANGE where EX_ID = subscription_id and EX_TYPE = 1))
return ods_serialize_sql_error ('37000', 'The item is not found');
delete from BMK.WA.EXCHANGE where EX_ID = subscription_id;
rc := row_count ();
return ods_serialize_int_res (rc);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.options.set" (
in inst_id int,
in options any) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc, account_id integer;
declare conv, f_conv, f_conv_init any;
declare uname varchar;
declare optionsParams, settings any;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
account_id := (select U_ID from WS.WS.SYS_DAV_USER where U_NAME = uname);
optionsParams := split_and_decode (options, 0, '%\0,=');
settings := BMK.WA.settings (inst_id);
BMK.WA.settings_init (settings);
conv := cast (get_keyword ('conv', settings, '0') as integer);
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'chars');
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'rows', vector ('name', 'Rows per page', 'class', 'integer', 'type', 'integer', 'minValue', 1, 'maxValue', 1000));
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'tbLabels');
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'atomVersion');
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'panes');
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'bookmarkOpen');
if (BMK.WA.discussion_check ())
{
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'conv');
ODS.ODS_API.bookmark_setting_set (settings, optionsParams, 'conv_init');
}
insert replacing BMK.WA.SETTINGS (S_DOMAIN_ID, S_ACCOUNT_ID, S_DATA)
values (inst_id, account_id, serialize (settings));
f_conv := cast (get_keyword ('conv', settings, '0') as integer);
f_conv_init := cast (get_keyword ('conv_init', settings, '0') as integer);
if (BMK.WA.discussion_check ())
{
BMK.WA.nntp_update (inst_id, null, null, conv, f_conv);
if (f_conv and f_conv_init)
BMK.WA.nntp_fill (inst_id);
}
return ods_serialize_int_res (1);
}
;
-------------------------------------------------------------------------------
--
create procedure ODS.ODS_API."bookmark.options.get" (
in inst_id int) __soap_http 'text/xml'
{
declare exit handler for sqlstate '*'
{
rollback work;
return ods_serialize_sql_error (__SQL_STATE, __SQL_MESSAGE);
};
declare rc integer;
declare uname varchar;
declare settings any;
if (not ods_check_auth (uname, inst_id, 'author'))
return ods_auth_failed ();
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = inst_id and WAI_TYPE_NAME = 'Bookmark'))
return ods_serialize_sql_error ('37000', 'The instance is not found');
settings := BMK.WA.settings (inst_id);
BMK.WA.settings_init (settings);
http ('');
http (ODS.ODS_API.bookmark_setting_xml (settings, 'chars'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'rows'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'tbLabels'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'atomVersion'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'conv'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'conv_init'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'panes'));
http (ODS.ODS_API.bookmark_setting_xml (settings, 'bookmarkOpen'));
http ('');
return '';
}
;
grant execute on ODS.ODS_API."bookmark.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.edit" to ODS_API;
grant execute on ODS.ODS_API."bookmark.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.folder.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.folder.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.import" to ODS_API;
grant execute on ODS.ODS_API."bookmark.export" to ODS_API;
grant execute on ODS.ODS_API."bookmark.annotation.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.annotation.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.annotation.claim" to ODS_API;
grant execute on ODS.ODS_API."bookmark.annotation.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.comment.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.comment.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.comment.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.publication.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.publication.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.publication.edit" to ODS_API;
grant execute on ODS.ODS_API."bookmark.publication.sync" to ODS_API;
grant execute on ODS.ODS_API."bookmark.publication.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.subscription.new" to ODS_API;
grant execute on ODS.ODS_API."bookmark.subscription.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.subscription.edit" to ODS_API;
grant execute on ODS.ODS_API."bookmark.subscription.sync" to ODS_API;
grant execute on ODS.ODS_API."bookmark.subscription.delete" to ODS_API;
grant execute on ODS.ODS_API."bookmark.options.get" to ODS_API;
grant execute on ODS.ODS_API."bookmark.options.set" to ODS_API;
use DB;¶ bookmark/sql/bmk-a-code.sqlß Y¼--
-- $Id: bmk-a-code.sql,v 1.154 2012/03/16 16:37:56 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2012 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
--
-------------------------------------------------------------------------------
--
-- ACL Functions
--
-------------------------------------------------------------------------------
--
create procedure BMK.WA.acl_condition (
in domain_id integer,
in id integer := null)
{
if (not is_https_ctx ())
return 0;
if (exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = domain_id and WAI_ACL is not null))
return 1;
if (exists (select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id and BD_ACL is not null))
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.acl_check (
in domain_id integer,
in id integer := null)
{
declare rc varchar;
declare graph_iri, groups_iri, acl_iris any;
rc := '';
if (BMK.WA.acl_condition (domain_id, id))
{
acl_iris := vector (BMK.WA.forum_iri (domain_id));
if (not isnull (id))
acl_iris := vector (SIOC..bmk_post_iri (domain_id, id), BMK.WA.forum_iri (domain_id));
graph_iri := BMK.WA.acl_graph (domain_id);
groups_iri := SIOC..acl_groups_graph (BMK.WA.domain_owner_id (domain_id));
rc := SIOC..acl_check (graph_iri, groups_iri, acl_iris);
}
return rc;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.acl_list (
in domain_id integer)
{
declare graph_iri, groups_iri, iri any;
iri := BMK.WA.forum_iri (domain_id);
graph_iri := BMK.WA.acl_graph (domain_id);
groups_iri := SIOC..acl_groups_graph (BMK.WA.domain_owner_id (domain_id));
return SIOC..acl_list (graph_iri, groups_iri, iri);
}
;
-------------------------------------------------------------------------------
--
-- Session Functions
--
-------------------------------------------------------------------------------
create procedure BMK.WA.session_domain (
inout params any)
{
declare aPath, domain_id, options any;
declare exit handler for sqlstate '*'
{
domain_id := -2;
goto _end;
};
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))
{
aPath := split_and_decode (trim (http_path (), '/'), 0, '\0\0/');
if ((length (aPath) = 1) or ((length (aPath) = 2) and (aPath[1] like '%.vsp%')))
{
domain_id := -1;
goto _end;
}
domain_id := cast (aPath[1] as integer);
}
if (not exists (select 1 from DB.DBA.WA_INSTANCE where WAI_ID = domain_id and WAI_TYPE_NAME = 'Bookmark'))
domain_id := -2;
_end:;
return cast (domain_id as integer);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.session_restore (
inout params any)
{
declare domain_id, account_id, account_rights any;
domain_id := BMK.WA.session_domain (params);
account_id := http_nobody_uid ();
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 = get_keyword ('realm', params, 'wa')
and S.VS_SID = get_keyword ('sid', params, '')
and S.VS_UID = U.U_NAME) do
{
account_id := U_ID;
}
return vector (
'domain_id', domain_id,
'account_id', account_id,
'account_rights', BMK.WA.account_rights (domain_id, account_id),
'person_rights', BMK.WA.person_rights (domain_id, account_id)
);
}
;
-------------------------------------------------------------------------------
--
-- 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;
if ((user_id = 0) or (user_id = http_dav_uid ()))
return 1;
group_id := (select U_GROUP from SYS_USERS where U_ID = user_id);
if ((group_id = 0) or (group_id = http_dav_uid ()) or (group_id = http_dav_uid()+1))
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.check_grants (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.person_rights (
in domain_id integer,
in account_id integer)
{
declare rc varchar;
if (domain_id = -1)
return 'R';
if (domain_id = -2)
return null;
if (BMK.WA.check_admin (account_id))
return 'W';
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_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 'W';
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_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 'W';
if (is_https_ctx ())
{
rc := BMK.WA.acl_check (domain_id);
if (rc <> '')
return rc;
}
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_id
and B.WAM_USER = A.U_ID
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 'R';
if (exists (select 1
from DB.DBA.WA_INSTANCE
where WAI_ID = domain_id
and WAI_IS_PUBLIC = 1))
return 'R';
if (is_https_ctx () and exists (select 1 from BMK.WA.acl_list (id)(iri varchar) x where x.id = domain_id))
return '';
return null;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_rights (
in domain_id integer,
in account_id integer)
{
declare rc varchar;
if (domain_id = -1)
return 'R';
if (domain_id = -2)
return null;
if (BMK.WA.check_admin (account_id))
return 'W';
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_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 'W';
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_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 'W';
if (exists (select 1
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_id
and B.WAM_USER = A.U_ID
and B.WAM_INST = C.WAI_NAME
and C.WAI_ID = domain_id))
return 'R';
if (exists (select 1
from DB.DBA.WA_INSTANCE
where WAI_ID = domain_id
and WAI_IS_PUBLIC = 1))
return 'R';
return null;
}
;
-------------------------------------------------------------------------------
--
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)
{
return
'
';
}
;
-------------------------------------------------------------------------------
--
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 || 'Gems/';
DB.DBA.DAV_MAKE_DIR (home, account_id, null, read_perm);
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 || 'Bookmark.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 || 'Bookmark.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 || 'Bookmark.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 || 'Bookmark.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 || 'Bookmark.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);
-- COMMENT
path := home || 'Bookmark.comment';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
content := BMK.WA.export_comment_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 discussion based XML document generated by OpenLink Bookmarks', 'dav', null, 0, 0, 1);
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_gems_delete (
in domain_id integer,
in account_id integer := null,
in appName varchar := 'Gems',
in appGems varchar := null,
in fileName varchar := 'Bookmark')
{
declare tmp, home, appHome, path varchar;
if (isnull (account_id))
account_id := BMK.WA.domain_owner_id (domain_id);
home := BMK.WA.dav_home(account_id);
if (isnull(home))
return;
if (isnull(appGems))
appGems := BMK.WA.domain_gems_name (domain_id);
appHome := home || appName || '/';
home := appHome || appGems || '/';
path := home || fileName || '.rss';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.rdf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.atom';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.ocs';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.opml';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.foaf';
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
path := home || fileName || '.comment';
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);
tmp := DB.DBA.DAV_DIR_LIST (appHome, 0, auth_uid, auth_pwd);
if (not isinteger (tmp) and not length(tmp))
DB.DBA.DAV_DELETE_INT (appHome, 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_name (domain_id) || '_Gems', 'BM');
BMK.WA.domain_gems_create (domain_id, account_id);
BMK.WA.sfolder_create (domain_id, 'All bookmarks', '');
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;
delete from BMK.WA.TAGS where T_DOMAIN_ID = domain_id;
delete from BMK.WA.EXCHANGE where EX_DOMAIN_ID = domain_id;
delete from BMK.WA.SETTINGS where S_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);
}
BMK.WA.domain_gems_delete (domain_id);
BMK.WA.nntp_update (domain_id, null, null, 1, 0);
VHOST_REMOVE(lpath => concat('/bookmark/', cast (domain_id as varchar)));
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_id (
in domain_name varchar)
{
return (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = domain_name);
}
;
-------------------------------------------------------------------------------
--
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_nntp_name (
in domain_id integer)
{
return BMK.WA.domain_nntp_name2 (BMK.WA.domain_name (domain_id), BMK.WA.domain_owner_name (domain_id));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_nntp_name2 (
in domain_name varchar,
in owner_name varchar)
{
return sprintf ('ods.bookmarks.%s.%U', owner_name, BMK.WA.string2nntp (domain_name));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_gems_name (
in domain_id integer)
{
return concat (BMK.WA.domain_name(domain_id), '');
}
;
-------------------------------------------------------------------------------
--
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)
{
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.forum_iri (domain_id), null, BMK.WA.gems_url (domain_id) || 'Bookmark.rss');
ODS..APP_PING (WAI_NAME, coalesce (WAI_DESCRIPTION, WAI_NAME), BMK.WA.forum_iri (domain_id), null, BMK.WA.gems_url (domain_id) || 'Bookmark.atom');
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.forum_iri (
in domain_id integer)
{
return SIOC..bmk_iri (BMK.WA.domain_name (domain_id));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.acl_graph (
in domain_id integer)
{
return SIOC..acl_graph ('Bookmark', BMK.WA.domain_name (domain_id));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.domain_sioc_url (
in domain_id integer,
in sid varchar := null,
in realm varchar := null)
{
declare S varchar;
S := BMK.WA.iri_fix (BMK.WA.forum_iri (domain_id));
return BMK.WA.url_fix (S, sid, realm);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.sparql_url ()
{
return sprintf ('http://%s/sparql?default-graph-uri=%U&query=%U&format=%U', SIOC..get_cname (), SIOC..get_graph (), 'DESCRIBE <_RDF_>', 'application/sparql-results+xml');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.page_url (
in domain_id integer,
in page varchar := null,
in sid varchar := null,
in realm varchar := null)
{
declare S varchar;
S := BMK.WA.iri_fix (BMK.WA.forum_iri (domain_id));
if (not isnull (page))
S := S || '/' || page;
return BMK.WA.url_fix (S, sid, realm);
}
;
-------------------------------------------------------------------------------
--
-- 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 (
inout auth_uid varchar,
inout auth_pwd varchar)
{
if (isnull (auth_uid))
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.GRANTS where G_GRANTER_ID = account_id or G_GRANTEE_ID = account_id;
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_id (
in account_name varchar)
{
return (select U_ID from DB.DBA.SYS_USERS where U_NAME = account_name);
}
;
-------------------------------------------------------------------------------
--
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_password (
in account_id integer)
{
return coalesce ((select pwd_magic_calc(U_NAME, U_PWD, 1) from WS.WS.SYS_DAV_USER where U_ID = account_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_fullName (
in account_id integer)
{
return coalesce ((select BMK.WA.user_name (U_NAME, U_FULL_NAME) from DB.DBA.SYS_USERS where U_ID = account_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_mail(
in account_id integer)
{
return coalesce((select U_E_MAIL from DB.DBA.SYS_USERS where U_ID = account_id), '');
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_sioc_url (
in domain_id integer,
in sid varchar := null,
in realm varchar := null)
{
declare S varchar;
S := BMK.WA.iri_fix (SIOC..person_iri (SIOC..user_iri (BMK.WA.domain_owner_id (domain_id), null)));
return BMK.WA.url_fix (S, sid, realm);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.account_basicAuthorization (
in account_id integer)
{
declare account_name, account_password varchar;
account_name := BMK.WA.account_name (account_id);
account_password := BMK.WA.account_password (account_id);
return sprintf ('Basic %s', encode_base64 (account_name || ':' || account_password));
}
;
-------------------------------------------------------------------------------
--
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 trim (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 tags any,
in folder_id integer,
in uid varchar := null,
in acl any := null)
{
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 BD_BOOKMARK_ID = bookmark_id and BD_UID = uid), -1);
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 <= 0)
{
insert into BMK.WA.BOOKMARK_DOMAIN (BD_DOMAIN_ID, BD_BOOKMARK_ID, BD_NAME, BD_DESCRIPTION, BD_TAGS, BD_UPDATED, BD_CREATED, BD_FOLDER_ID, BD_UID, BD_ACL)
values (domain_id, bookmark_id, name, description, tags, now(), now(), folder_id, uid, acl);
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_TAGS = tags,
BD_UPDATED = now(),
BD_FOLDER_ID = folder_id,
BD_ACL = acl
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_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 folder_id integer := null,
in tags varchar := '',
in progress_id varchar := null)
{
declare V, V2 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 (isnull (V))
goto _xbel;
BMK..bookmark_import_netscape (domain_id, folder_id, tags, xml_cut(V), progress_id);
goto _end;
_xbel:;
-- check XBEL format
--
V := BMK.WA.string2xml (S);
if (isnull (V))
goto _end;
V2 := xpath_eval('/xbel', V);
if (isnull (V2))
goto _rss;
BMK..bookmark_import_xbel (domain_id, folder_id, tags, xml_cut(V2), progress_id, 'xbel');
goto _end;
_rss:;
-- check RSS format
--
V2 := xpath_eval ('/rss/channel/item|/rss/item|/RDF/item|/Channel/items/item', V);
if (isnull (V2))
goto _atom;
BMK..bookmark_import_rss (domain_id, folder_id, tags, V2, progress_id);
goto _end;
_atom:;
-- check Atom format
--
V2 := xpath_eval ('/feed/entry', V);
if (isnull (V2))
goto _delicious;
BMK..bookmark_import_atom (domain_id, folder_id, tags, V2, progress_id);
goto _end;
_delicious:;
V2 := xpath_eval('/posts', V);
if (isnull (V2))
{
signal ('BMK01', 'The content being imported was not of a format ODS-Bookmarks understands!<>');
goto _end;
}
BMK..bookmark_import_delicious (domain_id, folder_id, tags, xml_cut(V2), progress_id);
_end:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_netscape (
in domain_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare tmp, T, Q any;
declare N 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);
BMK.WA.bookmark_import_update (domain_id, Q, T, null, tags, folder_id, progress_id);
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, tmp, tags, xml_cut(T), progress_id);
N := N + 1;
}
_exit:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_xbel (
in domain_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar,
in tag varchar)
{
declare T, Q, D any;
declare N 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));
BMK.WA.bookmark_import_update (domain_id, Q, T, D, tags, folder_id, progress_id);
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, folder_id, tags, xml_cut(T), progress_id, 'folder');
N := N + 1;
}
_exit:
return;
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_rss (
in domain_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare items, item, T, Q, D any;
declare N, L integer;
items := xpath_eval ('/rss/channel/item|/rss/item|/RDF/item|/Channel/items/item', V, 0);
L := length (items);
for (N := 0; N < L; N := N + 1)
{
item := xml_cut(items[N]);
T := serialize_to_UTF8_xml (xpath_eval ('string(/item/title)', item, 1));
D := xpath_eval ('[ xmlns:content="http://purl.org/rss/1.0/modules/content/" ] string(/item/content:encoded)', item, 1);
if (is_empty_or_null (D))
D := xpath_eval ('string(/item/description)', item, 1);
D := serialize_to_UTF8_xml (D);
Q := cast (xpath_eval ('/item/link', item, 1) as varchar);
if (isnull (Q))
{
Q := cast (xpath_eval ('[xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"] /item/@rdf:about', item, 1) as varchar);
if ((isnull (Q)) and isnull (cast(xpath_eval ('/item/guid[@isPermaLink = "false"]', item, 1) as varchar)))
Q := cast (xpath_eval ('/item/guid', item, 1) as varchar);
}
BMK.WA.bookmark_import_update (domain_id, Q, T, D, tags, folder_id, progress_id);
}
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_atom (
in domain_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare items, item, contents, T, Q, D any;
declare N, L integer;
items := xpath_eval ('/feed/entry', V, 0);
L := length (items);
for (N := 0; N < L; N := N + 1)
{
item := xml_cut (items[N]);
T := serialize_to_UTF8_xml (xpath_eval ('string(/entry/title)', item, 1));
if (xpath_eval ('/entry/content[@type = "application/xhtml+xml" or @type="xhtml"]', item) is not null)
{
contents := xpath_eval ('/entry/content/*', item, 0);
if (length (contents) = 1)
{
D := serialize_to_UTF8_xml (contents[0]);
}
else
{
D := '
';
foreach (any content in contents) do
D := concat(D, BMK.WA.xml2string(content));
D := concat(D, '
');
}
}
else
{
D := xpath_eval ('string(/entry/content)', item, 1);
if (is_empty_or_null(D))
D := xpath_eval ('string(/entry/summary)', item, 1);
D := serialize_to_UTF8_xml (D);
}
Q := cast (xpath_eval ('/entry/link[@rel="alternate"]/@href', item, 1) as varchar);
BMK.WA.bookmark_import_update (domain_id, Q, T, D, tags, folder_id, progress_id);
}
}
;
-----------------------------------------------------
--
create procedure BMK.WA.bookmark_import_delicious (
in domain_id integer,
in folder_id integer,
in tags varchar,
in V any,
in progress_id varchar)
{
declare tmp, T, Q, D, H, nTags, TG, TGA any;
declare N 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));
H := cast (xpath_eval(sprintf('//post[%d]/@hash', N), V, 1) as varchar);
commit work;
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, ',');
BMK.WA.bookmark_import_update (domain_id, Q, T, D, nTags, folder_id, progress_id);
N := N + 1;
}
_exit:
return;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_import_update (
in domain_id integer,
in Q any,
in T any,
in D any,
in tags varchar,
in folder_id integer,
in progress_id varchar)
{
declare id, M integer;
commit work;
connection_set ('__bookmark_import', '1');
id := BMK.WA.bookmark_update (-1, domain_id, cast (Q as varchar), cast (T as varchar), D, tags, folder_id);
connection_set ('__bookmark_import', '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));
}
return id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_export (
in domain_id integer,
in folder_id integer := null,
in options any := null)
{
declare retValue any;
declare tagsInclude, tagsExclude any;
tagsInclude := null;
tagsExclude := null;
if (not isnull (options))
{
tagsInclude := get_keyword ('tagsInclude', options);
tagsExclude := get_keyword ('tagsExclude', options);
}
retValue := string_output ();
http ('\n', retValue);
http (sprintf('', coalesce(folder_id, -1)), retValue);
BMK.WA.bookmark_export_tmp (domain_id, folder_id, tagsInclude, tagsExclude, retValue);
http ('', retValue);
return string_output_string (retValue);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_export_tmp (
in domain_id integer,
in folder_id any,
in tagsInclude any,
in tagsExclude 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
{
if (BMK.WA.tags_exchangeTest (BD_TAGS, tagsInclude, tagsExclude))
{
http (sprintf('', BMK.WA.utf2wide (BD_NAME), BMK.WA.utf2wide (BD_DESCRIPTION), B_URI, BD_UID, BD_TAGS), 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, tagsInclude, tagsExclude, retValue);
http ('', retValue);
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmark_rights (
in domain_id integer,
in id integer,
in account_rights varchar,
in person_rights varchar)
{
declare retValue varchar;
retValue := '';
if (exists (select 1 from BMK.WA.BOOKMARK_DOMAIN where BD_ID = id and BD_DOMAIN_ID = domain_id))
{
if (isnull (person_rights) or (account_rights < person_rights))
retValue := BMK.WA.acl_check (domain_id, id);
if (retValue = '')
retValue := account_rights;
}
return retValue;
}
;
-------------------------------------------------------------------------------
--
-- Tags
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_tags (
inout domain_id integer,
inout id integer,
inout tags any)
{
update BMK.WA.BOOKMARK_DOMAIN
set BD_TAGS = tags,
BD_UPDATED = now()
where BD_DOMAIN_ID = domain_id
and BD_ID = id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_select (
inout domain_id integer,
inout id integer)
{
return (select BD_TAGS from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and BD_ID = id);
}
;
-------------------------------------------------------------------------------
--
-- Last access
--
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_visited (
inout domain_id integer,
inout id integer)
{
return (select BD_VISITED from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id and BD_ID = id);
}
;
-------------------------------------------------------------------------------
create procedure BMK.WA.bookmark_visited_set (
inout domain_id integer,
inout id integer,
inout visited datetime := null)
{
update BMK.WA.BOOKMARK_DOMAIN
set BD_VISITED = visited
where BD_DOMAIN_ID = domain_id
and BD_ID = id;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.folder_visited_set (
inout domain_id integer,
inout id integer,
inout visited datetime := null)
{
-- delete childs
for (select F_ID from BMK.WA.FOLDER where F_PARENT_ID = id) do
BMK.WA.folder_visited_set (domain_id, F_ID, visited);
-- delete bookmarks
for (select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_FOLDER_ID = id) do
BMK.WA.bookmark_visited_set (domain_id, BD_ID, visited);
}
;
-------------------------------------------------------------------------------
--
-- 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 (trim (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 coalesce (F_PARENT_ID, -1) = -1))
insert into BMK.WA.FOLDER (F_DOMAIN_ID, F_PARENT_ID, F_NAME, F_PATH) values (domain_id, -1, aPath[i], '');
folder_id := (select F_ID from BMK.WA.FOLDER where F_DOMAIN_ID = domain_id and F_NAME = aPath[i] and coalesce (F_PARENT_ID, -1) = -1);
}
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 integer,
in folder_name varchar,
in folder_id integer)
{
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 integer,
in parent_id integer,
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;
commit work;
}
;
-------------------------------------------------------------------------------
--
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 folder_id integer)
{
return coalesce((select F_NAME from BMK.WA.FOLDER where 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 := case when G_OBJECT_TYPE = 'F' then coalesce(folder_name, '') else '' end;
}
}
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;
}
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 account_rights varchar,
in data varchar,
in maxRows varchar := '',
in nodeType varchar := 'b')
{
declare tmp any;
declare S, T, where2, delimiter2 varchar;
where2 := ' \n ';
delimiter2 := '\n and ';
S :=
'select \n' ||
' distinct \n' ||
' 1 _TYPE, \n' ||
' a.BD_ID _ID, \n' ||
' BMK.WA.make_node ('''', a.BD_ID) _NODE, \n' ||
' a.BD_NAME _NAME, \n' ||
' b.B_URI _URI, \n' ||
' a.BD_VISITED _VISITED, \n' ||
' a.BD_UPDATED _UPDATED, \n' ||
' a.BD_CREATED _CREATED, \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.FOLDER d on d.F_ID = a.BD_FOLDER_ID \n' ||
'where a.BD_DOMAIN_ID = \n';
T := '';
tmp := BMK.WA.xml_get('keywords', data);
if (not is_empty_or_null(tmp)) {
T := FTI_MAKE_SEARCH_STRING(tmp);
} else {
tmp := BMK.WA.xml_get('expression', data);
if (not is_empty_or_null(tmp))
T := tmp;
}
tmp := BMK.WA.xml_get('tags', data);
if (not is_empty_or_null(tmp))
{
if (T = '') {
T := BMK.WA.tags2search (tmp);
} else {
T := T || ' and ' || BMK.WA.tags2search (tmp);
}
}
if (T <> '')
S := replace(S, '', sprintf('and contains (a.BD_DESCRIPTION, \'[__lang "x-ViDoc"] %s\') \n', T));
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('folderID', data);
if (not is_empty_or_null(tmp))
{
tmp := cast (tmp as integer);
BMK.WA.sfolder_sql_where (where2, delimiter2, sprintf ('coalesce(a.BD_FOLDER_ID, -1) = %d', 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));
}
tmp := BMK.WA.xml_get('updatedAfter', data);
if (not is_empty_or_null(tmp))
{
BMK.WA.sfolder_sql_where (where2, delimiter2, sprintf ('a.BD_UPDATED >= \'%s\'', tmp));
}
tmp := BMK.WA.xml_get('updatedBefore', data);
if (not is_empty_or_null(tmp))
{
BMK.WA.sfolder_sql_where (where2, delimiter2, sprintf ('a.BD_UPDATED <= \'%s\'', tmp));
}
if (account_rights = '')
{
if (is_https_ctx ())
{
S := S || ' and SIOC..bmk_post_iri (a.BD_DOMAIN_ID, a.BD_ID) in (select s.iri from BMK.WA.acl_list (id)(iri varchar) s where s.id = a.BD_DOMAIN_ID)';
} else {
S := S || ' and 1=0';
}
}
if (maxRows <> '')
maxRows := 'TOP ' || maxRows;
S := replace(S, '', maxRows);
S := replace(S, '', nodeType);
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, '', where2);
-- dbg_obj_print(S);
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.shared_sql (
inout domain_id integer,
inout account_id integer,
inout account_rights varchar,
in data any,
in maxRows varchar := '')
{
declare N, gid, did, aid, fid, bid, own, shared integer;
declare grants, 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 datetime;
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);
own := cast (BMK.WA.xml_get ('myBookmarks', data, '1') as integer);
shared := cast (BMK.WA.xml_get ('mySharedBookmarks', data, '0') as integer);
-- search in my own
if (own = 1)
{
state := '00000';
sql := BMK.WA.sfolder_sql (domain_id, account_id, account_rights, 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 := BMK.WA.xml_get ('grants', data);
grants := split_and_decode (trim (grants, ','), 0, '\0\0,');
for (select G_ID as _GID from BMK..GRANTS_OBJECT_VIEW where GOW_TO = account_id) do
{
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_ID = _GID) 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, account_rights, newData, maxRows, 'B');
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.shareNode (
in account_id integer,
in node varchar,
in grants varchar,
in override integer)
{
declare N, pos, id integer;
declare name, V any;
grants := replace(grants, ' ', '');
grants := replace(grants, ',,', ',');
grants := trim (grants, ',', '');
grants := grants || ',';
for (select U_ID, U_NAME from BMK.WA.GRANTS, DB.DBA.SYS_USERS where G_GRANTER_ID = account_id and G_GRANTEE_ID = U_ID and lcase(G_OBJECT_TYPE) = lcase(BMK.WA.node_type (node)) and G_OBJECT_ID = BMK.WA.node_id (node)) do
{
name := U_NAME;
id := U_ID;
pos := strstr(grants, name || ',');
if (isnull(pos))
{
if (override)
delete from BMK.WA.GRANTS where G_GRANTER_ID = account_id and G_GRANTEE_ID = id and lcase(G_OBJECT_TYPE) = lcase(BMK.WA.node_type (node)) and G_OBJECT_ID = BMK.WA.node_id (node);
} else {
grants := replace(grants, name || ',', '');
}
}
V := split_and_decode(trim (grants, ','), 0, '\0\0,');
for (N := 0; N < length(V); N := N + 1)
{
id := (select U_ID from SYS_USERS where U_NAME = V[N]);
if (not isnull(id))
insert into BMK.WA.GRANTS (G_GRANTER_ID, G_GRANTEE_ID, G_TYPE, G_OBJECT_TYPE, G_OBJECT_ID)
values(account_id, id, 'G', ucase(BMK.WA.node_type (node)), BMK.WA.node_id (node));
}
}
;
-------------------------------------------------------------------------------
--
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)
{
declare id varchar;
id := coalesce((select SF_ID from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id and SF_NAME = name), -1);
if (id = -1)
{
insert into BMK.WA.SFOLDER (SF_DOMAIN_ID, SF_NAME, SF_DATA)
values(domain_id, name, data);
} else {
update BMK.WA.SFOLDER
set SF_DATA = data
where SF_ID = id;
}
return (select SF_ID from BMK.WA.SFOLDER where SF_DOMAIN_ID = domain_id and SF_NAME = name);
}
;
-------------------------------------------------------------------------------
--
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.sfolder_name (
in sfolder_id integer)
{
return coalesce((select SF_NAME from BMK.WA.SFOLDER where SF_ID = sfolder_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.tag_id (
in tag varchar)
{
tag := trim(tag);
tag := replace (tag, ' ', '_');
tag := replace (tag, '+', '_');
return tag;
}
;
---------------------------------------------------------------------------------
--
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, ' ^T', 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.tags2delicious (
inout tags varchar)
{
declare aVector any;
declare aResult varchar;
declare N, M integer;
aResult := '';
aVector := BMK.WA.tags2vector(tags);
for (N := 0; N < length(aVector); N := N + 1)
{
aResult := aResult || ' ' || replace(aVector[N], ' ', '_');
}
return aResult;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_exchangeTest (
inout tagsEntry any,
inout tagsInclude any := null,
inout tagsExclude any := null)
{
declare N integer;
declare tags, testTags any;
if (is_empty_or_null (tagsEntry) and not is_empty_or_null (tagsInclude))
goto _false;
-- test exclude tags
if (is_empty_or_null (tagsExclude))
goto _include;
if (is_empty_or_null (tagsEntry))
goto _include;
tags := BMK.WA.tags2vector (tagsEntry);
testTags := BMK.WA.tags2vector (tagsExclude);
for (N := 0; N < length (tags); N := N + 1)
{
if (BMK.WA.vector_contains (testTags, tags [N]))
goto _false;
}
_include:;
-- test include tags
if (is_empty_or_null (tagsInclude))
goto _true;
tags := BMK.WA.tags2vector (tagsEntry);
testTags := BMK.WA.tags2vector (tagsInclude);
for (N := 0; N < length (tags); N := N + 1)
{
if (BMK.WA.vector_contains (testTags, tags [N]))
goto _true;
}
_false:;
return 0;
_true:;
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings (
inout domain_id integer)
{
return coalesce((select deserialize (blob_to_string (S_DATA)) from BMK.WA.SETTINGS where S_DOMAIN_ID = domain_id), vector ());
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_init (
inout settings any)
{
BMK.WA.set_keyword ('chars', settings, cast (get_keyword ('chars', settings, '60') as integer));
BMK.WA.set_keyword ('rows', settings, cast (get_keyword ('rows', settings, '10') as integer));
BMK.WA.set_keyword ('tbLabels', settings, cast (get_keyword ('tbLabels', settings, '1') as integer));
BMK.WA.set_keyword ('atomVersion', settings, get_keyword ('atomVersion', settings, '1.0'));
BMK.WA.set_keyword ('conv', settings, cast (get_keyword ('conv', settings, '0') as integer));
BMK.WA.set_keyword ('conv_init', settings, cast (get_keyword ('conv_init', settings, '0') as integer));
BMK.WA.set_keyword ('panes', settings, cast (get_keyword ('panes', settings, '0') as integer));
BMK.WA.set_keyword ('bookmarkOpen', settings, cast (get_keyword ('bookmarkOpen', settings, '0') as integer));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_chars (
inout settings any)
{
return cast (get_keyword ('chars', settings, '60') as integer);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_rows (
inout settings any)
{
return cast (get_keyword ('rows', settings, '10') as integer);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.settings_atomVersion (
inout settings any)
{
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.dav_logical_home (
inout account_id integer) returns varchar
{
declare home any;
home := BMK.WA.dav_home (account_id);
if (not isnull (home))
home := replace (home, '/DAV', '');
return home;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.host_protocol ()
{
return case when is_https_ctx () then 'https://' else 'http://' end;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.host_url ()
{
declare host varchar;
declare exit handler for sqlstate '*' { goto _default; };
if (is_http_ctx ())
{
host := http_request_header (http_request_header ( ) , 'Host' , null , sys_connected_server_address ());
if (isstring (host) and strchr (host , ':') is null)
{
declare hp varchar;
declare hpa any;
hp := sys_connected_server_address ();
hpa := split_and_decode ( hp , 0 , '\0\0:');
host := host || ':' || hpa [1];
}
goto _exit;
}
_default:;
host := cfg_item_value (virtuoso_ini_path (), 'URIQA', 'DefaultHost');
if (host is null)
{
host := sys_stat ('st_host_name');
if (server_http_port () <> '80')
host := host || ':' || server_http_port ();
}
_exit:;
if (host not like BMK.WA.host_protocol () || '%')
host := BMK.WA.host_protocol () || host;
return host;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.bookmarks_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 ('http://', DB.DBA.wa_cname (), 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('http://%s/dataspace/%U/bookmark/%U/sioc.rdf', DB.DBA.wa_cname (), BMK.WA.domain_owner_name (domain_id), replace (BMK.WA.domain_name (domain_id), '+', '%2B'));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.gems_url (
in domain_id integer)
{
return sprintf('http://%s/dataspace/%U/bookmark/%U/gems/', DB.DBA.wa_cname (), BMK.WA.domain_owner_name (domain_id), replace (BMK.WA.domain_name (domain_id), '+', '%2B'));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.foaf_url (
in domain_id integer)
{
return SIOC..person_iri (sprintf('http://%s%s/%s#this', SIOC..get_cname (), SIOC..get_base_path (), BMK.WA.domain_owner_name (domain_id)), '/about.rdf');
}
;
-------------------------------------------------------------------------------
--
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.bookmark_url (
in domain_id integer,
in bookmark_id integer)
{
return concat (BMK.WA.bookmarks_url (domain_id), 'bookmarks.vspx?id=', cast (bookmark_id as varchar));
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.banner_links (
in domain_id integer,
in sid varchar := null,
in realm varchar := null)
{
if (domain_id <= 0)
return 'Public Bookmarks';
return sprintf ('%V (%V)',
BMK.WA.domain_sioc_url (domain_id),
BMK.WA.domain_name (domain_id),
BMK.WA.domain_name (domain_id),
BMK.WA.account_sioc_url (domain_id),
BMK.WA.account_fullName (BMK.WA.domain_owner_id (domain_id)),
BMK.WA.account_fullName (BMK.WA.domain_owner_id (domain_id))
);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_content (
in uri varchar,
in auth_uid varchar := null,
in auth_pwd varchar := null)
{
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;
newUri := replace (uri, ' ', '%20');
reqHdr := null;
if (isnull (auth_uid) or isnull (auth_pwd))
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.iri_fix (
in S varchar)
{
if (is_https_ctx ())
{
declare V any;
V := rfc1808_parse_uri (cast (S as varchar));
V [0] := 'https';
V [1] := http_request_header (http_request_header(), 'Host', null, registry_get ('URIQADefaultHost'));
S := DB.DBA.vspx_uri_compose (V);
}
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.url_fix (
in S varchar,
in sid varchar := null,
in realm varchar := null)
{
declare T varchar;
T := '&';
if (isnull (strchr (S, '?')))
{
T := '?';
}
if (not is_empty_or_null (sid))
{
S := S || T || 'sid=' || sid;
T := '&';
}
if (not is_empty_or_null (realm))
{
S := S || T || 'realm=' || realm;
}
return S;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.uid ()
{
return sprintf ('%s@%s', uuid (), sys_stat ('st_host_name'));
}
;
--------------------------------------------------------------------------------
--
create procedure BMK.WA.exchange_exec (
in _id integer,
in _mode integer := 0,
in _exMode integer := null)
{
declare retValue any;
declare exit handler for SQLSTATE '*'
{
update BMK.WA.EXCHANGE
set EX_EXEC_LOG = __SQL_STATE || ' ' || BMK.WA.test_clear (__SQL_MESSAGE)
where EX_ID = _id;
commit work;
if (_mode)
resignal;
};
retValue := BMK.WA.exchange_exec_internal (_id, _exMode);
update BMK.WA.EXCHANGE
set EX_EXEC_TIME = now (),
EX_EXEC_LOG = null,
EX_UPDATE_SUBTYPE = null
where EX_ID = _id;
commit work;
return retValue;
}
;
--------------------------------------------------------------------------------
--
create procedure BMK.WA.exchange_entry_update (
in _domain_id integer)
{
for (select EX_ID as _id from BMK.WA.EXCHANGE where EX_DOMAIN_ID = _domain_id and EX_TYPE = 0 and EX_UPDATE_TYPE = 1) do
{
if (connection_get ('__bookmark_import') = '1')
{
update BMK.WA.EXCHANGE
set EX_UPDATE_SUBTYPE = 1
where EX_ID = _id;
} else {
BMK.WA.exchange_exec (_id);
}
}
}
;
--------------------------------------------------------------------------------
--
create procedure BMK.WA.exchange_exec_internal (
in _id integer,
in _exMode integer := null)
{
for (select EX_DOMAIN_ID as _domain_id, EX_TYPE as _direction, deserialize (EX_OPTIONS) as _options from BMK.WA.EXCHANGE where EX_ID = _id) do
{
declare _type, _name, _pName, _user, _password, _tagsInclude, _tagsExclude, _tags, _folderPath, _folder_id any;
declare _content any;
_type := get_keyword ('type', _options);
_name := get_keyword ('name', _options);
_user := get_keyword ('user', _options);
_password := get_keyword ('password', _options);
_tagsInclude := get_keyword ('tagsInclude', _options);
_tagsExclude := get_keyword ('tagsExclude', _options);
_tags := get_keyword ('tags', _options);
_folderPath := get_keyword ('folderPath', _options);
_folder_id := BMK.WA.folder_create (_domain_id, _folderPath, null);
-- publish
if (_direction = 0)
{
if ((_type = 1) or (_type = 2))
{
_content := BMK.WA.export_netscape (_domain_id, _folder_id, _options);
if (_type = 1)
{
declare retValue, permissions any;
{
declare exit handler for SQLSTATE '*'
{
signal ('BMK02', 'The export/publication did not pass successfully. Please verify the path and parameters values!<>');
};
permissions := BMK.WA.dav_permissions (_name, _user, _password);
_pName := replace (_name, ' ', '%20');
_name := http_physical_path_resolve (_name);
if (_name is null)
{
_name := _pName;
}
else if (_name not like '/DAV/%')
{
_name := '/DAV' || _name;
}
retValue := DB.DBA.DAV_RES_UPLOAD (_name, _content, 'text/html', permissions, _user, null, _user, _password);
if (DB.DBA.DAV_HIDE_ERROR (retValue) is null)
{
signal ('BMK01', 'WebDAV: ' || DB.DBA.DAV_PERROR (retValue) || '.<>');
}
}
}
else if (_type = 2)
{
declare retContent, resHeader, reqHeader any;
reqHeader := null;
if (_user <> '')
{
reqHeader := sprintf ('Authorization: Basic %s', encode_base64 (_user || ':' || _password));
}
commit work;
{
declare exit handler for SQLSTATE '*'
{
signal ('BMK02', 'Connection Error in HTTP Client!<>');
};
retContent := http_get (_name, resHeader, 'PUT', reqHeader, _content);
if (not (length (resHeader) > 0 and (resHeader[0] like 'HTTP/1._ 2__ %' or resHeader[0] like 'HTTP/1._ 3__ %')))
{
signal ('BMK02', 'The export/publication did not pass successfully. Please verify the path and parameters values!<>');
}
}
}
}
else if (_type = 3)
{
-- Delicious
declare rc, path, tmp, xt, posts any;
_name := 'https://api.del.icio.us/v1/posts/add?replace=yes';
_content := BMK.WA.bookmark_export (_domain_id, _folder_id, _options);
xt := xml_tree_doc (xml_tree (_content));
posts := xpath_eval ('//bookmark', xt, 0);
foreach (any post in posts) do
{
commit work;
path := _name;
tmp := cast (xpath_eval ('@uri', post) as varchar);
if (not is_empty_or_null (tmp))
path := sprintf ('%s&url=%U', path, tmp);
tmp := cast (xpath_eval ('@name', post) as varchar);
if (not is_empty_or_null (tmp))
path := sprintf ('%s&description=%U', path, tmp);
tmp := cast (xpath_eval ('@description', post) as varchar);
if (not is_empty_or_null (tmp))
path := sprintf ('%s&extended=%U', path, tmp);
tmp := cast (xpath_eval ('@tags', post) as varchar);
if (not is_empty_or_null (tmp))
path := sprintf ('%s&tags=%U', path, BMK.WA.tags2delicious(tmp));
rc := http_client (path, _user, _password, 'POST', null, null, null, null);
}
}
}
-- subscribe
else if (_direction = 1)
{
if (_type = 1)
{
_name := BMK.WA.host_url () || _name;
_content := BMK.WA.dav_content (_name, _user, _password);
}
else if (_type = 2)
{
_content := BMK.WA.dav_content (_name, _user, _password);
}
else if (_type = 3)
{
-- Delicious
_name := 'https://api.del.icio.us/v1/posts/all';
_content := http_client (_name, _user, _password, 'GET', null, null, null, null);
if (not is_empty_or_null (xpath_eval('string(//title)', xml_tree_doc (xml_tree (_content, 2)))))
{
_content := null;
}
}
if (isnull (_content))
{
signal ('BMK01', 'Bad import/subscription source!<>');
}
BMK.WA.bookmark_import (_content, _domain_id, _folder_id, _tags);
}
}
}
;
--------------------------------------------------------------------------------
--
create procedure BMK.WA.exchange_scheduler ()
{
declare id, days, rc, err integer;
declare bm any;
declare _error integer;
declare _bookmark any;
declare _dt datetime;
declare exID any;
_dt := now ();
declare cr static cursor for select EX_ID
from BMK.WA.EXCHANGE
where (EX_UPDATE_TYPE = 2 and (EX_EXEC_TIME is null or dateadd ('minute', EX_UPDATE_INTERVAL, EX_EXEC_TIME) < _dt))
or (EX_UPDATE_TYPE = 1 and EX_UPDATE_SUBTYPE is not null);
whenever not found goto _done;
open cr (exclusive, prefetch 1);
fetch cr into exID;
while (1)
{
_bookmark := bookmark(cr);
_error := 0;
close cr;
{
declare exit handler for sqlstate '*'
{
_error := 1;
goto _next;
};
BMK.WA.exchange_exec (exID, 1);
commit work;
}
_next:
open cr (exclusive, prefetch 1);
fetch cr bookmark _bookmark into exID;
if (_error)
fetch cr next into exID;
}
_done:;
close cr;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_check_authenticate (
in _path varchar,
in _user varchar,
in _password varchar,
in _permissions varchar)
{
declare _type varchar;
_type := case when (strrchr (_path, '/') = length (_path) - 1) then 'C' else 'R' end;
if (DB.DBA.DAV_AUTHENTICATE (DB.DBA.DAV_SEARCH_ID (_path, _type), _type, _permissions, _user, _password) < 0)
return 0;
return 1;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_parent (
in path varchar)
{
declare pos integer;
path := trim (path, '/');
pos := strrchr (path, '/');
if (not isnull (pos))
path := substring (path, 1, pos);
return '/' || path || '/';
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dav_permissions (
in path varchar,
in auth_name varchar := null,
in auth_pwd varchar := null)
{
declare uid, gid integer;
declare permissions varchar;
permissions := -1;
permissions := DB.DBA.DAV_PROP_GET (path, ':virtpermissions', auth_name, auth_pwd);
if (permissions < 0)
{
path := BMK.WA.dav_parent (path);
if (path <> BMK.WA.dav_home (BMK.WA.account_id (auth_name)))
permissions := DB.DBA.DAV_PROP_GET (path, ':virtpermissions', auth_name, auth_pwd);
if (permissions < 0)
permissions := USER_GET_OPTION (auth_name, 'PERMISSIONS');
}
return permissions;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_netscape (
in domain_id integer,
in folder_id integer,
in options any)
{
declare retValue any;
retValue := string_output ();
http_value (xslt (BMK.WA.xslt_full ('Netscape.xsl'), xtree_doc (BMK.WA.bookmark_export (domain_id, folder_id, options))), null, retValue);
return string_output_string (retValue);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.export_xbel (
in domain_id integer,
in options any)
{
declare retValue any;
retValue := string_output ();
http_value (xslt (BMK.WA.xslt_full ('XBEL.xsl'), xtree_doc (BMK.WA.bookmark_export (domain_id, null, options))), null, retValue);
return string_output_string (retValue);
}
;
-------------------------------------------------------------------------------
--
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\', BMK.WA.utf2wide (U_FULL_NAME || \' <\' || 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.bookmarks_url()), \n', retValue);
http (' (select XMLAGG (XMLELEMENT(\'http://www.w3.org/2005/Atom:link\', XMLATTRIBUTES (SH_URL as "href", \'hub\' as "rel", \'PubSubHub\' as "title"))) from ODS.DBA.SVC_HOST, ODS.DBA.APP_PING_REG where SH_PROTO = \'PubSubHub\' and SH_ID = AP_HOST_ID and AP_WAI_ID = ), \n', retValue);
http (' XMLELEMENT(\'language\', \'en-us\') \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/ods/:modified\', BMK.WA.dt_iso8601 (BD_UPDATED)))) \n', retValue);
http ('from (select top 15 \n', retValue);
http (' BD_NAME, \n', retValue);
http (' BD_DESCRIPTION, \n', retValue);
http (' BD_UPDATED, \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_UPDATED 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;
}
;
-------------------------------------------------------------------------------
--
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 (BMK.WA.settings (domain_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_comment_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 (', BD_ID)), \n', retValue);
http (' XMLELEMENT (\'pubDate\', BMK.WA.dt_rfc1123 (BD_CREATED)), \n', retValue);
http (' XMLELEMENT (\'generator\', \'Virtuoso Universal Server \' || sys_stat(\'st_dbms_ver\')), \n', retValue);
http (' XMLELEMENT (\'http://purl.org/dc/elements/1.1/:creator\', U_FULL_NAME) \n', retValue);
http (' from \n', retValue);
http (' BMK.WA.BOOKMARK_DOMAIN, DB.DBA.SYS_USERS, DB.DBA.WA_INSTANCE \n', retValue);
http (' where \n', retValue);
http (' BD_ID = :id and U_ID = and BD_DOMAIN_ID = and WAI_ID = BD_DOMAIN_ID and WAI_IS_PUBLIC = 1\n', retValue);
http (']]>\n', retValue);
http (')||\'conversation.vspx\'||\'?id=\'||cast (BC_BOOKMARK_ID as varchar)||\'#\'||cast (BC_ID as varchar)),\n', retValue);
http (' XMLELEMENT (\'link\', BMK.WA.bookmarks_url ()||\'conversation.vspx\'||\'?id=\'||cast (BC_BOOKMARK_ID as varchar)||\'#\'||cast (BC_ID as varchar)),\n', retValue);
http (' XMLELEMENT (\'http://purl.org/dc/elements/1.1/:creator\', BC_U_MAIL),\n', retValue);
http (' XMLELEMENT (\'pubDate\', DB.DBA.date_rfc1123 (BC_UPDATED)),\n', retValue);
http (' XMLELEMENT (\'description\', BMK.WA.utf2wide (blob_to_string (BC_COMMENT))))) \n', retValue);
http (' from \n', retValue);
http (' (select TOP 15 \n', retValue);
http (' BC_ID, \n', retValue);
http (' BC_BOOKMARK_ID, \n', retValue);
http (' BC_TITLE, \n', retValue);
http (' BC_COMMENT, \n', retValue);
http (' BC_U_MAIL, \n', retValue);
http (' BC_UPDATED \n', retValue);
http (' from \n', retValue);
http (' BMK.WA.BOOKMARK_COMMENT, DB.DBA.WA_INSTANCE \n', retValue);
http (' where \n', retValue);
http (' BC_BOOKMARK_ID = :id and WAI_ID = BC_DOMAIN_ID and WAI_IS_PUBLIC = 1\n', retValue);
http (' order by BC_UPDATED desc\n', retValue);
http (' ) sub \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.xtree_doc (
in xt varchar,
in xtMode integer := 0)
{
declare exit handler for SQLSTATE '*' {
return null;
};
return xtree_doc (xt, xtMode);
}
;
-----------------------------------------------------------------------------
--
create procedure BMK.WA.xml_set (
in id varchar,
inout pXml varchar,
in value any)
{
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.string2nntp (
in S varchar)
{
S := replace (S, '.', '_');
S := replace (S, '@', '_');
return sprintf ('%U', S);
}
;
-------------------------------------------------------------------------------
--
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 retValue any;
if (isstring (S))
{
retValue := charset_recode (S, 'UTF-8', '_WIDE_');
if (iswidestring (retValue))
return retValue;
}
return S;
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.wide2utf (
in S any)
{
declare retValue any;
if (iswidestring (S))
{
retValue := charset_recode (S, '_WIDE_', 'UTF-8' );
if (isstring (retValue))
return retValue;
}
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.isVector (
inout aVector any)
{
if (isarray (aVector) and not isstring (aVector))
return 1;
return 0;
}
;
-------------------------------------------------------------------------------
--
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 varchar := '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_tree (
in domain_id integer,
in user_id integer,
in node varchar,
in path varchar)
{
declare node_type, node_id any;
declare retValue any;
retValue := vector ();
node_id := BMK.WA.node_id(node);
node_type := BMK.WA.node_type(node);
if ((node_type = 'r') and (node_id = 0))
{
retValue := vector('Bookmarks', BMK.WA.make_node ('f', -1), BMK.WA.make_path('', 'f', -1));
}
else if ((node_type = 'r') and (node_id = 1))
{
retValue := 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), 'Shared Bookmarks By', BMK.WA.make_node ('u', -1), BMK.WA.make_path(path, 'u', -1));
}
else if ((node_type = 'u') and (node_id = -1))
{
for (select distinct U_ID, U_NAME from BMK..GRANTS_VIEW where GW_ID = user_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)));
}
else 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)));
}
else 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)));
}
else if ((node_type = 'u') and (node_id >= 0))
{
for (select distinct F_ID, F_NAME from BMK.WA.FOLDER, BMK..GRANTS_OBJECT_VIEW where GOW_TYPE = 'F' and F_ID = G_OBJECT_ID and GOW_TO = user_id and GOW_FROM = 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)));
}
else 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_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 := -1)
{
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_rs(
in p0 integer)
{
declare c0 integer;
declare c1 varchar;
declare c2 datetime;
result_names(c0, c1, c2);
for (select top 10 *
from (select BD_ID,
BD_NAME,
BD_UPDATED
from BMK.WA.BOOKMARK_DOMAIN
where BD_DOMAIN_ID = p0
order by BD_UPDATED desc
) x) do
{
result (BD_ID, BD_NAME, coalesce (BD_UPDATED, now ()));
}
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.dashboard_get(
in domain_id integer)
{
declare account_id integer;
declare aStream any;
account_id := BMK.WA.domain_owner_id (domain_id);
aStream := string_output ();
http ('', aStream);
for (select x.* from BMK.WA.dashboard_rs(p0)(_id integer, _name varchar, _time datetime) x where p0 = domain_id) do
{
http ('', aStream);
http (sprintf ('
%s
', date_iso8601 (_time)), aStream);
http (sprintf ('', _name), aStream);
http (sprintf ('%V', SIOC..bmk_post_iri (domain_id, _id)), aStream);
http (sprintf ('', BMK.WA.account_fullName (account_id)), aStream);
http (sprintf ('%s', BMK.WA.account_name (account_id)), aStream);
http ('', aStream);
}
http ('', aStream);
return string_output_string (aStream);
}
;
-------------------------------------------------------------------------------
--
-- 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)
{
if (isnull(pDate))
return null;
if (isnull(pUser))
pUser := connection_get('owner_user');
if (isnull(pUser))
pUser := connection_get('vspx_user');
if (is_empty_or_null (pUser))
return pDate;
return dateadd('minute', coalesce (USER_GET_OPTION(pUser, 'TIMEZONE'), 0) * 60, 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 varchar := 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;
declare exit handler for sqlstate '*' {
return '';
};
S := '';
for (N := 1; N <= length(pFormat); N := N + 1)
{
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);
}
}
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 integer)
{
declare V any;
V := regexp_parse('[0-9]+', S, N);
if (length(V) > 1)
{
N := V[1];
return atoi (subseq (S, V[0], 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)
{
S := substring (S, 1, coalesce (strstr (S, '<>'), length (S)));
S := substring (S, 1, coalesce (strstr (S, '\nin'), length (S)));
return 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 than %s!<>', valueName, cast (tmp as varchar)));
if (__SQL_STATE = 'MAX')
signal ('TEST', sprintf('''%s'' value should be less than %s!<>', valueName, cast (tmp as varchar)));
if (__SQL_STATE = 'MINLENGTH')
signal ('TEST', sprintf('The length of field ''%s'' should be greater than %s characters!<>', valueName, cast (tmp as varchar)));
if (__SQL_STATE = 'MAXLENGTH')
signal ('TEST', sprintf('The length of field ''%s'' should be less than %s characters!<>', valueName, cast (tmp as varchar)));
if (__SQL_STATE = 'SPECIAL')
signal ('TEST', __SQL_MESSAGE);
signal ('TEST', 'Unknown validation error!<>');
--resignal;
};
if (isstring (value))
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, cast (value as varchar));
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;
if (__SQL_STATE = 'SPECIAL')
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 T varchar)
{
declare S any;
S := T;
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.rdfa_value (
in S varchar,
in property varchar)
{
if (isnull (S))
return '';
return sprintf ('%s', property, S);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.discussion_check ()
{
if (isnull (VAD_CHECK_VERSION ('Discussion')))
return 0;
return 1;
}
;
-----------------------------------------------------------------------------------------
--
-- NNTP Conversation
--
-----------------------------------------------------------------------------------------
create procedure BMK.WA.conversation_enable(
in domain_id integer)
{
return cast (get_keyword ('conv', BMK.WA.settings(domain_id), '0') as integer);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.cm_root_node (
in bookmark_id varchar)
{
declare root_id any;
declare xt any;
root_id := (select BC_ID from BMK.WA.BOOKMARK_COMMENT where BC_BOOKMARK_ID = bookmark_id and BC_PARENT_ID is null);
xt := (select xmlagg (xmlelement ('node', xmlattributes (BC_ID as id, BC_ID as name, BC_BOOKMARK_ID as post)))
from BMK.WA.BOOKMARK_COMMENT
where BC_BOOKMARK_ID = bookmark_id
and BC_PARENT_ID = root_id
order by BC_UPDATED);
return xpath_eval ('//node', xt, 0);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.cm_child_node (
in bookmark_id varchar,
inout node any)
{
declare parent_id int;
declare xt any;
parent_id := xpath_eval ('number (@id)', node);
bookmark_id := xpath_eval ('@post', node);
xt := (select xmlagg (xmlelement ('node', xmlattributes (BC_ID as id, BC_ID as name, BC_BOOKMARK_ID as post)))
from BMK.WA.BOOKMARK_COMMENT
where BC_BOOKMARK_ID = bookmark_id and BC_PARENT_ID = parent_id order by BC_UPDATED);
return xpath_eval ('//node', xt, 0);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.make_rfc_id (
in bookmark_id integer,
in comment_id integer := null)
{
declare hashed, host any;
hashed := md5 (uuid ());
host := sys_stat ('st_host_name');
if (isnull (comment_id))
return sprintf ('<%d.%s@%s>', bookmark_id, hashed, host);
return sprintf ('<%d.%d.%s@%s>', bookmark_id, comment_id, hashed, host);
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.make_mail_subject (
in txt any,
in id varchar := null)
{
declare enc any;
enc := encode_base64 (BMK.WA.wide2utf (txt));
enc := encode_base64 (txt);
enc := replace (enc, '\r\n', '');
txt := concat ('Subject: =?UTF-8?B?', enc, '?=\r\n');
if (not isnull (id))
txt := concat (txt, 'X-Virt-NewsID: ', uuid (), ';', id, '\r\n');
return txt;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.make_post_rfc_header (
in mid varchar,
in refs varchar,
in gid varchar,
in title varchar,
in rec datetime,
in author_mail varchar)
{
declare ses any;
ses := string_output ();
http (BMK.WA.make_mail_subject (title), ses);
http (sprintf ('Date: %s\r\n', DB.DBA.date_rfc1123 (rec)), ses);
http (sprintf ('Message-Id: %s\r\n', mid), ses);
if (not isnull (refs))
http (sprintf ('References: %s\r\n', refs), ses);
http (sprintf ('From: %s\r\n', author_mail), ses);
http ('Content-Type: text/html; charset=UTF-8\r\n', ses);
http (sprintf ('Newsgroups: %s\r\n\r\n', gid), ses);
ses := string_output_string (ses);
return ses;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.make_post_rfc_msg (
inout head varchar,
inout body varchar,
in tree int := 0)
{
declare ses any;
ses := string_output ();
http (coalesce (head, ''), ses);
http (coalesce (body, ''), ses);
http ('\r\n.\r\n', ses);
ses := string_output_string (ses);
if (tree)
ses := serialize (mime_tree (ses));
return ses;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_root (
in domain_id integer,
in bookmark_id integer)
{
declare owner_id integer;
declare name, mail, title, comment any;
owner_id := BMK.WA.domain_owner_id (domain_id);
name := BMK.WA.account_fullName (owner_id);
mail := BMK.WA.account_mail (owner_id);
select coalesce (BD_NAME, ''), coalesce (BD_DESCRIPTION, '') into title, comment from BMK.WA.BOOKMARK_DOMAIN where BD_ID = bookmark_id;
insert into BMK.WA.BOOKMARK_COMMENT (BC_PARENT_ID, BC_DOMAIN_ID, BC_BOOKMARK_ID, BC_TITLE, BC_COMMENT, BC_U_NAME, BC_U_MAIL, BC_CREATED, BC_UPDATED)
values (null, domain_id, bookmark_id, title, comment, name, mail, now (), now ());
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_update_item (
in domain_id integer,
in bookmark_id integer)
{
declare grp, ngnext integer;
declare nntpName, rfc_id varchar;
nntpName := BMK.WA.domain_nntp_name (domain_id);
select NG_GROUP, NG_NEXT_NUM into grp, ngnext from DB..NEWS_GROUPS where NG_NAME = nntpName;
select BC_RFC_ID into rfc_id from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = domain_id and BC_BOOKMARK_ID = bookmark_id and BC_PARENT_ID is null;
if (exists (select 1 from DB.DBA.NEWS_MULTI_MSG where NM_KEY_ID = rfc_id and NM_GROUP = grp))
return;
if (ngnext < 1)
ngnext := 1;
for (select BC_RFC_ID as rfc_id from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = domain_id and BC_BOOKMARK_ID = bookmark_id) do
{
insert soft DB.DBA.NEWS_MULTI_MSG (NM_KEY_ID, NM_GROUP, NM_NUM_GROUP) values (rfc_id, grp, ngnext);
ngnext := ngnext + 1;
}
set triggers off;
update DB.DBA.NEWS_GROUPS set NG_NEXT_NUM = ngnext + 1 where NG_NAME = nntpName;
DB.DBA.ns_up_num (grp);
set triggers on;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_update (
in domain_id integer,
in oInstance varchar,
in nInstance varchar,
in oConversation integer := null,
in nConversation integer := null)
{
declare nntpGroup integer;
declare nDescription varchar;
if (isnull (oInstance))
oInstance := BMK.WA.domain_nntp_name (domain_id);
if (isnull (nInstance))
nInstance := BMK.WA.domain_nntp_name (domain_id);
nDescription := BMK.WA.domain_description (domain_id);
if (isnull (nConversation))
{
update DB.DBA.NEWS_GROUPS
set NG_POST = 1,
NG_NAME = nInstance,
NG_DESC = nDescription
where NG_NAME = oInstance;
return;
}
if (oConversation = 1 and nConversation = 0)
{
nntpGroup := (select NG_GROUP from DB.DBA.NEWS_GROUPS where NG_NAME = oInstance);
delete from DB.DBA.NEWS_MULTI_MSG where NM_GROUP = nntpGroup;
delete from DB.DBA.NEWS_GROUPS where NG_NAME = oInstance;
}
else if (oConversation = 0 and nConversation = 1)
{
declare exit handler for sqlstate '*' { return; };
insert into DB.DBA.NEWS_GROUPS (NG_NEXT_NUM, NG_NAME, NG_DESC, NG_SERVER, NG_POST, NG_UP_TIME, NG_CREAT, NG_UP_INT, NG_PASS, NG_UP_MESS, NG_NUM, NG_FIRST, NG_LAST, NG_LAST_OUT, NG_CLEAR_INT, NG_TYPE)
values (0, nInstance, nDescription, null, 1, now(), now(), 30, 0, 0, 0, 0, 0, 0, 120, 'BOOKMARKS');
}
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_fill (
in domain_id integer)
{
declare exit handler for SQLSTATE '*', not found {
return;
};
declare grp, ngnext integer;
declare nntpName varchar;
for (select BD_ID from BMK.WA.BOOKMARK_DOMAIN where BD_DOMAIN_ID = domain_id) do
{
if (not exists (select 1 from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = domain_id and BC_BOOKMARK_ID = BD_ID and BC_PARENT_ID is null))
BMK.WA.nntp_root (domain_id, BD_ID);
}
nntpName := BMK.WA.domain_nntp_name (domain_id);
select NG_GROUP, NG_NEXT_NUM into grp, ngnext from DB..NEWS_GROUPS where NG_NAME = nntpName;
if (ngnext < 1)
ngnext := 1;
for (select BC_RFC_ID as rfc_id from BMK.WA.BOOKMARK_COMMENT where BC_DOMAIN_ID = domain_id) do
{
insert soft DB.DBA.NEWS_MULTI_MSG (NM_KEY_ID, NM_GROUP, NM_NUM_GROUP) values (rfc_id, grp, ngnext);
ngnext := ngnext + 1;
}
set triggers off;
update DB.DBA.NEWS_GROUPS set NG_NEXT_NUM = ngnext + 1 where NG_NAME = nntpName;
DB.DBA.ns_up_num (grp);
set triggers on;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.mail_address_split (
in author any,
out person any,
out email any)
{
declare pos int;
person := '';
pos := strchr (author, '<');
if (pos is not NULL)
{
person := "LEFT" (author, pos);
email := subseq (author, pos, length (author));
email := replace (email, '<', '');
email := replace (email, '>', '');
person := trim (replace (person, '"', ''));
} else {
pos := strchr (author, '(');
if (pos is not NULL)
{
email := trim ("LEFT" (author, pos));
person := subseq (author, pos, length (author));
person := replace (person, '(', '');
person := replace (person, ')', '');
}
}
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_decode_subject (
inout str varchar)
{
declare match varchar;
declare inx int;
inx := 50;
str := replace (str, '\t', '');
match := regexp_match ('=\\?[^\\?]+\\?[A-Z]\\?[^\\?]+\\?=', str);
while (match is not null and inx > 0)
{
declare enc, ty, dat, tmp, cp, dec any;
cp := match;
tmp := regexp_match ('^=\\?[^\\?]+\\?[A-Z]\\?', match);
match := substring (match, length (tmp)+1, length (match) - length (tmp) - 2);
enc := regexp_match ('=\\?[^\\?]+\\?', tmp);
tmp := replace (tmp, enc, '');
enc := trim (enc, '?=');
ty := trim (tmp, '?');
if (ty = 'B')
{
dec := decode_base64 (match);
} else if (ty = 'Q') {
dec := uudecode (match, 12);
} else {
dec := '';
}
declare exit handler for sqlstate '2C000' { return;};
dec := charset_recode (dec, enc, 'UTF-8');
str := replace (str, cp, dec);
match := regexp_match ('=\\?[^\\?]+\\?[A-Z]\\?[^\\?]+\\?=', str);
inx := inx - 1;
}
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.nntp_process_parts (
in parts any,
inout body varchar,
inout amime any,
out result any,
in any_part int)
{
declare name1, mime1, name, mime, enc, content, charset varchar;
declare i, i1, l1, is_allowed int;
declare part any;
if (not isarray (result))
result := vector ();
if (not isarray (parts) or not isarray (parts[0]))
return 0;
part := parts[0];
name1 := get_keyword_ucase ('filename', part, '');
if (name1 = '')
name1 := get_keyword_ucase ('name', part, '');
mime1 := get_keyword_ucase ('Content-Type', part, '');
charset := get_keyword_ucase ('charset', part, '');
if (mime1 = 'application/octet-stream' and name1 <> '')
mime1 := http_mime_type (name1);
is_allowed := 0;
i1 := 0;
l1 := length (amime);
while (i1 < l1)
{
declare elm any;
elm := trim(amime[i1]);
if (mime1 like elm)
{
is_allowed := 1;
i1 := l1;
}
i1 := i1 + 1;
}
declare _cnt_disp any;
_cnt_disp := get_keyword_ucase('Content-Disposition', part, '');
if (is_allowed and (any_part or (name1 <> '' and _cnt_disp in ('attachment', 'inline'))))
{
name := name1;
mime := mime1;
enc := get_keyword_ucase ('Content-Transfer-Encoding', part, '');
content := subseq (body, parts[1][0], parts[1][1]);
if (enc = 'base64')
content := decode_base64 (content);
result := vector_concat (result, vector (vector (name, mime, content, _cnt_disp, enc, charset)));
return 1;
}
-- process the parts
if (isarray (parts[2]))
for (i := 0; i < length (parts[2]); i := i + 1)
BMK.WA.nntp_process_parts (parts[2][i], body, amime, result, any_part);
return 0;
}
;
-----------------------------------------------------------------------------------------
--
DB.DBA.NNTP_NEWS_MSG_ADD (
'BOOKMARKS',
'select
\'BOOKMARKS\',
BC_RFC_ID,
BC_RFC_REFERENCES,
0, -- NM_READ
null,
BC_UPDATED,
0, -- NM_STAT
null, -- NM_TRY_POST
0, -- NM_DELETED
BMK.WA.make_post_rfc_msg (BC_RFC_HEADER, BC_COMMENT, 1), -- NM_HEAD
BMK.WA.make_post_rfc_msg (BC_RFC_HEADER, BC_COMMENT),
BC_ID
from BMK.WA.BOOKMARK_COMMENT'
)
;
-----------------------------------------------------------------------------------------
--
create procedure DB.DBA.BOOKMARKS_NEWS_MSG_I (
inout N_NM_ID any,
inout N_NM_REF any,
inout N_NM_READ any,
inout N_NM_OWN any,
inout N_NM_REC_DATE any,
inout N_NM_STAT any,
inout N_NM_TRY_POST any,
inout N_NM_DELETED any,
inout N_NM_HEAD any,
inout N_NM_BODY any)
{
declare uid, parent_id, domain_id, item_id any;
declare author, name, mail, tree, head, contentType, content, subject, title, cset any;
declare rfc_id, rfc_header, rfc_references, refs any;
uid := connection_get ('nntp_uid');
if (isnull (N_NM_REF) and isnull (uid))
signal ('CONVA', 'The post cannot be done via news client, this requires authentication.');
tree := deserialize (N_NM_HEAD);
head := tree [0];
contentType := get_keyword_ucase ('Content-Type', head, 'text/plain');
cset := upper (get_keyword_ucase ('charset', head));
author := get_keyword_ucase ('From', head, 'nobody@unknown');
subject := get_keyword_ucase ('Subject', head);
if (not isnull (subject))
BMK.WA.nntp_decode_subject (subject);
if (contentType like 'text/%')
{
declare st, en int;
declare last any;
st := tree[1][0];
en := tree[1][1];
if (en > st + 5) {
last := subseq (N_NM_BODY, en - 4, en);
if (last = '\r\n.\r')
en := en - 4;
}
content := subseq (N_NM_BODY, st, en);
if (cset is not null and cset <> 'UTF-8')
{
declare exit handler for sqlstate '2C000' { goto next_1;};
content := charset_recode (content, cset, 'UTF-8');
}
next_1:;
if (contentType = 'text/plain')
content := '
' || content || '
';
}
else if (contentType like 'multipart/%')
{
declare res, best_cnt any;
declare exit handler for sqlstate '*' { signal ('CONVX', __SQL_MESSAGE);};
BMK.WA.nntp_process_parts (tree, N_NM_BODY, vector ('text/%'), res, 1);
best_cnt := null;
content := null;
foreach (any elm in res) do
{
if (elm[1] = 'text/html' and (content is null or best_cnt = 'text/plain'))
{
best_cnt := 'text/html';
content := elm[2];
if (elm[4] = 'quoted-printable')
{
content := uudecode (content, 12);
} else if (elm[4] = 'base64') {
content := decode_base64 (content);
}
cset := elm[5];
} else if (best_cnt is null and elm[1] = 'text/plain') {
content := elm[2];
best_cnt := 'text/plain';
cset := elm[5];
}
if (elm[1] not like 'text/%')
signal ('CONVX', sprintf ('The post contains parts of type [%s] which is prohibited.', elm[1]));
}
if (length (cset) and cset <> 'UTF-8')
{
declare exit handler for sqlstate '2C000' { goto next_2;};
content := charset_recode (content, cset, 'UTF-8');
}
next_2:;
} else {
signal ('CONVX', sprintf ('The content type [%s] is not supported', contentType));
}
rfc_header := '';
for (declare i int, i := 0; i < length (head); i := i + 2)
{
if (lower (head[i]) <> 'content-type' and lower (head[i]) <> 'mime-version' and lower (head[i]) <> 'boundary' and lower (head[i]) <> 'subject')
rfc_header := rfc_header || head[i] ||': ' || head[i + 1]||'\r\n';
}
rfc_header := BMK.WA.make_mail_subject (subject) || rfc_header || 'Content-Type: text/html; charset=UTF-8\r\n\r\n';
rfc_references := N_NM_REF;
if (not isnull (N_NM_REF))
{
declare exit handler for not found { signal ('CONV1', 'No such article.');};
parent_id := null;
refs := split_and_decode (N_NM_REF, 0, '\0\0 ');
if (length (refs))
N_NM_REF := refs[length (refs) - 1];
select BC_ID, BC_DOMAIN_ID, BC_BOOKMARK_ID, BC_TITLE
into parent_id, domain_id, item_id, title
from BMK.WA.BOOKMARK_COMMENT
where BC_RFC_ID = N_NM_REF;
if (isnull (subject))
subject := 'Re: '|| title;
BMK.WA.mail_address_split (author, name, mail);
insert into BMK.WA.BOOKMARK_COMMENT (BC_PARENT_ID, BC_DOMAIN_ID, BC_BOOKMARK_ID, BC_TITLE, BC_COMMENT, BC_U_NAME, BC_U_MAIL, BC_UPDATED, BC_RFC_ID, BC_RFC_HEADER, BC_RFC_REFERENCES)
values (parent_id, domain_id, item_id, subject, content, name, mail, N_NM_REC_DATE, N_NM_ID, rfc_header, rfc_references);
}
}
;
-----------------------------------------------------------------------------------------
--
create procedure DB.DBA.BOOKMARKS_NEWS_MSG_U (
inout O_NM_ID any,
inout N_NM_ID any,
inout N_NM_REF any,
inout N_NM_READ any,
inout N_NM_OWN any,
inout N_NM_REC_DATE any,
inout N_NM_STAT any,
inout N_NM_TRY_POST any,
inout N_NM_DELETED any,
inout N_NM_HEAD any,
inout N_NM_BODY any)
{
return;
}
;
-----------------------------------------------------------------------------------------
--
create procedure DB.DBA.BOOKMARKS_NEWS_MSG_D (
inout O_NM_ID any)
{
signal ('CONV3', 'Delete of a Bookmarks comment is not allowed');
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.news_comment_get_mess_attachments (inout _data any, in get_uuparts integer)
{
declare data, outp, _all any;
declare line varchar;
declare in_UU, get_body integer;
data := string_output (http_strses_memory_size ());
http (_data, data);
http ('\n', data);
_all := vector ();
outp := string_output (http_strses_memory_size ());
in_UU := 0;
get_body := 1;
while (1 = 1)
{
line := ses_read_line (data, 0);
if (line is null or isstring (line) = 0)
{
if (length (_all) = 0)
{
_all := vector_concat (_all, vector (string_output_string (outp)));
}
return _all;
}
if (in_UU = 0 and subseq (line, 0, 6) = 'begin ' and length (line) > 6)
{
in_UU := 1;
if (get_body)
{
get_body := 0;
_all := vector_concat (_all, vector (string_output_string (outp)));
http_output_flush (outp);
}
_all := vector_concat (_all, vector (subseq (line, 10)));
}
else if (in_UU = 1 and subseq (line, 0, 3) = 'end')
{
in_UU := 0;
if (get_uuparts)
{
_all := vector_concat (_all, vector (string_output_string (outp)));
http_output_flush (outp);
}
}
else if ((get_uuparts and in_UU = 1) or get_body)
{
http (line, outp);
http ('\n', outp);
}
}
return _all;
}
;
-----------------------------------------------------------------------------------------
--
create procedure BMK.WA.news_comment_get_cn_type (in f_name varchar)
{
declare ext varchar;
declare temp any;
ext := 'text/html';
temp := split_and_decode (f_name, 0, '\0\0.');
if (length (temp) < 2)
return ext;
temp := temp[1];
if (exists (select 1 from WS.WS.SYS_DAV_RES_TYPES where T_EXT = temp))
ext := ((select T_TYPE from WS.WS.SYS_DAV_RES_TYPES where T_EXT = temp));
return ext;
}
;
¶ bookmark/sql/bmk-a-ods.sqlß å--
-- $Id: bmk-a-ods.sql,v 1.4 2009/01/08 19:40:07 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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_DOMAIN) do
wa_add_tag_to_count (BD_TAGS, id);
}
;
¶ bookmark/sql/bmk-a-table.sqlß gÄ--
-- $Id: bmk-a-table.sql,v 1.38 2011/12/01 21:06:29 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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
--
-------------------------------------------------------------------------------
--
-- Contains 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)
');
-------------------------------------------------------------------------------
--
-- Contains 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);
}
}
;
-------------------------------------------------------------------------------
--
-- Contains 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)
');
BMK.WA.exec_no_error (
'set_identity_column (\'BMK.WA.SFOLDER\', \'SF_ID\', %d)', 'I', 'BMK.WA.SFOLDER', 'SF_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)
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tags_update (
inout domain_id integer,
in oTags any,
in nTags any)
{
declare N integer;
oTags := split_and_decode (oTags, 0, '\0\0,');
nTags := split_and_decode (nTags, 0, '\0\0,');
foreach (any tag in oTags) do
{
if (not BMK.WA.vector_contains (nTags, lcase (tag)))
update BMK.WA.TAGS
set T_COUNT = T_COUNT - 1
where T_DOMAIN_ID = domain_id
and T_TAG = lcase (tag)
and T_COUNT > 0;
}
foreach (any tag in nTags) do
{
if (not BMK.WA.vector_contains (oTags, lcase (tag)))
if (exists (select 1 from BMK.WA.TAGS where T_DOMAIN_ID = domain_id and T_TAG = lcase (tag)))
{
update BMK.WA.TAGS
set T_COUNT = T_COUNT + 1
where T_DOMAIN_ID = domain_id
and T_TAG = lcase (tag);
} else {
insert replacing BMK.WA.TAGS (T_DOMAIN_ID, T_ACCOUNT_ID, T_TAG, T_COUNT)
values (domain_id, 0, lcase (tag), 1);
}
}
}
;
-------------------------------------------------------------------------------
--
-- Contains domain bookmarks
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.BOOKMARK_DOMAIN (
BD_ID integer identity,
BD_UID varchar,
BD_DOMAIN_ID integer not null,
BD_BOOKMARK_ID integer not null,
BD_FOLDER_ID integer,
BD_NAME varchar,
BD_DESCRIPTION varchar,
BD_TAGS varchar,
BD_ACL long varchar,
BD_CREATED datetime,
BD_UPDATED datetime,
BD_VISITED 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_UID varchar', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_UID'
);
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DOMAIN add BD_TAGS varchar', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_TAGS'
);
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DOMAIN add BD_UPDATED datetime', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_UPDATED'
);
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DOMAIN add BD_VISITED datetime', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_VISITED'
);
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 (
'alter table BMK.WA.BOOKMARK_DOMAIN add BD_ACL long varchar', 'C', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_ACL'
);
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 {
declare _uid varchar;
_uid := N.BD_UID;
if (isnull (_uid))
{
_uid := BMK.WA.uid ();
set triggers off;
update BMK.WA.BOOKMARK_DOMAIN set BD_UID = _uid where BD_ID = N.BD_ID;
set triggers on;
}
BMK.WA.tags_update (N.BD_DOMAIN_ID, \'\', N.BD_TAGS);
BMK.WA.exchange_entry_update (N.BD_DOMAIN_ID);
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 old as O, new as N {
declare _uid varchar;
_uid := N.BD_UID;
if (isnull (_uid))
{
_uid := BMK.WA.uid ();
set triggers off;
update BMK.WA.BOOKMARK_DOMAIN set BD_UID = _uid where BD_ID = N.BD_ID;
set triggers on;
}
BMK.WA.tags_update (N.BD_DOMAIN_ID, O.BD_TAGS, N.BD_TAGS);
BMK.WA.exchange_entry_update (N.BD_DOMAIN_ID);
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 {
BMK.WA.tags_update (O.BD_DOMAIN_ID, O.BD_TAGS, \'\');
if (__proc_exists (\'DB.DBA.WA_NEW_BOOKMARKS_RM\'))
DB.DBA.WA_NEW_BOOKMARKS_RM (O.BD_ID);
}
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.table_update ()
{
if (registry_get ('bmk_table_update') = '1')
return;
declare _account_id integer;
BMK.WA.exec_no_error ('update BMK.WA.BOOKMARK_DOMAIN set BD_UPDATED = BD_LAST_UPDATE');
delete from BMK.WA.TAGS;
for (select BD_ID as _id, BD_DOMAIN_ID as _domain_id, BD_BOOKMARK_ID as _bookmark_id from BMK.WA.BOOKMARK_DOMAIN) do
{
_account_id := BMK.WA.domain_owner_id (_domain_id);
update BMK.WA.BOOKMARK_DOMAIN set BD_TAGS = BMK.WA.tags_select (_domain_id, _account_id, _bookmark_id) where BD_ID = _id;
}
registry_set ('bmk_table_update', '1');
}
;
BMK.WA.table_update ();
BMK.WA.exec_no_error (
'alter table BMK.WA.BOOKMARK_DOMAIN drop BD_LAST_UPDATE', 'D', 'BMK.WA.BOOKMARK_DOMAIN', 'BD_LAST_UPDATE'
);
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error ('
create table BMK.WA.ANNOTATIONS (
A_ID integer identity,
A_DOMAIN_ID integer not null,
A_OBJECT_ID integer not null,
A_BODY long varchar,
A_CLAIMS long varchar,
A_CONTEXT varchar,
A_AUTHOR varchar,
A_CREATED datetime,
A_UPDATED datetime,
constraint FK_BMK_ANNOTATIONS_01 FOREIGN KEY (A_OBJECT_ID) references BMK.WA.BOOKMARK_DOMAIN (BD_ID) on delete cascade,
primary key (A_ID)
)
');
BMK.WA.exec_no_error (
'alter table BMK.WA.ANNOTATIONS add A_CLAIMS long varchar', 'C', 'BMK.WA.ANNOTATIONS', 'A_CLAIMS'
);
BMK.WA.exec_no_error ('
create index SK_BMK_ANNOTATIONS_01 on BMK.WA.ANNOTATIONS (A_OBJECT_ID, A_ID)
');
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error ('
create table BMK.WA.BOOKMARK_COMMENT (
BC_ID integer identity,
BC_PARENT_ID integer,
BC_DOMAIN_ID integer not null,
BC_BOOKMARK_ID varchar not null,
BC_TITLE varchar,
BC_COMMENT long varchar,
BC_U_NAME varchar,
BC_U_MAIL varchar,
BC_U_URL varchar,
BC_RFC_ID varchar,
BC_RFC_HEADER long varchar,
BC_RFC_REFERENCES varchar,
BC_OPENID_SIG long varbinary,
BC_CREATED datetime,
BC_UPDATED datetime,
constraint FK_BOOKMARK_COMMENT_01 FOREIGN KEY (BC_BOOKMARK_ID) references BMK.WA.BOOKMARK_DOMAIN (BD_ID) on delete cascade,
primary key (BC_ID)
)
');
BMK.WA.exec_no_error ('
create index SK_BOOKMARK_COMMENT_01 on BMK.WA.BOOKMARK_COMMENT (BC_BOOKMARK_ID)
');
BMK.WA.exec_no_error ('
create trigger BOOKMARK_COMMENT_I after insert on BMK.WA.BOOKMARK_COMMENT referencing new as N
{
declare id integer;
declare rfc_id, rfc_header, rfc_references varchar;
declare nInstance any;
nInstance := BMK.WA.domain_nntp_name (N.BC_DOMAIN_ID);
id := N.BC_ID;
rfc_id := N.BC_RFC_ID;
if (isnull(rfc_id))
rfc_id := BMK.WA.make_rfc_id (N.BC_BOOKMARK_ID, N.BC_ID);
rfc_references := \'\';
if (N.BC_PARENT_ID)
{
declare p_rfc_id, p_rfc_references any;
--declare exit handler for not found;
select BC_RFC_ID, BC_RFC_REFERENCES
into p_rfc_id, p_rfc_references
from BMK.WA.BOOKMARK_COMMENT
where BC_ID = N.BC_PARENT_ID;
if (isnull(p_rfc_references))
p_rfc_references := rfc_references;
rfc_references := p_rfc_references || \' \' || p_rfc_id;
}
rfc_header := N.BC_RFC_HEADER;
if (isnull(rfc_header))
rfc_header := BMK.WA.make_post_rfc_header (rfc_id, rfc_references, nInstance, N.BC_TITLE, N.BC_UPDATED, N.BC_U_MAIL);
set triggers off;
update BMK.WA.BOOKMARK_COMMENT
set BC_RFC_ID = rfc_id,
BC_RFC_HEADER = rfc_header,
BC_RFC_REFERENCES = rfc_references
where BC_ID = id;
set triggers on;
}
')
;
BMK.WA.exec_no_error ('
create trigger BOOKMARK_COMMENT_NEWS_I after insert on BMK.WA.BOOKMARK_COMMENT order 30 referencing new as N
{
declare grp, ngnext integer;
declare rfc_id, nInstance any;
declare exit handler for not found { return;};
nInstance := BMK.WA.domain_nntp_name (N.BC_DOMAIN_ID);
select NG_GROUP, NG_NEXT_NUM into grp, ngnext from DB..NEWS_GROUPS where NG_NAME = nInstance;
if (ngnext < 1)
ngnext := 1;
rfc_id := (select BC_RFC_ID from BMK.WA.BOOKMARK_COMMENT where BC_ID = N.BC_ID);
insert into DB.DBA.NEWS_MULTI_MSG (NM_KEY_ID, NM_GROUP, NM_NUM_GROUP)
values (rfc_id, grp, ngnext);
set triggers off;
update DB.DBA.NEWS_GROUPS
set NG_NEXT_NUM = ngnext + 1
where NG_NAME = nInstance;
DB.DBA.ns_up_num (grp);
set triggers on;
}
')
;
BMK.WA.exec_no_error ('
create trigger BOOKMARK_COMMENT_D after delete on BMK.WA.BOOKMARK_COMMENT referencing old as O
{
-- update all that have BC_PARENT_ID == O.BC_PARENT_ID
set triggers off;
update BMK.WA.BOOKMARK_COMMENT
set BC_PARENT_ID = O.BC_PARENT_ID
where BC_PARENT_ID = O.BC_ID;
set triggers on;
}
')
;
BMK.WA.exec_no_error ('
create trigger BOOKMARK_COMMENT_NEWS_D after delete on BMK.WA.BOOKMARK_COMMENT order 30 referencing old as O
{
declare grp integer;
declare oInstance any;
oInstance := BMK.WA.domain_nntp_name (O.BC_DOMAIN_ID);
grp := (select NG_GROUP from DB..NEWS_GROUPS where NG_NAME = oInstance);
delete from DB.DBA.NEWS_MULTI_MSG where NM_KEY_ID = O.BC_RFC_ID and NM_GROUP = grp;
DB.DBA.ns_up_num (grp);
}
')
;
-------------------------------------------------------------------------------
--
-- Contains settings
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error('
create table BMK.WA.SETTINGS (
S_DOMAIN_ID integer,
S_DATA varchar,
S_ACCOUNT_ID integer,
primary key (S_DOMAIN_ID)
)
');
BMK.WA.exec_no_error (
'alter table BMK.WA.SETTINGS add S_DOMAIN_ID integer', 'C', 'BMK.WA.SETTINGS', 'S_DOMAIN_ID'
)
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tmp_update ()
{
declare account_id, domain_id integer;
if (registry_get ('bmk_settings_update') = '1')
return;
BMK.WA.exec_no_error ('update BMK.WA.SETTINGS set S_DOMAIN_ID = -S_ACCOUNT_ID');
set triggers off;
for (select * from BMK.WA.SETTINGS) do
{
account_id := abs (S_DOMAIN_ID);
domain_id := (select top 1 C.WAI_ID
from SYS_USERS A,
WA_MEMBER B,
WA_INSTANCE C
where A.U_ID = account_id
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');
if (isnull (domain_id))
{
delete from BMK.WA.SETTINGS where S_DOMAIN_ID = -account_id;
} else {
update BMK.WA.SETTINGS set S_DOMAIN_ID = domain_id where S_DOMAIN_ID = -account_id;
}
}
set triggers on;
--BMK.WA.exec_no_error ('alter table BMK.WA.SETTINGS drop S_ACCOUNT_ID', 'D', 'BMK.WA.SETTINGS', 'S_ACCOUNT_ID');
BMK.WA.exec_no_error ('alter table BMK.WA.SETTINGS modify primary key (S_DOMAIN_ID)');
registry_set ('bmk_settings_update', '1');
}
;
BMK.WA.tmp_update ();
-------------------------------------------------------------------------------
--
-- Contains 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)
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.grants_procedure (
in gw_id integer)
{
declare c0 integer;
declare c1 varchar;
result_names (c0, c1);
for (select distinct b.U_ID, b.U_NAME
from BMK.WA.GRANTS a,
DB.DBA.SYS_USERS b
where a.G_GRANTEE_ID = gw_id
and a.G_GRANTER_ID = b.U_ID
order by 2) do
{
result (U_ID, U_NAME);
}
for (select distinct b.U_ID, b.U_NAME
from BMK.WA.GRANTS a,
DB.DBA.SYS_USERS b,
DB.DBA.SYS_ROLE_GRANTS c
where a.G_GRANTER_ID = b.U_ID
and c.GI_SUPER = gw_id
and c.GI_GRANT = a.G_GRANTEE_ID
and c.GI_DIRECT = '1'
order by 2) do
{
result (U_ID, U_NAME);
}
}
;
BMK.WA.exec_no_error ('
create procedure view BMK..GRANTS_VIEW as BMK.WA.grants_procedure (gw_id) (U_ID integer, U_NAME varchar)
')
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.grants_object_procedure (
in gow_type varchar := null,
in gow_to integer,
in gow_from integer := null)
{
declare c0 integer;
result_names (c0, c0);
for (select distinct G_ID, G_OBJECT_ID
from BMK.WA.GRANTS
where (G_OBJECT_TYPE = gow_type or gow_type is null)
and G_GRANTEE_ID = gow_to
and (G_GRANTER_ID = gow_from or gow_from is null) order by 1) do
{
result (G_ID, G_OBJECT_ID);
}
for (select distinct G_ID, G_OBJECT_ID
from BMK.WA.GRANTS a,
DB.DBA.SYS_ROLE_GRANTS c
where (a.G_OBJECT_TYPE = gow_type or gow_type is null)
and c.GI_SUPER = gow_to
and (a.G_GRANTER_ID = gow_from or gow_from is null)
and c.GI_GRANT = a.G_GRANTEE_ID
and c.GI_DIRECT = '1'
order by 1) do
{
result (G_ID, G_OBJECT_ID);
}
}
;
BMK.WA.exec_no_error ('
create procedure view BMK..GRANTS_OBJECT_VIEW as BMK.WA.grants_object_procedure (gow_type, gow_to, gow_from) (G_ID integer, G_OBJECT_ID integer)
')
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.drop_index ()
{
if (registry_get ('bmk_index_version') = '3')
return;
BMK.WA.exec_no_error ('drop table BMK.WA.BOOKMARK_DOMAIN_BD_DESCRIPTION_WORDS');
registry_set ('bmk_index_version', '3');
}
;
BMK.WA.drop_index ();
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, BD_UPDATED) using function language \'x-ViDoc\'
');
-------------------------------------------------------------------------------
--
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)
{
declare tags any;
for (select BD_DOMAIN_ID, BD_BOOKMARK_ID, BD_NAME, BD_DESCRIPTION, BD_TAGS 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, sprintf('^UID%d', coalesce (BMK.WA.domain_owner_id (BD_DOMAIN_ID), 0)), 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);
tags := split_and_decode (BD_TAGS, 0, '\0\0,');
foreach (any tag in tags) do
{
tag := concat('^T', trim(tag));
tag := replace (tag, ' ', '_');
tag := replace (tag, '+', '_');
vt_batch_feed (vtb, tag, 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 trigger WA_MEMBER_AU_BMK');
-------------------------------------------------------------------------------
--
-- PUBLISH & SUBSCRIBE
--
-------------------------------------------------------------------------------
BMK.WA.exec_no_error ('
create table BMK.WA.EXCHANGE (
EX_ID integer identity,
EX_DOMAIN_ID integer not null,
EX_TYPE integer not null,
EX_NAME varchar not null,
EX_UPDATE_TYPE integer not null,
EX_UPDATE_SUBTYPE integer,
EX_UPDATE_INTERVAL integer,
EX_UPDATE_PERIOD varchar,
EX_UPDATE_FREQ integer,
EX_OPTIONS varchar,
EX_EXEC_LOG long varchar,
EX_EXEC_TIME datetime,
primary key (EX_ID)
)
');
BMK.WA.exec_no_error(
'alter table BMK.WA.EXCHANGE add EX_UPDATE_SUBTYPE integer', 'C', 'BMK.WA.EXCHANGE', 'EX_UPDATE_SUBTYPE'
);
BMK.WA.exec_no_error ('
create trigger EXCHANGE_AI AFTER INSERT ON BMK.WA.EXCHANGE referencing new as N
{
BMK.WA.calc_update_interval (N.EX_ID, N.EX_UPDATE_TYPE, N.EX_UPDATE_PERIOD, N.EX_UPDATE_FREQ);
}
');
BMK.WA.exec_no_error ('
create trigger EXCHANGE_AU AFTER UPDATE on BMK.WA.EXCHANGE referencing old as O, new as N
{
BMK.WA.calc_update_interval (N.EX_ID, N.EX_UPDATE_TYPE, N.EX_UPDATE_PERIOD, N.EX_UPDATE_FREQ);
}
');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.calc_update_interval (
in _id any,
in _type any,
in _period any,
in _freq any)
{
declare _update integer;
if (_type < 2)
return;
_update := case lower (coalesce (_period, 'daily'))
when 'hourly' then 60
when 'daily' then 1440
else 1440
end / coalesce (_freq, 1);
set triggers off;
update BMK.WA.EXCHANGE
set EX_UPDATE_INTERVAL = _update
where EX_ID = _id;
set triggers on;
}
;
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error ('
insert replacing DB.DBA.SYS_SCHEDULED_EVENT (SE_NAME, SE_START, SE_SQL, SE_INTERVAL)
values(\'Bookmark Exchange Scheduler\', now(), \'BMK.WA.exchange_scheduler ()\', 30)
')
;
-------------------------------------------------------------------------------
--
BMK.WA.exec_no_error('
delete from DB.DBA.SYS_SCHEDULED_EVENT where SE_NAME = \'BM tags aggregator\'
')
;
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, 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')
return;
update BMK.WA.FOLDER set F_NAME = F_NAME where coalesce(F_PARENT_ID, -1) = -1;
registry_set ('bmk_path_update', '1');
}
;
BMK.WA.path_update()
;
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);
}
');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.BOOKMARK_DATA');
¶ bookmark/sql/bmk-a-update.sqlß h--
-- $Id: bmk-a-update.sql,v 1.5 2010/10/06 08:13:31 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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 procedure BMK.WA.tmp_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.tmp_update ()
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tmp_update ()
{
if (registry_get ('bmk_uid_update') = '1')
return;
set triggers off;
update BMK.WA.BOOKMARK_DOMAIN set BD_UID = BMK.WA.uid () where BD_UID is null;
set triggers on;
registry_set ('bmk_uid_update', '1');
}
;
BMK.WA.tmp_update ();
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tmp_update ()
{
if (registry_get ('bmk_acl_update') = '1')
return;
registry_set ('bmk_acl_update', '1');
set triggers off;
update BMK.WA.BOOKMARK_DOMAIN set BD_ACL = null where BD_ACL is not null;
set triggers on;
}
;
BMK.WA.tmp_update ();
¶ bookmark/sql/bmk-a-wa.sqlß D'--
-- $Id: bmk-a-wa.sql,v 1.29 2011/05/17 08:14:14 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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);
}
if (execType = 'I') {
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'
);
-- old SOAP
-- api user & url
BMK.WA.exec_no_error ('USER_DROP (\'SOAP_BOOKMARK\')');
VHOST_REMOVE (lpath => '/dataspace/services/bookmark');
-- procs
BMK.WA.exec_no_error ('DROP procedure DBA.DB.bookmark_import');
BMK.WA.exec_no_error ('DROP procedure DBA.DB.bookmark_export');
BMK.WA.exec_no_error ('DROP procedure DBA.DB.bookmark_update');
}
;
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 overriding method wa_dashboard () 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'
)
;
BMK.WA.exec_no_error (
'alter type wa_bookmark add overriding method wa_addition_urls () returns any'
)
;
BMK.WA.exec_no_error (
'alter type wa_bookmark add overriding method wa_update_instance (in oldValues any, in newValues any) returns any'
)
;
-------------------------------------------------------------------------------
--
-- 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
{
for (select HP_LPATH as _lpath,
HP_HOST as _vhost,
HP_LISTEN_HOST as _lhost
from DB.DBA.HTTP_PATH
where HP_LPATH = '/bookmark/' || self.BookmarkID) do
{
VHOST_REMOVE (vhost=>_vhost, lhost=>_lhost, lpath=>_lpath);
}
BMK.WA.domain_delete (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;
declare retValue any;
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);
retValue := (self as web_app).wa_new_inst (login);
return retValue;
}
;
-------------------------------------------------------------------------------
--
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 () for wa_bookmark
{
declare iWaiID integer;
iWaiID := self.BookmarkID;
return (select XMLAGG (
XMLELEMENT (
'dash-row',
XMLATTRIBUTES (
'normal' as "class",
BMK.WA.dt_format(_time, 'Y/M/D H:N') as "time",
self.wa_name as "application"
),
XMLELEMENT(
'dash-data',
XMLATTRIBUTES ( concat (N'', BMK.WA.utf2wide (_title), N'') as "content",
0 "comments"
)
)
)
)
from BMK.WA.dashboard_rs(p0)(_id integer, _title varchar, _time datetime) x
where p0 = iWaiID
);
}
;
-------------------------------------------------------------------------------
--
create method wa_dashboard_last_item () for wa_bookmark
{
return BMK.WA.dashboard_get (self.BookmarkID);
}
;
-------------------------------------------------------------------------------
--
create method wa_rdf_url (in vhost varchar, in lhost varchar) for wa_bookmark
{
declare domainID, userID integer;
domainID := self.BookmarkID;
userID := BMK.WA.domain_owner_id (domainID);
return concat(BMK.WA.dav_url2 (domainID, userID), 'BM.rdf');
}
;
-------------------------------------------------------------------------------
--
create method wa_addition_urls () for wa_bookmark
{
return vector (
vector (null, null, '/bookmark', self.get_param ('host')||'www/', self.get_param ('isDAV'), 0, 'bookmarks.vspx', null, 'wa', null, 'dba', null, null, 0, null, null, null, 0),
vector (null, null, '/dataspace/services/bookmark', '/SOAP/', 0, 0, null, null, null, null, null, 'SOAP_BOOKMARK', null, 1, vector('Use', 'literal', 'XML-RPC', 'no' ), null, null, 0)
);
}
;
-------------------------------------------------------------------------------
--
create method wa_update_instance (in oldValues any, in newValues any) for wa_bookmark
{
declare domainID, ownerID integer;
domainID := (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_NAME = newValues[0]);
ownerID := (select WAM_USER from WA_MEMBER B where WAM_INST = oldValues[0] and WAM_MEMBER_TYPE = 1);
BMK.WA.domain_gems_delete (domainID, ownerID, 'BM', oldValues[0] || '_Gems');
BMK.WA.domain_gems_create (domainID, ownerID);
BMK.WA.nntp_update (domainID, BMK.WA.domain_nntp_name2 (oldValues[0], BMK.WA.account_name (ownerID)), BMK.WA.domain_nntp_name2 (newValues[0], BMK.WA.account_name (ownerID)));
return (self as web_app).wa_update_instance (oldValues, newValues);
}
;
-------------------------------------------------------------------------------
--
create procedure BMK.WA.path_upgrade ()
{
declare _new_lpath varchar;
if (registry_get ('bmk_path_upgrade2') = '1')
return;
for (select WAI_ID from DB.DBA.WA_INSTANCE where WAI_TYPE_NAME = 'Bookmark') do
{
for (select HP_LPATH as _lpath,
HP_HOST as _vhost,
HP_LISTEN_HOST as _lhost
from DB.DBA.HTTP_PATH
where HP_LPATH = '/bookmark/' || cast (WAI_ID as varchar) || '/bookmarks.vspx') do
{
_new_lpath := '/bookmark/' || cast (WAI_ID as varchar);
if (exists (select 1 from DB.DBA.HTTP_PATH where HP_LPATH = _new_lpath and HP_HOST = _vhost and HP_LISTEN_HOST = _lhost))
{
VHOST_REMOVE (vhost=>_vhost, lhost=>_lhost, lpath=>_lpath);
} else {
update DB.DBA.HTTP_PATH
set HP_LPATH = _new_lpath
where HP_LPATH = _lpath
and HP_HOST = _vhost
and HP_LISTEN_HOST = _lhost;
http_map_del (_lpath, _vhost, _lhost);
VHOST_MAP_RELOAD (vhost=>_vhost, lhost=>_lhost, lpath=>_new_lpath);
}
}
}
registry_set ('bmk_path_upgrade2', '1');
}
;
BMK.WA.path_upgrade ();
¶ bookmark/sql/bmk-d.sqlß )9--
-- $Id: bmk-d.sql,v 1.27 2011/05/18 09:45:18 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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 installation.
-- Copyright (C) 2004 OpenLink Software
------------------------------------------------------------------------------
create procedure BMK.WA.uninstall ()
{
for select WAI_INST from DB.DBA.WA_INSTANCE WHERE WAI_TYPE_NAME = 'Bookmark' do
{
(WAI_INST as DB.DBA.wa_bookmark).wa_drop_instance();
commit work;
}
}
;
BMK.WA.uninstall ()
;
create procedure BMK.WA.uninstall ()
{
for select DB.DBA.DAV_SEARCH_PATH (COL_ID, 'C') path from WS.WS.SYS_DAV_COL where COL_DET = 'Bookmark' do
{
DB.DBA.DAV_DELETE_INT (path, 1, null, null, 0);
commit work;
}
}
;
BMK.WA.uninstall ()
;
-- Scheduler
BMK.WA.exec_no_error ('DELETE FROM DB.DBA.SYS_SCHEDULED_EVENT WHERE SE_NAME = \'Bookmark Exchange Scheduler\'');
VHOST_REMOVE (lpath => '/bookmark');
VHOST_REMOVE (lpath => '/dataspace/services/bookmark');
-- NNTP
BMK.WA.exec_no_error ('DROP procedure DB.DBA.BOOKMARKS_NEWS_MSG_I');
BMK.WA.exec_no_error ('DROP procedure DB.DBA.BOOKMARKS_NEWS_MSG_U');
BMK.WA.exec_no_error ('DROP procedure DB.DBA.BOOKMARKS_NEWS_MSG_D');
BMK.WA.exec_no_error ('DB.DBA.NNTP_NEWS_MSG_DEL (\'BOOKMARKS\')');
-- 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 TRIGGER 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.ANNOTATIONS');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.BOOKMARK_COMMENT');
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');
BMK.WA.exec_no_error('DROP TABLE BMK.WA.EXCHANGE');
-- 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');
BMK.WA.exec_no_error('drop view BMK..GRANTS_VIEW');
BMK.WA.exec_no_error('drop view BMK..GRANTS_OBJECT_VIEW');
-- Registry
registry_remove ('_bookmark_path_');
registry_remove ('_bookmark_version_');
registry_remove ('_bookmark_build_');
registry_remove ('__ods_bookmark_sioc_init');
registry_remove ('bmk_table_update');
registry_remove ('bmk_index_version');
registry_remove ('bmk_path_update');
registry_remove ('bmk_path_upgrade2');
registry_remove ('bmk_services_update');
-- 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_comment_iri');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_annotation_iri');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_links_to');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_tag_iri');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.fill_ods_bookmark_sioc2');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.clean_ods_bookmark_sioc2');
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_comments_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_comments_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_comment_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_comment_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_annotations_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bookmark_annotations_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_annotation_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_annotation_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_claims_insert');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.bmk_claims_delete');
BMK.WA.exec_no_error('DROP procedure SIOC.DBA.ods_bookmark_sioc_init');
-- RDF Views - procs & views
BMK.WA.exec_no_error ('DROP procedure SIOC.DBA.rdf_bookmark_view_str');
BMK.WA.exec_no_error ('DROP procedure SIOC.DBA.rdf_bookmark_view_str_tables');
BMK.WA.exec_no_error ('DROP procedure SIOC.DBA.rdf_bookmark_view_str_maps');
BMK.WA.exec_no_error ('DROP procedure DB.DBA.ODS_BMK_TAGS');
BMK.WA.exec_no_error ('DROP view DB.DBA.ODS_BMK_POSTS');
BMK.WA.exec_no_error ('DROP view DB.DBA.ODS_BMK_TAGS');
-- reinit
ODS_RDF_VIEW_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');
-- dropping SIOC procs
BMK.WA.exec_no_error('DROP procedure DBA.DB.bookmarks_import');
BMK.WA.exec_no_error('DROP procedure DBA.DB.bookmarks_export');
BMK.WA.exec_no_error('DROP procedure DBA.DB.bookmarks_update');
-- dropping API procs
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.get"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.new"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.edit"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.delete"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.folder.new"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.folder.delete"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.import"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.export"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.comment.get"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.comment.new"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.comment.delete"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.publication.new"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.publication.edit"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.publication.delete"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.subscription.new"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.subscription.edit"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.subscription.delete"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.options.set"');
BMK.WA.exec_no_error('DROP procedure ODS.ODS_API."bookmark.options.get"');
-- dropping DET procs
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_FIXNAME"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_COMPOSE_XBEL_NAME"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_COMPOSE_FOLDERS_PATH"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_ACCESS_PARAMS"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_AUTHENTICATE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_AUTHENTICATE_HTTP"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_GET_PARENT"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_COL_CREATE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_COL_MOUNT"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_COL_MOUNT_HERE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_DELETE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_RES_UPLOAD"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_PROP_REMOVE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_PROP_SET"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_PROP_GET"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_PROP_LIST"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_DIR_SINGLE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_DIR_LIST"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_FC_PRED_METAS"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_FC_TABLE_METAS"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_FC_PRINT_WHERE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_DIR_FILTER"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_SEARCH_ID_IMPL"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_SEARCH_ID"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_SEARCH_PATH"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_RES_UPLOAD_COPY"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_RES_UPLOAD_MOVE"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_RES_CONTENT"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_SYMLINK"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_DEREFERENCE_LIST"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_RESOLVE_PATH"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_LOCK"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_UNLOCK"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_IS_LOCKED"');
BMK.WA.exec_no_error('DROP procedure DB.DBA."bookmark_DAV_LIST_LOCKS"');
-- final proc
BMK.WA.exec_no_error('DROP procedure BMK.WA.exec_no_error');
¶ bookmark/sql/sioc_bmk.sqlß †E--
-- $Id: sioc_bmk.sql,v 1.57 2011/12/29 18:09:12 ddimitrov Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2009 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.WA.exec_no_error ('DROP procedure SIOC.DBA.fill_ods_bookmark_sioc');
use sioc;
-------------------------------------------------------------------------------
--
create procedure SIOC..bmk_post_iri (
in domain_id integer,
in bookmark_id integer)
{
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, bookmark_id);
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_comment_iri (
in domain_id varchar,
in bookmark_id integer,
in comment_id integer)
{
declare c_iri varchar;
c_iri := SIOC..bmk_post_iri (domain_id, bookmark_id);
if (isnull (c_iri))
return c_iri;
return sprintf ('%s/%d', c_iri, comment_id);
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_annotation_iri (
in domain_id varchar,
in bookmark_id integer,
in annotation_id integer)
{
declare c_iri varchar;
c_iri := SIOC..bmk_post_iri (domain_id, bookmark_id);
if (isnull (c_iri))
return c_iri;
return sprintf ('%s/annotation/%d', c_iri, annotation_id);
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_links_to (inout content any)
{
declare xt, retValue any;
if (content is null)
return null;
xt := case when (isentity (content)) then content else xtree_doc (content, 2, '', 'UTF-8') end;
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_sioc2 (
in _wai_name varchar := null,
in _access_mode integer := null)
{
declare id, deadl, cnt integer;
declare domain_id, bookmark_id integer;
declare graph_iri, forum_iri, creator_iri, bookmark_iri, iri varchar;
{
-- init services
SIOC..fill_ods_bookmark_services ();
for (select WAI_ID,
WAI_IS_PUBLIC,
WAI_TYPE_NAME,
WAI_NAME,
WAI_ACL
from DB.DBA.WA_INSTANCE
where ((_wai_name is null) or (WAI_NAME = _wai_name))
and WAI_TYPE_NAME = 'Bookmark') do
{
graph_iri := SIOC..acl_graph (WAI_TYPE_NAME, WAI_NAME);
exec (sprintf ('sparql clear graph <%s>', graph_iri));
SIOC..wa_instance_acl_insert (WAI_IS_PUBLIC, WAI_TYPE_NAME, WAI_NAME, WAI_ACL);
for (select BD_DOMAIN_ID, BD_ID, BD_ACL
from BMK..BOOKMARK_DOMAIN
where BD_DOMAIN_ID = WAI_ID and BD_ACL is not null) do
{
bookmark_acl_insert (BD_DOMAIN_ID, BD_ID, BD_ACL);
}
}
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 WAI_NAME,
WAM_USER,
WAI_IS_PUBLIC,
BD_DOMAIN_ID,
BD_ID,
BD_BOOKMARK_ID,
BD_NAME,
BD_DESCRIPTION,
BD_TAGS,
BD_UPDATED,
BD_CREATED,
BD_ACL
from DB.DBA.WA_INSTANCE,
BMK..BOOKMARK_DOMAIN,
DB.DBA.WA_MEMBER
where WAM_INST = WAI_NAME
and WAM_MEMBER_TYPE = 1
and ((WAM_IS_PUBLIC > 0 and _wai_name is null) or WAI_NAME = _wai_name)
and BD_ID > id
and BD_DOMAIN_ID = WAI_ID
order by BD_ID) do
{
bookmark_iri := SIOC..bmk_post_iri (BD_DOMAIN_ID, BD_ID);
graph_iri := SIOC..get_graph_new (coalesce (_access_mode, WAI_IS_PUBLIC), bookmark_iri);
forum_iri := SIOC..bmk_iri (coalesce (_wai_name, WAI_NAME));
creator_iri := SIOC..user_iri (WAM_USER);
bookmark_domain_insert (graph_iri,
forum_iri,
creator_iri,
BD_DOMAIN_ID,
BD_ID,
BD_BOOKMARK_ID,
BD_NAME,
BD_DESCRIPTION,
BD_TAGS,
BD_CREATED,
BD_UPDATED
);
cnt := cnt + 1;
if (mod (cnt, 500) = 0)
{
commit work;
id := BD_ID;
}
}
commit work;
}
}
;
-------------------------------------------------------------------------------
--
create procedure fill_ods_bookmark_services ()
{
declare graph_iri, services_iri, service_iri, service_url varchar;
declare svc_functions any;
graph_iri := get_graph ();
-- instance
svc_functions := vector ('bookmark.new', 'bookmark.import', 'bookmark.export', 'bookmark.publication.new', 'bookmark.subscription.new', 'bookmark.options.set', 'bookmark.options.get');
ods_object_services (graph_iri, 'bookmark', 'ODS Bookmark instance services', svc_functions);
-- item
svc_functions := vector ('bookmark.get', 'bookmark.edit', 'bookmark.delete', 'bookmark.comment.new', 'bookmark.annotation.new');
ods_object_services (graph_iri, 'bookmark/item', 'ODS Bookmark item services', svc_functions);
-- item comment
svc_functions := vector ('bookmark.comment.get', 'bookmark.comment.delete');
ods_object_services (graph_iri, 'bookmark/item/comment', 'ODS Bookmark comment services', svc_functions);
-- item annotation
svc_functions := vector ('bookmark.annotation.get', 'bookmark.annotation.claim', 'bookmark.annotation.delete');
ods_object_services (graph_iri, 'bookmark/item/annotation', 'ODS Bookmark annotation services', svc_functions);
}
;
-------------------------------------------------------------------------------
--
create procedure clean_ods_bookmark_sioc (
in _wai_name varchar := null,
in _access_mode integer := null)
{
declare id, deadl, cnt integer;
declare domain_id, bookmark_id integer;
declare graph_iri, forum_iri, creator_iri, bookmark_iri varchar;
{
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 WAI_NAME,
WAM_USER,
WAI_ID,
WAI_IS_PUBLIC,
BD_DOMAIN_ID,
BD_ID
from DB.DBA.WA_INSTANCE,
BMK.WA.BOOKMARK_DOMAIN,
DB.DBA.WA_MEMBER
where WAM_INST = WAI_NAME
and WAM_MEMBER_TYPE = 1
and ((WAM_IS_PUBLIC > 0 and _wai_name is null) or WAI_NAME = _wai_name)
and BD_ID > id
and BD_DOMAIN_ID = WAI_ID
order by BD_ID) do
{
bookmark_iri := SIOC..bmk_post_iri (BD_DOMAIN_ID, BD_ID);
graph_iri := SIOC..get_graph_new (coalesce (_access_mode, WAI_IS_PUBLIC), bookmark_iri);
SIOC..bookmark_domain_delete (graph_iri, BD_DOMAIN_ID, BD_ID);
cnt := cnt + 1;
if (mod (cnt, 500) = 0)
{
commit work;
id := BD_ID;
}
}
commit work;
}
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_domain_insert (
in graph_iri varchar,
in forum_iri varchar,
in creator_iri varchar,
inout domain_id integer,
inout bd_id integer,
inout bookmark_id integer,
inout name varchar,
inout description varchar,
inout tags varchar,
inout created datetime,
inout updated datetime)
{
declare uri, bookmark_iri, linksTo any;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
bookmark_iri := SIOC..bmk_post_iri (domain_id, bd_id);
if (isnull (graph_iri))
{
for (select WAM_USER,
WAI_ID,
WAI_IS_PUBLIC,
WAI_NAME,
coalesce(U_FULL_NAME, U_NAME) U_FULL_NAME,
U_E_MAIL
from DB.DBA.WA_INSTANCE,
DB.DBA.WA_MEMBER,
DB.DBA.SYS_USERS
where WAI_ID = domain_id
and WAI_IS_PUBLIC > 0
and WAM_INST = WAI_NAME
and U_ID = WAM_USER) do
{
graph_iri := SIOC..get_graph_new (WAI_IS_PUBLIC, bookmark_iri);
forum_iri := SIOC..bmk_iri (WAI_NAME);
creator_iri := SIOC..user_iri (WAM_USER);
-- maker
foaf_maker (graph_iri, SIOC..person_iri (creator_iri), U_FULL_NAME, U_E_MAIL);
}
}
if (isnull (graph_iri))
return;
uri := (select B_URI from BMK.WA.BOOKMARK where B_ID = bookmark_id);
linksTo := SIOC..bmk_links_to (description);
SIOC..ods_sioc_post (graph_iri, bookmark_iri, forum_iri, creator_iri, name, created, updated, uri, description, null, linksTo);
SIOC..scot_tags_insert (domain_id, bookmark_iri, tags);
-- bookmark services
SIOC..ods_object_services_dettach (graph_iri, bookmark_iri, 'bookmark/item');
SIOC..bookmark_comments_insert (graph_iri, forum_iri, domain_id, bookmark_id);
SIOC..bookmark_annotations_insert (graph_iri, domain_id, bookmark_id);
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_domain_delete (
in graph_iri varchar,
inout domain_id integer,
inout bookmark_id integer)
{
declare bookmark_iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
bookmark_iri := SIOC..bmk_post_iri (domain_id, bookmark_id);
if (isnull (graph_iri))
{
graph_iri := SIOC..get_graph_new (BMK.WA.domain_is_public (domain_id), bookmark_iri);
if (isnull (graph_iri))
return;
}
SIOC..delete_quad_s_or_o (graph_iri, bookmark_iri, bookmark_iri);
SIOC..ods_object_services_attach (graph_iri, bookmark_iri, 'bookmark/item');
SIOC..bookmark_comments_delete (graph_iri, domain_id, bookmark_id);
SIOC..bookmark_annotations_delete (graph_iri, domain_id, bookmark_id);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_I after insert on BMK.WA.BOOKMARK_DOMAIN referencing new as N
{
bookmark_domain_insert (null,
null,
null,
N.BD_DOMAIN_ID,
N.BD_ID,
N.BD_BOOKMARK_ID,
N.BD_NAME,
N.BD_DESCRIPTION,
N.BD_TAGS,
N.BD_CREATED,
N.BD_UPDATED);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_U after update on BMK.WA.BOOKMARK_DOMAIN referencing old as O, new as N
{
bookmark_domain_delete (null,
O.BD_DOMAIN_ID,
O.BD_ID);
bookmark_domain_insert (null,
null,
null,
N.BD_DOMAIN_ID,
N.BD_ID,
N.BD_BOOKMARK_ID,
N.BD_NAME,
N.BD_DESCRIPTION,
N.BD_TAGS,
N.BD_CREATED,
N.BD_UPDATED);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_D before delete on BMK.WA.BOOKMARK_DOMAIN referencing old as O
{
bookmark_domain_delete (null,
O.BD_DOMAIN_ID,
O.BD_ID);
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_acl_insert (
inout domain_id integer,
inout bookmark_id integer,
inout acl any)
{
declare graph_iri, iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
iri := SIOC..bmk_post_iri (domain_id, bookmark_id);
graph_iri := BMK.WA.acl_graph (domain_id);
SIOC..acl_insert (graph_iri, iri, acl);
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_acl_delete (
inout domain_id integer,
inout bookmark_id integer,
inout acl any)
{
declare graph_iri, iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
iri := SIOC..bmk_post_iri (domain_id, bookmark_id);
graph_iri := BMK.WA.acl_graph (domain_id);
SIOC..acl_delete (graph_iri, iri, acl);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_ACL_I after insert on BMK.WA.BOOKMARK_DOMAIN order 100 referencing new as N
{
if (coalesce (N.BD_ACL, '') <> '')
{
bookmark_acl_insert (N.BD_DOMAIN_ID,
N.BD_ID,
N.BD_ACL);
SIOC..acl_ping (N.BD_DOMAIN_ID,
SIOC..bmk_post_iri (N.BD_DOMAIN_ID, N.BD_ID),
null,
N.BD_ACL);
}
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_ACL_U after update (BD_ACL) on BMK.WA.BOOKMARK_DOMAIN order 100 referencing old as O, new as N
{
if (coalesce (O.BD_ACL, '') <> '')
bookmark_acl_delete (O.BD_DOMAIN_ID,
O.BD_ID,
O.BD_ACL);
if (coalesce (N.BD_ACL, '') <> '')
bookmark_acl_insert (N.BD_DOMAIN_ID,
N.BD_ID,
N.BD_ACL);
SIOC..acl_ping (N.BD_DOMAIN_ID,
SIOC..bmk_post_iri (N.BD_DOMAIN_ID, N.BD_ID),
O.BD_ACL,
N.BD_ACL);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_DOMAIN_SIOC_ACL_D before delete on BMK.WA.BOOKMARK_DOMAIN order 100 referencing old as O
{
if (coalesce (O.BD_ACL, '') <> '')
bookmark_acl_delete (O.BD_DOMAIN_ID,
O.BD_ID,
O.BD_ACL);
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_comments_insert (
in graph_iri varchar,
in forum_iri varchar,
inout domain_id integer,
inout master_id integer)
{
for (select BC_ID,
BC_DOMAIN_ID,
BC_BOOKMARK_ID,
BC_TITLE,
BC_COMMENT,
BC_UPDATED,
BC_U_NAME,
BC_U_MAIL,
BC_U_URL
from BMK.WA.BOOKMARK_COMMENT
where BC_BOOKMARK_ID = master_id) do
{
SIOC..bmk_comment_insert (graph_iri,
forum_iri,
BC_DOMAIN_ID,
BC_BOOKMARK_ID,
BC_ID,
BC_TITLE,
BC_COMMENT,
BC_UPDATED,
BC_U_NAME,
BC_U_MAIL,
BC_U_URL);
}
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_comments_delete (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer)
{
for (select BC_ID,
BC_DOMAIN_ID,
BC_BOOKMARK_ID
from BMK.WA.BOOKMARK_COMMENT
where BC_BOOKMARK_ID = master_id) do
{
SIOC..bmk_comment_delete (graph_iri,
BC_DOMAIN_ID,
BC_BOOKMARK_ID,
BC_ID);
}
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_comment_insert (
in graph_iri varchar,
in forum_iri varchar,
inout domain_id integer,
inout master_id integer,
inout comment_id integer,
inout title varchar,
inout comment varchar,
inout last_update datetime,
inout u_name varchar,
inout u_mail varchar,
inout u_url varchar)
{
declare master_iri, comment_iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
master_id := cast (master_id as integer);
master_iri := SIOC..bmk_post_iri (domain_id, master_id);
if (isnull (graph_iri))
{
graph_iri := get_graph_new (BMK.WA.domain_is_public (domain_id), master_iri);
if (isnull (graph_iri))
return;
}
if (isnull (forum_iri))
{
forum_iri := BMK.WA.forum_iri (domain_id);
if (isnull (forum_iri))
return;
}
comment_iri := bmk_comment_iri (domain_id, master_id, comment_id);
if (isnull (comment_iri))
return;
foaf_maker (graph_iri, u_url, u_name, u_mail);
SIOC..ods_sioc_post (graph_iri, comment_iri, forum_iri, null, title, last_update, last_update, null, comment, null, null, u_url);
SIOC..ods_object_services_attach (graph_iri, comment_iri, 'bookmark/item/comment');
DB.DBA.ODS_QUAD_URI (graph_iri, master_iri, sioc_iri ('has_reply'), comment_iri);
DB.DBA.ODS_QUAD_URI (graph_iri, comment_iri, sioc_iri ('reply_of'), master_iri);
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_comment_delete (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer,
inout comment_id integer)
{
declare master_iri, comment_iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
master_id := cast (master_id as integer);
master_iri := SIOC..bmk_post_iri (domain_id, master_id);
if (isnull (graph_iri))
{
graph_iri := SIOC..get_graph_new (BMK.WA.domain_is_public (domain_id), master_iri);
if (isnull (graph_iri))
return;
}
comment_iri := bmk_comment_iri (domain_id, master_id, comment_id);
delete_quad_s_or_o (graph_iri, comment_iri, comment_iri);
SIOC..ods_object_services_dettach (graph_iri, comment_iri, 'bookmark/item/comment');
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_COMMENT_SIOC_I after insert on BMK.WA.BOOKMARK_COMMENT referencing new as N
{
if (not isnull (N.BC_PARENT_ID))
bmk_comment_insert (null,
null,
N.BC_ID,
N.BC_DOMAIN_ID,
N.BC_BOOKMARK_ID,
N.BC_TITLE,
N.BC_COMMENT,
N.BC_UPDATED,
N.BC_U_NAME,
N.BC_U_MAIL,
N.BC_U_URL);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_COMMENT_SIOC_U after update on BMK.WA.BOOKMARK_COMMENT referencing old as O, new as N
{
if (not isnull (O.BC_PARENT_ID))
bmk_comment_delete (null,
O.BC_DOMAIN_ID,
O.BC_BOOKMARK_ID,
O.BC_ID);
if (not isnull (N.BC_PARENT_ID))
bmk_comment_insert (null,
null,
N.BC_DOMAIN_ID,
N.BC_BOOKMARK_ID,
N.BC_ID,
N.BC_TITLE,
N.BC_COMMENT,
N.BC_UPDATED,
N.BC_U_NAME,
N.BC_U_MAIL,
N.BC_U_URL);
}
;
-------------------------------------------------------------------------------
--
create trigger BOOKMARK_COMMENT_SIOC_D before delete on BMK.WA.BOOKMARK_COMMENT referencing old as O
{
if (not isnull(O.BC_PARENT_ID))
bmk_comment_delete (null,
O.BC_DOMAIN_ID,
O.BC_BOOKMARK_ID,
O.BC_ID);
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_annotations_insert (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer)
{
for (select A_ID,
A_DOMAIN_ID,
A_OBJECT_ID,
A_AUTHOR,
A_BODY,
A_CLAIMS,
A_CREATED,
A_UPDATED
from BMK.WA.ANNOTATIONS
where A_OBJECT_ID = master_id) do
{
bmk_annotation_insert (graph_iri,
A_DOMAIN_ID,
A_OBJECT_ID,
A_ID,
A_AUTHOR,
A_BODY,
A_CLAIMS,
A_CREATED,
A_UPDATED
);
}
}
;
-------------------------------------------------------------------------------
--
create procedure bookmark_annotations_delete (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer)
{
for (select A_ID,
A_DOMAIN_ID,
A_OBJECT_ID,
A_CLAIMS
from BMK.WA.ANNOTATIONS
where A_OBJECT_ID = master_id) do
{
bmk_annotation_delete (graph_iri,
A_DOMAIN_ID,
A_OBJECT_ID,
A_ID,
A_CLAIMS
);
}
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_annotation_insert (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer,
inout annotation_id integer,
inout author varchar,
inout body varchar,
inout claims any,
inout created datetime,
inout updated datetime)
{
declare master_iri, annotation_iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
master_id := cast (master_id as integer);
master_iri := SIOC..bmk_post_iri (domain_id, master_id);
if (isnull (graph_iri))
{
graph_iri := get_graph_new (BMK.WA.domain_is_public (domain_id), master_iri);
if (isnull (graph_iri))
return;
}
annotation_iri := bmk_annotation_iri (domain_id, master_id, annotation_id);
DB.DBA.ODS_QUAD_URI (graph_iri, annotation_iri, an_iri ('annotates'), master_iri);
DB.DBA.ODS_QUAD_URI (graph_iri, master_iri, an_iri ('hasAnnotation'), annotation_iri);
DB.DBA.ODS_QUAD_URI_L (graph_iri, annotation_iri, an_iri ('author'), author);
DB.DBA.ODS_QUAD_URI_L (graph_iri, annotation_iri, an_iri ('body'), body);
DB.DBA.ODS_QUAD_URI_L (graph_iri, annotation_iri, an_iri ('created'), created);
DB.DBA.ODS_QUAD_URI_L (graph_iri, annotation_iri, an_iri ('modified'), updated);
bmk_claims_insert (graph_iri, annotation_iri, claims);
SIOC..ods_object_services_attach (graph_iri, annotation_iri, 'bookmark/item/annotation');
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_annotation_delete (
in graph_iri varchar,
inout domain_id integer,
inout master_id integer,
inout annotation_id integer,
inout claims any)
{
declare master_iri, annotation_iri varchar;
declare exit handler for sqlstate '*'
{
sioc_log_message (__SQL_MESSAGE);
return;
};
master_id := cast (master_id as integer);
if (isnull (graph_iri))
{
master_iri := SIOC..bmk_post_iri (domain_id, master_id);
graph_iri := SIOC..get_graph_new (BMK.WA.domain_is_public (domain_id), master_iri);
if (isnull (graph_iri))
return;
}
annotation_iri := bmk_annotation_iri (domain_id, master_id, annotation_id);
SIOC..delete_quad_s_or_o (graph_iri, annotation_iri, annotation_iri);
SIOC..ods_object_services_dettach (graph_iri, annotation_iri, 'bookmark/item/annotation');
}
;
-------------------------------------------------------------------------------
--
create procedure bmk_claims_insert (
in graph_iri varchar,
in annotation_iri varchar,
in claims any)
{
declare N integer;
declare V, cURI, cPedicate, cValue any;
V := deserialize (claims);
for (N := 0; N < length (V); N := N +1)
{
cPedicate := V[N][1];
cValue := V[N][2];
if (0 = length (cPedicate))
{
cPedicate := rdfs_iri ('seeAlso');
} else {
cPedicate := ODS.ODS_API."ontology.denormalize" (cPedicate);
}
DB.DBA.ODS_QUAD_URI (graph_iri, annotation_iri, cPedicate, cValue);
}
}
;
-------------------------------------------------------------------------------
--
create trigger ANNOTATIONS_SIOC_I after insert on BMK.WA.ANNOTATIONS referencing new as N
{
bmk_annotation_insert (null,
N.A_DOMAIN_ID,
N.A_OBJECT_ID,
N.A_ID,
N.A_AUTHOR,
N.A_BODY,
N.A_CLAIMS,
N.A_CREATED,
N.A_UPDATED);
}
;
-------------------------------------------------------------------------------
--
create trigger ANNOTATIONS_SIOC_U after update on BMK.WA.ANNOTATIONS referencing old as O, new as N
{
bmk_annotation_delete (null,
O.A_DOMAIN_ID,
O.A_OBJECT_ID,
O.A_ID,
O.A_CLAIMS);
bmk_annotation_insert (null,
N.A_DOMAIN_ID,
N.A_OBJECT_ID,
N.A_ID,
N.A_AUTHOR,
N.A_BODY,
N.A_CLAIMS,
N.A_CREATED,
N.A_UPDATED);
}
;
-------------------------------------------------------------------------------
--
create trigger ANNOTATIONS_SIOC_D before delete on BMK.WA.ANNOTATIONS referencing old as O
{
bmk_annotation_delete (null,
O.A_DOMAIN_ID,
O.A_OBJECT_ID,
O.A_ID,
O.A_CLAIMS);
}
;
-------------------------------------------------------------------------------
--
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 ()');
-------------------------------------------------------------------------------
--
create procedure BMK.WA.tmp_update ()
{
if (registry_get ('bmk_services_update') = '1')
return;
SIOC..fill_ods_bookmark_services();
registry_set ('bmk_services_update', '1');
}
;
BMK.WA.tmp_update ();
-------------------------------------------------------------------------------
--
-- Bookmarks RDF Views
--
-------------------------------------------------------------------------------
use DB;
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_UPDATED) as BD_UPDATED,
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 V any;
declare inst, uname, bd_id, tag any;
result_names (inst, uname, bd_id, tag);
for (select WAM_INST,
U_NAME,
BD_ID,
BD_TAGS
from BMK.WA.BOOKMARK_DOMAIN,
WA_MEMBER,
WA_INSTANCE,
SYS_USERS
where WAM_INST = WAI_NAME
and WAM_MEMBER_TYPE = 1
and WAM_USER = U_ID
and BD_DOMAIN_ID = WAI_ID
and length (BD_TAGS) > 0) do {
V := split_and_decode (BD_TAGS, 0, '\0\0,');
foreach (any t in V) do
{
t := trim(t);
if (length (t))
result (WAM_INST, U_NAME, BD_ID, t);
}
}
}
;
wa_exec_no_error ('drop view ODS_BMK_TAGS');
create procedure view ODS_BMK_TAGS as DB.DBA.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 ;
dc:title BD_NAME;
dct:created BD_CREATED ;
dct:modified BD_UPDATED ;
dc:date BD_UPDATED ;
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_UPDATED ;
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)
.
'
;
};
create procedure sioc.DBA.rdf_bookmark_view_str_tables ()
{
return
'
from DB.DBA.ODS_BMK_POSTS as bmk_posts
where (^{bmk_posts.}^.U_NAME = ^{users.}^.U_NAME)
from DB.DBA.ODS_BMK_TAGS as bmk_tags
where (^{bmk_tags.}^.U_NAME = ^{users.}^.U_NAME)
'
;
};
create procedure sioc.DBA.rdf_bookmark_view_str_maps ()
{
return
'
# Bookmark
ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID)
a bm:Bookmark ;
dc:title bmk_posts.BD_NAME;
dct:created bmk_posts.BD_CREATED ;
dct:modified bmk_posts.BD_UPDATED ;
dc:date bmk_posts.BD_UPDATED ;
ann:created bmk_posts.BD_CREATED ;
dc:creator bmk_posts.U_NAME ;
bm:recalls ods:proxy (bmk_posts.B_URI) ;
sioc:link ods:proxy (bmk_posts.B_URI) ;
sioc:content bmk_posts.BD_DESCRIPTION ;
sioc:has_creator ods:user (bmk_posts.U_NAME) ;
foaf:maker ods:person (bmk_posts.U_NAME) ;
sioc:has_container ods:bmk_forum (bmk_posts.U_NAME, bmk_posts.WAI_NAME) .
ods:bmk_forum (bmk_posts.U_NAME, bmk_posts.WAI_NAME)
sioc:container_of ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID) .
ods:user (bmk_posts.U_NAME)
sioc:creator_of ods:bmk_post (bmk_posts.U_NAME, bmk_posts.WAI_NAME, bmk_posts.BD_BOOKMARK_ID) .
ods:bmk_post (bmk_tags.U_NAME, bmk_tags.WAM_INST, bmk_tags.ITEM_ID)
sioc:topic ods:tag (bmk_tags.U_NAME, bmk_tags.BD_TAG) .
ods:tag (bmk_tags.U_NAME, bmk_tags.BD_TAG) a skos:Concept ;
skos:prefLabel bmk_tags.BD_TAG ;
skos:isSubjectOf ods:bmk_post (bmk_tags.U_NAME, bmk_tags.WAM_INST, bmk_tags.ITEM_ID) .
# end Bookmark
'
;
};
grant select on ODS_BMK_POSTS to SPARQL_SELECT;
grant select on ODS_BMK_TAGS to SPARQL_SELECT;
grant execute on DB.DBA.ODS_BMK_TAGS to SPARQL_SELECT;
-- END BOOKMARK
ODS_RDF_VIEW_INIT ();
¶ bookmark/www/.cvsignoreß *.vspx-m *.vspx-m0 *.vspx-sql¶ bookmark/www/ajax.vspß C');
http(sprintf('%s', cast (progressIndex as varchar)));
http('');
}
}
else if (subAction = 'init')
{
registry_set ('bookmark_index_' || progressID, '0');
http_rewrite ();
http_header ('Content-Type: text/xml\r\n');
http ('');
http (sprintf ('%s', cast (progressID as varchar)));
http ('');
http_flush ();
declare folder_id, folder_name, tags, R, S, T any;
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);
-- 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, folder_id, tags, progressID);
}
_end:;
registry_remove ('bookmark_index_' || progressID);
registry_remove ('bookmark_action_' || progressID);
}
}
else if (action = 'tree')
{
nodePath := trim (get_keyword ('np', params, ''), '/');
if (subAction = 'load')
{
declare nodeID, nodeType any;
declare itemID, itemType, itemLabel, itemPath, itemImage, itemSelected, itemDraggable any;
vectorbld_init (returnData);
if ((nodePath = '') and (_domain_id < 0))
{
node := 'r#0';
}
else if ((nodePath = '') and (_domain_id > 0))
{
node := 'r#1';
}
else
{
parts := split_and_decode (nodePath, 0, '\0\0/');
node := case when length (parts) then parts[length (parts)-1] else '' end;
}
_account_id := cast (get_keyword ('account_id', sessionData, '-1') as integer);
nodes := BMK.WA.bmk_tree (_domain_id, _account_id, node, nodePath);
for (N := 0; N < length (nodes); N := N + 3)
{
nodeID := BMK.WA.node_id (nodes [N+1]);
nodeType := lcase (BMK.WA.node_type (nodes [N+1]));
itemID := nodes [N+1];
itemType := 1;
if (
((nodeType = 's') and (nodeID <> -1)) or
(nodeType = 'b')
)
{
itemType := 0;
}
itemLabel := nodes [N];
itemPath := replace ('/' || nodes [N+2], '//', '/');
itemImage := '';
if ((nodeType = 's') and (nodeID <> -1))
{
itemImage := '/subscriptions/image/sfolder_16.jpg';
}
itemSelected := 1;
itemDraggable := 0;
vectorbld_acc (returnData, vector (itemID, itemType, itemLabel, itemPath, itemImage, itemSelected, itemDraggable));
}
vectorbld_final (returnData);
}
http_rewrite ();
http_header ('Content-Type: text/plain\r\n');
http (ODS..obj2json (returnData, 5));
}
else if (action = 'tags')
{
declare tagsMin, tagsMax integer;
declare tag, tagStyle varchar;
nodePath := trim (get_keyword ('np', params, ''), '/');
tag := BMK.WA.node_suffix (nodePath);
http_rewrite ();
http_header ('Content-Type: text/html\r\n');
select max(T_COUNT), min(T_COUNT) into tagsMax, tagsMin from BMK.WA.TAGS where T_DOMAIN_ID = _domain_id and T_COUNT > 0;
for (select T_TAG, T_COUNT from BMK.WA.TAGS where T_DOMAIN_ID = _domain_id and T_COUNT > 0 order by T_TAG) do
{
tagStyle := ODS.WA.tag_style (T_COUNT, tagsMin, tagsMax) || 'padding-left: 3px;';
http (sprintf ('%s ', BMK.WA.tag_id (T_TAG), SIOC..tag_iri (BMK.WA.forum_iri (_domain_id), T_TAG), T_TAG, tagStyle, T_TAG));
}
}
else if (action = 'form')
{
declare exit handler for SQLSTATE '*'
{
if (__SQL_STATE = 'TEST')
{
returnData := BMK.WA.test_clear(__SQL_MESSAGE);
} else {
returnData := __SQL_STATE || ': Unexpected error!';
}
goto _formExit;
};
returnData := '';
if (subAction in ('Bookmark/Create', 'Bookmark/Edit'))
{
declare tmp, id, name, uri, description, folder_id, folder_name, tags, grants, acl, suffix any;
id := cast (get_keyword ('b_id', params, '-1') as integer);
name := trim (get_keyword ('b_name', params, ''));
description := trim (get_keyword ('b_description', params, ''));
uri := trim (get_keyword ('b_uri', params, ''));
folder_id := cast (get_keyword ('b_folder_id', params) as integer);
folder_name := trim (get_keyword ('b_folder_name', params, ''));
tags := trim (get_keyword ('b_tags', params, ''));
grants := '';
for (N := 0; N < length (params); N := N + 2)
{
if ((params [N] like 'f_fld_1_%') and (trim (params [N+1]) <> ''))
{
tmp := split_and_decode (trim (params[N+1]), 0, '\0\0,');
for (M := 0; M < length (tmp); M := M + 1)
{
if (not isnull (BMK.WA.account_id (trim (tmp[M]))))
grants := grants || ',' || tmp[M];
}
}
}
grants := trim (grants, ',');
BMK.WA.test (name, vector ('name', 'Bookmark Name', 'class', 'varchar', 'type', 'varchar', 'minLength', 1, 'maxLength', 255));
BMK.WA.test (uri, vector('name', 'Bookmark Link', 'class', 'uri', 'type', 'varchar', 'minLength', 1, 'maxLength', 255));
if ((folder_name <> '') and (not BMK.WA.folder_check_name (folder_name, 1)))
{
returnData := 'Please, enter other folder name. This name contains bad characters.';
goto _formExit;
}
BMK.WA.test (tags, vector('name', 'Tags', 'class', 'tags'));
tmp := BMK.WA.tags2vector (tags);
tmp := BMK.WA.vector_unique (tmp);
tags := BMK.WA.vector2tags (tmp);
acl := serialize (DB.DBA.wa_aci_params (params));
folder_id := BMK.WA.folder_create (_domain_id, folder_name, folder_id);
id := BMK.WA.bookmark_update (id, _domain_id, uri, name, description, tags, folder_id, null, acl);
BMK.WA.shareNode (_account_id, BMK.WA.make_node ('b', id), grants, 1);
}
else if (subAction in ('Folder/Create', 'Folder/Edit'))
{
declare tmp, id, name, parent_id, grants any;
id := cast (get_keyword ('f_id', params, -1) as integer);
parent_id := cast (get_keyword ('f_parent_id', params, 0) as integer);
name := trim (get_keyword ('f_name', params, ''));
grants := trim (get_keyword ('f_grants', params, ''));
if (parent_id = 0)
parent_id := null;
BMK.WA.test (name, vector ('name', 'Folder name', 'class', 'folder', 'type', 'varchar', 'minLength', 1, 'maxLength', 255));
if (BMK.WA.folder_check_unique (_domain_id, parent_id, name, id))
{
signal('TEST', 'Folder name already exists. Please, enter new name!<>');
}
if ((subAction <> 'Folder/Create') and BMK.WA.folder_check_parent(_domain_id, id, parent_id))
{
signal('TEST', 'Please, enter other parent folder. This folder is superior of the selected parent folder!<>');
}
if (subAction = 'Folder/Create')
{
id := BMK.WA.folder_create2(_domain_id, parent_id, name);
} else {
update BMK.WA.FOLDER
set F_PARENT_ID = parent_id,
F_NAME = name
where F_ID = id;
}
BMK.WA.shareNode (_account_id, BMK.WA.make_node ('f', id), grants, 1);
}
else if (subAction in ('Smart Folder/Create', 'Smart Folder/Edit'))
{
declare tmp, id, name, keywords, expression, tags, own, folder_id, shared, grants any;
id := cast (get_keyword ('s_id', params, '-1') as integer);
name := trim (get_keyword ('s_name', params, ''));
keywords := trim (get_keyword ('s_keywords', params, ''));
expression := trim (get_keyword ('s_expression', params, ''));
tags := trim (get_keyword ('s_tags', params, ''));
own := cast (get_keyword ('s_own', params, '0') as integer);
folder_id := cast (get_keyword ('s_folder', params, '0') as integer);;
shared := cast (get_keyword ('s_shared', params, '0') as integer);
grants := trim (get_keyword ('s_grants', params, ''));
BMK.WA.test(name, vector('name', 'Smart folder name', 'class', 'folder', 'type', 'varchar', 'minLength', 1, 'maxLength', 255));
tmp := coalesce((select SF_ID from BMK.WA.SFOLDER where SF_DOMAIN_ID = _domain_id and SF_NAME = name), -1);
if (((subAction = 'Smart Folder/Create') and (tmp <> -1)) or ((subAction = 'Smart Folder/Update') and (tmp <> id) and (tmp <> -1)))
signal('TEST', 'Smart folder name already exists. Please, enter new ''Smart folder name''!<>');
BMK.WA.test (keywords, vector('name', 'Keywords', 'class', 'free-text'));
BMK.WA.test (expression, vector('name', 'Expression', 'class', 'free-text-expression'));
BMK.WA.test (tags, vector('name', ' Tags', 'class', 'tags'));
tmp := BMK.WA.ft2vector (keywords);
tmp := BMK.WA.vector_unique (tmp, 2);
keywords := BMK.WA.vector2str (tmp);
tmp := BMK.WA.tags2vector (tags);
tmp := BMK.WA.vector_unique (tmp, 2);
tags := BMK.WA.vector2tags (tmp);
declare data varchar;
BMK.WA.xml_set ('keywords', data, keywords);
BMK.WA.xml_set ('expression', data, expression);
BMK.WA.xml_set ('tags', data, tags);
if (own = 1)
{
BMK.WA.xml_set('myBookmarks', data, 1);
if (folder_id > 0)
BMK.WA.xml_set('folder', data, folder_id);
}
if (shared = 1)
{
BMK.WA.xml_set('mySharedBookmarks', data, 1);
if (grants <> '')
BMK.WA.xml_set('grants', data, grants);
}
data := BMK.WA.xml2string (data);
if (subAction = 'Smart Folder/Create')
{
BMK.WA.sfolder_create (_domain_id, name, data);
} else {
BMK.WA.sfolder_update (_domain_id, id, name, data);
}
}
else if (subAction = 'tags')
{
declare node_id, node_type any;
declare tags, oTags, nTags any;
tags := get_keyword ('t_tag', params, '');
if (not BMK.WA.validate_tags (tags))
{
returnData := 'The expression contans not valid tag(s).';
goto _formExit;
}
for (N := 0; N < length (params); N := N + 2)
{
if (params[N] = 'cb_item')
{
node_id := BMK.WA.node_id (params[N+1]);
node_type := BMK.WA.node_type (params[N+1]);
if (node_type = 'b')
{
oTags := BMK.WA.tags_select (_domain_id, node_id);
nTags := BMK.WA.tags_join (oTags, tags);
BMK.WA.bookmark_tags (_domain_id, node_id, nTags);
}
}
}
}
else if (subAction = 'move')
{
declare node_id, node_type any;
declare mFolderID, mFolderName any;
mFolderID := get_keyword ('m_folder_id', params, '');
mFolderName := trim (get_keyword ('m_folder_name', params, ''));
if ((mFolderName <> '') and (not BMK.WA.folder_check_name (mFolderName, 1)))
{
returnData := 'Please, enter other folder name. This name contains bad characters.';
goto _formExit;
}
mFolderID := BMK.WA.folder_create (_domain_id, mFolderName, mFolderID);
for (N := 0; N < length (params); N := N + 2)
{
if (params[N] = 'cb_item')
{
node_id := BMK.WA.node_id (params[N+1]);
node_type := BMK.WA.node_type (params[N+1]);
if (node_type = 'f')
{
BMK.WA.folder_parent (node_id, mFolderID);
}
else if (node_type = 'b')
{
BMK.WA.bookmark_parent (node_id, mFolderID);
}
}
}
}
else if (subAction = 'share')
{
declare sShare, sOverride any;
sShare := trim (get_keyword ('s_share', params, ''));
sOverride := get_keyword ('s_override', params, '');
for (N := 0; N < length (params); N := N + 2)
{
if (params[N] = 'cb_item')
{
BMK.WA.shareNode (_account_id, params[N+1], sShare, sOverride);
}
}
}
else if (subAction = 'delete')
{
declare node_id, node_type any;
for (N := 0; N < length (params); N := N + 2)
{
if (params[N] = 'cb_item')
{
node_id := BMK.WA.node_id (params[N+1]);
node_type := BMK.WA.node_type (params[N+1]);
if (node_type = 'f')
{
BMK.WA.folder_delete (_domain_id, node_id);
}
else if (node_type = 'b')
{
BMK.WA.bookmark_delete (_domain_id, node_id);
}
else if (node_type = 's')
{
BMK.WA.sfolder_delete (_domain_id, node_id);
}
}
}
}
_formExit:;
http_rewrite ();
http_header ('Content-Type: text/plain\r\n');
http (ODS..obj2json(returnData, 5));
}
else if (action = 'about')
{
http ( '
');
for (select T_TAG from BMK.WA.TAGS where T_DOMAIN_ID = self.domain_id and T_COUNT > 0 and T_TAG <> '' order by T_TAG) do
{
http (sprintf ('%s ', T_TAG, fieldName, T_TAG));
}
http ('
');
http ('
');
}
]]>
%s', SIOC..tag_iri (BMK.WA.forum_iri (self.domain_id), tags[N]), tags[N]));
delimiter := ', ';
}
}
}
]]>
%s', BMK.WA.page_url (self.domain_id, p_url, self.sid, self.realm), p_name, p_name, p_title, p_name);
]]>
Forms
', self.bNode));
?>
'')
{
flag := case when flag = 'visited' then now () else null end;
for (i := 0; i < length(params); i := i + 2)
{
if (params[i] = 'cb_item')
{
declare exit handler for sqlstate '*'
{
rollback work;
goto _next;
};
commit work;
if (lcase (BMK.WA.node_type (params[i+1])) = 'f')
BMK.WA.folder_visited_set (self.domain_id, BMK.WA.node_id (params[i+1]), flag);
if (lcase (BMK.WA.node_type (params[i+1])) = 'b')
BMK.WA.bookmark_visited_set (self.domain_id, BMK.WA.node_id (params[i+1]), flag);
}
_next:;
}
}
mt := '';
st := '';
if ((self.person_rights = 'W') and (not (((node_type = 's') and (node_id = -1)) or (node_type = 'u') or (node_type = 'F'))))
{
mt := sprintf('Selected as ');
st := sprintf('View ');
sv := get_keyword('show', params, '');
st := replace(st, sprintf('value="%s"', sv), sprintf('value="%s" selected="selected"', sv));
}
imageName := '/ods/images/oat/Tree_node-collapsed.png';
nodeName := null;
if (lcase (node_type) = 'f')
{
if (node_id >= 0)
{
nodeName := BMK.WA.folder_name (node_id);
} else {
nodeName := 'Bookmarks';
}
}
else if (node_type = 's')
{
if (node_id >= 0)
{
imageName := 'image/sfolder_16.jpg';
nodeName := BMK.WA.sfolder_name (node_id);
} else {
nodeName := 'Smart Folders';
}
}
else if (node_type = 't')
{
if (BMK.WA.node_suffix (self.bNode) <> '')
{
imageName := 'image/tag_16.png';
nodeName := 'Tag: ' || BMK.WA.node_suffix (self.bNode);
} else {
nodeName := 'Tags';
}
}
else if (node_type = 'u')
{
if (node_id >= 0)
{
imageName := 'image/user_16.png';
nodeName := BMK.WA.account_fullName (node_id);
} else {
imageName := 'image/group_16.png';
nodeName := 'Shared Bookmarks By';
}
}
nodeName := BMK.WA.stringCut (coalesce (nodeName, ''), self.chars);
if (not is_empty_or_null(nodeName))
{
http('
');
http(sprintf('
%s
', imageName, nodeName));
http(sprintf('
%s %s
', mt, st));
http(' ');
http('
');
}
?>
= 0)
{
sql := 'select *
from (select 0 _TYPE,
F_ID _ID,
BMK.WA.make_node(\'f\', F_ID) _NODE,
F_NAME _NAME,
\'\' _URI,
null _VISITED,
null _UPDATED,
null _CREATED,
null _FOLDER_ID,
null _FOLDER_NAME,
null _GRANT_ID
from BMK.WA.FOLDER
where F_DOMAIN_ID =
and coalesce (F_PARENT_ID, -1) =
union
) x
where 1 = 1';
BMK.WA.xml_set('folderID', data, BMK.WA.node_suffix(self.bNode));
tmp := BMK.WA.sfolder_sql (self.domain_id, self.account_id, self.person_rights, data);
sql := replace(sql, '', tmp);
sql := replace(sql, '', BMK.WA.node_suffix(self.bNode));
}
else
{
sql := 'select *
from (select TOP 100
1 _TYPE,
BD_ID _ID,
BMK.WA.make_node(\'b\', BD_ID) _NODE,
BD_NAME _NAME,
B_URI _URI,
BD_VISITED _VISITED,
BD_UPDATED _UPDATED,
BD_CREATED _CREATED
from BMK.WA.BOOKMARK_DOMAIN,
BMK.WA.BOOKMARK,
DB.DBA.WA_INSTANCE
where BD_BOOKMARK_ID = B_ID
and WAI_ID = BD_DOMAIN_ID
and WAI_IS_PUBLIC = 1
order by BD_UPDATED desc
) x
where 1 = 1';
}
}
else if ((node_type = 's') and (node_id = -1))
{
sql := 'select *
from (select 1 _TYPE,
SF_ID _ID,
BMK.WA.make_node(\'s\', SF_ID) _NODE,
SF_NAME _NAME,
\'\' _URI,
null _VISITED,
null _UPDATED,
null _CREATED
from BMK.WA.SFOLDER
where SF_DOMAIN_ID = ) x
where 1 = 1';
sql := replace(sql, '', cast (self.domain_id as varchar));
}
else if ((node_type = 's') and (node_id >= 0))
{
data := (select SF_DATA from BMK.WA.SFOLDER where SF_DOMAIN_ID = self.domain_id and SF_ID = node_id);
sql := 'select distinct rs.* from BMK.WA.shared_sql (rs0, rs1, rs2, rs3)(_TYPE integer, _ID integer, _NODE varchar, _NAME varchar, _URI varchar, _VISITED datetime, _UPDATED datetime, _CREATED datetime, _FOLDER_ID integer, _FOLDER_NAME varchar, _GRANT_ID integer) rs where rs0 = ? and rs1 = ? and rs2 = ? and rs3 = ?';
control.add_parameter (self.domain_id);
control.add_parameter (self.account_id);
control.add_parameter (self.person_rights);
control.add_parameter (data);
}
else if ((node_type = 't') and not is_empty_or_null (BMK.WA.node_suffix (self.bNode)))
{
BMK.WA.xml_set('tags', data, BMK.WA.node_suffix(self.bNode));
sql := BMK.WA.sfolder_sql (self.domain_id, self.account_id, self.person_rights, data);
}
else if ((node_type = 'u') and (node_id = -1))
{
sql := 'select *
from (select distinct
1 _TYPE,
U_ID _ID,
BMK.WA.make_node(\'u\', U_ID) _NODE,
U_NAME _NAME,
\'\' _URI,
null _VISITED,
null _UPDATED,
null _CREATED
from BMK..GRANTS_VIEW
where GW_ID =
) x
where 1 = 1';
sql := replace(sql, '', cast (self.account_id as varchar));
}
else if ((node_type = 'u') and (node_id >= 0))
{
sql := 'select *
from (select 0 _TYPE,
F_ID _ID,
BMK.WA.make_node(\'F\', F_ID) _NODE,
F_NAME _NAME,
\'\' _URI,
null _VISITED,
null _UPDATED,
null _CREATED
from BMK.WA.FOLDER,
BMK..GRANTS_OBJECT_VIEW
where GOW_TYPE = \'F\'
and G_OBJECT_ID = F_ID
and GOW_FROM =
and GOW_TO =
union
select 1 _TYPE,
a.BD_ID _ID,
BMK.WA.make_node(\'B\', a.BD_ID) _NODE,
a.BD_NAME _NAME,
b.B_URI _URI,
a.BD_VISITED _VISITED,
a.BD_UPDATED _UPDATED,
a.BD_CREATED _CREATED
from BMK..GRANTS_OBJECT_VIEW d,
BMK.WA.BOOKMARK_DOMAIN a
join BMK.WA.BOOKMARK b on b.B_ID = a.BD_BOOKMARK_ID
where d.GOW_TYPE = \'B\'
and d.G_OBJECT_ID = a.BD_ID
and GOW_FROM =
and GOW_TO =
) x
where 1 = 1';
sql := replace(sql, '', BMK.WA.node_suffix(self.bNode));
}
else if (node_type = 'F')
{
sql := 'select *
from (select 0 _TYPE,
F_ID _ID,
BMK.WA.make_node(\'F\', F_ID) _NODE,
F_NAME _NAME,
\'\' _URI,
null _VISITED,
null _UPDATED,
null _CREATED
from BMK.WA.FOLDER
where coalesce(F_PARENT_ID, -1) =
union
select 1 _TYPE,
a.BD_ID _ID,
BMK.WA.make_node(\'B\', a.BD_ID) _NODE,
a.BD_NAME _NAME,
b.B_URI _URI,
a.BD_VISITED _VISITED,
a.BD_UPDATED _UPDATED,
a.BD_CREATED _CREATED
from BMK.WA.BOOKMARK_DOMAIN a
join BMK.WA.BOOKMARK b on b.B_ID = a.BD_BOOKMARK_ID
where coalesce(a.BD_FOLDER_ID, -1) =
) x
where 1 = 1';
sql := replace(sql, '', BMK.WA.node_suffix(self.bNode));
}
else
{
control.ds_sql := 'select 0 _TYPE, F_ID _ID, \'\' _NODE, F_NAME _NAME, null _URI, null _VISITED, null _UPDATED, null _CREATED from BMK.WA.FOLDER where 1=0';
goto _end;
}
sql := replace(sql, '', cast (self.domain_id as varchar));
sql := replace(sql, '', cast (self.account_id as varchar));
flag := get_keyword('show', params, '');
if (flag = 'visited')
sql := concat (sql, ' and (_VISITED is not null)');
else if (flag = 'unvisited')
sql := concat (sql, ' and (_VISITED is null)');
self.sortChange (get_keyword ('sortColumn', params, ''));
control.ds_sql := concat (sql, ' order by _TYPE, ', self.n_order, ' ', self.n_direction, ', _ID');
_end:;
]]>
', '');
S := replace(S, 'FOLDED', '');
S := replace(S, ' ', ' ');
S := replace(S, '&', '&');
V := BMK.WA.string2xml (S, 2);
if (isnull (V))
goto _xbel;
V2 := xpath_eval ('//dl', V);
if (isnull (V2))
goto _xbel;
progressMax := xpath_eval('count (//a)', V2);
goto _end;
_xbel:;
-- check XBEL format
--
V := BMK.WA.string2xml (S);
if (isnull (V))
goto _end;
V2 := xpath_eval('/xbel', V);
if (isnull (V2))
goto _rss;
progressMax := xpath_eval('count (//bookmark)', V2);
goto _end;
_rss:;
-- check RSS format
--
V2 := xpath_eval ('/rss/channel/item|/rss/item|/RDF/item|/Channel/items/item', V);
if (isnull (V2))
goto _atom;
progressMax := xpath_eval('count (/rss/channel/item|/rss/item|/RDF/item|/Channel/items/item)', V2);
goto _end;
_atom:;
-- check Atom format
--
V2 := xpath_eval ('/feed/entry', V);
if (isnull (V2))
goto _delicious;
progressMax := xpath_eval('count (/feed/entry)', V2);
goto _end;
_delicious:;
-- check delicious format
--
V2 := xpath_eval('/posts', V);
if (isnull (V2))
goto _end;
progressMax := xpath_eval('count (//post)', V2);
_end:;
http (cast (progressMax as varchar));
?>
Export
', self.v_id));
?>
', self.v_id));
?>
= 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:;
}
]]>
', self.v_id));
?>
', case when (self.v_own = 1) then 'checked="checked"' else '' end));
?>
', case when (self.v_shared = 1) then 'checked="checked"' else '' end));
?>