本文整理汇总了PHP中SpoonHTTP类的典型用法代码示例。如果您正苦于以下问题:PHP SpoonHTTP类的具体用法?PHP SpoonHTTP怎么用?PHP SpoonHTTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SpoonHTTP类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parse
/**
* Parse the correct messages into the template
*/
protected function parse()
{
parent::parse();
// grab the error-type from the parameters
$errorType = $this->getParameter('type');
// set correct headers
switch ($errorType) {
case 'module-not-allowed':
case 'action-not-allowed':
SpoonHTTP::setHeadersByCode(403);
break;
case 'not-found':
SpoonHTTP::setHeadersByCode(404);
break;
}
// querystring provided?
if ($this->getParameter('querystring') !== null) {
// split into file and parameters
$chunks = explode('?', $this->getParameter('querystring'));
// get extension
$extension = SpoonFile::getExtension($chunks[0]);
// if the file has an extension it is a non-existing-file
if ($extension != '' && $extension != $chunks[0]) {
// set correct headers
SpoonHTTP::setHeadersByCode(404);
// give a nice error, so we can detect which file is missing
echo 'Requested file (' . htmlspecialchars($this->getParameter('querystring')) . ') not found.';
// stop script execution
exit;
}
}
// assign the correct message into the template
$this->tpl->assign('message', BL::err(SpoonFilter::toCamelCase(htmlspecialchars($errorType), '-')));
}
示例2: validateForm
/**
* Validate the form
*/
protected function validateForm()
{
if ($this->frm->isSubmitted()) {
$this->frm->cleanupFields();
$fields = $this->frm->getFields();
$fields['email']->isFilled(BL::err('FieldIsRequired'));
if ($this->frm->isCorrect()) {
//--Get the mail
$mailing = BackendMailengineModel::get($this->id);
//--Get the template
$template = BackendMailengineModel::getTemplate($mailing['template_id']);
//--Create basic mail
$text = BackendMailengineModel::createMail($mailing, $template);
$mailing['from_email'] = $template['from_email'];
$mailing['from_name'] = html_entity_decode($template['from_name']);
$mailing['reply_email'] = $template['reply_email'];
$mailing['reply_name'] = html_entity_decode($template['reply_name']);
$emails = explode(',', $fields['email']->getValue());
if (!empty($emails)) {
foreach ($emails as $email) {
$email = trim($email);
if (\SpoonFilter::isEmail($email)) {
//--Send test mailing
BackendMailengineModel::sendMail(html_entity_decode($mailing['subject']), $text, $email, 'Test Recepient', $mailing);
}
}
}
//--Redirect
\SpoonHTTP::redirect(BackendModel::createURLForAction('index', $this->module) . "&id=" . $this->id . "&report=TestEmailSend");
}
}
$this->frm->parse($this->tpl);
}
示例3: outputCSV
/**
* Output a CSV-file as a download
*
* @param string $filename The name of the file.
* @param array $array The array to convert.
* @param array[optional] $columns The column names you want to use.
* @param array[optional] $excludeColumns The columns you want to exclude.
*/
public static function outputCSV($filename, array $array, array $columns = null, array $excludeColumns = null)
{
// get settings
$splitCharacter = BackendAuthentication::getUser()->getSetting('csv_split_character');
$lineEnding = BackendAuthentication::getUser()->getSetting('csv_line_ending');
// reformat
if ($lineEnding == '\\n') {
$lineEnding = "\n";
}
if ($lineEnding == '\\r\\n') {
$lineEnding = "\r\n";
}
// convert into CSV
$csv = SpoonFileCSV::arrayToString($array, $columns, $excludeColumns, $splitCharacter, '"', $lineEnding);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=' . SPOON_CHARSET;
$headers[] = 'Content-Disposition: attachment; filename="' . $filename;
$headers[] = 'Content-Length: ' . strlen($csv);
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// ouput the CSV
echo $csv;
exit;
}
示例4: execute
/**
* Execute the action
*/
public function execute()
{
// call parent, this will probably add some general CSS/JS or other required files
parent::execute();
// init vars
$templates = array();
$theme = BackendModel::getModuleSetting('core', 'theme');
$files[] = BACKEND_PATH . '/core/layout/editor_templates/templates.js';
$themePath = FRONTEND_PATH . '/themes/' . $theme . '/core/layout/editor_templates/templates.js';
if (SpoonFile::exists($themePath)) {
$files[] = $themePath;
}
// loop all files
foreach ($files as $file) {
// process file
$templates = array_merge($templates, $this->processFile($file));
}
// set headers
SpoonHTTP::setHeaders('Content-type: text/javascript');
// output the templates
if (!empty($templates)) {
echo 'CKEDITOR.addTemplates(\'default\', { imagesPath: \'/\', templates:' . "\n";
echo json_encode($templates) . "\n";
echo '});';
}
exit;
}
示例5: parse
/**
* Parse the ical and output into the browser.
*
* @param bool[optional] $headers Should the headers be set? (Use false if you're debugging).
*/
public function parse($headers = true)
{
// set headers
if ((bool) $headers) {
SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . SpoonFilter::urlise($this->getTitle()) . '.ics');
}
// call the parent
parent::parse($headers);
}
示例6: parse
/**
* Parse the iCal and output into the browser.
*
* @param bool $headers Should the headers be set? (Use false if you're debugging).
*/
public function parse($headers = true)
{
// set headers
if ((bool) $headers) {
\SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . CommonUri::getUrl($this->getTitle()) . '.ics');
}
// call the parent
parent::parse($headers);
}
示例7: parse
/**
* Export the templates as XML.
*/
protected function parse()
{
$xml = Model::createTemplateXmlForExport($this->selectedTheme);
$filename = 'templates_' . BackendModel::getUTCDate('d-m-Y') . '.xml';
$headers = array('Content-type: text/xml', 'Content-disposition: attachment; filename="' . $filename . '"');
\SpoonHTTP::setHeaders($headers);
echo $xml;
exit;
}
示例8: display
/**
* Output the template into the browser
* Will also assign the interfacelabels and all user-defined constants.
*
* @param string $template The path for the template.
* @param bool[optional] $customHeaders Are there custom headers set?
*/
public function display($template, $customHeaders = false)
{
$this->parseConstants();
$this->parseAuthenticatedUser();
$this->parseDebug();
$this->parseLabels();
$this->parseLocale();
$this->parseVars();
// parse headers
if (!$customHeaders) {
SpoonHTTP::setHeaders('Content-type: text/html;charset=' . SPOON_CHARSET);
}
parent::display($template);
}
示例9: createXML
/**
* Create the XML based on the locale items.
*/
private function createXML()
{
$charset = BackendModel::getContainer()->getParameter('kernel.charset');
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
// xml headers
$headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
$headers[] = 'Content-Type: application/octet-stream;charset=' . $charset;
$headers[] = 'Content-Length: ' . strlen($xmlOutput);
// set headers
\SpoonHTTP::setHeaders($headers);
// output XML
echo $xmlOutput;
exit;
}
示例10: createXML
/**
* Create the XML based on the locale items.
*
* @return void
*/
private function createXML()
{
// create XML
$xmlOutput = BackendLocaleModel::createXMLForExport($this->locale);
// xml headers
$headers[] = 'Content-Disposition: attachment; filename="locale_' . BackendModel::getUTCDate('d-m-Y') . '.xml"';
$headers[] = 'Content-Type: application/octet-stream;charset=utf-8';
$headers[] = 'Content-Length: ' . strlen($xmlOutput);
// set headers
SpoonHTTP::setHeaders($headers);
// output XML
echo $xmlOutput;
// stop script
exit;
}
示例11: createCsv
/**
* Create the CSV.
*
* @return void
*/
private function createCsv()
{
// create csv
$csv = SpoonFileCSV::arrayToString($this->rows, $this->columnHeaders);
// set headers for download
$headers[] = 'Content-type: application/csv; charset=utf-8';
$headers[] = 'Content-Disposition: attachment; filename="' . date('Ymd_His') . '.csv"';
$headers[] = 'Content-Length: ' . strlen($csv);
$headers[] = 'Pragma: no-cache';
// overwrite the headers
SpoonHTTP::setHeaders($headers);
// output
echo $csv;
// exit here
exit;
}
示例12: __construct
/**
* Check if all required settings have been set
*
* @param string $module The module.
*/
public function __construct($module)
{
parent::__construct($module);
$error = false;
$action = Spoon::exists('url') ? Spoon::get('url')->getAction() : null;
// analytics session token
if (BackendModel::getModuleSetting('analytics', 'session_token') === null) {
$error = true;
}
// analytics table id
if (BackendModel::getModuleSetting('analytics', 'table_id') === null) {
$error = true;
}
// missing settings, so redirect to the index-page to show a message (except on the index- and settings-page)
if ($error && $action != 'settings' && $action != 'index') {
SpoonHTTP::redirect(BackendModel::createURLForAction('index'));
}
}
示例13: validateForm
/**
* Validate the form
*
* @return void
*/
private function validateForm()
{
// is the form submitted?
if ($this->frm->isSubmitted()) {
// cleanup the submitted fields, ignore fields that were added by hackers
$this->frm->cleanupFields();
// validate fields
$this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
$this->frm->getField('street')->isFilled(BL::err('FieldIsRequired'));
$this->frm->getField('number')->isFilled(BL::err('FieldIsRequired'));
$this->frm->getField('zip')->isFilled(BL::err('FieldIsRequired'));
$this->frm->getField('city')->isFilled(BL::err('FieldIsRequired'));
// no errors?
if ($this->frm->isCorrect()) {
// build item
$item['language'] = BL::getWorkingLanguage();
$item['title'] = $this->frm->getField('title')->getValue();
$item['text'] = $this->frm->getField('text')->getValue();
$item['street'] = $this->frm->getField('street')->getValue();
$item['number'] = $this->frm->getField('number')->getValue();
$item['zip'] = $this->frm->getField('zip')->getValue();
$item['city'] = $this->frm->getField('city')->getValue();
$item['country'] = $this->frm->getField('country')->getValue();
// geocode address
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($item['street'] . ' ' . $item['number'] . ', ' . $item['zip'] . ' ' . $item['city'] . ', ' . SpoonLocale::getCountry($item['country'], BL::getWorkingLanguage())) . '&sensor=false';
$geocode = json_decode(SpoonHTTP::getContent($url));
$item['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
$item['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
// insert the item
$id = BackendLocationModel::insert($item);
// add search index
// if(is_callable(array('BackendSearchModel', 'addIndex'))) BackendSearchModel::addIndex($this->getModule(), (int) $id, array('title' => $item['title'], 'text' => $item['text']));
// everything is saved, so redirect to the overview
if ($item['lat'] && $item['lng']) {
// trigger event
BackendModel::triggerEvent($this->getModule(), 'after_add', array('item' => $item));
// redirect
$this->redirect(BackendModel::createURLForAction('index') . '&report=added&var=' . urlencode($item['title']) . '&highlight=row-' . $id);
} else {
$this->redirect(BackendModel::createURLForAction('edit') . '&id=' . $id);
}
}
}
}
示例14: __construct
/**
* You have to specify the action and module so we know what to do with this instance
*
* @param string $action The action to load.
* @param string $module The module to load.
*/
public function __construct($action, $module)
{
$this->setModule($module);
$this->setAction($action);
$this->loadConfig();
$allowed = false;
// is this an allowed action
if (BackendAuthentication::isAllowedAction($action, $this->getModule())) {
$allowed = true;
}
// is this an allowed AJAX-action?
if (!$allowed) {
// set correct headers
SpoonHTTP::setHeadersByCode(403);
// output
$fakeAction = new BackendBaseAJAXAction('', '');
$fakeAction->output(BackendBaseAJAXAction::FORBIDDEN, null, 'Not logged in.');
}
}
示例15: validateForm
/**
* Validate form
*/
private function validateForm()
{
if ($this->frm->isSubmitted()) {
if ($this->frm->isCorrect()) {
if (!empty($this->records)) {
$teller = 0;
foreach ($this->records as $key => $record) {
if ($teller < $this->frm->getField("number_of_items")->getValue()) {
$data = array();
//--Create url
$url = 'http://maps.googleapis.com/maps/api/geocode/json?address=' . urlencode($record['address'] . ', ' . $record['zipcode'] . ' ' . $record['city'] . ', ' . \SpoonLocale::getCountry($record['country'], BL::getWorkingLanguage())) . '&sensor=false';
//--Get lat
$geocode = json_decode(\SpoonHTTP::getContent($url));
//--Sleep between the requests
sleep(0.05);
//--Check result
$data['lat'] = isset($geocode->results[0]->geometry->location->lat) ? $geocode->results[0]->geometry->location->lat : null;
$data['lng'] = isset($geocode->results[0]->geometry->location->lng) ? $geocode->results[0]->geometry->location->lng : null;
if ($data['lat'] != null) {
BackendAddressesModel::update($record['id'], $data);
$this->response .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . " <i>(Lat: " . $data['lat'] . ", Lng: " . $data['lng'] . ")</i><br/>";
//--Delete from array
unset($this->records[$key]);
} else {
$data['lat'] = "notfound";
$data['lng'] = "notfound";
BackendAddressesModel::update($record['id'], $data);
$this->responseError .= "<strong>" . $record['company'] . "</strong> - " . $record['address'] . " " . $record['zipcode'] . " " . $record['city'] . "<br/>";
}
} else {
break;
}
//--Add teller
$teller++;
}
$this->tpl->assign("responseError", $this->responseError);
$this->tpl->assign("response", $this->response);
}
}
}
}