protected function handleException(\Exception $e)
 {
     _dump("{$e}");
     $this->logError(sprintf("[%s] %s", get_class($e), $e->getMessage()));
     $response = $this->getResponse();
     $response->setStatusCode(400);
     $response->setContent(\Zend\Json\Json::encode(array('error' => 'general error', 'error_description' => sprintf("[%s] %s", get_class($e), $e->getMessage()))));
     return $response;
 }
Exemple #2
0
 public function getQuery()
 {
     $fields = array();
     foreach ($this->fieldPair as $alias => $sql) {
         $s = "{$alias}";
         if ($sql != $alias) {
             $s = $sql . ' AS ' . $alias;
         }
         $fields[] = $s;
     }
     _dump($fields);
 }
<?php

use Zend\Http\Request;
use Zend\Http\Client;
require __DIR__ . '/../init_autoload.php';
$client = _createHttpClient();
$request = new Request();
$request->setUri('https://accounts.google.com/o/oauth2/token');
$response = $client->send($request);
_dump($response->toString());
function _createHttpClient()
{
    $adapter = new Client\Adapter\Socket();
    $client = new Client();
    $client->setOptions(array('maxredirects' => 2, 'strictredirects' => true));
    $client->setAdapter($adapter);
    $adapter->setStreamContext(array('ssl' => array('capath' => '/etc/ssl/certs')));
    return $client;
}
Exemple #4
0
function _db_table($table)
{
    $sql = 'SELECT * FROM ' . $table;
    echo "<p>{$sql}</p>";
    $result = mysql_query($sql);
    $vObj = null;
    if ($result !== false) {
        $i = 0;
        $vObj = array();
        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
            $vObj[$i] = array();
            foreach ($row as $key => $value) {
                $vObj[$i][$key] = $value;
            }
            $i++;
        }
    }
    _dump($vObj);
}
<?php

use InoPerunApi\Client\ClientFactory;
use InoPerunApi\Manager\GenericManager;
include __DIR__ . '/_common.php';
$config = (require __DIR__ . '/_client_config.php');
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($config);
$usersManager = new GenericManager($client);
$usersManager->setManagerName('usersManager');
/*
$user = $usersManager->callMethod('getRichUserWithAttributes', array(
    'user' => 13521
));
*/
$user = $usersManager->getRichUserWithAttributes(array('user' => 13521));
_dump($user);
Exemple #6
0
 protected function toArray($entity, $includeNoUpdate = false, $includeNoInsert = false)
 {
     $toReturn = array();
     foreach ($this->fields as $f) {
         if (!$includeNoInsert && $f->getNoInsert()) {
             continue;
         }
         if (!$includeNoUpdate && $f->getNoUpdate()) {
             continue;
         }
         $getter = 'get' . ucfirst($f->getName());
         $v = $entity->{$getter}();
         _dump($v);
         $toReturn[$f->getNameInDB()] = $v;
     }
     return $toReturn;
 }
<?php

use InoOicClient\Flow\Basic;
require __DIR__ . '/../../init_autoload.php';
$config = (require __DIR__ . '/config.php');
$flow = new Basic($config);
if (!isset($_GET['redirect'])) {
    try {
        $uri = $flow->getAuthorizationRequestUri('user:email');
        _dump($uri);
        printf("<pre>%s</pre><br>", $uri);
        printf("<a href=\"%s\">Login</a>", $uri);
    } catch (\Exception $e) {
        _dump("{$e}");
        printf("Exception during authorization URI creation: [%s] %s", get_class($e), $e->getMessage());
    }
} else {
    try {
        $userInfo = $flow->process();
        printf("<pre>%s</pre>", print_r($userInfo, true));
    } catch (\Exception $e) {
        _dump("{$e}");
        printf("Exception during user authentication: <br><pre>%s</pre>", $e);
        echo "<br>";
        _dump($flow->getTokenDispatcher()->getLastHttpResponse()->getBody());
    }
}
    public function process()
    {
        $db = db::getInstance();
        $user = user::getInstance();
        include './models/game.class.php';
        // récupérer les paramètres
        $this->gameid = isset($_GET['gameid']) ? intval($_GET['gameid']) : false;
        $this->gridid = isset($_GET['gridid']) ? intval($_GET['gridid']) : false;
        $this->right_words = isset($_GET['right_words']) ? $_GET['right_words'] : false;
        $this->send = isset($_GET['send']) ? $_GET['send'] : false;
        if (!$this->gameid) {
            trigger_error('Sorry, no results available!', E_USER_ERROR);
        }
        if ($this->right_words) {
            // mise à jour des statuts des mots de la wordbox que l'apprenant connait
            foreach ($this->right_words as $word) {
                $sql = 'UPDATE wordbox
							SET wordboxstatus = 2
							WHERE userid = ' . intval($user->id) . '
							AND wordboxword = \'' . $word . '\'';
                $db->query($sql);
                _dump($sql);
            }
            return false;
        }
        // s'il y a plus de 10 mots dans la wordbox, faire l'exercice
        $sql = 'SELECT COUNT(*)
					FROM wordbox
					WHERE userid = ' . intval($user->id);
        $result = $db->query($sql);
        $row = $result->fetch_assoc();
        $count_wordbox = $row['COUNT(*)'];
        if ($count_wordbox < 10) {
            $this->redirect = true;
            return $this->display();
        }
        // lecture de la partie
        $this->game = new game();
        $this->game->read($this->gameid);
        // liste des grilles
        $this->gridtypes = array();
        switch ($this->game->gametype) {
            case GAMETYPE_BATTLE:
            case GAMETYPE_PRACTICE_FULL:
                $this->gridtypes = array(GRIDTYPE_ALLWORDS, GRIDTYPE_LONGEST, GRIDTYPE_CONSTRAINTS);
                break;
            case GAMETYPE_PRACTICE_ALLWORDS:
                $this->gridtypes = array(GRIDTYPE_ALLWORDS);
                break;
            case GAMETYPE_PRACTICE_LONGEST:
                $this->gridtypes = array(GRIDTYPE_LONGEST);
                break;
            case GAMETYPE_PRACTICE_CONSTRAINTS:
                $this->gridtypes = array(GRIDTYPE_CONSTRAINTS);
                break;
        }
        // obtenir le nombre de grilles terminées pour l'utilisateur
        $sql = 'SELECT COUNT(gridid) AS count_gridid
					FROM gamesstatus
					WHERE gameid = ' . intval($this->gameid) . '
						AND gridstatus = ' . intval(GRIDSTATUS_STARTED) . '
						AND userid = ' . intval($user->id);
        $result = $db->query($sql);
        $count_gridid = ($row = $result->fetch_assoc()) ? intval($row['count_gridid']) : 0;
        // dernière partie : le nombre de grilles terminées pour le user est égal au nombre de grille du type de partie
        $this->last_grid = $count_gridid == count($this->gridtypes);
        // mots trouvés par utilisateur
        $this->def_words = array();
        $this->users_words = array();
        $this->users_wordscount = array();
        $sql = 'SELECT userid, word, wordpoints, wordexists
					FROM gamesuserswords
					WHERE gameid = ' . intval($this->gameid) . '
						AND gridid = ' . intval($this->gridid) . '
						AND userid = ' . intval($user->id) . '
					ORDER BY userid, wordpoints DESC, word';
        $result = $db->query($sql);
        while ($row = $result->fetch_assoc()) {
            array_push($this->words_found, $row['word']);
        }
        foreach ($this->words_found as $word) {
            // recherche des mots que l'apprenant ne connait pas encore
            $sql = 'SELECT *
						FROM wordbox
						WHERE userid = ' . intval($user->id) . '
						AND wordboxword = \'' . $word . '\'
						AND (
							wordboxstatus = 0
							OR wordboxstatus = 1
							)
						AND wordboxlang = ' . $db->escape((string) $user->get_lang());
            $result = $db->query($sql);
            while ($row = $result->fetch_assoc()) {
                array_push($this->words_not_known, $word);
            }
        }
        if (!$this->words_not_known) {
            $this->redirect = true;
            return $this->display();
        }
        // ajouter les mots à l'exercice de définitions
        foreach ($this->words_not_known as $word) {
            $this->def_words[intval($user->id)][] = array('word' => $word);
            array_push($this->def_test_words, $word);
        }
        // mise à jour des statuts des mots de la wordbox si l'apprenant l'a trouvé dans la grille
        $sql = 'UPDATE wordbox
					SET wordboxstatus = 1
					WHERE userid = ' . intval($user->id) . '
					AND wordboxword = \'' . $row['word'] . '\'
					AND wordboxstatus = 0
					AND wordboxlang = \'it\'';
        $db->query($sql);
        $found = false;
        while ($found === false) {
            $found = true;
            $this->def_rand_words = array();
            $this->def_test_words_temp = $this->def_test_words;
            $sql = 'SELECT wordboxword
						FROM wordbox
						ORDER BY RAND()
						LIMIT 2';
            $result = $db->query($sql);
            while ($row = $result->fetch_assoc()) {
                array_push($this->def_rand_words, $row['wordboxword']);
                array_push($this->def_test_words_temp, $row['wordboxword']);
            }
            foreach ($this->def_rand_words as $rand_word) {
                foreach ($this->def_words[$user->id] as $key => $word) {
                    if ($word['word'] == $rand_word) {
                        $found = false;
                    }
                }
            }
        }
        shuffle($this->def_test_words_temp);
        $this->def_test_words = $this->def_test_words_temp;
        return $this->display();
    }
/**
 determine the mime type of an item
*/
function get_mime_type($dir, $item, $query = 'type')
{
    _debug(_dump($dir, $item, $query));
    switch (filetype(get_abs_item($dir, $item))) {
        case "dir":
            $mime_type = $GLOBALS["super_mimes"]["dir"][0];
            $image = $GLOBALS["super_mimes"]["dir"][1];
            break;
        case "link":
            $mime_type = $GLOBALS["super_mimes"]["link"][0];
            $image = $GLOBALS["super_mimes"]["link"][1];
            break;
        default:
            list($mime_type, $image, $type) = _get_used_mime_info($item);
            if ($mime_type != NULL) {
                _debug("found mime type {$mime_type}");
                break;
            }
            if (function_exists("is_executable") && @is_executable(get_abs_item($dir, $item)) || @eregi($GLOBALS["super_mimes"]["exe"][2], $item)) {
                $mime_type = $GLOBALS["super_mimes"]["exe"][0];
                $image = $GLOBALS["super_mimes"]["exe"][1];
            } else {
                // unknown file
                _debug("unknown file type ");
                $mime_type = $GLOBALS["super_mimes"]["file"][0];
                $image = $GLOBALS["super_mimes"]["file"][1];
            }
    }
    switch ($query) {
        case "img":
            return $image;
        case "ext":
            return $type;
        default:
            return $mime_type;
    }
}
Exemple #10
0
function _dump($mixed)
{
    //Array
    if (is_array($mixed)) {
        $arrKeys = array_keys($mixed);
        $rtn = "";
        $rtn .= HTMLOutput::getStyle("array", "#669900", "#99cc00", "#263300");
        $rtn .= HTMLOutput::getHead("array", "Array");
        for ($i = 0; $i < count($arrKeys); $i++) {
            $rtn .= HTMLOutput::getItem("array", $arrKeys[$i], _dump($mixed[$arrKeys[$i]]));
        }
        $rtn .= HTMLOutput::getBottom();
        return $rtn;
    } else {
        if (is_object($mixed) && method_exists($mixed, "dump")) {
            return $mixed->dump();
        } else {
            if (is_object($mixed)) {
                $className = get_class($mixed);
                $vars = get_class_vars($className);
                $methods = get_class_methods($mixed);
                $rtn = "";
                $rtn .= HTMLOutput::getStyle("object", "#b09300", "#f0cc02", "#3f3100");
                $rtn .= HTMLOutput::getHead("object", $className);
                // vars
                /*$rtn.= HTMLOutput::getBigRow("object","Vars(s)");
                		if($vars)
                		for($i=0;$i<count($vars);$i++)	{
                			$rtn.= HTMLOutput::getItem("object","String", $vars[$i]);
                		}*/
                // methods
                //$rtn.= HTMLOutput::getBigRow("object","Method(s)");
                for ($i = 0; $i < count($methods); $i++) {
                    $rtn .= HTMLOutput::getRow("object", $methods[$i] . "()");
                }
                $rtn .= HTMLOutput::getBottom();
                return $rtn;
            } else {
                if (is_bool($mixed)) {
                    $rtn = "";
                    $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                    $rtn .= HTMLOutput::smallHead("simple");
                    $rtn .= HTMLOutput::getItem("simple", "boolean", $mixed ? "yes" : "no");
                    $rtn .= HTMLOutput::getBottom();
                    return $rtn;
                } else {
                    if (is_numeric($mixed)) {
                        $rtn = "";
                        $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                        $rtn .= HTMLOutput::smallHead("simple");
                        $rtn .= HTMLOutput::getItem("simple", "numeric", $mixed);
                        $rtn .= HTMLOutput::getBottom();
                        return $rtn;
                    } else {
                        $rtn = "";
                        $rtn .= HTMLOutput::getStyle("simple", "#ff4400", "#ff954f", "#4f1500");
                        $rtn .= HTMLOutput::smallHead("simple");
                        $rtn .= HTMLOutput::getItem("simple", "String", $mixed);
                        $rtn .= HTMLOutput::getBottom();
                        return $rtn;
                    }
                }
            }
        }
    }
}
Exemple #11
0
 public function update($entity, $broadcastEvents = true)
 {
     $pk = $this->getPk();
     if (is_null($pk)) {
         throw new \LogicException(sprintf('Trying to update entity "%s" with no Primary Key defined', $this->getEntityClass()));
     }
     if (method_exists($entity, 'ormBeforeUpdate')) {
         $entity->ormBeforeUpdate();
     }
     $eventManager = null;
     $eventName = '';
     if ($broadcastEvents) {
         $eventName = str_replace('\\', '.', $this->getEntityClass());
         $eventManager = Registry::get('Velox.EventManager');
         $eventManager->broadcast(new Event($eventName . '.BeforeUpdate', $entity));
     }
     $a = $this->castToDbArray($entity);
     // broadcast event
     $assignments = array();
     foreach ($this->fields as $f) {
         if ($f->isNoUpdate()) {
             continue;
         }
         $propName = $f->getPropName();
         if (is_null($a[$propName]) && !$f->getIsNullable()) {
             throw new Exception\NullValueException(sprintf('Updating not nullable "%s" property of "%s" with null.', $propName, $this->getEntityClass()));
         }
         if (is_null($a[$propName])) {
             $assignments[] = $f->getSql($this->getTableName()) . '=NULL';
         } else {
             $assignments[] = $f->getSql($this->getTableName()) . '=' . $this->dbDriver->escape($a[$propName]);
         }
     }
     $q = sprintf('UPDATE `%s` SET %s WHERE %s', $this->getTableName(), implode(', ', $assignments), $pk->getSql($this->getTableName()) . '=' . $this->dbDriver->escape($a[$pk->getPropName()]));
     $q = $this->prepare($q);
     if ($this->dumpQueryOnce) {
         $this->dumpQueryOnce = false;
         _dump($q);
     }
     $toReturn = $this->dbDriver->update($q);
     if (method_exists($entity, 'ormAfterUpdate')) {
         $entity->ormAfterUpdate();
     }
     if ($broadcastEvents) {
         $eventManager->broadcast(new Event($eventName . '.AfterUpdate', $entity));
     }
     return $toReturn;
 }
$client->resetParameters();
$client->setMethod('POST');
$request = new \Zend\Http\Request();
$request->setUri($tokenUri);
$request->setMethod('POST');
$request->getPost()->fromArray(array('grant_type' => 'authorization_code', 'code' => $data['code'], 'redirect_uri' => 'https://dummy', 'client_id' => $clientId));
// Client authentication
$request->getHeaders()->addHeaders(array('Authorization' => $clientAuthorization));
_dumpRequest($request);
$client->setMethod('POST');
$response = $client->send($request);
_dumpResponse($response);
$tokenData = \Zend\Json\Json::decode($response->getContent(), \Zend\Json\Json::TYPE_ARRAY);
_dump($tokenData);
if (isset($tokenData['error'])) {
    die("ERROR\n");
}
/*
 * User info request
 */
$request = new \Zend\Http\Request();
$request->setUri($userInfoUri);
$request->getQuery()->fromArray(array('schema' => 'openid'));
$request->getHeaders()->addHeaders(array('Authorization' => sprintf("Bearer %s", $tokenData['access_token'])));
_dumpRequest($request);
$client->setMethod('GET');
$response = $client->send($request);
_dumpResponse($response);
$userData = \Zend\Json\Json::decode($response->getContent(), \Zend\Json\Json::TYPE_ARRAY);
_dump($userData);
<?php

use InoPerunApi\Client\ClientFactory;
include __DIR__ . '/_common.php';
$config = (require __DIR__ . '/_client_config.php');
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($config);
/*
 * $manager = 'usersManager'; $method = 'getUserByExtSourceNameAndExtLogin'; $params = array( 'extSourceName' =>
 * 'https://whoami.cesnet.cz/idp/shibboleth', 'extLogin' => '*****@*****.**' ); $changeState = true;
 */
$manager = 'groupsManager';
$method = 'createGroup';
$params = array('vo' => 421, 'group' => array('name' => 'Test group'));
$changeState = true;
try {
    $perunResponse = $client->sendRequest($manager, $method, $params, $changeState);
} catch (\Exception $e) {
    _dump("{$e}");
    // exit();
}
_dump($client->getHttpClient()->getLastRawRequest());
_dump($client->getHttpClient()->getLastRawResponse());
_dump($perunResponse);
Exemple #14
0
<?php

/**
* 测试首页
*
* @author    indraw <*****@*****.**>
* @version   1.0
* @copyright 商业软件,受著作权保护
* @link      http://***
* @create     2007/2/9 下午
*/
//包含配置
include_once 'includes/LibConfig.inc.php';
/*--------------------------------------------------------*/
//简单流程
if ($_SESSION['username']) {
    $sUserName = $_SESSION['username'];
} else {
    $sUserName = "******";
}
//模板调用
$oSmarty->assign("username", $sUserName);
$oSmarty->display("index.htm");
//调试信息
_dump($_SESSION);
/*--------------------------------------------------------*/
 /**
  * Recupère la ressource
  *
  * @throws CopixResourceForbiddenException si l'accès à la ressource est interdit,
  *         CopixResourceNotFoundException si la ressource n'a pas été trouvée.
  */
 public function fetch()
 {
     // Vérifie qu'on ait pas de "backward"
     $unescapedPath = utf8_decode($this->_path);
     // Pas de blague avec l'UTF8
     if (preg_match('@\\.\\.[/\\\\]@', $unescapedPath)) {
         throw new CopixResourceForbiddenException($this->_path);
     }
     // Vérifie l'existence du theme
     if (!$this->_theme || !is_dir('themes/' . $this->_theme)) {
         throw new CopixResourceNotFoundException($this->_theme);
     }
     $arModules = $this->_getArModules();
     // Si on a bien un module
     if ($this->_module) {
         // Vérifie l'existence du module
         if (isset($arModules[$this->_module])) {
             $this->_modulePath = $arModules[$this->_module] . $this->_module . '/';
         } else {
             throw new CopixResourceNotFoundException($this->_module);
         }
         // Vérifie l'existence du chemin 'www' du module
         if (!is_dir($this->_modulePath . "www")) {
             throw new CopixResourceNotFoundException($this->_module);
         }
     }
     // Récupère la config
     $config = $this->_getCopixConfig();
     // Recherche le fichier
     if (!($filePath = CopixResource::findResourcePath($this->_path, $this->_module, $this->_modulePath, $this->_theme, $config->i18n_path_enabled, $this->_lang, $this->_country))) {
         throw new CopixResourceNotFoundException($this->_path);
     }
     // Récupère le type MIME
     $mimeType = CopixMIMETypes::getFromFileName($filePath);
     // La substitution ne touche que les fichiers des modules
     if ($this->_modulePath && substr($filePath, 0, strlen($this->_modulePath)) == $this->_modulePath) {
         $filePath = $this->_processModuleFile($filePath, $mimeType);
     }
     // Mode DEBUG ?
     if (isset($_REQUEST['DEBUG'])) {
         _dump(array('this' => $this, 'filePath' => $filePath, 'mimeType' => $mimeType, 'included_files' => get_included_files()));
         exit;
     }
     // Envoie le fichier
     $this->_sendFile($filePath, $mimeType);
 }
            $userInfoRequest = new UserInfo\Request();
            $userInfoRequest->setAccessToken($tokenResponse->getAccessToken());
            $userInfoRequest->setClientInfo($clientInfo);
            $userInfoDispatcher = new UserInfo\Dispatcher($httpClient);
            try {
                $userInfoResponse = $userInfoDispatcher->sendUserInfoRequest($userInfoRequest);
                _dump($userInfoResponse->getClaims());
                printf("User info: %s", \Zend\Json\Json::encode($userInfoResponse->getClaims(), \Zend\Json\Json::TYPE_ARRAY));
            } catch (\Exception $e) {
                printf("Error: [%s] %s<br>", get_class($e), $e->getMessage());
                _dump("{$e}");
            }
            _dump($httpClient);
        } catch (\Exception $e) {
            printf("Error: [%s] %s<br>", get_class($e), $e->getMessage());
            _dump("{$e}");
        }
    } catch (ErrorResponseException $e) {
        $error = $e->getError();
        printf("Error: %s<br>Description: %s<br>", $error->getCode(), $error->getDescription());
    } catch (StateException $e) {
        printf("State exception:<br>%s", $e);
    } catch (\Exception $e) {
        _dump("{$e}");
    }
}
function _createHttpClient()
{
    $httpClientFactory = new ClientFactory();
    return $httpClientFactory->createHttpClient();
}
<?php

use InoPerunApi\Client\ClientFactory;
use InoPerunApi\Entity\Group;
use InoPerunApi\Manager\GenericManager;
include __DIR__ . '/_common.php';
$config = (require __DIR__ . '/_client_config.php');
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($config);
$groupsManager = new GenericManager($client);
$groupsManager->setManagerName('groupsManager');
$group = new Group();
$group->setName('New test group 5');
$group->setParentGroupId(3141);
try {
    $newGroup = $groupsManager->createGroup(array('vo' => 421, 'group' => $group), true);
} catch (\Exception $e) {
    _dump("{$e}");
}
_dump($client->getHttpClient()->getLastRawRequest());
_dump($client->getHttpClient()->getLastRawResponse());
_dump($newGroup);
Exemple #18
0
<?php

use InoPerunApi\Client\ClientFactory;
include __DIR__ . '/_common.php';
$config = (require __DIR__ . '/_client_config.php');
$clientFactory = new ClientFactory();
$client = $clientFactory->createClient($config);
try {
    $perunResponse = $client->sendRequest('usersManager', 'getUserById', array('id' => 13793));
} catch (\Exception $e) {
    _dump("{$e}");
    exit;
}
if ($perunResponse->isError()) {
    printf("Perun error [%s]: %s (%s)\n", $perunResponse->getErrorId(), $perunResponse->getErrorType(), $perunResponse->getErrorMessage());
}
_dump($client->getHttpClient()->getLastRawRequest());
_dump($client->getHttpClient()->getLastRawResponse());
_dump($perunResponse);
$payload = $perunResponse->getPayload();
_dump($payload->getParam('firstName'));
 /**
  * Handles an exception - returns an error.
  * 
  * @param \Exception $e
  * @param string $label
  */
 protected function handleException(\Exception $e, $label = 'Exception')
 {
     _dump("{$e}");
     return $this->handleError(sprintf("%s: [%s] %s", $label, get_class($e), $e->getMessage()));
 }