Ejemplo n.º 1
0
 public function executeDisplayLinks()
 {
     $this->linksList = W3sPagePeer::getPagesOrderedByName();
     $oLanguage = W3sLanguagePeer::retrieveByPk($this->getRequestParameter('lang'));
     $this->language = $oLanguage->getLanguage();
     // 'italian';    . $idLanguage
 }
Ejemplo n.º 2
0
 public function executeSignout($request)
 {
     /* We need to be sure that user is authenticated because it can have more
      * sessions opened in several browsers ot browsers tabs
      */
     if ($this->getUser()->isAuthenticated()) {
         $idUser = $this->getUser()->getGuardUser()->getId();
         $this->getUser()->signOut();
         $operation = $request->getParameter('lang') . $request->getParameter('page');
         semaphore::deleteOperation($idUser, $operation);
     }
     $oPage = W3sPagePeer::retrieveByPk($this->getRequestParameter('page'));
     $oLanguage = W3sLanguagePeer::retrieveByPk($this->getRequestParameter('lang'));
     $this->getResponse()->setHttpHeader('X-JSON', '([["sPageUrl", "/' . strtolower($oLanguage->getLanguage()) . '/' . strtolower($oPage->getPageName()) . '.html"]])');
     return sfView::HEADER_ONLY;
 }
 /**
  * Renames the page
  */
 public function executeRename($request)
 {
     if ($request->hasParameter('idPage') && $request->hasParameter('newName')) {
         $page = W3sPagePeer::retrieveByPk($this->getRequestParameter('idPage'));
         if ($page != null) {
             $page->setPageName($this->getRequestParameter('newName'));
             $page->save();
             $fileManager = new w3sFileManager($this->getRequestParameter('curLang'), $this->getRequestParameter('curPage'));
             return $this->renderPartial('listPages', array('fileManager' => $fileManager));
         } else {
             $this->getResponse()->setStatusCode(404);
             return $this->renderText(w3sCommonFunctions::toI18n('The requested page does not exists anymore.'));
         }
     } else {
         $this->getResponse()->setStatusCode(404);
         return $this->renderText(w3sCommonFunctions::toI18n('One or more required parameter are missing.'));
     }
 }
Ejemplo n.º 4
0
 /**
  * Constructor.
  * 
  * @param int  The current language id
  * @param int  The current page id
  *
  */
 public function __construct($language, $page)
 {
     // When language is null, main language is retrieved
     if ($language == null) {
         $language = 'none';
     }
     // When page is null, home page is retrieved
     if ($page == null) {
         $page = 'none';
     }
     // Checks that the two parameters are integers values
     if ((int) $language == 0) {
         $oLanguage = $language != 'none' ? W3sLanguagePeer::getFromLanguageName($language) : W3sLanguagePeer::getMainLanguage();
     } else {
         $oLanguage = DbFinder::from('W3sLanguage')->findPk($language);
         //W3sLanguagePeer::getMainLanguage();
     }
     if ($oLanguage != null) {
         $this->idLanguage = $oLanguage->getId();
         $this->languageName = $oLanguage->getLanguage();
     } else {
         $this->idLanguage = -1;
         $this->languageName = 'none';
     }
     if ((int) $page == 0) {
         $oPage = $page != 'none' ? W3sPagePeer::getFromPageName($page) : W3sPagePeer::getHomePage();
     } else {
         $oPage = DbFinder::from('W3sPage')->findPk($page);
     }
     if ($oPage != null) {
         $this->idPage = $oPage->getId();
         $this->pageName = $oPage->getPageName();
     } else {
         $this->idPage = -1;
         $this->pageName = 'none';
     }
     if ($this->idPage != -1) {
         $this->setTemplateInfo($this->idPage);
     }
 }
Ejemplo n.º 5
0
?>

<div id="w3s_signin">
  <form action="<?php 
echo url_for('@sf_guard_signin');
?>
" method="post">
    <table style="padding: 4px">
      <?php 
echo $form;
?>
      <tr>
        <td></td>
        <td>
          <?php 
$oPage = W3sPagePeer::retrieveByPk($sf_request->getParameter('page'));
if ($oPage != null) {
    $pageName = $oPage->getPageName();
    $oLanguage = W3sLanguagePeer::retrieveByPk($sf_request->getParameter('lang'));
    $languageName = $oLanguage != null ? $oLanguage->getLanguage() : '';
} else {
    $pageName = '';
    $languageName = '';
}
/* In the test enviroment we need a real submit button. In others
 * enviroments the button to perform the login is a link to a
 * javascript function.
 */
if (sfConfig::get('sf_environment') == 'test' || !$isAjax) {
    echo submit_tag(__('signin'));
} else {
Ejemplo n.º 6
0
 /**
  * Adds a page and inserts default contents where content is available
  *
  * @param  string The name of the page to save
  * @param  int The id of the related group
  * 
  * @return int 0 - The save operation failed
  *             1 - Success
  *             2 - Page already exists
  */
 public function add($pageName, $idGroup)
 {
     try {
         $pageName = trim($pageName);
         if ($pageName != '') {
             // Checks if page already exists
             $pageName = w3sCommonFunctions::slugify($pageName);
             $oPage = W3sPagePeer::getFromPageName($pageName);
             if ($oPage == null) {
                 if ($idGroup != null) {
                     if (DbFinder::from('W3sGroup')->findPK($idGroup) != null) {
                         $con = Propel::getConnection();
                         // We assure that all the operations W3StudioCMS makes will be successfully done
                         $rollBack = false;
                         $con = w3sPropelWorkaround::beginTransaction($con);
                         // Save page
                         $this->page->setGroupId($idGroup);
                         $this->page->setPageName($pageName);
                         $result = $this->page->save();
                         if ($this->page->isModified() && $result == 0) {
                             $rollBack = true;
                         } else {
                             // Getting the page's id inserted yet
                             $idPage = $this->page->getId();
                             $attributes = w3sTemplateEngine::retrieveTemplateAttributesFromPage($this->page);
                             $templateContents = w3sCommonFunctions::readFileContents(sprintf("%1\$s%2\$s%3\$s%2\$sdata%2\$s%4\$s.yml", sfConfig::get('app_w3s_web_themes_dir'), DIRECTORY_SEPARATOR, $attributes["projectName"], $attributes["templateName"]));
                             $defaultContents = sfYaml::load($templateContents);
                             $defaultContents = $defaultContents["W3sContent"];
                             // Inserts the contents for every language
                             $oLanguages = DbFinder::from('W3sLanguage')->where('ToDelete', '0')->find();
                             foreach ($oLanguages as $language) {
                                 $idLanguage = $language->getId();
                                 // Cycles the slot's three repeated contents status
                                 for ($i = 0; $i <= 2; $i++) {
                                     // Retrieve the slots with the $i status for the page's template
                                     $slots = W3sSlotPeer::getTemplateSlots($attributes["idTemplate"], $i);
                                     foreach ($slots as $slot) {
                                         // Retrieves a content that belongs to the current slot
                                         $baseContent = DbFinder::from('W3sContent')->where('SlotId', $slot->getId())->where('LanguageId', $idLanguage)->findOne();
                                         // When no repeated content, the content is simply copied
                                         if ($slot->getRepeatedContents() == 0 || $baseContent == null) {
                                             $slotName = $slot->getSlotName();
                                             foreach ($defaultContents as $defaultContent) {
                                                 if ($defaultContent['slotId'] == $slotName) {
                                                     $content = w3sContentManagerFactory::create($defaultContent["contentTypeId"]);
                                                     $contentValue = array("PageId" => $idPage, "SlotId" => $slot->getId(), "LanguageId" => $idLanguage, "GroupId" => $idGroup, "Content" => $defaultContent["content"], "ContentTypeId" => $defaultContent["contentTypeId"], "ContentPosition" => $defaultContent["contentPosition"], "Edited" => 1);
                                                     $content->setUpdateForeigns(false);
                                                     $content->add($contentValue);
                                                 }
                                             }
                                         } else {
                                             // Retrive base page, if any, but NOT current one
                                             $pageFinder = DbFinder::from('W3sPage')->whereToDelete(0)->whereIdNot($idPage);
                                             if ($basePage = $pageFinder->findOne()) {
                                                 // Retrieve a content that belongs to the current slot
                                                 $baseContents = DbFinder::from('W3sContent')->whereToDelete(0)->relatedTo($basePage)->relatedTo($slot)->whereLanguageId($idLanguage)->find();
                                                 foreach ($baseContents as $baseContent) {
                                                     // Creates a new content from the base content
                                                     $newContent = w3sContentManagerFactory::create($baseContent->getContentTypeId(), $baseContent);
                                                     // Converts the content in array and changes the page's id and the group's id
                                                     $contentValue = W3sContentPeer::contentToArray($newContent->getContent());
                                                     $contentValue["PageId"] = $idPage;
                                                     $contentValue["GroupId"] = $idGroup;
                                                     // Updates the content and copies the related elements
                                                     $newContent->setUpdateForeigns(false);
                                                     $newContent->add($contentValue);
                                                     w3sContentManagerMenuPeer::copyRelatedElements($baseContent->getId(), $newContent->getContent()->getId());
                                                 }
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                         if (!$rollBack) {
                             // Everything was fine so W3StudioCMS commits to database
                             $con->commit();
                             $result = 1;
                         } else {
                             // Something was wrong so W3StudioCMS aborts the operation and restores to previous status
                             w3sPropelWorkaround::rollBack($con);
                             $result = 0;
                         }
                     } else {
                         $result = 16;
                     }
                 } else {
                     $result = 8;
                 }
             } else {
                 $result = 2;
             }
         } else {
             $result = 4;
         }
     } catch (Exception $e) {
         w3sPropelWorkaround::rollBack($con);
         $result = 0;
         sfContext::getInstance()->getLogger()->info("W3StudioCMS - An Error occoured while addin a language. The exception message is:\n" . $e->getMessage() . "\n");
     }
     return $result;
 }
 public static function linkConverter($content, $mode = 'editor')
 {
     $text = $content->getContent();
     $oLanguage = $content->getW3sLanguage();
     // Retrieves all the links, the attributes and the link content
     preg_match_all('/\\<a(.*?)\\>(.*?)\\<\\/a\\>?/', $text, $result);
     $i = 0;
     foreach ($result[1] as $linkAttributes) {
         // Examines one attribute a time and retrieves href and class attributes if exists
         $href = '';
         $class = '';
         $linkAttributes = explode(' ', $linkAttributes);
         foreach ($linkAttributes as $attribute) {
             if (strpos($attribute, 'href') !== false) {
                 $href = self::getTagAttribute($attribute, 'href');
             }
             if (strpos($attribute, 'class') !== false) {
                 $class = self::getTagAttribute($attribute, 'class');
             }
         }
         $currentPageName = self::getPageNameFromLink($href);
         $classValue = !empty($class) ? 'class=' . $class : '';
         // Checks if the examined link is internal and in this case W3StudioCMS converts it
         $oPage = W3sPagePeer::getFromPageName($currentPageName);
         if ($oPage != null) {
             $anchorPos = strpos($href, '#');
             $anchor = $anchorPos !== false ? substr($href, $anchorPos, strlen($href) - $anchorPos) : '';
             /*
             $symfonyLink = ($mode == 'preview') ?
               link_to_function($result[2][$i], 'W3sTemplate.loadPreviewPage('. $content->getLanguageId() . ', ' . $oPage->getId() . ')', $classValue)
                                                 :
               '<a href="/' . $oLanguage->getLanguage() . '/' . $currentPageName . '.html' . $anchor . '"' . $classValue . '>' . $result[2][$i] . '</a>';
             */
             $symfonyLink = $mode == 'preview' ? sprintf('<a href="#" onclick="W3sTemplate.loadPreviewPage(%s, %s); return false;" %s>%s</a>', $content->getLanguageId(), $oPage->getId(), $classValue, $result[2][$i]) : sprintf('<a href="/%s/%s.html%s" %s>%s</a>', $oLanguage->getLanguage(), $currentPageName, $anchor, $classValue, $result[2][$i]);
             $text = str_replace($result[0][$i], $symfonyLink, $text);
         } else {
             if ($mode == 'preview') {
                 $symfonyLink = sprintf('<a href="#" onclick="alert(\'%s\'); return false;" %s>%s</a>', w3sCommonFunctions::toI18n('This page is not linked to an internal link. In preview only internal links can be tested'), $classValue, $result[2][$i]);
                 $text = str_replace($result[0][$i], $symfonyLink, $text);
             } else {
                 if (substr($href, 0, 1) != '/' && strpos($href, 'http://') === false && strpos($href, 'mailto:') === false && $href != '#') {
                     $text = str_replace($href, 'http://' . $href, $text);
                 }
             }
         }
         $i++;
     }
     // target="_blank" has been deprecated, so it must be replaced with a javascript function
     $text = str_replace('target="_blank"', 'onclick="window.open(this.href); return false;"', $text);
     return $text;
 }
 /** 
  * Deletes from the database all the deleted languages, pages and contents 
  * during the edit phase
  * 
  * @return bool The operation result
  */
 private function updateDb()
 {
     try {
         $con = Propel::getConnection();
         $con = w3sPropelWorkaround::beginTransaction($con);
         // Deletes the languages
         $c = new Criteria();
         $c->add(W3sLanguagePeer::TO_DELETE, 1);
         W3sLanguagePeer::doDelete($c);
         // Deletes the groups
         $c = new Criteria();
         $c->add(W3sGroupPeer::TO_DELETE, 1);
         W3sGroupPeer::doDelete($c);
         // Deletes the pages
         $c = new Criteria();
         $c->add(W3sPagePeer::TO_DELETE, 1);
         W3sPagePeer::doDelete($c);
         // Deletes the contents
         $c = new Criteria();
         $c->add(W3sContentPeer::TO_DELETE, 1);
         W3sContentPeer::doDelete($c);
         $con->commit();
         return true;
     } catch (Exception $e) {
         w3sPropelWorkaround::rollBack($con);
         sfContext::getInstance()->getLogger()->info('W3StudioCMS - ' . $this->setExceptionError($e->getMessage()));
         return false;
     }
 }