Exemple #1
0
 /**
  * Returns a list of types
  * @param mixed Boolean
  * @param mixed Boolean
  * @return array
  */
 function setDirectory($dir = null, $protect = true)
 {
     $success = false;
     // checks to confirm existence of directory
     // then confirms directory is writeable
     if ($dir === null) {
         $dir = $this->getDirectory();
     }
     if ($protect) {
         $helper = new DSCHelper();
         $helper->checkDirectory($dir);
         // then confirms existence of htaccess file
         $htaccess = $dir . DS . '.htaccess';
         if (!($fileexists = JFile::exists($htaccess))) {
             $destination = $htaccess;
             $text = "deny from all";
             if (!JFile::write($destination, $text)) {
                 $this->setError(JText::_('STORAGE DIRECTORY IS UNPROTECTED'));
                 return $success;
             }
         }
     }
     $this->_directory = $dir;
     return $this->_directory;
 }
Exemple #2
0
 /**
  * Protected! Use the getInstance
  */
 protected function DSCHelperImage()
 {
     // Parent Helper Construction
     parent::__construct();
     $config = DSCConfig::getInstance();
     // Load default Parameters
     $this->product_img_height = $config->get('product_img_height');
     $this->product_img_width = $config->get('product_img_width');
     $this->category_img_height = $config->get('category_img_height');
     $this->category_img_width = $config->get('category_img_width');
     $this->manufacturer_img_width = $config->get('manufacturer_img_width');
     $this->manufacturer_img_height = $config->get('manufacturer_img_height');
     $this->product_img_path = DSC::getPath('products_images');
     $this->category_img_path = DSC::getPath('categories_images');
     $this->manufacturer_img_path = DSC::getPath('manufacturers_images');
     $this->product_thumb_path = DSC::getPath('products_thumbs');
     $this->category_thumb_path = DSC::getPath('categories_thumbs');
     $this->manufacturer_thumb_path = DSC::getPath('manufacturers_thumbs');
 }
Exemple #3
0
 /**
  * constructor
  * make it protected where necessary
  */
 function __construct()
 {
     parent::__construct();
 }
Exemple #4
0
 /**
  * Format a number according to currency rules
  *
  * @param unknown_type $amount
  * @param unknown_type $currency
  * @return unknown_type
  */
 function format($amount, $currency = '', $options = '')
 {
     // default to whatever is in config
     $config = DSCConfig::getInstance();
     $options = (array) $options;
     $num_decimals = isset($options['num_decimals']) ? $options['num_decimals'] : $config->get('currency_num_decimals', '2');
     $thousands = isset($options['thousands']) ? $options['thousands'] : $config->get('currency_thousands', ',');
     $decimal = isset($options['decimal']) ? $options['decimal'] : $config->get('currency_decimal', '.');
     $pre = isset($options['pre']) ? $options['pre'] : $config->get('currency_symbol_pre', '$');
     $post = isset($options['post']) ? $options['post'] : $config->get('currency_symbol_post', '');
     // Now check the session variable to see if there is a currency setting there
     $session_currency = DSCHelper::getSessionVariable('currency_id', 0);
     if ($session_currency) {
         // Let the code below deal with currency loading
         $currency = $session_currency;
     }
     // if currency is an object, use it's properties
     if (is_object($currency)) {
         $table = $currency;
         $num_decimals = $table->currency_decimals;
         $thousands = $table->thousands_separator;
         $decimal = $table->decimal_separator;
         $pre = $table->symbol_left;
         $post = $table->symbol_right;
     } elseif (!empty($currency) && is_numeric($currency)) {
         // TODO if currency is an integer, load the object for its id
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sample' . DS . 'tables');
         $table = JTable::getInstance('Currencies', 'DSCTable');
         $table->load((int) $currency);
         if (!empty($table->currency_id)) {
             $num_decimals = $table->currency_decimals;
             $thousands = $table->thousands_separator;
             $decimal = $table->decimal_separator;
             $pre = $table->symbol_left;
             $post = $table->symbol_right;
         }
     } elseif (!empty($currency)) {
         // TODO if currency is a string (currency_code) load the object for its code
         JTable::addIncludePath(JPATH_ADMINISTRATOR . DS . 'components' . DS . 'com_sample' . DS . 'tables');
         $table = JTable::getInstance('Currencies', 'DSCTable');
         $keynames = array();
         $keynames['currency_code'] = (string) $currency;
         $table->load($keynames);
         if (!empty($table->currency_id)) {
             $num_decimals = $table->currency_decimals;
             $thousands = $table->thousands_separator;
             $decimal = $table->decimal_separator;
             $pre = $table->symbol_left;
             $post = $table->symbol_right;
         }
     }
     $return = $pre . number_format($amount, $num_decimals, $decimal, $thousands) . $post;
     return $return;
 }
 /**
  * Verifies the fields in a submitted form.  Uses the table's check() method.
  * Will often be overridden. Is expected to be called via Ajax
  *
  * @return unknown_type
  */
 function validate()
 {
     $input = JFactory::getApplication()->input;
     $response = array();
     $response['msg'] = '';
     $response['error'] = '';
     // get elements from post
     $elements = json_decode(preg_replace('/[\\n\\r]+/', '\\n', $input->getString('elements')));
     // convert elements to array that can be binded
     $helper = new DSCHelper();
     $values = $helper->elementsToArray($elements);
     // get table object
     $table = $this->getModel($this->get('suffix'))->getTable();
     // bind to values
     $table->bind($values);
     // validate it using table's ->check() method
     if (!$table->check()) {
         $string = '';
         // if it fails check, return message
         $response['error'] = '1';
         foreach ($table->getErrors() as $error) {
             $string .= "<li>" . $error . "</li>";
         }
         $response['msg'] = $helper->generateMessage($string, false);
     }
     echo json_encode($response);
     return;
 }
Exemple #6
0
 /**
  * Protected! Use getInstance()
  */
 protected function DSCHelperEmail()
 {
     parent::__construct();
     $this->use_html = true;
 }
Exemple #7
0
 /**
  * Batch actions for saving a thumb of an image
  *
  * @param image	string	filename of the image
  * @param options	array	array of options: width, height, thumb_path
  * @return thumb full path
  */
 function saveThumb($img, $options = array())
 {
     $thumb_path = $img->getDirectory() . DS . 'thumbs';
     $img_width = 'thumb_width';
     $img_height = 'thumb_height';
     $img->load();
     // Default width or options width?
     if (!empty($options['width']) && is_numeric($options['width'])) {
         $width = $options['width'];
     } else {
         $width = $this->{$img_width};
     }
     // Default height or options height?
     if (!empty($options['height']) && is_numeric($options['height'])) {
         $height = $options['height'];
     } else {
         $height = $this->{$img_height};
     }
     // Default thumb path or options thumb path?
     if (!empty($options['thumb_path'])) {
         $dest_dir = $options['thumb_path'];
     } else {
         $dest_dir = $thumb_path;
     }
     $helper = new DSCHelper();
     $helper->checkDirectory($dest_dir);
     if ($width >= $height) {
         $img->resizeToWidth($width);
     } else {
         $img->resizeToHeight($height);
     }
     $dest_path = $dest_dir . DS . $img->getPhysicalName();
     if (!$img->save($dest_path)) {
         $this->setError($img->getError());
         return false;
     }
     return $dest_path;
 }