本文整理汇总了PHP中SpoonFile::getContent方法的典型用法代码示例。如果您正苦于以下问题:PHP SpoonFile::getContent方法的具体用法?PHP SpoonFile::getContent怎么用?PHP SpoonFile::getContent使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SpoonFile
的用法示例。
在下文中一共展示了SpoonFile::getContent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processFile
/**
* Process the content of the file.
*
* @param string $file The file to process.
* @return boolean|array
*/
private function processFile($file)
{
// if the files doesn't exists we can stop here and just return an empty string
if (!SpoonFile::exists($file)) {
return array();
}
// fetch content from file
$content = SpoonFile::getContent($file);
$json = @json_decode($content, true);
// skip invalid JSON
if ($json === false || $json === null) {
return array();
}
$return = array();
// loop templates
foreach ($json as $template) {
// skip items without a title
if (!isset($template['title'])) {
continue;
}
if (isset($template['file'])) {
if (SpoonFile::exists(PATH_WWW . $template['file'])) {
$template['html'] = SpoonFile::getContent(PATH_WWW . $template['file']);
}
}
// skip items without HTML
if (!isset($template['html'])) {
continue;
}
$image = '';
if (isset($template['image'])) {
// we have to remove the first slash, because that is set in the wrapper. Otherwise the images don't work
$image = ltrim($template['image'], '/');
}
$temp['title'] = $template['title'];
$temp['description'] = isset($template['description']) ? $template['description'] : '';
$temp['image'] = $image;
$temp['html'] = $template['html'];
// add the template
$return[] = $temp;
}
return $return;
}
示例2: downloadCSV
/**
* Sets the headers so we may download the CSV file in question
*
* @param string $path The full path to the CSV file you wish to download.
* @return array
*/
private function downloadCSV($path)
{
// check if the file exists
if (!SpoonFile::exists($path)) {
throw new SpoonFileException('The file ' . $path . ' doesn\'t exist.');
}
// fetch the filename from the path string
$explodedFilename = explode('/', $path);
$filename = end($explodedFilename);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
$headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// get the file contents
$content = SpoonFile::getContent($path);
// output the file contents
echo $content;
exit;
}
示例3: correct
public static function correct(&$frm)
{
if ($frm->getField('photo')->isFilled()) {
$imagename = uniqid();
SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('photo')->getTempFileName()), 9));
//create Thumbnail
$frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130);
SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), gzcompress(SpoonFile::getContent(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension()), 9));
}
if ($frm->getField('attachment')->isFilled()) {
$attachname = uniqid();
SpoonFile::setContent(ATTACH_PATH . '/' . $attachname . '.' . $frm->getField('attachment')->getExtension(), gzcompress(SpoonFile::getContent($frm->getField('attachment')->getTempFileName()), 9));
}
$company = "";
for ($i = 1; $i < 6; $i++) {
$company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue() . ', ';
}
$company = substr($company, 0, -2);
//company field names
$values = array();
for ($i = 1; $i < 6; $i++) {
$values = array_merge($values, array('company' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'shareholder' . $i, 'registeraddr' . $i, 'businessaddr' . $i));
}
$values = array_merge($frm->getValues(array_merge(array('form', 'submit', '_utf8'), $values)), $frm->getField('photo')->isFilled() ? array('photo' => $imagename, 'photoext' => $frm->getField('photo')->getExtension()) : array(), $frm->getField('attachment')->isFilled() ? array('attachment' => $attachname, 'attachext' => $frm->getField('attachment')->getExtension()) : array(), array("company" => $company, 'lastupdate' => time()));
foreach ($values as $key => $value) {
if ($value == NULL) {
unset($values[$key]);
}
}
return $values;
}
示例4: getTemplate
/**
* Get the template record
*
* @param string $language The language.
* @param string $name The name of the template.
* @return array
*/
public static function getTemplate($language, $name)
{
// set the path to the template folders for this language
$path = BACKEND_MODULE_PATH . '/templates/' . $language;
// load all templates in the 'templates' folder for this language
$templates = SpoonDirectory::getList($path, false, array('.svn'));
// stop here if no directories were found
if (empty($templates) || !in_array($name, $templates)) {
return array();
}
// load all templates in the 'templates' folder for this language
if (!SpoonFile::exists($path . '/' . $name . '/template.tpl')) {
throw new SpoonException('The template folder "' . $name . '" exists, but no template.tpl file was found. Please create one.');
}
if (!SpoonFile::exists($path . '/' . $name . '/css/screen.css')) {
throw new SpoonException('The template folder "' . $name . '" exists, but no screen.css file was found. Please create one in a subfolder "css".');
}
// set template data
$record = array();
$record['name'] = $name;
$record['language'] = $language;
$record['label'] = BL::lbl('Template' . SpoonFilter::toCamelCase($record, array('-', '_')));
$record['path_content'] = $path . '/' . $name . '/template.tpl';
$record['path_css'] = $path . '/' . $name . '/css/screen.css';
$record['url_css'] = SITE_URL . '/backend/modules/mailmotor/templates/' . $language . '/' . $name . '/css/screen.css';
// check if the template file actually exists
if (SpoonFile::exists($record['path_content'])) {
$record['content'] = SpoonFile::getContent($record['path_content']);
}
if (SpoonFile::exists($record['path_css'])) {
$record['css'] = SpoonFile::getContent($record['path_css']);
}
return $record;
}
示例5: getNonExistingFrontendLocale
/**
* Get the locale that is used in the frontend but doesn't exists.
*
* @param string $language The language to check.
* @return array
*/
public static function getNonExistingFrontendLocale($language)
{
// get files to process
$tree = self::getTree(FRONTEND_PATH);
$used = array();
// loop files
foreach ($tree as $file) {
// grab content
$content = SpoonFile::getContent($file);
// process the file based on extension
switch (SpoonFile::getExtension($file)) {
// javascript file
case 'js':
$matches = array();
// get matches
preg_match_all('/\\{\\$(act|err|lbl|msg)(.*)(\\|.*)?\\}/iU', $content, $matches);
// any matches?
if (isset($matches[2])) {
// loop matches
foreach ($matches[2] as $key => $match) {
// set type
$type = $matches[1][$key];
// init if needed
if (!isset($used[$match])) {
$used[$type][$match] = array('files' => array());
}
// add file
if (!in_array($file, $used[$type][$match]['files'])) {
$used[$type][$match]['files'][] = $file;
}
}
}
break;
// PHP file
// PHP file
case 'php':
$matches = array();
// get matches
preg_match_all('/(FrontendLanguage|FL)::(get(Action|Label|Error|Message)|act|lbl|err|msg)\\(\'(.*)\'\\)/iU', $content, $matches);
// any matches?
if (!empty($matches[4])) {
// loop matches
foreach ($matches[4] as $key => $match) {
$type = 'lbl';
if ($matches[3][$key] == 'Action') {
$type = 'act';
}
if ($matches[2][$key] == 'act') {
$type = 'act';
}
if ($matches[3][$key] == 'Error') {
$type = 'err';
}
if ($matches[2][$key] == 'err') {
$type = 'err';
}
if ($matches[3][$key] == 'Message') {
$type = 'msg';
}
if ($matches[2][$key] == 'msg') {
$type = 'msg';
}
// init if needed
if (!isset($used[$type][$match])) {
$used[$type][$match] = array('files' => array());
}
// add file
if (!in_array($file, $used[$type][$match]['files'])) {
$used[$type][$match]['files'][] = $file;
}
}
}
break;
// template file
// template file
case 'tpl':
$matches = array();
// get matches
preg_match_all('/\\{\\$(act|err|lbl|msg)([a-z-_]*)(\\|.*)?\\}/iU', $content, $matches);
// any matches?
if (isset($matches[2])) {
// loop matches
foreach ($matches[2] as $key => $match) {
// set type
$type = $matches[1][$key];
// init if needed
if (!isset($used[$type][$match])) {
$used[$type][$match] = array('files' => array());
}
// add file
if (!in_array($file, $used[$type][$match]['files'])) {
$used[$type][$match]['files'][] = $file;
}
}
//.........这里部分代码省略.........
示例6: parse
/**
* Parse the template.
*/
protected function parse()
{
// not yet parsed
if (!$this->parsed) {
// while developing, you might want to know about the undefined indexes
$errorReporting = $this->debug ? 'E_ALL | E_STRICT' : 0;
$displayErrors = $this->debug ? 'On' : 'Off';
// add to the list of parsed files
$this->files[] = $this->getCompileName($this->template);
// map modifiers
$this->modifiers = SpoonTemplateModifiers::getModifiers();
// set content
$this->content = SpoonFile::getContent($this->template);
// strip php code
$this->content = $this->stripCode($this->content);
// strip comments
$this->content = $this->stripComments($this->content);
// prepare iterations
$this->content = $this->prepareIterations($this->content);
// parse iterations
$this->content = $this->parseIterations($this->content);
// parse variables
$this->content = $this->parseVariables($this->content);
// parse options
$this->content = $this->parseOptions($this->content);
// includes
$this->content = $this->parseIncludes($this->content);
// parse cache tags
$this->content = $this->parseCache($this->content);
// parse forms
$this->content = $this->parseForms($this->content);
// replace variables
$this->content = $this->replaceVariables($this->content);
// add error_reporting setting
$this->content = '<?php error_reporting(' . $errorReporting . '); ini_set(\'display_errors\', \'' . $displayErrors . '\'); ?>' . "\n" . $this->content;
// parsed
$this->parsed = true;
}
}
示例7: execute
public function execute()
{
parent::execute();
$txtText = \SpoonFile::getContent(BACKEND_MODULE_PATH . "/meubelwinkels.txt");
$arrText = explode("\n", $txtText);
$strShop = "";
$arrShops = array();
$arrShopsFinal = array();
$arrElements = array("company", "phone", "zipcode", "city", "address", "contact", "email", "website", "fax", "vat", "assort", "m�", "open", "gesloten", "visit");
$arrElementsDash = array("assort", "m�", "open", "gesloten", "visit");
foreach ($arrText as $line) {
//--Check if the line is only a zipcode or pagenumbers (1000 or 52 53)
if (preg_match("/^\\d+\$/", $line) || preg_match("/^[0-9 ]+\$/", $line)) {
continue;
}
//--Search for T : in the line (this is the first line of the address)
if (strpos($line, "T :") !== false) {
//--If line is not empty, add it to the array
if (!empty($strShop)) {
$arrShops[] = $strShop;
}
$strShop = "";
}
//--Add the line + add a marker [LINE]
$strShop .= $line . "[LINE]";
}
//--Loop all the shops
foreach ($arrShops as $shop) {
//--Explode the shop with [LINE]
$arrShop = explode("[LINE]", $shop);
$arrShopFinal = array();
//--Get the phone number and name of the shop
$strPosTelephone = strpos($arrShop[0], "T :");
//--Create array
$arrShopFinal["company"] = ucwords(mb_strtolower(substr($arrShop[0], 0, $strPosTelephone)));
$arrShopFinal["phone"] = trim(str_replace("T :", "", substr($arrShop[0], $strPosTelephone)));
//--Get the address
$strAddress = ucwords(mb_strtolower($arrShop[1]));
//--Get position of the space
$strPosSpaceZipcode = strpos($strAddress, " ");
//--Add the zipcode
$arrShopFinal["zipcode"] = substr($strAddress, 0, $strPosSpaceZipcode);
//--Alter the address-string
$strAddress = substr($strAddress, $strPosSpaceZipcode);
//--Search comma
$strPosCommaCity = strpos($strAddress, ",");
//--Add the city
$arrShopFinal["city"] = substr($strAddress, 0, $strPosCommaCity);
//--Add the address
$arrShopFinal["address"] = trim(substr($strAddress, $strPosCommaCity + 1));
//--Unset first and second item
unset($arrShop[0]);
unset($arrShop[1]);
//--Loop the shop
foreach ($arrShop as $key => $row) {
//--Get the contact
if (!isset($arrShopFinal["contact"]) && strpos($row, "contact:") !== false) {
$arrShopFinal["contact"] = ucwords(mb_strtolower(trim(substr($row, 8))));
}
//--Find the e-mailaddress in the string
if (!isset($arrShopFinal["email"])) {
preg_match("/[_a-z0-9-]+(\\.[_a-z0-9-]+)*@[a-z0-9-]+(\\.[a-z0-9-]+)*(\\.[a-z]{2,3})/i", $row, $matches);
if (!empty($matches)) {
$arrShopFinal["email"] = $matches[0];
}
}
//--Find the website address
if (!isset($arrShopFinal["website"])) {
preg_match("/www\\.[a-zA-Z0-9-]+\\.[a-z]{2,7}/i", $row, $matches);
if (!empty($matches)) {
$arrShopFinal["website"] = $matches[0];
}
}
//--Find the fax
if (!isset($arrShopFinal["fax"])) {
preg_match("/F: ([\\s0-9]+)/i", $row, $matches);
if (!empty($matches)) {
$arrShopFinal["fax"] = $matches[1];
}
}
//--Find the VAT
if (!isset($arrShopFinal["btw"])) {
preg_match("/BTW : ([A-Z]{2}[\\s]*[0-9-\\.\\s]+)/i", $row, $matches);
if (!empty($matches)) {
$arrShopFinal["vat"] = $matches[1];
}
}
//--Check if the dash is for a numeric value (not - assort:)
preg_match("/([0-9]{1}[\\s]-[\\s][0-9]{1})/i", $row, $matches);
if (!empty($matches)) {
foreach ($matches as $match) {
$strMatchReplace = str_replace(" - ", "-", $match);
$row = str_replace($match, $strMatchReplace, $row);
}
}
//--Split the text with " - ";
$arrDashes = explode(" - ", $row);
//--Check if there are elements
if (!empty($arrDashes)) {
//--Loop the different pieces
//.........这里部分代码省略.........
示例8: setBusyFile
/**
* Set the busy file
*
* @return void
*/
protected function setBusyFile()
{
// do not set busy file in debug mode
if (SPOON_DEBUG) {
return;
}
// build path
$path = BACKEND_CACHE_PATH . '/cronjobs/' . $this->getId() . '.busy';
// init var
$isBusy = false;
// does the busy file already exists.
if (SpoonFile::exists($path)) {
$isBusy = true;
// grab counter
$counter = (int) SpoonFile::getContent($path);
// check the counter
if ($counter > 9) {
// build class name
$className = 'Backend' . SpoonFilter::toCamelCase($this->getModule() . '_cronjob_' . $this->getAction());
// notify user
throw new BackendException('Cronjob (' . $className . ') is still busy after 10 runs, check it out!');
}
} else {
$counter = 0;
}
// increment counter
$counter++;
// store content
SpoonFile::setContent($path, $counter, true, false);
// if the cronjob is busy we should NOT proceed
if ($isBusy) {
exit;
}
}
示例9: startProcessingHooks
/**
* Start processing the hooks
*/
public static function startProcessingHooks()
{
// is the queue already running?
if (SpoonFile::exists(FRONTEND_CACHE_PATH . '/hooks/pid')) {
// get the pid
$pid = trim(SpoonFile::getContent(FRONTEND_CACHE_PATH . '/hooks/pid'));
// running on windows?
if (strtolower(substr(php_uname('s'), 0, 3)) == 'win') {
// get output
$output = @shell_exec('tasklist.exe /FO LIST /FI "PID eq ' . $pid . '"');
// validate output
if ($output == '' || $output === false) {
// delete the pid file
SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid');
} else {
return true;
}
} elseif (strtolower(substr(php_uname('s'), 0, 6)) == 'darwin') {
// get output
$output = @posix_getsid($pid);
// validate output
if ($output === false) {
// delete the pid file
SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid');
} else {
return true;
}
} else {
// check if the process is still running, by checking the proc folder
if (!SpoonFile::exists('/proc/' . $pid)) {
// delete the pid file
SpoonFile::delete(FRONTEND_CACHE_PATH . '/hooks/pid');
} else {
return true;
}
}
}
// init var
$parts = parse_url(SITE_URL);
$errNo = '';
$errStr = '';
$defaultPort = 80;
if ($parts['scheme'] == 'https') {
$defaultPort = 433;
}
// open the socket
$socket = fsockopen($parts['host'], isset($parts['port']) ? $parts['port'] : $defaultPort, $errNo, $errStr, 1);
// build the request
$request = 'GET /backend/cronjob.php?module=core&action=process_queued_hooks HTTP/1.1' . "\r\n";
$request .= 'Host: ' . $parts['host'] . "\r\n";
$request .= 'Content-Length: 0' . "\r\n\r\n";
$request .= 'Connection: Close' . "\r\n\r\n";
// send the request
fwrite($socket, $request);
// close the socket
fclose($socket);
// return
return true;
}
示例10: addAttachment
/**
* Adds an attachment to the headers.
*
* @param string $filename The path to (including the filename for) the attachment.
* @param string[optional] $newName The new name of the attachment.
* @param string[optional] $disposition The disposition of the attachment. Can be 'attachment' or 'inline'.
* @param string[optional] $encoding The attachment encoding (only base64 for now).
*/
public function addAttachment($filename, $newName = null, $disposition = 'attachment', $encoding = 'base64')
{
// check input
if (!SpoonFile::exists($filename)) {
throw new SpoonEmailException('File not found.');
}
// no name was found in the input
if (empty($newName)) {
// use the source file's base name
$newName = basename($filename);
}
// store file extension
$extension = SpoonFile::getExtension($newName);
// store attachment disposition
$disposition = SpoonFilter::getValue($disposition, array('attachment', 'inline'), 'attachment');
// store type according to disposition
if ($disposition === 'attachment') {
$extension = 'default';
}
// store file info
$this->attachments[] = array('file' => $filename, 'name' => $newName, 'encoding' => $encoding, 'type' => $this->getAttachmentContentType($extension), 'disposition' => $disposition, 'data' => chunk_split(base64_encode(SpoonFile::getContent($filename))));
}
示例11: insertPage
//.........这里部分代码省略.........
$revision['allow_delete'] = 'Y';
}
if (!isset($revision['sequence'])) {
$revision['sequence'] = (int) $this->getDB()->getVar('SELECT MAX(sequence) + 1 FROM pages WHERE language = ? AND parent_id = ? AND type = ?', array($revision['language'], $revision['parent_id'], $revision['type']));
}
if (!isset($revision['extra_ids'])) {
$revision['extra_ids'] = null;
}
if (!isset($revision['has_extra'])) {
$revision['has_extra'] = $revision['extra_ids'] ? 'Y' : 'N';
}
// meta needs to be inserted
if (!isset($revision['meta_id'])) {
// build meta
if (!isset($meta['keywords'])) {
$meta['keywords'] = $revision['title'];
}
if (!isset($meta['keywords_overwrite'])) {
$meta['keywords_overwrite'] = false;
}
if (!isset($meta['description'])) {
$meta['description'] = $revision['title'];
}
if (!isset($meta['description_overwrite'])) {
$meta['description_overwrite'] = false;
}
if (!isset($meta['title'])) {
$meta['title'] = $revision['title'];
}
if (!isset($meta['title_overwrite'])) {
$meta['title_overwrite'] = false;
}
if (!isset($meta['url'])) {
$meta['url'] = SpoonFilter::urlise($revision['title']);
}
if (!isset($meta['url_overwrite'])) {
$meta['url_overwrite'] = false;
}
if (!isset($meta['custom'])) {
$meta['custom'] = null;
}
if (!isset($meta['data'])) {
$meta['data'] = null;
}
// insert meta
$revision['meta_id'] = $this->insertMeta($meta['keywords'], $meta['description'], $meta['title'], $meta['url'], $meta['keywords_overwrite'], $meta['description_overwrite'], $meta['title_overwrite'], $meta['url_overwrite'], $meta['custom'], $meta['data']);
}
// insert page
$revision['revision_id'] = $this->getDB()->insert('pages', $revision);
// get number of blocks to insert
$numBlocks = $this->getDB()->getVar('SELECT MAX(num_blocks) FROM pages_templates WHERE theme = ? AND active = ?', array($this->getSetting('core', 'theme'), 'Y'));
// get arguments (this function has a variable length argument list, to allow multiple blocks to be added)
$blocks = array();
// loop blocks
for ($i = 0; $i < $numBlocks; $i++) {
// get block
$block = @func_get_arg($i + 2);
if ($block === false) {
$block = array();
} else {
$block = (array) $block;
}
// build block
if (!isset($block['id'])) {
$block['id'] = $i;
}
if (!isset($block['revision_id'])) {
$block['revision_id'] = $revision['revision_id'];
}
if (!isset($block['status'])) {
$block['status'] = 'active';
}
if (!isset($block['created_on'])) {
$block['created_on'] = gmdate('Y-m-d H:i:s');
}
if (!isset($block['edited_on'])) {
$block['edited_on'] = gmdate('Y-m-d H:i:s');
}
if (!isset($block['extra_id'])) {
$block['extra_id'] = null;
} else {
$revision['extra_ids'] = trim($revision['extra_ids'] . ',' . $block['extra_id'], ',');
}
if (!isset($block['html'])) {
$block['html'] = '';
} elseif (SpoonFile::exists($block['html'])) {
$block['html'] = SpoonFile::getContent($block['html']);
}
// insert block
$this->getDB()->insert('pages_blocks', $block);
}
// blocks added
if ($revision['extra_ids'] && $revision['has_extra'] == 'N') {
// update page
$revision['has_extra'] = 'Y';
$this->getDB()->update('pages', $revision, 'revision_id = ?', array($revision['revision_id']));
}
// return page id
return $revision['id'];
}
示例12: uniqid
}
if (!in_array($frm->getField('blood')->getValue(), array('', 'O+', 'A+', 'B+', 'AB+', 'O-', 'A-', 'B-', 'AB-'))) {
$frm->getField('blood')->setError('Please choose from the list only!');
}
if ($frm->getField('height')->isFilled()) {
$frm->getField('height')->isNumeric('Digits only please! eg: 180');
//it needs to be numeric!
}
if ($frm->getField('weight')->isFilled()) {
$frm->getField('weight')->isNumeric('Digits only please! eg: 80');
//it needs to be numeric!
}
if ($frm->isCorrect()) {
if ($frm->getField('photo')->isFilled()) {
$imagename = uniqid();
SpoonFile::setContent(IMAGE_PATH . '/' . $imagename . '.' . $frm->getField('photo')->getExtension(), SpoonFile::getContent($frm->getField('photo')->getTempFileName()));
//create Thumbnail
$frm->getField('photo')->createThumbnail(IMAGE_PATH . '/' . $imagename . '_thumbnail.' . $frm->getField('photo')->getExtension(), 130, 130);
}
$company = "";
for ($i = 1; $i < 6; $i++) {
$company .= $frm->getField('company' . $i)->getValue() . ', ' . $frm->getField('registerno' . $i)->getValue() . ', ' . $frm->getField('companyno' . $i)->getValue() . ', ' . $frm->getField('companyemail' . $i)->getValue() . ', ' . $frm->getField('shareholder' . $i)->getValue() . ', ' . $frm->getField('registeraddr' . $i)->getValue() . ', ' . $frm->getField('businessaddr' . $i)->getValue();
if ($i < 6) {
$company .= ', ';
}
}
//get values from form
$values = array();
for ($i = 1; $i < 6; $i++) {
$values = array_merge($values, array('company' . $i, 'shareholder' . $i, 'registerno' . $i, 'companyno' . $i, 'companyemail' . $i, 'registeraddr' . $i, 'businessaddr' . $i));
}
示例13: minifyJavascript
/**
* Minify a javascript-file
*
* @return string
* @param string $file The file to be minified.
*/
private function minifyJavascript($file)
{
// create unique filename
$fileName = md5($file) . '.js';
$finalURL = FRONTEND_CACHE_URL . '/minified_js/' . $fileName;
$finalPath = FRONTEND_CACHE_PATH . '/minified_js/' . $fileName;
// file already exists (if SPOON_DEBUG is true, we should reminify every time
if (SpoonFile::exists($finalPath) && !SPOON_DEBUG) {
return $finalURL;
}
// grab content
$content = SpoonFile::getContent(PATH_WWW . $file);
// remove comments
$content = preg_replace('/\\/\\*(.*)\\*\\//iUs', '', $content);
$content = preg_replace('/([\\t\\w]{1,})\\/\\/.*/i', '', $content);
// remove tabs
$content = preg_replace('/\\t/i', ' ', $content);
// remove faulty newlines
$content = preg_replace('/\\r/iU', '', $content);
// remove empty lines
$content = preg_replace('/(^[\\r\\n]*|[\\r\\n]+)[\\s\\t]*[\\r\\n]+/', "\n", $content);
// store
SpoonFile::setContent($finalPath, $content);
// return
return $finalURL;
}
示例14: fileToArray
/**
* Converts a CSV file to an array
*
* @return array
* @param array $path The full path to the CSV-file you want to extract an array from.
* @param array[optional] $columns The column names you want to use.
* @param array[optional] $excludeColumns The columns to exclude.
* @param string[optional] $delimiter The field delimiter of the CSV.
* @param string[optional] $enclosure The enclosure character of the CSV.
*/
public static function fileToArray($path, array $columns = array(), array $excludeColumns = null, $delimiter = ',', $enclosure = '"')
{
// reset variables
$path = (string) $path;
// validation
if (!SpoonFile::exists($path)) {
throw new SpoonFileException($path . ' doesn\'t exists.');
}
// get delimiter and enclosure from the contents
if (!$delimiter || !$enclosure) {
$autoDetect = self::getDelimiterAndEnclosure(SpoonFile::getContent($path), $delimiter, $enclosure);
}
if (!$delimiter) {
$delimiter = $autoDetect[0];
}
if (!$enclosure) {
$enclosure = $autoDetect[1];
}
// automagicaly detect line endings
@ini_set('auto_detect_line_endings', 1);
// init var
$rows = array();
// open file
$handle = @fopen($path, 'r');
// loop lines and store the rows
while (($row = @fgetcsv($handle, 0, $delimiter == '' ? ',' : $delimiter, $enclosure == '' ? '"' : $enclosure)) !== false) {
$rows[] = $row;
}
// close file
@fclose($handle);
// no lines
if (count($rows) == 0) {
return false;
}
// no column names are set
if (empty($columns)) {
$columns = array_values($rows[0]);
}
// remove the first row
array_shift($rows);
// loop the rows
foreach ($rows as $rowId => &$row) {
// the keys of this row
$keys = array_keys($row);
// some columns are excluded
if (!empty($excludeColumns)) {
// unset the keys related to the excluded columns
foreach ($excludeColumns as $columnKey => $column) {
unset($keys[array_search($columnKey, $columns)], $row[$columnKey]);
}
}
// loop the keys
foreach ($keys as $columnId) {
// add the field to this row
$row[$columns[$columnId]] = $row[$columnId];
// remove the original field from this row
unset($row[$columnId]);
}
}
// return the array
return $rows;
}
示例15: addAttachment
/**
* Add an attachment
*
* @return void
* @param string[optional] $url A url to the file.
* @param string[optional] $filePath The Path to the file if you want to include it in the ical file.
* @param string[optional] $fmType Reccomended when using filePAth, the media type of file.
*/
public function addAttachment($url = null, $filePath = null, $fmtType = null)
{
// validate
if ($url == null && $filePath == null) {
throw new SpoonIcalException('Please provide either a file or url');
}
// init var
$attachment = array();
if ($url == null) {
$attachment['ENCODING'] = "BASE64";
$attachment['VALUE'] = "BINARY";
if ($fmtType !== null) {
$attachment['FMTTYPE'] = $fmtType;
}
$attachment['content'] = base64_encode(SpoonFile::getContent($filePath));
} else {
$attachment['VALUE'] = 'URI';
$attachment['content'] = $url;
}
// init the array if empty
if ($this->attach == null) {
$this->attach = array();
}
$attach[] = $attachment;
}