Skip to content

Commit 34646f7

Browse files
committed
no message
1 parent 69b88e6 commit 34646f7

15 files changed

+587
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ With time, this package would contain all modifications of the bare Laravel app.
1616
## Installation
1717

1818
1. Add
19-
`"unrulynatives/helpers": "0.0.13"`
19+
`"unrulynatives/helpers": "0.1.1"`
2020
to your composer.json file.
2121

2222
2. Add this to your `config/app.php` file in packages section

src/HelpersServiceProvider.php

+12-1
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,21 @@ public function boot()
2323
__DIR__.'/unstarter_views' => base_path('resources/views/unstarter'),
2424

2525
// publish app files (Models, Controllers, etc.) for the UN Starter Kit
26+
// UNFINISHED!
2627
__DIR__.'/unstarter_app' => base_path('unstarter'),
2728

2829
// publish Controllers to the app's app/Http/Controllers folder
29-
__DIR__.'/unstarter_controllers' => base_path('app/Http/Controllers'),
30+
__DIR__.'/unstarter_controllers' => base_path('app/Models'),
31+
32+
// publish Models to the app's app/Http/Controllers folder
33+
__DIR__.'/unstarter_models' => base_path('app/Http/Controllers'),
34+
35+
// publish Helpers to the app's app/Http/Controllers folder
36+
__DIR__.'/unstarter_helpers' => base_path('app/Helpers'),
37+
38+
39+
// publish Middleware to the app's app/Http/Controllers folder
40+
__DIR__.'/unstarter_middleware' => base_path('app/Http/Middleware'),
3041

3142

3243

src/unstarter_app/routes/unstarter.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// comment this route to make the `/` route in 'web.php' be first to read
88
Route::get('/', 'UNStarter\StarterController@landing');
99

10+
// referred to in help.md
11+
Route::get('unrulyhelpers', 'UNStarter\StarterController@landing');
12+
13+
1014
// example - using functions in routes file
1115
// Route::get('/', function () {
1216
// return view('starter.landing');
@@ -38,6 +42,7 @@
3842
// http://laravel.io/forum/02-17-2015-laravel-5-routes-restricting-based-on-user-type
3943

4044
Route::get('/', 'UNStarter\StarterController@landing');
45+
Route::get('landing', 'UNStarter\StarterController@landing');
4146

4247
Route::get('frontend', function () {
4348
return view('unstarter.frontend.components_common');
@@ -48,7 +53,6 @@
4853
Route::get('contributors', 'UNStarter\StarterController@contributors');
4954
Route::get('minitools', 'UNStarter\StarterController@minitools');
5055
Route::get('snippets', 'UNStarter\StarterController@snippets');
51-
Route::get('landing', 'UNStarter\StarterController@landing');
5256
Route::get('admintools', 'UNStarter\AdminToolsController@dashboard_admintools');
5357

5458

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
namespace Unrulynatives\Helpers;
3+
4+
use App\User;
5+
6+
class AvatarHelper {
7+
8+
public static function dispAvatar($itemkind,$string=null) {
9+
if ($string == '') {
10+
$avatar = '_empty_'.$itemkind.'.jpg';
11+
12+
13+
} else {
14+
$avatar = $string;
15+
}
16+
17+
return $avatar;
18+
}
19+
20+
21+
22+
23+
public static function userAvatar($userid) {
24+
if($userid == '') {
25+
return '';
26+
}
27+
$user = User::find($userid);
28+
$hash = md5(strtolower($user->email));
29+
return "http://www.gravatar.com/avatar/$hash";
30+
// return 'xx';
31+
32+
}
33+
34+
}
35+

src/unstarter_helpers/DateHelper.php

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
namespace Unrulynatives\Helpers\Helpers;
3+
4+
class DateHelper {
5+
6+
public static function dateYmd($date) {
7+
if ($date) {
8+
$dt = new \DateTime($date);
9+
10+
// return = $date;
11+
if(strtotime($date) == 0) {
12+
return 'No date set.';
13+
}
14+
return $dt->format("Y-m-d"); //
15+
}
16+
}
17+
18+
19+
public static function dateDfh($date) {
20+
if ($date) {
21+
$dt = new \DateTime($date);
22+
23+
// return = $date;
24+
if(strtotime($date) == 0) {
25+
return trans('messages.no_date_set');
26+
}
27+
28+
return \Jenssegers\Date\Date::parse($date)->diffForHumans(); // diffForHumans
29+
}
30+
}
31+
}
32+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
<?php
2+
namespace Unrulynatives\Helpers;
3+
4+
use App\Models\Reminder;
5+
use App\Models\Userattitude;
6+
use App\Models\Entitystandpoint;
7+
use App\Models\Usersetting;
8+
use App\Models\Exemplar;
9+
use App\User;
10+
use DB;
11+
use Auth;
12+
use URL;
13+
14+
class UNStarterSitewideHelper {
15+
16+
17+
18+
19+
public static function getDomainName($url, $length) {
20+
$domain = parse_url($url, PHP_URL_HOST);
21+
return $domain;
22+
23+
24+
}
25+
26+
public static function creatorAvatar($userid) {
27+
$user = User::find($userid);
28+
$hash = md5(strtolower($user->email));
29+
return "http://www.gravatar.com/avatar/$hash";
30+
31+
32+
}
33+
34+
public static function creatorName($userid) {
35+
$user = User::find($userid);
36+
37+
return $user->name;
38+
// return 'xx';
39+
40+
}
41+
42+
43+
44+
public static function setTopbar() {
45+
46+
if(Auth::check()) {
47+
$chosen_topbar = Auth::user()->settings->option_show_topbar_type;
48+
49+
} else {
50+
$chosen_topbar = request()->cookie('topbar','2');
51+
if(!$chosen_topbar) {
52+
$chosen_topbar = request()->cookie('topbar') ? request()->cookie('topbar') : '2';
53+
return $chosen_topbar;
54+
return response();
55+
// ->withCookie('topbar', $chosen_topbar, 10000);
56+
}
57+
}
58+
59+
return $chosen_topbar;
60+
return response();
61+
// return response();
62+
63+
}
64+
65+
public static function getActiveExemplar() {
66+
67+
// $active_exemplar_id = request()->cookie('active_exemplar', '8');
68+
69+
$active_exemplar_id = request()->cookie('active_exemplar') ? request()->cookie('active_exemplar') : '8';
70+
71+
if(!$active_exemplar_id) {
72+
//create the active_exemplar cookie with value 8
73+
$active_exemplar_id = '8';
74+
// $active_exemplar->withCookie('active_exemplar', '11', 2628000);
75+
}
76+
77+
$active_exemplar = Exemplar::find($active_exemplar_id);
78+
79+
return $active_exemplar;
80+
81+
}
82+
83+
84+
85+
public static function optionValue($option) {
86+
87+
if (Auth::check()) {
88+
$object = Usersetting::where('user_id',Auth::id())->first();
89+
$valname = 'option_'.$option;
90+
$output = $object->$valname;
91+
return $output;
92+
} else {
93+
94+
}
95+
96+
97+
// return $output;
98+
99+
}
100+
101+
public static function orgFramework($themename) {
102+
103+
if ($themename == 'bootstrap') {
104+
return "bootstrap";
105+
}
106+
if ($themename == 'semantic') {
107+
return "semantic";
108+
}
109+
110+
return "semantic";
111+
112+
113+
}
114+
public static function optionSwitch($optionname) {
115+
116+
117+
return "<button data-load='" . URL::to('option_switch/'.$optionname) . "' id='os_111' data-puthere='#os_111' title='Przełączenie opcji ".$optionname."'>Switch option </button>";
118+
119+
// return $output;
120+
121+
}
122+
123+
// used in /sprawdz-spojnosc-wlasnych-pogladow (percept 09.07)
124+
// sitewideHelper::listAttitudes('41', '5');
125+
public static function listAttitudes($questionid, $user) {
126+
127+
128+
// task: Userattitude list
129+
$user_attitudes = Userattitude::join('entitystandpoints', function ($q) use($questionid,$user) {
130+
$q->where('user_attitudes.item_type', '=', 'entitystandpoint');
131+
$q->on('user_attitudes.item_id', '=', 'entitystandpoints.id');
132+
$q->where('entitystandpoints.question_id', '=', $questionid);
133+
$q->where('user_attitudes.creator_id','=', $user);
134+
})
135+
// ->select('questions.id AS id')
136+
->select('user_attitudes.*')
137+
// ->selectRaw('SUM(user_attitudes.importance) AS importranking')
138+
// ->groupBy('questions.id')
139+
// ->orderBy('importranking', 'desc')
140+
->get();
141+
142+
return $user_attitudes;
143+
144+
}
145+
146+
147+
public static function parseTitle($url) {
148+
$default = '(no title)';
149+
$req_headers = ["Accept-Language: en-US,en;q=0.8", "Accept-Charset: UTF-8,*;q=0.5"];
150+
$useragent = "Mozilla/5.0 (X11; Linux x86_64; rv:19.0) Gecko/20100101 Firefox/19.0 FirePHP/0.4";
151+
$timeout = 5;
152+
153+
$ch = curl_init($url);
154+
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
155+
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
156+
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
157+
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
158+
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
159+
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
160+
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
161+
curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
162+
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);
163+
curl_setopt($ch, CURLOPT_HTTPHEADER, $req_headers);
164+
curl_setopt($ch, CURLOPT_ENCODING, '');
165+
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
166+
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
167+
$headers = '';
168+
curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($ch, $h) use (&$headers) {
169+
$headers.= $h;
170+
return strlen($h);
171+
});
172+
$content = curl_exec($ch);
173+
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
174+
curl_close($ch);
175+
176+
if ($content === FALSE || $code >= 400) {
177+
return $default;
178+
}
179+
180+
preg_match("/Content-Type:.*charset\s*=\s*(.*)[\s;]*/i", $headers, $enc);
181+
if (!isset($enc[1])) {
182+
preg_match('/<meta\s*http-equiv\s*=\s*"\s*content-type\s*"\s*content\s*=\s*".*;\s*charset\s*=\s*(.*?)\s*"\s*\/?>/i', $content, $enc);
183+
}
184+
if (!isset($enc[1])) {
185+
preg_match('/<meta\s*charset\s*=\s*"?\s*(.*?)\s*"?\s*\/?>/i', $content, $enc);
186+
}
187+
if (isset($enc[1])) {
188+
$pageenc = strtolower(trim($enc[1]));
189+
if ($pageenc !== 'utf-8') {
190+
$errh = set_error_handler(NULL);
191+
// unfortunately.. is there a better way to stop laravel from throwing exceptions here when iconv has a problem?
192+
$content = @iconv($pageenc, 'utf-8', $content);
193+
set_error_handler($errh);
194+
}
195+
}
196+
197+
preg_match("/<title.*?>\s*(.*?)\s*<\/title>/is", $content, $page_title);
198+
$page_title = isset($page_title[1]) ? $page_title[1] : $default;
199+
$page_title = preg_replace_callback("/(&#[0-9]+;)/", function($m) {
200+
return mb_convert_encoding($m[1], "UTF-8", "HTML-ENTITIES");
201+
}, $page_title);
202+
$page_title = preg_replace('/\s+/', ' ', $page_title);
203+
return trim($page_title);
204+
}
205+
206+
207+
public static function listStandpoints($questionid, $user, $judged) {
208+
209+
210+
// zadanie: lista Userattitude wobec stanowisk postaci wyrażonych w konkretnym pytaniu
211+
// (Entitystandpoint where question_id = $questionid)
212+
// $standpoints = Entitystandpoint::join('user_attitudes', function ($q) use($questionid,$user) {
213+
// $q->where('user_attitudes.item_type', '=', 'entitystandpoint');
214+
// $q->on('entitystandpoints.id', '=', 'user_attitudes.item_id');
215+
// $q->where('entitystandpoints.question_id', '=', $questionid);
216+
// $q->where('user_attitudes.creator_id','=', $user);
217+
// $q->whereNull('user_attitudes.id');
218+
// })
219+
// // ->select('questions.id AS id')
220+
// ->select('user_attitudes.*')
221+
// // ->whereNull('user_attitudes.id')
222+
// // ->selectRaw('SUM(user_attitudes.importance) AS importranking')
223+
// // ->groupBy('questions.id')
224+
// // ->orderBy('importranking', 'desc')
225+
// ->count();
226+
227+
228+
// $standpoints = Userattitude::leftJoin('entitystandpoints', function ($q) use($questionid,$user) {
229+
// $q->where('user_attitudes.item_type', '=', 'entitystandpoint');
230+
// $q->on('user_attitudes.item_id', '=', 'entitystandpoints.id');
231+
// $q->where('entitystandpoints.question_id', '=', $questionid);
232+
// $q->where('user_attitudes.creator_id','=', $user);
233+
// })
234+
// ->whereNull('entitystandpoints.id')
235+
// ->select('user_attitudes.*')
236+
// ->get();
237+
238+
239+
240+
241+
242+
243+
// return $standpoints;
244+
245+
}
246+
247+
248+
249+
250+
}
251+
252+
253+
// if($judged=0) {
254+
// // te standpointy, których user jeszcze nie ocenił
255+
256+
// }
257+
// if($judged=1) {
258+
// // standpointy, już ocenione
259+
// } else {
260+
// // wszystkie standpointy dla tego pytania
261+
// }

0 commit comments

Comments
 (0)