/**
  * Open the dir, suppressing possible errors and try to
  * create when it does not exist
  *
  * @param type $directory
  * @return Directory
  */
 protected function _checkDir($directory)
 {
     $eDir = @dir($directory);
     if (false == $eDir) {
         // Dir does probably not exist
         if (!is_dir($directory)) {
             if (false === @mkdir($directory, 0777, true)) {
                 \MUtil_Echo::pre(sprintf($this->translate->_('Directory %s not found and unable to create'), $directory), 'OpenRosa ERROR');
             } else {
                 $eDir = @dir($directory);
             }
         }
     }
     return $eDir;
 }
示例#2
0
 /**
  * Compile a less file
  *
  * @param \Zend_View $view
  * @param string $href The less file
  * @param boolean $always Always compile
  * @return boolean True when changed
  */
 public function compile(\Zend_View $view, $href, $always = false)
 {
     if (\MUtil_String::startsWith($href, 'http', true)) {
         // When a local url, strip the serverUrl and basepath
         $base = $view->serverUrl() . $view->baseUrl();
         if (\MUtil_String::startsWith($href, $base, true)) {
             // Only strip when urls match
             $href = substr($href, strlen($base));
         }
     }
     // Add full path to the webdir
     $inFile = $this->_webroot . '/' . $href;
     $outFile = substr($inFile, 0, -strlen(pathinfo($inFile, PATHINFO_EXTENSION))) . 'css';
     // Try compiling
     try {
         // \MUtil_Echo::track($inFile, $outFile);
         $lessc = new lessc();
         $lessc->registerFunction('base64encode', array($this, 'base64encode'));
         if ($always || array_key_exists('compilecss', \Zend_Controller_Front::getInstance()->getRequest()->getParams())) {
             $result = (bool) $lessc->compileFile($inFile, $outFile);
         } else {
             $result = $lessc->checkedCompile($inFile, $outFile);
         }
     } catch (\Exception $exc) {
         // If we have an error, present it if not in production
         if (APPLICATION_ENV !== 'production' || APPLICATION_ENV !== 'acceptance') {
             \MUtil_Echo::pre($exc->getMessage());
         }
         $result = null;
     }
     return $result;
 }
 /**
  * Get a select statement using a filter and sort
  *
  * @param array $filter Filter array, num keys contain fixed expresions, text keys are equal or one of filters
  * @param array $sort Sort array field name => sort type
  * @return \Zend_Db_Table_Select
  */
 protected function _createSelect(array $filter, array $sort)
 {
     $select = $this->getSelect();
     if ($this->hasItemsUsed()) {
         // Add expression columns by default
         // getColumn() triggers the columns as 'used'
         $this->getCol('column_expression');
         // Add each column to the select statement
         foreach ($this->getItemsUsed() as $name) {
             if ($expression = $this->get($name, 'column_expression')) {
                 $select->columns(array($name => $expression));
             } else {
                 if ($table = $this->get($name, 'table')) {
                     $select->columns(array($name => $name), $table);
                 }
             }
         }
     } else {
         // Add only the columns, all other fields are returned already.
         foreach ($this->getCol('column_expression') as $name => $expression) {
             $select->columns(array($name => $expression));
         }
     }
     $adapter = $this->getAdapter();
     // Filter
     foreach ($filter as $name => $value) {
         if (is_int($name)) {
             $select->where($value);
         } else {
             if ($expression = $this->get($name, 'column_expression')) {
                 //The brackets tell \Zend_Db_Select that this is an epression in a sort.
                 $name = '(' . $expression . ')';
             } elseif ('limit' === strtolower($name)) {
                 if (is_array($value)) {
                     $count = array_shift($value);
                     $offset = reset($value);
                 } else {
                     $count = $value;
                     $offset = null;
                 }
                 $select->limit($count, $offset);
                 continue;
             } else {
                 $name = $adapter->quoteIdentifier($name);
             }
             if (null === $value) {
                 $select->where($name . ' IS NULL');
             } elseif (is_array($value)) {
                 if ($value) {
                     $select->where($name . ' IN (' . $adapter->quote($value) . ')');
                 } else {
                     // Never a result when a value should be one of an empty set.
                     $select->where('1=0');
                 }
             } else {
                 $select->where($name . ' = ?', $value);
             }
         }
     }
     // Sort
     foreach ($sort as $key => $order) {
         if (is_numeric($key) || is_string($order)) {
             if ($this->has($order)) {
                 $sqlsort[] = $order;
             }
         } else {
             // Code not needed at least for MySQL, a named calculated column can be used in
             // an ORDER BY. However, it does work.
             /*
                             if ($expression = $this->get($key, 'column_expression')) {
                                 //The brackets tell \Zend_Db_Select that this is an epression in a sort.
                                 $key = '(' . $expression . ')';
                             } // */
             switch ($order) {
                 case SORT_ASC:
                     if ($this->has($key)) {
                         $sqlsort[] = $key . ' ASC';
                     }
                     break;
                 case SORT_DESC:
                     if ($this->has($key)) {
                         $sqlsort[] = $key . ' DESC';
                     }
                     break;
                 default:
                     if ($this->has($order)) {
                         $sqlsort[] = $order;
                     }
                     break;
             }
         }
     }
     if (isset($sqlsort)) {
         $select->order($sqlsort);
     }
     if (\MUtil_Model::$verbose) {
         \MUtil_Echo::pre($select, get_class($this) . ' select');
     }
     return $select;
 }