<commit_before><?php

class BasedmFrontActions extends dmFrontBaseActions
{
  
  public function executePage(dmWebRequest $request)
  {
    $slug = $request->getParameter('slug');

    $this->page = dmDb::table('DmPage')->findOneBySlug($slug);
    
    // the page does not exist
    if (!$this->page)
    {
      // if page_not_found_handler suggest a redirection
      if ($redirectionUrl = $this->context->get('page_not_found_handler')->getRedirection($slug))
      {
        return $this->redirect($redirectionUrl, 301);
      }
      
      // else use main.error404 page
      $this->page = dmDb::table('DmPage')->fetchError404();
    }
    
    if (
          // the site is not active and requires the view_site permission to be displayed
          (!dmConfig::get('site_active') && !$this->getUser()->can('view_site'))
          // the page is secured and requires authentication to be displayed
      ||  ($this->page->get('is_secure') && !$this->getUser()->isAuthenticated())
    )
    {
      // use main.login page
      $this->page = dmDb::table('DmPage')->fetchLogin();
    }
     
    return $this->renderPage();
  }
  
  public function executeError404(dmWebRequest $request)
  {
    $this->page = dmDb::table('DmPage')->fetchError404();
    
    return $this->renderPage();
  }
  
  public function executeLogin(dmWebRequest $request)
  {
    $this->page = dmDb::table('DmPage')->fetchLogin();
    
    return $this->renderPage();
  }
  
  public function executeSecure(dmWebRequest $request)
  {
    return $this->executeLogin($request);
  }
  
  protected function renderPage()
  {
    // share current page
    $this->context->setPage($this->page);
    
    if ($this->page->isModuleAction('main', 'error404'))
    {
      $this->response->setStatusCode(404); 
    }
    elseif($this->page->isModuleAction('main', 'login'))
    {
      $this->getResponse()->setStatusCode(401);
    }

    /*
     * BC : catch exceptions when getting the layout template
     * because Diem 5.0.0 < ALPHA6 doesn't have this field in database
     */
    try
    {
      $template = $this->page->getPageView()->getLayout()->get('template');
    }
    catch(Exception $e)
    {
      $template = 'page';
    }
    
    $this->setTemplate($template);
    
    $this->setLayout(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/layout'));

    $this->helper = $this->context->get('page_helper');
    
    $this->isEditMode = $this->getUser()->getIsEditMode();
    
    $this->launchDirectActions();
    
    return sfView::SUCCESS;
  }
  
  public function executeToAdmin(dmWebRequest $request)
  {<commit_msg>[Diem] fixed dmFront does not check if a user layout is available<commit_after><?php

class BasedmFrontActions extends dmFrontBaseActions
{
  
  public function executePage(dmWebRequest $request)
  {
    $slug = $request->getParameter('slug');

    $this->page = dmDb::table('DmPage')->findOneBySlug($slug);
    
    // the page does not exist
    if (!$this->page)
    {
      // if page_not_found_handler suggest a redirection
      if ($redirectionUrl = $this->context->get('page_not_found_handler')->getRedirection($slug))
      {
        return $this->redirect($redirectionUrl, 301);
      }
      
      // else use main.error404 page
      $this->page = dmDb::table('DmPage')->fetchError404();
    }
    
    if (
          // the site is not active and requires the view_site permission to be displayed
          (!dmConfig::get('site_active') && !$this->getUser()->can('view_site'))
          // the page is secured and requires authentication to be displayed
      ||  ($this->page->get('is_secure') && !$this->getUser()->isAuthenticated())
    )
    {
      // use main.login page
      $this->page = dmDb::table('DmPage')->fetchLogin();
    }
     
    return $this->renderPage();
  }
  
  public function executeError404(dmWebRequest $request)
  {
    $this->page = dmDb::table('DmPage')->fetchError404();
    
    return $this->renderPage();
  }
  
  public function executeLogin(dmWebRequest $request)
  {
    $this->page = dmDb::table('DmPage')->fetchLogin();
    
    return $this->renderPage();
  }
  
  public function executeSecure(dmWebRequest $request)
  {
    return $this->executeLogin($request);
  }
  
  protected function renderPage()
  {
    // share current page
    $this->context->setPage($this->page);
    
    if ($this->page->isModuleAction('main', 'error404'))
    {
      $this->response->setStatusCode(404); 
    }
    elseif($this->page->isModuleAction('main', 'login'))
    {
      $this->getResponse()->setStatusCode(401);
    }

    /*
     * BC : catch exceptions when getting the layout template
     * because Diem 5.0.0 < ALPHA6 doesn't have this field in database
     */
    try
    {
      $template = $this->page->getPageView()->getLayout()->get('template');
    }
    catch(Exception $e)
    {
      $template = 'page';
    }
    
    $this->setTemplate($template);
    
    $userLayout = dmProject::rootify('apps/front/modules/dmFront/templates/layout');
    if (file_exists($userLayout.'.php'))
    {
      $this->setLayout($userLayout);
    }
    else
    {
      $this->setLayout(dmOs::join(sfConfig::get('dm_front_dir'), 'modules/dmFront/templates/layout'));
    }

    $this->helper = $this->context->get('page_helper');
    
    $this->isEditMode = $this->getUser()->getIsEditMode();
    
    $this->launchDirectActions();
    
    return sfView::SUCCESS;
  }
  
  public function executeToAdmin(dmWebRequest $request)
  {
{'fraction_non_alphanumeric': 0.15867828612926652, 'fraction_numerical': 0.010167029774872912, 'mean_word_length': 2.893286219081272, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 104, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4903105', 'n_tokens_mistral': 1755, 'n_tokens_neox': 1707, 'n_words': 311}