/**
 * The method that is called by Alfred
 *
 * @param string $request	User input string
 */
function googleTranslate($request, $languages = false)
{
    if ($languages) {
        list($sourceLanguage, $targetLanguage) = $languages;
        $phrase = $request;
    } else {
        list($phrase, $sourceLanguage, $targetLanguage) = parseRequest($request);
    }
    $url = 'http://translate.google.com/translate_a/t?client=p&text=' . urlencode($phrase) . '&hl=en-EN&sl=' . $sourceLanguage . '&tl=' . $targetLanguage . '&multires=1&ssel=0&tsel=0&sc=1&ie=UTF-8&oe=UTF-8';
    $userUrl = 'https://translate.google.com/#' . $sourceLanguage . '/' . $targetLanguage . '/' . urlencode($phrase);
    $defaults = array(CURLOPT_RETURNTRANSFER => true, CURLOPT_URL => $url, CURLOPT_FRESH_CONNECT => true);
    $ch = curl_init();
    curl_setopt_array($ch, $defaults);
    $out = curl_exec($ch);
    curl_close($ch);
    $xml = new AlfredResult();
    $xml->setShared('uid', 'mtranslate');
    $iconFilename = 'Icons/' . $targetLanguage . '.png';
    if (!file_exists($iconFilename)) {
        $iconFilename = 'icon.png';
    }
    $xml->setShared('icon', $iconFilename);
    //$stderr = fopen('php://stderr', 'w');
    //fwrite($stderr, $out);
    //fclose($stderr);
    $json = json_decode($out);
    $sourceLanguage = $json->src;
    if (isset($json->dict)) {
        $googleResults = $json->dict[0]->entry;
        if (is_array($googleResults)) {
            foreach ($googleResults as $translatedData) {
                $xml->addItem(array('arg' => $userUrl . '|' . $translatedData->word, 'valid' => 'yes', 'title' => $translatedData->word . ' (' . languageMap($targetLanguage) . ')', 'subtitle' => implode(', ', $translatedData->reverse_translation) . ' (' . languageMap($sourceLanguage) . ')'));
            }
        }
    } elseif (isset($json->sentences)) {
        foreach ($json->sentences as $sentence) {
            $xml->addItem(array('arg' => $userUrl . '|' . $sentence->trans, 'valid' => 'yes', 'title' => $sentence->trans . ' (' . languageMap($targetLanguage) . ')', 'subtitle' => $sentence->orig . ' (' . languageMap($sourceLanguage) . ')'));
        }
    } else {
        $xml->addItem(array('title' => 'No results found'));
    }
    // var_dump($xml);
    echo $xml;
}
Example #2
0
<?php

include "inc/sql_devtools.php";
include "inc/sql_daityo.php";
include "inc/common.php";
$errors = array();
$id = '';
$formData['aid'] = '';
$formData['pwd'] = '';
if (isset($_POST['sbm'])) {
    $formData = parseRequest($_POST);
    $errors = validateFormData($formData);
    if (is_array($errors) && count($errors) > 0) {
    } else {
        $id = $formData['aid'];
        $pw = $formData['pwd'];
        setcookie("devid", $id, time() + 60 * 60 * 24 * 5);
        // 有効期限5日間
        $errors = login_new($id, $pw);
    }
} else {
    if (isset($_REQUEST['error_msg'])) {
        $errors = $_REQUEST['error_msg'];
    }
}
$users = list_users();
if (strlen($formData['aid']) > 0 && $formData['aid'] != '') {
    $id = $formData['aid'];
} else {
    $id = $_COOKIE["devid"];
    //まずクッキーを読み出して変数に格納
Example #3
0
    $arr2 = array("message" => array("id" => 1, "nickname" => $values['name'], "messageBody" => $values['message']));
    $arr = array_merge($arr1, $arr2);
    return $arr;
}
function postToThread($threadId, $values)
{
    /* Adds reply to a thread
    	IRL should read the value of $threadId and select the thread accordingly */
    $arr = array("id" => 2, "nickname" => $values['name'], "message" => $values['message']);
    return $arr;
}
/* Define the Constants, which in real life would probably be either 
	database values or System ENVS */
define("PATH", "/api/index.php/");
define("PREVIEW_LENGTH", 70);
$request = parseRequest($_SERVER);
// handle the Request
// check if ACTION is proper
if ($request[1][0] != "threads") {
    /* because "threads" is only allowed action
    			per specs, return an error if something else
    				provided */
    die("Invalid API Call: Forbidden action");
}
// check if ID is an integer
if (is_numeric($request[1][1])) {
    $id = (int) $request[1][1];
} else {
    $id = null;
}
/* Perform the correct action based on the parsed request array */
Example #4
0
// If the first part of the request is "admin", presume we're in the admin section.
if ($requestParts[0] == "admin") {
    $controllers = ETFactory::$adminControllers;
    array_shift($requestParts);
    if (empty($requestParts[0])) {
        $requestParts[0] = "dashboard";
    }
} else {
    $controllers = ETFactory::$controllers;
    // If the first character of the URL parameter is numeric, assume the conversation controller.
    if ($requestParts[0] and is_numeric($requestParts[0][0])) {
        array_unshift($requestParts, "conversation");
    }
}
// Parse the request store all of the request information.
list(ET::$controllerName, ET::$controller, $method, $arguments, $responseType) = parseRequest($requestParts, $controllers);
ET::$controller->selfURL = $selfURL;
ET::$controller->controllerMethod = $method;
ET::$controller->responseType = $responseType;
//***** 11. SHOW THE PAGE
// Initialize plugins.
foreach (ET::$plugins as $plugin) {
    $plugin->init();
}
// Include the config/custom.php file, a convenient way to override things.
if (file_exists($file = PATH_CONFIG . "/custom.php")) {
    include $file;
}
// Include render functions. We do this after we initialize plugins so that they can override any functions if they want.
require PATH_LIBRARY . "/functions.render.php";
// Initialize the controller.
<?php

require_once 'config.php';
require_once 'routes.php';
session_start();
$parsedRequest = parseRequest();
executeRequest($parsedRequest);
<?php

require_once 'config.php';
require_once 'functions.php';
session_start();
$requestParsed = parseRequest();
processRequest($requestParsed);
Example #7
0
header('Content-Type: application/json');
// o retorno do controller é sempre em json
require_once "{$root}/src/\$.php";
// funções globais
require_once "{$root}/src/DB.php";
// banco de dados
try {
    parse_str(file_get_contents("php://input"), $request);
    // pega os parametros enviados (seja qual for o método)
    $method = $_SERVER['REQUEST_METHOD'];
    // pega o método que enviou os parametros
    $function = $_REQUEST['function'];
    // pega a função requisitada
    $id = $_REQUEST['id'];
    // id da pessoa
    parseRequest($request);
    // converter arrays JSON para arrays PHP
    switch ($function) {
        case 'ReceberCompras':
            $pessoa = Pessoa::find($id);
            $pedidos = $pessoa->getPedidos();
            foreach ($pedidos as $pedido) {
                if ($pedido->getTpPedido() == 'C') {
                    if ($pedido->getStEntrega() == 'PN') {
                        $itens = $pedido->getItens();
                        foreach ($itens as $item) {
                            if ($item->getStEntregaItem() == 'PN') {
                                $entrega = array("nrEntrega" => count($item->getEntregas()) + 1, "dtEntrega" => date('Y-m-d', time()), "qtEntrega" => $item->getQtRestante(), "idItem" => $item->getIdItem());
                                Entrega::persistEntrega($entrega);
                            }
                        }
Example #8
0
function printBody()
{
    $request = $_REQUEST['page'];
    $elements = split("/", $request);
    $html = "\n        <body><div id=\"wrapper\">";
    $html .= BANNER;
    $category = getCategoryField($request);
    $top = printTopBar($category);
    $html .= $top;
    #$main= "<div class=\"main\">\n";
    $main .= parseRequest($request, $category);
    #$main.= "</div>\n";
    //breadcrumbs should be initialized now.
    $html .= $breadcrumbs . $main . $breadcrumbs;
    #$html.=$top;//printTopBar($category);
    $html .= FOOTER;
    $html .= "</div>";
    global $analytics;
    $html .= "{$analytics}</body>";
    return $html;
}