-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathComposerHelper.php
More file actions
139 lines (128 loc) · 3.38 KB
/
ComposerHelper.php
File metadata and controls
139 lines (128 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Composer helper
*
* @copyright Copyright 2014, NetCommons Project
* @author Kohei Teraguchi <kteraguchi@commonsnet.org>
* @link http://www.netcommons.org NetCommons Project
* @license http://www.netcommons.org/license.txt NetCommons License
*/
App::uses('AppHelper', 'View/Helper');
App::uses('File', 'Utility');
App::uses('CakePlugin', 'Core');
/**
* Composer helper
*
* @author Shohei Nakajima <nakajimashouhei@gmail.com>
* @package NetCommons\NetCommons\View\Helper
*/
class ComposerHelper extends AppHelper {
/**
* use helpers
*
* @var array
*/
public $helpers = array(
'Html'
);
/**
* Plugin composer data
*
* @var array
*/
private $__plugins;
/**
* Get the composer.json
*
* @param string $plugin Plugin path
* @return string|array Composer value
*/
private function __getComposer($plugin) {
$filePath = CakePlugin::path(Inflector::camelize($plugin)) . 'composer.json';
if (file_exists($filePath)) {
$file = new File($filePath);
$contents = $file->read();
$file->close();
$this->__plugins[$plugin] = json_decode($contents, true);
} else {
$this->__plugins[$plugin] = array();
}
}
/**
* composer.jsonからデータ取得
*
* @param string $plugin プラグインkey
* @param string $key Composerのkey
* @param mixed $default デフォルト値
* @return string|array Composerの値
*/
public function getComposer($plugin, $key = null, $default = null) {
if (! isset($this->__plugins[$plugin])) {
$this->__getComposer($plugin);
}
$composer = $this->__plugins[$plugin];
if (! is_null($key)) {
return Hash::get($composer, $key, $default);
} else {
return $composer;
}
}
/**
* Get the container size for layout
*
* @param string $plugin Plugin path
* @param array $options Option data
* @return string|array Composer value
*/
public function getAuthors($plugin, $options = array()) {
$authors = $this->getComposer($plugin, 'authors', array());
$options += array('useTag' => true);
if (! $options['useTag']) {
return $authors;
}
//$html = '<ul class="list-inline small frame-add-plugin">';
$html = '';
$html .= $this->Html->tag('li',
'<strong class="h4">' . __d('plugin_manager', 'Author(s)') . '</strong>',
array('class' => 'dropdown-header')
);
//$html .= $this->Html->tag('li', '', array('class' => 'divider'));
foreach ($authors as $author) {
$name = '';
if ($author['name'] === 'NetCommons Community') {
$author['name'] = __d('net_commons', 'NetCommons Community');
} else {
$author['name'] = __d($plugin, $author['name']);
}
if (isset($author['role']) && strtolower($author['role']) === 'developer') {
$author['name'] = h($author['name']) .
' <span class="small"><span class="text-danger">' .
__d('plugin_manager', '[Developer]') .
'</span></span>';
}
if (isset($author['homepage'])) {
$name .= $this->Html->link(
$author['name'],
$author['homepage'],
array('target' => '_blank', 'escapeTitle' => false)
);
} else {
$name .= h($author['name']);
}
$html .= $this->Html->tag('li', $name);
}
$html .= '</ul>';
return $html;
}
/**
* Get the container size for layout
*
* @param string $plugin Plugin path
* @return string|array Composer value
*/
public function getDescription($plugin) {
//$description = $this->getComposer($plugin, 'description');
$description = '';
return h(__d($plugin, $description));
}
}