public function testIsFilename()
 {
     $this->assertTrue(SpoonFilter::isFilename('test.tpl'));
     $this->assertTrue(SpoonFilter::isFilename('spoon_template.php'));
     $this->assertFalse(SpoonFilter::isFilename('/Users/bauffman/Desktop/test.txt'));
     // Simulating PHP < 5.4 behaviour
     $this->assertTrue(SpoonFilter::isFilename(array()));
 }
Example #2
0
File: text.php Project: szLuis/oac
 /**
  * Checks for a valid file name (including dots but no slashes and other forbidden characters).
  *
  * @return	bool
  * @param	string[optional] $error		The error message to set.
  */
 public function isFilename($error = null)
 {
     // filled
     if ($this->isFilled()) {
         // post/get data
         $data = $this->getMethod(true);
         // validate
         if (!isset($data[$this->attributes['name']]) || !SpoonFilter::isFilename($data[$this->attributes['name']])) {
             if ($error !== null) {
                 $this->setError($error);
             }
             return false;
         }
         return true;
     }
     // has error
     if ($error !== null) {
         $this->setError($error);
     }
     return false;
 }
Example #3
0
 /**
  * Function to store the actual content for either HTML or plain text.
  *
  * @param	string $content			The body of the e-mail you wish to send.
  * @param	array $variables		The variables to parse into the content.
  * @param	string[optional] $type	The e-mail type. Either 'html' or 'plain'.
  */
 private function processContent($content, $variables, $type = 'html')
 {
     // check for type
     $type = SpoonFilter::getValue($type, array('html', 'plain'), 'html');
     // exploded string
     $exploded = explode('/', str_replace('\\', '/', $content));
     $filename = end($exploded);
     // check if the string provided is a formatted as a file
     if (SpoonFilter::isFilename($filename) && preg_match('/^[\\S]+\\.\\w{2,3}[\\S]$/', $filename) && !strstr($filename, ' ')) {
         // check if template exists
         if (!SpoonFile::exists($content)) {
             throw new SpoonEmailException('Template not found. (' . $content . ')');
         }
         // store content
         $this->content[$type] = (string) $this->getTemplateContent($content, $variables);
     } else {
         // set the name for the temporary file
         $tempFile = $this->compileDirectory . '/' . md5(uniqid()) . '.tpl';
         // write temp file
         SpoonFile::setContent($tempFile, $content);
         // store content
         $this->content[$type] = (string) $this->getTemplateContent($tempFile, $variables);
         // delete the temporary
         SpoonFile::delete($tempFile);
     }
 }
Example #4
0
 /**
  * Checks for a valid file name (including dots but no slashes and other forbidden characters).
  *
  * @return	bool
  * @param	string[optional] $error		The error message to set.
  */
 public function isFilename($error = null)
 {
     // correct filename
     if ($this->isFilled() && SpoonFilter::isFilename($this->getFileName())) {
         return true;
     }
     // has error
     if ($error !== null) {
         $this->setError($error);
     }
     return false;
 }
 public function testIsFilename()
 {
     $this->assertTrue(SpoonFilter::isFilename('test.tpl'));
     $this->assertTrue(SpoonFilter::isFilename('spoon_template.php'));
     $this->assertFalse(SpoonFilter::isFilename('/Users/bauffman/Desktop/test.txt'));
 }