Marius Cramer
2013-11-14 b1a6a5a3991cec5cd08873b01376e45d0b247f18
server/lib/classes/aps_base.inc.php
@@ -43,61 +43,69 @@
class ApsBase
{
    protected $log_prefix = '';
    protected $fetch_url = '';
    protected $aps_version = '';
    protected $packages_dir = '';
    protected $temp_pkg_dir = '';
    protected $interface_pkg_dir = '';
    protected $interface_mode = false; // server mode by default
   protected $log_prefix = '';
   protected $fetch_url = '';
   protected $aps_version = '';
   protected $packages_dir = '';
   protected $temp_pkg_dir = '';
   protected $interface_pkg_dir = '';
   protected $interface_mode = false; // server mode by default
    /**
     * Constructor
     *
     * @param $app the application instance (db handle + log method)
     * @param $interface_mode act in interface (true) or server mode (false)
     * @param $log_prefix a prefix to set before all log entries
     */
    public function __construct($app, $log_prefix = 'APS: ', $interface_mode = false)
    {
        $this->log_prefix = $log_prefix;
        $this->interface_mode = $interface_mode;
        $this->fetch_url = 'apscatalog.com';
        $this->aps_version = '1';
        $this->packages_dir = ISPC_ROOT_PATH.'/aps_packages';
        $this->interface_pkg_dir = ISPC_ROOT_PATH.'/web/sites/aps_meta_packages';
    }
    /**
     * Converts a given value to it's native representation in 1024 units
     *
     * @param $value the size to convert
     * @return integer and string
     */
    public function convertSize($value)
    {
        $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB');
        return @round($value/pow(1024, ($i = floor(log($value, 1024)))), 2).' '.$unit[$i];
    }
    /**
     * Determine a specific xpath from a given SimpleXMLElement handle. If the
     * element is found, it's string representation is returned. If not,
     * the return value will stay empty
     *
     * @param $xml_handle the SimpleXMLElement handle
     * @param $query the XPath query
     * @param $array define whether to return an array or a string
     * @return $ret the return string
     */
    protected function getXPathValue($xml_handle, $query, $array = false)
    {
        $ret = '';
        $xp_result = @($xml_handle->xpath($query)) ? $xml_handle->xpath($query) : false;
        if($xp_result !== false) $ret = (($array === false) ? (string)$xp_result[0] : $xp_result);
        return $ret;
    }
   /**
    * Constructor
    *
    * @param $app the application instance (db handle + log method)
    * @param $interface_mode act in interface (true) or server mode (false)
    * @param $log_prefix a prefix to set before all log entries
    */
   public function __construct($app, $log_prefix = 'APS: ', $interface_mode = false)
   {
      $this->log_prefix = $log_prefix;
      $this->interface_mode = $interface_mode;
      $this->fetch_url = 'apscatalog.com';
      $this->aps_version = '1';
      $this->packages_dir = ISPC_ROOT_PATH.'/aps_packages';
      $this->interface_pkg_dir = ISPC_ROOT_PATH.'/web/sites/aps_meta_packages';
   }
   /**
    * Converts a given value to it's native representation in 1024 units
    *
    * @param $value the size to convert
    * @return integer and string
    */
   public function convertSize($value)
   {
      $unit = array('Bytes', 'KB', 'MB', 'GB', 'TB');
      return @round($value/pow(1024, ($i = floor(log($value, 1024)))), 2).' '.$unit[$i];
   }
   /**
    * Determine a specific xpath from a given SimpleXMLElement handle. If the
    * element is found, it's string representation is returned. If not,
    * the return value will stay empty
    *
    * @param $xml_handle the SimpleXMLElement handle
    * @param $query the XPath query
    * @param $array define whether to return an array or a string
    * @return $ret the return string
    */
   protected function getXPathValue($xml_handle, $query, $array = false)
   {
      $ret = '';
      $xp_result = @($xml_handle->xpath($query)) ? $xml_handle->xpath($query) : false;
      if($xp_result !== false) $ret = (($array === false) ? (string)$xp_result[0] : $xp_result);
      return $ret;
   }
}
?>
?>