Exemplo n.º 1
0
Arquivo: BlockIps.php Projeto: ksst/kf
 public function execute(\Koch\Event\Event $event)
 {
     $ip = \Koch\Http\HttpRequest::getRemoteAddress();
     if (in_array($ip, $this->blockedIps, true)) {
         $event->cancel();
     }
 }
Exemplo n.º 2
0
 /**
  * Redirect to Referer.
  */
 public function redirectToReferer()
 {
     $referer = $this->request->getReferer();
     // we have a referer in the environment
     if (empty($referer) === false) {
         $this->redirect(SERVER_URL . $referer);
     } else {
         // build referer on base of the current module
         $route = $this->request->getRoute();
         // we use internal rewrite style here: /module/action
         $redirect_to = '/' . $route->getModuleName();
         $submodule = $route->getSubModuleName();
         if (empty($submodule) === false) {
             $redirect_to .= '/' . $submodule;
         }
         // redirect() builds the url
         $this->response->redirect($redirect_to);
     }
 }
Exemplo n.º 3
0
/**
 * Smarty ModuleNavigation
 * Displays a Module Navigation Element
 * depends on module configuration file.
 *
 * Examples:
 * <pre>
 * {modulnavigation}
 * </pre>
 *
 * Type:     function<br>
 * Name:     modulenavigation<br>
 * Purpose:  display modulenavigation<br>
 *
 * @param array  $params
 * @param Smarty $smarty
 *
 * @return string
 */
function Smarty_function_modulenavigation($params, $smarty)
{
    $module = \Koch\Http\HttpRequest::getRoute()->getModule();
    $file = APPLICATION_MODULES_PATH . $module . DIRECTORY_SEPARATOR . $module . '.menu.php';
    if (is_file($file)) {
        // this includes the file, which contains a php array name $modulenavigation
        include $file;
        // push the $modulenavigation array to a callback function
        // for further processing of the menu items
        $modulenavigation = array_map('applyCallbacks', $modulenavigation);
        $smarty->assign('modulenavigation', $modulenavigation);
        // The file is located in /themes/core/view/smarty/modulenavigation-generic.tpl
        return $smarty->fetch('modulenavigation-generic.tpl');
    } else {
        // the module menu navigation file is missing
        $smarty->assign('modulename', $module);
        $errormessage = $smarty->fetch('modulenavigation_not_found.tpl');
        trigger_error($errormessage);
    }
}
Exemplo n.º 4
0
Arquivo: Form.php Projeto: ksst/kf
 /**
  * Set Values to Form.
  *
  * An associative array is used to pre-populate form elements.
  * The keys of this array correspond with the element names.
  *
  * There are two use cases for this method:
  * 1) pre-filled form
  *    Some default values are set to the form, which then get altered by the user.
  * b) incomming post data
  *    Set the incomming POST data values are set to the form for validation.
  *
  * @param object|array $data Object or Array. If null (default), POST parameters are used.
  */
 public function setValues($data = null)
 {
     // because $data might be an object, typecast $data object to array
     if (is_object($data)) {
         $data = (array) $data;
     }
     if (null === $data) {
         // fetch data from POST
         if ('POST' === \Koch\Http\HttpRequest::getRequestMethod()) {
             $data = \Koch\Http\HttpRequest::getPost();
         }
     }
     // now we got an $data array to populate all the formelements with (setValue)
     foreach ($data as $key => $value) {
         foreach ($this->formelements as $formelement) {
             /*
              * Exclude some formelements from setValue() by type, e.g. Buttons, etc.
              * Setting the value would just change the visible "name" of these elements.
              */
             $type = $formelement->getType();
             if (true === in_array($type, ['submit', 'button', 'cancelbutton', 'resetbutton'], true)) {
                 continue;
             }
             // data[key] and formelement[name] have to match
             //if ($formelement->getName() == ucfirst($key)) {
             $formelement->setValue($value);
             //}
         }
     }
 }
Exemplo n.º 5
0
Arquivo: Mapper.php Projeto: ksst/kf
 /**
  * Returns the fullpath to Template by searching in the Module Template Path.
  *
  * @param string $template Template Filename
  * @param string $module
  *
  * @return string
  */
 public static function getModuleTemplatePath($template, $module = null)
 {
     $paths = self::getModuleTemplatePaths($module);
     // check if template exists in one of the defined paths
     $module_template = self::findFileInPaths($paths, $template);
     #\Koch\Debug\Debug::firebug('Module Template: ' . $module_template . '<br />');
     if ($module_template !== null) {
         return $module_template;
     } else {
         // fetch renderer name for template path construction
         $renderer = HttpRequest::getRoute()->getRenderEngine();
         // the template with that name is not found on our default paths
         // @todo if this would be a html template, we could skip determining the render engine
         return APPLICATION_PATH . 'themes/core/view/' . $renderer . '/template_not_found.tpl';
     }
 }
Exemplo n.º 6
0
 public function testMethod_setRequestMethod()
 {
     $this->request->setRequestMethod('BUTTHEAD');
     $this->assertEqual('BUTTHEAD', HttpRequest::getRequestMethod());
 }
Exemplo n.º 7
0
 public static function getAjaxMode()
 {
     return HttpRequest::isAjax();
 }
Exemplo n.º 8
0
 /**
  * Returns the fullpath to Template by searching in the Module Template Path
  *
  * @param  string $template Template Filename
  * @return string
  */
 public static function getModuleTemplatePath($template)
 {
     $paths = self::getModuleTemplatePaths();
     $module_template = null;
     // check if template exists in one of the defined paths
     $module_template = self::findFileInPaths($paths, $template);
     if ($module_template != null) {
         return $module_template;
     } else {
         // fetch renderer name for template path construction
         $renderer = HttpRequest::getRoute()->getRenderEngine();
         // the template with that name is not found on our default paths
         return ROOT_THEMES_CORE . 'view' . DIRECTORY_SEPARATOR . $renderer . DIRECTORY_SEPARATOR . 'template_not_found.tpl';
     }
 }
Exemplo n.º 9
0
 public function testMethod_match_SEO_Dynamic_Routes()
 {
     HttpRequest::setRequestMethod('GET');
     $this->router->prepareRequestURI('http://example.com/category/movies/Se7en.htm');
     $route = $this->router->route();
     HttpRequest::setRequestMethod('GET');
     $this->router->prepareRequestURI('http://example.com/feeds/news/atom.xml');
     $route = $this->router->route();
     HttpRequest::setRequestMethod('GET');
     $this->router->prepareRequestURI('http://example.com/news/atom.xml');
     $route = $this->router->route();
     $this->markTestIncomplete('Test not implemented yet.');
 }
Exemplo n.º 10
0
 /**
  * Returns the object Koch_Theme for accessing Configuration Values
  *
  * @return object Koch_Theme
  */
 public function getTheme()
 {
     if ($this->theme === null) {
         $themename = HttpRequest::getRoute()->getThemeName();
         $this->theme = new \Koch\View\Helper\Theme($themename);
     }
     return $this->theme;
 }