repository_name
stringlengths
5
67
func_path_in_repository
stringlengths
4
234
func_name
stringlengths
0
314
whole_func_string
stringlengths
52
3.87M
language
stringclasses
6 values
func_code_string
stringlengths
52
3.87M
func_code_tokens
listlengths
15
672k
func_documentation_string
stringlengths
1
47.2k
func_documentation_tokens
listlengths
1
3.92k
split_name
stringclasses
1 value
func_code_url
stringlengths
85
339
koala-framework/koala-framework
Kwf/Media/Image.php
Kwf_Media_Image.getResponsiveWidthSteps
public static function getResponsiveWidthSteps($dim, $imageDimensions) { $ret = array(); if (is_string($imageDimensions)) { if (!file_exists($imageDimensions)) { return array(); } $size = getimagesize($imageDimensions); $imageDimensions = array( 'width' => $size[0], 'height' => $size[1], ); } else if ($imageDimensions instanceof Kwf_Uploads_Row) { $imageDimensions = $imageDimensions->getImageDimensions(); } else if ($imageDimensions instanceof Imagick) { $imageDimensions = array( 'width' => $imageDimensions->getImageWidth(), 'height' => $imageDimensions->getImageHeight() ); } if (!$imageDimensions['width']) { throw new Kwf_Exception("Image must have a width"); } $maxWidth = $dim['width'] * 2; if ($imageDimensions['width'] < $dim['width'] * 2) { $maxWidth = $imageDimensions['width']; } $calculateWidth = $dim['width']; if ($imageDimensions['width'] < $dim['width']) { $calculateWidth = $imageDimensions['width']; } $width = $calculateWidth; do { $ret[] = $width; $width -= self::_getOffsetAtWidth($width); } while ($width > 0); $width = $calculateWidth; while (true) { $width += self::_getOffsetAtWidth($width); if ($width >= $maxWidth) { break; } $ret[] = $width; } $ret[] = $maxWidth; sort($ret); return $ret; }
php
public static function getResponsiveWidthSteps($dim, $imageDimensions) { $ret = array(); if (is_string($imageDimensions)) { if (!file_exists($imageDimensions)) { return array(); } $size = getimagesize($imageDimensions); $imageDimensions = array( 'width' => $size[0], 'height' => $size[1], ); } else if ($imageDimensions instanceof Kwf_Uploads_Row) { $imageDimensions = $imageDimensions->getImageDimensions(); } else if ($imageDimensions instanceof Imagick) { $imageDimensions = array( 'width' => $imageDimensions->getImageWidth(), 'height' => $imageDimensions->getImageHeight() ); } if (!$imageDimensions['width']) { throw new Kwf_Exception("Image must have a width"); } $maxWidth = $dim['width'] * 2; if ($imageDimensions['width'] < $dim['width'] * 2) { $maxWidth = $imageDimensions['width']; } $calculateWidth = $dim['width']; if ($imageDimensions['width'] < $dim['width']) { $calculateWidth = $imageDimensions['width']; } $width = $calculateWidth; do { $ret[] = $width; $width -= self::_getOffsetAtWidth($width); } while ($width > 0); $width = $calculateWidth; while (true) { $width += self::_getOffsetAtWidth($width); if ($width >= $maxWidth) { break; } $ret[] = $width; } $ret[] = $maxWidth; sort($ret); return $ret; }
[ "public", "static", "function", "getResponsiveWidthSteps", "(", "$", "dim", ",", "$", "imageDimensions", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "if", "(", "is_string", "(", "$", "imageDimensions", ")", ")", "{", "if", "(", "!", "file_exists", "(", "$", "imageDimensions", ")", ")", "{", "return", "array", "(", ")", ";", "}", "$", "size", "=", "getimagesize", "(", "$", "imageDimensions", ")", ";", "$", "imageDimensions", "=", "array", "(", "'width'", "=>", "$", "size", "[", "0", "]", ",", "'height'", "=>", "$", "size", "[", "1", "]", ",", ")", ";", "}", "else", "if", "(", "$", "imageDimensions", "instanceof", "Kwf_Uploads_Row", ")", "{", "$", "imageDimensions", "=", "$", "imageDimensions", "->", "getImageDimensions", "(", ")", ";", "}", "else", "if", "(", "$", "imageDimensions", "instanceof", "Imagick", ")", "{", "$", "imageDimensions", "=", "array", "(", "'width'", "=>", "$", "imageDimensions", "->", "getImageWidth", "(", ")", ",", "'height'", "=>", "$", "imageDimensions", "->", "getImageHeight", "(", ")", ")", ";", "}", "if", "(", "!", "$", "imageDimensions", "[", "'width'", "]", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"Image must have a width\"", ")", ";", "}", "$", "maxWidth", "=", "$", "dim", "[", "'width'", "]", "*", "2", ";", "if", "(", "$", "imageDimensions", "[", "'width'", "]", "<", "$", "dim", "[", "'width'", "]", "*", "2", ")", "{", "$", "maxWidth", "=", "$", "imageDimensions", "[", "'width'", "]", ";", "}", "$", "calculateWidth", "=", "$", "dim", "[", "'width'", "]", ";", "if", "(", "$", "imageDimensions", "[", "'width'", "]", "<", "$", "dim", "[", "'width'", "]", ")", "{", "$", "calculateWidth", "=", "$", "imageDimensions", "[", "'width'", "]", ";", "}", "$", "width", "=", "$", "calculateWidth", ";", "do", "{", "$", "ret", "[", "]", "=", "$", "width", ";", "$", "width", "-=", "self", "::", "_getOffsetAtWidth", "(", "$", "width", ")", ";", "}", "while", "(", "$", "width", ">", "0", ")", ";", "$", "width", "=", "$", "calculateWidth", ";", "while", "(", "true", ")", "{", "$", "width", "+=", "self", "::", "_getOffsetAtWidth", "(", "$", "width", ")", ";", "if", "(", "$", "width", ">=", "$", "maxWidth", ")", "{", "break", ";", "}", "$", "ret", "[", "]", "=", "$", "width", ";", "}", "$", "ret", "[", "]", "=", "$", "maxWidth", ";", "sort", "(", "$", "ret", ")", ";", "return", "$", "ret", ";", "}" ]
Returns supported image-widths of specific image with given base-dimensions
[ "Returns", "supported", "image", "-", "widths", "of", "specific", "image", "with", "given", "base", "-", "dimensions" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Image.php#L30-L83
koala-framework/koala-framework
Kwf/Media/Image.php
Kwf_Media_Image.getExifRotation
public static function getExifRotation($source) { if (!Kwf_Registry::get('config')->image->autoExifRotate) { return 0; } $handle = fopen($source, 'rb'); // b for windows compatibility // Check if image is jpg file if (fread($handle, 2) != chr(0xFF).chr(0xD8)) { fclose($handle); return 0; } $fileSize = filesize($source); $count = 0; $rotation = 0; while ($count < 3) { // Run through marker $count++; $marker = fread($handle, 2); // Marks start of stream (SOS) if ($marker == chr(0xFF).chr(0xDA)) break; $size = self::_generateIntValue(fread($handle, 1), fread($handle, 1), false); if ($marker == chr(0xFF).chr(0xE1)) { // Start of exif-data-block if (fread($handle, 6) != 'Exif'.chr(0).chr(0)) break; $tiffHeaderBytes = fread($handle, 4); // should be 0x49492A00 or 0x4D4D002A if ($tiffHeaderBytes == 'II'.chr(0x2A).chr(0x00)) { // Motorola $reversed = true; } else if ($tiffHeaderBytes == 'MM'.chr(0x00).chr(0x2A)) { // Intel $reversed = false; } else { // this case should not exist break; } $count = 0; while ($count < 5) { $count++; // IFD = Image File Directory => Image properties // check offset from tiffHeader-Start to IFD's, if 0 end of all IFD-Blocks if (fread($handle, 4) == chr(0x00).chr(0x00).chr(0x00).chr(0x00)) break 2; $ifdCount = self::_generateIntValue(fread($handle, 1), fread($handle, 1), $reversed); if ($fileSize < ftell($handle) + $ifdCount * 12 + 6) break 2; // check to handle eof if ($ifdCount > 100) break 2; // check if ifdCount is a possible value for ($i = 0; $i < $ifdCount; $i++) { $ifdBytes = fread($handle, 12); $tag = self::_generateIntValue($ifdBytes[0], $ifdBytes[1], $reversed); if ($tag == 0x0112) { // reversed saved in this form: 00 06 | 00 00 should be 00 00 | 00 06 // normally saved in this form: 06 00 | 00 00 $highBytes = self::_generateIntValue($ifdBytes[10], $ifdBytes[11], $reversed); $lowBytes = self::_generateIntValue($ifdBytes[8], $ifdBytes[9], $reversed); $exifOrientation = $highBytes * pow(16, 4) + $lowBytes; switch ($exifOrientation) { case 1: $rotation = 0; break; case 8: //Left_Bottom $rotation = -90; break; case 3: $rotation = 180; break; case 6: //Right_Top $rotation = 90; break; } break 3; } } } } else { // Any other marker (e.g. JFIF-0xFFE0, Photoshop-Stuff), not supported. Set file-pointer to end of marker-data fseek($handle, $size -2, SEEK_CUR); } } fclose($handle); return $rotation; }
php
public static function getExifRotation($source) { if (!Kwf_Registry::get('config')->image->autoExifRotate) { return 0; } $handle = fopen($source, 'rb'); // b for windows compatibility // Check if image is jpg file if (fread($handle, 2) != chr(0xFF).chr(0xD8)) { fclose($handle); return 0; } $fileSize = filesize($source); $count = 0; $rotation = 0; while ($count < 3) { // Run through marker $count++; $marker = fread($handle, 2); // Marks start of stream (SOS) if ($marker == chr(0xFF).chr(0xDA)) break; $size = self::_generateIntValue(fread($handle, 1), fread($handle, 1), false); if ($marker == chr(0xFF).chr(0xE1)) { // Start of exif-data-block if (fread($handle, 6) != 'Exif'.chr(0).chr(0)) break; $tiffHeaderBytes = fread($handle, 4); // should be 0x49492A00 or 0x4D4D002A if ($tiffHeaderBytes == 'II'.chr(0x2A).chr(0x00)) { // Motorola $reversed = true; } else if ($tiffHeaderBytes == 'MM'.chr(0x00).chr(0x2A)) { // Intel $reversed = false; } else { // this case should not exist break; } $count = 0; while ($count < 5) { $count++; // IFD = Image File Directory => Image properties // check offset from tiffHeader-Start to IFD's, if 0 end of all IFD-Blocks if (fread($handle, 4) == chr(0x00).chr(0x00).chr(0x00).chr(0x00)) break 2; $ifdCount = self::_generateIntValue(fread($handle, 1), fread($handle, 1), $reversed); if ($fileSize < ftell($handle) + $ifdCount * 12 + 6) break 2; // check to handle eof if ($ifdCount > 100) break 2; // check if ifdCount is a possible value for ($i = 0; $i < $ifdCount; $i++) { $ifdBytes = fread($handle, 12); $tag = self::_generateIntValue($ifdBytes[0], $ifdBytes[1], $reversed); if ($tag == 0x0112) { // reversed saved in this form: 00 06 | 00 00 should be 00 00 | 00 06 // normally saved in this form: 06 00 | 00 00 $highBytes = self::_generateIntValue($ifdBytes[10], $ifdBytes[11], $reversed); $lowBytes = self::_generateIntValue($ifdBytes[8], $ifdBytes[9], $reversed); $exifOrientation = $highBytes * pow(16, 4) + $lowBytes; switch ($exifOrientation) { case 1: $rotation = 0; break; case 8: //Left_Bottom $rotation = -90; break; case 3: $rotation = 180; break; case 6: //Right_Top $rotation = 90; break; } break 3; } } } } else { // Any other marker (e.g. JFIF-0xFFE0, Photoshop-Stuff), not supported. Set file-pointer to end of marker-data fseek($handle, $size -2, SEEK_CUR); } } fclose($handle); return $rotation; }
[ "public", "static", "function", "getExifRotation", "(", "$", "source", ")", "{", "if", "(", "!", "Kwf_Registry", "::", "get", "(", "'config'", ")", "->", "image", "->", "autoExifRotate", ")", "{", "return", "0", ";", "}", "$", "handle", "=", "fopen", "(", "$", "source", ",", "'rb'", ")", ";", "// b for windows compatibility", "// Check if image is jpg file", "if", "(", "fread", "(", "$", "handle", ",", "2", ")", "!=", "chr", "(", "0xFF", ")", ".", "chr", "(", "0xD8", ")", ")", "{", "fclose", "(", "$", "handle", ")", ";", "return", "0", ";", "}", "$", "fileSize", "=", "filesize", "(", "$", "source", ")", ";", "$", "count", "=", "0", ";", "$", "rotation", "=", "0", ";", "while", "(", "$", "count", "<", "3", ")", "{", "// Run through marker", "$", "count", "++", ";", "$", "marker", "=", "fread", "(", "$", "handle", ",", "2", ")", ";", "// Marks start of stream (SOS)", "if", "(", "$", "marker", "==", "chr", "(", "0xFF", ")", ".", "chr", "(", "0xDA", ")", ")", "break", ";", "$", "size", "=", "self", "::", "_generateIntValue", "(", "fread", "(", "$", "handle", ",", "1", ")", ",", "fread", "(", "$", "handle", ",", "1", ")", ",", "false", ")", ";", "if", "(", "$", "marker", "==", "chr", "(", "0xFF", ")", ".", "chr", "(", "0xE1", ")", ")", "{", "// Start of exif-data-block", "if", "(", "fread", "(", "$", "handle", ",", "6", ")", "!=", "'Exif'", ".", "chr", "(", "0", ")", ".", "chr", "(", "0", ")", ")", "break", ";", "$", "tiffHeaderBytes", "=", "fread", "(", "$", "handle", ",", "4", ")", ";", "// should be 0x49492A00 or 0x4D4D002A", "if", "(", "$", "tiffHeaderBytes", "==", "'II'", ".", "chr", "(", "0x2A", ")", ".", "chr", "(", "0x00", ")", ")", "{", "// Motorola", "$", "reversed", "=", "true", ";", "}", "else", "if", "(", "$", "tiffHeaderBytes", "==", "'MM'", ".", "chr", "(", "0x00", ")", ".", "chr", "(", "0x2A", ")", ")", "{", "// Intel", "$", "reversed", "=", "false", ";", "}", "else", "{", "// this case should not exist", "break", ";", "}", "$", "count", "=", "0", ";", "while", "(", "$", "count", "<", "5", ")", "{", "$", "count", "++", ";", "// IFD = Image File Directory => Image properties", "// check offset from tiffHeader-Start to IFD's, if 0 end of all IFD-Blocks", "if", "(", "fread", "(", "$", "handle", ",", "4", ")", "==", "chr", "(", "0x00", ")", ".", "chr", "(", "0x00", ")", ".", "chr", "(", "0x00", ")", ".", "chr", "(", "0x00", ")", ")", "break", "2", ";", "$", "ifdCount", "=", "self", "::", "_generateIntValue", "(", "fread", "(", "$", "handle", ",", "1", ")", ",", "fread", "(", "$", "handle", ",", "1", ")", ",", "$", "reversed", ")", ";", "if", "(", "$", "fileSize", "<", "ftell", "(", "$", "handle", ")", "+", "$", "ifdCount", "*", "12", "+", "6", ")", "break", "2", ";", "// check to handle eof", "if", "(", "$", "ifdCount", ">", "100", ")", "break", "2", ";", "// check if ifdCount is a possible value", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "ifdCount", ";", "$", "i", "++", ")", "{", "$", "ifdBytes", "=", "fread", "(", "$", "handle", ",", "12", ")", ";", "$", "tag", "=", "self", "::", "_generateIntValue", "(", "$", "ifdBytes", "[", "0", "]", ",", "$", "ifdBytes", "[", "1", "]", ",", "$", "reversed", ")", ";", "if", "(", "$", "tag", "==", "0x0112", ")", "{", "// reversed saved in this form: 00 06 | 00 00 should be 00 00 | 00 06", "// normally saved in this form: 06 00 | 00 00", "$", "highBytes", "=", "self", "::", "_generateIntValue", "(", "$", "ifdBytes", "[", "10", "]", ",", "$", "ifdBytes", "[", "11", "]", ",", "$", "reversed", ")", ";", "$", "lowBytes", "=", "self", "::", "_generateIntValue", "(", "$", "ifdBytes", "[", "8", "]", ",", "$", "ifdBytes", "[", "9", "]", ",", "$", "reversed", ")", ";", "$", "exifOrientation", "=", "$", "highBytes", "*", "pow", "(", "16", ",", "4", ")", "+", "$", "lowBytes", ";", "switch", "(", "$", "exifOrientation", ")", "{", "case", "1", ":", "$", "rotation", "=", "0", ";", "break", ";", "case", "8", ":", "//Left_Bottom", "$", "rotation", "=", "-", "90", ";", "break", ";", "case", "3", ":", "$", "rotation", "=", "180", ";", "break", ";", "case", "6", ":", "//Right_Top", "$", "rotation", "=", "90", ";", "break", ";", "}", "break", "3", ";", "}", "}", "}", "}", "else", "{", "// Any other marker (e.g. JFIF-0xFFE0, Photoshop-Stuff), not supported. Set file-pointer to end of marker-data", "fseek", "(", "$", "handle", ",", "$", "size", "-", "2", ",", "SEEK_CUR", ")", ";", "}", "}", "fclose", "(", "$", "handle", ")", ";", "return", "$", "rotation", ";", "}" ]
Got information from http://www.media.mit.edu/pia/Research/deepview/exif.html and http://www.impulseadventure.com/photo/exif-orientation.html
[ "Got", "information", "from", "http", ":", "//", "www", ".", "media", ".", "mit", ".", "edu", "/", "pia", "/", "Research", "/", "deepview", "/", "exif", ".", "html", "and", "http", ":", "//", "www", ".", "impulseadventure", ".", "com", "/", "photo", "/", "exif", "-", "orientation", ".", "html" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Image.php#L94-L173
koala-framework/koala-framework
Kwf/Media/Image.php
Kwf_Media_Image.getHandyScaleFactor
public static function getHandyScaleFactor($original) { $targetSize = array(600, 600, 'cover' => false); if (is_string($original)) { if (!file_exists($original)) return 1; $size = getimagesize($original); $original = array( 'width' => $size[0], 'height' => $size[1], 'rotation' => self::getExifRotation($original), ); } $target = Kwf_Media_Image::calculateScaleDimensions($original, $targetSize); if (abs($original['rotation']) == 90) { $original = array('width'=>$original['height'], 'height'=>$original['width']); } if ($original['width'] <= $target['width'] && $original['height'] <= $target['height']) { return 1; } else { return $original['width'] / $target['width']; } }
php
public static function getHandyScaleFactor($original) { $targetSize = array(600, 600, 'cover' => false); if (is_string($original)) { if (!file_exists($original)) return 1; $size = getimagesize($original); $original = array( 'width' => $size[0], 'height' => $size[1], 'rotation' => self::getExifRotation($original), ); } $target = Kwf_Media_Image::calculateScaleDimensions($original, $targetSize); if (abs($original['rotation']) == 90) { $original = array('width'=>$original['height'], 'height'=>$original['width']); } if ($original['width'] <= $target['width'] && $original['height'] <= $target['height']) { return 1; } else { return $original['width'] / $target['width']; } }
[ "public", "static", "function", "getHandyScaleFactor", "(", "$", "original", ")", "{", "$", "targetSize", "=", "array", "(", "600", ",", "600", ",", "'cover'", "=>", "false", ")", ";", "if", "(", "is_string", "(", "$", "original", ")", ")", "{", "if", "(", "!", "file_exists", "(", "$", "original", ")", ")", "return", "1", ";", "$", "size", "=", "getimagesize", "(", "$", "original", ")", ";", "$", "original", "=", "array", "(", "'width'", "=>", "$", "size", "[", "0", "]", ",", "'height'", "=>", "$", "size", "[", "1", "]", ",", "'rotation'", "=>", "self", "::", "getExifRotation", "(", "$", "original", ")", ",", ")", ";", "}", "$", "target", "=", "Kwf_Media_Image", "::", "calculateScaleDimensions", "(", "$", "original", ",", "$", "targetSize", ")", ";", "if", "(", "abs", "(", "$", "original", "[", "'rotation'", "]", ")", "==", "90", ")", "{", "$", "original", "=", "array", "(", "'width'", "=>", "$", "original", "[", "'height'", "]", ",", "'height'", "=>", "$", "original", "[", "'width'", "]", ")", ";", "}", "if", "(", "$", "original", "[", "'width'", "]", "<=", "$", "target", "[", "'width'", "]", "&&", "$", "original", "[", "'height'", "]", "<=", "$", "target", "[", "'height'", "]", ")", "{", "return", "1", ";", "}", "else", "{", "return", "$", "original", "[", "'width'", "]", "/", "$", "target", "[", "'width'", "]", ";", "}", "}" ]
Returns an image with a size which should be good to work with. Acutally this is a 600x600 max-width. If it's smaller in both dimensions it will keep it's original size.
[ "Returns", "an", "image", "with", "a", "size", "which", "should", "be", "good", "to", "work", "with", ".", "Acutally", "this", "is", "a", "600x600", "max", "-", "width", ".", "If", "it", "s", "smaller", "in", "both", "dimensions", "it", "will", "keep", "it", "s", "original", "size", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Image.php#L180-L203
koala-framework/koala-framework
Kwf/Media/Image.php
Kwf_Media_Image.calculateScaleDimensions
public static function calculateScaleDimensions($source, $targetSize) { // Get size of image (handle different param-possibilities) if (is_string($source)) { $sourceSize = @getimagesize($source); $sourceSize['rotation'] = self::getExifRotation($source); } else if ($source instanceof Imagick) { $sourceSize = $source->getImageGeometry(); $source = null; } else if ($source instanceof Kwf_Uploads_Row) { $sourceSize = $source->getImageDimensions(); $source = null; } else { $sourceSize = $source; $source = null; } if (!$sourceSize) return false; if (!isset($sourceSize['rotation'])) $sourceSize['rotation'] = 0; $w = null; if (isset($sourceSize[0])) $w = $sourceSize[0]; if (isset($sourceSize['width'])) $w = $sourceSize['width']; $h = null; if (isset($sourceSize[1])) $h = $sourceSize[1]; if (isset($sourceSize['height'])) $h = $sourceSize['height']; if (!$w || !$h) return false; $originalSize = array($w, $h); // get output-width $outputWidth = 0; if (isset($targetSize[0])) $outputWidth = $targetSize[0]; if (isset($targetSize['width'])) $outputWidth = $targetSize['width']; // get output-height $outputHeight = 0; if (isset($targetSize[1])) $outputHeight = $targetSize[1]; if (isset($targetSize['height'])) $outputHeight = $targetSize['height']; // get crop-data $crop = isset($targetSize['crop']) ? $targetSize['crop'] : null; // get cover $cover = isset($targetSize['cover']) ? $targetSize['cover'] : true; // Check if image has to be rotated if ($sourceSize['rotation'] == 90) { $originalSize = array($originalSize[1], $originalSize[0]); } if ($outputWidth == 0 && $outputHeight == 0) { if ($crop) { $ret = array( 'width' => $crop['width'], 'height' => $crop['height'], 'rotate' => 0, 'crop' => array( 'x' => $crop['x'], 'y' => $crop['y'], 'width' => $crop['width'], 'height' => $crop['height'] ) ); if (isset($targetSize['imageCompressionQuality'])) { $ret['imageCompressionQuality'] = $targetSize['imageCompressionQuality']; } return $ret; } else { // Handle keep original return array( 'width' => $originalSize[0], 'height' => $originalSize[1], 'rotate' => 0, 'crop' => array( 'x' => 0, 'y' => 0, 'width' => $originalSize[0], 'height' => $originalSize[1] ), 'keepOriginal' => true, ); } } // Calculate missing dimension $calculateWidth = $originalSize[0]; $calculateHeight = $originalSize[1]; if ($crop) { $calculateWidth = $crop['width']; $calculateHeight = $crop['height']; } if ($cover) { // image will always have defined size if ($outputWidth == 0) { if (isset($targetSize['aspectRatio'])) { $outputWidth = round($outputHeight * $targetSize['aspectRatio']); } else { $outputWidth = round($outputHeight * ($calculateWidth / $calculateHeight)); } if ($outputWidth <= 0) $outputWidth = 1; } if ($outputHeight == 0) { if (isset($targetSize['aspectRatio']) && $targetSize['aspectRatio']) { $outputHeight = round($outputWidth * $targetSize['aspectRatio']); } else { $outputHeight = round($outputWidth * ($calculateHeight / $calculateWidth)); } if ($outputHeight <= 0) $outputHeight = 1; } if (!$crop) { // crop from complete image $crop = array(); // calculate crop depending on target-size if (($outputWidth / $outputHeight) >= ($originalSize[0] / $originalSize[1])) { $crop['width'] = $originalSize[0]; $crop['height'] = $originalSize[0] * ($outputHeight / $outputWidth); } else { $crop['height'] = $originalSize[1]; $crop['width'] = $originalSize[1] * ($outputWidth / $outputHeight); } // calculate x and y of crop $xDiff = $originalSize[0] - $crop['width']; $crop['x'] = $xDiff > 0 ? $xDiff / 2 : 0; $yDiff = $originalSize[1] - $crop['height']; $crop['y'] = $yDiff > 0 ? $yDiff / 2 : 0; } else { $oldCrop['width'] = $crop['width']; $oldCrop['height'] = $crop['height']; if (($outputWidth / $outputHeight) >= ($crop['width'] / $crop['height'])) { $crop['width'] = $crop['width']; $crop['height'] = $crop['width'] * ($outputHeight / $outputWidth); } else { $crop['height'] = $crop['height']; $crop['width'] = $crop['height'] * ($outputWidth / $outputHeight); } $xDiff = $oldCrop['width'] - $crop['width']; $crop['x'] += $xDiff > 0 ? $xDiff / 2 : 0; $yDiff = $oldCrop['height'] - $crop['height']; $crop['y'] += $yDiff > 0 ? $yDiff / 2 : 0; } } elseif (!$cover) { // image keeps aspectratio and will not be scaled up // calculateWidth is cropWidth if existing else originalWidth. // prevent image scale up if (!$crop) { $crop = array( 'x' => 0, 'y' => 0, 'width' => $originalSize[0], 'height' => $originalSize[1] ); } if ($calculateWidth <= $outputWidth && $calculateHeight <= $outputHeight) { $outputWidth = $calculateWidth; $outputHeight = $calculateHeight; } else { if ($calculateWidth < $outputWidth) { $outputWidth = $calculateWidth; } if ($calculateHeight < $outputHeight) { $outputHeight = $calculateHeight; } } $widthRatio = $outputWidth ? $calculateWidth / $outputWidth : null; $heightRatio = $outputHeight ? $calculateHeight / $outputHeight : null; if ($widthRatio > $heightRatio) { $outputWidth = $calculateWidth / $widthRatio; $outputHeight = $calculateHeight / $widthRatio; } else if ($heightRatio > $widthRatio) { $outputWidth = $calculateWidth / $heightRatio; $outputHeight = $calculateHeight / $heightRatio; } } $outputWidth = round($outputWidth); if ($outputWidth <= 0) $outputWidth = 1; $outputHeight = round($outputHeight); if ($outputHeight <= 0) $outputHeight = 1; $ret = array( 'width' => round($outputWidth), 'height' => round($outputHeight), 'rotate' => $sourceSize['rotation'], 'crop' => $crop ); if (isset($targetSize['imageCompressionQuality'])) { $ret['imageCompressionQuality'] = $targetSize['imageCompressionQuality']; } //Set values to match original-parameters when original won't change if ($ret['crop']['x'] == 0 && $ret['crop']['y'] == 0 && $ret['crop']['width'] == $originalSize[0] && $ret['crop']['height'] == $originalSize[1] && $ret['width'] == $originalSize[0] && $ret['height'] == $originalSize[1] && !$ret['rotate'] ) { $ret['keepOriginal'] = true; } return $ret; }
php
public static function calculateScaleDimensions($source, $targetSize) { // Get size of image (handle different param-possibilities) if (is_string($source)) { $sourceSize = @getimagesize($source); $sourceSize['rotation'] = self::getExifRotation($source); } else if ($source instanceof Imagick) { $sourceSize = $source->getImageGeometry(); $source = null; } else if ($source instanceof Kwf_Uploads_Row) { $sourceSize = $source->getImageDimensions(); $source = null; } else { $sourceSize = $source; $source = null; } if (!$sourceSize) return false; if (!isset($sourceSize['rotation'])) $sourceSize['rotation'] = 0; $w = null; if (isset($sourceSize[0])) $w = $sourceSize[0]; if (isset($sourceSize['width'])) $w = $sourceSize['width']; $h = null; if (isset($sourceSize[1])) $h = $sourceSize[1]; if (isset($sourceSize['height'])) $h = $sourceSize['height']; if (!$w || !$h) return false; $originalSize = array($w, $h); // get output-width $outputWidth = 0; if (isset($targetSize[0])) $outputWidth = $targetSize[0]; if (isset($targetSize['width'])) $outputWidth = $targetSize['width']; // get output-height $outputHeight = 0; if (isset($targetSize[1])) $outputHeight = $targetSize[1]; if (isset($targetSize['height'])) $outputHeight = $targetSize['height']; // get crop-data $crop = isset($targetSize['crop']) ? $targetSize['crop'] : null; // get cover $cover = isset($targetSize['cover']) ? $targetSize['cover'] : true; // Check if image has to be rotated if ($sourceSize['rotation'] == 90) { $originalSize = array($originalSize[1], $originalSize[0]); } if ($outputWidth == 0 && $outputHeight == 0) { if ($crop) { $ret = array( 'width' => $crop['width'], 'height' => $crop['height'], 'rotate' => 0, 'crop' => array( 'x' => $crop['x'], 'y' => $crop['y'], 'width' => $crop['width'], 'height' => $crop['height'] ) ); if (isset($targetSize['imageCompressionQuality'])) { $ret['imageCompressionQuality'] = $targetSize['imageCompressionQuality']; } return $ret; } else { // Handle keep original return array( 'width' => $originalSize[0], 'height' => $originalSize[1], 'rotate' => 0, 'crop' => array( 'x' => 0, 'y' => 0, 'width' => $originalSize[0], 'height' => $originalSize[1] ), 'keepOriginal' => true, ); } } // Calculate missing dimension $calculateWidth = $originalSize[0]; $calculateHeight = $originalSize[1]; if ($crop) { $calculateWidth = $crop['width']; $calculateHeight = $crop['height']; } if ($cover) { // image will always have defined size if ($outputWidth == 0) { if (isset($targetSize['aspectRatio'])) { $outputWidth = round($outputHeight * $targetSize['aspectRatio']); } else { $outputWidth = round($outputHeight * ($calculateWidth / $calculateHeight)); } if ($outputWidth <= 0) $outputWidth = 1; } if ($outputHeight == 0) { if (isset($targetSize['aspectRatio']) && $targetSize['aspectRatio']) { $outputHeight = round($outputWidth * $targetSize['aspectRatio']); } else { $outputHeight = round($outputWidth * ($calculateHeight / $calculateWidth)); } if ($outputHeight <= 0) $outputHeight = 1; } if (!$crop) { // crop from complete image $crop = array(); // calculate crop depending on target-size if (($outputWidth / $outputHeight) >= ($originalSize[0] / $originalSize[1])) { $crop['width'] = $originalSize[0]; $crop['height'] = $originalSize[0] * ($outputHeight / $outputWidth); } else { $crop['height'] = $originalSize[1]; $crop['width'] = $originalSize[1] * ($outputWidth / $outputHeight); } // calculate x and y of crop $xDiff = $originalSize[0] - $crop['width']; $crop['x'] = $xDiff > 0 ? $xDiff / 2 : 0; $yDiff = $originalSize[1] - $crop['height']; $crop['y'] = $yDiff > 0 ? $yDiff / 2 : 0; } else { $oldCrop['width'] = $crop['width']; $oldCrop['height'] = $crop['height']; if (($outputWidth / $outputHeight) >= ($crop['width'] / $crop['height'])) { $crop['width'] = $crop['width']; $crop['height'] = $crop['width'] * ($outputHeight / $outputWidth); } else { $crop['height'] = $crop['height']; $crop['width'] = $crop['height'] * ($outputWidth / $outputHeight); } $xDiff = $oldCrop['width'] - $crop['width']; $crop['x'] += $xDiff > 0 ? $xDiff / 2 : 0; $yDiff = $oldCrop['height'] - $crop['height']; $crop['y'] += $yDiff > 0 ? $yDiff / 2 : 0; } } elseif (!$cover) { // image keeps aspectratio and will not be scaled up // calculateWidth is cropWidth if existing else originalWidth. // prevent image scale up if (!$crop) { $crop = array( 'x' => 0, 'y' => 0, 'width' => $originalSize[0], 'height' => $originalSize[1] ); } if ($calculateWidth <= $outputWidth && $calculateHeight <= $outputHeight) { $outputWidth = $calculateWidth; $outputHeight = $calculateHeight; } else { if ($calculateWidth < $outputWidth) { $outputWidth = $calculateWidth; } if ($calculateHeight < $outputHeight) { $outputHeight = $calculateHeight; } } $widthRatio = $outputWidth ? $calculateWidth / $outputWidth : null; $heightRatio = $outputHeight ? $calculateHeight / $outputHeight : null; if ($widthRatio > $heightRatio) { $outputWidth = $calculateWidth / $widthRatio; $outputHeight = $calculateHeight / $widthRatio; } else if ($heightRatio > $widthRatio) { $outputWidth = $calculateWidth / $heightRatio; $outputHeight = $calculateHeight / $heightRatio; } } $outputWidth = round($outputWidth); if ($outputWidth <= 0) $outputWidth = 1; $outputHeight = round($outputHeight); if ($outputHeight <= 0) $outputHeight = 1; $ret = array( 'width' => round($outputWidth), 'height' => round($outputHeight), 'rotate' => $sourceSize['rotation'], 'crop' => $crop ); if (isset($targetSize['imageCompressionQuality'])) { $ret['imageCompressionQuality'] = $targetSize['imageCompressionQuality']; } //Set values to match original-parameters when original won't change if ($ret['crop']['x'] == 0 && $ret['crop']['y'] == 0 && $ret['crop']['width'] == $originalSize[0] && $ret['crop']['height'] == $originalSize[1] && $ret['width'] == $originalSize[0] && $ret['height'] == $originalSize[1] && !$ret['rotate'] ) { $ret['keepOriginal'] = true; } return $ret; }
[ "public", "static", "function", "calculateScaleDimensions", "(", "$", "source", ",", "$", "targetSize", ")", "{", "// Get size of image (handle different param-possibilities)", "if", "(", "is_string", "(", "$", "source", ")", ")", "{", "$", "sourceSize", "=", "@", "getimagesize", "(", "$", "source", ")", ";", "$", "sourceSize", "[", "'rotation'", "]", "=", "self", "::", "getExifRotation", "(", "$", "source", ")", ";", "}", "else", "if", "(", "$", "source", "instanceof", "Imagick", ")", "{", "$", "sourceSize", "=", "$", "source", "->", "getImageGeometry", "(", ")", ";", "$", "source", "=", "null", ";", "}", "else", "if", "(", "$", "source", "instanceof", "Kwf_Uploads_Row", ")", "{", "$", "sourceSize", "=", "$", "source", "->", "getImageDimensions", "(", ")", ";", "$", "source", "=", "null", ";", "}", "else", "{", "$", "sourceSize", "=", "$", "source", ";", "$", "source", "=", "null", ";", "}", "if", "(", "!", "$", "sourceSize", ")", "return", "false", ";", "if", "(", "!", "isset", "(", "$", "sourceSize", "[", "'rotation'", "]", ")", ")", "$", "sourceSize", "[", "'rotation'", "]", "=", "0", ";", "$", "w", "=", "null", ";", "if", "(", "isset", "(", "$", "sourceSize", "[", "0", "]", ")", ")", "$", "w", "=", "$", "sourceSize", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "sourceSize", "[", "'width'", "]", ")", ")", "$", "w", "=", "$", "sourceSize", "[", "'width'", "]", ";", "$", "h", "=", "null", ";", "if", "(", "isset", "(", "$", "sourceSize", "[", "1", "]", ")", ")", "$", "h", "=", "$", "sourceSize", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "sourceSize", "[", "'height'", "]", ")", ")", "$", "h", "=", "$", "sourceSize", "[", "'height'", "]", ";", "if", "(", "!", "$", "w", "||", "!", "$", "h", ")", "return", "false", ";", "$", "originalSize", "=", "array", "(", "$", "w", ",", "$", "h", ")", ";", "// get output-width", "$", "outputWidth", "=", "0", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "0", "]", ")", ")", "$", "outputWidth", "=", "$", "targetSize", "[", "0", "]", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "'width'", "]", ")", ")", "$", "outputWidth", "=", "$", "targetSize", "[", "'width'", "]", ";", "// get output-height", "$", "outputHeight", "=", "0", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "1", "]", ")", ")", "$", "outputHeight", "=", "$", "targetSize", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "'height'", "]", ")", ")", "$", "outputHeight", "=", "$", "targetSize", "[", "'height'", "]", ";", "// get crop-data", "$", "crop", "=", "isset", "(", "$", "targetSize", "[", "'crop'", "]", ")", "?", "$", "targetSize", "[", "'crop'", "]", ":", "null", ";", "// get cover", "$", "cover", "=", "isset", "(", "$", "targetSize", "[", "'cover'", "]", ")", "?", "$", "targetSize", "[", "'cover'", "]", ":", "true", ";", "// Check if image has to be rotated", "if", "(", "$", "sourceSize", "[", "'rotation'", "]", "==", "90", ")", "{", "$", "originalSize", "=", "array", "(", "$", "originalSize", "[", "1", "]", ",", "$", "originalSize", "[", "0", "]", ")", ";", "}", "if", "(", "$", "outputWidth", "==", "0", "&&", "$", "outputHeight", "==", "0", ")", "{", "if", "(", "$", "crop", ")", "{", "$", "ret", "=", "array", "(", "'width'", "=>", "$", "crop", "[", "'width'", "]", ",", "'height'", "=>", "$", "crop", "[", "'height'", "]", ",", "'rotate'", "=>", "0", ",", "'crop'", "=>", "array", "(", "'x'", "=>", "$", "crop", "[", "'x'", "]", ",", "'y'", "=>", "$", "crop", "[", "'y'", "]", ",", "'width'", "=>", "$", "crop", "[", "'width'", "]", ",", "'height'", "=>", "$", "crop", "[", "'height'", "]", ")", ")", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "'imageCompressionQuality'", "]", ")", ")", "{", "$", "ret", "[", "'imageCompressionQuality'", "]", "=", "$", "targetSize", "[", "'imageCompressionQuality'", "]", ";", "}", "return", "$", "ret", ";", "}", "else", "{", "// Handle keep original", "return", "array", "(", "'width'", "=>", "$", "originalSize", "[", "0", "]", ",", "'height'", "=>", "$", "originalSize", "[", "1", "]", ",", "'rotate'", "=>", "0", ",", "'crop'", "=>", "array", "(", "'x'", "=>", "0", ",", "'y'", "=>", "0", ",", "'width'", "=>", "$", "originalSize", "[", "0", "]", ",", "'height'", "=>", "$", "originalSize", "[", "1", "]", ")", ",", "'keepOriginal'", "=>", "true", ",", ")", ";", "}", "}", "// Calculate missing dimension", "$", "calculateWidth", "=", "$", "originalSize", "[", "0", "]", ";", "$", "calculateHeight", "=", "$", "originalSize", "[", "1", "]", ";", "if", "(", "$", "crop", ")", "{", "$", "calculateWidth", "=", "$", "crop", "[", "'width'", "]", ";", "$", "calculateHeight", "=", "$", "crop", "[", "'height'", "]", ";", "}", "if", "(", "$", "cover", ")", "{", "// image will always have defined size", "if", "(", "$", "outputWidth", "==", "0", ")", "{", "if", "(", "isset", "(", "$", "targetSize", "[", "'aspectRatio'", "]", ")", ")", "{", "$", "outputWidth", "=", "round", "(", "$", "outputHeight", "*", "$", "targetSize", "[", "'aspectRatio'", "]", ")", ";", "}", "else", "{", "$", "outputWidth", "=", "round", "(", "$", "outputHeight", "*", "(", "$", "calculateWidth", "/", "$", "calculateHeight", ")", ")", ";", "}", "if", "(", "$", "outputWidth", "<=", "0", ")", "$", "outputWidth", "=", "1", ";", "}", "if", "(", "$", "outputHeight", "==", "0", ")", "{", "if", "(", "isset", "(", "$", "targetSize", "[", "'aspectRatio'", "]", ")", "&&", "$", "targetSize", "[", "'aspectRatio'", "]", ")", "{", "$", "outputHeight", "=", "round", "(", "$", "outputWidth", "*", "$", "targetSize", "[", "'aspectRatio'", "]", ")", ";", "}", "else", "{", "$", "outputHeight", "=", "round", "(", "$", "outputWidth", "*", "(", "$", "calculateHeight", "/", "$", "calculateWidth", ")", ")", ";", "}", "if", "(", "$", "outputHeight", "<=", "0", ")", "$", "outputHeight", "=", "1", ";", "}", "if", "(", "!", "$", "crop", ")", "{", "// crop from complete image", "$", "crop", "=", "array", "(", ")", ";", "// calculate crop depending on target-size", "if", "(", "(", "$", "outputWidth", "/", "$", "outputHeight", ")", ">=", "(", "$", "originalSize", "[", "0", "]", "/", "$", "originalSize", "[", "1", "]", ")", ")", "{", "$", "crop", "[", "'width'", "]", "=", "$", "originalSize", "[", "0", "]", ";", "$", "crop", "[", "'height'", "]", "=", "$", "originalSize", "[", "0", "]", "*", "(", "$", "outputHeight", "/", "$", "outputWidth", ")", ";", "}", "else", "{", "$", "crop", "[", "'height'", "]", "=", "$", "originalSize", "[", "1", "]", ";", "$", "crop", "[", "'width'", "]", "=", "$", "originalSize", "[", "1", "]", "*", "(", "$", "outputWidth", "/", "$", "outputHeight", ")", ";", "}", "// calculate x and y of crop", "$", "xDiff", "=", "$", "originalSize", "[", "0", "]", "-", "$", "crop", "[", "'width'", "]", ";", "$", "crop", "[", "'x'", "]", "=", "$", "xDiff", ">", "0", "?", "$", "xDiff", "/", "2", ":", "0", ";", "$", "yDiff", "=", "$", "originalSize", "[", "1", "]", "-", "$", "crop", "[", "'height'", "]", ";", "$", "crop", "[", "'y'", "]", "=", "$", "yDiff", ">", "0", "?", "$", "yDiff", "/", "2", ":", "0", ";", "}", "else", "{", "$", "oldCrop", "[", "'width'", "]", "=", "$", "crop", "[", "'width'", "]", ";", "$", "oldCrop", "[", "'height'", "]", "=", "$", "crop", "[", "'height'", "]", ";", "if", "(", "(", "$", "outputWidth", "/", "$", "outputHeight", ")", ">=", "(", "$", "crop", "[", "'width'", "]", "/", "$", "crop", "[", "'height'", "]", ")", ")", "{", "$", "crop", "[", "'width'", "]", "=", "$", "crop", "[", "'width'", "]", ";", "$", "crop", "[", "'height'", "]", "=", "$", "crop", "[", "'width'", "]", "*", "(", "$", "outputHeight", "/", "$", "outputWidth", ")", ";", "}", "else", "{", "$", "crop", "[", "'height'", "]", "=", "$", "crop", "[", "'height'", "]", ";", "$", "crop", "[", "'width'", "]", "=", "$", "crop", "[", "'height'", "]", "*", "(", "$", "outputWidth", "/", "$", "outputHeight", ")", ";", "}", "$", "xDiff", "=", "$", "oldCrop", "[", "'width'", "]", "-", "$", "crop", "[", "'width'", "]", ";", "$", "crop", "[", "'x'", "]", "+=", "$", "xDiff", ">", "0", "?", "$", "xDiff", "/", "2", ":", "0", ";", "$", "yDiff", "=", "$", "oldCrop", "[", "'height'", "]", "-", "$", "crop", "[", "'height'", "]", ";", "$", "crop", "[", "'y'", "]", "+=", "$", "yDiff", ">", "0", "?", "$", "yDiff", "/", "2", ":", "0", ";", "}", "}", "elseif", "(", "!", "$", "cover", ")", "{", "// image keeps aspectratio and will not be scaled up", "// calculateWidth is cropWidth if existing else originalWidth.", "// prevent image scale up", "if", "(", "!", "$", "crop", ")", "{", "$", "crop", "=", "array", "(", "'x'", "=>", "0", ",", "'y'", "=>", "0", ",", "'width'", "=>", "$", "originalSize", "[", "0", "]", ",", "'height'", "=>", "$", "originalSize", "[", "1", "]", ")", ";", "}", "if", "(", "$", "calculateWidth", "<=", "$", "outputWidth", "&&", "$", "calculateHeight", "<=", "$", "outputHeight", ")", "{", "$", "outputWidth", "=", "$", "calculateWidth", ";", "$", "outputHeight", "=", "$", "calculateHeight", ";", "}", "else", "{", "if", "(", "$", "calculateWidth", "<", "$", "outputWidth", ")", "{", "$", "outputWidth", "=", "$", "calculateWidth", ";", "}", "if", "(", "$", "calculateHeight", "<", "$", "outputHeight", ")", "{", "$", "outputHeight", "=", "$", "calculateHeight", ";", "}", "}", "$", "widthRatio", "=", "$", "outputWidth", "?", "$", "calculateWidth", "/", "$", "outputWidth", ":", "null", ";", "$", "heightRatio", "=", "$", "outputHeight", "?", "$", "calculateHeight", "/", "$", "outputHeight", ":", "null", ";", "if", "(", "$", "widthRatio", ">", "$", "heightRatio", ")", "{", "$", "outputWidth", "=", "$", "calculateWidth", "/", "$", "widthRatio", ";", "$", "outputHeight", "=", "$", "calculateHeight", "/", "$", "widthRatio", ";", "}", "else", "if", "(", "$", "heightRatio", ">", "$", "widthRatio", ")", "{", "$", "outputWidth", "=", "$", "calculateWidth", "/", "$", "heightRatio", ";", "$", "outputHeight", "=", "$", "calculateHeight", "/", "$", "heightRatio", ";", "}", "}", "$", "outputWidth", "=", "round", "(", "$", "outputWidth", ")", ";", "if", "(", "$", "outputWidth", "<=", "0", ")", "$", "outputWidth", "=", "1", ";", "$", "outputHeight", "=", "round", "(", "$", "outputHeight", ")", ";", "if", "(", "$", "outputHeight", "<=", "0", ")", "$", "outputHeight", "=", "1", ";", "$", "ret", "=", "array", "(", "'width'", "=>", "round", "(", "$", "outputWidth", ")", ",", "'height'", "=>", "round", "(", "$", "outputHeight", ")", ",", "'rotate'", "=>", "$", "sourceSize", "[", "'rotation'", "]", ",", "'crop'", "=>", "$", "crop", ")", ";", "if", "(", "isset", "(", "$", "targetSize", "[", "'imageCompressionQuality'", "]", ")", ")", "{", "$", "ret", "[", "'imageCompressionQuality'", "]", "=", "$", "targetSize", "[", "'imageCompressionQuality'", "]", ";", "}", "//Set values to match original-parameters when original won't change", "if", "(", "$", "ret", "[", "'crop'", "]", "[", "'x'", "]", "==", "0", "&&", "$", "ret", "[", "'crop'", "]", "[", "'y'", "]", "==", "0", "&&", "$", "ret", "[", "'crop'", "]", "[", "'width'", "]", "==", "$", "originalSize", "[", "0", "]", "&&", "$", "ret", "[", "'crop'", "]", "[", "'height'", "]", "==", "$", "originalSize", "[", "1", "]", "&&", "$", "ret", "[", "'width'", "]", "==", "$", "originalSize", "[", "0", "]", "&&", "$", "ret", "[", "'height'", "]", "==", "$", "originalSize", "[", "1", "]", "&&", "!", "$", "ret", "[", "'rotate'", "]", ")", "{", "$", "ret", "[", "'keepOriginal'", "]", "=", "true", ";", "}", "return", "$", "ret", ";", "}" ]
targetSize options: width, height, cover, aspectRatio
[ "targetSize", "options", ":", "width", "height", "cover", "aspectRatio" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Image.php#L208-L418
koala-framework/koala-framework
Kwf/User/Auth/PasswordFields.php
Kwf_User_Auth_PasswordFields.generatePasswordSalt
public function generatePasswordSalt(Kwf_Model_Row_Interface $row) { mt_srand((double)microtime()*1000000); $row->password_salt = substr(md5(uniqid(mt_rand(), true)), 0, 10); }
php
public function generatePasswordSalt(Kwf_Model_Row_Interface $row) { mt_srand((double)microtime()*1000000); $row->password_salt = substr(md5(uniqid(mt_rand(), true)), 0, 10); }
[ "public", "function", "generatePasswordSalt", "(", "Kwf_Model_Row_Interface", "$", "row", ")", "{", "mt_srand", "(", "(", "double", ")", "microtime", "(", ")", "*", "1000000", ")", ";", "$", "row", "->", "password_salt", "=", "substr", "(", "md5", "(", "uniqid", "(", "mt_rand", "(", ")", ",", "true", ")", ")", ",", "0", ",", "10", ")", ";", "}" ]
not part of interface but used by Kwf_User_EditRow
[ "not", "part", "of", "interface", "but", "used", "by", "Kwf_User_EditRow" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/User/Auth/PasswordFields.php#L33-L37
koala-framework/koala-framework
Kwf/Component/Renderer/Abstract.php
Kwf_Component_Renderer_Abstract.renderComponent
public function renderComponent($component, &$hasDynamicParts = false) { if (Kwf_Component_Data_Root::getShowInvisible()) { $hasDynamicParts = true; } $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this); $content = $helper->component($component); $content = $this->_renderPass2($content, $hasDynamicParts); Kwf_Component_Cache::getInstance()->writeBuffer(); foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) { $content = $plugin->processOutput($content, $component); } return $content; }
php
public function renderComponent($component, &$hasDynamicParts = false) { if (Kwf_Component_Data_Root::getShowInvisible()) { $hasDynamicParts = true; } $helper = new Kwf_Component_View_Helper_Component(); $helper->setRenderer($this); $content = $helper->component($component); $content = $this->_renderPass2($content, $hasDynamicParts); Kwf_Component_Cache::getInstance()->writeBuffer(); foreach (Kwf_Component_Data_Root::getInstance()->getPlugins('Kwf_Component_PluginRoot_Interface_PostRender') as $plugin) { $content = $plugin->processOutput($content, $component); } return $content; }
[ "public", "function", "renderComponent", "(", "$", "component", ",", "&", "$", "hasDynamicParts", "=", "false", ")", "{", "if", "(", "Kwf_Component_Data_Root", "::", "getShowInvisible", "(", ")", ")", "{", "$", "hasDynamicParts", "=", "true", ";", "}", "$", "helper", "=", "new", "Kwf_Component_View_Helper_Component", "(", ")", ";", "$", "helper", "->", "setRenderer", "(", "$", "this", ")", ";", "$", "content", "=", "$", "helper", "->", "component", "(", "$", "component", ")", ";", "$", "content", "=", "$", "this", "->", "_renderPass2", "(", "$", "content", ",", "$", "hasDynamicParts", ")", ";", "Kwf_Component_Cache", "::", "getInstance", "(", ")", "->", "writeBuffer", "(", ")", ";", "foreach", "(", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getPlugins", "(", "'Kwf_Component_PluginRoot_Interface_PostRender'", ")", "as", "$", "plugin", ")", "{", "$", "content", "=", "$", "plugin", "->", "processOutput", "(", "$", "content", ",", "$", "component", ")", ";", "}", "return", "$", "content", ";", "}" ]
Renders a single component without master
[ "Renders", "a", "single", "component", "without", "master" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Renderer/Abstract.php#L39-L57
koala-framework/koala-framework
Kwf/Component/Renderer/Abstract.php
Kwf_Component_Renderer_Abstract.getTemplate
public function getTemplate(Kwf_Component_Data $component, $type) { if ($type == 'Master') { if (Kwc_Abstract::hasSetting($component->componentClass, 'masterTemplate')) { return Kwc_Abstract::getSetting($component->componentClass, 'masterTemplate'); } } $template = Kwc_Abstract::getTemplateFile($component->componentClass, $type); if (!$template) throw new Kwf_Exception("No $type-Template found for '{$component->componentClass}'"); return $template; }
php
public function getTemplate(Kwf_Component_Data $component, $type) { if ($type == 'Master') { if (Kwc_Abstract::hasSetting($component->componentClass, 'masterTemplate')) { return Kwc_Abstract::getSetting($component->componentClass, 'masterTemplate'); } } $template = Kwc_Abstract::getTemplateFile($component->componentClass, $type); if (!$template) throw new Kwf_Exception("No $type-Template found for '{$component->componentClass}'"); return $template; }
[ "public", "function", "getTemplate", "(", "Kwf_Component_Data", "$", "component", ",", "$", "type", ")", "{", "if", "(", "$", "type", "==", "'Master'", ")", "{", "if", "(", "Kwc_Abstract", "::", "hasSetting", "(", "$", "component", "->", "componentClass", ",", "'masterTemplate'", ")", ")", "{", "return", "Kwc_Abstract", "::", "getSetting", "(", "$", "component", "->", "componentClass", ",", "'masterTemplate'", ")", ";", "}", "}", "$", "template", "=", "Kwc_Abstract", "::", "getTemplateFile", "(", "$", "component", "->", "componentClass", ",", "$", "type", ")", ";", "if", "(", "!", "$", "template", ")", "throw", "new", "Kwf_Exception", "(", "\"No $type-Template found for '{$component->componentClass}'\"", ")", ";", "return", "$", "template", ";", "}" ]
overridden by Renderer_Mail to use mail templates
[ "overridden", "by", "Renderer_Mail", "to", "use", "mail", "templates" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Renderer/Abstract.php#L62-L72
koala-framework/koala-framework
Kwf/Component/Renderer/Abstract.php
Kwf_Component_Renderer_Abstract._renderPass1
protected function _renderPass1($ret, &$pass1Cacheable = true) { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) $benchmarkEnabled = Kwf_Benchmark::isEnabled(); $offset = 0; while ($target = $this->_getNextRenderTarget($ret, 1, $offset)) { if ($benchmarkEnabled) $startTime = microtime(true); $helper = $this->_getHelper($target['type']); $statType = null; $content = null; if ($this->_enableCache) { $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']); } if (!is_null($content)) { //cache hit $statType = 'hit'; //look for UseViewCache plugin in $content if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) { if (!$p['plugin']->useViewCache($this)) { //useViewCache=false: re-render but don't cache $pass1Cacheable = false; $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } else { //useViewCache=true //continue with <pluginC in $content (so it can be cached in fullPage cache) } } } else { //cache miss $statType = 'miss'; $cacheSaved = true; $content = $this->_renderAndCache( $target['componentId'], $target['type'], $target['value'], $target['config'], true, //addPluginPlaceholders (so it can be cached in fullPage cache) $cacheSaved //will be set to false if we can't use fullPage cache because eg a UseViewCache plugin returned false ); if (!$cacheSaved) $pass1Cacheable = false; } //if $pass1Cacheable=true $content must include all <plugin?s //if $pass1Cacheable=false $contents must only include <pluginA and all other plugins must be executed already $content = $helper->renderCached($content, $target['componentId'], $target['config']); $ret = substr($ret, 0, $target['start']).$content.substr($ret, $target['end']+1); if ($statType) { if ($benchmarkEnabled) Kwf_Benchmark::count("rendered $statType", $target['statId']); Kwf_Benchmark::countLog('render-'.$statType); } if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint($target['componentId'].' '.$target['type'], microtime(true)-$startTime); } return $ret; }
php
protected function _renderPass1($ret, &$pass1Cacheable = true) { static $benchmarkEnabled; if (!isset($benchmarkEnabled)) $benchmarkEnabled = Kwf_Benchmark::isEnabled(); $offset = 0; while ($target = $this->_getNextRenderTarget($ret, 1, $offset)) { if ($benchmarkEnabled) $startTime = microtime(true); $helper = $this->_getHelper($target['type']); $statType = null; $content = null; if ($this->_enableCache) { $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']); } if (!is_null($content)) { //cache hit $statType = 'hit'; //look for UseViewCache plugin in $content if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) { if (!$p['plugin']->useViewCache($this)) { //useViewCache=false: re-render but don't cache $pass1Cacheable = false; $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } else { //useViewCache=true //continue with <pluginC in $content (so it can be cached in fullPage cache) } } } else { //cache miss $statType = 'miss'; $cacheSaved = true; $content = $this->_renderAndCache( $target['componentId'], $target['type'], $target['value'], $target['config'], true, //addPluginPlaceholders (so it can be cached in fullPage cache) $cacheSaved //will be set to false if we can't use fullPage cache because eg a UseViewCache plugin returned false ); if (!$cacheSaved) $pass1Cacheable = false; } //if $pass1Cacheable=true $content must include all <plugin?s //if $pass1Cacheable=false $contents must only include <pluginA and all other plugins must be executed already $content = $helper->renderCached($content, $target['componentId'], $target['config']); $ret = substr($ret, 0, $target['start']).$content.substr($ret, $target['end']+1); if ($statType) { if ($benchmarkEnabled) Kwf_Benchmark::count("rendered $statType", $target['statId']); Kwf_Benchmark::countLog('render-'.$statType); } if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint($target['componentId'].' '.$target['type'], microtime(true)-$startTime); } return $ret; }
[ "protected", "function", "_renderPass1", "(", "$", "ret", ",", "&", "$", "pass1Cacheable", "=", "true", ")", "{", "static", "$", "benchmarkEnabled", ";", "if", "(", "!", "isset", "(", "$", "benchmarkEnabled", ")", ")", "$", "benchmarkEnabled", "=", "Kwf_Benchmark", "::", "isEnabled", "(", ")", ";", "$", "offset", "=", "0", ";", "while", "(", "$", "target", "=", "$", "this", "->", "_getNextRenderTarget", "(", "$", "ret", ",", "1", ",", "$", "offset", ")", ")", "{", "if", "(", "$", "benchmarkEnabled", ")", "$", "startTime", "=", "microtime", "(", "true", ")", ";", "$", "helper", "=", "$", "this", "->", "_getHelper", "(", "$", "target", "[", "'type'", "]", ")", ";", "$", "statType", "=", "null", ";", "$", "content", "=", "null", ";", "if", "(", "$", "this", "->", "_enableCache", ")", "{", "$", "content", "=", "$", "this", "->", "_cacheLoad", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'value'", "]", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "content", ")", ")", "{", "//cache hit", "$", "statType", "=", "'hit'", ";", "//look for UseViewCache plugin in $content", "if", "(", "$", "p", "=", "$", "this", "->", "_findSinglePlugin", "(", "self", "::", "PLUGIN_TYPE_USECACHE", ",", "$", "content", ")", ")", "{", "if", "(", "!", "$", "p", "[", "'plugin'", "]", "->", "useViewCache", "(", "$", "this", ")", ")", "{", "//useViewCache=false: re-render but don't cache", "$", "pass1Cacheable", "=", "false", ";", "$", "content", "=", "$", "this", "->", "_renderUncached", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'config'", "]", ")", ";", "}", "else", "{", "//useViewCache=true", "//continue with <pluginC in $content (so it can be cached in fullPage cache)", "}", "}", "}", "else", "{", "//cache miss", "$", "statType", "=", "'miss'", ";", "$", "cacheSaved", "=", "true", ";", "$", "content", "=", "$", "this", "->", "_renderAndCache", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'value'", "]", ",", "$", "target", "[", "'config'", "]", ",", "true", ",", "//addPluginPlaceholders (so it can be cached in fullPage cache)", "$", "cacheSaved", "//will be set to false if we can't use fullPage cache because eg a UseViewCache plugin returned false", ")", ";", "if", "(", "!", "$", "cacheSaved", ")", "$", "pass1Cacheable", "=", "false", ";", "}", "//if $pass1Cacheable=true $content must include all <plugin?s", "//if $pass1Cacheable=false $contents must only include <pluginA and all other plugins must be executed already", "$", "content", "=", "$", "helper", "->", "renderCached", "(", "$", "content", ",", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'config'", "]", ")", ";", "$", "ret", "=", "substr", "(", "$", "ret", ",", "0", ",", "$", "target", "[", "'start'", "]", ")", ".", "$", "content", ".", "substr", "(", "$", "ret", ",", "$", "target", "[", "'end'", "]", "+", "1", ")", ";", "if", "(", "$", "statType", ")", "{", "if", "(", "$", "benchmarkEnabled", ")", "Kwf_Benchmark", "::", "count", "(", "\"rendered $statType\"", ",", "$", "target", "[", "'statId'", "]", ")", ";", "Kwf_Benchmark", "::", "countLog", "(", "'render-'", ".", "$", "statType", ")", ";", "}", "if", "(", "$", "benchmarkEnabled", ")", "Kwf_Benchmark", "::", "subCheckpoint", "(", "$", "target", "[", "'componentId'", "]", ".", "' '", ".", "$", "target", "[", "'type'", "]", ",", "microtime", "(", "true", ")", "-", "$", "startTime", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Render components (ie. expand <kwc ...>) Pass 1 for content that can be stored in fullPage cache, 2 for everything else. 2 includes 1, so calling just with 2 also works @param string render content @param bool if returned contents is cacheable
[ "Render", "components", "(", "ie", ".", "expand", "<kwc", "...", ">", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Renderer/Abstract.php#L311-L370
koala-framework/koala-framework
Kwf/Component/Renderer/Abstract.php
Kwf_Component_Renderer_Abstract._renderPass2
protected function _renderPass2($ret, &$hasDynamicParts = false) { //execute all plugins that where added in pass 1 $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_USECACHE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_REPLACE, $hasDynamicParts); $ret = $this->_findAndExecuteUseCacheDynamic($ret, $hasDynamicParts); static $benchmarkEnabled; if (!isset($benchmarkEnabled)) $benchmarkEnabled = Kwf_Benchmark::isEnabled(); $offset = 0; while ($target = $this->_getNextRenderTarget($ret, 2, $offset)) { if ($benchmarkEnabled) $startTime = microtime(true); $helper = $this->_getHelper($target['type']); $statType = null; $content = null; if ($this->_enableCache && $target['isCacheable']) { $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']); } if (!is_null($content)) { //cache hit $statType = 'hit'; //look for UseViewCache plugin in $content if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) { $hasDynamicParts = true; if (!$p['plugin']->useViewCache($this)) { //re-render, without <pluginC $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } else { //continue with content $content = $p['content']; } } else { //execute replace and before plugin if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_REPLACE, $content)) { $hasDynamicParts = true; $r = $p['plugin']->replaceOutput($this); if ($r !== false) { $content = $r; } else { $content = $p['content']; } } $content = $this->_findAndExecutePlugins($content, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); } $content = $this->_findAndExecuteUseCacheDynamic($content, $hasDynamicParts); } else { if ($this->_enableCache && $target['isCacheable']) { //cache miss $statType = 'miss'; $content = $this->_renderAndCache($target['componentId'], $target['type'], $target['value'], $target['config'], false //don't add plugin placeholders, execute them ); } else { $hasDynamicParts = true; //view cache disabled $statType = 'noviewcache'; $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } } $content = $helper->renderCached($content, $target['componentId'], $target['config']); $ret = substr($ret, 0, $target['start']).$content.substr($ret, $target['end']+1); if ($statType) { if ($benchmarkEnabled) Kwf_Benchmark::count("rendered $statType", $target['statId']); Kwf_Benchmark::countLog('render-'.$statType); } if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint($target['componentId'].' '.$target['type'], microtime(true)-$startTime); } //execute Render Cached Dynamic, used eg for callback link modifier in componentLink while (($start = strpos($ret, '<rcd ')) !== false) { $hasDynamicParts = true; $startEnd = strpos($ret, '>', $start); $args = explode(' ', substr($ret, $start+5, $startEnd-$start-5)); $end = strpos($ret, '</rcd '.$args[0].'>'); $content = substr($ret, $startEnd+1, $end-$startEnd-1); if ($benchmarkEnabled) $startTime = microtime(true); $componentId = $args[0]; $type = $args[1]; $settings = json_decode($args[2], true); $content = $this->_getHelper($type)->renderCachedDynamic($content, $componentId, $settings); if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint("renderCachedDynamic $type $componentId", microtime(true)-$startTime); $ret = substr($ret, 0, $start).$content.substr($ret, $end+7+strlen($args[0])); } $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_AFTER, $hasDynamicParts); return $ret; }
php
protected function _renderPass2($ret, &$hasDynamicParts = false) { //execute all plugins that where added in pass 1 $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_USECACHE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_REPLACE, $hasDynamicParts); $ret = $this->_findAndExecuteUseCacheDynamic($ret, $hasDynamicParts); static $benchmarkEnabled; if (!isset($benchmarkEnabled)) $benchmarkEnabled = Kwf_Benchmark::isEnabled(); $offset = 0; while ($target = $this->_getNextRenderTarget($ret, 2, $offset)) { if ($benchmarkEnabled) $startTime = microtime(true); $helper = $this->_getHelper($target['type']); $statType = null; $content = null; if ($this->_enableCache && $target['isCacheable']) { $content = $this->_cacheLoad($target['componentId'], $target['type'], $target['value']); } if (!is_null($content)) { //cache hit $statType = 'hit'; //look for UseViewCache plugin in $content if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_USECACHE, $content)) { $hasDynamicParts = true; if (!$p['plugin']->useViewCache($this)) { //re-render, without <pluginC $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } else { //continue with content $content = $p['content']; } } else { //execute replace and before plugin if ($p = $this->_findSinglePlugin(self::PLUGIN_TYPE_REPLACE, $content)) { $hasDynamicParts = true; $r = $p['plugin']->replaceOutput($this); if ($r !== false) { $content = $r; } else { $content = $p['content']; } } $content = $this->_findAndExecutePlugins($content, self::PLUGIN_TYPE_BEFORE, $hasDynamicParts); } $content = $this->_findAndExecuteUseCacheDynamic($content, $hasDynamicParts); } else { if ($this->_enableCache && $target['isCacheable']) { //cache miss $statType = 'miss'; $content = $this->_renderAndCache($target['componentId'], $target['type'], $target['value'], $target['config'], false //don't add plugin placeholders, execute them ); } else { $hasDynamicParts = true; //view cache disabled $statType = 'noviewcache'; $content = $this->_renderUncached($target['componentId'], $target['type'], $target['config']); } } $content = $helper->renderCached($content, $target['componentId'], $target['config']); $ret = substr($ret, 0, $target['start']).$content.substr($ret, $target['end']+1); if ($statType) { if ($benchmarkEnabled) Kwf_Benchmark::count("rendered $statType", $target['statId']); Kwf_Benchmark::countLog('render-'.$statType); } if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint($target['componentId'].' '.$target['type'], microtime(true)-$startTime); } //execute Render Cached Dynamic, used eg for callback link modifier in componentLink while (($start = strpos($ret, '<rcd ')) !== false) { $hasDynamicParts = true; $startEnd = strpos($ret, '>', $start); $args = explode(' ', substr($ret, $start+5, $startEnd-$start-5)); $end = strpos($ret, '</rcd '.$args[0].'>'); $content = substr($ret, $startEnd+1, $end-$startEnd-1); if ($benchmarkEnabled) $startTime = microtime(true); $componentId = $args[0]; $type = $args[1]; $settings = json_decode($args[2], true); $content = $this->_getHelper($type)->renderCachedDynamic($content, $componentId, $settings); if ($benchmarkEnabled) Kwf_Benchmark::subCheckpoint("renderCachedDynamic $type $componentId", microtime(true)-$startTime); $ret = substr($ret, 0, $start).$content.substr($ret, $end+7+strlen($args[0])); } $ret = $this->_findAndExecutePlugins($ret, self::PLUGIN_TYPE_AFTER, $hasDynamicParts); return $ret; }
[ "protected", "function", "_renderPass2", "(", "$", "ret", ",", "&", "$", "hasDynamicParts", "=", "false", ")", "{", "//execute all plugins that where added in pass 1", "$", "ret", "=", "$", "this", "->", "_findAndExecutePlugins", "(", "$", "ret", ",", "self", "::", "PLUGIN_TYPE_USECACHE", ",", "$", "hasDynamicParts", ")", ";", "$", "ret", "=", "$", "this", "->", "_findAndExecutePlugins", "(", "$", "ret", ",", "self", "::", "PLUGIN_TYPE_BEFORE", ",", "$", "hasDynamicParts", ")", ";", "$", "ret", "=", "$", "this", "->", "_findAndExecutePlugins", "(", "$", "ret", ",", "self", "::", "PLUGIN_TYPE_REPLACE", ",", "$", "hasDynamicParts", ")", ";", "$", "ret", "=", "$", "this", "->", "_findAndExecuteUseCacheDynamic", "(", "$", "ret", ",", "$", "hasDynamicParts", ")", ";", "static", "$", "benchmarkEnabled", ";", "if", "(", "!", "isset", "(", "$", "benchmarkEnabled", ")", ")", "$", "benchmarkEnabled", "=", "Kwf_Benchmark", "::", "isEnabled", "(", ")", ";", "$", "offset", "=", "0", ";", "while", "(", "$", "target", "=", "$", "this", "->", "_getNextRenderTarget", "(", "$", "ret", ",", "2", ",", "$", "offset", ")", ")", "{", "if", "(", "$", "benchmarkEnabled", ")", "$", "startTime", "=", "microtime", "(", "true", ")", ";", "$", "helper", "=", "$", "this", "->", "_getHelper", "(", "$", "target", "[", "'type'", "]", ")", ";", "$", "statType", "=", "null", ";", "$", "content", "=", "null", ";", "if", "(", "$", "this", "->", "_enableCache", "&&", "$", "target", "[", "'isCacheable'", "]", ")", "{", "$", "content", "=", "$", "this", "->", "_cacheLoad", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'value'", "]", ")", ";", "}", "if", "(", "!", "is_null", "(", "$", "content", ")", ")", "{", "//cache hit", "$", "statType", "=", "'hit'", ";", "//look for UseViewCache plugin in $content", "if", "(", "$", "p", "=", "$", "this", "->", "_findSinglePlugin", "(", "self", "::", "PLUGIN_TYPE_USECACHE", ",", "$", "content", ")", ")", "{", "$", "hasDynamicParts", "=", "true", ";", "if", "(", "!", "$", "p", "[", "'plugin'", "]", "->", "useViewCache", "(", "$", "this", ")", ")", "{", "//re-render, without <pluginC", "$", "content", "=", "$", "this", "->", "_renderUncached", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'config'", "]", ")", ";", "}", "else", "{", "//continue with content", "$", "content", "=", "$", "p", "[", "'content'", "]", ";", "}", "}", "else", "{", "//execute replace and before plugin", "if", "(", "$", "p", "=", "$", "this", "->", "_findSinglePlugin", "(", "self", "::", "PLUGIN_TYPE_REPLACE", ",", "$", "content", ")", ")", "{", "$", "hasDynamicParts", "=", "true", ";", "$", "r", "=", "$", "p", "[", "'plugin'", "]", "->", "replaceOutput", "(", "$", "this", ")", ";", "if", "(", "$", "r", "!==", "false", ")", "{", "$", "content", "=", "$", "r", ";", "}", "else", "{", "$", "content", "=", "$", "p", "[", "'content'", "]", ";", "}", "}", "$", "content", "=", "$", "this", "->", "_findAndExecutePlugins", "(", "$", "content", ",", "self", "::", "PLUGIN_TYPE_BEFORE", ",", "$", "hasDynamicParts", ")", ";", "}", "$", "content", "=", "$", "this", "->", "_findAndExecuteUseCacheDynamic", "(", "$", "content", ",", "$", "hasDynamicParts", ")", ";", "}", "else", "{", "if", "(", "$", "this", "->", "_enableCache", "&&", "$", "target", "[", "'isCacheable'", "]", ")", "{", "//cache miss", "$", "statType", "=", "'miss'", ";", "$", "content", "=", "$", "this", "->", "_renderAndCache", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'value'", "]", ",", "$", "target", "[", "'config'", "]", ",", "false", "//don't add plugin placeholders, execute them", ")", ";", "}", "else", "{", "$", "hasDynamicParts", "=", "true", ";", "//view cache disabled", "$", "statType", "=", "'noviewcache'", ";", "$", "content", "=", "$", "this", "->", "_renderUncached", "(", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'type'", "]", ",", "$", "target", "[", "'config'", "]", ")", ";", "}", "}", "$", "content", "=", "$", "helper", "->", "renderCached", "(", "$", "content", ",", "$", "target", "[", "'componentId'", "]", ",", "$", "target", "[", "'config'", "]", ")", ";", "$", "ret", "=", "substr", "(", "$", "ret", ",", "0", ",", "$", "target", "[", "'start'", "]", ")", ".", "$", "content", ".", "substr", "(", "$", "ret", ",", "$", "target", "[", "'end'", "]", "+", "1", ")", ";", "if", "(", "$", "statType", ")", "{", "if", "(", "$", "benchmarkEnabled", ")", "Kwf_Benchmark", "::", "count", "(", "\"rendered $statType\"", ",", "$", "target", "[", "'statId'", "]", ")", ";", "Kwf_Benchmark", "::", "countLog", "(", "'render-'", ".", "$", "statType", ")", ";", "}", "if", "(", "$", "benchmarkEnabled", ")", "Kwf_Benchmark", "::", "subCheckpoint", "(", "$", "target", "[", "'componentId'", "]", ".", "' '", ".", "$", "target", "[", "'type'", "]", ",", "microtime", "(", "true", ")", "-", "$", "startTime", ")", ";", "}", "//execute Render Cached Dynamic, used eg for callback link modifier in componentLink", "while", "(", "(", "$", "start", "=", "strpos", "(", "$", "ret", ",", "'<rcd '", ")", ")", "!==", "false", ")", "{", "$", "hasDynamicParts", "=", "true", ";", "$", "startEnd", "=", "strpos", "(", "$", "ret", ",", "'>'", ",", "$", "start", ")", ";", "$", "args", "=", "explode", "(", "' '", ",", "substr", "(", "$", "ret", ",", "$", "start", "+", "5", ",", "$", "startEnd", "-", "$", "start", "-", "5", ")", ")", ";", "$", "end", "=", "strpos", "(", "$", "ret", ",", "'</rcd '", ".", "$", "args", "[", "0", "]", ".", "'>'", ")", ";", "$", "content", "=", "substr", "(", "$", "ret", ",", "$", "startEnd", "+", "1", ",", "$", "end", "-", "$", "startEnd", "-", "1", ")", ";", "if", "(", "$", "benchmarkEnabled", ")", "$", "startTime", "=", "microtime", "(", "true", ")", ";", "$", "componentId", "=", "$", "args", "[", "0", "]", ";", "$", "type", "=", "$", "args", "[", "1", "]", ";", "$", "settings", "=", "json_decode", "(", "$", "args", "[", "2", "]", ",", "true", ")", ";", "$", "content", "=", "$", "this", "->", "_getHelper", "(", "$", "type", ")", "->", "renderCachedDynamic", "(", "$", "content", ",", "$", "componentId", ",", "$", "settings", ")", ";", "if", "(", "$", "benchmarkEnabled", ")", "Kwf_Benchmark", "::", "subCheckpoint", "(", "\"renderCachedDynamic $type $componentId\"", ",", "microtime", "(", "true", ")", "-", "$", "startTime", ")", ";", "$", "ret", "=", "substr", "(", "$", "ret", ",", "0", ",", "$", "start", ")", ".", "$", "content", ".", "substr", "(", "$", "ret", ",", "$", "end", "+", "7", "+", "strlen", "(", "$", "args", "[", "0", "]", ")", ")", ";", "}", "$", "ret", "=", "$", "this", "->", "_findAndExecutePlugins", "(", "$", "ret", ",", "self", "::", "PLUGIN_TYPE_AFTER", ",", "$", "hasDynamicParts", ")", ";", "return", "$", "ret", ";", "}" ]
Render components (ie. expand <kwc ...>) Pass 1 for content that can be stored in fullPage cache, 2 for everything else. 2 includes 1, so calling just with 2 also works @param string render content
[ "Render", "components", "(", "ie", ".", "expand", "<kwc", "...", ">", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Renderer/Abstract.php#L405-L505
koala-framework/koala-framework
Kwf/View/Helper/FormField.php
Kwf_View_Helper_FormField.returnFormField
public function returnFormField($vars) { extract($vars); $ret = ''; if (isset($mask)) $ret .= '{' . $mask . '}'; if (isset($preHtml)) { $ret .= $preHtml; } if (isset($html)) { $ret .= $html; } elseif (isset($items)) { foreach ($items as $i) { $ret .= $this->returnFormField($i); } } elseif (isset($component)) { $view = new Kwf_Component_Renderer(); $ret .= $view->renderComponent($component); } if (isset($postHtml)) { $ret .= $postHtml; } if (isset($mask)) $ret .= '{/' . $mask . '}'; return $ret; }
php
public function returnFormField($vars) { extract($vars); $ret = ''; if (isset($mask)) $ret .= '{' . $mask . '}'; if (isset($preHtml)) { $ret .= $preHtml; } if (isset($html)) { $ret .= $html; } elseif (isset($items)) { foreach ($items as $i) { $ret .= $this->returnFormField($i); } } elseif (isset($component)) { $view = new Kwf_Component_Renderer(); $ret .= $view->renderComponent($component); } if (isset($postHtml)) { $ret .= $postHtml; } if (isset($mask)) $ret .= '{/' . $mask . '}'; return $ret; }
[ "public", "function", "returnFormField", "(", "$", "vars", ")", "{", "extract", "(", "$", "vars", ")", ";", "$", "ret", "=", "''", ";", "if", "(", "isset", "(", "$", "mask", ")", ")", "$", "ret", ".=", "'{'", ".", "$", "mask", ".", "'}'", ";", "if", "(", "isset", "(", "$", "preHtml", ")", ")", "{", "$", "ret", ".=", "$", "preHtml", ";", "}", "if", "(", "isset", "(", "$", "html", ")", ")", "{", "$", "ret", ".=", "$", "html", ";", "}", "elseif", "(", "isset", "(", "$", "items", ")", ")", "{", "foreach", "(", "$", "items", "as", "$", "i", ")", "{", "$", "ret", ".=", "$", "this", "->", "returnFormField", "(", "$", "i", ")", ";", "}", "}", "elseif", "(", "isset", "(", "$", "component", ")", ")", "{", "$", "view", "=", "new", "Kwf_Component_Renderer", "(", ")", ";", "$", "ret", ".=", "$", "view", "->", "renderComponent", "(", "$", "component", ")", ";", "}", "if", "(", "isset", "(", "$", "postHtml", ")", ")", "{", "$", "ret", ".=", "$", "postHtml", ";", "}", "if", "(", "isset", "(", "$", "mask", ")", ")", "$", "ret", ".=", "'{/'", ".", "$", "mask", ".", "'}'", ";", "return", "$", "ret", ";", "}" ]
Diese Methode returned. Die eigentliche (obere) funktion wurde aus rückwärtskompatibilität belassen. Diese Methode wird zB im getTemplateVars der MultiCheckbox verwendet.
[ "Diese", "Methode", "returned", ".", "Die", "eigentliche", "(", "obere", ")", "funktion", "wurde", "aus", "rückwärtskompatibilität", "belassen", ".", "Diese", "Methode", "wird", "zB", "im", "getTemplateVars", "der", "MultiCheckbox", "verwendet", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/View/Helper/FormField.php#L14-L33
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode.set_parameter
public function set_parameter($option, $value = false) { if (!is_array($option)) { $option = array($option => $value); } foreach ($option as $k => $v) { switch ($k) { case 'encoding': switch ($v) { case 'utf8': case 'ucs4_string': case 'ucs4_array': $this->_api_encoding = $v; break; default: $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); return false; } break; case 'overlong': $this->_allow_overlong = ($v) ? true : false; break; case 'strict': $this->_strict_mode = ($v) ? true : false; break; case 'encode_german_sz': $this->_encode_german_sz = ($v) ? true : false; break; default: $this->_error('Set Parameter: Unknown option '.$k); return false; } } return true; }
php
public function set_parameter($option, $value = false) { if (!is_array($option)) { $option = array($option => $value); } foreach ($option as $k => $v) { switch ($k) { case 'encoding': switch ($v) { case 'utf8': case 'ucs4_string': case 'ucs4_array': $this->_api_encoding = $v; break; default: $this->_error('Set Parameter: Unknown parameter '.$v.' for option '.$k); return false; } break; case 'overlong': $this->_allow_overlong = ($v) ? true : false; break; case 'strict': $this->_strict_mode = ($v) ? true : false; break; case 'encode_german_sz': $this->_encode_german_sz = ($v) ? true : false; break; default: $this->_error('Set Parameter: Unknown option '.$k); return false; } } return true; }
[ "public", "function", "set_parameter", "(", "$", "option", ",", "$", "value", "=", "false", ")", "{", "if", "(", "!", "is_array", "(", "$", "option", ")", ")", "{", "$", "option", "=", "array", "(", "$", "option", "=>", "$", "value", ")", ";", "}", "foreach", "(", "$", "option", "as", "$", "k", "=>", "$", "v", ")", "{", "switch", "(", "$", "k", ")", "{", "case", "'encoding'", ":", "switch", "(", "$", "v", ")", "{", "case", "'utf8'", ":", "case", "'ucs4_string'", ":", "case", "'ucs4_array'", ":", "$", "this", "->", "_api_encoding", "=", "$", "v", ";", "break", ";", "default", ":", "$", "this", "->", "_error", "(", "'Set Parameter: Unknown parameter '", ".", "$", "v", ".", "' for option '", ".", "$", "k", ")", ";", "return", "false", ";", "}", "break", ";", "case", "'overlong'", ":", "$", "this", "->", "_allow_overlong", "=", "(", "$", "v", ")", "?", "true", ":", "false", ";", "break", ";", "case", "'strict'", ":", "$", "this", "->", "_strict_mode", "=", "(", "$", "v", ")", "?", "true", ":", "false", ";", "break", ";", "case", "'encode_german_sz'", ":", "$", "this", "->", "_encode_german_sz", "=", "(", "$", "v", ")", "?", "true", ":", "false", ";", "break", ";", "default", ":", "$", "this", "->", "_error", "(", "'Set Parameter: Unknown option '", ".", "$", "k", ")", ";", "return", "false", ";", "}", "}", "return", "true", ";", "}" ]
Sets a new option value. Available options and values: [encoding - Use either UTF-8, UCS4 as array or UCS4 as string as input ('utf8' for UTF-8, 'ucs4_string' and 'ucs4_array' respectively for UCS4); The output is always UTF-8] [overlong - Unicode does not allow unnecessarily long encodings of chars, to allow this, set this parameter to true, else to false; default is false.] [strict - true: strict mode, good for registration purposes - Causes errors on failures; false: loose mode, ideal for "wildlife" applications by silently ignoring errors and returning the original input instead @param mixed Parameter to set (string: single parameter; array of Parameter => Value pairs) @param string Value to use (if parameter 1 is a string) @return boolean true on success, false otherwise
[ "Sets", "a", "new", "option", "value", ".", "Available", "options", "and", "values", ":", "[", "encoding", "-", "Use", "either", "UTF", "-", "8", "UCS4", "as", "array", "or", "UCS4", "as", "string", "as", "input", "(", "utf8", "for", "UTF", "-", "8", "ucs4_string", "and", "ucs4_array", "respectively", "for", "UCS4", ")", ";", "The", "output", "is", "always", "UTF", "-", "8", "]", "[", "overlong", "-", "Unicode", "does", "not", "allow", "unnecessarily", "long", "encodings", "of", "chars", "to", "allow", "this", "set", "this", "parameter", "to", "true", "else", "to", "false", ";", "default", "is", "false", ".", "]", "[", "strict", "-", "true", ":", "strict", "mode", "good", "for", "registration", "purposes", "-", "Causes", "errors", "on", "failures", ";", "false", ":", "loose", "mode", "ideal", "for", "wildlife", "applications", "by", "silently", "ignoring", "errors", "and", "returning", "the", "original", "input", "instead" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L124-L158
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode._decode
protected function _decode($encoded) { $decoded = array(); // find the Punycode prefix if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) { $this->_error('This is not a punycode string'); return false; } $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded); // If nothing left after removing the prefix, it is hopeless if (!$encode_test) { $this->_error('The given encoded string was empty'); return false; } // Find last occurence of the delimiter $delim_pos = strrpos($encoded, '-'); if ($delim_pos > strlen($this->_punycode_prefix)) { for ($k = strlen($this->_punycode_prefix); $k < $delim_pos; ++$k) { $decoded[] = ord($encoded{$k}); } } $deco_len = count($decoded); $enco_len = strlen($encoded); // Wandering through the strings; init $is_first = true; $bias = $this->_initial_bias; $idx = 0; $char = $this->_initial_n; for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) { for ($old_idx = $idx, $w = 1, $k = $this->_base; 1 ; $k += $this->_base) { $digit = $this->_decode_digit($encoded{$enco_idx++}); $idx += $digit * $w; $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); if ($digit < $t) break; $w = (int) ($w * ($this->_base - $t)); } $bias = $this->_adapt($idx - $old_idx, $deco_len + 1, $is_first); $is_first = false; $char += (int) ($idx / ($deco_len + 1)); $idx %= ($deco_len + 1); if ($deco_len > 0) { // Make room for the decoded char for ($i = $deco_len; $i > $idx; $i--) $decoded[$i] = $decoded[($i - 1)]; } $decoded[$idx++] = $char; } return $this->_ucs4_to_utf8($decoded); }
php
protected function _decode($encoded) { $decoded = array(); // find the Punycode prefix if (!preg_match('!^'.preg_quote($this->_punycode_prefix, '!').'!', $encoded)) { $this->_error('This is not a punycode string'); return false; } $encode_test = preg_replace('!^'.preg_quote($this->_punycode_prefix, '!').'!', '', $encoded); // If nothing left after removing the prefix, it is hopeless if (!$encode_test) { $this->_error('The given encoded string was empty'); return false; } // Find last occurence of the delimiter $delim_pos = strrpos($encoded, '-'); if ($delim_pos > strlen($this->_punycode_prefix)) { for ($k = strlen($this->_punycode_prefix); $k < $delim_pos; ++$k) { $decoded[] = ord($encoded{$k}); } } $deco_len = count($decoded); $enco_len = strlen($encoded); // Wandering through the strings; init $is_first = true; $bias = $this->_initial_bias; $idx = 0; $char = $this->_initial_n; for ($enco_idx = ($delim_pos) ? ($delim_pos + 1) : 0; $enco_idx < $enco_len; ++$deco_len) { for ($old_idx = $idx, $w = 1, $k = $this->_base; 1 ; $k += $this->_base) { $digit = $this->_decode_digit($encoded{$enco_idx++}); $idx += $digit * $w; $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : ($k - $bias)); if ($digit < $t) break; $w = (int) ($w * ($this->_base - $t)); } $bias = $this->_adapt($idx - $old_idx, $deco_len + 1, $is_first); $is_first = false; $char += (int) ($idx / ($deco_len + 1)); $idx %= ($deco_len + 1); if ($deco_len > 0) { // Make room for the decoded char for ($i = $deco_len; $i > $idx; $i--) $decoded[$i] = $decoded[($i - 1)]; } $decoded[$idx++] = $char; } return $this->_ucs4_to_utf8($decoded); }
[ "protected", "function", "_decode", "(", "$", "encoded", ")", "{", "$", "decoded", "=", "array", "(", ")", ";", "// find the Punycode prefix", "if", "(", "!", "preg_match", "(", "'!^'", ".", "preg_quote", "(", "$", "this", "->", "_punycode_prefix", ",", "'!'", ")", ".", "'!'", ",", "$", "encoded", ")", ")", "{", "$", "this", "->", "_error", "(", "'This is not a punycode string'", ")", ";", "return", "false", ";", "}", "$", "encode_test", "=", "preg_replace", "(", "'!^'", ".", "preg_quote", "(", "$", "this", "->", "_punycode_prefix", ",", "'!'", ")", ".", "'!'", ",", "''", ",", "$", "encoded", ")", ";", "// If nothing left after removing the prefix, it is hopeless", "if", "(", "!", "$", "encode_test", ")", "{", "$", "this", "->", "_error", "(", "'The given encoded string was empty'", ")", ";", "return", "false", ";", "}", "// Find last occurence of the delimiter", "$", "delim_pos", "=", "strrpos", "(", "$", "encoded", ",", "'-'", ")", ";", "if", "(", "$", "delim_pos", ">", "strlen", "(", "$", "this", "->", "_punycode_prefix", ")", ")", "{", "for", "(", "$", "k", "=", "strlen", "(", "$", "this", "->", "_punycode_prefix", ")", ";", "$", "k", "<", "$", "delim_pos", ";", "++", "$", "k", ")", "{", "$", "decoded", "[", "]", "=", "ord", "(", "$", "encoded", "{", "$", "k", "}", ")", ";", "}", "}", "$", "deco_len", "=", "count", "(", "$", "decoded", ")", ";", "$", "enco_len", "=", "strlen", "(", "$", "encoded", ")", ";", "// Wandering through the strings; init", "$", "is_first", "=", "true", ";", "$", "bias", "=", "$", "this", "->", "_initial_bias", ";", "$", "idx", "=", "0", ";", "$", "char", "=", "$", "this", "->", "_initial_n", ";", "for", "(", "$", "enco_idx", "=", "(", "$", "delim_pos", ")", "?", "(", "$", "delim_pos", "+", "1", ")", ":", "0", ";", "$", "enco_idx", "<", "$", "enco_len", ";", "++", "$", "deco_len", ")", "{", "for", "(", "$", "old_idx", "=", "$", "idx", ",", "$", "w", "=", "1", ",", "$", "k", "=", "$", "this", "->", "_base", ";", "1", ";", "$", "k", "+=", "$", "this", "->", "_base", ")", "{", "$", "digit", "=", "$", "this", "->", "_decode_digit", "(", "$", "encoded", "{", "$", "enco_idx", "++", "}", ")", ";", "$", "idx", "+=", "$", "digit", "*", "$", "w", ";", "$", "t", "=", "(", "$", "k", "<=", "$", "bias", ")", "?", "$", "this", "->", "_tmin", ":", "(", "(", "$", "k", ">=", "$", "bias", "+", "$", "this", "->", "_tmax", ")", "?", "$", "this", "->", "_tmax", ":", "(", "$", "k", "-", "$", "bias", ")", ")", ";", "if", "(", "$", "digit", "<", "$", "t", ")", "break", ";", "$", "w", "=", "(", "int", ")", "(", "$", "w", "*", "(", "$", "this", "->", "_base", "-", "$", "t", ")", ")", ";", "}", "$", "bias", "=", "$", "this", "->", "_adapt", "(", "$", "idx", "-", "$", "old_idx", ",", "$", "deco_len", "+", "1", ",", "$", "is_first", ")", ";", "$", "is_first", "=", "false", ";", "$", "char", "+=", "(", "int", ")", "(", "$", "idx", "/", "(", "$", "deco_len", "+", "1", ")", ")", ";", "$", "idx", "%=", "(", "$", "deco_len", "+", "1", ")", ";", "if", "(", "$", "deco_len", ">", "0", ")", "{", "// Make room for the decoded char", "for", "(", "$", "i", "=", "$", "deco_len", ";", "$", "i", ">", "$", "idx", ";", "$", "i", "--", ")", "$", "decoded", "[", "$", "i", "]", "=", "$", "decoded", "[", "(", "$", "i", "-", "1", ")", "]", ";", "}", "$", "decoded", "[", "$", "idx", "++", "]", "=", "$", "char", ";", "}", "return", "$", "this", "->", "_ucs4_to_utf8", "(", "$", "decoded", ")", ";", "}" ]
The actual decoding algorithm @param string @return mixed
[ "The", "actual", "decoding", "algorithm" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L391-L441
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode._encode
protected function _encode($decoded) { // We cannot encode a domain name containing the Punycode prefix $extract = strlen($this->_punycode_prefix); $check_pref = $this->_utf8_to_ucs4($this->_punycode_prefix); $check_deco = array_slice($decoded, 0, $extract); if ($check_pref == $check_deco) { $this->_error('This is already a punycode string'); return false; } // We will not try to encode strings consisting of basic code points only $encodable = false; foreach ($decoded as $k => $v) { if ($v > 0x7a) { $encodable = true; break; } } if (!$encodable) { $this->_error('The given string does not contain encodable chars'); return false; } // Do NAMEPREP $decoded = $this->_nameprep($decoded); if (!$decoded || !is_array($decoded)) return false; // NAMEPREP failed $deco_len = count($decoded); if (!$deco_len) return false; // Empty array $codecount = 0; // How many chars have been consumed $encoded = ''; // Copy all basic code points to output for ($i = 0; $i < $deco_len; ++$i) { $test = $decoded[$i]; // Will match [-0-9a-zA-Z] if ((0x2F < $test && $test < 0x40) || (0x40 < $test && $test < 0x5B) || (0x60 < $test && $test <= 0x7B) || (0x2D == $test)) { $encoded .= chr($decoded[$i]); $codecount++; } } if ($codecount == $deco_len) return $encoded; // All codepoints were basic ones // Start with the prefix; copy it to output $encoded = $this->_punycode_prefix.$encoded; // If we have basic code points in output, add an hyphen to the end if ($codecount) $encoded .= '-'; // Now find and encode all non-basic code points $is_first = true; $cur_code = $this->_initial_n; $bias = $this->_initial_bias; $delta = 0; while ($codecount < $deco_len) { // Find the smallest code point >= the current code point and // remember the last ouccrence of it in the input for ($i = 0, $next_code = $this->_max_ucs; $i < $deco_len; $i++) { if ($decoded[$i] >= $cur_code && $decoded[$i] <= $next_code) { $next_code = $decoded[$i]; } } $delta += ($next_code - $cur_code) * ($codecount + 1); $cur_code = $next_code; // Scan input again and encode all characters whose code point is $cur_code for ($i = 0; $i < $deco_len; $i++) { if ($decoded[$i] < $cur_code) { $delta++; } elseif ($decoded[$i] == $cur_code) { for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) { $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); if ($q < $t) break; $encoded .= $this->_encode_digit(intval($t + (($q - $t) % ($this->_base - $t)))); //v0.4.5 Changed from ceil() to intval() $q = (int) (($q - $t) / ($this->_base - $t)); } $encoded .= $this->_encode_digit($q); $bias = $this->_adapt($delta, $codecount+1, $is_first); $codecount++; $delta = 0; $is_first = false; } } $delta++; $cur_code++; } return $encoded; }
php
protected function _encode($decoded) { // We cannot encode a domain name containing the Punycode prefix $extract = strlen($this->_punycode_prefix); $check_pref = $this->_utf8_to_ucs4($this->_punycode_prefix); $check_deco = array_slice($decoded, 0, $extract); if ($check_pref == $check_deco) { $this->_error('This is already a punycode string'); return false; } // We will not try to encode strings consisting of basic code points only $encodable = false; foreach ($decoded as $k => $v) { if ($v > 0x7a) { $encodable = true; break; } } if (!$encodable) { $this->_error('The given string does not contain encodable chars'); return false; } // Do NAMEPREP $decoded = $this->_nameprep($decoded); if (!$decoded || !is_array($decoded)) return false; // NAMEPREP failed $deco_len = count($decoded); if (!$deco_len) return false; // Empty array $codecount = 0; // How many chars have been consumed $encoded = ''; // Copy all basic code points to output for ($i = 0; $i < $deco_len; ++$i) { $test = $decoded[$i]; // Will match [-0-9a-zA-Z] if ((0x2F < $test && $test < 0x40) || (0x40 < $test && $test < 0x5B) || (0x60 < $test && $test <= 0x7B) || (0x2D == $test)) { $encoded .= chr($decoded[$i]); $codecount++; } } if ($codecount == $deco_len) return $encoded; // All codepoints were basic ones // Start with the prefix; copy it to output $encoded = $this->_punycode_prefix.$encoded; // If we have basic code points in output, add an hyphen to the end if ($codecount) $encoded .= '-'; // Now find and encode all non-basic code points $is_first = true; $cur_code = $this->_initial_n; $bias = $this->_initial_bias; $delta = 0; while ($codecount < $deco_len) { // Find the smallest code point >= the current code point and // remember the last ouccrence of it in the input for ($i = 0, $next_code = $this->_max_ucs; $i < $deco_len; $i++) { if ($decoded[$i] >= $cur_code && $decoded[$i] <= $next_code) { $next_code = $decoded[$i]; } } $delta += ($next_code - $cur_code) * ($codecount + 1); $cur_code = $next_code; // Scan input again and encode all characters whose code point is $cur_code for ($i = 0; $i < $deco_len; $i++) { if ($decoded[$i] < $cur_code) { $delta++; } elseif ($decoded[$i] == $cur_code) { for ($q = $delta, $k = $this->_base; 1; $k += $this->_base) { $t = ($k <= $bias) ? $this->_tmin : (($k >= $bias + $this->_tmax) ? $this->_tmax : $k - $bias); if ($q < $t) break; $encoded .= $this->_encode_digit(intval($t + (($q - $t) % ($this->_base - $t)))); //v0.4.5 Changed from ceil() to intval() $q = (int) (($q - $t) / ($this->_base - $t)); } $encoded .= $this->_encode_digit($q); $bias = $this->_adapt($delta, $codecount+1, $is_first); $codecount++; $delta = 0; $is_first = false; } } $delta++; $cur_code++; } return $encoded; }
[ "protected", "function", "_encode", "(", "$", "decoded", ")", "{", "// We cannot encode a domain name containing the Punycode prefix", "$", "extract", "=", "strlen", "(", "$", "this", "->", "_punycode_prefix", ")", ";", "$", "check_pref", "=", "$", "this", "->", "_utf8_to_ucs4", "(", "$", "this", "->", "_punycode_prefix", ")", ";", "$", "check_deco", "=", "array_slice", "(", "$", "decoded", ",", "0", ",", "$", "extract", ")", ";", "if", "(", "$", "check_pref", "==", "$", "check_deco", ")", "{", "$", "this", "->", "_error", "(", "'This is already a punycode string'", ")", ";", "return", "false", ";", "}", "// We will not try to encode strings consisting of basic code points only", "$", "encodable", "=", "false", ";", "foreach", "(", "$", "decoded", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", ">", "0x7a", ")", "{", "$", "encodable", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "encodable", ")", "{", "$", "this", "->", "_error", "(", "'The given string does not contain encodable chars'", ")", ";", "return", "false", ";", "}", "// Do NAMEPREP", "$", "decoded", "=", "$", "this", "->", "_nameprep", "(", "$", "decoded", ")", ";", "if", "(", "!", "$", "decoded", "||", "!", "is_array", "(", "$", "decoded", ")", ")", "return", "false", ";", "// NAMEPREP failed", "$", "deco_len", "=", "count", "(", "$", "decoded", ")", ";", "if", "(", "!", "$", "deco_len", ")", "return", "false", ";", "// Empty array", "$", "codecount", "=", "0", ";", "// How many chars have been consumed", "$", "encoded", "=", "''", ";", "// Copy all basic code points to output", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "deco_len", ";", "++", "$", "i", ")", "{", "$", "test", "=", "$", "decoded", "[", "$", "i", "]", ";", "// Will match [-0-9a-zA-Z]", "if", "(", "(", "0x2F", "<", "$", "test", "&&", "$", "test", "<", "0x40", ")", "||", "(", "0x40", "<", "$", "test", "&&", "$", "test", "<", "0x5B", ")", "||", "(", "0x60", "<", "$", "test", "&&", "$", "test", "<=", "0x7B", ")", "||", "(", "0x2D", "==", "$", "test", ")", ")", "{", "$", "encoded", ".=", "chr", "(", "$", "decoded", "[", "$", "i", "]", ")", ";", "$", "codecount", "++", ";", "}", "}", "if", "(", "$", "codecount", "==", "$", "deco_len", ")", "return", "$", "encoded", ";", "// All codepoints were basic ones", "// Start with the prefix; copy it to output", "$", "encoded", "=", "$", "this", "->", "_punycode_prefix", ".", "$", "encoded", ";", "// If we have basic code points in output, add an hyphen to the end", "if", "(", "$", "codecount", ")", "$", "encoded", ".=", "'-'", ";", "// Now find and encode all non-basic code points", "$", "is_first", "=", "true", ";", "$", "cur_code", "=", "$", "this", "->", "_initial_n", ";", "$", "bias", "=", "$", "this", "->", "_initial_bias", ";", "$", "delta", "=", "0", ";", "while", "(", "$", "codecount", "<", "$", "deco_len", ")", "{", "// Find the smallest code point >= the current code point and", "// remember the last ouccrence of it in the input", "for", "(", "$", "i", "=", "0", ",", "$", "next_code", "=", "$", "this", "->", "_max_ucs", ";", "$", "i", "<", "$", "deco_len", ";", "$", "i", "++", ")", "{", "if", "(", "$", "decoded", "[", "$", "i", "]", ">=", "$", "cur_code", "&&", "$", "decoded", "[", "$", "i", "]", "<=", "$", "next_code", ")", "{", "$", "next_code", "=", "$", "decoded", "[", "$", "i", "]", ";", "}", "}", "$", "delta", "+=", "(", "$", "next_code", "-", "$", "cur_code", ")", "*", "(", "$", "codecount", "+", "1", ")", ";", "$", "cur_code", "=", "$", "next_code", ";", "// Scan input again and encode all characters whose code point is $cur_code", "for", "(", "$", "i", "=", "0", ";", "$", "i", "<", "$", "deco_len", ";", "$", "i", "++", ")", "{", "if", "(", "$", "decoded", "[", "$", "i", "]", "<", "$", "cur_code", ")", "{", "$", "delta", "++", ";", "}", "elseif", "(", "$", "decoded", "[", "$", "i", "]", "==", "$", "cur_code", ")", "{", "for", "(", "$", "q", "=", "$", "delta", ",", "$", "k", "=", "$", "this", "->", "_base", ";", "1", ";", "$", "k", "+=", "$", "this", "->", "_base", ")", "{", "$", "t", "=", "(", "$", "k", "<=", "$", "bias", ")", "?", "$", "this", "->", "_tmin", ":", "(", "(", "$", "k", ">=", "$", "bias", "+", "$", "this", "->", "_tmax", ")", "?", "$", "this", "->", "_tmax", ":", "$", "k", "-", "$", "bias", ")", ";", "if", "(", "$", "q", "<", "$", "t", ")", "break", ";", "$", "encoded", ".=", "$", "this", "->", "_encode_digit", "(", "intval", "(", "$", "t", "+", "(", "(", "$", "q", "-", "$", "t", ")", "%", "(", "$", "this", "->", "_base", "-", "$", "t", ")", ")", ")", ")", ";", "//v0.4.5 Changed from ceil() to intval()", "$", "q", "=", "(", "int", ")", "(", "(", "$", "q", "-", "$", "t", ")", "/", "(", "$", "this", "->", "_base", "-", "$", "t", ")", ")", ";", "}", "$", "encoded", ".=", "$", "this", "->", "_encode_digit", "(", "$", "q", ")", ";", "$", "bias", "=", "$", "this", "->", "_adapt", "(", "$", "delta", ",", "$", "codecount", "+", "1", ",", "$", "is_first", ")", ";", "$", "codecount", "++", ";", "$", "delta", "=", "0", ";", "$", "is_first", "=", "false", ";", "}", "}", "$", "delta", "++", ";", "$", "cur_code", "++", ";", "}", "return", "$", "encoded", ";", "}" ]
The actual encoding algorithm @param string @return mixed
[ "The", "actual", "encoding", "algorithm" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L448-L533
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode._adapt
protected function _adapt($delta, $npoints, $is_first) { $delta = intval($is_first ? ($delta / $this->_damp) : ($delta / 2)); $delta += intval($delta / $npoints); for ($k = 0; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2; $k += $this->_base) { $delta = intval($delta / ($this->_base - $this->_tmin)); } return intval($k + ($this->_base - $this->_tmin + 1) * $delta / ($delta + $this->_skew)); }
php
protected function _adapt($delta, $npoints, $is_first) { $delta = intval($is_first ? ($delta / $this->_damp) : ($delta / 2)); $delta += intval($delta / $npoints); for ($k = 0; $delta > (($this->_base - $this->_tmin) * $this->_tmax) / 2; $k += $this->_base) { $delta = intval($delta / ($this->_base - $this->_tmin)); } return intval($k + ($this->_base - $this->_tmin + 1) * $delta / ($delta + $this->_skew)); }
[ "protected", "function", "_adapt", "(", "$", "delta", ",", "$", "npoints", ",", "$", "is_first", ")", "{", "$", "delta", "=", "intval", "(", "$", "is_first", "?", "(", "$", "delta", "/", "$", "this", "->", "_damp", ")", ":", "(", "$", "delta", "/", "2", ")", ")", ";", "$", "delta", "+=", "intval", "(", "$", "delta", "/", "$", "npoints", ")", ";", "for", "(", "$", "k", "=", "0", ";", "$", "delta", ">", "(", "(", "$", "this", "->", "_base", "-", "$", "this", "->", "_tmin", ")", "*", "$", "this", "->", "_tmax", ")", "/", "2", ";", "$", "k", "+=", "$", "this", "->", "_base", ")", "{", "$", "delta", "=", "intval", "(", "$", "delta", "/", "(", "$", "this", "->", "_base", "-", "$", "this", "->", "_tmin", ")", ")", ";", "}", "return", "intval", "(", "$", "k", "+", "(", "$", "this", "->", "_base", "-", "$", "this", "->", "_tmin", "+", "1", ")", "*", "$", "delta", "/", "(", "$", "delta", "+", "$", "this", "->", "_skew", ")", ")", ";", "}" ]
Adapt the bias according to the current code point and position @param int $delta @param int $npoints @param int $is_first @return int
[ "Adapt", "the", "bias", "according", "to", "the", "current", "code", "point", "and", "position" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L542-L550
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode._decode_digit
protected function _decode_digit($cp) { $cp = ord($cp); return ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $this->_base)); }
php
protected function _decode_digit($cp) { $cp = ord($cp); return ($cp - 48 < 10) ? $cp - 22 : (($cp - 65 < 26) ? $cp - 65 : (($cp - 97 < 26) ? $cp - 97 : $this->_base)); }
[ "protected", "function", "_decode_digit", "(", "$", "cp", ")", "{", "$", "cp", "=", "ord", "(", "$", "cp", ")", ";", "return", "(", "$", "cp", "-", "48", "<", "10", ")", "?", "$", "cp", "-", "22", ":", "(", "(", "$", "cp", "-", "65", "<", "26", ")", "?", "$", "cp", "-", "65", ":", "(", "(", "$", "cp", "-", "97", "<", "26", ")", "?", "$", "cp", "-", "97", ":", "$", "this", "->", "_base", ")", ")", ";", "}" ]
Decode a certain digit @param int $cp @return int
[ "Decode", "a", "certain", "digit" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L567-L571
koala-framework/koala-framework
Kwf/Util/Punycode.php
Kwf_Util_Punycode._ucs4_to_utf8
protected function _ucs4_to_utf8($input) { $output = ''; foreach ($input as $k => $v) { if ($v < 128) { // 7bit are transferred literally $output .= chr($v); } elseif ($v < (1 << 11)) { // 2 bytes $output .= chr(192+($v >> 6)).chr(128+($v & 63)); } elseif ($v < (1 << 16)) { // 3 bytes $output .= chr(224+($v >> 12)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63)); } elseif ($v < (1 << 21)) { // 4 bytes $output .= chr(240+($v >> 18)).chr(128+(($v >> 12) & 63)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63)); } elseif (self::$safe_mode) { $output .= self::$safe_char; } else { $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k); return false; } } return $output; }
php
protected function _ucs4_to_utf8($input) { $output = ''; foreach ($input as $k => $v) { if ($v < 128) { // 7bit are transferred literally $output .= chr($v); } elseif ($v < (1 << 11)) { // 2 bytes $output .= chr(192+($v >> 6)).chr(128+($v & 63)); } elseif ($v < (1 << 16)) { // 3 bytes $output .= chr(224+($v >> 12)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63)); } elseif ($v < (1 << 21)) { // 4 bytes $output .= chr(240+($v >> 18)).chr(128+(($v >> 12) & 63)).chr(128+(($v >> 6) & 63)).chr(128+($v & 63)); } elseif (self::$safe_mode) { $output .= self::$safe_char; } else { $this->_error('Conversion from UCS-4 to UTF-8 failed: malformed input at byte '.$k); return false; } } return $output; }
[ "protected", "function", "_ucs4_to_utf8", "(", "$", "input", ")", "{", "$", "output", "=", "''", ";", "foreach", "(", "$", "input", "as", "$", "k", "=>", "$", "v", ")", "{", "if", "(", "$", "v", "<", "128", ")", "{", "// 7bit are transferred literally", "$", "output", ".=", "chr", "(", "$", "v", ")", ";", "}", "elseif", "(", "$", "v", "<", "(", "1", "<<", "11", ")", ")", "{", "// 2 bytes", "$", "output", ".=", "chr", "(", "192", "+", "(", "$", "v", ">>", "6", ")", ")", ".", "chr", "(", "128", "+", "(", "$", "v", "&", "63", ")", ")", ";", "}", "elseif", "(", "$", "v", "<", "(", "1", "<<", "16", ")", ")", "{", "// 3 bytes", "$", "output", ".=", "chr", "(", "224", "+", "(", "$", "v", ">>", "12", ")", ")", ".", "chr", "(", "128", "+", "(", "(", "$", "v", ">>", "6", ")", "&", "63", ")", ")", ".", "chr", "(", "128", "+", "(", "$", "v", "&", "63", ")", ")", ";", "}", "elseif", "(", "$", "v", "<", "(", "1", "<<", "21", ")", ")", "{", "// 4 bytes", "$", "output", ".=", "chr", "(", "240", "+", "(", "$", "v", ">>", "18", ")", ")", ".", "chr", "(", "128", "+", "(", "(", "$", "v", ">>", "12", ")", "&", "63", ")", ")", ".", "chr", "(", "128", "+", "(", "(", "$", "v", ">>", "6", ")", "&", "63", ")", ")", ".", "chr", "(", "128", "+", "(", "$", "v", "&", "63", ")", ")", ";", "}", "elseif", "(", "self", "::", "$", "safe_mode", ")", "{", "$", "output", ".=", "self", "::", "$", "safe_char", ";", "}", "else", "{", "$", "this", "->", "_error", "(", "'Conversion from UCS-4 to UTF-8 failed: malformed input at byte '", ".", "$", "k", ")", ";", "return", "false", ";", "}", "}", "return", "$", "output", ";", "}" ]
Convert UCS-4 string into UTF-8 string See _utf8_to_ucs4() for details @param string $input @return string
[ "Convert", "UCS", "-", "4", "string", "into", "UTF", "-", "8", "string", "See", "_utf8_to_ucs4", "()", "for", "details" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Punycode.php#L884-L904
koala-framework/koala-framework
Kwf/Component/Cache/Memory.php
Kwf_Component_Cache_Memory._getFileNameForCacheId
private static function _getFileNameForCacheId($cacheId) { $cacheId = preg_replace('#[^a-zA-Z0-9_-]#', '_', $cacheId); if (strlen($cacheId) > 50) { $cacheId = substr($cacheId, 0, 50).md5($cacheId); } return "cache/view/".self::CACHE_VERSION.'-'.$cacheId; }
php
private static function _getFileNameForCacheId($cacheId) { $cacheId = preg_replace('#[^a-zA-Z0-9_-]#', '_', $cacheId); if (strlen($cacheId) > 50) { $cacheId = substr($cacheId, 0, 50).md5($cacheId); } return "cache/view/".self::CACHE_VERSION.'-'.$cacheId; }
[ "private", "static", "function", "_getFileNameForCacheId", "(", "$", "cacheId", ")", "{", "$", "cacheId", "=", "preg_replace", "(", "'#[^a-zA-Z0-9_-]#'", ",", "'_'", ",", "$", "cacheId", ")", ";", "if", "(", "strlen", "(", "$", "cacheId", ")", ">", "50", ")", "{", "$", "cacheId", "=", "substr", "(", "$", "cacheId", ",", "0", ",", "50", ")", ".", "md5", "(", "$", "cacheId", ")", ";", "}", "return", "\"cache/view/\"", ".", "self", "::", "CACHE_VERSION", ".", "'-'", ".", "$", "cacheId", ";", "}" ]
for 'file' backend
[ "for", "file", "backend" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Cache/Memory.php#L36-L43
koala-framework/koala-framework
Kwf/Component/Cache/Memory.php
Kwf_Component_Cache_Memory._clean
public function _clean() { $be = Kwf_Cache_Simple::getBackend(); if ($be == 'memcache') { return Kwf_Cache_Simple::getMemcache()->flush(); } else if ($be == 'file') { foreach (glob('cache/view/*') as $i) { unlink($i); } return true; } else { return self::getZendCache()->clean(); } }
php
public function _clean() { $be = Kwf_Cache_Simple::getBackend(); if ($be == 'memcache') { return Kwf_Cache_Simple::getMemcache()->flush(); } else if ($be == 'file') { foreach (glob('cache/view/*') as $i) { unlink($i); } return true; } else { return self::getZendCache()->clean(); } }
[ "public", "function", "_clean", "(", ")", "{", "$", "be", "=", "Kwf_Cache_Simple", "::", "getBackend", "(", ")", ";", "if", "(", "$", "be", "==", "'memcache'", ")", "{", "return", "Kwf_Cache_Simple", "::", "getMemcache", "(", ")", "->", "flush", "(", ")", ";", "}", "else", "if", "(", "$", "be", "==", "'file'", ")", "{", "foreach", "(", "glob", "(", "'cache/view/*'", ")", "as", "$", "i", ")", "{", "unlink", "(", "$", "i", ")", ";", "}", "return", "true", ";", "}", "else", "{", "return", "self", "::", "getZendCache", "(", ")", "->", "clean", "(", ")", ";", "}", "}" ]
Internal function only ment to be used by unit tests @internal
[ "Internal", "function", "only", "ment", "to", "be", "used", "by", "unit", "tests" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Cache/Memory.php#L125-L138
koala-framework/koala-framework
Kwc/Shop/Cart/Checkout/Payment/Wirecard/LogModel.php
Kwc_Shop_Cart_Checkout_Payment_Wirecard_LogModel.getEncodedCallback
public static function getEncodedCallback($ipnCallback, $data = array()) { $ret = 'kwf:'; $data = array( 'data' => $data, 'cb' => $ipnCallback ); $data = serialize($data); $ret .= substr(Kwf_Util_Hash::hash($data), 0, 10); $data = base64_encode($data); $ret .= $data; if (strlen($ret) > 256) { throw new Kwf_Exception("Wirecard custom field does not support more than 256 characters"); } return $ret; }
php
public static function getEncodedCallback($ipnCallback, $data = array()) { $ret = 'kwf:'; $data = array( 'data' => $data, 'cb' => $ipnCallback ); $data = serialize($data); $ret .= substr(Kwf_Util_Hash::hash($data), 0, 10); $data = base64_encode($data); $ret .= $data; if (strlen($ret) > 256) { throw new Kwf_Exception("Wirecard custom field does not support more than 256 characters"); } return $ret; }
[ "public", "static", "function", "getEncodedCallback", "(", "$", "ipnCallback", ",", "$", "data", "=", "array", "(", ")", ")", "{", "$", "ret", "=", "'kwf:'", ";", "$", "data", "=", "array", "(", "'data'", "=>", "$", "data", ",", "'cb'", "=>", "$", "ipnCallback", ")", ";", "$", "data", "=", "serialize", "(", "$", "data", ")", ";", "$", "ret", ".=", "substr", "(", "Kwf_Util_Hash", "::", "hash", "(", "$", "data", ")", ",", "0", ",", "10", ")", ";", "$", "data", "=", "base64_encode", "(", "$", "data", ")", ";", "$", "ret", ".=", "$", "data", ";", "if", "(", "strlen", "(", "$", "ret", ")", ">", "256", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"Wirecard custom field does not support more than 256 characters\"", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Muss in "custom" von der bezahlung gespeichert werden
[ "Muss", "in", "custom", "von", "der", "bezahlung", "gespeichert", "werden" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Checkout/Payment/Wirecard/LogModel.php#L18-L33
koala-framework/koala-framework
Kwf/Component/Layout/Abstract.php
Kwf_Component_Layout_Abstract.getChildContentWidth
public function getChildContentWidth(Kwf_Component_Data $data, Kwf_Component_Data $child) { $ret = $this->getContentWidth($data); if ($this->_hasSetting('contentWidthSubtract')) { $ret -= $this->_getSetting('contentWidthSubtract'); } return $ret; }
php
public function getChildContentWidth(Kwf_Component_Data $data, Kwf_Component_Data $child) { $ret = $this->getContentWidth($data); if ($this->_hasSetting('contentWidthSubtract')) { $ret -= $this->_getSetting('contentWidthSubtract'); } return $ret; }
[ "public", "function", "getChildContentWidth", "(", "Kwf_Component_Data", "$", "data", ",", "Kwf_Component_Data", "$", "child", ")", "{", "$", "ret", "=", "$", "this", "->", "getContentWidth", "(", "$", "data", ")", ";", "if", "(", "$", "this", "->", "_hasSetting", "(", "'contentWidthSubtract'", ")", ")", "{", "$", "ret", "-=", "$", "this", "->", "_getSetting", "(", "'contentWidthSubtract'", ")", ";", "}", "return", "$", "ret", ";", "}" ]
Returns the contentWidth of a given child Can be overridden to adapt the available child width Use 'contentWidthSubtract' setting to subtract a fixed amount from getContentWidth() value @return int
[ "Returns", "the", "contentWidth", "of", "a", "given", "child" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Layout/Abstract.php#L152-L159
koala-framework/koala-framework
Kwf/Assets/Package.php
Kwf_Assets_Package.getBuildContents
public function getBuildContents($mimeType, $language) { if ($mimeType == 'text/javascript') $ext = 'js'; else if ($mimeType == 'text/javascript; defer') $ext = 'defer.js'; else if ($mimeType == 'text/css') $ext = 'css'; $cacheId = Kwf_Assets_Dispatcher::getInstance()->getCacheIdByPackage($this, $ext, $language); $ret = Kwf_Assets_BuildCache::getInstance()->load($cacheId); if ($ret === false || $ret === 'outdated') { if ($ret === 'outdated' && Kwf_Config::getValue('assets.lazyBuild') == 'outdated') { Kwf_Assets_BuildCache::getInstance()->building = true; } else if (Kwf_Config::getValue('assets.lazyBuild') !== true) { if (Kwf_Exception_Abstract::isDebug()) { //proper error message on development server throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please include package in build."); } else { throw new Kwf_Exception_NotFound(); } } $ret = $this->getPackageContents($mimeType, $language)->getFileContents(); Kwf_Assets_BuildCache::getInstance()->building = false; } else { $ret = $ret['contents']; } return $ret; }
php
public function getBuildContents($mimeType, $language) { if ($mimeType == 'text/javascript') $ext = 'js'; else if ($mimeType == 'text/javascript; defer') $ext = 'defer.js'; else if ($mimeType == 'text/css') $ext = 'css'; $cacheId = Kwf_Assets_Dispatcher::getInstance()->getCacheIdByPackage($this, $ext, $language); $ret = Kwf_Assets_BuildCache::getInstance()->load($cacheId); if ($ret === false || $ret === 'outdated') { if ($ret === 'outdated' && Kwf_Config::getValue('assets.lazyBuild') == 'outdated') { Kwf_Assets_BuildCache::getInstance()->building = true; } else if (Kwf_Config::getValue('assets.lazyBuild') !== true) { if (Kwf_Exception_Abstract::isDebug()) { //proper error message on development server throw new Kwf_Exception("Building assets is disabled (assets.lazyBuild). Please include package in build."); } else { throw new Kwf_Exception_NotFound(); } } $ret = $this->getPackageContents($mimeType, $language)->getFileContents(); Kwf_Assets_BuildCache::getInstance()->building = false; } else { $ret = $ret['contents']; } return $ret; }
[ "public", "function", "getBuildContents", "(", "$", "mimeType", ",", "$", "language", ")", "{", "if", "(", "$", "mimeType", "==", "'text/javascript'", ")", "$", "ext", "=", "'js'", ";", "else", "if", "(", "$", "mimeType", "==", "'text/javascript; defer'", ")", "$", "ext", "=", "'defer.js'", ";", "else", "if", "(", "$", "mimeType", "==", "'text/css'", ")", "$", "ext", "=", "'css'", ";", "$", "cacheId", "=", "Kwf_Assets_Dispatcher", "::", "getInstance", "(", ")", "->", "getCacheIdByPackage", "(", "$", "this", ",", "$", "ext", ",", "$", "language", ")", ";", "$", "ret", "=", "Kwf_Assets_BuildCache", "::", "getInstance", "(", ")", "->", "load", "(", "$", "cacheId", ")", ";", "if", "(", "$", "ret", "===", "false", "||", "$", "ret", "===", "'outdated'", ")", "{", "if", "(", "$", "ret", "===", "'outdated'", "&&", "Kwf_Config", "::", "getValue", "(", "'assets.lazyBuild'", ")", "==", "'outdated'", ")", "{", "Kwf_Assets_BuildCache", "::", "getInstance", "(", ")", "->", "building", "=", "true", ";", "}", "else", "if", "(", "Kwf_Config", "::", "getValue", "(", "'assets.lazyBuild'", ")", "!==", "true", ")", "{", "if", "(", "Kwf_Exception_Abstract", "::", "isDebug", "(", ")", ")", "{", "//proper error message on development server", "throw", "new", "Kwf_Exception", "(", "\"Building assets is disabled (assets.lazyBuild). Please include package in build.\"", ")", ";", "}", "else", "{", "throw", "new", "Kwf_Exception_NotFound", "(", ")", ";", "}", "}", "$", "ret", "=", "$", "this", "->", "getPackageContents", "(", "$", "mimeType", ",", "$", "language", ")", "->", "getFileContents", "(", ")", ";", "Kwf_Assets_BuildCache", "::", "getInstance", "(", ")", "->", "building", "=", "false", ";", "}", "else", "{", "$", "ret", "=", "$", "ret", "[", "'contents'", "]", ";", "}", "return", "$", "ret", ";", "}" ]
Get built contents of a package, to be used by eg. mails
[ "Get", "built", "contents", "of", "a", "package", "to", "be", "used", "by", "eg", ".", "mails" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Assets/Package.php#L78-L103
koala-framework/koala-framework
Kwc/Shop/Cart/Checkout/Payment/Wirecard/ConfirmLink/Component.php
Kwc_Shop_Cart_Checkout_Payment_Wirecard_ConfirmLink_Component.buildWirecardButtonHtml
public static function buildWirecardButtonHtml($params, $payment, $order) { $wirecardCustomerId = $payment->getBaseProperty('wirecard.customerId'); $wirecardSecret = $payment->getBaseProperty('wirecard.secret'); if (!$wirecardCustomerId || !$wirecardSecret) { throw new Kwf_Exception('Set wirecard settings (customerId & secret) in config!'); } $params = array_merge($params, array( 'secret' => $wirecardSecret, 'customerId' => $wirecardCustomerId, 'language' => $payment->getLanguage(), 'orderDescription' => $order->firstname . ' ' . $order->lastname . ' (' . $order->zip . '), '.$payment->trlKwf('Order: {0}', $order->number), 'displayText' => $payment->trlKwf('Thank you very much for your order.'), 'successURL' => $payment->getChildComponent('_success')->getAbsoluteUrl(), 'confirmURL' => $payment->getChildComponent('_ipn')->getAbsoluteUrl(), 'serviceURL' => $payment->getSubroot()->getAbsoluteUrl(), 'failureURL' => $payment->getChildComponent('_failure')->getAbsoluteUrl(), 'cancelURL' => $payment->getChildComponent('_cancel')->getAbsoluteUrl(), 'requestFingerprintOrder' => '', )); if ($shopId = $payment->getBaseProperty('wirecard.shopId')) $params['shopId'] = $shopId; $requestFingerprintSeed = ""; $exclude = array('requestFingerprintOrder'); foreach ($params as $key=>$value) { if (in_array($key, $exclude)) continue; $params['requestFingerprintOrder'] .= "$key,"; $requestFingerprintSeed .= $value; } $params['requestFingerprintOrder'] .= "requestFingerprintOrder"; $requestFingerprintSeed .= $params['requestFingerprintOrder']; $params['requestFingerprint'] = md5($requestFingerprintSeed); $initURL = "https://checkout.wirecard.com/page/init.php"; $ret = "<form action=\"$initURL\" method=\"post\" name=\"form\">\n"; foreach ($params as $k=>$i) { if ($k == 'secret') continue; $ret .= "<input type=\"hidden\" name=\"$k\" value=\"".Kwf_Util_HtmlSpecialChars::filter($i)."\">\n"; } $ret .= "<input type=\"button\" value=\"{$payment->trlKwf('Buy now')}\" class=\"submit\">\n"; $ret .= "</form>\n"; return $ret; }
php
public static function buildWirecardButtonHtml($params, $payment, $order) { $wirecardCustomerId = $payment->getBaseProperty('wirecard.customerId'); $wirecardSecret = $payment->getBaseProperty('wirecard.secret'); if (!$wirecardCustomerId || !$wirecardSecret) { throw new Kwf_Exception('Set wirecard settings (customerId & secret) in config!'); } $params = array_merge($params, array( 'secret' => $wirecardSecret, 'customerId' => $wirecardCustomerId, 'language' => $payment->getLanguage(), 'orderDescription' => $order->firstname . ' ' . $order->lastname . ' (' . $order->zip . '), '.$payment->trlKwf('Order: {0}', $order->number), 'displayText' => $payment->trlKwf('Thank you very much for your order.'), 'successURL' => $payment->getChildComponent('_success')->getAbsoluteUrl(), 'confirmURL' => $payment->getChildComponent('_ipn')->getAbsoluteUrl(), 'serviceURL' => $payment->getSubroot()->getAbsoluteUrl(), 'failureURL' => $payment->getChildComponent('_failure')->getAbsoluteUrl(), 'cancelURL' => $payment->getChildComponent('_cancel')->getAbsoluteUrl(), 'requestFingerprintOrder' => '', )); if ($shopId = $payment->getBaseProperty('wirecard.shopId')) $params['shopId'] = $shopId; $requestFingerprintSeed = ""; $exclude = array('requestFingerprintOrder'); foreach ($params as $key=>$value) { if (in_array($key, $exclude)) continue; $params['requestFingerprintOrder'] .= "$key,"; $requestFingerprintSeed .= $value; } $params['requestFingerprintOrder'] .= "requestFingerprintOrder"; $requestFingerprintSeed .= $params['requestFingerprintOrder']; $params['requestFingerprint'] = md5($requestFingerprintSeed); $initURL = "https://checkout.wirecard.com/page/init.php"; $ret = "<form action=\"$initURL\" method=\"post\" name=\"form\">\n"; foreach ($params as $k=>$i) { if ($k == 'secret') continue; $ret .= "<input type=\"hidden\" name=\"$k\" value=\"".Kwf_Util_HtmlSpecialChars::filter($i)."\">\n"; } $ret .= "<input type=\"button\" value=\"{$payment->trlKwf('Buy now')}\" class=\"submit\">\n"; $ret .= "</form>\n"; return $ret; }
[ "public", "static", "function", "buildWirecardButtonHtml", "(", "$", "params", ",", "$", "payment", ",", "$", "order", ")", "{", "$", "wirecardCustomerId", "=", "$", "payment", "->", "getBaseProperty", "(", "'wirecard.customerId'", ")", ";", "$", "wirecardSecret", "=", "$", "payment", "->", "getBaseProperty", "(", "'wirecard.secret'", ")", ";", "if", "(", "!", "$", "wirecardCustomerId", "||", "!", "$", "wirecardSecret", ")", "{", "throw", "new", "Kwf_Exception", "(", "'Set wirecard settings (customerId & secret) in config!'", ")", ";", "}", "$", "params", "=", "array_merge", "(", "$", "params", ",", "array", "(", "'secret'", "=>", "$", "wirecardSecret", ",", "'customerId'", "=>", "$", "wirecardCustomerId", ",", "'language'", "=>", "$", "payment", "->", "getLanguage", "(", ")", ",", "'orderDescription'", "=>", "$", "order", "->", "firstname", ".", "' '", ".", "$", "order", "->", "lastname", ".", "' ('", ".", "$", "order", "->", "zip", ".", "'), '", ".", "$", "payment", "->", "trlKwf", "(", "'Order: {0}'", ",", "$", "order", "->", "number", ")", ",", "'displayText'", "=>", "$", "payment", "->", "trlKwf", "(", "'Thank you very much for your order.'", ")", ",", "'successURL'", "=>", "$", "payment", "->", "getChildComponent", "(", "'_success'", ")", "->", "getAbsoluteUrl", "(", ")", ",", "'confirmURL'", "=>", "$", "payment", "->", "getChildComponent", "(", "'_ipn'", ")", "->", "getAbsoluteUrl", "(", ")", ",", "'serviceURL'", "=>", "$", "payment", "->", "getSubroot", "(", ")", "->", "getAbsoluteUrl", "(", ")", ",", "'failureURL'", "=>", "$", "payment", "->", "getChildComponent", "(", "'_failure'", ")", "->", "getAbsoluteUrl", "(", ")", ",", "'cancelURL'", "=>", "$", "payment", "->", "getChildComponent", "(", "'_cancel'", ")", "->", "getAbsoluteUrl", "(", ")", ",", "'requestFingerprintOrder'", "=>", "''", ",", ")", ")", ";", "if", "(", "$", "shopId", "=", "$", "payment", "->", "getBaseProperty", "(", "'wirecard.shopId'", ")", ")", "$", "params", "[", "'shopId'", "]", "=", "$", "shopId", ";", "$", "requestFingerprintSeed", "=", "\"\"", ";", "$", "exclude", "=", "array", "(", "'requestFingerprintOrder'", ")", ";", "foreach", "(", "$", "params", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "in_array", "(", "$", "key", ",", "$", "exclude", ")", ")", "continue", ";", "$", "params", "[", "'requestFingerprintOrder'", "]", ".=", "\"$key,\"", ";", "$", "requestFingerprintSeed", ".=", "$", "value", ";", "}", "$", "params", "[", "'requestFingerprintOrder'", "]", ".=", "\"requestFingerprintOrder\"", ";", "$", "requestFingerprintSeed", ".=", "$", "params", "[", "'requestFingerprintOrder'", "]", ";", "$", "params", "[", "'requestFingerprint'", "]", "=", "md5", "(", "$", "requestFingerprintSeed", ")", ";", "$", "initURL", "=", "\"https://checkout.wirecard.com/page/init.php\"", ";", "$", "ret", "=", "\"<form action=\\\"$initURL\\\" method=\\\"post\\\" name=\\\"form\\\">\\n\"", ";", "foreach", "(", "$", "params", "as", "$", "k", "=>", "$", "i", ")", "{", "if", "(", "$", "k", "==", "'secret'", ")", "continue", ";", "$", "ret", ".=", "\"<input type=\\\"hidden\\\" name=\\\"$k\\\" value=\\\"\"", ".", "Kwf_Util_HtmlSpecialChars", "::", "filter", "(", "$", "i", ")", ".", "\"\\\">\\n\"", ";", "}", "$", "ret", ".=", "\"<input type=\\\"button\\\" value=\\\"{$payment->trlKwf('Buy now')}\\\" class=\\\"submit\\\">\\n\"", ";", "$", "ret", ".=", "\"</form>\\n\"", ";", "return", "$", "ret", ";", "}" ]
used in trl
[ "used", "in", "trl" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Checkout/Payment/Wirecard/ConfirmLink/Component.php#L27-L72
koala-framework/koala-framework
Kwc/Basic/Table/Component.php
Kwc_Basic_Table_Component.addDefaultCssClasses
public static function addDefaultCssClasses($dataArray, $rowStyles) { $count = 0; $ret = array(); foreach ($dataArray as $dataItem) { if (!isset($dataItem['cssStyle'])) { $dataItem['cssClass'] = $count%2 == 0 ? 'odd' : 'even'; $dataItem['htmlTag'] = 'td'; } else { $dataItem['cssClass'] = $dataItem['cssStyle']. ' ' . ($count%2 == 0 ? 'odd' : 'even'); $dataItem['htmlTag'] = $rowStyles[$dataItem['cssStyle']]['tag']; } for ($i = 1; $i < count($dataItem['data'])+1; $i++) { if (empty($dataItem['data']['column'.$i]['cssClass'])) { $dataItem['data']['column'.$i]['cssClass'] .= 'col'.$i; } else { $dataItem['data']['column'.$i]['cssClass'] .= ' col'.$i; } if ($i == 1) { $dataItem['data']['column'.$i]['cssClass'] .= ' first'; } else if ($i == count($dataItem['data'])) { $dataItem['data']['column'.$i]['cssClass'] .= ' last'; } } $ret[] = $dataItem; $count++; } return $ret; }
php
public static function addDefaultCssClasses($dataArray, $rowStyles) { $count = 0; $ret = array(); foreach ($dataArray as $dataItem) { if (!isset($dataItem['cssStyle'])) { $dataItem['cssClass'] = $count%2 == 0 ? 'odd' : 'even'; $dataItem['htmlTag'] = 'td'; } else { $dataItem['cssClass'] = $dataItem['cssStyle']. ' ' . ($count%2 == 0 ? 'odd' : 'even'); $dataItem['htmlTag'] = $rowStyles[$dataItem['cssStyle']]['tag']; } for ($i = 1; $i < count($dataItem['data'])+1; $i++) { if (empty($dataItem['data']['column'.$i]['cssClass'])) { $dataItem['data']['column'.$i]['cssClass'] .= 'col'.$i; } else { $dataItem['data']['column'.$i]['cssClass'] .= ' col'.$i; } if ($i == 1) { $dataItem['data']['column'.$i]['cssClass'] .= ' first'; } else if ($i == count($dataItem['data'])) { $dataItem['data']['column'.$i]['cssClass'] .= ' last'; } } $ret[] = $dataItem; $count++; } return $ret; }
[ "public", "static", "function", "addDefaultCssClasses", "(", "$", "dataArray", ",", "$", "rowStyles", ")", "{", "$", "count", "=", "0", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "dataArray", "as", "$", "dataItem", ")", "{", "if", "(", "!", "isset", "(", "$", "dataItem", "[", "'cssStyle'", "]", ")", ")", "{", "$", "dataItem", "[", "'cssClass'", "]", "=", "$", "count", "%", "2", "==", "0", "?", "'odd'", ":", "'even'", ";", "$", "dataItem", "[", "'htmlTag'", "]", "=", "'td'", ";", "}", "else", "{", "$", "dataItem", "[", "'cssClass'", "]", "=", "$", "dataItem", "[", "'cssStyle'", "]", ".", "' '", ".", "(", "$", "count", "%", "2", "==", "0", "?", "'odd'", ":", "'even'", ")", ";", "$", "dataItem", "[", "'htmlTag'", "]", "=", "$", "rowStyles", "[", "$", "dataItem", "[", "'cssStyle'", "]", "]", "[", "'tag'", "]", ";", "}", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<", "count", "(", "$", "dataItem", "[", "'data'", "]", ")", "+", "1", ";", "$", "i", "++", ")", "{", "if", "(", "empty", "(", "$", "dataItem", "[", "'data'", "]", "[", "'column'", ".", "$", "i", "]", "[", "'cssClass'", "]", ")", ")", "{", "$", "dataItem", "[", "'data'", "]", "[", "'column'", ".", "$", "i", "]", "[", "'cssClass'", "]", ".=", "'col'", ".", "$", "i", ";", "}", "else", "{", "$", "dataItem", "[", "'data'", "]", "[", "'column'", ".", "$", "i", "]", "[", "'cssClass'", "]", ".=", "' col'", ".", "$", "i", ";", "}", "if", "(", "$", "i", "==", "1", ")", "{", "$", "dataItem", "[", "'data'", "]", "[", "'column'", ".", "$", "i", "]", "[", "'cssClass'", "]", ".=", "' first'", ";", "}", "else", "if", "(", "$", "i", "==", "count", "(", "$", "dataItem", "[", "'data'", "]", ")", ")", "{", "$", "dataItem", "[", "'data'", "]", "[", "'column'", ".", "$", "i", "]", "[", "'cssClass'", "]", ".=", "' last'", ";", "}", "}", "$", "ret", "[", "]", "=", "$", "dataItem", ";", "$", "count", "++", ";", "}", "return", "$", "ret", ";", "}" ]
used from Kwc_Basic_Table_Trl_Component
[ "used", "from", "Kwc_Basic_Table_Trl_Component" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/Table/Component.php#L76-L105
koala-framework/koala-framework
Kwc/Basic/LinkTag/Intern/Trl/Events.php
Kwc_Basic_LinkTag_Intern_Trl_Events._getIdsFromRecursiveEvent
private function _getIdsFromRecursiveEvent(Kwf_Component_Event_Component_RecursiveAbstract $event) { $c = $event->component->chained; $ids = array($c->dbId); $c = $c->getPageOrRoot(); foreach (Kwf_Component_Data_Root::getInstance()->getPageGenerators() as $gen) { foreach ($gen->getRecursivePageChildIds($c->dbId) as $id) { //similar to master, but also invisible ones $ids[] = (string)$id; } } return $ids; }
php
private function _getIdsFromRecursiveEvent(Kwf_Component_Event_Component_RecursiveAbstract $event) { $c = $event->component->chained; $ids = array($c->dbId); $c = $c->getPageOrRoot(); foreach (Kwf_Component_Data_Root::getInstance()->getPageGenerators() as $gen) { foreach ($gen->getRecursivePageChildIds($c->dbId) as $id) { //similar to master, but also invisible ones $ids[] = (string)$id; } } return $ids; }
[ "private", "function", "_getIdsFromRecursiveEvent", "(", "Kwf_Component_Event_Component_RecursiveAbstract", "$", "event", ")", "{", "$", "c", "=", "$", "event", "->", "component", "->", "chained", ";", "$", "ids", "=", "array", "(", "$", "c", "->", "dbId", ")", ";", "$", "c", "=", "$", "c", "->", "getPageOrRoot", "(", ")", ";", "foreach", "(", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getPageGenerators", "(", ")", "as", "$", "gen", ")", "{", "foreach", "(", "$", "gen", "->", "getRecursivePageChildIds", "(", "$", "c", "->", "dbId", ")", "as", "$", "id", ")", "{", "//similar to master, but also invisible ones", "$", "ids", "[", "]", "=", "(", "string", ")", "$", "id", ";", "}", "}", "return", "$", "ids", ";", "}" ]
this method returns all child ids needed for deleting recursively
[ "this", "method", "returns", "all", "child", "ids", "needed", "for", "deleting", "recursively" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/LinkTag/Intern/Trl/Events.php#L37-L48
koala-framework/koala-framework
Kwc/Box/MetaTags/Component.php
Kwc_Box_MetaTags_Component.getMetaTagsForData
public static function getMetaTagsForData($data) { $ret = array(); if (Kwf_Config::getValue('application.kwf.name') == 'Koala Framework') { $ret['generator'] = 'Koala Web Framework CMS'; } if ($data->getPage()) { if (Kwc_Abstract::getFlag($data->getPage()->componentClass, 'metaTags')) { foreach ($data->getPage()->getComponent()->getMetaTags() as $name=>$content) { if (!isset($ret[$name])) $ret[$name] = ''; //TODO: for eg noindex,nofollow other separator $ret[$name] .= ' '.$content; } } if (Kwc_Abstract::getFlag($data->getPage()->componentClass, 'noIndex')) { if (isset($ret['robots'])) { $ret['robots'] .= ','; } else { $ret['robots'] = ''; } $ret['robots'] .= 'noindex'; } } foreach ($ret as &$i) $i = trim($i); unset($i); // verify-v1 if (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = Kwf_Config::getValue('server.domain'); } $hostParts = explode('.', $host); if (count($hostParts) < 2) { $configDomain = $host; } else { $shortParts = array('com', 'co', 'gv', 'or'); if (count($hostParts) > 2 & in_array($hostParts[count($hostParts)-2], $shortParts)) { $hostParts[count($hostParts)-2] = $hostParts[count($hostParts)-3].$hostParts[count($hostParts)-2]; } $configDomain = $hostParts[count($hostParts)-2] // zB 'vivid-planet' .$hostParts[count($hostParts)-1]; // zB 'com' } $configVerify = Kwf_Config::getValueArray('verifyV1'); if ($configVerify && isset($configVerify[$configDomain])) { $ret['verify-v1'] = $configVerify[$configDomain]; } $configVerify = Kwf_Config::getValueArray('googleSiteVerification'); if ($configVerify && isset($configVerify[$configDomain])) { $ret['google-site-verification'] = $configVerify[$configDomain]; } return $ret; }
php
public static function getMetaTagsForData($data) { $ret = array(); if (Kwf_Config::getValue('application.kwf.name') == 'Koala Framework') { $ret['generator'] = 'Koala Web Framework CMS'; } if ($data->getPage()) { if (Kwc_Abstract::getFlag($data->getPage()->componentClass, 'metaTags')) { foreach ($data->getPage()->getComponent()->getMetaTags() as $name=>$content) { if (!isset($ret[$name])) $ret[$name] = ''; //TODO: for eg noindex,nofollow other separator $ret[$name] .= ' '.$content; } } if (Kwc_Abstract::getFlag($data->getPage()->componentClass, 'noIndex')) { if (isset($ret['robots'])) { $ret['robots'] .= ','; } else { $ret['robots'] = ''; } $ret['robots'] .= 'noindex'; } } foreach ($ret as &$i) $i = trim($i); unset($i); // verify-v1 if (isset($_SERVER['HTTP_HOST'])) { $host = $_SERVER['HTTP_HOST']; } else { $host = Kwf_Config::getValue('server.domain'); } $hostParts = explode('.', $host); if (count($hostParts) < 2) { $configDomain = $host; } else { $shortParts = array('com', 'co', 'gv', 'or'); if (count($hostParts) > 2 & in_array($hostParts[count($hostParts)-2], $shortParts)) { $hostParts[count($hostParts)-2] = $hostParts[count($hostParts)-3].$hostParts[count($hostParts)-2]; } $configDomain = $hostParts[count($hostParts)-2] // zB 'vivid-planet' .$hostParts[count($hostParts)-1]; // zB 'com' } $configVerify = Kwf_Config::getValueArray('verifyV1'); if ($configVerify && isset($configVerify[$configDomain])) { $ret['verify-v1'] = $configVerify[$configDomain]; } $configVerify = Kwf_Config::getValueArray('googleSiteVerification'); if ($configVerify && isset($configVerify[$configDomain])) { $ret['google-site-verification'] = $configVerify[$configDomain]; } return $ret; }
[ "public", "static", "function", "getMetaTagsForData", "(", "$", "data", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "if", "(", "Kwf_Config", "::", "getValue", "(", "'application.kwf.name'", ")", "==", "'Koala Framework'", ")", "{", "$", "ret", "[", "'generator'", "]", "=", "'Koala Web Framework CMS'", ";", "}", "if", "(", "$", "data", "->", "getPage", "(", ")", ")", "{", "if", "(", "Kwc_Abstract", "::", "getFlag", "(", "$", "data", "->", "getPage", "(", ")", "->", "componentClass", ",", "'metaTags'", ")", ")", "{", "foreach", "(", "$", "data", "->", "getPage", "(", ")", "->", "getComponent", "(", ")", "->", "getMetaTags", "(", ")", "as", "$", "name", "=>", "$", "content", ")", "{", "if", "(", "!", "isset", "(", "$", "ret", "[", "$", "name", "]", ")", ")", "$", "ret", "[", "$", "name", "]", "=", "''", ";", "//TODO: for eg noindex,nofollow other separator", "$", "ret", "[", "$", "name", "]", ".=", "' '", ".", "$", "content", ";", "}", "}", "if", "(", "Kwc_Abstract", "::", "getFlag", "(", "$", "data", "->", "getPage", "(", ")", "->", "componentClass", ",", "'noIndex'", ")", ")", "{", "if", "(", "isset", "(", "$", "ret", "[", "'robots'", "]", ")", ")", "{", "$", "ret", "[", "'robots'", "]", ".=", "','", ";", "}", "else", "{", "$", "ret", "[", "'robots'", "]", "=", "''", ";", "}", "$", "ret", "[", "'robots'", "]", ".=", "'noindex'", ";", "}", "}", "foreach", "(", "$", "ret", "as", "&", "$", "i", ")", "$", "i", "=", "trim", "(", "$", "i", ")", ";", "unset", "(", "$", "i", ")", ";", "// verify-v1", "if", "(", "isset", "(", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ")", ")", "{", "$", "host", "=", "$", "_SERVER", "[", "'HTTP_HOST'", "]", ";", "}", "else", "{", "$", "host", "=", "Kwf_Config", "::", "getValue", "(", "'server.domain'", ")", ";", "}", "$", "hostParts", "=", "explode", "(", "'.'", ",", "$", "host", ")", ";", "if", "(", "count", "(", "$", "hostParts", ")", "<", "2", ")", "{", "$", "configDomain", "=", "$", "host", ";", "}", "else", "{", "$", "shortParts", "=", "array", "(", "'com'", ",", "'co'", ",", "'gv'", ",", "'or'", ")", ";", "if", "(", "count", "(", "$", "hostParts", ")", ">", "2", "&", "in_array", "(", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "2", "]", ",", "$", "shortParts", ")", ")", "{", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "2", "]", "=", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "3", "]", ".", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "2", "]", ";", "}", "$", "configDomain", "=", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "2", "]", "// zB 'vivid-planet'", ".", "$", "hostParts", "[", "count", "(", "$", "hostParts", ")", "-", "1", "]", ";", "// zB 'com'", "}", "$", "configVerify", "=", "Kwf_Config", "::", "getValueArray", "(", "'verifyV1'", ")", ";", "if", "(", "$", "configVerify", "&&", "isset", "(", "$", "configVerify", "[", "$", "configDomain", "]", ")", ")", "{", "$", "ret", "[", "'verify-v1'", "]", "=", "$", "configVerify", "[", "$", "configDomain", "]", ";", "}", "$", "configVerify", "=", "Kwf_Config", "::", "getValueArray", "(", "'googleSiteVerification'", ")", ";", "if", "(", "$", "configVerify", "&&", "isset", "(", "$", "configVerify", "[", "$", "configDomain", "]", ")", ")", "{", "$", "ret", "[", "'google-site-verification'", "]", "=", "$", "configVerify", "[", "$", "configDomain", "]", ";", "}", "return", "$", "ret", ";", "}" ]
public for trl
[ "public", "for", "trl" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Box/MetaTags/Component.php#L23-L77
koala-framework/koala-framework
Kwc/Box/MetaTags/Component.php
Kwc_Box_MetaTags_Component.injectMeta
public static function injectMeta($html, $title) { $kwfUp = Kwf_Config::getValue('application.uniquePrefix') ? Kwf_Config::getValue('application.uniquePrefix').'-' : ''; $startPos = strpos($html, '<!-- '.$kwfUp.'metaTags -->'); $endPos = strpos($html, '<!-- /'.$kwfUp.'metaTags -->')+18+strlen($kwfUp); $html = substr($html, 0, $startPos) .$title .substr($html, $endPos); return $html; }
php
public static function injectMeta($html, $title) { $kwfUp = Kwf_Config::getValue('application.uniquePrefix') ? Kwf_Config::getValue('application.uniquePrefix').'-' : ''; $startPos = strpos($html, '<!-- '.$kwfUp.'metaTags -->'); $endPos = strpos($html, '<!-- /'.$kwfUp.'metaTags -->')+18+strlen($kwfUp); $html = substr($html, 0, $startPos) .$title .substr($html, $endPos); return $html; }
[ "public", "static", "function", "injectMeta", "(", "$", "html", ",", "$", "title", ")", "{", "$", "kwfUp", "=", "Kwf_Config", "::", "getValue", "(", "'application.uniquePrefix'", ")", "?", "Kwf_Config", "::", "getValue", "(", "'application.uniquePrefix'", ")", ".", "'-'", ":", "''", ";", "$", "startPos", "=", "strpos", "(", "$", "html", ",", "'<!-- '", ".", "$", "kwfUp", ".", "'metaTags -->'", ")", ";", "$", "endPos", "=", "strpos", "(", "$", "html", ",", "'<!-- /'", ".", "$", "kwfUp", ".", "'metaTags -->'", ")", "+", "18", "+", "strlen", "(", "$", "kwfUp", ")", ";", "$", "html", "=", "substr", "(", "$", "html", ",", "0", ",", "$", "startPos", ")", ".", "$", "title", ".", "substr", "(", "$", "html", ",", "$", "endPos", ")", ";", "return", "$", "html", ";", "}" ]
public for trl
[ "public", "for", "trl" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Box/MetaTags/Component.php#L93-L102
koala-framework/koala-framework
Kwc/Form/Component.php
Kwc_Form_Component._handleProcessException
protected function _handleProcessException(Exception $e) { if ($e instanceof Kwf_Exception_Client) { $this->_errors[] = array( 'message' => $e->getMessage() ); } else { if (!$e instanceof Kwf_Exception) $e = new Kwf_Exception_Other($e); $e->logOrThrow(); $this->_errors[] = array( 'message' => trlKwf('An error occured while processing the form. Please try to submit again later.') ); } }
php
protected function _handleProcessException(Exception $e) { if ($e instanceof Kwf_Exception_Client) { $this->_errors[] = array( 'message' => $e->getMessage() ); } else { if (!$e instanceof Kwf_Exception) $e = new Kwf_Exception_Other($e); $e->logOrThrow(); $this->_errors[] = array( 'message' => trlKwf('An error occured while processing the form. Please try to submit again later.') ); } }
[ "protected", "function", "_handleProcessException", "(", "Exception", "$", "e", ")", "{", "if", "(", "$", "e", "instanceof", "Kwf_Exception_Client", ")", "{", "$", "this", "->", "_errors", "[", "]", "=", "array", "(", "'message'", "=>", "$", "e", "->", "getMessage", "(", ")", ")", ";", "}", "else", "{", "if", "(", "!", "$", "e", "instanceof", "Kwf_Exception", ")", "$", "e", "=", "new", "Kwf_Exception_Other", "(", "$", "e", ")", ";", "$", "e", "->", "logOrThrow", "(", ")", ";", "$", "this", "->", "_errors", "[", "]", "=", "array", "(", "'message'", "=>", "trlKwf", "(", "'An error occured while processing the form. Please try to submit again later.'", ")", ")", ";", "}", "}" ]
can be overriden to *not* log specific exceptions or adapt error
[ "can", "be", "overriden", "to", "*", "not", "*", "log", "specific", "exceptions", "or", "adapt", "error" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Form/Component.php#L134-L147
koala-framework/koala-framework
Kwf/Loader.php
Kwf_Loader.setIncludePath
public static function setIncludePath($ip) { if (self::$_includePath) throw new Kwf_Exception("include path is already set"); self::$_includePath = $ip; set_include_path($ip); }
php
public static function setIncludePath($ip) { if (self::$_includePath) throw new Kwf_Exception("include path is already set"); self::$_includePath = $ip; set_include_path($ip); }
[ "public", "static", "function", "setIncludePath", "(", "$", "ip", ")", "{", "if", "(", "self", "::", "$", "_includePath", ")", "throw", "new", "Kwf_Exception", "(", "\"include path is already set\"", ")", ";", "self", "::", "$", "_includePath", "=", "$", "ip", ";", "set_include_path", "(", "$", "ip", ")", ";", "}" ]
Set include path used for Kwf_Loader::isValidClass called exactly once in setup get_include_path is not used, because some external library might have changed that. @internal
[ "Set", "include", "path", "used", "for", "Kwf_Loader", "::", "isValidClass" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Loader.php#L14-L19
koala-framework/koala-framework
Kwf/Service/Amazon.php
Kwf_Service_Amazon.itemSearch
public function itemSearch(array $options) { Kwf_Benchmark::countBt('Service Amazon request', 'itemSearch'.print_r($options, true)); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $defaultOptions = array('ResponseGroup' => 'Small'); $options = $this->_prepareOptions('ItemSearch', $options, $defaultOptions); $client->getHttpClient()->resetParameters(); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Kwf_Service_Amazon_ResultSet($dom); }
php
public function itemSearch(array $options) { Kwf_Benchmark::countBt('Service Amazon request', 'itemSearch'.print_r($options, true)); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $defaultOptions = array('ResponseGroup' => 'Small'); $options = $this->_prepareOptions('ItemSearch', $options, $defaultOptions); $client->getHttpClient()->resetParameters(); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Kwf_Service_Amazon_ResultSet($dom); }
[ "public", "function", "itemSearch", "(", "array", "$", "options", ")", "{", "Kwf_Benchmark", "::", "countBt", "(", "'Service Amazon request'", ",", "'itemSearch'", ".", "print_r", "(", "$", "options", ",", "true", ")", ")", ";", "$", "client", "=", "$", "this", "->", "getRestClient", "(", ")", ";", "$", "client", "->", "setUri", "(", "$", "this", "->", "_baseUri", ")", ";", "$", "defaultOptions", "=", "array", "(", "'ResponseGroup'", "=>", "'Small'", ")", ";", "$", "options", "=", "$", "this", "->", "_prepareOptions", "(", "'ItemSearch'", ",", "$", "options", ",", "$", "defaultOptions", ")", ";", "$", "client", "->", "getHttpClient", "(", ")", "->", "resetParameters", "(", ")", ";", "$", "response", "=", "$", "client", "->", "restGet", "(", "'/onca/xml'", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "isError", "(", ")", ")", "{", "/**\n * @see Zend_Service_Exception\n */", "throw", "new", "Zend_Service_Exception", "(", "'An error occurred sending request. Status code: '", ".", "$", "response", "->", "getStatus", "(", ")", ")", ";", "}", "$", "dom", "=", "new", "DOMDocument", "(", ")", ";", "$", "dom", "->", "loadXML", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "self", "::", "_checkErrors", "(", "$", "dom", ")", ";", "return", "new", "Kwf_Service_Amazon_ResultSet", "(", "$", "dom", ")", ";", "}" ]
Search for Items @param array $options Options to use for the Search Query @throws Zend_Service_Exception @return Kwf_Service_Amazon_ResultSet @see http://www.amazon.com/gp/aws/sdk/main.html/102-9041115-9057709?s=AWSEcommerceService&v=2011-08-01&p=ApiReference/ItemSearchOperation
[ "Search", "for", "Items" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Service/Amazon.php#L23-L48
koala-framework/koala-framework
Kwf/Service/Amazon.php
Kwf_Service_Amazon.itemLookup
public function itemLookup($asin, array $options = array()) { Kwf_Benchmark::count('Service Amazon request', 'itemLookup '.$asin); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $client->getHttpClient()->resetParameters(); $defaultOptions = array('ResponseGroup' => 'Small'); $options['ItemId'] = (string) $asin; $options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception( 'An error occurred sending request. Status code: ' . $response->getStatus() ); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); $xpath = new DOMXPath($dom); $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01'); $items = $xpath->query('//az:Items/az:Item'); if ($items->length == 1) { return new Kwf_Service_Amazon_Item($items->item(0)); } return new Kwf_Service_Amazon_ResultSet($dom); }
php
public function itemLookup($asin, array $options = array()) { Kwf_Benchmark::count('Service Amazon request', 'itemLookup '.$asin); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $client->getHttpClient()->resetParameters(); $defaultOptions = array('ResponseGroup' => 'Small'); $options['ItemId'] = (string) $asin; $options = $this->_prepareOptions('ItemLookup', $options, $defaultOptions); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception( 'An error occurred sending request. Status code: ' . $response->getStatus() ); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); $xpath = new DOMXPath($dom); $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01'); $items = $xpath->query('//az:Items/az:Item'); if ($items->length == 1) { return new Kwf_Service_Amazon_Item($items->item(0)); } return new Kwf_Service_Amazon_ResultSet($dom); }
[ "public", "function", "itemLookup", "(", "$", "asin", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "Kwf_Benchmark", "::", "count", "(", "'Service Amazon request'", ",", "'itemLookup '", ".", "$", "asin", ")", ";", "$", "client", "=", "$", "this", "->", "getRestClient", "(", ")", ";", "$", "client", "->", "setUri", "(", "$", "this", "->", "_baseUri", ")", ";", "$", "client", "->", "getHttpClient", "(", ")", "->", "resetParameters", "(", ")", ";", "$", "defaultOptions", "=", "array", "(", "'ResponseGroup'", "=>", "'Small'", ")", ";", "$", "options", "[", "'ItemId'", "]", "=", "(", "string", ")", "$", "asin", ";", "$", "options", "=", "$", "this", "->", "_prepareOptions", "(", "'ItemLookup'", ",", "$", "options", ",", "$", "defaultOptions", ")", ";", "$", "response", "=", "$", "client", "->", "restGet", "(", "'/onca/xml'", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "isError", "(", ")", ")", "{", "/**\n * @see Zend_Service_Exception\n */", "throw", "new", "Zend_Service_Exception", "(", "'An error occurred sending request. Status code: '", ".", "$", "response", "->", "getStatus", "(", ")", ")", ";", "}", "$", "dom", "=", "new", "DOMDocument", "(", ")", ";", "$", "dom", "->", "loadXML", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "self", "::", "_checkErrors", "(", "$", "dom", ")", ";", "$", "xpath", "=", "new", "DOMXPath", "(", "$", "dom", ")", ";", "$", "xpath", "->", "registerNamespace", "(", "'az'", ",", "'http://webservices.amazon.com/AWSECommerceService/2011-08-01'", ")", ";", "$", "items", "=", "$", "xpath", "->", "query", "(", "'//az:Items/az:Item'", ")", ";", "if", "(", "$", "items", "->", "length", "==", "1", ")", "{", "return", "new", "Kwf_Service_Amazon_Item", "(", "$", "items", "->", "item", "(", "0", ")", ")", ";", "}", "return", "new", "Kwf_Service_Amazon_ResultSet", "(", "$", "dom", ")", ";", "}" ]
Look up item(s) by ASIN @param string $asin Amazon ASIN ID @param array $options Query Options @see http://www.amazon.com/gp/aws/sdk/main.html/102-9041115-9057709?s=AWSEcommerceService&v=2011-08-01&p=ApiReference/ItemLookupOperation @throws Zend_Service_Exception @return Kwf_Service_Amazon_Item|Kwf_Service_Amazon_ResultSet
[ "Look", "up", "item", "(", "s", ")", "by", "ASIN" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Service/Amazon.php#L60-L94
koala-framework/koala-framework
Kwf/Service/Amazon.php
Kwf_Service_Amazon.browseNodeLookup
public function browseNodeLookup($nodeId, array $options = array()) { Kwf_Benchmark::count('Service Amazon request', 'browseNodeLookup'); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $client->getHttpClient()->resetParameters(); $defaultOptions = array('IdType' => 'ASIN', 'ResponseGroup' => 'BrowseNodeInfo'); $options['BrowseNodeId'] = (string) $nodeId; $options = $this->_prepareOptions('BrowseNodeLookup', $options, $defaultOptions); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Kwf_Service_Amazon_BrowseNode($dom); }
php
public function browseNodeLookup($nodeId, array $options = array()) { Kwf_Benchmark::count('Service Amazon request', 'browseNodeLookup'); $client = $this->getRestClient(); $client->setUri($this->_baseUri); $client->getHttpClient()->resetParameters(); $defaultOptions = array('IdType' => 'ASIN', 'ResponseGroup' => 'BrowseNodeInfo'); $options['BrowseNodeId'] = (string) $nodeId; $options = $this->_prepareOptions('BrowseNodeLookup', $options, $defaultOptions); $response = $client->restGet('/onca/xml', $options); if ($response->isError()) { /** * @see Zend_Service_Exception */ throw new Zend_Service_Exception('An error occurred sending request. Status code: ' . $response->getStatus()); } $dom = new DOMDocument(); $dom->loadXML($response->getBody()); self::_checkErrors($dom); return new Kwf_Service_Amazon_BrowseNode($dom); }
[ "public", "function", "browseNodeLookup", "(", "$", "nodeId", ",", "array", "$", "options", "=", "array", "(", ")", ")", "{", "Kwf_Benchmark", "::", "count", "(", "'Service Amazon request'", ",", "'browseNodeLookup'", ")", ";", "$", "client", "=", "$", "this", "->", "getRestClient", "(", ")", ";", "$", "client", "->", "setUri", "(", "$", "this", "->", "_baseUri", ")", ";", "$", "client", "->", "getHttpClient", "(", ")", "->", "resetParameters", "(", ")", ";", "$", "defaultOptions", "=", "array", "(", "'IdType'", "=>", "'ASIN'", ",", "'ResponseGroup'", "=>", "'BrowseNodeInfo'", ")", ";", "$", "options", "[", "'BrowseNodeId'", "]", "=", "(", "string", ")", "$", "nodeId", ";", "$", "options", "=", "$", "this", "->", "_prepareOptions", "(", "'BrowseNodeLookup'", ",", "$", "options", ",", "$", "defaultOptions", ")", ";", "$", "response", "=", "$", "client", "->", "restGet", "(", "'/onca/xml'", ",", "$", "options", ")", ";", "if", "(", "$", "response", "->", "isError", "(", ")", ")", "{", "/**\n * @see Zend_Service_Exception\n */", "throw", "new", "Zend_Service_Exception", "(", "'An error occurred sending request. Status code: '", ".", "$", "response", "->", "getStatus", "(", ")", ")", ";", "}", "$", "dom", "=", "new", "DOMDocument", "(", ")", ";", "$", "dom", "->", "loadXML", "(", "$", "response", "->", "getBody", "(", ")", ")", ";", "self", "::", "_checkErrors", "(", "$", "dom", ")", ";", "return", "new", "Kwf_Service_Amazon_BrowseNode", "(", "$", "dom", ")", ";", "}" ]
Look up item(s) by ASIN @param string $asin Amazon ASIN ID @param array $options Query Options @see http://docs.amazonwebservices.com/AWSEcommerceService/2011-08-01/ApiReference/BrowseNodeLookupOperation.html @throws Zend_Service_Exception @return Kwf_Service_Amazon_BrowseNode
[ "Look", "up", "item", "(", "s", ")", "by", "ASIN" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Service/Amazon.php#L105-L130
koala-framework/koala-framework
Kwf/Benchmark.php
Kwf_Benchmark._getInstance
private static function _getInstance() { static $i; if (!isset($i)) { $c = Kwf_Config::getValue('benchmarkClass'); if (!class_exists($c)) { $c = 'Kwf_Benchmark'; } $i = new $c(); } return $i; }
php
private static function _getInstance() { static $i; if (!isset($i)) { $c = Kwf_Config::getValue('benchmarkClass'); if (!class_exists($c)) { $c = 'Kwf_Benchmark'; } $i = new $c(); } return $i; }
[ "private", "static", "function", "_getInstance", "(", ")", "{", "static", "$", "i", ";", "if", "(", "!", "isset", "(", "$", "i", ")", ")", "{", "$", "c", "=", "Kwf_Config", "::", "getValue", "(", "'benchmarkClass'", ")", ";", "if", "(", "!", "class_exists", "(", "$", "c", ")", ")", "{", "$", "c", "=", "'Kwf_Benchmark'", ";", "}", "$", "i", "=", "new", "$", "c", "(", ")", ";", "}", "return", "$", "i", ";", "}" ]
wird von Kwf_Setup::setUp gesetzt
[ "wird", "von", "Kwf_Setup", "::", "setUp", "gesetzt" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Benchmark.php#L13-L24
koala-framework/koala-framework
Kwf/Benchmark.php
Kwf_Benchmark.start
public static function start($identifier = null, $addInfo = null) { if (!self::$_enabled) return null; return new Kwf_Benchmark_Profile($identifier, $addInfo); }
php
public static function start($identifier = null, $addInfo = null) { if (!self::$_enabled) return null; return new Kwf_Benchmark_Profile($identifier, $addInfo); }
[ "public", "static", "function", "start", "(", "$", "identifier", "=", "null", ",", "$", "addInfo", "=", "null", ")", "{", "if", "(", "!", "self", "::", "$", "_enabled", ")", "return", "null", ";", "return", "new", "Kwf_Benchmark_Profile", "(", "$", "identifier", ",", "$", "addInfo", ")", ";", "}" ]
Startet eine Sequenz @param string $identifier
[ "Startet", "eine", "Sequenz" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Benchmark.php#L31-L35
koala-framework/koala-framework
Kwc/Articles/ReadRequired/Component.php
Kwc_Articles_ReadRequired_Component.getRedirectUrl
public function getRedirectUrl($postData) { $allowRedirect = !isset($postData['redirect']) || $postData['redirect'] == '/'; if ($allowRedirect) { $requiredArticles = $this->_getRequiredArticles(); if ($requiredArticles && $requiredArticles->count() > 0) { return $this->getData()->url; } } return null; }
php
public function getRedirectUrl($postData) { $allowRedirect = !isset($postData['redirect']) || $postData['redirect'] == '/'; if ($allowRedirect) { $requiredArticles = $this->_getRequiredArticles(); if ($requiredArticles && $requiredArticles->count() > 0) { return $this->getData()->url; } } return null; }
[ "public", "function", "getRedirectUrl", "(", "$", "postData", ")", "{", "$", "allowRedirect", "=", "!", "isset", "(", "$", "postData", "[", "'redirect'", "]", ")", "||", "$", "postData", "[", "'redirect'", "]", "==", "'/'", ";", "if", "(", "$", "allowRedirect", ")", "{", "$", "requiredArticles", "=", "$", "this", "->", "_getRequiredArticles", "(", ")", ";", "if", "(", "$", "requiredArticles", "&&", "$", "requiredArticles", "->", "count", "(", ")", ">", "0", ")", "{", "return", "$", "this", "->", "getData", "(", ")", "->", "url", ";", "}", "}", "return", "null", ";", "}" ]
To be called in Kwc_User_Login_Component::_getUrlForRedirect()
[ "To", "be", "called", "in", "Kwc_User_Login_Component", "::", "_getUrlForRedirect", "()" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Articles/ReadRequired/Component.php#L58-L68
koala-framework/koala-framework
Kwc/Root/TrlRoot/Chained/Admin.php
Kwc_Root_TrlRoot_Chained_Admin.duplicated
public static function duplicated(Kwf_Component_Data $source, Kwf_Component_Data $new) { $chained = Kwf_Component_Data_Root::getInstance() ->getComponentsByClass('Kwc_Root_TrlRoot_Chained_Component', array('ignoreVisible'=>true)); //bySameClass wenn fkt nicht mehr static (todo oben erledigt) $sourceChained = array(); foreach ($chained as $c) { $subRootAboveTrl = $c; //eg. domain while($subRootAboveTrl = $subRootAboveTrl->parent) { if (Kwc_Abstract::getFlag($subRootAboveTrl->componentClass, 'subroot')) { break; } } if (!$subRootAboveTrl) { $subRootAboveTrl = Kwf_Component_Data_Root::getInstance(); } $d = $source; while($d = $d->parent) { if ($d->componentId == $subRootAboveTrl->componentId) { $sourceChained[$c->getLanguage()] = $c; } } } $targetChained = array(); foreach ($chained as $c) { $subRootAboveTrl = $c; //eg. domain while($subRootAboveTrl = $subRootAboveTrl->parent) { if (Kwc_Abstract::getFlag($subRootAboveTrl->componentClass, 'subroot')) { break; } } if (!$subRootAboveTrl) { $subRootAboveTrl = Kwf_Component_Data_Root::getInstance(); } $d = $new; while($d = $d->parent) { if ($d->componentId == $subRootAboveTrl->componentId) { if (isset($sourceChained[$c->getLanguage()])) { //only if there is a source language $targetChained[] = array( 'targetChained' => $c, 'sourceChained' => $sourceChained[$c->getLanguage()], ); } } } } foreach ($targetChained as $c) { $sourceChained = Kwc_Chained_Trl_Component::getChainedByMaster($source, $c['sourceChained'], array('ignoreVisible'=>true)); $newChained = Kwc_Chained_Trl_Component::getChainedByMaster($new, $c['targetChained'], array('ignoreVisible'=>true)); if (!$sourceChained || $source->componentId==$sourceChained->componentId) { continue; //wenn sourceChained nicht gefunden handelt es sich zB um ein MasterAsChild - was ignoriert werden muss } if (!$newChained) { throw new Kwf_Exception("can't find chained components"); } Kwc_Admin::getInstance($newChained->componentClass)->duplicate($sourceChained, $newChained); } }
php
public static function duplicated(Kwf_Component_Data $source, Kwf_Component_Data $new) { $chained = Kwf_Component_Data_Root::getInstance() ->getComponentsByClass('Kwc_Root_TrlRoot_Chained_Component', array('ignoreVisible'=>true)); //bySameClass wenn fkt nicht mehr static (todo oben erledigt) $sourceChained = array(); foreach ($chained as $c) { $subRootAboveTrl = $c; //eg. domain while($subRootAboveTrl = $subRootAboveTrl->parent) { if (Kwc_Abstract::getFlag($subRootAboveTrl->componentClass, 'subroot')) { break; } } if (!$subRootAboveTrl) { $subRootAboveTrl = Kwf_Component_Data_Root::getInstance(); } $d = $source; while($d = $d->parent) { if ($d->componentId == $subRootAboveTrl->componentId) { $sourceChained[$c->getLanguage()] = $c; } } } $targetChained = array(); foreach ($chained as $c) { $subRootAboveTrl = $c; //eg. domain while($subRootAboveTrl = $subRootAboveTrl->parent) { if (Kwc_Abstract::getFlag($subRootAboveTrl->componentClass, 'subroot')) { break; } } if (!$subRootAboveTrl) { $subRootAboveTrl = Kwf_Component_Data_Root::getInstance(); } $d = $new; while($d = $d->parent) { if ($d->componentId == $subRootAboveTrl->componentId) { if (isset($sourceChained[$c->getLanguage()])) { //only if there is a source language $targetChained[] = array( 'targetChained' => $c, 'sourceChained' => $sourceChained[$c->getLanguage()], ); } } } } foreach ($targetChained as $c) { $sourceChained = Kwc_Chained_Trl_Component::getChainedByMaster($source, $c['sourceChained'], array('ignoreVisible'=>true)); $newChained = Kwc_Chained_Trl_Component::getChainedByMaster($new, $c['targetChained'], array('ignoreVisible'=>true)); if (!$sourceChained || $source->componentId==$sourceChained->componentId) { continue; //wenn sourceChained nicht gefunden handelt es sich zB um ein MasterAsChild - was ignoriert werden muss } if (!$newChained) { throw new Kwf_Exception("can't find chained components"); } Kwc_Admin::getInstance($newChained->componentClass)->duplicate($sourceChained, $newChained); } }
[ "public", "static", "function", "duplicated", "(", "Kwf_Component_Data", "$", "source", ",", "Kwf_Component_Data", "$", "new", ")", "{", "$", "chained", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentsByClass", "(", "'Kwc_Root_TrlRoot_Chained_Component'", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "//bySameClass wenn fkt nicht mehr static (todo oben erledigt)", "$", "sourceChained", "=", "array", "(", ")", ";", "foreach", "(", "$", "chained", "as", "$", "c", ")", "{", "$", "subRootAboveTrl", "=", "$", "c", ";", "//eg. domain", "while", "(", "$", "subRootAboveTrl", "=", "$", "subRootAboveTrl", "->", "parent", ")", "{", "if", "(", "Kwc_Abstract", "::", "getFlag", "(", "$", "subRootAboveTrl", "->", "componentClass", ",", "'subroot'", ")", ")", "{", "break", ";", "}", "}", "if", "(", "!", "$", "subRootAboveTrl", ")", "{", "$", "subRootAboveTrl", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", ";", "}", "$", "d", "=", "$", "source", ";", "while", "(", "$", "d", "=", "$", "d", "->", "parent", ")", "{", "if", "(", "$", "d", "->", "componentId", "==", "$", "subRootAboveTrl", "->", "componentId", ")", "{", "$", "sourceChained", "[", "$", "c", "->", "getLanguage", "(", ")", "]", "=", "$", "c", ";", "}", "}", "}", "$", "targetChained", "=", "array", "(", ")", ";", "foreach", "(", "$", "chained", "as", "$", "c", ")", "{", "$", "subRootAboveTrl", "=", "$", "c", ";", "//eg. domain", "while", "(", "$", "subRootAboveTrl", "=", "$", "subRootAboveTrl", "->", "parent", ")", "{", "if", "(", "Kwc_Abstract", "::", "getFlag", "(", "$", "subRootAboveTrl", "->", "componentClass", ",", "'subroot'", ")", ")", "{", "break", ";", "}", "}", "if", "(", "!", "$", "subRootAboveTrl", ")", "{", "$", "subRootAboveTrl", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", ";", "}", "$", "d", "=", "$", "new", ";", "while", "(", "$", "d", "=", "$", "d", "->", "parent", ")", "{", "if", "(", "$", "d", "->", "componentId", "==", "$", "subRootAboveTrl", "->", "componentId", ")", "{", "if", "(", "isset", "(", "$", "sourceChained", "[", "$", "c", "->", "getLanguage", "(", ")", "]", ")", ")", "{", "//only if there is a source language", "$", "targetChained", "[", "]", "=", "array", "(", "'targetChained'", "=>", "$", "c", ",", "'sourceChained'", "=>", "$", "sourceChained", "[", "$", "c", "->", "getLanguage", "(", ")", "]", ",", ")", ";", "}", "}", "}", "}", "foreach", "(", "$", "targetChained", "as", "$", "c", ")", "{", "$", "sourceChained", "=", "Kwc_Chained_Trl_Component", "::", "getChainedByMaster", "(", "$", "source", ",", "$", "c", "[", "'sourceChained'", "]", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "$", "newChained", "=", "Kwc_Chained_Trl_Component", "::", "getChainedByMaster", "(", "$", "new", ",", "$", "c", "[", "'targetChained'", "]", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "if", "(", "!", "$", "sourceChained", "||", "$", "source", "->", "componentId", "==", "$", "sourceChained", "->", "componentId", ")", "{", "continue", ";", "//wenn sourceChained nicht gefunden handelt es sich zB um ein MasterAsChild - was ignoriert werden muss", "}", "if", "(", "!", "$", "newChained", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"can't find chained components\"", ")", ";", "}", "Kwc_Admin", "::", "getInstance", "(", "$", "newChained", "->", "componentClass", ")", "->", "duplicate", "(", "$", "sourceChained", ",", "$", "newChained", ")", ";", "}", "}" ]
TODO sollte nicht mehr static sein wenn todo in Kwf_Util_Component::duplicate erledigt wurde
[ "TODO", "sollte", "nicht", "mehr", "static", "sein", "wenn", "todo", "in", "Kwf_Util_Component", "::", "duplicate", "erledigt", "wurde" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Root/TrlRoot/Chained/Admin.php#L5-L64
koala-framework/koala-framework
Kwc/Root/Category/GeneratorEvents.php
Kwc_Root_Category_GeneratorEvents.onRowUpdatesFinished
public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event) { foreach ($this->_deferredDeleteChildPageIdsCache as $i) { $this->_deleteChildPageIdsCache($i); } $this->_deferredDeleteChildPageIdsCache = array(); }
php
public function onRowUpdatesFinished(Kwf_Events_Event_Row_UpdatesFinished $event) { foreach ($this->_deferredDeleteChildPageIdsCache as $i) { $this->_deleteChildPageIdsCache($i); } $this->_deferredDeleteChildPageIdsCache = array(); }
[ "public", "function", "onRowUpdatesFinished", "(", "Kwf_Events_Event_Row_UpdatesFinished", "$", "event", ")", "{", "foreach", "(", "$", "this", "->", "_deferredDeleteChildPageIdsCache", "as", "$", "i", ")", "{", "$", "this", "->", "_deleteChildPageIdsCache", "(", "$", "i", ")", ";", "}", "$", "this", "->", "_deferredDeleteChildPageIdsCache", "=", "array", "(", ")", ";", "}" ]
else the Generator would cache again with the *old* data as it's called from menu events
[ "else", "the", "Generator", "would", "cache", "again", "with", "the", "*", "old", "*", "data", "as", "it", "s", "called", "from", "menu", "events" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Root/Category/GeneratorEvents.php#L141-L147
koala-framework/koala-framework
Kwf/Component/Events/ProcessInputCache.php
Kwf_Component_Events_ProcessInputCache.onComponentAddedOrRemoved
public function onComponentAddedOrRemoved(Kwf_Component_Event_Component_Abstract $event) { $cacheId = 'procI-'.$event->component->getPageOrRoot()->componentId; Kwf_Cache_Simple::delete($cacheId); $log = Kwf_Events_Log::getInstance(); if ($log) { $log->log("processInput cache clear componentId=".$event->component->getPageOrRoot()->componentId, Zend_Log::INFO); } }
php
public function onComponentAddedOrRemoved(Kwf_Component_Event_Component_Abstract $event) { $cacheId = 'procI-'.$event->component->getPageOrRoot()->componentId; Kwf_Cache_Simple::delete($cacheId); $log = Kwf_Events_Log::getInstance(); if ($log) { $log->log("processInput cache clear componentId=".$event->component->getPageOrRoot()->componentId, Zend_Log::INFO); } }
[ "public", "function", "onComponentAddedOrRemoved", "(", "Kwf_Component_Event_Component_Abstract", "$", "event", ")", "{", "$", "cacheId", "=", "'procI-'", ".", "$", "event", "->", "component", "->", "getPageOrRoot", "(", ")", "->", "componentId", ";", "Kwf_Cache_Simple", "::", "delete", "(", "$", "cacheId", ")", ";", "$", "log", "=", "Kwf_Events_Log", "::", "getInstance", "(", ")", ";", "if", "(", "$", "log", ")", "{", "$", "log", "->", "log", "(", "\"processInput cache clear componentId=\"", ".", "$", "event", "->", "component", "->", "getPageOrRoot", "(", ")", "->", "componentId", ",", "Zend_Log", "::", "INFO", ")", ";", "}", "}" ]
clear cache used in Kwf_Component_Abstract_ContentSender_Default
[ "clear", "cache", "used", "in", "Kwf_Component_Abstract_ContentSender_Default" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Events/ProcessInputCache.php#L27-L35
koala-framework/koala-framework
Kwc/Chained/Trl/MasterAsChild/ContentSender.php
Kwc_Chained_Trl_MasterAsChild_ContentSender.sendContent
public function sendContent($includeMaster) { $data = $this->_data->getChildComponent('-child'); $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender'); $contentSender = new $contentSender($data); $contentSender->sendContent($includeMaster); }
php
public function sendContent($includeMaster) { $data = $this->_data->getChildComponent('-child'); $contentSender = Kwc_Abstract::getSetting($data->componentClass, 'contentSender'); $contentSender = new $contentSender($data); $contentSender->sendContent($includeMaster); }
[ "public", "function", "sendContent", "(", "$", "includeMaster", ")", "{", "$", "data", "=", "$", "this", "->", "_data", "->", "getChildComponent", "(", "'-child'", ")", ";", "$", "contentSender", "=", "Kwc_Abstract", "::", "getSetting", "(", "$", "data", "->", "componentClass", ",", "'contentSender'", ")", ";", "$", "contentSender", "=", "new", "$", "contentSender", "(", "$", "data", ")", ";", "$", "contentSender", "->", "sendContent", "(", "$", "includeMaster", ")", ";", "}" ]
und zwar ist die page nicht die für die sendContent() aufgerufen wird sondern die child, und da fehlen dann die boxen und alles
[ "und", "zwar", "ist", "die", "page", "nicht", "die", "für", "die", "sendContent", "()", "aufgerufen", "wird", "sondern", "die", "child", "und", "da", "fehlen", "dann", "die", "boxen", "und", "alles" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Chained/Trl/MasterAsChild/ContentSender.php#L7-L13
koala-framework/koala-framework
Kwc/Basic/LinkTag/News/Admin.php
Kwc_Basic_LinkTag_News_Admin.afterDuplicate
public function afterDuplicate($rootSource, $rootTarget) { parent::afterDuplicate($rootSource, $rootTarget); $prefix = $this->_prefix; $column = "{$prefix}_id"; foreach ($this->_duplicated as $d) { //modify duplicated links so they point to duplicated page //only IF link points to page below $rootSource $source = Kwf_Component_Data_Root::getInstance()->getComponentById($d['source'], array('ignoreVisible'=>true)); $sourceRow = $source->getComponent()->getRow(); $linkTargetIsBelowRootSource = false; foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($prefix.'_'.$sourceRow->$column, array('ignoreVisible'=>true)) as $sourceLinkTarget) { do { if ($sourceLinkTarget->componentId == $rootSource->componentId) { $linkTargetIsBelowRootSource = true; break; } } while ($sourceLinkTarget = $sourceLinkTarget->parent); } if ($linkTargetIsBelowRootSource) { //get duplicated link target id from duplicate log $sql = "SELECT target_component_id FROM kwc_log_duplicate WHERE source_component_id = ? ORDER BY id DESC LIMIT 1"; $q = Kwf_Registry::get('db')->query($sql, $prefix.'_'.$sourceRow->$column); $q = $q->fetchAll(); if (!$q) continue; $linkTargetId = $q[0]['target_component_id']; $target = Kwf_Component_Data_Root::getInstance()->getComponentById($d['target'], array('ignoreVisible'=>true)); $targetRow = $target->getComponent()->getRow(); if (substr($linkTargetId, 0, 5) != $prefix.'_') { throw new Kwf_Exception('invalid target_component_id'); } $targetRow->$column = substr($linkTargetId, 5); $targetRow->save(); } } $this->_duplicated = array(); }
php
public function afterDuplicate($rootSource, $rootTarget) { parent::afterDuplicate($rootSource, $rootTarget); $prefix = $this->_prefix; $column = "{$prefix}_id"; foreach ($this->_duplicated as $d) { //modify duplicated links so they point to duplicated page //only IF link points to page below $rootSource $source = Kwf_Component_Data_Root::getInstance()->getComponentById($d['source'], array('ignoreVisible'=>true)); $sourceRow = $source->getComponent()->getRow(); $linkTargetIsBelowRootSource = false; foreach (Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($prefix.'_'.$sourceRow->$column, array('ignoreVisible'=>true)) as $sourceLinkTarget) { do { if ($sourceLinkTarget->componentId == $rootSource->componentId) { $linkTargetIsBelowRootSource = true; break; } } while ($sourceLinkTarget = $sourceLinkTarget->parent); } if ($linkTargetIsBelowRootSource) { //get duplicated link target id from duplicate log $sql = "SELECT target_component_id FROM kwc_log_duplicate WHERE source_component_id = ? ORDER BY id DESC LIMIT 1"; $q = Kwf_Registry::get('db')->query($sql, $prefix.'_'.$sourceRow->$column); $q = $q->fetchAll(); if (!$q) continue; $linkTargetId = $q[0]['target_component_id']; $target = Kwf_Component_Data_Root::getInstance()->getComponentById($d['target'], array('ignoreVisible'=>true)); $targetRow = $target->getComponent()->getRow(); if (substr($linkTargetId, 0, 5) != $prefix.'_') { throw new Kwf_Exception('invalid target_component_id'); } $targetRow->$column = substr($linkTargetId, 5); $targetRow->save(); } } $this->_duplicated = array(); }
[ "public", "function", "afterDuplicate", "(", "$", "rootSource", ",", "$", "rootTarget", ")", "{", "parent", "::", "afterDuplicate", "(", "$", "rootSource", ",", "$", "rootTarget", ")", ";", "$", "prefix", "=", "$", "this", "->", "_prefix", ";", "$", "column", "=", "\"{$prefix}_id\"", ";", "foreach", "(", "$", "this", "->", "_duplicated", "as", "$", "d", ")", "{", "//modify duplicated links so they point to duplicated page", "//only IF link points to page below $rootSource", "$", "source", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentById", "(", "$", "d", "[", "'source'", "]", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "$", "sourceRow", "=", "$", "source", "->", "getComponent", "(", ")", "->", "getRow", "(", ")", ";", "$", "linkTargetIsBelowRootSource", "=", "false", ";", "foreach", "(", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentsByDbId", "(", "$", "prefix", ".", "'_'", ".", "$", "sourceRow", "->", "$", "column", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", "as", "$", "sourceLinkTarget", ")", "{", "do", "{", "if", "(", "$", "sourceLinkTarget", "->", "componentId", "==", "$", "rootSource", "->", "componentId", ")", "{", "$", "linkTargetIsBelowRootSource", "=", "true", ";", "break", ";", "}", "}", "while", "(", "$", "sourceLinkTarget", "=", "$", "sourceLinkTarget", "->", "parent", ")", ";", "}", "if", "(", "$", "linkTargetIsBelowRootSource", ")", "{", "//get duplicated link target id from duplicate log", "$", "sql", "=", "\"SELECT target_component_id FROM kwc_log_duplicate WHERE source_component_id = ? ORDER BY id DESC LIMIT 1\"", ";", "$", "q", "=", "Kwf_Registry", "::", "get", "(", "'db'", ")", "->", "query", "(", "$", "sql", ",", "$", "prefix", ".", "'_'", ".", "$", "sourceRow", "->", "$", "column", ")", ";", "$", "q", "=", "$", "q", "->", "fetchAll", "(", ")", ";", "if", "(", "!", "$", "q", ")", "continue", ";", "$", "linkTargetId", "=", "$", "q", "[", "0", "]", "[", "'target_component_id'", "]", ";", "$", "target", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentById", "(", "$", "d", "[", "'target'", "]", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "$", "targetRow", "=", "$", "target", "->", "getComponent", "(", ")", "->", "getRow", "(", ")", ";", "if", "(", "substr", "(", "$", "linkTargetId", ",", "0", ",", "5", ")", "!=", "$", "prefix", ".", "'_'", ")", "{", "throw", "new", "Kwf_Exception", "(", "'invalid target_component_id'", ")", ";", "}", "$", "targetRow", "->", "$", "column", "=", "substr", "(", "$", "linkTargetId", ",", "5", ")", ";", "$", "targetRow", "->", "save", "(", ")", ";", "}", "}", "$", "this", "->", "_duplicated", "=", "array", "(", ")", ";", "}" ]
TODO: reuse code from Link_Intern, but for that we have to inherit Link_Intern_Admin which we don't atm
[ "TODO", ":", "reuse", "code", "from", "Link_Intern", "but", "for", "that", "we", "have", "to", "inherit", "Link_Intern_Admin", "which", "we", "don", "t", "atm" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/LinkTag/News/Admin.php#L82-L118
koala-framework/koala-framework
Kwc/Shop/Cart/Order.php
Kwc_Shop_Cart_Order.getProductText
public final function getProductText($orderProduct) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($orderProduct->add_component_class); return $data->getProductText($orderProduct); }
php
public final function getProductText($orderProduct) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($orderProduct->add_component_class); return $data->getProductText($orderProduct); }
[ "public", "final", "function", "getProductText", "(", "$", "orderProduct", ")", "{", "$", "data", "=", "Kwc_Shop_VoucherProduct_AddToCart_OrderProductData", "::", "getInstance", "(", "$", "orderProduct", "->", "add_component_class", ")", ";", "return", "$", "data", "->", "getProductText", "(", "$", "orderProduct", ")", ";", "}" ]
override in addToCart
[ "override", "in", "addToCart" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Order.php#L72-L76
koala-framework/koala-framework
Kwc/Shop/Cart/Order.php
Kwc_Shop_Cart_Order._getProductPrice
protected function _getProductPrice($orderProduct) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($orderProduct->add_component_class); return $data->getPrice($orderProduct); }
php
protected function _getProductPrice($orderProduct) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($orderProduct->add_component_class); return $data->getPrice($orderProduct); }
[ "protected", "function", "_getProductPrice", "(", "$", "orderProduct", ")", "{", "$", "data", "=", "Kwc_Shop_VoucherProduct_AddToCart_OrderProductData", "::", "getInstance", "(", "$", "orderProduct", "->", "add_component_class", ")", ";", "return", "$", "data", "->", "getPrice", "(", "$", "orderProduct", ")", ";", "}" ]
override to implement eg. excl. vat prices for the whole order
[ "override", "to", "implement", "eg", ".", "excl", ".", "vat", "prices", "for", "the", "whole", "order" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Order.php#L85-L89
koala-framework/koala-framework
Kwc/Shop/Cart/Order.php
Kwc_Shop_Cart_Order._getProductsData
private function _getProductsData(Kwf_Component_Data $subroot = null) { $ret = array(); $items = $this->getChildRows('Products'); $ret = array(); foreach ($items as $i) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($i->add_component_class); $r = array( 'id' => $i->id, 'additionalOrderData' => $data->getAdditionalOrderData($i), 'price' => $this->_getProductPrice($i), 'amount' => $data->getAmount($i), 'text' => $data->getProductText($i), ); if ($subroot) { $addComponent = Kwc_Shop_AddToCartAbstract_OrderProductData::getAddComponentByDbId( $i->add_component_id, $subroot ); if (!$addComponent) { //product doesn't exist anymore, also delete from cart $i->delete(); continue; } else { $r['product'] = $addComponent->parent; $r['text'] = $addComponent->getComponent()->getProductText($i); } } $ret[] = (object)$r; } return $ret; }
php
private function _getProductsData(Kwf_Component_Data $subroot = null) { $ret = array(); $items = $this->getChildRows('Products'); $ret = array(); foreach ($items as $i) { $data = Kwc_Shop_VoucherProduct_AddToCart_OrderProductData::getInstance($i->add_component_class); $r = array( 'id' => $i->id, 'additionalOrderData' => $data->getAdditionalOrderData($i), 'price' => $this->_getProductPrice($i), 'amount' => $data->getAmount($i), 'text' => $data->getProductText($i), ); if ($subroot) { $addComponent = Kwc_Shop_AddToCartAbstract_OrderProductData::getAddComponentByDbId( $i->add_component_id, $subroot ); if (!$addComponent) { //product doesn't exist anymore, also delete from cart $i->delete(); continue; } else { $r['product'] = $addComponent->parent; $r['text'] = $addComponent->getComponent()->getProductText($i); } } $ret[] = (object)$r; } return $ret; }
[ "private", "function", "_getProductsData", "(", "Kwf_Component_Data", "$", "subroot", "=", "null", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "items", "=", "$", "this", "->", "getChildRows", "(", "'Products'", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "items", "as", "$", "i", ")", "{", "$", "data", "=", "Kwc_Shop_VoucherProduct_AddToCart_OrderProductData", "::", "getInstance", "(", "$", "i", "->", "add_component_class", ")", ";", "$", "r", "=", "array", "(", "'id'", "=>", "$", "i", "->", "id", ",", "'additionalOrderData'", "=>", "$", "data", "->", "getAdditionalOrderData", "(", "$", "i", ")", ",", "'price'", "=>", "$", "this", "->", "_getProductPrice", "(", "$", "i", ")", ",", "'amount'", "=>", "$", "data", "->", "getAmount", "(", "$", "i", ")", ",", "'text'", "=>", "$", "data", "->", "getProductText", "(", "$", "i", ")", ",", ")", ";", "if", "(", "$", "subroot", ")", "{", "$", "addComponent", "=", "Kwc_Shop_AddToCartAbstract_OrderProductData", "::", "getAddComponentByDbId", "(", "$", "i", "->", "add_component_id", ",", "$", "subroot", ")", ";", "if", "(", "!", "$", "addComponent", ")", "{", "//product doesn't exist anymore, also delete from cart", "$", "i", "->", "delete", "(", ")", ";", "continue", ";", "}", "else", "{", "$", "r", "[", "'product'", "]", "=", "$", "addComponent", "->", "parent", ";", "$", "r", "[", "'text'", "]", "=", "$", "addComponent", "->", "getComponent", "(", ")", "->", "getProductText", "(", "$", "i", ")", ";", "}", "}", "$", "ret", "[", "]", "=", "(", "object", ")", "$", "r", ";", "}", "return", "$", "ret", ";", "}" ]
if product is not available in sitetree anymore it is deleted (also called by Kwc_Shop_Cart_Component)
[ "if", "product", "is", "not", "available", "in", "sitetree", "anymore", "it", "is", "deleted", "(", "also", "called", "by", "Kwc_Shop_Cart_Component", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Order.php#L165-L197
koala-framework/koala-framework
Kwc/Shop/Cart/Order.php
Kwc_Shop_Cart_Order._getAdditionalSumRows
protected function _getAdditionalSumRows($total) { $ret = array(); $payments = Kwc_Abstract::getChildComponentClasses( Kwc_Abstract::getChildComponentClass($this->getModel()->getCartComponentClass(), 'checkout'), 'payment'); if (isset($payments[$this->payment])) { $rows = Kwc_Shop_Cart_Checkout_Payment_Abstract_OrderData ::getInstance($payments[$this->payment]) ->getAdditionalSumRows($this); foreach ($rows as $r) $total += $r['amount']; $ret = array_merge($ret, $rows); } foreach ($this->getModel()->getShopCartPlugins() as $p) { $rows = $p->getAdditionalSumRows($this, $total); foreach ($rows as $r) $total += $r['amount']; $ret = array_merge($ret, $rows); } return $ret; }
php
protected function _getAdditionalSumRows($total) { $ret = array(); $payments = Kwc_Abstract::getChildComponentClasses( Kwc_Abstract::getChildComponentClass($this->getModel()->getCartComponentClass(), 'checkout'), 'payment'); if (isset($payments[$this->payment])) { $rows = Kwc_Shop_Cart_Checkout_Payment_Abstract_OrderData ::getInstance($payments[$this->payment]) ->getAdditionalSumRows($this); foreach ($rows as $r) $total += $r['amount']; $ret = array_merge($ret, $rows); } foreach ($this->getModel()->getShopCartPlugins() as $p) { $rows = $p->getAdditionalSumRows($this, $total); foreach ($rows as $r) $total += $r['amount']; $ret = array_merge($ret, $rows); } return $ret; }
[ "protected", "function", "_getAdditionalSumRows", "(", "$", "total", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "payments", "=", "Kwc_Abstract", "::", "getChildComponentClasses", "(", "Kwc_Abstract", "::", "getChildComponentClass", "(", "$", "this", "->", "getModel", "(", ")", "->", "getCartComponentClass", "(", ")", ",", "'checkout'", ")", ",", "'payment'", ")", ";", "if", "(", "isset", "(", "$", "payments", "[", "$", "this", "->", "payment", "]", ")", ")", "{", "$", "rows", "=", "Kwc_Shop_Cart_Checkout_Payment_Abstract_OrderData", "::", "getInstance", "(", "$", "payments", "[", "$", "this", "->", "payment", "]", ")", "->", "getAdditionalSumRows", "(", "$", "this", ")", ";", "foreach", "(", "$", "rows", "as", "$", "r", ")", "$", "total", "+=", "$", "r", "[", "'amount'", "]", ";", "$", "ret", "=", "array_merge", "(", "$", "ret", ",", "$", "rows", ")", ";", "}", "foreach", "(", "$", "this", "->", "getModel", "(", ")", "->", "getShopCartPlugins", "(", ")", "as", "$", "p", ")", "{", "$", "rows", "=", "$", "p", "->", "getAdditionalSumRows", "(", "$", "this", ",", "$", "total", ")", ";", "foreach", "(", "$", "rows", "as", "$", "r", ")", "$", "total", "+=", "$", "r", "[", "'amount'", "]", ";", "$", "ret", "=", "array_merge", "(", "$", "ret", ",", "$", "rows", ")", ";", "}", "return", "$", "ret", ";", "}" ]
kann überschrieben werden um zeilen für alle payments zu ändern
[ "kann", "überschrieben", "werden", "um", "zeilen", "für", "alle", "payments", "zu", "ändern" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/Cart/Order.php#L214-L232
koala-framework/koala-framework
Kwc/Advanced/Sitemap/Component.php
Kwc_Advanced_Sitemap_Component.getListHtml
public static function getListHtml(Kwf_Component_Renderer_Abstract $renderer, Kwf_Component_Data $c, $level, $levels, $className) { $ret = ''; $level++; $select = new Kwf_Component_Select(); $select->whereShowInMenu(true); $ret .= '<ul class="' . self::getBemClass($className, 'sitemapListLevel'.$level) . '">' . "\n"; $count = 1; foreach ($c->getChildPages($select) as $child) { $ret .= '<li class="' . self::getBemClass($className, 'sitemapListItemLevel'.$level); if ($count % 3 === 0) { $ret .= ' ' . self::getBemClass($className, '--third'); } if ($count % 2 === 0) { $ret .= ' ' . self::getBemClass($className, '--second'); } if (!$child->getChildPages($select)) { $ret .= ' ' . self::getBemClass($className, '--noChild'); } $ret .= '">'; $helper = new Kwf_Component_View_Helper_ComponentLink(); $helper->setRenderer($renderer); $ret .= $helper->componentLink($child); $ret .= "\n"; if ($level < $levels) { $ret .= self::getListHtml($renderer, $child, $level, $levels, $className); } $ret .= "</li>\n"; $count++; } $ret .= "</ul>\n"; return $ret; }
php
public static function getListHtml(Kwf_Component_Renderer_Abstract $renderer, Kwf_Component_Data $c, $level, $levels, $className) { $ret = ''; $level++; $select = new Kwf_Component_Select(); $select->whereShowInMenu(true); $ret .= '<ul class="' . self::getBemClass($className, 'sitemapListLevel'.$level) . '">' . "\n"; $count = 1; foreach ($c->getChildPages($select) as $child) { $ret .= '<li class="' . self::getBemClass($className, 'sitemapListItemLevel'.$level); if ($count % 3 === 0) { $ret .= ' ' . self::getBemClass($className, '--third'); } if ($count % 2 === 0) { $ret .= ' ' . self::getBemClass($className, '--second'); } if (!$child->getChildPages($select)) { $ret .= ' ' . self::getBemClass($className, '--noChild'); } $ret .= '">'; $helper = new Kwf_Component_View_Helper_ComponentLink(); $helper->setRenderer($renderer); $ret .= $helper->componentLink($child); $ret .= "\n"; if ($level < $levels) { $ret .= self::getListHtml($renderer, $child, $level, $levels, $className); } $ret .= "</li>\n"; $count++; } $ret .= "</ul>\n"; return $ret; }
[ "public", "static", "function", "getListHtml", "(", "Kwf_Component_Renderer_Abstract", "$", "renderer", ",", "Kwf_Component_Data", "$", "c", ",", "$", "level", ",", "$", "levels", ",", "$", "className", ")", "{", "$", "ret", "=", "''", ";", "$", "level", "++", ";", "$", "select", "=", "new", "Kwf_Component_Select", "(", ")", ";", "$", "select", "->", "whereShowInMenu", "(", "true", ")", ";", "$", "ret", ".=", "'<ul class=\"'", ".", "self", "::", "getBemClass", "(", "$", "className", ",", "'sitemapListLevel'", ".", "$", "level", ")", ".", "'\">'", ".", "\"\\n\"", ";", "$", "count", "=", "1", ";", "foreach", "(", "$", "c", "->", "getChildPages", "(", "$", "select", ")", "as", "$", "child", ")", "{", "$", "ret", ".=", "'<li class=\"'", ".", "self", "::", "getBemClass", "(", "$", "className", ",", "'sitemapListItemLevel'", ".", "$", "level", ")", ";", "if", "(", "$", "count", "%", "3", "===", "0", ")", "{", "$", "ret", ".=", "' '", ".", "self", "::", "getBemClass", "(", "$", "className", ",", "'--third'", ")", ";", "}", "if", "(", "$", "count", "%", "2", "===", "0", ")", "{", "$", "ret", ".=", "' '", ".", "self", "::", "getBemClass", "(", "$", "className", ",", "'--second'", ")", ";", "}", "if", "(", "!", "$", "child", "->", "getChildPages", "(", "$", "select", ")", ")", "{", "$", "ret", ".=", "' '", ".", "self", "::", "getBemClass", "(", "$", "className", ",", "'--noChild'", ")", ";", "}", "$", "ret", ".=", "'\">'", ";", "$", "helper", "=", "new", "Kwf_Component_View_Helper_ComponentLink", "(", ")", ";", "$", "helper", "->", "setRenderer", "(", "$", "renderer", ")", ";", "$", "ret", ".=", "$", "helper", "->", "componentLink", "(", "$", "child", ")", ";", "$", "ret", ".=", "\"\\n\"", ";", "if", "(", "$", "level", "<", "$", "levels", ")", "{", "$", "ret", ".=", "self", "::", "getListHtml", "(", "$", "renderer", ",", "$", "child", ",", "$", "level", ",", "$", "levels", ",", "$", "className", ")", ";", "}", "$", "ret", ".=", "\"</li>\\n\"", ";", "$", "count", "++", ";", "}", "$", "ret", ".=", "\"</ul>\\n\"", ";", "return", "$", "ret", ";", "}" ]
public because for trl
[ "public", "because", "for", "trl" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Advanced/Sitemap/Component.php#L30-L62
koala-framework/koala-framework
Kwc/Basic/Text/Row.php
Kwc_Basic_Text_Row.getContentParts
public function getContentParts($content = null, $ignoreLinksWithClass = null) { $classes = $this->_classes; $usedChildComponentNrs = array(); $componentId = $this->component_id; if (is_null($content)) $content = $this->content; $ret = array(); //1 2 3 4 5 while (preg_match('#^(.*)(<img[^>]+src=[\n ]*"([^"]*)"[^>]*>|<a[^>]+href=[\n ]*"([^"]*)"[^>]*>)(.*)$#Usi', $content, $m)) { if ($m[1] != '') { $ret[] = $m[1]; } if (isset($classes['image']) && $m[3] != '' && preg_match('#/media/([^/]+)/([^/]+)#', $m[3], $m2)) { //"/media/$class/$id/$rule/$type/$checksum/$filename.$extension$random" $isInvalid = false; $childComponentId = $m2[2]; if (substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-i') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('i'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'i'.$nr; $ret[] = array('type'=>'image', 'nr'=>$nr, 'html'=>$m[2]); } else { $isInvalid = true; } } else { $isInvalid = true; } if ($isInvalid) { $ret[] = array('type'=>'invalidImage', 'src'=>$m[3], 'componentClass'=>$m2[1], 'componentId'=>$childComponentId, 'html'=>$m[2]); } } else if (isset($classes['image']) && $m[3] != '') { $ret[] = array('type'=>'invalidImage', 'src'=>$m[3], 'html'=>$m[2]); } else if ($m[3] != '') { //kein image möglich } if ((isset($classes['link']) || isset($classes['download'])) && $m[4] != '' && preg_match('#/?([^/]+)$#', $m[4], $m2)) { $isInvalid = false; $childComponentId = $m2[1]; if (isset($classes['link']) && substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-l') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('l'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'l'.$nr; $ret[] = array('type'=>'link', 'nr'=>$nr, 'html'=>$m[2]); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } } else if (isset($classes['download']) && substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-d') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('d'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'd'.$nr; $ret[] = array('type'=>'download', 'nr'=>$nr, 'html'=>$m[2]); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidDownload', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } } else if (isset($classes['link']) && preg_match('#-l[0-9]+$#', $m2[1])) { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } else if (isset($classes['download']) && preg_match('#-d[0-9]+$#', $m2[1])) { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidDownload', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'html'=>$m[2]) ); } } else if (isset($classes['link']) && $m[4] != '') { $ret[] = $this->_checkIgnoreLinksWithClass($ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'html'=>$m[2])); } else if ($m[4] != '') { //kein link möglich } $content = $m[5]; } if(!$m) $ret[] = $content; return $ret; }
php
public function getContentParts($content = null, $ignoreLinksWithClass = null) { $classes = $this->_classes; $usedChildComponentNrs = array(); $componentId = $this->component_id; if (is_null($content)) $content = $this->content; $ret = array(); //1 2 3 4 5 while (preg_match('#^(.*)(<img[^>]+src=[\n ]*"([^"]*)"[^>]*>|<a[^>]+href=[\n ]*"([^"]*)"[^>]*>)(.*)$#Usi', $content, $m)) { if ($m[1] != '') { $ret[] = $m[1]; } if (isset($classes['image']) && $m[3] != '' && preg_match('#/media/([^/]+)/([^/]+)#', $m[3], $m2)) { //"/media/$class/$id/$rule/$type/$checksum/$filename.$extension$random" $isInvalid = false; $childComponentId = $m2[2]; if (substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-i') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('i'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'i'.$nr; $ret[] = array('type'=>'image', 'nr'=>$nr, 'html'=>$m[2]); } else { $isInvalid = true; } } else { $isInvalid = true; } if ($isInvalid) { $ret[] = array('type'=>'invalidImage', 'src'=>$m[3], 'componentClass'=>$m2[1], 'componentId'=>$childComponentId, 'html'=>$m[2]); } } else if (isset($classes['image']) && $m[3] != '') { $ret[] = array('type'=>'invalidImage', 'src'=>$m[3], 'html'=>$m[2]); } else if ($m[3] != '') { //kein image möglich } if ((isset($classes['link']) || isset($classes['download'])) && $m[4] != '' && preg_match('#/?([^/]+)$#', $m[4], $m2)) { $isInvalid = false; $childComponentId = $m2[1]; if (isset($classes['link']) && substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-l') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('l'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'l'.$nr; $ret[] = array('type'=>'link', 'nr'=>$nr, 'html'=>$m[2]); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } } else if (isset($classes['download']) && substr($childComponentId, 0, strlen($componentId)+2) == $componentId.'-d') { $nr = substr($childComponentId, strlen($componentId)+2); if (!in_array('d'.$nr, $usedChildComponentNrs)) { $usedChildComponentNrs[] = 'd'.$nr; $ret[] = array('type'=>'download', 'nr'=>$nr, 'html'=>$m[2]); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidDownload', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } } else if (isset($classes['link']) && preg_match('#-l[0-9]+$#', $m2[1])) { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } else if (isset($classes['download']) && preg_match('#-d[0-9]+$#', $m2[1])) { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidDownload', 'href'=>$m[4], 'componentId'=>$m2[1], 'html'=>$m[2]) ); } else { $ret[] = $this->_checkIgnoreLinksWithClass( $ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'html'=>$m[2]) ); } } else if (isset($classes['link']) && $m[4] != '') { $ret[] = $this->_checkIgnoreLinksWithClass($ignoreLinksWithClass, array('type'=>'invalidLink', 'href'=>$m[4], 'html'=>$m[2])); } else if ($m[4] != '') { //kein link möglich } $content = $m[5]; } if(!$m) $ret[] = $content; return $ret; }
[ "public", "function", "getContentParts", "(", "$", "content", "=", "null", ",", "$", "ignoreLinksWithClass", "=", "null", ")", "{", "$", "classes", "=", "$", "this", "->", "_classes", ";", "$", "usedChildComponentNrs", "=", "array", "(", ")", ";", "$", "componentId", "=", "$", "this", "->", "component_id", ";", "if", "(", "is_null", "(", "$", "content", ")", ")", "$", "content", "=", "$", "this", "->", "content", ";", "$", "ret", "=", "array", "(", ")", ";", "//1 2 3 4 5", "while", "(", "preg_match", "(", "'#^(.*)(<img[^>]+src=[\\n ]*\"([^\"]*)\"[^>]*>|<a[^>]+href=[\\n ]*\"([^\"]*)\"[^>]*>)(.*)$#Usi'", ",", "$", "content", ",", "$", "m", ")", ")", "{", "if", "(", "$", "m", "[", "1", "]", "!=", "''", ")", "{", "$", "ret", "[", "]", "=", "$", "m", "[", "1", "]", ";", "}", "if", "(", "isset", "(", "$", "classes", "[", "'image'", "]", ")", "&&", "$", "m", "[", "3", "]", "!=", "''", "&&", "preg_match", "(", "'#/media/([^/]+)/([^/]+)#'", ",", "$", "m", "[", "3", "]", ",", "$", "m2", ")", ")", "{", "//\"/media/$class/$id/$rule/$type/$checksum/$filename.$extension$random\"", "$", "isInvalid", "=", "false", ";", "$", "childComponentId", "=", "$", "m2", "[", "2", "]", ";", "if", "(", "substr", "(", "$", "childComponentId", ",", "0", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", "==", "$", "componentId", ".", "'-i'", ")", "{", "$", "nr", "=", "substr", "(", "$", "childComponentId", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", ";", "if", "(", "!", "in_array", "(", "'i'", ".", "$", "nr", ",", "$", "usedChildComponentNrs", ")", ")", "{", "$", "usedChildComponentNrs", "[", "]", "=", "'i'", ".", "$", "nr", ";", "$", "ret", "[", "]", "=", "array", "(", "'type'", "=>", "'image'", ",", "'nr'", "=>", "$", "nr", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ";", "}", "else", "{", "$", "isInvalid", "=", "true", ";", "}", "}", "else", "{", "$", "isInvalid", "=", "true", ";", "}", "if", "(", "$", "isInvalid", ")", "{", "$", "ret", "[", "]", "=", "array", "(", "'type'", "=>", "'invalidImage'", ",", "'src'", "=>", "$", "m", "[", "3", "]", ",", "'componentClass'", "=>", "$", "m2", "[", "1", "]", ",", "'componentId'", "=>", "$", "childComponentId", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "classes", "[", "'image'", "]", ")", "&&", "$", "m", "[", "3", "]", "!=", "''", ")", "{", "$", "ret", "[", "]", "=", "array", "(", "'type'", "=>", "'invalidImage'", ",", "'src'", "=>", "$", "m", "[", "3", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ";", "}", "else", "if", "(", "$", "m", "[", "3", "]", "!=", "''", ")", "{", "//kein image möglich", "}", "if", "(", "(", "isset", "(", "$", "classes", "[", "'link'", "]", ")", "||", "isset", "(", "$", "classes", "[", "'download'", "]", ")", ")", "&&", "$", "m", "[", "4", "]", "!=", "''", "&&", "preg_match", "(", "'#/?([^/]+)$#'", ",", "$", "m", "[", "4", "]", ",", "$", "m2", ")", ")", "{", "$", "isInvalid", "=", "false", ";", "$", "childComponentId", "=", "$", "m2", "[", "1", "]", ";", "if", "(", "isset", "(", "$", "classes", "[", "'link'", "]", ")", "&&", "substr", "(", "$", "childComponentId", ",", "0", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", "==", "$", "componentId", ".", "'-l'", ")", "{", "$", "nr", "=", "substr", "(", "$", "childComponentId", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", ";", "if", "(", "!", "in_array", "(", "'l'", ".", "$", "nr", ",", "$", "usedChildComponentNrs", ")", ")", "{", "$", "usedChildComponentNrs", "[", "]", "=", "'l'", ".", "$", "nr", ";", "$", "ret", "[", "]", "=", "array", "(", "'type'", "=>", "'link'", ",", "'nr'", "=>", "$", "nr", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ";", "}", "else", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidLink'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'componentId'", "=>", "$", "m2", "[", "1", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "classes", "[", "'download'", "]", ")", "&&", "substr", "(", "$", "childComponentId", ",", "0", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", "==", "$", "componentId", ".", "'-d'", ")", "{", "$", "nr", "=", "substr", "(", "$", "childComponentId", ",", "strlen", "(", "$", "componentId", ")", "+", "2", ")", ";", "if", "(", "!", "in_array", "(", "'d'", ".", "$", "nr", ",", "$", "usedChildComponentNrs", ")", ")", "{", "$", "usedChildComponentNrs", "[", "]", "=", "'d'", ".", "$", "nr", ";", "$", "ret", "[", "]", "=", "array", "(", "'type'", "=>", "'download'", ",", "'nr'", "=>", "$", "nr", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ";", "}", "else", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidDownload'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'componentId'", "=>", "$", "m2", "[", "1", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "classes", "[", "'link'", "]", ")", "&&", "preg_match", "(", "'#-l[0-9]+$#'", ",", "$", "m2", "[", "1", "]", ")", ")", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidLink'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'componentId'", "=>", "$", "m2", "[", "1", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "classes", "[", "'download'", "]", ")", "&&", "preg_match", "(", "'#-d[0-9]+$#'", ",", "$", "m2", "[", "1", "]", ")", ")", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidDownload'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'componentId'", "=>", "$", "m2", "[", "1", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "else", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidLink'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "classes", "[", "'link'", "]", ")", "&&", "$", "m", "[", "4", "]", "!=", "''", ")", "{", "$", "ret", "[", "]", "=", "$", "this", "->", "_checkIgnoreLinksWithClass", "(", "$", "ignoreLinksWithClass", ",", "array", "(", "'type'", "=>", "'invalidLink'", ",", "'href'", "=>", "$", "m", "[", "4", "]", ",", "'html'", "=>", "$", "m", "[", "2", "]", ")", ")", ";", "}", "else", "if", "(", "$", "m", "[", "4", "]", "!=", "''", ")", "{", "//kein link möglich", "}", "$", "content", "=", "$", "m", "[", "5", "]", ";", "}", "if", "(", "!", "$", "m", ")", "$", "ret", "[", "]", "=", "$", "content", ";", "return", "$", "ret", ";", "}" ]
für Component und Row
[ "für", "Component", "und", "Row" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/Text/Row.php#L15-L120
koala-framework/koala-framework
Kwc/Basic/Text/Row.php
Kwc_Basic_Text_Row._beforeSave
protected function _beforeSave() { $classes = $this->_classes; $this->content = $this->tidy($this->content); $newParts = $this->getContentParts($this->content); $newPartStrings = array(); foreach ($newParts as $part) { if (!is_string($part) ) { $newPartStrings[] = $part['type'].$part['nr']; } } $rows = $this->getChildRows('ChildComponents'); $existingParts = array(); foreach ($rows as $row) { if (!in_array($row->component.$row->nr, $newPartStrings)) { $row->delete(); } else { if (!$row->saved) { $row->saved = 1; $row->save(); } $existingParts[] = $row->component.$row->nr; } } foreach ($newParts as $part) { if (!is_string($part) && !in_array($part['type'].$part['nr'], $existingParts)) { $row = $this->createChildRow('ChildComponents'); $row->component = $part['type']; $row->nr = $part['nr']; $row->saved = 1; } } //for clearing text view cache when styles change $this->uses_styles = (bool)preg_match('#(<[a-z]+ [^>]*)class="style(\d+)"([^>]*>)#', $this->content); }
php
protected function _beforeSave() { $classes = $this->_classes; $this->content = $this->tidy($this->content); $newParts = $this->getContentParts($this->content); $newPartStrings = array(); foreach ($newParts as $part) { if (!is_string($part) ) { $newPartStrings[] = $part['type'].$part['nr']; } } $rows = $this->getChildRows('ChildComponents'); $existingParts = array(); foreach ($rows as $row) { if (!in_array($row->component.$row->nr, $newPartStrings)) { $row->delete(); } else { if (!$row->saved) { $row->saved = 1; $row->save(); } $existingParts[] = $row->component.$row->nr; } } foreach ($newParts as $part) { if (!is_string($part) && !in_array($part['type'].$part['nr'], $existingParts)) { $row = $this->createChildRow('ChildComponents'); $row->component = $part['type']; $row->nr = $part['nr']; $row->saved = 1; } } //for clearing text view cache when styles change $this->uses_styles = (bool)preg_match('#(<[a-z]+ [^>]*)class="style(\d+)"([^>]*>)#', $this->content); }
[ "protected", "function", "_beforeSave", "(", ")", "{", "$", "classes", "=", "$", "this", "->", "_classes", ";", "$", "this", "->", "content", "=", "$", "this", "->", "tidy", "(", "$", "this", "->", "content", ")", ";", "$", "newParts", "=", "$", "this", "->", "getContentParts", "(", "$", "this", "->", "content", ")", ";", "$", "newPartStrings", "=", "array", "(", ")", ";", "foreach", "(", "$", "newParts", "as", "$", "part", ")", "{", "if", "(", "!", "is_string", "(", "$", "part", ")", ")", "{", "$", "newPartStrings", "[", "]", "=", "$", "part", "[", "'type'", "]", ".", "$", "part", "[", "'nr'", "]", ";", "}", "}", "$", "rows", "=", "$", "this", "->", "getChildRows", "(", "'ChildComponents'", ")", ";", "$", "existingParts", "=", "array", "(", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "if", "(", "!", "in_array", "(", "$", "row", "->", "component", ".", "$", "row", "->", "nr", ",", "$", "newPartStrings", ")", ")", "{", "$", "row", "->", "delete", "(", ")", ";", "}", "else", "{", "if", "(", "!", "$", "row", "->", "saved", ")", "{", "$", "row", "->", "saved", "=", "1", ";", "$", "row", "->", "save", "(", ")", ";", "}", "$", "existingParts", "[", "]", "=", "$", "row", "->", "component", ".", "$", "row", "->", "nr", ";", "}", "}", "foreach", "(", "$", "newParts", "as", "$", "part", ")", "{", "if", "(", "!", "is_string", "(", "$", "part", ")", "&&", "!", "in_array", "(", "$", "part", "[", "'type'", "]", ".", "$", "part", "[", "'nr'", "]", ",", "$", "existingParts", ")", ")", "{", "$", "row", "=", "$", "this", "->", "createChildRow", "(", "'ChildComponents'", ")", ";", "$", "row", "->", "component", "=", "$", "part", "[", "'type'", "]", ";", "$", "row", "->", "nr", "=", "$", "part", "[", "'nr'", "]", ";", "$", "row", "->", "saved", "=", "1", ";", "}", "}", "//for clearing text view cache when styles change", "$", "this", "->", "uses_styles", "=", "(", "bool", ")", "preg_match", "(", "'#(<[a-z]+ [^>]*)class=\"style(\\d+)\"([^>]*>)#'", ",", "$", "this", "->", "content", ")", ";", "}" ]
childComponents löschen die aus dem html-code entfernt wurden
[ "childComponents", "löschen", "die", "aus", "dem", "html", "-", "code", "entfernt", "wurden" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/Text/Row.php#L145-L184
koala-framework/koala-framework
Kwc/Basic/Text/Row.php
Kwc_Basic_Text_Row.addChildComponentRow
public function addChildComponentRow($type, $childComponentRow = null) { $r = $this->createChildRow('ChildComponents'); $r->component = $type; $r->nr = $this->getMaxChildComponentNr($type)+1; $r->saved = 0; $r->save(); if ($childComponentRow) { $childComponentRow->component_id = $this->component_id.'-'.substr($type, 0, 1).$r->nr; } return $r; }
php
public function addChildComponentRow($type, $childComponentRow = null) { $r = $this->createChildRow('ChildComponents'); $r->component = $type; $r->nr = $this->getMaxChildComponentNr($type)+1; $r->saved = 0; $r->save(); if ($childComponentRow) { $childComponentRow->component_id = $this->component_id.'-'.substr($type, 0, 1).$r->nr; } return $r; }
[ "public", "function", "addChildComponentRow", "(", "$", "type", ",", "$", "childComponentRow", "=", "null", ")", "{", "$", "r", "=", "$", "this", "->", "createChildRow", "(", "'ChildComponents'", ")", ";", "$", "r", "->", "component", "=", "$", "type", ";", "$", "r", "->", "nr", "=", "$", "this", "->", "getMaxChildComponentNr", "(", "$", "type", ")", "+", "1", ";", "$", "r", "->", "saved", "=", "0", ";", "$", "r", "->", "save", "(", ")", ";", "if", "(", "$", "childComponentRow", ")", "{", "$", "childComponentRow", "->", "component_id", "=", "$", "this", "->", "component_id", ".", "'-'", ".", "substr", "(", "$", "type", ",", "0", ",", "1", ")", ".", "$", "r", "->", "nr", ";", "}", "return", "$", "r", ";", "}" ]
im Controller + in der row
[ "im", "Controller", "+", "in", "der", "row" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/Text/Row.php#L467-L479
koala-framework/koala-framework
Kwf/Controller/Action.php
Kwf_Controller_Action.dispatch
public function dispatch($action) { // Notify helpers of action preDispatch state $this->_helper->notifyPreDispatch(); $this->preDispatch(); Kwf_Benchmark::checkpoint('Action::preDispatch'); if ($this->getRequest()->isDispatched()) { if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) { if ($this->getInvokeArg('useCaseSensitiveActions')) { trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"'); } $this->$action(); } else { $this->__call($action, array()); } Kwf_Benchmark::checkpoint('Action::action'); $this->postDispatch(); Kwf_Benchmark::checkpoint('Action::postDispatch'); } // whats actually important here is that this action controller is // shutting down, regardless of dispatching; notify the helpers of this // state $this->_helper->notifyPostDispatch(); }
php
public function dispatch($action) { // Notify helpers of action preDispatch state $this->_helper->notifyPreDispatch(); $this->preDispatch(); Kwf_Benchmark::checkpoint('Action::preDispatch'); if ($this->getRequest()->isDispatched()) { if (null === $this->_classMethods) { $this->_classMethods = get_class_methods($this); } // preDispatch() didn't change the action, so we can continue if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) { if ($this->getInvokeArg('useCaseSensitiveActions')) { trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"'); } $this->$action(); } else { $this->__call($action, array()); } Kwf_Benchmark::checkpoint('Action::action'); $this->postDispatch(); Kwf_Benchmark::checkpoint('Action::postDispatch'); } // whats actually important here is that this action controller is // shutting down, regardless of dispatching; notify the helpers of this // state $this->_helper->notifyPostDispatch(); }
[ "public", "function", "dispatch", "(", "$", "action", ")", "{", "// Notify helpers of action preDispatch state", "$", "this", "->", "_helper", "->", "notifyPreDispatch", "(", ")", ";", "$", "this", "->", "preDispatch", "(", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'Action::preDispatch'", ")", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "isDispatched", "(", ")", ")", "{", "if", "(", "null", "===", "$", "this", "->", "_classMethods", ")", "{", "$", "this", "->", "_classMethods", "=", "get_class_methods", "(", "$", "this", ")", ";", "}", "// preDispatch() didn't change the action, so we can continue", "if", "(", "$", "this", "->", "getInvokeArg", "(", "'useCaseSensitiveActions'", ")", "||", "in_array", "(", "$", "action", ",", "$", "this", "->", "_classMethods", ")", ")", "{", "if", "(", "$", "this", "->", "getInvokeArg", "(", "'useCaseSensitiveActions'", ")", ")", "{", "trigger_error", "(", "'Using case sensitive actions without word separators is deprecated; please do not rely on this \"feature\"'", ")", ";", "}", "$", "this", "->", "$", "action", "(", ")", ";", "}", "else", "{", "$", "this", "->", "__call", "(", "$", "action", ",", "array", "(", ")", ")", ";", "}", "Kwf_Benchmark", "::", "checkpoint", "(", "'Action::action'", ")", ";", "$", "this", "->", "postDispatch", "(", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'Action::postDispatch'", ")", ";", "}", "// whats actually important here is that this action controller is", "// shutting down, regardless of dispatching; notify the helpers of this", "// state", "$", "this", "->", "_helper", "->", "notifyPostDispatch", "(", ")", ";", "}" ]
copied from zend to insert benchmark checkpoints
[ "copied", "from", "zend", "to", "insert", "benchmark", "checkpoints" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Controller/Action.php#L16-L47
koala-framework/koala-framework
Kwf/Util/MemoryLimit.php
Kwf_Util_MemoryLimit.set
public static function set($limit) { if (!is_int($limit)) throw new Kwf_Exception('Limit must be an integer'); if ($limit <= 0) throw new Kwf_Exception('Not allowed setting memory limit to: ' . $limit); $currentLimit = self::convertToMegabyte(ini_get('memory_limit')); if ($limit < (int)$currentLimit) return false; $value = $limit; $maxLimit = self::getMaxLimit(); if ($maxLimit > 0 && $maxLimit < $limit) { $value = $maxLimit; } ini_set('memory_limit', $value . 'M'); return $limit == $value; }
php
public static function set($limit) { if (!is_int($limit)) throw new Kwf_Exception('Limit must be an integer'); if ($limit <= 0) throw new Kwf_Exception('Not allowed setting memory limit to: ' . $limit); $currentLimit = self::convertToMegabyte(ini_get('memory_limit')); if ($limit < (int)$currentLimit) return false; $value = $limit; $maxLimit = self::getMaxLimit(); if ($maxLimit > 0 && $maxLimit < $limit) { $value = $maxLimit; } ini_set('memory_limit', $value . 'M'); return $limit == $value; }
[ "public", "static", "function", "set", "(", "$", "limit", ")", "{", "if", "(", "!", "is_int", "(", "$", "limit", ")", ")", "throw", "new", "Kwf_Exception", "(", "'Limit must be an integer'", ")", ";", "if", "(", "$", "limit", "<=", "0", ")", "throw", "new", "Kwf_Exception", "(", "'Not allowed setting memory limit to: '", ".", "$", "limit", ")", ";", "$", "currentLimit", "=", "self", "::", "convertToMegabyte", "(", "ini_get", "(", "'memory_limit'", ")", ")", ";", "if", "(", "$", "limit", "<", "(", "int", ")", "$", "currentLimit", ")", "return", "false", ";", "$", "value", "=", "$", "limit", ";", "$", "maxLimit", "=", "self", "::", "getMaxLimit", "(", ")", ";", "if", "(", "$", "maxLimit", ">", "0", "&&", "$", "maxLimit", "<", "$", "limit", ")", "{", "$", "value", "=", "$", "maxLimit", ";", "}", "ini_set", "(", "'memory_limit'", ",", "$", "value", ".", "'M'", ")", ";", "return", "$", "limit", "==", "$", "value", ";", "}" ]
Sets the memory limit in megabytes Does not lower the limit. Considers maximum value constrained by suhosin. @param int limit in Megabytes @return bool Whether setting limit was successful
[ "Sets", "the", "memory", "limit", "in", "megabytes" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/MemoryLimit.php#L14-L30
koala-framework/koala-framework
Kwf/Component/Abstract/ContentSender/Abstract.php
Kwf_Component_Abstract_ContentSender_Abstract.__getProcessInputComponents
public static function __getProcessInputComponents($data) { $showInvisible = Kwf_Component_Data_Root::getShowInvisible(); $cacheId = 'procI-'.$data->componentId; $success = false; if (!$showInvisible) { //don't cache in preview $cacheContents = Kwf_Cache_Simple::fetch($cacheId, $success); //cache is cleared in Kwf_Component_Events_ProcessInputCache } if (!$success) { $datas = array(); foreach (self::_findProcessInputComponents($data) as $p) { $plugins = array(); $c = $p; do { foreach ($c->getPlugins('Kwf_Component_Plugin_Interface_SkipProcessInput') as $i) { $plugins[] = array( 'pluginClass' => $i, 'componentId' => $c->componentId ); } $isPage = $c->isPage; $c = $c->parent; } while ($c && !$isPage); $datas[] = array( 'data' => $p, 'plugins' => $plugins, ); } if (!$showInvisible) { $cacheContents = array(); foreach ($datas as $p) { $cacheContents[] = array( 'data' => $p['data']->kwfSerialize(), 'plugins' => $p['plugins'], ); } Kwf_Cache_Simple::add($cacheId, $cacheContents); } } else { $datas = array(); foreach ($cacheContents as $d) { $datas[] = array( 'data' => Kwf_Component_Data::kwfUnserialize($d['data']), 'plugins' => $d['plugins'], ); } } //ask SkipProcessInput plugins if it should be skipped //evaluated every time $process = array(); foreach ($datas as $d) { foreach ($d['plugins'] as $p) { $plugin = Kwf_Component_Plugin_Abstract::getInstance($p['pluginClass'], $p['componentId']); if ($plugin->skipProcessInput($d['data'])) { continue 2; } } $process[] = $d['data']; } return $process; }
php
public static function __getProcessInputComponents($data) { $showInvisible = Kwf_Component_Data_Root::getShowInvisible(); $cacheId = 'procI-'.$data->componentId; $success = false; if (!$showInvisible) { //don't cache in preview $cacheContents = Kwf_Cache_Simple::fetch($cacheId, $success); //cache is cleared in Kwf_Component_Events_ProcessInputCache } if (!$success) { $datas = array(); foreach (self::_findProcessInputComponents($data) as $p) { $plugins = array(); $c = $p; do { foreach ($c->getPlugins('Kwf_Component_Plugin_Interface_SkipProcessInput') as $i) { $plugins[] = array( 'pluginClass' => $i, 'componentId' => $c->componentId ); } $isPage = $c->isPage; $c = $c->parent; } while ($c && !$isPage); $datas[] = array( 'data' => $p, 'plugins' => $plugins, ); } if (!$showInvisible) { $cacheContents = array(); foreach ($datas as $p) { $cacheContents[] = array( 'data' => $p['data']->kwfSerialize(), 'plugins' => $p['plugins'], ); } Kwf_Cache_Simple::add($cacheId, $cacheContents); } } else { $datas = array(); foreach ($cacheContents as $d) { $datas[] = array( 'data' => Kwf_Component_Data::kwfUnserialize($d['data']), 'plugins' => $d['plugins'], ); } } //ask SkipProcessInput plugins if it should be skipped //evaluated every time $process = array(); foreach ($datas as $d) { foreach ($d['plugins'] as $p) { $plugin = Kwf_Component_Plugin_Abstract::getInstance($p['pluginClass'], $p['componentId']); if ($plugin->skipProcessInput($d['data'])) { continue 2; } } $process[] = $d['data']; } return $process; }
[ "public", "static", "function", "__getProcessInputComponents", "(", "$", "data", ")", "{", "$", "showInvisible", "=", "Kwf_Component_Data_Root", "::", "getShowInvisible", "(", ")", ";", "$", "cacheId", "=", "'procI-'", ".", "$", "data", "->", "componentId", ";", "$", "success", "=", "false", ";", "if", "(", "!", "$", "showInvisible", ")", "{", "//don't cache in preview", "$", "cacheContents", "=", "Kwf_Cache_Simple", "::", "fetch", "(", "$", "cacheId", ",", "$", "success", ")", ";", "//cache is cleared in Kwf_Component_Events_ProcessInputCache", "}", "if", "(", "!", "$", "success", ")", "{", "$", "datas", "=", "array", "(", ")", ";", "foreach", "(", "self", "::", "_findProcessInputComponents", "(", "$", "data", ")", "as", "$", "p", ")", "{", "$", "plugins", "=", "array", "(", ")", ";", "$", "c", "=", "$", "p", ";", "do", "{", "foreach", "(", "$", "c", "->", "getPlugins", "(", "'Kwf_Component_Plugin_Interface_SkipProcessInput'", ")", "as", "$", "i", ")", "{", "$", "plugins", "[", "]", "=", "array", "(", "'pluginClass'", "=>", "$", "i", ",", "'componentId'", "=>", "$", "c", "->", "componentId", ")", ";", "}", "$", "isPage", "=", "$", "c", "->", "isPage", ";", "$", "c", "=", "$", "c", "->", "parent", ";", "}", "while", "(", "$", "c", "&&", "!", "$", "isPage", ")", ";", "$", "datas", "[", "]", "=", "array", "(", "'data'", "=>", "$", "p", ",", "'plugins'", "=>", "$", "plugins", ",", ")", ";", "}", "if", "(", "!", "$", "showInvisible", ")", "{", "$", "cacheContents", "=", "array", "(", ")", ";", "foreach", "(", "$", "datas", "as", "$", "p", ")", "{", "$", "cacheContents", "[", "]", "=", "array", "(", "'data'", "=>", "$", "p", "[", "'data'", "]", "->", "kwfSerialize", "(", ")", ",", "'plugins'", "=>", "$", "p", "[", "'plugins'", "]", ",", ")", ";", "}", "Kwf_Cache_Simple", "::", "add", "(", "$", "cacheId", ",", "$", "cacheContents", ")", ";", "}", "}", "else", "{", "$", "datas", "=", "array", "(", ")", ";", "foreach", "(", "$", "cacheContents", "as", "$", "d", ")", "{", "$", "datas", "[", "]", "=", "array", "(", "'data'", "=>", "Kwf_Component_Data", "::", "kwfUnserialize", "(", "$", "d", "[", "'data'", "]", ")", ",", "'plugins'", "=>", "$", "d", "[", "'plugins'", "]", ",", ")", ";", "}", "}", "//ask SkipProcessInput plugins if it should be skipped", "//evaluated every time", "$", "process", "=", "array", "(", ")", ";", "foreach", "(", "$", "datas", "as", "$", "d", ")", "{", "foreach", "(", "$", "d", "[", "'plugins'", "]", "as", "$", "p", ")", "{", "$", "plugin", "=", "Kwf_Component_Plugin_Abstract", "::", "getInstance", "(", "$", "p", "[", "'pluginClass'", "]", ",", "$", "p", "[", "'componentId'", "]", ")", ";", "if", "(", "$", "plugin", "->", "skipProcessInput", "(", "$", "d", "[", "'data'", "]", ")", ")", "{", "continue", "2", ";", "}", "}", "$", "process", "[", "]", "=", "$", "d", "[", "'data'", "]", ";", "}", "return", "$", "process", ";", "}" ]
public for unittest
[ "public", "for", "unittest" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Component/Abstract/ContentSender/Abstract.php#L41-L104
koala-framework/koala-framework
Kwf/Util/Https.php
Kwf_Util_Https.domainSupportsHttps
public static function domainSupportsHttps($domain) { if (Kwf_Config::getValue('server.https') === true) { if ($domains = Kwf_Config::getValueArray('server.httpsDomains')) { if ($domains && !in_array($domain, $domains)) { foreach ($domains as $d) { if (substr($d, 0, 2) == '*.') { if (substr($d, 1) == substr($domain, strpos($domain, '.'))) { return true; } } } return false; //current host is not in server.httpsDomains, don't use https } } return true; } return false; }
php
public static function domainSupportsHttps($domain) { if (Kwf_Config::getValue('server.https') === true) { if ($domains = Kwf_Config::getValueArray('server.httpsDomains')) { if ($domains && !in_array($domain, $domains)) { foreach ($domains as $d) { if (substr($d, 0, 2) == '*.') { if (substr($d, 1) == substr($domain, strpos($domain, '.'))) { return true; } } } return false; //current host is not in server.httpsDomains, don't use https } } return true; } return false; }
[ "public", "static", "function", "domainSupportsHttps", "(", "$", "domain", ")", "{", "if", "(", "Kwf_Config", "::", "getValue", "(", "'server.https'", ")", "===", "true", ")", "{", "if", "(", "$", "domains", "=", "Kwf_Config", "::", "getValueArray", "(", "'server.httpsDomains'", ")", ")", "{", "if", "(", "$", "domains", "&&", "!", "in_array", "(", "$", "domain", ",", "$", "domains", ")", ")", "{", "foreach", "(", "$", "domains", "as", "$", "d", ")", "{", "if", "(", "substr", "(", "$", "d", ",", "0", ",", "2", ")", "==", "'*.'", ")", "{", "if", "(", "substr", "(", "$", "d", ",", "1", ")", "==", "substr", "(", "$", "domain", ",", "strpos", "(", "$", "domain", ",", "'.'", ")", ")", ")", "{", "return", "true", ";", "}", "}", "}", "return", "false", ";", "//current host is not in server.httpsDomains, don't use https", "}", "}", "return", "true", ";", "}", "return", "false", ";", "}" ]
Returns if the current request would support https and ensureHttps() would redirect to https
[ "Returns", "if", "the", "current", "request", "would", "support", "https", "and", "ensureHttps", "()", "would", "redirect", "to", "https" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Https.php#L15-L33
koala-framework/koala-framework
Kwf/Form/Field/ComboBoxFilter.php
Kwf_Form_Field_ComboBoxFilter.getMetaData
public function getMetaData($model) { $ret = parent::getMetaData($model); $saveCombo = $this->getFilteredCombo(); $saveMetaData = $saveCombo->getMetaData($model); $filterMetaData = $ret; $filterMetaData['xtype'] = 'combobox'; if (!$saveCombo->getFilterField()) { throw new Kwf_Exception("setFilterField(str) must be called for the save-combo-box"); } $data = $saveCombo->getValues(); if (is_array($data)) { $saveMetaData['store']['data'] = array(); foreach ($data as $k=>$i) { $addArray = array(); foreach ($i as $i2) { $addArray[] = $i2; } $saveMetaData['store']['data'][] = $addArray; } } $ret['items'] = array( $filterMetaData, $saveMetaData ); return $ret; }
php
public function getMetaData($model) { $ret = parent::getMetaData($model); $saveCombo = $this->getFilteredCombo(); $saveMetaData = $saveCombo->getMetaData($model); $filterMetaData = $ret; $filterMetaData['xtype'] = 'combobox'; if (!$saveCombo->getFilterField()) { throw new Kwf_Exception("setFilterField(str) must be called for the save-combo-box"); } $data = $saveCombo->getValues(); if (is_array($data)) { $saveMetaData['store']['data'] = array(); foreach ($data as $k=>$i) { $addArray = array(); foreach ($i as $i2) { $addArray[] = $i2; } $saveMetaData['store']['data'][] = $addArray; } } $ret['items'] = array( $filterMetaData, $saveMetaData ); return $ret; }
[ "public", "function", "getMetaData", "(", "$", "model", ")", "{", "$", "ret", "=", "parent", "::", "getMetaData", "(", "$", "model", ")", ";", "$", "saveCombo", "=", "$", "this", "->", "getFilteredCombo", "(", ")", ";", "$", "saveMetaData", "=", "$", "saveCombo", "->", "getMetaData", "(", "$", "model", ")", ";", "$", "filterMetaData", "=", "$", "ret", ";", "$", "filterMetaData", "[", "'xtype'", "]", "=", "'combobox'", ";", "if", "(", "!", "$", "saveCombo", "->", "getFilterField", "(", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"setFilterField(str) must be called for the save-combo-box\"", ")", ";", "}", "$", "data", "=", "$", "saveCombo", "->", "getValues", "(", ")", ";", "if", "(", "is_array", "(", "$", "data", ")", ")", "{", "$", "saveMetaData", "[", "'store'", "]", "[", "'data'", "]", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "k", "=>", "$", "i", ")", "{", "$", "addArray", "=", "array", "(", ")", ";", "foreach", "(", "$", "i", "as", "$", "i2", ")", "{", "$", "addArray", "[", "]", "=", "$", "i2", ";", "}", "$", "saveMetaData", "[", "'store'", "]", "[", "'data'", "]", "[", "]", "=", "$", "addArray", ";", "}", "}", "$", "ret", "[", "'items'", "]", "=", "array", "(", "$", "filterMetaData", ",", "$", "saveMetaData", ")", ";", "return", "$", "ret", ";", "}" ]
setFilteredCombo(combo)
[ "setFilteredCombo", "(", "combo", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Form/Field/ComboBoxFilter.php#L21-L53
koala-framework/koala-framework
Kwf/Util/ProgressBar/Adapter/Cache.php
Kwf_Util_ProgressBar_Adapter_Cache.notify
public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text) { //lastWrittenPercent and lastWrittenTime are used to prevent performance issues if //many progresses are written. (the filesystem access at nfs can slow that down) //we just update the progressbar if the percentage increases and //the last request was at least 500ms ago if (!$this->_lastWrittenPercent) { $this->_lastWrittenPercent = (int)($percent*100); } if (!$this->_lastWrittenTime) { $this->_lastWrittenTime = microtime(true); } if ($this->_lastWrittenPercent < (int)($percent*100) && $this->_lastWrittenTime+0.5 <= microtime(true)) { $arguments = array( 'current' => $current, 'max' => $max, 'percent' => ($percent * 100), 'timeTaken' => $timeTaken, 'timeRemaining' => $timeRemaining, 'text' => $text, 'finished' => false ); $this->_saveStatus($arguments); $this->_lastWrittenPercent = (int)($percent*100); $this->_lastWrittenTime = microtime(true); } }
php
public function notify($current, $max, $percent, $timeTaken, $timeRemaining, $text) { //lastWrittenPercent and lastWrittenTime are used to prevent performance issues if //many progresses are written. (the filesystem access at nfs can slow that down) //we just update the progressbar if the percentage increases and //the last request was at least 500ms ago if (!$this->_lastWrittenPercent) { $this->_lastWrittenPercent = (int)($percent*100); } if (!$this->_lastWrittenTime) { $this->_lastWrittenTime = microtime(true); } if ($this->_lastWrittenPercent < (int)($percent*100) && $this->_lastWrittenTime+0.5 <= microtime(true)) { $arguments = array( 'current' => $current, 'max' => $max, 'percent' => ($percent * 100), 'timeTaken' => $timeTaken, 'timeRemaining' => $timeRemaining, 'text' => $text, 'finished' => false ); $this->_saveStatus($arguments); $this->_lastWrittenPercent = (int)($percent*100); $this->_lastWrittenTime = microtime(true); } }
[ "public", "function", "notify", "(", "$", "current", ",", "$", "max", ",", "$", "percent", ",", "$", "timeTaken", ",", "$", "timeRemaining", ",", "$", "text", ")", "{", "//lastWrittenPercent and lastWrittenTime are used to prevent performance issues if", "//many progresses are written. (the filesystem access at nfs can slow that down)", "//we just update the progressbar if the percentage increases and", "//the last request was at least 500ms ago", "if", "(", "!", "$", "this", "->", "_lastWrittenPercent", ")", "{", "$", "this", "->", "_lastWrittenPercent", "=", "(", "int", ")", "(", "$", "percent", "*", "100", ")", ";", "}", "if", "(", "!", "$", "this", "->", "_lastWrittenTime", ")", "{", "$", "this", "->", "_lastWrittenTime", "=", "microtime", "(", "true", ")", ";", "}", "if", "(", "$", "this", "->", "_lastWrittenPercent", "<", "(", "int", ")", "(", "$", "percent", "*", "100", ")", "&&", "$", "this", "->", "_lastWrittenTime", "+", "0.5", "<=", "microtime", "(", "true", ")", ")", "{", "$", "arguments", "=", "array", "(", "'current'", "=>", "$", "current", ",", "'max'", "=>", "$", "max", ",", "'percent'", "=>", "(", "$", "percent", "*", "100", ")", ",", "'timeTaken'", "=>", "$", "timeTaken", ",", "'timeRemaining'", "=>", "$", "timeRemaining", ",", "'text'", "=>", "$", "text", ",", "'finished'", "=>", "false", ")", ";", "$", "this", "->", "_saveStatus", "(", "$", "arguments", ")", ";", "$", "this", "->", "_lastWrittenPercent", "=", "(", "int", ")", "(", "$", "percent", "*", "100", ")", ";", "$", "this", "->", "_lastWrittenTime", "=", "microtime", "(", "true", ")", ";", "}", "}" ]
the following methods must be overwritten
[ "the", "following", "methods", "must", "be", "overwritten" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/ProgressBar/Adapter/Cache.php#L60-L87
koala-framework/koala-framework
Kwf/Rest/Controller/Model.php
Kwf_Rest_Controller_Model.indexAction
public function indexAction() { $this->view->data = array(); $s = $this->_getSelectIndex(); if ($this->_loadColumns) { foreach ($this->_loadColumns as $c) { $s->expr($c); } } foreach ($this->_model->getRows($s) as $row) { $this->view->data[] = $this->_loadDataFromRow($row); } $this->view->total = $this->_model->countRows($s); }
php
public function indexAction() { $this->view->data = array(); $s = $this->_getSelectIndex(); if ($this->_loadColumns) { foreach ($this->_loadColumns as $c) { $s->expr($c); } } foreach ($this->_model->getRows($s) as $row) { $this->view->data[] = $this->_loadDataFromRow($row); } $this->view->total = $this->_model->countRows($s); }
[ "public", "function", "indexAction", "(", ")", "{", "$", "this", "->", "view", "->", "data", "=", "array", "(", ")", ";", "$", "s", "=", "$", "this", "->", "_getSelectIndex", "(", ")", ";", "if", "(", "$", "this", "->", "_loadColumns", ")", "{", "foreach", "(", "$", "this", "->", "_loadColumns", "as", "$", "c", ")", "{", "$", "s", "->", "expr", "(", "$", "c", ")", ";", "}", "}", "foreach", "(", "$", "this", "->", "_model", "->", "getRows", "(", "$", "s", ")", "as", "$", "row", ")", "{", "$", "this", "->", "view", "->", "data", "[", "]", "=", "$", "this", "->", "_loadDataFromRow", "(", "$", "row", ")", ";", "}", "$", "this", "->", "view", "->", "total", "=", "$", "this", "->", "_model", "->", "countRows", "(", "$", "s", ")", ";", "}" ]
Handle GET and return a list of resources
[ "Handle", "GET", "and", "return", "a", "list", "of", "resources" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Rest/Controller/Model.php#L174-L187
koala-framework/koala-framework
Kwf/Rest/Controller/Model.php
Kwf_Rest_Controller_Model.getAction
public function getAction() { $s = $this->_getSelect(); if ($this->_loadColumns) { foreach ($this->_loadColumns as $c) { $s->expr($c); } } $s->whereId($this->_getParam('id')); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->view->data = $this->_loadDataFromRow($row); }
php
public function getAction() { $s = $this->_getSelect(); if ($this->_loadColumns) { foreach ($this->_loadColumns as $c) { $s->expr($c); } } $s->whereId($this->_getParam('id')); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->view->data = $this->_loadDataFromRow($row); }
[ "public", "function", "getAction", "(", ")", "{", "$", "s", "=", "$", "this", "->", "_getSelect", "(", ")", ";", "if", "(", "$", "this", "->", "_loadColumns", ")", "{", "foreach", "(", "$", "this", "->", "_loadColumns", "as", "$", "c", ")", "{", "$", "s", "->", "expr", "(", "$", "c", ")", ";", "}", "}", "$", "s", "->", "whereId", "(", "$", "this", "->", "_getParam", "(", "'id'", ")", ")", ";", "$", "row", "=", "$", "this", "->", "_model", "->", "getRow", "(", "$", "s", ")", ";", "if", "(", "!", "$", "row", ")", "throw", "new", "Kwf_Exception_NotFound", "(", ")", ";", "$", "this", "->", "view", "->", "data", "=", "$", "this", "->", "_loadDataFromRow", "(", "$", "row", ")", ";", "}" ]
Handle GET and return a specific resource item
[ "Handle", "GET", "and", "return", "a", "specific", "resource", "item" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Rest/Controller/Model.php#L190-L202
koala-framework/koala-framework
Kwf/Rest/Controller/Model.php
Kwf_Rest_Controller_Model.postAction
public function postAction() { $data = json_decode($this->getRequest()->getRawBody()); if (!is_array($data)) $data = array($data); $ret = array(); foreach ($data as $d) { $row = $this->_model->createRow(); if (isset($d->id) && $d->id) { $row->id = $d->id; } $this->_validateInsert((array)$d); $this->_validateSave((array)$d); $this->_fillRowInsert($row, $d); $this->_beforeInsert($row); $this->_beforeSave($row); $row->save(); $this->_afterSave($row, $d); $this->_afterInsert($row, $d); $ret[] = $this->_loadDataFromRow($row); } if (count($ret) == 1) $ret = reset($ret); $this->view->data = $ret; }
php
public function postAction() { $data = json_decode($this->getRequest()->getRawBody()); if (!is_array($data)) $data = array($data); $ret = array(); foreach ($data as $d) { $row = $this->_model->createRow(); if (isset($d->id) && $d->id) { $row->id = $d->id; } $this->_validateInsert((array)$d); $this->_validateSave((array)$d); $this->_fillRowInsert($row, $d); $this->_beforeInsert($row); $this->_beforeSave($row); $row->save(); $this->_afterSave($row, $d); $this->_afterInsert($row, $d); $ret[] = $this->_loadDataFromRow($row); } if (count($ret) == 1) $ret = reset($ret); $this->view->data = $ret; }
[ "public", "function", "postAction", "(", ")", "{", "$", "data", "=", "json_decode", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getRawBody", "(", ")", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "$", "data", "=", "array", "(", "$", "data", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "d", ")", "{", "$", "row", "=", "$", "this", "->", "_model", "->", "createRow", "(", ")", ";", "if", "(", "isset", "(", "$", "d", "->", "id", ")", "&&", "$", "d", "->", "id", ")", "{", "$", "row", "->", "id", "=", "$", "d", "->", "id", ";", "}", "$", "this", "->", "_validateInsert", "(", "(", "array", ")", "$", "d", ")", ";", "$", "this", "->", "_validateSave", "(", "(", "array", ")", "$", "d", ")", ";", "$", "this", "->", "_fillRowInsert", "(", "$", "row", ",", "$", "d", ")", ";", "$", "this", "->", "_beforeInsert", "(", "$", "row", ")", ";", "$", "this", "->", "_beforeSave", "(", "$", "row", ")", ";", "$", "row", "->", "save", "(", ")", ";", "$", "this", "->", "_afterSave", "(", "$", "row", ",", "$", "d", ")", ";", "$", "this", "->", "_afterInsert", "(", "$", "row", ",", "$", "d", ")", ";", "$", "ret", "[", "]", "=", "$", "this", "->", "_loadDataFromRow", "(", "$", "row", ")", ";", "}", "if", "(", "count", "(", "$", "ret", ")", "==", "1", ")", "$", "ret", "=", "reset", "(", "$", "ret", ")", ";", "$", "this", "->", "view", "->", "data", "=", "$", "ret", ";", "}" ]
Handle POST requests to create a new resource item
[ "Handle", "POST", "requests", "to", "create", "a", "new", "resource", "item" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Rest/Controller/Model.php#L205-L231
koala-framework/koala-framework
Kwf/Rest/Controller/Model.php
Kwf_Rest_Controller_Model.putAction
public function putAction() { $data = json_decode($this->getRequest()->getRawBody()); if (!is_array($data)) $data = array($data); $ret = array(); foreach ($data as $d) { $s = $this->_getSelect(); $s->whereId($d->id); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->_validateUpdate((array)$d); $this->_validateSave((array)$d); $this->_fillRow($row, $d); $this->_beforeUpdate($row); $this->_beforeSave($row); $row->save(); $this->_afterSave($row, $d); $this->_afterUpdate($row, $d); $ret[] = $this->_loadDataFromRow($row); } if (count($ret) == 1) $ret = reset($ret); $this->view->data = $ret; }
php
public function putAction() { $data = json_decode($this->getRequest()->getRawBody()); if (!is_array($data)) $data = array($data); $ret = array(); foreach ($data as $d) { $s = $this->_getSelect(); $s->whereId($d->id); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->_validateUpdate((array)$d); $this->_validateSave((array)$d); $this->_fillRow($row, $d); $this->_beforeUpdate($row); $this->_beforeSave($row); $row->save(); $this->_afterSave($row, $d); $this->_afterUpdate($row, $d); $ret[] = $this->_loadDataFromRow($row); } if (count($ret) == 1) $ret = reset($ret); $this->view->data = $ret; }
[ "public", "function", "putAction", "(", ")", "{", "$", "data", "=", "json_decode", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getRawBody", "(", ")", ")", ";", "if", "(", "!", "is_array", "(", "$", "data", ")", ")", "$", "data", "=", "array", "(", "$", "data", ")", ";", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "as", "$", "d", ")", "{", "$", "s", "=", "$", "this", "->", "_getSelect", "(", ")", ";", "$", "s", "->", "whereId", "(", "$", "d", "->", "id", ")", ";", "$", "row", "=", "$", "this", "->", "_model", "->", "getRow", "(", "$", "s", ")", ";", "if", "(", "!", "$", "row", ")", "throw", "new", "Kwf_Exception_NotFound", "(", ")", ";", "$", "this", "->", "_validateUpdate", "(", "(", "array", ")", "$", "d", ")", ";", "$", "this", "->", "_validateSave", "(", "(", "array", ")", "$", "d", ")", ";", "$", "this", "->", "_fillRow", "(", "$", "row", ",", "$", "d", ")", ";", "$", "this", "->", "_beforeUpdate", "(", "$", "row", ")", ";", "$", "this", "->", "_beforeSave", "(", "$", "row", ")", ";", "$", "row", "->", "save", "(", ")", ";", "$", "this", "->", "_afterSave", "(", "$", "row", ",", "$", "d", ")", ";", "$", "this", "->", "_afterUpdate", "(", "$", "row", ",", "$", "d", ")", ";", "$", "ret", "[", "]", "=", "$", "this", "->", "_loadDataFromRow", "(", "$", "row", ")", ";", "}", "if", "(", "count", "(", "$", "ret", ")", "==", "1", ")", "$", "ret", "=", "reset", "(", "$", "ret", ")", ";", "$", "this", "->", "view", "->", "data", "=", "$", "ret", ";", "}" ]
Handle PUT requests to update a specific resource item
[ "Handle", "PUT", "requests", "to", "update", "a", "specific", "resource", "item" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Rest/Controller/Model.php#L255-L281
koala-framework/koala-framework
Kwf/Rest/Controller/Model.php
Kwf_Rest_Controller_Model.deleteAction
public function deleteAction() { $s = $this->_getSelect(); $s->whereId($this->_getParam('id')); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->_beforeDelete($row); $row->delete(); }
php
public function deleteAction() { $s = $this->_getSelect(); $s->whereId($this->_getParam('id')); $row = $this->_model->getRow($s); if (!$row) throw new Kwf_Exception_NotFound(); $this->_beforeDelete($row); $row->delete(); }
[ "public", "function", "deleteAction", "(", ")", "{", "$", "s", "=", "$", "this", "->", "_getSelect", "(", ")", ";", "$", "s", "->", "whereId", "(", "$", "this", "->", "_getParam", "(", "'id'", ")", ")", ";", "$", "row", "=", "$", "this", "->", "_model", "->", "getRow", "(", "$", "s", ")", ";", "if", "(", "!", "$", "row", ")", "throw", "new", "Kwf_Exception_NotFound", "(", ")", ";", "$", "this", "->", "_beforeDelete", "(", "$", "row", ")", ";", "$", "row", "->", "delete", "(", ")", ";", "}" ]
Handle DELETE requests to delete a specific item
[ "Handle", "DELETE", "requests", "to", "delete", "a", "specific", "item" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Rest/Controller/Model.php#L284-L292
koala-framework/koala-framework
Kwc/Shop/AddToCartAbstract/OrderProductData.php
Kwc_Shop_AddToCartAbstract_OrderProductData.getAddComponentByDbId
public static function getAddComponentByDbId($dbId, $subroot) { $ret = null; $addComponents = Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($dbId); if (count($addComponents) > 1) { foreach ($addComponents as $addComponent) { if ($addComponent->getSubroot()->componentId == $subroot->getSubroot()->componentId) { $ret = $addComponent; break; } } } else if (count($addComponents) == 1) { $ret = $addComponents[0]; } return $ret; }
php
public static function getAddComponentByDbId($dbId, $subroot) { $ret = null; $addComponents = Kwf_Component_Data_Root::getInstance()->getComponentsByDbId($dbId); if (count($addComponents) > 1) { foreach ($addComponents as $addComponent) { if ($addComponent->getSubroot()->componentId == $subroot->getSubroot()->componentId) { $ret = $addComponent; break; } } } else if (count($addComponents) == 1) { $ret = $addComponents[0]; } return $ret; }
[ "public", "static", "function", "getAddComponentByDbId", "(", "$", "dbId", ",", "$", "subroot", ")", "{", "$", "ret", "=", "null", ";", "$", "addComponents", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentsByDbId", "(", "$", "dbId", ")", ";", "if", "(", "count", "(", "$", "addComponents", ")", ">", "1", ")", "{", "foreach", "(", "$", "addComponents", "as", "$", "addComponent", ")", "{", "if", "(", "$", "addComponent", "->", "getSubroot", "(", ")", "->", "componentId", "==", "$", "subroot", "->", "getSubroot", "(", ")", "->", "componentId", ")", "{", "$", "ret", "=", "$", "addComponent", ";", "break", ";", "}", "}", "}", "else", "if", "(", "count", "(", "$", "addComponents", ")", "==", "1", ")", "{", "$", "ret", "=", "$", "addComponents", "[", "0", "]", ";", "}", "return", "$", "ret", ";", "}" ]
This method is needed to support: multiple domain web where domains share products (getComponentsByDbId returns multiple, correct one is selected based on $subroot) trl web where translated version of product has own db_id but lives in a different subroot (the $subroot won't be used in that case)
[ "This", "method", "is", "needed", "to", "support", ":" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Shop/AddToCartAbstract/OrderProductData.php#L47-L64
koala-framework/koala-framework
Kwc/Directories/List/Component.php
Kwc_Directories_List_Component._getParentItemDirectoryClasses
protected static function _getParentItemDirectoryClasses($componentClass, $steps = null) { $ret = array(); foreach (Kwc_Abstract::getComponentClasses() as $class) { foreach (Kwc_Abstract::getChildComponentClasses($class) as $childClass) { if ($childClass == $componentClass) { if ($steps === 0) { $ret[] = $class; } else if (is_null($steps)) { if (is_instance_of($class, 'Kwc_Directories_Item_Directory_Component')) { $ret[] = $class; } } else { $ret = array_merge( $ret, self::_getParentItemDirectoryClasses($class, $steps - 1) ); } } } } return $ret; }
php
protected static function _getParentItemDirectoryClasses($componentClass, $steps = null) { $ret = array(); foreach (Kwc_Abstract::getComponentClasses() as $class) { foreach (Kwc_Abstract::getChildComponentClasses($class) as $childClass) { if ($childClass == $componentClass) { if ($steps === 0) { $ret[] = $class; } else if (is_null($steps)) { if (is_instance_of($class, 'Kwc_Directories_Item_Directory_Component')) { $ret[] = $class; } } else { $ret = array_merge( $ret, self::_getParentItemDirectoryClasses($class, $steps - 1) ); } } } } return $ret; }
[ "protected", "static", "function", "_getParentItemDirectoryClasses", "(", "$", "componentClass", ",", "$", "steps", "=", "null", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "Kwc_Abstract", "::", "getComponentClasses", "(", ")", "as", "$", "class", ")", "{", "foreach", "(", "Kwc_Abstract", "::", "getChildComponentClasses", "(", "$", "class", ")", "as", "$", "childClass", ")", "{", "if", "(", "$", "childClass", "==", "$", "componentClass", ")", "{", "if", "(", "$", "steps", "===", "0", ")", "{", "$", "ret", "[", "]", "=", "$", "class", ";", "}", "else", "if", "(", "is_null", "(", "$", "steps", ")", ")", "{", "if", "(", "is_instance_of", "(", "$", "class", ",", "'Kwc_Directories_Item_Directory_Component'", ")", ")", "{", "$", "ret", "[", "]", "=", "$", "class", ";", "}", "}", "else", "{", "$", "ret", "=", "array_merge", "(", "$", "ret", ",", "self", "::", "_getParentItemDirectoryClasses", "(", "$", "class", ",", "$", "steps", "-", "1", ")", ")", ";", "}", "}", "}", "}", "return", "$", "ret", ";", "}" ]
abstract public static function getItemDirectoryClasses($componentClass);
[ "abstract", "public", "static", "function", "getItemDirectoryClasses", "(", "$componentClass", ")", ";" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Directories/List/Component.php#L58-L80
koala-framework/koala-framework
Kwc/Favourites/Component.php
Kwc_Favourites_Component.getFavouriteComponentIds
public static function getFavouriteComponentIds($favouritesModel) { $ret = array(); $userId = Kwf_Registry::get('userModel')->getAuthedUserId(); if ($userId) { $cacheIdUser = 'favCIds'.$userId; $ret = Kwf_Cache_Simple::fetch($cacheIdUser, $success); if (!$success) { // get all favourites related to user $select = new Kwf_Model_Select(); $select->whereEquals('user_id', $userId); $favouritesModel = Kwf_Model_Abstract::getInstance($favouritesModel); $favourites = $favouritesModel->getRows($select); $componentIds = array(); foreach ($favourites as $favourite) { $component = Kwf_Component_Data_Root::getInstance() ->getComponentById($favourite->component_id); // check if component is visible and existent if ($component) { // if component is visible create list of users related to component $componentIds[] = $component->componentId; } } // cache relation of visible components to user Kwf_Cache_Simple::add($cacheIdUser, $componentIds); $ret = $componentIds; } } return $ret; }
php
public static function getFavouriteComponentIds($favouritesModel) { $ret = array(); $userId = Kwf_Registry::get('userModel')->getAuthedUserId(); if ($userId) { $cacheIdUser = 'favCIds'.$userId; $ret = Kwf_Cache_Simple::fetch($cacheIdUser, $success); if (!$success) { // get all favourites related to user $select = new Kwf_Model_Select(); $select->whereEquals('user_id', $userId); $favouritesModel = Kwf_Model_Abstract::getInstance($favouritesModel); $favourites = $favouritesModel->getRows($select); $componentIds = array(); foreach ($favourites as $favourite) { $component = Kwf_Component_Data_Root::getInstance() ->getComponentById($favourite->component_id); // check if component is visible and existent if ($component) { // if component is visible create list of users related to component $componentIds[] = $component->componentId; } } // cache relation of visible components to user Kwf_Cache_Simple::add($cacheIdUser, $componentIds); $ret = $componentIds; } } return $ret; }
[ "public", "static", "function", "getFavouriteComponentIds", "(", "$", "favouritesModel", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "$", "userId", "=", "Kwf_Registry", "::", "get", "(", "'userModel'", ")", "->", "getAuthedUserId", "(", ")", ";", "if", "(", "$", "userId", ")", "{", "$", "cacheIdUser", "=", "'favCIds'", ".", "$", "userId", ";", "$", "ret", "=", "Kwf_Cache_Simple", "::", "fetch", "(", "$", "cacheIdUser", ",", "$", "success", ")", ";", "if", "(", "!", "$", "success", ")", "{", "// get all favourites related to user", "$", "select", "=", "new", "Kwf_Model_Select", "(", ")", ";", "$", "select", "->", "whereEquals", "(", "'user_id'", ",", "$", "userId", ")", ";", "$", "favouritesModel", "=", "Kwf_Model_Abstract", "::", "getInstance", "(", "$", "favouritesModel", ")", ";", "$", "favourites", "=", "$", "favouritesModel", "->", "getRows", "(", "$", "select", ")", ";", "$", "componentIds", "=", "array", "(", ")", ";", "foreach", "(", "$", "favourites", "as", "$", "favourite", ")", "{", "$", "component", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentById", "(", "$", "favourite", "->", "component_id", ")", ";", "// check if component is visible and existent", "if", "(", "$", "component", ")", "{", "// if component is visible create list of users related to component", "$", "componentIds", "[", "]", "=", "$", "component", "->", "componentId", ";", "}", "}", "// cache relation of visible components to user", "Kwf_Cache_Simple", "::", "add", "(", "$", "cacheIdUser", ",", "$", "componentIds", ")", ";", "$", "ret", "=", "$", "componentIds", ";", "}", "}", "return", "$", "ret", ";", "}" ]
returns a list of all visible favourite componentIds
[ "returns", "a", "list", "of", "all", "visible", "favourite", "componentIds" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Favourites/Component.php#L39-L68
koala-framework/koala-framework
Kwf/Util/Update/Helper.php
Kwf_Util_Update_Helper.getUpdateTags
public static function getUpdateTags() { if (!isset(self::$_updateTagsCache)) { self::$_updateTagsCache = Kwf_Registry::get('config')->server->updateTags->toArray(); foreach (Kwf_Component_Abstract::getComponentClasses() as $class) { if (Kwc_Abstract::hasSetting($class, 'updateTags')) { self::$_updateTagsCache = array_unique(array_merge(self::$_updateTagsCache, Kwc_Abstract::getSetting($class, 'updateTags'))); } } } return self::$_updateTagsCache; }
php
public static function getUpdateTags() { if (!isset(self::$_updateTagsCache)) { self::$_updateTagsCache = Kwf_Registry::get('config')->server->updateTags->toArray(); foreach (Kwf_Component_Abstract::getComponentClasses() as $class) { if (Kwc_Abstract::hasSetting($class, 'updateTags')) { self::$_updateTagsCache = array_unique(array_merge(self::$_updateTagsCache, Kwc_Abstract::getSetting($class, 'updateTags'))); } } } return self::$_updateTagsCache; }
[ "public", "static", "function", "getUpdateTags", "(", ")", "{", "if", "(", "!", "isset", "(", "self", "::", "$", "_updateTagsCache", ")", ")", "{", "self", "::", "$", "_updateTagsCache", "=", "Kwf_Registry", "::", "get", "(", "'config'", ")", "->", "server", "->", "updateTags", "->", "toArray", "(", ")", ";", "foreach", "(", "Kwf_Component_Abstract", "::", "getComponentClasses", "(", ")", "as", "$", "class", ")", "{", "if", "(", "Kwc_Abstract", "::", "hasSetting", "(", "$", "class", ",", "'updateTags'", ")", ")", "{", "self", "::", "$", "_updateTagsCache", "=", "array_unique", "(", "array_merge", "(", "self", "::", "$", "_updateTagsCache", ",", "Kwc_Abstract", "::", "getSetting", "(", "$", "class", ",", "'updateTags'", ")", ")", ")", ";", "}", "}", "}", "return", "self", "::", "$", "_updateTagsCache", ";", "}" ]
Returns all udpate tags used by this webs. They are usually set in config.ini
[ "Returns", "all", "udpate", "tags", "used", "by", "this", "webs", ".", "They", "are", "usually", "set", "in", "config", ".", "ini" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Update/Helper.php#L19-L30
koala-framework/koala-framework
Kwc/Directories/Item/Detail/AssignedCategories/Component.php
Kwc_Directories_Item_Detail_AssignedCategories_Component.getSelect
public function getSelect() { $ret = parent::getSelect(); $categoryDirectory = $this->getItemDirectory()->getComponent(); $refData = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData( Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'), 'Category' ); $ret->join($refData['tableName'], "{$refData['refTableName']}.{$refData['refItemColumn']} = " ."{$refData['tableName']}.{$refData['itemColumn']}", array() ); $refDataItem = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData( Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'), 'Item' ); $ret->where( $refDataItem['tableName'].'.'.$refDataItem['itemColumn'].' = ?', $this->_getItemDetail()->row->id ); return $ret; }
php
public function getSelect() { $ret = parent::getSelect(); $categoryDirectory = $this->getItemDirectory()->getComponent(); $refData = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData( Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'), 'Category' ); $ret->join($refData['tableName'], "{$refData['refTableName']}.{$refData['refItemColumn']} = " ."{$refData['tableName']}.{$refData['itemColumn']}", array() ); $refDataItem = Kwc_Directories_Category_Detail_List_Component::getTableReferenceData( Kwc_Abstract::getSetting(get_class($categoryDirectory), 'categoryToItemModelName'), 'Item' ); $ret->where( $refDataItem['tableName'].'.'.$refDataItem['itemColumn'].' = ?', $this->_getItemDetail()->row->id ); return $ret; }
[ "public", "function", "getSelect", "(", ")", "{", "$", "ret", "=", "parent", "::", "getSelect", "(", ")", ";", "$", "categoryDirectory", "=", "$", "this", "->", "getItemDirectory", "(", ")", "->", "getComponent", "(", ")", ";", "$", "refData", "=", "Kwc_Directories_Category_Detail_List_Component", "::", "getTableReferenceData", "(", "Kwc_Abstract", "::", "getSetting", "(", "get_class", "(", "$", "categoryDirectory", ")", ",", "'categoryToItemModelName'", ")", ",", "'Category'", ")", ";", "$", "ret", "->", "join", "(", "$", "refData", "[", "'tableName'", "]", ",", "\"{$refData['refTableName']}.{$refData['refItemColumn']} = \"", ".", "\"{$refData['tableName']}.{$refData['itemColumn']}\"", ",", "array", "(", ")", ")", ";", "$", "refDataItem", "=", "Kwc_Directories_Category_Detail_List_Component", "::", "getTableReferenceData", "(", "Kwc_Abstract", "::", "getSetting", "(", "get_class", "(", "$", "categoryDirectory", ")", ",", "'categoryToItemModelName'", ")", ",", "'Item'", ")", ";", "$", "ret", "->", "where", "(", "$", "refDataItem", "[", "'tableName'", "]", ".", "'.'", ".", "$", "refDataItem", "[", "'itemColumn'", "]", ".", "' = ?'", ",", "$", "this", "->", "_getItemDetail", "(", ")", "->", "row", "->", "id", ")", ";", "return", "$", "ret", ";", "}" ]
/* public function getCacheVars() { return $this->getData()->getChildComponent('-view')->getComponent()->getCacheVars(); }
[ "/", "*", "public", "function", "getCacheVars", "()", "{", "return", "$this", "-", ">", "getData", "()", "-", ">", "getChildComponent", "(", "-", "view", ")", "-", ">", "getComponent", "()", "-", ">", "getCacheVars", "()", ";", "}" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Directories/Item/Detail/AssignedCategories/Component.php#L43-L69
koala-framework/koala-framework
Kwc/Basic/LinkTag/Intern/Trl/DataAbstract.php
Kwc_Basic_LinkTag_Intern_Trl_DataAbstract.getLinkedData
public final function getLinkedData() { if (!isset($this->_data)) { $masterLinkData = $this->chained->getLinkedData(array('ignoreVisible'=>true)); if (!$masterLinkData) $this->_data = false; if ($masterLinkData) { if (is_null($this->_type)) throw new Kwf_Exception("_type may not be null"); if ($this->_type == 'Trl') { $linkComponent = Kwc_Chained_Trl_Component::getChainedByMaster($masterLinkData, $this); } else if ($this->_type == 'Cc') { $linkComponent = Kwc_Chained_Cc_Component::getChainedByMaster($masterLinkData, $this); } if (!$linkComponent) { $this->_data = false; //kann offline sein } else { $this->_data = $linkComponent; } } } $chained = $this->chained; while (isset($chained->chained)) $chained = $chained->chained; $m = Kwc_Abstract::createModel($chained->componentClass); $result = $m->fetchColumnsByPrimaryId(array('anchor'), $chained->dbId); if ($result['anchor']) $this->_anchor = $result['anchor']; return $this->_data; }
php
public final function getLinkedData() { if (!isset($this->_data)) { $masterLinkData = $this->chained->getLinkedData(array('ignoreVisible'=>true)); if (!$masterLinkData) $this->_data = false; if ($masterLinkData) { if (is_null($this->_type)) throw new Kwf_Exception("_type may not be null"); if ($this->_type == 'Trl') { $linkComponent = Kwc_Chained_Trl_Component::getChainedByMaster($masterLinkData, $this); } else if ($this->_type == 'Cc') { $linkComponent = Kwc_Chained_Cc_Component::getChainedByMaster($masterLinkData, $this); } if (!$linkComponent) { $this->_data = false; //kann offline sein } else { $this->_data = $linkComponent; } } } $chained = $this->chained; while (isset($chained->chained)) $chained = $chained->chained; $m = Kwc_Abstract::createModel($chained->componentClass); $result = $m->fetchColumnsByPrimaryId(array('anchor'), $chained->dbId); if ($result['anchor']) $this->_anchor = $result['anchor']; return $this->_data; }
[ "public", "final", "function", "getLinkedData", "(", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_data", ")", ")", "{", "$", "masterLinkData", "=", "$", "this", "->", "chained", "->", "getLinkedData", "(", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "if", "(", "!", "$", "masterLinkData", ")", "$", "this", "->", "_data", "=", "false", ";", "if", "(", "$", "masterLinkData", ")", "{", "if", "(", "is_null", "(", "$", "this", "->", "_type", ")", ")", "throw", "new", "Kwf_Exception", "(", "\"_type may not be null\"", ")", ";", "if", "(", "$", "this", "->", "_type", "==", "'Trl'", ")", "{", "$", "linkComponent", "=", "Kwc_Chained_Trl_Component", "::", "getChainedByMaster", "(", "$", "masterLinkData", ",", "$", "this", ")", ";", "}", "else", "if", "(", "$", "this", "->", "_type", "==", "'Cc'", ")", "{", "$", "linkComponent", "=", "Kwc_Chained_Cc_Component", "::", "getChainedByMaster", "(", "$", "masterLinkData", ",", "$", "this", ")", ";", "}", "if", "(", "!", "$", "linkComponent", ")", "{", "$", "this", "->", "_data", "=", "false", ";", "//kann offline sein", "}", "else", "{", "$", "this", "->", "_data", "=", "$", "linkComponent", ";", "}", "}", "}", "$", "chained", "=", "$", "this", "->", "chained", ";", "while", "(", "isset", "(", "$", "chained", "->", "chained", ")", ")", "$", "chained", "=", "$", "chained", "->", "chained", ";", "$", "m", "=", "Kwc_Abstract", "::", "createModel", "(", "$", "chained", "->", "componentClass", ")", ";", "$", "result", "=", "$", "m", "->", "fetchColumnsByPrimaryId", "(", "array", "(", "'anchor'", ")", ",", "$", "chained", "->", "dbId", ")", ";", "if", "(", "$", "result", "[", "'anchor'", "]", ")", "$", "this", "->", "_anchor", "=", "$", "result", "[", "'anchor'", "]", ";", "return", "$", "this", "->", "_data", ";", "}" ]
'cc' oder 'trl'
[ "cc", "oder", "trl" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/LinkTag/Intern/Trl/DataAbstract.php#L8-L36
koala-framework/koala-framework
Kwf/Trl.php
Kwf_Trl._findElementPlural
protected function _findElementPlural($needle, $plural, $source, $context = '', $language = null) { if ($language) $target = $language; else $target = $this->getTargetLanguage(); $cacheId = 'trlp-'.$source.'-'.$target.'-'.$plural.'-'.$context; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } if (!isset($this->_trlElements[$source][$target.'_plural'])) { $this->_loadTrlElements($source, $target, true); } if (isset($this->_trlElements[$source][$target.'_plural'][$plural.'-'.$context])) { $ret = $this->_trlElements[$source][$target.'_plural'][$plural.'-'.$context]; } else { $ret = $plural; } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
php
protected function _findElementPlural($needle, $plural, $source, $context = '', $language = null) { if ($language) $target = $language; else $target = $this->getTargetLanguage(); $cacheId = 'trlp-'.$source.'-'.$target.'-'.$plural.'-'.$context; $ret = Kwf_Cache_SimpleStatic::fetch($cacheId, $success); if ($success) { return $ret; } if (!isset($this->_trlElements[$source][$target.'_plural'])) { $this->_loadTrlElements($source, $target, true); } if (isset($this->_trlElements[$source][$target.'_plural'][$plural.'-'.$context])) { $ret = $this->_trlElements[$source][$target.'_plural'][$plural.'-'.$context]; } else { $ret = $plural; } Kwf_Cache_SimpleStatic::add($cacheId, $ret); return $ret; }
[ "protected", "function", "_findElementPlural", "(", "$", "needle", ",", "$", "plural", ",", "$", "source", ",", "$", "context", "=", "''", ",", "$", "language", "=", "null", ")", "{", "if", "(", "$", "language", ")", "$", "target", "=", "$", "language", ";", "else", "$", "target", "=", "$", "this", "->", "getTargetLanguage", "(", ")", ";", "$", "cacheId", "=", "'trlp-'", ".", "$", "source", ".", "'-'", ".", "$", "target", ".", "'-'", ".", "$", "plural", ".", "'-'", ".", "$", "context", ";", "$", "ret", "=", "Kwf_Cache_SimpleStatic", "::", "fetch", "(", "$", "cacheId", ",", "$", "success", ")", ";", "if", "(", "$", "success", ")", "{", "return", "$", "ret", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_trlElements", "[", "$", "source", "]", "[", "$", "target", ".", "'_plural'", "]", ")", ")", "{", "$", "this", "->", "_loadTrlElements", "(", "$", "source", ",", "$", "target", ",", "true", ")", ";", "}", "if", "(", "isset", "(", "$", "this", "->", "_trlElements", "[", "$", "source", "]", "[", "$", "target", ".", "'_plural'", "]", "[", "$", "plural", ".", "'-'", ".", "$", "context", "]", ")", ")", "{", "$", "ret", "=", "$", "this", "->", "_trlElements", "[", "$", "source", "]", "[", "$", "target", ".", "'_plural'", "]", "[", "$", "plural", ".", "'-'", ".", "$", "context", "]", ";", "}", "else", "{", "$", "ret", "=", "$", "plural", ";", "}", "Kwf_Cache_SimpleStatic", "::", "add", "(", "$", "cacheId", ",", "$", "ret", ")", ";", "return", "$", "ret", ";", "}" ]
TODO: wofuer wird der $needle parameter verwendet?!
[ "TODO", ":", "wofuer", "wird", "der", "$needle", "parameter", "verwendet?!" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Trl.php#L434-L455
koala-framework/koala-framework
Kwf/Util/SimpleHttpProxy.php
Kwf_Util_SimpleHttpProxy.dispatch
public static function dispatch($hostnames) { if (Kwf_Setup::getRequestPath()===false) return; if (!preg_match('#^/kwf/proxy/?$#i', Kwf_Setup::getRequestPath())) return; if (is_string($hostnames)) { $hostnames = array($hostnames); } $proxyUrl = $_REQUEST['proxyUrl']; $proxyPostVars = $_POST; $proxyGetVars = $_GET; if (array_key_exists('proxyUrl', $proxyPostVars)) unset($proxyPostVars['proxyUrl']); if (array_key_exists('proxyUrl', $proxyGetVars)) unset($proxyGetVars['proxyUrl']); // host checking $proxyHost = parse_url($proxyUrl, PHP_URL_HOST); $matched = false; foreach ($hostnames as $hostname) { if (preg_match('/^'.$hostname.'$/i', $proxyHost)) { $matched = true; break; } } if (!$matched) return; // proxying $http = new Zend_Http_Client($proxyUrl); if (count($_POST)) { $http->setMethod(Zend_Http_Client::POST); } else { $http->setMethod(Zend_Http_Client::GET); } if (count($_GET)) $http->setParameterGet($proxyGetVars); if (count($_POST)) $http->setParameterPost($proxyPostVars); $response = $http->request(); $headers = $response->getHeaders(); if ($headers && !empty($headers['Content-type'])) { header("Content-Type: ".$headers['Content-type']); } echo $response->getBody(); exit; }
php
public static function dispatch($hostnames) { if (Kwf_Setup::getRequestPath()===false) return; if (!preg_match('#^/kwf/proxy/?$#i', Kwf_Setup::getRequestPath())) return; if (is_string($hostnames)) { $hostnames = array($hostnames); } $proxyUrl = $_REQUEST['proxyUrl']; $proxyPostVars = $_POST; $proxyGetVars = $_GET; if (array_key_exists('proxyUrl', $proxyPostVars)) unset($proxyPostVars['proxyUrl']); if (array_key_exists('proxyUrl', $proxyGetVars)) unset($proxyGetVars['proxyUrl']); // host checking $proxyHost = parse_url($proxyUrl, PHP_URL_HOST); $matched = false; foreach ($hostnames as $hostname) { if (preg_match('/^'.$hostname.'$/i', $proxyHost)) { $matched = true; break; } } if (!$matched) return; // proxying $http = new Zend_Http_Client($proxyUrl); if (count($_POST)) { $http->setMethod(Zend_Http_Client::POST); } else { $http->setMethod(Zend_Http_Client::GET); } if (count($_GET)) $http->setParameterGet($proxyGetVars); if (count($_POST)) $http->setParameterPost($proxyPostVars); $response = $http->request(); $headers = $response->getHeaders(); if ($headers && !empty($headers['Content-type'])) { header("Content-Type: ".$headers['Content-type']); } echo $response->getBody(); exit; }
[ "public", "static", "function", "dispatch", "(", "$", "hostnames", ")", "{", "if", "(", "Kwf_Setup", "::", "getRequestPath", "(", ")", "===", "false", ")", "return", ";", "if", "(", "!", "preg_match", "(", "'#^/kwf/proxy/?$#i'", ",", "Kwf_Setup", "::", "getRequestPath", "(", ")", ")", ")", "return", ";", "if", "(", "is_string", "(", "$", "hostnames", ")", ")", "{", "$", "hostnames", "=", "array", "(", "$", "hostnames", ")", ";", "}", "$", "proxyUrl", "=", "$", "_REQUEST", "[", "'proxyUrl'", "]", ";", "$", "proxyPostVars", "=", "$", "_POST", ";", "$", "proxyGetVars", "=", "$", "_GET", ";", "if", "(", "array_key_exists", "(", "'proxyUrl'", ",", "$", "proxyPostVars", ")", ")", "unset", "(", "$", "proxyPostVars", "[", "'proxyUrl'", "]", ")", ";", "if", "(", "array_key_exists", "(", "'proxyUrl'", ",", "$", "proxyGetVars", ")", ")", "unset", "(", "$", "proxyGetVars", "[", "'proxyUrl'", "]", ")", ";", "// host checking", "$", "proxyHost", "=", "parse_url", "(", "$", "proxyUrl", ",", "PHP_URL_HOST", ")", ";", "$", "matched", "=", "false", ";", "foreach", "(", "$", "hostnames", "as", "$", "hostname", ")", "{", "if", "(", "preg_match", "(", "'/^'", ".", "$", "hostname", ".", "'$/i'", ",", "$", "proxyHost", ")", ")", "{", "$", "matched", "=", "true", ";", "break", ";", "}", "}", "if", "(", "!", "$", "matched", ")", "return", ";", "// proxying", "$", "http", "=", "new", "Zend_Http_Client", "(", "$", "proxyUrl", ")", ";", "if", "(", "count", "(", "$", "_POST", ")", ")", "{", "$", "http", "->", "setMethod", "(", "Zend_Http_Client", "::", "POST", ")", ";", "}", "else", "{", "$", "http", "->", "setMethod", "(", "Zend_Http_Client", "::", "GET", ")", ";", "}", "if", "(", "count", "(", "$", "_GET", ")", ")", "$", "http", "->", "setParameterGet", "(", "$", "proxyGetVars", ")", ";", "if", "(", "count", "(", "$", "_POST", ")", ")", "$", "http", "->", "setParameterPost", "(", "$", "proxyPostVars", ")", ";", "$", "response", "=", "$", "http", "->", "request", "(", ")", ";", "$", "headers", "=", "$", "response", "->", "getHeaders", "(", ")", ";", "if", "(", "$", "headers", "&&", "!", "empty", "(", "$", "headers", "[", "'Content-type'", "]", ")", ")", "{", "header", "(", "\"Content-Type: \"", ".", "$", "headers", "[", "'Content-type'", "]", ")", ";", "}", "echo", "$", "response", "->", "getBody", "(", ")", ";", "exit", ";", "}" ]
Proxy, der zB für cross-domain ajax requests verwendet werden kann @param string|array $hosts Erlaubte Hostnamen (RegExp erlaubt, ^ vorne und $ hinten werden autom. angefügt)
[ "Proxy", "der", "zB", "für", "cross", "-", "domain", "ajax", "requests", "verwendet", "werden", "kann" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/SimpleHttpProxy.php#L9-L52
koala-framework/koala-framework
Kwc/Mail/Redirect/Component.php
Kwc_Mail_Redirect_Component._getRedirectUrl
protected function _getRedirectUrl() { $r = $this->_getRedirectRow(); if (isset($r->type) && $r->type && $r->type != 'redirect') { throw new Kwf_Exception_NotFound('Invalid type'); } return $r->value; }
php
protected function _getRedirectUrl() { $r = $this->_getRedirectRow(); if (isset($r->type) && $r->type && $r->type != 'redirect') { throw new Kwf_Exception_NotFound('Invalid type'); } return $r->value; }
[ "protected", "function", "_getRedirectUrl", "(", ")", "{", "$", "r", "=", "$", "this", "->", "_getRedirectRow", "(", ")", ";", "if", "(", "isset", "(", "$", "r", "->", "type", ")", "&&", "$", "r", "->", "type", "&&", "$", "r", "->", "type", "!=", "'redirect'", ")", "{", "throw", "new", "Kwf_Exception_NotFound", "(", "'Invalid type'", ")", ";", "}", "return", "$", "r", "->", "value", ";", "}" ]
can be overridden to customize redirect url
[ "can", "be", "overridden", "to", "customize", "redirect", "url" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Mail/Redirect/Component.php#L48-L57
koala-framework/koala-framework
Kwc/Mail/Redirect/Component.php
Kwc_Mail_Redirect_Component._createRedirectUrl
public function _createRedirectUrl($href, $recipient) { $recipientPrimary = $recipient->getModel()->getPrimaryKey(); $recipientSource = $this->getRecipientModelShortcut(get_class($recipient->getModel())); $m = $this->getChildModel(); if (substr($href, 0, 1) == '#') return $href; $hrefParts = parse_url($href); if (!isset($hrefParts['path'])) { $hrefParts['path'] = ''; } $query = isset($hrefParts['query']) ? $hrefParts['query'] : null; $useAbsoluteUrl = true; if (isset($hrefParts['scheme'])) { if (($hrefParts['scheme'] == 'http' || $hrefParts['scheme'] == 'https') && isset($hrefParts['host'])) { if ($hrefParts['host'] == $this->getData()->getDomain()) { $useAbsoluteUrl = false; } } } else if (!isset($hrefParts['scheme']) && !isset($hrefParts['host'])) { $useAbsoluteUrl = false; } if ($useAbsoluteUrl) { $link = (isset($hrefParts['scheme']) ? "{$hrefParts['scheme']}:" : '') . (isset($hrefParts['host']) ? '//' : '') . (isset($hrefParts['host']) ? "{$hrefParts['host']}" : '') . (isset($hrefParts['port']) ? ":{$hrefParts['port']}" : '') . (isset($hrefParts['path']) ? "{$hrefParts['path']}" : '') . (isset($hrefParts['fragment']) ? "#{$hrefParts['fragment']}" : ''); } else { $link = $hrefParts['path']; if (!$link) $link = '/'; if (isset($hrefParts['fragment'])) $link .= '#' . $hrefParts['fragment']; } if (!isset($this->_redirectRowsCache[$link])) { $select = $m->select(); $select->whereEquals('value', $link); $r = $m->getRow($select); if (!$r) { $r = $m->createRow(array( 'value' => $link, )); $r->save(); } $this->_redirectRowsCache[$link] = $r; } $r = $this->_redirectRowsCache[$link]; // $recipientSource muss immer dabei sein, auch wenn es nur ein // model gibt. Würde später eines dazukommen, funktionierten die alten // Links nicht mehr // linkId_userId_userSource_hash return $this->_createHashedRedirectUrl(array( $r->id, $recipient->$recipientPrimary, $recipientSource )).($query ? '&'.$query : ''); }
php
public function _createRedirectUrl($href, $recipient) { $recipientPrimary = $recipient->getModel()->getPrimaryKey(); $recipientSource = $this->getRecipientModelShortcut(get_class($recipient->getModel())); $m = $this->getChildModel(); if (substr($href, 0, 1) == '#') return $href; $hrefParts = parse_url($href); if (!isset($hrefParts['path'])) { $hrefParts['path'] = ''; } $query = isset($hrefParts['query']) ? $hrefParts['query'] : null; $useAbsoluteUrl = true; if (isset($hrefParts['scheme'])) { if (($hrefParts['scheme'] == 'http' || $hrefParts['scheme'] == 'https') && isset($hrefParts['host'])) { if ($hrefParts['host'] == $this->getData()->getDomain()) { $useAbsoluteUrl = false; } } } else if (!isset($hrefParts['scheme']) && !isset($hrefParts['host'])) { $useAbsoluteUrl = false; } if ($useAbsoluteUrl) { $link = (isset($hrefParts['scheme']) ? "{$hrefParts['scheme']}:" : '') . (isset($hrefParts['host']) ? '//' : '') . (isset($hrefParts['host']) ? "{$hrefParts['host']}" : '') . (isset($hrefParts['port']) ? ":{$hrefParts['port']}" : '') . (isset($hrefParts['path']) ? "{$hrefParts['path']}" : '') . (isset($hrefParts['fragment']) ? "#{$hrefParts['fragment']}" : ''); } else { $link = $hrefParts['path']; if (!$link) $link = '/'; if (isset($hrefParts['fragment'])) $link .= '#' . $hrefParts['fragment']; } if (!isset($this->_redirectRowsCache[$link])) { $select = $m->select(); $select->whereEquals('value', $link); $r = $m->getRow($select); if (!$r) { $r = $m->createRow(array( 'value' => $link, )); $r->save(); } $this->_redirectRowsCache[$link] = $r; } $r = $this->_redirectRowsCache[$link]; // $recipientSource muss immer dabei sein, auch wenn es nur ein // model gibt. Würde später eines dazukommen, funktionierten die alten // Links nicht mehr // linkId_userId_userSource_hash return $this->_createHashedRedirectUrl(array( $r->id, $recipient->$recipientPrimary, $recipientSource )).($query ? '&'.$query : ''); }
[ "public", "function", "_createRedirectUrl", "(", "$", "href", ",", "$", "recipient", ")", "{", "$", "recipientPrimary", "=", "$", "recipient", "->", "getModel", "(", ")", "->", "getPrimaryKey", "(", ")", ";", "$", "recipientSource", "=", "$", "this", "->", "getRecipientModelShortcut", "(", "get_class", "(", "$", "recipient", "->", "getModel", "(", ")", ")", ")", ";", "$", "m", "=", "$", "this", "->", "getChildModel", "(", ")", ";", "if", "(", "substr", "(", "$", "href", ",", "0", ",", "1", ")", "==", "'#'", ")", "return", "$", "href", ";", "$", "hrefParts", "=", "parse_url", "(", "$", "href", ")", ";", "if", "(", "!", "isset", "(", "$", "hrefParts", "[", "'path'", "]", ")", ")", "{", "$", "hrefParts", "[", "'path'", "]", "=", "''", ";", "}", "$", "query", "=", "isset", "(", "$", "hrefParts", "[", "'query'", "]", ")", "?", "$", "hrefParts", "[", "'query'", "]", ":", "null", ";", "$", "useAbsoluteUrl", "=", "true", ";", "if", "(", "isset", "(", "$", "hrefParts", "[", "'scheme'", "]", ")", ")", "{", "if", "(", "(", "$", "hrefParts", "[", "'scheme'", "]", "==", "'http'", "||", "$", "hrefParts", "[", "'scheme'", "]", "==", "'https'", ")", "&&", "isset", "(", "$", "hrefParts", "[", "'host'", "]", ")", ")", "{", "if", "(", "$", "hrefParts", "[", "'host'", "]", "==", "$", "this", "->", "getData", "(", ")", "->", "getDomain", "(", ")", ")", "{", "$", "useAbsoluteUrl", "=", "false", ";", "}", "}", "}", "else", "if", "(", "!", "isset", "(", "$", "hrefParts", "[", "'scheme'", "]", ")", "&&", "!", "isset", "(", "$", "hrefParts", "[", "'host'", "]", ")", ")", "{", "$", "useAbsoluteUrl", "=", "false", ";", "}", "if", "(", "$", "useAbsoluteUrl", ")", "{", "$", "link", "=", "(", "isset", "(", "$", "hrefParts", "[", "'scheme'", "]", ")", "?", "\"{$hrefParts['scheme']}:\"", ":", "''", ")", ".", "(", "isset", "(", "$", "hrefParts", "[", "'host'", "]", ")", "?", "'//'", ":", "''", ")", ".", "(", "isset", "(", "$", "hrefParts", "[", "'host'", "]", ")", "?", "\"{$hrefParts['host']}\"", ":", "''", ")", ".", "(", "isset", "(", "$", "hrefParts", "[", "'port'", "]", ")", "?", "\":{$hrefParts['port']}\"", ":", "''", ")", ".", "(", "isset", "(", "$", "hrefParts", "[", "'path'", "]", ")", "?", "\"{$hrefParts['path']}\"", ":", "''", ")", ".", "(", "isset", "(", "$", "hrefParts", "[", "'fragment'", "]", ")", "?", "\"#{$hrefParts['fragment']}\"", ":", "''", ")", ";", "}", "else", "{", "$", "link", "=", "$", "hrefParts", "[", "'path'", "]", ";", "if", "(", "!", "$", "link", ")", "$", "link", "=", "'/'", ";", "if", "(", "isset", "(", "$", "hrefParts", "[", "'fragment'", "]", ")", ")", "$", "link", ".=", "'#'", ".", "$", "hrefParts", "[", "'fragment'", "]", ";", "}", "if", "(", "!", "isset", "(", "$", "this", "->", "_redirectRowsCache", "[", "$", "link", "]", ")", ")", "{", "$", "select", "=", "$", "m", "->", "select", "(", ")", ";", "$", "select", "->", "whereEquals", "(", "'value'", ",", "$", "link", ")", ";", "$", "r", "=", "$", "m", "->", "getRow", "(", "$", "select", ")", ";", "if", "(", "!", "$", "r", ")", "{", "$", "r", "=", "$", "m", "->", "createRow", "(", "array", "(", "'value'", "=>", "$", "link", ",", ")", ")", ";", "$", "r", "->", "save", "(", ")", ";", "}", "$", "this", "->", "_redirectRowsCache", "[", "$", "link", "]", "=", "$", "r", ";", "}", "$", "r", "=", "$", "this", "->", "_redirectRowsCache", "[", "$", "link", "]", ";", "// $recipientSource muss immer dabei sein, auch wenn es nur ein", "// model gibt. Würde später eines dazukommen, funktionierten die alten", "// Links nicht mehr", "// linkId_userId_userSource_hash", "return", "$", "this", "->", "_createHashedRedirectUrl", "(", "array", "(", "$", "r", "->", "id", ",", "$", "recipient", "->", "$", "recipientPrimary", ",", "$", "recipientSource", ")", ")", ".", "(", "$", "query", "?", "'&'", ".", "$", "query", ":", "''", ")", ";", "}" ]
TODO: when upgrading to php 5.4 change to protected (and change $that in closure to $this)
[ "TODO", ":", "when", "upgrading", "to", "php", "5", ".", "4", "change", "to", "protected", "(", "and", "change", "$that", "in", "closure", "to", "$this", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Mail/Redirect/Component.php#L189-L250
koala-framework/koala-framework
Kwc/Columns/Update/20150309Legacy00001.php
Kwc_Columns_Update_20150309Legacy00001.postUpdate
public function postUpdate() { $search = array(); $replace = array(); $dbPattern = array(); $model = null; $j = 0; $components = Kwf_Component_Data_Root::getInstance() ->getComponentsByClass('Kwc_Columns_Component', array('ignoreVisible' => true)); if (count($components) > 50) { echo "Kwc_Columns_Update_1: updating ".count($components)." components, this might take some time\n"; } foreach ($components as $c) { if (!$model) $model = $c->getComponent()->getChildModel(); $totalColumns = (int)substr($c->getComponent()->getRow()->type, 0, 1); $select = new Kwf_Model_Select(); $select->whereEquals('component_id', $c->dbId); if ($model->countRows($select)) continue; for ($i = 1; $i <= $totalColumns; $i++) { $id = $model->createRow(array( 'component_id' => $c->dbId, 'pos' => $i, 'visible' => true ))->save(); $s = $c->dbId . '-' . $i; $search[$j] = $s; $replace[$j] = $c->dbId . '-' . $id; $dbPattern[$j][] = $s . '-%'; $dbPattern[$j][] = $s . '\_%'; $dbPattern[$j][] = $s; $j++; } } if (empty($search)) return; $db = Zend_Registry::get('db'); foreach ($db->listTables() as $table) { if ($table == 'cache_component') continue; if ($table == 'cache_component_includes') continue; if ($table == 'cache_component_url') continue; if ($table == 'cache_users') continue; $hasComponentId = false; $column = 'component_id'; foreach ($db->query("SHOW FIELDS FROM $table")->fetchAll() as $field) { if ($table == 'kwf_pages') { $column = 'parent_id'; $hasComponentId = true; } else if ($field['Field'] == 'component_id') { $hasComponentId = true; } } if ($hasComponentId) { $where = "WHERE "; foreach ($search as $key => $value) { $where .= "$column LIKE '" . implode("' OR $column LIKE '", $dbPattern[$key]) . "' OR "; } $where = substr($where, 0, strlen($where)-4); $sql = "SELECT $column FROM $table $where"; $ids = $db->fetchCol($sql); if (empty($ids)) continue; $lastUpdatedId = false; foreach ($ids as $id) { if ($lastUpdatedId == $id) continue; $k = 0; foreach ($search as $key => $value) { if (strpos($id, $value) !== false) { $k = $key; break; } } $sql = "UPDATE $table SET $column = " . $db->quote(str_replace($search[$k], $replace[$k], $id)) . " WHERE $column = '$id'"; $db->query($sql); $lastUpdatedId = $id; } } } $where = "WHERE "; foreach ($search as $key => $value) { $where .= "content LIKE '%href=\"" . implode("\"%' OR content LIKE '%href=\"", $dbPattern[$key]) . "\"%' OR content LIKE '%href=\n \"" . implode("\"%' OR content LIKE '%href=\n \"", $dbPattern[$key]) . "\"%' OR "; } $where = substr($where, 0, strlen($where)-4); $sql = "SELECT component_id, content FROM kwc_basic_text $where"; $rows = $db->query($sql)->fetchAll(); foreach ($rows as $row) { $k = 0; foreach ($search as $key => $value) { if (strpos($row['content'], $value) !== false) { $row['content'] = preg_replace('#(href=\s*")([^"]*/)?([^"]*)'.preg_quote($search[$key]).'([^"]*)"#', '\1\2\3'.$replace[$key].'\4"', $row['content']); } } $sql = "UPDATE kwc_basic_text SET content = " . $db->quote($row['content']) . " WHERE component_id = '".$row['component_id']."'"; $db->query($sql); } }
php
public function postUpdate() { $search = array(); $replace = array(); $dbPattern = array(); $model = null; $j = 0; $components = Kwf_Component_Data_Root::getInstance() ->getComponentsByClass('Kwc_Columns_Component', array('ignoreVisible' => true)); if (count($components) > 50) { echo "Kwc_Columns_Update_1: updating ".count($components)." components, this might take some time\n"; } foreach ($components as $c) { if (!$model) $model = $c->getComponent()->getChildModel(); $totalColumns = (int)substr($c->getComponent()->getRow()->type, 0, 1); $select = new Kwf_Model_Select(); $select->whereEquals('component_id', $c->dbId); if ($model->countRows($select)) continue; for ($i = 1; $i <= $totalColumns; $i++) { $id = $model->createRow(array( 'component_id' => $c->dbId, 'pos' => $i, 'visible' => true ))->save(); $s = $c->dbId . '-' . $i; $search[$j] = $s; $replace[$j] = $c->dbId . '-' . $id; $dbPattern[$j][] = $s . '-%'; $dbPattern[$j][] = $s . '\_%'; $dbPattern[$j][] = $s; $j++; } } if (empty($search)) return; $db = Zend_Registry::get('db'); foreach ($db->listTables() as $table) { if ($table == 'cache_component') continue; if ($table == 'cache_component_includes') continue; if ($table == 'cache_component_url') continue; if ($table == 'cache_users') continue; $hasComponentId = false; $column = 'component_id'; foreach ($db->query("SHOW FIELDS FROM $table")->fetchAll() as $field) { if ($table == 'kwf_pages') { $column = 'parent_id'; $hasComponentId = true; } else if ($field['Field'] == 'component_id') { $hasComponentId = true; } } if ($hasComponentId) { $where = "WHERE "; foreach ($search as $key => $value) { $where .= "$column LIKE '" . implode("' OR $column LIKE '", $dbPattern[$key]) . "' OR "; } $where = substr($where, 0, strlen($where)-4); $sql = "SELECT $column FROM $table $where"; $ids = $db->fetchCol($sql); if (empty($ids)) continue; $lastUpdatedId = false; foreach ($ids as $id) { if ($lastUpdatedId == $id) continue; $k = 0; foreach ($search as $key => $value) { if (strpos($id, $value) !== false) { $k = $key; break; } } $sql = "UPDATE $table SET $column = " . $db->quote(str_replace($search[$k], $replace[$k], $id)) . " WHERE $column = '$id'"; $db->query($sql); $lastUpdatedId = $id; } } } $where = "WHERE "; foreach ($search as $key => $value) { $where .= "content LIKE '%href=\"" . implode("\"%' OR content LIKE '%href=\"", $dbPattern[$key]) . "\"%' OR content LIKE '%href=\n \"" . implode("\"%' OR content LIKE '%href=\n \"", $dbPattern[$key]) . "\"%' OR "; } $where = substr($where, 0, strlen($where)-4); $sql = "SELECT component_id, content FROM kwc_basic_text $where"; $rows = $db->query($sql)->fetchAll(); foreach ($rows as $row) { $k = 0; foreach ($search as $key => $value) { if (strpos($row['content'], $value) !== false) { $row['content'] = preg_replace('#(href=\s*")([^"]*/)?([^"]*)'.preg_quote($search[$key]).'([^"]*)"#', '\1\2\3'.$replace[$key].'\4"', $row['content']); } } $sql = "UPDATE kwc_basic_text SET content = " . $db->quote($row['content']) . " WHERE component_id = '".$row['component_id']."'"; $db->query($sql); } }
[ "public", "function", "postUpdate", "(", ")", "{", "$", "search", "=", "array", "(", ")", ";", "$", "replace", "=", "array", "(", ")", ";", "$", "dbPattern", "=", "array", "(", ")", ";", "$", "model", "=", "null", ";", "$", "j", "=", "0", ";", "$", "components", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentsByClass", "(", "'Kwc_Columns_Component'", ",", "array", "(", "'ignoreVisible'", "=>", "true", ")", ")", ";", "if", "(", "count", "(", "$", "components", ")", ">", "50", ")", "{", "echo", "\"Kwc_Columns_Update_1: updating \"", ".", "count", "(", "$", "components", ")", ".", "\" components, this might take some time\\n\"", ";", "}", "foreach", "(", "$", "components", "as", "$", "c", ")", "{", "if", "(", "!", "$", "model", ")", "$", "model", "=", "$", "c", "->", "getComponent", "(", ")", "->", "getChildModel", "(", ")", ";", "$", "totalColumns", "=", "(", "int", ")", "substr", "(", "$", "c", "->", "getComponent", "(", ")", "->", "getRow", "(", ")", "->", "type", ",", "0", ",", "1", ")", ";", "$", "select", "=", "new", "Kwf_Model_Select", "(", ")", ";", "$", "select", "->", "whereEquals", "(", "'component_id'", ",", "$", "c", "->", "dbId", ")", ";", "if", "(", "$", "model", "->", "countRows", "(", "$", "select", ")", ")", "continue", ";", "for", "(", "$", "i", "=", "1", ";", "$", "i", "<=", "$", "totalColumns", ";", "$", "i", "++", ")", "{", "$", "id", "=", "$", "model", "->", "createRow", "(", "array", "(", "'component_id'", "=>", "$", "c", "->", "dbId", ",", "'pos'", "=>", "$", "i", ",", "'visible'", "=>", "true", ")", ")", "->", "save", "(", ")", ";", "$", "s", "=", "$", "c", "->", "dbId", ".", "'-'", ".", "$", "i", ";", "$", "search", "[", "$", "j", "]", "=", "$", "s", ";", "$", "replace", "[", "$", "j", "]", "=", "$", "c", "->", "dbId", ".", "'-'", ".", "$", "id", ";", "$", "dbPattern", "[", "$", "j", "]", "[", "]", "=", "$", "s", ".", "'-%'", ";", "$", "dbPattern", "[", "$", "j", "]", "[", "]", "=", "$", "s", ".", "'\\_%'", ";", "$", "dbPattern", "[", "$", "j", "]", "[", "]", "=", "$", "s", ";", "$", "j", "++", ";", "}", "}", "if", "(", "empty", "(", "$", "search", ")", ")", "return", ";", "$", "db", "=", "Zend_Registry", "::", "get", "(", "'db'", ")", ";", "foreach", "(", "$", "db", "->", "listTables", "(", ")", "as", "$", "table", ")", "{", "if", "(", "$", "table", "==", "'cache_component'", ")", "continue", ";", "if", "(", "$", "table", "==", "'cache_component_includes'", ")", "continue", ";", "if", "(", "$", "table", "==", "'cache_component_url'", ")", "continue", ";", "if", "(", "$", "table", "==", "'cache_users'", ")", "continue", ";", "$", "hasComponentId", "=", "false", ";", "$", "column", "=", "'component_id'", ";", "foreach", "(", "$", "db", "->", "query", "(", "\"SHOW FIELDS FROM $table\"", ")", "->", "fetchAll", "(", ")", "as", "$", "field", ")", "{", "if", "(", "$", "table", "==", "'kwf_pages'", ")", "{", "$", "column", "=", "'parent_id'", ";", "$", "hasComponentId", "=", "true", ";", "}", "else", "if", "(", "$", "field", "[", "'Field'", "]", "==", "'component_id'", ")", "{", "$", "hasComponentId", "=", "true", ";", "}", "}", "if", "(", "$", "hasComponentId", ")", "{", "$", "where", "=", "\"WHERE \"", ";", "foreach", "(", "$", "search", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "where", ".=", "\"$column LIKE '\"", ".", "implode", "(", "\"' OR $column LIKE '\"", ",", "$", "dbPattern", "[", "$", "key", "]", ")", ".", "\"' OR \"", ";", "}", "$", "where", "=", "substr", "(", "$", "where", ",", "0", ",", "strlen", "(", "$", "where", ")", "-", "4", ")", ";", "$", "sql", "=", "\"SELECT $column FROM $table $where\"", ";", "$", "ids", "=", "$", "db", "->", "fetchCol", "(", "$", "sql", ")", ";", "if", "(", "empty", "(", "$", "ids", ")", ")", "continue", ";", "$", "lastUpdatedId", "=", "false", ";", "foreach", "(", "$", "ids", "as", "$", "id", ")", "{", "if", "(", "$", "lastUpdatedId", "==", "$", "id", ")", "continue", ";", "$", "k", "=", "0", ";", "foreach", "(", "$", "search", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "id", ",", "$", "value", ")", "!==", "false", ")", "{", "$", "k", "=", "$", "key", ";", "break", ";", "}", "}", "$", "sql", "=", "\"UPDATE $table SET $column = \"", ".", "$", "db", "->", "quote", "(", "str_replace", "(", "$", "search", "[", "$", "k", "]", ",", "$", "replace", "[", "$", "k", "]", ",", "$", "id", ")", ")", ".", "\"\n WHERE $column = '$id'\"", ";", "$", "db", "->", "query", "(", "$", "sql", ")", ";", "$", "lastUpdatedId", "=", "$", "id", ";", "}", "}", "}", "$", "where", "=", "\"WHERE \"", ";", "foreach", "(", "$", "search", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "where", ".=", "\"content LIKE '%href=\\\"\"", ".", "implode", "(", "\"\\\"%' OR content LIKE '%href=\\\"\"", ",", "$", "dbPattern", "[", "$", "key", "]", ")", ".", "\"\\\"%' OR content LIKE '%href=\\n \\\"\"", ".", "implode", "(", "\"\\\"%' OR content LIKE '%href=\\n \\\"\"", ",", "$", "dbPattern", "[", "$", "key", "]", ")", ".", "\"\\\"%' OR \"", ";", "}", "$", "where", "=", "substr", "(", "$", "where", ",", "0", ",", "strlen", "(", "$", "where", ")", "-", "4", ")", ";", "$", "sql", "=", "\"SELECT component_id, content FROM kwc_basic_text $where\"", ";", "$", "rows", "=", "$", "db", "->", "query", "(", "$", "sql", ")", "->", "fetchAll", "(", ")", ";", "foreach", "(", "$", "rows", "as", "$", "row", ")", "{", "$", "k", "=", "0", ";", "foreach", "(", "$", "search", "as", "$", "key", "=>", "$", "value", ")", "{", "if", "(", "strpos", "(", "$", "row", "[", "'content'", "]", ",", "$", "value", ")", "!==", "false", ")", "{", "$", "row", "[", "'content'", "]", "=", "preg_replace", "(", "'#(href=\\s*\")([^\"]*/)?([^\"]*)'", ".", "preg_quote", "(", "$", "search", "[", "$", "key", "]", ")", ".", "'([^\"]*)\"#'", ",", "'\\1\\2\\3'", ".", "$", "replace", "[", "$", "key", "]", ".", "'\\4\"'", ",", "$", "row", "[", "'content'", "]", ")", ";", "}", "}", "$", "sql", "=", "\"UPDATE kwc_basic_text SET content = \"", ".", "$", "db", "->", "quote", "(", "$", "row", "[", "'content'", "]", ")", ".", "\"\n WHERE component_id = '\"", ".", "$", "row", "[", "'component_id'", "]", ".", "\"'\"", ";", "$", "db", "->", "query", "(", "$", "sql", ")", ";", "}", "}" ]
required in postUpdate as we use getComponentsByClass which would possibly not work in update()
[ "required", "in", "postUpdate", "as", "we", "use", "getComponentsByClass", "which", "would", "possibly", "not", "work", "in", "update", "()" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Columns/Update/20150309Legacy00001.php#L5-L113
koala-framework/koala-framework
Kwc/Mail/Abstract/Component.php
Kwc_Mail_Abstract_Component.send
public function send(Kwc_Mail_Recipient_Interface $recipient, $data = null, $toAddress = null, $format = null, $addViewTracker = true) { $mail = $this->createMail($recipient, $data, $toAddress, $format, $addViewTracker); return $mail->send(); }
php
public function send(Kwc_Mail_Recipient_Interface $recipient, $data = null, $toAddress = null, $format = null, $addViewTracker = true) { $mail = $this->createMail($recipient, $data, $toAddress, $format, $addViewTracker); return $mail->send(); }
[ "public", "function", "send", "(", "Kwc_Mail_Recipient_Interface", "$", "recipient", ",", "$", "data", "=", "null", ",", "$", "toAddress", "=", "null", ",", "$", "format", "=", "null", ",", "$", "addViewTracker", "=", "true", ")", "{", "$", "mail", "=", "$", "this", "->", "createMail", "(", "$", "recipient", ",", "$", "data", ",", "$", "toAddress", ",", "$", "format", ",", "$", "addViewTracker", ")", ";", "return", "$", "mail", "->", "send", "(", ")", ";", "}" ]
Verschickt ein mail an @param $recipient. @param $data Optionale Daten die benötigt werden, kann von den Komponenten per $this->getData()->getParentByClass('Kwc_Mail_Component')->getComponent()->getMailData(); ausgelesen werden Wird von Gästebuch verwendet
[ "Verschickt", "ein", "mail", "an" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Mail/Abstract/Component.php#L203-L207
koala-framework/koala-framework
Kwc/Mail/Abstract/Component.php
Kwc_Mail_Abstract_Component.getHtml
public function getHtml(Kwc_Mail_Recipient_Interface $recipient = null, $addViewTracker = false) { $renderer = new Kwf_Component_Renderer_Mail(); $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_HTML); $renderer->setRecipient($recipient); $renderer->setHtmlStyles($this->getHtmlStyles()); $ret = $renderer->renderComponent($this->getData()); Kwf_Benchmark::checkpoint('html: render'); $ret = $this->_processPlaceholder($ret, $recipient); Kwf_Benchmark::checkpoint('html: placeholder'); $redirectComponent = $this->getData()->getChildComponent('_redirect'); if ($redirectComponent) { $redirectComponent = $redirectComponent->getComponent(); $ret = $redirectComponent->replaceLinks($ret, $recipient, 'mailhtml'); } Kwf_Benchmark::checkpoint('html: replaceLinks'); if ($addViewTracker && $this->_getSetting('trackViews')) { $params = array(); if ($recipient->id) $params['recipientId'] = urlencode($recipient->id); if ($shortcut = $redirectComponent->getRecipientModelShortcut(get_class($recipient->getModel()))) $params['recipientModelShortcut'] = urlencode($shortcut); $https = Kwf_Util_Https::domainSupportsHttps($this->getData()->getDomain()); $protocol = $https ? 'https' : 'http'; $imgUrl = $protocol . '://'.$this->getData()->getDomain() . Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'views', 'blank.gif'); $imgUrl .= '?' . http_build_query($params); $ret .= '<img src="' . $imgUrl . '" width="1" height="1" />'; Kwf_Benchmark::checkpoint('html: view tracker'); } $ret = ltrim($this->_getSetting('docType')."\n".$ret); return $ret; }
php
public function getHtml(Kwc_Mail_Recipient_Interface $recipient = null, $addViewTracker = false) { $renderer = new Kwf_Component_Renderer_Mail(); $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_HTML); $renderer->setRecipient($recipient); $renderer->setHtmlStyles($this->getHtmlStyles()); $ret = $renderer->renderComponent($this->getData()); Kwf_Benchmark::checkpoint('html: render'); $ret = $this->_processPlaceholder($ret, $recipient); Kwf_Benchmark::checkpoint('html: placeholder'); $redirectComponent = $this->getData()->getChildComponent('_redirect'); if ($redirectComponent) { $redirectComponent = $redirectComponent->getComponent(); $ret = $redirectComponent->replaceLinks($ret, $recipient, 'mailhtml'); } Kwf_Benchmark::checkpoint('html: replaceLinks'); if ($addViewTracker && $this->_getSetting('trackViews')) { $params = array(); if ($recipient->id) $params['recipientId'] = urlencode($recipient->id); if ($shortcut = $redirectComponent->getRecipientModelShortcut(get_class($recipient->getModel()))) $params['recipientModelShortcut'] = urlencode($shortcut); $https = Kwf_Util_Https::domainSupportsHttps($this->getData()->getDomain()); $protocol = $https ? 'https' : 'http'; $imgUrl = $protocol . '://'.$this->getData()->getDomain() . Kwf_Media::getUrl($this->getData()->componentClass, $this->getData()->componentId, 'views', 'blank.gif'); $imgUrl .= '?' . http_build_query($params); $ret .= '<img src="' . $imgUrl . '" width="1" height="1" />'; Kwf_Benchmark::checkpoint('html: view tracker'); } $ret = ltrim($this->_getSetting('docType')."\n".$ret); return $ret; }
[ "public", "function", "getHtml", "(", "Kwc_Mail_Recipient_Interface", "$", "recipient", "=", "null", ",", "$", "addViewTracker", "=", "false", ")", "{", "$", "renderer", "=", "new", "Kwf_Component_Renderer_Mail", "(", ")", ";", "$", "renderer", "->", "setRenderFormat", "(", "Kwf_Component_Renderer_Mail", "::", "RENDER_HTML", ")", ";", "$", "renderer", "->", "setRecipient", "(", "$", "recipient", ")", ";", "$", "renderer", "->", "setHtmlStyles", "(", "$", "this", "->", "getHtmlStyles", "(", ")", ")", ";", "$", "ret", "=", "$", "renderer", "->", "renderComponent", "(", "$", "this", "->", "getData", "(", ")", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'html: render'", ")", ";", "$", "ret", "=", "$", "this", "->", "_processPlaceholder", "(", "$", "ret", ",", "$", "recipient", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'html: placeholder'", ")", ";", "$", "redirectComponent", "=", "$", "this", "->", "getData", "(", ")", "->", "getChildComponent", "(", "'_redirect'", ")", ";", "if", "(", "$", "redirectComponent", ")", "{", "$", "redirectComponent", "=", "$", "redirectComponent", "->", "getComponent", "(", ")", ";", "$", "ret", "=", "$", "redirectComponent", "->", "replaceLinks", "(", "$", "ret", ",", "$", "recipient", ",", "'mailhtml'", ")", ";", "}", "Kwf_Benchmark", "::", "checkpoint", "(", "'html: replaceLinks'", ")", ";", "if", "(", "$", "addViewTracker", "&&", "$", "this", "->", "_getSetting", "(", "'trackViews'", ")", ")", "{", "$", "params", "=", "array", "(", ")", ";", "if", "(", "$", "recipient", "->", "id", ")", "$", "params", "[", "'recipientId'", "]", "=", "urlencode", "(", "$", "recipient", "->", "id", ")", ";", "if", "(", "$", "shortcut", "=", "$", "redirectComponent", "->", "getRecipientModelShortcut", "(", "get_class", "(", "$", "recipient", "->", "getModel", "(", ")", ")", ")", ")", "$", "params", "[", "'recipientModelShortcut'", "]", "=", "urlencode", "(", "$", "shortcut", ")", ";", "$", "https", "=", "Kwf_Util_Https", "::", "domainSupportsHttps", "(", "$", "this", "->", "getData", "(", ")", "->", "getDomain", "(", ")", ")", ";", "$", "protocol", "=", "$", "https", "?", "'https'", ":", "'http'", ";", "$", "imgUrl", "=", "$", "protocol", ".", "'://'", ".", "$", "this", "->", "getData", "(", ")", "->", "getDomain", "(", ")", ".", "Kwf_Media", "::", "getUrl", "(", "$", "this", "->", "getData", "(", ")", "->", "componentClass", ",", "$", "this", "->", "getData", "(", ")", "->", "componentId", ",", "'views'", ",", "'blank.gif'", ")", ";", "$", "imgUrl", ".=", "'?'", ".", "http_build_query", "(", "$", "params", ")", ";", "$", "ret", ".=", "'<img src=\"'", ".", "$", "imgUrl", ".", "'\" width=\"1\" height=\"1\" />'", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'html: view tracker'", ")", ";", "}", "$", "ret", "=", "ltrim", "(", "$", "this", "->", "_getSetting", "(", "'docType'", ")", ".", "\"\\n\"", ".", "$", "ret", ")", ";", "return", "$", "ret", ";", "}" ]
Gibt den personalisierten HTML-Quelltext der Mail zurück
[ "Gibt", "den", "personalisierten", "HTML", "-", "Quelltext", "der", "Mail", "zurück" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Mail/Abstract/Component.php#L219-L251
koala-framework/koala-framework
Kwc/Mail/Abstract/Component.php
Kwc_Mail_Abstract_Component.getText
public function getText(Kwc_Mail_Recipient_Interface $recipient = null) { $renderer = new Kwf_Component_Renderer_Mail(); $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_TXT); $renderer->setRecipient($recipient); $ret = $renderer->renderComponent($this->getData()); Kwf_Benchmark::checkpoint('text: render'); $ret = $this->_processPlaceholder($ret, $recipient); Kwf_Benchmark::checkpoint('text: placeholder'); $ret = str_replace('&nbsp;', ' ', $ret); $redirect = $this->getData()->getChildComponent('_redirect'); if ($redirect) { $ret = $redirect->getComponent()->replaceLinks($ret, $recipient, 'mailtext'); } Kwf_Benchmark::checkpoint('text: replaceLinks'); return $ret; }
php
public function getText(Kwc_Mail_Recipient_Interface $recipient = null) { $renderer = new Kwf_Component_Renderer_Mail(); $renderer->setRenderFormat(Kwf_Component_Renderer_Mail::RENDER_TXT); $renderer->setRecipient($recipient); $ret = $renderer->renderComponent($this->getData()); Kwf_Benchmark::checkpoint('text: render'); $ret = $this->_processPlaceholder($ret, $recipient); Kwf_Benchmark::checkpoint('text: placeholder'); $ret = str_replace('&nbsp;', ' ', $ret); $redirect = $this->getData()->getChildComponent('_redirect'); if ($redirect) { $ret = $redirect->getComponent()->replaceLinks($ret, $recipient, 'mailtext'); } Kwf_Benchmark::checkpoint('text: replaceLinks'); return $ret; }
[ "public", "function", "getText", "(", "Kwc_Mail_Recipient_Interface", "$", "recipient", "=", "null", ")", "{", "$", "renderer", "=", "new", "Kwf_Component_Renderer_Mail", "(", ")", ";", "$", "renderer", "->", "setRenderFormat", "(", "Kwf_Component_Renderer_Mail", "::", "RENDER_TXT", ")", ";", "$", "renderer", "->", "setRecipient", "(", "$", "recipient", ")", ";", "$", "ret", "=", "$", "renderer", "->", "renderComponent", "(", "$", "this", "->", "getData", "(", ")", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'text: render'", ")", ";", "$", "ret", "=", "$", "this", "->", "_processPlaceholder", "(", "$", "ret", ",", "$", "recipient", ")", ";", "Kwf_Benchmark", "::", "checkpoint", "(", "'text: placeholder'", ")", ";", "$", "ret", "=", "str_replace", "(", "'&nbsp;'", ",", "' '", ",", "$", "ret", ")", ";", "$", "redirect", "=", "$", "this", "->", "getData", "(", ")", "->", "getChildComponent", "(", "'_redirect'", ")", ";", "if", "(", "$", "redirect", ")", "{", "$", "ret", "=", "$", "redirect", "->", "getComponent", "(", ")", "->", "replaceLinks", "(", "$", "ret", ",", "$", "recipient", ",", "'mailtext'", ")", ";", "}", "Kwf_Benchmark", "::", "checkpoint", "(", "'text: replaceLinks'", ")", ";", "return", "$", "ret", ";", "}" ]
Gibt den personalisierten Quelltext der Mail zurück @see getHtml Für Ersetzungen siehe
[ "Gibt", "den", "personalisierten", "Quelltext", "der", "Mail", "zurück" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Mail/Abstract/Component.php#L258-L274
koala-framework/koala-framework
Kwf/Controller/Action/Auto/Grid.php
Kwf_Controller_Action_Auto_Grid.jsonDataAction
public function jsonDataAction() { $limit = null; $start = null; $order = 0; if ($this->_paging) { $limit = $this->getRequest()->getParam('limit'); $start = $this->getRequest()->getParam('start'); if (!$limit) { if (!is_array($this->_paging) && $this->_paging > 0) { $limit = $this->_paging; } else if (is_array($this->_paging) && isset($this->_paging['pageSize'])) { $limit = $this->_paging['pageSize']; } else { $limit = $this->_paging; } } // wird vermutlich nicht benötigt, da beim ersten laden 'sortInfo' in den metadaten drin ist // falls es irgendwo benötigt wird wieder einkommentieren // $this->view->order = $order; } //TODO: dieser code sollte in _getOrder liegen $order = $this->_defaultOrder; if ($this->getRequest()->getParam('sort')) { $order['field'] = $this->getRequest()->getParam('sort'); } if ($this->_getParam("direction") && $this->_getParam('direction') != 'undefined') { $order['direction'] = $this->_getParam('direction'); } $primaryKey = $this->_primaryKey; $rowSet = $this->_fetchData($order, $limit, $start); if (!is_null($rowSet)) { if (isset($this->_paging['type']) && $this->_paging['type'] == 'Date') { //nothing to do, we don't know the total } else if ($this->_paging) { $this->view->total = $this->_fetchCount(); } else { $this->view->total = sizeof($rowSet); } $number = 0; if ($start) $number = $start; $rows = array(); foreach ($rowSet as $row) { $r = array(); if (is_array($row)) { $row = (object)$row; } if (!$this->_hasPermissions($row, 'load')) { throw new Kwf_Exception("You don't have the permissions to load this row"); } foreach ($this->_columns as $column) { if ($column instanceof Kwf_Grid_Column_RowNumberer) continue; if ($column->getShowIn() & Kwf_Grid_Column::SHOW_IN_GRID) { $data = $column->load($row, Kwf_Grid_Column::ROLE_DISPLAY, array( 'number' => $number, 'total' => $this->view->total, )); $r[$column->getDataIndex()] = $data; } } if (!isset($r[$primaryKey]) && isset($row->$primaryKey)) { $r[$primaryKey] = $row->$primaryKey; } $rows[] = $r; $number++; } $this->view->rows = $rows; } else { $this->view->total = 0; $this->view->rows = array(); } if ($this->getRequest()->getParam('meta')) { $this->_appendMetaData(); } }
php
public function jsonDataAction() { $limit = null; $start = null; $order = 0; if ($this->_paging) { $limit = $this->getRequest()->getParam('limit'); $start = $this->getRequest()->getParam('start'); if (!$limit) { if (!is_array($this->_paging) && $this->_paging > 0) { $limit = $this->_paging; } else if (is_array($this->_paging) && isset($this->_paging['pageSize'])) { $limit = $this->_paging['pageSize']; } else { $limit = $this->_paging; } } // wird vermutlich nicht benötigt, da beim ersten laden 'sortInfo' in den metadaten drin ist // falls es irgendwo benötigt wird wieder einkommentieren // $this->view->order = $order; } //TODO: dieser code sollte in _getOrder liegen $order = $this->_defaultOrder; if ($this->getRequest()->getParam('sort')) { $order['field'] = $this->getRequest()->getParam('sort'); } if ($this->_getParam("direction") && $this->_getParam('direction') != 'undefined') { $order['direction'] = $this->_getParam('direction'); } $primaryKey = $this->_primaryKey; $rowSet = $this->_fetchData($order, $limit, $start); if (!is_null($rowSet)) { if (isset($this->_paging['type']) && $this->_paging['type'] == 'Date') { //nothing to do, we don't know the total } else if ($this->_paging) { $this->view->total = $this->_fetchCount(); } else { $this->view->total = sizeof($rowSet); } $number = 0; if ($start) $number = $start; $rows = array(); foreach ($rowSet as $row) { $r = array(); if (is_array($row)) { $row = (object)$row; } if (!$this->_hasPermissions($row, 'load')) { throw new Kwf_Exception("You don't have the permissions to load this row"); } foreach ($this->_columns as $column) { if ($column instanceof Kwf_Grid_Column_RowNumberer) continue; if ($column->getShowIn() & Kwf_Grid_Column::SHOW_IN_GRID) { $data = $column->load($row, Kwf_Grid_Column::ROLE_DISPLAY, array( 'number' => $number, 'total' => $this->view->total, )); $r[$column->getDataIndex()] = $data; } } if (!isset($r[$primaryKey]) && isset($row->$primaryKey)) { $r[$primaryKey] = $row->$primaryKey; } $rows[] = $r; $number++; } $this->view->rows = $rows; } else { $this->view->total = 0; $this->view->rows = array(); } if ($this->getRequest()->getParam('meta')) { $this->_appendMetaData(); } }
[ "public", "function", "jsonDataAction", "(", ")", "{", "$", "limit", "=", "null", ";", "$", "start", "=", "null", ";", "$", "order", "=", "0", ";", "if", "(", "$", "this", "->", "_paging", ")", "{", "$", "limit", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'limit'", ")", ";", "$", "start", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'start'", ")", ";", "if", "(", "!", "$", "limit", ")", "{", "if", "(", "!", "is_array", "(", "$", "this", "->", "_paging", ")", "&&", "$", "this", "->", "_paging", ">", "0", ")", "{", "$", "limit", "=", "$", "this", "->", "_paging", ";", "}", "else", "if", "(", "is_array", "(", "$", "this", "->", "_paging", ")", "&&", "isset", "(", "$", "this", "->", "_paging", "[", "'pageSize'", "]", ")", ")", "{", "$", "limit", "=", "$", "this", "->", "_paging", "[", "'pageSize'", "]", ";", "}", "else", "{", "$", "limit", "=", "$", "this", "->", "_paging", ";", "}", "}", "// wird vermutlich nicht benötigt, da beim ersten laden 'sortInfo' in den metadaten drin ist", "// falls es irgendwo benötigt wird wieder einkommentieren", "// $this->view->order = $order;", "}", "//TODO: dieser code sollte in _getOrder liegen", "$", "order", "=", "$", "this", "->", "_defaultOrder", ";", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'sort'", ")", ")", "{", "$", "order", "[", "'field'", "]", "=", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'sort'", ")", ";", "}", "if", "(", "$", "this", "->", "_getParam", "(", "\"direction\"", ")", "&&", "$", "this", "->", "_getParam", "(", "'direction'", ")", "!=", "'undefined'", ")", "{", "$", "order", "[", "'direction'", "]", "=", "$", "this", "->", "_getParam", "(", "'direction'", ")", ";", "}", "$", "primaryKey", "=", "$", "this", "->", "_primaryKey", ";", "$", "rowSet", "=", "$", "this", "->", "_fetchData", "(", "$", "order", ",", "$", "limit", ",", "$", "start", ")", ";", "if", "(", "!", "is_null", "(", "$", "rowSet", ")", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_paging", "[", "'type'", "]", ")", "&&", "$", "this", "->", "_paging", "[", "'type'", "]", "==", "'Date'", ")", "{", "//nothing to do, we don't know the total", "}", "else", "if", "(", "$", "this", "->", "_paging", ")", "{", "$", "this", "->", "view", "->", "total", "=", "$", "this", "->", "_fetchCount", "(", ")", ";", "}", "else", "{", "$", "this", "->", "view", "->", "total", "=", "sizeof", "(", "$", "rowSet", ")", ";", "}", "$", "number", "=", "0", ";", "if", "(", "$", "start", ")", "$", "number", "=", "$", "start", ";", "$", "rows", "=", "array", "(", ")", ";", "foreach", "(", "$", "rowSet", "as", "$", "row", ")", "{", "$", "r", "=", "array", "(", ")", ";", "if", "(", "is_array", "(", "$", "row", ")", ")", "{", "$", "row", "=", "(", "object", ")", "$", "row", ";", "}", "if", "(", "!", "$", "this", "->", "_hasPermissions", "(", "$", "row", ",", "'load'", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"You don't have the permissions to load this row\"", ")", ";", "}", "foreach", "(", "$", "this", "->", "_columns", "as", "$", "column", ")", "{", "if", "(", "$", "column", "instanceof", "Kwf_Grid_Column_RowNumberer", ")", "continue", ";", "if", "(", "$", "column", "->", "getShowIn", "(", ")", "&", "Kwf_Grid_Column", "::", "SHOW_IN_GRID", ")", "{", "$", "data", "=", "$", "column", "->", "load", "(", "$", "row", ",", "Kwf_Grid_Column", "::", "ROLE_DISPLAY", ",", "array", "(", "'number'", "=>", "$", "number", ",", "'total'", "=>", "$", "this", "->", "view", "->", "total", ",", ")", ")", ";", "$", "r", "[", "$", "column", "->", "getDataIndex", "(", ")", "]", "=", "$", "data", ";", "}", "}", "if", "(", "!", "isset", "(", "$", "r", "[", "$", "primaryKey", "]", ")", "&&", "isset", "(", "$", "row", "->", "$", "primaryKey", ")", ")", "{", "$", "r", "[", "$", "primaryKey", "]", "=", "$", "row", "->", "$", "primaryKey", ";", "}", "$", "rows", "[", "]", "=", "$", "r", ";", "$", "number", "++", ";", "}", "$", "this", "->", "view", "->", "rows", "=", "$", "rows", ";", "}", "else", "{", "$", "this", "->", "view", "->", "total", "=", "0", ";", "$", "this", "->", "view", "->", "rows", "=", "array", "(", ")", ";", "}", "if", "(", "$", "this", "->", "getRequest", "(", ")", "->", "getParam", "(", "'meta'", ")", ")", "{", "$", "this", "->", "_appendMetaData", "(", ")", ";", "}", "}" ]
This function is called when CONTROLLER_URL/json-data is called.
[ "This", "function", "is", "called", "when", "CONTROLLER_URL", "/", "json", "-", "data", "is", "called", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Controller/Action/Auto/Grid.php#L328-L407
koala-framework/koala-framework
Kwc/Directories/Category/Detail/List/Component.php
Kwc_Directories_Category_Detail_List_Component.getTableReferenceData
static public function getTableReferenceData($relationModel, $rule/* = 'Item'*/) { if (is_string($relationModel)) { $relationModel = Kwf_Model_Abstract::getInstance($relationModel); } $reference = $relationModel->getReference($rule); $dataModel = Kwf_Model_Abstract::getInstance($reference['refModelClass']); while ($dataModel instanceof Kwf_Model_Proxy) { $dataModel = $dataModel->getProxyModel(); } return array( 'tableName' => $relationModel->getProxyModel()->getTableName(), 'itemColumn' => $reference['column'], 'refItemColumn' => $dataModel->getPrimaryKey(), 'refTableName' => $dataModel->getTableName() ); }
php
static public function getTableReferenceData($relationModel, $rule/* = 'Item'*/) { if (is_string($relationModel)) { $relationModel = Kwf_Model_Abstract::getInstance($relationModel); } $reference = $relationModel->getReference($rule); $dataModel = Kwf_Model_Abstract::getInstance($reference['refModelClass']); while ($dataModel instanceof Kwf_Model_Proxy) { $dataModel = $dataModel->getProxyModel(); } return array( 'tableName' => $relationModel->getProxyModel()->getTableName(), 'itemColumn' => $reference['column'], 'refItemColumn' => $dataModel->getPrimaryKey(), 'refTableName' => $dataModel->getTableName() ); }
[ "static", "public", "function", "getTableReferenceData", "(", "$", "relationModel", ",", "$", "rule", "/* = 'Item'*/", ")", "{", "if", "(", "is_string", "(", "$", "relationModel", ")", ")", "{", "$", "relationModel", "=", "Kwf_Model_Abstract", "::", "getInstance", "(", "$", "relationModel", ")", ";", "}", "$", "reference", "=", "$", "relationModel", "->", "getReference", "(", "$", "rule", ")", ";", "$", "dataModel", "=", "Kwf_Model_Abstract", "::", "getInstance", "(", "$", "reference", "[", "'refModelClass'", "]", ")", ";", "while", "(", "$", "dataModel", "instanceof", "Kwf_Model_Proxy", ")", "{", "$", "dataModel", "=", "$", "dataModel", "->", "getProxyModel", "(", ")", ";", "}", "return", "array", "(", "'tableName'", "=>", "$", "relationModel", "->", "getProxyModel", "(", ")", "->", "getTableName", "(", ")", ",", "'itemColumn'", "=>", "$", "reference", "[", "'column'", "]", ",", "'refItemColumn'", "=>", "$", "dataModel", "->", "getPrimaryKey", "(", ")", ",", "'refTableName'", "=>", "$", "dataModel", "->", "getTableName", "(", ")", ")", ";", "}" ]
wurder ursprünglich hier verwendet was jedoch auf Expr_Child_Contains umgeschireben wurde
[ "wurder", "ursprünglich", "hier", "verwendet", "was", "jedoch", "auf", "Expr_Child_Contains", "umgeschireben", "wurde" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Directories/Category/Detail/List/Component.php#L31-L49
koala-framework/koala-framework
Kwc/Directories/Item/Directory/Trl/Events.php
Kwc_Directories_Item_Directory_Trl_Events.onChildRowUpdate
public function onChildRowUpdate(Kwf_Events_Event_Row_Updated $event) { $dbId = $event->row->component_id; $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($dbId, array('limit'=>1, 'ignoreVisible'=>true)); if ($c && $c->parent->componentClass == $this->_class) { $this->fireEvent(new Kwc_Directories_List_EventItemUpdated($this->_class, $c->id, $c->getSubroot())); $this->fireEvent(new Kwc_Directories_List_EventItemDeleted($this->_class, $c->id, $c->getSubroot())); } }
php
public function onChildRowUpdate(Kwf_Events_Event_Row_Updated $event) { $dbId = $event->row->component_id; $c = Kwf_Component_Data_Root::getInstance()->getComponentByDbId($dbId, array('limit'=>1, 'ignoreVisible'=>true)); if ($c && $c->parent->componentClass == $this->_class) { $this->fireEvent(new Kwc_Directories_List_EventItemUpdated($this->_class, $c->id, $c->getSubroot())); $this->fireEvent(new Kwc_Directories_List_EventItemDeleted($this->_class, $c->id, $c->getSubroot())); } }
[ "public", "function", "onChildRowUpdate", "(", "Kwf_Events_Event_Row_Updated", "$", "event", ")", "{", "$", "dbId", "=", "$", "event", "->", "row", "->", "component_id", ";", "$", "c", "=", "Kwf_Component_Data_Root", "::", "getInstance", "(", ")", "->", "getComponentByDbId", "(", "$", "dbId", ",", "array", "(", "'limit'", "=>", "1", ",", "'ignoreVisible'", "=>", "true", ")", ")", ";", "if", "(", "$", "c", "&&", "$", "c", "->", "parent", "->", "componentClass", "==", "$", "this", "->", "_class", ")", "{", "$", "this", "->", "fireEvent", "(", "new", "Kwc_Directories_List_EventItemUpdated", "(", "$", "this", "->", "_class", ",", "$", "c", "->", "id", ",", "$", "c", "->", "getSubroot", "(", ")", ")", ")", ";", "$", "this", "->", "fireEvent", "(", "new", "Kwc_Directories_List_EventItemDeleted", "(", "$", "this", "->", "_class", ",", "$", "c", "->", "id", ",", "$", "c", "->", "getSubroot", "(", ")", ")", ")", ";", "}", "}" ]
trl model (optional)
[ "trl", "model", "(", "optional", ")" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Directories/Item/Directory/Trl/Events.php#L86-L94
koala-framework/koala-framework
Kwc/Basic/ImageEnlarge/EnlargeTag/Component.php
Kwc_Basic_ImageEnlarge_EnlargeTag_Component.getImageDimensions
public function getImageDimensions() { $dimension = $this->_getSetting('dimension'); if ($this->getRow()->use_crop) { $parentDimension = $this->_getImageEnlargeComponent()->getImageDimensions(); $dimension['crop'] = $parentDimension['crop']; } $data = $this->getImageData(); return Kwf_Media_Image::calculateScaleDimensions($data['file'], $dimension); }
php
public function getImageDimensions() { $dimension = $this->_getSetting('dimension'); if ($this->getRow()->use_crop) { $parentDimension = $this->_getImageEnlargeComponent()->getImageDimensions(); $dimension['crop'] = $parentDimension['crop']; } $data = $this->getImageData(); return Kwf_Media_Image::calculateScaleDimensions($data['file'], $dimension); }
[ "public", "function", "getImageDimensions", "(", ")", "{", "$", "dimension", "=", "$", "this", "->", "_getSetting", "(", "'dimension'", ")", ";", "if", "(", "$", "this", "->", "getRow", "(", ")", "->", "use_crop", ")", "{", "$", "parentDimension", "=", "$", "this", "->", "_getImageEnlargeComponent", "(", ")", "->", "getImageDimensions", "(", ")", ";", "$", "dimension", "[", "'crop'", "]", "=", "$", "parentDimension", "[", "'crop'", "]", ";", "}", "$", "data", "=", "$", "this", "->", "getImageData", "(", ")", ";", "return", "Kwf_Media_Image", "::", "calculateScaleDimensions", "(", "$", "data", "[", "'file'", "]", ",", "$", "dimension", ")", ";", "}" ]
This function is used by Kwc_Basic_ImageEnlarge_EnlargeTag_ImagePage_Component to get the dimension-values defined in getSettings and the crop-values if use_crop was checked.
[ "This", "function", "is", "used", "by", "Kwc_Basic_ImageEnlarge_EnlargeTag_ImagePage_Component", "to", "get", "the", "dimension", "-", "values", "defined", "in", "getSettings", "and", "the", "crop", "-", "values", "if", "use_crop", "was", "checked", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/ImageEnlarge/EnlargeTag/Component.php#L29-L38
koala-framework/koala-framework
Kwc/Basic/ImageEnlarge/EnlargeTag/Component.php
Kwc_Basic_ImageEnlarge_EnlargeTag_Component.getImageUrl
public function getImageUrl() { $baseUrl = $this->getBaseImageUrl(); if ($baseUrl) { $dimensions = $this->getImageDimensions(); $imageData = $this->getImageData(); $width = Kwf_Media_Image::getResponsiveWidthStep($dimensions['width'], Kwf_Media_Image::getResponsiveWidthSteps($dimensions, $imageData['file'])); $ret = str_replace('{width}', $width, $baseUrl); $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $ret); Kwf_Events_Dispatcher::fireEvent($ev); return $ev->url; } return null; }
php
public function getImageUrl() { $baseUrl = $this->getBaseImageUrl(); if ($baseUrl) { $dimensions = $this->getImageDimensions(); $imageData = $this->getImageData(); $width = Kwf_Media_Image::getResponsiveWidthStep($dimensions['width'], Kwf_Media_Image::getResponsiveWidthSteps($dimensions, $imageData['file'])); $ret = str_replace('{width}', $width, $baseUrl); $ev = new Kwf_Component_Event_CreateMediaUrl($this->getData()->componentClass, $this->getData(), $ret); Kwf_Events_Dispatcher::fireEvent($ev); return $ev->url; } return null; }
[ "public", "function", "getImageUrl", "(", ")", "{", "$", "baseUrl", "=", "$", "this", "->", "getBaseImageUrl", "(", ")", ";", "if", "(", "$", "baseUrl", ")", "{", "$", "dimensions", "=", "$", "this", "->", "getImageDimensions", "(", ")", ";", "$", "imageData", "=", "$", "this", "->", "getImageData", "(", ")", ";", "$", "width", "=", "Kwf_Media_Image", "::", "getResponsiveWidthStep", "(", "$", "dimensions", "[", "'width'", "]", ",", "Kwf_Media_Image", "::", "getResponsiveWidthSteps", "(", "$", "dimensions", ",", "$", "imageData", "[", "'file'", "]", ")", ")", ";", "$", "ret", "=", "str_replace", "(", "'{width}'", ",", "$", "width", ",", "$", "baseUrl", ")", ";", "$", "ev", "=", "new", "Kwf_Component_Event_CreateMediaUrl", "(", "$", "this", "->", "getData", "(", ")", "->", "componentClass", ",", "$", "this", "->", "getData", "(", ")", ",", "$", "ret", ")", ";", "Kwf_Events_Dispatcher", "::", "fireEvent", "(", "$", "ev", ")", ";", "return", "$", "ev", "->", "url", ";", "}", "return", "null", ";", "}" ]
This function is used by Kwc_Basic_ImageEnlarge_EnlargeTag_ImagePage_Component to get the url to show the image from parent with dimension defined through this component.
[ "This", "function", "is", "used", "by", "Kwc_Basic_ImageEnlarge_EnlargeTag_ImagePage_Component", "to", "get", "the", "url", "to", "show", "the", "image", "from", "parent", "with", "dimension", "defined", "through", "this", "component", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Basic/ImageEnlarge/EnlargeTag/Component.php#L99-L113
koala-framework/koala-framework
Kwf/Util/Tcp.php
Kwf_Util_Tcp.getFreePort
public static function getFreePort($from, $host = 'localhost') { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $ret = $from; while (true) { if (@socket_bind($socket, $host, $ret)) { break; } $ret++; if ($ret > $from+100) { $this->fail('can\'t get free port number'); } } socket_close($socket); return $ret; }
php
public static function getFreePort($from, $host = 'localhost') { $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP); $ret = $from; while (true) { if (@socket_bind($socket, $host, $ret)) { break; } $ret++; if ($ret > $from+100) { $this->fail('can\'t get free port number'); } } socket_close($socket); return $ret; }
[ "public", "static", "function", "getFreePort", "(", "$", "from", ",", "$", "host", "=", "'localhost'", ")", "{", "$", "socket", "=", "socket_create", "(", "AF_INET", ",", "SOCK_STREAM", ",", "SOL_TCP", ")", ";", "$", "ret", "=", "$", "from", ";", "while", "(", "true", ")", "{", "if", "(", "@", "socket_bind", "(", "$", "socket", ",", "$", "host", ",", "$", "ret", ")", ")", "{", "break", ";", "}", "$", "ret", "++", ";", "if", "(", "$", "ret", ">", "$", "from", "+", "100", ")", "{", "$", "this", "->", "fail", "(", "'can\\'t get free port number'", ")", ";", "}", "}", "socket_close", "(", "$", "socket", ")", ";", "return", "$", "ret", ";", "}" ]
Get a free port number No perfect solution, race conditions can occur
[ "Get", "a", "free", "port", "number" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Tcp.php#L9-L24
koala-framework/koala-framework
Kwc/Chained/Trl/GeneratorEvents/Table.php
Kwc_Chained_Trl_GeneratorEvents_Table._fireComponentEvent
protected function _fireComponentEvent($eventType, Kwf_Component_Data $c, $flag) { $cls = 'Kwf_Component_Event_Component_'.$eventType; $this->fireEvent(new $cls($c->componentClass, $c, $flag)); }
php
protected function _fireComponentEvent($eventType, Kwf_Component_Data $c, $flag) { $cls = 'Kwf_Component_Event_Component_'.$eventType; $this->fireEvent(new $cls($c->componentClass, $c, $flag)); }
[ "protected", "function", "_fireComponentEvent", "(", "$", "eventType", ",", "Kwf_Component_Data", "$", "c", ",", "$", "flag", ")", "{", "$", "cls", "=", "'Kwf_Component_Event_Component_'", ".", "$", "eventType", ";", "$", "this", "->", "fireEvent", "(", "new", "$", "cls", "(", "$", "c", "->", "componentClass", ",", "$", "c", ",", "$", "flag", ")", ")", ";", "}" ]
overridden in Page_Events_Table to fire Page events
[ "overridden", "in", "Page_Events_Table", "to", "fire", "Page", "events" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Chained/Trl/GeneratorEvents/Table.php#L45-L49
koala-framework/koala-framework
Kwf/Assets/Util/Trl.php
Kwf_Assets_Util_Trl.getJsReplacement
public static function getJsReplacement($trlElement) { $b = $trlElement['before']; $fn = substr($b, 0, strpos($b, '(')); $key = $trlElement['type'].'.'.$trlElement['source']; if (isset($trlElement['context'])) $key .= '.'.$trlElement['context']; $key .= '.'.str_replace("'", "\\'", $trlElement['text']); $replace = ''; if (preg_match('#^(_?([a-z]+(2\.default)?\.))trl#i', $b, $m)) { $replace = substr($b, 0, strlen($m[1])); } if ($trlElement['type'] == 'trlp' || $trlElement['type'] == 'trlcp') { $replace .= "_kwfTrlp"; } else { $replace .= "_kwfTrl"; } $replace .= "('$key', ".substr($b, strpos($b, '(')+1); unset($trlElement['before']); unset($trlElement['linenr']); unset($trlElement['error_short']); return array( 'before' => $b, 'replace' => $replace, 'trlElement' => (object)$trlElement ); }
php
public static function getJsReplacement($trlElement) { $b = $trlElement['before']; $fn = substr($b, 0, strpos($b, '(')); $key = $trlElement['type'].'.'.$trlElement['source']; if (isset($trlElement['context'])) $key .= '.'.$trlElement['context']; $key .= '.'.str_replace("'", "\\'", $trlElement['text']); $replace = ''; if (preg_match('#^(_?([a-z]+(2\.default)?\.))trl#i', $b, $m)) { $replace = substr($b, 0, strlen($m[1])); } if ($trlElement['type'] == 'trlp' || $trlElement['type'] == 'trlcp') { $replace .= "_kwfTrlp"; } else { $replace .= "_kwfTrl"; } $replace .= "('$key', ".substr($b, strpos($b, '(')+1); unset($trlElement['before']); unset($trlElement['linenr']); unset($trlElement['error_short']); return array( 'before' => $b, 'replace' => $replace, 'trlElement' => (object)$trlElement ); }
[ "public", "static", "function", "getJsReplacement", "(", "$", "trlElement", ")", "{", "$", "b", "=", "$", "trlElement", "[", "'before'", "]", ";", "$", "fn", "=", "substr", "(", "$", "b", ",", "0", ",", "strpos", "(", "$", "b", ",", "'('", ")", ")", ";", "$", "key", "=", "$", "trlElement", "[", "'type'", "]", ".", "'.'", ".", "$", "trlElement", "[", "'source'", "]", ";", "if", "(", "isset", "(", "$", "trlElement", "[", "'context'", "]", ")", ")", "$", "key", ".=", "'.'", ".", "$", "trlElement", "[", "'context'", "]", ";", "$", "key", ".=", "'.'", ".", "str_replace", "(", "\"'\"", ",", "\"\\\\'\"", ",", "$", "trlElement", "[", "'text'", "]", ")", ";", "$", "replace", "=", "''", ";", "if", "(", "preg_match", "(", "'#^(_?([a-z]+(2\\.default)?\\.))trl#i'", ",", "$", "b", ",", "$", "m", ")", ")", "{", "$", "replace", "=", "substr", "(", "$", "b", ",", "0", ",", "strlen", "(", "$", "m", "[", "1", "]", ")", ")", ";", "}", "if", "(", "$", "trlElement", "[", "'type'", "]", "==", "'trlp'", "||", "$", "trlElement", "[", "'type'", "]", "==", "'trlcp'", ")", "{", "$", "replace", ".=", "\"_kwfTrlp\"", ";", "}", "else", "{", "$", "replace", ".=", "\"_kwfTrl\"", ";", "}", "$", "replace", ".=", "\"('$key', \"", ".", "substr", "(", "$", "b", ",", "strpos", "(", "$", "b", ",", "'('", ")", "+", "1", ")", ";", "unset", "(", "$", "trlElement", "[", "'before'", "]", ")", ";", "unset", "(", "$", "trlElement", "[", "'linenr'", "]", ")", ";", "unset", "(", "$", "trlElement", "[", "'error_short'", "]", ")", ";", "return", "array", "(", "'before'", "=>", "$", "b", ",", "'replace'", "=>", "$", "replace", ",", "'trlElement'", "=>", "(", "object", ")", "$", "trlElement", ")", ";", "}" ]
used by Kwf_Assets_Dependency_File_Js and Kwf_Assets_CommonJs_Underscore_TemplateDependency
[ "used", "by", "Kwf_Assets_Dependency_File_Js", "and", "Kwf_Assets_CommonJs_Underscore_TemplateDependency" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Assets/Util/Trl.php#L6-L33
koala-framework/koala-framework
Kwf/Util/ModelSync.php
Kwf_Util_ModelSync.sync
public static function sync(Kwf_Model_Abstract $model, array $compareColumns, array $data, Kwf_Model_Select $select = null) { $sync = new Kwf_Util_ModelSync($model, $compareColumns); $sync->syncData($data, $select); return $sync->getMappingForLastSync(); }
php
public static function sync(Kwf_Model_Abstract $model, array $compareColumns, array $data, Kwf_Model_Select $select = null) { $sync = new Kwf_Util_ModelSync($model, $compareColumns); $sync->syncData($data, $select); return $sync->getMappingForLastSync(); }
[ "public", "static", "function", "sync", "(", "Kwf_Model_Abstract", "$", "model", ",", "array", "$", "compareColumns", ",", "array", "$", "data", ",", "Kwf_Model_Select", "$", "select", "=", "null", ")", "{", "$", "sync", "=", "new", "Kwf_Util_ModelSync", "(", "$", "model", ",", "$", "compareColumns", ")", ";", "$", "sync", "->", "syncData", "(", "$", "data", ",", "$", "select", ")", ";", "return", "$", "sync", "->", "getMappingForLastSync", "(", ")", ";", "}" ]
Syncs given array with given rowset @param mixed Model @param array() Name of columns which are used to compare the syncing rows @param array Data to sync @param mixed Which rows are to be considered for syncing @return array Mapping of synced rows ("key of import array" => "id of synced row")
[ "Syncs", "given", "array", "with", "given", "rowset" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/ModelSync.php#L92-L97
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.setOptions
public function setOptions(Array $options) { foreach ($options as $key => $value) { switch ($key) { case self::ADAPTER: $this->_setAdapter($value); break; case self::SCHEMA: $this->_schema = (string) $value; break; case self::NAME: $this->_name = (string) $value; break; case self::PRIMARY: $this->_primary = (array) $value; break; case self::SEQUENCE: $this->_setSequence($value); break; default: // ignore unrecognized configuration directive break; } } return $this; }
php
public function setOptions(Array $options) { foreach ($options as $key => $value) { switch ($key) { case self::ADAPTER: $this->_setAdapter($value); break; case self::SCHEMA: $this->_schema = (string) $value; break; case self::NAME: $this->_name = (string) $value; break; case self::PRIMARY: $this->_primary = (array) $value; break; case self::SEQUENCE: $this->_setSequence($value); break; default: // ignore unrecognized configuration directive break; } } return $this; }
[ "public", "function", "setOptions", "(", "Array", "$", "options", ")", "{", "foreach", "(", "$", "options", "as", "$", "key", "=>", "$", "value", ")", "{", "switch", "(", "$", "key", ")", "{", "case", "self", "::", "ADAPTER", ":", "$", "this", "->", "_setAdapter", "(", "$", "value", ")", ";", "break", ";", "case", "self", "::", "SCHEMA", ":", "$", "this", "->", "_schema", "=", "(", "string", ")", "$", "value", ";", "break", ";", "case", "self", "::", "NAME", ":", "$", "this", "->", "_name", "=", "(", "string", ")", "$", "value", ";", "break", ";", "case", "self", "::", "PRIMARY", ":", "$", "this", "->", "_primary", "=", "(", "array", ")", "$", "value", ";", "break", ";", "case", "self", "::", "SEQUENCE", ":", "$", "this", "->", "_setSequence", "(", "$", "value", ")", ";", "break", ";", "default", ":", "// ignore unrecognized configuration directive", "break", ";", "}", "}", "return", "$", "this", ";", "}" ]
setOptions() @param array $options @return Kwf_Db_Table
[ "setOptions", "()" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L222-L248
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table._setupTableName
protected function _setupTableName() { if (strpos($this->_name, '.')) { list($this->_schema, $this->_name) = explode('.', $this->_name); } }
php
protected function _setupTableName() { if (strpos($this->_name, '.')) { list($this->_schema, $this->_name) = explode('.', $this->_name); } }
[ "protected", "function", "_setupTableName", "(", ")", "{", "if", "(", "strpos", "(", "$", "this", "->", "_name", ",", "'.'", ")", ")", "{", "list", "(", "$", "this", "->", "_schema", ",", "$", "this", "->", "_name", ")", "=", "explode", "(", "'.'", ",", "$", "this", "->", "_name", ")", ";", "}", "}" ]
Initialize table and schema names. If the table name is not set in the class definition, use the class name itself as the table name. A schema name provided with the table name (e.g., "schema.table") overrides any existing value for $this->_schema. @return void
[ "Initialize", "table", "and", "schema", "names", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L303-L308
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table._setupMetadata
protected function _setupMetadata() { if (count($this->_metadata) > 0) { return true; } // Assume that metadata will be loaded from cache $isMetadataFromCache = true; // Define the cache identifier where the metadata are saved //get db configuration $dbConfig = $this->_db->getConfig(); $port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : (isset($dbConfig['port']) ? ':'.$dbConfig['port'] : null); $host = isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : (isset($dbConfig['host']) ? ':'.$dbConfig['host'] : null); // Define the cache identifier where the metadata are saved $cacheId = 'dbtbl_'.md5( // port:host/dbname:schema.table (based on availabilty) $port . $host . '/'. $dbConfig['dbname'] . ':' . $this->_schema. '.' . $this->_name ); // If $this has no metadata cache or metadata cache misses if (!($metadata = Kwf_Cache_SimpleStatic::fetch($cacheId))) { // Metadata are not loaded from cache $isMetadataFromCache = false; // Fetch metadata from the adapter's describeTable() method $metadata = $this->_db->describeTable($this->_name, $this->_schema); // If $this has a metadata cache, then cache the metadata Kwf_Cache_SimpleStatic::add($cacheId, $metadata); } // Assign the metadata to $this $this->_metadata = $metadata; // Return whether the metadata were loaded from cache return $isMetadataFromCache; }
php
protected function _setupMetadata() { if (count($this->_metadata) > 0) { return true; } // Assume that metadata will be loaded from cache $isMetadataFromCache = true; // Define the cache identifier where the metadata are saved //get db configuration $dbConfig = $this->_db->getConfig(); $port = isset($dbConfig['options']['port']) ? ':'.$dbConfig['options']['port'] : (isset($dbConfig['port']) ? ':'.$dbConfig['port'] : null); $host = isset($dbConfig['options']['host']) ? ':'.$dbConfig['options']['host'] : (isset($dbConfig['host']) ? ':'.$dbConfig['host'] : null); // Define the cache identifier where the metadata are saved $cacheId = 'dbtbl_'.md5( // port:host/dbname:schema.table (based on availabilty) $port . $host . '/'. $dbConfig['dbname'] . ':' . $this->_schema. '.' . $this->_name ); // If $this has no metadata cache or metadata cache misses if (!($metadata = Kwf_Cache_SimpleStatic::fetch($cacheId))) { // Metadata are not loaded from cache $isMetadataFromCache = false; // Fetch metadata from the adapter's describeTable() method $metadata = $this->_db->describeTable($this->_name, $this->_schema); // If $this has a metadata cache, then cache the metadata Kwf_Cache_SimpleStatic::add($cacheId, $metadata); } // Assign the metadata to $this $this->_metadata = $metadata; // Return whether the metadata were loaded from cache return $isMetadataFromCache; }
[ "protected", "function", "_setupMetadata", "(", ")", "{", "if", "(", "count", "(", "$", "this", "->", "_metadata", ")", ">", "0", ")", "{", "return", "true", ";", "}", "// Assume that metadata will be loaded from cache", "$", "isMetadataFromCache", "=", "true", ";", "// Define the cache identifier where the metadata are saved", "//get db configuration", "$", "dbConfig", "=", "$", "this", "->", "_db", "->", "getConfig", "(", ")", ";", "$", "port", "=", "isset", "(", "$", "dbConfig", "[", "'options'", "]", "[", "'port'", "]", ")", "?", "':'", ".", "$", "dbConfig", "[", "'options'", "]", "[", "'port'", "]", ":", "(", "isset", "(", "$", "dbConfig", "[", "'port'", "]", ")", "?", "':'", ".", "$", "dbConfig", "[", "'port'", "]", ":", "null", ")", ";", "$", "host", "=", "isset", "(", "$", "dbConfig", "[", "'options'", "]", "[", "'host'", "]", ")", "?", "':'", ".", "$", "dbConfig", "[", "'options'", "]", "[", "'host'", "]", ":", "(", "isset", "(", "$", "dbConfig", "[", "'host'", "]", ")", "?", "':'", ".", "$", "dbConfig", "[", "'host'", "]", ":", "null", ")", ";", "// Define the cache identifier where the metadata are saved", "$", "cacheId", "=", "'dbtbl_'", ".", "md5", "(", "// port:host/dbname:schema.table (based on availabilty)", "$", "port", ".", "$", "host", ".", "'/'", ".", "$", "dbConfig", "[", "'dbname'", "]", ".", "':'", ".", "$", "this", "->", "_schema", ".", "'.'", ".", "$", "this", "->", "_name", ")", ";", "// If $this has no metadata cache or metadata cache misses", "if", "(", "!", "(", "$", "metadata", "=", "Kwf_Cache_SimpleStatic", "::", "fetch", "(", "$", "cacheId", ")", ")", ")", "{", "// Metadata are not loaded from cache", "$", "isMetadataFromCache", "=", "false", ";", "// Fetch metadata from the adapter's describeTable() method", "$", "metadata", "=", "$", "this", "->", "_db", "->", "describeTable", "(", "$", "this", "->", "_name", ",", "$", "this", "->", "_schema", ")", ";", "// If $this has a metadata cache, then cache the metadata", "Kwf_Cache_SimpleStatic", "::", "add", "(", "$", "cacheId", ",", "$", "metadata", ")", ";", "}", "// Assign the metadata to $this", "$", "this", "->", "_metadata", "=", "$", "metadata", ";", "// Return whether the metadata were loaded from cache", "return", "$", "isMetadataFromCache", ";", "}" ]
Initializes metadata. If metadata cannot be loaded from cache, adapter's describeTable() method is called to discover metadata information. Returns true if and only if the metadata are loaded from cache. @return boolean @throws Kwf_Exception
[ "Initializes", "metadata", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L319-L366
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.getColumns
public function getColumns() { if (null === $this->_cols) { $this->_setupMetadata(); $this->_cols = array_keys($this->_metadata); } return $this->_cols; }
php
public function getColumns() { if (null === $this->_cols) { $this->_setupMetadata(); $this->_cols = array_keys($this->_metadata); } return $this->_cols; }
[ "public", "function", "getColumns", "(", ")", "{", "if", "(", "null", "===", "$", "this", "->", "_cols", ")", "{", "$", "this", "->", "_setupMetadata", "(", ")", ";", "$", "this", "->", "_cols", "=", "array_keys", "(", "$", "this", "->", "_metadata", ")", ";", "}", "return", "$", "this", "->", "_cols", ";", "}" ]
Retrieve table columns @return array
[ "Retrieve", "table", "columns" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L373-L380
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.info
public function info($key = null) { $this->_setupPrimaryKey(); $info = array( self::SCHEMA => $this->_schema, self::NAME => $this->_name, self::COLS => $this->getColumns(), self::PRIMARY => $this->getPrimaryKey(), self::METADATA => $this->_metadata, self::SEQUENCE => $this->_sequence ); if ($key === null) { return $info; } if (!array_key_exists($key, $info)) { throw new Kwf_Exception('There is no table information for the key "' . $key . '"'); } return $info[$key]; }
php
public function info($key = null) { $this->_setupPrimaryKey(); $info = array( self::SCHEMA => $this->_schema, self::NAME => $this->_name, self::COLS => $this->getColumns(), self::PRIMARY => $this->getPrimaryKey(), self::METADATA => $this->_metadata, self::SEQUENCE => $this->_sequence ); if ($key === null) { return $info; } if (!array_key_exists($key, $info)) { throw new Kwf_Exception('There is no table information for the key "' . $key . '"'); } return $info[$key]; }
[ "public", "function", "info", "(", "$", "key", "=", "null", ")", "{", "$", "this", "->", "_setupPrimaryKey", "(", ")", ";", "$", "info", "=", "array", "(", "self", "::", "SCHEMA", "=>", "$", "this", "->", "_schema", ",", "self", "::", "NAME", "=>", "$", "this", "->", "_name", ",", "self", "::", "COLS", "=>", "$", "this", "->", "getColumns", "(", ")", ",", "self", "::", "PRIMARY", "=>", "$", "this", "->", "getPrimaryKey", "(", ")", ",", "self", "::", "METADATA", "=>", "$", "this", "->", "_metadata", ",", "self", "::", "SEQUENCE", "=>", "$", "this", "->", "_sequence", ")", ";", "if", "(", "$", "key", "===", "null", ")", "{", "return", "$", "info", ";", "}", "if", "(", "!", "array_key_exists", "(", "$", "key", ",", "$", "info", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "'There is no table information for the key \"'", ".", "$", "key", ".", "'\"'", ")", ";", "}", "return", "$", "info", "[", "$", "key", "]", ";", "}" ]
Returns table information. You can elect to return only a part of this information by supplying its key name, otherwise all information is returned as an array. @param string $key The specific info part to return OPTIONAL @return mixed @throws Kwf_Exception
[ "Returns", "table", "information", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L476-L498
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.fetchAll
public function fetchAll($where = null, $order = null, $count = null, $offset = null) { if (!($where instanceof Kwf_Db_Table_Select)) { $select = $this->select(); if ($where !== null) { $this->_where($select, $where); } if ($order !== null) { $this->_order($select, $order); } if ($count !== null || $offset !== null) { $select->limit($count, $offset); } } else { $select = $where; } $rows = $this->_fetch($select); $data = array( 'table' => $this, 'data' => $rows, 'rowClass' => $this->_rowClass, 'stored' => true ); $rowsetClass = $this->_rowsetClass; return new $rowsetClass($data); }
php
public function fetchAll($where = null, $order = null, $count = null, $offset = null) { if (!($where instanceof Kwf_Db_Table_Select)) { $select = $this->select(); if ($where !== null) { $this->_where($select, $where); } if ($order !== null) { $this->_order($select, $order); } if ($count !== null || $offset !== null) { $select->limit($count, $offset); } } else { $select = $where; } $rows = $this->_fetch($select); $data = array( 'table' => $this, 'data' => $rows, 'rowClass' => $this->_rowClass, 'stored' => true ); $rowsetClass = $this->_rowsetClass; return new $rowsetClass($data); }
[ "public", "function", "fetchAll", "(", "$", "where", "=", "null", ",", "$", "order", "=", "null", ",", "$", "count", "=", "null", ",", "$", "offset", "=", "null", ")", "{", "if", "(", "!", "(", "$", "where", "instanceof", "Kwf_Db_Table_Select", ")", ")", "{", "$", "select", "=", "$", "this", "->", "select", "(", ")", ";", "if", "(", "$", "where", "!==", "null", ")", "{", "$", "this", "->", "_where", "(", "$", "select", ",", "$", "where", ")", ";", "}", "if", "(", "$", "order", "!==", "null", ")", "{", "$", "this", "->", "_order", "(", "$", "select", ",", "$", "order", ")", ";", "}", "if", "(", "$", "count", "!==", "null", "||", "$", "offset", "!==", "null", ")", "{", "$", "select", "->", "limit", "(", "$", "count", ",", "$", "offset", ")", ";", "}", "}", "else", "{", "$", "select", "=", "$", "where", ";", "}", "$", "rows", "=", "$", "this", "->", "_fetch", "(", "$", "select", ")", ";", "$", "data", "=", "array", "(", "'table'", "=>", "$", "this", ",", "'data'", "=>", "$", "rows", ",", "'rowClass'", "=>", "$", "this", "->", "_rowClass", ",", "'stored'", "=>", "true", ")", ";", "$", "rowsetClass", "=", "$", "this", "->", "_rowsetClass", ";", "return", "new", "$", "rowsetClass", "(", "$", "data", ")", ";", "}" ]
Fetches all rows. Honors the Zend_Db_Adapter fetch mode. @param string|array|Kwf_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Kwf_Db_Table_Select object. @param string|array $order OPTIONAL An SQL ORDER clause. @param int $count OPTIONAL An SQL LIMIT count. @param int $offset OPTIONAL An SQL LIMIT offset. @return Kwf_Db_Table_Rowset The row results per the Zend_Db_Adapter fetch mode.
[ "Fetches", "all", "rows", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L610-L642
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.fetchRow
public function fetchRow($where = null, $order = null, $offset = null) { if (!($where instanceof Kwf_Db_Table_Select)) { $select = $this->select(); if ($where !== null) { $this->_where($select, $where); } if ($order !== null) { $this->_order($select, $order); } $select->limit(1, ((is_numeric($offset)) ? (int) $offset : null)); } else { $select = $where->limit(1, $where->getPart(Zend_Db_Select::LIMIT_OFFSET)); } $rows = $this->_fetch($select); if (count($rows) == 0) { return null; } $data = array( 'table' => $this, 'data' => $rows[0], 'stored' => true ); $rowClass = $this->_rowClass; return new $rowClass($data); }
php
public function fetchRow($where = null, $order = null, $offset = null) { if (!($where instanceof Kwf_Db_Table_Select)) { $select = $this->select(); if ($where !== null) { $this->_where($select, $where); } if ($order !== null) { $this->_order($select, $order); } $select->limit(1, ((is_numeric($offset)) ? (int) $offset : null)); } else { $select = $where->limit(1, $where->getPart(Zend_Db_Select::LIMIT_OFFSET)); } $rows = $this->_fetch($select); if (count($rows) == 0) { return null; } $data = array( 'table' => $this, 'data' => $rows[0], 'stored' => true ); $rowClass = $this->_rowClass; return new $rowClass($data); }
[ "public", "function", "fetchRow", "(", "$", "where", "=", "null", ",", "$", "order", "=", "null", ",", "$", "offset", "=", "null", ")", "{", "if", "(", "!", "(", "$", "where", "instanceof", "Kwf_Db_Table_Select", ")", ")", "{", "$", "select", "=", "$", "this", "->", "select", "(", ")", ";", "if", "(", "$", "where", "!==", "null", ")", "{", "$", "this", "->", "_where", "(", "$", "select", ",", "$", "where", ")", ";", "}", "if", "(", "$", "order", "!==", "null", ")", "{", "$", "this", "->", "_order", "(", "$", "select", ",", "$", "order", ")", ";", "}", "$", "select", "->", "limit", "(", "1", ",", "(", "(", "is_numeric", "(", "$", "offset", ")", ")", "?", "(", "int", ")", "$", "offset", ":", "null", ")", ")", ";", "}", "else", "{", "$", "select", "=", "$", "where", "->", "limit", "(", "1", ",", "$", "where", "->", "getPart", "(", "Zend_Db_Select", "::", "LIMIT_OFFSET", ")", ")", ";", "}", "$", "rows", "=", "$", "this", "->", "_fetch", "(", "$", "select", ")", ";", "if", "(", "count", "(", "$", "rows", ")", "==", "0", ")", "{", "return", "null", ";", "}", "$", "data", "=", "array", "(", "'table'", "=>", "$", "this", ",", "'data'", "=>", "$", "rows", "[", "0", "]", ",", "'stored'", "=>", "true", ")", ";", "$", "rowClass", "=", "$", "this", "->", "_rowClass", ";", "return", "new", "$", "rowClass", "(", "$", "data", ")", ";", "}" ]
Fetches one row in an object of type Kwf_Db_Table_Row, or returns null if no row matches the specified criteria. @param string|array|Kwf_Db_Table_Select $where OPTIONAL An SQL WHERE clause or Kwf_Db_Table_Select object. @param string|array $order OPTIONAL An SQL ORDER clause. @param int $offset OPTIONAL An SQL OFFSET value. @return Kwf_Db_Table_Row|null The row results per the Zend_Db_Adapter fetch mode, or null if no row found.
[ "Fetches", "one", "row", "in", "an", "object", "of", "type", "Kwf_Db_Table_Row", "or", "returns", "null", "if", "no", "row", "matches", "the", "specified", "criteria", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L654-L687
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table.createRow
public function createRow(array $data = array()) { $cols = $this->getColumns(); $defaults = array_combine($cols, array_fill(0, count($cols), null)); $config = array( 'table' => $this, 'data' => $defaults, 'stored' => false ); $rowClass = $this->_rowClass; $row = new $rowClass($config); $row->setFromArray($data); return $row; }
php
public function createRow(array $data = array()) { $cols = $this->getColumns(); $defaults = array_combine($cols, array_fill(0, count($cols), null)); $config = array( 'table' => $this, 'data' => $defaults, 'stored' => false ); $rowClass = $this->_rowClass; $row = new $rowClass($config); $row->setFromArray($data); return $row; }
[ "public", "function", "createRow", "(", "array", "$", "data", "=", "array", "(", ")", ")", "{", "$", "cols", "=", "$", "this", "->", "getColumns", "(", ")", ";", "$", "defaults", "=", "array_combine", "(", "$", "cols", ",", "array_fill", "(", "0", ",", "count", "(", "$", "cols", ")", ",", "null", ")", ")", ";", "$", "config", "=", "array", "(", "'table'", "=>", "$", "this", ",", "'data'", "=>", "$", "defaults", ",", "'stored'", "=>", "false", ")", ";", "$", "rowClass", "=", "$", "this", "->", "_rowClass", ";", "$", "row", "=", "new", "$", "rowClass", "(", "$", "config", ")", ";", "$", "row", "->", "setFromArray", "(", "$", "data", ")", ";", "return", "$", "row", ";", "}" ]
Fetches a new blank row (not from the database). @param array $data OPTIONAL data to populate in the new row. @return Kwf_Db_Table_Row_Abstract
[ "Fetches", "a", "new", "blank", "row", "(", "not", "from", "the", "database", ")", "." ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L695-L710
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table._where
protected function _where(Kwf_Db_Table_Select $select, $where) { $where = (array) $where; foreach ($where as $key => $val) { // is $key an int? if (is_int($key)) { // $val is the full condition $select->where($val); } else { // $key is the condition with placeholder, // and $val is quoted into the condition $select->where($key, $val); } } return $select; }
php
protected function _where(Kwf_Db_Table_Select $select, $where) { $where = (array) $where; foreach ($where as $key => $val) { // is $key an int? if (is_int($key)) { // $val is the full condition $select->where($val); } else { // $key is the condition with placeholder, // and $val is quoted into the condition $select->where($key, $val); } } return $select; }
[ "protected", "function", "_where", "(", "Kwf_Db_Table_Select", "$", "select", ",", "$", "where", ")", "{", "$", "where", "=", "(", "array", ")", "$", "where", ";", "foreach", "(", "$", "where", "as", "$", "key", "=>", "$", "val", ")", "{", "// is $key an int?", "if", "(", "is_int", "(", "$", "key", ")", ")", "{", "// $val is the full condition", "$", "select", "->", "where", "(", "$", "val", ")", ";", "}", "else", "{", "// $key is the condition with placeholder,", "// and $val is quoted into the condition", "$", "select", "->", "where", "(", "$", "key", ",", "$", "val", ")", ";", "}", "}", "return", "$", "select", ";", "}" ]
Generate WHERE clause from user-supplied string or array @param string|array $where OPTIONAL An SQL WHERE clause. @return Kwf_Db_Table_Select
[ "Generate", "WHERE", "clause", "from", "user", "-", "supplied", "string", "or", "array" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L718-L735
koala-framework/koala-framework
Kwf/Db/Table.php
Kwf_Db_Table._order
protected function _order(Kwf_Db_Table_Select $select, $order) { if (!is_array($order)) { $order = array($order); } foreach ($order as $val) { $select->order($val); } return $select; }
php
protected function _order(Kwf_Db_Table_Select $select, $order) { if (!is_array($order)) { $order = array($order); } foreach ($order as $val) { $select->order($val); } return $select; }
[ "protected", "function", "_order", "(", "Kwf_Db_Table_Select", "$", "select", ",", "$", "order", ")", "{", "if", "(", "!", "is_array", "(", "$", "order", ")", ")", "{", "$", "order", "=", "array", "(", "$", "order", ")", ";", "}", "foreach", "(", "$", "order", "as", "$", "val", ")", "{", "$", "select", "->", "order", "(", "$", "val", ")", ";", "}", "return", "$", "select", ";", "}" ]
Generate ORDER clause from user-supplied string or array @param string|array $order OPTIONAL An SQL ORDER clause. @return Kwf_Db_Table_Select
[ "Generate", "ORDER", "clause", "from", "user", "-", "supplied", "string", "or", "array" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Db/Table.php#L743-L754
koala-framework/koala-framework
Kwf/Media/Output.php
Kwf_Media_Output.getOutputData
public static function getOutputData($file, array $headers) { $ret = array('headers' => array()); if (!isset($file['contents'])) { if (isset($file['file'])) { if (!is_file($file['file'])) { throw new Kwf_Exception_NotFound("File '$file[file]' not found."); } if (!isset($file['mtime'])) $file['mtime'] = filemtime($file['file']); } else if (isset($file['contentsCallback'])) { //contents will be fetched on demand thru contentsCallback } else { throw new Kwf_Exception_NotFound(); } } if (isset($file['mtime'])) { $lastModifiedString = gmdate("D, d M Y H:i:s \G\M\T", $file['mtime']); } $lifetime = (24*60*60*7*4); if (isset($file['lifetime'])) { if ($file['lifetime'] === false) { $lifetime = false; } else { $lifetime = $file['lifetime']; } } // According to following link it's not possible in IE<9 to download // any file with Pragma set to "no-cache" or order of Cache-Control other // than "no-store, no-cache" when using a SSL connection. // http://blogs.msdn.com/b/ieinternals/archive/2009/10/02/internet-explorer-cannot-download-over-https-when-no-cache.aspx // The order of Cache-Control is correct in default-implementation so // it's only required to reset Pragma to nothing. // The definition of Pragma can be found here (http://www.ietf.org/rfc/rfc2616.txt) // at chapter 14.32 if ($lifetime) { if (isset($headers['Https']) && isset($headers['User-Agent']) && preg_match('/msie [6-8]/i', $headers['User-Agent']) ) { $ret['headers'][] = 'Cache-Control: private, max-age='.$lifetime; $ret['headers'][] = 'Pragma:'; } else { $ret['headers'][] = 'Cache-Control: public, max-age='.$lifetime; $ret['headers'][] = 'Expires: '.gmdate("D, d M Y H:i:s \G\M\T", time()+$lifetime); $ret['headers'][] = 'Pragma: public'; } } else { $ret['headers'][] = 'Cache-Control: private'; $ret['headers'][] = 'Pragma:'; } if (isset($file['mtime']) && isset($headers['If-Modified-Since']) && $file['mtime'] <= strtotime($headers['If-Modified-Since'])) { $ret['responseCode'] = 304; $ret['contentLength'] = 0; if (PHP_SAPI == 'cgi-fcgi') { $ret['headers'][] = "Status: 304 Not Modified"; } else { $ret['headers'][] = array('Not Modified', true, 304); } $ret['headers'][] = 'Last-Modified: '.$headers['If-Modified-Since']; } else if (isset($file['etag']) && isset($headers['If-None-Match']) && $headers['If-None-Match'] == $file['etag']) { $ret['responseCode'] = 304; $ret['contentLength'] = 0; if (PHP_SAPI == 'cgi-fcgi') { $ret['headers'][] = "Status: 304 Not Modified"; } else { $ret['headers'][] = array('Not Modified', true, 304); } $ret['headers'][] = 'ETag: '.$headers['If-None-Match']; } else { if (substr($file['mimeType'], 0, 12) != 'application/') { $ret['headers'][] = 'Accept-Ranges: bytes'; if (isset($headers['Range'])) { $ret['responseCode'] = 206; $ret['headers'][] = array('Partial Content', true, 206); } else { $ret['responseCode'] = 200; } } else { $ret['headers'][] = 'Accept-Ranges: none'; $ret['responseCode'] = 200; } if (isset($file['etag'])) { $ret['headers'][] = 'ETag: ' . $file['etag']; } else { //wird benötigt für IE der sonst den download verweigert $ret['headers'][] = 'ETag: tag'; } if (isset($file['mtime'] )) $ret['headers'][] = 'Last-Modified: ' . $lastModifiedString; if (isset($file['downloadFilename']) && $file['downloadFilename']) { $ret['headers'][] = 'Content-Disposition: attachment; filename="' . $file['downloadFilename'] . '"'; } if (isset($file['filename']) && $file['filename']) { $ret['headers'][] = 'Content-Disposition: inline; filename="' . $file['filename'] . '"'; } $encoding = self::ENCODING_NONE; if (isset($file['encoding'])) { $encoding = $file['encoding']; } else { if (substr($file['mimeType'], 0, 5) == 'text/' || $file['mimeType'] == 'application/json') { if (isset($file['contents'])) { $encoding = self::getEncoding($headers); $file['contents'] = self::encode($file['contents'], $encoding); } else if (isset($file['contentsCallback'])) { $encoding = self::getEncoding($headers); if (isset($file['cache'])) { $file['contents'] = $file['cache']->load($file['cacheId'].'_'.$encoding); if ($file['contents']===false) { $contents = call_user_func($file['contentsCallback'], $file); $file['contents'] = self::encode($contents, $encoding); $file['cache']->save($file['contents'], $file['cacheId'].'_'.$encoding); } } else { $contents = call_user_func($file['contentsCallback'], $file); $file['contents'] = self::encode($contents, $encoding); } } else { //don't encode file (as they are usually large and read using readfile) } } } $ret['encoding'] = $encoding; if ($encoding != self::ENCODING_NONE) { $ret['headers'][] = 'Content-Encoding: ' . $encoding; } $ret['headers'][] = 'Content-Type: ' . $file['mimeType']; if (!isset($file['contents']) && isset($file['contentsCallback'])) { if (isset($file['cache'])) { $file['contents'] = $file['cache']->load($file['cacheId'].'_'.$encoding); if ($file['contents']===false) { $file['contents'] = call_user_func($file['contentsCallback'], $file); $file['cache']->save($file['contents'], $file['cacheId'].'_'.$encoding); } } else { $file['contents'] = call_user_func($file['contentsCallback'], $file); } } if (isset($file['contents'])) { if (isset($headers['Range'])) { if (!preg_match('#bytes#', $headers['Range'])) { throw new Kwf_Exception('wrong Range-Type'); } $range = explode('=', $headers['Range']); $range = explode('-', $range[1]); $ret['contents'] = substr($file['contents'], $range[0], $range[1]+1); $ret['contentLength'] = strlen($ret['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['headers'][] = 'Content-Range: bytes ' . $range[0] . '-' . $range[1] . '/' . strlen($file['contents']); } else { $ret['contentLength'] = strlen($file['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['contents'] = $file['contents']; } } else if (isset($file['file'])) { if (isset($headers['Range'])) { $range = explode('=', $headers['Range']); $range = explode('-', $range[1]); if (!$range[1]) { $range[1] = filesize($file['file'])-1; } $ret['contents'] = self::_getPartialFileContent($file['file'], $range); $ret['contentLength'] = strlen($ret['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['headers'][] = 'Content-Range: bytes ' . $range[0] . '-' . $range[1] . '/' . filesize($file['file']); } else { $ret['contentLength'] = filesize($file['file']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['file'] = $file['file']; } } else { throw new Kwf_Exception("contents not set"); } } return $ret; }
php
public static function getOutputData($file, array $headers) { $ret = array('headers' => array()); if (!isset($file['contents'])) { if (isset($file['file'])) { if (!is_file($file['file'])) { throw new Kwf_Exception_NotFound("File '$file[file]' not found."); } if (!isset($file['mtime'])) $file['mtime'] = filemtime($file['file']); } else if (isset($file['contentsCallback'])) { //contents will be fetched on demand thru contentsCallback } else { throw new Kwf_Exception_NotFound(); } } if (isset($file['mtime'])) { $lastModifiedString = gmdate("D, d M Y H:i:s \G\M\T", $file['mtime']); } $lifetime = (24*60*60*7*4); if (isset($file['lifetime'])) { if ($file['lifetime'] === false) { $lifetime = false; } else { $lifetime = $file['lifetime']; } } // According to following link it's not possible in IE<9 to download // any file with Pragma set to "no-cache" or order of Cache-Control other // than "no-store, no-cache" when using a SSL connection. // http://blogs.msdn.com/b/ieinternals/archive/2009/10/02/internet-explorer-cannot-download-over-https-when-no-cache.aspx // The order of Cache-Control is correct in default-implementation so // it's only required to reset Pragma to nothing. // The definition of Pragma can be found here (http://www.ietf.org/rfc/rfc2616.txt) // at chapter 14.32 if ($lifetime) { if (isset($headers['Https']) && isset($headers['User-Agent']) && preg_match('/msie [6-8]/i', $headers['User-Agent']) ) { $ret['headers'][] = 'Cache-Control: private, max-age='.$lifetime; $ret['headers'][] = 'Pragma:'; } else { $ret['headers'][] = 'Cache-Control: public, max-age='.$lifetime; $ret['headers'][] = 'Expires: '.gmdate("D, d M Y H:i:s \G\M\T", time()+$lifetime); $ret['headers'][] = 'Pragma: public'; } } else { $ret['headers'][] = 'Cache-Control: private'; $ret['headers'][] = 'Pragma:'; } if (isset($file['mtime']) && isset($headers['If-Modified-Since']) && $file['mtime'] <= strtotime($headers['If-Modified-Since'])) { $ret['responseCode'] = 304; $ret['contentLength'] = 0; if (PHP_SAPI == 'cgi-fcgi') { $ret['headers'][] = "Status: 304 Not Modified"; } else { $ret['headers'][] = array('Not Modified', true, 304); } $ret['headers'][] = 'Last-Modified: '.$headers['If-Modified-Since']; } else if (isset($file['etag']) && isset($headers['If-None-Match']) && $headers['If-None-Match'] == $file['etag']) { $ret['responseCode'] = 304; $ret['contentLength'] = 0; if (PHP_SAPI == 'cgi-fcgi') { $ret['headers'][] = "Status: 304 Not Modified"; } else { $ret['headers'][] = array('Not Modified', true, 304); } $ret['headers'][] = 'ETag: '.$headers['If-None-Match']; } else { if (substr($file['mimeType'], 0, 12) != 'application/') { $ret['headers'][] = 'Accept-Ranges: bytes'; if (isset($headers['Range'])) { $ret['responseCode'] = 206; $ret['headers'][] = array('Partial Content', true, 206); } else { $ret['responseCode'] = 200; } } else { $ret['headers'][] = 'Accept-Ranges: none'; $ret['responseCode'] = 200; } if (isset($file['etag'])) { $ret['headers'][] = 'ETag: ' . $file['etag']; } else { //wird benötigt für IE der sonst den download verweigert $ret['headers'][] = 'ETag: tag'; } if (isset($file['mtime'] )) $ret['headers'][] = 'Last-Modified: ' . $lastModifiedString; if (isset($file['downloadFilename']) && $file['downloadFilename']) { $ret['headers'][] = 'Content-Disposition: attachment; filename="' . $file['downloadFilename'] . '"'; } if (isset($file['filename']) && $file['filename']) { $ret['headers'][] = 'Content-Disposition: inline; filename="' . $file['filename'] . '"'; } $encoding = self::ENCODING_NONE; if (isset($file['encoding'])) { $encoding = $file['encoding']; } else { if (substr($file['mimeType'], 0, 5) == 'text/' || $file['mimeType'] == 'application/json') { if (isset($file['contents'])) { $encoding = self::getEncoding($headers); $file['contents'] = self::encode($file['contents'], $encoding); } else if (isset($file['contentsCallback'])) { $encoding = self::getEncoding($headers); if (isset($file['cache'])) { $file['contents'] = $file['cache']->load($file['cacheId'].'_'.$encoding); if ($file['contents']===false) { $contents = call_user_func($file['contentsCallback'], $file); $file['contents'] = self::encode($contents, $encoding); $file['cache']->save($file['contents'], $file['cacheId'].'_'.$encoding); } } else { $contents = call_user_func($file['contentsCallback'], $file); $file['contents'] = self::encode($contents, $encoding); } } else { //don't encode file (as they are usually large and read using readfile) } } } $ret['encoding'] = $encoding; if ($encoding != self::ENCODING_NONE) { $ret['headers'][] = 'Content-Encoding: ' . $encoding; } $ret['headers'][] = 'Content-Type: ' . $file['mimeType']; if (!isset($file['contents']) && isset($file['contentsCallback'])) { if (isset($file['cache'])) { $file['contents'] = $file['cache']->load($file['cacheId'].'_'.$encoding); if ($file['contents']===false) { $file['contents'] = call_user_func($file['contentsCallback'], $file); $file['cache']->save($file['contents'], $file['cacheId'].'_'.$encoding); } } else { $file['contents'] = call_user_func($file['contentsCallback'], $file); } } if (isset($file['contents'])) { if (isset($headers['Range'])) { if (!preg_match('#bytes#', $headers['Range'])) { throw new Kwf_Exception('wrong Range-Type'); } $range = explode('=', $headers['Range']); $range = explode('-', $range[1]); $ret['contents'] = substr($file['contents'], $range[0], $range[1]+1); $ret['contentLength'] = strlen($ret['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['headers'][] = 'Content-Range: bytes ' . $range[0] . '-' . $range[1] . '/' . strlen($file['contents']); } else { $ret['contentLength'] = strlen($file['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['contents'] = $file['contents']; } } else if (isset($file['file'])) { if (isset($headers['Range'])) { $range = explode('=', $headers['Range']); $range = explode('-', $range[1]); if (!$range[1]) { $range[1] = filesize($file['file'])-1; } $ret['contents'] = self::_getPartialFileContent($file['file'], $range); $ret['contentLength'] = strlen($ret['contents']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['headers'][] = 'Content-Range: bytes ' . $range[0] . '-' . $range[1] . '/' . filesize($file['file']); } else { $ret['contentLength'] = filesize($file['file']); $ret['headers'][] = 'Content-Length: ' . $ret['contentLength']; $ret['file'] = $file['file']; } } else { throw new Kwf_Exception("contents not set"); } } return $ret; }
[ "public", "static", "function", "getOutputData", "(", "$", "file", ",", "array", "$", "headers", ")", "{", "$", "ret", "=", "array", "(", "'headers'", "=>", "array", "(", ")", ")", ";", "if", "(", "!", "isset", "(", "$", "file", "[", "'contents'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "file", "[", "'file'", "]", ")", ")", "{", "if", "(", "!", "is_file", "(", "$", "file", "[", "'file'", "]", ")", ")", "{", "throw", "new", "Kwf_Exception_NotFound", "(", "\"File '$file[file]' not found.\"", ")", ";", "}", "if", "(", "!", "isset", "(", "$", "file", "[", "'mtime'", "]", ")", ")", "$", "file", "[", "'mtime'", "]", "=", "filemtime", "(", "$", "file", "[", "'file'", "]", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "file", "[", "'contentsCallback'", "]", ")", ")", "{", "//contents will be fetched on demand thru contentsCallback", "}", "else", "{", "throw", "new", "Kwf_Exception_NotFound", "(", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "file", "[", "'mtime'", "]", ")", ")", "{", "$", "lastModifiedString", "=", "gmdate", "(", "\"D, d M Y H:i:s \\G\\M\\T\"", ",", "$", "file", "[", "'mtime'", "]", ")", ";", "}", "$", "lifetime", "=", "(", "24", "*", "60", "*", "60", "*", "7", "*", "4", ")", ";", "if", "(", "isset", "(", "$", "file", "[", "'lifetime'", "]", ")", ")", "{", "if", "(", "$", "file", "[", "'lifetime'", "]", "===", "false", ")", "{", "$", "lifetime", "=", "false", ";", "}", "else", "{", "$", "lifetime", "=", "$", "file", "[", "'lifetime'", "]", ";", "}", "}", "// According to following link it's not possible in IE<9 to download", "// any file with Pragma set to \"no-cache\" or order of Cache-Control other", "// than \"no-store, no-cache\" when using a SSL connection.", "// http://blogs.msdn.com/b/ieinternals/archive/2009/10/02/internet-explorer-cannot-download-over-https-when-no-cache.aspx", "// The order of Cache-Control is correct in default-implementation so", "// it's only required to reset Pragma to nothing.", "// The definition of Pragma can be found here (http://www.ietf.org/rfc/rfc2616.txt)", "// at chapter 14.32", "if", "(", "$", "lifetime", ")", "{", "if", "(", "isset", "(", "$", "headers", "[", "'Https'", "]", ")", "&&", "isset", "(", "$", "headers", "[", "'User-Agent'", "]", ")", "&&", "preg_match", "(", "'/msie [6-8]/i'", ",", "$", "headers", "[", "'User-Agent'", "]", ")", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Cache-Control: private, max-age='", ".", "$", "lifetime", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Pragma:'", ";", "}", "else", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Cache-Control: public, max-age='", ".", "$", "lifetime", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Expires: '", ".", "gmdate", "(", "\"D, d M Y H:i:s \\G\\M\\T\"", ",", "time", "(", ")", "+", "$", "lifetime", ")", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Pragma: public'", ";", "}", "}", "else", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Cache-Control: private'", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Pragma:'", ";", "}", "if", "(", "isset", "(", "$", "file", "[", "'mtime'", "]", ")", "&&", "isset", "(", "$", "headers", "[", "'If-Modified-Since'", "]", ")", "&&", "$", "file", "[", "'mtime'", "]", "<=", "strtotime", "(", "$", "headers", "[", "'If-Modified-Since'", "]", ")", ")", "{", "$", "ret", "[", "'responseCode'", "]", "=", "304", ";", "$", "ret", "[", "'contentLength'", "]", "=", "0", ";", "if", "(", "PHP_SAPI", "==", "'cgi-fcgi'", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "\"Status: 304 Not Modified\"", ";", "}", "else", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "array", "(", "'Not Modified'", ",", "true", ",", "304", ")", ";", "}", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Last-Modified: '", ".", "$", "headers", "[", "'If-Modified-Since'", "]", ";", "}", "else", "if", "(", "isset", "(", "$", "file", "[", "'etag'", "]", ")", "&&", "isset", "(", "$", "headers", "[", "'If-None-Match'", "]", ")", "&&", "$", "headers", "[", "'If-None-Match'", "]", "==", "$", "file", "[", "'etag'", "]", ")", "{", "$", "ret", "[", "'responseCode'", "]", "=", "304", ";", "$", "ret", "[", "'contentLength'", "]", "=", "0", ";", "if", "(", "PHP_SAPI", "==", "'cgi-fcgi'", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "\"Status: 304 Not Modified\"", ";", "}", "else", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "array", "(", "'Not Modified'", ",", "true", ",", "304", ")", ";", "}", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'ETag: '", ".", "$", "headers", "[", "'If-None-Match'", "]", ";", "}", "else", "{", "if", "(", "substr", "(", "$", "file", "[", "'mimeType'", "]", ",", "0", ",", "12", ")", "!=", "'application/'", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Accept-Ranges: bytes'", ";", "if", "(", "isset", "(", "$", "headers", "[", "'Range'", "]", ")", ")", "{", "$", "ret", "[", "'responseCode'", "]", "=", "206", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "array", "(", "'Partial Content'", ",", "true", ",", "206", ")", ";", "}", "else", "{", "$", "ret", "[", "'responseCode'", "]", "=", "200", ";", "}", "}", "else", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Accept-Ranges: none'", ";", "$", "ret", "[", "'responseCode'", "]", "=", "200", ";", "}", "if", "(", "isset", "(", "$", "file", "[", "'etag'", "]", ")", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'ETag: '", ".", "$", "file", "[", "'etag'", "]", ";", "}", "else", "{", "//wird benötigt für IE der sonst den download verweigert", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'ETag: tag'", ";", "}", "if", "(", "isset", "(", "$", "file", "[", "'mtime'", "]", ")", ")", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Last-Modified: '", ".", "$", "lastModifiedString", ";", "if", "(", "isset", "(", "$", "file", "[", "'downloadFilename'", "]", ")", "&&", "$", "file", "[", "'downloadFilename'", "]", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Disposition: attachment; filename=\"'", ".", "$", "file", "[", "'downloadFilename'", "]", ".", "'\"'", ";", "}", "if", "(", "isset", "(", "$", "file", "[", "'filename'", "]", ")", "&&", "$", "file", "[", "'filename'", "]", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Disposition: inline; filename=\"'", ".", "$", "file", "[", "'filename'", "]", ".", "'\"'", ";", "}", "$", "encoding", "=", "self", "::", "ENCODING_NONE", ";", "if", "(", "isset", "(", "$", "file", "[", "'encoding'", "]", ")", ")", "{", "$", "encoding", "=", "$", "file", "[", "'encoding'", "]", ";", "}", "else", "{", "if", "(", "substr", "(", "$", "file", "[", "'mimeType'", "]", ",", "0", ",", "5", ")", "==", "'text/'", "||", "$", "file", "[", "'mimeType'", "]", "==", "'application/json'", ")", "{", "if", "(", "isset", "(", "$", "file", "[", "'contents'", "]", ")", ")", "{", "$", "encoding", "=", "self", "::", "getEncoding", "(", "$", "headers", ")", ";", "$", "file", "[", "'contents'", "]", "=", "self", "::", "encode", "(", "$", "file", "[", "'contents'", "]", ",", "$", "encoding", ")", ";", "}", "else", "if", "(", "isset", "(", "$", "file", "[", "'contentsCallback'", "]", ")", ")", "{", "$", "encoding", "=", "self", "::", "getEncoding", "(", "$", "headers", ")", ";", "if", "(", "isset", "(", "$", "file", "[", "'cache'", "]", ")", ")", "{", "$", "file", "[", "'contents'", "]", "=", "$", "file", "[", "'cache'", "]", "->", "load", "(", "$", "file", "[", "'cacheId'", "]", ".", "'_'", ".", "$", "encoding", ")", ";", "if", "(", "$", "file", "[", "'contents'", "]", "===", "false", ")", "{", "$", "contents", "=", "call_user_func", "(", "$", "file", "[", "'contentsCallback'", "]", ",", "$", "file", ")", ";", "$", "file", "[", "'contents'", "]", "=", "self", "::", "encode", "(", "$", "contents", ",", "$", "encoding", ")", ";", "$", "file", "[", "'cache'", "]", "->", "save", "(", "$", "file", "[", "'contents'", "]", ",", "$", "file", "[", "'cacheId'", "]", ".", "'_'", ".", "$", "encoding", ")", ";", "}", "}", "else", "{", "$", "contents", "=", "call_user_func", "(", "$", "file", "[", "'contentsCallback'", "]", ",", "$", "file", ")", ";", "$", "file", "[", "'contents'", "]", "=", "self", "::", "encode", "(", "$", "contents", ",", "$", "encoding", ")", ";", "}", "}", "else", "{", "//don't encode file (as they are usually large and read using readfile)", "}", "}", "}", "$", "ret", "[", "'encoding'", "]", "=", "$", "encoding", ";", "if", "(", "$", "encoding", "!=", "self", "::", "ENCODING_NONE", ")", "{", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Encoding: '", ".", "$", "encoding", ";", "}", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Type: '", ".", "$", "file", "[", "'mimeType'", "]", ";", "if", "(", "!", "isset", "(", "$", "file", "[", "'contents'", "]", ")", "&&", "isset", "(", "$", "file", "[", "'contentsCallback'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "file", "[", "'cache'", "]", ")", ")", "{", "$", "file", "[", "'contents'", "]", "=", "$", "file", "[", "'cache'", "]", "->", "load", "(", "$", "file", "[", "'cacheId'", "]", ".", "'_'", ".", "$", "encoding", ")", ";", "if", "(", "$", "file", "[", "'contents'", "]", "===", "false", ")", "{", "$", "file", "[", "'contents'", "]", "=", "call_user_func", "(", "$", "file", "[", "'contentsCallback'", "]", ",", "$", "file", ")", ";", "$", "file", "[", "'cache'", "]", "->", "save", "(", "$", "file", "[", "'contents'", "]", ",", "$", "file", "[", "'cacheId'", "]", ".", "'_'", ".", "$", "encoding", ")", ";", "}", "}", "else", "{", "$", "file", "[", "'contents'", "]", "=", "call_user_func", "(", "$", "file", "[", "'contentsCallback'", "]", ",", "$", "file", ")", ";", "}", "}", "if", "(", "isset", "(", "$", "file", "[", "'contents'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "headers", "[", "'Range'", "]", ")", ")", "{", "if", "(", "!", "preg_match", "(", "'#bytes#'", ",", "$", "headers", "[", "'Range'", "]", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "'wrong Range-Type'", ")", ";", "}", "$", "range", "=", "explode", "(", "'='", ",", "$", "headers", "[", "'Range'", "]", ")", ";", "$", "range", "=", "explode", "(", "'-'", ",", "$", "range", "[", "1", "]", ")", ";", "$", "ret", "[", "'contents'", "]", "=", "substr", "(", "$", "file", "[", "'contents'", "]", ",", "$", "range", "[", "0", "]", ",", "$", "range", "[", "1", "]", "+", "1", ")", ";", "$", "ret", "[", "'contentLength'", "]", "=", "strlen", "(", "$", "ret", "[", "'contents'", "]", ")", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Length: '", ".", "$", "ret", "[", "'contentLength'", "]", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Range: bytes '", ".", "$", "range", "[", "0", "]", ".", "'-'", ".", "$", "range", "[", "1", "]", ".", "'/'", ".", "strlen", "(", "$", "file", "[", "'contents'", "]", ")", ";", "}", "else", "{", "$", "ret", "[", "'contentLength'", "]", "=", "strlen", "(", "$", "file", "[", "'contents'", "]", ")", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Length: '", ".", "$", "ret", "[", "'contentLength'", "]", ";", "$", "ret", "[", "'contents'", "]", "=", "$", "file", "[", "'contents'", "]", ";", "}", "}", "else", "if", "(", "isset", "(", "$", "file", "[", "'file'", "]", ")", ")", "{", "if", "(", "isset", "(", "$", "headers", "[", "'Range'", "]", ")", ")", "{", "$", "range", "=", "explode", "(", "'='", ",", "$", "headers", "[", "'Range'", "]", ")", ";", "$", "range", "=", "explode", "(", "'-'", ",", "$", "range", "[", "1", "]", ")", ";", "if", "(", "!", "$", "range", "[", "1", "]", ")", "{", "$", "range", "[", "1", "]", "=", "filesize", "(", "$", "file", "[", "'file'", "]", ")", "-", "1", ";", "}", "$", "ret", "[", "'contents'", "]", "=", "self", "::", "_getPartialFileContent", "(", "$", "file", "[", "'file'", "]", ",", "$", "range", ")", ";", "$", "ret", "[", "'contentLength'", "]", "=", "strlen", "(", "$", "ret", "[", "'contents'", "]", ")", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Length: '", ".", "$", "ret", "[", "'contentLength'", "]", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Range: bytes '", ".", "$", "range", "[", "0", "]", ".", "'-'", ".", "$", "range", "[", "1", "]", ".", "'/'", ".", "filesize", "(", "$", "file", "[", "'file'", "]", ")", ";", "}", "else", "{", "$", "ret", "[", "'contentLength'", "]", "=", "filesize", "(", "$", "file", "[", "'file'", "]", ")", ";", "$", "ret", "[", "'headers'", "]", "[", "]", "=", "'Content-Length: '", ".", "$", "ret", "[", "'contentLength'", "]", ";", "$", "ret", "[", "'file'", "]", "=", "$", "file", "[", "'file'", "]", ";", "}", "}", "else", "{", "throw", "new", "Kwf_Exception", "(", "\"contents not set\"", ")", ";", "}", "}", "return", "$", "ret", ";", "}" ]
PUBLIC METHOD FOR UNIT TESTING ONLY !
[ "PUBLIC", "METHOD", "FOR", "UNIT", "TESTING", "ONLY", "!" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Output.php#L60-L240
koala-framework/koala-framework
Kwf/Media/Output.php
Kwf_Media_Output._getPartialFileContent
private static function _getPartialFileContent($file, $range) { $length = $range[1]-$range[0]+1; if( !$handle = fopen($file, 'r') ) throw new Kwf_Exception(sprintf("Could not get handle for file %s", $file)); if( fseek($handle, $range[0], SEEK_SET) == -1 ) throw new Kwf_Exception(sprintf("Could not seek to byte offset {$rage[0]}")); $ret = fread($handle, $length); return $ret; }
php
private static function _getPartialFileContent($file, $range) { $length = $range[1]-$range[0]+1; if( !$handle = fopen($file, 'r') ) throw new Kwf_Exception(sprintf("Could not get handle for file %s", $file)); if( fseek($handle, $range[0], SEEK_SET) == -1 ) throw new Kwf_Exception(sprintf("Could not seek to byte offset {$rage[0]}")); $ret = fread($handle, $length); return $ret; }
[ "private", "static", "function", "_getPartialFileContent", "(", "$", "file", ",", "$", "range", ")", "{", "$", "length", "=", "$", "range", "[", "1", "]", "-", "$", "range", "[", "0", "]", "+", "1", ";", "if", "(", "!", "$", "handle", "=", "fopen", "(", "$", "file", ",", "'r'", ")", ")", "throw", "new", "Kwf_Exception", "(", "sprintf", "(", "\"Could not get handle for file %s\"", ",", "$", "file", ")", ")", ";", "if", "(", "fseek", "(", "$", "handle", ",", "$", "range", "[", "0", "]", ",", "SEEK_SET", ")", "==", "-", "1", ")", "throw", "new", "Kwf_Exception", "(", "sprintf", "(", "\"Could not seek to byte offset {$rage[0]}\"", ")", ")", ";", "$", "ret", "=", "fread", "(", "$", "handle", ",", "$", "length", ")", ";", "return", "$", "ret", ";", "}" ]
returns the partial content from a file
[ "returns", "the", "partial", "content", "from", "a", "file" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Media/Output.php#L252-L263
koala-framework/koala-framework
Kwf/Util/Check/Ip.php
Kwf_Util_Check_Ip.checkIp
public function checkIp($ip = null, $preventException = false) { if (is_null($ip)) { $ip = $_SERVER['REMOTE_ADDR']; } if (!preg_match('/^(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}$/', $ip)) { throw new Kwf_Exception("The set IP address '$ip' is not an Ip address"); } $allowedIps = $this->_getAllowedAddresses(); if (!is_array($allowedIps)) { throw new Kwf_Exception("_getAllowedAddresses() must return type 'array', '".gettype($allowedIps)."' given."); } // wenn domains, dann durch ips ersetzen foreach ($allowedIps as $key => $allowedIp) { $allowedIp = trim($allowedIp); $allowedIps[$key] = $allowedIp; if (!preg_match('/^(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}$/', $allowedIp)) { $ipByDomain = self::_getIpByDomain($allowedIp); if ($ipByDomain) $allowedIps[$key] = $ipByDomain; } } $checkIpParts = explode('.', $ip); $ipCorrect = false; foreach ($allowedIps as $allowedIp) { $allowedIpParts = explode('.', $allowedIp); $ipCorrect = true; foreach ($allowedIpParts as $k => $allowedIpPart) { if ($allowedIpPart != '*' && $allowedIpPart != $checkIpParts[$k]) { $ipCorrect = false; break 1; } } if ($ipCorrect === true) break 1; } if ($ipCorrect === false) { if ($preventException) { return false; } else { throw new Kwf_Util_Check_Ip_Exception("IP address '$ip' is not allowed."); } } return true; }
php
public function checkIp($ip = null, $preventException = false) { if (is_null($ip)) { $ip = $_SERVER['REMOTE_ADDR']; } if (!preg_match('/^(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}$/', $ip)) { throw new Kwf_Exception("The set IP address '$ip' is not an Ip address"); } $allowedIps = $this->_getAllowedAddresses(); if (!is_array($allowedIps)) { throw new Kwf_Exception("_getAllowedAddresses() must return type 'array', '".gettype($allowedIps)."' given."); } // wenn domains, dann durch ips ersetzen foreach ($allowedIps as $key => $allowedIp) { $allowedIp = trim($allowedIp); $allowedIps[$key] = $allowedIp; if (!preg_match('/^(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}\.(\d|\*){1,3}$/', $allowedIp)) { $ipByDomain = self::_getIpByDomain($allowedIp); if ($ipByDomain) $allowedIps[$key] = $ipByDomain; } } $checkIpParts = explode('.', $ip); $ipCorrect = false; foreach ($allowedIps as $allowedIp) { $allowedIpParts = explode('.', $allowedIp); $ipCorrect = true; foreach ($allowedIpParts as $k => $allowedIpPart) { if ($allowedIpPart != '*' && $allowedIpPart != $checkIpParts[$k]) { $ipCorrect = false; break 1; } } if ($ipCorrect === true) break 1; } if ($ipCorrect === false) { if ($preventException) { return false; } else { throw new Kwf_Util_Check_Ip_Exception("IP address '$ip' is not allowed."); } } return true; }
[ "public", "function", "checkIp", "(", "$", "ip", "=", "null", ",", "$", "preventException", "=", "false", ")", "{", "if", "(", "is_null", "(", "$", "ip", ")", ")", "{", "$", "ip", "=", "$", "_SERVER", "[", "'REMOTE_ADDR'", "]", ";", "}", "if", "(", "!", "preg_match", "(", "'/^(\\d|\\*){1,3}\\.(\\d|\\*){1,3}\\.(\\d|\\*){1,3}\\.(\\d|\\*){1,3}$/'", ",", "$", "ip", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"The set IP address '$ip' is not an Ip address\"", ")", ";", "}", "$", "allowedIps", "=", "$", "this", "->", "_getAllowedAddresses", "(", ")", ";", "if", "(", "!", "is_array", "(", "$", "allowedIps", ")", ")", "{", "throw", "new", "Kwf_Exception", "(", "\"_getAllowedAddresses() must return type 'array', '\"", ".", "gettype", "(", "$", "allowedIps", ")", ".", "\"' given.\"", ")", ";", "}", "// wenn domains, dann durch ips ersetzen", "foreach", "(", "$", "allowedIps", "as", "$", "key", "=>", "$", "allowedIp", ")", "{", "$", "allowedIp", "=", "trim", "(", "$", "allowedIp", ")", ";", "$", "allowedIps", "[", "$", "key", "]", "=", "$", "allowedIp", ";", "if", "(", "!", "preg_match", "(", "'/^(\\d|\\*){1,3}\\.(\\d|\\*){1,3}\\.(\\d|\\*){1,3}\\.(\\d|\\*){1,3}$/'", ",", "$", "allowedIp", ")", ")", "{", "$", "ipByDomain", "=", "self", "::", "_getIpByDomain", "(", "$", "allowedIp", ")", ";", "if", "(", "$", "ipByDomain", ")", "$", "allowedIps", "[", "$", "key", "]", "=", "$", "ipByDomain", ";", "}", "}", "$", "checkIpParts", "=", "explode", "(", "'.'", ",", "$", "ip", ")", ";", "$", "ipCorrect", "=", "false", ";", "foreach", "(", "$", "allowedIps", "as", "$", "allowedIp", ")", "{", "$", "allowedIpParts", "=", "explode", "(", "'.'", ",", "$", "allowedIp", ")", ";", "$", "ipCorrect", "=", "true", ";", "foreach", "(", "$", "allowedIpParts", "as", "$", "k", "=>", "$", "allowedIpPart", ")", "{", "if", "(", "$", "allowedIpPart", "!=", "'*'", "&&", "$", "allowedIpPart", "!=", "$", "checkIpParts", "[", "$", "k", "]", ")", "{", "$", "ipCorrect", "=", "false", ";", "break", "1", ";", "}", "}", "if", "(", "$", "ipCorrect", "===", "true", ")", "break", "1", ";", "}", "if", "(", "$", "ipCorrect", "===", "false", ")", "{", "if", "(", "$", "preventException", ")", "{", "return", "false", ";", "}", "else", "{", "throw", "new", "Kwf_Util_Check_Ip_Exception", "(", "\"IP address '$ip' is not allowed.\"", ")", ";", "}", "}", "return", "true", ";", "}" ]
Checkt ob eine IP-Adresse in den von {@link _getAllowedAddresses} zurückgegebenen IPs / Domains erlaubt ist @param string $ip [optional] Die zu überprüfende IP-Adresse. Wenn nicht übergeben wird die REMOTE_ADDR verwendet @param boolean $preventException [optional] Wenn true wird ein boolscher Wert returned und in keinem Fall eine Exception geworfen. @return boolean $allowed Wenn zweites argument true ist wird returned ob die IP erlaubt ist oder nicht. Ansonste wird eine Exception geworfen.
[ "Checkt", "ob", "eine", "IP", "-", "Adresse", "in", "den", "von", "{", "@link", "_getAllowedAddresses", "}", "zurückgegebenen", "IPs", "/", "Domains", "erlaubt", "ist" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Util/Check/Ip.php#L56-L103
koala-framework/koala-framework
Kwf/Cache/SimpleStatic.php
Kwf_Cache_SimpleStatic.clear
public static function clear($cacheIdPrefix) { if (!extension_loaded('apc') || PHP_SAPI == 'cli') { self::$_cache = array(); //don't use $cacheIdPrefix as filenames are base64 encoded foreach (glob('cache/simpleStatic/*') as $f) { unlink($f); } if (extension_loaded('apc')) { Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic'=>$cacheIdPrefix)); } } else { if (!class_exists('APCIterator')) { throw new Kwf_Exception_NotYetImplemented("We don't want to clear the whole"); } else { static $prefix; if (!isset($prefix)) $prefix = Kwf_Cache_Simple::$uniquePrefix.'-'; $it = new APCIterator('user', '#^'.preg_quote($prefix.$cacheIdPrefix).'#', APC_ITER_NONE); if ($it->getTotalCount() && !$it->current()) { //APCIterator is borked, delete everything //see https://bugs.php.net/bug.php?id=59938 if (extension_loaded('apcu')) { apc_clear_cache(); } else { apc_clear_cache('user'); } } else { //APCIterator seems to work, use it for deletion apc_delete($it); } } } }
php
public static function clear($cacheIdPrefix) { if (!extension_loaded('apc') || PHP_SAPI == 'cli') { self::$_cache = array(); //don't use $cacheIdPrefix as filenames are base64 encoded foreach (glob('cache/simpleStatic/*') as $f) { unlink($f); } if (extension_loaded('apc')) { Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic'=>$cacheIdPrefix)); } } else { if (!class_exists('APCIterator')) { throw new Kwf_Exception_NotYetImplemented("We don't want to clear the whole"); } else { static $prefix; if (!isset($prefix)) $prefix = Kwf_Cache_Simple::$uniquePrefix.'-'; $it = new APCIterator('user', '#^'.preg_quote($prefix.$cacheIdPrefix).'#', APC_ITER_NONE); if ($it->getTotalCount() && !$it->current()) { //APCIterator is borked, delete everything //see https://bugs.php.net/bug.php?id=59938 if (extension_loaded('apcu')) { apc_clear_cache(); } else { apc_clear_cache('user'); } } else { //APCIterator seems to work, use it for deletion apc_delete($it); } } } }
[ "public", "static", "function", "clear", "(", "$", "cacheIdPrefix", ")", "{", "if", "(", "!", "extension_loaded", "(", "'apc'", ")", "||", "PHP_SAPI", "==", "'cli'", ")", "{", "self", "::", "$", "_cache", "=", "array", "(", ")", ";", "//don't use $cacheIdPrefix as filenames are base64 encoded", "foreach", "(", "glob", "(", "'cache/simpleStatic/*'", ")", "as", "$", "f", ")", "{", "unlink", "(", "$", "f", ")", ";", "}", "if", "(", "extension_loaded", "(", "'apc'", ")", ")", "{", "Kwf_Util_Apc", "::", "callClearCacheByCli", "(", "array", "(", "'clearCacheSimpleStatic'", "=>", "$", "cacheIdPrefix", ")", ")", ";", "}", "}", "else", "{", "if", "(", "!", "class_exists", "(", "'APCIterator'", ")", ")", "{", "throw", "new", "Kwf_Exception_NotYetImplemented", "(", "\"We don't want to clear the whole\"", ")", ";", "}", "else", "{", "static", "$", "prefix", ";", "if", "(", "!", "isset", "(", "$", "prefix", ")", ")", "$", "prefix", "=", "Kwf_Cache_Simple", "::", "$", "uniquePrefix", ".", "'-'", ";", "$", "it", "=", "new", "APCIterator", "(", "'user'", ",", "'#^'", ".", "preg_quote", "(", "$", "prefix", ".", "$", "cacheIdPrefix", ")", ".", "'#'", ",", "APC_ITER_NONE", ")", ";", "if", "(", "$", "it", "->", "getTotalCount", "(", ")", "&&", "!", "$", "it", "->", "current", "(", ")", ")", "{", "//APCIterator is borked, delete everything", "//see https://bugs.php.net/bug.php?id=59938", "if", "(", "extension_loaded", "(", "'apcu'", ")", ")", "{", "apc_clear_cache", "(", ")", ";", "}", "else", "{", "apc_clear_cache", "(", "'user'", ")", ";", "}", "}", "else", "{", "//APCIterator seems to work, use it for deletion", "apc_delete", "(", "$", "it", ")", ";", "}", "}", "}", "}" ]
clear static cache with prefix, don't use except in clear-cache-watcher @internal
[ "clear", "static", "cache", "with", "prefix", "don", "t", "use", "except", "in", "clear", "-", "cache", "-", "watcher" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Cache/SimpleStatic.php#L120-L152
koala-framework/koala-framework
Kwf/Cache/SimpleStatic.php
Kwf_Cache_SimpleStatic._delete
public static function _delete($cacheIds) { if (!is_array($cacheIds)) $cacheIds = array($cacheIds); $ret = true; if (!extension_loaded('apc') || PHP_SAPI == 'cli') { foreach ($cacheIds as $cacheId) { unset(self::$_cache[$cacheId]); $file = self::_getFileNameForCacheId($cacheId); if (!file_exists($file)) { $ret = false; } else { if (!unlink($file)) $ret = false; } } if (extension_loaded('apc')) { $result = Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic' => implode(',', $cacheIds))); if (!$result['result']) $ret = false; } } else { $prefix = Kwf_Cache_Simple::$uniquePrefix.'-'; foreach ($cacheIds as $cacheId) { if (!apc_delete($prefix.$cacheId)) { $ret = false; } } } return $ret; }
php
public static function _delete($cacheIds) { if (!is_array($cacheIds)) $cacheIds = array($cacheIds); $ret = true; if (!extension_loaded('apc') || PHP_SAPI == 'cli') { foreach ($cacheIds as $cacheId) { unset(self::$_cache[$cacheId]); $file = self::_getFileNameForCacheId($cacheId); if (!file_exists($file)) { $ret = false; } else { if (!unlink($file)) $ret = false; } } if (extension_loaded('apc')) { $result = Kwf_Util_Apc::callClearCacheByCli(array('clearCacheSimpleStatic' => implode(',', $cacheIds))); if (!$result['result']) $ret = false; } } else { $prefix = Kwf_Cache_Simple::$uniquePrefix.'-'; foreach ($cacheIds as $cacheId) { if (!apc_delete($prefix.$cacheId)) { $ret = false; } } } return $ret; }
[ "public", "static", "function", "_delete", "(", "$", "cacheIds", ")", "{", "if", "(", "!", "is_array", "(", "$", "cacheIds", ")", ")", "$", "cacheIds", "=", "array", "(", "$", "cacheIds", ")", ";", "$", "ret", "=", "true", ";", "if", "(", "!", "extension_loaded", "(", "'apc'", ")", "||", "PHP_SAPI", "==", "'cli'", ")", "{", "foreach", "(", "$", "cacheIds", "as", "$", "cacheId", ")", "{", "unset", "(", "self", "::", "$", "_cache", "[", "$", "cacheId", "]", ")", ";", "$", "file", "=", "self", "::", "_getFileNameForCacheId", "(", "$", "cacheId", ")", ";", "if", "(", "!", "file_exists", "(", "$", "file", ")", ")", "{", "$", "ret", "=", "false", ";", "}", "else", "{", "if", "(", "!", "unlink", "(", "$", "file", ")", ")", "$", "ret", "=", "false", ";", "}", "}", "if", "(", "extension_loaded", "(", "'apc'", ")", ")", "{", "$", "result", "=", "Kwf_Util_Apc", "::", "callClearCacheByCli", "(", "array", "(", "'clearCacheSimpleStatic'", "=>", "implode", "(", "','", ",", "$", "cacheIds", ")", ")", ")", ";", "if", "(", "!", "$", "result", "[", "'result'", "]", ")", "$", "ret", "=", "false", ";", "}", "}", "else", "{", "$", "prefix", "=", "Kwf_Cache_Simple", "::", "$", "uniquePrefix", ".", "'-'", ";", "foreach", "(", "$", "cacheIds", "as", "$", "cacheId", ")", "{", "if", "(", "!", "apc_delete", "(", "$", "prefix", ".", "$", "cacheId", ")", ")", "{", "$", "ret", "=", "false", ";", "}", "}", "}", "return", "$", "ret", ";", "}" ]
Delete static cache, don't use except in unittests @internal
[ "Delete", "static", "cache", "don", "t", "use", "except", "in", "unittests" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Cache/SimpleStatic.php#L159-L187
koala-framework/koala-framework
Kwc/Form/Dynamic/Form/Component.php
Kwc_Form_Dynamic_Form_Component._findFormFields
private static function _findFormFields($data) { $ret = array(); foreach ($data->getChildComponents(array('page'=>false, 'pseudoPage'=>false)) as $c) { if (Kwc_Abstract::getFlag($c->componentClass, 'formField')) { $ret[] = $c; } $ret = array_merge($ret, self::_findFormFields($c)); } return $ret; }
php
private static function _findFormFields($data) { $ret = array(); foreach ($data->getChildComponents(array('page'=>false, 'pseudoPage'=>false)) as $c) { if (Kwc_Abstract::getFlag($c->componentClass, 'formField')) { $ret[] = $c; } $ret = array_merge($ret, self::_findFormFields($c)); } return $ret; }
[ "private", "static", "function", "_findFormFields", "(", "$", "data", ")", "{", "$", "ret", "=", "array", "(", ")", ";", "foreach", "(", "$", "data", "->", "getChildComponents", "(", "array", "(", "'page'", "=>", "false", ",", "'pseudoPage'", "=>", "false", ")", ")", "as", "$", "c", ")", "{", "if", "(", "Kwc_Abstract", "::", "getFlag", "(", "$", "c", "->", "componentClass", ",", "'formField'", ")", ")", "{", "$", "ret", "[", "]", "=", "$", "c", ";", "}", "$", "ret", "=", "array_merge", "(", "$", "ret", ",", "self", "::", "_findFormFields", "(", "$", "c", ")", ")", ";", "}", "return", "$", "ret", ";", "}" ]
don't use getRecursiveChildComponents as that won't return items in an defined order
[ "don", "t", "use", "getRecursiveChildComponents", "as", "that", "won", "t", "return", "items", "in", "an", "defined", "order" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwc/Form/Dynamic/Form/Component.php#L57-L67
koala-framework/koala-framework
Kwf/Session.php
Kwf_Session._processValidators
private static function _processValidators() { foreach ($_SESSION['__KWF']['VALID'] as $validator_name => $valid_data) { $validator = new $validator_name; if ($validator->validate() === false) { $_SESSION = array(); Zend_Session::regenerateId(); break; } } }
php
private static function _processValidators() { foreach ($_SESSION['__KWF']['VALID'] as $validator_name => $valid_data) { $validator = new $validator_name; if ($validator->validate() === false) { $_SESSION = array(); Zend_Session::regenerateId(); break; } } }
[ "private", "static", "function", "_processValidators", "(", ")", "{", "foreach", "(", "$", "_SESSION", "[", "'__KWF'", "]", "[", "'VALID'", "]", "as", "$", "validator_name", "=>", "$", "valid_data", ")", "{", "$", "validator", "=", "new", "$", "validator_name", ";", "if", "(", "$", "validator", "->", "validate", "(", ")", "===", "false", ")", "{", "$", "_SESSION", "=", "array", "(", ")", ";", "Zend_Session", "::", "regenerateId", "(", ")", ";", "break", ";", "}", "}", "}" ]
instead empty session
[ "instead", "empty", "session" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Session.php#L47-L57
koala-framework/koala-framework
Kwf/View/Helper/Abstract/MailLink.php
Kwf_View_Helper_Abstract_MailLink.encodeMail
public function encodeMail($address) { if ($this->_getRenderer() instanceof Kwf_Component_Renderer_Mail) { return $text; } $address = trim($address); $address = preg_replace('/^(.+)@(.+)\.([^\.\s]+)$/i', '$1'.$this->_atEncoding.'$2'.$this->_dotEncoding.'$3', $address ); return $address; }
php
public function encodeMail($address) { if ($this->_getRenderer() instanceof Kwf_Component_Renderer_Mail) { return $text; } $address = trim($address); $address = preg_replace('/^(.+)@(.+)\.([^\.\s]+)$/i', '$1'.$this->_atEncoding.'$2'.$this->_dotEncoding.'$3', $address ); return $address; }
[ "public", "function", "encodeMail", "(", "$", "address", ")", "{", "if", "(", "$", "this", "->", "_getRenderer", "(", ")", "instanceof", "Kwf_Component_Renderer_Mail", ")", "{", "return", "$", "text", ";", "}", "$", "address", "=", "trim", "(", "$", "address", ")", ";", "$", "address", "=", "preg_replace", "(", "'/^(.+)@(.+)\\.([^\\.\\s]+)$/i'", ",", "'$1'", ".", "$", "this", "->", "_atEncoding", ".", "'$2'", ".", "$", "this", "->", "_dotEncoding", ".", "'$3'", ",", "$", "address", ")", ";", "return", "$", "address", ";", "}" ]
wird zB in LinkTag_Mail_Data.php verwendet, deshalb public
[ "wird", "zB", "in", "LinkTag_Mail_Data", ".", "php", "verwendet", "deshalb", "public" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/View/Helper/Abstract/MailLink.php#L10-L21
koala-framework/koala-framework
Kwf/Exception.php
Kwf_Exception.notify
public function notify() { if ($this->log()) { return; } if (PHP_SAPI == 'cli') { echo 'WARNING: '.$this->getMessage()."\n"; } else if ( Zend_Registry::get('config')->debug->firephp && class_exists('FirePHP') && FirePHP::getInstance() && FirePHP::getInstance()->detectClientExtension() ) { p($this->getMessage(), 'WARNING'); } }
php
public function notify() { if ($this->log()) { return; } if (PHP_SAPI == 'cli') { echo 'WARNING: '.$this->getMessage()."\n"; } else if ( Zend_Registry::get('config')->debug->firephp && class_exists('FirePHP') && FirePHP::getInstance() && FirePHP::getInstance()->detectClientExtension() ) { p($this->getMessage(), 'WARNING'); } }
[ "public", "function", "notify", "(", ")", "{", "if", "(", "$", "this", "->", "log", "(", ")", ")", "{", "return", ";", "}", "if", "(", "PHP_SAPI", "==", "'cli'", ")", "{", "echo", "'WARNING: '", ".", "$", "this", "->", "getMessage", "(", ")", ".", "\"\\n\"", ";", "}", "else", "if", "(", "Zend_Registry", "::", "get", "(", "'config'", ")", "->", "debug", "->", "firephp", "&&", "class_exists", "(", "'FirePHP'", ")", "&&", "FirePHP", "::", "getInstance", "(", ")", "&&", "FirePHP", "::", "getInstance", "(", ")", "->", "detectClientExtension", "(", ")", ")", "{", "p", "(", "$", "this", "->", "getMessage", "(", ")", ",", "'WARNING'", ")", ";", "}", "}" ]
Informiert den Entwickler über diese Exception
[ "Informiert", "den", "Entwickler", "über", "diese", "Exception" ]
train
https://github.com/koala-framework/koala-framework/blob/2131b9b10b6c368ea02ad448d5f8a4deef0fe971/Kwf/Exception.php#L7-L22