/** * Main action the generate the new Nooku component based on the uploaded file * * @param KCommandContext A command context object */ function _actionGenerate(KCommandContext $context) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helper' . DS . 'BiffWorkbook.inc.php'; $app = JFactory::getApplication(); $component = $this->getModel()->getItem(); // set up sanitize filter $config = array('separator' => ''); $this->filter = KFilter::factory('slug', $config); //create mysql table and import data $result = $this->importExcel($component); if (!$result) { return false; } //show information message $msg = JText::_('Created table and imported data'); $app->enqueueMessage($msg); $result = $this->copyfiles($component); if (!$result) { return false; } $msg = 'Copied files'; $app->enqueueMessage($msg); $result = $this->createentry($component); if ($result == false) { return false; } $msg = 'Registered component'; $app->enqueueMessage($msg); $app = JFactory::getApplication(); $app->redirect('index.php?option=com_' . $this->filter->sanitize($component->name)); }
protected function _databaseBeforeSave($context) { $row = $context->caller; if (!is_uploaded_file($row->file)) { // remote file $file = KFactory::get('com://admin/files.database.row.url'); $file->setData(array('file' => $row->file)); $file->load(); $row->contents = $file->contents; if (empty($row->path)) { $uri = KFactory::get('koowa:http.url', array('url' => $row->file)); $path = $uri->get(KHttpUrl::PATH | KHttpUrl::FORMAT); if (strpos($path, '/') !== false) { $path = basename($path); } $row->path = $path; } } $row->path = KFactory::get('com://admin/files.filter.file.name')->sanitize($row->path); return KFilter::factory('com://admin/files.filter.file.uploadable')->validate($context); }
protected function _databaseBeforeSave($context) { $row = $context->caller; $row->path = KFactory::get('com://admin/files.filter.folder.name')->sanitize($row->path); return KFilter::factory('com://admin/files.filter.folder.uploadable')->validate($context); }
public function getView() { $view = parent::getView(); if ($view) { $return = KFilter::factory('base64')->sanitize($this->_request->return); $view->assign('return', $return); } return $view; }
/** * Get sanitized data from the request. * * @param string Variable identifier, prefixed by hash name eg post.foo.bar * @param mixed Filter(s), can be a KFilter object, a filter name, an array of filter names or a filter identifier * @param mixed Default value when the variable doesn't exist * @throws KRequestException When an invalid filter was passed * @return mixed The sanitized data */ public static function get($identifier, $filter, $default = null) { list($hash, $keys) = self::_parseIdentifier($identifier); $result = null; if(isset($GLOBALS['_'.$hash])) { $result = $GLOBALS['_'.$hash]; foreach($keys as $key) { if(array_key_exists($key, $result)) { $result = $result[$key]; } else { $result = null; break; } } } // If the value is null return the default if(is_null($result)) { return $default; } // Handle magic quotes compatability if (get_magic_quotes_gpc() && !in_array($hash, array('FILES', 'SESSION'))) { $result = self::_stripSlashes( $result ); } if(!($filter instanceof KFilterInterface)) { $filter = KFilter::factory($filter); } return $filter->sanitize($result); }
/** * Implements access to $_filter by reference so that it appears to be * a public $filter property. * * @param string The virtual property to return, only accepts 'filter' * @return mixed The value of the virtual property. */ public function __get($key) { if ($key == 'filter') { if(!isset($this->_filter)) { $this->_filter = $this->type; } if(!($this->_filter instanceof KFilterInterface)) { $this->_filter = KFilter::factory($this->_filter); } return $this->_filter; } }
function getItem() { $item = parent::getItem(); // Initial parsing of the Excel file to determine field types if ($item->filename) { require_once JPATH_COMPONENT_ADMINISTRATOR . DS . 'helper' . DS . 'BiffWorkbook.inc.php'; // set up sanitize filter $config = array('separator' => ''); $filter = KFilter::factory('slug', $config); try { $doc = new CompoundDocument('utf-8'); $doc->parse(file_get_contents(JPATH_COMPONENT_ADMINISTRATOR . DS . 'uploads' . DS . $item->filename)); $wb = new BiffWorkbook($doc); $wb->parse(); } catch (Exception $e) { $app = JFactory::getApplication(); $app->enqueueMessage($e->getMessage()); return false; } foreach ($wb->sheets as $sheetName => $sheet) { for ($col = 0; $col < $sheet->cols(); $col++) { if (!isset($sheet->cells[0][$col])) { continue; } $cell = $sheet->cells[0][$col]; if (is_null($cell->value)) { // skip column } else { $columnname = $filter->sanitize($cell->value); $isnumeric = true; $isint = true; $isdate = true; $strlen = 0; for ($row = 1; $row < $sheet->rows(); $row++) { if (!isset($sheet->cells[$row][$col])) { continue; } if (is_null($sheet->cells[$row][$col]->value)) { continue; } $value = $sheet->cells[$row][$col]->value; if (is_numeric($value)) { if (is_int($value) == false) { $isint = false; } } else { $isnumeric = false; $strlen = max($strlen, strlen($value)); // could it also be a date? $datearr = date_parse_from_format("j/n/y", $value); //needs PHP 5.3 if ($datearr['year'] && $datearr['month'] && $datearr['day']) { // valid date } else { // no valid date $isdate = false; } } } if ($isnumeric) { $columns[$columnname] = 'DECIMAL(10,2)'; if ($isint) { $columns[$columnname] = 'INT(11)'; } } else { if ($isdate) { $columns[$columnname] = 'DATE'; } else { $columns[$columnname] = 'VARCHAR (' . $strlen . ')'; } } } } } $item->columns = $columns; } $this->_item = $item; return $item; }
/** * Set the state data * * @param array|object An associative array of state values by name * @return KConfigState */ public function setData(array $data) { // Filter data foreach($data as $key => $value) { if(isset($this->_data[$key])) { $filter = $this->_data[$key]->filter; if(!($filter instanceof KFilterInterface)) { $filter = KFilter::factory($filter); } $this->_data[$key]->value = $filter->sanitize($value); } } return $this; }