Ejemplo n.º 1
0
 function geocode_from_latlng($lat, $lng)
 {
     //**********************************************************************
     //unify format
     $lat = number_format($lat, 6, '.', '');
     $lng = number_format($lng, 6, '.', '');
     //Check if address is in geocode table
     $latlng = $lat . '.' . $lng;
     $dotaz = "SELECT * FROM handol5_data.s_geocode WHERE latlng='{$latlng}' LIMIT 1";
     $result = @mysqli_query($dotaz);
     if (!$result) {
         die('Invalid query: ' . mysqli_error($dotaz) . '; error code: ' . mysqli_errno($dotaz));
     }
     $num_rows = mysqli_num_rows($result);
     if ($num_rows == 1) {
         while ($zaznam = mysqli_fetch_array($result)) {
             print_r($zaznam);
             return $zaznam;
         }
     } else {
         // single curl request
         $sc = new SingleCurl();
         $result = $sc->request("http://where.yahooapis.com/geocode?location=" . $lat . "," . $lng . "&gflags=R&appid=NhjeGJ72", 'x');
         //**********************************************************************
         echo "<br />";
         print_r($result['INF']);
         echo "<hr />";
         $patterns = array('error' => '//resultset/error', 'errormessage' => '//resultset/errormessage', 'found' => '//resultset/found', 'quality' => '//resultset/result/quality', 'latitude' => '//resultset/result/latitude', 'longitude' => '//resultset/result/longitude', 'line1' => '//resultset/result/line1', 'line2' => '//resultset/result/line2', 'line3' => '//resultset/result/line3', 'line4' => '//resultset/result/line4', 'house' => '//resultset/result/house', 'street' => '//resultset/result/street', 'postal' => '//resultset/result/postal', 'city' => '//resultset/result/city', 'country' => '//resultset/result/country');
         //get all relevent information from XML
         $address = new xpath();
         $address_array = $address->getVariousItems($result['EXE'], $patterns);
         //show error message if error
         if ($address_array['error'] == '1') {
             echo 'error yahoo geocoding - ' . $address_array['errormessage'];
         } else {
             //remove elements which won't be put into database
             unset($address_array['error']);
             unset($address_array['errormessage']);
             unset($address_array['found']);
             //create index value
             $latlng = $address_array['latitude'] . '.' . $address_array['longitude'];
             $address_array['latlng'] = $latlng;
             //write to database
             $query = new mysqli_queries();
             $query->insert('handol5_data.s_geocode', $address_array);
         }
         echo "<hr />";
         //**********************************************************************
         //Check if address is in geocode table
         $latlng = $lat . '.' . $lng;
         $dotaz = "SELECT * FROM handol5_data.s_geocode WHERE latlng='{$latlng}' LIMIT 1";
         $result = @mysqli_query($dotaz);
         if (!$result) {
             die('Invalid query: ' . mysqli_error($dotaz) . '; error code: ' . mysqli_errno($dotaz));
         }
         $num_rows = mysqli_num_rows($result);
         if ($num_rows == 1) {
             while ($zaznam = mysqli_fetch_array($result)) {
                 print_r($zaznam);
                 return $zaznam;
             }
         } else {
             echo "<span style='color:red;'>error - check geocode class, function geocode_from_latlng()</span><br />";
         }
     }
 }
/**
 * Switches any encode backup links to 'proper' form.
 * Will search for user info and add as needed.
 * @param string $content
 * @param xpath $xpath
 */
function oublog_decode_perbloglinks($content, $xpath, $userposts = null, $olduserid = null)
{
    global $CFG, $SOURCESERVER;
    $result = $content;
    if (strpos($content, '$@OUBLOGVIEWUSER') !== false) {
        // Process blog links.
        $searchstring = '/\\$@(OUBLOGVIEWUSER)\\*([0-9]+)@\\$/';
        preg_match_all($searchstring, $result, $foundset);
        if ($foundset[0]) {
            // Iterate over foundset[2]. They are the old_ids.
            foreach ($foundset[2] as $old_id) {
                // We get the needed variables here (stored in users in xml)
                $users = $xpath->query("/DATA/USERS/USER[@id={$old_id}]");
                $newid = false;
                if ($users->length != 0) {
                    $user = childnodes_to_object($users->item(0));
                    if (!empty($user->username)) {
                        $newid = urlencode($user->username);
                    }
                }
                // Update the link to its new location.
                if (!empty($newid)) {
                    // Now replace it.
                    $result = str_replace("\$@OUBLOGVIEWUSER*{$old_id}@\$", $CFG->wwwroot . '/mod/oublog/view.php?u=' . $newid, $result);
                } else {
                    // Can't find, leave it as original.
                    $result = str_replace("\$@OUBLOGVIEWUSER*{$old_id}@\$", $SOURCESERVER . '/mod/oublog/view.php?user='******'$@OUBLOGVIEWPOST') !== false) {
        // Porcess post links.
        $searchstring = '/\\$@(OUBLOGVIEWPOST)\\*([0-9]+)@\\$/';
        preg_match_all($searchstring, $result, $foundset);
        if ($foundset[0]) {
            // Iterate over foundset[2]. They are the old_ids.
            foreach ($foundset[2] as $old_id) {
                $newusername = false;
                $newposttime = false;
                //See if this user made the post refered to, if so use their details.
                if ($userposts && $olduserid) {
                    foreach ($userposts as $post) {
                        if (isset($post->id) && $post->id == $old_id && !empty($post->timeposted)) {
                            $newposttime = $post->timeposted;
                            // We get the needed variables here (stored in users in xml).
                            $users = $xpath->query("/DATA/USERS/USER[@id={$olduserid}]");
                            if ($users->length != 0) {
                                $user = childnodes_to_object($users->item(0));
                                if (!empty($user->username)) {
                                    $newusername = urlencode($user->username);
                                }
                            }
                            break;
                        }
                    }
                }
                // Update the link to its new location.
                if (!empty($newusername) && !empty($newposttime)) {
                    // Now replace it.
                    $posturl = new moodle_url('/mod/oublog/viewpost.php', array('u' => $newusername, 'time' => $newposttime, 'post' => 0));
                    $result = str_replace("\$@OUBLOGVIEWPOST*{$old_id}@\$", $posturl->out(false), $result);
                } else {
                    // Can't find, leave it as original.
                    $result = str_replace("\$@OUBLOGVIEWPOST*{$old_id}@\$", $SOURCESERVER . '/mod/oublog/viewpost.php?post=' . $old_id, $result);
                }
            }
        }
    }
    return $result;
}