Ejemplo n.º 1
0
 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;
 }
Ejemplo n.º 2
0
 public function executeSavePage()
 {
     try {
         PanelService::objectSave($obj, $parent);
         Urlrewrite::updateUrlRelationCache();
         //UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error saving Page: " . $e->getMessage(), "error");
     }
     //		exec('rm -fr '.SF_ROOT_DIR.DIRECTORY_SEPARATOR.'cache'.DIRECTORY_SEPARATOR.'menus/*');
     //		PanelService::redirect();
     //		exit();
 }
Ejemplo n.º 3
0
 public function executeSaveNewsI18n()
 {
     try {
         BackendService::objectSave($obj, $parent);
         $end_date = $obj->getEndDate();
         $obj->setEndDate(substr($end_date, 0, 11) . '23:59:59');
         $obj->save(null, $parent, $parameters["attrCulture"]);
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
     }
     $this->forward(strtolower($this->getRequestParameter('moduleName')), "edit" . $this->getRequestParameter('documentName'));
     exit;
 }
Ejemplo n.º 4
0
 public function executeLogin()
 {
     $referer = @$_SERVER['HTTP_REFERER'];
     if (!strstr($referer, 'panel') || !strstr($referer, "?")) {
         $referer = null;
     }
     $this->getUser()->setAttribute('referer', $referer);
     $this->setLayout("panel");
     if ($this->getRequestParameter("submit")) {
         if ($this->getRequestParameter("login") && $this->getRequestParameter("password")) {
             $subscriber_pass = $this->getRequestParameter('password');
             $subscriber_login = $this->getRequestParameter('login');
             $c = new Criteria();
             $c->add(UserPeer::LOGIN, $subscriber_login);
             $subscriber = UserPeer::doSelectOne($c);
             if ($subscriber) {
                 if ($subscriber->getBackend() != 1) {
                     //						$this->getRequest()->setError('login_error', 'Your have no access to site admisnistration');
                     UtilsHelper::setBackendMsg('Your have no access to site admisnistration', "info");
                 } elseif ($subscriber->getPublicationStatus() != UtilsHelper::STATUS_ACTIVE) {
                     //						$this->getRequest()->setError('login_error', 'Your account is not active');
                     UtilsHelper::setBackendMsg('Your account is not active', "info");
                 } elseif (sha1($subscriber->getSalt() . $subscriber_pass) == $subscriber->getSha1Password()) {
                     $this->getUser()->signIn($subscriber);
                     $this->user = $subscriber;
                     //exit("referer ".$_SERVER['HTTP_REFERER']);
                     $this->redirect($this->getUser()->getAttribute("referer"));
                 } else {
                     //						$this->getRequest()->setError('login_error', 'Wrong password');
                     UtilsHelper::setBackendMsg('Wrong username or password', "error");
                 }
             } else {
                 UtilsHelper::setBackendMsg('Wrong username or password', "error");
             }
         } else {
             //				$this->getRequest()->setError('login_error', 'Please, enter username and password');
             UtilsHelper::setBackendMsg('Please, enter username and password', "info");
         }
     } else {
         if ($subscriber = $this->getUser()->getAttribute('forceAutoLogAsAdmin')) {
             $this->getUser()->signIn($subscriber);
             $this->getUser()->setAttribute('forceAutoLogAsAdmin', null);
             $this->redirect("http://" . $_SERVER['HTTP_HOST'] . "/admin/index.php?refresh=" . $this->getRequestParameter('refresh'));
         }
     }
 }
Ejemplo n.º 5
0
 public function executeSaveMedia()
 {
     try {
         $media = Media::upload('attrFilename');
         if ($media && $media->IsImage()) {
             list($originalWidth, $originalHeight) = getimagesize($media->getServerAbsoluteUrl());
             if ($originalWidth > $originalHeight && $originalWidth > 1500) {
                 $media->resizeImage(null, null, 1500);
             } else {
                 if ($originalHeight > 1500) {
                     $media->resizeImage(null, 1500);
                 }
             }
             $media->resizeImage("thumbs", 100);
         } else {
             if ($media && in_array($media->getFiletype(), array("video/x-msvideo", "video/mpeg", "video/mp4", "video/quicktime", "video/x-ms-wmv", "video/avi", "video/wmv"))) {
                 $media->convertToFlv();
             } else {
                 if ($media && in_array($media->getFiletype(), array("video/x-flv", "flv-application/octet-stream"))) {
                     $media->saveFlv();
                 } else {
                     if ($media && in_array($media->getFiletype(), array("application/octet-stream")) && substr($media->getFilename(), -4) == ".flv") {
                         $media->saveFlv();
                     } else {
                         if ($media && in_array($media->getFiletype(), array("application/binary")) && substr($media->getFilename(), -4) == ".mpg" || $media && in_array($media->getFiletype(), array("application/binary")) && substr($media->getFilename(), -5) == ".mpeg") {
                             $media->convertToFlv();
                         }
                     }
                 }
             }
         }
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error while saving: " . UtilsHelper::Localize("media.backend." . $e->getMessage(), "en"), "error");
     }
     $this->forward(strtolower($this->getRequestParameter('moduleName')), "edit" . $this->getRequestParameter('documentName'));
 }
Ejemplo n.º 6
0
 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;
     }
 }
Ejemplo n.º 7
0
 public static function objectSave(&$obj, &$parent, $documentName = null)
 {
     try {
         $parameters = sfContext::getInstance()->getRequest()->getParameterHolder()->getAll();
         if (!$documentName) {
             $documentName = $parameters["documentName"];
         }
         if (!$parent) {
             $parent = Document::getDocumentInstance($parameters['parent']);
         }
         if (!is_object($obj)) {
             if (is_numeric($parameters['id']) && !$parent) {
                 $obj = Document::getDocumentInstance($parameters['id']);
                 $parent = Document::getParentOf($parameters['id']);
                 $documentName = $parameters["documentName"];
             } else {
                 $obj = new $documentName();
             }
         }
         include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php";
         $m = "get" . $documentName . "Properties";
         $properties = Schema::$m();
         //$imageFields = explode(",", $parameters['imageFields']);
         foreach ($parameters as $key => $value) {
             if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") {
                 $key = str_replace('attr', '', $key);
                 if ($properties && $key != "Password" && !in_array($key, $properties)) {
                     continue;
                 }
                 if ($key == "Password" && empty($value)) {
                     continue;
                 }
                 $function = 'set' . $key;
                 if (is_array($value)) {
                     //$value = implode('-', $value);
                     $date = $value['year'] . '-' . $value['month'] . '-' . $value['day'];
                     // 2009-02-09 16:10:20
                     if ($value['hour'] && $value['minute']) {
                         $time = $value['hour'] . ':' . $value['minute'];
                         $value = $date . ' ' . $time;
                     } else {
                         $value = $date;
                     }
                 }
                 /*if (in_array($key, $imageFields))
                 					{
                 					$getFunction = 'get'.$key;
                 
                 					$imgId = $obj->$getFunction();
                 					if ($imgId != $value)
                 					{
                 					$img = Document::getDocumentInstance($imgId);
                 					if ($img)
                 					{
                 					$imgExt = $img->getExtention();
                 					@unlink(sfConfig::get('sf_root_dir')."/www/media/upload/thumbs/".$parameters["moduleName"]."/".$imgId."-".$key.".".$imgExt);
                 					}
                 					}
                 					}*/
                 if ($key == "Keywords") {
                     if ($value) {
                         $value = str_replace(',', '][', $value);
                         $value = '[' . substr($value, 0, -1);
                     }
                 }
                 $obj->{$function}($value);
             }
             /*if (in_array($key, $imageFields) && (!empty($value)))
             		{
             			$image = Document::getDocumentInstance($value);
             			if ($image)
             			{
             				if (empty($parameters[$key.'_thumbheight']))
             				{
             					$parameters[$key.'_thumbheight'] = null;
             				}
             				if (empty($parameters[$key.'_thumbwidth']))
             				{
             					$parameters[$key.'_thumbwidth'] = null;
             				}
             				$image->resizeImage($parameters["moduleName"], $parameters[$key.'_thumbheight'], $parameters[$key.'_thumbwidth'], $key);
             			}
             		}*/
         }
         if (class_exists($documentName . "I18n") && $documentName != "Listitem") {
             if (!($culture = $parameters["attrCulture"])) {
                 if (SF_APP == "panel") {
                     $culture = sfContext::getInstance()->getUser()->getCulture();
                 } else {
                     $culture = Document::getDocumentByExclusiveTag("default_culture");
                 }
                 if ($culture) {
                     $culture = $culture->getValue();
                 } else {
                     throw new Exception("No default culture defined");
                 }
             }
             $obj->save(null, $parent, $culture);
             if (!$parameters["id"] || SF_APP == 'panel') {
                 if (class_exists($documentName . "I18n")) {
                     if (SF_APP == "panel") {
                         $objI8n = Document::getDocumentByCulture($obj, null, true);
                     }
                     self::objectSave($objI8n, $obj, $documentName . "I18n");
                     if ($documentName == "Page") {
                         $objI8n->setRewriteUrl($parameters["attrRewriteUrl"]);
                     }
                     $objI8n->setCulture($culture);
                     $objI8n->save(null, $obj, $culture);
                 }
                 if (SF_APP != "panel") {
                     $request = sfContext::getInstance()->getRequest();
                     $request->setParameter("id", $obj->getId());
                 }
             }
         } else {
             $obj->save(null, $parent);
         }
         $tags = Document::getAvailableTagsOf($parameters['moduleName'], $documentName);
         foreach ($tags as $tag) {
             if ($parameters['tag_id_' . $tag->getId()]) {
                 Document::addTag($obj, $tag->getTagId());
             } else {
                 Document::removeTag($obj, $tag->getTagId());
             }
         }
         Tagrelation::updateTagRelationCache();
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         throw $e;
     }
     if (SF_APP == "panel") {
         self::panelRedirect();
     }
 }
Ejemplo n.º 8
0
 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;
     }
 }
Ejemplo n.º 9
0
 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;
     }
 }
Ejemplo n.º 10
0
 public function executeSavePageI18n()
 {
     try {
         $pageType = $this->getRequestParameter("attrPageType");
         if (!$pageType) {
             $request = $this->getRequest();
             $request->setParameter('attrPageType', 'CONTENT');
         }
         BackendService::objectSave($obj, $parent);
         $obj->setRewriteUrl($this->getRequestParameter("attrRewriteUrl"));
         if (!$this->getRequestParameter("attrIsSecure")) {
             $obj->setIsSecure(NULL);
         }
         $obj->save(null, $parent, $this->getRequestParameter("attrCulture"));
         Urlrewrite::updateUrlRelationCache();
         UtilsHelper::setBackendMsg("Saved");
     } catch (Exception $e) {
         UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error");
     }
     $this->forward(strtolower($this->getRequestParameter('moduleName')), "edit" . $this->getRequestParameter('documentName'));
     exit;
 }