本文整理汇总了PHP中Data::add方法的典型用法代码示例。如果您正苦于以下问题:PHP Data::add方法的具体用法?PHP Data::add怎么用?PHP Data::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Data
的用法示例。
在下文中一共展示了Data::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: put
/**
* 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);
}
示例2: save
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;
}
示例3: __construct
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;
}
示例4: auto
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;
}
示例5: getAds
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';
//.........这里部分代码省略.........
示例6: Data
<?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();
示例7: Data
/*
* 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();
示例8: fixtures
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' => 'admin@admin.com');
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());
//.........这里部分代码省略.........
示例9: Data
<?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();
示例10: Data
<?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();