Open Journal Systems  3.3.0
StyleSheet.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2016 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
10 namespace Seboettg\CiteProc;
11 
13 
23 {
24 
35  public static function loadStyleSheet($styleName)
36  {
37  $stylesPath = self::vendorPath()."/citation-style-language/styles-distribution/";
38  return file_get_contents($stylesPath.$styleName.'.csl');
39  }
40 
48  public static function loadLocales($langKey)
49  {
50  $data = null;
51  $localesPath = self::vendorPath()."/citation-style-language/locales/";
52  $localeFile = $localesPath."locales-".$langKey.'.xml';
53  if (file_exists($localeFile)) {
54  $data = file_get_contents($localeFile);
55  } else {
56  $metadata = self::loadLocalesMetadata();
57  if (!empty($metadata->{'primary-dialects'}->{$langKey})) {
58  $data = file_get_contents(
59  $localesPath."locales-".$metadata->{'primary-dialects'}->{$langKey}.'.xml'
60  );
61  }
62  }
63 
64  return $data;
65  }
66 
71  public static function loadLocalesMetadata()
72  {
73  $localesMetadataPath = self::vendorPath()."/citation-style-language/locales/locales.json";
74  return json_decode(file_get_contents($localesMetadataPath));
75  }
76 
81  private static function vendorPath()
82  {
83  include_once realpath(__DIR__.'/../').'/vendorPath.php';
84  if (!($vendorPath = vendorPath())) {
85  // @codeCoverageIgnoreStart
86  throw new CiteProcException('vendor path not found. Use composer to initialize your project');
87  // @codeCoverageIgnoreEnd
88  }
89  return $vendorPath;
90  }
91 }
Seboettg\CiteProc
Definition: CiteProc.php:10
Seboettg\CiteProc\StyleSheet\loadStyleSheet
static loadStyleSheet($styleName)
Definition: StyleSheet.php:35
Seboettg\CiteProc\StyleSheet\loadLocales
static loadLocales($langKey)
Definition: StyleSheet.php:48
Seboettg\CiteProc\Exception\CiteProcException
Definition: CiteProcException.php:20
Seboettg\CiteProc\StyleSheet
Definition: StyleSheet.php:22
Seboettg\CiteProc\StyleSheet\loadLocalesMetadata
static loadLocalesMetadata()
Definition: StyleSheet.php:71