/** * Write an item to the cache for a given number of minutes. * * @param string $key * @param mixed $value * @param int $minutes * @return void */ public function put($key, $value, $minutes = 60) { $this->_cleanCache(); if (0 >= $minutes) { return; } $this->forget($key); $expiration = $this->expiration($minutes); $data = array('key' => $key, 'value' => $value, 'expiration' => $expiration, 'namespace' => $this->namespace); Data::add('cache', $data); }
public static function save($id) { $res = Data::query('movie', 'id_ac = ' . $id); if (!count($res)) { $info = static::getInfosMovie($id); $info['id_ac'] = $id; $info['id_video'] = null; $info['plateforme'] = null; $movie = Data::getById('movie', Data::add('movie', $info)); } else { $movie = Data::getObject(current($res)); } return $movie; }
public function __construct($name, $duration = 3600) { $this->checkTimeout(); $ip = static::getIP(); $this->_duration = $duration; $this->_key = sha1($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT'] . date('dmY')); $this->_sessionName = $name; $sessions = parent::query('thinsession', 'session_name = ' . $this->_sessionName . ' && session_key = ' . $this->_key . ' && expire >= ' . time()); if (count($sessions)) { $this->_session = parent::getObject(current($sessions)); } else { $create = array(); $create['expire'] = time() + $duration; $create['session_name'] = $this->_sessionName; $create['session_key'] = $this->_key; $create['data'] = new \thinDataSession(); $newId = parent::add('thinsession', $create); $this->_session = parent::getById('thinsession', $newId); } $data = $this->_session->getData(); return $data; }
public static function auto($sentence, $source = 'fr', $target = 'en') { $key = sha1(serialize(func_get_args())); $res = Data::query('translation', 'key = ' . $key); if (count($res)) { $obj = current($res); return $obj->getSentence(); } $source = Inflector::lower($source); $target = Inflector::lower($target); $url = "http://api.mymemory.translated.net/get?q=" . urlencode($sentence) . "&langpair=" . urlencode($source) . "|" . urlencode($target); $res = dwn($url); $tab = json_decode($res, true); if (Arrays::exists('responseData', $tab)) { if (Arrays::exists('translatedText', $tab['responseData'])) { $translation = $tab['responseData']['translatedText']; $data = array('source' => $source, 'target' => $target, 'key' => $key, 'sentence' => $translation); Data::add('translation', $data); return $translation; } } return $sentence; }
public function getAds($maxPages = 0) { set_time_limit(0); $first = dwn('http://m.duproprio.com/resultats?hash=/s-pmin=0/s-pmax=99999999/p-ord=date/p-dir=DESC/pa-ge=1/s-filter=forsale/s-build=1/p-con=main/g-pr=1/s-bmin=0'); $nbPages = 0 == $maxPages ? Utils::cut('Page 1 de ', ' ', $first) : $maxPages; $ids = array(); $infos = array(); $pageIds = array(); $tab = explode('<a id=', $first); for ($i = 1; $i < count($tab); $i++) { $seg = trim($tab[$i]); $id = Utils::cut('"', '"', $seg); if (!Arrays::in($id, $ids)) { array_push($ids, $id); array_push($pageIds, $id); } } foreach ($pageIds as $id) { $seg = $this->tag('<div class="thumbnail" data-listing-code="' . $id . '">', '<a id="', $first); if (!empty($seg)) { $tmp = $this->tag('<img src="', '"', $seg); $picId = $this->tag('-big-', '.', $tmp); $infos[$id]['thumb'] = $picId; $type = $this->tag('<span class="listing-type">', '</span>', $seg); $type = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($type))); if (contain(',', $type)) { list($type, $bedroom) = explode(',', $type, 2); } else { $type = $type; $bedroom = 0; } $infos[$id]['type'] = $this->clean($type); $infos[$id]['bedroom'] = repl(' ch.', '', $this->clean($bedroom)); $address = $this->tag('<span class="listing-address">', '</span>', $seg); $address = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($address))); $address = $this->clean($address); $tabAddress = explode(', ', $address); if (count($tabAddress)) { $city = Arrays::last($tabAddress); $address = repl(', ' . $city, '', $address); } else { $city = ''; } $infos[$id]['address'] = $address; $infos[$id]['city'] = $city; $price = $this->tag('<span class="listing-price">', '</span>', $seg); $price = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($price))); $infos[$id]['price'] = $this->clean(repl(array(' ', '$'), '', $price)); $infos[$id]['partner'] = 'duproprio'; $infos[$id]['partner_id'] = $id; } } foreach ($infos as $id => $property) { Data::getById('property', Data::add('propriete', $property)); } for ($j = 2; $j <= (int) $nbPages; $j++) { $page = dwn('http://m.duproprio.com/resultats?page=' . $j . '&hash=%2Fs-pmin%3D0%2Fs-pmax%3D99999999%2Fp-ord%3Ddate%2Fp-dir%3DDESC%2Fpa-ge%3D2%2Fs-filter%3Dforsale%2Fs-build%3D1%2Fp-con%3Dmain%2Fg-pr%3D1%2Fs-bmin%3D0'); $infos = array(); $pageIds = array(); $tab = explode('<a id=', $page); for ($i = 1; $i < count($tab); $i++) { $seg = trim($tab[$i]); $id = Utils::cut('"', '"', $seg); if (!Arrays::in($id, $ids)) { array_push($ids, $id); array_push($pageIds, $id); } } foreach ($pageIds as $id) { $seg = $this->tag('<div class="thumbnail" data-listing-code="' . $id . '">', '<a id="', $page); if (!empty($seg)) { $tmp = $this->tag('<img src="', '"', $seg); $picId = $this->tag('-big-', '.', $tmp); $infos[$id]['thumb'] = $picId; $type = $this->tag('<span class="listing-type">', '</span>', $seg); $type = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($type))); if (contain(',', $type)) { list($type, $bedroom) = explode(',', $type, 2); } else { $type = $type; $bedroom = 0; } $infos[$id]['type'] = $this->clean($type); $infos[$id]['bedroom'] = repl(' ch.', '', $this->clean($bedroom)); $address = $this->tag('<span class="listing-address">', '</span>', $seg); $address = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($address))); $address = $this->clean($address); $tabAddress = explode(', ', $address); if (count($tabAddress)) { $city = Arrays::last($tabAddress); $address = repl(', ' . $city, '', $address); } else { $city = ''; } $infos[$id]['address'] = $address; $infos[$id]['city'] = $city; $price = $this->tag('<span class="listing-price">', '</span>', $seg); $price = html_entity_decode(repl(array("\n", "\r", "\t"), '', strip_tags($price))); $infos[$id]['price'] = $this->clean(repl(array(' ', '$'), '', $price)); $infos[$id]['partner'] = 'duproprio'; $infos[$id]['partner_id'] = $id; } } foreach ($infos as $id => $property) { Data::getById('property', Data::add('propriete', $property)); } } return $this; }
<?php define('GEOCODER', 'hybrid'); require_once '../../spider.php'; $data = new Data('salzburg.info'); $indexes = array('http://www2.salzburg.info/sehenswertes_222.htm', 'http://www2.salzburg.info/sehenswertes_361.htm'); foreach ($indexes as $url) { $indexUrl = new URL($url); while ($indexUrl) { $indexPage = $indexUrl->get(); foreach ($indexPage->match('/<a href="([^"]+)" class="link_darkred"><b>more/') as $match) { $itemUrl = new URL($match, $indexUrl); $itemPage = $itemUrl->get(); list($lat, $lng) = $data->geocode($itemPage->match('/<tr>[\\s\\n]+<td><img src="pics\\/1\\.gif" width="1" height="8"><\\/td>[\\s\\n]+<\\/tr>[\\s\\n]+<tr>[\\s\\n]+<td>([^<]+).*?<\\/td>[\\s\\n]+<\\/tr>[\\s\\n]+<tr>[\\s\\n]+<td><img src="pics\\/1\\.gif" width="1" height="8"><\\/td>[\\s\\n]+<\\/tr>/') . ' Salzburg Austria'); $data->add(array('title' => $itemPage->match('/<h1>([^<]+)/'), 'description' => $itemPage->match('/<\\/td>[\\s\\n]+<td valign="top">[\\s\\n]+<table width="160" border="0" cellspacing="0" cellpadding="0">[\\s\\n]+<tr>[\\s\\n]+<td>([^<]+)/'), 'lat' => $lat, 'lng' => $lng, 'href' => $itemUrl)); } $nextUrl = $indexPage->match('/<a href="([^"]+)" class="link_darkred">next/'); if ((string) $nextUrl) { $indexUrl = new URL($nextUrl, $url); } else { break; } } } // we're done, close the CSV file $data->done();
/* * This example usage grabs data from www.worldtravelguide.net and creates a CSV * file www.worldtravelguide.net.csv containing the scraped data. */ // we'll just use the Yahoo geocoder define('GEOCODER', 'yahoo'); // include the spider library require_once 'spider.php'; // create a data object to store our data in $data = new Data('www.worldtravelguide.net'); // get the index page of the attractions $indexUrl = new URL('http://www.worldtravelguide.net/attraction/'); $indexPage = $indexUrl->get(); // match each subpage URL foreach ($indexPage->match('/<li><b><a href="([^"]+)/') as $match) { // get the subpage $continentUrl = new URL($match, $indexUrl); $continentPage = $continentUrl->get(); // match each attracton page URL foreach ($continentPage->match('/<b><a href="([^"]+)/') as $match) { // get the attraction page $itemUrl = new URL($match, $continentUrl); $itemPage = $itemUrl->get(); // extract the address from the page and geocode it list($lat, $lng) = $data->geocode($itemPage->match('/<h3>Contact Addresses<\\/h3>[\\r\\n\\t ]+<div class="paragraph">.+?,([^<]+)/')); // extract the other data from the page and add it to the data object along with the geocoded lat/lng data $data->add(array('title' => preg_replace('/\\([^)]+\\)/', '', $itemPage->match('/<title>(.+?) Guide/')), 'description' => $itemPage->match('/<\\/h2>[\\r\\n\\t ]+<div class="paragraph">(.+?)<\\/div>/'), 'lat' => $lat, 'lng' => $lng, 'href' => $itemUrl)); } } // we're done, close the CSV file $data->done();
public static function fixtures() { $adminTables = Data::getAll('admintable'); $adminUsers = Data::getAll('adminuser'); $adminactions = Data::getAll('adminaction'); $adminRights = Data::getAll('adminright'); $adminTaskStatus = Data::getAll('admintaskstatus'); $adminTaskType = Data::getAll('admintasktype'); $adminTaskTypes = Data::getAll('admintasktype'); $adminCountries = Data::getAll('admincountry'); $options = Data::getAll('option'); $bools = Data::getAll('bool'); $formTypes = Data::getAll('adminformfieldtype'); if (!count($bools)) { $bool1 = array('name' => 'Oui', 'value' => 'true'); $bool2 = array('name' => 'Non', 'value' => 'false'); Data::add('bool', $bool1); Data::getAll('bool'); Data::add('bool', $bool2); Data::getAll('bool'); } if (!count($formTypes)) { $typesToAdd = array(); $typesToAdd[] = array('name' => 'Classique', 'value' => 'text'); $typesToAdd[] = array('name' => 'Texte', 'value' => 'textarea'); $typesToAdd[] = array('name' => 'Date', 'value' => 'date'); $typesToAdd[] = array('name' => 'Courriel', 'value' => 'email'); $typesToAdd[] = array('name' => 'Sélection', 'value' => 'select'); $typesToAdd[] = array('name' => 'Téléphone', 'value' => 'telephone'); $typesToAdd[] = array('name' => 'Caché', 'value' => 'hidden'); $typesToAdd[] = array('name' => 'Url', 'value' => 'url'); foreach ($typesToAdd as $typeToAdd) { Data::add('adminformfieldtype', $typeToAdd); Data::getAll('adminformfieldtype'); } } if (!count($adminCountries)) { $list = fgc("http://web.gpweb.co/u/45880241/cdn/pays.csv"); $rows = explode("\n", $list); foreach ($rows as $row) { $row = repl('"', '', trim($row)); if (contain(';', $row)) { list($id, $name, $upp, $low, $code) = explode(';', $row, 5); $country = array('name' => $name, 'code' => $code); Data::add('admincountry', $country); Data::getAll('admincountry'); } } } if (!count($adminTaskTypes)) { $types = array('Bogue', 'Snippet', 'SEO', 'Traduction', 'Graphisme', 'Contenu', 'Html', 'Css', 'Javascript'); foreach ($types as $type) { $taskType = array('name' => $type); Data::add('admintasktype', $taskType); Data::getAll('admintasktype'); } } if (!count($adminTaskStatus)) { $allStatus = array(1 => 'Attribuée', 4 => 'Terminée', 2 => 'En cours', 7 => 'En suspens', 6 => 'En attente d\'information', 3 => 'En test', 5 => 'Réattribuée', 8 => 'Annulée'); foreach ($allStatus as $priority => $status) { $taskStatus = array('name' => $status, 'priority' => $priority); Data::add('admintaskstatus', $taskStatus); Data::getAll('admintaskstatus'); } } if (!count($adminTables)) { $entities = container()->getEntities(); if (count($entities)) { foreach ($entities as $entity) { $table = array('name' => $entity); Data::add('admintable', $table); Data::getAll('admintable'); } } } if (!count($adminactions)) { $actions = array('list', 'add', 'duplicate', 'view', 'delete', 'edit', 'import', 'export', 'search', 'empty_cache'); foreach ($actions as $action) { $newAction = array('name' => $action); Data::add('adminaction', $newAction); Data::getAll('adminaction'); } } if (!count($adminUsers)) { $user = array('name' => 'Admin', 'firstname' => 'Dear', 'login' => 'admin', 'password' => 'admin', 'email' => '*****@*****.**'); Data::add('adminuser', $user); Data::getAll('adminuser'); } if (!count($adminRights)) { $sql = dm('adminuser'); $res = $sql->where('email = admin@admin.com')->get(); $user = $sql->first($res); $tables = Data::getAll('admintable'); $actions = Data::getAll('adminaction'); if (count($tables)) { foreach ($tables as $table) { $table = Data::getIt('admintable', $table); foreach ($actions as $action) { $action = Data::getIt('adminaction', $action); $right = array('adminuser' => $user->getId(), 'admintable' => $table->getId(), 'adminaction' => $action->getId()); Data::add('adminright', $right); Data::getAll('adminright'); } } } } if (!count($options)) { $optionsToAdd = array(); $optionsToAdd[] = array('name' => 'default_language', 'value' => 'fr'); $optionsToAdd[] = array('name' => 'lng_fr_display', 'value' => 'flag'); $optionsToAdd[] = array('name' => 'page_languages', 'value' => 'fr'); $optionsToAdd[] = array('name' => 'theme', 'value' => SITE_NAME); $optionsToAdd[] = array('name' => 'menu_fixed', 'value' => 'true'); $optionsToAdd[] = array('name' => 'show_menu', 'value' => 'true'); $optionsToAdd[] = array('name' => 'logo_max_width', 'value' => 400); $optionsToAdd[] = array('name' => 'menu_background_color', 'value' => '#eee'); $optionsToAdd[] = array('name' => 'menu_link_background_color', 'value' => '#444'); $optionsToAdd[] = array('name' => 'menu_link_color', 'value' => '#fff'); $optionsToAdd[] = array('name' => 'page_background', 'value' => '#e2e2e2'); $optionsToAdd[] = array('name' => 'page_color', 'value' => '#333'); $optionsToAdd[] = array('name' => 'show_logo', 'value' => 'true'); $optionsToAdd[] = array('name' => 'site_font_family', 'value' => 'Oswald'); $optionsToAdd[] = array('name' => 'site_font_size', 'value' => '14px'); $optionsToAdd[] = array('name' => 'slideshow_background', 'value' => '#222'); $optionsToAdd[] = array('name' => 'slideshow_height', 'value' => '500px'); $optionsToAdd[] = array('name' => 'slideshow_text_color', 'value' => '#fff'); $optionsToAdd[] = array('name' => 'title_font_family', 'value' => 'Passion One'); $optionsToAdd[] = array('name' => 'company_name', 'value' => 'My website'); $optionsToAdd[] = array('name' => 'google_fonts', 'value' => 'Ubuntu,Oswald,Passion One'); $optionsToAdd[] = array('name' => 'map_marker_name', 'value' => 'My website'); $optionsToAdd[] = array('name' => 'map_text', 'value' => 'Bienvenue!'); $optionsToAdd[] = array('name' => 'custom_css', 'value' => ' '); $optionsToAdd[] = array('name' => 'latitude', 'value' => 48); $optionsToAdd[] = array('name' => 'longitude', 'value' => -71); $optionsToAdd[] = array('name' => 'contact_email', 'value' => '*****@*****.**'); $optionsToAdd[] = array('name' => 'form_email', 'value' => '*****@*****.**'); foreach ($optionsToAdd as $optionToAdd) { Data::add('option', $optionToAdd); Data::getAll('option'); } $status1 = array('name' => 'online'); $status2 = array('name' => 'offline'); $status3 = array('name' => 'maintenance'); Data::add('statuspage', $status1); Data::getAll('statuspage'); Data::add('statuspage', $status2); Data::getAll('statuspage'); Data::add('statuspage', $status3); Data::getAll('statuspage'); $sql = dm('statuspage'); $res = $sql->where('name = online')->get(); $status = $sql->first($res); $page = array('name' => 'Accueil', 'url' => array('fr' => 'home'), 'template' => 'home', 'parent' => null, 'statuspage' => $status->getId(), 'date_out' => null, 'hierarchy' => 1, 'is_home' => getBool('true')->getId()); Data::add('page', $page); Data::getAll('page'); } }
<?php define('GEOCODER', 'yahoo'); require_once '../../spider.php'; $data = new Data('austria.intermaps.com'); $indexes = array('museum' => 'http://austria.intermaps.com/soew/oewtemplate/mol.xml?subid=412&level=600&startX=25000&endX=700000&startY=0&endY=700000', 'theatre' => 'http://austria.intermaps.com/soew/oewtemplate/mol.xml?subid=213&level=600&startX=25000&endX=700000&startY=0&endY=700000', 'nature' => 'http://austria.intermaps.com/soew/oewtemplate/mol.xml?subid=413&level=600&startX=25000&endX=700000&startY=0&endY=700000'); foreach ($indexes as $type => $url) { $indexUrl = new URL($url); $indexPage = $indexUrl->get(); foreach ($indexPage->match('/<OBJECT Object_ID="([^"]+)"/') as $match) { $itemUrl = new URL('http://austria.intermaps.com/soew/oewtemplate/ObjectShow.xml?objid=' . $match . '&lang=en'); $itemPage = $itemUrl->get(); $city = $itemPage->match('/<[is]_city>([^<]+)/'); $postcode = $itemPage->match('/<[is]_postcode>([^<]+)/'); $location = $itemPage->match('/<[is]_location>([^<]+)/'); list($lat, $lng) = $data->geocode($city . ' ' . $postcode . ' ' . $location . ' Austria'); $href = $itemPage->match('/<[is]_web>([^<]+)/'); if (substr($href, 0, 7) != 'http://') { $href = 'http://' . $href; } $data->add(array('title' => $itemPage->match('/<o_name>([^<]+)/'), 'description' => $itemPage->match('/<DETAIL d_art="Beschreibung" d_language="en" d_priority="0"><\\!\\[CDATA\\[(.+?)\\]\\]>/'), 'lat' => $lat, 'lng' => $lng, 'href' => $href, 'type' => $type)); } } // we're done, close the CSV file $data->done();
<?php define('GEOCODER', 'hybrid'); require_once '../../spider.php'; $data = new Data('aboutvienna.org'); $indexUrl = new URL('http://www.aboutvienna.org/sights/ankeruhr.htm'); $indexPage = $indexUrl->get(); foreach ($indexPage->match('/<td width="50%"(?: height="11")?><a href="([^"]+)/') as $match) { $itemUrl = new URL($match, $indexUrl); $itemPage = $itemUrl->get(); list($lat, $lng) = $data->geocode($itemPage->match('/<span class="Adressen">([^<]+)/') . ' Vienna Austria'); $data->add(array('title' => $itemPage->match('/<h1 class="tdolive_gross_strich"><a name="1"><\\/a>([^<]+)/'), 'description' => $itemPage->match('/<\\!-- google_ad_section_start -->([^<]+)/'), 'lat' => $lat, 'lng' => $lng, 'href' => $itemUrl)); } // we're done, close the CSV file $data->done();