コード例 #1
0
ファイル: View.php プロジェクト: piiskop/pstk
 /**
  * This function builds the main structure in HTML.
  *
  * @access public
  * @author kalmer:piiskop <*****@*****.**>
  * @param string $parameters['address']
  *        	the address
  * @param string $parameters['blogDate']
  *        	the date of the blog
  * @param string $parameters['blogEntry']
  *        	the blog entry
  * @param Human $parameters['designer']
  *        	the designer
  * @param string $parameters['menu']
  *        	the body
  * @param string $parameters['phoneNumber']
  *        	the phone number
  * @param string $parameters['title']
  *        	the title
  * @param string $parameters['twitter']
  *        	the Twitter-time
  * @return string the parsed HTML-structure
  * @uses BEGINNING_OF_URL for links
  * @uses \pstk\ErrorView for displaying error messages
  * @uses MENU_COMMON for the common menu
  * @uses MENU_SIDE for the menu in sidebar
  */
 public static function buildView($parameters)
 {
     require_once 'HTML/Template/IT.php';
     require_once dirname(__FILE__) . '/../php/ErrorView.php';
     \PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(new \pstk\ErrorView(), 'raiseError'));
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'html');
     $tpl->loadTemplatefile('particle-template.html');
     if (isset($parameters['menus'])) {
         if (isset($parameters['menus'][MENU_COMMON])) {
             $tpl->setCurrentBlock('common-menu');
             $tpl->setVariable(array('COMMON-MENU' => $parameters['menus'][MENU_COMMON]));
             $tpl->parse('common-menu');
         }
         if (isset($parameters['menus'][MENU_SIDE])) {
             $tpl->setCurrentBlock('menu-in-sidebar');
             $tpl->setVariable(array('MENU-IN-SIDEBAR' => $parameters['menus'][MENU_SIDE]));
             $tpl->parse('menu-in-sidebar');
         }
     }
     if (isset($parameters['posts'])) {
         $tpl->setCurrentBlock('posts');
         $tpl->setVariable(array('POSTS' => $parameters['posts']));
         $tpl->parse('posts');
     }
     require_once dirname(__FILE__) . '/Model.php';
     $model = new Model();
     $model->setComplete();
     require_once dirname(__FILE__) . '/../php/CssView.php';
     $tpl->setCurrentBlock('html');
     $tpl->setVariable(array('ACTION' => '', 'BEGINNING-OF-URL' => BEGINNING_OF_URL, 'FOLLOW-ME' => $model->translate(array('property' => 'followMe')), 'HEADING' => $parameters['title'], 'OLDER-POSTS' => $model->translate(array('property' => 'olderPosts')), 'NEWER-POSTS' => $model->translate(array('property' => 'newerPosts')), 'SEARCH' => \pstk\String::translate('search'), 'SUBSCRIBE' => $model->translate(array('property' => 'subscribe')), 'STYLE' => \pstk\CssView::buildCss(array('fileName' => 'particle-template')), 'TITLE' => mb_strtoupper($parameters['title'], 'UTF-8')));
     $tpl->parse('html');
     return $tpl->get('html');
 }
コード例 #2
0
ファイル: MenuElementView.php プロジェクト: piiskop/pstk
 /**
  * This function creates a HTML-block for a menu item.
  *
  * @access public
  * @author k
  * @param MenuElement $parameters['menuElement']
  *        	the menu element
  * @param string $parameters['type']
  *        	the type
  * @see MenuElement::$type
  * @uses Error for error handling
  * @uses ErrorView for error handling
  * @uses MENU_COMMON for the common menu
  * @uses MENU_SIDE for the menu in sidebar
  */
 public static function buildMenuElement($parameters)
 {
     require_once 'HTML/Template/IT.php';
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'html');
     $tpl->loadTemplatefile('particle-template.html');
     switch ($parameters['type']) {
         case MENU_COMMON:
             $tpl->setCurrentBlock('item-in-common-menu');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-COMMON-MENU' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-COMMON-MENU' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-common-menu');
             // echo ' 38: ', $tpl->get('menu-item');
             return $tpl->get('item-in-common-menu');
             break;
         case MENU_SIDE:
             $tpl->setCurrentBlock('item-in-menu-in-sidebar');
             $tpl->setVariable(array('HREF-OF-ITEM-IN-MENU-IN-SIDEBAR' => null === $parameters['menuElement']->getHref() ? $parameters['menuElement']->translate(array('property' => 'href', 'isSlug' => true)) : $parameters['menuElement']->getHref(), 'LABEL-OF-ITEM-IN-MENU-IN-SIDEBAR' => $parameters['menuElement']->translate(array('property' => 'label'))));
             $tpl->parse('item-in-menu-in-sidebar');
             return $tpl->get('item-in-menu-in-sidebar');
             break;
         default:
             require_once dirname(__FILE__) . '/Error.php';
             $error = new Error();
             $error->setMessage(\pstk\String::translate('errorWhichMenu'));
             require_once dirname(__FILE__) . '/ErrorView.php';
             ErrorView::raiseError($error);
     }
 }
コード例 #3
0
ファイル: ErrorView.php プロジェクト: piiskop/pstk
 /**
  * This function raises the error as a callback function for views.
  *
  * @access public
  * @author Kalmer Piiskop <*****@*****.**>
  * @param object $errorFromOutside
  *        	the error object
  */
 public static function raiseError($errorFromOutside)
 {
     require_once 'HTML/Template/IT.php';
     $template = new \HTML_Template_IT(ROOT_FOLDER . '../html');
     $template->loadTemplateFile('errors.html');
     $template->setCurrentBlock('html');
     $template->setVariable(array('TITLE-OF-ERROR' => \pstk\String::translate('titleOfError'), 'MESSAGE' => $errorFromOutside->getMessage(), 'DEBUG-INFO' => $errorFromOutside->getDebugInfo()));
     $template->parse('html');
     exit($template->get('html'));
 }
コード例 #4
0
ファイル: PostView.php プロジェクト: piiskop/pstk
 /**
  * This function creates a HTML-block for a post item.
  *
  * @access public
  * @author kalmer:piiskop <*****@*****.**>
  * @param Service $parameters['post']
  *        	the post
  * @return string the parsed post
  * @uses BEGINNING_OF_URL for links
  */
 public static function buildPost($parameters)
 {
     require_once 'HTML/Template/IT.php';
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'html');
     $tpl->loadTemplatefile('particle-template.html');
     $tpl->setCurrentBlock('post-item');
     $date = strtotime($parameters['post']->getDate());
     $tpl->setVariable(array('BEGINNING-OF-URL' => BEGINNING_OF_URL, 'DATE-OF-POST' => date('d', $date), 'MONTH-OF-POST' => date('M', $date), 'HREF-TO-COMMENTS' => \pstk\String::translate('comments'), 'HREF-TO-POST' => $parameters['post']->translate(array('property' => 'heading', 'isSlug' => true)), 'LABEL-OF-POST' => $parameters['post']->translate(array('property' => 'heading')), 'LEAD-OF-POST' => $parameters['post']->translate(array('property' => 'lead')), 'NUMBER-OF-COMMENTS' => count($parameters['post']->getComments())));
     $tpl->parse('post-item');
     return $tpl->get('post-item');
 }
コード例 #5
0
ファイル: ago.php プロジェクト: piiskop/pstk
/**
 * This function finds the difference between two timestamps and constructs a
 * human-readable string for it.
 *
 * @author kalmer:piiskop <pandeero@gmail.com.
 * @param string $parameters['timestampInPast']
 *        	the timestamp in the past in the format
 *        	<code>/\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}/u</code>
 * @param string $parameters['timestampInFuture']
 *        	the timestamp in the future in the format
 *        	<code>/\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}/u</code>
 * @return string the human-readable string
 */
function findDifference($parameters)
{
    if (isset($parameters['timestampInPast'])) {
        $timestampInPast = new DateTime($parameters['timestampInPast']);
    } else {
        $timestampInPast = new DateTime();
    }
    if (isset($parameters['timestampInFuture'])) {
        $timestampInFuture = new DateTime($parameters['timestampInFuture']);
    } else {
        $timestampInFuture = new DateTime();
    }
    if ($timestampInFuture->getTimestamp() > $timestampInPast->getTimestamp()) {
        $difference = $timestampInPast->diff($timestampInFuture);
    } else {
        $difference = $timestampInFuture->diff($timestampInPast);
    }
    $partsOfTime = array();
    // @formatter:off
    if ($difference->y > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->y, 'unitInSingular' => \pstk\String::translate('year'), 'unitInPlural' => \pstk\String::translate('years')));
    }
    if ($difference->m > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->m, 'unitInSingular' => \pstk\String::translate('month'), 'unitInPlural' => \pstk\String::translate('months')));
    }
    if ($difference->d > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->d, 'unitInSingular' => \pstk\String::translate('day'), 'unitInPlural' => \pstk\String::translate('days')));
    }
    if ($difference->h > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->h, 'unitInSingular' => \pstk\String::translate('hour'), 'unitInPlural' => \pstk\String::translate('hours')));
    }
    if ($difference->i > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->i, 'unitInSingular' => \pstk\String::translate('minute'), 'unitInPlural' => \pstk\String::translate('minutes')));
    }
    if ($difference->s > 0) {
        echo ' 193 ';
        $partsOfTime[] = generatePartialString(array('time' => $difference->s, 'unitInSingular' => \pstk\String::translate('second'), 'unitInPlural' => \pstk\String::translate('seconds')));
    }
    // @formatter:on
    $humanReadableString = implode(" ", $partsOfTime);
    // 	echo ' <br/>201: ', $humanReadableString;
    return $humanReadableString;
}
コード例 #6
0
ファイル: View.php プロジェクト: piiskop/pstk
 /**
  * This function builds the main structure in HTML.
  *
  * @access public
  * @author arnold<*****@*****.**>
  * @param string $parameters['address']
  *        	the address
  * @param string $parameters['blogDate']
  *        	the date of the blog
  * @param string $parameters['blogEntry']
  *        	the blog entry
  * @param Human $parameters['designer']
  *        	the designer
  * @param string $parameters['menu']
  *        	the body
  * @param string $parameters['phoneNumber']
  *        	the phone number
  * @param string $parameters['title']
  *        	the title
  * @param string $parameters['twitter']
  *        	the Twitter-time
  * @return string the parsed HTML-structure
  * @uses BEGINNING_OF_URL for links
  * @uses MENU_COMMON for the common menu
  * @uses MENU_OUTER for the menu of outer links
  * @uses MENU_INNER for the menu of inner links
  */
 public static function buildView($parameters)
 {
     require_once 'HTML/Template/IT.php';
     require_once dirname(__FILE__) . '/ErrorView.php';
     ///////////////////////
     \PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, array(new ErrorView(), 'raiseError'));
     $tpl = new \HTML_Template_IT(ROOT_FOLDER . 'tutshtml');
     $tpl->loadTemplatefile('burnstudio2-template.html');
     // echo ' 182: <pre>';var_dump($parameters); echo '</pre>';
     if (isset($parameters['logos'])) {
         $tpl->setCurrentBlock('logos');
         $tpl->setVariable(array('LOGO' => $parameters['logos']));
         $tpl->parse('logos');
     }
     if (isset($parameters['menus'])) {
         if (isset($parameters['menus'][MENU_COMMON])) {
             $tpl->setCurrentBlock('menu-items');
             $tpl->setVariable(array('MENU-ITEMS' => $parameters['menus'][MENU_COMMON]));
             $tpl->parse('menu-items');
             // echo ' 190: ', $tpl->get('menu-items');
         }
         if (isset($parameters['menus'][MENU_OUTER])) {
             $tpl->setCurrentBlock('outer-links');
             $tpl->setVariable(array('OTHER' => \pstk\String::translate('other'), 'LINKS' => \pstk\String::translate('links'), 'OUTER-LINKS' => $parameters['menus'][MENU_OUTER]));
             $tpl->parse('outer-links');
         }
         if (isset($parameters['menus'][MENU_INNER])) {
             $tpl->setCurrentBlock('inner-links');
             $tpl->setVariable(array('INNER-LINK' => $parameters['menus'][MENU_INNER]));
             $tpl->parse('inner-links');
         }
     }
     if (isset($parameters['services'])) {
         $tpl->setCurrentBlock('services');
         $tpl->setVariable(array('SERVICES' => $parameters['services']));
         $tpl->parse('services');
     }
     $tpl->setCurrentBlock('html');
     $tpl->setVariable(array('ACTION' => '', 'ADDRESS' => $parameters['address'], 'BEGINNING-OF-URL' => BEGINNING_OF_URL, 'BLOG-DATE' => date('m.d.Y', strtotime($parameters['blogDate'])), 'BLOG-ENTRY' => $parameters['blogEntry'], 'LATEST' => \pstk\String::translate('latest'), 'BLOG' => \pstk\String::translate('blog'), 'HREF-OF-BLOG' => BLOG, 'CALL-US' => \pstk\String::translate('callUs'), 'NOW' => \pstk\String::translate('now'), 'EMAIL-OF-DESIGNER' => $parameters['designer']->getEmail(), 'HREF-OF-DESIGNER' => $parameters['designer']->getHref(), 'LABEL-OF-DESIGNER' => $parameters['designer']->getLabel(), 'NAME-OF-DESIGNER' => \str_replace(' ', '&#160', $parameters['designer']->getName()), 'HREF-OF-VIDEOS' => VIDEOS, 'PHONE-NUMBER' => $parameters['phoneNumber'], 'QUICK' => \pstk\String::translate('quick'), 'VIDEOS' => \pstk\String::translate('videos'), 'HEADING-TO-VIDEOS' => \pstk\String::translate('headingToVideos'), 'SEARCH' => \pstk\String::translate('search'), 'STYLE' => \tuts\View::buildCss(), 'TIME' => \tuts\View::findDifference(array('timestampInPast' => $parameters['twitter'])), 'TITLE' => $parameters['title'], 'TWITTER' => \pstk\String::translate('twitter'), 'FEED' => \pstk\String::translate('feed'), 'LIKE' => \pstk\String::translate('like'), 'OUR' => \pstk\String::translate('our'), 'LOCATION' => \pstk\String::translate('location'), 'DESIGNED-BY' => \pstk\String::translate('designedBy')));
     $tpl->parse('html');
     return $tpl->get('html');
 }
コード例 #7
0
ファイル: View.php プロジェクト: piiskop/pstk
 /**
  * This function finds the difference between two timestamps and constructs
  * a
  * human-readable string for it.
  *
  * @access private
  * @param string $parameters['timestampInPast']
  *        	the timestamp in the past in the format
  *        	<code>/\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}/u</code>
  * @param string $parameters['timestampInFuture']
  *        	the timestamp in the future in the format
  *        	<code>/\d{4}-\d{1,2}-\d{1,2}\s\d{1,2}:\d{1,2}:\d{1,2}/u</code>
  * @return string the human-readable string
  */
 private static function findDifference($parameters)
 {
     if (isset($parameters['timestampInPast'])) {
         try {
             $timestampInPast = new \DateTime($parameters['timestampInPast']);
         } catch (\Exception $e) {
             // @formatter:off
             die(sprintf('Varasem ajatempel ei ole sobivas vormingus. Veateade: %1$s Teekond vea olukorrani: %2$s', $e->getMessage(), $e->getTraceAsString()));
             // @formatter:on
         }
     } else {
         $timestampInPast = new \DateTime();
     }
     if (isset($parameters['timestampInFuture'])) {
         try {
             $timestampInFuture = new \DateTime($parameters['timestampInFuture']);
         } catch (Exception $e) {
             // @formatter:off
             die(\sprintf('Hilisem ajatempel ei ole sobivas vormingus. Veateade: %1$s Teekond vea olukorrani: %2$s', $e->getMessage(), $e->getTraceAsString()));
             // @formatter:on
         }
     } else {
         $timestampInFuture = new \DateTime();
     }
     if ($timestampInFuture->getTimestamp() > $timestampInPast->getTimestamp()) {
         $difference = $timestampInPast->diff($timestampInFuture);
     } else {
         $difference = $timestampInFuture->diff($timestampInPast);
     }
     $partsOfTime = array();
     if ($difference->y > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->y, 'unitInSingular' => \pstk\String::translate('year'), 'unitInPlural' => \pstk\String::translate('years')));
     }
     if ($difference->m > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->m, 'unitInSingular' => \pstk\String::translate('month'), 'unitInPlural' => \pstk\String::translate('months')));
     }
     if ($difference->d > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->d, 'unitInSingular' => \pstk\String::translate('day'), 'unitInPlural' => \pstk\String::translate('days')));
     }
     if ($difference->h > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->h, 'unitInSingular' => \pstk\String::translate('hour'), 'unitInPlural' => \pstk\String::translate('hours')));
     }
     if ($difference->i > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->i, 'unitInSingular' => \pstk\String::translate('minute'), 'unitInPlural' => \pstk\String::translate('minutes')));
     }
     if ($difference->s > 0) {
         $partsOfTime[] = \psdtohtml\View::generatePartialString(array('time' => $difference->s, 'unitInSingular' => \pstk\String::translate('second'), 'unitInPlural' => \pstk\String::translate('seconds')));
     }
     $humanReadableString = implode(" ", $partsOfTime);
     // echo ' <br/>201: ', $humanReadableString;
     return $humanReadableString;
 }
コード例 #8
0
ファイル: ago_by_kalmer.php プロジェクト: piiskop/pstk
        $partsOfTime[] = generatePartialString(array('time' => $difference->h, 'unit' => 'hour'));
    }
    if ($difference->i > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->i, 'unit' => 'minute'));
    }
    if ($difference->s > 0) {
        $partsOfTime[] = generatePartialString(array('time' => $difference->s, 'unit' => 'second'));
    }
    // @formatter:on
    $humanReadableString = implode(" ", $partsOfTime);
    return $humanReadableString;
}
$_SESSION['language'] = 'et_EE';
$timeInPast = strtotime('2016-2-3 5:8:9');
echo ' <br/>85: ', $timeInPast;
$timeInFuture = strtotime('2032-04-08 21:30:15');
// @formatter:off
echo ' <br/>38: ', sprintf('The incident has taken place %1$s.', ago(strtotime($timeInPast)));
echo ' <br/>85: ', sprintf('The incident is going to take place %1$s.', ago(strtotime($timeInFuture)));
echo ' <br/>89: ', sprintf('The incident has taken place %1$s.', _ago(strtotime($timeInPast), 0));
echo ' <br/>100: nullpnkt: ', date('YmdHis', 0);
echo ' <br/>100: PHP lõpp: ', date('YmdHis', PHP_INT_MAX);
echo ' <br/>93: ', sprintf('The incident is going to take place %1$s.', _ago(strtotime($timeInFuture), 20));
echo ' <br/>155: ', sprintf('The difference between 2015-11-11 16:25:00 and now is %1$s.', findDifference(array('timestampInPast' => '2015-10-11 16:25:00')));
echo ' <br/>197: ', sprintf('The difference between 2016-11-11 16:25:00 and now is %1$s.', findDifference(array('timestampInFuture' => '2018-11-11 16:25:00')));
$datetime1 = new DateTime('2009-10-14');
$datetime2 = new DateTime('2009-10-13');
$interval = $datetime2->diff($datetime1);
echo ' <br/>207: ', $interval->invert;
echo ' <br/>231: ', \pstk\String::translate('second');
// @formatter:on