[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* +*********************************************************************************** 4 * The contents of this file are subject to the vtiger CRM Public License Version 1.0 5 * ("License"); You may not use this file except in compliance with the License 6 * The Original Code is: vtiger CRM Open Source 7 * The Initial Developer of the Original Code is vtiger. 8 * Portions created by vtiger are Copyright (C) vtiger. 9 * All Rights Reserved. 10 *************************************************************************************/ 11 12 /** 13 * Helper methods to work with ShortURLs 14 */ 15 class Vtiger_ShortURL_Helper { 16 /* 17 * @param options array( 18 * 'handler_path' => 'path/to/TrackerClass.php', 19 * 'handler_class' => 'TrackerClass', 20 * 'handler_function' => 'trackingFunction', 21 * 'handler_data' => array( 22 * 'key1' => 'value1', 23 * 'key2' => 'value2' 24 * ) 25 * )); 26 */ 27 28 static function generateURL(array $options) { 29 global $site_URL; 30 if (!isset($options['onetime'])) 31 $options['onetime'] = 0; 32 $uid = self::generate($options); 33 return rtrim($site_URL, '/') . "/shorturl.php?id=" . $uid; 34 } 35 36 static function generate(array $options) { 37 $db = PearDatabase::getInstance(); 38 39 // TODO Review the random unique ID generation 40 $uid = uniqid("", true); 41 42 $handlerPath = $options['handler_path']; 43 $handlerClass = $options['handler_class']; 44 $handlerFn = $options['handler_function']; 45 $handlerData = $options['handler_data']; 46 47 if (empty($handlerPath) || empty($handlerClass) || empty($handlerFn)) { 48 throw new Exception("Invalid options for generate"); 49 } 50 51 $sql = "INSERT INTO vtiger_shorturls(uid, handler_path, handler_class, handler_function, handler_data, onetime) VALUES (?,?,?,?,?,?)"; 52 $params = array($uid, $handlerPath, $handlerClass, $handlerFn, json_encode($handlerData), $options['onetime']); 53 54 $db->pquery($sql, $params); 55 return $uid; 56 } 57 58 static function handle($uid) { 59 $db = PearDatabase::getInstance(); 60 61 $rs = $db->pquery('SELECT * FROM vtiger_shorturls WHERE uid=?', array($uid)); 62 if ($rs && $db->num_rows($rs)) { 63 $record = $db->fetch_array($rs); 64 $handlerPath = decode_html($record['handler_path']); 65 $handlerClass = decode_html($record['handler_class']); 66 $handlerFn = decode_html($record['handler_function']); 67 $handlerData = json_decode(decode_html($record['handler_data']), true); 68 69 checkFileAccessForInclusion($handlerPath); 70 require_once $handlerPath; 71 72 $handler = new $handlerClass(); 73 74 // Delete onetime URL 75 if ($record['onetime']) 76 $db->pquery('DELETE FROM vtiger_shorturls WHERE id=?', array($record['id'])); 77 call_user_func(array($handler, $handlerFn), $handlerData); 78 } else { 79 echo '<h3>Link you have used is invalid or has expired. .</h3>'; 80 } 81 } 82 83 /** 84 * Function will send tracker image of 1X1 pixel transparent Image 85 */ 86 static function sendTrackerImage() { 87 header('Content-Type: image/png'); 88 echo base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABAQMAAAAl21bKAAAAA1BMVEUAAACnej3aAAAAAXRSTlMAQObYZgAAAApJREFUCNdjYAAAAAIAAeIhvDMAAAAASUVORK5CYII='); 89 } 90 91 function getInstance($id) { 92 $db = PearDatabase::getInstance(); 93 $self = new self(); 94 $rs = $db->pquery('SELECT * FROM vtiger_shorturls WHERE uid=?', array($id)); 95 if ($rs && $db->num_rows($rs)) { 96 $row = $db->fetch_array($rs); 97 $self->id = $row['id']; 98 $self->uid = $row['uid']; 99 $self->handler_path = $row['handler_path']; 100 $self->handler_class = $row['handler_class']; 101 $self->handler_function = $row['handler_function']; 102 $self->handler_data = json_decode(decode_html($row['handler_data']), true); 103 } 104 return $self; 105 } 106 107 function compareEquals($data) { 108 $valid = true; 109 if ($this->handler_data) { 110 foreach ($this->handler_data as $key => $value) { 111 if ($data[$key] != $value) { 112 $valid = false; 113 break; 114 } 115 } 116 } else { 117 $valid = false; 118 } 119 return $valid; 120 } 121 122 function delete() { 123 $db = PearDatabase::getInstance(); 124 $db->pquery('DELETE FROM vtiger_shorturls WHERE id=?', array($this->id)); 125 } 126 127 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |