示例#1
0
/**
 * Reads a file
 * <pre>
 *  * file : path or URI of the file to read (however reading from another website is not recommended for performance reasons)
 *  * assign : if set, the file will be saved in this variable instead of being output
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.1.0
 * @date       2009-07-18
 * @package    Dwoo
 */
function Dwoo_Plugin_fetch(Dwoo $dwoo, $file, $assign = null)
{
    if ($file === '') {
        return;
    }
    if ($policy = $dwoo->getSecurityPolicy()) {
        while (true) {
            if (preg_match('{^([a-z]+?)://}i', $file)) {
                return $dwoo->triggerError('The security policy prevents you to read files from external sources.', E_USER_WARNING);
            }
            $file = realpath($file);
            $dirs = $policy->getAllowedDirectories();
            foreach ($dirs as $dir => $dummy) {
                if (strpos($file, $dir) === 0) {
                    break 2;
                }
            }
            return $dwoo->triggerError('The security policy prevents you to read <em>' . $file . '</em>', E_USER_WARNING);
        }
    }
    $file = str_replace(array("\t", "\n", "\r"), array('\\t', '\\n', '\\r'), $file);
    $out = file_get_contents($file);
    if ($assign === null) {
        return $out;
    }
    $dwoo->assignInScope($out, $assign);
}
示例#2
0
 function main($itsp)
 {
     $itsp->bLang->setLanguage($_GET["lang"]);
     include_once "dwoo/dwooAutoload.php";
     $params = array();
     $params["lang"] = "dk";
     $params["screen"] = "newUser";
     $newUserUrl = $itsp->bUrl->newUrl("newuser", $params, 0, 0);
     $params = array();
     $screenshoturl = $itsp->bUrl->newUrl("screenshots", $params, 0, 0);
     $params = array();
     $loginUrl = $itsp->bUrl->newUrl("home", $params);
     $tpl = new Dwoo_Template_File('templates/frontpage.tpl');
     $dwoo = new Dwoo();
     $jsfiles = array();
     $jsfiles[] = array('jsfile' => 'js/newuser.js');
     $markerArray = templateArray();
     $markerArray["headertitle"] = $itsp->bLang->getLL("title") . " frontpage";
     $markerArray["username"] = $itsp->bLang->getLL("username");
     $markerArray["password"] = $itsp->bLang->getLL("password");
     $markerArray["title"] = "myTasks frontpage";
     $markerArray["loginbtn"] = "Login";
     $markerArray["createNewUser"] = $itsp->bLang->getLL("createNewUser");
     $markerArray["url"] = $newUserUrl;
     $markerArray["loginUrl"] = $loginUrl;
     $markerArray["js_list"] = $jsfiles;
     $markerArray["screenshoturl"] = $screenshoturl;
     $output = $dwoo->get($tpl, $markerArray);
     print $output;
 }
/**
 * Dwoo {str} function plugin
 *
 * Type:     function<br>
 * Name:     str<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Fetch internationalized strings
 * @author   Catalyst IT Ltd
 * @version  1.0
 * @return Internationalized string
 */
function Dwoo_Plugin_str(Dwoo $dwoo, $tag, $section = 'mahara', $args = null, $arg1 = null, $arg2 = null, $arg3 = null, $assign = null)
{
    static $dictionary;
    $params = array($tag, $section);
    if ($args) {
        if (!is_array($args)) {
            $args = array($args);
        }
        $params = array_merge($params, $args);
    } else {
        if (isset($arg1)) {
            foreach (array('arg1', 'arg2', 'arg3') as $k) {
                if (isset(${$k})) {
                    $params[] = ${$k};
                }
            }
        }
    }
    $ret = call_user_func_array('get_string', $params);
    // If there is an 'assign' parameter, place it into that instead.
    if (!empty($assign)) {
        $dwoo->assignInScope($ret, $assign);
        return;
    }
    return $ret;
}
示例#4
0
 /**
  * {@inheritdoc}
  */
 public function render($viewName, Model $model, NotificationCenter $notificationCenter, $output = true)
 {
     Profile::start('Renderer', 'Generate HTML');
     $templateName = $viewName . '.' . static::$templateFileExtension;
     $dwoo = new Dwoo($this->compiledPath, $this->cachePath);
     $dwoo->getLoader()->addDirectory($this->functionsPath);
     Profile::start('Renderer', 'Create template file.');
     $template = new Dwoo_Template_File($templateName);
     $template->setIncludePath($this->getTemplatesPath());
     Profile::stop();
     Profile::start('Renderer', 'Render');
     $dwooData = new Dwoo_Data();
     $dwooData->setData($model->getData());
     $dwooData->assign('errorMessages', $notificationCenter->getErrors());
     $dwooData->assign('successMessages', $notificationCenter->getSuccesses());
     $this->setHeader('Content-type: text/html', $output);
     // I do never output directly from dwoo to have the possibility to show an error page if there was a render error.
     $result = $rendered = $dwoo->get($template, $dwooData, null, false);
     if ($output) {
         echo $result;
     }
     Profile::stop();
     Profile::stop();
     return $output ? null : $rendered;
 }
 function main($itsp)
 {
     include_once "dwoo/dwooAutoload.php";
     $displayNewUserForm = 1;
     $emailsent = "";
     $reset = $itsp->bUrl->getGP("s");
     $username = $itsp->bUrl->getGP("u");
     $showform = 1;
     $errormsg = "";
     if ($_POST["reset"]) {
         include_once "user_backend.php";
         $user = new user_backend("reset");
         if ($user->setNewPassword($_POST["reset"], $_POST["password"])) {
             $showform = 0;
             $tpl = new Dwoo_Template_File('templates/setnewpassword1.tpl');
             $dwoo = new Dwoo();
             $markerArray = templateArray();
             $output = $dwoo->get($tpl, $markerArray);
             print $output;
             exit;
         } else {
             $errormsg = "Please enter a valid password";
         }
     }
     if ($reset != "" && $username != "" && $showform) {
         $tpl = new Dwoo_Template_File('templates/setnewpassword.tpl');
         $dwoo = new Dwoo();
         $markerArray = templateArray();
         $markerArray["url"] = $_SERVER["REQUEST_URI"];
         $markerArray["reset"] = $reset;
         $markerArray["errormsg"] = $errormsg;
         $output = $dwoo->get($tpl, $markerArray);
         print $output;
     }
 }
示例#6
0
 public function getData()
 {
     $this->check_permission();
     //get global_lib Singelton
     $mainlib = global_lib::getInstance();
     //Create path of Controller Files   =>  controller/FILENAME.php
     $path = $mainlib->joinPaths("controller/", $this->meta_data["main_file"] . ".php");
     try {
         //Include Controller File
         include_once $path;
     } catch (Exception $e) {
         //Exception
         var_dump($e);
     }
     try {
         //Call Class from Controller File
         $web_call = new $this->meta_data["main_class"]($this->request);
         //Request Type (Method) to Lowercase
         $method_call = strtolower($this->request->method);
         //Rufe die methode im Class File auf
         $web_call->{$method_call}();
         // Generiere Variablen für die Template Engine
         $template_engine_var = $web_call->get_context();
         // Generiere für das Template den Pfad
         $template_path = $mainlib->joinPaths("view/", $web_call->template . ".html");
         // Lade Dwoo Template Engine
         $dwoo = new Dwoo();
         // Compare get_context and template
         $dwoo->output($template_path, $template_engine_var);
     } catch (Exception $e) {
         var_dump($e);
     }
 }
/**
 * Dwoo {contextualhelp} function plugin
 *
 * Type:     function<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Provide inline contextual help for arbitrary sections
 * @author   Catalyst IT Ltd
 * @version  1.0
 * @return HTML snippet for help icon
 */
function Dwoo_Plugin_contextualhelp(Dwoo $dwoo, $plugintype, $pluginname, $form = null, $element = null, $section = null, $assign = null)
{
    $ret = call_user_func_array('get_help_icon', array($plugintype, $pluginname, $form, $element, null, $section));
    // If there is an 'assign' parameter, place it into that instead.
    if ($assign) {
        $dwoo->assignInScope($ret, $assign);
        return;
    }
    return $ret;
}
示例#8
0
 function main($itsp)
 {
     include "dwoo/dwooAutoload.php";
     $tpl = new Dwoo_Template_File('templates/screenshots.tpl');
     $dwoo = new Dwoo();
     $markerArray = templateArray();
     $markerArray["title"] = "screenshots";
     $output = $dwoo->get($tpl, $markerArray);
     print $output;
 }
示例#9
0
 function GenerateModLogRSS()
 {
     global $tc_db;
     require_once KU_ROOTDIR . 'lib/dwoo.php';
     $dwoo = new Dwoo();
     $dwoo_data = new Dwoo_Data();
     $entries = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "modlog` ORDER BY `timestamp` DESC LIMIT 15");
     $dwoo_data->assign('entries', $entries);
     $rss = $dwoo->get(KU_TEMPLATEDIR . '/rss_mod.tpl', $dwoo_data);
     return $rss;
 }
示例#10
0
 public function testRebuildClassPath()
 {
     $dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR);
     $loader = new Dwoo_Loader(TEST_DIRECTORY . '/temp/cache');
     $dwoo->setLoader($loader);
     $loader->addDirectory(TEST_DIRECTORY . '/resources/plugins');
     file_put_contents(TEST_DIRECTORY . '/resources/plugins/loaderTest2.php', '<?php function Dwoo_Plugin_loaderTest2(Dwoo $dwoo) { return "It works!"; }');
     $tpl = new Dwoo_Template_String('{loaderTest2}');
     $tpl->forceCompilation();
     $this->assertEquals('It works!', $dwoo->get($tpl, array(), $this->compiler));
     unlink(TEST_DIRECTORY . '/resources/plugins/loaderTest2.php');
 }
示例#11
0
 function main($itsp)
 {
     include "dwoo/dwooAutoload.php";
     $tpl = new Dwoo_Template_File('templates/error.tpl');
     $dwoo = new Dwoo();
     $markerArray = templateArray();
     $markerArray["title"] = $itsp->bLang->getLL("page.error.title");
     $markerArray["pagenotfound"] = $itsp->bLang->getLL("page.error.pagenotfound");
     $markerArray["goback"] = $itsp->bLang->getLL("page.error.goback");
     $output = $dwoo->get($tpl, $markerArray);
     print $output;
 }
示例#12
0
/**
 * Evaluates the given string as if it was a template
 *
 * Although this plugin is kind of optimized and will
 * not recompile your string each time, it is still not
 * a good practice to use it. If you want to have templates
 * stored in a database or something you should probably use
 * the Dwoo_Template_String class or make another class that
 * extends it
 * <pre>
 * * var : the string to use as a template
 * * assign : if set, the output of the template will be saved in this variable instead of being output
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author	Jordi Boggiano <*****@*****.**>
 * @copyright Copyright (c) 2008, Jordi Boggiano
 * @license	http://dwoo.org/LICENSE Modified BSD License
 * @link	http://dwoo.org/
 * @version	1.0.0
 * @date	2008-10-23
 * @package	Dwoo
 */
function Dwoo_Plugin_eval(Dwoo $dwoo, $var, $assign = null)
{
    if ($var == '') {
        return;
    }
    $tpl = new Dwoo_Template_String($var);
    $out = $dwoo->get($tpl, $dwoo->readVar('_parent'));
    if ($assign !== null) {
        $dwoo->assignInScope($out, $assign);
    } else {
        return $out;
    }
}
示例#13
0
 function go()
 {
     include_once "dwoo/dwooAutoload.php";
     if ($_POST) {
         $tpl = new Dwoo_Template_File('templates/config.php.tpl');
         $dwoo = new Dwoo();
         $hostname = str_replace("http:", "", $_POST["hostname"]);
         $hostname = str_replace("/", "", $hostname);
         $markerArray = array();
         $markerArray["dbusername"] = $_POST["mysqlusername"];
         $markerArray["dbpassword"] = $_POST["mysqlpassword"];
         $markerArray["dbhostname"] = $_POST["mysqlhostname"];
         $markerArray["dbtable"] = $_POST["mysqldatabase"];
         $markerArray["installpath"] = $_POST["installpath"];
         $markerArray["basehref"] = "http://" . $hostname . "/" . $_POST["installpath"];
         $markerArray["prefix"] = $_POST["mysqlprefix"];
         $markerArray["prettyurls"] = $_POST["prettyurls"] ? 1 : 0;
         $markerArray["hostname"] = $hostname;
         $markerArray["newuseremail"] = $_POST["newuseremail"];
         $markerArray["resetpasswordemail"] = $_POST["resetpassword"];
         $output = "<?\n";
         $output .= $dwoo->get($tpl, $markerArray);
         $output .= "?>";
         $fp = fopen('config.php', 'w');
         fwrite($fp, $output);
         fclose($fp);
         include_once "config.php";
         include_once "database_backend.php";
         $db = new database_backend();
         $db->connect();
         $handle = fopen("database.sql", "rb");
         $databasesql = stream_get_contents($handle);
         fclose($handle);
         $databasesql = str_replace("itsp_", $_POST["mysqlprefix"], $databasesql);
         $sql_cmds = explode(";", $databasesql);
         for ($i = 0; $i < count($sql_cmds); $i++) {
             mysql_query($sql_cmds[$i]);
         }
         return 1;
     }
     $tpl = new Dwoo_Template_File('templates/wizard.tpl');
     $dwoo = new Dwoo();
     $markerArray = array();
     $markerArray["hostname"] = "http://" . $_SERVER["HTTP_HOST"] . "/";
     $markerArray["installpath"] = substr($_SERVER["REQUEST_URI"], 1);
     $markerArray["newuseremail"] = "newuser@" . $_SERVER["HTTP_HOST"];
     $markerArray["resetpassword"] = "******" . $_SERVER["HTTP_HOST"];
     $output = $dwoo->get($tpl, $markerArray);
     print $output;
     return 0;
 }
示例#14
0
 function main($itsp)
 {
     include "dwoo/dwooAutoload.php";
     $displayNewUserForm = 1;
     $emailsent = "";
     if ($_POST["username"]) {
         include_once "user_backend.php";
         $bUser = new user_backend("newuser");
         $sess = $bUser->resetPassword($_POST["username"]);
         if ($sess) {
             $tpl = new Dwoo_Template_File('templates/forgotpasswordemail.tpl');
             $dwoo = new Dwoo();
             $params = array();
             $params["s"] = $sess["reset"];
             $params["u"] = $sess["username"];
             $setnewpasswordUrl = $itsp->bUrl->newUrl("setnewpassword", $params, 1);
             $markerArray = array();
             $markerArray["emailForgotpasswordHello"] = $itsp->bLang->getLL("email.forgotpassword.hello");
             $markerArray["username"] = $sess["username"];
             $markerArray["emailForgotpasswordHostname"] = config::hostname;
             $markerArray["emailForgotpasswordMsg1"] = $itsp->bLang->getLL("email.forgotpassword.msg1");
             $markerArray["emailForgotpasswordMsg2"] = $itsp->bLang->getLL("email.forgotpassword.msg2");
             $markerArray["emailForgotpasswordMsg3"] = $itsp->bLang->getLL("email.forgotpassword.msg3");
             $markerArray["emailForgotpasswordMsg4"] = $itsp->bLang->getLL("email.forgotpassword.msg4");
             $markerArray["emailForgotpasswordMsg5"] = $itsp->bLang->getLL("email.forgotpassword.msg5");
             $markerArray["emailForgotpasswordMsg6"] = $itsp->bLang->getLL("email.forgotpassword.msg6");
             $markerArray["emailForgotpasswordURL"] = $setnewpasswordUrl;
             $markerArray["emailForgotpasswordSignature"] = $itsp->bLang->getLL("email.forgotpassword.signature");
             $forgotemail = $dwoo->get($tpl, $markerArray);
             $emailto = $sess["email"];
             $emailsubject = $itsp->bLang->getLL("email.forgotpassword.subject");
             $emailheaders = "From: " . config::resetpasswordFromEmail . "\r\n";
             mail($emailto, $emailsubject, $forgotemail, $emailheaders);
             $emailsent = "Email sent";
         }
     }
     if ($displayNewUserForm) {
         $tpl = new Dwoo_Template_File('templates/forgotpassword.tpl');
         $dwoo = new Dwoo();
         $markerArray = templateArray();
         $markerArray["url"] = $_SERVER["REQUEST_URI"];
         $markerArray["username"] = $itsp->bLang->getLL("username");
         $markerArray["password"] = $itsp->bLang->getLL("password");
         $markerArray["headertitle"] = $itsp->bLang->getLL("page.forgotpassword.title");
         $markerArray["loginbtn"] = $itsp->bLang->getLL("login");
         $markerArray["sendit"] = $itsp->bLang->getLL("sendit");
         $markerArray["emailsent"] = $emailsent;
         $createnewuser = $dwoo->get($tpl, $markerArray);
         print $createnewuser;
     }
 }
示例#15
0
 function main($itsp)
 {
     $itsp->bLang->setLanguage($_GET["lang"]);
     include "dwoo/dwooAutoload.php";
     $tpl = new Dwoo_Template_File('templates/login.tpl');
     $dwoo = new Dwoo();
     $markerArray = array();
     $markerArray["headertitle"] = $itsp->bLang->getLL("title");
     $markerArray["username"] = $itsp->bLang->getLL("username");
     $markerArray["password"] = $itsp->bLang->getLL("password");
     $markerArray["loginbtn"] = "Login";
     $settings = $dwoo->get($tpl, $markerArray);
     print $settings;
 }
示例#16
0
 /**
  * @param  $eventData
  * @return void
  */
 public function notify()
 {
     $iso = $this->_getLocale();
     $message = $this->_emailNotification->{$iso};
     if ($message == null) {
         return;
     }
     $dwoo = new Dwoo();
     $template = new Dwoo_Template_String($message);
     $data = new Dwoo_Data();
     $data = $this->_assign($data);
     $parsedMessage = $dwoo->get($template, $data);
     return $this->_send($parsedMessage);
 }
示例#17
0
/**
 * Reverses a string or an array
 * <pre>
 *  * value : the string or array to reverse
 *  * preserve_keys : if value is an array and this is true, then the array keys are left intact
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.0.0
 * @date       2008-10-23
 * @package    Dwoo
 */
function Dwoo_Plugin_reverse(Dwoo $dwoo, $value, $preserve_keys = false)
{
    if (is_array($value)) {
        return array_reverse($value, $preserve_keys);
    } elseif (($charset = $dwoo->getCharset()) === 'iso-8859-1') {
        return strrev((string) $value);
    } else {
        $strlen = mb_strlen($value);
        $out = '';
        while ($strlen--) {
            $out .= mb_substr($value, $strlen, 1, $charset);
        }
        return $out;
    }
}
示例#18
0
function Dwoo_Plugin_flickr(Dwoo $dwoo, $tags, $assign = 'flickrPhotos', $count = 5, $tagmode = 'all')
{
    $cacheKey = sprintf('flickr?tagmode=%s&tags=%s', urlencode($tagmode), urlencode($tags));
    if (!($flickrData = apc_fetch($cacheKey))) {
        $feedURL = sprintf('http://api.flickr.com/services/feeds/photos_public.gne?format=php_serial&tagmode=%s&tags=%s', urlencode($tagmode), urlencode($tags));
        $flickrData = @unserialize(@file_get_contents($feedURL));
        apc_store($cacheKey, $flickrData, 600);
    }
    if (!empty($flickrData['items'])) {
        $dwoo->assignInScope(array_slice($flickrData['items'], 0, $count), $assign);
    } else {
        $dwoo->assignInScope(array(), $assign);
    }
    return '';
}
示例#19
0
 function main($itsp)
 {
     include "dwoo/dwooAutoload.php";
     if ($itsp->bUrl->getGP("s")) {
         user_backend::verifyUser($itsp->bUrl->getGP("s"), $itsp->bUrl->getGP("u"), 9);
         $tpl = new Dwoo_Template_File('templates/rejectuser.tpl');
         $dwoo = new Dwoo();
         $markerArray = templateArray();
         $markerArray["pageRejectedMsg1"] = $itsp->bLang->getLL("page.rejecteduser.msg1");
         $output = $dwoo->get($tpl, $markerArray);
         print $output;
     } else {
         print "access denied";
     }
 }
示例#20
0
 /**
  * Spawns a new instance of Dwoo.
  *
  * @return object
  **/
 protected function spawn()
 {
     if (is_writable($this->compile_dir)) {
         // Main Dwoo object
         $dwoo = new Dwoo();
         // Set the directory of where to compile the files
         $dwoo->setCompileDir($this->compile_dir);
         // set security policy
         $security = new MY_Security_Policy();
         // no PHP handline
         $security->setPhpHandling(1);
         $security->allowPhpFunction($this->allowed_functions);
         $dwoo->setSecurityPolicy($security);
         return $dwoo;
     }
 }
 public function __construct()
 {
     global $THEME;
     // make sure cache/compile paths exist
     check_dir_exists(get_config('dataroot') . 'dwoo/compile/' . $THEME->basename);
     check_dir_exists(get_config('dataroot') . 'dwoo/cache/' . $THEME->basename);
     // set paths
     $this->template_dir = $THEME->templatedirs;
     $compileDir = get_config('dataroot') . 'dwoo/compile/' . $THEME->basename;
     $cacheDir = get_config('dataroot') . 'dwoo/cache/' . $THEME->basename;
     parent::__construct($compileDir, $cacheDir);
     // add plugins dir to the loader
     $this->getLoader()->addDirectory(get_config('libroot') . 'dwoo/mahara/plugins/');
     // adds mahara resources and compiler factory
     $this->setDefaultCompilerFactory('file', array($this, 'compilerFactory'));
     $this->addResource('artefact', 'Dwoo_Template_Mahara_Artefact', array($this, 'compilerFactory'));
     $this->addResource('blocktype', 'Dwoo_Template_Mahara_Blocktype', array($this, 'compilerFactory'));
     $this->addResource('export', 'Dwoo_Template_Mahara_Export', array($this, 'compilerFactory'));
     $this->addResource('interaction', 'Dwoo_Template_Mahara_Interaction', array($this, 'compilerFactory'));
     // set base data
     $theme_list = array();
     $themepaths = themepaths();
     foreach ($themepaths['mahara'] as $themepath) {
         $theme_list[$themepath] = $THEME->get_url($themepath);
     }
     $this->_data = array('THEME' => $THEME, 'WWWROOT' => get_config('wwwroot'), 'THEMELIST' => json_encode($theme_list), 'HTTPSWWWROOT' => get_config('httpswwwroot'));
 }
/**
 * Capitalizes the first letter of each word
 * <pre>
 *  * value : the string to capitalize
 *  * numwords : if true, the words containing numbers are capitalized as well
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.1.0
 * @date       2009-07-18
 * @package    Dwoo
 */
function Dwoo_Plugin_capitalize(Dwoo $dwoo, $value, $numwords = false)
{
    if ($numwords || preg_match('#^[^0-9]+$#', $value)) {
        return mb_convert_case((string) $value, MB_CASE_TITLE, $dwoo->getCharset());
    } else {
        $bits = explode(' ', (string) $value);
        $out = '';
        while (list(, $v) = each($bits)) {
            if (preg_match('#^[^0-9]+$#', $v)) {
                $out .= ' ' . mb_convert_case($v, MB_CASE_TITLE, $dwoo->getCharset());
            } else {
                $out .= ' ' . $v;
            }
        }
        return substr($out, 1);
    }
}
示例#23
0
 /**
  * Renders a view file.
  * This method is required by {@link IViewRenderer}.
  * @param CBaseController the controller or widget who is rendering the view file.
  * @param string the view file path
  * @param mixed the data to be passed to the view
  * @param boolean whether the rendering result should be returned
  * @return mixed the rendering result, or null if the rendering result is not needed.
  */
 public function renderFile($context, $sourceFile, $data, $return)
 {
     // current controller properties will be accessible as {this.property}
     $data['this'] = $context;
     $data['Yii'] = Yii::app();
     $data["TIME"] = sprintf('%0.5f', Yii::getLogger()->getExecutionTime());
     $data["MEMORY"] = round(Yii::getLogger()->getMemoryUsage() / (1024 * 1024), 2) . " MB";
     // check if view file exists
     if (!is_file($sourceFile) || ($file = realpath($sourceFile)) === false) {
         throw new CException(Yii::t('yiiext', 'View file "{file}" does not exist.', array('{file}' => $sourceFile)));
     }
     //render or return
     if ($return) {
         return $this->dwoo->get($sourceFile, $data);
     } else {
         $this->dwoo->get($sourceFile, $data, null, true);
     }
 }
示例#24
0
 function main($itsp)
 {
     $itsp->bLang->setLanguage($_GET["lang"]);
     include_once "dwoo/dwooAutoload.php";
     $valid = isValidUser();
     if ($valid) {
         $tpl = new Dwoo_Template_File('templates/home.tpl');
         $dwoo = new Dwoo();
         $markerArray = loggedInArray();
         $output = $dwoo->get($tpl, $markerArray);
         print $output;
     } else {
         $tpl = new Dwoo_Template_File('templates/frontpage.tpl');
         $dwoo = new Dwoo();
         $markerArray = templateArray();
         $markerArray["loginerror"] = "Failed to login";
         $output = $dwoo->get($tpl, $markerArray);
         print $output;
     }
 }
示例#25
0
function Dwoo_Plugin_format_text(Dwoo $dwoo, $text, $format = 'plain', $mode = 'format')
{
    switch ($format) {
        case 'html':
            if ($mode == 'strip') {
                return strip_tags($text);
            } else {
                return $text;
            }
        case 'micstext':
            // load plugin
            if (function_exists('Dwoo_Plugin_micstext') === false) {
                $dwoo->getLoader()->loadPlugin('micstext');
            }
            return Dwoo_Plugin_micstext($dwoo, $text, $mode);
        default:
        case 'plain':
            return nl2br(htmlspecialchars($text));
    }
}
/**
 *
 * @package    mahara
 * @subpackage dwoo
 * @author     Catalyst IT Ltd
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
 * @copyright  For copyright information on Mahara, please see the README file distributed with this software.
 *
 */
function Dwoo_Plugin_loadgroupquota(Dwoo $dwoo)
{
    $group = group_current_group();
    $quota = $group->quota;
    $quotaused = $group->quotaused;
    if ($quota >= 1048576) {
        $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fMB', $group->quotaused / 1048576), sprintf('%0.1fMB', $quota / 1048567));
    } else {
        if ($quota >= 1024) {
            $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%0.1fKB', $group->quotaused / 1024), sprintf('%0.1fKB', $quota / 1024));
        } else {
            $quota_message = get_string('quotausagegroup', 'mahara', sprintf('%d bytes', $group->quotaused), sprintf('%d bytes', $quota));
        }
    }
    $dwoo->assignInScope($quota_message, 'GROUPQUOTA_MESSAGE');
    if ($quota == 0) {
        $dwoo->assignInScope(100, 'GROUPQUOTA_PERCENTAGE');
    } else {
        $dwoo->assignInScope(round($quotaused / $quota * 100), 'GROUPQUOTA_PERCENTAGE');
    }
}
示例#27
0
    public function testHtmlFormat()
    {
        $tpl = new Dwoo_Template_String("<html><body><div><p>a<em>b</em>c<hr /></p><textarea>a\n  b</textarea></div></body><html>");
        $tpl->forceCompilation();
        $dwoo = new Dwoo(DWOO_COMPILE_DIR, DWOO_CACHE_DIR);
        $dwoo->addFilter('html_format', true);
        $this->assertEquals(str_replace("\r", '', <<<SNIPPET

<html>
<body>
\t<div>
\t\t<p>
\t\t\ta<em>b</em>c
\t\t\t<hr />
\t\t</p><textarea>a
  b</textarea>
\t</div>
</body>
<html>
SNIPPET
), $dwoo->get($tpl, array(), $this->compiler));
    }
示例#28
0
 function main($itsp)
 {
     include "dwoo/dwooAutoload.php";
     if ($itsp->bUrl->getGP("s")) {
         user_backend::verifyUser($itsp->bUrl->getGP("s"), $itsp->bUrl->getGP("u"), 1);
     }
     $valid = isValidUser();
     if ($valid) {
         $tpl = new Dwoo_Template_File('templates/verifieduser.tpl');
         $dwoo = new Dwoo();
         $params = array();
         $homeurl = "/" . config::installpath . "" . $itsp->bUrl->newUrl("tasks", $params);
         $markerArray = loggedInArray();
         $markerArray["pageVerifiedUserAccepted"] = $itsp->bLang->getLL("page.verifieduser.useraccepted");
         $markerArray["pageVerifiedUserHomeUrl"] = $itsp->bLang->getLL("page.verifieduser.homeurl");
         $markerArray["homeUrl"] = $homeurl;
         $output = $dwoo->get($tpl, $markerArray);
         print $output;
     } else {
         print "access denied";
     }
 }
示例#29
0
/**
 * Applies various escaping schemes on the given string
 * <pre>
 *  * value : the string to process
 *  * format : escaping format to use, valid formats are : html, htmlall, url, urlpathinfo, quotes, hex, hexentity, javascript and mail
 *  * charset : character set to use for the conversion (applies to some formats only), defaults to the current Dwoo charset
 * </pre>
 * This software is provided 'as-is', without any express or implied warranty.
 * In no event will the authors be held liable for any damages arising from the use of this software.
 *
 * @author     Jordi Boggiano <*****@*****.**>
 * @copyright  Copyright (c) 2008, Jordi Boggiano
 * @license    http://dwoo.org/LICENSE   Modified BSD License
 * @link       http://dwoo.org/
 * @version    1.0.0
 * @date       2008-10-23
 * @package    Dwoo
 */
function Dwoo_Plugin_escape(Dwoo $dwoo, $value = '', $format = 'html', $charset = null)
{
    if ($charset === null) {
        $charset = $dwoo->getCharset();
    }
    switch ($format) {
        case 'html':
            return htmlspecialchars((string) $value, ENT_QUOTES, $charset);
        case 'htmlall':
            return htmlentities((string) $value, ENT_QUOTES, $charset);
        case 'url':
            return rawurlencode((string) $value);
        case 'urlpathinfo':
            return str_replace('%2F', '/', rawurlencode((string) $value));
        case 'quotes':
            return preg_replace("#(?<!\\\\)'#", "\\'", (string) $value);
        case 'hex':
            $out = '';
            $cnt = strlen((string) $value);
            for ($i = 0; $i < $cnt; $i++) {
                $out .= '%' . bin2hex((string) $value[$i]);
            }
            return $out;
        case 'hexentity':
            $out = '';
            $cnt = strlen((string) $value);
            for ($i = 0; $i < $cnt; $i++) {
                $out .= '&#x' . bin2hex((string) $value[$i]) . ';';
            }
            return $out;
        case 'javascript':
            return strtr((string) $value, array('\\' => '\\\\', "'" => "\\'", '"' => '\\"', "\r" => '\\r', "\n" => '\\n', '</' => '<\\/'));
        case 'mail':
            return str_replace(array('@', '.'), array('&nbsp;(AT)&nbsp;', '&nbsp;(DOT)&nbsp;'), (string) $value);
        default:
            return $dwoo->triggerError('Escape\'s format argument must be one of : html, htmlall, url, urlpathinfo, hex, hexentity, javascript or mail, "' . $format . '" given.', E_USER_WARNING);
    }
}
/**
 * Dwoo {loadquota} function plugin
 *
 * Type:     function<br>
 * Name:     loadquota<br>
 * Date:     June 22, 2006<br>
 * Purpose:  Set quota related variables for the quota template
 * @author   Catalyst IT Ltd
 * @version  1.0
 * @return Nothing
 */
function Dwoo_Plugin_loadquota(Dwoo $dwoo)
{
    global $USER;
    if (!$USER->is_logged_in()) {
        return;
    }
    $quota = $USER->get('quota');
    $quotaused = $USER->get('quotaused');
    if ($quota >= 1048576) {
        $quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fMB', $USER->get('quotaused') / 1048576), sprintf('%0.1fMB', $quota / 1048567));
    } else {
        if ($quota >= 1024) {
            $quota_message = get_string('quotausage', 'mahara', sprintf('%0.1fKB', $USER->get('quotaused') / 1024), sprintf('%0.1fKB', $quota / 1024));
        } else {
            $quota_message = get_string('quotausage', 'mahara', sprintf('%d bytes', $USER->get('quotaused')), sprintf('%d bytes', $quota));
        }
    }
    $dwoo->assignInScope($quota_message, 'QUOTA_MESSAGE');
    if ($quota == 0) {
        $dwoo->assignInScope(100, 'QUOTA_PERCENTAGE');
    } else {
        $dwoo->assignInScope(round($quotaused / $quota * 100), 'QUOTA_PERCENTAGE');
    }
}