Beispiel #1
0
/**
 * Shortcode for paragraph
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_p($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "force" => 0), $atts));
    // execute shortcodes inside...
    $content = trim(Bbpp_ThankMeLater_Shortcoder::apply($content));
    // empty paragraph?
    if (empty($content) && !$force) {
        return "";
    }
    if ($email_type == "text") {
        return $content . "\n\n";
    } else {
        // elements which cannot appear in a <p>
        $noninline_els_regex = implode("|", array("address", "applet", "area", "base", "basefont", "blockquote", "body", "button", "caption", "center", "col", "colgroup", "dd", "dir", "div", "dl", "dt", "fieldset", "form", "frame", "frameset", "h1", "h2", "h3", "h4", "h5", "h6", "head", "hr", "html", "iframe", "ins", "isindex", "legend", "li", "link", "map", "menu", "meta", "noframes", "noscript", "object", "ol", "optgroup", "option", "p", "param", "pre", "style", "table", "tbody", "td", "tfoot", "th", "thead", "title", "tr", "u", "ul", "article", "aside", "audio", "bdi", "canvas", "command", "datalist", "details", "embed", "figcaption", "figure", "header", "hgroup", "keygen", "mark", "output", "progress", "rp", "rt", "ruby", "section", "source", "summary", "time", "track", "video"));
        // if there's any non-inline elements involved, don't put in the paragraph:
        // up to the user to place [p] ... [/p] themselves (around elements which
        // are not block)
        // TODO may consider inserting a paragraph up to the point that the non-inline
        // element occurs
        if (preg_match("#</?({$noninline_els_regex})( |>)#i", $content)) {
            return $content;
        } else {
            return "<p>" . nl2br($content) . "</p>";
        }
    }
}
Beispiel #2
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_name($atts)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "attr" => 0), $atts));
    if ($attr) {
        return esc_attr($comment->comment_author);
    }
    return $email_type == "html" ? esc_html($comment->comment_author) : $comment->comment_author;
}
Beispiel #3
0
/**
 * Shortcode for a template part (e.g. the sidebar, content, etc)
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_t_part($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "name" => "main"), $atts));
    $content = trim(Bbpp_ThankMeLater_Shortcoder::apply($content));
    Bbpp_ThankMeLater_TemplateHelper::add_part($name, $content);
    // Show no output. The template must explicity load this part!
    return "";
}
Beispiel #4
0
/**
 * Shortcode for post ID
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_post_id($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "attr" => 0), $atts));
    if ($attr) {
        return esc_attr($comment->comment_post_ID);
    }
    return $email_type == "html" ? esc_html($comment->comment_post_ID) : $comment->comment_post_ID;
}
Beispiel #5
0
/**
 * Shortcode for <h[0-6]>
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_h($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "level" => 1), $atts));
    if ($email_type == "text") {
        return str_repeat("*", $level) . " " . $content;
    }
    return "<h{$level}>" . $content . "</h{$level}>";
}
Beispiel #6
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_track($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "url" => FALSE), $atts));
    $code = base64_encode($comment->comment_ID . "-" . $comment->comment_author_email);
    $track_url = get_site_url() . "/?bbpp-thankmelater-open=" . urlencode($code);
    if ($url) {
        return $track_url;
    }
    if ($email_type == "html") {
        return "<img src=\"" . $track_url . "\" width=\"1\" height=\"1\">";
    }
}
Beispiel #7
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_htmlonly($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "apply_shortcodes" => 1), $atts));
    $apply_shortcodes = strtolower($apply_shortcodes);
    if ($email_type == "html") {
        if ($apply_shortcodes) {
            return Bbpp_ThankMeLater_Shortcoder::apply($content);
        } else {
            return $content;
        }
    }
    return "";
}
Beispiel #8
0
/**
 * Date of the comment
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_date($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "format" => _x("d M Y", "date syntax", "bbpp-thankmelater"), "gmt" => 0, "attr" => 0), $atts));
    $time = strtotime($comment->comment_date_gmt . " GMT");
    if ($gmt) {
        $date = gmdate($format, $time);
    } else {
        $date = date($format, $time);
    }
    if ($attr) {
        return esc_attr($date);
    }
    return $date;
}
Beispiel #9
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_comment_url($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "attr" => 0), $atts));
    $url = get_comment_link($comment);
    if ($attr) {
        return esc_attr($url);
    } else {
        if ($email_type == "html") {
            return esc_html($url);
        } else {
            return $url;
        }
    }
}
Beispiel #10
0
/**
 * Shortcode for image
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_img($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "src" => "", "width" => 0, "height" => 0), $atts));
    if ($email_type == "text") {
        return "";
    }
    $tag = "<img";
    $tag .= " src=\"" . htmlspecialchars($src) . "\"";
    if ($width) {
        $tag .= " width=\"" . htmlspecialchars($width) . "\"";
    }
    if ($height) {
        $tag .= " height=\"" . htmlspecialchars($height) . "\"";
    }
    return $tag;
}
Beispiel #11
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_opt_out($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "url" => TRUE), $atts));
    $code = base64_encode($comment->comment_ID . "-" . $comment->comment_author_email);
    $unsub_url = get_site_url() . "/?bbpp-thankmelater-unsubscribe=" . $code;
    if ($url) {
        return $unsub_url;
    }
    $t_html = __("We sent you this email because you left a comment on our blog. %sUnsubscribe from future emails%s.", "bbpp-thankmelater");
    $t_text = __("We sent you this email because you left a comment on our blog. Click this URL to unsubscribe from future emails: %s", "bbpp-thankmelater");
    if ($email_type == "html") {
        return "<center><small>" . sprintf($t_html, "<a href=\"" . esc_attr($unsub_url) . "\">", "</a>") . "</small></center>";
    } else {
        return sprintf($t_text, $unsub_url);
    }
}
Beispiel #12
0
/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_comment($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "maxlength" => NULL, "attr" => 0), $atts));
    $message = strip_tags($comment->comment_content);
    if ($maxlength && strlen($message) > $maxlength) {
        $message = explode("<f>", wordwrap($message, $maxlength - 3, "<f>", TRUE));
        $message = $message[0] . "...";
    }
    if ($attr) {
        return esc_attr($message);
    }
    if ($email_type == "html") {
        return esc_html($message);
    } else {
        return $message;
    }
}
Beispiel #13
0
 /**
  * Evaluate the shortcodes on some text
  * 
  * @param string $content Text containing shortcodes (or none)
  * @param array $passatt Attributes to be passed to the shortcode handler callbacks.
  * @return string The transformed text.
  */
 public static function apply($content, $passatt = NULL)
 {
     if ($passatt !== NULL) {
         self::$passatt = $passatt;
     }
     $pattern = self::getRegex();
     // we want to split the message into nice paragraphs first. Don't want
     // to interfere with shortcode tags or the content between them, so
     // translate the tags into keys...
     $keysuffix = uniqid();
     $keyed = array();
     // replace \r\n style line breaks with \n
     $content = str_replace("\r\n", "\n", $content);
     preg_match_all("/{$pattern}/s", $content, $match);
     foreach ($match[0] as $match) {
         $key = md5($match . $keysuffix);
         $keyed[$key] = $match;
         $content = str_replace($match, $key, $content);
     }
     // split by two or more new lines/carriage returns
     $lines = preg_split("#[\n\r]{2,}#", $content, NULL, PREG_SPLIT_DELIM_CAPTURE);
     // reconstruct as a sequence of paragraphs:
     $trans_content = "";
     if (count($lines) > 1) {
         foreach ($lines as $line) {
             $trans_content .= "[_p]" . trim($line) . "[/_p]";
         }
     } else {
         // [_p] will call us back... when we get to one line after evaluating
         // shortcodes inside the [_p], we stop adding [_p]'s.
         $trans_content = $lines[0];
     }
     // replace back the tag keys with the actual tags:
     foreach ($keyed as $key => $match) {
         $trans_content = str_replace($key, $match, $trans_content);
     }
     // evaluate the shortcodes (including the paragraphs we just created).
     return trim(preg_replace_callback("/{$pattern}/s", array("Bbpp_ThankMeLater_Shortcoder", "applyTag"), $trans_content));
 }
Beispiel #14
0
/**
 * Shortcode for simple template
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_t_simple($atts, $content = NULL)
{
    extract(Bbpp_ThankMeLater_Shortcoder::atts(array("email_type" => NULL, "comment" => NULL, "background_color" => "#F6F6F6", "page_background_color" => "#FFFFFF"), $atts));
    if (!preg_match("#^\\#[0-F]{6}\$#i", $background_color)) {
        $background_color = "#F6F6F6";
    }
    if (!preg_match("#^\\#[0-F]{6}\$#i", $page_background_color)) {
        $page_background_color = "#FFFFFF";
    }
    // execute shortcodes inside...
    $content = trim(Bbpp_ThankMeLater_Shortcoder::apply($content));
    $main = Bbpp_ThankMeLater_TemplateHelper::get_part("main");
    if (!$main) {
        $main = $content;
    }
    if ($email_type == "text") {
        $output = "";
        $output .= Bbpp_ThankMeLater_TemplateHelper::get_part("header") . "\n\n";
        $output .= $main . "\n\n";
        $output .= Bbpp_ThankMeLater_TemplateHelper::get_part("footer");
        return $output;
    }
    $output = "";
    $output .= "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"" . " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n";
    $output .= "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";
    $output .= "<head>\n";
    $output .= "<style type=\"text/css\">\n";
    $output .= "body { width: 100%; margin: 0px; padding: 0px;" . "font-family: arial, sans-serif; font-size: 14px; line-height: 18px;" . "color: #333333; background: {$background_color};}\n";
    $output .= "#wrap { padding-top: 10px; }\n";
    $output .= "#header-banner { padding: 0px; }\n";
    $output .= "#header { padding-top: 5px; padding-bottom: 5px;" . " padding-left: 20px; padding-right: 20px; }\n";
    $output .= "h1 { font-size: 32px; line-height: 41px; margin: 0px;" . " letter-spacing: -1px;}\n";
    $output .= "h2 { font-size: 18px; line-height: 23px; margin: 0px;" . " letter-spacing: -1px;}\n";
    $output .= "a { color: #0000FF; }\n";
    $output .= "p { padding-top: 0px; padding-bottom: 18px; margin: 0px; }\n";
    $output .= "#header-banner-table { background-color: " . $page_background_color . "; }\n";
    $output .= "#header-table { background-color: " . $page_background_color . "; }\n";
    $output .= "#content-table { background-color: " . $page_background_color . ";" . " padding-bottom: 20px; }\n";
    $output .= "#main { padding-left: 20px; padding-right: 20px; }\n";
    $output .= "#footer { padding-top: 5px; padding-bottom: 5px;" . " padding-left: 20px; padding-right: 20px; }\n";
    $output .= "#footer-table { background-color: " . $page_background_color . "; padding-bottom: 20px; }\n";
    $output .= "</style>\n";
    $output .= "</head>\n";
    $output .= "<body>\n";
    // center
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\" " . "width=\"100%\">\n";
    $output .= "<tr>\n";
    $output .= "<td align=\"center\" id=\"wrap\">\n";
    // header banner
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" . " width=\"600\" id=\"header-banner-table\">\n";
    $output .= "<tr>\n";
    $output .= "<td id=\"header-banner\">\n";
    if ($header_banner = Bbpp_ThankMeLater_TemplateHelper::get_part("header_banner")) {
        $output .= $header_banner . "\n";
    } else {
        $output .= "<img src=\"" . plugins_url('imgs/thank-you-banner.png', dirname(__FILE__)) . "\" width=\"600\" height=\"75\">";
    }
    // end header banner
    $output .= "</td>\n";
    $output .= "</tr>\n";
    $output .= "</table>\n";
    // header
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" . " width=\"600\" id=\"header-table\">\n";
    $output .= "<tr>\n";
    $output .= "<td id=\"header\">\n";
    $output .= Bbpp_ThankMeLater_TemplateHelper::get_part("header") . "\n";
    // end header
    $output .= "</td>\n";
    $output .= "</tr>\n";
    $output .= "</table>\n";
    // main
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" . " width=\"600\" id=\"content-table\">\n";
    $output .= "<tr>\n";
    $output .= "<td id=\"main\" valign=\"top\">\n";
    $output .= $main;
    // end main
    $output .= "</td>\n";
    $output .= "</tr>\n";
    $output .= "</table>\n";
    // footer
    $output .= "<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"" . " width=\"600\" id=\"footer-table\">\n";
    $output .= "<tr>\n";
    $output .= "<td id=\"footer\">\n";
    $output .= Bbpp_ThankMeLater_TemplateHelper::get_part("footer") . "\n";
    // end footer
    $output .= "</td>\n";
    $output .= "</tr>\n";
    $output .= "</table>\n";
    // end center
    $output .= "</td>\n";
    $output .= "</tr>\n";
    $output .= "</table>\n";
    $output .= "</body>\n";
    $output .= "</html>";
    return Bbpp_ThankMeLater_TemplateHelper::inline_css($output);
}
Beispiel #15
0
<?php

/**
 * 
 * @param type $attr
 */
function bbpp_thankmelater_shortcode_snip($atts)
{
    return "";
}
Bbpp_ThankMeLater_Shortcoder::add("snip", "bbpp_thankmelater_shortcode_snip");
Beispiel #16
0
 /**
  * Get the subject of message after shortcodes applied
  * 
  * @param object $comment the result of get_comment($id, OBJECT) for a particular comment.
  * @return string|null the parsed subject, or null if not available.
  */
 public function getParsedSubject($comment)
 {
     if (!class_exists("Bbpp_ThankMeLater_Shortcoder")) {
         require_once BBPP_THANKMELATER_PLUGIN_PATH . "Shortcoder.php";
     }
     if (isset($this->data[$this->pointer], $this->data[$this->pointer]["subject"])) {
         $subject = $this->data[$this->pointer]["subject"];
     } else {
         return NULL;
     }
     $subject_parsed = Bbpp_ThankMeLater_Shortcoder::apply($subject, array("email_type" => "text", "comment" => $comment));
     return $subject_parsed;
 }