Beispiel #1
0
 /**
  * @param ContentBlock[] $blocks
  * @param Url $oldUrl
  * @param Url $newUrl
  * @return ContentBlock[] blocks with refactored links
  */
 public function refactorLinks($blocks, $oldUrl, $newUrl)
 {
     foreach ($blocks as $block) {
         /** @var \simple_html_dom $dom */
         $dom = HtmlDomParser::str_get_html($block->getContent());
         $domLinks = $dom->find('a');
         foreach ($domLinks as $domLink) {
             if ($this->checkSimilarity($domLink->getAttribute('href'), "/" . $oldUrl->getUrl())) {
                 $domLink->setAttribute('href', $this->newUrlString($domLink->getAttribute('href'), $newUrl->getUrl()));
             }
         }
         $block->setContent($dom);
     }
     return $blocks;
 }
Beispiel #2
0
 /**
  * @DynamicRoute /{string}
  * @param $shortUrl
  * @throws Error
  */
 function dynamicRouteTest($shortUrl)
 {
     $bean = Url::findUrl($shortUrl);
     if (!$bean) {
         throw new Error('The request URL is not exists', 404);
     } else {
         header('Location: ' . $bean->url);
     }
 }
 /**
  * @param Url $url
  * @return UrlDataObject
  */
 public function mapToDataObject(Url $url)
 {
     $urlDataObject = new UrlDataObject();
     $urlDataObject->id = $url->getId();
     $urlDataObject->userId = $url->getUserId();
     $urlDataObject->url = $url->getUrl();
     $urlDataObject->title = $url->getTitle();
     $urlDataObject->description = $url->getDescription();
     $urlDataObject->created = $url->getCreated()->format('c');
     $urlDataObject->updated = $url->getUpdated()->format('c');
     return $urlDataObject;
 }
Beispiel #4
0
 public function redirect()
 {
     $requestPath = Request::getRequestPath();
     $requestPath = ltrim($requestPath, '/');
     $bean = Url::findUrl($requestPath);
     if (!$bean) {
         throw new Error('The request URL is not exists', 404);
     } else {
         header('Location: ' . $bean->url);
     }
 }
 public function linkRefactoring(Application $app, Request $request)
 {
     $data = $request->get('refactoringBlocks');
     try {
         /** @var \Model\Url $oldUrl */
         $oldUrl = $app['em']->find('\\Model\\Url', $request->get('oldUrl'));
     } catch (Expcetion $e) {
         $app['monolog']->addError($e->getMessage());
         return new Response($app['admin.message_composer']->exceptionMessage($e), 500);
     }
     if (!isset($oldUrl) || is_null($oldUrl)) {
         return new Response($app['admin.message_composer']->failureMessage("Url to be refactored does not exist"), 400);
     }
     $newUrl = new Url();
     $newUrl->setUrl($request->get('newUrl'));
     $blockIds = array();
     foreach ($data as $blockId => $val) {
         $blockIds[] = $blockId;
     }
     $blocks = $app['em']->getRepository('\\Model\\ContentBlock')->findBy(array('id' => $blockIds));
     $lass = new LinkAssistant();
     try {
         $updatedBlocks = $lass->refactorLinks($blocks, $oldUrl, $newUrl);
         //Saving blocks
         $app['em']->beginTransaction();
         foreach ($updatedBlocks as $block) {
             $app['em']->merge($block);
         }
         //Update url row with new url refactored
         $oldUrl->setUrl($newUrl->getUrl());
         $app['em']->merge($oldUrl);
         $app['em']->flush();
         $app['em']->commit();
     } catch (\Exception $e) {
         $app['em']->rollback();
         $app['monolog']->addError($e->getMessage());
         return new Response($app['admin.message_composer']->exceptionMessage($e), 500);
     }
     return new Response($app['admin.message_composer']->successMessage(), 200);
 }
 /**
  * @param $em \Doctrine\ORM\EntityManager
  * @param $data array
  * @param null $pageid int
  * @return int Id of processed page
  */
 protected function insertUpdateProcessing($em, $data, $pageid = null)
 {
     $update = !is_null($pageid);
     if ($update) {
         $page = $em->find('Model\\Page', $pageid);
     } else {
         $page = new Page();
     }
     if ($update) {
         $deleteurl = $em->createQueryBuilder()->delete()->from('Model\\Url', "url")->where("url.page=" . $page->getId())->getQuery();
         $deletepageblock = $em->createQueryBuilder()->delete()->from('Model\\PageBlock', "pb")->where("pb.page=" . $page->getId())->getQuery();
         $deleteurl->execute();
         $deletepageblock->execute();
     }
     $page->setName($data['name']);
     $page->setDescription($data['description']);
     $page->setTitle($data['title']);
     $page->setPublished(!is_null($data['published']));
     $page->setPublic(!is_null($data['public']));
     $language = $em->find('Model\\Language', $data['language']);
     $page->setLanguage($language);
     //Url insertion
     foreach ($data['url'] as $urlstring) {
         if (strlen($urlstring) > 2) {
             $url = new Url();
             $url->setUrl($urlstring);
             $page->addUrl($url);
         }
     }
     if (!$update) {
         $em->persist($page);
         $em->flush();
     }
     //Processing Blocks
     for ($i = 0; $i < count($data['block']['id']); $i++) {
         $blockid = $data['block']['id'][$i];
         //If block is new and content is empty, skip the block
         //Iterates over remaining blocks
         if (!($blockid == 0 && strlen($data['block']['content'][$i]) == 0)) {
             $isContentBlock = isset($data['block']['content'][$i]) && strlen($data['block']['content'][$i]) > 0;
             if ($blockid == 0) {
                 //Insert new block
                 $block = new \Model\ContentBlock();
             } else {
                 //Update existing block
                 if ($isContentBlock) {
                     $block = $em->find('Model\\ContentBlock', $blockid);
                 } else {
                     $block = $em->find('Model\\Block', $blockid);
                 }
             }
             if (is_null($block)) {
                 print "IS CONTENT BLOCK ->" . $isContentBlock . "\n";
                 print $data['block']['content'][$i];
                 print "BLOCK ID -> " . $blockid;
             }
             //Sets block properties
             $block->setName($data['block']['name'][$i]);
             $block->setDescription($data['block']['description'][$i]);
             $block->setBlockStyleClassName($data['block']['style'][$i]);
             $block->setBgurl($data['block']['bckurl'][$i]);
             $block->setBgred(intval($data['block']['bckred'][$i]));
             $block->setBggreen(intval($data['block']['bckgreen'][$i]));
             $block->setBgblue(intval($data['block']['bckblue'][$i]));
             $block->setBgopacity(floatval($data['block']['bckopacity'][$i]));
             $bgrepeatx = !(strlen($data['block']['bckrepeatx'][$i]) <= 0 || $data['block']['bckrepeatx'][$i] == 'false');
             $bgrepeaty = !(strlen($data['block']['bckrepeaty'][$i]) <= 0 || $data['block']['bckrepeaty'][$i] == 'false');
             $block->setBgrepeatx($bgrepeatx);
             $block->setBgrepeaty($bgrepeaty);
             $block->setBgsize($data['block']['bcksize'][$i]);
             // If is set content field, this block is a content block
             // If content is not set, I can work directly with block object
             if ($isContentBlock) {
                 $block->setContent($data['block']['content'][$i]);
             }
             if ($blockid == 0) {
                 $em->persist($block);
             } else {
                 $em->merge($block);
             }
             $em->flush();
             //Adding block to page
             $page->addBlock($block, $i);
         }
     }
     if ($update) {
         $em->merge($page);
     } else {
         $em->persist($page);
     }
     $em->flush();
     return $page->getId();
 }
 /**
  * @param Url $url
  * @param string $edit_link
  * @return Template
  */
 public function buildUrlListEntry(Url $url, $edit_link)
 {
     $urlListEntry = $this->templateBuilder->createTemplate();
     $urlListEntry->loadFile('urlListEntry.html')->addPlaceHolder('id', $url->getId())->addPlaceHolder('url', $url->getUrl())->addPlaceHolder('title', $url->getTitle())->addPlaceHolder('description', $url->getDescription())->addPlaceHolder('updated', $url->getUpdated()->format('d.m.Y'))->addPlaceHolder('edit_link', $edit_link);
     return $urlListEntry;
 }