2002-07-01 16:36:27 +00:00
/ *
* macro for rendering a part of the content .
* /
function content _macro ( param ) {
2002-07-26 12:39:31 +00:00
// moved the check for old property layout to
// objectFunctions.js/getContentPart() because
// this function is called directly sometimes [ts]
2002-07-01 16:36:27 +00:00
if ( param . as == "editor" ) {
2002-07-26 12:44:25 +00:00
// this is a first trial to add a title like
// "Re: title of previous posting" to a new posting
2002-07-26 12:39:31 +00:00
if ( param . part == "title" && ! this . content ) {
2002-07-26 13:32:22 +00:00
if ( path . comment && path . comment . title )
param . value = "Re: " + path . comment . title ;
else if ( path . story && path . story . title )
2002-07-26 12:39:31 +00:00
param . value = "Re: " + path . story . title ;
}
2002-07-26 13:21:50 +00:00
else
2002-07-26 12:39:31 +00:00
param . value = this . getContentPart ( param . part ) ;
2002-07-26 13:21:50 +00:00
param . name = "content_" + param . part ;
2002-07-10 12:20:22 +00:00
delete ( param . part ) ;
if ( ! param . height || parseInt ( param . height ) == 1 )
renderInputText ( param ) ;
2002-07-01 16:36:27 +00:00
else
2002-07-10 12:20:22 +00:00
renderInputTextarea ( param ) ;
2002-07-19 14:58:59 +00:00
} else if ( param . as == "image" ) {
var part = this . getContentPart ( param . part ) ;
if ( part && this . site . images [ part ] ) {
delete ( param . part ) ;
renderImage ( this . site . images [ part ] , param ) ;
}
2002-07-01 16:36:27 +00:00
} else if ( ! this . content ) {
return ;
} else {
var part = this . getRenderedContentPart ( param . part ) ;
if ( ! part && param . fallback )
part = this . getRenderedContentPart ( param . fallback ) ;
if ( param . part == "title" && param . as == "link" && ! part ) {
part = this . getRenderedContentPart ( "text" ) ;
param . limit = "20" ;
}
if ( param . as == "link" )
openLink ( this . href ( "main" ) ) ;
if ( ! param . limit )
2002-07-19 08:48:22 +00:00
res . write ( format ( part ) ) ;
2002-07-01 16:36:27 +00:00
else
2002-07-26 12:39:31 +00:00
renderTextPreview ( part , param . limit , param . clipping ) ;
2002-07-01 16:36:27 +00:00
if ( param . as == "link" )
closeLink ( ) ;
}
}
2001-06-18 08:57:33 +00:00
/ * *
* macro rendering title of story
* /
function title _macro ( param ) {
2002-07-01 16:36:27 +00:00
param . part = "title" ;
this . content _macro ( param ) ;
2001-06-18 08:57:33 +00:00
}
/ * *
* macro rendering text of story
* /
function text _macro ( param ) {
2002-07-01 16:36:27 +00:00
param . part = "text" ;
this . content _macro ( param ) ;
2001-06-18 08:57:33 +00:00
}
/ * *
* macro rendering online - status of story
* /
function online _macro ( param ) {
2001-12-16 18:14:00 +00:00
if ( param . as == "editor" ) {
2002-01-05 02:33:50 +00:00
var options = new Array ( "offline" , "online in topic" , "online in weblog" ) ;
2002-06-03 16:56:14 +00:00
renderDropDownBox ( "online" , options , this . online ) ;
2001-12-16 18:14:00 +00:00
} else {
if ( ! this . isOnline ( ) )
res . write ( "offline" ) ;
else if ( parseInt ( this . online , 10 ) < 2 ) {
res . write ( "online in " ) ;
2002-06-26 16:35:28 +00:00
openLink ( this . site . topics . get ( this . topic ) . href ( ) ) ;
2001-12-16 18:14:00 +00:00
res . write ( this . topic ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-12-16 18:14:00 +00:00
} else
res . write ( "online in weblog" ) ;
}
2001-06-18 08:57:33 +00:00
}
/ * *
* macro rendering createtime of story
* /
function createtime _macro ( param ) {
2002-04-08 11:56:18 +00:00
if ( param . as == "editor" ) {
if ( this . createtime )
2002-05-27 18:57:52 +00:00
param . value = formatTimestamp ( this . createtime , "yyyy-MM-dd HH:mm" ) ;
2002-04-08 11:56:18 +00:00
else
2002-05-27 18:57:52 +00:00
param . value = formatTimestamp ( new Date ( ) , "yyyy-MM-dd HH:mm" ) ;
2002-04-08 11:56:18 +00:00
param . name = "createtime" ;
2002-06-04 14:53:17 +00:00
renderInputText ( param ) ;
2002-04-08 11:56:18 +00:00
} else {
if ( ! this . createtime )
return ;
2002-05-27 18:57:52 +00:00
res . write ( formatTimestamp ( this . createtime , param . format ) ) ;
2002-04-08 11:56:18 +00:00
}
2001-06-18 08:57:33 +00:00
}
2001-06-28 18:06:25 +00:00
/ * *
* macro rendering modifytime of story
* /
function modifytime _macro ( param ) {
2001-08-15 09:15:58 +00:00
if ( this . modifytime ) {
2002-05-27 18:57:52 +00:00
res . write ( formatTimestamp ( this . modifytime , param . format ) ) ;
2001-06-28 18:06:25 +00:00
}
}
2001-06-18 08:57:33 +00:00
2001-07-01 19:40:08 +00:00
/ * *
* macro renders the name of the author
2002-06-26 16:35:28 +00:00
* ! ! ! left for backwards - compatibility ! ! !
2001-07-01 19:40:08 +00:00
* /
function author _macro ( param ) {
2002-06-26 16:35:28 +00:00
this . creator _macro ( param ) ;
}
/ * *
* macro renders the name of the creator
* /
function creator _macro ( param ) {
if ( ! this . creator )
2001-07-21 22:01:36 +00:00
return ;
2002-06-26 16:35:28 +00:00
if ( param . as == "link" && this . creator . url ) {
openLink ( this . creator . url ) ;
res . write ( this . creator . name ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-07-21 13:25:06 +00:00
} else
2002-06-26 16:35:28 +00:00
res . write ( this . creator . name ) ;
2001-07-01 19:40:08 +00:00
}
2001-07-21 22:01:36 +00:00
/ * *
* macro renders the name of the modifier
* /
function modifier _macro ( param ) {
2001-08-15 09:15:58 +00:00
if ( ! this . modifier )
2001-07-21 22:01:36 +00:00
return ;
if ( param . as == "link" && this . modifier . url ) {
2002-06-04 14:18:27 +00:00
openLink ( this . modifier . url ) ;
2001-07-21 22:01:36 +00:00
res . write ( this . modifier . name ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-07-21 22:01:36 +00:00
} else
res . write ( this . modifier . name ) ;
}
2001-10-21 12:04:38 +00:00
/ * *
* macro renders the url of this story
* /
function url _macro ( param ) {
res . write ( this . href ( ) ) ;
}
2001-06-18 08:57:33 +00:00
/ * *
* macro rendering a link to edit
* if user is allowed to edit
* /
function editlink _macro ( param ) {
2002-06-02 16:05:37 +00:00
if ( ! this . isEditDenied ( session . user ) ) {
2002-06-04 14:18:27 +00:00
openLink ( this . href ( "edit" ) ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
2001-06-18 08:57:33 +00:00
else
2001-07-21 22:01:36 +00:00
res . write ( param . text ? param . text : "edit" ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-06-18 08:57:33 +00:00
}
}
/ * *
* macro rendering a link to delete
2002-06-26 16:35:28 +00:00
* if user is creator of this story
2001-06-18 08:57:33 +00:00
* /
function deletelink _macro ( param ) {
2002-06-02 16:05:37 +00:00
if ( ! this . isDeleteDenied ( session . user ) ) {
2002-06-04 14:18:27 +00:00
openLink ( this . href ( "delete" ) ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
2001-06-18 08:57:33 +00:00
else
2001-07-21 22:01:36 +00:00
res . write ( param . text ? param . text : "delete" ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-06-18 08:57:33 +00:00
}
}
2001-11-18 13:23:36 +00:00
/ * *
* macro renders a link to
* toggle the online - status of this story
* /
function onlinelink _macro ( param ) {
2002-06-02 16:05:37 +00:00
if ( ! this . isEditDenied ( session . user ) ) {
2002-06-04 14:18:27 +00:00
param . linkto = "edit" ;
2002-06-04 15:37:41 +00:00
param . urlparam = "set=" + ( this . isOnline ( ) ? "offline" : "online" ) ;
2002-06-04 14:18:27 +00:00
openMarkupElement ( "a" , this . createLinkParam ( param ) ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
2001-11-18 13:23:36 +00:00
else
res . write ( this . isOnline ( ) ? "set offline" : "set online" ) ;
2002-06-04 14:18:27 +00:00
closeMarkupElement ( "a" ) ;
2001-11-18 13:23:36 +00:00
}
}
/ * *
* macro renders a link to the story
* /
function viewlink _macro ( param ) {
2002-06-02 16:05:37 +00:00
if ( this . isViewDenied ( session . user ) )
2001-11-18 13:23:36 +00:00
return ;
2002-06-04 14:18:27 +00:00
openLink ( this . href ( ) ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
2001-11-18 13:23:36 +00:00
else
res . write ( param . text ? param . text : "view" ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-11-18 13:23:36 +00:00
}
2001-06-18 08:57:33 +00:00
/ * *
* macro rendering link to comments
2001-07-21 22:01:36 +00:00
* DEPRECATED
2002-06-26 16:35:28 +00:00
* this is just left for compatibility with existing sites
2001-07-21 22:01:36 +00:00
* use a simple like i . e . < % story . link to = "comment" text = "place your comment" % > instead
2001-06-18 08:57:33 +00:00
* /
function commentlink _macro ( param ) {
2002-07-19 08:48:22 +00:00
if ( ! this . hasDiscussions ( ) )
return ;
openLink ( this . href ( param . to ? param . to : "comment" ) ) ;
res . write ( param . text ? param . text : "place your comment" ) ;
closeLink ( ) ;
2001-06-18 08:57:33 +00:00
}
2001-07-21 22:01:36 +00:00
2001-06-18 08:57:33 +00:00
/ * *
* macro renders number of comments
* options : text to use when no comment
* text to use when one comment
* text to use when more than one comment
2001-12-10 23:26:45 +00:00
* action to link to ( default : main )
2001-06-18 08:57:33 +00:00
* /
function commentcounter _macro ( param ) {
2002-07-19 08:48:22 +00:00
if ( ! this . hasDiscussions ( ) )
return ;
var commentCnt = this . comments . count ( ) ;
if ( ! param . linkto )
param . linkto = "main" ;
2002-07-29 16:00:47 +00:00
// cloning the param object to remove the macro-specific
// attributes from the clone for valid markup output:
var param2 = cloneObject ( param ) ;
delete param2 . one ;
delete param2 . more ;
delete param2 . no ;
var linkflag = ( param . as == "link" && param . as != "text" || ! param . as && commentCnt > 0 ) ;
if ( linkflag )
2002-07-29 13:04:45 +00:00
openMarkupElement ( "a" , this . createLinkParam ( param2 ) ) ;
2002-07-29 16:00:47 +00:00
if ( commentCnt == 0 )
res . write ( commentCnt + ( param . no ? param . no : " comments" ) ) ;
else if ( commentCnt == 1 )
res . write ( commentCnt + ( param . one ? param . one : " comment" ) ) ;
else
res . write ( commentCnt + ( param . more ? param . more : " comments" ) ) ;
if ( linkflag )
2002-07-19 08:48:22 +00:00
closeMarkupElement ( "a" ) ;
return ;
2001-06-18 08:57:33 +00:00
}
/ * *
* macro loops over comments and renders them
* /
function comments _macro ( param ) {
2002-07-19 08:48:22 +00:00
if ( ! path . story . hasDiscussions ( ) )
return ;
for ( var i = 0 ; i < this . size ( ) ; i ++ ) {
var c = this . get ( i ) ;
var linkParam = new Object ( ) ;
linkParam . name = c . _id ;
renderMarkupElement ( "a" , linkParam ) ;
if ( c . parent )
c . renderSkin ( "reply" ) ;
else
c . renderSkin ( "toplevel" ) ;
2001-06-18 08:57:33 +00:00
}
}
/ * *
* macro checks if user is logged in and not blocked
* if true , render form to add a comment
* /
function commentform _macro ( param ) {
2002-06-02 16:05:37 +00:00
if ( session . user ) {
2001-09-05 21:44:06 +00:00
var c = new comment ( ) ;
c . renderSkin ( "edit" ) ;
} else {
2002-06-26 16:35:28 +00:00
openLink ( this . site . members . href ( "login" ) ) ;
2001-09-05 21:44:06 +00:00
res . write ( param . text ? param . text : "login to add your comment!" ) ;
2002-06-04 14:18:27 +00:00
closeLink ( ) ;
2001-09-05 21:44:06 +00:00
}
2001-06-18 08:57:33 +00:00
}
/ * *
2001-10-21 12:04:38 +00:00
* macro left for backwards - compatibility
* calls global image _macro ( )
2001-06-18 08:57:33 +00:00
* /
function image _macro ( param ) {
2001-10-21 12:04:38 +00:00
image _macro ( param ) ;
2001-07-18 15:58:18 +00:00
}
2001-07-21 22:01:36 +00:00
2001-08-26 19:15:29 +00:00
/ * *
2001-10-21 12:04:38 +00:00
* macro left for backwards - compatibility
2002-06-04 18:11:59 +00:00
* calls global image _macro ( ) as "popup"
2001-08-26 19:15:29 +00:00
* /
function thumbnail _macro ( param ) {
2002-06-04 18:11:59 +00:00
param . as = "popup" ;
image _macro ( param ) ;
2001-08-26 19:15:29 +00:00
}
2001-07-21 22:01:36 +00:00
/ * *
* macro renders the property of story that defines if
* other users may edit this story
* /
function editableby _macro ( param ) {
2002-06-26 16:35:28 +00:00
if ( param . as == "editor" && ( session . user == this . creator || ! this . creator ) ) {
2002-01-22 19:49:49 +00:00
var options = new Array ( "Subscribers and Contributors" , "Contributors only" ) ;
2002-06-03 16:56:14 +00:00
renderDropDownBox ( "editableby" , options , this . editableby , "----" ) ;
2001-07-21 22:01:36 +00:00
} else {
if ( this . editableby == 0 )
2002-06-26 16:35:28 +00:00
res . write ( "Subscribers of and Contributors to " + this . site . title ) ;
2001-07-21 22:01:36 +00:00
else if ( this . editableby == 1 )
2002-06-26 16:35:28 +00:00
res . write ( "Contributors to " + this . site . title ) ;
2001-11-03 09:21:43 +00:00
else
2002-06-26 16:35:28 +00:00
res . write ( "Content Managers and Admins of " + this . site . title ) ;
2001-07-21 22:01:36 +00:00
}
2001-08-24 11:59:24 +00:00
}
2002-07-19 08:48:22 +00:00
/ * *
* macro renders a checkbox for enabling / disabling discussions
* /
function discussions _macro ( param ) {
if ( param . as == "editor" ) {
if ( this . discussions == null && path . site . hasDiscussions ( ) )
param . check = "true" ;
renderInputCheckbox ( this . createInputParam ( "discussions" , param ) ) ;
} else
res . write ( parseInt ( this . discussions , 10 ) ? "yes" : "no" ) ;
}
2002-01-05 02:33:50 +00:00
/ * *
* macro renders a list of existing topics as dropdown
* /
function topicchooser _macro ( param ) {
2002-06-26 16:35:28 +00:00
var size = path . site . topics . size ( ) ;
2002-01-05 02:33:50 +00:00
var options = new Array ( ) ;
for ( var i = 0 ; i < size ; i ++ ) {
2002-06-26 16:35:28 +00:00
var topic = path . site . topics . get ( i ) ;
2002-01-05 02:33:50 +00:00
if ( topic . size ( ) ) {
2002-02-10 16:35:18 +00:00
options [ i ] = topic . groupname ;
2002-01-05 02:33:50 +00:00
if ( this . topic == topic . groupname )
2002-02-10 16:35:18 +00:00
var selectedIndex = i ;
2002-01-05 02:33:50 +00:00
}
}
2002-06-03 16:56:14 +00:00
renderDropDownBox ( "topicidx" , options , selectedIndex , "-- choose topic --" ) ;
2002-01-05 02:33:50 +00:00
}
2002-02-10 16:35:18 +00:00
/ * *
* macro renders the name of the topic this story belongs to
2002-07-26 17:09:40 +00:00
* either as link , image ( if an image entiteld by the
* topic name is available ) or plain text
* NOTE : for backwards compatibility , the default is a link and
* you have to set "text" explicitely ( which is not so nice , imho . )
2002-02-10 16:35:18 +00:00
* /
function topic _macro ( param ) {
if ( ! this . topic )
return ;
2002-07-26 17:09:40 +00:00
if ( ! param . as || param . as == "link" ) {
openLink ( this . site . topics . get ( this . topic ) . href ( ) ) ;
res . write ( this . topic ) ;
closeLink ( ) ;
}
else if ( param . as == "image" ) {
var img = getPoolObj ( this . topic , "images" ) ;
if ( ! img )
return ;
openLink ( this . site . topics . get ( this . topic ) . href ( ) ) ;
renderImage ( img . obj , param )
closeLink ( ) ;
}
else if ( param . as = "text" )
res . write ( this . topic ) ;
2002-04-08 11:56:18 +00:00
}
2002-04-24 13:35:44 +00:00
2002-04-25 08:00:33 +00:00
/ * *
* macro returns a list of references linking to a story
* /
2002-04-24 13:35:44 +00:00
2002-04-25 08:00:33 +00:00
function backlinks _macro ( ) {
2002-06-26 16:35:28 +00:00
// this is a clone of site.listReferrers_macro.
2002-04-24 13:35:44 +00:00
var str = "" ;
var c = getDBConnection ( "antville" ) ;
2002-06-12 17:19:05 +00:00
var dbError = c . getLastError ( ) ;
if ( dbError )
2002-06-26 16:35:28 +00:00
return ( getMsg ( "error" , "database" , dbError ) ) ;
2002-04-24 13:35:44 +00:00
// we're doing this with direct db access here
// (there's no need to do it with prototypes):
2002-06-26 16:35:28 +00:00
var query = "select *, count(*) as \"COUNT\" from AV_ACCESSLOG where ACCESSLOG_F_TEXT = " + this . _id + " group by ACCESSLOG_REFERRER order by \"COUNT\" desc, ACCESSLOG_REFERRER asc;" ;
2002-04-24 13:35:44 +00:00
var rows = c . executeRetrieval ( query ) ;
2002-06-12 17:19:05 +00:00
var dbError = c . getLastError ( ) ;
if ( dbError )
2002-06-26 16:35:28 +00:00
return ( getMsg ( "error" , "database" , dbError ) ) ;
2002-04-24 13:35:44 +00:00
var param = new Object ( ) ;
while ( rows . next ( ) ) {
param . count = rows . getColumnItem ( "COUNT" ) ;
2002-05-14 14:22:24 +00:00
// these two lines are necessary only for hsqldb connections:
if ( param . count == 0 )
continue ;
2002-06-26 16:35:28 +00:00
param . referrer = rows . getColumnItem ( "ACCESSLOG_REFERRER" ) ;
2002-04-24 13:35:44 +00:00
param . text = param . referrer . length > 50 ? param . referrer . substring ( 0 , 50 ) + "..." : param . referrer ;
2002-04-25 08:00:33 +00:00
str += this . renderSkinAsString ( "backlinkItem" , param ) ;
2002-04-24 13:35:44 +00:00
}
2002-04-26 13:07:51 +00:00
rows . release ( ) ;
2002-04-24 13:35:44 +00:00
param = new Object ( ) ;
param . referrers = str ;
2002-04-25 08:00:33 +00:00
if ( str )
str = this . renderSkinAsString ( "backlinks" , param ) ;
2002-04-24 13:35:44 +00:00
return ( str ) ;
2002-07-19 14:58:59 +00:00
}