/** 
  * 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;
 }