public function admin_export($id = null) { if (!$id) { $this->notice('invalid'); } $this->Template->recursive = -1; $template = $this->Template->read(array('name', 'description', 'author', 'header', 'footer'), $id); if (empty($template)) { $this->notice('invalid'); } $pattern = "/src=[\\\"']?([^\\\"']?.*(png|jpg|gif|jpeg))[\\\"']?/i"; preg_match_all($pattern, $template['Template']['header'], $images); $path = TMP . 'cache' . DS . 'newsletter' . DS . 'template' . DS . $template['Template']['name']; $Folder = new Folder($path, 0777); $slash = $Folder->correctSlashFor($path); App::import('File'); App::import('Folder'); $File = new File($path . DS . 'template.xml', true, 0777); $imageFiles = array(); if (!empty($images[1])) { foreach ($images[1] as $img) { $img = str_replace('/', $slash, $img); $img = str_replace('\\', $slash . $slash, $img); $imageFiles[] = $img; if (is_file(APP . 'webroot' . $img)) { $Folder->create(dirname($path . $img), 0777); $File->path = APP . 'webroot' . $img; $File->copy(dirname($path . $img) . DS . basename($img)); } } } $xml['template']['name'] = 'Infinitas Newsletter Template'; $xml['template']['generator'] = 'Infinitas Template Generator'; $xml['template']['version'] = $this->version; $xml['template']['template'] = $template['Template']['name']; $xml['template']['description'] = $template['Template']['description']; $xml['template']['author'] = $template['Template']['author']; $xml['data']['header'] = $template['Template']['header']; $xml['data']['footer'] = $template['Template']['footer']; $xml['files']['images'] = $imageFiles; App::Import('Helper', 'Xml'); $Xml = new XmlHelper(); $File->path = $path . DS . 'template.xml'; $File->write($Xml->serialize($xml)); App::import('Vendor', 'Zip', array('file' => 'zip.php')); $Zip = new CreateZipFile(); $Zip->zipDirectory($path, null); $File = new File($path . DS . 'template.zip', true, 0777); $File->write($Zip->getZippedfile()); $this->view = 'Media'; $params = array('id' => 'template.zip', 'name' => $template['Template']['name'], 'download' => true, 'extension' => 'zip', 'path' => $path . DS); $this->set($params); $Folder = new Folder($path); $Folder->read(); $Folder->delete($path); }
/** * Returns $path with added terminating slash (corrected for Windows or other OS). * * @param string $path Path to check * @return string Path with ending slash * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::slashTerm */ public static function slashTerm($path) { if (Folder::isSlashTerm($path)) { return $path; } return $path . Folder::correctSlashFor($path); }
/** * correctSlashFor method * * @access public * @return void */ function correctSlashFor() { $path = '/path/to/file'; $result = Folder::correctSlashFor($path); $this->assertEqual($result, '/'); $path = '\\path\\to\\file'; $result = Folder::correctSlashFor($path); $this->assertEqual($result, '/'); $path = 'C:\\path\\to\\file'; $result = Folder::correctSlashFor($path); $this->assertEqual($result, '\\'); }
/** * correctSlashFor method * * @return void */ public function testCorrectSlashFor() { $path = '/path/to/file'; $result = Folder::correctSlashFor($path); $this->assertEquals('/', $result); $path = '\\path\\to\\file'; $result = Folder::correctSlashFor($path); $this->assertEquals('/', $result); $path = 'C:\\path\\to\\file'; $result = Folder::correctSlashFor($path); $this->assertEquals('\\', $result); }
/** * Returns a correct set of slashes for given $path. (\\ for Windows paths and / for other paths.) * * @param string $path Path to check * * @return string Set of slashes ("\\" or "/") * @link http://book.cakephp.org/2.0/en/core-utility-libraries/file-folder.html#Folder::normalizePath */ public static function normalizePath($path) { return Folder::correctSlashFor($path); }