/**
  * Update the related contents.
  * 
  * @return bool
  *
  */
 public function update($params = array())
 {
     $result = true;
     // Retrieves the slot
     $slot = DbFinder::from('W3sSlot')->findPK($this->baseContentAttributes["SlotId"]);
     /*
     		echo $this->baseContentAttributes["SlotId"];
     		print_r($slot);
     		echo "<br><br>";*/
     // Checks if the slot has contents to update
     if ($slot->getRepeatedContents() > 0) {
         $this->slotName = $slot->getSlotName();
         $pagesFinder = DbFinder::from('W3sPage')->where('ToDelete', '0')->where('Id', '!=', $this->baseContentAttributes["PageId"]);
         if ($slot->getRepeatedContents() == 1) {
             $pagesFinder = $pagesFinder->where('GroupId', $this->baseContentAttributes["GroupId"]);
         }
         $pages = $pagesFinder->find();
         // Checks for all the website's pages
         $contents = array();
         foreach ($pages as $targetPage) {
             $this->targetPageId = $targetPage->getId();
             // This function is declared in the derived classes
             if ($this->updateForeignContent() != 1) {
                 $result = false;
                 break;
             }
         }
     }
     return $result;
 }
 /**
  * Format content to display the image on the web page, using the image's properties
  * edited by user at runtime. Overrides the same function of w3sContentManager  
  *
  * @param      array The array with contents.
  * 
  * @return     array The array with contents formatted.
  */
 protected function formatContent($contentValues)
 {
     // Cycles all properties passed from the serialized form and creates an
     // array with the following path: array[property_name] = array[property_value]
     $formattedProperties = array();
     $properties = explode('&', urldecode($contentValues["Content"]));
     foreach ($properties as $property) {
         $propertyValues = explode('=', $property);
         $formattedProperties[$propertyValues[0]] = $propertyValues[1];
     }
     // build src attribute
     $src = $formattedProperties['w3s_ppt_image'];
     $image_name = basename($formattedProperties['w3s_ppt_image']);
     if ($image_name == $formattedProperties['w3s_ppt_image']) {
         $src = sfConfig::get('app_absolute_images_path') . $src;
     }
     // Creates the image
     $image = sprintf('<img src="%s" alt="%s" title="%s" width="%s" height="%s" />', $src, $formattedProperties['w3s_ppt_alt_text'], $formattedProperties['w3s_ppt_title_text'], $formattedProperties['w3s_ppt_width'], $formattedProperties['w3s_ppt_height']);
     // Check for a link
     if ($formattedProperties['w3s_ppt_int_link'] != 0) {
         // If internal link the page's id is passed, so the page name is retrieved from the db
         $page = DbFinder::from('W3sPage')->findPK($formattedProperties['w3s_ppt_int_link']);
         $link = $page->getPageName() . '.html';
     } elseif ($formattedProperties['w3s_ppt_ext_link'] != '') {
         $link = $formattedProperties['w3s_ppt_ext_link'];
     } else {
         $link = null;
     }
     if ($link != null) {
         $image = sprintf('<a href="%s">%s</a>', $link, $image);
     }
     // Updates the Content
     $contentValues["Content"] = $image;
     return $contentValues;
 }
 /**
  * @see sfTask
  */
 protected function execute($arguments = array(), $options = array())
 {
     if (!class_exists('DbFinder')) {
         throw new Exception('sfCombine expects DbFinder to call combined asset file');
     }
     // initialize database manager
     $databaseManager = new sfDatabaseManager($this->configuration);
     $flag = true;
     if (function_exists('apc_store') && ini_get('apc.enabled')) {
         $cache = new sfAPCCache();
         if (!ini_get('apc.enable_cli')) {
             $this->logSection('combine', 'Check apc.enabled_cli in your ini file', null, 'ERROR');
             $flag = false;
         }
     } else {
         $cache = new sfFileCache(array('cache_dir' => sfConfig::get('sf_cache_dir') . '/combiners'));
     }
     if ($flag) {
         $results = DbFinder::from('sfCombine')->find();
         foreach ($results as $result) {
             $cache->remove($result->getAssetsKey());
         }
         $this->logSection('combine', 'Cleanup cache complete', null, 'INFO');
         $nbAssets = DbFinder::from('sfCombine')->delete();
         $this->logSection('combine', sprintf('Cleanup database complete (%d rows deleted)', $nbAssets), null, 'INFO');
     }
 }
 /**
  * Retrieves the content that corresponds to the current content on the target page.
  * 
  * @return object The finded content
  *
  */
 protected function getForeignContent()
 {
     // Retrieves the slot where the same content of the base content is placed.
     // This because when working at site level the slots have the same name
     // but not the same id.
     $currentSlot = DbFinder::from('W3sSlot')->join('W3sSlot.TemplateId', 'W3sTemplate.Id', 'inner join')->join('W3sTemplate.Id', 'W3sGroup.TemplateId', 'inner join')->join('W3sGroup.Id', 'W3sPage.GroupId', 'inner join')->where('W3sPage.Id', $this->targetPageId)->where('SlotName', $this->slotName)->findOne();
     // Current slot can be null if there is a page that has a different template
     // from the one assigned to the page we are working on. In this case the
     // returned value for the $foreignContent is null.
     if ($currentSlot != null) {
         // Updates the SlotId value with the foreign content's value
         $this->baseContentAttributes["SlotId"] = $currentSlot->getId();
         // Retrieves the content that matchs text and position and returns it
         $foreignContent = DbFinder::from('W3sContent')->where('LanguageId', $this->baseContentAttributes["LanguageId"])->where('PageId', $this->targetPageId)->where('SlotId', $currentSlot->getId())->where('Content', $this->baseContentAttributes["Content"])->where('ContentPosition', $this->baseContentAttributes["ContentPosition"])->where('ToDelete', '0')->findOne();
         // When a content is not find using the text and position as keys,
         // tries to retrieve the content that matchs only the text
         if ($foreignContent == null) {
             $foreignContent = DbFinder::from('W3sContent')->where('LanguageId', $this->baseContentAttributes["LanguageId"])->where('PageId', $this->targetPageId)->where('SlotId', $currentSlot->getId())->where('Content', $this->baseContentAttributes["Content"])->where('ToDelete', '0')->findOne();
         }
         // When a content is not find using only the text as key,
         // tries to retrieve the content that matchs only the position
         if ($foreignContent == null) {
             $foreignContent = DbFinder::from('W3sContent')->where('LanguageId', $this->baseContentAttributes["LanguageId"])->where('PageId', $this->targetPageId)->where('SlotId', $currentSlot->getId())->where('ContentPosition', $this->baseContentAttributes["ContentPosition"])->where('ToDelete', '0')->findOne();
         }
     } else {
         $foreignContent = false;
     }
     return $foreignContent;
 }
 public function renderPages()
 {
     $i = 0;
     $result = '';
     $pagesList = DbFinder::from('W3sPage')->with('W3sGroup')->orderBy('PageName', 'ASC')->where('ToDelete', '0')->find();
     foreach ($pagesList as $page) {
         $idPage = $page->getId();
         $class = $i % 2 ? "w3s_white_row" : "w3s_yellow_row";
         if ($this->idLanguage . $idPage == $this->currentPage) {
             $class .= '_active';
         }
         $c = new Criteria();
         $c->add(W3sContentPeer::EDITED, 1);
         $edited = $page->countW3sContents($c);
         if ($this->idLanguage . $idPage != $this->currentPage) {
             $changePageFunction = 'InteractiveMenu.hide();W3sTemplate.loadEditorPage(' . $this->idLanguage . ', ' . $idPage . ');';
             $renamePageFunction = '$(\'w3s_page_name_' . $idPage . '\').style.display=\'none\';$(\'w3s_page_name_editor_' . $idPage . '\').style.display=\'block\';';
         } else {
             $changePageFunction = '';
             $renamePageFunction = '';
         }
         $result .= sprintf($this->rowSkeleton, $this->idLanguage . $idPage, $class, $idPage, link_to_function(w3sCommonFunctions::setStringMaxWidth($page->getPageName(), 20), $changePageFunction), $idPage, $this->drawPageEditor($page), link_to_function(w3sCommonFunctions::setStringMaxWidth($page->getW3sGroup()->getGroupName(), 14), $changePageFunction, 'style="color:#FF9900;"'), $edited > 0 ? image_tag(sfConfig::get('app_w3s_web_skin_images_dir') . '/control_panel/button_edited.gif') : '&nbsp;', link_to_function(image_tag(sfConfig::get('app_w3s_web_skin_images_dir') . '/control_panel/button_edit.gif', 'alt=' . __('Rename current page') . ' size=14x14'), $renamePageFunction), $this->idLanguage . $idPage != $this->currentPage ? link_to_function(image_tag(sfConfig::get('app_w3s_web_skin_images_dir') . '/control_panel/button_delete.gif', 'alt=' . __('Delete current page') . ' size=14x14'), 'W3sPage.remove(' . $idPage . ', \'' . __('If you delete this page, W3Studio will also delete all contents and metatags related with it: do you want to continue with deleting?') . '\')') : image_tag(sfConfig::get('app_w3s_web_skin_images_dir') . '/control_panel/button_delete_disabled.gif'));
         $i++;
     }
     return $result;
 }
 public function render()
 {
     $result = '';
     $page = DbFinder::from('W3sPage')->with('W3sTemplate', 'W3sProject')->leftJoin('W3sGroup')->leftJoin('W3sTemplate')->leftJoin('W3sProject')->findPK($this->idPage);
     $slots = W3sSlotPeer::getTemplateSlots($page->getW3sGroup()->getTemplateId());
     $i = 0;
     foreach ($slots as $slot) {
         $idSlot = $slot->getId();
         $class = $i / 2 == intval($i / 2) ? "w3s_white_row" : "w3s_blue_row";
         switch ($slot->getRepeatedContents()) {
             case 0:
                 $repeatedColor = 'green';
                 $repeatedAlt = __('This contents is not repeated through pages');
                 break;
             case 1:
                 $repeatedColor = 'orange';
                 $repeatedAlt = __('This contents is repeated at group level');
                 break;
             case 2:
                 $repeatedColor = 'blue';
                 $repeatedAlt = __('This contents is repeated at site level');
                 break;
         }
         $result .= sprintf($this->rowSkeleton, $this->idLanguage . $idSlot, $class, $idSlot, link_to_function($slot->getSlotName(), 'W3sControlPanel.showRepeatedContentsForm(' . $idSlot . ');', 'onmouseover="W3sControlPanel.highlightSlot(\'' . $slot->getSlotName() . '\', ' . $slot->getRepeatedContents() . ')"'), image_tag(sfConfig::get('app_w3s_web_skin_images_dir') . '/control_panel/button_slot_' . $repeatedColor . '.jpg', 'title=' . $repeatedAlt . ' size=14x14'));
         $i++;
     }
     return sprintf('<div id="w3s_slot_list">%s</div>', $result);
 }
 /**
  * Copies the menu links for the sourceContent to the targetContent
  *  
  * @parameter  int The id of the source content
  * @parameter  int The id of the target content
  * 
  * @return     bool false - The save operation has failed
  *                  true  - The save operation has correctly done 
  */
 public static function copyRelatedElements($sourceContent, $targetContent)
 {
     $bRollBack = false;
     $con = Propel::getConnection();
     $con = w3sPropelWorkaround::beginTransaction($con);
     // Deletes all the target menus
     $targetMenus = W3sMenuElementPeer::getContentMenu($targetContent);
     foreach ($targetMenus as $targetMenu) {
         $targetMenu->delete();
     }
     // Retrieves the menu rows related to source content
     $sourceMenus = DbFinder::from('W3sMenuElement')->where('contentId', $sourceContent)->orderBy('position')->find();
     foreach ($sourceMenus as $sourceMenu) {
         $oTargetMenu = new W3sMenuElement();
         $contentValues = array("ContentId" => $targetContent, "PageId" => $sourceMenu->getPageId(), "Link" => $sourceMenu->getLink(), "ExternalLink" => $sourceMenu->getExternalLink(), "Image" => $sourceMenu->getImage(), "RolloverImage" => $sourceMenu->getRolloverImage(), "Position" => $sourceMenu->getPosition());
         $oTargetMenu->fromArray($contentValues);
         // Saves
         $result = $oTargetMenu->save();
         if ($oTargetMenu->isModified() && $result == 0) {
             $bRollBack = true;
             break;
         }
     }
     if (!$bRollBack) {
         // Everything was fine so W3StudioCMS commits to database
         $con->commit();
         $result = true;
     } else {
         // Something was wrong so W3StudioCMS aborts the operation and restores to previous status
         w3sPropelWorkaround::rollBack($con);
         $result = false;
     }
     return $result;
 }
 protected function execute($arguments = array(), $options = array())
 {
     // initialize the database connection
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     $nbAssets = DbFinder::from('sfCombine')->delete();
     sfProcessCache::clear();
 }
Exemple #9
0
 /**
  * Retrieves all the slot rows related to a template
  *  
  * @parameter  int The id of the related template
  * 
  * @return     obj The related slot rows. Null if it doesn't exists
  */
 public static function getTemplateSlots($idTemplate, $repeated = -1)
 {
     $slots = DbFinder::from('W3sSlot')->where('TemplateId', $idTemplate);
     if ($repeated != -1) {
         $slots->where('RepeatedContents', $repeated);
     }
     return $slots->find();
 }
 public function executeSignin($request)
 {
     $this->isAjax = $request->getHttpHeader('X_REQUESTED_WITH') == 'XMLHttpRequest' ? true : false;
     $language = $request->getParameter('lang') == null ? DbFinder::from('W3sLanguage')->where('mainLanguage', 1)->findOne()->getId() : $request->getParameter('lang');
     $page = $request->getParameter('page') == null ? DbFinder::from('W3sPage')->where('isHome', 1)->findOne()->getId() : $request->getParameter('page');
     $defaults = array('lang' => $language, 'page' => $page);
     $this->form = new sfGuardFormW3studioCmsSignin($defaults);
 }
 public function executeFeed()
 {
     /** @var sfWebRequest **/
     $request = $this->getContext()->getRequest();
     $IdType = $this->getRequestParameter('IdType', null);
     $id = $this->getRequestParameter('id', null);
     //Build the title
     $title = "Metadata Registry Change History";
     $filter = false;
     switch ($IdType) {
         //ElementSet :: (Schema)Element  :: (Schema)ElementProperty
         //Schema     :: SchemaProperty :: SchemaPropertyElement
         case "schema_property_element_id":
             /** @var SchemaPropertyElement **/
             $element = DbFinder::from('SchemaPropertyElement')->findPk($id);
             if ($element) {
                 /** @var SchemaProperty **/
                 $property = $element->getSchemaPropertyRelatedBySchemaPropertyId();
                 $title .= " for Property: '" . $element->getProfileProperty()->getLabel();
                 if ($property) {
                     $title .= "' of Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'";
                 }
             }
             $filter = true;
             break;
         case "schema_property_id":
             /** @var SchemaProperty **/
             $property = DbFinder::from('SchemaProperty')->findPk($id);
             if ($property) {
                 $title .= " for Element: '" . $property->getLabel() . "' in Element Set: '" . $property->getSchema()->getName() . "'";
             }
             $filter = true;
             break;
         case "schema_id":
             /** @var Schema **/
             $schema = DbFinder::from('Schema')->findPk($id);
             if ($schema) {
                 $title .= " for Element Set: '" . $schema->getName() . "'";
             }
             $filter = true;
             break;
         default:
             //the whole shebang
             $title .= " for all Element Sets";
             break;
     }
     $column = sfInflector::camelize($IdType);
     //default limit to 100 if not set in config
     $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100));
     $finder = DbFinder::from('SchemaPropertyElementHistory')->orderBy('SchemaPropertyElementHistory.CreatedAt', 'desc')->join('SchemaPropertyElementHistory.SchemaPropertyElementId', 'SchemaPropertyElement.Id', 'left join')->join('SchemaProperty', 'left join')->join('Schema', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('ProfileProperty', 'left join')->with('Schema', 'ProfileProperty', 'User', 'Status', 'SchemaProperty');
     if ($filter) {
         $finder = $finder->where('SchemaPropertyElementHistory.' . $column, $id);
     }
     $finder = $finder->find($limit);
     $this->setTemplate('feed');
     $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId')));
     return;
 }
Exemple #12
0
 /**
  * Returns the web-site's home page row
  *
  * @return     obj The page row
  */
 public static function getHomePage()
 {
     /*
         $c = new Criteria();
         $c->add(self::IS_HOME, 1);
         $c->add(self::TO_DELETE, '0');
     
         return self::doSelectOne($c);*/
     return DbFinder::from('W3sPage')->where('IsHome', '1')->where('ToDelete', '0')->findOne();
 }
 /**
  * rss and atom feeds
  *
  * @return return_type
  */
 public function executeFeed()
 {
     /** @var sfWebRequest **/
     $request = $this->getContext()->getRequest();
     $IdType = $this->getRequestParameter('IdType', null);
     $id = $this->getRequestParameter('id', null);
     //Build the title
     $title = "Metadata Registry Change History";
     $filter = false;
     switch ($IdType) {
         case "property_id":
             /** @var ConceptProperty **/
             $conceptProperty = ConceptPropertyPeer::retrieveByPK($id);
             if ($conceptProperty) {
                 $vocabularyname = $conceptProperty->getVocabulary() ? $conceptProperty->getVocabulary()->getName() : "?";
                 $title .= " for Property: '" . $conceptProperty->getProfileProperty()->getName() . "' of Concept: '" . $conceptProperty->getConceptRelatedByConceptId()->getPrefLabel() . "' in Vocabulary: '" . $vocabularyname . "'";
             }
             $filter = true;
             break;
         case "concept_id":
             /** @var Concept **/
             $concept = DbFinder::from('Concept')->findPk($id);
             if ($concept) {
                 $title .= " for Concept: '" . $concept->getPrefLabel() . "' in Vocabulary: '" . $concept->getVocabulary()->getName() . "'";
             }
             $filter = true;
             break;
         case "vocabulary_id":
             /** @var Vocabulary **/
             $vocab = DbFinder::from('Vocabulary')->findPk($id);
             if ($vocab) {
                 $title .= " for Vocabulary: '" . $vocab->getName() . "'";
             }
             $filter = true;
             break;
         default:
             //the whole shebang
             $title .= " for all Vocabularies";
             break;
     }
     //special rule for property_id
     $column = "property_id" == $IdType ? "ConceptPropertyId" : sfInflector::camelize($IdType);
     //default limit to 100 if not set in config
     $limit = $request->getParameter('nb', sfConfig::get('app_frontend_feed_count', 100));
     $finder = DbFinder::from('ConceptPropertyHistory')->orderBy('ConceptPropertyHistory.CreatedAt', 'desc')->join('ConceptProperty', 'left join')->join('Concept', 'left join')->join('Vocabulary', 'left join')->join('Status', 'left join')->join('User', 'left join')->join('SkosProperty', 'left join')->with('Vocabulary', 'SkosProperty', 'User', 'Status', 'ConceptProperty', 'Concept');
     if ($filter) {
         $finder = $finder->where('ConceptPropertyHistory.' . $column, $id);
     }
     $finder = $finder->find($limit);
     $this->setTemplate('feed');
     $this->feed = sfFeedPeer::createFromObjects($finder, array('format' => $request->getParameter('format', 'atom1'), 'link' => $request->getUriPrefix() . $request->getPathInfo(), 'feedUrl' => $request->getUriPrefix() . $request->getPathInfo(), 'title' => htmlentities($title), 'methods' => array('authorEmail' => '', 'link' => 'getFeedUniqueId')));
     return;
 }
 public function executeToggleComment()
 {
     $post = DbFinder::from('sfSimpleBlogPost')->findPk($this->getRequestParameter('id'));
     $this->forward404Unless($post);
     $post->setAllowComments(!$post->getAllowComments());
     $post->save();
     if ($referer = $this->getRequest()->getReferer()) {
         $this->redirect($referer);
     } else {
         $this->redirect('sfSimpleBlogPostAdmin/list');
     }
 }
 public function getFinder($key)
 {
     if (!array_key_exists($key, $this->finders)) {
         $options = $this->getModelOptions($key);
         $finder = DbFinder::from($options['model']);
         if (isset($options['finder_methods'])) {
             foreach ($options['finder_methods'] as $finder_methods) {
                 $finder->{$finder_methods}();
             }
         }
         $this->finders[$key] = $finder;
     }
     return $this->finders[$key];
 }
 public function setTagsAsString($tagString)
 {
     DbFinder::from('sfSimpleBlogTag')->relatedTo($this)->delete();
     $tags = explode(' ', $tagString);
     foreach ($tags as $tag) {
         if (!$tag) {
             continue;
         }
         $tagObject = new sfSimpleBlogTag();
         $tagObject->setTag($tag);
         $tagObject->setSfBlogPostId($this->getId());
         $tagObject->setsfSimpleBlogPost($this);
         $tagObject->save();
     }
 }
 public function executeTogglePublish()
 {
     $comment = DbFinder::from('sfSimpleBlogComment')->findPk($this->getRequestParameter('id'));
     $this->forward404Unless($comment);
     $comment->setIsModerated(!$comment->getIsModerated());
     $comment->save();
     if ($this->getRequestParameter('from_email') == 1) {
         $this->comment = $comment;
         return sfView::SUCCESS;
     }
     if ($referer = $this->getRequest()->getReferer()) {
         $this->redirect($referer);
     } else {
         $this->redirect('sfSimpleBlogCommentAdmin/list');
     }
 }
 /**
  * Draws the languages' table as a horizontal toolbar. This function assumes that
  * every image that represents a language has the same name of the language. Override
  * this function if you want to change this behaviour
  *   
  * @return string
  *
  */
 public function drawLanguages($mode)
 {
     $pageName = $this->content->getW3sPage()->getPageName();
     // Cycles all the site's languages
     $languages = DbFinder::from('W3sLanguage')->find();
     $buttons = '';
     foreach ($languages as $language) {
         // Set the buttons
         if ($mode == 'preview') {
             $buttons .= sprintf('<td><a href="#" onclick="W3sTemplate.loadPreviewPage(\'%s\', %s, %s)">%s</a></td>', sfContext::getInstance()->getController()->genUrl('webEditor/preview'), $language->getId(), $this->content->getPageId(), $language->getLanguage());
         } else {
             $buttons .= sprintf('<td><a href="/%s/%s.html">%s</a></td>', $language->getLanguage(), $pageName, $language->getLanguage());
         }
     }
     // Draws the languages
     return sprintf('<table><tr>%s</tr></table>', $buttons);
 }
 /**
  * Deletes the group that is selected into the groups' combobox
  */
 public function executeDelete()
 {
     if ($this->getRequest()->hasParameter('idGroup')) {
         $result = 0;
         $group = DbFinder::from('W3sGroup')->findPK($this->getRequestParameter('idGroup'));
         if (!empty($group)) {
             $groupManager = new w3sGroupManager($group);
             $result = $groupManager->delete();
         }
         if ($result != 1) {
             $this->getResponse()->setStatusCode(404);
         }
     } else {
         $result = 2;
         $this->getResponse()->setStatusCode(404);
     }
     return $this->renderPartial('delete', array('result' => $result));
 }
 /**
  * Update the related contents.
  * 
  * @return bool
  *
  */
 public function update($params = array())
 {
     $result = true;
     $slot = DbFinder::from('W3sSlot')->findPK($this->baseContentAttributes["SlotId"]);
     $this->slotName = $slot->getSlotName();
     $pagesFinder = DbFinder::from('W3sPage')->where('ToDelete', '0')->where('GroupId', $this->baseContentAttributes["GroupId"]);
     $pages = $pagesFinder->find();
     // Checks for all the website's pages
     $contents = array();
     foreach ($pages as $targetPage) {
         $this->targetPageId = $targetPage->getId();
         // This function is declared in the derived classes
         if ($this->updateForeignContent($params) != 1) {
             $result = false;
             break;
         }
     }
     return $result;
 }
 /**
  * Deletes the page
  */
 public function executeDelete($request)
 {
     if ($request->hasParameter('idPage') && $request->hasParameter('curLang') && $request->hasParameter('curPage')) {
         $result = 0;
         $page = DbFinder::from('W3sPage')->findPK($this->getRequestParameter('idPage'));
         if ($page != null) {
             $pageManager = new w3sPageManager($page);
             $pageManager->delete();
             $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.'));
     }
 }
 /** 
  * Publish all the website's pages
  */
 public function publish()
 {
     if ($this->updateDb()) {
         // Deletes the old directory with the previous published version
         w3sCommonFunctions::clearDirectory(sfConfig::get('app_w3s_web_published_dir'), array('.svn'));
         // Retrieves all the website's languages and pages from the database
         $languages = DbFinder::from('W3sLanguage')->find();
         $pages = DbFinder::from('W3sPage')->with('W3sTemplate', 'W3sProject')->leftJoin('W3sGroup')->leftJoin('W3sTemplate')->leftJoin('W3sProject')->find();
         // Cycles all the website's languages
         foreach ($languages as $language) {
             // Creates the directory for the lanugage if doesn't exists
             if (!is_dir(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage())) {
                 mkdir(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage());
             }
             // Cycles all the website's pages
             foreach ($pages as $page) {
                 // Retrieves the information needed to publish every single page
                 $pageContents = '';
                 $templateInfo = self::retrieveTemplateAttributesFromPage($page);
                 $pageContents = w3sCommonFunctions::readFileContents(self::getTemplateFile($templateInfo["projectName"], $templateInfo["templateName"]));
                 $this->idTemplate = $templateInfo["idTemplate"];
                 // Renders ther page
                 $slotContents = $this->getSlotContents($language->getId(), $page->getId());
                 foreach ($slotContents as $slot) {
                     $contents = $this->drawSlot($slot);
                     $pageContents = preg_replace('/\\<\\?php.*?include_slot\\(\'' . $slot['slotName'] . '\'\\).*?\\?\\>/', $contents, $pageContents);
                     /*$pageContents = str_replace('<?php include_slot(\'' . $slot['slotName'] . '\')?>', $contents, $pageContents);*/
                 }
                 // Renders the W3StudioCMS Copyright button. Please do not remove. See the function
                 // declaration to learn the best way to implement it in your web site.
                 // Thank you
                 $pageContents = $this->renderCopyright($pageContents);
                 // Writes the page
                 $handle = fopen(sfConfig::get('app_w3s_web_published_dir') . '/' . $language->getLanguage() . '/' . $page->getPageName() . '.php', "w");
                 fwrite($handle, $pageContents);
                 fclose($handle);
             }
         }
     } else {
         return 0;
     }
     return 1;
 }
Exemple #23
0
 public function executeSignin($request)
 {
     $user = $this->getUser();
     if ($user->isAuthenticated()) {
         return $this->redirect('@homepage');
     }
     if ($request->isMethod('post')) {
         $this->isAjax = $request->getHttpHeader('X_REQUESTED_WITH') == 'XMLHttpRequest' ? true : false;
         $defaults = array('lang' => $request->getParameter('lang'), 'page' => $request->getParameter('page'));
         $this->form = new sfGuardFormW3studioCmsSignin($defaults);
         $this->form->bind($request->getParameter('signin'));
         if ($this->form->isValid()) {
             $values = $this->form->getValues();
             $this->getUser()->signin($values['user']);
             $signinUrl = sfConfig::get('app_sf_guard_plugin_success_signin_url', $user->getReferer($request->getReferer()));
             if ($this->isAjax) {
                 return sfView::NONE;
             } else {
                 if ((int) $values['lang'] > 0 && (int) $values['page'] > 0) {
                     $language = DbFinder::from('W3sLanguage')->findPK($values['lang']);
                     $page = DbFinder::from('W3sPage')->findPK($values['page']);
                     if ($language == null) {
                         $language = DbFinder::from('W3sLanguage')->where('mainLanguage', 1)->findOne();
                     }
                     if ($page == null) {
                         $page = DbFinder::from('W3sPage')->where('isHome', 1)->findOne();
                     }
                     $languageName = $language->getLanguage();
                     $pageName = $page->getPageName();
                 } else {
                     $languageName = $values['lang'];
                     $pageName = $values['page'];
                 }
                 return $this->redirect(sprintf('/W3studioCms/%s/%s.html', $languageName, $pageName));
             }
         }
     }
 }
 /**
  * Retrieve the content of the assets corresponding to a hash
  *
  * @param string $key Key to a list of asset files in the `sf_combine` table
  *
  * @return array list ($file_path => $file_content) of the assets
  */
 protected function getContents($key)
 {
     $asset_include = '';
     $combine = DbFinder::from('sfCombine')->where('AssetsKey', $key)->findOne();
     if (!$combine) {
         throw new Exception('Calling non-existent combined asset file: ' . $key);
     }
     $contents = array();
     foreach ($combine->getFiles() as $file) {
         $filePath = $this->getAssetPath($file);
         $include = @file_get_contents(sfConfig::get('sf_web_dir') . $filePath);
         if ($include === false) {
             // maybe we are looking for a file under $symfony_data_dir/web/sf ?
             $include = @file_get_contents(sfConfig::get('sf_symfony_data_dir') . '/web' . $filePath);
             if ($include === false) {
                 sfContext::getInstance()->getLogger()->err('Can not open ' . sfConfig::get('sf_web_dir') . $filePath . ' for merging');
             }
         }
         if ($include) {
             $contents[$file] = $include;
         }
     }
     return $contents;
 }
 public function executeLastArticleTitle(sfWebRequest $request)
 {
     $this->blog_article_list = DbFinder::from('BlogArticle')->orderBy('CreatedAt', 'desc')->find();
 }
 /**
  * Executes delete action
  *
  */
 public function executeDelete($request)
 {
     if ($request->hasParameter('idLanguage')) {
         $language = DbFinder::from('W3sLanguage')->findPK($this->getRequestParameter('idLanguage'));
         if ($language != null) {
             $language = new w3sLanguageManager($language);
             $result = $language->delete();
         } else {
             $result = 4;
         }
     } else {
         $result = 8;
     }
     if ($result != 1) {
         $this->getResponse()->setStatusCode(404);
     }
     return $this->renderPartial('delete', array('result' => $result));
 }
$article1->save();
$article2 = new Article();
$article2->setTitle('foo2');
$article2->save();

$finder = DbFinder::from('Article')->useCache($cache, 10);
           $finder->where('Title', 'foo1')->findOne(); // normal query
$article = $finder->where('Title', 'foo1')->findOne(); // cached query
$t->isa_ok($article, 'Article', 'Cached finder queries return Model objects');
$t->is($article->getId(), $article1->getId(), 'find() finder queries can be cached');
      $finder->where('Title', 'foo1')->count(); // normal query
$nb = $finder->where('Title', 'foo1')->count(); // cached query
$t->is($nb, 1, 'count() finder queries can be cached');

$cache->clear();

$finder = DbFinder::from('Article')->useCache($cache, 10);
           $finder->where('Title', 'foo1')->limit(1)->find(); // normal query
$article = $finder->where('Title', 'foo1')->findOne();        // cached query
$t->isa_ok($article, 'Article', 'Cached queries return the correct result type');

$t->diag('useCache(true)');

$cache->clear();

$finder = DbFinder::from('Article')->useCache(true, 10);
$finder->where('Title', 'foo1')->limit(1);
$key = $finder->getUniqueIdentifier();
$t->is($cache->get($key), null, 'No cache is set until the query is written');
$finder->find();
$t->isnt($cache->get($key), null, 'useCache(true) automatically selects available cache backend');
 public function executeList(sfWebRequest $request)
 {
     $this->blog_link_list = DbFinder::from('BlogLink')->orderBy('Name', 'asc')->find();
 }
 /**
  * Changes the content's position.
  * 
  * @param array An array with the id of contents that belongs to the new slot
  * @param int optional The content that is leaving the slot. When null the condition
  * 						is skipped
  * 
  */
 protected function changeContentsPosition($newSlotContents, $leavingContentId = null)
 {
     $bResult = true;
     $position = 1;
     foreach ($newSlotContents as $contentId) {
         // Skips the content position change when the slot loses the content.
         // In the other two cases, this operation is always performed
         if ($leavingContentId == null || $contentId != $leavingContentId) {
             $content = DbFinder::from('W3sContent')->findPK($contentId);
             $contentManager = w3sContentManagerFactory::create($content->getContentTypeId(), $content);
             $params = array("ContentPosition" => $position);
             $result = $contentManager->edit($params);
             if ($contentManager->getContent()->isModified() && $result == 0) {
                 $bResult = false;
                 break;
             }
             $contentManager = null;
             $content = null;
             $position++;
         }
     }
     return $bResult;
 }
 public function executeTagList()
 {
     $this->tags = DbFinder::from('sfSimpleBlogTag')->findAllWithCount();
 }