function refreshCompetitor($id = null)
 {
     $db =& JFactory::getDBO();
     $app =& JFactory::getApplication();
     $rsseoConfig = $app->getuserState('rsseoConfig');
     $cid = is_null($id) ? JRequest::getInt('cid', 0) : $id;
     $db->setQuery("SELECT * FROM #__rsseo_competitors WHERE IdCompetitor= '" . $cid . "'");
     $Competitor = $db->loadObject();
     if (isset($Competitor->Competitor) && !is_null($Competitor->Competitor)) {
         $array['page_rank'] = rsseoHelper::getPageRank($Competitor->Competitor);
         $array['alexa_rank'] = rsseoHelper::getAlexaRank($Competitor->Competitor);
         $array['tehnorati_rank'] = rsseoHelper::getTehnoratiRank($Competitor->Competitor);
         $array['google_pages'] = rsseoHelper::getGooglePages($Competitor->Competitor);
         $array['yahoo_pages'] = rsseoHelper::getYahooPages($Competitor->Competitor);
         $array['bing_pages'] = rsseoHelper::getBingPages($Competitor->Competitor);
         $array['google_backlinks'] = rsseoHelper::getGoogleBacklinks($Competitor->Competitor);
         $array['yahoo_backlinks'] = rsseoHelper::getYahooBacklinks($Competitor->Competitor);
         $array['bing_backlinks'] = rsseoHelper::getBingBacklinks($Competitor->Competitor);
         $dmoz = rsseoHelper::getDmoz($Competitor->Competitor);
         $array['date_refreshed'] = time();
         $query = "INSERT INTO #__rsseo_competitors_history SET " . "IdCompetitor='" . $cid . "', " . "PageRank='" . $array['page_rank'] . "', " . "AlexaRank='" . $array['alexa_rank'] . "', " . "TehnoratiRank='" . $array['tehnorati_rank'] . "', " . "GoogleBacklinks='" . $array['google_backlinks'] . "', " . "YahooBacklinks='" . $array['yahoo_backlinks'] . "', " . "BingBacklinks='" . $array['bing_backlinks'] . "', " . "GooglePages='" . $array['google_pages'] . "', " . "YahooPages='" . $array['yahoo_pages'] . "', " . "BingPages='" . $array['bing_pages'] . "', " . "DateRefreshed='" . $array['date_refreshed'] . "'";
         //save to keyword details
         $db->setQuery($query);
         $db->query();
         $query = "UPDATE #__rsseo_competitors SET " . "LastPageRank='" . $array['page_rank'] . "', " . "LastAlexaRank='" . $array['alexa_rank'] . "', " . "LastTehnoratiRank='" . $array['tehnorati_rank'] . "', " . "LastGoogleBacklinks='" . $array['google_backlinks'] . "', " . "LastYahooBacklinks='" . $array['yahoo_backlinks'] . "', " . "LastBingBacklinks='" . $array['bing_backlinks'] . "', " . "LastGooglePages='" . $array['google_pages'] . "', " . "LastYahooPages='" . $array['yahoo_pages'] . "', " . "LastBingPages='" . $array['bing_pages'] . "', " . "Dmoz='" . $dmoz . "', " . "LastDateRefreshed='" . $array['date_refreshed'] . "' " . "WHERE IdCompetitor = '" . $cid . "'";
         //update last keyword
         $db->setQuery($query);
         $db->query();
         $array['date_refreshed'] = date($rsseoConfig['global.dateformat'], $array['date_refreshed']);
         $db->setQuery("SELECT * FROM #__rsseo_competitors_history WHERE IdCompetitor = " . $cid . " ORDER BY DateRefreshed DESC LIMIT 2 ");
         $history = $db->loadObjectList();
         if (isset($history[1])) {
             $compare = $history[0];
         }
         //google page rank
         if ($compare->PageRank > $Competitor->LastPageRank) {
             $color1 = 'colorgreen';
         }
         if ($compare->PageRank < $Competitor->LastPageRank) {
             $color1 = 'colorred';
         }
         if ($compare->PageRank == $Competitor->LastPageRank) {
             $color1 = 'colornone';
         }
         //alexa page rank
         if ($compare->AlexaRank > $Competitor->LastAlexaRank) {
             $color2 = 'colorred';
         }
         if ($compare->AlexaRank < $Competitor->LastAlexaRank) {
             $color2 = 'colorgreen';
         }
         if ($compare->AlexaRank == $Competitor->LastAlexaRank) {
             $color2 = 'colornone';
         }
         //google pages
         if ($compare->GooglePages > $Competitor->LastGooglePages) {
             $color3 = 'colorgreen';
         }
         if ($compare->GooglePages < $Competitor->LastGooglePages) {
             $color3 = 'colorred';
         }
         if ($compare->GooglePages == $Competitor->LastGooglePages) {
             $color3 = 'colornone';
         }
         //yahoo pages
         if ($compare->YahooPages > $Competitor->LastYahooPages) {
             $color4 = 'colorgreen';
         }
         if ($compare->YahooPages < $Competitor->LastYahooPages) {
             $color4 = 'colorred';
         }
         if ($compare->YahooPages == $Competitor->LastYahooPages) {
             $color4 = 'colornone';
         }
         //bing pages
         if ($compare->BingPages > $Competitor->LastBingPages) {
             $color5 = 'colorgreen';
         }
         if ($compare->BingPages < $Competitor->LastBingPages) {
             $color5 = 'colorred';
         }
         if ($compare->BingPages == $Competitor->LastBingPages) {
             $color5 = 'colornone';
         }
         //google backlinks
         if ($compare->GoogleBacklinks > $Competitor->LastGoogleBacklinks) {
             $color6 = 'colorgreen';
         }
         if ($compare->GoogleBacklinks < $Competitor->LastGoogleBacklinks) {
             $color6 = 'colorred';
         }
         if ($compare->GoogleBacklinks == $Competitor->LastGoogleBacklinks) {
             $color6 = 'colornone';
         }
         //yahoo backlinks
         if ($compare->YahooBacklinks > $Competitor->LastYahooBacklinks) {
             $color7 = 'colorgreen';
         }
         if ($compare->YahooBacklinks < $Competitor->LastYahooBacklinks) {
             $color7 = 'colorred';
         }
         if ($compare->YahooBacklinks == $Competitor->LastYahooBacklinks) {
             $color7 = 'colornone';
         }
         //bing backlinks
         if ($compare->BingBacklinks > $Competitor->LastBingBacklinks) {
             $color8 = 'colorgreen';
         }
         if ($compare->BingBacklinks < $Competitor->LastBingBacklinks) {
             $color8 = 'colorred';
         }
         if ($compare->BingBacklinks == $Competitor->LastBingBacklinks) {
             $color8 = 'colornone';
         }
         //tehnorati rank
         if ($compare->TehnoratiRank > $Competitor->LastTehnoratiRank) {
             $color9 = 'colorgreen';
         }
         if ($compare->TehnoratiRank < $Competitor->LastTehnoratiRank) {
             $color9 = 'colorred';
         }
         if ($compare->TehnoratiRank == $Competitor->LastTehnoratiRank) {
             $color9 = 'colornone';
         }
         $array['color1'] = $color1;
         $array['color2'] = $color2;
         $array['color3'] = $color3;
         $array['color4'] = $color4;
         $array['color5'] = $color5;
         $array['color6'] = $color6;
         $array['color7'] = $color7;
         $array['color8'] = $color8;
         $array['color9'] = $color9;
         $array['dmoz'] = $dmoz == 0 ? JText::_('RSSEO_NO') : JText::_('RSSEO_YES');
         echo implode("\n", $array);
     }
     if ($id == null) {
         exit;
     }
 }