/**
  * Generates the code and returns the filename under which it was stored in
  * cache directory. If $filename is null then it is generated automatically
  *
  * @param string $filename
  * @return string
  */
 public function generate($filename = null)
 {
     $result = '';
     if (count($this->sequence->getVariables())) {
         $var = '$x' . $this->xmlVariableNumber++;
         array_push($this->xmlStack, $var);
         $result .= $this->openPhpTag() . $var . ' = $this->xml;';
     }
     $result .= $this->generateForSequence($this->sequence);
     if (count($this->sequence->getVariables())) {
         array_pop($this->xmlStack);
     }
     if (is_null($filename)) {
         $filename = tempnam(XmlImportConfig::getInstance()->getCacheDirectory(), 'xim');
     }
     if (!$filename or !@is_writable($filename)) {
         $uploads = wp_upload_dir();
         $filename = $uploads['path'] . '/' . wp_unique_filename($uploads['path'], 'tmpfile');
     }
     file_put_contents($filename, $result);
     return $filename;
 }
 /**
  * Generates the code and returns the filename under which it was stored in
  * cache directory. If $filename is null then it is generated automatically
  *
  * @param string $filename
  * @return string
  */
 public function generate($filename = null)
 {
     $result = '';
     if (count($this->sequence->getVariables())) {
         $var = '$x' . $this->xmlVariableNumber++;
         array_push($this->xmlStack, $var);
         $result .= $this->openPhpTag() . $var . ' = $this->xml;';
     }
     $result .= $this->generateForSequence($this->sequence);
     if (count($this->sequence->getVariables())) {
         array_pop($this->xmlStack);
     }
     if (is_null($filename)) {
         $filename = @tempnam(XmlImportConfig::getInstance()->getCacheDirectory(), 'xim');
     }
     if (!$filename or !@is_writable($filename)) {
         $uploads = wp_upload_dir();
         $targetDir = $uploads['basedir'] . DIRECTORY_SEPARATOR . PMXI_Plugin::TEMP_DIRECTORY;
         $filename = $targetDir . DIRECTORY_SEPARATOR . wp_unique_filename($targetDir, 'tmpfile');
     }
     file_put_contents($filename, $result);
     //@chmod($filename, 0666);
     return $filename;
 }