public static function getInstance() { if (self::$_instance === null) { self::$_instance = new self(); } return self::$_instance; }
public function __construct($shortName = null, $secret = null, $jwt = null) { $this->shortName = $shortName; $this->secret = $secret; $this->jwt = $jwt; $this->generator = Typecho_Widget::widget('Widget_Options')->generator; $this->http = Typecho_Http_Client::get(); $this->userAgent = $this->generator . '|Duoshuo/' . Duoshuo_Typecho::VERSION; $this->plugin = Duoshuo_Typecho::getInstance(); if ($this->plugin->getPlugOption('end_point') !== NULL) { $this->end_point = Duoshuo_Typecho::$PointMap[intval($this->plugin->getPlugOption('end_point'))]; } }
public function api() { $this->fileload(); if (!headers_sent()) { $this->nocache_headers(); //max age TODO: header('Content-Type: text/javascript; charset=utf8'); } if (!class_exists('Duoshuo_Typecho')) { $response = array('code' => 30, 'errorMessage' => 'duoshuo plugin hasn\'t been activated.'); echo json_encode($response); exit; } $plugin = Duoshuo_Typecho::getInstance(); try { if ($plugin->getPlugOption('sync_to_local') !== NULL) { if ($plugin->getPlugOption('sync_to_local') == 0) { $response = array('code' => 31, 'errorMessage' => 'duoshuo plugin hasn\'t been closed'); echo json_encode($response); exit; } } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $server = new Duoshuo_LocalServer($plugin); $input = $_POST; if (get_magic_quotes_gpc()) { foreach ($input as $key => $value) { $input[$key] = stripslashes($value); } } $server->dispatch($input); } } catch (Exception $e) { Duoshuo_LocalServer::sendException($e); exit; } }