Ejemplo n.º 1
0
 /**
  * Performs the server-side validation
  *
  * Before the Rules added to the element kick in, the element checks the
  * error code added to the $_FILES array by PHP. If the code isn't
  * UPLOAD_ERR_OK or UPLOAD_ERR_NO_FILE then a built-in error message will be
  * displayed and no further validation will take place.
  *
  * @return   boolean     Whether the element is valid
  */
 protected function validate()
 {
     if (strlen($this->error)) {
         return false;
     }
     if (isset($this->value['error']) && !in_array($this->value['error'], array(UPLOAD_ERR_OK, UPLOAD_ERR_NO_FILE))) {
         $errorMessage = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('file', $this->value['error']), $this->language) : call_user_func($this->messageProvider, array('file', $this->value['error']), $this->language);
         if (UPLOAD_ERR_INI_SIZE == $this->value['error']) {
             $iniSize = ini_get('upload_max_filesize');
             $size = intval($iniSize);
             switch (strtoupper(substr($iniSize, -1))) {
                 case 'G':
                     $size *= 1024;
                 case 'M':
                     $size *= 1024;
                 case 'K':
                     $size *= 1024;
             }
         } elseif (UPLOAD_ERR_FORM_SIZE == $this->value['error']) {
             foreach ($this->getDataSources() as $ds) {
                 if ($ds instanceof HTML_QuickForm2_DataSource_Submit) {
                     $size = intval($ds->getValue('MAX_FILE_SIZE'));
                     break;
                 }
             }
         }
         $this->error = isset($size) ? sprintf($errorMessage, $size) : $errorMessage;
         return false;
     }
     return parent::validate();
 }
Ejemplo n.º 2
0
 /**
  * @param string $filename
  * @return string
  * */
 public function contentRaw($filename)
 {
     if (!$this->has($filename)) {
         throw new IOException(self::T_DOWNLOADER_STR_FILE_NOT_FOUND, self::T_DOWNLOADER_CODE_FILE_NOT_FOUND);
     }
     $this->_before->__invoke();
     return file_get_contents($this->__fullpath($filename));
 }
Ejemplo n.º 3
0
 private static function updateSets(callback $callback = null)
 {
     // Update the callback if one is present
     if ($callback) {
         $callback->call('Updating sets...');
     }
     // Pull the country list
     $db = new DatabaseConnection();
     $rs = $db->getRows("SELECT isocode,capital FROM geonames_countryinfo");
     foreach ($rs as $cc) {
         $f = $db->getSingleRow("SELECT * FROM geonames_datasets WHERE setkey=%s", $cc['isocode']);
         if (!$f) {
             $db->insertRow("INSERT INTO geonames_datasets (setkey,setname,url,active) VALUES (%s,%s,%s,0)", $cc['isocode'], $cc['capital'], self::getUrl($cc['isocode'] . '.zip'));
         }
     }
     if ($callback) {
         $callback->call('All sets updated');
     }
 }
Ejemplo n.º 4
0
 /**
  * Asserts specific queries going into the database. Currently assumes mongo.
  *
  * Yikes this is a stubby method, but honey badger don't give a shit.
  *
  * {{{
  * $this->assertQueries()
  * }}}
  *
  * @param  string    $class     Fully namespaced model class.
  * @param  int       $expected  Number of queries expected.
  * @param  callback  $query     Callback to be executed, contains the `::find` or `::all`.
  * @param  string    $message   optional
  * @return bool
  */
 public function assertQueries($class, $expected, $query, $message = '{:message}')
 {
     $result = array();
     $args = array();
     $connection = $class::connection();
     $connection->applyFilter('read', function ($self, $params, $chain) use(&$result, &$args) {
         $args = $params['query']->export($self);
         $queryParams = array('name' => $params['query']->config('source'));
         foreach (array('conditions', 'fields', 'order', 'limit', 'offset') as $key) {
             if (!empty($args[$key])) {
                 $queryParams[$key] = $args[$key];
             }
         }
         $result[] = $queryParams;
         return $chain->next($self, $params, $chain);
     });
     $query->__invoke();
     $connection->applyFilter('read', false);
     return $this->assertEqual($expected, $result, $message, compact('expected', 'result'));
 }
Ejemplo n.º 5
0
 /**
  * Select and return an object array based on a table definition.
  *
  * The result is filtered by a callback object passed into the function. This object must
  * have implemented a method called "checkResult" which is passed the resulting data rows
  * one by one. The "checkResult" function returns true if the datarow is ok, otherwise
  * it returns false.
  *
  * Example:
  * <code>
  * class myFilter
  * {
  *   var $userId;
  *
  *   function checkResult($datarow)
  *   {
  *     return $datarow['ownerUserId'] == $this->userId;
  *   }
  * }
  * </code>
  *
  * @param string   $table          The treated table reference.
  * @param string   $where          The where clause (optional) (default='').
  * @param string   $orderby        The order by clause (optional) (default='').
  * @param integer  $limitOffset    The lower limit bound (optional) (default=-1).
  * @param integer  $limitNumRows   The upper limit bound (optional) (default=-1).
  * @param string   $assocKey       The key field to use to build the associative index (optional) (default='').
  * @param callback $filterCallback The filter callback object.
  * @param array    $categoryFilter The category list to use for filtering.
  * @param array    $columnArray    The columns to marshall into the resulting object (optional) (default=null).
  *
  * @return The resulting object array
  */
 public static function selectObjectArrayFilter($table, $where = '', $orderby = '', $limitOffset = -1, $limitNumRows = -1, $assocKey = '', $filterCallback, $categoryFilter = null, $columnArray = null)
 {
     self::_setFetchedObjectCount(0);
     $where = self::generateCategoryFilterWhere($table, $where, $categoryFilter);
     $where = self::_checkWhereClause($where);
     $orderby = self::_checkOrderByClause($orderby, $table);
     $objects = array();
     $fetchedObjectCount = 0;
     $ca = null;
     //Note required since Zikula 1.3.0 because of PDO::fetchAll() see #2227 //self::getColumnsArray($table, $columnArray);
     $sql = self::_getSelectAllColumnsFrom($table, $where, $orderby, $columnArray);
     do {
         $stmt = $sql;
         $limitOffset += $fetchedObjectCount;
         $res = self::executeSQL($stmt, $limitOffset, $limitNumRows);
         if ($res === false) {
             return $res;
         }
         $objArr = self::marshallObjects($res, $ca, true, $assocKey, true, null, $table);
         $fetchedObjectCount = self::_getFetchedObjectCount();
         for ($i = 0, $cou = count($objArr); $i < $cou; ++$i) {
             $obj =& $objArr[$i];
             if ($filterCallback->checkResult($obj)) {
                 $objects[] = $obj;
             }
         }
     } while ($limitNumRows != -1 && $limitNumRows > 0 && $fetchedObjectCount > 0 && count($objects) < $limitNumRows);
     $tables = self::getTables();
     $idFieldName = isset($tables["{$table}_primary_key_column"]) ? $tables["{$table}_primary_key_column"] : 'id';
     $objects = self::_selectPostProcess($objects, $table, $idFieldName);
     return $objects;
 }
Ejemplo n.º 6
0
 /**
  * Class constructor
  *
  * The following keys may appear in $data array:
  * - 'messageProvider': a callback or an instance of a class implementing
  *   HTML_QuickForm2_MessageProvider interface, this will be used to get
  *   localized names of months and weekdays. Some of the default ones will
  *   be used if not given.
  * - 'language': date language, use 'locale' here to display month / weekday
  *   names according to the current locale.
  * - 'format': Format of the date, based on PHP's date() function.
  *   The following characters are currently recognised in format string:
  *   <pre>
  *       D => Short names of days
  *       l => Long names of days
  *       d => Day numbers
  *       M => Short names of months
  *       F => Long names of months
  *       m => Month numbers
  *       Y => Four digit year
  *       y => Two digit year
  *       h => 12 hour format
  *       H => 24 hour format
  *       i => Minutes
  *       s => Seconds
  *       a => am/pm
  *       A => AM/PM
  *   </pre>
  * - 'minYear': Minimum year in year select
  * - 'maxYear': Maximum year in year select
  * - 'addEmptyOption': Should an empty option be added to the top of
  *    each select box?
  * - 'emptyOptionValue': The value passed by the empty option.
  * - 'emptyOptionText': The text displayed for the empty option.
  * - 'optionIncrement': Step to increase the option values by (works for 'i' and 's')
  * - 'minHour': Minimum hour in hour select (only for 24 hour format!)
  * - 'maxHour': Maximum hour in hour select (only for 24 hour format!)
  * - 'minMonth': Minimum month in month select
  * - 'maxMonth': Maximum month in month select
  *
  * @param    string  Element name
  * @param    mixed   Attributes (either a string or an array)
  * @param    array   Element data (label, options and data used for element creation)
  */
 public function __construct($name = null, $attributes = null, array $data = array())
 {
     if (isset($data['messageProvider'])) {
         if (!is_callable($data['messageProvider']) && !$data['messageProvider'] instanceof HTML_QuickForm2_MessageProvider) {
             throw new HTML_QuickForm2_InvalidArgumentException("messageProvider: expecting a callback or an implementation" . " of HTML_QuickForm2_MessageProvider");
         }
         $this->messageProvider = $data['messageProvider'];
     } else {
         if (isset($data['language']) && 'locale' == $data['language']) {
             HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_MessageProvider_Strftime');
             $this->messageProvider = new HTML_QuickForm2_MessageProvider_Strftime();
         } else {
             HTML_QuickForm2_Loader::loadClass('HTML_QuickForm2_MessageProvider_Default');
             $this->messageProvider = HTML_QuickForm2_MessageProvider_Default::getInstance();
         }
     }
     if (isset($data['language'])) {
         $this->language = $data['language'];
     }
     unset($data['messageProvider'], $data['language']);
     // http://pear.php.net/bugs/bug.php?id=18171
     $this->data['maxYear'] = date('Y');
     parent::__construct($name, $attributes, $data);
     $backslash = false;
     $separators = array();
     $separator = '';
     for ($i = 0, $length = strlen($this->data['format']); $i < $length; $i++) {
         $sign = $this->data['format'][$i];
         if ($backslash) {
             $backslash = false;
             $separator .= $sign;
         } else {
             $loadSelect = true;
             switch ($sign) {
                 case 'D':
                     // Sunday is 0 like with 'w' in date()
                     $options = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', 'weekdays_short'), $this->language) : call_user_func($this->messageProvider, array('date', 'weekdays_short'), $this->language);
                     break;
                 case 'l':
                     $options = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', 'weekdays_long'), $this->language) : call_user_func($this->messageProvider, array('date', 'weekdays_long'), $this->language);
                     break;
                 case 'd':
                     $options = $this->createOptionList(1, 31);
                     break;
                 case 'M':
                 case 'm':
                 case 'F':
                     $options = $this->createOptionList($this->data['minMonth'], $this->data['maxMonth'], $this->data['minMonth'] > $this->data['maxMonth'] ? -1 : 1);
                     if ('M' == $sign || 'F' == $sign) {
                         $key = 'M' == $sign ? 'months_short' : 'months_long';
                         $names = $this->messageProvider instanceof HTML_QuickForm2_MessageProvider ? $this->messageProvider->get(array('date', $key), $this->language) : call_user_func($this->messageProvider, array('date', $key), $this->language);
                         foreach ($options as $k => &$v) {
                             $v = $names[$k - 1];
                         }
                     }
                     break;
                 case 'Y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     break;
                 case 'y':
                     $options = $this->createOptionList($this->data['minYear'], $this->data['maxYear'], $this->data['minYear'] > $this->data['maxYear'] ? -1 : 1);
                     array_walk($options, create_function('&$v,$k', '$v = substr($v,-2);'));
                     break;
                 case 'h':
                     $options = $this->createOptionList(1, 12);
                     break;
                 case 'g':
                     $options = $this->createOptionList(1, 12);
                     array_walk($options, create_function('&$v,$k', '$v = intval($v);'));
                     break;
                 case 'H':
                     $options = $this->createOptionList($this->data['minHour'], $this->data['maxHour'], $this->data['minHour'] > $this->data['maxHour'] ? -1 : 1);
                     break;
                 case 'i':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['i']);
                     break;
                 case 's':
                     $options = $this->createOptionList(0, 59, $this->data['optionIncrement']['s']);
                     break;
                 case 'a':
                     $options = array('am' => 'am', 'pm' => 'pm');
                     break;
                 case 'A':
                     $options = array('AM' => 'AM', 'PM' => 'PM');
                     break;
                 case 'W':
                     $options = $this->createOptionList(1, 53);
                     break;
                 case '\\':
                     $backslash = true;
                     $loadSelect = false;
                     break;
                 default:
                     $separator .= ' ' == $sign ? '&nbsp;' : $sign;
                     $loadSelect = false;
             }
             if ($loadSelect) {
                 if (0 < count($this)) {
                     $separators[] = $separator;
                 }
                 $separator = '';
                 // Should we add an empty option to the top of the select?
                 if (!is_array($this->data['addEmptyOption']) && $this->data['addEmptyOption'] || is_array($this->data['addEmptyOption']) && !empty($this->data['addEmptyOption'][$sign])) {
                     // Using '+' array operator to preserve the keys
                     if (is_array($this->data['emptyOptionText']) && !empty($this->data['emptyOptionText'][$sign])) {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText'][$sign]) + $options;
                     } else {
                         $options = array($this->data['emptyOptionValue'] => $this->data['emptyOptionText']) + $options;
                     }
                 }
                 $this->addSelect($sign, array('id' => self::generateId($this->getName() . "[{$sign}]")) + $this->getAttributes())->loadOptions($options);
             }
         }
     }
     $separators[] = $separator . ($backslash ? '\\' : '');
     $this->setSeparator($separators);
 }