This repository has been archived by the owner on Apr 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathloadscripture.php
968 lines (914 loc) · 30 KB
/
loadscripture.php
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
<?php
/**
*
* @version 1.0.2 December 01, 2014
* @package Get Bible - Load Scripture Plugin
* @author Llewellyn van der Merwe <[email protected]>
* @copyright Copyright (C) 2013 Vast Development Method <http://www.vdm.io>
* @license GNU General Public License <http://www.gnu.org/copyleft/gpl.html>
*
* */
defined('_JEXEC') or die;
jimport('joomla.application.component.helper');
// Added for Joomla 3.0
if (!defined('DS'))
{
define('DS', DIRECTORY_SEPARATOR);
}
class PlgContentLoadscripture extends JPlugin
{
protected $component;
protected $document;
protected $com_params;
protected $action;
protected $diplayOption;
protected $buket;
protected $cURLheader;
protected $referer;
protected $jFactory;
protected $appMenuItemid;
protected $loacal = false;
public function onPrepareContent(&$row, &$params, $page = 0)
{
return $this->_prepareLoadScripture($row, $params, $page);
}
public function onContentPrepare($context, &$article, &$params, $page = 0)
{
return $this->_prepareLoadScripture($article, $params, $page);
}
protected function _prepareLoadScripture(&$article, &$params, $page = 0)
{
$this->jFactory = JFactory::getApplication();
// check if this is a HTML stream
if ($this->jFactory->input->getCmd('format', 'html') != 'html')
{
return;
}
// get call string
$callClass = $this->params->get('callClass', 'getBible');
// Simple performance check to determine whether bot should process further
if (strpos($article->text, $callClass) === false)
{
return true;
}
// setup regex match
$callClass = preg_quote($callClass);
$regex = '/<span class="' . $callClass . '">(.*?)<\/span>/i';
$this->_doWork($article, $regex);
return true;
}
protected function _doWork(&$article, $regex)
{
// find all instances of plugin and put in $matches
preg_match_all($regex, $article->text, $matches, PREG_SET_ORDER);
// No matches, skip this
if (count($matches))
{
// load all the defaults once
$this->setDefaults();
$this->buket['div'] = '';
$this->buket['script'] = '';
if ($this->params->get('callOption') == 2)
{
// load session
$this->session = JFactory::getSession();
}
foreach ($matches as $match)
{
// $match[0] is full pattern match, $match[1] is the item id or alias
$scripture = trim($match[1]);
$target = preg_quote($match[0]);
if ($scripture)
{
$output = $this->_setScript($scripture);
// We should replace only first occurrence in order to allow positions with the same name to regenerate their content:
$preg_replace["|$target|"] = $output;
}
}
$article->text = preg_replace(array_keys($preg_replace), array_values($preg_replace), $article->text, 1);
$article->text .= $this->buket['div'];
if ($this->params->get('callOption') == 1)
{
$article->text .= ' <script type="text/javascript">' . $this->buket['script'] . '</script> ';
}
}
return true;
}
protected function _setScript($scripture)
{
// set defaults
$id = $this->randomkey(8);
$version = $this->getStringIn($scripture, '(', ')');
$diplayOption = $this->getStringIn($scripture, '[', ']');
if ($diplayOption)
{
switch ($diplayOption)
{
case 'tip':
case 1:
$this->diplayOption = 1;
break;
case 'can':
case 2:
$this->diplayOption = 2;
break;
case 'pop':
case 3:
$this->diplayOption = 3;
break;
case 'in':
case 4:
$this->diplayOption = 4;
break;
case 'link':
case 5:
$this->diplayOption = 5;
break;
default:
$this->diplayOption = $this->params->get('diplayOption');
}
}
else
{
$this->diplayOption = $this->params->get('diplayOption');
}
if (!$version)
{
if ($this->params->get('method') == 1)
{
$version = 'kjv';
}
else
{
$version = $this->com_params->get('defaultStartVersion');
}
$scripture = current(explode('[', $scripture));
}
else
{
$scripture = current(explode('(', $scripture));
}
// remove all white space
$get_scripture = preg_replace('/\s+/', '', $scripture);
if ($this->params->get('callOption') == 2)
{
if ($this->diplayOption === 5)
{
$request = $get_scripture;
}
else
{
$request = '&p=' . urlencode($get_scripture) . '&v=' . strtolower(urlencode($version));
}
return $this->setCurl($scripture, $id, $request, $version);
}
else
{
if ($this->diplayOption === 5)
{
$request = $get_scripture;
}
else
{
$request = 'p=' . urlencode($get_scripture) . '&v=' . strtolower(urlencode($version));
}
return $this->setAjax($scripture, $id, $request, $version);
}
}
protected function setCurl($scripture, $id, $request, $version)
{
if ($this->diplayOption !== 5)
{
$recievedResult = $this->getScriptureFormated($scripture, $request, $version);
}
// load result based on desplay option
if ($this->diplayOption == 2)
{
// offcanvas display option
$this->buket['div'] .= '<div id="' . $id . '" class="uk-offcanvas"><div class="uk-offcanvas-bar"><div class="uk-panel" id="can_' . $id . '">' . $recievedResult . '</div></div></div>';
// return the html
return '<a href="#' . $id . '" data-uk-offcanvas>' . $this->htmlEscape($scripture) . '</a>';
}
elseif ($this->diplayOption == 3)
{
// popup display option
$this->buket['div'] .= '<div id="' . $id . '" class="uk-modal"><div class="uk-modal-dialog"><a class="uk-modal-close uk-close"></a><div class="uk-panel" id="pop_' . $id . '">' . $recievedResult . '</div></div></div>';
// return the html
return '<a href="#' . $id . '" data-uk-modal>' . $this->htmlEscape($scripture) . '</a>';
}
elseif ($this->diplayOption == 4)
{
// inline display option
// return the html
return '<span>' . $recievedResult . '</span>';
}
elseif ($this->diplayOption == 5)
{
// link display option
// return the html
return '<a id="' . $id . '" href="javascript:void(0)" onclick="loadAppPage(\'' . $request . '\', \'' . strtolower($version) . '\')">' . $this->htmlEscape($scripture) . ' (' . strtoupper($version) . ')</a>';
}
else
{
// tooltip display option
// return the html
return '<span style="cursor: pointer;" data-uk-tooltip="{pos:\'bottom-left\'}" title="' . $this->htmlEscape($recievedResult) . '">' . $this->htmlEscape($scripture) . '</span>';
}
}
protected function setAjax($scripture, $id, $request, $version)
{
// load result based on desplay option
if ($this->diplayOption == 2)
{
// offcanvas display option
$this->buket['div'] .= '<div id="' . $id . '" class="uk-offcanvas"><div class="uk-offcanvas-bar"><div class="uk-panel" id="can_' . $id . '"> loading ' . $this->htmlEscape($scripture) . '... </div></div></div>';
$this->buket['script'] .= "jQuery('#" . $id . "').click(loadscripture('" . $request . "','can_" . $id . "','diplay_2', '" . strtoupper($version) . "'));";
// return the html
return '<a href="#' . $id . '" data-uk-offcanvas>' . $this->htmlEscape($scripture) . '</a>';
}
else if ($this->diplayOption == 3)
{
// popup display option
$this->buket['div'] .= '<div id="' . $id . '" class="uk-modal"><div class="uk-modal-dialog"><a class="uk-modal-close uk-close"></a><div class="uk-panel" id="pop_' . $id . '"> loading ' . $this->htmlEscape($scripture) . '... </div></div></div>';
$this->buket['script'] .= "jQuery('#" . $id . "').click(loadscripture('" . $request . "','pop_" . $id . "','diplay_3', '" . strtoupper($version) . "'));";
// return the html
return '<a href="#' . $id . '" data-uk-modal>' . $this->htmlEscape($scripture) . '</a>';
}
elseif ($this->diplayOption == 4)
{
// inline display option
$this->buket['script'] .= "loadscripture('" . $request . "','in_" . $id . "','diplay_4', '" . strtoupper($version) . "');";
// return the html
return '<span id="in_' . $id . '"> loading ' . $this->htmlEscape($scripture) . '... </span>';
}
elseif ($this->diplayOption == 5)
{
// link display option
// return the html
return '<a id="' . $id . '" href="javascript:void(0)" onclick="loadAppPage(\'' . $request . '\', \'' . strtolower($version) . '\')">' . $this->htmlEscape($scripture) . ' (' . strtoupper($version) . ')</a>';
}
else
{
// tooltip display option
$this->buket['script'] .= "jQuery('#" . $id . "').hover(loadscripture('" . $request . "','" . $id . "','diplay_1', '" . strtoupper($version) . "'));";
// return the html
return '<span style="cursor: pointer;" id="' . $id . '" data-uk-tooltip="{pos:\'bottom-left\'}" title="">' . $this->htmlEscape($scripture) . '</span>';
}
}
protected function getStringIn($string, $fist = '(', $last = ')')
{
$string = " " . $string;
$foo = strpos($string, $fist);
if ($foo == 0)
{
return false;
}
$foo += strlen($fist);
$var = strpos($string, $last, $foo) - $foo;
return substr($string, $foo, $var);
}
protected function htmlEscape($val)
{
return htmlentities($val, ENT_COMPAT, 'UTF-8');
}
protected function randomkey($size)
{
$bag = "abcefghijknop1234567890qrstuwxyzABCDDEFGHIJKLLMMNOPQRSTUVVWXYZabcddefghijkllmmnopqrs0987654321tuvvwxyzABCEFGHIJKNOPQRSTUWXYZ";
$key = array();
$bagsize = strlen($bag) - 1;
for ($i = 0; $i < $size; $i++)
{
$get = rand(0, $bagsize);
$key[] = $bag[$get];
}
return implode($key);
}
protected function setDefaults()
{
// get the document
$this->document = JFactory::getDocument();
// set the getBible component params
if ($this->params->get('method') == 1)
{
$this->com_params = false;
$this->component = false;
$this->appLink = $this->params->get('network_url') . '/index.php?option=com_getbible&view=app';
}
else
{
// set the getBible component defaults
$this->component = JComponentHelper::getComponent('com_getbible');
$this->com_params = JComponentHelper::getParams('com_getbible');
$this->appMenuItemid = $this->getMenuItemId('app');
// build the link
if ($this->appMenuItemid)
{
$this->appLink = $this->getRouteUrl('index.php?Itemid=' . $this->appMenuItemid);
}
else
{
$this->appLink = $this->getRouteUrl('index.php?option=com_getbible&view=app');
}
}
// make sure all scripts are loaded
if (!$this->css_loaded('uikit'))
{
if ($this->params->get('method') == 1)
{
$this->document->addScript($this->params->get('network_url') . '/media/com_getbible/uikit/css/uikit.min.css');
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->document->addStyleSheet(JURI::base(true) . '/media/com_getbible/uikit/css/uikit.min.css');
}
elseif ($this->com_params->get('jsonQueryOptions') == 2)
{
$this->document->addScript('https://getbible.net/media/com_getbible/uikit/css/uikit.min.css');
}
else
{
$this->document->addScript('http://getbible.net/media/com_getbible/uikit/css/uikit.min.css');
}
}
}
// add css to page
$css = "
.rtl {
direction: rtl;
text-align: right;
unicode-bidi: bidi-override;
}
.ltr {
direction: ltr;
text-align: left;
unicode-bidi: bidi-override;
}
";
$this->document->addStyleDeclaration($css);
// add script to page
if (!$this->js_loaded('jquery'))
{
JHtml::_('jquery.framework');
}
if (!$this->js_loaded('uikit.min'))
{
if ($this->params->get('method') == 1)
{
$this->document->addScript($this->params->get('network_url') . '/media/com_getbible/uikit/js/uikit.min.js');
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->document->addScript(JURI::base(true) . '/media/com_getbible/uikit/js/uikit.min.js');
}
elseif ($this->com_params->get('jsonQueryOptions') == 2)
{
$this->document->addScript('https://getbible.net/media/com_getbible/uikit/js/uikit.min.js');
}
else
{
$this->document->addScript('http://getbible.net/media/com_getbible/uikit/js/uikit.min.js');
}
}
}
if ($this->params->get('callOption') == 2)
{ // setup for the curl query
// set security keys
$key = '';
if ($this->params->get('method') == 1)
{
if (strlen($this->params->get('network_key')) > 0)
{
$key = "&key=" . $this->params->get('network_key');
}
}
else
{
if ($this->com_params->get('jsonAPIaccess'))
{
$key = "&appKey=" . JSession::getFormToken();
}
}
if ($this->params->get('method') == 1)
{
$this->action = $this->params->get('network_url') . '/index.php?option=com_getbible&view=json' . $key;
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->action = JURI::base().'index.php?option=com_getbible&view=json' . $key;
}
else
{
$this->action = 'https://getbible.net/index.php?option=com_getbible&view=json' . $key;
}
}
$this->referer = JURI::current();
// setup the curl header data once here
$this->cURLheader[0] = "Accept: text/xml,application/xml,application/xhtml+xml,";
$this->cURLheader[0] .= "text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$this->cURLheader[] = "Cache-Control: max-age=0";
$this->cURLheader[] = "Connection: keep-alive";
$this->cURLheader[] = "Keep-Alive: 300";
$this->cURLheader[] = "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7";
$this->cURLheader[] = "Accept-Language: en-us,en;q=0.5";
$this->cURLheader[] = "Pragma: ";
}
else
{ // setup for the ajax query
if (!$this->js_loaded('json'))
{
if ($this->params->get('method') == 1)
{
$this->document->addScript($this->params->get('network_url') . '/media/com_getbible/js/jquery.json.min.js');
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->document->addScript(JURI::base(true) . '/media/com_getbible/js/jquery.json.min.js');
}
elseif ($this->com_params->get('jsonQueryOptions') == 2)
{
$this->document->addScript('https://getbible.net/media/com_getbible/js/jquery.json.min.js');
}
else
{
$this->document->addScript('http://getbible.net/media/com_getbible/js/jquery.json.min.js');
}
}
}
if (!$this->js_loaded('jstorage'))
{
if ($this->params->get('method') == 1)
{
$this->document->addScript($this->params->get('network_url') . '/media/com_getbible/js/jstorage.min.js');
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->document->addScript(JURI::base(true) . '/media/com_getbible/js/jstorage.min.js');
}
elseif ($this->com_params->get('jsonQueryOptions') == 2)
{
$this->document->addScript('https://getbible.net/media/com_getbible/js/jstorage.min.js');
}
else
{
$this->document->addScript('http://getbible.net/media/com_getbible/js/jstorage.min.js');
}
}
}
// load the correct url
if ($this->params->get('method') == 1)
{
$this->action = $this->params->get('network_url') . '/index.php?option=com_getbible&view=json';
}
else
{
if ($this->com_params->get('jsonQueryOptions') == 1)
{
$this->action = JURI::base().'index.php?option=com_getbible&view=json';
}
elseif ($this->com_params->get('jsonQueryOptions') == 2)
{
$this->action = 'https://getbible.net/index.php?option=com_getbible&view=json';
}
else
{
$this->action = 'https://getbible.net/index.php?option=com_getbible&view=json';
}
}
$script = "";
// set security keys
if ($this->params->get('method') == 1)
{
if (strlen($this->params->get('network_key')) > 0)
{
$script .= "var key = '" . $this->params->get('network_key') . "';";
}
}
else
{
if ($this->com_params->get('jsonAPIaccess'))
{
$key = JSession::getFormToken();
$script .= "var appKey = '" . $key . "';";
}
}
// set inline option
if ($this->params->get('inlineOption'))
{
$script .= "var inlineOption = " . $this->params->get('inlineOption') . ";";
}
else
{
$script .= "var inlineOption = 1;";
}
// load the javascript needed to get the text
$script .= $this->javascriptFunc();
$this->document->addScriptDeclaration($script);
}
}
protected function javascriptFunc()
{
return "
function loadAppPage(request, version){
var url = '" . $this->appLink . "';
var input = '<input type=\"hidden\" name=\"search_app\" value=\"1\" />';
input += '<input type=\"hidden\" name=\"search_version\" value=\"'+ version +'\" />';
input += '<input type=\"hidden\" name=\"search\" value=\"'+ request +'\" />';
input += '<input type=\"hidden\" name=\"search_type\" value=\"all\" />';
input += '<input type=\"hidden\" name=\"search_crit\" value=\"1_1_1\" />';
jQuery('<form action=\"'+ url +'\" method=\"post\">'+input+'</form>').appendTo('body').submit().remove();
}
function loadscripture(request,addTo,diplayOption,version) {
var requestStore = request;
// if memory is too full remove some
if(jQuery.jStorage.storageSize() > 4500000){
var storeIndex = jQuery.jStorage.index();
// now remove the first once set when full
jQuery.jStorage.deleteKey(storeIndex[5]);
jQuery.jStorage.deleteKey(storeIndex[6]);
jQuery.jStorage.deleteKey(storeIndex[7]);
jQuery.jStorage.deleteKey(storeIndex[8]);
jQuery.jStorage.deleteKey(storeIndex[9]);
}
if (typeof appKey !== 'undefined') {
request = request+'&appKey='+appKey;
} else if (typeof key !== 'undefined') {
request = request+'&key='+key;
}
// Check if requestStore exists in the local storage
var jsonStore = jQuery.jStorage.get(requestStore);
if(!jsonStore){
jQuery.ajax({
url:'" . $this->action . "',
dataType: 'jsonp',
data: request,
jsonp: 'getbible',
success:function(json){
// and save the result
jQuery.jStorage.set(requestStore,json);
// set text direction
if (json.direction == 'RTL'){
var direction = 'rtl';
} else {
var direction = 'ltr';
}
// check json
if (json.type == 'verse'){
setVerses(json,direction,addTo,diplayOption,version);
} else if (json.type == 'chapter'){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', 'Whole chapter/s not allowed in tooltip mode, please select another.');
} else {
setChapter(json,direction,addTo,diplayOption,version);
}
} else if (json.type == 'book'){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', 'Whole book/s! not allowed in tooltip mode, please select another.');
} else {
setBook(json,direction,addTo,diplayOption,version);
}
}
},
error:function(){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', 'No scripture was returned, please fix scripture reference!');
} else {
jQuery('#'+addTo).html('<span class=\"uk-text-danger\">No scripture was returned, please fix scripture reference!</span>');
}
},
});
} else {
// set text direction
if (jsonStore.direction == 'RTL'){
var direction = 'rtl';
} else {
var direction = 'ltr';
}
// check jsonStore
if (jsonStore.type == 'verse'){
setVerses(jsonStore,direction,addTo,diplayOption,version);
} else if (jsonStore.type == 'chapter'){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', 'Whole chapter/s not allowed in tooltip mode, please select another.');
} else {
setChapter(jsonStore,direction,addTo,diplayOption,version);
}
} else if (jsonStore.type == 'book'){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', 'Whole book/s! not allowed in tooltip mode, please select another.');
} else {
setBook(jsonStore,direction,addTo,diplayOption,version);
}
}
}
}
// Set Verses
function setVerses(json,direction,addTo,diplayOption,version){
var output = '';
jQuery.each(json.book, function(index, value) {
if(diplayOption == 'diplay_1') {
output += '<p class=\"'+direction+'\">';
} else if(diplayOption == 'diplay_4' && inlineOption == 1) {
output += '<span class=\"'+direction+'\"><span class=\"ltr uk-text-muted\">'+value.book_name+'</span> ';
var chapter_nr = value.chapter_nr;
} else {
output += '<center><b>'+value.book_name+' '+value.chapter_nr+'</b></center><br/><p class=\"'+direction+'\">';
}
jQuery.each(value.chapter, function(index, value) {
if(diplayOption == 'diplay_4' && inlineOption == 1) {
output += ' <span class=\"ltr uk-text-muted\">('+ chapter_nr+':'+value.verse_nr+ ')</span> ';
} else {
output += '  <small class=\"ltr\">' +value.verse_nr+ '</small>  ';
}
output += escapeHtmlEntities(value.verse);
if(diplayOption == 'diplay_4' && inlineOption == 1) {
output += '';
} else {
output += '<br />';
}
});
if(diplayOption == 'diplay_4' && inlineOption == 1) {
output += '</span> <small class=\"ltr uk-text-muted\"> (Taken From '+version+')</small> ';
} else {
output += '<small class=\"uk-text-right\"> (Taken From '+version+')</small></p>';
}
});
if(addTo){
if(diplayOption == 'diplay_1') {
jQuery('#'+addTo).prop('title', output);
} else {
jQuery('#'+addTo).html(output);
}
} else {
jQuery('#'+addTo).prop('title', 'error!');
}
}
// Set Chapter
function setChapter(json,direction,addTo,diplayOption,version){
var output = '<center><b>'+json.book_name+' '+json.chapter_nr+'</b></center><br/><p class=\"'+direction+'\">';
jQuery.each(json.chapter, function(index, value) {
output += '  <small class=\"ltr\">' +value.verse_nr+ '</small>  ';
output += escapeHtmlEntities(value.verse);
output += '<br/>';
});
output += '<small class=\"uk-text-right\"> (Taken From '+version+')</small></p>';
if(addTo){
jQuery('#'+addTo).html(output);
}
}
// Set Book
function setBook(json,direction,addTo,diplayOption,version){
var output = '';
jQuery.each(json.book, function(index, value) {
output += '<center><b>'+json.book_name+' '+value.chapter_nr+'</b></center><br/><p class=\"'+direction+'\">';
jQuery.each(value.chapter, function(index, value) {
output += '  <small class=\"ltr\">' +value.verse_nr+ '</small>  ';
output += escapeHtmlEntities(value.verse);
output += '<br/>';
});
output += '<small class=\"uk-text-right\"> (Taken From '+version+')</small></p>';
});
if(addTo){
jQuery('#'+addTo).html(output);
}
}
function escapeHtmlEntities (str) {
if (typeof jQuery !== 'undefined') {
// Create an empty div to use as a container,
// then put the raw text in and get the HTML
// equivalent out.
return jQuery('<div/>').text(str).html();
}
// No jQuery, so use string replace.
return str
.replace(/&/g, '&')
.replace(/>/g, '>')
.replace(/</g, '<')
.replace(/\"/g, '"');
}
";
}
protected function getMenuItemId($view)
{
$menu = $this->jFactory->getMenu();
//get only com_getbible menu items
$items = $menu->getItems('component_id', $this->component->id);
foreach ($items as $item)
{
if (isset($item->query['view']) && $item->query['view'] === $view)
{
return $item->id;
}
}
return false;
}
protected function getRouteUrl($route)
{
// Get the global site router.
$config = JFactory::getConfig();
$router = JRouter::getInstance('site');
$router->setMode($config->get('sef', 1));
$uri = $router->build($route);
$path = $uri->toString(array('path', 'query', 'fragment'));
return $path;
}
protected function js_loaded($script_name)
{
$head_data = $this->document->getHeadData();
foreach (array_keys($head_data['scripts']) as $script)
{
if (stristr($script, $script_name))
{
return true;
}
}
return false;
}
protected function css_loaded($script_name)
{
$head_data = $this->document->getHeadData();
foreach (array_keys($head_data['styleSheets']) as $script)
{
if (stristr($script, $script_name))
{
return true;
}
}
return false;
}
protected function getScriptureFormated($scripture, $request, $version)
{
// check if it has the result in the session
$result = $this->session->get($request, false);
if ($result)
{
$result = json_decode(base64_decode($result));
}
else
{
// set the url to use in curl command
$url = $this->action . $request;
// get the result set from the set url
$result = $this->getScriptureCurl($url);
$this->session->set($request, base64_encode($result));
$result = json_decode($result);
}
if (is_object($result))
{
// set text direction
if ($result->direction == 'RTL')
{
$direction = 'rtl';
}
else
{
$direction = 'ltr';
}
// check the type of result returned
if ($result->type == 'verse')
{
return $this->setVerses($result, $direction, $version);
}
elseif ($result->type == 'chapter')
{
if ($this->diplayOption == '1')
{
return "Whole chapter's not allowed in tooltip mode, please select another.";
}
else
{
return $this->setChapter($result, $direction, $version);
}
}
elseif ($result->type == 'book')
{
if ($this->diplayOption == '1')
{
return "Whole book's! not allowed in tooltip mode, please select another.";
}
else
{
return $this->setBook($result, $direction, $version);
}
}
}
// if no results retuned return the following error messages
if ($this->diplayOption == '1')
{
return "No scripture was returned, please fix scripture reference!";
}
else
{
return '<span class="uk-text-danger">No scripture was returned, please fix scripture reference!</span>';
}
}
protected function setVerses($result, $direction, $version)
{
$output = '';
foreach ($result->book as $in => &$book)
{
if ($this->diplayOption == 1)
{
$output .= '<p class="' . $direction . '">';
}
elseif ($this->diplayOption == 4 && $this->params->get('inlineOption') == 1)
{
$output .= '<span class="' . $direction . '"><span class="ltr uk-text-muted">' . $book->book_name . '</span> ';
}
else
{
$output .= '<center><b>' . $book->book_name . ' ' . $book->chapter_nr . '</b></center><br/><p class="' . $direction . '">';
}
foreach ($book->chapter as $as => &$chapter)
{
if ($this->diplayOption == 4 && $this->params->get('inlineOption') == 1)
{
$output .= ' <span class="ltr uk-text-muted">(' . $book->chapter_nr . ':' . $chapter->verse_nr . ')</span> ';
}
else
{
$output .= '  <small class="ltr">' . $chapter->verse_nr . '</small>  ';
}
$output .= $this->htmlEscape($chapter->verse);
if ($this->diplayOption == 4 && $this->params->get('inlineOption') == 1)
{
$output .= '';
}
else
{
$output .= '<br />';
}
}
if ($this->diplayOption == 4 && $this->params->get('inlineOption') == 1)
{
$output .= '</span> <small class="ltr uk-text-muted"> (Taken From ' . $version . ')</small> ';
}
else
{
$output .= '<small class="uk-text-right"> (Taken From ' . $version . ')</small></p>';
}
}
return $output;
}
protected function setChapter($result, $direction, $version)
{
$output = '<center><b>' . $result->book_name . ' ' . $result->chapter_nr . '</b></center><br/><p class="' . $direction . '">';
foreach ($result->chapter as $in => &$chapter)
{
$output .= '  <small class="ltr">' . $chapter->verse_nr . '</small>  ';
$output .= $this->htmlEscape($chapter->verse);
$output .= '<br/>';
}
$output .= '<small class="uk-text-right"> (Taken From ' . $version . ')</small></p>';
return $output;
}
protected function setBook($result, $direction, $version)
{
$output = '';
foreach ($result->book as $in => &$book)
{
$output .= '<center><b>' . $result->book_name . ' ' . $result->chapter_nr . '</b></center><br/><p class="' . $direction . '">';
foreach ($book->chapter as $chapter)
{
$output .= '  <small class="ltr">' . $chapter->verse_nr . '</small>  ';
$output .= $this->htmlEscape($chapter->verse);
$output .= '<br/>';
}
$output .= '<small class="uk-text-right"> (Taken From ' . $version . ')</small></p>';
}
return $output;
}
protected function getScriptureCurl($url)
{
// startup curl
$curl = curl_init();
// set curl options
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0');
curl_setopt($curl, CURLOPT_HTTPHEADER, $this->cURLheader);
curl_setopt($curl, CURLOPT_REFERER, $this->referer);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate');
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
// get results from execution of curl command
$results = curl_exec($curl);
// close curl
curl_close($curl);
// fix the result set for json
$results = rtrim($results, ";");
$results = rtrim($results, ")");
$results = ltrim($results, '(');
// retun object
return $results;
}
}