Example #1
0
function smarty_modifier_msg($name)
{
    $c =& Controller::getInstance();
    $messages = $c->request->getAttribute('messages');
    $messages[$name] = str_replace('\\n', "\n", $messages[$name]);
    return $messages[$name];
}
Example #2
0
 /**
  * Initialization
  *
  * Determine error handling configuration ans setup correspondent properties.
  *
  * This functions wiil be executes one time before first error/eception or never
  * if error/exception hasn't occur.
  */
 static function init()
 {
     if (self::$rootDir) {
         return;
     }
     try {
         $c = Config::getInstance();
         $root_dir = $c->root_dir;
         $data_dir = $c->data_dir;
     } catch (Exception $e) {
         $root_dir = dirname(dirname(__FILE__));
         $data_dir = '/data';
     }
     self::$rootDir = $root_dir;
     $textTemplate = $root_dir . $data_dir . '/exceptionTemplate.text.php';
     $webTemplate = $root_dir . $data_dir . '/exceptionTemplate.web.php';
     // errors will be logged
     if (self::iniToBool(ini_get('log_errors'))) {
         self::$logTemplate = $textTemplate;
     }
     // errors wiil be displayed
     if (self::iniToBool(ini_get('display_errors'))) {
         // in console(CLI) and Ajax we preffered to display errors in plain text
         self::$displayTemplate = php_sapi_name() == 'cli' || Controller::getInstance()->isAjax() ? $textTemplate : $webTemplate;
     }
 }
Example #3
0
/**
 * This method will get a module/action or module template result
 * 
 * @param array $params     
 * @param Smarty $smarty 
 */
function smarty_function_widget($params, &$smarty)
{
    if (!isset($params['module']) || !isset($params['action']) && !isset($params['template']) || isset($params['action']) && isset($params['template'])) {
        throw new SmartyException('{widget} : module and action (or template) parameters must be defined');
    }
    $args = array();
    if (count($params) > 2) {
        foreach ($params as $k => $v) {
            if ($k !== 'module' && $k !== 'action' && $k !== 'template') {
                $args[$k] = $v;
            }
        }
    }
    if (isset($params['action'])) {
        Controller::getInstance()->setModule($params['module'])->setAction($params['action'])->setArgs(array($args))->dispatch();
    } else {
        if ($file = get_module_file($params['module'], 'template/' . $params['template'], true)) {
            $tpl = Template::getInstance($file);
            foreach ($smarty->tpl_vars as $k => $v) {
                if ($k !== 'SCRIPT_NAME' && $k !== 'smarty' && !isset($args[$k])) {
                    $args[$k] = $v->value;
                }
            }
            if (empty($args)) {
                return $tpl->get();
            }
            foreach ($args as $name => $value) {
                $tpl->assign($name, $value);
            }
            return $tpl->get();
        }
    }
}
 /**
  * @return array<list_Item>
  */
 public final function getItems()
 {
     $request = Controller::getInstance()->getContext()->getRequest();
     $form = null;
     $conditionOn = null;
     try {
         $conditionOnId = intval($request->getParameter('documentId', 0));
         if ($conditionOnId > 0) {
             $conditionOn = DocumentHelper::getDocumentInstance($conditionOnId);
             $form = $conditionOn->getForm();
         } else {
             $parent = DocumentHelper::getDocumentInstance(intval($request->getParameter('parentId', 0)));
             if ($parent instanceof form_persistentdocument_baseform) {
                 $form = $parent;
             } else {
                 if ($parent instanceof form_persistentdocument_group) {
                     $form = $parent->getForm();
                 }
             }
         }
     } catch (Exception $e) {
         Framework::exception($e);
     }
     if (!$form instanceof form_persistentdocument_baseform) {
         return array();
     }
     $results = array();
     $excludeIds = $this->getExcludeIds($conditionOn);
     foreach ($form->getDocumentService()->getValidActivationFields($form, $excludeIds) as $field) {
         $results[] = new list_Item($field->getLabel(), $field->getId());
     }
     return $results;
 }
 /**
  * @return array<list_Item>
  */
 public final function getItems()
 {
     try {
         $request = Controller::getInstance()->getContext()->getRequest();
         $questionId = intval($request->getParameter('questionId', 0));
         $question = DocumentHelper::getDocumentInstance($questionId);
     } catch (Exception $e) {
         if (Framework::isDebugEnabled()) {
             Framework::debug(__METHOD__ . ' EXCEPTION: ' . $e->getMessage());
         }
         return array();
     }
     // Here we must use instanceof and not getDocumentModelName to work with injection.
     $results = array();
     if ($question instanceof form_persistentdocument_boolean) {
         $trueLabel = $question->getTruelabel();
         $falseLabel = $question->getFalselabel();
         $results[$trueLabel] = new list_Item($trueLabel, $trueLabel);
         $results[$falseLabel] = new list_Item($falseLabel, $falseLabel);
     } else {
         if ($question instanceof form_persistentdocument_list) {
             $results = $question->getDataSource()->getItems();
         }
     }
     return $results;
 }
Example #6
0
 public static function findPage(Controller $oController)
 {
     if (self::$currentPageID > 0) {
         return;
     }
     if ($oController->indexPage()) {
         $oPage = new Page();
         if ($oPage->loadIndexPage()) {
             if (Controller::getInstance()->controllerExists($oPage["Link"])) {
                 $oController->route[self::$level] = $oPage["Link"];
             }
             self::$level = 1;
             self::$page = $oPage;
             self::$currentPageID = $oPage->PageID;
         }
     } else {
         $db = MySQL::getInstance();
         $db->query("SELECT PageID, StaticPath, Level, LeftKey, RightKey, Link\n\t\t\t\tFROM `page` WHERE\n\t\t\t\t\tWebsiteID = " . $db->escape(WEBSITE_ID) . "\n\t\t\t\t\tAND StaticPath IN (" . implode(", ", $db->escape($oController->route)) . ")\n\t\t\t\t\tAND LanguageCode = " . $db->escape(LANG) . "\n\t\t\t\t\tAND Level > 1\n\t\t\t\tORDER BY LeftKey");
         self::$level = 0;
         $moduleFound = false;
         $currentPageID = null;
         while ($row = $db->fetchRow()) {
             if ($row["StaticPath"] == $oController->route[0] && $row["Level"] == 2) {
                 $currentPageID = $row["PageID"];
                 self::$currentLeftKey = $row["LeftKey"];
                 self::$currentRightKey = $row["RightKey"];
                 if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                     $oController->route[0] = $row["Link"];
                     break;
                 }
                 self::$level++;
                 continue;
             }
             if (!is_null($currentPageID) && count($oController->route) > self::$level) {
                 if ($row["StaticPath"] == $oController->route[self::$level] && $row["LeftKey"] > self::$currentLeftKey && $row["RightKey"] < self::$currentRightKey) {
                     $currentPageID = $row["PageID"];
                     self::$currentLeftKey = $row["LeftKey"];
                     self::$currentRightKey = $row["RightKey"];
                     if ($moduleFound = Controller::getInstance()->controllerExists($row["Link"])) {
                         $oController->route[self::$level] = $row["Link"];
                         break;
                     }
                     self::$level++;
                 }
             }
         }
         if (self::$level == count($oController->route) || $moduleFound != false) {
             $oPage = new Page();
             if ($oPage->loadByID($currentPageID)) {
                 self::$page = $oPage;
                 self::$currentPageID = $oPage->PageID;
             }
         }
     }
     for ($i = 0; $i < self::$level; $i++) {
         array_shift($oController->route);
     }
 }
Example #7
0
function smarty_function_mojavi_error($params, &$smarty)
{
    $controller =& Controller::getInstance();
    $request =& $controller->request;
    if ($request->hasError($params['name'])) {
        return $request->getError($params['name']);
    }
    return null;
}
Example #8
0
 /**
  * Generate a new cache file from the buffer of the controller.
  * @return string
  */
 private function generateCache()
 {
     $instance =& Controller::getInstance();
     $size = file_put_contents($this->_cachefile, $instance->buffer);
     if ($size > 0) {
         return file_get_contents($this->_cachefile);
     } else {
         die("Error writing to cache file.");
     }
 }
Example #9
0
 /**
  * Method description
  *
  * More detailed method description
  * @param    void
  * @return   void
  */
 function buildComplete()
 {
     if (!isset($this->tpl)) {
         $this->tpl = $this->createTemplate();
     }
     $controller = Controller::getInstance();
     $controller->addScript("colorpicker.js");
     $controller->addCSS("colorpicker.css");
     parent::buildComplete();
 }
Example #10
0
 /**
  * Method description
  *
  * More detailed method description
  * @param    void
  * @return   void
  */
 function buildComplete()
 {
     if (!isset($this->tpl)) {
         $this->tpl = $this->createTemplate();
     }
     $this->setHREF(Controller::getInstance()->getNavigator()->getStepURL(-1));
     if ($this->items->isEmpty()) {
         $this->items->setText(Language::message('widgets', 'back_link'));
     }
     parent::buildComplete();
 }
Example #11
0
 /**
  * Method description
  *
  * More detailed method description
  * @param    void
  * @return   void
  */
 function buildComplete()
 {
     if (!isset($this->tpl)) {
         $this->tpl = $this->createTemplate();
     }
     $controller = Controller::getInstance();
     $controller->addScript("jquery.ui.js");
     $controller->addCSS("jquery-ui.css");
     $this->tabs->filter("WTab");
     parent::buildComplete();
 }
Example #12
0
 /**
  * Creating instance and initializing class properties.
  * Trying to restore steps saved in persistent storage.
  * @param null
  * @return null
  */
 function __construct()
 {
     $this->storage = Storage::createWithSession('AdminNavigator' . Controller::getInstance()->getStoragePostfix());
     $this->controller_name = Controller::getInstance()->getControllerName();
     if (empty($this->controller_name)) {
         $this->controller_name = "index";
     }
     $this->user_path = $this->storage->get("user_path");
     if (empty($this->user_path) || $this->user_path === false) {
         $this->user_path = array();
     }
 }
Example #13
0
 /**
  * Method description
  *
  * More detailed method description
  * @param    void
  * @return   void
  */
 function buildComplete()
 {
     if (!isset($this->tpl)) {
         $this->tpl = $this->createTemplate();
     }
     $controller = Controller::getInstance();
     $controller->addScript("jquery.ui.js");
     $controller->addScript("jquery.markitup_set.js");
     $controller->addScript("jquery.markitup.js");
     $controller->addCSS("jquery-ui.css");
     $controller->addCSS("jquery.markitup_main.css");
     $controller->addCSS("jquery.markitup_markdown.css");
     parent::buildComplete();
 }
Example #14
0
 /**
  * Tries to find default data, composing it to the 
  * {@link WidgetResultSet} and injecting this result set 
  * to the data-setter method of particular widget, specified
  * by widget_id parameter.
  *
  * If no data was found, empty {@link WidgetResultSet}
  * will be passed to widget.
  *
  * @param string id of the widget for which to make a lookup
  * @return WidgetResultSet with default data
  */
 static function findDefault($widget_id)
 {
     $wrs = new WidgetResultSet();
     if (($widget = Controller::getInstance()->getWidget($widget_id)) === null) {
         return $wrs;
     }
     if (($data_setter = $widget->getDataSetterMethod()) === null || $widget instanceof iNotSelectable) {
         return $wrs;
     }
     foreach (self::$pool as $v) {
         $d_o = $v['data_object'];
         if (($def = $d_o->getData($widget_id)) !== null && !$def instanceof WidgetResultSet) {
             $wrs->setDef($def);
         }
     }
     $widget->{$data_setter}($wrs);
 }
Example #15
0
 function &getSmartyRenderer()
 {
     global $messages;
     $controller =& Controller::getInstance();
     $request =& $controller->request;
     $user =& $controller->user;
     $renderer =& new SmartyRenderer($controller, $request, $user);
     $smarty =& $renderer->getEngine();
     $smarty->cache_dir = SMARTY_CACHE_DIR;
     $smarty->caching = SMARTY_CACHING;
     $smarty->force_compile = SMARTY_FORCE_COMPILE;
     $smarty->compile_dir = SMARTY_COMPILE_DIR;
     $smarty->config_dir = $controller->getModuleDir() . 'config/';
     $smarty->debugging = SMARTY_DEBUGGING;
     $smarty->compile_id = $controller->currentModule . '_' . $controller->currentAction;
     $smarty->register_function('mojavi_url', 'smarty_function_mojavi_url');
     $smarty->register_function('mojavi_action', 'smarty_function_mojavi_action');
     $smarty->register_function('mojavi_error', 'smarty_function_mojavi_error');
     $smarty->register_function('css_link_tag', 'smarty_function_css_link_tag');
     $smarty->register_function('js_link_tag', 'smarty_function_js_link_tag');
     $smarty->register_function('to_json', 'smarty_function_to_json');
     $smarty->register_function('html_select_date_simple', 'smarty_function_html_select_date_simple');
     $smarty->register_modifier('format_price', 'smarty_modifier_format_price');
     $smarty->register_modifier('mb_truncate', 'smarty_modifier_mb_truncate');
     $smarty->register_modifier('tofavicon', 'smarty_modifier_tofavicon');
     $smarty->register_modifier('date_RFC822', 'smarty_modifier_date_RFC822');
     $smarty->register_modifier('date_W3C', 'smarty_modifier_date_W3C');
     $smarty->register_modifier('msg', 'smarty_modifier_msg');
     if ($user->isAuthenticated() && $user->hasAttribute('member', GLU_NS)) {
         $smarty->assign('member', $user->getAttribute('member', GLU_NS));
     }
     $smarty->assign($_SERVER);
     $smarty->assign('params', $request->getParameters());
     $smarty->assign('errors', $request->getErrors());
     $smarty->assign('module', $controller->requestModule);
     $smarty->assign('action', $controller->requestAction);
     $smarty->assign(array('webmod' => WEB_MODULE_DIR, 'curmod' => WEB_MODULE_DIR . $controller->currentModule . '/', 'SCRIPT_PATH' => SCRIPT_PATH, 'PLNET_CUSTOM_TEMPLATE_ID' => PLNET_CUSTOM_TEMPLATE_ID));
     $smarty->assign('shared_dir', BASE_DIR . 'templates');
     $smarty->assign($request->getAttributes());
     return $renderer;
 }
Example #16
0
function smarty_function_mojavi_action($params, &$smarty)
{
    $id = $params['module'] . '_' . $params['action'];
    if (isset($params['lifetime'])) {
        include_once 'Cache/Lite.php';
        $cache =& new Cache_Lite(array('cacheDir' => CACHE_LITE_DIR, 'lifeTime' => $params['lifetime'], 'automaticCleaningFactor' => CACHE_LITE_AUTO_CLEANING, 'automaticSerialization' => true));
        $cache_id = $id . '_' . (isset($params['cache_id']) ? $params['cache_id'] : '');
        if ($data = $cache->get($cache_id)) {
            return $data;
        }
    }
    $controller =& Controller::getInstance();
    $actionChain =& new ActionChain();
    $actionChain->register($id, $params['module'], $params['action']);
    $actionChain->execute($controller, $controller->request, $controller->user);
    $data = $actionChain->fetchResult($id);
    if (isset($params['lifetime'])) {
        $cache->save($data, $cache_id);
    }
    return $data;
}
Example #17
0
 /**
  * Allow to the app to join data with the views
  * @param type $traverse
  */
 public function nexus($traverse)
 {
     $instance =& Controller::getInstance();
     foreach (get_object_vars($instance) as $_sl_key => $_sl_var) {
         if (!isset($this->buffer)) {
             $this->{$_sl_key} =& $instance->{$_sl_key};
         }
     }
     ob_start();
     if (isset($traverse['vars'])) {
         foreach ($traverse['vars'] as $key => $value) {
             ${$key} = $value;
         }
     }
     if (!@(include VIEWS_PATH . $traverse['views'] . ".php")) {
         echo "Error loading " . $traverse['views'] . " view";
     }
     $instance->buffer .= ob_get_clean();
     if (Application::loadConfig('compress') == 1) {
         $search = array('/\\>[^\\S ]+/s', '/[^\\S ]+\\</s', '/(\\s)+/s');
         $replace = array('>', '<', '\\1');
         $instance->buffer = preg_replace($search, $replace, $instance->buffer);
     }
 }
Example #18
0
<?php

/*
 * The point-of-entry for our application
 *
 * Our web server should be configured to forward
 * all requests to this script
 *
 * See INSTALL for more information
 */
// Start or resume session handling
//
if (!session_id()) {
    session_start();
}
require realpath('..') . '/config.php';
// Include our configuration variables
// Declare our application's valid URL routes
$routes = (require dirname(dirname(__FILE__)) . '/' . 'src' . '/' . 'routes.php');
$x = array('/' => array('GET' => 'show_entries'), '/add' => array('POST' => 'add_entry'), '/login' => array('GET' => 'login', 'POST' => 'login'), '/logout' => array('GET' => 'logout'), '/delete' => array('GET' => 'delete_entry'));
// Instantiate our front controller and handle the request
$controller = Controller::getInstance($routes);
$path = parse_url($_SERVER['REQUEST_URI'])['path'];
$controller->dispatch($_SERVER['REQUEST_METHOD'], $path);
Example #19
0
 /**
  * Replacing parameters, marked as "from='limit'" with real values.
  *
  * @param null
  * @return null
  */
 function replaceLimitParams()
 {
     $controller = Controller::getInstance();
     foreach ($this->params_from as $k => $v) {
         if ($v == "limit") {
             $this->params[$k] = array('from' => $controller->getDisplayModeParams()->predicted_from, 'limit' => $controller->getDisplayModeParams()->predicted_limit);
         }
     }
 }
Example #20
0
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//TODO Warning: develop a solutions for session hijack
session_start();
require_once 'src/util/EMail.php';
require_once 'pages/bases/localization/Localization.php';
/* Importing action files */
require_once 'src/actions/ActionDom.php';
require_once 'src/actions/CommonsActions.php';
require_once 'src/actions/ElementActions.php';
require_once 'src/actions/RoomActions.php';
require_once 'src/actions/EduquitoActions.php';
require_once 'src/actions/PlataformActions.php';
require_once 'src/actions/PlaceActions.php';
$controller = Controller::getInstance();
$controller->run();
class Controller
{
    private static $instance;
    private $mapping;
    private $dom;
    public static function getInstance()
    {
        if (!isset(self::$instance)) {
            $class = __CLASS__;
            self::$instance = new $class();
        }
        return self::$instance;
    }
    public function __construct()
Example #21
0
 /**
  * Performs verification of specified post data. 
  * Usually calls from Controller, when POST data arrives.
  *
  * There is such rules:
  * <ul>
  * <li>required. Fires, that this filed must be filled.</li>
  * <li>minlength. Sets minimum length of the string for this field.</li>
  * <li>maxlength. Sets maximum length of the string for this field.</li>
  * <li>rangelength. Sets minimum and maximum length of the string for this field (in [4,6] format).</li>
  * <li>min. Sets minimum value of the field.</li>
  * <li>max. Sets maximum value of the field.</li>
  * <li>range. Sets minimum and maximum value of the field (in [10,20] format).</li>
  * <li>email. Fires that this field must be a valid email. $email_regexp is used.</li>
  * <li>url. Fires that this filed must be a valid URL. $url_regexp is used.</li>
  * <li>date. Fires that this filed must be a valid date to be parsed by strtotime().</li>
  * <li>dateISO. Fires that this filed must be a valid date in ISO format.$date_iso regexp is used.</li>
  * <li>number. Fires that this filed must be a valid number (float, integer).</li>
  * <li>digits. Fires that this filed must consists only of the digits.No other symbols are allowed.</li>
  * </ul>
  *
  * These rules are compatible with jQuery validation plugin, which is used for client-side form 
  * validation.
  *
  * If no custom messages defined, built-in are used.
  *
  * @param HTTPParamHolder object with post data to check
  * @param string signature of the form that comes 
  * @param array array of rules
  * @param array optional array of custom messages
  * @return null
  */
 static function checkByRules($formid_name, $rules, $messages = array())
 {
     if (empty($rules) || empty($rules[$formid_name])) {
         return;
     }
     $rules = $rules[$formid_name];
     if (isset($messages[$formid_name])) {
         POSTErrors::setCustomMessages($messages[$formid_name]);
     }
     $post = Controller::getInstance()->post;
     foreach ($rules as $name => $cr) {
         if (isset($cr['filter'])) {
             $post->bindFilter($name, $cr['filter']);
         }
         $p_val = $post->{$name};
         if ($p_val === "") {
             $p_val = null;
         }
         foreach ($cr as $rule => $rule_value) {
             if ($rule === 'required' && $rule_value === 'true') {
                 if (!isset($p_val) || $p_val === null || $p_val === "") {
                     POSTErrors::addError($name, null, Language::message('checkers', 'REQUIRED'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && $p_val2 == "" || $p_val2 === null) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'REQUIRED'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && ($p_val2[0] === null || $p_val2[0] === "")) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'REQUIRED'));
                         } elseif (!t(new UploadedFiles($name))->isUploaded($name)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'REQUIRED'));
                         }
                     }
                 }
             }
             if ($rule === 'minlength' && is_numeric($rule_value) && isset($p_val)) {
                 if (is_string($p_val) && strlen(htmlspecialchars_decode($p_val, ENT_QUOTES)) < 0 + $rule_value) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'MINLENGTH', $rule_value));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && strlen(htmlspecialchars_decode($p_val2, ENT_QUOTES)) < 0 + $rule_value || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MINLENGTH', $rule_value));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && strlen(htmlspecialchars_decode($p_val2[0], ENT_QUOTES)) < 0 + $rule_value) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MINLENGTH', $rule_value));
                         }
                     }
                 }
             }
             if ($rule === 'maxlength' && is_numeric($rule_value) && isset($p_val)) {
                 if (is_string($p_val) && strlen(htmlspecialchars_decode($p_val, ENT_QUOTES)) > 0 + $rule_value) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'MAXLENGTH', $rule_value));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && strlen(htmlspecialchars_decode($p_val2, ENT_QUOTES)) > 0 + $rule_value || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MAXLENGTH', $rule_value));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && strlen(htmlspecialchars_decode($p_val2[0], ENT_QUOTES)) > 0 + $rule_value) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MAXLENGTH', $rule_value));
                         }
                     }
                 }
             }
             if ($rule === 'rangelength' && !empty($rule_value) && isset($p_val)) {
                 if (preg_match("/\\[\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\]/", $rule_value, $m)) {
                     $range_from = $m[1];
                     $range_to = $m[2];
                     if (is_string($p_val) && (($len = strlen(htmlspecialchars_decode($p_val, ENT_QUOTES))) > 0 + $rule_to || $len < 0 + $range_from)) {
                         POSTErrors::addError($name, null, Language::message('checkers', 'RANGELENGTH', $range_from, $range_to));
                     } elseif (is_array($p_val)) {
                         foreach ($p_val as $add_id => $p_val2) {
                             if (is_string($p_val2) && (($len = strlen(htmlspecialchars_decode($p_val2, ENT_QUOTES))) > 0 + $range_to || $len < 0 + $range_from) || !isset($p_val2)) {
                                 POSTErrors::addError($name, $add_id, Language::message('checkers', 'RANGELENGTH', $range_from, $range_to));
                             } elseif (is_array($p_val2) && count($p_val2) == 1 && (($len = strlen(htmlspecialchars_decode($p_val2[0], ENT_QUOTES))) > 0 + $rule_to || $len < 0 + $range_from)) {
                                 POSTErrors::addError($name, $add_id, Language::message('checkers', 'RANGELENGTH', $range_from, $range_to));
                             }
                         }
                     }
                 }
             }
             if ($rule === 'min' && is_numeric($rule_value) && isset($p_val)) {
                 if (is_numeric($p_val) && $p_val < 0 + $rule_value) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'MIN', $rule_value));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_numeric($p_val2) && $p_val2 < 0 + $rule_value || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MIN', $rule_value));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && is_numeric($p_val2[0]) && $p_val2[0] < 0 + $rule_value) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MIN', $rule_value));
                         }
                     }
                 }
             }
             if ($rule === 'max' && is_numeric($rule_value) && isset($p_val)) {
                 if (is_numeric($p_val) && $p_val > 0 + $rule_value) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'MAX', $rule_value));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_numeric($p_val2) && $p_val2 > 0 + $rule_value || !isset($p_val2) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MAX', $rule_value));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && is_numeric($p_val2[0]) && $p_val2[0] > 0 + $rule_value) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'MAX', $rule_value));
                         }
                     }
                 }
             }
             if ($rule === 'range' && !empty($rule_value) && isset($p_val)) {
                 if (preg_match("/\\[\\s*(\\d+)\\s*,\\s*(\\d+)\\s*\\]/", $rule_value, $m)) {
                     $range_from = $m[1];
                     $range_to = $m[2];
                     if (is_numeric($p_val) && ($p_val > 0 + $range_to || $p_val < 0 + $range_from)) {
                         POSTErrors::addError($name, null, Language::message('checkers', 'RANGE', $range_from, $range_to));
                     } elseif (is_array($p_val)) {
                         foreach ($p_val as $add_id => $p_val2) {
                             if (is_numeric($p_val2) && ($p_val2 > 0 + $range_to || $p_val2 < 0 + $range_from) || !isset($p_val2)) {
                                 POSTErrors::addError($name, $add_id, Language::message('checkers', 'RANGE', $range_from, $range_to));
                             } elseif (is_array($p_val2) && count($p_val2) == 1 && is_numeric($p_val2[0]) && ($p_val2[0] > 0 + $rule_to || $p_val2[0] < 0 + $range_from)) {
                                 POSTErrors::addError($name, $add_id, Language::message('checkers', 'RANGE', $range_from, $range_to));
                             }
                         }
                     }
                 }
             }
             if ($rule === 'email' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && !preg_match(self::$email_regexp, $p_val)) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'EMAIL'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && !preg_match(self::$email_regexp, $p_val2) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'EMAIL'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && !preg_match(self::$email_regexp, $p_val2[0])) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'EMAIL'));
                         }
                     }
                 }
             }
             if ($rule === 'url' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && !preg_match(self::$url_regexp, $p_val)) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'URL'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && !preg_match(self::$url_regexp, $p_val2) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'URL'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && !preg_match(self::$url_regexp, $p_val2[0])) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'URL'));
                         }
                     }
                 }
             }
             if ($rule === 'date' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && strtotime($p_val) === -1) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'DATE'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && strtotime($p_val2) === -1 || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DATE'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && strtotime($p_val2[0]) === -1) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DATE'));
                         }
                     }
                 }
             }
             if ($rule === 'dateISO' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && !preg_match(self::$date_iso, $p_val)) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'DATEISO'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && !preg_match(self::$date_iso, $p_val2) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DATEISO'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && !preg_match(self::$date_iso, $p_val2[0])) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DATEISO'));
                         }
                     }
                 }
             }
             if ($rule === 'number' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && !is_numeric(str_replace(",", ".", $p_val))) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'NUMBER'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && !is_numeric(str_replace(",", ".", $p_val2)) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'NUMBER'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && !is_numeric(str_replace(",", ".", $p_val2[0]))) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'NUMBER'));
                         }
                     }
                 }
             }
             if ($rule === 'digits' && $rule_value === 'true' && isset($p_val)) {
                 if (is_string($p_val) && !preg_match(self::$digits, $p_val)) {
                     POSTErrors::addError($name, null, Language::message('checkers', 'DIGITS'));
                 } elseif (is_array($p_val)) {
                     foreach ($p_val as $add_id => $p_val2) {
                         if (is_string($p_val2) && !preg_match(self::$digits, $p_val2) || !isset($p_val2)) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DIGITS'));
                         } elseif (is_array($p_val2) && count($p_val2) == 1 && !preg_match(self::$digits, $p_val2[0])) {
                             POSTErrors::addError($name, $add_id, Language::message('checkers', 'DIGITS'));
                         }
                     }
                 }
             }
         }
     }
 }
 /**
  * @param String $code
  */
 protected final function registerCode($code)
 {
     Controller::getInstance()->getContext()->getUser()->setAttribute(CAPTCHA_SESSION_KEY, $code);
 }
Example #23
0
<?php

require_once "/inc/bootstrap.php";
$view = isset($_REQUEST['view']) && $_REQUEST['view'] ? $_REQUEST['view'] : 'welcome';
$action = isset($_REQUEST['action']) && $_REQUEST['action'] ? $_REQUEST['action'] : null;
if ($action) {
    Controller::getInstance()->invokePostAction();
}
$file = '/views/' . $view . '.php';
if (file_exists(__DIR__ . $file)) {
    require $file;
}
Example #24
0
 function postRender()
 {
     Controller::getInstance()->getDispatcher()->deleteSubscriber("have_valuechecker", $this->getId());
     Controller::getInstance()->getDispatcher()->deleteEvent("have_valuechecker");
     //$controller->dispatcher->deleteSubscriber("valuechecker_puttosubmit",$this->id);
     //$controller->getDispatcher->deleteEvent("valuechecker_getfunc");
     parent::postRender();
 }
Example #25
0
if (!defined('APPLICATION_DIR')) {
    /**
     * Main application dir
     */
    define('APPLICATION_DIR', dirname(__FILE__));
}
/**
 * Load library
 */
require_once $libDir . '/loadlib.php';
unset($appBase, $libDir);
/**
 * Config
 */
if (file_exists(APPLICATION_DIR . '/config/config.php')) {
    require_once APPLICATION_DIR . '/config/config.php';
} elseif (file_exists(APPLICATION_DIR . '/config/config.dist.php')) {
    require_once APPLICATION_DIR . '/config/config.dist.php';
} else {
    throw new Exception('Config file not found.');
}
/**
 * Application
 */
require_once APPLICATION_DIR . '/loadapp.php';
/**
 * Front controller
 */
$frontController = Controller::getInstance();
// unset global vars
unset($frontController);
Example #26
0
 /**
  * 
  * @return Pack1
  */
 public static function getInstance()
 {
     return parent::getInstance();
 }
Example #27
0
 /**
  * Saves session to storage (DB) and sends cookies. This function
  * utilizes 
  * <code>session.cookie.name</code> for cookie name to send,
  * <code>session.encrypt_guest_cookie.use</code> to define whether to use 
  * signing of guest cookie,
  * <code>session.cookie.length</code> to define TTL of cookies,
  * <code>session.remember_me</code> to extend TTL on the 
  * <code>session.remember_me_for</code>.
  *
  * It's usually called by "register_shutdown_function".
  *
  * Behaviors BeforeSendCookieOnSave, AfterSendCookieOnSave, 
  * BeforeSave, AfterSave are defined.
  *
  * @return   array
  */
 function save()
 {
     $config = Config::getInstance();
     $this->trigger("BeforeSendCookieOnSave", $this);
     if (!$this->is_persistent) {
         return;
     }
     Controller::getInstance()->cookies[$config->session->cookie->name] = array("value" => $config->session->encrypt_guest_cookie->use && $this->user_id == User::GUEST ? $this->id . ":" . $this->getGuestHash($this->id) : $this->id, "expire" => $config->session->cookie->length == 0 && !$config->session->remember_me ? 0 : time() + $config->session->cookie->length + ($config->session->remember_me ? $config->session->remember_me_for : 0));
     $this->trigger("AfterSendCookieOnSave", $this);
     //do not save session data to DB/storage/etc if verified guest
     if ($config->session->encrypt_guest_cookie->use && $this->user_id == User::GUEST && $this->verified_guest) {
         return;
     }
     $params = array();
     foreach ($this->params2save as $v) {
         $params[$v] = $this->{$v};
     }
     $this->deleteExpired();
     $params['time'] = time() + Config::getInstance()->session->length + ($this->remember_me ? Config::getInstance()->session->remember_me_for : 0);
     $this->trigger("BeforeSave", array(&$params));
     if ($params) {
         $this->engine->save($this->id, $params);
     }
     $this->trigger("AfterSave", $this);
 }
 /**
  * Initialize the <b>Controller</b>.
  *
  * Called by the <b>initializeFacade()</b> method.
  *
  * Override this method in your subclass of <b>Facade</b> if
  * one or both of the following are true:
  *
  * - You wish to initialize a different <b>Controller</b>.
  * - You have <b>Commands</b> to register with the <b>Controller</b> at startup.
  *
  * If you don't want to initialize a different <b>Controller</b>,
  * call <samp>parent::initializeController()</samp> at the beginning of your
  * method, then register Commands.
  *
  * @return void
  */
 protected function initializeController()
 {
     if (isset($this->controller)) {
         return;
     }
     $this->controller = Controller::getInstance($this->multitonKey);
 }
 protected function initializeController()
 {
     if ($this->controller != null) {
         return;
     }
     $this->controller = Controller::getInstance();
 }
Example #30
0
 /**
  * Among the stored selectors search those, which are matched with the 
  * current widget's state.
  *
  * For matched selectors {@link WidgetResultSet} will be filled with the 
  * data, passed from the user's models.
  *
  * In order to reduce the lookups of result of matching given widget with
  * the particular selector, intermediate caching in $GLBALS is used.
  *
  * @param WComponent widget to be analyzed
  * @return WidgetResultSet with the data that should be passed to this widget
  */
 function findMatched(WComponent $widget)
 {
     $wrs = new WidgetResultSet();
     foreach ($this->fors as $selectors => $v) {
         foreach (explode(",", $selectors) as $selector) {
             // hit the cache, ie SelectorMatcher::matched for this widget and selector
             // was called
             if (array_key_exists($md5 = md5($selector . $widget->getId()), $GLOBALS['__m_cache'])) {
                 if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) {
                     continue;
                 } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) {
                     @$wrs->merge($this->for_values[$selectors]);
                     @$wrs->setDef($this->default_values[$selectors]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors[$selectors]);
                         unset($this->for_values[$selectors]);
                     }
                 } elseif (SelectorMatcher::matched($widget, $selector, null, null)) {
                     @$wrs->merge($this->for_values[$selectors]);
                     @$wrs->setDef($this->default_values[$selectors]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors[$selectors]);
                         unset($this->for_values[$selectors]);
                     }
                 }
             } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, null, null)) {
                 @$wrs->merge($this->for_values[$selectors]);
                 @$wrs->setDef($this->default_values[$selectors]);
                 if (isset($this->f1s[$selectors])) {
                     unset($this->fors[$selectors]);
                     unset($this->for_values[$selectors]);
                 }
             }
         }
     }
     //once again but now for selector with indexes
     foreach ($this->fors_array as $selectors => $arr) {
         foreach (explode(",", $selectors) as $selector) {
             $md5 = md5($selector . $widget->getId());
             if (array_key_exists($md5, $GLOBALS['__m_cache'])) {
                 if ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::FALSE_CACHE) {
                     continue;
                 } elseif ($GLOBALS['__m_cache'][$md5] === SelectorMatcher::TRUE_CACHE) {
                     @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                     @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors_array[$selectors]['index'][$matched]);
                         unset($this->fors_array[$selectors]['scope'][$matched]);
                         unset($this->for_values_array[$selectors][$matched]);
                     }
                 } elseif (SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) {
                     @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                     @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                     if (isset($this->f1s[$selectors])) {
                         unset($this->fors_array[$selectors]['index'][$matched]);
                         unset($this->fors_array[$selectors]['scope'][$matched]);
                         unset($this->for_values_array[$selectors][$matched]);
                     }
                 }
             } elseif ($GLOBALS['__m_cache'][$md5] = SelectorMatcher::matched($widget, $selector, $arr['index'], $arr['scope'])) {
                 @$wrs->merge($this->for_values_array[$selectors][$matched = Controller::getInstance()->getDisplayModeParams()->getMatchedIndex()]);
                 @$wrs->setDef($this->default_values_array[$selectors][$matched]);
                 if (isset($this->f1s[$selectors])) {
                     unset($this->fors_array[$selectors]['index'][$matched]);
                     unset($this->fors_array[$selectors]['scope'][$matched]);
                     unset($this->for_values_array[$selectors][$matched]);
                 }
             }
         }
     }
     return $wrs;
 }