1<?php
2/**
3 * Helper for DokuWiki Plugin netlogo
4 *
5 * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
6 * @author  Rik Blok <rik.blok@ubc.ca>
7 *
8 * ToDo:
9 */
10
11function relativePath($from, $to, $ps = '/')
12// Returns the relative path from $from to $to. Note: On Windows it does not work when $from and $to are on different drives.
13// From http://www.php.net/manual/en/function.realpath.php#105876
14{
15  $arFrom = explode($ps, rtrim($from, $ps));
16  $arTo = explode($ps, rtrim($to, $ps));
17  while(count($arFrom) && count($arTo) && ($arFrom[0] == $arTo[0]))
18  {
19    array_shift($arFrom);
20    array_shift($arTo);
21  }
22  return str_pad("", count($arFrom) * 3, '..'.$ps).implode($ps, $arTo);
23}
24
25function uuid4()
26// Returns valid version 4 UUID.
27// From http://www.php.net/manual/en/function.com-create-guid.php#99425
28// See https://en.wikipedia.org/wiki/Uuid#Version_4_.28random.29
29{
30    if (function_exists('com_create_guid') === true)
31    {
32        return trim(com_create_guid(), '{}');
33    }
34
35    return sprintf('%04X%04X-%04X-%04X-%04X-%04X%04X%04X', mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(16384, 20479), mt_rand(32768, 49151), mt_rand(0, 65535), mt_rand(0, 65535), mt_rand(0, 65535));
36}
37
38
39// vim:ts=4:sw=4:et:
40