Example #1
0
 /**
  * Function to get a session var
  *
  * @since 1.0.0
  *
  * @param string $key  - The session var name
  * @param string $prefix (OPTIONAL) - The session var prefix
  *
  * @return object - The cookie
  */
 public static function sessionGet($key, $prefix = "")
 {
     $key = $prefix . $key;
     $value = null;
     if (isset($_SESSION[$key])) {
         $value = $_SESSION[$key];
         if (preg_match("/" . TSP_Settings::$cookie_prefix_encoded . "/", $value)) {
             $value = preg_replace("/" . TSP_Settings::$cookie_prefix_encoded . "/", "", $value);
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("Get encoded session var [{$key}] = {$value}");
             }
             $value = stripslashes($value);
             $value = json_decode($value, true);
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("Get decoded session var [{$key}] = " . @json_encode($value));
             }
         } else {
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("Get session var [{$key}] = {$value}");
             }
         }
     }
     return $value;
 }
Example #2
0
 /**
  * Funciton to send mail using PHPMailer
  *
  * @since 1.0.0
  *
  * @param string $to - the email address
  * @param string $subject - the email subject
  * @param string $body - the email body
  * @param optional string $attachment - the email attachment
  *
  * @return none
  *
  */
 public function send($to, $subject, $body, $attachment = null)
 {
     try {
         if (TSP_Config::get('app.debug')) {
             TSP_Log::info("Preparing mail...");
         }
         $this->mail->setFrom($this->mail->From, $this->mail->FromName);
         if (TSP_Settings::$admin_notify) {
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("Adding admin to BCC...");
             }
             $this->mail->AddBCC(TSP_Settings::$admin_email, TSP_Settings::$admin_email);
         }
         $plain_text = strip_tags($body, "<br>");
         $plain_text = preg_replace("/\\<br\\>/", "\n", $plain_text);
         $this->mail->addReplyTo($this->mail->From, $this->mail->FromName);
         $this->mail->addAddress($to);
         $this->mail->Subject = utf8_decode($subject);
         $this->mail->msgHTML($body);
         $this->mail->AltBody = $plain_text;
         if (file_exists($attachment)) {
             $this->mail->AddAttachment($attachment, basename($attachment));
         }
         if (TSP_Config::get('app.debug')) {
             TSP_Log::info("Sending mail...");
         }
         if (TSP_Config::get('app.debug')) {
             TSP_Log::info("Sending mail content {$plain_text}...");
         }
         if (!$this->mail->Send()) {
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("DID NOT send email, Response: {$this->mail->ErrorInfo}.");
             }
         } else {
             if (TSP_Config::get('app.debug')) {
                 TSP_Log::info("Message sent!");
             }
         }
         $this->mail->ClearAddresses();
         $this->mail->ClearAllRecipients();
     } catch (phpmailerException $e) {
         if (TSP_Config::get('app.debug')) {
             TSP_Log::info("PHPMailer: DID NOT send email, Response: {$e->errorMessage()}.");
         }
     } catch (Exception $e) {
         if (TSP_Config::get('app.debug')) {
             TSP_Log::info("Exception: DID NOT send email, Response: {$e->errorMessage()}.");
         }
     }
 }
    /**
     * Function to add a new contact to OAP
     *
     * @since 1.0.4
     *
     * @param int $id - the contact ID
     * @param array $params - a list of parameters to add
     *
     * @return string $response - The curl response (XML)
     */
    public function updateContact($id, $params, $tag = "Contact Information")
    {
        $reqType = "update";
        $data = <<<STRING
<contact id="{$id}">
    <Group_Tag name="{$tag}">

STRING;
        foreach ($params as $key => $value) {
            $data .= <<<STRING
            <field name="{$key}">{$value}</field>
STRING;
        }
        $data .= <<<STRING

    </Group_Tag>
    <Group_Tag name="Sequences and Tags">
        <field name="Contact Tags">{$params['tags']}</field>
        <field name="Sequences">{$params['sequences']}</field>
    </Group_Tag>
</contact>
STRING;
        $postargs = array('appid' => $this->id, 'key' => $this->key, 'return_id' => '1', 'reqType' => $reqType, 'data' => $data);
        if (TSP_Config::get('app.debug')) {
            TSP_Log::info("Sending post args to update info to OAP: " . @json_encode($postargs));
        }
        $response = TSP_Helper::getCurlResults($this->URL, null, $postargs, true);
        return $response;
    }