Exemplo n.º 1
0
function launchFacebook($terminoBuscar)
{
    $app_access_token = genToken();
    $resultFacebook = app_request("https://graph.facebook.com/v2.5/search?q=" . $terminoBuscar . "&type=page&limit=10&fields=id,name,picture.type(normal),likes&" . $app_access_token);
    //printVar($resultFacebook,$_SERVER['SERVER_NAME'].'/publication/search/results/resultFacebook.json');
    //printVar($_SERVER["DOCUMENT_ROOT"]);
    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/publication/search/results/resultFacebook.json', 'w');
    $qpaso = fwrite($fp, json_encode($resultFacebook));
    fclose($fp);
    //printVar($qpaso,'que paso');
    $obj = DB_DataObject::Factory('MpBrand');
    $obj->name = $terminoBuscar;
    $find = $obj->find();
    if ($find > 0) {
        // echo 'entra al if';
        while ($obj->fetch()) {
            //DB_DataObject::debugLevel(1);
            $obj->picture = $resultFacebook['data'][0]['picture']['data']['url'];
            $obj->update();
        }
    } else {
    }
    $obj->free();
    //echo json_encode('');
}
Exemplo n.º 2
0
include 'db/requires.php';
if (isset($_POST['red']) && isset($_POST['url']) && !empty($_POST['url'])) {
    $red = $_POST['red'];
    $url = $_POST['url'];
    $find = '0';
    //  printVar($url.'Url de post');
    //printVar($red,'flag de red 0->f, 1->t, 2->y');
    switch ($red) {
        case '0':
            $dividir = explode('/?', $url);
            $dividir = is_array($dividir) ? $dividir : explode('?', $url);
            $url = is_array($dividir) ? $dividir[0] : $dividir;
            $dividir = is_array($dividir) ? explode('www.facebook.com/', $dividir[0]) : explode('www.facebook.com/', $dividir);
            $terminoBuscar = $dividir['1'];
            $app_access_token = genToken();
            $resultFacebook = app_request("https://graph.facebook.com/v2.5/search?q=" . $terminoBuscar . "&type=page&limit=6&fields=id,name,link,picture.type(normal),likes&" . $app_access_token);
            for ($i = 0; $i < count($resultFacebook['data']); $i++) {
                //   printVar($url,'url recortada');
                //  printVar($resultFacebook['data'][$i]['link']);
                if ($resultFacebook['data'][$i]['link'] == $url || $resultFacebook['data'][$i]['link'] == $url . '/') {
                    $fp = fopen($_SERVER["DOCUMENT_ROOT"] . '/publication/search/results/resultFacebook.json', 'w');
                    fwrite($fp, json_encode($resultFacebook));
                    fclose($fp);
                    $find = '1';
                }
            }
            if ($find != '0') {
                echo json_encode('1');
            } else {
                echo json_encode('0');
            }