<commit_before><?php

require_once(Config::get('CONTROLLER_DIR') . 'admin/admin_controller.php');

class CommonController extends AdminController
{

  /**
  * 言語設定変更
  */
  public function lang()
  {
    $request = Request::getInstance();

    // 言語の設定
    $lang = $request->get('lang');
    if ($language=Config::get('LANGUAGES.' . $lang)) {
      Cookie::set('lang', $lang);
    }

    // TOPへ戻す
    $url = Config::get('BASE_DIRECTORY');
    $device_name = App::getArgsDevice();
    if (!empty($device_name)) {
      $url .= '?' . $device_name;
    }
    $this->redirectBack($url);
  }

  /**
  * デバイス変更
  */
  public function device_change()
  {
    $request = Request::getInstance();

    // デバイスの設定
    $device_type = 0;
    $device = $request->get('device');
    switch ($device) {
      case 'pc': $device_type = Config::get('DEVICE_PC'); break;
      case 'm':
      case 'mb':  $device_type = Config::get('DEVICE_MB'); break;
      case 'sp': $device_type = Config::get('DEVICE_SP'); break;
      case 'tb': $device_type = Config::get('DEVICE_TB'); break;
      default:
        Cookie::set('device', null);
        $this->redirectBack(array('controller'=>'entries', 'action'=>'index'));
    }

    Cookie::set('device', $device_type);
    $this->redirectBack(array('controller'=>'entries', 'action'=>'index'));
  }

  /**
  * 初期表示ページ(ブログの設定よりリダイレクト)
  */
  public function initial()
  {
    $setting = Model::load('BlogSettings')->findByBlogId($this->getBlogId());
    switch($setting['start_page']){
      default:
      case Config::get('BLOG.START_PAGE.NOTICE'):
        $this->redirect(array('controller'=>'Common', 'action'=>'notice'));
        break ;

      case Config::get('BLOG.START_PAGE.ENTRY'):
        $this->redirect(array('controller'=>'Entries', 'action'=>'create'));
        break ;
    }
  }

  public function index()
  {
    return $this->initial();
  }

  /**
  * お知らせ一覧画面
  */
  public function notice()
  {
    $blog_id = $this->getBlogId();

    $comments_model = Model::load('Comments');
    $this->set('unread_count', $comments_model->getUnreadCount($blog_id));
    $this->set('unapproved_count', $comments_model->getUnapprovedCount($blog_id));
  }

  /**
  * インストール画面
  */<commit_msg>Fix: avoid notice error when $settings is null.<commit_after><?php

require_once(Config::get('CONTROLLER_DIR') . 'admin/admin_controller.php');

class CommonController extends AdminController
{

  /**
  * 言語設定変更
  */
  public function lang()
  {
    $request = Request::getInstance();

    // 言語の設定
    $lang = $request->get('lang');
    if ($language=Config::get('LANGUAGES.' . $lang)) {
      Cookie::set('lang', $lang);
    }

    // TOPへ戻す
    $url = Config::get('BASE_DIRECTORY');
    $device_name = App::getArgsDevice();
    if (!empty($device_name)) {
      $url .= '?' . $device_name;
    }
    $this->redirectBack($url);
  }

  /**
  * デバイス変更
  */
  public function device_change()
  {
    $request = Request::getInstance();

    // デバイスの設定
    $device_type = 0;
    $device = $request->get('device');
    switch ($device) {
      case 'pc': $device_type = Config::get('DEVICE_PC'); break;
      case 'm':
      case 'mb':  $device_type = Config::get('DEVICE_MB'); break;
      case 'sp': $device_type = Config::get('DEVICE_SP'); break;
      case 'tb': $device_type = Config::get('DEVICE_TB'); break;
      default:
        Cookie::set('device', null);
        $this->redirectBack(array('controller'=>'entries', 'action'=>'index'));
    }

    Cookie::set('device', $device_type);
    $this->redirectBack(array('controller'=>'entries', 'action'=>'index'));
  }

  /**
  * 初期表示ページ(ブログの設定よりリダイレクト)
  */
  public function initial()
  {
    $setting = Model::load('BlogSettings')->findByBlogId($this->getBlogId());
    if (is_array($setting)) {
      switch ($setting['start_page']) {
        default:
        case Config::get('BLOG.START_PAGE.NOTICE'):
          $this->redirect(array('controller' => 'Common', 'action' => 'notice'));
          break;

        case Config::get('BLOG.START_PAGE.ENTRY'):
          $this->redirect(array('controller' => 'Entries', 'action' => 'create'));
          break;
      }
    } else {
      $this->redirect(array('controller' => 'Common', 'action' => 'notice'));
    }
  }

  public function index()
  {
    return $this->initial();
  }

  /**
  * お知らせ一覧画面
  */
  public function notice()
  {
    $blog_id = $this->getBlogId();

    $comments_model = Model::load('Comments');
    $this->set('unread_count', $comments_model->getUnreadCount($blog_id));
    $this->set('unapproved_count', $comments_model->getUnapprovedCount($blog_id));
  }

  /**
  * インストール画面
  */
{'fraction_non_alphanumeric': 0.198013388037141, 'fraction_numerical': 0.0004318721658389117, 'mean_word_length': 3.2928637627432806, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 52, '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': '4141098', 'n_tokens_mistral': 1625, 'n_tokens_neox': 1596, 'n_words': 241}