$posjete = $pik_db->artikli_posjete->find(array('koga' => '1984619', 'ref' => array('$ne' => ''), 'ko' => array('$ne' => '66')), array('ref')); foreach($posjete as $ref) { $staba = strtolower(trim($ref['ref'])); $url = parse_url($staba); if(!empty($url['host']) and !empty($url['path'])) { $ex = explode('/', $url['path']); if(!empty($ex[1]) and ($ex[1] == 'profil') and !empty($ex[2])) { $staba = 'http://www.pik.ba/profil/'.$ex[2]; } if(!empty($ex[1]) and ($ex[1] == 'artikal' and $ex[2] == '1984639')) continue; // necemo linkove na artikal sa istog tog artikla } if((!empty($url['host']) and ($url['host'] == 'www.facebook.com' or $url['host'] == 'm.facebook.com' or $url['host'] == '0.facebook.com' or $url['host'] == 'facebook.com'))) $staba = 'http://www.facebook.com'; if((!empty($url['host']) and ($url['host'] == 'www.twitter.com' or $url['host'] == 'twitter.com' or $url['host'] == 't.co'))) $staba = 'http://www.twitter.com'; if($staba == '') continue; // direktne posjete bez ref if(empty($final["$staba"])) $final["$staba"] = 1; else $final["$staba"] = $final["$staba"]+1; unset($staba, $ex, $url); } arsort($final); // sortiraj po broju posjeta $final = array_slice($final, 0, 30);