function.uniqueid.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2015 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 
12 /*
13 * Smarty plugin
14 * -------------------------------------------------------------
15 * File: function.uniqueid.php
16 * Type: function
17 * Name: uniqueid
18 * Purpose: output an unique id or assign it to a smarty variable
19 * Usage: e.g. {uniqueid} or {uniqueid varname="uid"}
20 * -------------------------------------------------------------
21 */
22 function smarty_function_uniqueid($params, \Smarty_Internal_Template $template) {
23  $uid = md5(uniqid(ip2long($_SERVER['REMOTE_ADDR']) ^ (int)$_SERVER['REMOTE_PORT'] ^ @getmypid() ^ @disk_free_space('/tmp'), 1));
24  if (isset($params['varname'])) {
25  $template->assign($params['varname'], $uid);
26  }
27  else {
28  echo $uid;
29  }
30 }
31 ?>