示例#1
0
 /**
  * 插件实现方法
  *
  * @access public
  * @return void
  */
 public static function render($agent)
 {
     $options = Typecho_Widget::widget('Widget_Options');
     $url_plugin = $options->pluginUrl . '/UserAgent/';
     //插件地址  ->  http://domain.com/usr/plugins/UserAgent/
     global $url_img, $icons;
     $url_img = $url_plugin . "img/";
     $icons = Typecho_Widget::widget('Widget_Options')->plugin('UserAgent')->icons;
     $show = Typecho_Widget::widget('Widget_Options')->plugin('UserAgent')->show;
     require_once 'useragent-os.php';
     $os = detect_os($agent);
     $os_img = self::img($os['code'], "/os/", $os['title']);
     $os_title = $os['title'];
     require_once 'useragent-webbrowser.php';
     $wb = detect_webbrowser($agent);
     $wb_img = self::img($wb['code'], "/net/", $wb['title']);
     $wb_title = $wb['title'];
     switch ($show) {
         case 1:
             $ua = "  " . $os_img . " " . $wb_img;
             break;
         case 2:
             $ua = "  (" . $os_title . " / " . $wb_title . ")";
             break;
         case 3:
             $ua = "  " . $os_img . "(" . $os_title . ") / " . $wb_img . "(" . $wb_title . ")";
             break;
         default:
             $ua = "  " . $os_img . $wb_img;
             break;
     }
     echo $ua;
 }
示例#2
0
function display_useragent()
{
    global $comment, $ua_show_text, $ua_text_surfing, $ua_text_on, $ua_text_via, $ua_show_ua_bool, $ua_hide_unknown_bool, $ua_doctype;
    // Check if the comment is a trackback or a comment
    if ($comment->comment_type == 'trackback' || $comment->comment_type == 'pingback') {
        // We've got a trackback...
        $trackback = detect_trackback();
        if ($ua_show_text == "1" || $ua_show_text == "3") {
            if ($ua_hide_unknown_bool == 'true' && strpos($trackback, "Unknown")) {
                $ua = "";
            } else {
                $ua = "{$ua_text_via} {$trackback}";
            }
        } elseif ($ua_show_text == "2") {
            if ($ua_hide_unknown_bool == 'true' && strpos($trackback, "Unknown")) {
                $ua = "";
            } else {
                $ua = $trackback;
            }
        }
    } else {
        // We've got a comment...
        $webbrowser = detect_webbrowser();
        $platform = detect_platform();
        // Does the user want to display text, icons, or both?
        if ($ua_show_text == "1" || $ua_show_text == "3") {
            if ($ua_hide_unknown_bool == 'true' && strpos($webbrowser, "Unknown") && strpos($platform, "Unknown")) {
                $ua = "";
            } elseif ($ua_hide_unknown_bool == 'true' && strpos($webbrowser, "Unknown")) {
                $ua = "{$ua_text_on} {$platform}";
            } elseif ($ua_hide_unknown_bool == 'true' && strpos($platform, "Unknown")) {
                $ua = "{$ua_text_surfing} {$webbrowser}";
            } else {
                $ua = "{$ua_text_surfing} {$webbrowser} {$ua_text_on} {$platform}";
            }
        } elseif ($ua_show_text == "2") {
            if ($ua_hide_unknown_bool == 'true' && strpos($webbrowser, "Unknown") && strpos($platform, "Unknown")) {
                $ua = "";
            } elseif ($ua_hide_unknown_bool == 'true' && strpos($webbrowser, "Unknown")) {
                $ua = $platform;
            } elseif ($ua_hide_unknown_bool == 'true' && strpos($platform, "Unknown")) {
                $ua = $webbrowser;
            } else {
                $ua = $webbrowser . $platform;
            }
        }
    }
    // Does the user want to display the full ua string?
    if ($ua_show_ua_bool == 'true') {
        if (strlen($ua) > 0) {
            if ($ua_doctype == "html") {
                $ua .= "<br>";
            } elseif ($ua_doctype == "xhtml") {
                $ua .= "<br />";
            }
        }
        // Attach the full ua string to the output.
        $ua .= "<small>" . htmlspecialchars(wp_strip_all_tags($comment->comment_agent, false)) . "</small>";
    }
    // The following conditional will hopefully prevent a problem where
    // the echo statement will interrupt redirects from the comment page.
    if (empty($_POST['comment_post_ID'])) {
        echo $ua;
    }
}