-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHtml.php
More file actions
6627 lines (5956 loc) · 168 KB
/
Html.php
File metadata and controls
6627 lines (5956 loc) · 168 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
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
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
require_once(dirname(__FILE__)."/lib/authenticate.php");
require_once(dirname(__FILE__)."/lib/session.php");
class Html
{
/**
* HTTP vars from the request.
*
* @private
* @since 0.0.1
*/
var $HTTPVars;
/**
* The users data file.
*
* @private
* @since 0.0.1
*/
var $datafil = NULL;
/**
* The class containning the options.
*
* @private
* @since 0.0.1
*/
var $stier;
/**
* An instanceof the {@link SiteContext}.
*
* @private
* @since 0.0.1
*/
var $siteContext;
/**
* An instance of the <code>Rounder</code>.
*
* @private
* @since 0.0.1
*/
var $rounder;
/**
* Creates a new instance.
*
* @param $HTTPVars variables form the request
* @param $inddata the content of users data file.
* @public
* @version 0.0.1
* @since 0.0.1
*/
function __construct($HTTPVars, &$datafil, $rounder=null)
{
$this->setHTTPVars($HTTPVars);
if (is_object($datafil))
$this->setDatafil($datafil);
if ($rounder === null)
$rounder = new Rounder();
$this->setRounder($rounder);
}
/**
* Sets an instance of the {@link Rounder}.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return void
* @param $rounder an instance of the {@link Rounder}.
*/
function setRounder(&$rounder)
{
$this->rounder = &$rounder;
}
/**
* Gets an instance of the {@link Rounder}.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return Rounder an instance of the {@link Rounder}.
*/
function &getRounder()
{
return $this->rounder;
}
/**
* Sets the {@link SiteContext} object.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $siteContext the {@link SiteContext} object.
* @return void
*/
function setSiteContext(&$siteContext)
{
if (strtolower(get_class($siteContext)) == 'sitecontext')
$this->siteContext = &$siteContext;
else
{
echo "<b>Error 893:</b> Param <code>\$siteContext</code> to contrusctor <code>StatSite()</code> must be an instance of the class <code>SiteContext</code>.";
exit;
}
}
/**
* Sets the class containning the options.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $stier the class containning the options.
* @return void
*/
function setStier(&$stier)
{
$this->stier = &$stier;
}
/**
* Returns the class containning the options.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return Stier the class containning the options.
*/
function &getStier()
{
return $this->stier;
}
/**
* Sets the variables from the request.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $HTTPVars the variables from the request.
* @return void
*/
function setHTTPVars($HTTPVars)
{
$this->HTTPVars = $HTTPVars;
}
/**
* Returns the variables from the request.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return String[] the variables from the request.
*/
function getHTTPVars()
{
return $this->HTTPVars;
}
/**
* Returns one variable from the request.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $theVar the name of the wanted variable
* @return String the named variable from the request.
*/
function getHTTPVar($theVar)
{
return $this->HTTPVars[$theVar];
}
/**
* Sets the users datafile, as a {@link Datafil} object.
*
* @public
* @since 0.0.1
* @version 0.0.1
* @param $datafil the users datafile.
* @return void
* @see Datafil
*/
function setDatafil(&$datafil)
{
//if (strtolower(get_class($datafil)) == "datafil")
$this->datafil = &$datafil;
/*else
{
echo "<b>Error:</b> Invalid parameter for function <code>setDatafil(Datafil)</code>. Only instances of class <code>Datafil</code> is valid.";
exit;
}*/
}
/**
* Returns the data source.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return DataSource the data source.
*/
function &getDataSource()
{
return $this->getDatafil();
}
/**
* Returns the users datafile, as a {@link Datafil} object.
*
* @private
* @version 0.0.1
* @since 0.0.1
* @return Datafil brugerens data
*/
function &getDatafil()
{
return $this->datafil;
}
/**
* Takes the one of the arrays which is used, and reurns it.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $POST_VARS the post vars array
* @param $GET_VARS the get vars array
* @return String[] the one of the parameters which is used.
*/
static function setPostOrGetVars($POST_VARS, $GET_VARS)
{
if (isset($GET_VARS) and sizeof($GET_VARS) > 0) {
return $GET_VARS;
} elseif (isset($POST_VARS) and sizeof($POST_VARS)) {
return $POST_VARS;
} elseif (isset($_POST) and sizeof($_POST) > 0) {
return $_POST;
} elseif (isset($_GET) and sizeof($_GET)) {
return $_GET;
}
return array();
}
/**
* Sends header which tells the browser not to cache the page.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return void
*/
static function outputNoCacheHeaders()
{
header("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
}
/**
* Formats a string to explain a poblem has occured.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $tekst the text, may contain html.
* @param $type if 0 is specified, html is generated,
* if 1 is specified, java script is generated.
* @return String a formated string explaining a problem has occured.
*/
function problemer($tekst, $type=0)
{
if ($type == 0)
return "<h3>Der opstod flgende problem(er):</h3><ul>" . $tekst . "</ul>";
elseif ($type == 1)
return "document.write('".addslashes($tekst)."');\n";
else
{
echo "<b>Error</b> Unvalid value in parameter in 2nd function problemer() in class Html line ".__LINE__.": \$type=$type. Valid values: <code>0</code> or <code>1</code>.";
exit;
}
}
/**
* Sets the pro value $no (see {@link #pro} for valid values) to the
* value $val.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $no the field to set
* @param $val the value to set.
* @returns void
*/
function setPro($no, $val) {
$provalue = explode('::',$this->datafil->getLine(58));
$provalue[$no] = $val;
$this->datafil->setLine(58, implode('::', $provalue));
}
/**
* Specifies if the user has a pro account or not.
* If no parameter is given, or the text "test" is given, 1 is
* returned if the user has pro, else 0.
* If a number is given, the the corresponding pro value is returned.
*
* <p>Pro numbers:<br>
* 0-Max no reference pages<br>
* 1-Max no unique ip adresses<br>
* 2-Info about latest X users<br>
* 3-No questions<br>
* 4-No anwsers for each question<br>
* 5-Max no counters<br>
* 6-Hits pr. users, calculated over X weeks<br>
* 7-Max no domains<br>
* 8-Max no search terms<br>
* 9-No send stat mail times<br>
* 10-Max no click counter adresses<br>
* 11-Max no movements<br>
* 12-Max no charaters for key words<br>
* 13-Max no charaters for description<br>
* 14-Max no categories in the index<br> Not implemented
* 15-Max no adresses to only register stats on<br>
* 16-Max no entry sites<br>
* 17-Max no exit sites<br>
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $nr the wanted pro field, or "test" for general pro.
* @return boolean the wanted pro field, or if the user has pro or not.
*/
function pro($nr = "test")
{
//If this is called when the data source has not been loaded
if ($this->datafil === NULL)
return false;
if ($this->datafil->loaded()) {
$pro = $this->datafil->getLine(61);
} else {
$pro = 1;
}
if (! is_numeric($pro)) {
$pro = 0;
}
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
$normvalue = array(100, 30, 20,10,10, 50, 3,100,100, 30, 50, 50, 75, 75, 1, 5, 50, 50); /*The limit for ordinarry users.*/
$pro_stdvalue =array( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,999, 0, 300, 85, 1, 0, 0, 0); /*0 means the user can change the value itself, > 0 means the number can not be changed*/
$maxvalue = array(150, 100,150,99,99,500,9,150,150,200,999,150, 300, 85, 1,99,150, 150); /*Maximal values used - the users can specify lager values, which is saved, but theese are the heighest actually used. Use of theese can be disabled in stier.php.*/
//if (($pro + 7*24*3600 > time()) or ($this->stier->getOption('always_pro') == 1))
if (($pro + 7*24*3600 > 1034310769) or ($this->stier->getOption('always_pro') == 1))
{
if ($nr === "test")
return 1;
else
{
if ($this->datafil->loaded()) {
$provalue = explode("::",$this->datafil->getLine(58));
} else {
$provalue = array();
}
//Returns values
if ($pro_stdvalue[$nr] === 0) /*Chek type*/
{
if (isset($provalue[$nr]) and $this->ok0tal($provalue[$nr])) /*Is the users value ok?*/
{
//Limit the user selected options
if (($this->stier->getOption('use_pro_limits') == 1) and ($provalue[$nr] > $maxvalue[$nr]))
return $maxvalue[$nr];
else
return $provalue[$nr];
}
else
return $normvalue[$nr];
}
else /*If this is a value the user can't change.*/
return $pro_stdvalue[$nr];
} /*End of if if ($pro + [...]*/
}
else
{
if ($nr === "test")
return 0;
else
return $normvalue[$nr];
}
} /*End of function pro*/
/**
* States if the given number is correct and < 0.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $tal the number to validate
* @return boolean 1 if the number is ok, else 0.
*/
function ok0tal($tal)
{
if ($this->oktal($tal) and $tal > 0)
return 1;
else
return 0;
}
/**
* States if <code>$tal</code> is a valid number.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $tal the number to validate
* @return boolean 1 if the number is ok, else 0.
*/
function oktal($tal)
{
if (! preg_match("/[^0-9]/",$tal))
return 1;
else
return 0;
}
/**
* Returns if the visit is unique.
*
* @param $ip the IP address of the user.
* @return if the visit is unique.
* @public
*/
function isVisitUnique($ip)
{
return ! in_array( $ip, explode(":",$this->datafil->getLine(45)) );
}
/**
* Calculates the numbers of hits pr. user on the basis of the datafile.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return float the numbers of hits pr. user on the basis of the datafile.
*/
function hpb()
{
$sec = date('s'); /*Second*/
$min = date('i'); /*Minute*/
$hour = date('H'); /*Hour*/
$mday = date('j'); /*Day in month*/
$mon = date('n'); /*Month*/
$year = date('Y'); /*Year*/
$wday = date('w'); /*Day of week*/
$yday = date('z'); /*Day in year*/
$ind1 = $this->datafil->getLine(64);
$ind2 = $this->datafil->getLine(65);
$tmp = explode("::",$ind1);
$tmp2 = explode("::",$ind2);
$hpbmax = $this->pro(6);
$ugenr = round(($yday/7)+1);
$genr = $ugenr;
if ($hpbmax > 0)
{
while ($ugenr > $hpbmax)
$ugenr -= $hpbmax;
}
$n = $hpbmax;
$ht = 0;
$hn = 0;
$hpb = 0;
for ($i = 0;$i < $hpbmax; $i++)
{
if ($hpbmax != 0) {
if (isset($tmp[$i]) and is_numeric($tmp[$i])) {
$ht += $tmp[$i] * ($n/$hpbmax);
}
if (isset($tmp2[$i]) and is_numeric($tmp2[$i])) {
$hn += $tmp2[$i] * ($n/$hpbmax);
}
}
$n--;
if ($n < 0)
$n = $hpbmax;
}
if ($hn > 0 and $ht != 0)
$hpb = $hn/$ht;
return $hpb;
}
/**
* Rounds the number to a suiting number of decimals.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $tal the number to round.
* @return float the rounded number.
*/
function afrund($tal)
{
if ($tal < 0.001) $ud = round($tal,4);
elseif ($tal < 0.01) $ud = round($tal,3);
elseif ($tal < 0.1) $ud = round($tal,2);
elseif ($tal <= 10) $ud = round($tal*100)/100;
elseif ($tal > 10 and $tal <= 100) $ud = round($tal*10)/10;
else $ud = round($tal);
$ud = preg_replace("/\./",",",$ud);
return $ud;
}
/**
* States if a stat may be counted on a given url.
* This function is for ignoring hits from other pages than your own.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $url the url for the page, on which to check if we may register
* sats on.
* @param $okSider an array or <code>::</code> separated text string
* of the adresses the url may start with to be allowed to have
* stats registered for them.
* @return <code>true</code> for yes, <code>false</code> for no.
* @todo the @c $okSider array can be fetch from the datasource - do this.
*/
function countVisit($url, $okSider)
{
//Convrts the 2nd parameter to an array, if nessary.
if (! is_array($okSider))
$okSider = explode("::",$okSider);
//Remove invalid urls.
$okokSider = array();
foreach ($okSider as $enkeltSide) {
if (strlen(trim($enkeltSide)) > 0)
$okokSider[] = $enkeltSide;
}
//Is there a valid url at all?
if (sizeof($okokSider) === 0)
return true;
foreach ($okokSider as $tjekSide)
{
//If there is nothing to check: Next;
if ($tjekSide === "")
next;
//Does $tjekSide start with http:// or https://
$startHttp = (strpos($tjekSide,"http://") === 0 or strpos($tjekSide,"https://") === 0);
//Does the given page start with the text of the okSide
if ( /*tjekSide starts with http://*/
($startHttp and strpos(strtolower($url),strtolower($tjekSide)) === 0)
or /*tjekSide does not start with http://*/
((! $startHttp) and strpos(strtolower($url),strtolower($tjekSide)) !== false)
)
{
return true;
}
}
return false;
}
/**
* Returns a text formated string of the current date and time.
* The format is: "[day] d. [date]/[month]-[year] kl. [hour]:[minute]".";
* The format can not be changed, thus this metod is depricated.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @return Stirng en tekststreng der viser dags dato og tid.
* @depricated use the date function of PHPand a localized format.
*/
function kortdato()
{
$timeAdjusted = Html::getTimeAdjusted();
$sec = date('s', $timeAdjusted); /*Sekund*/
$min = date('i', $timeAdjusted); /*Minut*/
$hour = date('H', $timeAdjusted); /*time*/
$mday = date('j', $timeAdjusted); /*dag i mned*/
$mon = date('n', $timeAdjusted); /*mned*/
$year = date('Y', $timeAdjusted); /*r*/
$wday = date('w', $timeAdjusted); /*ugedage*/
$yday = date('z', $timeAdjusted); /*dag i r*/
//Write day of week
if ($wday == 1)
$uge = "man";
elseif($wday == 2)
$uge="tirs";
elseif($wday == 3)
$uge="ons";
elseif($wday == 4)
$uge="tors";
elseif($wday == 5)
$uge="fre";
elseif($wday == 6)
$uge="lør";
else
$uge="søn";
return "$uge d. $mday/$mon-$year kl. $hour:$min";
}
/**
* Recives a full domain name, and returns the domain+topdomain;
* if the domain is 'co' the 3rd level is also returned. E.g.
* <code>www.zip.dk</code> returns <code>zip.dk</code> and
* <code>www.amazon.co.uk</code> gives <code>amazon.co.uk</code>.
*/
function getDom($dom)
{
$domArray = explode(".",$dom);
$domArray = array_reverse($domArray);
if (count($domArray) > 2 and $domArray[1] === "co")
$udDomArray = array($domArray[0],$domArray[1],$domArray[2]);
else if(count($domArray) > 1)
$udDomArray = array($domArray[0],$domArray[1]);
else
$udDomArray = array();
$udDomArray = array_reverse($udDomArray);
return implode(".",$udDomArray);
}
/**
* Returns the top domain from the domain.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $domaene det domain to get the topdomain from.
* @return String the topdomain of the domain.
*/
function getTopDom($domaene)
{
$dom = explode(".",$this->getDom($domaene));
$dom = array_reverse($dom);
return $dom[0];
}
/**
* Returns an array in which index 0 is the counter number and index 1 is an
* array of the counter names.
*
* If $createNew is set to @c false (default is @c true):
* Non existing counter numbers/names will @em not be added to the
* list of counters. Existing numbers/names will be counted up.
* If no useable counter was found, the first index of the result will be
* 0 as usual, and when getting this result it is then possible to treat
* the visit as not yet counted.
* $createNew was added to support legacy references to ZIP Stat that still
* contains the old type of counters.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $counterNo the number of the counter in question (or empty).
* @param $counterName the name of the counter in question (or empty).
* @param $counterNameList array of the counter names corresponding to the.
* numbers (the indexes of the array).
* @param $pro_max_counters the largest amount of counters this user may have.
* @param $HTTP_REFERER the address of the registered page.
* @param $createNew shall a non existing name be added to the
* list of counters?
* @return String[] index 0 is the found counter number, index 1 is the
* new array of counter names ($counterNameList)
* with the new countername added, if a new counter is created.
*/
function taelnummer($counterNo, $counterName, $counterNameList,
$pro_max_counters, $HTTP_REFERER, $createNew = true)
{
if (isset($counterNo) and ($counterNo*1) > 0)
{
/*If a counter number is given.*/
$i = $counterNo;
}
elseif (isset($counterName) and strlen($counterName) > 0)
{
/*If a counter name is given.*/
//Find the counter number that matches the name.
$i = 0;
while (($counterNameList[$i] != $counterName) and ($i <= $pro_max_counters)) {
$i++;
}
if ($i == ($pro_max_counters + 1)) {
/*If we can't find a counter name.*/
$i=0;
}
}
else
{
//If nothing is given.
//Find the file name of the page:
$filename = $HTTP_REFERER;
//If it's not a valid URL: We can't do this.
if (!preg_match("#^http://#i",$filename)) {
return array(0,$counterNameList);
}
$filename = Html::taelnummer_url2name($filename);
$notFound = 1;
$location = 0;
$nameIndex = 0;
while (($notFound) and ($nameIndex <= $pro_max_counters))
{
//Find the counter number for which a corresponding name exists.
if ($counterNameList[$nameIndex] == $filename)
{
$i = $nameIndex;
$notFound = 0;
}
if (! (($counterNameList[$nameIndex]) or ($location)) )
$location = $nameIndex;
$nameIndex++;
}
if (($notFound) and ($location))
{
if ($createNew === true) {
//Don't create non existing.
return array(0,$counterNameList);
}
//Create a new counter if required.
$counterNameList[$location] = $filename;
$i = $location;
}
elseif ($notFound)
{
//If there wasn't room for a new counter.
$i = 0;
}
}
//If the counter number is too heigh: Use the default counter.
if ($i > $pro_max_counters)
$i = 0;
return array($i,$counterNameList);
}
/** Returns the counter name of the given url or the url if the name was
* not found.
*
* The purpose of this method is only to provide legacy support for
* counter names given in existing urls, as in taelnummer(). Please do not
* use it for anything else.
*
* @public
* @param $url the one to find a name for.
* @return the name of the $url or the whole url.
*/
static function taelnummer_url2name($url) {
$filename = $url;
//Remove text after ? and # (both included).
if (strpos($filename,'?') > 0)
$filename = substr($filename,0,strpos($filename,'?'));
if (strpos($filename,'#') > 0)
$filename = substr($filename,0,strpos($filename,'#'));
$filenameArray = explode("/",$filename);
if (isset($filenameArray[2])) {
$domain = $filenameArray[2];
} else {
$domain = "";
}
$filenameArray = array_reverse($filenameArray);
//Use index 0 (folder name) or index 1 (file name)?
if (strlen($filenameArray[0]) == 0)
$useIndex = 1;
else
$useIndex = 0;
if (isset($filenameArray[$useIndex])) {
if ($filenameArray[$useIndex] == $domain)
$filename = strtolower($filenameArray[$useIndex]);
else
$filename = $filenameArray[$useIndex];
} else {
$filename = "";;
}
return $filename;
}
/**
* Returns if the given string is a valid e-mail address.
*
* @public
* @param $mail The e-mail address to validate.
* @return boolean if the given string is a valid e-mail address.
*/
static function okmail($mail)
{
return true; // preg_match("/[\w-_.]+\@[\w-_.]/",$mail);
}
/**
* Returns if the given string is a valid web url.
*
* @public
* @param $url the url to validate.
* @return boolean if the given string is a valid web url.
*/
function okurl($url)
{
//Nothing is not valid
if ($url === "")
return 0;
if ( preg_match("%^https?://[a-z0-9\-.]+\.[a-z0-9\-.~_#/=?+&]+%i",$url)) {
//Valid - pure url.
return 1;
} elseif (strpos(strtolower($url),"mailto:") == 0) {
//mailto url: Validate as e-mail.
return Html::okmail(substr($url,7));
} else {
//We don't know this one: Invalid.
return 0;
}
}
/**
* Returns the parameters of the given url.
*
* @public
* @param $url the url to get parameters from.
* @return String[] associative array with the parameres of the url.
*/
function urlkeys($url)
{
//No parameters.
if (strpos($url,"?") === false)
return array();
//Cut off the domain + path part.
$url = substr($url,strpos($url,"?")+1);
//Split it.
$urlArray = explode("&",$url);
//Separate into key/value pairs.
$params = array();
foreach ($urlArray as $keyvals)
{
$tmp = explode("=",$keyvals);
$params[$tmp[0]] = $tmp[1];
}
return $params;
}
/**
* Add <code>String</code> zeros on the empty places in the given array.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $upTo add zeros on empty places up to this index.
* @param $anArray the array that shall have zeros added.
* @return Object[] an array with zeros on empty spots.
*/
static function addZeros($upTo,$anArray)
{
for ($i = 0;$i <= $upTo;$i++)
if (!isset($anArray[$i]) or $anArray[$i] === 0 or $anArray[$i] == "")
$anArray[$i] = '0';
return $anArray;
}
/**
* Removes invalid data pairs.
* Returns an array containing two arrays. Index 0 contains the new
* text array and index 1 contains the new number array.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $textArray an array containing text witch matches the numbers in
* the following parameter.
* @param $numersArray an array containing numbers witch matches the text
* in the previous array.
* @return String[][] an array containing the two new arrays.
*/
static function removeInvalidData($textArray,$numbersArray)
{
//Arryays the valid data is put into.
$textOkArray = array();
$numOkArray = array();
//Iterates the data
for ($i = 0;$i < sizeof($textArray);$i++)
{
//Checks the data and
if (
isset($textArray[$i]) and $textArray[$i] !== "" and $textArray[$i] !== 0
and $textArray[$i] !== " " and $textArray[$i] !== " " and $textArray[$i] !== null
and
isset($numbersArray[$i]) and $numbersArray[$i] > 0 and $numbersArray[$i] !== ""
and $numbersArray[$i] !== " " and $numbersArray[$i] !== null
)
{ /*If the data is OK*/
$textOkArray[] = $textArray[$i];
$numOkArray[] = $numbersArray[$i];
}
} /*End of for ...*/
return array($textOkArray, $numOkArray);
}
/**
* Returns the length of the given month.
* 1 is January and 12 is December.
*
* @public
* @version 0.0.1
* @since 0.0.1
* @param $month the month of witch the length shall be returned.
* @return int the length of the given month.
*/
static function lengthOfMont($month)
{
$dates = getDate();
if ($month == 1) return 31; /*January*/
elseif (($month == 2) and ($dates['year']/4 != round($dates['year']/4))) return 28;
elseif (($month == 2) and ($dates['year']/4 == round($dates['year']/4))) return 29;
elseif ($month == 3) return 31;
elseif ($month == 4) return 30;
elseif ($month == 5) return 31;
elseif ($month == 6) return 30;
elseif ($month == 7) return 31;
elseif ($month == 8) return 31;
elseif ($month == 9) return 30;
elseif ($month == 10) return 31;
elseif ($month == 11) return 30;
else return 31;
}
/**
* Converts the given @c $str to a boolean value of @c 0 for @c false,
* @c 1 for @c true and @c 2 for don't know.
*
* @param $str the one to convert.
* @return 0, 1 or 2.
*/
function toBool($str) {
//Make sure we can treat even messy strings.
$str = strtolower(trim($str));
//Language notes: 'ja' is yes and 'nej' is no in danish.
//Note the non typed comparison (== and not ===).
if (strlen($str) > 0 and $str == "false" or $str == "no" or $str == "nej" or $str == "0") {
return 0;
} else if (strlen($str) > 0 and $str == "true" or $str == "yes" or $str == "ja" or $str == "1") {
return 1;
} else {
return 2;
}
}
/**
* Returns the current unix time adjusted acording to settings and
* algorithms.
*
* @param $time the time to adjust. If not given, the output of the
* @c time() function is used.
* @param $settings an instance of the settings object. This should only