public function destroy() { Session::del('Twitter_Token'); Session::del('Twitter_TokenSecret'); Session::del('Twitter_State'); $this->oauth = new OAuth(self::CONFIG_KEY, self::CONFIG_SECRET); $this->state = self::STATE_NOTHING; $this->token = ''; $this->tokenSecret = ''; TwCensus::redirect('/'); }
protected function actionWebsite() { // Default action // $this->action = ''; $this->mappy = new Mappy(); $this->twitter = new Twitter(); if (Request::isPost()) { $saved = false; if (Request::hasPost('save') && $this->twitter->connected()) { $idCountry = Request::getPost('country', 0); $idArea = Request::getPost('area', 0); $idLocality = Request::getPost('locality', 0); if (!$idCountry) { $countryName = Request::getPost('country_name', ''); $countryISO = Request::getPost('country_iso', ''); $countryCode = self::encode($countryName); $country = Db::fetchRow("SELECT countries.id_country\n , countries.code\n , countries.name\n , countries.iso\n FROM twcensus_countries AS countries\n WHERE countries.code = '{$countryCode}'\n AND countries.iso = '{$countryISO}'"); if ($country) { $idCountry = $country['id_country']; } else { $idCountry = Db::insert('twcensus_countries', array('code' => $countryCode, 'name' => $countryName, 'iso' => $countryISO)); } } if (!$idArea) { $areaName = Request::getPost('area_name', ''); $areaCode = self::encode($areaName); $area = Db::fetchRow("SELECT areas.id_area\n , areas.code\n , areas.name\n FROM twcensus_areas AS areas\n WHERE areas.id_country = '{$idCountry}'\n AND areas.code = '{$areaCode}'"); if ($area) { $idArea = $area['id_area']; } else { $idArea = Db::insert('twcensus_areas', array('id_country' => $idCountry, 'code' => $areaCode, 'name' => $areaName)); } } if (!$idLocality) { $localityName = Request::getPost('locality_name', ''); $localityCode = self::encode($localityName); $locality = Db::fetchRow("SELECT localities.id_locality\n , localities.code\n , localities.name\n FROM twcensus_localities AS localities\n WHERE localities.id_area = '{$idArea}'\n AND localities.code = '{$localityCode}'"); if ($locality) { $idLocality = $locality['id_locality']; } else { $idLocality = Db::insert('twcensus_localities', array('id_area' => $idArea, 'code' => $localityCode, 'name' => $localityName)); } } $info = array('id_country' => $idCountry, 'id_area' => $idArea, 'id_locality' => $idLocality, 'address' => Request::getPost('address', ''), 'x' => Request::getPost('coord_x', 0), 'y' => Request::getPost('coord_y', 0), 'sex' => Request::getPost('sex', 0), 'age' => Request::getPost('age', 0), 'saved' => time()); Db::update('twcensus_users', $info, array('id_user' => $this->twitter->getID())); $saved = true; } TwCensus::redirect('/' . ($saved ? '?saved' : '')); } elseif (Request::hasQuery('destroy')) { $this->twitter->destroy(); } elseif ($this->twitter->connected()) { $data = $this->twitter->credentials(); $info = array('name' => $data['name'], 'username' => $data['username'], 'location' => $data['location'], 'description' => $data['description'], 'image' => $data['image'], 'url' => $data['url'], 'token' => $this->twitter->getToken(), 'secret' => $this->twitter->getTokenSecret()); if ($this->exists($data['id'])) { $info['modified'] = time(); Db::update('twcensus_users', $info, array('id_user' => $data['id'])); } else { $info['id_user'] = $data['id']; $info['created'] = time(); Db::insert('twcensus_users', $info); } $this->select($data['id']); } elseif (Request::hasQuery('area')) { $this->area = Db::fetchRow("SELECT areas.id_area\n , areas.code\n , areas.name\n FROM twcensus_areas AS areas\n INNER JOIN twcensus_countries AS countries\n ON countries.id_country = areas.id_country\n AND countries.iso = '" . self::$config['country'] . "'\n WHERE areas.code = '" . Request::getQuery('area', '') . "'\n LIMIT 1"); } }