dry0106 2013-11-01 11:58
浏览 404

如何将SEOStats与Codeigniter集成?

Hello I want to integrate the SEOStats Class with a project in codeigniter , is anyone provide me solution ?

I have tried to make the SEOstats class as a helper and load the helper in the specific controler , but a blank page is showing , I also try to include it via view but the same blank page i am seeing ,

I have included this code in my view file , the SEOstats directory also in the same views directory .

    <?php
    require_once  'SEOstats/bootstrap.php';

  use \SEOstats\Services as SEOstats;

  try {
    $url = 'http://www.google.com/';

 // Create a new SEOstats instance.
 $seostats = new \SEOstats\SEOstats;

  // Bind the URL to the current SEOstats instance.
  if ($seostats->setUrl($url)) {

   echo SEOstats\Alexa::getGlobalRank();
   echo SEOstats\Google::getPageRank();
 }
 }
 catch (SEOstatsException $e) {
 die($e->getMessage());
 }

i have also used it as library

<?php
 namespace SEOstats;

 use SEOstats\Common\SEOstatsException as E;
 use SEOstats\Config as Config;
 use SEOstats\Helper as Helper;
use SEOstats\Services as Service;



 class SEOstats
 {
   const BUILD_NO = Config\Package::VERSION_CODE;

protected static $_url,
                 $_host,
                 $_lastHtml,
                 $_lastLoadedUrl
                 = false;

public function __construct($url = false)
{
    if (false !== $url) {
        self::setUrl($url);
    }
}

public function Alexa()
{
    return new Service\Alexa;
}

public function Google()
{
    return new Service\Google;
}

public function OpenSiteExplorer()
{
    return new Service\OpenSiteExplorer;
}

public function SEMRush()
{
    return new Service\SemRush;
}

public function Sistrix()
{
    return new Service\Sistrix;
}

public function Social()
{
    return new Service\Social;
}

public static function getHost()
{
    return self::$_host;
}

public static function getLastLoadedHtml()
{
    return self::$_lastHtml;
}

public static function getLastLoadedUrl()
{
    return self::$_lastLoadedUrl;
}

/**
 * Ensure the URL is set, return default otherwise
 * @return string
 */
public static function getUrl($url = false)
{
    $url = false !== $url ? $url : self::$_url;
    return $url;
}

public function setUrl($url)
{
    if (false !== Helper\Url::isRfc($url)) {
        self::$_url  = $url;
        self::$_host = Helper\Url::parseHost($url);
    }
    else {
        throw new E('Invalid URL!');
        exit();
    }
    return true;
}

/**
 * @return DOMDocument
 */
protected static function _getDOMDocument($html) {
    $doc = new \DOMDocument;
    @$doc->loadHtml($html);
    return $doc;
}

/**
 * @return DOMXPath
 */
protected static function _getDOMXPath($doc) {
    $xpath = new \DOMXPath($doc);
    return $xpath;
}

/**
 * @return HTML string
 */
protected static function _getPage($url) {
    $url = self::getUrl($url);
    if (self::getLastLoadedUrl() == $url) {
        return self::getLastLoadedHtml();
    }

    $html = Helper\HttpRequest::sendRequest($url);
    if ($html) {
        self::$_lastLoadedUrl = $url;
        self::_setHtml($html);
        return $html;
    }
    else {
        self::noDataDefaultValue();
    }
}

protected static function _setHtml($str)
{
    self::$_lastHtml = $str;
}

protected static function noDataDefaultValue()
{
    return Config\DefaultSettings::DEFAULT_RETURN_NO_DATA;
}

  }

and loaded the library as

$this->load->library('SEOstats');
  • 写回答

2条回答 默认 最新

  • douxie3625 2014-05-30 18:48
    关注

    This is how I include SEOStats on my Codeigniter website

    class Cron extends Frontend_Controller
    {
    
        public function get_google_page_rank() {
            require_once (APPPATH . 'libraries/SEOstats/bootstrap.php');
            try {
                $url = 'http://www.google.com/';
    
                // Get the Google PageRank for the given URL.
                $pagerank = \SEOstats\Services\Google::getPageRank($url);
                echo "The current Google PageRank for {$url} is {$pagerank}." . PHP_EOL;
            }
            catch(\Exception $e) {
                echo 'Caught SEOstatsException: ' . $e->getMessage();
            }
        }
        public function get_alexa_page_rank() {
            require_once (APPPATH . 'libraries/SEOstats/bootstrap.php');
    
            //use \SEOstats\Services\Alexa as Alexa;
    
            try {
                $url = 'https://www.google.com/';
    
                // Create a new SEOstats instance.
                $seostats = new \SEOstats\SEOstats;
    
                // Bind the URL to the current SEOstats instance.
                if ($seostats->setUrl($url)) {
    
                    /**
                     *  Print HTML code for the 'daily traffic trend'-graph.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(1);
    
                    /**
                     *  Print HTML code for the 'daily pageviews (percent)'-graph.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(2);
    
                    /**
                     *  Print HTML code for the 'daily pageviews per user'-graph.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(3);
    
                    /**
                     *  Print HTML code for the 'time on site (in minutes)'-graph.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(4);
    
                    /**
                     *  Print HTML code for the 'bounce rate (percent)'-graph.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(5);
    
                    /**
                     *  Print HTML code for the 'search visits'-graph, using
                     *  specific graph dimensions of 320*240 px.
                     */
                    echo \SEOstats\Services\Alexa::getTrafficGraph(6, false, 320, 240);
                }
            }
            catch(\Exception $e) {
                echo 'Caught SEOstatsException: ' . $e->getMessage();
            }
        }
    }
    

    Hope this helps

    PS: Copy SEOstats folder in application/libraries folder

    评论

报告相同问题?

悬赏问题

  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)