idx
int64
0
60.3k
question
stringlengths
64
4.24k
target
stringlengths
5
618
45,200
public function initScatterSerie ( $ ID ) { if ( isset ( $ this -> Data [ "ScatterSeries" ] [ $ ID ] ) ) { return null ; } $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Description" ] = "Scatter " . $ ID ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "isDrawable" ] = true ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Picture" ] = null ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Ticks" ] = 0 ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Weight" ] = 0 ; if ( isset ( $ this -> Palette [ $ ID ] ) ) { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] = $ this -> Palette [ $ ID ] ; } else { $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "R" ] = rand ( 0 , 255 ) ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "G" ] = rand ( 0 , 255 ) ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "B" ] = rand ( 0 , 255 ) ; $ this -> Data [ "ScatterSeries" ] [ $ ID ] [ "Color" ] [ "Alpha" ] = 100 ; } }
Initialise a given scatter serie
45,201
public function initialise ( $ Serie ) { $ ID = 0 ; if ( isset ( $ this -> Data [ "Series" ] ) ) { $ ID = count ( $ this -> Data [ "Series" ] ) ; } $ this -> Data [ "Series" ] [ $ Serie ] [ "Description" ] = $ Serie ; $ this -> Data [ "Series" ] [ $ Serie ] [ "isDrawable" ] = true ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Picture" ] = null ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Max" ] = null ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Min" ] = null ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Axis" ] = 0 ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Ticks" ] = 0 ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Weight" ] = 0 ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Shape" ] = SERIE_SHAPE_FILLEDCIRCLE ; if ( isset ( $ this -> Palette [ $ ID ] ) ) { $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] = $ this -> Palette [ $ ID ] ; } else { $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "R" ] = rand ( 0 , 255 ) ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "G" ] = rand ( 0 , 255 ) ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "B" ] = rand ( 0 , 255 ) ; $ this -> Data [ "Series" ] [ $ Serie ] [ "Color" ] [ "Alpha" ] = 100 ; } $ this -> Data [ "Series" ] [ $ Serie ] [ "Data" ] = [ ] ; }
Initialise a given serie
45,202
public function createFunctionSerie ( $ SerieName , $ Formula = "" , array $ Options = [ ] ) { $ MinX = isset ( $ Options [ "MinX" ] ) ? $ Options [ "MinX" ] : - 10 ; $ MaxX = isset ( $ Options [ "MaxX" ] ) ? $ Options [ "MaxX" ] : 10 ; $ XStep = isset ( $ Options [ "XStep" ] ) ? $ Options [ "XStep" ] : 1 ; $ AutoDescription = isset ( $ Options [ "AutoDescription" ] ) ? $ Options [ "AutoDescription" ] : false ; $ RecordAbscissa = isset ( $ Options [ "RecordAbscissa" ] ) ? $ Options [ "RecordAbscissa" ] : false ; $ AbscissaSerie = isset ( $ Options [ "AbscissaSerie" ] ) ? $ Options [ "AbscissaSerie" ] : "Abscissa" ; if ( $ Formula == "" ) { return null ; } $ Result = [ ] ; $ Abscissa = [ ] ; for ( $ i = $ MinX ; $ i <= $ MaxX ; $ i = $ i + $ XStep ) { $ Expression = "\$return = '!'.(" . str_replace ( "z" , $ i , $ Formula ) . ");" ; if ( @ eval ( $ Expression ) === false ) { $ return = VOID ; } if ( $ return == "!" ) { $ return = VOID ; } else { $ return = $ this -> right ( $ return , strlen ( $ return ) - 1 ) ; } if ( $ return == "NAN" ) { $ return = VOID ; } if ( $ return == "INF" ) { $ return = VOID ; } if ( $ return == "-INF" ) { $ return = VOID ; } $ Abscissa [ ] = $ i ; $ Result [ ] = $ return ; } $ this -> addPoints ( $ Result , $ SerieName ) ; if ( $ AutoDescription ) { $ this -> setSerieDescription ( $ SerieName , $ Formula ) ; } if ( $ RecordAbscissa ) { $ this -> addPoints ( $ Abscissa , $ AbscissaSerie ) ; } }
Create a dataset based on a formula
45,203
public function setGrid ( $ XSize = 10 , $ YSize = 10 ) { for ( $ X = 0 ; $ X <= $ XSize ; $ X ++ ) { for ( $ Y = 0 ; $ Y <= $ YSize ; $ Y ++ ) { $ this -> Points [ $ X ] [ $ Y ] = UNKNOWN ; } } $ this -> GridSizeX = $ XSize ; $ this -> GridSizeY = $ YSize ; }
Define the grid size and initialise the 2D matrix
45,204
public function addPoint ( $ X , $ Y , $ Value , $ Force = true ) { if ( $ X < 0 || $ X > $ this -> GridSizeX ) { return 0 ; } if ( $ Y < 0 || $ Y > $ this -> GridSizeY ) { return 0 ; } if ( $ this -> Points [ $ X ] [ $ Y ] == UNKNOWN || $ Force ) { $ this -> Points [ $ X ] [ $ Y ] = $ Value ; } elseif ( $ this -> Points [ $ X ] [ $ Y ] == UNKNOWN ) { $ this -> Points [ $ X ] [ $ Y ] = $ Value ; } else { $ this -> Points [ $ X ] [ $ Y ] = ( $ this -> Points [ $ X ] [ $ Y ] + $ Value ) / 2 ; } }
Add a point on the grid
45,205
public function writeYLabels ( array $ Format = [ ] ) { $ R = isset ( $ Format [ "R" ] ) ? $ Format [ "R" ] : $ this -> pChartObject -> FontColorR ; $ G = isset ( $ Format [ "G" ] ) ? $ Format [ "G" ] : $ this -> pChartObject -> FontColorG ; $ B = isset ( $ Format [ "B" ] ) ? $ Format [ "B" ] : $ this -> pChartObject -> FontColorB ; $ Alpha = isset ( $ Format [ "Alpha" ] ) ? $ Format [ "Alpha" ] : $ this -> pChartObject -> FontColorA ; $ Angle = isset ( $ Format [ "Angle" ] ) ? $ Format [ "Angle" ] : 0 ; $ Padding = isset ( $ Format [ "Padding" ] ) ? $ Format [ "Padding" ] : 5 ; $ Position = isset ( $ Format [ "Position" ] ) ? $ Format [ "Position" ] : LABEL_POSITION_LEFT ; $ Labels = isset ( $ Format [ "Labels" ] ) ? $ Format [ "Labels" ] : null ; $ CountOffset = isset ( $ Format [ "CountOffset" ] ) ? $ Format [ "CountOffset" ] : 0 ; if ( $ Labels != null && ! is_array ( $ Labels ) ) { $ Label = $ Labels ; $ Labels = [ $ Label ] ; } $ Y0 = $ this -> pChartObject -> GraphAreaY1 ; $ YSize = ( $ this -> pChartObject -> GraphAreaY2 - $ this -> pChartObject -> GraphAreaY1 ) / ( $ this -> GridSizeY + 1 ) ; $ Settings = [ "Angle" => $ Angle , "R" => $ R , "G" => $ G , "B" => $ B , "Alpha" => $ Alpha ] ; if ( $ Position == LABEL_POSITION_LEFT ) { $ XPos = $ this -> pChartObject -> GraphAreaX1 - $ Padding ; $ Settings [ "Align" ] = TEXT_ALIGN_MIDDLERIGHT ; } elseif ( $ Position == LABEL_POSITION_RIGHT ) { $ XPos = $ this -> pChartObject -> GraphAreaX2 + $ Padding ; $ Settings [ "Align" ] = TEXT_ALIGN_MIDDLELEFT ; } else { return - 1 ; } for ( $ Y = 0 ; $ Y <= $ this -> GridSizeY ; $ Y ++ ) { $ YPos = floor ( $ Y0 + $ Y * $ YSize + $ YSize / 2 ) ; if ( $ Labels == null || ! isset ( $ Labels [ $ Y ] ) ) { $ Value = $ Y + $ CountOffset ; } else { $ Value = $ Labels [ $ Y ] ; } $ this -> pChartObject -> drawText ( $ XPos , $ YPos , $ Value , $ Settings ) ; } }
Write the Y labels
45,206
public function computeMissing ( ) { $ Missing = [ ] ; for ( $ X = 0 ; $ X <= $ this -> GridSizeX ; $ X ++ ) { for ( $ Y = 0 ; $ Y <= $ this -> GridSizeY ; $ Y ++ ) { if ( $ this -> Points [ $ X ] [ $ Y ] == UNKNOWN ) { $ Missing [ ] = $ X . "," . $ Y ; } } } shuffle ( $ Missing ) ; foreach ( $ Missing as $ Pos ) { $ Pos = preg_split ( "/,/" , $ Pos ) ; $ X = $ Pos [ 0 ] ; $ Y = $ Pos [ 1 ] ; if ( $ this -> Points [ $ X ] [ $ Y ] == UNKNOWN ) { $ NearestNeighbor = $ this -> getNearestNeighbor ( $ X , $ Y ) ; $ Value = 0 ; $ Points = 0 ; for ( $ Xi = $ X - $ NearestNeighbor ; $ Xi <= $ X + $ NearestNeighbor ; $ Xi ++ ) { for ( $ Yi = $ Y - $ NearestNeighbor ; $ Yi <= $ Y + $ NearestNeighbor ; $ Yi ++ ) { if ( $ Xi >= 0 && $ Yi >= 0 && $ Xi <= $ this -> GridSizeX && $ Yi <= $ this -> GridSizeY && $ this -> Points [ $ Xi ] [ $ Yi ] != UNKNOWN && $ this -> Points [ $ Xi ] [ $ Yi ] != IGNORED ) { $ Value = $ Value + $ this -> Points [ $ Xi ] [ $ Yi ] ; $ Points ++ ; } } } if ( $ Points != 0 ) { $ this -> Points [ $ X ] [ $ Y ] = $ Value / $ Points ; } } } }
Compute the missing points
45,207
public function getNearestNeighbor ( $ Xp , $ Yp ) { $ Nearest = UNKNOWN ; for ( $ X = 0 ; $ X <= $ this -> GridSizeX ; $ X ++ ) { for ( $ Y = 0 ; $ Y <= $ this -> GridSizeY ; $ Y ++ ) { if ( $ this -> Points [ $ X ] [ $ Y ] != UNKNOWN && $ this -> Points [ $ X ] [ $ Y ] != IGNORED ) { $ DistanceX = max ( $ Xp , $ X ) - min ( $ Xp , $ X ) ; $ DistanceY = max ( $ Yp , $ Y ) - min ( $ Yp , $ Y ) ; $ Distance = max ( $ DistanceX , $ DistanceY ) ; if ( $ Distance < $ Nearest || $ Nearest == UNKNOWN ) { $ Nearest = $ Distance ; } } } } return $ Nearest ; }
Return the nearest Neighbor distance of a point
45,208
public function getSize ( $ TextString , $ Format = "" ) { $ Angle = isset ( $ Format [ "Angle" ] ) ? $ Format [ "Angle" ] : 0 ; $ ShowLegend = isset ( $ Format [ "ShowLegend" ] ) ? $ Format [ "ShowLegend" ] : false ; $ LegendOffset = isset ( $ Format [ "LegendOffset" ] ) ? $ Format [ "LegendOffset" ] : 5 ; $ DrawArea = isset ( $ Format [ "DrawArea" ] ) ? $ Format [ "DrawArea" ] : false ; $ FontSize = isset ( $ Format [ "FontSize" ] ) ? $ Format [ "FontSize" ] : 12 ; $ Height = isset ( $ Format [ "Height" ] ) ? $ Format [ "Height" ] : 30 ; $ TextString = $ this -> encode128 ( $ TextString ) ; $ BarcodeLength = strlen ( $ this -> Result ) ; $ WOffset = $ DrawArea ? 20 : 0 ; $ HOffset = $ ShowLegend ? $ FontSize + $ LegendOffset + $ WOffset : 0 ; $ X1 = cos ( $ Angle * PI / 180 ) * ( $ WOffset + $ BarcodeLength ) ; $ Y1 = sin ( $ Angle * PI / 180 ) * ( $ WOffset + $ BarcodeLength ) ; $ X2 = $ X1 + cos ( ( $ Angle + 90 ) * PI / 180 ) * ( $ HOffset + $ Height ) ; $ Y2 = $ Y1 + sin ( ( $ Angle + 90 ) * PI / 180 ) * ( $ HOffset + $ Height ) ; $ AreaWidth = max ( abs ( $ X1 ) , abs ( $ X2 ) ) ; $ AreaHeight = max ( abs ( $ Y1 ) , abs ( $ Y2 ) ) ; return [ "Width" => $ AreaWidth , "Height" => $ AreaHeight ] ; }
Return the projected size of a barcode
45,209
public function drawRectangleMarker ( $ X , $ Y , array $ Format = [ ] ) { $ Size = isset ( $ Format [ "Size" ] ) ? $ Format [ "Size" ] : 4 ; $ HalfSize = floor ( $ Size / 2 ) ; $ this -> drawFilledRectangle ( $ X - $ HalfSize , $ Y - $ HalfSize , $ X + $ HalfSize , $ Y + $ HalfSize , $ Format ) ; }
Draw a rectangular marker of the specified size
45,210
public function drawAlphaPixel ( $ X , $ Y , $ Alpha , $ R , $ G , $ B ) { if ( isset ( $ this -> Mask [ $ X ] ) && isset ( $ this -> Mask [ $ X ] [ $ Y ] ) ) { return 0 ; } if ( $ X < 0 || $ Y < 0 || $ X >= $ this -> XSize || $ Y >= $ this -> YSize ) { return - 1 ; } if ( $ R < 0 ) { $ R = 0 ; } if ( $ R > 255 ) { $ R = 255 ; } if ( $ G < 0 ) { $ G = 0 ; } if ( $ G > 255 ) { $ G = 255 ; } if ( $ B < 0 ) { $ B = 0 ; } if ( $ B > 255 ) { $ B = 255 ; } if ( $ this -> Shadow && $ this -> ShadowX != 0 && $ this -> ShadowY != 0 ) { $ AlphaFactor = floor ( ( $ Alpha / 100 ) * $ this -> Shadowa ) ; $ ShadowColor = $ this -> allocateColor ( $ this -> Picture , $ this -> ShadowR , $ this -> ShadowG , $ this -> ShadowB , $ AlphaFactor ) ; imagesetpixel ( $ this -> Picture , $ X + $ this -> ShadowX , $ Y + $ this -> ShadowY , $ ShadowColor ) ; } $ C_Aliased = $ this -> allocateColor ( $ this -> Picture , $ R , $ G , $ B , $ Alpha ) ; imagesetpixel ( $ this -> Picture , $ X , $ Y , $ C_Aliased ) ; }
Draw a semi - transparent pixel
45,211
public function drawFromPicture ( $ PicType , $ FileName , $ X , $ Y ) { if ( file_exists ( $ FileName ) ) { list ( $ Width , $ Height ) = $ this -> getPicInfo ( $ FileName ) ; if ( $ PicType == 1 ) { $ Raster = imagecreatefrompng ( $ FileName ) ; } elseif ( $ PicType == 2 ) { $ Raster = imagecreatefromgif ( $ FileName ) ; } elseif ( $ PicType == 3 ) { $ Raster = imagecreatefromjpeg ( $ FileName ) ; } else { return 0 ; } $ RestoreShadow = $ this -> Shadow ; if ( $ this -> Shadow && $ this -> ShadowX != 0 && $ this -> ShadowY != 0 ) { $ this -> Shadow = false ; if ( $ PicType == 3 ) { $ this -> drawFilledRectangle ( $ X + $ this -> ShadowX , $ Y + $ this -> ShadowY , $ X + $ Width + $ this -> ShadowX , $ Y + $ Height + $ this -> ShadowY , [ "R" => $ this -> ShadowR , "G" => $ this -> ShadowG , "B" => $ this -> ShadowB , "Alpha" => $ this -> Shadowa ] ) ; } else { $ TranparentID = imagecolortransparent ( $ Raster ) ; for ( $ Xc = 0 ; $ Xc <= $ Width - 1 ; $ Xc ++ ) { for ( $ Yc = 0 ; $ Yc <= $ Height - 1 ; $ Yc ++ ) { $ RGBa = imagecolorat ( $ Raster , $ Xc , $ Yc ) ; $ Values = imagecolorsforindex ( $ Raster , $ RGBa ) ; if ( $ Values [ "alpha" ] < 120 ) { $ AlphaFactor = floor ( ( $ this -> Shadowa / 100 ) * ( ( 100 / 127 ) * ( 127 - $ Values [ "alpha" ] ) ) ) ; $ this -> drawAlphaPixel ( $ X + $ Xc + $ this -> ShadowX , $ Y + $ Yc + $ this -> ShadowY , $ AlphaFactor , $ this -> ShadowR , $ this -> ShadowG , $ this -> ShadowB ) ; } } } } } $ this -> Shadow = $ RestoreShadow ; imagecopy ( $ this -> Picture , $ Raster , $ X , $ Y , 0 , 0 , $ Width , $ Height ) ; imagedestroy ( $ Raster ) ; } }
Generic loader public function for external pictures
45,212
public function flush ( ) { if ( file_exists ( $ this -> CacheFolder . "/" . $ this -> CacheIndex ) ) { unlink ( $ this -> CacheFolder . "/" . $ this -> CacheIndex ) ; touch ( $ this -> CacheFolder . "/" . $ this -> CacheIndex ) ; } if ( file_exists ( $ this -> CacheFolder . "/" . $ this -> CacheDB ) ) { unlink ( $ this -> CacheFolder . "/" . $ this -> CacheDB ) ; touch ( $ this -> CacheFolder . "/" . $ this -> CacheDB ) ; } }
Flush the cache contents
45,213
public function writeToCache ( $ ID , Image $ pChartObject ) { $ TemporaryFile = tempnam ( $ this -> CacheFolder , "tmp_" ) ; $ Database = $ this -> CacheFolder . "/" . $ this -> CacheDB ; $ Index = $ this -> CacheFolder . "/" . $ this -> CacheIndex ; imagepng ( $ pChartObject -> Picture , $ TemporaryFile ) ; $ PictureSize = filesize ( $ TemporaryFile ) ; $ DBSize = filesize ( $ Database ) ; $ Handle = fopen ( $ Index , "a" ) ; fwrite ( $ Handle , $ ID . "," . $ DBSize . "," . $ PictureSize . "," . time ( ) . ",0\r\n" ) ; fclose ( $ Handle ) ; $ Handle = fopen ( $ TemporaryFile , "r" ) ; $ Raw = fread ( $ Handle , $ PictureSize ) ; fclose ( $ Handle ) ; $ Handle = fopen ( $ Database , "a" ) ; fwrite ( $ Handle , $ Raw ) ; fclose ( $ Handle ) ; unlink ( $ TemporaryFile ) ; }
Write the generated picture to the cache
45,214
public function dbRemoval ( array $ Settings ) { $ ID = isset ( $ Settings [ "Name" ] ) ? $ Settings [ "Name" ] : null ; $ Expiry = isset ( $ Settings [ "Expiry" ] ) ? $ Settings [ "Expiry" ] : - ( 24 * 60 * 60 ) ; $ TS = time ( ) - $ Expiry ; $ Database = $ this -> CacheFolder . "/" . $ this -> CacheDB ; $ Index = $ this -> CacheFolder . "/" . $ this -> CacheIndex ; $ DatabaseTemp = $ this -> CacheFolder . "/" . $ this -> CacheDB . ".tmp" ; $ IndexTemp = $ this -> CacheFolder . "/" . $ this -> CacheIndex . ".tmp" ; if ( $ ID != null ) { $ Object = $ this -> isInCache ( $ ID , true ) ; if ( ! $ Object ) { return ( 0 ) ; } } if ( ! file_exists ( $ DatabaseTemp ) ) { touch ( $ DatabaseTemp ) ; } if ( ! file_exists ( $ IndexTemp ) ) { touch ( $ IndexTemp ) ; } $ IndexHandle = @ fopen ( $ Index , "r" ) ; $ IndexTempHandle = @ fopen ( $ IndexTemp , "w" ) ; $ DBHandle = @ fopen ( $ Database , "r" ) ; $ DBTempHandle = @ fopen ( $ DatabaseTemp , "w" ) ; while ( ! feof ( $ IndexHandle ) ) { $ Entry = fgets ( $ IndexHandle , 4096 ) ; $ Entry = str_replace ( "\r" , "" , $ Entry ) ; $ Entry = str_replace ( "\n" , "" , $ Entry ) ; $ Settings = preg_split ( "/,/" , $ Entry ) ; if ( $ Entry != "" ) { $ PicID = $ Settings [ 0 ] ; $ DBPos = $ Settings [ 1 ] ; $ PicSize = $ Settings [ 2 ] ; $ GeneratedTS = $ Settings [ 3 ] ; $ Hits = $ Settings [ 4 ] ; if ( $ Settings [ 0 ] != $ ID && $ GeneratedTS > $ TS ) { $ CurrentPos = ftell ( $ DBTempHandle ) ; fwrite ( $ IndexTempHandle , sprintf ( "%s,%s,%s,%s,%s\r\n" , $ PicID , $ CurrentPos , $ PicSize , $ GeneratedTS , $ Hits ) ) ; fseek ( $ DBHandle , $ DBPos ) ; $ Picture = fread ( $ DBHandle , $ PicSize ) ; fwrite ( $ DBTempHandle , $ Picture ) ; } } } fclose ( $ IndexHandle ) ; fclose ( $ IndexTempHandle ) ; fclose ( $ DBHandle ) ; fclose ( $ DBTempHandle ) ; unlink ( $ Database ) ; unlink ( $ Index ) ; rename ( $ DatabaseTemp , $ Database ) ; rename ( $ IndexTemp , $ Index ) ; }
Remove with specified criterias .
45,215
public function isInCache ( $ ID , $ Verbose = false , $ UpdateHitsCount = false ) { $ Index = $ this -> CacheFolder . "/" . $ this -> CacheIndex ; $ Handle = @ fopen ( $ Index , "r" ) ; while ( ! feof ( $ Handle ) ) { $ IndexPos = ftell ( $ Handle ) ; $ Entry = fgets ( $ Handle , 4096 ) ; if ( $ Entry != "" ) { $ Settings = preg_split ( "/,/" , $ Entry ) ; $ PicID = $ Settings [ 0 ] ; if ( $ PicID == $ ID ) { fclose ( $ Handle ) ; $ DBPos = $ Settings [ 1 ] ; $ PicSize = $ Settings [ 2 ] ; $ GeneratedTS = $ Settings [ 3 ] ; $ Hits = intval ( $ Settings [ 4 ] ) ; if ( $ UpdateHitsCount ) { $ Hits ++ ; if ( strlen ( $ Hits ) < 7 ) { $ Hits = $ Hits . str_repeat ( " " , 7 - strlen ( $ Hits ) ) ; } $ Handle = @ fopen ( $ Index , "r+" ) ; fseek ( $ Handle , $ IndexPos ) ; fwrite ( $ Handle , sprintf ( "%s,%s,%s,%s,%s\r\n" , $ PicID , $ DBPos , $ PicSize , $ GeneratedTS , $ Hits ) ) ; fclose ( $ Handle ) ; } if ( $ Verbose ) { return [ "DBPos" => $ DBPos , "PicSize" => $ PicSize , "GeneratedTS" => $ GeneratedTS , "Hits" => $ Hits ] ; } else { return true ; } } } } fclose ( $ Handle ) ; return false ; }
Is the file in cache?
45,216
public function autoOutput ( $ ID , $ Destination = "output.png" ) { if ( php_sapi_name ( ) == "cli" ) { $ this -> saveFromCache ( $ ID , $ Destination ) ; } else { $ this -> strokeFromCache ( $ ID ) ; } }
Automatic output method based on the calling interface
45,217
public function strokeFromCache ( $ ID ) { $ Picture = $ this -> getFromCache ( $ ID ) ; if ( $ Picture == null ) { return false ; } header ( 'Content-type: image/png' ) ; echo $ Picture ; return true ; }
Show image from cache
45,218
public function saveFromCache ( $ ID , $ Destination ) { $ Picture = $ this -> getFromCache ( $ ID ) ; if ( $ Picture == null ) { return false ; } $ Handle = fopen ( $ Destination , "w" ) ; fwrite ( $ Handle , $ Picture ) ; fclose ( $ Handle ) ; return true ; }
Save file from cache .
45,219
public function getFromCache ( $ ID ) { $ Database = $ this -> CacheFolder . "/" . $ this -> CacheDB ; $ CacheInfo = $ this -> isInCache ( $ ID , true , true ) ; if ( ! $ CacheInfo ) { return null ; } $ DBPos = $ CacheInfo [ "DBPos" ] ; $ PicSize = $ CacheInfo [ "PicSize" ] ; $ Handle = @ fopen ( $ Database , "r" ) ; fseek ( $ Handle , $ DBPos ) ; $ Picture = fread ( $ Handle , $ PicSize ) ; fclose ( $ Handle ) ; return $ Picture ; }
Get file from cache
45,220
public function getPosArray ( $ Values , $ AxisID ) { $ Data = $ this -> pDataObject -> getData ( ) ; if ( ! is_array ( $ Values ) ) { $ Values = [ $ Values ] ; } if ( $ Data [ "Axis" ] [ $ AxisID ] [ "Identity" ] == AXIS_X ) { $ Height = ( $ this -> pChartObject -> GraphAreaX2 - $ this -> pChartObject -> GraphAreaX1 ) - $ Data [ "Axis" ] [ $ AxisID ] [ "Margin" ] * 2 ; $ ScaleHeight = $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMax" ] - $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMin" ] ; $ Step = $ Height / $ ScaleHeight ; $ Result = [ ] ; foreach ( $ Values as $ Key => $ Value ) { if ( $ Value == VOID ) { $ Result [ ] = VOID ; } else { $ Result [ ] = $ this -> pChartObject -> GraphAreaX1 + $ Data [ "Axis" ] [ $ AxisID ] [ "Margin" ] + ( $ Step * ( $ Value - $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMin" ] ) ) ; } } } else { $ Height = ( $ this -> pChartObject -> GraphAreaY2 - $ this -> pChartObject -> GraphAreaY1 ) - $ Data [ "Axis" ] [ $ AxisID ] [ "Margin" ] * 2 ; $ ScaleHeight = $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMax" ] - $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMin" ] ; $ Step = $ Height / $ ScaleHeight ; $ Result = [ ] ; foreach ( $ Values as $ Key => $ Value ) { if ( $ Value == VOID ) { $ Result [ ] = VOID ; } else { $ Result [ ] = $ this -> pChartObject -> GraphAreaY2 - $ Data [ "Axis" ] [ $ AxisID ] [ "Margin" ] - ( $ Step * ( $ Value - $ Data [ "Axis" ] [ $ AxisID ] [ "ScaleMin" ] ) ) ; } } } return count ( $ Result ) == 1 ? reset ( $ Result ) : $ Result ; }
Return the scaled plot position
45,221
public function autoFreeZone ( ) { foreach ( $ this -> Data as $ Key => $ Settings ) { if ( isset ( $ Settings [ "Connections" ] ) ) { $ this -> Data [ $ Key ] [ "FreeZone" ] = count ( $ Settings [ "Connections" ] ) * 10 + 20 ; } else { $ this -> Data [ $ Key ] [ "FreeZone" ] = 20 ; } } }
Auto compute the FreeZone size based on the number of connections
45,222
public function linkProperties ( $ FromNode , $ ToNode , array $ Settings ) { if ( ! isset ( $ this -> Data [ $ FromNode ] ) ) { return 0 ; } if ( ! isset ( $ this -> Data [ $ ToNode ] ) ) { return 0 ; } $ R = isset ( $ Settings [ "R" ] ) ? $ Settings [ "R" ] : 0 ; $ G = isset ( $ Settings [ "G" ] ) ? $ Settings [ "G" ] : 0 ; $ B = isset ( $ Settings [ "B" ] ) ? $ Settings [ "B" ] : 0 ; $ Alpha = isset ( $ Settings [ "Alpha" ] ) ? $ Settings [ "Alpha" ] : 100 ; $ Name = isset ( $ Settings [ "Name" ] ) ? $ Settings [ "Name" ] : null ; $ Ticks = isset ( $ Settings [ "Ticks" ] ) ? $ Settings [ "Ticks" ] : null ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "R" ] = $ R ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "R" ] = $ R ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "G" ] = $ G ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "G" ] = $ G ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "B" ] = $ B ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "B" ] = $ B ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "Alpha" ] = $ Alpha ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "Alpha" ] = $ Alpha ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "Name" ] = $ Name ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "Name" ] = $ Name ; $ this -> Links [ $ FromNode ] [ $ ToNode ] [ "Ticks" ] = $ Ticks ; $ this -> Links [ $ ToNode ] [ $ FromNode ] [ "Ticks" ] = $ Ticks ; }
Set link properties
45,223
public function checkConnection ( $ SourceID , $ TargetID ) { if ( isset ( $ this -> Data [ $ SourceID ] [ "Connections" ] ) ) { foreach ( $ this -> Data [ $ SourceID ] [ "Connections" ] as $ ConnectionID ) { if ( $ TargetID == $ ConnectionID ) { return true ; } } } $ this -> Data [ $ SourceID ] [ "Connections" ] [ ] = $ TargetID ; }
Check if a connection exists and create it if required
45,224
public function getMedianOffset ( $ Key , $ X , $ Y ) { $ Cpt = 1 ; if ( isset ( $ this -> Data [ $ Key ] [ "Connections" ] ) ) { foreach ( $ this -> Data [ $ Key ] [ "Connections" ] as $ NodeID ) { if ( isset ( $ this -> Data [ $ NodeID ] [ "X" ] ) && isset ( $ this -> Data [ $ NodeID ] [ "Y" ] ) ) { $ X = $ X + $ this -> Data [ $ NodeID ] [ "X" ] ; $ Y = $ Y + $ this -> Data [ $ NodeID ] [ "Y" ] ; $ Cpt ++ ; } } } return [ "X" => $ X / $ Cpt , "Y" => $ Y / $ Cpt ] ; }
Get the median linked nodes position
45,225
public function getBiggestPartner ( $ Key ) { if ( ! isset ( $ this -> Data [ $ Key ] [ "Connections" ] ) ) { return "" ; } $ MaxWeight = 0 ; $ Result = "" ; foreach ( $ this -> Data [ $ Key ] [ "Connections" ] as $ Key => $ PeerID ) { if ( $ this -> Data [ $ PeerID ] [ "Weight" ] > $ MaxWeight ) { $ MaxWeight = $ this -> Data [ $ PeerID ] [ "Weight" ] ; $ Result = $ PeerID ; } } return $ Result ; }
Return the ID of the attached partner with the biggest weight
45,226
public function center ( ) { $ TargetCenterX = ( $ this -> X2 - $ this -> X1 ) / 2 + $ this -> X1 ; $ TargetCenterY = ( $ this -> Y2 - $ this -> Y1 ) / 2 + $ this -> Y1 ; $ XMin = $ this -> X2 ; $ XMax = $ this -> X1 ; $ YMin = $ this -> Y2 ; $ YMax = $ this -> Y1 ; foreach ( $ this -> Data as $ Key => $ Settings ) { $ X = $ Settings [ "X" ] ; $ Y = $ Settings [ "Y" ] ; if ( $ X < $ XMin ) { $ XMin = $ X ; } if ( $ X > $ XMax ) { $ XMax = $ X ; } if ( $ Y < $ YMin ) { $ YMin = $ Y ; } if ( $ Y > $ YMax ) { $ YMax = $ Y ; } } $ CurrentCenterX = ( $ XMax - $ XMin ) / 2 + $ XMin ; $ CurrentCenterY = ( $ YMax - $ YMin ) / 2 + $ YMin ; $ XOffset = $ TargetCenterX - $ CurrentCenterX ; $ YOffset = $ TargetCenterY - $ CurrentCenterY ; foreach ( $ this -> Data as $ Key => $ Settings ) { $ this -> Data [ $ Key ] [ "X" ] = $ Settings [ "X" ] + $ XOffset ; $ this -> Data [ $ Key ] [ "Y" ] = $ Settings [ "Y" ] + $ YOffset ; } }
Center the graph
45,227
public function getDistance ( $ X1 , $ Y1 , $ X2 , $ Y2 ) { return sqrt ( ( $ X2 - $ X1 ) * ( $ X2 - $ X1 ) + ( $ Y2 - $ Y1 ) * ( $ Y2 - $ Y1 ) ) ; }
Return the distance between two points
45,228
public function getAngle ( $ X1 , $ Y1 , $ X2 , $ Y2 ) { $ Opposite = $ Y2 - $ Y1 ; $ Adjacent = $ X2 - $ X1 ; $ Angle = rad2deg ( atan2 ( $ Opposite , $ Adjacent ) ) ; return $ Angle > 0 ? $ Angle : 360 - abs ( $ Angle ) ; }
Return the angle made by a line and the X axis
45,229
public function getKeyword ( $ keyword ) { $ k = $ this -> getAvailableKeywords ( ) ; if ( $ keyword == 'Link' ) { $ link = Director :: makeRelative ( $ this -> owner -> Link ( ) ) ; return Controller :: join_links ( Director :: absoluteBaseURL ( ) , $ link ) ; } if ( isset ( $ k [ $ keyword ] ) ) { return $ this -> owner -> $ keyword ; } return ; }
Gets a replacement for a keyword
45,230
public function sendNotification ( $ notification , $ context , $ data ) { $ users = $ notification -> getRecipients ( $ context ) ; foreach ( $ users as $ user ) { $ this -> sendToUser ( $ notification , $ context , $ user , $ data ) ; } }
Send a notification via email to the selected users
45,231
public function read ( $ ID ) { $ member = Member :: currentUser ( ) ; if ( ! $ member ) { return false ; } if ( $ ID ) { $ notification = InternalNotification :: get ( ) -> filter ( [ 'ID' => $ ID , 'ToID' => $ member -> ID , 'IsRead' => false ] ) -> first ( ) ; if ( $ notification ) { $ notification -> IsRead = true ; $ notification -> write ( ) ; return true ; } } return false ; }
Mark a Notification as read accepts a notification ID and returns a boolean for success or failure .
45,232
public function see ( $ ID ) { $ member = Member :: currentUser ( ) ; if ( ! $ member ) { return false ; } if ( $ ID ) { $ notification = InternalNotification :: get ( ) -> filter ( [ 'ID' => $ ID , 'ToID' => $ member -> ID ] ) -> first ( ) ; if ( $ notification ) { if ( ! $ notification -> IsSeen ) { $ notification -> IsSeen = true ; $ notification -> write ( ) ; } return true ; } } return false ; }
Mark a Notification as seen accepts a notification ID and returns a boolean for success or failure .
45,233
public function getRecipients ( $ event ) { $ groupIds = $ this -> Groups ( ) -> column ( 'ID' ) ; if ( count ( $ groupIds ) ) { $ members = Member :: get ( ) -> filter ( 'Groups.ID' , $ groupIds ) ; return $ members ; } return [ ] ; }
Gets the list of recipients for a given notification event based on this object s state .
45,234
public function addSender ( $ channel , $ sender ) { $ sender = is_string ( $ sender ) ? singleton ( $ sender ) : $ sender ; $ this -> senders [ $ channel ] = $ sender ; return $ this ; }
Add a notification sender
45,235
public function setSenders ( $ senders ) { $ this -> senders = [ ] ; if ( count ( $ senders ) ) { foreach ( $ senders as $ channel => $ sender ) { $ this -> addSender ( $ channel , $ sender ) ; } } return $ this ; }
Add a notification sender to a channel
45,236
public function getSender ( $ channel ) { return isset ( $ this -> senders [ $ channel ] ) ? $ this -> senders [ $ channel ] : null ; }
Get a sender for a particular channel
45,237
public function notify ( $ identifier , $ context , $ data = [ ] , $ channel = null ) { if ( $ notifications = SystemNotification :: get ( ) -> filter ( 'Identifier' , $ identifier ) ) { foreach ( $ notifications as $ notification ) { if ( $ notification -> NotifyOnClass ) { $ subclasses = ClassInfo :: subclassesFor ( $ notification -> NotifyOnClass ) ; if ( ! isset ( $ subclasses [ strtolower ( get_class ( $ context ) ) ] ) ) { continue ; } } $ channels = $ channel ? [ $ channel ] : [ ] ; if ( $ notification -> Channels ) { $ channels = json_decode ( $ notification -> Channels ) ; } $ this -> sendNotification ( $ notification , $ context , $ data , $ channels ) ; } } }
Trigger a notification event
45,238
public function sendNotification ( SystemNotification $ notification , DataObject $ context , $ extraData = [ ] , $ channels = null ) { $ recipients = $ notification -> getRecipients ( $ context ) ; if ( ! count ( $ recipients ) ) { return ; } if ( $ this -> config ( ) -> get ( 'use_queues' ) && count ( $ recipients ) > 5 ) { $ extraData [ 'SEND_CHANNELS' ] = $ channels ; singleton ( QueuedJobService :: class ) -> queueJob ( new SendNotificationJob ( $ notification , $ context , $ extraData ) ) ; } else { if ( ! is_array ( $ channels ) ) { $ channels = [ $ channels ] ; } $ channels = count ( $ channels ) ? $ channels : $ this -> channels ; foreach ( $ channels as $ channel ) { if ( $ sender = $ this -> getSender ( $ channel ) ) { $ sender -> sendNotification ( $ notification , $ context , $ extraData ) ; } } } }
Send out a notification
45,239
public function sendToUser ( SystemNotification $ notification , DataObject $ context , $ user , $ extraData = [ ] ) { $ channels = $ this -> channels ; if ( $ extraData && isset ( $ extraData [ 'SEND_CHANNELS' ] ) ) { $ channels = $ extraData [ 'SEND_CHANNELS' ] ; unset ( $ extraData [ 'SEND_CHANNELS' ] ) ; } if ( ! is_array ( $ channels ) ) { $ channels = [ $ channels ] ; } foreach ( $ channels as $ channel ) { if ( $ sender = $ this -> getSender ( $ channel ) ) { $ sender -> sendToUser ( $ notification , $ context , $ user , $ extraData ) ; } } }
Sends a notification directly to a user
45,240
public function getKeywords ( ) { $ keywords = [ ] ; foreach ( $ this -> config ( ) -> get ( 'global_keywords' ) as $ k => $ v ) { $ keywords [ ] = '<strong>' . $ k . '</strong> ' . $ v ; } if ( $ this -> NotifyOnClass && class_exists ( $ this -> NotifyOnClass ) ) { $ dummy = singleton ( $ this -> NotifyOnClass ) ; if ( $ dummy instanceof NotifiedOn || $ dummy -> hasMethod ( 'getAvailableKeywords' ) ) { $ myKeywords = $ dummy -> getAvailableKeywords ( ) ; if ( is_array ( $ myKeywords ) ) { foreach ( $ myKeywords as $ keyword => $ desc ) { $ keywords [ ] = '<strong>' . $ keyword . '</strong> - ' . $ desc ; } } } } return $ keywords ; }
Get a list of available keywords to help the cms user know what s available
45,241
public function getRecipients ( $ context = null ) { $ recipients = ArrayList :: create ( ) ; if ( $ context && ( $ context instanceof NotifiedOn || $ context -> hasMethod ( 'getRecipients' ) ) ) { $ contextRecipients = $ context -> getRecipients ( $ this -> Identifier ) ; if ( $ contextRecipients ) { $ recipients -> merge ( $ contextRecipients ) ; } } if ( $ context instanceof Member ) { $ recipients -> push ( $ context ) ; } else { if ( $ context instanceof Group ) { $ recipients = $ context -> Members ( ) ; } } return $ recipients ; }
Get a list of recipients from the notification with the given context
45,242
public function format ( $ text , $ context , $ user = null , $ extraData = [ ] ) { $ data = $ this -> getTemplateData ( $ context , $ user , $ extraData ) ; $ viewer = new SSViewer_FromString ( $ text ) ; try { $ string = $ viewer -> process ( $ data ) ; } catch ( Exception $ e ) { $ string = $ text ; } return $ string ; }
Format text with given keywords etc
45,243
public function getTemplateData ( $ context , $ user = null , $ extraData = [ ] ) { $ data = [ 'ThemeDirs' => new ArrayList ( SSViewer :: get_themes ( ) ) , 'SiteConfig' => SiteConfig :: current_site_config ( ) , ] ; $ clsPath = explode ( '\\' , get_class ( $ context ) ) ; $ data [ end ( $ clsPath ) ] = $ context ; $ data [ 'Context' ] = $ context ; $ contextData = method_exists ( $ context , 'getNotificationTemplateData' ) ? $ context -> getNotificationTemplateData ( ) : null ; if ( is_array ( $ contextData ) ) { $ data = array_merge ( $ data , $ contextData ) ; } $ data [ 'Member' ] = $ user ; $ data = array_merge ( $ data , $ extraData ) ; return ArrayData :: create ( $ data ) ; }
Get compiled template data to render a string with
45,244
public static function percentageWordsWithThreeSyllables ( $ strText , $ blnCountProperNouns = true , $ strEncoding = '' ) { $ intWordCount = Text :: wordCount ( $ strText , $ strEncoding ) ; $ intLongWordCount = self :: wordsWithThreeSyllables ( $ strText , $ blnCountProperNouns , $ strEncoding ) ; $ intPercentage = Maths :: bcCalc ( Maths :: bcCalc ( $ intLongWordCount , '/' , $ intWordCount ) , '*' , 100 ) ; return $ intPercentage ; }
Returns the percentage of words with more than three syllables
45,245
public static function normaliseOperator ( $ operator ) { switch ( $ operator ) { case 'add' : case 'addition' : $ operator = '+' ; break ; case 'sub' : case 'subtract' : $ operator = '-' ; break ; case 'mul' : case 'multiply' : $ operator = '*' ; break ; case 'div' : case 'divide' : $ operator = '/' ; break ; case 'mod' : case 'modulus' : $ operator = '%' ; break ; case 'comp' : case 'compare' : $ operator = '=' ; break ; } return $ operator ; }
Normalise operators for bcMath function .
45,246
private static function performCalc ( $ number1 , $ action , $ number2 , $ round , $ decimals , $ precision ) { $ result = null ; $ compare = false ; switch ( $ action ) { case '+' : $ result = ( self :: $ blnBcmath ) ? bcadd ( $ number1 , $ number2 , $ precision ) : ( $ number1 + $ number2 ) ; break ; case '-' : $ result = ( self :: $ blnBcmath ) ? bcsub ( $ number1 , $ number2 , $ precision ) : ( $ number1 - $ number2 ) ; break ; case '*' : $ result = ( self :: $ blnBcmath ) ? bcmul ( $ number1 , $ number2 , $ precision ) : ( $ number1 * $ number2 ) ; break ; case 'sqrt' : $ result = ( self :: $ blnBcmath ) ? bcsqrt ( $ number1 , $ precision ) : sqrt ( $ number1 ) ; break ; case '/' : if ( $ number2 > 0 ) { if ( self :: $ blnBcmath ) { $ result = bcdiv ( $ number1 , $ number2 , $ precision ) ; } else if ( $ number2 != 0 ) { $ result = $ number1 / $ number2 ; } } if ( ! isset ( $ result ) ) { $ result = 0 ; } break ; case '%' : if ( self :: $ blnBcmath ) { $ result = bcmod ( $ number1 , $ number2 ) ; } else if ( $ number2 != 0 ) { $ result = $ number1 % $ number2 ; } if ( ! isset ( $ result ) ) { $ result = 0 ; } break ; case '=' : $ compare = true ; if ( self :: $ blnBcmath ) { $ result = bccomp ( $ number1 , $ number2 , $ precision ) ; } else { $ result = ( $ number1 == $ number2 ) ? 0 : ( ( $ number1 > $ number2 ) ? 1 : - 1 ) ; } break ; } if ( isset ( $ result ) ) { if ( $ compare === false ) { if ( $ round === true ) { $ result = round ( floatval ( $ result ) , $ decimals ) ; if ( $ decimals === 0 ) { $ result = ( int ) $ result ; } } else { $ result = ( intval ( $ result ) == $ result ) ? intval ( $ result ) : floatval ( $ result ) ; } } return $ result ; } return false ; }
Function which performs calculation .
45,247
public static function fetchSpacheWordList ( ) { if ( is_array ( self :: $ arrSpache ) ) { return self :: $ arrSpache ; } $ arrSpacheWordList = array ( ) ; include_once ( 'resources/SpacheWordList.php' ) ; self :: $ arrSpache = $ arrSpacheWordList ; return $ arrSpacheWordList ; }
Fetch the list of Spache easy words
45,248
public static function fetchDaleChallWordList ( ) { if ( is_array ( self :: $ arrDaleChall ) ) { return self :: $ arrDaleChall ; } $ arrDaleChallWordList = array ( ) ; include_once ( 'resources/DaleChallWordList.php' ) ; self :: $ arrDaleChall = $ arrDaleChallWordList ; return $ arrDaleChallWordList ; }
Fetch the list of Dale - Chall easy words
45,249
public static function cleanText ( $ strText ) { if ( is_bool ( $ strText ) ) { return '' ; } $ key = sha1 ( $ strText ) ; if ( isset ( self :: $ clean [ $ key ] ) ) { return self :: $ clean [ $ key ] ; } $ strText = utf8_decode ( $ strText ) ; $ strText = str_replace ( array ( "\xe2\x80\x98" , "\xe2\x80\x99" , "\xe2\x80\x9c" , "\xe2\x80\x9d" , "\xe2\x80\x93" , "\xe2\x80\x94" , "\xe2\x80\xa6" ) , array ( "'" , "'" , '"' , '"' , '-' , '--' , '...' ) , $ strText ) ; $ strText = str_replace ( array ( chr ( 145 ) , chr ( 146 ) , chr ( 147 ) , chr ( 148 ) , chr ( 150 ) , chr ( 151 ) , chr ( 133 ) ) , array ( "'" , "'" , '"' , '"' , '-' , '--' , '...' ) , $ strText ) ; $ strText = preg_replace ( '`([^0-9][0-9]+)\.([0-9]+[^0-9])`mis' , '${1}0$2' , $ strText ) ; $ strText = preg_replace ( '`<script(.*?)>(.*?)</script>`is' , '' , $ strText ) ; $ strText = preg_replace ( '`\</?(address|blockquote|center|dir|div|dl|dd|dt|fieldset|form|h1|h2|h3|h4|h5|h6|menu|noscript|ol|p|pre|table|ul|li)[^>]*>`is' , '.' , $ strText ) ; $ strText = html_entity_decode ( $ strText ) ; $ strText = strip_tags ( $ strText ) ; $ strText = preg_replace ( '`(\r\n|\n\r)`is' , "\n" , $ strText ) ; $ strText = preg_replace ( '`(\r|\n){2,}`is' , ".\n\n" , $ strText ) ; $ strText = preg_replace ( '`[ ]*(\n|\r\n|\r)[ ]*`' , ' ' , $ strText ) ; $ strText = preg_replace ( '`[",:;()/\`-]`' , ' ' , $ strText ) ; $ strText = trim ( $ strText , '. ' ) . '.' ; $ strText = preg_replace ( '`[\.!?]`' , '.' , $ strText ) ; $ strText = preg_replace ( '`([\.\s]*\.[\.\s]*)`mis' , '. ' , $ strText ) ; $ strText = preg_replace ( '`[ ]+`' , ' ' , $ strText ) ; $ strText = preg_replace ( '`([\.])[\. ]+`' , '$1' , $ strText ) ; $ strText = trim ( preg_replace ( '`[ ]*([\.])`' , '$1 ' , $ strText ) ) ; $ strText = preg_replace_callback ( '`\. [^\. ]`' , function ( $ matches ) { return strtolower ( $ matches [ 0 ] ) ; } , $ strText ) ; $ strText = trim ( $ strText ) ; self :: $ clean [ $ key ] = $ strText ; return $ strText ; }
Trims removes line breaks multiple spaces and generally cleans text before processing .
45,250
public static function lowerCase ( $ strText , $ strEncoding = '' ) { if ( is_null ( self :: $ blnMbstring ) ) { self :: $ blnMbstring = extension_loaded ( 'mbstring' ) ; } if ( ! self :: $ blnMbstring ) { $ strLowerCaseText = strtolower ( $ strText ) ; } else { if ( $ strEncoding == '' ) { $ strLowerCaseText = mb_strtolower ( $ strText ) ; } else { $ strLowerCaseText = mb_strtolower ( $ strText , $ strEncoding ) ; } } return $ strLowerCaseText ; }
Converts string to lower case . Tries mb_strtolower and if that fails uses regular strtolower .
45,251
public static function upperCase ( $ strText , $ strEncoding = '' ) { if ( is_null ( self :: $ blnMbstring ) ) { self :: $ blnMbstring = extension_loaded ( 'mbstring' ) ; } if ( ! self :: $ blnMbstring ) { $ strUpperCaseText = strtoupper ( $ strText ) ; } else { if ( $ strEncoding == '' ) { $ strUpperCaseText = mb_strtoupper ( $ strText ) ; } else { $ strUpperCaseText = mb_strtoupper ( $ strText , $ strEncoding ) ; } } return $ strUpperCaseText ; }
Converts string to upper case . Tries mb_strtoupper and if that fails uses regular strtoupper .
45,252
public static function substring ( $ strText , $ intStart , $ intLength , $ strEncoding = '' ) { if ( is_null ( self :: $ blnMbstring ) ) { self :: $ blnMbstring = extension_loaded ( 'mbstring' ) ; } if ( ! self :: $ blnMbstring ) { $ strSubstring = substr ( $ strText , $ intStart , $ intLength ) ; } else { if ( $ strEncoding == '' ) { $ strSubstring = mb_substr ( $ strText , $ intStart , $ intLength ) ; } else { $ strSubstring = mb_substr ( $ strText , $ intStart , $ intLength , $ strEncoding ) ; } } return $ strSubstring ; }
Gets portion of string . Tries mb_substr and if that fails uses regular substr .
45,253
public static function textLength ( $ strText , $ strEncoding = '' ) { if ( is_null ( self :: $ blnMbstring ) ) { self :: $ blnMbstring = extension_loaded ( 'mbstring' ) ; } if ( ! self :: $ blnMbstring ) { $ intTextLength = strlen ( $ strText ) ; } else { if ( $ strEncoding == '' ) { $ intTextLength = mb_strlen ( $ strText ) ; } else { $ intTextLength = mb_strlen ( $ strText , $ strEncoding ) ; } } return $ intTextLength ; }
Gives string length . Tries mb_strlen and if that fails uses regular strlen .
45,254
public function setText ( $ strText ) { if ( $ strText !== false ) { self :: $ strText = Text :: cleanText ( $ strText ) ; } return self :: $ strText ; }
Set the text to measure the readability of .
45,255
public function fleschKincaidReadingEase ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( Maths :: bcCalc ( 206.835 , '-' , Maths :: bcCalc ( 1.015 , '*' , Text :: averageWordsPerSentence ( $ strText , $ this -> strEncoding ) ) ) , '-' , Maths :: bcCalc ( 84.6 , '*' , Syllables :: averageSyllablesPerWord ( $ strText , $ this -> strEncoding ) ) ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , 100 , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the Flesch - Kincaid Reading Ease of text entered rounded to one digit
45,256
public function gunningFogScore ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( Maths :: bcCalc ( Text :: averageWordsPerSentence ( $ strText , $ this -> strEncoding ) , '+' , Syllables :: percentageWordsWithThreeSyllables ( $ strText , false , $ this -> strEncoding ) ) , '*' , '0.4' ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , 19 , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the Gunning - Fog score of text entered rounded to one digit
45,257
public function smogIndex ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( 1.043 , '*' , Maths :: bcCalc ( Maths :: bcCalc ( Maths :: bcCalc ( Syllables :: wordsWithThreeSyllables ( $ strText , true , $ this -> strEncoding ) , '*' , Maths :: bcCalc ( 30 , '/' , Text :: sentenceCount ( $ strText , $ this -> strEncoding ) ) ) , 'sqrt' , 0 ) , '+' , 3.1291 ) ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , $ this -> maxGradeLevel , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the SMOG Index of text entered rounded to one digit
45,258
public function automatedReadabilityIndex ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( Maths :: bcCalc ( 4.71 , '*' , Maths :: bcCalc ( Text :: letterCount ( $ strText , $ this -> strEncoding ) , '/' , Text :: wordCount ( $ strText , $ this -> strEncoding ) ) ) , '+' , Maths :: bcCalc ( Maths :: bcCalc ( 0.5 , '*' , Maths :: bcCalc ( Text :: wordCount ( $ strText , $ this -> strEncoding ) , '/' , Text :: sentenceCount ( $ strText , $ this -> strEncoding ) ) ) , '-' , 21.43 ) ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , $ this -> maxGradeLevel , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the Automated Readability Index of text entered rounded to one digit
45,259
public function daleChallReadabilityScore ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( Maths :: bcCalc ( 0.1579 , '*' , Maths :: bcCalc ( 100 , '*' , Maths :: bcCalc ( $ this -> daleChallDifficultWordCount ( $ strText ) , '/' , Text :: wordCount ( $ strText , $ this -> strEncoding ) ) ) ) , '+' , Maths :: bcCalc ( 0.0496 , '*' , Maths :: bcCalc ( Text :: wordCount ( $ strText , $ this -> strEncoding ) , '/' , Text :: sentenceCount ( $ strText , $ this -> strEncoding ) ) ) ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , 10 , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the Dale - Chall readability score of text entered rounded to one digit
45,260
public function spacheReadabilityScore ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ score = Maths :: bcCalc ( Maths :: bcCalc ( Maths :: bcCalc ( 0.121 , '*' , Maths :: bcCalc ( Text :: wordCount ( $ strText , $ this -> strEncoding ) , '/' , Text :: sentenceCount ( $ strText , $ this -> strEncoding ) ) ) , '+' , Maths :: bcCalc ( 0.082 , '*' , $ this -> spacheDifficultWordCount ( $ strText ) ) ) , '+' , 0.659 ) ; if ( $ this -> normalise ) { return Maths :: normaliseScore ( $ score , 0 , 5 , $ this -> dps ) ; } else { return Maths :: bcCalc ( $ score , '+' , 0 , true , $ this -> dps ) ; } }
Gives the Spache readability score of text entered rounded to one digit
45,261
public function daleChallDifficultWordCount ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ intDifficultWords = 0 ; $ arrWords = explode ( ' ' , Text :: lowerCase ( preg_replace ( '`[^A-za-z\' ]`' , '' , $ strText ) , $ this -> strEncoding ) ) ; $ arrDaleChall = Resource :: fetchDaleChallWordList ( ) ; for ( $ i = 0 , $ intWordCount = count ( $ arrWords ) ; $ i < $ intWordCount ; $ i ++ ) { if ( strlen ( trim ( $ arrWords [ $ i ] ) ) < 2 ) { continue ; } if ( ( ! in_array ( Pluralise :: getPlural ( $ arrWords [ $ i ] ) , $ arrDaleChall ) ) && ( ! in_array ( Pluralise :: getSingular ( $ arrWords [ $ i ] ) , $ arrDaleChall ) ) ) { $ intDifficultWords ++ ; } } return $ intDifficultWords ; }
Returns the number of words NOT on the Dale - Chall easy word list
45,262
public function spacheDifficultWordCount ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; $ intDifficultWords = 0 ; $ arrWords = explode ( ' ' , strtolower ( preg_replace ( '`[^A-za-z\' ]`' , '' , $ strText ) ) ) ; $ wordsCounted = array ( ) ; $ arrSpache = Resource :: fetchSpacheWordList ( ) ; for ( $ i = 0 , $ intWordCount = count ( $ arrWords ) ; $ i < $ intWordCount ; $ i ++ ) { if ( strlen ( trim ( $ arrWords [ $ i ] ) ) < 2 ) { continue ; } $ singularWord = Pluralise :: getSingular ( $ arrWords [ $ i ] ) ; if ( ( ! in_array ( Pluralise :: getPlural ( $ arrWords [ $ i ] ) , $ arrSpache ) ) && ( ! in_array ( $ singularWord , $ arrSpache ) ) ) { if ( ! in_array ( $ singularWord , $ wordsCounted ) ) { $ intDifficultWords ++ ; $ wordsCounted [ ] = $ singularWord ; } } } return $ intDifficultWords ; }
Returns the number of unique words NOT on the Spache easy word list
45,263
public function letterCount ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; return Text :: letterCount ( $ strText , $ this -> strEncoding ) ; }
Returns letter count for text .
45,264
public function syllableCount ( $ strText = false ) { $ strText = $ this -> setText ( $ strText ) ; return Syllables :: syllableCount ( $ strText , $ this -> strEncoding ) ; }
Returns number of syllables in a word
45,265
public function getMemcachedCompleteKey ( $ id ) { $ memcachedKey = implode ( $ this -> separator , array ( $ this -> prefix , $ this -> name , $ this -> suffix , $ id ) ) ; return $ memcachedKey ; }
Appends the suffix to the base memcached key
45,266
public function setAutoFilter ( $ filteredColumnName , $ filteredValue ) { if ( ! is_string ( $ filteredColumnName ) ) { throw new InvalidArgumentException ( 'setAutoFilter only accepts string as argument.' ) ; } if ( ! isset ( $ filteredColumnName ) ) { throw new InvalidArgumentException ( 'filteredValue must be set.' ) ; } $ this -> filteredColumnName = $ filteredColumnName ; $ this -> filteredValue = $ filteredValue ; return $ this ; }
Set the filtered column name
45,267
protected function implementVOs ( array $ datas = array ( ) ) { $ ret = array ( ) ; if ( ! $ class = $ this -> getVOFQCN ( ) ) { throw new \ RuntimeException ( 'VOFQCN is not defined for ' . get_called_class ( ) ) ; } $ datas = $ this -> translationLoader ( $ class , $ datas ) ; foreach ( $ datas as & $ row ) { $ ret [ $ row [ $ this -> getIdentityColumn ( ) ] ] = new $ class ( $ row ) ; } return $ ret ; }
Implements a bunch of \ Berthe \ VO from datas
45,268
public function selectByIds ( array $ ids = array ( ) ) { if ( empty ( $ ids ) ) { return array ( ) ; } $ ids = array_map ( 'intval' , $ ids ) ; $ sql = $ this -> getSelectQueryByIds ( $ ids ) ; $ resultSet = $ this -> db -> fetchAll ( $ sql ) ; return $ this -> implementVOs ( $ resultSet ) ; }
Gets a bunch of \ Berthe \ AbstractVOVO from database from their ids
45,269
protected function _extractColumnsFromSelectQuery ( ) { $ _query = $ this -> getSelectQuery ( ) ; $ _matches = array ( ) ; $ _pattern = '#.*(SELECT)(.*)(FROM|LEFT|JOIN)#ims' ; preg_match ( $ _pattern , $ _query , $ _matches ) ; $ _columnsList = explode ( ',' , $ _matches [ 2 ] ) ; array_walk ( $ _columnsList , function ( & $ value , $ index ) { $ value = trim ( $ value ) ; } ) ; return $ _columnsList ; }
Extract the list of columns from Select Query
45,270
protected function _getColumnIndexInSelectQuery ( $ col ) { $ _columns = $ this -> _extractColumnsFromSelectQuery ( ) ; $ _columnIndex = false ; foreach ( $ _columns as $ index => $ column ) { if ( $ col == $ column ) { $ _columnIndex = $ index ; break ; } } return $ _columnIndex ; }
Returns the index of selected column in the select query
45,271
protected function getTableName ( ) { if ( $ this -> tableName ) { if ( trim ( $ this -> schemaName ) !== '' ) { return $ this -> schemaName . '.' . $ this -> tableName ; } return $ this -> tableName ; } throw new \ RuntimeException ( 'Table name is not defined for ' . get_called_class ( ) ) ; }
Returns the table name of the table .
45,272
public function insert ( \ Berthe \ VO $ object ) { $ this -> validateTableAndIdentityColumn ( ) ; $ mappings = $ this -> getSaveMappings ( ) ; if ( empty ( $ mappings ) ) { $ mappings = $ this -> getDefaultMappings ( $ object ) ; } $ valueElements = array ( ) ; $ columnElements = array ( ) ; $ params = array ( ) ; $ values = $ object -> __toArray ( ) ; foreach ( $ mappings as $ column => $ property ) { if ( $ column != $ this -> identityColumn ) { $ value = in_array ( $ property , $ object -> getTranslatableFields ( ) ) ? $ object -> getAttribute ( $ property ) : $ values [ $ property ] ; $ columnElements [ ] = $ column ; $ params [ $ column ] = $ value ; if ( $ value instanceof \ Berthe \ Translation \ Translation ) { $ this -> translator -> saveTranslation ( $ value ) ; } } } $ columnAssignment = $ this -> escapeCharacter . implode ( $ this -> escapeCharacter . ', ' . $ this -> escapeCharacter , $ columnElements ) . $ this -> escapeCharacter ; $ valueAssignment = '%s' . str_repeat ( ', %s' , count ( $ columnElements ) - 1 ) ; $ query = <<<EOQINSERT INTO {$this->getTableName()} ({$columnAssignment})VALUES ({$valueAssignment});EOQ ; if ( ( bool ) $ this -> db -> query ( $ query , $ params ) ) { $ id = ( int ) $ this -> db -> lastInsertId ( $ this -> getTableName ( ) , $ this -> identityColumn ) ; $ object -> setId ( $ id ) ; } return $ object -> getId ( ) > 0 ; }
Insert the object in database
45,273
public function update ( \ Berthe \ VO $ object ) { $ this -> validateTableAndIdentityColumn ( ) ; $ mappings = $ this -> getSaveMappings ( ) ; if ( empty ( $ mappings ) ) { $ mappings = $ this -> getDefaultMappings ( $ object ) ; } $ clauseElements = array ( ) ; $ params = array ( ) ; $ values = $ object -> __toArray ( ) ; foreach ( $ mappings as $ column => $ property ) { $ escape = $ this -> escapeCharacter ; $ clauseElements [ ] = sprintf ( '%s%s%s = %%s' , $ escape , $ column , $ escape ) ; if ( in_array ( $ property , $ object -> getTranslatableFields ( ) ) ) { $ value = $ object -> getAttribute ( $ property ) ; } else { $ value = $ values [ $ property ] ; } $ params [ $ column ] = $ value ; if ( $ value instanceof \ Berthe \ Translation \ Translation ) { $ this -> translator -> saveTranslation ( $ value ) ; } } $ params [ 'identity' ] = $ object -> getId ( ) ; $ columnAssignment = implode ( ', ' , $ clauseElements ) ; $ query = <<<EOQUPDATE {$this->getTableName()} SET {$columnAssignment}WHERE {$this->escapeCharacter}{$this->identityColumn}{$this->escapeCharacter} = %s;EOQ ; return ( bool ) $ this -> db -> query ( $ query , $ params ) ; }
Update the object in database
45,274
public function deleteById ( $ id ) { $ this -> validateTableAndIdentityColumn ( ) ; if ( $ this -> deleteColumnName ) { $ query = <<<EOQUPDATE {$this->getTableName()}SET {$this->deleteColumnName} = 1WHERE {$this->escapeCharacter}{$this->identityColumn}{$this->escapeCharacter} = %sEOQ ; } else { $ query = <<<EOQDELETE FROM {$this->getTableName()}WHERE {$this->escapeCharacter}{$this->identityColumn}{$this->escapeCharacter} = %sEOQ ; } $ params = array ( 'identity' => $ id ) ; return ( bool ) $ this -> db -> query ( $ query , $ params ) ; }
Delete an object by id from database
45,275
public function isEqual ( Event $ event ) { try { return $ this -> getName ( ) === $ event -> getName ( ) && $ this -> get ( 'id' ) === $ event -> get ( 'id' ) && self :: getSortedKeys ( $ this -> getParameters ( ) ) === self :: getSortedKeys ( $ event -> getParameters ( ) ) ; } catch ( \ Exception $ e ) { } return false ; }
They re equal if this is the same type of event and the same id Allows to know if an event concerns a same type of action on the same object . Very useful to delete doubles .
45,276
protected function dateToTimeZone ( $ stringDate ) { $ date = new DateTime ( $ stringDate ) ; $ date -> setTimezone ( new DateTimeZone ( $ this -> timeZone ) ) ; return $ date ; }
Transform a date string into a DateTime object using GMT timezone
45,277
public function compose ( Resource $ resource , $ scopeIdentifier = null , Scope $ parentScopeInstance = null ) { $ scopeInstance = new Scope ( $ this , $ resource , $ scopeIdentifier ) ; if ( $ parentScopeInstance !== null ) { $ scopeArray = $ parentScopeInstance -> getParentScopes ( ) ; $ scopeArray [ ] = $ parentScopeInstance -> getCurrentScope ( ) ; $ scopeInstance -> setParentScopes ( $ scopeArray ) ; } return $ scopeInstance ; }
Compose a Resource
45,278
public function offsetSet ( $ offset , $ value ) { ! is_int ( $ offset ) and trigger_error ( __CLASS__ . '::' . __FUNCTION__ . '() : Only accepts integer offsets' , E_USER_WARNING ) ; ( $ this -> _count >= $ this -> _nbByPage ) and trigger_error ( __CLASS__ . '::' . __FUNCTION__ . '() : Max number of elements by page reached' , E_USER_ERROR ) ; if ( is_int ( $ offset ) and ( $ this -> hasLimit ( ) && ( $ this -> _count >= $ this -> _nbByPage ) ) ) { $ this -> _elements [ $ offset ] = $ value ; $ this -> _count = count ( $ this -> _elements ) ; } }
sets an offset
45,279
public function offsetUnset ( $ offset ) { ! is_int ( $ offset ) and trigger_error ( __CLASS__ . '::' . __FUNCTION__ . '() : Only accepts integer offsets' , E_USER_WARNING ) ; if ( is_int ( $ offset ) and isset ( $ this -> _elements [ $ offset ] ) ) { unset ( $ this -> _elements [ $ offset ] ) ; $ this -> _count = count ( $ this -> _elements ) ; } }
Unsets an offset
45,280
public function delete ( $ object ) { $ ret = $ this -> getValidator ( ) -> validateDelete ( $ object ) ; if ( $ ret ) { $ ret = $ this -> _delete ( $ object ) ; } return $ ret ; }
Default method to delete an object
45,281
public function save ( VO $ vo ) { $ store = $ this -> getPrimaryStore ( ) ; $ success = $ store -> save ( $ vo ) ; if ( ! $ success ) { throw new \ RuntimeException ( "Couldn't store object in primary store" , 500 ) ; } foreach ( $ this -> stores as $ storeName => $ store ) { if ( ! $ this -> isPrimaryStore ( $ storeName ) ) { $ store -> save ( $ vo ) ; } } return $ success ; }
Saves a VO
45,282
public function delete ( VO $ vo ) { foreach ( $ this -> stores as $ storeName => $ store ) { if ( ! $ this -> isPrimaryStore ( $ storeName ) ) { $ ret = $ store -> delete ( $ vo ) ; if ( ! $ ret ) { throw new \ RuntimeException ( sprintf ( "Couldn't remove object from non-primary store, aborting" ) , 500 ) ; } } } $ primaryStore = $ this -> getPrimaryStore ( ) ; $ success = $ primaryStore -> delete ( $ vo ) ; if ( ! $ success ) { throw new \ RuntimeException ( sprintf ( "Couldn't remove object from primary store, aborting" ) , 500 ) ; } return true ; }
Deletes a VO
45,283
public function deleteById ( $ id ) { try { $ obj = $ this -> getById ( $ id ) ; $ this -> delete ( $ obj ) ; return true ; } catch ( \ Exception $ e ) { throw $ e ; } }
Deletes a VO by its id
45,284
protected function load ( array $ ids = array ( ) ) { $ idsNotFound = array_filter ( $ ids ) ; $ output = array ( ) ; $ stores = $ this -> stores ; foreach ( $ this -> stores as $ storeName => $ store ) { if ( ! empty ( $ idsNotFound ) ) { $ objects = $ store -> load ( $ idsNotFound ) ; $ loadedKeys = array_keys ( $ objects ) ; $ remainingKeys = array_values ( array_diff ( $ idsNotFound , $ loadedKeys ) ) ; $ idsNotFound = $ remainingKeys ; $ output = $ output + $ objects ; if ( ! empty ( $ objects ) && $ store == $ this -> primaryStore ) { foreach ( $ stores as $ storeName2 => $ store2 ) { if ( $ storeName2 !== $ storeName ) { $ ret = $ store2 -> saveMulti ( $ objects ) ; } } } } } return $ output ; }
Try to load requested objects from stores
45,285
public function isEnabled ( $ bool = null ) { if ( $ bool === true || $ bool === false ) { $ this -> isEnabled = $ bool ; } return $ this -> isEnabled ; }
Getter and setter for isEnabled toggle
45,286
public function destroy ( $ id , VisitLogModel $ visitLog ) { $ visitLog = $ visitLog -> find ( $ id ) ; if ( $ visitLog && ! $ visitLog -> delete ( ) ) { return Redirect :: back ( ) -> withErrors ( $ visitLog -> errors ( ) ) ; } return Redirect :: back ( ) ; }
Deletes a record .
45,287
public function destroyAll ( VisitLogModel $ visitLog ) { if ( ! $ visitLog -> truncate ( ) ) { return Redirect :: back ( ) -> withErrors ( $ visitLog -> errors ( ) ) ; } return Redirect :: back ( ) ; }
Deletes all records .
45,288
public function save ( ) { $ data = $ this -> getData ( ) ; if ( config ( 'visitlog.unique' ) ) { $ model = VisitLogModel :: where ( 'ip' , $ this -> getUserIP ( ) ) -> first ( ) ; if ( $ model ) { $ model -> touch ( ) ; return $ model -> update ( $ data ) ; } } return VisitLogModel :: create ( $ data ) ; }
Saves visit info into db .
45,289
protected function getBrowserInfo ( ) { $ browser = $ this -> browser -> getBrowser ( ) ? : 'Other' ; $ browserVersion = $ this -> browser -> getVersion ( ) ; if ( trim ( $ browserVersion ) ) { return $ browser . ' (' . $ browserVersion . ')' ; } return $ browser ; }
Gets OS information .
45,290
protected function getData ( ) { $ ip = $ this -> getUserIP ( ) ; $ cacheKey = $ this -> cachePrefix . $ ip ; $ url = $ this -> freegeoipUrl . '/' . $ ip . '?' . '&access_key=' . config ( 'visitlog.token' ) . $ this -> tokenString ; $ data = [ 'ip' => $ ip , 'browser' => $ this -> getBrowserInfo ( ) , 'os' => $ this -> browser -> getPlatform ( ) ? : 'Unknown' , ] ; if ( config ( 'visitlog.iptolocation' ) ) { if ( config ( 'visitlog.cache' ) ) { $ freegeoipData = unserialize ( Cache :: get ( $ cacheKey ) ) ; if ( ! $ freegeoipData ) { $ freegeoipData = @ json_decode ( file_get_contents ( $ url ) , true ) ; if ( $ freegeoipData ) { Cache :: forever ( $ cacheKey , serialize ( $ freegeoipData ) ) ; } } } else { $ freegeoipData = @ json_decode ( file_get_contents ( $ url ) , true ) ; } if ( $ freegeoipData ) { $ data = array_merge ( $ data , $ freegeoipData ) ; } } $ userData = $ this -> getUser ( ) ; if ( $ userData ) { $ data = array_merge ( $ data , $ userData ) ; } return $ data ; }
Returns visit data to be saved in db .
45,291
protected function getUser ( ) { $ userData = [ ] ; if ( config ( 'visitlog.log_user' ) ) { $ name = '' ; $ userNameFields = config ( 'visitlog.user_name_fields' ) ; if ( Auth :: check ( ) ) { $ user = Auth :: user ( ) ; $ userData [ 'user_id' ] = $ user -> id ; if ( is_array ( $ userNameFields ) ) { foreach ( $ userNameFields as $ userNameField ) { $ name .= @ $ user -> $ userNameField . ' ' ; } $ name = rtrim ( $ name ) ; } else { $ name = @ $ user -> $ userNameFields ; } $ userData [ 'user_name' ] = $ name ; } else { $ userData [ 'user_id' ] = 0 ; $ userData [ 'user_name' ] = 'Guest' ; } } return $ userData ; }
Gets logged user info .
45,292
public function generateNumber ( Order $ order = null ) { $ date = Carbon :: now ( ) ; $ number = sprintf ( '%s-%s-%s%s%s' , $ this -> getYearAndDayHash ( $ date ) , str_pad ( base_convert ( $ date -> secondsSinceMidnight ( ) , 10 , 36 ) , 4 , '0' , STR_PAD_LEFT ) , str_pad ( base_convert ( $ this -> getRapidMicroNumber ( ) , 10 , 36 ) , 2 , '0' , STR_PAD_LEFT ) , base_convert ( mt_rand ( 0 , 35 ) , 10 , 36 ) , ( ( string ) $ this -> getSlowMicroNumber ( ) ) [ 0 ] ) ; if ( $ this -> highVariance ) { $ number .= '-' . str_pad ( base_convert ( $ this -> getSlowMicroNumber ( ) , 10 , 36 ) , 2 , '0' , STR_PAD_LEFT ) . str_pad ( base_convert ( mt_rand ( 0 , 1295 ) , 10 , 36 ) , 2 , '0' , STR_PAD_LEFT ) ; } return $ this -> uppercase ? strtoupper ( $ number ) : $ number ; }
Returns an order number for an order with a time + random based hash
45,293
protected function createItem ( Order $ order , array $ item ) { if ( $ this -> itemContainsABuyable ( $ item ) ) { $ product = $ item [ 'product' ] ; $ item = array_merge ( $ item , [ 'product_type' => $ product -> morphTypeName ( ) , 'product_id' => $ product -> getId ( ) , 'price' => $ product -> getPrice ( ) , 'name' => $ product -> getName ( ) ] ) ; unset ( $ item [ 'product' ] ) ; } $ order -> items ( ) -> create ( $ item ) ; }
Creates a single item for the given order
45,294
protected function registerMacro ( ) { DataTableAbstract :: macro ( 'setTransformer' , function ( $ transformer ) { $ this -> transformer = [ $ transformer ] ; return $ this ; } ) ; DataTableAbstract :: macro ( 'addTransformer' , function ( $ transformer ) { $ this -> transformer [ ] = $ transformer ; return $ this ; } ) ; DataTableAbstract :: macro ( 'setSerializer' , function ( $ serializer ) { $ this -> serializer = $ serializer ; return $ this ; } ) ; }
Register DataTables macro methods .
45,295
public function transform ( $ output , $ transformer , $ serializer = null ) { if ( $ serializer !== null ) { $ this -> fractal -> setSerializer ( $ this -> createSerializer ( $ serializer ) ) ; } $ collector = [ ] ; foreach ( $ transformer as $ transform ) { if ( $ transform != null ) { $ resource = new Collection ( $ output , $ this -> createTransformer ( $ transform ) ) ; $ collection = $ this -> fractal -> createData ( $ resource ) -> toArray ( ) ; $ transformed = $ collection [ 'data' ] ?? $ collection ; $ collector = array_map ( function ( $ item_collector , $ item_transformed ) { if ( $ item_collector === null ) { $ item_collector = [ ] ; } return array_merge ( $ item_collector , $ item_transformed ) ; } , $ collector , $ transformed ) ; } } return $ collector ; }
Transform output using the given transformer and serializer .
45,296
public function sendVerifyLink ( $ user ) { if ( is_null ( $ user ) ) { return static :: INVALID_USER ; } $ expiration = Carbon :: now ( ) -> addMinutes ( $ this -> expiration ) -> timestamp ; $ user -> sendEmailVerificationNotification ( $ this -> createToken ( $ user , $ expiration ) , $ expiration ) ; $ this -> events -> dispatch ( new EmailVerificationSent ( $ user ) ) ; return static :: VERIFY_LINK_SENT ; }
Send a email verification link to a user .
45,297
public function verify ( array $ credentials , Closure $ callback ) { $ user = $ this -> validateEmailVerification ( $ credentials ) ; if ( ! $ user instanceof CanVerifyEmailContract ) { return $ user ; } if ( $ callback ( $ user ) ) { $ this -> events -> dispatch ( new UserVerified ( $ user ) ) ; } return static :: VERIFIED ; }
Verify the user for the given token .
45,298
protected function validateEmailVerification ( array $ credentials ) { if ( is_null ( $ user = $ this -> getUser ( $ credentials ) ) ) { return static :: INVALID_USER ; } if ( ! $ this -> validateToken ( $ user , $ credentials ) ) { return static :: INVALID_TOKEN ; } if ( ! $ this -> validateTimestamp ( $ credentials [ 'expiration' ] ) ) { return static :: EXPIRED_TOKEN ; } return $ user ; }
Validate a email verification for the given credentials .
45,299
public function verify ( Request $ request , EmailVerification $ emailVerification ) { $ this -> validateVerificationRequest ( $ request ) ; $ response = $ emailVerification -> verify ( $ request -> only ( 'email' , 'expiration' , 'token' ) , function ( $ user ) { return $ this -> verifiedEmail ( $ user ) ; } ) ; return $ response == EmailVerification :: VERIFIED ? $ this -> sendVerificationResponse ( $ response ) : $ this -> sendVerificationFailedResponse ( $ request , $ response ) ; }
Verifies the given user s email .