Example #1
0
 /**
  * This method exists because the service container needs to be set before
  * the rest of API functionality gets loaded.
  */
 public function initialize()
 {
     $this->tpl = new \SpoonTemplate();
     $this->tpl->setForceCompile(true);
     $this->tpl->setCompileDirectory(BACKEND_CACHE_PATH . '/CompiledTemplates');
     $this->loadModules();
     $this->parse();
     $this->display();
 }
Example #2
0
 public function __construct()
 {
     require_once 'spoon/form/form.php';
     require_once 'spoon/form/button.php';
     require_once 'spoon/template/template.php';
     $this->tpl = new SpoonTemplate();
     $this->tpl->setForceCompile(true);
     $this->tpl->setCompileDirectory(BACKEND_CACHE_PATH . '/compiled_templates');
     $this->loadModules();
     $this->parse();
     $this->display();
 }
Example #3
0
 /**
  * @param int $step The step to load.
  */
 public function __construct($step)
 {
     // set setp
     $this->step = (int) $step;
     // skip step 1
     if ($this->step > 1) {
         // include path
         set_include_path($_SESSION['path_library'] . PATH_SEPARATOR . get_include_path());
         // load spoon
         require_once $_SESSION['path_library'] . '/spoon/spoon.php';
         // create template
         $this->tpl = new SpoonTemplate();
         $this->tpl->setForceCompile(true);
         $this->tpl->setCompileDirectory(dirname(__FILE__) . '/../cache/');
         // assign the path
         if (defined('PATH_WWW')) {
             $this->tpl->assign('PATH_WWW', PATH_WWW);
         }
         // create form
         $this->frm = new SpoonForm('step' . $step, 'index.php?step=' . $step);
         $this->frm->setParameter('class', 'forkForms submitWithLink');
         $this->frm->setParameter('id', 'installForm');
     }
 }
Example #4
0
<?php

date_default_timezone_set('Europe/Berlin');
// set include path
ini_set("include_path", ".:../library/");
// required classes
require_once 'spoon/spoon.php';
require_once 'publicApp/publicApp.php';
$tpl = new SpoonTemplate();
$tpl->setForceCompile(true);
$tpl->setCompileDirectory('./compiled_templates');
// do I know you?
if (SpoonSession::exists('public_uid')) {
    $tpl->assign('oLogout', true);
    $tpl->assign('oNavMe', true);
    $uid = SpoonSession::get('public_uid');
    $user = new User($uid);
    if ($user->GetFollowing() != null) {
        $values = $user->GetFollowing();
        $following = array();
        foreach ($values as $value) {
            $userFollowing = new User($value['friend']);
            if ($userFollowing->fb_uid == null) {
                $userFollowing->fb_uid = 1;
            }
            array_push($following, get_object_vars($userFollowing));
        }
        $tpl->assign('oFollowing', true);
        $tpl->assign('iFollowing', $following);
    } else {
        $tpl->assign('oNoFollowing', true);
Example #5
0
 /**
  * Builds & returns the pagination.
  *
  * @return	string
  * @param	string $URL
  * @param	int $offset
  * @param	string $order
  * @param	string $sort
  * @param	int $numResults
  * @param	int $numPerPage
  * @param	bool[optional] $debug
  * @param	string[optional] $compileDirectory
  */
 public static function getContent($URL, $offset, $order, $sort, $numResults, $numPerPage, $debug = true, $compileDirectory = null)
 {
     // current page
     $currentPage = ceil($offset / $numPerPage) + 1;
     // number of pages
     $numPages = ceil($numResults / $numPerPage);
     // load template
     $tpl = new SpoonTemplate();
     // compile directory
     if ($compileDirectory !== null) {
         $tpl->setCompileDirectory($compileDirectory);
     } else {
         $tpl->setCompileDirectory(dirname(__FILE__));
     }
     // force compiling
     $tpl->setForceCompile((bool) $debug);
     // previous url
     if ($currentPage > 1) {
         // label & url
         $previousLabel = self::$previous;
         $previousURL = str_replace(array('[offset]', '[order]', '[sort]'), array($offset - $numPerPage, $order, $sort), $URL);
         $tpl->assign('previousLabel', $previousLabel);
         $tpl->assign('previousURL', $previousURL);
     }
     // next url
     if ($currentPage < $numPages) {
         // label & url
         $nextLabel = self::$next;
         $nextURL = str_replace(array('[offset]', '[order]', '[sort]'), array($offset + $numPerPage, $order, $sort), $URL);
         $tpl->assign('nextLabel', $nextLabel);
         $tpl->assign('nextURL', $nextURL);
     }
     // limit
     $limit = 7;
     $breakpoint = 4;
     $items = array();
     /**
      * Less than or 7 pages. We know all the keys, and we put them in the array
      * that we will use to generate the actual pagination.
      */
     if ($numPages <= $limit) {
         for ($i = 1; $i <= $numPages; $i++) {
             $items[$i] = $i;
         }
     } else {
         // first page
         if ($currentPage == 1) {
             // [1] 2 3 4 5 6 7 8 9 10 11 12 13
             for ($i = 1; $i <= $limit; $i++) {
                 $items[$i] = $i;
             }
             $items[$limit + 1] = '...';
         } elseif ($currentPage == $numPages) {
             // 1 2 3 4 5 6 7 8 9 10 11 12 [13]
             $items[$numPages - $limit - 1] = '...';
             for ($i = $numPages - $limit; $i <= $numPages; $i++) {
                 $items[$i] = $i;
             }
         } else {
             // 1 2 3 [4] 5 6 7 8 9 10 11 12 13
             // define min & max
             $min = $currentPage - $breakpoint + 1;
             $max = $currentPage + $breakpoint - 1;
             // minimum doesnt exist
             while ($min <= 0) {
                 $min++;
                 $max++;
             }
             // maximum doesnt exist
             while ($max > $numPages) {
                 $min--;
                 $max--;
             }
             // create the list
             if ($min != 1) {
                 $items[$min - 1] = '...';
             }
             for ($i = $min; $i <= $max; $i++) {
                 $items[$i] = $i;
             }
             if ($max != $numPages) {
                 $items[$max + 1] = '...';
             }
         }
     }
     // init var
     $pages = array();
     // loop pages
     foreach ($items as $item) {
         // counter
         if (!isset($i)) {
             $i = 0;
         }
         // base details
         $pages[$i]['page'] = false;
         $pages[$i]['currentPage'] = false;
         $pages[$i]['otherPage'] = false;
         $pages[$i]['noPage'] = false;
         $pages[$i]['url'] = '';
         $pages[$i]['pageNumber'] = $item;
         // hellips
         if ($item == '...') {
             $pages[$i]['noPage'] = true;
         } else {
             // show page
             $pages[$i]['page'] = true;
             // current page ?
             if ($item == $currentPage) {
                 $pages[$i]['currentPage'] = true;
             } else {
                 // show the page
                 $pages[$i]['otherPage'] = true;
                 // url to this page
                 $pages[$i]['url'] = str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $item - $numPerPage, $order, $sort), $URL);
             }
         }
         // update counter
         $i++;
     }
     // first key needs to be zero
     $pages = SpoonFilter::arraySortKeys($pages);
     // assign pages
     $tpl->assign('pages', $pages);
     // cough it up
     ob_start();
     $tpl->display(dirname(__FILE__) . '/paging.tpl');
     return ob_get_clean();
 }
Example #6
0
 /**
  * Parse the datagrid.
  *
  * @return	void
  */
 private function parse()
 {
     // has results
     if ($this->source->getNumResults() > 0) {
         // fetch records
         $aRecords = $this->source->getData($this->getOffset(), $this->getPagingLimit(), $this->getOrder(), $this->getSort());
         // has results
         if (count($aRecords) != 0) {
             // compile directory
             $compileDirectory = $this->compileDirectory !== null ? $this->compileDirectory : dirname(realpath(__FILE__));
             $this->tpl->setCompileDirectory($compileDirectory);
             // only force compiling when debug is enabled
             if ($this->debug) {
                 $this->tpl->setForceCompile(true);
             }
             // table attributes
             $this->parseAttributes();
             // table summary
             $this->parseSummary();
             // caption/description
             $this->parseCaption();
             // header row
             $this->parseHeader();
             // actual rows
             $this->parseBody($aRecords);
             // pagination
             $this->parseFooter();
             // parse to buffer
             ob_start();
             $this->tpl->display($this->getTemplatePath());
             $this->content = ob_get_clean();
         }
     }
     // update parsed status
     $this->parsed = true;
 }
Example #7
0
 /**
  * Returns the parsed content of a given template with optional variables.
  *
  * @return	string
  * @param	string $template			The path to (including the filename for) the template.
  * @param	array[optional] $variables	The variables to parse into $template.
  */
 private function getTemplateContent($template, array $variables = null)
 {
     // check if compile directory is set
     if (empty($this->compileDirectory)) {
         throw new SpoonEmailException('Compile directory is not set. Use setTemplateCompileDirectory.');
     }
     // declare template
     $tpl = new SpoonTemplate();
     $tpl->setCompileDirectory($this->compileDirectory);
     $tpl->setForceCompile(true);
     // parse variables in the template if any are found
     if (!empty($variables)) {
         $tpl->assign($variables);
     }
     // return template content
     return $tpl->getContent($template);
 }
Example #8
0
 /**
  * Builds & returns the pagination
  *
  * @param string $URL
  * @param int $offset
  * @param string $order The name of the column to sort on.
  * @param string $sort The sorting method, possible values are: asc, desc.
  * @param int $numResults
  * @param int $numPerPage The items per page.
  * @param bool[optional] $debug
  * @param string[optional] $compileDirectory
  * @return string
  */
 public static function getContent($URL, $offset, $order, $sort, $numResults, $numPerPage, $debug = true, $compileDirectory = null)
 {
     // if there is just one page we don't need paging
     if ($numResults < $numPerPage) {
         return '';
     }
     // load template
     $tpl = new SpoonTemplate();
     // compile directory
     if ($compileDirectory !== null) {
         $tpl->setCompileDirectory($compileDirectory);
     } else {
         $tpl->setCompileDirectory(dirname(__FILE__));
     }
     // force compiling
     $tpl->setForceCompile((bool) $debug);
     // init vars
     $pagination = null;
     $showFirstPages = false;
     $showLastPages = false;
     // current page
     $currentPage = ceil($offset / $numPerPage) + 1;
     // number of pages
     $numPages = ceil($numResults / $numPerPage);
     // populate count fields
     $pagination['num_pages'] = $numPages;
     $pagination['current_page'] = $currentPage;
     // as long as we are below page 7 we should show all pages starting from 1
     if ($currentPage < 8) {
         // init vars
         $pagesStart = 1;
         $pagesEnd = $numPages >= 7 ? 7 : $numPages;
         // show last pages
         if ($numPages > 8) {
             $showLastPages = true;
         }
     } elseif ($currentPage > $numPages - 7) {
         // init vars
         $pagesStart = $numPages == 9 ? $numPages - 6 : $numPages - 7;
         $pagesEnd = $numPages;
         // show first pages
         $showFirstPages = true;
     } else {
         // init vars
         $pagesStart = $currentPage - 2;
         $pagesEnd = $currentPage + 2;
         $showFirstPages = true;
         $showLastPages = true;
     }
     // show previous
     if ($currentPage > 1) {
         // set
         $pagination['show_previous'] = true;
         $pagination['previous_url'] = str_replace(array('[offset]', '[order]', '[sort]'), array($offset - $numPerPage, $order, $sort), $URL);
     }
     // show first pages?
     if ($showFirstPages) {
         // init var
         $pagesFirstStart = 1;
         $pagesFirstEnd = 2;
         // loop pages
         for ($i = $pagesFirstStart; $i <= $pagesFirstEnd; $i++) {
             // add
             $pagination['first'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $URL), 'label' => $i);
         }
     }
     // build array
     for ($i = $pagesStart; $i <= $pagesEnd; $i++) {
         // init var
         $current = $i == $currentPage;
         // add
         $pagination['pages'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $URL), 'label' => $i, 'current' => $current);
     }
     // show last pages?
     if ($showLastPages) {
         // init var
         $pagesLastStart = $numPages - 1;
         $pagesLastEnd = $numPages;
         // loop pages
         for ($i = $pagesLastStart; $i <= $pagesLastEnd; $i++) {
             // add
             $pagination['last'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $URL), 'label' => $i);
         }
     }
     // show next
     if ($currentPage < $numPages) {
         // set
         $pagination['show_next'] = true;
         $pagination['next_url'] = str_replace(array('[offset]', '[order]', '[sort]'), array($offset + $numPerPage, $order, $sort), $URL);
     }
     // multiple pages
     $pagination['multiple_pages'] = $numPages == 1 ? false : true;
     // assign pagination
     $tpl->assign('pagination', $pagination);
     // assign labels
     $tpl->assign('previousLabel', BL::lbl('PreviousPage'));
     $tpl->assign('nextLabel', BL::lbl('NextPage'));
     $tpl->assign('goToLabel', BL::lbl('GoToPage'));
     return $tpl->getContent(BACKEND_CORE_PATH . '/layout/templates/datagrid_paging.tpl');
 }
Example #9
0
 /**
  * Builds & returns the pagination
  *
  * @param string $url
  * @param int    $offset
  * @param string $order      The name of the column to sort on.
  * @param string $sort       The sorting method, possible values are: asc, desc.
  * @param int    $numResults
  * @param int    $numPerPage The items per page.
  * @param bool   $debug
  * @param string $compileDirectory
  *
  * @return string
  */
 public static function getContent($url, $offset, $order, $sort, $numResults, $numPerPage, $debug = true, $compileDirectory = null)
 {
     // if there is just one page we don't need paging
     if ($numResults < $numPerPage) {
         return '';
     }
     // load template
     $tpl = new \SpoonTemplate();
     // compile directory
     if ($compileDirectory !== null) {
         $tpl->setCompileDirectory($compileDirectory);
     } else {
         $tpl->setCompileDirectory(__DIR__);
     }
     // force compiling
     $tpl->setForceCompile((bool) $debug);
     // init vars
     $pagination = null;
     $showFirstPages = false;
     $showLastPages = false;
     // current page
     $currentPage = ceil($offset / $numPerPage) + 1;
     // number of pages
     $numPages = ceil($numResults / $numPerPage);
     // populate count fields
     $pagination['num_pages'] = $numPages;
     $pagination['current_page'] = $currentPage;
     // as long as we have more then 5 pages and are 5 pages from the end we should show all pages till the end
     if ($currentPage > 5 && $currentPage >= $numPages - 4) {
         // init vars
         $pagesStart = $numPages > 7 ? $numPages - 5 : $numPages - 6;
         $pagesEnd = $numPages;
         // fix for page 6
         if ($numPages == 6) {
             $pagesStart = 1;
         }
         // show first pages
         if ($numPages > 7) {
             $showFirstPages = true;
         }
     } elseif ($currentPage <= 5) {
         // as long as we are below page 5 and below 5 from the end we should show all pages starting from 1
         $pagesStart = 1;
         $pagesEnd = 6;
         if ($numPages == 7) {
             // when we have 7 pages, show 7 as end
             $pagesEnd = 7;
         } elseif ($numPages <= 6) {
             // when we have less then 6 pages, show the maximum page
             $pagesEnd = $numPages;
         }
         // show last pages
         if ($numPages > 7) {
             $showLastPages = true;
         }
     } else {
         // page 6
         $pagesStart = $currentPage - 2;
         $pagesEnd = $currentPage + 2;
         $showFirstPages = true;
         $showLastPages = true;
     }
     // show previous
     if ($currentPage > 1) {
         // set
         $pagination['show_previous'] = true;
         $pagination['previous_url'] = str_replace(array('[offset]', '[order]', '[sort]'), array($offset - $numPerPage, $order, $sort), $url);
     }
     // show first pages?
     if ($showFirstPages) {
         // init var
         $pagesFirstStart = 1;
         $pagesFirstEnd = 2;
         // loop pages
         for ($i = $pagesFirstStart; $i <= $pagesFirstEnd; ++$i) {
             // add
             $pagination['first'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $url), 'label' => $i);
         }
     }
     // build array
     for ($i = $pagesStart; $i <= $pagesEnd; ++$i) {
         // init var
         $current = $i == $currentPage;
         // add
         $pagination['pages'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $url), 'label' => $i, 'current' => $current);
     }
     // show last pages?
     if ($showLastPages) {
         // init var
         $pagesLastStart = $numPages - 1;
         $pagesLastEnd = $numPages;
         // loop pages
         for ($i = $pagesLastStart; $i <= $pagesLastEnd; ++$i) {
             // add
             $pagination['last'][] = array('url' => str_replace(array('[offset]', '[order]', '[sort]'), array($numPerPage * $i - $numPerPage, $order, $sort), $url), 'label' => $i);
         }
     }
     // show next
     if ($currentPage < $numPages) {
         // set
         $pagination['show_next'] = true;
         $pagination['next_url'] = str_replace(array('[offset]', '[order]', '[sort]'), array($offset + $numPerPage, $order, $sort), $url);
     }
     // multiple pages
     $pagination['multiple_pages'] = $numPages == 1 ? false : true;
     // assign pagination
     $tpl->assign('pagination', $pagination);
     // assign labels
     $tpl->assign('previousLabel', BackendLanguage::lbl('PreviousPage'));
     $tpl->assign('nextLabel', BackendLanguage::lbl('NextPage'));
     $tpl->assign('goToLabel', BackendLanguage::lbl('GoToPage'));
     return $tpl->getContent(BACKEND_CORE_PATH . '/Layout/Templates/DatagridPaging.tpl');
 }