public function executeSaveTag() { try { $parameters = $this->getRequest()->getParameterHolder()->getAll(); if ($parameters['id']) { $obj = Document::getDocumentInstance($parameters['id']); $parent = Document::getParentOf($parameters['id']); } else { $obj = new Tag(); $parent = Document::getDocumentInstance($parameters['parent']); } foreach ($parameters as $key => $value) { if (!(strpos($key, 'attr') === false)) { $function = 'set' . str_replace('attr', '', $key); $obj->{$function}($value); } } if (!$parameters['attrExclusive']) { $obj->setExclusive(0); } $obj->save(null, $parent); UtilsHelper::setBackendMsg("Saved"); } catch (Exception $e) { UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error"); } PanelService::redirect('tag'); exit; }
public function executeEditLabel() { $this->setLayout(false); $culture = sfContext::getInstance()->getUser()->getCulture(); $id = $this->id = $this->getRequestParameter('id'); $this->page = $this->getRequestParameter('page'); $phpFile = sfConfig::get('sf_root_dir') . "/cache/locales.php"; $xmlFile = sfConfig::get('sf_root_dir') . "/config/locales.xml"; if ($this->getRequestParameter('submitEdit')) { $attrValue = $this->getRequestParameter('attrValue'); if (trim($attrValue) == '') { $request = $this->getRequest(); $request->setError('attrValue', 1); UtilsHelper::setBackendMsg('Field <b>Value</b> is empty!', 'error'); return; } $locale = $id; // write XML Locales (in lib folder); if ($content = file_get_contents($xmlFile)) { $lines = explode("</locale>", $content); $changed = false; foreach ($lines as &$line) { if (strpos($line, '<locale label="' . $locale . '"') != false) { $arr = explode("\n", $line); foreach ($arr as &$l) { if (strpos($l, '<item lang="' . $culture . '"') != false) { //$v = str_replace('"', "'", $attrValue); //$val = htmlspecialchars($attrValue); $val = htmlentities($attrValue, ENT_COMPAT | ENT_HTML401, 'UTF-8'); $l = ' <item lang="' . $culture . '" value="' . $val . '" />'; $changed = true; break; } } $line = implode("\n", $arr); break; } } if ($changed) { $content = implode("</locale>", $lines); file_put_contents($xmlFile, $content); } else { $request = $this->getRequest(); $request->setError('attrValue', 1); UtilsHelper::setBackendMsg('Locale "' . $id . '" is missing in XML file!', 'error'); return; } } // write COMPILED Locales (in cache folder); if ($content = file_get_contents($phpFile)) { $lines = explode("\n", $content); foreach ($lines as &$line) { // replace ['media.frontend.gallery-no-tag-warn']['en'] if (strpos($line, "['{$id}']") != false) { //$val = str_replace('"', '\"', $attrValue); //$val = htmlspecialchars($attrValue); $val = htmlentities($attrValue, ENT_COMPAT | ENT_HTML401, 'UTF-8'); $line = "\t\$locales['{$id}'] = \"{$val}\";"; break; } } $content = implode("\n", $lines); file_put_contents($phpFile, $content); } PanelService::redirect(); } else { if (!($this->val = $this->getRequestParameter('attrValue'))) { include $phpFile; $this->val = htmlspecialchars_decode($locales[$id]); } $this->id = $id; } }
public function executeSaveMedia() { $hasError = false; try { $request = $this->getRequest(); $id = $this->getRequestParameter("id"); if ($this->getRequestParameter("submitEdit")) { $fileName = $request->getFilePath('attrFilename'); if (!$id && !$fileName) { UtilsHelper::setBackendMsg("Error: Please upload an image (JPG, GIF or JPG)!", "error"); return; } if ($fileName) { $allowedArr = array("image/gif", "image/png", "image/jpg", "image/jpeg", "image/pjpeg"); $media = Media::upload('attrFilename', 'upload', $allowedArr); $media->resizeImage("thumbs", null, 100); } } } catch (Exception $e) { $hasError = true; UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error"); } if (!$hasError) { PanelService::redirect(); exit; } }
public function executeEditSettings() { $this->setLayout(false); $culture = sfContext::getInstance()->getUser()->getCulture(); $id = $this->id = $this->getRequestParameter('id'); $this->page = $this->getRequestParameter('page'); $phpFile = sfConfig::get('sf_root_dir') . "/cache/settings.php"; $xmlFile = sfConfig::get('sf_root_dir') . "/config/settings.xml"; if ($this->getRequestParameter('submitEdit')) { $attrValue = $this->getRequestParameter('attrValue'); if (trim($attrValue) == '') { $request = $this->getRequest(); $request->setError('attrValue', 1); UtilsHelper::setBackendMsg('Field <b>Value</b> is empty!', 'error'); return; } $setting = $id; if ($content = file_get_contents($xmlFile)) { $lines = explode("</element>", $content); $changed = false; foreach ($lines as &$line) { if (strpos($line, '<element label="' . $setting . '"') != false) { $arr = explode("\n", $line); foreach ($arr as &$l) { if (strpos($l, '<item lang="' . $culture . '"') != false) { $v = htmlspecialchars($attrValue); $l = ' <item lang="' . $culture . '" value="' . $v . '" />'; $changed = true; break; } } $line = implode("\n", $arr); break; } } if ($changed) { $content = implode("</element>", $lines); file_put_contents($xmlFile, $content); } else { $request = $this->getRequest(); $request->setError('attrValue', 1); UtilsHelper::setBackendMsg('Settings "' . $id . '" is missing in XML file!', 'error'); return; } } if ($content = file_get_contents($phpFile)) { $lines = explode("\n", $content); foreach ($lines as &$line) { if (strpos($line, "['{$id}']") != false) { $v = str_replace('"', '\\"', $attrValue); $line = "\t\$settings['{$id}'] = \"{$v}\";"; break; } } $content = implode("\n", $lines); file_put_contents($phpFile, $content); } PanelService::redirect(); } else { if (!($this->val = $this->getRequestParameter('attrValue'))) { include $phpFile; $this->val = htmlspecialchars_decode($settings[$id]); } $this->id = $id; } }