示例#1
0
 public function compile()
 {
     $db =& $this->Database;
     $ext = $db->prepare("select * from `tl_repository_installs` where `extension`='SWGlossar'")->execute();
     if ($ext->lickey == false || $ext->lickey == 'free2use') {
         $this->Template->lickey = false;
     } else {
         $this->Template->lickey = true;
     }
     $Log = \GlossarLogModel::findBy(array("tl_glossar_log.tstamp >= ?"), array(time() - 86400 * 7 * 31), array('order' => 'tstamp DESC', 'limit' => 500));
     $arrTerms = $arrLog = array();
     if (!empty($Log)) {
         while ($Log->next()) {
             $_term = $Log->getRelated('term');
             $arrLog[$Log->action][$Log->term][] = $Log->user;
             $_log = $Log->row();
             $_log['term'] = $_term->row();
             $arrTerms[$_term->id][] = $_log;
         }
     }
     $this->Template->terms = $arrTerms;
     $arrTerms = null;
     $stdArray = array(0 => array('avg' => 0, 'sum' => 0, 'unique' => 0, 'user' => array(), 'user_percent' => array()));
     $arrStats = array('load' => $stdArray, 'follow' => $stdArray, 'close' => $stdArray, 'cloud' => $stdArray, 'span' => $stdArray);
     $stdArray = null;
     foreach ($arrLog as $type => $terms) {
         foreach ($terms as $id => $users) {
             $arrStats[$type][$id]['unique'] = count(array_unique($users));
             foreach ($users as $key => $sid) {
                 if (empty($arrStats[$type][$id]['user'][$sid])) {
                     $arrStats[$type][$id]['user'][$sid] = 0;
                 }
                 $arrStats[$type][$id]['user'][$sid]++;
                 if (empty($arrStats[$type][0]['user'][$sid])) {
                     $arrStats[$type][0]['user'][$sid] = 0;
                 }
                 $arrStats[$type][0]['user'][$sid]++;
             }
             $arrStats[$type][$id]['sum'] = array_sum($arrStats[$type][$id]['user']);
             $arrStats[$type][0]['sum'] += $arrStats[$type][$id]['sum'];
             foreach ($arrStats[$type][$id]['user'] as $sid => $count) {
                 $arrStats[$type][$id]['user_percent'][$sid] = number_format($count * 100 / $arrStats[$type][$id]['sum'], 2);
             }
             $arrStats[$type][$id]['avg'] = $arrStats[$type][$id]['sum'] / count($arrStats[$type][$id]['user']);
             ksort($arrStats[$type][$id]);
         }
         $arrStats[$type][0]['avg'] = $arrStats[$type][0]['sum'] / count($arrStats[$type][0]['user']);
         foreach ($arrStats[$type][0]['user'] as $sid => $count) {
             $arrStats[$type][0]['user_percent'][$sid] = number_format($count * 100 / $arrStats[$type][0]['sum'], 2);
         }
         $arrStats[$type][0]['unique'] = count($arrStats[$type][0]['user']);
         ksort($arrStats[$type][0]);
         ksort($arrStats[$type]);
     }
     $this->Template->stats = $arrStats;
     $this->Template->log = $arrLog;
 }
示例#2
0
 public function getGlossarTerm()
 {
     if (\Input::post('id')) {
         $Term = \SwGlossarModel::findByPk(\Input::post('id'));
     }
     if ($Term === null && \Input::post('cloud') == '') {
         return false;
     }
     if (!$this->checkLizenz()) {
         $Log = new \GlossarLogModel();
         $Log->tstamp = time();
         $Log->user = session_id();
         $GAction = 'load';
         if (\Input::post('loaded') == 1) {
             $GAction = 'close';
         }
         if (\Input::post('clicked') == 1) {
             $GAction = 'follow';
             if (\Input::post('no_ref') == 1) {
                 $GAction = 'span';
             }
         }
         if ($id = \Input::post('cloud')) {
             $GAction = 'cloud';
             $Term = new \stdClass();
             $Term->id = $id;
         }
         $Log->action = $GAction;
         $Log->term = $Term->id;
         $Log->page = $_SESSION['FE_DATA']['referer']['current'];
         $Log->language = $_SESSION['TL_LANGUAGE'];
         $Log->save();
     }
     if (\Input::post('cloud') != '') {
         return false;
     }
     $Content = \GlossarContentModel::findPublishedByPidAndTable($Term->id, 'tl_sw_glossar');
     $termObj = new \FrontendTemplate('glossar_layer');
     $termObj->setData($Term->row());
     $termObj->class = 'ce_glossar_layer';
     if (!empty($Content)) {
         if ($GLOBALS['TL_CONFIG']['jumpToGlossar']) {
             $link = \GlossarPageModel::findByPk($GLOBALS['TL_CONFIG']['jumpToGlossar']);
             $termObj->link = $this->generateFrontendUrl($link->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . $termObj->alias);
         }
         if ($termObj->jumpTo) {
             $link = \GlossarPageModel::findByPk($termObj->jumpTo);
             $termObj->link = $this->generateFrontendUrl($link->row(), ($GLOBALS['TL_CONFIG']['useAutoItem'] && !$GLOBALS['TL_CONFIG']['disableAlias'] ? '/' : '/items/') . $termObj->alias);
         }
     }
     echo json_encode(array('content' => $termObj->parse()));
     die;
 }