1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
|
--
-- $Id: blog_bridge.sql,v 1.2 2006/08/16 07:58:12 source Exp $
--
-- This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
-- project.
--
-- Copyright (C) 1998-2006 OpenLink Software
--
-- This project is free software; you can redistribute it and/or modify it
-- under the terms of the GNU General Public License as published by the
-- Free Software Foundation; only version 2 of the License, dated June 1991.
--
-- This program is distributed in the hope that it will be useful, but
-- WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-- General Public License for more details.
--
-- You should have received a copy of the GNU General Public License along
-- with this program; if not, write to the Free Software Foundation, Inc.,
-- 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--
--
create procedure make_wwwroot ()
{
if (not exists (select 1 from HTTP_PATH where HP_LPATH = '/RPC2' and HP_HOST = '*ini*'))
{
declare bapi, i, l any;
declare grant_stmt, gst, gmsg varchar;
VHOST_DEFINE (lpath=>'/RPC2', ppath=>'/SOAP/', soap_user=>'MT', soap_opts=>vector ('XML-RPC', 'yes'));
bapi := BLOG.."mt.supportedMethods" ();
i := 0; l := length (bapi);
while (i < l)
{
grant_stmt := 'grant execute on BLOG.DBA."'||bapi[i]||'" to "MT"';
gst := '00000';
exec (grant_stmt, gst, gmsg);
i := i + 1;
}
}
}
;
make_wwwroot ()
;
drop table blog_types
;
drop table blog_bridge_messages
;
drop table blog_bridge
;
create table blog_bridge (
bb_blog_id varchar,
bb_endpoint varchar,
bb_type varchar,
bb_user varchar,
bb_pwd varchar,
bb_self_id varchar,
primary key (bb_endpoint, bb_blog_id, bb_self_id)
)
;
create table blog_bridge_messages
(
bm_blog_id varchar,
bm_endpoint varchar,
bm_self_id varchar,
bm_post_id varchar,
bm_self_post_id varchar,
bm_error long varchar,
foreign key (bm_endpoint, bm_blog_id, bm_self_id) references
blog_bridge (bb_endpoint, bb_blog_id, bb_self_id) on update cascade on delete cascade,
primary key (bm_blog_id, bm_endpoint, bm_post_id)
)
;
create procedure message_or_meta_data (inout meta any,
inout uid int, inout content any, inout postid varchar,
inout tms datetime)
{
if (meta is not null)
return meta;
declare res BLOG.."MTWeblogPost";
res := new BLOG.."MTWeblogPost" ();
res.userid := (select U_NAME from SYS_USERS where U_ID = uid);
res.description := blob_to_string (content);
res.author := (select U_E_MAIL from SYS_USERS where U_ID = uid);
res.dateCreated := tms;
res.mt_allow_pings := 0;
res.mt_allow_comments := 0;
res.postid := postid;
return res;
}
;
create trigger SYS_BLOGS_I1 after insert on BLOG..SYS_BLOGS order 90
{
declare postid, fpostid varchar;
postid := B_POST_ID;
if (B_APPKEY = 'appKey_bridge')
return;
commit work;
for select bb_endpoint, bb_blog_id, bb_type, bb_user, bb_pwd from blog_bridge where bb_self_id = B_BLOG_ID do
{
declare req BLOG.."blogRequest";
req := new BLOG.."blogRequest" ('appKey_bridge', bb_blog_id, '', bb_user, bb_pwd);
declare exit handler for sqlstate '*' {
insert into blog_bridge_messages values
(bb_blog_id, bb_endpoint, B_BLOG_ID, postid, postid, __SQL_MESSAGE);
goto next;
};
if (bb_type = 'Blogger')
{
fpostid := BLOG.blogger.new_Post (bb_endpoint, req, B_CONTENT);
}
else if (bb_type = 'MetaWeblog' or bb_type = 'Moveable Type')
{
req.struct := message_or_meta_data (B_META, B_USER_ID, B_CONTENT, postid, B_TS);
fpostid := BLOG.metaweblog.new_Post (bb_endpoint, req);
}
insert into blog_bridge_messages values (bb_blog_id, bb_endpoint, B_BLOG_ID, fpostid, postid, null);
next: ;
}
}
;
create trigger SYS_BLOGS_U1 after update on BLOG..SYS_BLOGS order 90 referencing old as O , new as N
{
declare postid, fpostid varchar;
postid := O.B_POST_ID;
if (O.B_APPKEY = 'appKey_bridge')
return;
commit work;
for select bb_endpoint, bb_blog_id, bb_type, bb_user, bb_pwd from blog_bridge where bb_self_id = O.B_BLOG_ID do
{
declare req BLOG.."blogRequest";
for select bm_post_id from blog_bridge_messages where
bm_self_post_id = postid and
bm_endpoint = bb_endpoint and
bm_self_id = O.B_BLOG_ID and
bm_blog_id = bb_blog_id and
bm_error is null
do
{
req := new BLOG.."blogRequest" ('appKey_bridge', bb_blog_id, bm_post_id, bb_user, bb_pwd);
declare exit handler for sqlstate '*'
{
update blog_bridge_messages set bm_error = __SQL_MESSAGE where
bm_self_post_id = postid and
bm_endpoint = bb_endpoint and
bm_self_id = O.B_BLOG_ID and
bm_blog_id = bb_blog_id ;
goto next;
};
if (bb_type = 'Blogger')
{
BLOG.blogger.edit_Post (bb_endpoint, req, N.B_CONTENT);
}
else if (bb_type = 'MetaWeblog' or bb_type = 'Moveable Type')
{
req.struct := message_or_meta_data (N.B_META, N.B_USER_ID, N.B_CONTENT, postid, N.B_TS);
BLOG.metaweblog.edit_Post (bb_endpoint, req);
}
}
next: ;
}
}
;
create trigger SYS_BLOGS_D1 after delete on BLOG..SYS_BLOGS order 90 referencing old as O
{
declare postid, fpostid varchar;
postid := O.B_POST_ID;
if (O.B_APPKEY = 'appKey_bridge')
return;
commit work;
for select bb_endpoint, bb_blog_id, bb_type, bb_user, bb_pwd from blog_bridge where bb_self_id = O.B_BLOG_ID do
{
declare req BLOG.."blogRequest";
for select bm_post_id from blog_bridge_messages where
bm_self_post_id = postid and
bm_endpoint = bb_endpoint and
bm_self_id = O.B_BLOG_ID and
bm_blog_id = bb_blog_id and
bm_error is null
do
{
req := new BLOG.."blogRequest" ('appKey_bridge', bb_blog_id, bm_post_id, bb_user, bb_pwd);
declare exit handler for sqlstate '*' { goto next; };
if (bb_type = 'Blogger' or bb_type = 'MetaWeblog' or bb_type = 'Moveable Type')
{
BLOG.blogger.delete_Post (bb_endpoint, req);
}
}
next:
delete from blog_bridge_messages where
bm_self_post_id = postid and
bm_endpoint = bb_endpoint and
bm_self_id = O.B_BLOG_ID and
bm_blog_id = bb_blog_id;
}
}
;
create table blog_types (
bt_name varchar primary key
)
;
insert into blog_types values ('Blogger')
;
insert into blog_types values ('MetaWeblog')
;
insert into blog_types values ('Moveable Type')
;
create procedure
cal_icell (inout control vspx_control, in inx int)
{
return (control.vc_parent as vspx_row_template).te_rowset[inx];
}
;
create procedure
b_date_fmt (in d datetime)
returns varchar
{
declare n date;
n := now ();
if (d is null)
return '';
if (year (d) = year (n) and month (d) = month (n) and dayofmonth (d) = dayofmonth (n))
return sprintf ('%02d:%02d:%02d', hour (d), minute (d), second (d));
else
return sprintf ('%d/%d/%d', month (d), dayofmonth (d), year (d));
}
;
create procedure
b_tit_fmt (in d datetime)
returns varchar
{
declare n date;
n := now ();
if (d is null or (year (d) = year (n) and month (d) = month (n) and dayofmonth (d) = dayofmonth (n)))
return 'Previous 10 posts...';
else
return sprintf ('Posts for %d/%d/%d...', month (d), dayofmonth (d), year (d));
}
;
create procedure
blog_user_password (in name varchar)
{
declare pass varchar;
pass := NULL;
whenever not found goto none;
select pwd_magic_calc (U_NAME, U_PASSWORD, 1) into pass
from SYS_USERS where U_NAME = name and U_DAV_ENABLE = 1 and U_IS_ROLE = 0;
none:
return pass;
}
;
create procedure blog_get_user_blogs (in uri varchar, in name varchar, in passwd varchar)
{
declare i, l int;
declare blogid, blogname, url varchar;
declare arr any;
arr := BLOG.blogger.get_Users_Blogs (uri, BLOG..blogRequest ('appKey', '', '', name, passwd));
i := 0; l := length (arr);
result_names (blogid, blogname, url);
while (i < l)
{
blogid := get_keyword ('blogid', arr[i]);
blogname := get_keyword ('blogname', arr[i]);
url := get_keyword ('url', arr[i]);
result (blogid, blogname, url);
i := i + 1;
}
}
;
drop view blog_user_blogs
;
create procedure view blog_user_blogs as blog_get_user_blogs (uri, name, passwd) (blogid varchar, blogname varchar, url varchar)
;
|