<commit_before><?php
/**
  * @package Module
  * @subpackage Admin
  */

/**
  * @package Module
  * @subpackage Admin
  */
class AdminWebModule extends WebModule {
  protected $id = 'admin';
  
  protected function initialize() {

  }
  
  /* submit values are affected by the _type specifiers */
  protected function prepareSubmitData($key)
  {
    $var = $this->getArg($key, array());
        
    if (!$type = $this->getArg('_type')) {
        error_log("Type data not found");
        return $var;
    }
    
    if (!is_array($var)) {
        $type = isset($type[$key]) ? $type[$key] : null;
        return $this->prepareSubmitValue($var, $type);
    } elseif (!isset($type[$key])) {
        error_log("Type data not found for $key");
        return $var;
    }
    
    $types = $type[$key];
    foreach ($types as $key=>$type) {
        if (is_array($type)) {
            foreach ($type as $_key=>$_type) {
                $value = isset($var[$key][$_key]) ? $var[$key][$_key] : null;
                $var[$key][$_key] = $this->prepareSubmitValue($value, $_type);
            }
        } else {
            $value = isset($var[$key]) ? $var[$key] : null;
            $var[$key] = $this->prepareSubmitValue($value, $type);
        }
    }
    
    return $var;    
  }
  

  protected function prepareSubmitValue($value, $type)
  {
    switch ($type)
    {
        case 'paragraph':
            //convert CRLF to LF, then CR to LF (i.e. normalize line endings)
            $value = is_null($value) ? '' : explode("\n\n", str_replace(array("\r\n","\r"), array("\n","\n"), $value));
            break;
        case 'boolean':
            $value = is_null($value) ? 0 : $value;
            break;
        case 'text':
            $value = is_null($value) ? '' : $value;
            break;
        default:
            $value = is_null($value) ? null : $value;
            break;
    }
    
    return $value;
 }
 
  protected function getSectionTitleForKey($key)
  {
     switch (strtolower($key))
     {
        case 'ga':
            return 'Google Analytics';
        default:
           return implode(" ", array_map("ucfirst", explode("_", strtolower($key))));
     }
     return $key;
  }

                             
  protected function getSiteItemForKey($section, $key, $value)
  {
    $item = array(
        'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))),
        'name'=>"siteData[$section][$key]",
        'typename'=>"siteData][$section][$key",
        'value'=>$value,
        'type'=>'text'
    );

    switch ($key)
    {
        default:
            if (preg_match("/_(DEBUG|ENABLED)$/", $key)) {
                $item['type'] = 'boolean';
            }
            break;
    }
    
    return $item;
  }
  
  protected function initializeForPage() {
        $this->addJQuery();
        switch ($this->page)
        {
             case 'module':
                $moduleID = $this->getArg('moduleID');
                if (empty($moduleID)) {
                    $this->redirectTo('modules');
                }

                $module = WebModule::factory($moduleID);
                $moduleData = $module->getModuleData();
                $moduleSections = array();
                
                if ($section = $this->getArg('section')) {
                    
                    if ($section=='feeds' && $module->hasFeeds()) {
                        if (strlen($this->getArg('removeFeed'))>0) {
                            $index = $this->getArg('removeFeed');
                            $module->removeFeed($index);
                        }

                        if ($this->getArg('addFeed')) {
                            $feedData = $this->getArg('addFeedData');
                            if (!$module->addFeed($feedData, $error)) {
                                $this->assign('errorMessage', $error);
                            }
                        }

                        $moduleData['feeds'] = $module->loadFeedData();
                        $this->assign('feedURL', $this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID,
                                'section'=>$section),false
                            ));
                        $this->assign('feedFields', $module->getFeedFields());
                    }
                
                    if (!isset($moduleData[$section])) {
                        $section = null;
                    }
                }

                if ($this->getArg('submit')) {
                    $merge = $this->getArg('merge', true);<commit_msg>show feeds section even if no feeds are present<commit_after><?php
/**
  * @package Module
  * @subpackage Admin
  */

/**
  * @package Module
  * @subpackage Admin
  */
class AdminWebModule extends WebModule {
  protected $id = 'admin';
  
  protected function initialize() {

  }
  
  /* submit values are affected by the _type specifiers */
  protected function prepareSubmitData($key)
  {
    $var = $this->getArg($key, array());
        
    if (!$type = $this->getArg('_type')) {
        error_log("Type data not found");
        return $var;
    }
    
    if (!is_array($var)) {
        $type = isset($type[$key]) ? $type[$key] : null;
        return $this->prepareSubmitValue($var, $type);
    } elseif (!isset($type[$key])) {
        error_log("Type data not found for $key");
        return $var;
    }
    
    $types = $type[$key];
    foreach ($types as $key=>$type) {
        if (is_array($type)) {
            foreach ($type as $_key=>$_type) {
                $value = isset($var[$key][$_key]) ? $var[$key][$_key] : null;
                $var[$key][$_key] = $this->prepareSubmitValue($value, $_type);
            }
        } else {
            $value = isset($var[$key]) ? $var[$key] : null;
            $var[$key] = $this->prepareSubmitValue($value, $type);
        }
    }
    
    return $var;    
  }
  

  protected function prepareSubmitValue($value, $type)
  {
    switch ($type)
    {
        case 'paragraph':
            //convert CRLF to LF, then CR to LF (i.e. normalize line endings)
            $value = is_null($value) ? '' : explode("\n\n", str_replace(array("\r\n","\r"), array("\n","\n"), $value));
            break;
        case 'boolean':
            $value = is_null($value) ? 0 : $value;
            break;
        case 'text':
            $value = is_null($value) ? '' : $value;
            break;
        default:
            $value = is_null($value) ? null : $value;
            break;
    }
    
    return $value;
 }
 
  protected function getSectionTitleForKey($key)
  {
     switch (strtolower($key))
     {
        case 'ga':
            return 'Google Analytics';
        default:
           return implode(" ", array_map("ucfirst", explode("_", strtolower($key))));
     }
     return $key;
  }

                             
  protected function getSiteItemForKey($section, $key, $value)
  {
    $item = array(
        'label'=>implode(" ", array_map("ucfirst", explode("_", strtolower($key)))),
        'name'=>"siteData[$section][$key]",
        'typename'=>"siteData][$section][$key",
        'value'=>$value,
        'type'=>'text'
    );

    switch ($key)
    {
        default:
            if (preg_match("/_(DEBUG|ENABLED)$/", $key)) {
                $item['type'] = 'boolean';
            }
            break;
    }
    
    return $item;
  }
  
  protected function initializeForPage() {
        $this->addJQuery();
        switch ($this->page)
        {
             case 'module':
                $moduleID = $this->getArg('moduleID');
                if (empty($moduleID)) {
                    $this->redirectTo('modules');
                }

                $module = WebModule::factory($moduleID);
                $moduleData = $module->getModuleData();
                $moduleSections = array();
                
                if ($section = $this->getArg('section')) {
                    
                    if ($section=='feeds' && $module->hasFeeds()) {
                        if (strlen($this->getArg('removeFeed'))>0) {
                            $index = $this->getArg('removeFeed');
                            $module->removeFeed($index);
                        }

                        if ($this->getArg('addFeed')) {
                            $feedData = $this->getArg('addFeedData');
                            if (!$module->addFeed($feedData, $error)) {
                                $this->assign('errorMessage', $error);
                            }
                        }

                        $moduleData['feeds'] = $module->loadFeedData();
                        if (!$moduleData['feeds']) {
                            $moduleData['feeds'] = array();
                        }
                        $this->assign('feedURL', $this->buildBreadcrumbURL('module', array(
                                'moduleID'=>$moduleID,
                                'section'=>$section),false
                            ));
                        $this->assign('feedFields', $module->getFeedFields());
                    } elseif (!isset($moduleData[$section])) {
                        $this->redirectTo('module', array('moduleID'=>$moduleID), false);
                    }
                }

                if ($this->getArg('submit')) {
                    $merge = $this->getArg('merge', true);
{'fraction_non_alphanumeric': 0.1613382899628253, 'fraction_numerical': 0.00042485395645246946, 'mean_word_length': 1.4831223628691983, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 77, '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': '6327356', 'n_tokens_mistral': 2651, 'n_tokens_neox': 2579, 'n_words': 490}