Example #1
0
 public function executeApi(sfWebRequest $request)
 {
     $data = RestUtils::processRequest();
     $res = "";
     $code = 200;
     try {
         switch ($data->getMethod()) {
             case 'get':
                 $method = $request->getParameter('method');
                 $res = $this->{$method}($data);
                 break;
             case 'post':
                 //parse_str(file_get_contents('php://input'), $put_vars);
                 $method = "post_" . $request->getParameter('method', 'review');
                 $res = $this->{$method}($data);
                 break;
         }
     } catch (BadRequestException $e) {
         $res = $e->getMessage();
         $code = 400;
     } catch (Exception $e) {
         $res = $e->getMessage();
         $code = 500;
     }
     RestUtils::sendResponse($code, json_encode($res), 'application/json');
 }
Example #2
0
 public function action_preview_syllabus()
 {
     return false;
     # This needs to be revamped, but the coding for previews is still usable.
     $rest = new RestServer();
     $request = RestUtils::processRequest();
     $required = array("filename", "dept");
     $keys = array_keys($request);
     if (count(array_intersect($required, $keys)) != count($required)) {
         return RestUtils::sendResponse(308);
     }
     if (isset($_REQUEST["filename"], $_REQUEST["dept"])) {
         $width = isset($_REQUEST["w"]) ? $_REQUEST["w"] : 600;
         $height = isset($_REQUEST["h"]) ? $_REQUEST["h"] : 300;
         $dept = $_REQUEST["dept"];
         $filename = $_REQUEST["filename"];
         $user = Yii::app()->user->getState("_user");
         if (!$user->has_permission($dept)) {
             return print "You do not have permission to view this syllabus.";
         }
         $file = "C:/archive/" . $dept . "/" . $filename;
         $pathinfo = pathinfo($file);
         if ($pathinfo["extension"] == "pdf") {
             return print '<embed src="http://compass.colorado.edu/archive/' . $dept . '/' . $filename . '#view=FitH" width="' . $width . 'px" height="' . $height . 'px"/>';
         } elseif ($pathinfo["extension"] == "doc" or $pathinfo["extension"] == "docx") {
             return print '<iframe src="//docs.google.com/viewer?url=http%3A%2F%2Fcompass.colorado.edu%2Farchive%2F' . $dept . '%2F' . $filename . '&embedded=true" width="' . $width . 'px" height="' . $height . '" style="border: none;"></iframe>';
         } elseif ($pathinfo["extension"] == "txt" or $pathinfo["extension"] == "html") {
             return print file_get_contents($file);
         }
         return print "";
     }
     $syllabus = new SyllabusObj(@$_REQUEST["sid"]);
     if (!$syllabus->loaded) {
         return print "Could not load syllabus with id: " . $_REQUEST["sid"];
     }
     $class = new ClassObj($syllabus->classid);
     if (!$syllabus->loaded) {
         return print "Could not load class with id: " . $syllabus->classid;
     }
     $width = isset($_REQUEST["w"]) ? $_REQUEST["w"] - 50 : 600;
     $height = isset($_REQUEST["h"]) ? $_REQUEST["h"] - 70 : 300;
     if ($syllabus->type == "pdf") {
         return print '<embed src="http://compass.colorado.edu/archive/' . $class->course->prefix . '/' . $syllabus->filename . '#view=FitH" width="' . $width . 'px" height="' . $height . 'px"/>';
     } elseif ($syllabus->type == "doc" or $syllabus->type == "docx") {
         return print '<iframe src="//docs.google.com/viewer?url=http%3A%2F%2Fcompass.colorado.edu%2Farchive%2F' . $class->course->prefix . '%2F' . $syllabus->filename . '&embedded=true" width="' . $width . 'px" height="' . $height . '" style="border: none;"></iframe>';
     }
     return print "";
 }
Example #3
0
 public function actionFBLookup()
 {
     $rest = new RestServer();
     $request = RestUtils::processRequest();
     $required = array("q");
     $keys = array_keys($request);
     if (count(array_intersect($required, $keys)) != count($required)) {
         return RestUtils::sendResponse(308);
     }
     # The Directory we're connecting with is the Active Directory for the Campus
     # (not to be confused with this application's name)
     $ldap = new ADAuth("directory");
     $ldap->bind_anon();
     $info = $ldap->lookup_user($request["q"]);
     if ($info["count"] == 0) {
         return print json_encode(array());
     }
     return print json_encode(array($request["attribute"] => @$info[0][$request["attribute"]][0]));
 }
Example #4
0
include 'rest.class.php';
ini_set('error_reporting', E_ALL);
set_error_handler('myErrorHandler');
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
    $report = "Error Number: {$errno}<br/>\n\tError: {$errstr}<br/>\n\tFile: {$errfile}<br/>\n\tLine: {$errline}";
    RestUtils::error(500, $report);
}
include 'db.class.php';
include 'Resource.class.php';
include 'System.class.php';
include 'Profiles.class.php';
include 'Contacts.class.php';
include 'Groups.class.php';
include 'Conversations.class.php';
$request = RestUtils::processRequest();
switch (strtolower($request->getElement())) {
    case 'restsystem':
        $element = new System($request);
        break;
    case 'restprofiles':
        $element = new Profiles($request);
        break;
    case 'restgroups':
        $element = new Groups($request);
        break;
    case 'restcontacts':
        $element = new Contacts($request);
        break;
    case 'restconversations':
        $element = new Conversations($request);
<?php

include 'outilEtRequete.php';
header("Content-Type: 'text/html'; charset=utf8");
$data = RestUtils::processRequest();
try {
    $requete = $_GET['action'];
    switch ($requete) {
        case "similaire":
            $resultatGlobal = searchSimilaire();
            break;
        case "all":
            $resultatGlobal = searchPodcast(true);
            break;
        case "sans100":
            $resultatGlobal = searchPodcast(false, false);
            break;
        case "list":
        default:
            $resultatGlobal = searchPodcast(false);
            break;
    }
} catch (Exception $e) {
    // En cas d'erreur précédemment, on affiche un message et on arrête tout
    die('Erreur : ' . $e->getMessage());
}
switch ($data->getMethod()) {
    case 'get':
        RestUtils::sendResponse(200, json_encode($resultatGlobal, JSON_HEX_APOS), 'application/json');
        break;
    case 'post':
Example #6
0
<?php
include 'tagger/conf.php';
include 'rest/RestUtils.inc.php';
include 'access/iplog.php';

$controller = RestUtils::processRequest();

?>
Example #7
0
<?php

// SET PREPEND AND CREATE REST UTILITIES CLASS
require '../share/qcodo/includes/prepend.inc.php';
require 'classes/RestUtils.class.php';
require 'classes/ResourceUtils.class.php';
$objREST = RestUtils::processRequest();
if (QApplication::PathInfo(0) != '') {
    // IS SPECIFIED RESOURCE VALID
    $strResourceName = ucwords(QApplication::PathInfo(0));
    $objResource = new $strResourceName();
    if (!is_object($objResource)) {
        RestUtils::sendResponse('ERROR:  This resource was not found', 404);
    }
    // IS VALID RESOURCE ID
    if (QApplication::PathInfo(1) != '') {
        $intResourceID = QApplication::PathInfo(1);
    } else {
        $intResourceID = null;
    }
    // DOES SECONDARY RESOURCE EXIST
    if (QApplication::PathInfo(2) != '') {
        $strSecondResource = ucwords(QApplication::PathInfo(2));
    } else {
        $strSecondResource = null;
    }
} else {
    RestUtils::sendResponse('ERROR:  This resource was not found', 404);
}
switch ($objREST->getMethod()) {
    // GET
 function __construct()
 {
     // for the page execution time in the debug.
     $this->time_start = microtime(true);
     $this->requestData = RestUtils::processRequest();
     // get the path array - e.g. /home/about-us/welcome
     $this->pathArray = $this->requestData->getPathArray();
     $this->requestVars = $this->requestData->getRequestVars();
     $this->pageRequested = end($this->pathArray);
     // TO DO - merge in the REST UTILS? It's not rest anymore too!?
     /* 
     1.  First check if we have an entry for the page path 
     2.  If exists then check the cache - TODO
     3.  Otherwise build the page from the DB
     4.  Write this out and add to cache if cacheable - TODO
     
     Creating a page
     1.  Get the template 
     2.  Get all data for the page
     3.  Run it through the template engine
     */
     // 1. Check cache
     if (CACHE_ENABLED) {
         $cache = new CMSCache($this->pathArray);
         if ($cache->inCache) {
             $outputContent = $cache->cacheItem->content;
             $debug = false;
             if (isset($this->requestVars['debug']) && DEBUG) {
                 $debug = TRUE;
             }
             if ($debug === TRUE) {
                 // Get time for page creation execution time
                 $time_end = microtime(true);
                 $timeTaken = $time_end - $this->time_start;
                 $debugText = "\t<div id='debug' style='background: #ffdd00; color: #333; font-size: 12px !important; line-height: 1.62em;'>\n\t\t\t\t\t\t<table>\n\t\t\t\t\t\t<tr><td><b>CACHE HIT:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Cache created:</b></td><td>" . $cache->cacheItem->created . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Cache expires:</b></td><td>" . $cache->cacheItem->expiry . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Path Requested:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Page Requested:</b></td><td>" . htmlentities($this->pageRequested, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Request Variable:</b></td><td>" . htmlentities(print_r($this->requestVars, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t\t\t<tr><td><b>Time Taken:</b></td><td>{$timeTaken}</td></tr>\n\t\t\t\t\t\t</table>\n\t\t\t\t\t</div>";
                 $outputContent = $this->addDebugToBody($outputContent, $debugText);
             }
             RestUtils::sendResponse(200, $outputContent, 'text/html');
         }
     }
     $cms = new CMSHelper();
     $cms->checkPage($this->pathArray);
     switch ($cms->pageType) {
         case 'notfound':
             // Gets the 404 from a text file (not using a CMS node for added safety ? - Perhaps this needs changing)
             $fourohfour = file_get_contents('fourohfour.html', true);
             RestUtils::sendResponse(404, $fourohfour, 'text/html');
             break;
         case '301redirect':
             RestUtils::sendResponse(301, $cms->pagePath, 'text/html');
             break;
         case '302redirect':
             RestUtils::sendResponse(302, $cms->pagePath, 'text/html');
             break;
         case 'module':
             $module = new Module($cms->module);
             $output = $module->output;
             RestUtils::sendResponse(200, $output, 'text/html');
             break;
         case 'sitemap':
             // this might need to be done differently with different languages
             $sitemapBody = $cms->getSitemap();
             RestUtils::sendResponse(200, $sitemapBody, 'text/xml');
             break;
             //case 'cached':
             //	$replacedOutput =
         //case 'cached':
         //	$replacedOutput =
         case 'wildcard':
             // pretty much the same logic as the default normal pages but cached differently?
             // normal pages assumed!
         // pretty much the same logic as the default normal pages but cached differently?
         // normal pages assumed!
         default:
             // get the data and build the page
             // if getPage returns false it's a new page not yet published - 404 instead of error
             if (!$cms->getPage($this->pathArray, $this->requestVars)) {
                 // Gets the 404 from a text file (not using a CMS node for added safety ? - Perhaps this needs changing)
                 $fourohfour = file_get_contents('fourohfour.html', true);
                 RestUtils::sendResponse(404, $fourohfour, 'text/html');
             }
             $debug = false;
             if (isset($this->requestVars['debug']) && DEBUG) {
                 $debug = TRUE;
             }
             $replacedOutput = $cms->createPage();
             // store to cache// TODO - check if the page is allowed to be cacheable
             $pageCacheable = !$cms->page['noCache'];
             if (CACHE_ENABLED && $pageCacheable) {
                 $cache->writeCache($replacedOutput);
             }
             if ($debug === TRUE) {
                 // Get time for page creation execution time
                 $time_end = microtime(true);
                 $timeTaken = $time_end - $this->time_start;
                 $debugText = "\t<div id='debug' style='background: #ffdd00; color: #333; font-size: 12px !important; line-height: 1.62em;'>\n\t\t\t\t<table>\n\t\t\t\t<tr><td><b>Path Requested:</b></td><td>" . htmlentities(print_r($this->pathArray, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Requested:</b></td><td>" . htmlentities($this->pageRequested, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Node:</b></td><td>" . htmlentities($cms->nodeID, ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Data:</b></td><td>" . htmlentities(print_r($cms->page, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Request Variable:</b></td><td>" . htmlentities(print_r($this->requestVars, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Fields in template:</b></td><td>" . htmlentities(print_r($cms->fieldsFound, 1), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Page Content:</b></td><td>" . htmlentities(print_r($cms->page, 1)) . "</td></tr>\n\t\t\t\t<tr><td><b>Related Pages:</b></td><td>" . substr(htmlentities($cms->relatedNodeIDsStr, ENT_QUOTES, 'ISO-8859-1'), 0, 1000) . "</td></tr>\n\t\t\t\t<tr><td><b>Other Page Content:</b></td><td>" . substr(htmlentities(print_r($cms->relatedContent, 1), ENT_QUOTES, 'ISO-8859-1'), 0, 1000) . "</td></tr>\n\t\t\t\t<tr><td><b>Page Sections:</b></td><td>" . htmlentities(substr(print_r($cms->sections, 1), 0, 1000), ENT_QUOTES, 'ISO-8859-1') . "</td></tr>\n\t\t\t\t<tr><td><b>Time Taken:</b></td><td>{$timeTaken}</td></tr>\n\t\t\t\t</table>\n\t\t\t</div>";
                 $replacedOutput = $this->addDebugToBody($replacedOutput, $debugText);
             }
             RestUtils::sendResponse(200, $replacedOutput, 'text/html');
             break;
     }
 }
Example #9
0
 public function actionDepartmentName()
 {
     $rest = new RestServer();
     $request = RestUtils::processRequest();
     if ($this->has_required($request, array('deptcode'))) {
         extract($request);
     } else {
         return RestUtils::sendResponse(308);
     }
     $return = array();
     $deptname = Yii::app()->db->createCommand()->select('label as deptname')->from('ascore_departments')->where('id = :id', array(':id' => $deptcode))->order('id ASC')->queryScalar();
     return print json_encode($deptname);
 }