-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathviews.php
More file actions
208 lines (170 loc) · 5.47 KB
/
Copy pathviews.php
File metadata and controls
208 lines (170 loc) · 5.47 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<?php namespace Feather;
use URI;
use URL;
use Str;
use HTML;
use View;
use Asset;
use Event;
use Blade;
use Bundle;
use Session;
/*
|--------------------------------------------------------------------------
| View Bootstrapping
|--------------------------------------------------------------------------
*/
Asset::container('theme')->bundle('feather/themes/' . $feather['config']->get('feather: db.forum.theme', 'default'));
set_path('theme', path('themes') . $feather['config']->get('feather: db.forum.theme', 'default') . DS);
Bundle::register('feather theme', array(
'location' => 'path: ' . path('theme')
));
/*
|--------------------------------------------------------------------------
| View Event Override
|--------------------------------------------------------------------------
|
| Feather views behave differently to standard Laravel views. Templates
| have the ability to override views found in applications. This allows
| templates to provide custom structuring depending on the features the
| template offers.
|
| To enable this functionality Feather must override the event loader of
| view files.
|
*/
Event::override(View::loader, function($bundle, $view)
{
if(!str_contains($bundle, ' '))
{
$bundle = "feather {$bundle}";
}
$path = Bundle::path($bundle) . 'views';
if(!is_null(View::file($bundle, $view, path('theme') . 'views')))
{
$path = path('theme') . 'views';
}
if(str_contains($view, ': '))
{
list($directory, $view) = explode(': ', $view);
list($name, $view) = explode(' ', $view);
if(!is_null(View::file($bundle, $view, path('feather') . Str::plural($directory) . DS . $name . DS . 'views')))
{
$path = path('feather') . Str::plural($directory) . DS . $name . DS . 'views';
}
}
return View::file($bundle, $view, $path);
});
/*
|--------------------------------------------------------------------------
| Global Feather Variable
|--------------------------------------------------------------------------
|
| The feather global view variable is shared across all views. It contains
| some basic information about the forum as well as the currently logged in
| user.
|
*/
Event::listen('auth: started', function() use ($feather)
{
$user = array();
if($feather['auth']->online())
{
$user = $feather['auth']->user();
}
View::share('feather', (object) array_merge($feather['config']->get('feather: db.forum'), array('user' => (object) $user)));
});
/*
|--------------------------------------------------------------------------
| Default Variable Assignment
|--------------------------------------------------------------------------
|
| Some variables are used almost always inside a template. To ensure these
| varaiables are always set we'll set them if they are not currently set.
|
*/
$defaults = function($view)
{
if(!isset($view->title)) $view->title = 'Index';
if(!isset($view->alert)) $view->alert = Session::has('alert') ? (object) Session::get('alert') : null;
};
View::composer('feather core::template', $defaults);
View::composer('feather admin::template', $defaults);
/*
|--------------------------------------------------------------------------
| Blade Variable Assignment
|--------------------------------------------------------------------------
|
| Assign variables within Blade.
|
*/
Blade::extend(function($value)
{
return preg_replace('/(\s*)@assign\s*\(\$(.*), (.*)\)(\s*)/', '$1<?php $$2 = $3; ?>$4', $value);
});
/*
|--------------------------------------------------------------------------
| Blade Events
|--------------------------------------------------------------------------
|
| Fire custom Gear events.
|
*/
Blade::extend(function($value)
{
$matcher = Blade::matcher('event');
return preg_replace($matcher, '$1<?php echo Feather\Gear::fire$2; ?>', $value);
});
/*
|--------------------------------------------------------------------------
| Blade Inline Errors
|--------------------------------------------------------------------------
|
| Display inline errors for a specific form element.
|
*/
Blade::extend(function($value)
{
$matcher = Blade::matcher('error');
return preg_replace($matcher, '$1<?php echo $errors->has$2 ? view("feather core::error.inline", array("error" => $errors->first$2)) : null; ?>', $value);
});
/*
|--------------------------------------------------------------------------
| Blade Errors
|--------------------------------------------------------------------------
|
| Display all errors for a form.
|
*/
Blade::extend(function($value)
{
$matcher = Blade::matcher('errors');
return preg_replace($matcher, '$1<?php echo $errors->all() ? view("feather core::error.page", array("errors" => $errors->all())) : null; ?>', $value);
});
/*
|--------------------------------------------------------------------------
| HTML::link_to_new_discussion() Macro
|--------------------------------------------------------------------------
|
| Custom HTML macro to link to the new discussion page.
|
*/
HTML::macro('link_to_new_discussion', function($title, $attributes = array()) use ($feather)
{
$uri = URI::current();
if(str_contains($uri, 'place'))
{
$url = preg_replace('/\/p[0-9]+/', '', $uri) . (ends_with($uri, 'start') ? null : '/start');
preg_match('/(\d+)-.*?/', $uri, $matches);
// If the user cannot start discussions on the selected place, don't show the button.
if($feather['auth']->cannot('start: discussions', Core\Place::find(array_pop($matches))))
{
$url = URL::to_route('start.discussion');
}
}
else
{
$url = URL::to_route('start.discussion');
}
return HTML::link($url, $title, $attributes);
});