<commit_before><?php

/**
 * Sitetree form.
 *
 * @package    sfCmsPlugin
 * @subpackage form
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class PluginSitetreeForm extends BaseSitetreeForm 
{
  protected $canAdmin;

  public function __construct($sitetree) 
  {
    $this->canAdmin   = sfContext::getInstance()->getUser()->hasCredential('site.admin');
    $this->canPublish = ($this->canAdmin || sfContext::getInstance()->getUser()->hasCredential('site.publish'));

    parent::__construct($sitetree);
  }
  
  public function setup() 
  {
    parent::setup();
    
    $culture = sfContext::getInstance()->getUser()->getCulture();
    $this->embedI18n(array($culture));
    $this->widgetSchema->setLabel($culture, '&nbsp;');
    
    foreach ($this->getStandardWidgets() as $name => $widget)
    {
      $this->widgetSchema[$name] = $widget;
    }

    foreach ($this->getStandardValidators() as $name => $val)
    {
      $this->validatorSchema[$name] = $val;
    }
    
    if (!$this->object->is_locked) 
    {
      $this->widgetSchema->setLabel('base_url', 'Url <em>*</em>');
      $this->widgetSchema->setLabel('target_module', 'Module <em>*</em>');
      $this->widgetSchema->setLabel('prepend_parent_url', 'Prepend parent URL');
      $this->widgetSchema->setLabel('is_core_navigation', 'Core navigation');
      
      if ($this->canAdmin)
      {
        $this->widgetSchema->setLabel('is_locked', 'Lock page');
        $this->widgetSchema->setHelp('is_locked', 'Prevent page from being deleted (whilst locked), or the important settings from being changed');
      }
    }
    
    $this->useFields(array($culture) + array_keys($this->getStandardWidgets()));
    
    if ($this->canPublish)
    {
      $this->widgetSchema->setLabel('is_active', 'Live');
    }
    
    $this->widgetSchema->setLabel('is_hidden', 'Hide from sitemap');
    
    $this->widgetSchema->setHelp('prepend_parent_url', 'should we prepend the parent\'s url to this one? e.g: /footer/terms or /terms (second is not prepended)');
    $this->widgetSchema->setHelp('route_name', 'This is for development purposes to uniquely identify the page');
    $this->widgetSchema->setHelp('is_hidden', 'The page will be created, but only accessible via a direct URL - useful for competitions for example');
    
    sfImagePoolUtil::addImageChooser($this);
    $this->widgetSchema->setHelp('sf_image_pool_ids', 'Select an image tagged with "sitetree" to represent the page');
  }
    
  /**
   * Get the available module names as an array in the form:
   *
   * @return array
   */
  public function getModuleNames() 
  {
    $moduleDefinitions = siteManager::getInstance()->getModuleDefinitions();
    $availableModules = siteManager::getInstance()->getAvailableModules();
    
    // get the names of all of the allowed modules
    $moduleNames = array('' => '&nbsp;');
    
    foreach ($availableModules as $module)
    {
      if (isset($moduleDefinitions[$module])) 
      {
        $moduleNames[$module] = $moduleDefinitions[$module]['name'];
      }
    }
    
    // order nicely
    asort($moduleNames);
    
    return $moduleNames;
  }
  
  public function getStandardWidgets() 
  {
    $modules = $this->getModuleNames();

    $fields = array(
      'id'                    => new sfWidgetFormInputHidden(),
      'site'                  => new sfWidgetFormInputHidden(),
      'base_url'              => new sfWidgetFormInput(),
      'prepend_parent_url'    => new sfWidgetFormInputCheckbox(),
      'target_module'         => new sfWidgetFormSelect(array('choices' => $modules)),
      'is_hidden'             => new sfWidgetFormInputCheckbox(),
      'is_core_navigation'    => new sfWidgetFormInputCheckbox(),
    );
    
    if ($this->canPublish)
    {
      $fields['is_active']    = new sfWidgetFormInputCheckbox();
    }
    
    if ($this->canAdmin) 
    {
      $fields['is_locked']    = new sfWidgetFormInputCheckbox();
    }
    
    return $fields;
  }
  
  public function getStandardValidators() 
  {
    $modules = $this->getModuleNames();
    
    $fields = array(
      'id'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'base_url'            => new sfValidatorAnd(array(
                                    new sfValidatorCallback(array('callback' => array($this, 'baseRouteValidatorCallback'))),
                                    new sfValidatorRegex(array(
                                        'pattern' => '/^[a-z0-9-_]+$/i',
                                        'required' => !$this->getObject()->getNode()->isRoot()
                                    ),
                                    array('invalid' => 'Invalid - can only contain a-z, 0-9, _ and -'))
                                 ), array('required' => !$this->getObject()->getNode()->isRoot())),
      'target_module'       => new sfValidatorChoice(array('choices' => array_keys($modules))),
      'is_hidden'           => new sfValidatorBoolean(array('empty_value' => false)),
      'is_core_navigation'  => new sfValidatorBoolean(array('empty_value' => false)),
      'prepend_parent_url'  => new sfValidatorBoolean(array('empty_value' => false)),
    );
    
    if ($this->canPublish)
    {
      $fields['is_active']   = new sfValidatorBoolean(array('empty_value' => false));
    }
    
    if ($this->canAdmin) 
    {
      $fields['is_locked']   = new sfValidatorBoolean(array('empty_value' => false));
    }
    
    return $fields;
  }
    
  public function baseRouteValidatorCallback($validator, $value) 
  {
    return strtolower(trim($value, '/'));
  }
}
<commit_msg>Adding propery<commit_after><?php

/**
 * Sitetree form.
 *
 * @package    sfCmsPlugin
 * @subpackage form
 * @author     <NAME> <<EMAIL>>
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
abstract class PluginSitetreeForm extends BaseSitetreeForm 
{
  protected $canAdmin;
  protected $canPublish;

  public function __construct($sitetree) 
  {
    $this->canAdmin   = sfContext::getInstance()->getUser()->hasCredential('site.admin');
    $this->canPublish = ($this->canAdmin || sfContext::getInstance()->getUser()->hasCredential('site.publish'));

    parent::__construct($sitetree);
  }
  
  public function setup() 
  {
    parent::setup();
    
    $culture = sfContext::getInstance()->getUser()->getCulture();
    $this->embedI18n(array($culture));
    $this->widgetSchema->setLabel($culture, '&nbsp;');
    
    foreach ($this->getStandardWidgets() as $name => $widget)
    {
      $this->widgetSchema[$name] = $widget;
    }

    foreach ($this->getStandardValidators() as $name => $val)
    {
      $this->validatorSchema[$name] = $val;
    }
    
    if (!$this->object->is_locked) 
    {
      $this->widgetSchema->setLabel('base_url', 'Url <em>*</em>');
      $this->widgetSchema->setLabel('target_module', 'Module <em>*</em>');
      $this->widgetSchema->setLabel('prepend_parent_url', 'Prepend parent URL');
      $this->widgetSchema->setLabel('is_core_navigation', 'Core navigation');
      
      if ($this->canAdmin)
      {
        $this->widgetSchema->setLabel('is_locked', 'Lock page');
        $this->widgetSchema->setHelp('is_locked', 'Prevent page from being deleted (whilst locked), or the important settings from being changed');
      }
    }
    
    $this->useFields(array($culture) + array_keys($this->getStandardWidgets()));
    
    if ($this->canPublish)
    {
      $this->widgetSchema->setLabel('is_active', 'Live');
    }
    
    $this->widgetSchema->setLabel('is_hidden', 'Hide from sitemap');
    
    $this->widgetSchema->setHelp('prepend_parent_url', 'should we prepend the parent\'s url to this one? e.g: /footer/terms or /terms (second is not prepended)');
    $this->widgetSchema->setHelp('route_name', 'This is for development purposes to uniquely identify the page');
    $this->widgetSchema->setHelp('is_hidden', 'The page will be created, but only accessible via a direct URL - useful for competitions for example');
    
    sfImagePoolUtil::addImageChooser($this);
    $this->widgetSchema->setHelp('sf_image_pool_ids', 'Select an image tagged with "sitetree" to represent the page');
  }
    
  /**
   * Get the available module names as an array in the form:
   *
   * @return array
   */
  public function getModuleNames() 
  {
    $moduleDefinitions = siteManager::getInstance()->getModuleDefinitions();
    $availableModules = siteManager::getInstance()->getAvailableModules();
    
    // get the names of all of the allowed modules
    $moduleNames = array('' => '&nbsp;');
    
    foreach ($availableModules as $module)
    {
      if (isset($moduleDefinitions[$module])) 
      {
        $moduleNames[$module] = $moduleDefinitions[$module]['name'];
      }
    }
    
    // order nicely
    asort($moduleNames);
    
    return $moduleNames;
  }
  
  public function getStandardWidgets() 
  {
    $modules = $this->getModuleNames();

    $fields = array(
      'id'                    => new sfWidgetFormInputHidden(),
      'site'                  => new sfWidgetFormInputHidden(),
      'base_url'              => new sfWidgetFormInput(),
      'prepend_parent_url'    => new sfWidgetFormInputCheckbox(),
      'target_module'         => new sfWidgetFormSelect(array('choices' => $modules)),
      'is_hidden'             => new sfWidgetFormInputCheckbox(),
      'is_core_navigation'    => new sfWidgetFormInputCheckbox(),
    );
    
    if ($this->canPublish)
    {
      $fields['is_active']    = new sfWidgetFormInputCheckbox();
    }
    
    if ($this->canAdmin) 
    {
      $fields['is_locked']    = new sfWidgetFormInputCheckbox();
    }
    
    return $fields;
  }
  
  public function getStandardValidators() 
  {
    $modules = $this->getModuleNames();
    
    $fields = array(
      'id'                  => new sfValidatorString(array('max_length' => 255, 'required' => false)),
      'base_url'            => new sfValidatorAnd(array(
                                    new sfValidatorCallback(array('callback' => array($this, 'baseRouteValidatorCallback'))),
                                    new sfValidatorRegex(array(
                                        'pattern' => '/^[a-z0-9-_]+$/i',
                                        'required' => !$this->getObject()->getNode()->isRoot()
                                    ),
                                    array('invalid' => 'Invalid - can only contain a-z, 0-9, _ and -'))
                                 ), array('required' => !$this->getObject()->getNode()->isRoot())),
      'target_module'       => new sfValidatorChoice(array('choices' => array_keys($modules))),
      'is_hidden'           => new sfValidatorBoolean(array('empty_value' => false)),
      'is_core_navigation'  => new sfValidatorBoolean(array('empty_value' => false)),
      'prepend_parent_url'  => new sfValidatorBoolean(array('empty_value' => false)),
    );
    
    if ($this->canPublish)
    {
      $fields['is_active']   = new sfValidatorBoolean(array('empty_value' => false));
    }
    
    if ($this->canAdmin) 
    {
      $fields['is_locked']   = new sfValidatorBoolean(array('empty_value' => false));
    }
    
    return $fields;
  }
    
  public function baseRouteValidatorCallback($validator, $value) 
  {
    return strtolower(trim($value, '/'));
  }
}

{'fraction_non_alphanumeric': 0.15216631726065688, 'fraction_numerical': 0.004891684136967156, 'mean_word_length': 2.6860914359304573, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 197, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4432628', 'n_tokens_mistral': 3416, 'n_tokens_neox': 3314, 'n_words': 641}