"Fossies" - the Fresh Open Source Software Archive

Member "Open-Web-Analytics-1.7.0/owa_template.php" (16 Sep 2020, 25652 Bytes) of package /linux/www/Open-Web-Analytics-1.7.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "owa_template.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.6.9_vs_1.7.0.

    1 <?php
    2 
    3 //
    4 // Open Web Analytics - An Open Source Web Analytics Framework
    5 //
    6 // Copyright 2006 Peter Adams. All rights reserved.
    7 //
    8 // Licensed under GPL v2.0 http://www.gnu.org/copyleft/gpl.html
    9 //
   10 // Unless required by applicable law or agreed to in writing, software
   11 // distributed under the License is distributed on an "AS IS" BASIS,
   12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   13 // See the License for the specific language governing permissions and
   14 // limitations under the License.
   15 //
   16 // $Id$
   17 //
   18 
   19 if (!class_exists('Template')) {
   20     require_once(OWA_INCLUDE_DIR.'template_class.php');
   21 }
   22 
   23 if (!class_exists('owa_lib')) {
   24     require_once(OWA_BASE_DIR.'/owa_lib.php');
   25 }
   26 
   27 if (!class_exists('owa_sanitize')) {
   28     require_once(OWA_BASE_CLASS_DIR.'sanitize.php');
   29 }
   30 
   31 /**
   32  * OWA Wrapper for template class
   33  * 
   34  * @author      Peter Adams <peter@openwebanalytics.com>
   35  * @copyright   Copyright &copy; 2006 Peter Adams <peter@openwebanalytics.com>
   36  * @license     http://www.gnu.org/copyleft/gpl.html GPL v2.0
   37  * @category    owa
   38  * @package     owa
   39  * @version        $Revision$
   40  * @since        owa 1.0.0
   41  */
   42 
   43 class owa_template extends Template {
   44 
   45     /**
   46      * Configuration
   47      *
   48      * @var array
   49      */
   50     var $config;
   51 
   52     var $theme_template_dir;
   53 
   54     var $module_local_template_dir;
   55 
   56     var $module_template_dir;
   57 
   58     var $e;
   59 
   60     var $period;
   61 
   62     /**
   63      * Params passed by calling caller
   64      *
   65      * @var array
   66      */
   67     var $caller_params;
   68 
   69     function __construct( $module = null, $caller_params = array() ) {
   70 
   71         $this->caller_params = $caller_params;
   72 
   73         $c = owa_coreAPI::configSingleton();
   74         $this->config = $c->fetch('base');
   75 
   76         $this->e = owa_coreAPI::errorSingleton();
   77 
   78         // set template dirs
   79         if(!empty($caller_params['module'])):
   80             $this->_setTemplateDir($module);
   81         else:
   82             $this->_setTemplateDir('base');
   83         endif;
   84 
   85         $this->time_now = owa_lib::time_now();
   86     }
   87 
   88     function _setTemplateDir($module) {
   89 
   90         // set module template dir
   91         $this->module_template_dir = OWA_DIR.'modules'.'/' . $module . '/'.'templates'.'/';
   92 
   93         // set module local template override dir
   94         $this->module_local_template_dir = $this->module_template_dir.'local'.'/';
   95 
   96         // set theme template dir
   97         $this->theme_template_dir = OWA_THEMES_DIR.$this->config['theme'].'/';
   98 
   99         return;
  100     }
  101 
  102     function getTemplatePath($module, $file) {
  103 
  104         $this->_setTemplateDir($module);
  105 
  106         if ($file == null) {
  107             owa_coreAPI::error('No template file was specified.');
  108             return false;
  109         } else {
  110             // check module's local modification template Directory
  111             if (file_exists($this->module_local_template_dir.$file)) {
  112                 $fullfile = $this->module_local_template_dir.$file;
  113 
  114             // check theme's template Directory
  115             } elseif(file_exists($this->theme_template_dir.$file)) {
  116                 $fullfile = $this->theme_template_dir.$file;
  117 
  118             // check module's template directory
  119             } elseif(file_exists($this->module_template_dir.$file)) {
  120                 $fullfile = $this->module_template_dir.$file;
  121 
  122             // throw error
  123             } else {
  124                 $this->e->err(sprintf('%s was not found in any template directory.', $file));
  125                 return false;
  126             }
  127             return $fullfile;
  128         }
  129 
  130 
  131 
  132     }
  133 
  134     /**
  135      * Set the template file
  136      * @depricated
  137      * @param string $file
  138      */
  139     function set_template($file = null) {
  140 
  141         if (!$file):
  142             owa_coreAPI::error('No template file was specified.');
  143             return false;
  144         else:
  145             // check module's local modification template Directory
  146             if (file_exists($this->module_local_template_dir.$file)):
  147                 $this->file = $this->module_local_template_dir.$file;
  148 
  149             // check theme's template Directory
  150             elseif(file_exists($this->theme_template_dir.$file)):
  151                 $this->file = $this->theme_template_dir.$file;
  152 
  153             // check module's template directory
  154             elseif(file_exists($this->module_template_dir.$file)):
  155                 $this->file = $this->module_template_dir.$file;
  156 
  157             // throw error
  158             else:
  159                 $this->e->err(sprintf('%s was not found in any template directory.', $file));
  160                 return false;
  161             endif;
  162         
  163             return true;
  164         endif;
  165     }
  166     
  167     function setTemplateFile($module, $file) {
  168 
  169         //choose file
  170         $filepath = $this->getTemplatePath($module, $file);
  171         //set template
  172         if ($filepath) {
  173             $this->file = $filepath;
  174         }
  175     }
  176 
  177     /**
  178      * Truncate string
  179      *
  180      * @param string $str
  181      * @param integer $length
  182      * @param string $trailing
  183      * @return string
  184      */
  185     function truncate ($str, $length=10, $trailing='...')  {
  186 
  187       return owa_lib::truncate ($str, $length, $trailing); 
  188     }
  189 
  190     function get_month_label($month) {
  191 
  192         return owa_lib::get_month_label($month);
  193     }
  194 
  195     /**
  196      * Chooses the right icon based on browser type
  197      *
  198      * @param unknown_type $browser_type
  199      * @return unknown
  200      */
  201     function choose_browser_icon($browser_type) {
  202         
  203         $bicons = [
  204             
  205             'chrome'                => 'fab fa-chrome',
  206             'safari'                => 'fab fa-safari',
  207             'firefox'               => 'fab fa-firefox-browser',
  208             'internet explorer'     => 'fab fa-internet-explorer',
  209             'ie'                    => 'fab fa-internet-explorer',
  210             'opera'                 => 'fab fa-opera',
  211             'edge'                  => 'fab fa-edge'
  212         ];
  213         
  214         foreach ( $bicons as $k => $v ) {
  215             
  216             if ( strpos(strtolower($browser_type), $k) !== false ) {
  217                 
  218                 return $bicons[ $k ];
  219             }
  220         }
  221         
  222         return 'fas fa-window-maximize';
  223         
  224     }
  225 
  226     function getBrowserIcon($browser_family, $size = '128x128', $module = 'base') {
  227 
  228         if ($browser_family) {
  229             $browser_family = strtolower($browser_family);
  230         }
  231 
  232 
  233         if (file_exists(OWA_MODULES_DIR.$module.'/i/browsers/'.$size.'/'.$browser_family.'.png')) {
  234             return $this->makeImageLink('base/i/browsers/'.$size.'/'.$browser_family.'.png');
  235         } else {
  236             return $this->makeImageLink('base/i/browsers/'.$size.'/default.png');
  237         }
  238     }
  239 
  240 
  241     function makeLinkQueryString($query_params) {
  242 
  243         $new_query_params = array();
  244 
  245         //Load params passed by caller
  246         if (!empty($this->caller_params)):
  247             foreach ($this->caller_params as $name => $value) {
  248                 if (!empty($value)):
  249                     $new_query_params[$name] = $value;
  250                 endif;
  251             }
  252         endif;
  253 
  254         // Load overrides
  255         if (!empty($query_params)):
  256             foreach ($query_params as $name => $value) {
  257                 if (!empty($value)):
  258                     $new_query_params[$name] = $value;
  259                 endif;
  260             }
  261         endif;
  262 
  263         // Construct GET request
  264         if (!empty($new_query_params)):
  265             foreach ($new_query_params as $name => $value) {
  266                 if (!empty($value)):
  267                     $get .= $name . "=" . $value . "&";
  268                 endif;
  269             }
  270         endif;
  271 
  272         return $get;
  273 
  274     }
  275 
  276     /**
  277      * Makes navigation links by checking whether or not the view
  278      * that is rendering the template is not the view being refered to in the link.
  279      *
  280      * @param array navigation array
  281      */
  282     function makeNavigation($nav, $id = '', $class = '', $li_template = '<LI class="%s"><a href="%s">%s</a></LI>', $li_class = '') {
  283 
  284         $ul = sprintf('<UL id="%s" class="%s">', $id, $class);
  285 
  286         if (!empty($nav)):
  287 
  288             $navigation = $ul;
  289 
  290             foreach($nav as $k => $v) {
  291 
  292                 $navigation .= sprintf($li_template, $li_class,    $this->makeLink(array('do' => $v['ref']), true), $v['anchortext']);
  293 
  294             }
  295 
  296             $navigation .= '</UL>';
  297 
  298             return $navigation;
  299         else:
  300             return false;
  301         endif;
  302 
  303     }
  304 
  305     function makeTwoLevelNav($links) {
  306         print_r($links);
  307         $navigation = '<UL id="report_top_level_nav_ul">';
  308 
  309         foreach($links as $k => $v) {
  310 
  311             if (!empty($v['subgroup'])):
  312                 $sub_nav = $this->makeNavigation($v['subgroup']);
  313 
  314                 $navigation .= sprintf('<LI class="drawer"><H2 class="nav_header"><a href="%s">%s</a></H2>%s</LI>',
  315                                                 $this->makeLink(array('do' => $v['ref']), true),
  316                                                 $v['anchortext'], $sub_nav);
  317             else:
  318 
  319                 $navigation .= sprintf('<LI class="drawer"><H2 class="nav_header"><a href="%s">%s</a></H2></LI>',
  320                                                 $this->makeLink(array('do' => $v['ref']), true),
  321                                                 $v['anchortext']);
  322 
  323             endif;
  324 
  325         }
  326 
  327         $navigation .= '</UL>';
  328 
  329         return $navigation;
  330 
  331     }
  332 
  333     function daysAgo($time) {
  334 
  335         $now = mktime(23, 59, 59, $this->time_now['month'], $this->time_now['day'], $this->time_now['year']);
  336 
  337         $days = round(($now - $time) / (3600*24));
  338 
  339         switch ($days) {
  340 
  341             case 1:
  342                 return $days . " day ago";
  343 
  344             default:
  345                 return $days . " days ago";
  346         }
  347 
  348     }
  349 
  350     /**
  351      * @depricated
  352      * @todo remove
  353      */
  354     function getAuthStatus() {
  355 
  356         if (!class_exists('owa_auth')) {
  357             require_once(OWA_BASE_DIR.'/owa_auth.php');
  358         }
  359 
  360         $auth = &owa_auth::get_instance();
  361         return $auth->auth_status;
  362     }
  363 
  364     function makeWikiLink($page) {
  365 
  366         return sprintf($this->config['owa_wiki_link_template'], $page);
  367     }
  368 
  369     /**
  370      * Returns Namespace value to template
  371      *
  372      * @return string
  373      */
  374     function getNs() {
  375 
  376         return $this->config['ns'];
  377     }
  378 
  379     function makeParamString($params = array(), $add_state = false, $format = 'query', $namespace = true) {
  380 
  381         $all_params = array();
  382 
  383         // merge in state params
  384         if ($add_state) {
  385             $all_params = array_merge($all_params, $this->getAllStateParams());
  386         }
  387         //merge in params
  388         $all_params = array_merge($all_params, $params);
  389 
  390         switch($format) {
  391 
  392             case 'query':
  393 
  394                 $get = '';
  395 
  396                 $count = count($all_params);
  397 
  398                 $i = 0;
  399 
  400                 foreach ($all_params as $n => $v) {
  401 
  402                     $get .= owa_coreAPI::getSetting('base','ns').$n.'='.$v;
  403 
  404                     $i++;
  405 
  406                     if ($i < $count):
  407                         $get .= "&";
  408                     endif;
  409                 }
  410 
  411                 $string= $get;
  412 
  413                 break;
  414 
  415             case 'cookie':
  416 
  417                 $string = owa_lib::implode_assoc('=>', '|||', $all_params);
  418                 break;
  419 
  420             case 'json':
  421 
  422                 $string = json_encode( $all_params );
  423 
  424                 break;
  425         }
  426 
  427 
  428         return $string;
  429 
  430     }
  431 
  432     function getAllStateParams() {
  433 
  434         $all_params = array();
  435 
  436         if (!empty($this->caller_params['link_state'])) {
  437             $all_params = array_merge($all_params, $this->caller_params['link_state']);
  438         }
  439 
  440         // add in period properties if available
  441         $period = $this->get('timePeriod');
  442 
  443         if (!empty($period)) {
  444             $all_params = array_merge($all_params, $period->getPeriodProperties());
  445             //print_r($all_params);
  446         }
  447 
  448         return $all_params;
  449     }
  450     
  451     function getLinkStateParam( $key ) {
  452      
  453         $params = $this->getAllStateParams();
  454         
  455         if (array_key_exists($key, $params)) {
  456             
  457            return $params[ $key ];          
  458         }
  459 
  460     }
  461 
  462 
  463     /**
  464      * Makes Links, adds state to links optionaly.
  465      *
  466      * @param array $params
  467      * @param boolean $add_state
  468      * @return string
  469      */
  470     function makeLink($params = array(), $add_state = false, $url = '', $xml = false, $add_nonce = false) {
  471 
  472         $all_params = array();
  473 
  474         //Loads link state passed by caller
  475         if ($add_state == true) {
  476             if (!empty($this->caller_params['link_state'])) {
  477                 $all_params = array_merge($all_params, $this->caller_params['link_state']);
  478             }
  479 
  480             // add in period properties if available
  481             $period = $this->get('timePeriod');
  482 
  483             if (!empty($period)) {
  484                 $all_params = array_merge($all_params, $period->getPeriodProperties());
  485 
  486             }
  487         }
  488 
  489         // Load overrides
  490         if (!empty($params)) {
  491             $params = array_filter($params);
  492             $all_params = array_merge($all_params, $params);
  493         }
  494 
  495         // add nonce if called for
  496         if ($add_nonce) {
  497             if ( array_key_exists('do', $all_params) ) {
  498                 $action = $all_params['do'];
  499             } elseif ( array_key_exists('action', $all_params) ) {
  500                 $action = $all_params['action'];
  501             }
  502 
  503             $all_params['nonce'] = owa_coreAPI::createNonce($action);
  504         }
  505 
  506         $get = '';
  507 
  508         if (!empty($all_params)):
  509 
  510             $count = count($all_params);
  511 
  512             $i = 0;
  513 
  514             foreach ($all_params as $n => $v) {
  515 
  516                 $get .= $this->config['ns'].owa_sanitize::escapeForDisplay($n).'='.owa_sanitize::escapeForDisplay($v);
  517 
  518                 $i++;
  519 
  520                 if ($i < $count):
  521                     $get .= "&";
  522                 endif;
  523             }
  524         endif;
  525 
  526         if (empty($url)):
  527             $url = $this->config['main_url'];
  528         endif;
  529 
  530         $link = sprintf($this->config['link_template'], $url, $get);
  531 
  532         if ($xml == true):
  533             $link = $this->escapeForXml($link);
  534         endif;
  535 
  536         return $link;
  537 
  538     }
  539 
  540     function escapeForXml($string) {
  541 
  542         $string = str_replace(array('&', '"', "'", '<', '>' ), array('&amp;' , '&quot;', '&apos;' , '&lt;' , '&gt;'), $string);
  543         // removes non-ascii chars
  544         $string = owa_lib::escapeNonAsciiChars($string);
  545         return $string;
  546     }
  547 
  548     function makeAbsoluteLink($params = array(), $add_state = false, $url = '', $xml = false) {
  549 
  550         if (empty($url)):
  551             $url = $this->config['main_absolute_url'];
  552         endif;
  553 
  554         return $this->makeLink($params, $add_state, $url, $xml);
  555 
  556     }
  557     
  558     function getApiKey() {
  559         
  560         
  561         return;
  562     }
  563 
  564     function makeApiLink($params = array(), $add_state = false) {
  565 
  566         $url = $this->config['rest_api_url'];
  567       
  568         return $this->makeLink($params, $add_state, $url);
  569     }
  570 
  571 
  572     function makeImageLink($path, $absolute = false) {
  573 
  574         if ($absolute === true) {
  575             $url = owa_coreAPI::getSetting('base', 'modules_url');
  576         } else {
  577             $url = owa_coreAPI::getSetting('base', 'modules_url');
  578         }
  579 
  580         return $url.$path;
  581 
  582     }
  583 
  584     function includeTemplate($file) {
  585 
  586         $this->set_template($file);
  587         include($this->file);
  588         return;
  589 
  590     }
  591 
  592     function setTemplate($file) {
  593 
  594         $this->set_template($file);
  595         return $this->file;
  596 
  597     }
  598 
  599     function getWidget($do, $params = array(), $wrapper = true, $add_state = true) {
  600 
  601         $final_params = array();
  602 
  603         if (empty($params)):
  604             $params = array();
  605         endif;
  606 
  607         $params['do'] = $do;
  608 
  609         if ($wrapper === true):
  610             $params['initial_view'] = true;
  611             $params['wrapper'] = true;
  612         elseif ($wrapper === 'inpage'):
  613             $params['initial_view'] = true;
  614             $params['wrapper'] = 'inpage';
  615         else:
  616             $params['wrapper'] = false;
  617         endif;
  618 
  619         // add state params into request params
  620         if ($add_state === true):
  621             $final_params = array_merge($final_params, $this->caller_params['link_state']);
  622         endif;
  623 
  624         // apply overides made via the template
  625         $final_params = array_merge($final_params, array_filter($params));
  626 
  627         return owa_coreAPI::performAction($do, $final_params);
  628     }
  629 
  630     function makeJson($array) {
  631 
  632         $reserved_words = owa_coreAPI::getSetting('base', 'reserved_words');
  633 
  634         $json = '{';
  635 
  636         foreach ($array as $k => $v) {
  637 
  638             if (is_object($v)) {
  639                 if (method_exists($v, 'toString')) {
  640                     $v = $v->toString();
  641                 } else {
  642                     $v = '';
  643                 }
  644 
  645             }
  646 
  647             if (in_array($k, array_keys($reserved_words))) {
  648                 $k = $reserved_words[$k];
  649             }
  650 
  651             $json .= sprintf('%s: "%s", ', $k, $v);
  652 
  653         }
  654 
  655 
  656         $json = substr($json, 0, -2);
  657 
  658         $json .= '}';
  659 
  660         return $json;
  661 
  662     }
  663 
  664     function headerActions() {
  665 
  666         return;
  667     }
  668 
  669     function footerActions() {
  670 
  671         return;
  672     }
  673 
  674     function makePagination($pagination, $map = array(), $add_state = true, $template = '') {
  675 
  676         $pages = '';
  677         //print_r($pagination);
  678         if ($pagination['max_page_num'] > 1) {
  679 
  680             $pages = '<div class="owa_pagination"><UL>';
  681 
  682             for ($i = 1; $i <= $pagination['max_page_num'];$i++) {
  683 
  684                 if ($pagination['page_num'] != $i) {
  685                     $new_map = array();
  686                     $new_map = $map;
  687                     $new_map['page'] = $i;
  688                     $link = sprintf('<LI class="owa_reportPaginationControl"><a href="%s">%s</a></LI>',
  689                                                         $this->makeLink($new_map, $add_state),
  690                                                         $i);
  691 
  692                 } else {
  693 
  694                     $link = sprintf('<LI class="owa_reportPaginationControl">%s</LI>', $i);
  695                 }
  696 
  697                 $pages .= $link;
  698             }
  699 
  700             $pages .= '</UL></div>';
  701             $pages .= '<div style="clear:both;"></div>';
  702         }
  703 
  704         return $pages;
  705     }
  706 
  707     function makePaginationFromResultSet($pagination, $map = array(), $add_state = true, $template = '') {
  708 
  709         $pages = '';
  710         //print_r($pagination);
  711         //print $pagination->total_pages;
  712 
  713         if ($pagination->total_pages > 1) {
  714 
  715             $pages = '<div class="owa_pagination"><UL>';
  716 
  717             for ($i = 1; $i <= $pagination->total_pages;$i++) {
  718 
  719                 if ($pagination->page != $i) {
  720 
  721                     $new_map = array();
  722 
  723                     if (is_array($map)) {
  724                         $new_map = array_merge($map, $new_map);
  725                     }
  726 
  727                     $new_map['page'] = $i;
  728 
  729                     $link = sprintf('<LI class="owa_reportPaginationControl"><a href="%s">%s</a></LI>',
  730                                                         $this->makeLink($new_map, $add_state),
  731                                                         $i);
  732 
  733                 } else {
  734 
  735                     $link = sprintf('<LI class="owa_reportPaginationControl">%s</LI>', $i);
  736                 }
  737 
  738                 $pages .= $link;
  739             }
  740 
  741             $pages .= '</UL></div>';
  742 
  743 
  744 
  745         }
  746 
  747         return $pages;
  748     }
  749 
  750     function get($name) {
  751 
  752         if (array_key_exists($name, $this->vars)) {
  753             return $this->vars[$name];
  754         } else {
  755             return false;
  756         }
  757 
  758     }
  759 
  760     function getValue( $key, $var) {
  761 
  762         if ( isset( $var ) && is_array( $var ) ) {
  763             if ( array_key_exists( $key, $var) ) {
  764                 return $var[$key];
  765             }
  766         }
  767     }
  768 
  769     function substituteValue($string, $var_name) {
  770 
  771         $value = $this->get($var_name);
  772 
  773         if ($value) {
  774 
  775             return sprintf($string,$value);
  776         }
  777     }
  778 
  779     function makeNavigationMenu($links, $currentSiteId, $current_action = '') {
  780 
  781         if (!empty($links) && !empty($currentSiteId)) {
  782 
  783             $t = new owa_template;
  784             $t->set('links', $links);
  785             $t->set('currentSiteId', $currentSiteId);
  786             $t->set('params', array('do' => $current_action ));
  787             $t->caller_params['link_state'] = $this->caller_params['link_state'];
  788             $t->set_template('report_nav.tpl');
  789             return $t->fetch();
  790         } else {
  791 
  792             return false;
  793         }
  794 
  795     }
  796 
  797     function displayChart($id, $data, $width = '100%', $height = '200px') {
  798 
  799         if (!empty($data)) {
  800 
  801             $t = new owa_template;
  802             $t->set('dom_id', $id.'Chart');
  803             $t->set('data', $data);
  804             $t->set('width', $width);
  805             $t->set('height', $height);
  806             $t->set_template('chart_dom.tpl');
  807             return $t->fetch();
  808         } else {
  809 
  810             return false;
  811         }
  812     }
  813 
  814     function displaySparkline($id, $data, $width = '100px', $height = '35px') {
  815 
  816         if (!empty($data)) {
  817 
  818             $data_string = implode(',', $data);
  819 
  820             $t = new owa_template;
  821             $t->set('dom_id', $id.'Sparkline');
  822             $t->set('data', $data_string);
  823             $t->set('width', $width);
  824             $t->set('height', $height);
  825             $t->set_template('sparkline_dom.tpl');
  826             return $t->fetch();
  827 
  828         } else {
  829 
  830             return false;
  831         }
  832     }
  833 
  834     function displaySeriesAsSparkline($name, $result_set_obj, $id = '') {
  835 
  836         if (!$id) {
  837             $id = rand();
  838         }
  839 
  840         $series = $result_set_obj->getSeries($name);
  841 
  842         if ($series) {
  843             echo $this->displaySparkline($id, $series);
  844         }
  845     }
  846 
  847     function makeTable($labels, $data, $table_class = '', $table_id = '', $is_sortable = true) {
  848 
  849         $t = new owa_template;
  850 
  851         if (!empty($table_id)) {
  852             $id = rand();
  853         }
  854 
  855         $t->set('table_id', $id.'Table');
  856         $t->set('data', $data);
  857         $t->set('labels', $labels);
  858         $t->set('class', $table_class);
  859         if ($is_sortable === true) {
  860             $t->set('sort_table_class', 'tablesorter');
  861         }
  862 
  863         $t->set_template('generic_table.tpl');
  864 
  865         return $t->fetch();
  866 
  867     }
  868 
  869     function subTemplate($template_name = '', $map = array(), $linkstate = array()) {
  870 
  871         $t = new owa_template;
  872 
  873         $t->set_template($template_name);
  874 
  875         foreach ($map as $k => $v) {
  876 
  877             $t->set($k, $v);
  878         }
  879 
  880         return $t->fetch();
  881 
  882     }
  883 
  884     function formatNumber($num, $decimal_places) {
  885 
  886         return number_format($num, $decimal_places,'.',',');
  887     }
  888 
  889     function getAvatarImage($email) {
  890 
  891         if (false != $email && $email !== '(not set)') {
  892             return sprintf("https://www.gravatar.com/avatar/%s?s=30", md5($email));
  893         }
  894     }
  895 
  896     function displayMetricInfobox($params = array()) {
  897 
  898         $t = new owa_template;
  899 
  900         if (!empty($dom_id)) {
  901             $dom_id = rand();
  902         }
  903         $params['do'] = 'getResultSet';
  904         $count = owa_coreAPI::executeApiCommand($params);
  905         $params['period'] = 'last_thirty_days';
  906         $params['dimensions'] = 'date';
  907         $trend = owa_coreAPI::executeApiCommand($params);
  908         $t->set('metric_name', $params['metrics']);
  909         $t->set('dom_id', $dom_id);
  910         $t->set('count', $count);
  911         $t->set('trend', $trend);
  912         $t->set_template('metricInfobox.php');
  913 
  914         return $t->fetch();
  915 
  916     }
  917 
  918     public function renderKpiInfobox($number, $label, $link = '', $class = '') {
  919 
  920         $t = new owa_template;
  921         $t->set_template( 'kpiInfobox.php' );
  922         $t->set( 'number', $number );
  923         $t->set( 'label', $label );
  924 
  925         if ($link) {
  926             $t->set( 'link', $link );
  927         }
  928 
  929         if ($class) {
  930             $t->set( 'class', $class );
  931         }
  932 
  933         echo $t->fetch();
  934 
  935     }
  936 
  937     function renderDimension($template, $properties) {
  938 
  939         $t = new owa_template;
  940         $t->set('properties', $properties);
  941         $t->set_template($template);
  942         return $t->fetch();
  943     }
  944 
  945     /**
  946      * Creates a hidden nonce form field
  947      *
  948      * @param     string    $action the action that the nonce should be tied to.
  949      * @return    string The html fragment
  950      */
  951     function createNonceFormField($action) {
  952 
  953         return sprintf(
  954                 '<input type="hidden" name="%snonce" value="%s">',
  955                 owa_coreAPI::getSetting('base', 'ns'),
  956                 owa_coreAPI::createNonce($action));
  957     }
  958 
  959     function makeNonceLink() {
  960 
  961     }
  962 
  963     /**
  964      * Outputs data into the template
  965      *
  966      * @param    string    $output        The String to be output into the template
  967      * @param    bool    $sanitize    Flag that will sanitize the output for display
  968      */
  969     function out($output, $sanitize = true, $decode_special_entities = false) {
  970 
  971         if ( $sanitize ) {
  972             $output = owa_sanitize::escapeForDisplay($output);
  973 
  974             if ( $decode_special_entities ) {
  975                 $output = strtr($output, array('&amp;'  => '&'));
  976             }
  977 
  978         }
  979 
  980         echo $output;
  981     }
  982 
  983     function formatCurrency($value) {
  984         return owa_lib::formatCurrency( $value, owa_coreAPI::getSetting( 'base', 'currencyLocal' ), owa_coreAPI::getSetting( 'base', 'currencyISO3' ) );
  985     }
  986 
  987     function getCurrentUser() {
  988 
  989         return owa_coreAPI::getCurrentUser();
  990     }
  991 
  992     public function getSiteThumbnail( $domain, $width = '200' ) {
  993 
  994         echo sprintf('<img src="https://s.wordpress.com/mshots/v1/%s?w=%s" width="%s">', urlencode($domain .'/'), $width, $width );
  995     }
  996 
  997     /**
  998      * Checks is a display value is set.
  999      */
 1000     public function isValueSet( $string ) {
 1001 
 1002         if ($string === '(not set)' || empty( $string ) ) {
 1003 
 1004             return false;
 1005 
 1006         } else {
 1007 
 1008             return true;
 1009         }
 1010     }
 1011 }
 1012 
 1013 
 1014 ?>