register_hook('TPL_ACT_UNKNOWN', 'BEFORE', $this, 'handleTplActUnknown', array()); $controller->register_hook('ACTION_ACT_PREPROCESS', 'BEFORE', $this, 'handleActPreprocess', array()); $controller->register_hook('HTML_UPDATEPROFILEFORM_OUTPUT', 'BEFORE', $this, 'handle_profile_form', array()); } /* * Add a field for RTM import email */ function handle_profile_form(&$event, $param){ global $INFO; if (empty($_SERVER['REMOTE_USER'])) { return; // Not logged in } // include conf file for user $username = $_SERVER['REMOTE_USER']; $profileFilename = RTMCHECKLIST_ROOTDIR.'conf/profile_'.$username.'.php'; if (is_writable($profileFilename)) { include($profileFilename); } $currentRtmEmail = $INFO['userinfo']['rtmemail']; $inputRtmEmail = '
'; $rtm_form = '
'; $rtm_form = ''; $rtm_form.= '
'.$this->getLang('legend_title').''; $rtm_form.= ''; $rtm_form.= $inputRtmEmail; $rtm_form.= ''; $rtm_form.= ''; $rtm_form.= '
'; $rtm_form.= '
'; $pos = $event->data->findElementByAttribute('type', 'reset'); $event->data->insertElement($pos+3, $rtm_form); } function handleActPreprocess(&$event, $param){ if($event->data == 'plugin_rtmsend'){ // Accept the action $event->preventDefault(); $event->stopPropagation(); return; } else if($event->data == 'rtmemailregister') { // Accept the action $event->preventDefault(); $event->stopPropagation(); return; } else { // nothing to do for us return; } return; } /** * Hook for event TPL_ACT_UNKNOWN, action */ function handleTplActUnknown(&$event, $param) { if ($event->data == 'plugin_rtmsend') { global $INPUT; //available since release 2012-10-13 "Adora Belle" global $INFO; $wikitext = "=== ".$this->getLang('Results')." ===\n"; if(!checksecuritytoken()) { return; } // send the checklist to RTM $sendResult = false; if (empty($_SERVER['REMOTE_USER'])) { $event->data = 'login'; return; // Not logged in } // include conf file for user $username = $_SERVER['REMOTE_USER']; $profileFilename = RTMCHECKLIST_ROOTDIR.'conf/profile_'.$username.'.php'; if (is_writable($profileFilename)) { include($profileFilename); } // $tasksList = $INPUT->str('taskslist'); $rtmEmail = $INFO['userinfo']['rtmemail']; if(empty($rtmEmail)) { $wikitext .= $this->getLang('error_fill_email'); } // send the mail if(mail_send($rtmEmail, "", // no title $tasksList)) { $sendResult = true; } // Accept the action $event->preventDefault(); $event->stopPropagation(); // show final result if($sendResult) $wikitext.= $this->getLang('checklist_sent'); else $wikitext.= $this->getLang('checklist_not_sent'); $pageId = $INPUT->str('id'); $wikitext.= "[[".htmlspecialchars($pageId)."|".$this->getLang('go_back_to').htmlspecialchars($pageId)." ".$this->getLang('page')."]]"; // parse and render. TODO: cache $ret = p_render('xhtml',p_get_instructions($wikitext),$info); echo $ret; } else if($event->data == 'rtmemailregister') { global $INPUT; //available since release 2012-10-13 "Adora Belle" if(!checksecuritytoken()) { return; } // better safe than sorry if (empty($_SERVER['REMOTE_USER'])) { $event->data = 'login'; return; // Not logged in } $username = $_SERVER['REMOTE_USER']; // make sure dir RTMCHECKLIST_ROOTDIR is created mkdir(RTMCHECKLIST_ROOTDIR.'conf', 0700); //write file: RTMCHECKLIST_ROOTDIR.'conf/profile_'.$username.'.php' $fp = fopen(RTMCHECKLIST_ROOTDIR.'conf/profile_'.$username.'.php', 'w'); fwrite($fp, "str('rtmemail'))."';\n"); fwrite($fp, '?>'); fclose($fp); echo $this->getLang('your_email_add').htmlspecialchars($INPUT->str('rtmemail')).$this->getLang('is_now_saved'); // Accept the action $event->preventDefault(); $event->stopPropagation(); // all work has been done in handleActPreprocess() //$event->data = 'profile'; } } }