コード例 #1
0
 /**
  * Gets instance of a singleton class
  * @return XmlImportConfig
  */
 public static function getInstance()
 {
     //if (is_null(self::$instance)) {
     self::$instance = new self();
     self::$instance->init();
     //}
     return self::$instance;
 }
コード例 #2
0
ファイル: import.php プロジェクト: hikaram/wee
 protected function init()
 {
     parent::init();
     error_reporting(0);
     //PMXI_Plugin::$session = PMXI_Session::get_instance();
     if ('PMXI_Admin_Manage' == PMXI_Plugin::getInstance()->getAdminCurrentScreen()->base) {
         // prereqisites are not checked when flow control is deligated
         $id = $this->input->get('id');
         $this->data['import'] = $import = new PMXI_Import_Record();
         if (!$id or $import->getById($id)->isEmpty()) {
             // specified import is not found
             wp_redirect(add_query_arg('page', 'pmxi-admin-manage', admin_url('admin.php')));
             die;
         }
         $this->isWizard = false;
     } else {
         $action = PMXI_Plugin::getInstance()->getAdminCurrentScreen()->action;
         $this->_step_ready($action);
         $this->isInline = 'process' == $action;
     }
     XmlImportConfig::getInstance()->setCacheDirectory(sys_get_temp_dir());
     // preserve id parameter as part of baseUrl
     $id = $this->input->get('id') and $this->baseUrl = add_query_arg('id', $id, $this->baseUrl);
     $this->baseUrl = apply_filters('pmxi_base_url', $this->baseUrl);
 }
コード例 #3
0
 /**
  * Get the value by XPath expression
  *
  * @param SimpleXmlElement $xpath XPath result
  * @return mixed
  */
 protected function getValue($xpath)
 {
     if (is_array($xpath) && count($xpath) > 0) {
         $result = array();
         foreach ($xpath as $xp) {
             // cancatenate multiple elements into 1 string
             ob_start();
             echo $xp;
             $result[] = trim(ob_get_clean());
         }
         return implode(XmlImportConfig::getInstance()->getMultiGlue(), $result);
     } else {
         // return null if nothing found
         return null;
     }
 }
コード例 #4
0
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }