Exemple #1
0
 function createLake($title, $description, $fields, $related, $media, $fb_share)
 {
     $relate =& JModel::getInstance('relate', 'RelateModel');
     // com_content:
     $article =& JTable::getInstance('content');
     $filter = new JFilterInput(array(), array(), 1, 1);
     $article->title = trim($title);
     $article->alias = JFilterOutput::stringURLSafe($article->title);
     $article->introtext = $filter->clean($description);
     $article->fulltext = '';
     $article->state = 1;
     // published
     $article->sectionid = 1;
     // section 1 -> Fiskeplasser
     $article->catid = 1;
     // category 1 -> Vann
     $article->created = gmdate('Y-m-d H:i:s');
     $article->created_by = 103;
     // userid 103 = HOOKED
     $article->publish_up = $article->created;
     if (!$article->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $article_id = $article->_db->insertId();
     $article->id = $article_id;
     // jreviews_content:
     // contentid, email, jr_{...}
     $fields['contentid'] = $article_id;
     $fields['email'] = '*****@*****.**';
     // run geocoder on lat/lng, get jr_state & jr_zip
     $geodata = reverse_geocode($fields['jr_lat'], $fields['jr_long']);
     if ($geodata && $geodata != -1) {
         if ($geodata['state'] != '') {
             $geodata['state'] = '*' . str_replace(' ', '-', strtolower($geodata['state'])) . '*';
         }
         $fields['jr_state'] = $geodata['state'];
         $fields['jr_zip'] = $geodata['zip'];
     }
     $columns = implode(",", array_keys($fields));
     $values = implode("','", array_values($fields));
     $sql = "INSERT INTO `#__jreviews_content` ({$columns}) VALUES ('{$values}')";
     $this->_db->setQuery($sql);
     if (!$this->_db->query()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     $relate->add_listings($article_id, $related, false);
     $this->_streamAddLake($article);
     if (isset($media['photos'])) {
         $thumbs = str_replace(JURI::base(), '', $media['photos']);
         $sql = "SELECT id FROM #__community_photos WHERE thumbnail IN ('" . implode("','", $thumbs) . "')";
         $this->_db->setQuery($sql);
         $photo_ids = $this->_db->loadResultArray();
         $relate->add_photos($article_id, $photo_ids, false);
         if (isset($media['descriptions'])) {
             foreach ($media['descriptions'] as $thumb => $desc) {
                 $thumb = str_replace(JURI::base(), '', $thumb);
                 $sql = "UPDATE #__community_photos SET caption = '{$desc}' WHERE thumbnail = '{$thumb}'";
                 $this->_db->setQuery($sql);
                 $this->_db->query();
             }
         }
     }
     $article_link = ContentHelperRoute::getArticleRoute($article_id, $article->catid, $article->sectionid);
     $article->link = $article_link;
     $thumb = '';
     if (isset($media['photos']) && count($media['photos'])) {
         $thumb = $media['photos'][0];
         $article->thumbnail = $thumb;
     }
     $response = array();
     $response[] = array('id' => $article_id, 'title' => $article->title, 'link' => $article_link, 'thumbnail' => $thumb);
     if ($fb_share) {
         facebook_share($article, JText::sprintf('FACEBOOK LAKE MESSAGE', $title));
     }
     return $response;
 }
Exemple #2
0
             if ($state != '' && $country != '') {
                 $address = $state . ', ' . $country;
             } else {
                 if ($country != '') {
                     $address = $country;
                 }
             }
         }
     }
     // return $address;
     //return "$country/$state/$city/$lat/$lan";
     return "{$lat}/{$lan}";
 }
 /* Usage: In my case, I needed to return the State and Country of an address */
 //$myLocation = reverse_geocode("19-29 Martin Pl, Sydney");
 $myLocation = reverse_geocode("Maharashtra");
 //echo $myLocation."</ br>";
 $explode = explode('/', $myLocation);
 $explode[0] . '-' . $explode[1];
 if ($_POST['keyword'] != "" && $_POST['twitter_user'] == "1") {
     // User Search API
     if ($_POST['order_by'] == "popular") {
         $sort = "popular";
         $tw = "best";
     } elseif ($_POST['order_by'] == "recent") {
         $sort = "recent";
         $tw = "recent";
     } else {
         $sort = "recent";
         $tw = "recent";
     }
Exemple #3
0
define('_JEXEC', 1);
define('JPATH_BASE', dirname(__FILE__));
define('DS', DIRECTORY_SEPARATOR);
require_once JPATH_BASE . DS . 'includes' . DS . 'defines.php';
require_once JPATH_BASE . DS . 'includes' . DS . 'framework.php';
$mainframe &= JFactory::getApplication('site');
$req_limit = 10000;
// get listings which don't currently have a state/zip
$db =& JFactory::getDBO();
$sql = "SELECT jr.*, c.title FROM #__jreviews_content jr " . "LEFT JOIN #__content c ON c.id = jr.contentid " . "WHERE (jr_zip = '' AND jr_state = '') AND " . "(jr_lat IS NOT NULL AND jr_long IS NOT NULL) LIMIT {$req_limit}";
$db->setQuery($sql);
$listings = $db->loadObjectList();
$count = 0;
// reverse geocode up to limit
foreach ($listings as $listing) {
    $geodata = reverse_geocode($listing->jr_lat, $listing->jr_long);
    // format state name like a jreviews field option
    if ($geodata['state'] != '') {
        $geodata['state'] = '*' . str_replace(' ', '-', strtolower($geodata['state'])) . '*';
    }
    // store results back in db
    $sql = "UPDATE #__jreviews_content SET jr_zip = '" . $geodata['zip'] . "', jr_state = '" . $geodata['state'] . "' " . "WHERE contentid = " . $listing->contentid;
    $db->setQuery($sql);
    $db->query();
    echo $listing->title . " (" . $listing->jr_lat . ", " . $listing->jr_long . "): " . $geodata['state'] . ", " . $geodata['zip'] . "\n";
    $count++;
}
echo "{$count} rows updated\n";
function reverse_geocode($jr_lat, $jr_long)
{
    $geocode_url = 'http://where.yahooapis.com/geocode?q=%s,%s&gflags=R&flags=J';