Exemple #1
0
 /**
  * Get coords by user IP
  * @return type
  */
 public function ajaxGetCoordsByIp()
 {
     $objResponse = new JAXResponse();
     $config = CFactory::getConfig();
     $curl = new CCurl();
     /* Because this function is called by ajax. We can't detect real vistor IP in this function than we need to get it from session */
     $ip = JFactory::getSession()->get('jomsocial_userip');
     /**
      * We do request to 3rd service with our IP to get coords than return ajax to update current coords
      * We can use many method here to get fews of coords. Just update it into our javascript
      * @todo We can allow extend via addon files ?
      */
     /**
      * @url http://www.ipinfodb.com/ip_location_api.php
      */
     $ipinfodbAPIKey = $config->get('geolocation_ipinfodb_key', '40955706fc1ec858891c0a7e1c76672d02c766cf7cee9b3e3bf00bcb1575d252');
     $ipinfodbRequestUrl = 'http://api.ipinfodb.com/v3/ip-city/?key=' . $ipinfodbAPIKey . '&format=json';
     if ($ip) {
         $ipinfodbRequestUrl .= '&ip=' . $ip;
     }
     $response = $curl->post($ipinfodbRequestUrl);
     $body = $response->getBody();
     if ($body) {
         $body = json_decode($body);
         /* We'll response data as much as we have */
         if ($body->latitude != 0 && $body->longitude != 0) {
             $coords['coords'] = $body;
             $objResponse->addScriptCall('joms.location.updateCoords', $coords);
         }
     }
     return $objResponse->sendResponse();
 }
Exemple #2
0
 public static function fromContent($content)
 {
     $urls = self::fetchUrlsFromContent($content);
     /**
      * Crawle data
      * We only work with first url
      */
     if (count($urls) > 0) {
         $url = array_shift($urls);
         $curl = new CCurl();
         $header = $curl->getHeaderOnly($url);
         if (strpos($header['Content-Type'], ';') !== false) {
             $header = explode(';', $header['Content-Type']);
             $header = trim($header[0]);
         } else {
             $header = $header['Content-Type'];
         }
         switch ($header) {
             case 'text/html':
                 /* now we do curl again to get body */
                 /**
                  * @todo Somehow it's bug here that incorrect body content
                  */
                 //$curl->setCurl(CURLOPT_HEADER); /* ya don't need header again */
                 $response = $curl->get($url);
                 $body = $response->getBody();
                 /* get meta object */
                 $metasParser = new CParserMetas();
                 $metasParser->setContent($body);
                 $graphObject = $metasParser->extract();
                 /* Do image fetch into local and resize */
                 $images = $graphObject->get('image');
                 /**
                  * @todo allow config save dir
                  */
                 if (is_array($images)) {
                     $saveDir = JPATH_ROOT . '/images/community/activities';
                     /* Create save dir if not exists */
                     if (!JFolder::exists($saveDir)) {
                         JFolder::create($saveDir);
                     }
                     /* Do copy into local */
                     $localImages = array();
                     foreach ($images as $image) {
                         /* Hashing remote image url to use as fileName */
                         $localFileName = md5($image);
                         /* Get file extension */
                         $locaFileExt = JFile::getExt($image);
                         /* Generate local filename from hashed and extesion */
                         $localFile = $localFileName . '.' . $locaFileExt;
                         /* Local thumbnail filename by adding _thumb */
                         $localThumbFile = $localFileName . '_thumb.' . $locaFileExt;
                         /* Do save local */
                         copy($image, $saveDir . '/' . $localFile);
                         /* Get image file informantion */
                         $info = getimagesize($saveDir . '/' . $localFile);
                         /* Get image type than use it to createThumb */
                         $imgType = image_type_to_mime_type($info[2]);
                         /* Do make thumb */
                         CImageHelper::createThumb($saveDir . '/' . $localFile, $saveDir . '/' . $localThumbFile, $imgType);
                         $localImages[] = array('image' => $localFile, 'thumb' => $localThumbFile);
                     }
                     /* Save back */
                     $graphObject->set('localImages', $localImages);
                 }
                 return $graphObject;
                 break;
             default:
                 break;
         }
     }
 }