Exemplo n.º 1
0
 /**
  * simple function for creating prg pattern. 
  * (Keep state when reloading browser and resends forms etc.) 
  * @param int $last
  */
 public static function prg($max_time = 0)
 {
     if (!html::csrfValidate()) {
         http::locationHeader('/error/accessdenied', 'Bad request');
         return;
     }
     // genrate a session var holding the _POST
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $uniqid = uniqid();
         $_SESSION['post'][$uniqid] = $_POST;
         $_SESSION['post'][$uniqid]['prg_time'] = time();
         $_SESSION['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
         header("HTTP/1.1 303 See Other");
         $location = self::getRedirect() . 'prg=1&uniqid=' . $uniqid;
         self::locationHeader($location);
     }
     if (!isset($_SESSION['REQUEST_URI'])) {
         $_SESSION['post'] = null;
     } else {
         if (isset($_GET['prg'])) {
             $uniqid = $_GET['uniqid'];
             if (isset($_SESSION['post'][$uniqid])) {
                 if ($max_time && $_SESSION['post'][$uniqid]['prg_time'] + $max_time < time()) {
                     unset($_SESSION['post'][$uniqid]);
                 } else {
                     $_POST = $_SESSION['post'][$uniqid];
                 }
             }
         } else {
             @($_SESSION['REQUEST_URI'] = null);
         }
     }
 }
Exemplo n.º 2
0
 /**
  * method for getting title of page
  * @return string   $title title of document
  */
 public static function getTitle()
 {
     if (!empty(self::$title)) {
         return self::$title;
     }
     return html::specialEncode(conf::getMainIni('meta_title'));
 }
Exemplo n.º 3
0
 /**
  * Simple pattern for creating PRG. 
  * (Keep state when reloading browser and resends forms etc.) 
  * @param int $last
  */
 public static function prg($max_time = 0)
 {
     if (!html::csrfValidate()) {
         http::locationHeader('/error/accessdenied', 'Bad request');
         return;
     }
     prg::prg($max_time);
 }
Exemplo n.º 4
0
 /**
  * Get HTML mail part from ID
  * @param string $title
  * @param string $body
  * @paramn string $template_path
  * @return string $html
  */
 public function getEmailHtml($title, $body, $template_path = null)
 {
     $template = $this->getHtmlTemplate($template_path);
     if ($this->titleInBody) {
         $body = "# " . $title . PHP_EOL . PHP_EOL . $body;
     }
     $parser = new GithubMarkdown();
     $body = $parser->parse($body);
     $subject = html::specialEncode($title);
     $str = str_replace(array('{title}', '{content}'), array($subject, $body), $template);
     return $str;
 }
Exemplo n.º 5
0
 /**
  * method for getting html for front page. If no logo has been 
  * uploaded. You will get logo as html
  * @param type $options options to give to html::createHrefImage
  * @return string $str the html compsoing the logo or main title
  */
 public static function getLogoHTML($options = array())
 {
     $logo = conf::getMainIni('logo');
     if (!$logo) {
         $title = $_SERVER['HTTP_HOST'];
         $link = html::createLink('/', $title);
         return $str = "<div id=\"logo_title\">{$link}</div>";
     } else {
         $file = "/logo/" . conf::getMainIni('logo');
         $src = conf::getWebFilesPath($file);
         if (!isset($options['alt'])) {
             $options['alt'] = $_SERVER['HTTP_HOST'];
         }
         $href = html::createHrefImage('/', $src, $options);
         $str = '<div id="logo_img">' . $href . '</div>' . "\n";
         //die($str);
         return $str;
     }
 }
Exemplo n.º 6
0
 /**
  * Returns a dropdown with *the last 12 months* counting from current month
  * @param string $name name of form element
  * @param int $selected the selected month
  * @return string $html the clean html select element
  */
 public static function monthOffsetDropdown($name = 'month', $start = null, $selected = null, $extra = array())
 {
     if (!$start) {
         $start = date::getCurrentYear() . '-' . date::getCurrentMonth();
     } else {
         $ary = explode('-', $start);
         $start = $ary[0] . '-' . $ary[1];
     }
     if (!$selected) {
         $selected = date::getCurrentYear() . '-' . date::getCurrentMonth();
     } else {
         $ary = explode('-', $selected);
         $selected = $ary[0] . '-' . $ary[1];
     }
     $months = self::last12Months($start);
     foreach ($months as $key => $val) {
         $months[$key] = array('id' => $val['year'] . '-' . $val['month'], 'value' => date::getMonthName($val['month']));
     }
     return html::selectClean($name, $months, 'value', 'id', $selected, $extra);
 }
Exemplo n.º 7
0
 /**
  * sets all <head></head> meta info. 
  * Params should not be encoded
  * @param string $title html page title
  * @param string $description html page description and og description
  * @param string $keywords keywords
  * @param string $image image
  * @param string $type og type
  */
 public static function setMetaAll($title, $description = '', $keywords = '', $image = '', $type = '', $author = '')
 {
     // title
     assets::setTitle(html::specialEncode($title));
     self::setMetaAsStr('<meta property="og:title" content="' . html::specialEncode($title) . '" />' . "\n");
     // description
     if (empty($description)) {
         $description = conf::getMainIni('meta_desc');
     }
     $desc = strings::substr2($description, 255);
     $og_desc = html::specialEncode(strings::substr2($description, 320));
     if (!empty($og_desc)) {
         self::setMetaAsStr('<meta property="og:description" content="' . $og_desc . '"/>' . "\n");
     }
     if (!empty($desc)) {
         self::setMeta(array('description' => $desc));
     }
     if (!empty($author)) {
         self::setMeta(array('author' => $author));
     }
     // keywords
     if (empty($keywords)) {
         $keywords = conf::getMainIni('meta_meywords');
     }
     if (!empty($keywords)) {
         self::setMeta(array('keywords' => $keywords));
     }
     // image
     if (!empty($image)) {
         $server = conf::getSchemeWithServerName();
         $image = $server . $image;
     }
     if (!empty($image)) {
         self::setMetaAsStr('<meta property="og:image" content="' . $image . '"/>' . "\n");
     }
     // type
     if (!empty($type)) {
         self::setMetaAsStr('<meta property="og:type" content="' . $type . '"/>' . "\n");
     }
 }
Exemplo n.º 8
0
 /**
  * transforms a menu array into a menu link
  * @param array $menu
  * @return string $str
  */
 public static function parseMenuLinkFromArray($menu)
 {
     if (!isset($menu['extra'])) {
         $menu['extra'] = array();
     }
     if (isset($menu['auth']) && !empty($menu['auth'])) {
         if (!session::checkAccessClean($menu['auth'])) {
             return false;
         }
         return html::createLink($menu['url'], $menu['title'], $menu['extra']);
     } else {
         return html::createLink($menu['url'], $menu['title'], $menu['extra']);
     }
 }
Exemplo n.º 9
0
 /**
  * method that creates birthday dropdown
  * access of the submitted data can be found in the _POST['birth_day'],
  * $_POST['birth_month'], $_POST['birth_year']
  * @param string $name name of the form element
  * @param array $init the init array 
  * @return array $ary array with select elements in array ('day', 'month', 'year')
  */
 public static function birthdayDropdown($name = 'birth', $init = array())
 {
     for ($i = 1; $i <= 31; $i++) {
         $days[$i] = array('id' => $i, 'value' => $i);
     }
     for ($i = 1; $i <= 12; $i++) {
         $months[$i] = array('id' => $i, 'value' => dateGetMonthName($i));
     }
     $currentYear = date::getCurrentYear();
     $goBack = 120;
     //for ($i = $goBack; $goBack < $currentYear;  $currentYear-- ) {
     while ($goBack) {
         $years[$currentYear] = array('id' => $currentYear, 'value' => $currentYear);
         $currentYear--;
         $goBack--;
     }
     $day = html::selectClean('birth_day', $days, 'id', 'value');
     $month = html::selectClean('birth_month', $months, 'id', 'value');
     $year = html::selectClean('birth_year', $years, 'id', 'value');
     $ret = array('day' => $day, 'month' => $month, 'year' => $year, 'day_options' => $days, 'month_options' => $months, 'year_options' => $years);
     return $ret;
 }
Exemplo n.º 10
0
 public function importForm()
 {
     $f = new html();
     $f->formStart();
     $f->legend('Indsæt brugere');
     $f->textarea('users');
     $f->submit('submit', 'Send');
     $f->formEnd();
     return $f->getStr();
 }
Exemplo n.º 11
0
 /**
  * 
  * get feed string
  * @return  string  items in the feed
  */
 public function getItems($rows)
 {
     $items = '';
     foreach ($rows as $val) {
         $val = html::specialEncode($val);
         $items .= "<item>\n";
         $items .= "<title>{$val['title']}</title>\n";
         if (!isset($val['guid'])) {
             $items .= "<guid>{$val['url']}</guid>\n";
         } else {
             $items .= "<guid>{$val['guid']}</guid>\n";
         }
         $items .= "<link>{$val['url']}</link>\n";
         $items .= "<description>{$val['abstract']}</description>\n";
         $items .= "<pubDate>" . $this->timestampToPubdate($val['created']) . "</pubDate>\n";
         $items .= "</item>";
     }
     return $items;
 }
Exemplo n.º 12
0
 /**
  * Get a `<link rel="stylesheet" href="/link/to/css.css" .. </link>`  
  * @param string $css path to CSS
  * @return string $css link
  */
 public function getCssLink($css)
 {
     $css = \diversen\html::specialEncode($css);
     return '<link rel="stylesheet" href="' . $css . '" />"';
 }
Exemplo n.º 13
0
 /**
  * Form that creates a kvadrille
  * @param string $title
  * @return string $html
  */
 public function formCreateHel($title = 'Opret en hel kvadrille')
 {
     $f = new html();
     $f->init(array(), 'send', true);
     $f->formStart();
     $f->legend($title);
     //$f->label('name','Indtast et navn');
     //$f->text('name');
     $h = new eHelpers();
     $ary = $h->getFormHalveAry();
     $f->label('halv', 'Vælg en halv kvadrille som skal indgå i din kvadrille');
     $f->selectAry('halv', $ary);
     $f->label('send');
     $f->submit('send', 'Opret');
     $f->formEnd();
     return $f->getStr();
 }
Exemplo n.º 14
0
 public function getAdminLink($id)
 {
     $str = html::createLink("/account/admin/edit/{$id}", lang::translate('(Admin) Edit profile'));
     return $str;
 }
Exemplo n.º 15
0
 /**
  * Return <table> begin
  * @param array $options table options
  * @return string $html <table>
  */
 public static function tableBegin($options)
 {
     $extra = html::parseExtra($options);
     return "<table {$extra}>\n";
 }