* implement paging hooks in a templated way so it can be called from them.
authorWilfried Göesgens <willi@citadel.org>
Sat, 29 Aug 2009 23:23:29 +0000 (23:23 +0000)
committerWilfried Göesgens <willi@citadel.org>
Sat, 29 Aug 2009 23:23:29 +0000 (23:23 +0000)
webcit/paging.c
webcit/static/t/page_now.html [new file with mode: 0644]
webcit/static/t/paging.html [new file with mode: 0644]
webcit/static/t/paging_anchor.html [new file with mode: 0644]
webcit/static/t/paging_failed_hook.html [new file with mode: 0644]
webcit/webcit.c

index e93ac646bda13cd044668a182b47b3cef414b237..856ed018cc56a329fd8e918c8a28cf4ed3aab3f6 100644 (file)
@@ -139,58 +139,22 @@ void do_chat(void)
  * If there are instant messages waiting, and we notice that we haven't checked them in
  * a while, it probably means that we need to open the instant messenger window.
  */
-void page_popup(void)
+int Conditional_PAGE_WAITING(StrBuf *Target, WCTemplputParams *TP)
 {
        int len;
        char buf[SIZ];
 
        /** JavaScript function to alert the user that popups are probably blocked */
-       wprintf("<script type=\"text/javascript\">      "
-               "function PopUpFailed() {       "
-               " alert(\"%s\");        "
-               "}      "
-               "</script>\n",
-               _("You have one or more instant messages waiting, but the Citadel Instant Messenger "
-                 "window failed to open.  This is probably because you have a popup blocker "
-                 "installed.  Please configure your popup blocker to allow popups from this site "
-                 "if you wish to receive instant messages.")
-       );
-
        /** First, do the check as part of our page load. */
        serv_puts("NOOP");
        len = serv_getln(buf, sizeof buf);
        if ((len >= 3) && (buf[3] == '*')) {
                if ((time(NULL) - WC->last_pager_check) > 60) {
-                       wprintf("<script type=\"text/javascript\">"
-                               " var oWin = window.open('static/instant_messenger.html', "
-                               " 'CTDL_MESSENGER', 'width=700,height=400');    "
-                               " if (oWin==null || typeof(oWin)==\"undefined\") {      "
-                               "  PopUpFailed();       "
-                               " }     "
-                               "</script>"
-                       );      
+                       return 1;
                }
        }
-
+       return 0;
        /** Then schedule it to happen again a minute from now if the user is idle. */
-       wprintf("<script type=\"text/javascript\">      "
-               " function HandleSslp(sslg_xmlresponse) {       "
-               "  sslg_response = sslg_xmlresponse.responseText.substr(0, 1);  "
-               "  if (sslg_response == 'Y') {  "
-               "   var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER',   "
-               "    'width=700,height=400');   "
-               "   if (oWin==null || typeof(oWin)==\"undefined\") {    "
-               "    PopUpFailed();     "
-               "   }   "
-               "  }    "
-               " }     "
-               " function CheckPager() {       "
-               "  new Ajax.Request('sslg', { method: 'get', parameters: CtdlRandomString(),    "
-               "   onSuccess: HandleSslp } );  "
-               " }     "
-               " new PeriodicalExecuter(CheckPager, 30);       "
-               "</script>      "
-       );
 }
 
 
@@ -528,6 +492,7 @@ InitModule_PAGING
        WebcitAddUrlHandler(HKEY("chat_recv"), chat_recv, 0);
        WebcitAddUrlHandler(HKEY("chat_send"), chat_send, 0);
        WebcitAddUrlHandler(HKEY("ajax_send_instant_message"), ajax_send_instant_message, AJAX);
+       RegisterConditional(HKEY("COND:PAGE:WAITING"), 0, Conditional_PAGE_WAITING, CTX_NONE);
 }
 
 
diff --git a/webcit/static/t/page_now.html b/webcit/static/t/page_now.html
new file mode 100644 (file)
index 0000000..dab1c4f
--- /dev/null
@@ -0,0 +1,7 @@
+<script type="text/javascript">
+ var oWin = window.open('static/instant_messenger.html', 
+ 'CTDL_MESSENGER', 'width=700,height=400');    
+ if (oWin==null || typeof(oWin)=="undefined") {
+  PopUpFailed();
+ }
+</script>
diff --git a/webcit/static/t/paging.html b/webcit/static/t/paging.html
new file mode 100644 (file)
index 0000000..5ae3512
--- /dev/null
@@ -0,0 +1 @@
+<?=("paging_failed_hook")><?%("COND:PAGE:WAITING", 1, 1, 1, =("page_now"), "")><?=("paging_anchor")>
diff --git a/webcit/static/t/paging_anchor.html b/webcit/static/t/paging_anchor.html
new file mode 100644 (file)
index 0000000..15a0bab
--- /dev/null
@@ -0,0 +1,16 @@
+<script type="text/javascript"> function HandleSslp(sslg_xmlresponse) {
+  sslg_response = sslg_xmlresponse.responseText.substr(0, 1);
+  if (sslg_response == 'Y') {
+   var oWin = window.open('static/instant_messenger.html', 'CTDL_MESSENGER',
+    'width=700,height=400');
+   if (oWin==null || typeof(oWin)=="undefined") {
+    PopUpFailed();
+   }
+  }
+ }
+ function CheckPager() {
+  new Ajax.Request('sslg', { method: 'get', parameters: CtdlRandomString(),
+   onSuccess: HandleSslp } );
+ }
+ new PeriodicalExecuter(CheckPager, 30);
+</script>
diff --git a/webcit/static/t/paging_failed_hook.html b/webcit/static/t/paging_failed_hook.html
new file mode 100644 (file)
index 0000000..d814fcb
--- /dev/null
@@ -0,0 +1,5 @@
+<script type="text/javascript">
+function PopUpFailed() {
+ alert("<?_("You have one or more instant messages waiting, but the Citadel Instant Messenger window failed to open.  This is probably because you have a popup blocker installed.  Please configure your popup blocker to allow popups from this site if you wish to receive instant messages.")>");
+}
+</script>
index 869793a2c2ace1b4c524d9d388b99c2e3c2dbaef..391370bcac789f87d34d88deccdf0be681258ebb 100644 (file)
@@ -209,8 +209,7 @@ void output_headers(        int do_httpheaders,     /* 1 = output HTTP headers
                        FlushStrBuf(WCC->ImportantMsg);
                }
                if ( (WCC->logged_in) && (!unset_cookies) ) {
-                       /*DoTemplate(HKEY("iconbar"), NULL, &NoCtx);*/
-                       page_popup();
+                       DoTemplate(HKEY("paging"), NULL, &NoCtx);
                }
 
                if (do_room_banner == 1) {