Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • AccountsGridViewProfileWidget
  • ActionMenu
  • ActionsGridViewProfileWidget
  • ActionsQuickCreateRelationshipBehavior
  • ActiveDateRangeInput
  • ApplicationConfigBehavior
  • Attachments
  • ChatBox
  • CommonControllerBehavior
  • ContactMapInlineTags
  • ContactsGridViewProfileWidget
  • CronForm
  • CSaveRelationsBehavior
  • DateRangeInputsWidget
  • DocsGridViewProfileWidget
  • DocViewer
  • DocViewerProfileWidget
  • EButtonColumnWithClearFilters
  • EmailDeliveryBehavior
  • EmailProgressControl
  • EncryptedFieldsBehavior
  • EventsChartProfileWidget
  • FileUploader
  • FontPickerInput
  • Formatter
  • FormView
  • GridViewWidget
  • History
  • IframeWidget
  • ImportExportBehavior
  • InlineActionForm
  • InlineEmailAction
  • InlineEmailForm
  • InlineEmailModelBehavior
  • InlineQuotes
  • JSONEmbeddedModelFieldsBehavior
  • JSONFieldsDefaultValuesBehavior
  • LeadRoutingBehavior
  • LeftWidget
  • LoginThemeHelper
  • LoginThemeHelperBase
  • MarketingGridViewProfileWidget
  • MediaBox
  • MessageBox
  • MobileFormatter
  • MobileFormLayoutRenderer
  • MobileLayoutRenderer
  • MobileLoginThemeHelper
  • MobileViewLayoutRenderer
  • ModelFileUploader
  • NewWebLeadsGridViewProfileWidget
  • NormalizedJSONFieldsBehavior
  • NoteBox
  • OnlineUsers
  • OpportunitiesGridViewProfileWidget
  • Panel
  • ProfileDashboardManager
  • ProfileGridViewWidget
  • ProfileLayoutEditor
  • ProfilesGridViewProfileWidget
  • Publisher
  • PublisherActionTab
  • PublisherCalendarEventTab
  • PublisherCallTab
  • PublisherCommentTab
  • PublisherEventTab
  • PublisherSmallCalendarEventTab
  • PublisherTab
  • PublisherTimeTab
  • QuickContact
  • QuickCreateRelationshipBehavior
  • QuotesGridViewProfileWidget
  • RecordAliasesWidget
  • RecordViewLayoutManager
  • RecordViewWidgetManager
  • RememberPagination
  • Reminders
  • ResponseBehavior
  • ResponsiveHtml
  • SearchIndexBehavior
  • ServicesGridViewProfileWidget
  • SmallCalendar
  • SmartActiveDataProvider
  • SmartDataProviderBehavior
  • SmartSort
  • SocialForm
  • SortableWidgetManager
  • SortableWidgets
  • TagBehavior
  • TagCloud
  • TemplatesGridViewProfileWidget
  • TimeZone
  • TopContacts
  • TopSites
  • TransformedFieldStorageBehavior
  • TranslationLogger
  • TwitterFeed
  • TwoColumnSortableWidgetManager
  • UpdaterBehavior
  • UpdatesForm
  • UserIdentity
  • UsersChartProfileWidget
  • WorkflowBehavior
  • X2ActiveGridView
  • X2ActiveGridViewForSortableWidgets
  • X2AssetManager
  • X2AuthManager
  • X2ChangeLogBehavior
  • X2ClientScript
  • X2Color
  • X2DateUtil
  • X2FixtureManager
  • X2FlowFormatter
  • X2GridView
  • X2GridViewBase
  • X2GridViewForSortableWidgets
  • X2GridViewSortableWidgetsBehavior
  • X2LeadsGridViewProfileWidget
  • X2LinkableBehavior
  • X2ListView
  • X2PillBox
  • X2ProgressBar
  • X2SmartSearchModelBehavior
  • X2TimestampBehavior
  • X2TranslationBehavior
  • X2UrlRule
  • X2WebModule
  • X2Widget
  • X2WidgetList
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: /**
 38:  * Color utilities (unused)
 39:  * 
 40:  * @package application.components 
 41:  */
 42: class X2Color {
 43: 
 44:     /**
 45:      * Converts HEX color to YIQ color 
 46:      */
 47:     public static function rgb2yiq ($color) {
 48:         // RGB -> YIQ transformation matrix
 49:         $matrixA = array (
 50:             array (0.299, 0.587, 0.144),
 51:             array (0.595716, -0.274453, -0.321263),
 52:             array (0.211456, -0.522591, 0.31135),
 53:         );
 54:         $product = array ();
 55:         $matrixB = $color;
 56:         foreach ($matrixA as $row) {
 57:             $product[] = $row[0] * $matrixB[0] + $row[1] * $matrixB[1] + $row[2] * $matrixB[2]; 
 58:         }
 59:         return $product;
 60:     }
 61: 
 62:     /**
 63:      * @return int
 64:      */
 65:     public static function getColorBrightness ($hexColor) {
 66:         $rgb = self::hex2rgb ($hexColor);
 67:         if (!is_array ($rgb)) {
 68:             return false;
 69:         }
 70:         $yiq = self::rgb2yiq ($rgb);
 71:         return $yiq[0];
 72:     }
 73: 
 74:     // convert HEX color to RGB values
 75:     public static function hex2rgb($color) {
 76:         if($color[0] == '#')
 77:             $color = substr($color, 1);
 78:         
 79:         if(strlen($color) === 6)
 80:             list($r,$g,$b) = array($color[0].$color[1],$color[2].$color[3],$color[4].$color[5]);
 81:         elseif (strlen($color) === 3)
 82:             list($r,$g,$b) = array($color[0].$color[0],$color[1].$color[1],$color[2].$color[2]);
 83:         else
 84:             return false;
 85:         
 86:         return array(hexdec($r),hexdec($g),hexdec($b));
 87:     }
 88:     
 89:     public static function rgb2hex($r,$g,$b) {
 90:         $r = dechex($r);
 91:         $g = dechex($g);
 92:         $b = dechex($b);
 93:         if(strlen($r) < 2)
 94:             $r = '0'.$r;
 95:         if(strlen($g) <2 )
 96:             $g = '0'.$g;
 97:         if(strlen($b) < 2)
 98:             $b = '0'.$b;
 99:         
100:         return $r.$g.$b;
101:     }
102: 
103:     public static function rgb2hex2($r, $g=-1, $b=-1, $hash = '#') {
104:         if (is_array($r) && sizeof($r) == 3)
105:             list($r, $g, $b) = $r;
106: 
107:         $r = intval($r); 
108:         $g = intval($g);
109:         $b = intval($b);
110: 
111:         $r = dechex($r<0?0:($r>255?255:$r));
112:         $g = dechex($g<0?0:($g>255?255:$g));
113:         $b = dechex($b<0?0:($b>255?255:$b));
114: 
115:         $color = (strlen($r) < 2?'0':'').$r;
116:         $color .= (strlen($g) < 2?'0':'').$g;
117:         $color .= (strlen($b) < 2?'0':'').$b;
118:         return $hash.$color;
119:     }
120: 
121:     public static function hex2rgb2($color) {
122:         if ($color[0] == '#')
123:             $color = substr($color, 1);
124: 
125:         if (strlen($color) >= 6)
126:             list($r, $g, $b) = array($color[0].$color[1],
127:                                      $color[2].$color[3],
128:                                      $color[4].$color[5]);
129:         else if (strlen($color) == 3)
130:             list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
131:         else
132:             return false;
133: 
134:         $r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
135: 
136:         return array($r, $g, $b);
137:     }
138: 
139:     /**
140:      * Adjusts the brightness of a color
141:      * @param string $color The hexcode of the target color (with or without hash)
142:      * @param float $percent The adjustment to be made. < 0 indicated darker, >0 indicated lighter
143:      * @param boolean $smartMode If true, the color difference will reverse when necessary. 
144:      * @return string the adjusted hexcode
145:      */
146:     public static function brightness($color, $percent, $smartMode=false){
147:         if(!$color)
148:             return '';
149: 
150:         $color = self::hex2rgb2($color);
151:         if (!$color)
152:             return '';
153: 
154:         if ($smartMode) {
155:             $hsb = self::rgbtohsb($color);
156:             if ($hsb[2] > 0.6) {
157:                 $percent *= -1;
158:             }
159:         }
160: 
161: 
162:         $color[0] += 255*$percent;
163:         $color[1] += 255*$percent;
164:         $color[2] += 255*$percent;
165:         return self::rgb2hex2($color[0], $color[1], $color[2]);
166: 
167:     }
168: 
169:     public static function opaque($color, $percent = 0.9){
170:         if(!$color)
171:             return '';
172: 
173:         $color = self::hex2rgb2($color);
174: 
175:         return "rgba($color[0], $color[1], $color[2], $percent)" ;
176: 
177:     }
178: 
179:     public static function smartText($context, $text) {
180:         if(!$text || !$context){
181:             return '';
182:         }
183: 
184:         $contextRGB = self::hex2rgb2($context);
185:         $textRGB = self::hex2rgb2($text);
186: 
187:         $contextHSB = self::rgbtohsb($contextRGB);
188:         $textHSB = self::rgbtohsb($textRGB);
189: 
190:         $diff = $contextHSB[2] - $textHSB[2];
191:         if ( abs($diff) > 0.56 ) {
192: 
193:             return $text;
194:         }
195: 
196:         $h = $contextHSB[2] < 0.6 ? 0.8 : -0.8;
197:     
198:         $textHSB[2] += $h;
199: 
200:         $textRGB = self::hsbtorgb($textHSB);
201:         $text = self::rgb2hex2($textRGB);
202: 
203: 
204:         return $text;
205:     }
206: 
207:     public static function rgbtohsb( $rgb ) {
208:         $red = $rgb[0];
209:         $green = $rgb[1];
210:         $blue = $rgb[2];
211: 
212:         $oldR = $red;
213:         $oldG = $green;
214:         $oldB = $blue;
215: 
216: 
217:         $red /= 255;
218:         $green /= 255;
219:         $blue /= 255;
220: 
221:         $max = max( $red, $green, $blue );
222:         $min = min( $red, $green, $blue );
223: 
224:         $hue;
225:         $sat;
226:         $lum = ( $max + $min ) / 2;
227:         $diff = $max - $min;
228: 
229:             if( $diff == 0 ){
230:                 $hue = $sat = 0;
231:             } else {
232:                 $sat = $diff / ( 1 - abs( 2 * $lum - 1 ) );
233: 
234:             switch( $max ){
235:                     case $red:
236:                         $hue = 60 * fmod( ( ( $green - $blue ) / $diff ), 6 ); 
237:                             if ($blue > $green) {
238:                             $hue += 360;
239:                         }
240:                         break;
241: 
242:                     case $green: 
243:                         $hue = 60 * ( ( $blue - $red ) / $diff + 2 ); 
244:                         break;
245: 
246:                     case $blue: 
247:                         $hue = 60 * ( ( $red - $green ) / $diff + 4 ); 
248:                         break;
249:                 }                               
250:         }
251: 
252:         return array( round( $hue, 2 ), round( $sat, 2 ), round( $lum, 2 ) );
253:     }
254: 
255:     public static function hsbtorgb( $hsb ){
256: 
257:         foreach ($hsb as $i => $v){
258:             $hsb[$i] = ($v < 1) ? $v : 1;
259:             $hsb[$i] = ($v > 0) ? $v : 0;
260:         }
261: 
262:         $hue = $hsb[0];
263:         $sat = $hsb[1];
264:         $lum = $hsb[2];
265: 
266:         $red; 
267:         $green; 
268:         $blue;
269: 
270:         $c = ( 1 - abs( 2 * $lum - 1 ) ) * $sat;
271:         $x = $c * ( 1 - abs( fmod( ( $hue / 60 ), 2 ) - 1 ) );
272:         $m = $lum - ( $c / 2 );
273: 
274:         if ( $hue < 60 ) {
275:             $red = $c;
276:             $green = $x;
277:             $blue = 0;
278: 
279:         } else if ($hue < 120) {
280:             $red = $x;
281:             $green = $c;
282:             $blue = 0;      
283: 
284:         } else if ($hue < 180) {
285:             $red = 0;
286:             $green = $c;
287:             $blue = $x;       
288: 
289:         } else if ($hue < 240) {
290:             $red = 0;
291:             $green = $x;
292:             $blue = $c;
293: 
294:         } else if ($hue < 300) {
295:             $red = $x;
296:             $green = 0;
297:             $blue = $c;
298: 
299:         } else {
300:             $red = $c;
301:             $green = 0;
302:             $blue = $x;
303:         }
304: 
305:         $red = ( $red + $m ) * 255;
306:         $green = ( $green + $m ) * 255;
307:         $blue = ( $blue + $m  ) * 255;
308: 
309:         return array( floor( $red ), floor( $green ), floor( $blue ) );
310:     }
311:     
312:     public static function gradientCss($color1,$color2) {
313:         return "
314:             background:$color1;
315:             background:-moz-linear-gradient(top, $color1 0%, $color2 100%);
316:             background:-webkit-gradient(linear, left top, left bottom, color-stop(0%,$color1), color-stop(100%,$color2));
317:             background:-webkit-linear-gradient(top, $color1 0%,$color2 100%);
318:             background:-o-linear-gradient(top, $color1 0%,$color2 100%);
319:             background:-ms-linear-gradient(top, $color1 0%,$color2 100%);
320:             background:linear-gradient(to bottom, $color1 0%,$color2 100%);
321:             filter:progid:DXImageTransform.Microsoft.gradient( startColorstr='$color1', endColorstr='$color2',GradientType=0);";
322:     }
323: 
324:     public static function HSVToRGB ($h, $s, $v) {
325:         $h *= 360;
326:         $c = $v * $s;
327:         $hPrime = $h / 60;
328:         $x = $c * (1 - abs (fmod ($hPrime, 2) - 1));
329:         switch (floor ($hPrime)) {
330:             case 0:
331:                 list ($r, $g, $b) = array ($c, $x, 0);
332:                 break;
333:             case 1:
334:                 list ($r, $g, $b) = array ($x, $c, 0);
335:                 break;
336:             case 2:
337:                 list ($r, $g, $b) = array (0, $c, $x);
338:                 break;
339:             case 3:
340:                 list ($r, $g, $b) = array (0, $x, $c);
341:                 break;
342:             case 4:
343:                 list ($r, $g, $b) = array ($x, 0, $c);
344:                 break;
345:             case 5:
346:                 list ($r, $g, $b) = array ($c, 0, $x);
347:                 break;
348:         }
349:         $r *= 255;
350:         $g *= 255;
351:         $b *= 255;
352:         return array (floor ($r), floor ($g), floor ($b));
353:     }
354: 
355:     public static function generatePalette ($count, $seed=null, $s=0.95, $v=0.99) {
356:         $goldenRatio = 0.6180339887;
357:         if ($seed === null)
358:             $h = rand () / getrandmax ();
359:         else
360:             $h = $seed;
361:         $colors = array ();
362:         for ($i = 0; $i < $count; $i++) {
363:             $h += $goldenRatio;
364:             $h = fmod ($h, 1);
365:             $colors[] = self::HSVToRGB ($h, $s, $v);
366:         }
367:         return $colors;
368:     }
369: }
370: ?>
371: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0