2002-07-01 16:36:27 +00:00
/ *
2003-08-02 11:08:09 +00:00
* macro for rendering a part of the story content
2002-07-01 16:36:27 +00:00
* /
function content _macro ( param ) {
2003-08-02 11:08:09 +00:00
switch ( param . as ) {
case "editor" :
var inputParam = this . content . createInputParam ( param . part , param ) ;
delete inputParam . part ;
if ( param . cols || param . rows )
Html . textArea ( inputParam ) ;
2002-09-20 16:11:17 +00:00
else
2003-08-02 11:08:09 +00:00
Html . input ( inputParam ) ;
break ;
case "image" :
var part = this . content . getProperty ( param . part ) ;
if ( part && this . site . images [ part ] ) {
delete param . part ;
renderImage ( this . site . images [ part ] , param ) ;
2002-12-01 19:26:40 +00:00
}
2003-08-02 11:08:09 +00:00
break ;
default :
2004-01-07 15:04:28 +00:00
if ( ! param . clipping )
param . clipping = "..." ;
2003-08-02 11:08:09 +00:00
var part = this . getRenderedContentPart ( param . part ) ;
if ( ! part && param . fallback )
part = this . getRenderedContentPart ( param . fallback ) ;
if ( param . as == "link" ) {
if ( this . _prototype != "comment" )
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : this . href ( ) } ) ;
2003-08-02 11:08:09 +00:00
else
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : this . story . href ( ) + "#" + this . _id } ) ;
2004-01-07 15:04:28 +00:00
part = part ? part . stripTags ( ) : param . clipping ;
2003-08-02 11:08:09 +00:00
}
if ( ! param . limit )
res . write ( part ) ;
else
res . write ( part . clip ( param . limit , param . clipping ) . softwrap ( 25 ) ) ;
if ( param . as == "link" )
Html . closeLink ( ) ;
2002-07-01 16:36:27 +00:00
}
2004-01-07 15:04:28 +00:00
return ;
2002-07-01 16:36:27 +00:00
}
2001-06-18 08:57:33 +00:00
/ * *
2004-01-02 22:30:39 +00:00
* macro rendering online status of story
2001-06-18 08:57:33 +00:00
* /
function online _macro ( param ) {
2004-01-02 22:30:39 +00:00
if ( ! this . online )
res . write ( param . no ? param . no : "offline" ) ;
else
res . write ( param . yes ? param . yes : "online" ) ;
return ;
}
/ * *
* macro rendering the location of the story
* /
function location _macro ( param ) {
switch ( this . online ) {
case 1 :
Html . link ( { href : this . site . topics . get ( this . topic ) . href ( ) } , "topic" ) ;
break ;
case 2 :
res . write ( "site" ) ;
break ;
2001-12-16 18:14:00 +00:00
}
2004-01-02 22:30:39 +00:00
return ;
2001-06-18 08:57:33 +00:00
}
2004-01-02 22:30:39 +00:00
2001-06-18 08:57:33 +00:00
/ * *
2002-12-08 17:10:09 +00:00
* macro rendering createtime of story , either as editor ,
* plain text or as link to the frontpage of the day
2001-06-18 08:57:33 +00:00
* /
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" ;
2003-08-02 11:08:09 +00:00
Html . input ( param ) ;
2002-12-08 17:10:09 +00:00
} else if ( this . createtime ) {
2003-08-02 11:08:09 +00:00
var text = formatTimestamp ( this . createtime , param . format ) ;
if ( param . as == "link" && this . online == 2 )
2003-12-17 22:05:52 +00:00
Html . link ( { href : path . site . get ( String ( this . day ) ) . href ( ) } , text ) ;
2003-08-02 11:08:09 +00:00
else
2002-12-08 17:10:09 +00:00
res . write ( text ) ;
2002-04-08 11:56:18 +00:00
}
2002-12-08 17:10:09 +00:00
return ;
2001-06-18 08:57:33 +00:00
}
/ * *
* macro rendering a link to edit
* if user is allowed to edit
* /
function editlink _macro ( param ) {
2003-09-07 21:09:57 +00:00
if ( session . user ) {
try {
this . checkEdit ( session . user , req . data . memberlevel ) ;
} catch ( deny ) {
return ;
}
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : this . href ( "edit" ) } ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
2003-08-02 11:08:09 +00:00
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" ) ;
2003-08-02 11:08:09 +00:00
Html . closeLink ( ) ;
2001-06-18 08:57:33 +00:00
}
2003-09-07 21:09:57 +00:00
return ;
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 ) {
2003-09-07 21:09:57 +00:00
if ( session . user ) {
try {
this . checkDelete ( session . user , req . data . memberlevel ) ;
} catch ( deny ) {
return ;
}
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : this . href ( "delete" ) } ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
2003-08-02 11:08:09 +00:00
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" ) ;
2003-08-02 11:08:09 +00:00
Html . closeLink ( ) ;
2001-06-18 08:57:33 +00:00
}
2003-09-07 21:09:57 +00:00
return ;
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 ) {
2003-09-07 21:09:57 +00:00
if ( session . user ) {
try {
this . checkEdit ( session . user , req . data . memberlevel ) ;
} catch ( deny ) {
return ;
}
2002-12-01 19:26:40 +00:00
if ( this . online && param . mode != "toggle" )
return ;
2003-03-05 18:50:32 +00:00
delete param . mode ;
2003-05-09 14:12:06 +00:00
var text = param . text ;
2002-06-04 14:18:27 +00:00
param . linkto = "edit" ;
2002-12-01 19:26:40 +00:00
param . urlparam = "set=" + ( this . online ? "offline" : "online" ) ;
2003-08-02 11:08:09 +00:00
Html . openTag ( "a" , this . createLinkParam ( param ) ) ;
2002-06-26 16:35:28 +00:00
if ( param . image && this . site . images . get ( param . image ) )
2003-08-02 11:08:09 +00:00
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
2003-05-09 14:12:06 +00:00
else {
// currently, only the "set online" text is customizable, since this macro
// is by default only used in that context outside the story manager.
if ( this . online )
res . write ( "set offline" ) ;
else
res . write ( text ? text : "set online" ) ;
}
2003-08-02 11:08:09 +00:00
Html . closeTag ( "a" ) ;
2001-11-18 13:23:36 +00:00
}
2003-09-07 21:09:57 +00:00
return ;
2001-11-18 13:23:36 +00:00
}
/ * *
* macro renders a link to the story
* /
function viewlink _macro ( param ) {
2003-09-07 21:09:57 +00:00
if ( session . user ) {
try {
this . checkView ( session . user , req . data . memberlevel ) ;
} catch ( deny ) {
return ;
}
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : this . href ( ) } ) ;
2003-09-07 21:09:57 +00:00
if ( param . image && this . site . images . get ( param . image ) )
this . site . renderImage ( this . site . images . get ( param . image ) , param ) ;
else
res . write ( param . text ? param . text : "view" ) ;
Html . closeLink ( ) ;
}
2004-01-12 16:44:25 +00:00
return ;
2001-11-18 13:23:36 +00:00
}
2001-06-18 08:57:33 +00:00
/ * *
* macro rendering link to comments
* /
function commentlink _macro ( param ) {
2003-08-02 11:08:09 +00:00
if ( this . discussions && this . site . preferences . getProperty ( "discussions" ) )
2003-12-17 22:05:52 +00:00
Html . link ( { href : this . href ( param . to ? param . to : "comment" ) } ,
param . text ? param . text : "comment" ) ;
2003-08-02 11:08:09 +00:00
return ;
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 ) {
2003-08-02 11:08:09 +00:00
if ( ! this . site . preferences . getProperty ( "discussions" ) || ! this . discussions )
2002-07-19 08:48:22 +00:00
return ;
var commentCnt = this . comments . count ( ) ;
if ( ! param . linkto )
param . linkto = "main" ;
2003-11-23 18:24:44 +00:00
// cloning the param object to remove the macro-specific
2002-07-29 16:00:47 +00:00
// attributes from the clone for valid markup output:
2004-01-02 10:45:01 +00:00
var param2 = Object . clone ( param ) ;
2002-07-29 16:00:47 +00:00
delete param2 . one ;
delete param2 . more ;
delete param2 . no ;
var linkflag = ( param . as == "link" && param . as != "text" || ! param . as && commentCnt > 0 ) ;
if ( linkflag )
2003-08-02 11:08:09 +00:00
Html . openTag ( "a" , this . createLinkParam ( param2 ) ) ;
2002-07-29 16:00:47 +00:00
if ( commentCnt == 0 )
2003-09-18 15:49:21 +00:00
res . write ( param . no || param . no == "" ? param . no : "0 comments" ) ;
2002-07-29 16:00:47 +00:00
else if ( commentCnt == 1 )
2003-02-14 13:46:52 +00:00
res . write ( param . one ? param . one : "1 comment" ) ;
2002-07-29 16:00:47 +00:00
else
res . write ( commentCnt + ( param . more ? param . more : " comments" ) ) ;
if ( linkflag )
2003-08-02 11:08:09 +00:00
Html . closeTag ( "a" ) ;
2002-07-19 08:48:22 +00:00
return ;
2001-06-18 08:57:33 +00:00
}
/ * *
* macro loops over comments and renders them
* /
function comments _macro ( param ) {
2002-08-21 13:21:05 +00:00
var s = this . story ? this . story : this ;
2003-08-02 11:08:09 +00:00
if ( ! s . site . preferences . getProperty ( "discussions" ) || ! s . discussions )
2002-07-19 08:48:22 +00:00
return ;
2002-10-01 11:34:59 +00:00
this . comments . prefetchChildren ( ) ;
2002-07-19 08:48:22 +00:00
for ( var i = 0 ; i < this . size ( ) ; i ++ ) {
var c = this . get ( i ) ;
var linkParam = new Object ( ) ;
linkParam . name = c . _id ;
2003-08-02 11:08:09 +00:00
Html . openTag ( "a" , linkParam ) ;
Html . closeTag ( "a" ) ;
2002-07-19 08:48:22 +00:00
if ( c . parent )
c . renderSkin ( "reply" ) ;
else
c . renderSkin ( "toplevel" ) ;
2001-06-18 08:57:33 +00:00
}
2004-01-12 16:44:25 +00:00
return ;
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 ) {
2002-10-05 16:09:56 +00:00
res . data . action = this . href ( "comment" ) ;
2003-08-02 11:08:09 +00:00
( new comment ( ) ) . renderSkin ( "edit" ) ;
2001-09-05 21:44:06 +00:00
} else {
2003-12-17 22:05:52 +00:00
Html . link ( { href : this . site . members . href ( "login" ) } ,
param . text ? param . text : "Login to add your comment!" ) ;
2001-09-05 21:44:06 +00:00
}
2003-08-02 11:08:09 +00:00
return ;
2001-06-18 08:57:33 +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 ) ) {
2004-01-02 10:45:01 +00:00
var options = [ EDITABLEBY _ADMINS ,
EDITABLEBY _CONTRIBUTORS ,
EDITABLEBY _SUBSCRIBERS ] ;
var labels = [ "the author" , "all contributors" , "all subscribers" ] ;
2003-08-02 11:08:09 +00:00
delete param . as ;
if ( req . data . publish || req . data . save )
var selValue = ! isNaN ( req . data . editableby ) ? req . data . editableby : null ;
else
var selValue = this . editableby ;
2003-02-14 13:46:52 +00:00
for ( var i = 0 ; i < options . length ; i ++ ) {
2003-08-02 11:08:09 +00:00
Html . radioButton ( { name : "editableby" , value : options [ i ] , selectedValue : selValue } ) ;
res . write ( " " ) ;
res . write ( labels [ i ] ) ;
res . write ( " " ) ;
2003-02-14 13:46:52 +00:00
}
2001-07-21 22:01:36 +00:00
} else {
2003-08-02 11:08:09 +00:00
switch ( this . editableby ) {
case 0 :
2004-01-02 10:45:01 +00:00
res . write ( "Content managers and admins of '" + path . site . title + "'" ) ;
return ;
2003-08-02 11:08:09 +00:00
case 1 :
res . write ( "Contributors to '" + path . site . title + "'" ) ;
break ;
2004-01-02 10:45:01 +00:00
case 2 :
res . write ( "Subscribers of and contributors to '" + path . site . title + "'" ) ;
break ;
2003-08-02 11:08:09 +00:00
}
2001-07-21 22:01:36 +00:00
}
2002-12-01 19:26:40 +00:00
return ;
2001-08-24 11:59:24 +00:00
}
2002-07-19 08:48:22 +00:00
/ * *
* macro renders a checkbox for enabling / disabling discussions
2002-08-09 11:53:32 +00:00
* for backwards compatibility this macro also renders a hidden input
* so that we can check if the checkbox is embedded in story / edit . skin
2002-07-19 08:48:22 +00:00
* /
function discussions _macro ( param ) {
2003-08-02 11:08:09 +00:00
if ( ! path . site . preferences . getProperty ( "discussions" ) )
2003-07-22 12:01:41 +00:00
return ;
2003-03-25 15:56:07 +00:00
if ( param . as == "editor" ) {
2004-01-02 10:45:01 +00:00
var inputParam = this . createCheckBoxParam ( "discussions" , param ) ;
2003-08-02 11:08:09 +00:00
if ( ( req . data . publish || req . data . save ) && ! req . data . discussions )
2004-01-02 10:45:01 +00:00
delete inputParam . checked ;
Html . checkBox ( inputParam ) ;
2003-03-25 15:56:07 +00:00
} else
res . write ( this . discussions ? "yes" : "no" ) ;
return ;
2002-07-19 08:48:22 +00:00
}
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 ( ) ) {
2003-08-02 11:08:09 +00:00
options [ i ] = { value : topic . groupname , display : topic . groupname } ;
if ( req . data . addToTopic )
var selected = req . data . addToTopic ;
else if ( this . topic == topic . groupname )
var selected = topic . groupname ;
2002-01-05 02:33:50 +00:00
}
}
2003-12-17 22:05:52 +00:00
Html . dropDown ( { name : "addToTopic" } , options , selected , "-- choose topic --" ) ;
2003-08-02 11:08:09 +00:00
return ;
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
2003-11-23 18:24:44 +00:00
* either as link , image ( if an image entiteld by the
2002-07-26 17:09:40 +00:00
* topic name is available ) or plain text
2002-02-10 16:35:18 +00:00
* /
function topic _macro ( param ) {
2004-01-02 22:30:39 +00:00
if ( ! this . topic || ! this . online )
2002-02-10 16:35:18 +00:00
return ;
2004-01-02 22:30:39 +00:00
if ( ! param . as || param . as == "text" )
res . write ( this . topic ) ;
else if ( param . as == "link" ) {
var text = param . text ? param . text : this . topic ;
Html . link ( { href : path . site . topics . href ( this . topic ) } , text ) ;
2003-04-07 21:00:41 +00:00
} else if ( param . as == "image" ) {
2002-08-22 15:45:44 +00:00
if ( ! param . imgprefix )
param . imgprefix = "topic_" ;
2003-08-02 11:08:09 +00:00
var img = getPoolObj ( param . imgprefix + this . topic , "images" ) ;
2002-07-26 17:09:40 +00:00
if ( ! img )
return ;
2003-12-17 22:05:52 +00:00
Html . openLink ( { href : path . site . topics . href ( this . topic ) } ) ;
2002-07-26 17:09:40 +00:00
renderImage ( img . obj , param )
2003-08-02 11:08:09 +00:00
Html . closeLink ( ) ;
2004-01-02 22:30:39 +00:00
}
return ;
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-12-08 13:49:33 +00:00
* since referrers are asynchronously written to database by scheduler
* it makes sense to cache them in story . cache . rBacklinks because they
* won ' t change until the next referrer - update was done
* @ return String rendered backlinks
2002-04-25 08:00:33 +00:00
* /
2002-12-08 15:37:03 +00:00
function backlinks _macro ( param ) {
2002-12-08 13:49:33 +00:00
// check if scheduler has done a new update of accesslog
// if not and we have cached backlinks simply return them
2003-02-06 19:17:32 +00:00
if ( this . cache . lrBacklinks >= app . data . lastAccessLogUpdate )
2004-01-12 16:44:25 +00:00
return this . cache . rBacklinks ;
2002-12-08 13:49:33 +00:00
var c = getDBConnection ( "antville" ) ;
var dbError = c . getLastError ( ) ;
if ( dbError )
2003-08-02 11:08:09 +00:00
return getMessage ( "error.database" , dbError ) ;
2003-11-23 18:24:44 +00:00
2002-12-08 13:49:33 +00:00
// we're doing this with direct db access here
// (there's no need to do it with prototypes):
2003-11-23 18:24:44 +00:00
var query = "select ACCESSLOG_REFERRER, count(*) as \"COUNT\" from AV_ACCESSLOG where ACCESSLOG_F_TEXT = " + this . _id + " group by ACCESSLOG_REFERRER order by \"COUNT\" desc, ACCESSLOG_REFERRER asc;" ;
2002-12-08 13:49:33 +00:00
var rows = c . executeRetrieval ( query ) ;
var dbError = c . getLastError ( ) ;
if ( dbError )
2003-08-02 11:08:09 +00:00
return getMessage ( "error.database" , dbError ) ;
2003-11-23 18:24:44 +00:00
2002-12-08 13:49:33 +00:00
// we show a maximum of 100 backlinks
2003-08-02 11:08:09 +00:00
var limit = Math . min ( ( param . limit ? parseInt ( param . limit , 10 ) : 100 ) , 100 ) ;
2003-12-08 21:06:50 +00:00
res . push ( ) ;
2002-12-08 13:49:33 +00:00
2002-12-08 15:37:03 +00:00
var skinParam = new Object ( ) ;
var cnt = 0 ;
while ( rows . next ( ) && cnt <= limit ) {
skinParam . count = rows . getColumnItem ( "COUNT" ) ;
skinParam . referrer = rows . getColumnItem ( "ACCESSLOG_REFERRER" ) ;
2004-02-02 16:14:18 +00:00
skinParam . text = skinParam . referrer . clip ( 50 , "..." , true )
2003-12-08 21:06:50 +00:00
this . renderSkin ( "backlinkItem" , skinParam ) ;
2002-12-08 15:37:03 +00:00
cnt ++ ;
2002-12-08 13:49:33 +00:00
}
2002-04-26 13:07:51 +00:00
rows . release ( ) ;
2002-12-08 15:37:03 +00:00
// cache rendered backlinks and set timestamp for
// checking if backlinks should be rendered again
2003-12-08 21:06:50 +00:00
skinParam = { referrers : res . pop ( ) } ;
if ( skinParam . referrers . length > 0 )
2002-12-08 15:37:03 +00:00
this . cache . rBacklinks = this . renderSkinAsString ( "backlinks" , skinParam ) ;
2003-12-08 21:06:50 +00:00
else
2002-12-08 15:37:03 +00:00
this . cache . rBacklinks = "" ;
this . cache . lrBacklinks = new Date ( ) ;
2004-01-12 16:44:25 +00:00
res . write ( this . cache . rBacklinks ) ;
return ;
2002-12-17 21:15:23 +00:00
}
2003-02-14 13:46:52 +00:00
2003-03-20 18:53:55 +00:00
/ * *
2003-03-25 15:56:07 +00:00
* macro renders a checkbox whether the story is
2004-01-12 13:16:37 +00:00
* published on the site ' s front page
2003-03-20 18:53:55 +00:00
* /
function addtofront _macro ( param ) {
if ( param . as == "editor" ) {
2003-11-23 18:24:44 +00:00
// if we're in a submit, use the submitted form value.
2003-09-04 15:13:08 +00:00
// otherwise, render the object's value.
if ( req . data . publish || req . data . save ) {
if ( ! req . data . addToFront )
delete param . checked ;
} else if ( this . online != null && this . online < 2 ) {
2003-08-02 11:08:09 +00:00
delete param . checked ;
2003-09-04 15:13:08 +00:00
}
2003-08-02 11:08:09 +00:00
param . name = "addToFront" ;
2004-01-02 10:45:01 +00:00
param . value = 1 ;
2003-08-02 11:08:09 +00:00
delete param . as ;
Html . checkBox ( param ) ;
2003-03-20 18:53:55 +00:00
}
return ;
2003-02-14 13:46:52 +00:00
}