ossn.lib.route.php
Go to the documentation of this file.
1 <?php
2 /**
3  * Open Source Social Network
4  *
5  * @package (Informatikon.com).ossn
6  * @author OSSN Core Team <[email protected]>
7  * @copyright 2014 iNFORMATIKON TECHNOLOGIES
8  * @license General Public Licence http://www.opensource-socialnetwork.org/licence
9  * @link http://www.opensource-socialnetwork.org/licence
10  */
11 
12 /**
13  * Ossn Convert arrays to Object
14  *
15  * @param array $array Arrays
16  * @param string $class class name ,else it will be object of stdClass
17  *
18  * @return object
19  */
20 function arrayObject($array, $class = 'stdClass') {
21  $object = new $class;
22  if (empty($array)) {
23  return false;
24  }
25  foreach ($array as $key => $value) {
26  if (strlen($key)) {
27  if (is_array($value)) {
28  $object->{$key} = arrayObject($value, $class);
29  } else {
30  $object->{$key} = $value;
31  }
32  }
33  }
34  return $object;
35 }
36 
37 /**
38  * Force Object
39  * Sometimes php can't get object class ,
40  * so we need to make sure that object have class name
41  *
42  * @param object $object Object
43  *
44  * @return object
45  */
46 function forceObject(&$object) {
47  if (!is_object($object) && gettype($object) == 'object'
48  )
49  return ($object = unserialize(serialize($object)));
50  return $object;
51 }
52 
53 /**
54  * Get system directory paths
55  *
56  * @return object
57  */
58 function ossn_route() {
59  $root = str_replace("\\", "/", dirname(dirname(__FILE__)));
60  $defaults = array(
61  'www' => "$root/",
62  'libs' => "$root/libraries/",
63  'classes' => "$root/classes/",
64  'actions' => "$root/actions/",
65  'locale' => "$root/locale/",
66  'sys' => "$root/system/",
67  'configs' => "$root/configurations/",
68  'themes' => "$root/themes/",
69  'pages' => "$root/pages/",
70  'com' => "$root/components/",
71  'admin' => "$root/admin/",
72  'forms' => "$root/forms/",
73  'upgrade' => "$root/upgrade/",
74  'cache' => "{$root}/cache/",
75  'js' => "$root/javascripts/",
76  'system' => "$root/system/",
77  'components' => "$root/components",
78  );
79  return arrayObject($defaults);
80 }
81 
82 /**
83  * Get current url
84  *
85  * @param string $uport Want port or not? default will be disable
86  *
87  * @return object
88  */
89 function current_url($uport = '') {
90  $protocol = 'http';
91  $uri = $_SERVER['REQUEST_URI'];
92  if ($uport == true) {
93  $uri = substr($uri, 0, $uri);
94  }
95  if (!empty($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
96  $protocol = 'https';
97  }
98  $port = ':' . $_SERVER["SERVER_PORT"];
99  if ($port == ':80' || $port == ':443') {
100  if ($uport == true) {
101  $port = '';
102  }
103  }
104  $url = "$protocol://{$_SERVER['SERVER_NAME']}$port{$uri}";
105  return $url;
106 }