Exemplo n.º 1
0
 /**
  * Loads a list of static routes for the specicifies parameters, returns an array of Staticroute elements
  *
  * @return array
  */
 public function load()
 {
     $redirectsData = $this->db->fetchAll("SELECT id FROM redirects" . $this->getCondition() . $this->getOrder() . $this->getOffsetLimit(), $this->model->getConditionVariables());
     $redirects = array();
     foreach ($redirectsData as $redirectData) {
         $redirects[] = Redirect::getById($redirectData["id"]);
     }
     $this->model->setRedirects($redirects);
     return $redirects;
 }
Exemplo n.º 2
0
 public function redirectsAction()
 {
     if ($this->_getParam("data")) {
         if ($this->getUser()->isAllowed("redirects")) {
             if ($this->_getParam("xaction") == "destroy") {
                 $id = Zend_Json::decode($this->_getParam("data"));
                 $redirect = Redirect::getById($id);
                 $redirect->delete();
                 $this->_helper->json(array("success" => true, "data" => array()));
             } else {
                 if ($this->_getParam("xaction") == "update") {
                     $data = Zend_Json::decode($this->_getParam("data"));
                     // save redirect
                     $redirect = Redirect::getById($data["id"]);
                     if ($data["target"]) {
                         if ($doc = Document::getByPath($data["target"])) {
                             $data["target"] = $doc->getId();
                         }
                     }
                     $redirect->setValues($data);
                     $redirect->save();
                     $redirectTarget = $redirect->getTarget();
                     if (is_numeric($redirectTarget)) {
                         if ($doc = Document::getById(intval($redirectTarget))) {
                             $redirect->setTarget($doc->getFullPath());
                         }
                     }
                     $this->_helper->json(array("data" => $redirect, "success" => true));
                 } else {
                     if ($this->_getParam("xaction") == "create") {
                         $data = Zend_Json::decode($this->_getParam("data"));
                         unset($data["id"]);
                         // save route
                         $redirect = new Redirect();
                         if ($data["target"]) {
                             if ($doc = Document::getByPath($data["target"])) {
                                 $data["target"] = $doc->getId();
                             }
                         }
                         $redirect->setValues($data);
                         $redirect->save();
                         $redirectTarget = $redirect->getTarget();
                         if (is_numeric($redirectTarget)) {
                             if ($doc = Document::getById(intval($redirectTarget))) {
                                 $redirect->setTarget($doc->getFullPath());
                             }
                         }
                         $this->_helper->json(array("data" => $redirect, "success" => true));
                     }
                 }
             }
         } else {
             Logger::err("user [" . $this->getUser()->getId() . "] attempted to modify static routes, but has no permission to do so.");
         }
     } else {
         // get list of routes
         $list = new Redirect_List();
         $list->setLimit($this->_getParam("limit"));
         $list->setOffset($this->_getParam("start"));
         if ($this->_getParam("sort")) {
             $list->setOrderKey($this->_getParam("sort"));
             $list->setOrder($this->_getParam("dir"));
         }
         if ($this->_getParam("filter")) {
             $list->setCondition("`source` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%") . " OR `target` LIKE " . $list->quote("%" . $this->_getParam("filter") . "%"));
         }
         $list->load();
         $redirects = array();
         foreach ($list->getRedirects() as $redirect) {
             if ($link = $redirect->getTarget()) {
                 if (is_numeric($link)) {
                     if ($doc = Document::getById(intval($link))) {
                         $redirect->setTarget($doc->getFullPath());
                     }
                 }
             }
             $redirects[] = $redirect;
         }
         $this->_helper->json(array("data" => $redirects, "success" => true, "total" => $list->getTotalCount()));
     }
     $this->_helper->json(false);
 }
Exemplo n.º 3
0
 public function saveAction()
 {
     if ($this->_getParam("id")) {
         $page = Document_Page::getById($this->_getParam("id"));
         $page = $this->getLatestVersion($page);
         $page->setUserModification($this->getUser()->getId());
         // save to session
         $key = "document_" . $this->_getParam("id");
         $session = new Zend_Session_Namespace("pimcore_documents");
         $session->{$key} = $page;
         if ($this->_getParam("task") == "unpublish") {
             $page->setPublished(false);
         }
         if ($this->_getParam("task") == "publish") {
             $page->setPublished(true);
         }
         // check for redirects
         if ($this->getUser()->isAllowed("redirects") && $this->_getParam("settings")) {
             $settings = Zend_Json::decode($this->_getParam("settings"));
             if (is_array($settings)) {
                 $redirectList = new Redirect_List();
                 $redirectList->setCondition("target = ?", $page->getId());
                 $existingRedirects = $redirectList->load();
                 $existingRedirectIds = array();
                 foreach ($existingRedirects as $existingRedirect) {
                     $existingRedirectIds[$existingRedirect->getId()] = $existingRedirect->getId();
                 }
                 for ($i = 1; $i < 100; $i++) {
                     if (array_key_exists("redirect_url_" . $i, $settings)) {
                         // check for existing
                         if ($settings["redirect_id_" . $i]) {
                             $redirect = Redirect::getById($settings["redirect_id_" . $i]);
                             unset($existingRedirectIds[$redirect->getId()]);
                         } else {
                             // create new one
                             $redirect = new Redirect();
                         }
                         $redirect->setSource($settings["redirect_url_" . $i]);
                         $redirect->setTarget($page->getId());
                         $redirect->setStatusCode(301);
                         $redirect->save();
                     }
                 }
                 // remove existing redirects which were delete
                 foreach ($existingRedirectIds as $existingRedirectId) {
                     $redirect = Redirect::getById($existingRedirectId);
                     $redirect->delete();
                 }
             }
         }
         // only save when publish or unpublish
         if ($this->_getParam("task") == "publish" && $page->isAllowed("publish") or $this->_getParam("task") == "unpublish" && $page->isAllowed("unpublish")) {
             $this->setValuesToDocument($page);
             try {
                 $page->save();
                 $this->_helper->json(array("success" => true));
             } catch (Exception $e) {
                 Logger::err($e);
                 $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
             }
         } else {
             if ($page->isAllowed("save")) {
                 $this->setValuesToDocument($page);
                 try {
                     $page->saveVersion();
                     $this->_helper->json(array("success" => true));
                 } catch (Exception $e) {
                     Logger::err($e);
                     $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
                 }
             }
         }
     }
     $this->_helper->json(false);
 }