Index: /modules/branches/2.10/endpointman/emportal =================================================================== --- /modules/branches/2.10/endpointman/emportal (revision 14127) +++ /modules/branches/2.10/endpointman/emportal (revision 14127) @@ -0,0 +1,132 @@ +#!/usr/bin/php +fg_color("bold_red", "Sorry FreePBX 2.9+ is required\n")); +} + +require_once 'includes/functions.inc'; +if(!include_once 'Console/Getopt.php') { + die($colors->fg_color("bold_red", "Pear Console_Getopt Required\nTry to run 'pear install Console_Getopt'")); +} + +$debug = NULL; +$endpoint = new endpointmanager(); +echo $colors->fg_color("bold_red", "Endpoint Manager CLI\n\n"); + +$cg = new Console_Getopt(); +$args = $cg->readPHPArgv(); +array_shift($args); + +$shortOpts = 'h::'; +$longOpts = array('user=', 'group='); + +$params = $cg->getopt2($args, $shortOpts, $longOpts); + +print_r(condense_arguments($params)); + + +echo "\n"; + +if (PEAR::isError($params)) { + echo 'Error: ' . $params->getMessage() . "\n"; + exit(1); +} + +function &condense_arguments($params) +{ + $new_params = array(); + foreach ($params[0] as $param) { + $new_params[$param[0]] = $param[1]; + } + return $new_params; +} + +/** + * Color escapes for bash output + */ +class Escape_Colors +{ + private static $foreground = array( + 'black' => '0;30', + 'dark_gray' => '1;30', + 'red' => '0;31', + 'bold_red' => '1;31', + 'green' => '0;32', + 'bold_green' => '1;32', + 'brown' => '0;33', + 'yellow' => '1;33', + 'blue' => '0;34', + 'bold_blue' => '1;34', + 'purple' => '0;35', + 'bold_purple' => '1;35', + 'cyan' => '0;36', + 'bold_cyan' => '1;36', + 'white' => '1;37', + 'bold_gray' => '0;37', + ); + + private static $background = array( + 'black' => '40', + 'red' => '41', + 'magenta' => '45', + 'yellow' => '43', + 'green' => '42', + 'blue' => '44', + 'cyan' => '46', + 'light_gray' => '47', + ); + + /** + * Make string appear in color + */ + public static function fg_color($color, $string) + { + if (!isset(self::$foreground[$color])) + { + throw new Exception('Foreground color is not defined'); + } + + return "\033[" . self::$foreground[$color] . "m" . $string . "\033[0m"; + } + + /** + * Make string appear with background color + */ + public static function bg_color($color, $string) + { + if (!isset(self::$background[$color])) + { + throw new Exception('Background color is not defined'); + } + + return "\033[" . self::$background[$color] . 'm' . $string . "\033[0m"; + } + + /** + * See what they all look like + */ + public static function all_fg() + { + foreach (self::$foreground as $color => $code) + { + echo "$color - " . self::fg_color($color, 'Hello, world!') . PHP_EOL; + } + } + + /** + * See what they all look like + */ + public static function all_bg() + { + foreach (self::$background as $color => $code) + { + echo "$color - " . self::bg_color($color, 'Hello, world!') . PHP_EOL; + } + } +} Index: /modules/branches/2.10/endpointman/includes/diff.class.inc =================================================================== --- /modules/branches/2.10/endpointman/includes/diff.class.inc (revision 14127) +++ /modules/branches/2.10/endpointman/includes/diff.class.inc (revision 14127) @@ -0,0 +1,232 @@ + + May be used and distributed under the zlib/libpng license. + + ... for the actual diff code, i changed a few things and implemented a pretty interface to it. +*/ +class diff { + + var $changes = array(); + var $diff = array(); + var $linepadding = null; + + function doDiff($old, $new){ + if (!is_array($old)) $old = file($old); + if (!is_array($new)) $new = file($new); + + foreach($old as $oindex => $ovalue){ + $nkeys = array_keys($new, $ovalue); + foreach($nkeys as $nindex){ + $matrix[$oindex][$nindex] = isset($matrix[$oindex - 1][$nindex - 1]) ? $matrix[$oindex - 1][$nindex - 1] + 1 : 1; + if($matrix[$oindex][$nindex] > $maxlen){ + $maxlen = $matrix[$oindex][$nindex]; + $omax = $oindex + 1 - $maxlen; + $nmax = $nindex + 1 - $maxlen; + } + } + } + if($maxlen == 0) return array(array('d'=>$old, 'i'=>$new)); + + return array_merge( + $this->doDiff(array_slice($old, 0, $omax), array_slice($new, 0, $nmax)), + array_slice($new, $nmax, $maxlen), + $this->doDiff(array_slice($old, $omax + $maxlen), array_slice($new, $nmax + $maxlen))); + + } + + function diffWrap($old, $new){ + $this->diff = $this->doDiff($old, $new); + $this->changes = array(); + $ndiff = array(); + foreach ($this->diff as $line => $k){ + if(is_array($k)){ + if (isset($k['d'][0]) || isset($k['i'][0])){ + $this->changes[] = $line; + $ndiff[$line] = $k; + } + } else { + $ndiff[$line] = $k; + } + } + $this->diff = $ndiff; + return $this->diff; + } + + function formatcode($code){ + $code = htmlentities($code); + $code = str_replace(" ",' ',$code); + $code = str_replace("\t",'    ',$code); + return $code; + } + + function showline($line){ + if ($this->linepadding === 0){ + if (in_array($line,$this->changes)) return true; + return false; + } + if(is_null($this->linepadding)) return true; + + $start = (($line - $this->linepadding) > 0) ? ($line - $this->linepadding) : 0; + $end = ($line + $this->linepadding); + //echo '
'.$line.': '.$start.': '.$end; + $search = range($start,$end); + //pr($search); + foreach($search as $k){ + if (in_array($k,$this->changes)) return true; + } + return false; + + } + + function inline($old, $new, $linepadding=null){ + $this->linepadding = $linepadding; + + $ret = '
';
+		$ret.= '';
+		$count_old = 1;
+		$count_new = 1;
+		
+		$insert = false;
+		$delete = false;
+		$truncate = false;
+		
+		$diff = $this->diffWrap($old, $new);
+
+		foreach($diff as $line => $k){
+			if ($this->showline($line)){
+				$truncate = false;
+				if(is_array($k)){
+					foreach ($k['d'] as $val){
+						$class = '';
+						if (!$delete){
+							$delete = true;
+							$class = 'first';
+							if ($insert) $class = '';
+							$insert = false;
+						}
+						$ret.= '';
+						$ret.= '';
+						$ret.= '';
+						$ret.= '';
+						$count_old++;
+					}
+					foreach ($k['i'] as $val){
+						$class = '';
+						if (!$insert){
+							$insert = true;
+							$class = 'first';
+							if ($delete) $class = '';
+							$delete = false;
+						}
+						$ret.= '';
+						$ret.= '';
+						$ret.= '';
+						$ret.= '';
+						$count_new++;
+					}
+				} else {
+					$class = ($delete) ? 'del_end' : '';
+					$class = ($insert) ? 'ins_end' : $class;
+					$delete = false;
+					$insert = false;
+					$ret.= '';
+					$ret.= '';
+					$ret.= '';
+					$ret.= '';
+					$count_old++;
+					$count_new++;
+				}
+			} else {
+				$class = ($delete) ? 'del_end' : '';
+				$class = ($insert) ? 'ins_end' : $class;
+				$delete = false;
+				$insert = false;
+				
+				if (!$truncate){
+					$truncate = true;
+					$ret.= '';
+					$ret.= '';
+					$ret.= '';
+					$ret.= '';
+				}
+				$count_old++;
+				$count_new++;
+
+			}
+		}
+		$ret.= '
OldNew
'.$count_old.' '.$this->formatcode($val).'
 '.$count_new.''.$this->formatcode($val).'
'.$count_old.''.$count_new.''.$this->formatcode($k).'
...... 
'; + return $ret; + } +} +?> + +inline('users_controller.42.php','users_controller.45.php',2); +echo count($diff->changes).' changes'; +echo $text;