You are here

public function csl_locale::get_locale in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_locale::get_locale()
  2. 7.2 modules/CiteProc/CSL.inc \csl_locale::get_locale()

File

modules/CiteProc/CSL.inc, line 2138
CiteProc-PHP.

Class

csl_locale

Code

public function get_locale($type, $arg1, $arg2 = NULL, $arg3 = NULL) {
  switch ($type) {
    case 'term':
      $term = '';
      $form = $arg2 ? " and @form='{$arg2}'" : '';
      $plural = $arg3 ? "/cs:{$arg3}" : '';
      if ($arg2 == 'verb' || $arg2 == 'verb-short') {
        $plural = '';
      }
      if ($this->style_locale) {
        $term = @$this->style_locale
          ->xpath("//locale[@xml:lang='en']/terms/term[@name='{$arg1}'{$form}]{$plural}");
        if (!$term) {
          $term = @$this->style_locale
            ->xpath("//locale/terms/term[@name='{$arg1}'{$form}]{$plural}");
        }
      }
      if (!$term) {
        $term = $this->locale
          ->xpath("//cs:term[@name='{$arg1}'{$form}]{$plural}");
      }
      if (isset($term[0])) {
        if (isset($arg3) && isset($term[0]->{$arg3})) {
          return (string) $term[0]->{$arg3};
        }
        if (!isset($arg3) && isset($term[0]->single)) {
          return (string) $term[0]->single;
        }
        return (string) $term[0];
      }
      break;
    case 'date_option':
      $attribs = array();
      if ($this->style_locale) {
        $date_part = $this->style_locale
          ->xpath("//date[@form='{$arg1}']/date-part[@name='{$arg2}']");
      }
      if (!isset($date_part)) {
        $date_part = $this->locale
          ->xpath("//cs:date[@form='{$arg1}']/cs:date-part[@name='{$arg2}']");
      }
      if (isset($date_part)) {
        foreach (${$date_part}
          ->attributes() as $name => $value) {
          $attribs[$name] = (string) $value;
        }
      }
      return $attribs;
      break;
    case 'date_options':
      $options = array();
      if ($this->style_locale) {
        $options = $this->style_locale
          ->xpath("//locale[@xml:lang='en']/date[@form='{$arg1}']");
        if (!$options) {
          $options = $this->style_locale
            ->xpath("//locale/date[@form='{$arg1}']");
        }
      }
      if (!$options) {
        $options = $this->locale
          ->xpath("//cs:date[@form='{$arg1}']");
      }
      if (isset($options[0])) {
        return $options[0];
      }
      break;
    case 'style_option':
      $attribs = array();
      if ($this->style_locale) {
        $option = $this->style_locale
          ->xpath("//locale[@xml:lang='en']/style-options[@{$arg1}]");
        if (!$option) {
          $option = $this->style_locale
            ->xpath("//locale/style-options[@{$arg1}]");
        }
      }
      if (isset($option) && !empty($option)) {
        $attribs = $option[0]
          ->attributes();
      }
      if (empty($attribs)) {
        $option = $this->locale
          ->xpath("//cs:style-options[@{$arg1}]");
      }
      foreach ($option[0]
        ->attributes() as $name => $value) {
        if ($name == $arg1) {
          return (string) $value;
        }
      }
      break;
  }
}