예제 #1
0
 public function __construct()
 {
     // if the application wasn't defined before we will define it
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'frontend');
     }
     // set the module
     $this->setModule(SpoonFilter::getGetValue('module', null, ''));
     // set the requested file
     $this->setFile(SpoonFilter::getGetValue('file', null, ''));
     // set the language
     $this->setLanguage(SpoonFilter::getGetValue('language', FrontendLanguage::getActiveLanguages(), SITE_DEFAULT_LANGUAGE));
     // create a new template instance (this will handle all stuff for us)
     $tpl = new FrontendTemplate();
     // enable addslashes on each locale
     $tpl->setAddSlashes(true);
     // set correct headers
     SpoonHTTP::setHeaders('content-type: application/javascript');
     // fetch the template path
     if ($this->module == 'core') {
         $file = FRONTEND_CORE_PATH . '/js/' . $this->getFile();
     } else {
         $file = FRONTEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile();
     }
     // output the template
     $tpl->display(FrontendTheme::getPath($file), true);
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 /**
  * 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;
 }
예제 #4
0
 public function __construct()
 {
     // define the Named Application
     if (!defined('NAMED_APPLICATION')) {
         define('NAMED_APPLICATION', 'backend');
     }
     // set the module
     $this->setModule(SpoonFilter::getGetValue('module', null, ''));
     // set the requested file
     $this->setFile(SpoonFilter::getGetValue('file', null, ''));
     // set the language
     $this->setLanguage(SpoonFilter::getGetValue('language', array_keys(BackendLanguage::getWorkingLanguages()), SITE_DEFAULT_LANGUAGE));
     // build the path
     if ($this->module == 'core') {
         $path = BACKEND_CORE_PATH . '/js/' . $this->getFile();
     } else {
         $path = BACKEND_MODULES_PATH . '/' . $this->getModule() . '/js/' . $this->getFile();
     }
     // set correct headers
     SpoonHTTP::setHeaders('content-type: application/javascript');
     // create a new template instance (this will handle all stuff for us)
     $tpl = new BackendTemplate();
     // enable addslashes on each locale
     $tpl->setAddSlashes(true);
     // display
     $tpl->display($path, true);
 }
예제 #5
0
 /**
  * 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
0
 /**
  * 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);
 }
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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;
 }
예제 #10
0
 /**
  * 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;
 }
예제 #11
0
 /**
  * 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
0
 /**
  * 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;
 }
예제 #13
0
 /**
  * Output the template into the browser
  * Will also assign the interfacelabels and all user-defined constants.
  *
  * @return	void
  * @param	string $template				The path for the template.
  * @param	bool[optional] $customHeaders	Are there custom headers set?
  */
 public function display($template, $customHeaders = false)
 {
     // parse constants
     $this->parseConstants();
     // parse authenticated user
     $this->parseAuthenticatedUser();
     // check debug
     $this->parseDebug();
     // parse the label
     $this->parseLabels();
     // parse locale
     $this->parseLocale();
     // parse some vars
     $this->parseVars();
     // parse headers
     if (!$customHeaders) {
         SpoonHTTP::setHeaders('Content-type: text/html;charset=utf-8');
     }
     // call the parent
     parent::display($template);
 }
예제 #14
0
 /**
  * This method will be called by the Spoon Exception handler and is specific for exceptions thrown in AJAX-actions
  *
  * @param object $exception The exception that was thrown.
  * @param string $output    The output that should be mailed.
  */
 public static function exceptionAJAXHandler($exception, $output)
 {
     \SpoonHTTP::setHeaders('content-type: application/json');
     $response = array('code' => $exception->getCode() != 0 ? $exception->getCode() : 500, 'message' => $exception->getMessage());
     echo json_encode($response);
     exit;
 }
예제 #15
0
 /**
  * Output as XML
  *
  * @param int   $statusCode The status code.
  * @param array $data       The data to return.
  */
 private static function outputXML($statusCode, array $data = null)
 {
     // redefine
     $statusCode = (int) $statusCode;
     // init vars
     $charset = BackendModel::getContainer()->getParameter('kernel.charset');
     $pathChunks = explode(DIRECTORY_SEPARATOR, trim(dirname(__FILE__), DIRECTORY_SEPARATOR));
     $version = $pathChunks[count($pathChunks) - 2];
     $version = strtolower($version);
     // init XML
     $XML = new \DOMDocument('1.0', $charset);
     // set some properties
     $XML->preserveWhiteSpace = false;
     $XML->formatOutput = true;
     // create root element
     $root = $XML->createElement('fork');
     // add attributes
     $root->setAttribute('status_code', $statusCode);
     $root->setAttribute('status', $statusCode == 200 ? 'ok' : 'error');
     $root->setAttribute('version', FORK_VERSION);
     $root->setAttribute('endpoint', SITE_URL . '/api/' . $version);
     // append
     $XML->appendChild($root);
     // build XML
     array_walk($data, array(__CLASS__, 'arrayToXML'), $root);
     // set correct headers
     \SpoonHTTP::setHeadersByCode($statusCode);
     \SpoonHTTP::setHeaders('content-type: text/xml;charset=' . $charset);
     // output XML
     self::$content = $XML->saveXML();
 }
예제 #16
0
 /**
  * This method will be called by the Spoon Exceptionhandler and is specific for exceptions thrown in JS-files parsed through PHP
  *
  * @return	void
  * @param	object $exception	The exception that was thrown.
  * @param	string $output		The output that should be mailed.
  */
 public static function exceptionJSHandler($exception, $output)
 {
     // redefine
     $output = (string) $output;
     // set correct headers
     SpoonHTTP::setHeaders('content-type: application/javascript');
     // output
     echo '// ' . $exception->getMessage();
     // stop script execution
     exit;
 }
예제 #17
0
 /**
  * Output as XML
  *
  * @return	void
  * @param	int $statusCode			The status code.
  * @param	array[optional] $data	The data to return.
  */
 private static function outputXML($statusCode, array $data = null)
 {
     // redefine
     $statusCode = (int) $statusCode;
     // init vars
     $pathChunks = explode('/', trim(dirname(__FILE__), '/'));
     $version = $pathChunks[count($pathChunks) - 2];
     // init XML
     $XML = new DOMDocument('1.0', 'utf-8');
     // set some properties
     $XML->preserveWhiteSpace = false;
     $XML->formatOutput = true;
     // create root element
     $root = $XML->createElement('fork');
     // add attributes
     $root->setAttribute('status_code', $statusCode);
     $root->setAttribute('status', $statusCode == 200 ? 'ok' : 'error');
     $root->setAttribute('version', FORK_VERSION);
     $root->setAttribute('endpoint', SITE_URL . '/api/' . $version);
     // append
     $XML->appendChild($root);
     // build XML
     array_walk($data, array('API', 'arrayToXML'), $root);
     // set correct headers
     SpoonHTTP::setHeadersByCode($statusCode);
     SpoonHTTP::setHeaders('content-type: text/xml;charset=utf-8');
     // output XML
     echo $XML->saveXML();
     // stop script execution
     exit;
 }
예제 #18
0
파일: rss.php 프로젝트: jincongho/clienthub
 /**
  * Parse the feed and output the feed 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(self::HEADER . $this->getCharset());
     }
     // output
     echo $this->buildXML();
     // stop here
     exit;
 }
예제 #19
0
 /**
  * Output an answer to the browser
  *
  * @return	void
  * @param	int $statusCode				The status code for the response, use the available constants. (self::OK, self::BAD_REQUEST, self::FORBIDDEN, self::ERROR).
  * @param	mixed[optional] $data		The data to output.
  * @param	string[optional] $message	The text-message to send.
  */
 public function output($statusCode, $data = null, $message = null)
 {
     // redefine
     $statusCode = (int) $statusCode;
     if ($message !== null) {
         $message = (string) $message;
     }
     // create response array
     $response = array('code' => $statusCode, 'data' => $data, 'message' => $message);
     // set correct headers
     SpoonHTTP::setHeadersByCode($statusCode);
     SpoonHTTP::setHeaders('content-type: application/json');
     // output JSON to the browser
     echo json_encode($response);
     // stop script execution
     exit;
 }
예제 #20
0
 /**
  * Outputs the image as png to the browser.
  *
  * @param	bool[optional] $headers		Should the headers be send? This is a usefull when you're debugging.
  */
 public function parse($headers = true)
 {
     // set headers
     if ($headers) {
         SpoonHTTP::setHeaders('Content-type: image/png');
     }
     // get current dimensions
     $imageProperties = @getimagesize($this->filename);
     // validate imageProperties
     if ($imageProperties === false) {
         throw new SpoonThumbnailException('The sourcefile "' . $this->filename . '" could not be found.');
     }
     // set current dimensions
     $currentWidth = (int) $imageProperties[0];
     $currentHeight = (int) $imageProperties[1];
     $currentType = (int) $imageProperties[2];
     $currentMime = (string) $imageProperties['mime'];
     // resize image
     $this->resizeImage($currentWidth, $currentHeight, $currentType, $currentMime);
     // output image
     $success = @imagepng($this->image);
     // validate
     if (!$success) {
         throw new SpoonThumbnailException('Something went wrong while outputting the image.');
     }
     // cleanup the memory
     @imagedestroy($this->image);
 }
예제 #21
0
 /**
  * Parse the feed and output the feed into the browser.
  *
  * @return	void
  * @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-Type: text/Calendar');
         SpoonHTTP::setHeaders('Content-Disposition: inline; filename=' . $this->getfilename());
     }
     // output
     echo $this->build();
     // stop here
     exit;
 }
예제 #22
0
파일: csv.php 프로젝트: jincongho/clienthub
 /**
  * Sets the headers so we may download the CSV file in question
  *
  * @return	array
  * @param	string $path	The full path to the CSV file you wish to download.
  */
 private static function download($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 = array();
     $headers[] = 'Content-type: text/csv; charset=utf-8';
     $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
     // overwrite the headers
     SpoonHTTP::setHeaders($headers);
     // get the file contents
     $content = SpoonFile::getContent($path);
     // delete the CSV file
     SpoonFile::delete($path);
     // output the file contents
     echo $content;
     // exit here
     exit;
 }
예제 #23
0
 /**
  * Exports the statistics of all mailings for a given campaign ID in CSV format. This function
  * will send headers to download the CSV and exit your script after use.
  *
  * @param int $id The ID of the campaign.
  */
 public static function exportStatisticsByCampaignID($id)
 {
     // set the filename and path
     $filename = 'statistics-' . SpoonDate::getDate('YmdHi') . '.csv';
     // fetch the addresses by group
     $records = array();
     $records[] = BackendMailmotorCMHelper::getStatisticsByCampaignID($id);
     // unset some records
     unset($records[0]['opens'], $records[0]['clicks'], $records[0]['clicks_percentage'], $records[0]['recipients_total'], $records[0]['recipients_percentage']);
     // set columns
     $columns = array();
     $columns[] = BL::msg('MailingCSVRecipients');
     $columns[] = BL::msg('MailingCSVUniqueOpens');
     $columns[] = BL::msg('MailingCSVUnsubscribes');
     $columns[] = BL::msg('MailingCSVBounces');
     $columns[] = BL::msg('MailingCSVUnopens');
     $columns[] = BL::msg('MailingCSVBouncesPercentage');
     $columns[] = BL::msg('MailingCSVUniqueOpensPercentage');
     $columns[] = BL::msg('MailingCSVUnopensPercentage');
     // set start of the CSV
     $csv = BackendCSV::arrayToString($records, $columns);
     // fetch all mailings in this campaign
     $mailings = BackendModel::getDB()->getRecords(BackendMailmotorModel::QRY_DATAGRID_BROWSE_SENT_FOR_CAMPAIGN, array('sent', $id));
     // mailings set
     if (!empty($mailings)) {
         // set mailings columns
         $mailingColumns = array();
         $mailingColumns['name'] = BL::lbl('Name');
         $mailingColumns['language'] = BL::lbl('Language');
         // add the records to the csv string
         $csv .= PHP_EOL . 'Mailings:' . PHP_EOL . BackendCSV::arrayToString($mailings, $mailingColumns, array('id', 'campaign_id', 'campaign_name', 'send_on', 'status'));
     }
     // set headers for download
     $headers = array();
     $headers[] = 'Content-type: application/octet-stream';
     $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
     // overwrite the headers
     SpoonHTTP::setHeaders($headers);
     // output the CSV string
     echo $csv;
     // exit here
     exit;
 }
예제 #24
0
 /**
  * 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 (!is_file($path)) {
         throw new BackendException('The file ' . $path . ' doesn\'t exist.');
     }
     // init vars
     $charset = BackendModel::getContainer()->getParameter('kernel.charset');
     // fetch the filename from the path string
     $explodedFilename = explode('/', $path);
     $filename = end($explodedFilename);
     // set headers for download
     $headers[] = 'Content-type: application/csv; charset=' . $charset;
     $headers[] = 'Content-Disposition: attachment; filename="' . $filename . '"';
     $headers[] = 'Pragma: no-cache';
     // overwrite the headers
     \SpoonHTTP::setHeaders($headers);
     // get the file contents
     $content = file_get_contents($path);
     // output the file contents
     echo $content;
     exit;
 }
예제 #25
0
 /**
  * Output the template into the browser
  * Will also assign the labels and all user-defined constants.
  * If you want custom-headers, you should set them yourself, otherwise the content-type and charset will be set
  *
  * @param string $template The path of the template to use.
  * @param bool[optional] $customHeaders Are custom headers already set?
  * @param bool[optional] $parseCustom Parse custom template.
  */
 public function display($template, $customHeaders = false, $parseCustom = false)
 {
     // do custom stuff
     if ($parseCustom) {
         new FrontendTemplateCustom($this);
     }
     // parse constants
     $this->parseConstants();
     // check debug
     $this->parseDebug();
     // parse the label
     $this->parseLabels();
     // parse locale
     $this->parseLocale();
     // parse date/time formats
     $this->parseDateTimeFormats();
     // parse vars
     $this->parseVars();
     // parse headers
     if (!$customHeaders) {
         SpoonHTTP::setHeaders('content-type: text/html;charset=' . SPOON_CHARSET);
     }
     // get template path
     $template = FrontendTheme::getPath($template);
     /*
      * Code below is exactly the same as from our parent (SpoonTemplate::display), exept
      * for the compiler being used. We want our own compiler extension here.
      */
     // redefine
     $template = (string) $template;
     // validate name
     if (trim($template) == '' || !SpoonFile::exists($template)) {
         throw new SpoonTemplateException('Please provide an existing template.');
     }
     // compiled name
     $compileName = $this->getCompileName((string) $template);
     // compiled if needed
     if ($this->forceCompile || !SpoonFile::exists($this->compileDirectory . '/' . $compileName)) {
         // create compiler
         $compiler = new FrontendTemplateCompiler((string) $template, $this->variables);
         // set some options
         $compiler->setCacheDirectory($this->cacheDirectory);
         $compiler->setCompileDirectory($this->compileDirectory);
         $compiler->setForceCompile($this->forceCompile);
         $compiler->setForms($this->forms);
         // compile & save
         $compiler->parseToFile();
     }
     // load template
     require $this->compileDirectory . '/' . $compileName;
 }