public function testThatStrEndsWithCorrectlyIdentifiesIfAStringEndsWithASubString() { $string = 'fooBar'; $this->assertTrue(strEndsWith($string, 'Bar')); $string = 'barFoo'; $this->assertFalse(strEndsWith($string, 'Bar')); }
public function processData(\IRequestObject $requestObject) { $objectId = $requestObject->getId(); $steam = $GLOBALS["STEAM"]; $extensionMaster = \ExtensionMaster::getInstance(); $portalColumnExtension = $extensionMaster->getExtensionById("PortalColumn"); $this->getExtension()->addCSS(); $htmlBody = ""; $portalColumnObject = \steam_factory::get_object($GLOBALS["STEAM"]->get_id(), $objectId); $portlets = $portalColumnObject->get_inventory(); //handle column size $columnWidthPx = trim($portalColumnObject->get_attribute("bid:portal:column:width")); if (strEndsWith($columnWidthPx, "px")) { $columnWidth = str_replace("px", "", $columnWidthPx); $columnWidthExt = "px"; } else { if (strEndsWith($columnWidthPx, "%")) { $columnWidth = str_replace("%", "", $columnWidthPx); $columnWidthExt = "%"; } else { $columnWidth = $columnWidthPx; $columnWidthExt = "px"; } } if ((int) $columnWidth > 0) { $columnWidthPx = $columnWidth . $columnWidthExt; } else { $columnWidthPx = "200px"; } $this->rawHtmlWidget = new \Widgets\RawHtml(); $htmlBody .= '<div class="column" style="width:' . $columnWidthPx . ';">'; //popupmenu $popupmenu = new \Widgets\PopupMenu(); $popupmenu->setCommand("GetPopupMenu"); $popupmenu->setData($portalColumnObject); $popupmenu->setNamespace("PortalColumn"); $popupmenu->setElementId("portal-overlay"); $htmlBody .= '<h2 class="editbutton columnheadline"><div class="editbutton">' . $popupmenu->getHtml() . '</div><div style="margin-left:3px;">Spalte</div></h2>'; foreach ($portlets as $portlet) { //handle link objects as portlets $params = array(); if ($portlet instanceof \steam_link) { $params["referenced"] = true; $params["referenceId"] = $portlet->get_id(); $portlet = $portlet->get_link_object(); if ($portlet == NULL) { continue; } } $widgets = $extensionMaster->getWidgetsByObjectId($portlet->get_id(), "view", $params); $this->rawHtmlWidget->addWidgets($widgets); $data = \Widgets\Widget::getData($widgets); $htmlBody .= $data["html"]; } $htmlBody .= "</div>"; $this->rawHtmlWidget->setHtml($htmlBody); }
public function __construct() { $paths = explode(PATH_SEPARATOR, get_include_path()); foreach ($paths as $p) { $dirpath = $p . DIRECTORY_SEPARATOR . 'hash-bang/dwidgets/'; if (is_dir($dirpath)) { if ($dh = opendir($dirpath)) { while (($file = readdir($dh)) !== false) { if (strEndsWith($file, 'php')) { require_once $dirpath . $file; } } closedir($dh); } } } }
public function getCommands() { $result = array(); $path = $this->getExtensionPath() . "classes/commands"; if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file == '.' || $file == '..') { continue; } if (is_dir($path . "/" . $file)) { continue; } else { if (strEndsWith($file, ".class.php", false)) { $result[] = str_replace(".class.php", "", $file); } } } closedir($dh); } } return $result; }
/** * Converts a string to defined native PHP type. * * @param string $string The string to convert * @param string $typename The name of the required resulting PHP type. * Allowed types are (bool|boolean|double|float|int|integer|string|array) * @return mixed */ public static function StrToType(string $string, $typename) { if (null === $string) { return null; } $t = new Type($string); if (!$t->hasAssociatedString()) { return null; } $string = $t->getStringValue(); switch (\strtolower($typename)) { case 'bool': case 'boolean': $res = false; static::IsBoolConvertible($string, $res); return $res; case 'float': return \floatval(\str_replace(',', '.', $string)); case 'double': if (!static::IsDecimal($string, true)) { return null; } $res = \str_replace(',', '.', $string); $tmp = \explode('.', $res); $ts = \count($tmp); if ($ts > 2) { $dv = $tmp[$ts - 1]; unset($tmp[$ts - 1]); $dv = \join('', $tmp) . '.' . $dv; return \doubleval($dv); } return \doubleval($res); case 'int': case 'integer': if (static::IsInteger($string) || static::IsDecimal($string, true)) { return \intval($string); } return null; case 'string': return $string; case 'array': if (\strlen($string) < 1) { return []; } if (\strlen($string) > 3) { if (\substr($string, 0, 2) == 'a:') { try { $res = \unserialize($string); if (\is_array($res)) { return $res; } } catch (\Exception $ex) { } } if (strStartsWith($string, '[') && strEndsWith($string, ']')) { try { return (array) \json_decode($string); } catch (\Exception $ex) { } } else { if (strStartsWith($string, '{') && strEndsWith($string, '}')) { try { return (array) \json_decode($string); } catch (\Exception $ex) { } } } } return array($string); default: if (\strlen($string) < 1) { return null; } if (\strlen($string) > 3) { if (\substr($string, 0, 2) == 'O:' && \preg_match('~^O:[^"]+"' . $typename . '":~', $string)) { try { $res = \unserialize($string); if (!\is_object($res)) { return null; } if (\get_class($res) == $typename) { return $res; } } catch (\Throwable $ex) { } } } return null; } }
public function searchForExtensions($path) { $result = array(); if (is_dir($path)) { if ($dh = opendir($path)) { while (($file = readdir($dh)) !== false) { if ($file == "." || $file == ".." || $file == "CVS" || $file == ".settings" || $file == ".todo") { continue; } if (is_dir($path . "/" . $file)) { $result = array_merge($result, $this->searchForExtensions($path . "/" . $file)); } else { if (strEndsWith($file, ".extension.php", false)) { $result[] = str_replace(".extension.php", "", $file); } } } closedir($dh); } } return $result; }
/** * search forward starting from end minus needle length characters * * @param $string * @param $search * @return bool */ function strEndsWith($string, $search) { if (empty($string) || empty($search)) { throw new InvalidArgumentException("String and Search values cannot be empty."); } if (is_array($search)) { foreach ($search as $i => $str) { if (strEndsWith($string, $str)) { return true; } } return false; } return $search === "" || ($temp = strlen($string) - strlen($search)) >= 0 && strpos($string, $search, $temp) !== false; }
if(!$builtIn[$function]) { if(!$parse['func'][$function]) tlog(false, $function.' in '.$parse2['files'][$decl], 'OK', 'fail'); else $okCount1++; } } tlog(true, 'Other declarations: '.$okCount1, 'OK', 'fail'); tsection('Unused Code'); ksort($parse['func']); foreach($parse['func'] as $function => $decl) if(!strStartsWith($parse2['files'][$decl], './plugins/') && !strStartsWith($parse2['files'][$decl], './log/') && !strStartsWith($parse2['files'][$decl], './static/')) { if(!inStr($parse2['files'][$decl], 'controller') && substr($function, 0, 1) != '_' && substr($function, 0, 1) != '(' && !strStartsWith($parse2['files'][$decl], './msg') && !$ignoreCallCheck[$function] && !strEndsWith($function, 'callback()') && !strStartsWith($function, 'js_') && !strStartsWith($function, 'dyn_') && $function != 'h2_exceptionhandler()') { if(!$parse['call'][$function]) tlog(false, $function.' in '.$parse2['files'][$decl], 'OK', 'fail'); else $okCount2++; } } tlog(true, 'Other calls: '.$okCount2, 'OK', 'fail'); tsection_end(); ?><!--<pre> <? print_r($parse);
public function download($absoluteFilePath) { if (file_exists($absoluteFilePath)) { // Must be fresh start if (headers_sent()) { throw new Exception("Headers Sent"); } // Required for some browsers if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } if (strEndsWith($absoluteFilePath, ".css", false)) { $mimetype = "text/css"; } else { if (strEndsWith($absoluteFilePath, ".js", false)) { $mimetype = "text/javascript"; } else { if (strEndsWith($absoluteFilePath, ".gif", false)) { $mimetype = "image/gif"; } else { $finfo = finfo_open(FILEINFO_MIME_TYPE); $mimetype = finfo_file($finfo, $absoluteFilePath); finfo_close($finfo); } } } // Getting headers sent by the client. $headers = apache_request_headers(); // Checking if the client is validating his cache and if it is current. if (isset($headers['If-Modified-Since']) && strtotime($headers['If-Modified-Since']) >= filemtime($absoluteFilePath)) { // Client's cache IS current, so we just respond '304 Not Modified'. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($absoluteFilePath)) . ' GMT', true, 304); } else { $offset = 60 * 60 * 24 * 3; header("Pragma: public"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); header("Expires: 0"); // Image not cached or cache outdated, we respond '200 OK' and output the image. header('Last-Modified: ' . gmdate('D, d M Y H:i:s', filemtime($absoluteFilePath)) . ' GMT', true, 200); header("Cache-Control: must-revalidate, post-check=0, pre-check=0, max-age=3600-"); header("Cache-Control: private", false); // required for certain browsers header("Content-Type: " . $mimetype); header("Content-Disposition: inline; filename=\"" . basename($absoluteFilePath) . "\";"); header("Content-Transfer-Encoding: binary"); header("Content-Length:" . filesize($absoluteFilePath)); ob_clean(); flush(); @readfile($absoluteFilePath); } } else { header("HTTP/1.0 404 Not Found"); echo "<h1>HTTP/1.0 404 Not Found</h1>"; } }
function shouldProcessFile($file) { return strpos($file, 'banner') === 0 && strEndsWith($file, 'png'); }