<commit_before><?php
/**
 * Theme model.
 *
 * Class to handle all theme rendering and generation.
 * @author <NAME> <<EMAIL>>
 */
class Theme
{
  private $theme, $themeDir, $themeDirWeb;

  public function __construct()
  {
    $this->theme = getConfig()->get('defaults')->theme;
    $behavior = getConfig()->get('behavior');
    $themeConfig = getConfig()->get('theme');
    if($behavior !== null && Utility::isMobile() && $behavior->useDefaultMobile == '1')
    {
      $this->theme = getConfig()->get('defaults')->theme;
      if(file_exists($mobileSettings = sprintf('%s/%s/config/settings-mobile.ini', getConfig()->get('paths')->themes, $this->getThemeName())))
        getConfig()->load($mobileSettings);
    }
    elseif($themeConfig !== null)
    {
      $this->theme = $themeConfig->name;
    }

    $this->themeDir = sprintf('%s/%s', getConfig()->get('paths')->themes, $this->theme);
    $this->themeDirWeb = str_replace(sprintf('%s/html', dirname(dirname(dirname(__FILE__)))), '', $this->themeDir);
  }

  public function asset($type, $filename = '')
  {
    $filename = "/{$filename}";
    switch($type)
    {
      case 'base':
        echo "{$this->themeDirWeb}{$filename}";
        break;
      case 'image':
        echo "{$this->themeDirWeb}/images{$filename}";
        break;
      case 'javascript':
        echo "{$this->themeDirWeb}/javascripts{$filename}";
        break;
      case 'stylesheet':
        echo "{$this->themeDirWeb}/stylesheets{$filename}";
        break;
      //
      case 'jquery':
        echo '/assets/javascripts/jquery-1.6.2.min.js';
        break;
      case 'util':
        echo '/assets/javascripts/openphoto-util.js';
        break;
    }
  }

  public function display($template, $params = null)
  {
    getTemplate()->display("{$this->themeDir}/templates/{$template}", $params);
  }

  public function fileExists($path)
  {
    return file_exists(sprintf('%s/templates/%s', $this->themeDir, $path));
  }

  public function get($template, $params = null)
  {
    return getTemplate()->get("{$this->themeDir}/templates/{$template}", $params);
  }

  public function getThemeName()
  {
    return $this->theme;
  }

  public function getThemes()
  {
    $dir = dir(getConfig()->get('paths')->themes);
    $dirs = array();
    while (($name = $dir->read()) !== false)
    {
      if(substr($name, 0, 1) == '.')
        continue;

      $dirs[] = $name;
    }
    return $dirs;
  }

  public function meta($page, $key, $write = true)
  {
    if(isset(getConfig()->get($page)->$key))
      return Utility::returnValue(getConfig()->get($page)->$key, $write);
    elseif(isset(getConfig()->get($page)->default))
      return Utility::returnValue(getConfig()->get($page)->default, $write);
    else
      return Utility::returnValue('', $write);
  }
}

/**
  * The public interface for instantiating a theme obect.
  *
  * @return object A theme object
  */
function getTheme($singleton = true)
{
  static $theme;
  if($singleton && !$theme)
  {
    $theme = new Theme();
    return $theme;
  }

  return new Theme();
}
<commit_msg>Fixing bug to defaultly use mobile theme if specified. Closes Gh-250<commit_after><?php
/**
 * Theme model.
 *
 * Class to handle all theme rendering and generation.
 * @author <NAME> <<EMAIL>>
 */
class Theme
{
  const themeDefault = 'default';
  private $theme, $themeDir, $themeDirWeb;

  public function __construct()
  {
    $this->theme = getConfig()->get('defaults')->theme;
    $behavior = getConfig()->get('behavior');
    $themeConfig = getConfig()->get('theme');
    if($behavior !== null && Utility::isMobile() && $behavior->useDefaultMobile == '1')
    {
      $this->theme = self::themeDefault;
      if(file_exists($mobileSettings = sprintf('%s/%s/config/settings-mobile.ini', getConfig()->get('paths')->themes, $this->getThemeName())))
        getConfig()->load($mobileSettings);
    }
    elseif($themeConfig !== null)
    {
      $this->theme = $themeConfig->name;
    }

    $this->themeDir = sprintf('%s/%s', getConfig()->get('paths')->themes, $this->theme);
    $this->themeDirWeb = str_replace(sprintf('%s/html', dirname(dirname(dirname(__FILE__)))), '', $this->themeDir);
  }

  public function asset($type, $filename = '')
  {
    $filename = "/{$filename}";
    switch($type)
    {
      case 'base':
        echo "{$this->themeDirWeb}{$filename}";
        break;
      case 'image':
        echo "{$this->themeDirWeb}/images{$filename}";
        break;
      case 'javascript':
        echo "{$this->themeDirWeb}/javascripts{$filename}";
        break;
      case 'stylesheet':
        echo "{$this->themeDirWeb}/stylesheets{$filename}";
        break;
      //
      case 'jquery':
        echo '/assets/javascripts/jquery-1.6.2.min.js';
        break;
      case 'util':
        echo '/assets/javascripts/openphoto-util.js';
        break;
    }
  }

  public function display($template, $params = null)
  {
    getTemplate()->display("{$this->themeDir}/templates/{$template}", $params);
  }

  public function fileExists($path)
  {
    return file_exists(sprintf('%s/templates/%s', $this->themeDir, $path));
  }

  public function get($template, $params = null)
  {
    return getTemplate()->get("{$this->themeDir}/templates/{$template}", $params);
  }

  public function getThemeName()
  {
    return $this->theme;
  }

  public function getThemes()
  {
    $dir = dir(getConfig()->get('paths')->themes);
    $dirs = array();
    while (($name = $dir->read()) !== false)
    {
      if(substr($name, 0, 1) == '.')
        continue;

      $dirs[] = $name;
    }
    return $dirs;
  }

  public function meta($page, $key, $write = true)
  {
    if(isset(getConfig()->get($page)->$key))
      return Utility::returnValue(getConfig()->get($page)->$key, $write);
    elseif(isset(getConfig()->get($page)->default))
      return Utility::returnValue(getConfig()->get($page)->default, $write);
    else
      return Utility::returnValue('', $write);
  }
}

/**
  * The public interface for instantiating a theme obect.
  *
  * @return object A theme object
  */
function getTheme($singleton = true)
{
  static $theme;
  if($singleton && !$theme)
  {
    $theme = new Theme();
    return $theme;
  }

  return new Theme();
}

{'fraction_non_alphanumeric': 0.19344473007712082, 'fraction_numerical': 0.002410025706940874, 'mean_word_length': 3.1417165668662674, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 91, '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': '4098108', 'n_tokens_mistral': 1984, 'n_tokens_neox': 1943, 'n_words': 377}