function display_copyright($content) { if (BsaUtil::is_enabled(self::OPTION_NAME) && is_single()) { $copyright = BsaUtil::get_value(self::OPTION_INFO, ''); if (strpos($copyright, self::VAR_LINK)) { // Replace the reserved viarable with blog name and article link $blog_link = '<a href="' . get_permalink() . '">' . get_bloginfo('name') . '</a>'; $copyright = str_replace(self::VAR_LINK, $blog_link, $copyright); } $content = $content . $copyright; } return $content; }
static function baidu_submit($post_id) { // Prevent submitting the same post multi-times if (BsaUtil::is_enabled(self::OPTION_NAME) && function_exists('curl_init') && get_post_meta($post_id, '_baidu_submitted', true) != 1) { // Check if already submitted $url = get_permalink($post_ID); $token = BsaUtil::get_value(self::OPTION_TOKEN, ''); $domain = BsaUtil::get_domain(); // Compose API URL $api = sprintf(self::OPTION_BAIDU_APILINK, $domain, $token); $ch = curl_init(); $options = array(CURLOPT_URL => $api, CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_POSTFIELDS => $url, CURLOPT_HTTPHEADER => array('Content-Type: text/plain')); curl_setopt_array($ch, $options); // Get JSON formatted response $result = json_decode(curl_exec($ch), true); // There will be 'success' field if it is succeeded. if (array_key_exists('success', $result)) { add_post_meta($post_id, '_baidu_submitted', 1, true); } } }