/** * Create the XML object from a string, fFile or URL * * The `$default_namespace` will be used for any sort of methods calls, * member access or array access when the element or attribute name does * not include a `:`. * * @throws fValidationException When the source XML is invalid or does not exist * * @param fFile|string $source The source of the XML, either an fFile object, a string of XML, a file path or a URL * @param numeric $http_timeout The timeout to use in seconds when requesting an XML file from a URL * @return fXML */ public function __construct($source, $http_timeout = NULL) { // Prevent spitting out errors to we can throw exceptions $old_setting = libxml_use_internal_errors(TRUE); $exception_message = NULL; try { if ($source instanceof DOMElement) { $this->__dom = $source; $xml = TRUE; } elseif ($source instanceof fFile) { $xml = simplexml_load_file($source->getPath()); // This handles URLs specially by adding a reasonable timeout } elseif (preg_match('#^(?P<protocol>http(s)?)://#', $source, $matches)) { if ($http_timeout === NULL) { $http_timeout = ini_get('default_socket_timeout'); } // We use the appropriate protocol here so PHP can supress IIS https:// warnings $context = stream_context_create(array($matches['protocol'] => array('timeout' => $http_timeout))); // If the URL is not loaded in time, this supresses the file_get_contents() warning $old_level = error_reporting(error_reporting() & ~E_WARNING); $xml = file_get_contents($source, 0, $context); error_reporting($old_level); if (!$xml) { throw new fExpectedException('The URL specified, %s, could not be loaded', $source); } $xml = new SimpleXMLElement($xml); } else { $is_path = $source && !preg_match('#^\\s*<#', $source); $xml = new SimpleXMLElement($source, 0, $is_path); } } catch (Exception $e) { $exception_message = $e->getMessage(); $xml = FALSE; } // We want it to be clear when XML parsing issues occur if ($xml === FALSE) { $errors = libxml_get_errors(); foreach ($errors as $error) { $exception_message .= "\n" . $error->message; } // If internal errors were off before, turn them back off if (!$old_setting) { libxml_use_internal_errors(FALSE); } throw new fValidationException(str_replace('%', '%%', $exception_message)); } if (!$old_setting) { libxml_use_internal_errors(FALSE); } if (!$this->__dom) { $this->__dom = dom_import_simplexml($xml); } if ($this->__dom->namespaceURI && $this->__dom->prefix == '') { $this->addCustomPrefix('__', $this->__dom->namespaceURI); } }
/** * Validates a $_FILES array against the upload configuration * * @param array $file_array The $_FILES array for a single file * @return string The validation error message */ private function validateField($file_array) { if (empty($file_array['name'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if ($file_array['error'] == UPLOAD_ERR_FORM_SIZE || $file_array['error'] == UPLOAD_ERR_INI_SIZE) { $max_size = !empty($_POST['MAX_FILE_SIZE']) ? $_POST['MAX_FILE_SIZE'] : ini_get('upload_max_filesize'); $max_size = !is_numeric($max_size) ? fFilesystem::convertToBytes($max_size) : $max_size; return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($max_size)); } if ($this->max_size && $file_array['size'] > $this->max_size) { return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($this->max_size)); } if (empty($file_array['tmp_name']) || empty($file_array['size'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if (!empty($this->mime_types) && file_exists($file_array['tmp_name'])) { $contents = file_get_contents($file_array['tmp_name'], FALSE, NULL, 0, 4096); if (!in_array(fFile::determineMimeType($file_array['name'], $contents), $this->mime_types)) { return self::compose($this->mime_type_message); } } if (!$this->allow_php) { $file_info = fFilesystem::getPathInfo($file_array['name']); if (in_array(strtolower($file_info['extension']), array('php', 'php4', 'php5'))) { return self::compose('The file uploaded is a PHP file, but those are not permitted'); } } if (!$this->allow_dot_files) { if (substr($file_array['name'], 0, 1) == '.') { return self::compose('The name of the uploaded file may not being with a .'); } } if ($this->image_dimensions && file_exists($file_array['tmp_name'])) { if (fImage::isImageCompatible($file_array['tmp_name'])) { list($width, $height, $other) = getimagesize($file_array['tmp_name']); if ($this->image_dimensions['min_width'] && $width < $this->image_dimensions['min_width']) { return self::compose('The uploaded image is narrower than the minimum width of %spx', $this->image_dimensions['min_width']); } if ($this->image_dimensions['min_height'] && $height < $this->image_dimensions['min_height']) { return self::compose('The uploaded image is shorter than the minimum height of %spx', $this->image_dimensions['min_height']); } if ($this->image_dimensions['max_width'] && $width > $this->image_dimensions['max_width']) { return self::compose('The uploaded image is wider than the maximum width of %spx', $this->image_dimensions['max_width']); } if ($this->image_dimensions['max_height'] && $height > $this->image_dimensions['max_height']) { return self::compose('The uploaded image is taller than the maximum height of %spx', $this->image_dimensions['max_height']); } } } if ($this->image_ratio && file_exists($file_array['tmp_name'])) { if (fImage::isImageCompatible($file_array['tmp_name'])) { list($width, $height, $other) = getimagesize($file_array['tmp_name']); if ($this->image_ratio['allow_excess_dimension'] == 'width' && $width / $height < $this->image_ratio['width'] / $this->image_ratio['height']) { return self::compose('The uploaded image is too narrow for its height. The required ratio is %1$sx%2$s or wider.', $this->image_ratio['width'], $this->image_ratio['height']); } if ($this->image_ratio['allow_excess_dimension'] == 'height' && $width / $height > $this->image_ratio['width'] / $this->image_ratio['height']) { return self::compose('The uploaded image is too short for its width. The required ratio is %1$sx%2$s or taller.', $this->image_ratio['width'], $this->image_ratio['height']); } } } }
/** * Loads the plaintext version of the email body from a file and applies replacements * * The should contain either ASCII or UTF-8 encoded text. Please see * http://flourishlib.com/docs/UTF-8 for more information. * * @throws fValidationException When no file was specified, the file does not exist or the path specified is not a file * * @param string|fFile $file The plaintext version of the email body * @param array $replacements The method will search the contents of the file for each key and replace it with the corresponding value * @return void */ public function loadHTMLBody($file, $replacements = array()) { if (!$file instanceof fFile) { $file = new fFile($file); } $html = $file->read(); if ($replacements) { $html = strtr($html, $replacements); } $this->html_body = $html; }
/** * Keeps backup copies of files so they can be restored if there is a rollback * * @internal * * @param fFile $file The file that is being written to * @return void */ public static function recordWrite($file) { self::$rollback_operations[] = array('action' => 'write', 'filename' => $file->getPath(), 'old_data' => file_get_contents($file->getPath())); }
//$stationdatas = $station->buildStationdatas(); $fleepdatas = fRecordSet::buildFromSQL('Fleepdata', array("SELECT * FROM `fukushimadatas` WHERE `station_id`=%i AND reading_date > ADDDATE(NOW(), INTERVAL -9 DAY) ORDER BY `reading_date` DESC LIMIT 0 , 6", $station->getStationId())); //$fleepdatas = fRecordSet::buildFromSQL('Fleepdata', array("SELECT * FROM `fukushimadatas` WHERE `station_id`=%i ORDER BY `reading_date` DESC LIMIT 0 , 6",$station->getStationId())); //$stationdatas->sort('getDatetimeString','desc'); $datastreams .= '{"title": "' . $station->getStationNameEn() . '",' . '"title_jp": "' . $station->getStationNameJp() . '",' . '"description": "",' . '"creator": "fukushima_fleep",' . '"feed": "http://www.rdtn.org/feeds/station/' . $station->getStationId() . '.json",' . '"location": {"lon":' . $station->getLongitude() . ', "lat":' . $station->getLatitude() . ', "name": "' . $station->getPrefectureNameEn() . '"},' . '"id":' . $station->getStationId() . ',' . '"datastreams": ['; $success = false; foreach ($fleepdatas as $fleepdata) { $sa = $fleepdata->getReadingValue(); if ($sa != -888 && $sa != -999) { $unit = $fleepdata->createUnit(); $datastreams .= '{"at": "' . $fleepdata->getReadingDate() . '",' . '"max_value": "0",' . '"min_value": "0",' . '"current_value": "' . $fleepdata->getReadingValue() . '",' . '"id": "' . $fleepdata->getReadingId() . '",' . '"unit": {"type": "basicSI","label": "' . $unit->getUnitLabel() . '","symbol": "' . $unit->getUnitSymbol() . '"}}'; $success = true; break; } } if ($success) { //close and append $datastreams .= ']},'; $jsonData .= $datastreams; } $datastreams = ""; } $output .= rtrim($jsonData, ','); $output .= '], "itemsPerPage": ' . $stations->count() . ', "startIndex": 0, "totalResults": ' . $stations->count(TRUE) . '}'; $file = new fFile(DOC_ROOT . '/feeds/fukushima_full_static.json'); $file->write($output); echo $output; ?>
/** * Validates the uploaded file, ensuring a file was actually uploaded and that is matched the restrictions put in place * * @throws fValidationException When no file is uploaded or the uploaded file violates the options set for this object * * @param string $field The field the file was uploaded through * @param integer $index If the field was an array of file uploads, this specifies which one to validate * @return void */ public function validate($field, $index = NULL) { if (!self::check($field)) { throw new fProgrammerException('The field specified, %s, does not appear to be a file upload field', $field); } $file_array = $this->extractFileUploadArray($field, $index); // Do some validation of the file provided if (empty($file_array['name'])) { throw new fValidationException('Please upload a file'); } if ($file_array['error'] == UPLOAD_ERR_FORM_SIZE || $file_array['error'] == UPLOAD_ERR_INI_SIZE) { $max_size = !empty($_POST['MAX_FILE_SIZE']) ? $_POST['MAX_FILE_SIZE'] : ini_get('upload_max_filesize'); $max_size = !is_numeric($max_size) ? fFilesystem::convertToBytes($max_size) : $max_size; $msg = $this->max_message != "" ? $this->max_message : 'The file uploaded is over the limit of %s'; throw new fValidationException($msg, fFilesystem::formatFilesize($max_size)); } if ($this->max_file_size && $file_array['size'] > $this->max_file_size) { $msg = $this->max_message != "" ? $this->max_message : 'The file uploaded is over the limit of %s'; throw new fValidationException($msg, fFilesystem::formatFilesize($this->max_file_size)); } if (empty($file_array['tmp_name']) || empty($file_array['size'])) { throw new fValidationException('Please upload a file'); } if (!empty($this->mime_types) && file_exists($file_array['tmp_name']) && !in_array(fFile::determineMimeType($file_array['tmp_name']), $this->mime_types)) { throw new fValidationException($this->mime_type_message); } if (!$this->allow_php) { $file_info = fFilesystem::getPathInfo($file_array['name']); if (in_array(strtolower($file_info['extension']), array('php', 'php4', 'php5'))) { throw new fValidationException('The file uploaded is a PHP file, but those are not permitted'); } } return $file_array; }
public function testMove() { $file = new fFile('output/fFile/one.txt'); $file->move('output/fFile2/', TRUE); $this->assertEquals('one.txt', $file->getName()); $this->assertEquals(str_replace('/', DIRECTORY_SEPARATOR, $_SERVER['DOCUMENT_ROOT'] . '/output/fFile2/'), $file->getParent()->getPath()); }
case 16: $section = "articleagency"; break; case 17: $section = "turismb"; break; case 18: $section = "profile"; break; case 20: $section = "university"; break; } $file1 = new fFile("../uploads/{$section}/" . $resource->prepareUrl()); $file1->delete(); $file1 = new fFile("../uploads/{$section}/thumbs/" . $resource->prepareUrl()); $file1->delete(); } $resource->delete(); exit("1"); break; case "load_categories": require_once LOAD . 'load_categories.php'; break; case "load_giro": require_once LOAD . 'load_giro.php'; break; case "updateStatus": require_once LOAD . 'updateStatus.php'; break; case "load_girot":
/** * Validates a $_FILES array against the upload configuration * * @param array $file_array The $_FILES array for a single file * @return string The validation error message */ private function validateField($file_array) { if (empty($file_array['name'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if ($file_array['error'] == UPLOAD_ERR_FORM_SIZE || $file_array['error'] == UPLOAD_ERR_INI_SIZE) { $max_size = !empty($_POST['MAX_FILE_SIZE']) ? $_POST['MAX_FILE_SIZE'] : ini_get('upload_max_filesize'); $max_size = !is_numeric($max_size) ? fFilesystem::convertToBytes($max_size) : $max_size; return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($max_size)); } if ($this->max_size && $file_array['size'] > $this->max_size) { return self::compose('The file uploaded is over the limit of %s', fFilesystem::formatFilesize($this->max_size)); } if (empty($file_array['tmp_name']) || empty($file_array['size'])) { if ($this->required) { return self::compose('Please upload a file'); } return NULL; } if (!empty($this->mime_types) && file_exists($file_array['tmp_name'])) { $contents = file_get_contents($file_array['tmp_name'], FALSE, NULL, 0, 4096); if (!in_array(fFile::determineMimeType($file_array['name'], $contents), $this->mime_types)) { return self::compose($this->mime_type_message); } } if (!$this->allow_php) { $file_info = fFilesystem::getPathInfo($file_array['name']); if (in_array(strtolower($file_info['extension']), array('php', 'php4', 'php5'))) { return self::compose('The file uploaded is a PHP file, but those are not permitted'); } } if (!$this->allow_dot_files) { if (substr($file_array['name'], 0, 1) == '.') { return self::compose('The name of the uploaded file may not being with a .'); } } }
$jsonOutput .= '], "itemsPerPage": ' . $totalRecords . ', "startIndex": 0, "totalResults": ' . $totalRecords . '}'; //dont write files unless there were rows returned if ($jsonCount > 0) { echo DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json'; //write JSON try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json'); $file->write($jsonOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.json', $jsonOutput); } catch (fEnvironmentException $e) { } //write KML try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.kml'); $file->write($kmlOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.kml', $kmlOutput); } catch (fEnvironmentException $e) { } //write CSV try { $file = new fFile(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.csv'); $file->write($csvOutput); } catch (fExpectedException $e) { $new_file = fFile::create(DOC_ROOT . '/feeds/driveCache/drive' . $driveId . '.csv', $csvOutput); } catch (fEnvironmentException $e) { } } $db = null; //echo $output;
/** * Creates an object to represent an image on the filesystem * * @throws fValidationException When no image was specified, when the image does not exist or when the path specified is not an image * * @param string $file_path The path to the image * @param boolean $skip_checks If file checks should be skipped, which improves performance, but may cause undefined behavior - only skip these if they are duplicated elsewhere * @return fImage */ public function __construct($file_path, $skip_checks = FALSE) { self::determineProcessor(); parent::__construct($file_path, $skip_checks); if (!self::isImageCompatible($file_path)) { $valid_image_types = array('GIF', 'JPG', 'PNG'); if (self::$processor == 'imagemagick') { $valid_image_types[] = 'TIF'; } throw new fValidationException('The image specified, %1$s, is not a valid %2$s file', $file_path, fGrammar::joinArray($valid_image_types, 'or')); } }
<?php include dirname(__FILE__) . '/config.php'; $lang = fRequest::get('lang', "string?"); if ($lang != NULL) { fCookie::set('safecast_lang', $lang, '+1 year', '/', '.safecast.org'); } if ($lang == NULL) { $lang = fCookie::get('safecast_lang', 'en'); } // get language file $lang_file = DOC_ROOT . '/lang/' . $lang . '.json'; if (!file_exists($lang_file)) { $lang_file = DOC_ROOT . '/lang/en.json'; } $file = new fFile($lang_file); $lang_file_content = $file->read(); //print_r("file content: ".$lang_file_content); $translations = json_decode($lang_file_content); //print_r('file: '.$lang_file); //print_r('************'.$translations.'^^^^^^^^^^^^^^^'); //die; $tmpl = new fTemplating(DOC_ROOT . '/views/'); $tmpl->set('header', 'header.php'); $tmpl->set('header_headless', 'header_headless.php'); $tmpl->set('info_header', 'info_header.php'); $tmpl->set('footer', 'footer.php'); $tmpl->set('lang', $lang); require_once DOC_ROOT . '/Browser.php'; $mobile = mobile_device_detect(true, false, true, true, true, true, true, false, false); if ($mobile) {
<?php /** * Prepares classes and database for tests. */ // Some basics date_default_timezone_set('Europe/Copenhagen'); define("FIXTURES_ROOT", dirname(__FILE__) . '/fixtures/'); include dirname(__FILE__) . '/flourish/fLoader.php'; fLoader::best(); // Include fFixture include dirname(__FILE__) . '/../fFixture.php'; include dirname(__FILE__) . '/../fFixtureSeed.php'; // Emtpy database $db = new fDatabase('sqlite', dirname(__FILE__) . '/test.db'); $db_setup_file = new fFile(dirname(__FILE__) . '/bootstrap.sql'); define("RESET_DATABASE_SQL", $db_setup_file->read()); $db->execute(RESET_DATABASE_SQL); // Setup ORM fORMDatabase::attach($db); // Pretend implementations of fActiveRecord class Category extends fActiveRecord { } class Product extends fActiveRecord { } class Shop extends fActiveRecord { } class User extends fActiveRecord