/**
  * Analytics data management
  * 
  * @return void
  */
 public function analytics()
 {
     $this->load->library('Whois');
     $this->load->library('Googlepr');
     $this->googlepr->cacheDir = TEMPPATH . 'cache';
     $this->load->helper('seo_analytics', 'seo_advanced');
     $url = Seo_analytics_helper::prepare_url($this->input->post('url') ? $this->input->post('url') : base_url());
     if (!$url) {
         $this->system_messages->add_message('error', l('error_incorrect_url', 'seo_advanced'));
     }
     $whois = $this->whois->Lookup($url);
     $domain = $this->pg_module->get_module_config('seo_advanced', 'admin_seo_settings');
     if (!empty($domain)) {
         $domain = unserialize($domain);
     }
     if ((!$domain || $this->input->post('btn_save')) && $url) {
         $domain = array();
         $domain['registered'] = 'yes' === $whois['regrinfo']['registered'] ? true : false;
         $domain['created'] = isset($whois['regrinfo']['domain']['created']) ? $whois['regrinfo']['domain']['created'] : false;
         $domain['created_timestamp'] = strtotime($domain['created']);
         if ($domain['created_timestamp']) {
             $domain['age']['y'] = (int) date('Y') - date('Y', $domain['created_timestamp']);
             $domain['age']['m'] = (int) date('n') - date('n', $domain['created_timestamp']);
             $domain['age']['d'] = (int) date('j') - date('j', $domain['created_timestamp']);
             if ($domain['age']['m'] < 0) {
                 $domain['age']['y']--;
                 $domain['age']['m'] = 12 + $domain['age']['m'];
             }
         }
         // google page rank
         $domain['page_rank'] = $domain['registered'] ? $this->googlepr->get_pr($url) : 0;
         // yandex tic
         $domain['tic'] = $domain['registered'] ? Seo_analytics_helper::yandex_TIC($url) : 0;
         // alexa backlinks
         $domain['alexa_backlinks'] = Seo_analytics_helper::backlinks($url, 'alexa');
         // alexa traffic rank
         $domain['alexa_rank'] = Seo_analytics_helper::alexa_rank($url);
         // google backlinks
         $domain['google_backlinks'] = Seo_analytics_helper::backlinks($url, 'google');
         // yahoo backlinks
         $domain['yahoo_backlinks'] = Seo_analytics_helper::backlinks($url, 'yahoo');
         // technorati rank
         $domain['technorati_rank'] = Seo_analytics_helper::get_technorati_rank($url);
         // technorati authority
         $domain['technoraty_authority'] = Seo_analytics_helper::get_technorati_authority($url);
         // dmoz listed
         $domain['dmoz_listed'] = Seo_analytics_helper::dmoz_listed($url);
         // google directory listed
         //$domain['google_listed'] = Seo_analytics_helper::google_listed($url);
         // google indexed
         $domain['google_indexed'] = Seo_analytics_helper::google_indexed($url);
         // yahoo indexed
         $domain['yahoo_indexed'] = Seo_analytics_helper::yahoo_indexed($url);
         // yandex indexed
         $domain['yandex_indexed'] = Seo_analytics_helper::yandex_indexed($url);
         if ($url == Seo_analytics_helper::prepare_url(base_url())) {
             $this->pg_module->set_module_config('seo_advanced', 'admin_seo_settings', serialize($domain));
         }
     }
     $check_links = array();
     $check_links['alexa_backlinks'] = 'http://www.alexa.com/site/linksin/' . urlencode($url);
     $check_links['alexa_rank'] = 'http://www.alexa.com/siteinfo/' . urlencode($url);
     $check_links['yahoo_indexed'] = 'http://search.yahoo.com/search?p=site%3A' . urlencode($url);
     $check_links['google_indexed'] = 'http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=site%3A' . urlencode($url) . '&filter=0';
     $check_links['google_listed'] = 'http://www.google.com/search?q=' . urlencode($url) . '&hl=en&cat=gwd%2FTop';
     $check_links['dmoz_listed'] = 'http://search.dmoz.org/cgi-bin/search?search=u:' . urlencode($url);
     $check_links['technoraty_authority'] = 'http://technorati.com/blogs/' . urlencode($url);
     $check_links['technorati_rank'] = 'http://technorati.com/blogs/' . urlencode($url);
     $check_links['yahoo_backlinks'] = 'http://search.yahoo.com/search?p=%22http%3A%2F%2F' . urlencode($url) . '%22+%22http%3A%2F%2Fwww.' . urlencode($url) . '%22+-site%3A' . urlencode($url) . '+-site%3Awww.' . urlencode($url);
     $check_links['google_backlinks'] = 'http://www.google.com/search?hl=en&lr=&ie=UTF-8&q=link%3A' . urlencode($url) . '&filter=0';
     $check_links['yandex_indexed'] = 'http://webmaster.yandex.ru/check.xml?hostname=' . urlencode($url) . '&sk=uf58227b4419a945bf6a295c8138b7ed5';
     $this->template_lite->assign('url', $url);
     $this->template_lite->assign('domain', $domain);
     $this->template_lite->assign('check_links', $check_links);
     $this->system_messages->set_data('back_link', site_url() . 'admin/seo_advanced');
     $this->system_messages->set_data('header', l('admin_header_analytics', 'seo_advanced'));
     $this->template_lite->view('list_analytics');
 }
 /**
  * Return yandex TIC
  * @param mixed $uri
  * @access public
  * @return str
  */
 function yandex_TIC($uri)
 {
     $url = 'http://bar-navig.yandex.ru/u?ver=2&show=32&url=http%3A%2F%2F' . $uri;
     $v = Seo_analytics_helper::file_get_contents_curl($url);
     if (preg_match('/value=\\"(.\\d*)\\"/si', $v, $r)) {
         return $r[1];
     }
     return '';
 }