<ensure variable="att.function" value="">
<!--- > Functions: count, get, post, view. < --->
<if listFindNoCase("count,get,post,view",att.function) EQ 0>
<p>/routine-ping: invalid function="<b>#escapeMarkup(att.function)#</b>"</p>
<BREAK>
</if>
<ensure variable="att.age_bypass" value="0"> <!--- sometimes we can just bypass the whole age thing. --->
<ensure variable="att.email_from" value="">
<ensure variable="att.emailoptout_tag" value="">
<var att.emailoptout_tag = gutitleFormat(att.emailoptout_tag)>
<ensure variable="att.type" value="">
<var att.type = gutitleFormat(att.type)>
<var o = "ping">
<var _select = reReplace('
#o#.id,
#o#.so_dateinserted,
#o#.title,
#o#.name,
#o#.body,
#o#.notes,
#o#.giveto_unsignedint,
#o#.read_unsignedint,
#o#.content_extension (what was the named content''s file extension)
',"([[:space:]]|\([^\)]*\))","","all")>
<if att.function EQ "count">
<!--- count pings intended for this user --->
<ensure variable="att.user_id" value="#client_id#">
<set orb="#o#" select="count(#o#.id) AS idcount" where="#o#.giveto_unsignedint = #att.user_id#" orderby="#o#.so_dateinserted DESC">
<return set.idcount>
</set>
</if>
<if att.function EQ "get">
<!--- get pings intended for this user --->
<ensure variable="att.user_id" value="#client_id#">
<set orb="#o#" select="#_select#" where="#o#.giveto_unsignedint = #att.user_id#" orderby="#o#.so_dateinserted DESC">
<return set>
</set>
</if>
<if att.function EQ "post">
<return 0>
<if NOT ( isDefined("GLOBAL.Def.Client.published_unsignedint") AND GLOBAL.Def.Client.published_unsignedint EQ 1 )>
<if NOT ( isDefined("att.published_override") AND att.published_override EQ 1 )>
<BREAK>
</if>
</if>
<!--- send ping to a set of users --->
<ensure variable="att.users_intList" value="0">
<if isValidIntList(att.users_intList) NEQ 1>
<p>/routine-ping: users_intList="<b>#att.users_intList#</b>" is invalid.</p>
<BREAK>
</if>
<ensure variable="att.jstr" value="">
<var att.jstr = trim(lcase(att.jstr))>
<if att.jstr EQ "">
<p>/routine-ping: jstr="" is invalid.</p>
<BREAK>
</if>
<var att.jstr = replace(att.jstr,"|","","all")>
<var att.jstr = replace(att.jstr,"/","","all")>
<if listLen(att.jstr,"-") NEQ 2>
<p>/routine-ping: jstr="<b>#att.jstr#</b>" is invalid.</p>
<BREAK>
</if>
<var _tbl = listFirst(att.jstr,"-")>
<if isValidOrb(_tbl) NEQ 1>
<p>/routine-ping: jstr="<b>#att.jstr#</b>" is invalid.</p>
<BREAK>
</if>
<var _idnum = listLast(att.jstr,"-")>
<if NOT (isNumeric(_idnum) AND _idnum GT 1)>
<p>/routine-ping: jstr="<b>#att.jstr#</b>" should use a positive integer id number.</p>
<BREAK>
</if>
<var _idnum = Round(_idnum)>
<ensure variable="att.email_href" value="http://#this_domain#/j:/#_tbl#-#_idnum#">
<if att.email_href EQ "">
<p>/routine-ping: you must provide an email_href="[valid url]" attribute.</p>
<BREAK>
<elseif isValidUrl(att.email_href) NEQ 1>
<p>/routine-ping: email_href="<b>#escapeMarkup(att.email_href)#</b>" is invalid.</p>
<BREAK>
</if>
<ensure variable="att.message" value="">
<var att.message = trim(att.message)>
<if len(att.message) GT 255>
<tag.clean_shortstring str="#att.message#" chars="255">
<var att.message = return>
<BREAK>
</if>
<if att.message EQ "">
<var att.message = "#client_firstname# wants you to look at /#_tbl#-#_idnum#">
</if>
<ensure variable="att.send_email" value="0">
<ensure variable="att.user_whereclause_append" value="">
<!--- the content must be valid --->
<var _content_is_valid = 0>
<var _content_extension = "">
<var _age_num = 0>
<set j="/#_tbl#-#_idnum#.iqtpi_age_num_double">
<setcrawl>
<var _content_extension = set.extension>
<var _age_num = set.iqtpi_age_num_double>
<var _content_is_valid = 1>
</setcrawl>
<setempty>
<p>/routine-ping: record /#_tbl#-#_idnum# does not exist.</p>
</setempty>
</set>
<if _content_is_valid NEQ 1>
<BREAK>
</if>
<if att.age_bypass EQ 1>
<var _age_list = "'grown_up','way_grown_up','teen','kid'">
<else>
<if _tbl EQ "user">
<var _age_list = "'grown_up','way_grown_up','teen','kid'">
<else>
<var _age_list = "'grown_up','way_grown_up'">
<if _age_num GTE 1 AND _age_num LT 3>
<var _age_list = _age_list & "," & "'teen'">
</if>
<if _age_num GTE 1 AND _age_num LT 2>
<var _age_list = _age_list & "," & "'kid'">
</if>
</if>
</if>
<!--- weed out users that were sent a duplicate ping from the same user in the past day --->
<var _now = Now()>
<var _dt = createDate(year(_now),month(_now),day(_now))>
<var _dt = DateAdd("d",-1,_dt)>
<var _weeds = "0">
<var _weed_and = "">
<if att.type NEQ "">
<var _weed_and = " AND #o#.notes = '|#att.type#|'">
</if>
<set orb="#o#" select="#o#.giveto_unsignedint" where="#o#.user_id = #client_id# #_weed_and# AND #o#.giveto_unsignedint IN (#att.users_intList#) AND #o#.name = '|/#_tbl#-#_idnum#|' AND #o#.so_dateinserted > #createodbcdatetime(_dt)#"
groupby="#o#.giveto_unsignedint">
<setcrawl>
<var _weeds = _weeds & "," & set.giveto_unsignedint>
</setcrawl>
</set>
<var _where_append = "">
<if att.user_whereclause_append NEQ "">
<var _where_append = " AND (#att.user_whereclause_append#)">
</if>
<var _age_append = " AND user.iqtpi_agetype IN (#_age_list#)">
<if att.age_bypass EQ 1>
<var _age_append = "">
</if>
<set orb="user" select="user.id,user.name,user.email,user.emailoptout_protected"
where="user.id IN (#att.users_intList#) AND user.id NOT IN (#_weeds#)#_age_append##_where_append#">
<setcrawl>
<!--- insert the ping --->
<insert orb="ping"
title="#client_name#"
name="|/#_tbl#-#_idnum#|"
body="#att.message#"
notes="|#att.type#|"
giveto_unsignedint="#set.id#"
content_extension="#_content_extension#"
user_key_id="0">
<!--- send email --->
<var _emailoptout_case = 0>
<if att.emailoptout_tag NEQ "" AND listFindNoCase(set.emailoptout_protected,att.emailoptout_tag,"|#CHR(10)#") GT 0>
<var _emailoptout_case = 1>
</if>
<if att.send_email EQ 1 AND _emailoptout_case NEQ 1>
<var _from = "">
<if att.email_from NEQ "">
<var _from = att.email_from>
</if>
<if _from EQ "aRobot@smallerpage.com">
<tag.clean_shortstring chars="64" str="#replaceMarkup(att.message)#">
<var _subject = listFirst(return,"(")>
<var _because = "">
<var _heresalink = "#CHR(10)##CHR(10)#Here's a link to SmallerPage.com:#CHR(10)# http://smallerpage.com/">
<if att.email_href EQ "http://smallerpage.com/">
<var _heresalink = "">
</if>
<email to="#set.email#" from="#_from#" bcc="steve@fentriss.com" subject="#_subject#">Hello #escapeMarkup(set.name)#,
#escapeMarkup(att.message)#
You can view this on SmallerPage:
#att.email_href##_heresalink#
Enjoy,
- SmallerPage Email Robot
--</email>
<else>
<tag.clean_shortstring chars="64" str="#replaceMarkup(att.message)#">
<var _subject = listFirst(return,"(")>
<if listFind(GLOBAL.Def.Friends.intList,set.id) GT 0>
<var _because = "#CHR(10)##CHR(10)#We sent you this message because #escapeMarkup(client_name)# is one of your friends on #escapeMarkup(site_title)#.">
<elseif listFind(GLOBAL.Def.Followers.intList,set.id) GT 0>
<var _because = "#CHR(10)##CHR(10)#We sent you this message because you are following #escapeMarkup(client_name)# on #escapeMarkup(site_title)#.">
<else>
<var _because = "">
</if>
<email to="#set.email#" from="#_from#" bcc="steve@fentriss.com" subject="#_subject#">Hello #escapeMarkup(set.name)#,
#escapeMarkup(att.message)#
You can view this on #escapeMarkup(site_title)#:
#att.email_href##_because#
Enjoy!
- #escapeMarkup(site_title)#
--</email>
</if>
</if>
<return 1>
</setcrawl>
<setempty>
<return 0>
</setempty>
</set>
</if>
<if att.function EQ "view">
<return 0>
<!--- to "view" a ping means to delete it, provided it matches a certain jstr --->
<ensure variable="att.jstr" value="">
<var att.jstr = trim(lcase(att.jstr))>
<if att.jstr EQ "">
<BREAK>
</if>
<var att.jstr = replace(att.jstr,"|","","all")>
<var att.jstr = replace(att.jstr,"/","","all")>
<if listLen(att.jstr,"-") NEQ 2>
<return 'invalid jstr #att.jstr#'>
<BREAK>
</if>
<var _tbl = listFirst(att.jstr,"-")>
<if isValidOrb(_tbl) NEQ 1>
<return 'invalid table #_tbl#'>
<BREAK>
</if>
<var _idnum = listLast(att.jstr,"-")>
<if NOT (isNumeric(_idnum) AND _idnum GT 1)>
<return 'invalid id #_idnum#'>
<BREAK>
</if>
<var _idnum = Round(_idnum)>
<var _matches = 0>
<set orb="#o#" select="count(#o#.id) AS idcount" where="#o#.giveto_unsignedint = #client_id# AND #o#.name LIKE('%|/#_tbl#-#_idnum#|%')">
<setcrawl><var _matches = set.idcount></setcrawl>
</set>
<if _matches GT 0>
<delete orb="#o#" where="#o#.giveto_unsignedint = #client_id# AND #o#.name LIKE('%|/#_tbl#-#_idnum#|%')">
<return return>
</if>
</if>