Example #1
0
function loadUrlsFromDB($crawlid, $label, $numUrls, $bOther = false)
{
    global $gUrlsTable;
    $query = "select urlOrig, urlFixed, rank from {$gUrlsTable} where (rank <= {$numUrls}" . ($bOther ? " OR other=true" : "") . ")" . " and optout=false order by rank asc;";
    $result = doQuery($query);
    while ($row = mysql_fetch_assoc($result)) {
        $urlOrig = $row['urlOrig'];
        $urlFixed = $row['urlFixed'];
        loadUrl($crawlid, $label, $urlFixed ? $urlFixed : $urlOrig, $row['rank']);
    }
}
Example #2
0
        # Get API key from : http://code.google.com/apis/console/
        # Step-by-step tutorial : http://ngiriraj.com/work/google-connect-by-using-oauth-in-php/
        $apiKey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx';
        # Post Data
        $postData = array('longUrl' => $longUrl, 'key' => $apiKey);
        $shortUrlInfo = loadUrl('https://www.googleapis.com/urlshortener/v1/url', 'POST', $postData);
        # Get Short URL
        $shortUrl = $shortUrlInfo['id'];
    } else {
        # Default short URL
        $shortUrl = "http://goo.gl/Fgdzr";
    }
}
# Short URL Analytics
$analyticsUrl = "https://www.googleapis.com/urlshortener/v1/url?shortUrl=" . $shortUrl . "&projection=FULL";
$analyticsUrlInfo = loadUrl($analyticsUrl, 'GET', '', 0);
# Get the values
$longUrl = $analyticsUrlInfo['longUrl'];
# Default Period is "allTime"
$period = $_GET['period'] ? $_GET['period'] : "allTime";
$traffic = $analyticsUrlInfo['analytics'][$period];
# Clicks count
$clicks = $traffic['shortUrlClicks'];
# Get Referrers metrics and build the data
$referrers = $traffic['referrers'];
$ref_draw = "['Referrers', 'Count'],";
for ($i = 0; $i < sizeOf($referrers); $i++) {
    $count = $referrers[$i]['count'];
    $id = $referrers[$i]['id'];
    $ref_draw .= " ['" . $id . "'," . $count . "],";
}
Example #3
0
 function mcu($isbn)
 {
     $error = '0';
     $host = 'http://www.mcu.es';
     $url1 = $host . '/webISBN/tituloSimpleFilter.do?cache=init&prev_layout=busquedaisbn&layout=busquedaisbn&language=es';
     $postData = 'params.forzaQuery=N&params.cdispo=A&params.cisbnExt=' . $isbn . '&params.liConceptosExt[0].texto&params.orderByFormdId=1&language=es&prev_layout=busquedaisbn&layout=busquedaisbn&action=Buscar';
     $html = loadUrl($url1, array('method' => 'get', 'session' => true, 'session_close' => false));
     $html2 = str_get_html($html);
     $action = $html2->getElementById('libroBusquedaSimpleForm')->action;
     $url2 = $host . $action;
     $html = loadUrl($url2, array('method' => 'post', 'session' => true, 'session_close' => false, 'post_data' => $postData, 'referer' => $url1));
     $html2 = str_get_html($html);
     if (gettype($html2->getElementById('aviso')) === 'object') {
         return array('Error' => 'Sin datos');
     }
     $enlace = $html2->find('div.isbnResDescripcion span strong a', 0)->href;
     $editorial = $html2->find('div.isbnResDescripcion span a', 1)->href;
     $url3 = str_replace('&amp;', '&', $host . $enlace);
     $html = loadUrl($url3, array('method' => 'get', 'session' => true, 'referer' => $url2));
     $html3 = str_get_html($html);
     $tabla = $html3->find('div.fichaISBN table tbody', 0);
     $res = array();
     foreach ($tabla->find('tr') as $row) {
         $leyenda = trimutf8($row->find('th', 0)->plaintext);
         $conten = $row->find('td', 0);
         switch ($leyenda) {
             case 'Materia/s:':
             case 'Autor/es:':
                 $aumat = array();
                 foreach ($conten->find('span') as $cont) {
                     $aumat[] = trimutf8($cont->plaintext);
                 }
                 $contenido = $aumat;
                 break;
             case 'Colección:':
             case 'Lengua de publicación:':
                 $contenido = trimutf8($conten->find('span', 0)->plaintext);
                 break;
             case 'Publicación:':
                 $contenido = trimutf8($conten->find('span a', 0)->plaintext);
                 break;
             default:
                 $contenido = trimutf8($row->find('td', 0)->plaintext);
                 break;
         }
         $res[$leyenda] = $contenido;
     }
     //Conseguir la ciudad de la editorial.
     $urlEditorial = str_replace('&amp;', '&', $host . $editorial);
     $html = loadUrl($urlEditorial, array('method' => 'get', 'session' => true, 'session_close' => false, 'referer' => $url2));
     $html4 = str_get_html($html);
     $tabla2 = $html4->find('div.fichaISBN table tbody', 0);
     foreach ($tabla2->find('tr') as $row) {
         $leyenda = trimutf8($row->find('th', 0)->plaintext);
         if ($leyenda === 'Provincia:') {
             $conten = trimutf8($row->find('td', 0)->plaintext);
             $res[$leyenda] = $conten;
         }
     }
     //Correcciones en la presentación de los datos
     if (isset($res['Edición:'])) {
         $tmp = substr($res['Edición:'], 0, 1);
         //cogemos sólo el número de la Edición
         $res['Edición:'] = $tmp;
         if (isset($res['Fecha Edición:'])) {
             $tmp = explode('/', $res['Fecha Edición:']);
             //cogemos sólo el Año
             $res['Fecha Edición:'] = $tmp[1];
         } elseif (isset($res['Fecha Impresión:'])) {
             $tmp = explode('/', $res['Fecha Impresión:']);
             $res['Fecha Edición:'] = $tmp[1];
         } else {
             $error = 'Faltan datos';
         }
     } else {
         $error = 'Faltan datos';
     }
     $tmparr = array();
     $regular = array('\\[.*\\]', '\\(.*\\)');
     //quitamos los [] y ()
     if (isset($res['Autor/es:'])) {
         foreach ($res['Autor/es:'] as $autor) {
             if (!strstr($autor, 'tr.') && !strstr($autor, 'coord.') && !strstr($autor, 'dir.') && !strstr($autor, 'comp.') && !strstr($autor, 'lit.') && !strstr($autor, 'il.')) {
                 //sino es traductor ni coordinador ni director lo aceptamos
                 foreach ($regular as $reg) {
                     $autor = ereg_replace($reg, '', $autor);
                 }
                 // Si son varios autores.
                 if (strstr($autor, '...')) {
                     $autor = 'Varios';
                 }
                 $tmparr[] = trim($autor);
                 //trimutf8($autor)
             }
         }
         $res['Autor/es:'] = $tmparr;
     } else {
         $error = 'Faltan datos';
     }
     $res['Error'] = $error;
     return $res;
 }