本文整理汇总了PHP中Response::createFromText方法的典型用法代码示例。如果您正苦于以下问题:PHP Response::createFromText方法的具体用法?PHP Response::createFromText怎么用?PHP Response::createFromText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Response
的用法示例。
在下文中一共展示了Response::createFromText方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _main
/**
* Function called once this service is called
*
* @param Request
* @return Response
* */
public function _main(Request $request)
{
// do not allow blank searches
if (empty($request->query)) {
$response = new Response();
$response->setResponseSubject("Debe insertar un texto a buscar");
$response->createFromText("Usted no ha insertado ningún texto a buscar en Wikipedia. Inserte el texto en el asunto del email, justo después de la palabra WIKIPEDIA.<br/><br/>Por ejemplo: Asunto: WIKIPEDIA jose marti");
return $response;
}
// find the right query in wikipedia
$correctedQuery = $this->search($request->query);
if (empty($correctedQuery)) {
$response = new Response();
$response->setResponseSubject("Su busqueda no produjo resultados");
$response->createFromText("Su búsqueda <b>{$request->query}</b> no fue encontrada en Wikipedia. Por favor modifique el texto e intente nuevamente.");
return $response;
}
// get the HTML code for the page
$page = $this->get(urlencode($correctedQuery));
// get the home image
$imageName = empty($page['images']) ? false : $page['images'][0];
// create a json object to send to the template
$responseContent = array("title" => $page['title'], "body" => $page['body'], "image" => $imageName, "isLarge" => $page['isLarge']);
// send the response to the template
$response = new Response();
$response->setResponseSubject("Wikipedia: {$page['title']}");
$response->createFromTemplate("wikipedia.tpl", $responseContent, $page['images']);
return $response;
}
示例2: _main
/**
* Get the latest raffle
*
* @param Request
* @return Response
* */
public function _main(Request $request)
{
// set Spanish so the date come in Spanish
setlocale(LC_TIME, "es_ES");
// get the current raffle
$raffle = $this->utils->getCurrentRaffle();
// show message if there is no open raffle
if (!$raffle) {
$response = new Response();
$response->subject = "No hay ninguna Rifa abierta";
$response->createFromText("Lo sentimos, no hay ninguna Rifa abierta ahora mismo. Pruebe nuevamente en algunos días.");
return $response;
}
// get number of tickets adquired by the user
$connection = new Connection();
$userTickets = $connection->deepQuery("SELECT count(*) as tickets FROM ticket WHERE raffle_id is NULL AND email = '{$request->email}'");
$userTickets = $userTickets[0]->tickets;
// link to connect cuba logo
$connectCubaLogo = "{$this->pathToService}/images/connectcuba.jpg";
// create a json object to send to the template
$responseContent = array("description" => $raffle->item_desc, "startDate" => $raffle->start_date, "endDate" => $raffle->end_date, "tickets" => $raffle->tickets, "image" => $raffle->image, "userTickets" => $userTickets, "connectCubaLogo" => $connectCubaLogo);
// create the final user Response
$response = new Response();
$response->subject = "La Rifa de Apretaste";
$response->createFromTemplate("basic.tpl", $responseContent, array($raffle->image, $connectCubaLogo));
return $response;
}
示例3: _lista
public function _lista(Request $request)
{
$max = intval($request->query);
if ($max > 10000) {
$response = new Response();
$response->setResponseSubject("Numero demasiado grande para procesar");
$response->createFromText("El numero {$max} es demasiado grande para procesar la lista de primos.");
return $response;
}
$primos = array();
for ($i = 1; $i <= $max; $i++) {
if ($this->esPrimo($i)) {
$primos[] = $i;
}
}
$response = new Response();
$response->setResponseSubject("Lista de numeros primos hasta el {$max}");
$response->createFromTemplate("lista.tpl", array("primos" => $primos, "max" => $max));
return $response;
}
示例4: _main
/**
* Function executed when the service is called
*
* @param Request
* @return Response
* */
public function _main(Request $request)
{
// do not allow blank searches
if (empty($request->query)) {
$response = new Response();
$response->setResponseSubject("De donde sacamos el mapa?");
$response->createFromText("Usted no ha insertado ninguna dirección, coordenadas o lugar famoso a buscar. Inserte el texto en el asunto del email, justo después de la palabra MAPA.<br/><br/>Por ejemplo: Asunto: <b>MAPA capitolio, cuba</b>");
return $response;
}
// include google maps library
require_once "{$this->pathToService}/lib/GoogleStaticMap.php";
require_once "{$this->pathToService}/lib/GoogleStaticMapFeature.php";
require_once "{$this->pathToService}/lib/GoogleStaticMapFeatureStyling.php";
require_once "{$this->pathToService}/lib/GoogleStaticMapMarker.php";
require_once "{$this->pathToService}/lib/GoogleStaticMapPath.php";
require_once "{$this->pathToService}/lib/GoogleStaticMapPathPoint.php";
// get and clean the argument
$argument = $request->query;
$argument = str_replace("\n", " ", $argument);
$argument = str_replace("\r", "", $argument);
$argument = trim(strtolower($argument));
// detecting type
$type = 'hibrido';
$internalType = "hybrid";
if (stripos($argument, 'fisico') !== false) {
$type = 'fisico';
$internalType = "satellite";
} elseif (stripos($argument, 'politico') !== false) {
$type = 'politico';
$internalType = "roadmap";
} elseif (stripos($argument, 'terreno') !== false) {
$type = 'terreno';
$internalType = "terrain";
}
// remove the type from the query to display on the template
$argument = str_ireplace($type, '', $argument);
// detecting zoom
$zoom = null;
for ($i = 22; $i >= 1; $i--) {
if (stripos($argument, $i . 'x') !== false) {
$zoom = $i;
$argument = str_ireplace("{$i}x", '', $argument);
}
}
// remove bad starting arguments
if (substr($argument, 0, 3) == 'de ') {
$argument = substr($argument, 3);
}
if (substr($argument, 0, 4) == 'del ') {
$argument = substr($argument, 4);
}
// create the map
$oStaticMap = new GoogleStaticMap();
$oStaticMap->setScale(1);
$oStaticMap->setHeight(400);
$oStaticMap->setWidth(400);
$oStaticMap->setLanguage("es");
$oStaticMap->setHttps(true);
$oStaticMap->setMapType($internalType);
if (!is_null($zoom)) {
$oStaticMap->setZoom($zoom);
}
$oStaticMap->setCenter($argument);
// get path to the www folder
$di = \Phalcon\DI\FactoryDefault::getDefault();
$wwwroot = $di->get('path')['root'];
// save the image as a temp file
$mapImagePath = "{$wwwroot}/temp/" . $this->utils->generateRandomHash() . ".jpg";
$content = file_get_contents($oStaticMap);
file_put_contents($mapImagePath, $content);
// optimize the image
$this->utils->optimizeImage($mapImagePath);
// create the response variables
$responseContent = array("type" => $type, "request" => $argument, "zoom" => $zoom, "image" => $mapImagePath);
// create the response
$response = new Response();
$response->setResponseSubject("Mapa para " . $request->query);
$response->createFromTemplate("basic.tpl", $responseContent, array($mapImagePath));
return $response;
}
示例5: _comprar
/**
* Function executed when the subservice is called
*
* @param Request
* @return Response
* */
public function _comprar(Request $request)
{
$code = $request->query;
// get the payment details
$connection = new Connection();
$inventory = $connection->deepQuery("SELECT * FROM inventory WHERE code = '{$code}' && active = 1");
// error if the code was not valid or the inventory item cannot be found or its not active
if (empty($code) || empty($inventory)) {
$article = empty($code) ? "" : ", {$code}, ";
$response = new Response();
$response->subject = "Articulo incorrecto o temporalmente agotado";
$response->createFromText("El articulo que usted pidió comprar{$article}no existe o se encuentra temporalmente agotado. Por favor compruebe el código e intente nuevamente.");
return $response;
}
// get the element from the inventory
$inventory = $inventory[0];
// start a new transfer
$r = new Request();
$r->subject = "PURCHASE";
$r->name = $inventory->code;
$r->body = $inventory->name;
$r->email = $request->email;
$r->query = $inventory->price . " " . $inventory->seller;
return $this->_main($r);
}
示例6: getNotMemberResponse
/**
* Return common not member response
*
* @param string $email
* @return Response
*/
private function getNotMemberResponse($email = null)
{
$response = new Response();
if (is_null($email)) {
$response->setResponseSubject("Usted no forma parte la red Cupido");
$response->createFromText("Usted no forma parte la red Cupido");
} else {
$response->setResponseSubject("{$email} no forma parte la red Cupido");
$response->createFromText("El usuario {$email} no forma parte la red Cupido");
}
return $response;
}
示例7: _estadisticas
/**
* Subservice ESTADISTICAS
*
* @param Request $request
* @return Response
*/
public function _estadisticas(Request $request)
{
// get list of ads for the user
$connection = new Connection();
$result = $connection->deepQuery("SELECT * FROM ads WHERE owner = '{$request->email}' ORDER BY id");
// list all the ads
if (count($result) > 0) {
$response = new Response();
$response->setResponseSubject('Sus anuncios en Apretaste');
$response->createFromTemplate('stats.tpl', array('stats' => $result));
return $response;
}
// in case the user don't have any ads
$response = new Response();
$response->setResponseSubject('Usted no tiene anuncio corriendo');
$response->createFromText('Usted no tiene ningun anuncio en Apretaste');
return $response;
}
示例8: getResponseBasedOnNumberOfResults
/**
* Search and return based on number of results
*
* @author salvipascual
* */
private function getResponseBasedOnNumberOfResults(Request $request, $numberOfResults)
{
// if the search is empty, return a message to the user
if (empty($request->query)) {
$serviceUsage = str_replace("{APRETASTE_EMAIL}", $this->utils->getValidEmailAddress(), nl2br($this->serviceUsage));
$response = new Response();
$response->setResponseSubject("Inserte un producto o servicio a buscar");
$response->createFromText("Usted no ha insertado ningún producto o servicio a buscar, use nuestra tienda de la siguiente manera:<br/><br/><br/>{$serviceUsage}");
return $response;
}
// search for the results of the query
$searchResult = $this->search($request->query, $numberOfResults);
$count = $searchResult['count'];
$items = $searchResult['items'];
// return error to the user if no items were found
if (count($items) == 0) {
$response = new Response();
$response->setResponseSubject("Su busqueda no produjo resultados");
$response->createFromText("Su búsqueda '{$request->query}' no produjo ningún resultado. Por favor utilice otra frase de búsqueda e intente nuevamente.");
return $response;
}
// get the path
$di = \Phalcon\DI\FactoryDefault::getDefault();
$wwwroot = $di->get('path')['root'];
// check if is a buscar or buscartodo
$isSimpleSearch = $numberOfResults <= 10;
// clean the text and save the images
$images = array();
foreach ($items as $item) {
// clean the text
$item->ad_title = $this->clean($item->ad_title);
$item->ad_body = $this->clean($item->ad_body);
// save images if 10 results
if ($isSimpleSearch) {
if ($item->number_of_pictures == 0) {
continue;
}
$file = "{$wwwroot}/public/tienda/" . md5($item->source_url) . "_1.jpg";
if (file_exists($file)) {
$images[] = $file;
}
}
}
// select template
$template = $isSimpleSearch ? "buscar.tpl" : "buscartodo.tpl";
// send variables to the template
$responseContent = array("numberOfDisplayedResults" => $isSimpleSearch ? count($items) > 10 ? 10 : count($items) : count($items), "numberOfTotalResults" => $count, "searchQuery" => $request->query, "items" => $items, "wwwroot" => $wwwroot);
// display the results in the template
$response = new Response();
$response->setResponseSubject("La busqueda que usted pidio");
$response->createFromTemplate($template, $responseContent, $images);
return $response;
}
示例9: Response
/**
* A test for a subservice WIKIPEDIA
* */
function _test(Request $request)
{
$response = new Response();
$response->setResponseSubject("Just a test for subservice");
$response->createFromText("A test for the subservice WIKIPEDIA");
return $response;
}
示例10: _radar
/**
* Subservice radar
*
* @param Request
* @return Response
* */
public function _radar(Request $request)
{
$radares = array("http://www.met.inf.cu/Radar/NacComp200Km.gif", "http://www.met.inf.cu/Radar/03Cienfuegos/psjMAXw01a.gif", "http://www.met.inf.cu/Radar/04Camaguey/cmwMAXw01a.gif", "http://www.met.inf.cu/Radar/05Pilon/plnMAXw01a.gif", "http://www.met.inf.cu/Radar/00Pinar%20del%20Rio/lbjMAXw01a.gif");
$url = false;
foreach ($radares as $urlx) {
if (file_get_contents($urlx) !== false) {
$url = $urlx;
break;
}
}
// TODO: save last radar image on cache for future problems?
if ($url === false) {
$response = new Response();
$response->setResponseSubject("Clima: No se pudo obtener la imagen del radar");
$response->createFromText("No se pudo obtener la imagen del radar, intente m´s tarde");
return $response;
}
return $this->commonImageResponse("Imagen del radar", $url);
}
示例11: _negocios
/**
* List of businesses that accept bitcoin
*
* @param Request
* @return Response
* */
public function _negocios(Request $request)
{
// @TODO remove bulshit answer to use the service
$response = new Response();
$response->setResponseSubject("Bitcoin temporalmente no disponible");
$response->createFromText("Lo sentimos, pero Bitcoin esta temporalmente detenido. Le dejaremos saber cuando empecemos a funcionar. Gracias!");
return $response;
// END TODO
$path = $this->pathToService;
$images = array("{$path}/images/airbnb.jpg", "{$path}/images/carnival.jpg", "{$path}/images/virgin-atlantic.jpg", "{$path}/images/unilever.jpg", "{$path}/images/netflix.png", "{$path}/images/DimeCuba.jpg");
$response = new Response();
$response->setResponseSubject("Negocios que aceptan BitCoin");
$response->createFromTemplate("negocios.tpl", array("path" => $path), $images);
return $response;
}
示例12: _buscar
/**
* Get the last 50 messages sent by a user
*
* @author salvipascual
* @param Request
* @return Response
*
*/
public function _buscar(Request $request)
{
// do not work if the search comes in blank
$query = trim($request->query);
if (empty($query)) {
$response = new Response();
$response->createFromText("Por favor escriba un @username, un #hashtag o un texto a buscar.");
return $response;
}
$connection = new Connection();
// get the username from the email
$usern = $connection->deepQuery("SELECT username FROM person WHERE email='{$request->email}'");
$usern = $usern[0]->username;
// check if the query is a date
if (substr(strtolower($query), 0, 5) == 'fecha') {
$query = trim(substr($query, 5));
// by default
$where = " TRUE ";
$subject = "Ultimas 50 notas en Pizarra";
// getting the date
if ($query != '') {
$valid_formats = array('YmdHis', 'Y-m-d H:i:s', 'Ymd', 'Y-m-d', 'd/m/Y H:i:s', 'd/m/Y', 'd-m-Y H:i:s', 'd-m-Y');
foreach ($valid_formats as $vf) {
$date = date_create_from_format($vf, $query);
if ($date !== false) {
$where = " A.inserted >= '" . $date->format('Y-m-d H:i:s') . "' ";
$subject = "Ultimas notas a partir de " . $date->format('d/m/Y') . " a las " . $date->format('H:i:s') . 'hrs';
break;
}
}
}
} else {
// prepare to search for a text
// @TODO make it work with levestein type algorithm
$where = "A.text like '%{$query}%'";
$subject = 'Notas con el texto "' . $query . '"';
// get the number of words passed
$numberOfWords = count(explode(" ", $query));
// check if the query is a username
if ($numberOfWords == 1 && strlen($query) > 2 && $query[0] == "@") {
$username = str_replace("@", "", $query);
// $where = "B.username = '$username' OR A.text like '%$username%'";
if (strcasecmp(trim($username), trim($usern)) === 0) {
$subject = 'Mis notas en pizarra';
} else {
$subject = "Notas de {$query}";
}
$where = "B.username = '{$username}'";
}
// check if the query is a hashtag
if ($numberOfWords == 1 && strlen($query) > 2 && ($query[0] == "*" || $query[0] == "#")) {
$hashtag = str_replace("*", "#", $query);
$where = "A.text like '% {$hashtag}%'";
$subject = "Veces que {$hashtag} es mencionado";
}
}
// get the last 50 records from the db
$connection = new Connection();
$listOfNotes = $connection->deepQuery("\r\n\t\t\tSELECT A.*, B.username, B.first_name, B.last_name, B.province, B.picture, B.gender\r\n\t\t\tFROM _pizarra_notes A\r\n\t\t\tLEFT JOIN person B\r\n\t\t\tON A.email = B.email\r\n\t\t\tWHERE {$where}\r\n\t\t\tORDER BY inserted DESC\r\n\t\t\tLIMIT 50");
// display message if the response is blank
if (empty($listOfNotes)) {
$response = new Response();
$response->createFromText("No se encontraron notas para el @username, #hashtag o texto que usted buscó.");
return $response;
}
// format the array of notes
$notes = array();
foreach ($listOfNotes as $note) {
// get the name
$name = trim("{$note->first_name} {$note->last_name}");
if (empty($name)) {
$name = $note->email;
}
// get the location
if (empty($note->province)) {
$location = "Cuba";
} else {
$location = ucwords(strtolower(str_replace("_", " ", $note->province)));
}
// highlight usernames and link it to NOTA
$note->text = $this->hightlightUsernames($note->text, $usern);
// add the text to the array
$notes[] = array("id" => $note->id, "name" => $note->username, "location" => $location, "gender" => $note->gender, "picture" => $note->picture, "text" => $note->text, "inserted" => date("Y-m-d H:i:s", strtotime($note->inserted)), "likes" => $note->likes, 'source' => $note->source, 'email' => $note->email);
}
// highlight hash tags
for ($i = 0; $i < count($notes); $i++) {
$notes[$i]['text'] = ucfirst(strtolower($notes[$i]['text']));
// fix case
$notes[$i]['text'] = $this->highlightHashTags($notes[$i]['text']);
}
$content = array("header" => $subject, "notes" => $notes);
// create the response
//.........这里部分代码省略.........