示例#1
0
 /**
  * Registers multiple Events by Name
  *
  * @param array $events_array  eventname => filename
  * @param array $event_objects eventname => object
  */
 public static function loadEventHandlers($events)
 {
     if (empty($events) or is_array($events) === false) {
         return;
     } else {
         // ok, we got an array with some event names
         foreach ($events as $event) {
             // array[0] filename
             $filename = $array[0];
             // array[1] classname
             $classname = Koch_Functions::ensurePrefixedWith($array[1], 'Koch_Event_');
             // load eventhandler
             Koch_Loader::requireFile($filename, $classname);
             // instantiate eventhandler
             $event_object = new $classname();
             // add the eventhandler to the dispatcher
             $eventdispatcher = Koch_Eventdispatcher::instantiate();
             $eventdispatcher->addEventHandler($event, $event_object);
         }
     }
 }
/**
 * Smarty plugin
 *
 * Type:     modifier<br>
 * Name:     duration<br>
 * Date:     Oct 07, 2008
 * Purpose:  show format_seconds_to_shortstring from current timestamp in seconds
 * Input:
 *
 * Example:  {$seconds|formatseconds}
 * @param string
 * @return string
 */
function smarty_modifier_formatseconds($seconds)
{
    return Koch_Functions::format_seconds_to_shortstring($seconds);
}
示例#3
0
 /**
  * preRenderChecks
  */
 public function preRenderChecks()
 {
     $layout_tpl_name = $this->getLayoutTemplate();
     $this->renderer->template_dir = Koch_Functions::array_flatten($this->renderer->template_dir);
     foreach ($this->renderer->template_dir as $dir) {
         $filename = $dir . $layout_tpl_name;
         if (is_file($filename) === true) {
             return self::preRenderCheck($filename, file_get_contents($filename));
         }
     }
 }
示例#4
0
 /**
  * Gets a Config Value or sets a default value
  *
  * @example
  * Usage for one default variable:
  * self::getConfigValue('items_newswidget', '8');
  * Gets the value for the key items_newswidget from the moduleconfig or sets the value to 8.
  *
  * Usage for two default variables:
  * self::getConfigValue('items_newswidget', $_GET['numberNews'], '8');
  * Gets the value for the key items_newswidget from the moduleconfig or sets the value
  * incomming via GET, if nothing is incomming, sets the default value of 8.
  *
  * @param  string $keyname     The keyname to find in the array.
  * @param  mixed  $default_one A default value returned, when keyname was not found.
  * @param  mixed  $default_two A default value returned, when keyname was not found and default_one is null.
  * @return mixed
  */
 public static function getConfigValue($keyname, $default_one = null, $default_two = null)
 {
     // if we don't have a moduleconfig array yet, get it
     if (self::$moduleconfig === null) {
         self::$moduleconfig = self::getModuleConfig();
     }
     // try a lookup of the value by keyname
     $value = Koch_Functions::array_find_element_by_key($keyname, self::$moduleconfig);
     // return value or default
     if (empty($value) === false) {
         return $value;
     } elseif ($default_one != null) {
         return $default_one;
     } elseif ($default_two != null) {
         return $default_two;
     } else {
         return null;
     }
 }
/**
 * Smarty plugin
 *
 * Type:     modifier<br>
 * Name:     megabytes<br>
 * Date:     Oct 07, 2008
 * Purpose:  convert a number to megabytes , kilobytes, bytes
 * Input:<br>
 *         - string = bytesize to convert to mb, kb, b
 * Example:  {$bytesize|megabytes}
 * @param string
 * @return string
 */
function smarty_modifier_megabytes($string)
{
    return Koch_Functions::getsize($string);
}
示例#6
0
/**
 * Smarty plugin
 *
 * Type:     modifier<br>
 * Name:     duration<br>
 * Date:     Oct 07, 2008
 * Purpose:  show distanceOfTimeInWords from current timestamp to string timestamp
 * Input:
 * Example:  {$timestamp|duration}
 * @param string
 * @return string
 */
function smarty_modifier_duration($toTimestamp)
{
    return Koch_Functions::distanceOfTimeInWords(time(), $toTimestamp, false);
}
示例#7
0
 /**
  * The method
  * - lists all currently included and required files.
  * - counts all includes files
  * - calculates the total size (combined filesize) of all inclusions
  */
 public static function getIncludedFiles()
 {
     // init vars
     $includedFiles = $files = array();
     $includedFilesTotalSize = $includedFilesCount = 0;
     // fetch all included files
     $files = get_included_files();
     // loop over all included files and sum up filesize
     foreach ($files as $file) {
         $size = filesize($file);
         $includedFiles[] = array('name' => $file, 'size' => $size);
         $includedFilesTotalSize += $size;
     }
     // total number of included files
     $includedFilesCount = count($includedFiles);
     $includedFilesTotalSize = Koch_Functions::getsize($includedFilesTotalSize);
     self::printR(array('count' => $includedFilesCount, 'size' => $includedFilesTotalSize, 'files' => $includedFiles));
 }
示例#8
0
 /**
  * Get stats and usage Informations for display from APC
  * 1. Shared Memory Allocation
  * 2. Cache Infos / Meta-Data
  */
 public function stats()
 {
     $apc_sysinfos = array();
     // Retrieve APC Version
     $apc_sysinfos['version'] = phpversion('apc');
     $apc_sysinfos['phpversion'] = phpversion();
     /**
      * ========================================================
      *   Retrieves APC's Shared Memory Allocation information
      * ========================================================
      */
     if (function_exists('apc_sma_info')) {
         $apc_sysinfos['sma_info'] = apc_sma_info();
         // set "false" for details
         // Calculate "APC Memory Size" (Number of Segments * Size of Segment)
         $apc_sysinfos['sma_info']['mem_size'] = $apc_sysinfos['sma_info']['num_seg'] * $apc_sysinfos['sma_info']['seg_size'];
         // Calculate "APC Memory Usage" ( mem_size - avail_mem )
         $apc_sysinfos['sma_info']['mem_used'] = $apc_sysinfos['sma_info']['mem_size'] - $apc_sysinfos['sma_info']['avail_mem'];
         // Calculate "APC Free Memory Percentage" ( mem_size*100/mem_used )
         $apc_sysinfos['sma_info']['mem_avail_percentage'] = sprintf('(%.1f%%)', $apc_sysinfos['sma_info']['avail_mem'] * 100 / $apc_sysinfos['sma_info']['mem_size']);
     }
     if (function_exists('apc_cache_info') and false === extension_loaded('Zend Data Cache')) {
         // Retrieves cached information and meta-data from APC's data store
         $apc_sysinfos['cache_info'] = apc_cache_info();
         #Koch_Debug::printR(apc_cache_info());
         $apc_sysinfos['cache_info']['cached_files'] = count($apc_sysinfos['cache_info']['cache_list']);
         $apc_sysinfos['cache_info']['deleted_files'] = count($apc_sysinfos['cache_info']['deleted_list']);
         /**
          * ========================================================
          *   System Cache Informations
          * ========================================================
          */
         $apc_sysinfos['system_cache_info'] = apc_cache_info('system', false);
         // set "false" for details
         // Calculate "APC Hit Rate Percentage"
         $total_hits = $apc_sysinfos['system_cache_info']['num_hits'] + $apc_sysinfos['system_cache_info']['num_misses'];
         // div by zero fix
         if ($total_hits == 0) {
             $total_hits = 1;
         }
         $hit_rate = $apc_sysinfos['system_cache_info']['num_hits'] * 100 / $total_hits;
         $apc_sysinfos['system_cache_info']['hit_rate_percentage'] = sprintf('(%.1f%%)', $hit_rate);
         // Calculate "APC Miss Rate Percentage"
         $apc_sysinfos['system_cache_info']['miss_rate_percentage'] = sprintf('(%.1f%%)', $apc_sysinfos['system_cache_info']['num_misses'] * 100 / $total_hits);
         $apc_sysinfos['system_cache_info']['files_cached'] = count($apc_sysinfos['system_cache_info']['cache_list']);
         $apc_sysinfos['system_cache_info']['files_deleted'] = count($apc_sysinfos['system_cache_info']['deleted_list']);
         $time = time();
         // Request Rate (hits, misses) / cache requests/second
         $apc_sysinfos['system_cache_info']['req_rate'] = sprintf('%.2f', ($apc_sysinfos['system_cache_info']['num_hits'] + $apc_sysinfos['system_cache_info']['num_misses']) / ($time - $apc_sysinfos['system_cache_info']['start_time']));
         $apc_sysinfos['system_cache_info']['hit_rate'] = sprintf('%.2f', $apc_sysinfos['system_cache_info']['num_hits'] / ($time - $apc_sysinfos['system_cache_info']['start_time']));
         $apc_sysinfos['system_cache_info']['miss_rate'] = sprintf('%.2f', $apc_sysinfos['system_cache_info']['num_misses'] / ($time - $apc_sysinfos['system_cache_info']['start_time']));
         $apc_sysinfos['system_cache_info']['insert_rate'] = sprintf('%.2f', $apc_sysinfos['system_cache_info']['num_inserts'] / ($time - $apc_sysinfos['system_cache_info']['start_time']));
         // size
         $apc_sysinfos['system_cache_info']['size_files'] = Koch_Functions::getsize($apc_sysinfos['system_cache_info']['mem_size']);
     }
     $apc_sysinfos['settings'] = ini_get_all('apc');
     /**
      * ini_get_all array mod: for each accessvalue
      * add the name of the PHP ACCESS CONSTANTS as 'accessname'
      * @todo: cleanup?
      */
     foreach ($apc_sysinfos['settings'] as $key => $value) {
         foreach ($value as $key2 => $value2) {
             if ($key2 == 'access') {
                 $name = '';
                 // accessvalue => constantname
                 if ($value2 == '1') {
                     $name = 'PHP_INI_USER';
                 }
                 if ($value2 == '2') {
                     $name = 'PHP_INI_PERDIR';
                 }
                 if ($value2 == '4') {
                     $name = 'PHP_INI_SYSTEM';
                 }
                 if ($value2 == '7') {
                     $name = 'PHP_INI_ALL';
                 }
                 // add accessname to the original array
                 $apc_sysinfos['settings'][$key]['accessname'] = $name;
                 unset($name);
             }
         }
     }
     #$apc_sysinfos['sma_info']['size_vars']  = Koch_Functions::getsize($cache_user['mem_size']);
     return $apc_sysinfos;
 }