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); }
/** * Cria o snapshot na pasta que esta configurada * * @return boolean */ public function generate() { $this->Menu = ClassRegistry::init("Cms.Menu"); $aDados = $this->Menu->find('all'); if (!$this->isUpToDate($aDados)) { App::import("Helper", "Xml"); App::import("File"); $oXml = new XmlHelper(); $oXml->header(); $oXml->serialize($aDados); $oFile = new File(Configure::read('Cms.CheckPoint.menus') . time() . ".xml", true, 0777); $oFile->append($oXml->header()); $oFile->append("<menus>"); $oFile->append($oXml->serialize($aDados)); $oFile->append("</menus>"); return true; } return false; }