/** * Return array of names of modules that are avilable, but not yet installed * * @param void * @return array */ function findNotInstalled() { $names = Modules::findNames(); // names of installed modules $modules_path = APPLICATION_PATH . '/modules'; $d = dir($modules_path); if ($d) { $result = array(); while (($entry = $d->read()) !== false) { if (str_starts_with($entry, '.') || !is_dir(APPLICATION_PATH . '/modules/' . $entry)) { continue; } // if if (!in_array($entry, $names)) { $module_class = Inflector::camelize($entry) . 'Module'; require_once "{$modules_path}/{$entry}/{$module_class}.class.php"; $result[] = new $module_class(); } // if } // while return $result; } // if return null; }
/** * Gets the value of an environment variable. Supports boolean, empty and null. * * @param string $key * @param mixed $default * * @return mixed */ function env($key, $default = null) { $value = getenv($key); if ($value === false) { return value($default); } switch (strtolower($value)) { case 'true': case '(true)': return true; case 'false': case '(false)': return false; case 'null': case '(null)': return null; case 'empty': case '(empty)': return ''; } if (str_starts_with($value, '"') && str_ends_with($value, '"')) { return substr($value, 1, -1); } return $value; }
/** * Return array of translation files * * @param void * @return array */ function getTranslationFiles() { if ($this->translation_files === false) { $this->translation_files = array(); $localization_path = $this->getLocalizationPath(); $localization_path_len = strlen($localization_path); $files = get_files($localization_path, 'php'); if (is_foreachable($files)) { foreach ($files as $path) { $file = substr($path, $localization_path_len + 1); if (!str_starts_with($file, 'module.')) { continue; } // if $this->translation_files[] = substr($file, 7, strlen($file) - 11); } // foreach } // if if (count($this->translation_files) < 1) { $this->translation_files = null; } // if } // if return $this->translation_files; }
function array_searchRecursive_loose($needle, $haystack, $strict = false, $path = array(), $exact = false) { global $parent_subtree; if (!is_array($haystack)) { return false; } foreach ($haystack as $key => $val) { if (is_array($val) && ($subPath = array_searchRecursive_loose($needle, $val, $strict, $path))) { $path = array_merge($path, array($key), $subPath); return $path; } else { if (!$strict && str_starts_with($val, $needle) || $strict && str_starts_with($val, $needle)) { $path[] = $key; $parent_subtree = $haystack; return $path; } else { if (!is_array($val)) { if (preg_match("/" . $needle . "/i", $val, $match)) { $path[] = $key; $parent_subtree = $haystack; return $path; } } } } } return false; }
/** * @param $path */ public function setPath($path) { if (!str_starts_with($path, '/')) { $path = '/' . $path; } $this->path = $path; }
/** * Add webpage * * @access public * @param void * @return null */ function add() { if (logged_user()->isGuest()) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } $this->setTemplate('add'); $notAllowedMember = ''; if(!ProjectWebpage::canAdd(logged_user(), active_context(), $notAllowedMember)) { if (str_starts_with($notAllowedMember, '-- req dim --')) flash_error(lang('must choose at least one member of', str_replace_first('-- req dim --', '', $notAllowedMember, $in))); else flash_error(lang('no context permissions to add',lang("webpages"), $notAllowedMember)); ajx_current("empty"); return; } // if $webpage = new ProjectWebpage(); $webpage_data = array_var($_POST, 'webpage'); if(is_array(array_var($_POST, 'webpage'))) { try { if(substr_utf($webpage_data['url'],0,7) != 'http://' && substr_utf($webpage_data['url'],0,7) != 'file://' && substr_utf($webpage_data['url'],0,8) != 'https://' && substr_utf($webpage_data['url'],0,6) != 'about:' && substr_utf($webpage_data['url'],0,6) != 'ftp://') { $webpage_data['url'] = 'http://' . $webpage_data['url']; } $webpage->setFromAttributes($webpage_data); DB::beginWork(); $webpage->save(); $member_ids = json_decode(array_var($_POST, 'members')); //link it! $object_controller = new ObjectController(); $object_controller->add_subscribers($webpage); $object_controller->add_to_members($webpage, $member_ids); $object_controller->link_to_new_object($webpage); $object_controller->add_subscribers($webpage); $object_controller->add_custom_properties($webpage); ApplicationLogs::createLog($webpage, ApplicationLogs::ACTION_ADD); DB::commit(); flash_success(lang('success add webpage', $webpage->getObjectName())); ajx_current("back"); // Error... } catch(Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } } tpl_assign('webpage', $webpage); tpl_assign('webpage_data', $webpage_data); } // add
/** * Execute search * * @param void * @return null */ function search() { if (active_project() && !logged_user()->isProjectUser(active_project())) { flash_error(lang('no access permissions')); ajx_current("empty"); return; } // if $pageType = array_var($_GET, 'page_type'); $search_for = array_var($_GET, 'search_for'); $objectManagers = array("ProjectWebpages", "ProjectMessages", "MailContents", "ProjectFiles", "ProjectMilestones", "ProjectTasks", "ProjectEvents"); $objectTypes = array(lang('webpages'), lang('messages'), lang('emails'), lang('files'), lang('milestones'), lang('tasks'), lang('events')); $iconTypes = array('webpage', 'message', 'email', 'file', 'milestone', 'task', 'event'); if (user_config_option('show_file_revisions_search')) { array_splice($objectManagers, 4, 0, 'ProjectFileRevisions'); array_splice($objectTypes, 4, 0, lang('file contents')); array_splice($iconTypes, 4, 0, 'file'); } $search_results = array(); $timeBegin = microtime(true); if (trim($search_for) == '') { $search_results = null; $pagination = null; } else { $search_results = $this->searchWorkspaces($search_for, $search_results, 5); $search_results = $this->searchUsers($search_for, $search_results, 5); $search_results = $this->searchContacts($search_for, $search_results, 5); if (array_var($_GET, 'search_all_projects') != "true" && active_project() instanceof Project) { $projects = active_project()->getAllSubWorkspacesCSV(true); } else { $projects = null; } $c = 0; foreach ($objectManagers as $om) { $user_id = $om == "MailContents" ? logged_user()->getId() : 0; $results = SearchableObjects::searchByType($search_for, $projects, $om, true, 5, 1, null, $user_id); if (count($results[0]) > 0) { $sr = array(); $sr['result'] = $results[0]; $sr['pagination'] = $results[1]; $sr['type'] = $objectTypes[$c]; $sr['icontype'] = $iconTypes[$c]; $sr['manager'] = $om; $search_results[] = $sr; } $c++; } } // if $timeEnd = microtime(true); if (str_starts_with($search_for, '"') && str_ends_with($search_for, '"')) { $search_for = str_replace('"', '', $search_for); } tpl_assign('search_string', $search_for); tpl_assign('search_results', $search_results); tpl_assign('time', $timeEnd - $timeBegin); ajx_set_no_toolbar(true); ajx_replace(true); }
function update_footer($msg) { global $wp_version; if (!str_starts_with($msg, 'Version', false)) { return sprintf('Version %s | %s', $wp_version, $msg); } return $msg; }
/** * Log user in * * @param void * @return null */ function login() { $redirect_to = null; // Get page user wanted to visit based on GET params if ($this->request->get('re_route')) { $params = array(); foreach ($this->request->url_params as $k => $v) { if ($k != 're_route' && str_starts_with($k, 're_')) { $params[substr($k, 3)] = $v; } // if } // if $redirect_to = assemble_url($this->request->get('re_route'), $params); } else { $redirect_to = assemble_url('dashboard'); } // if // If user is already logged in redirect him to page he wanted to visit if (instance_of($this->logged_user, 'User')) { flash_error('You are already logged in as :display. Please logout before you can login on another account', array('display' => $this->logged_user->getDisplayName())); $this->redirectToUrl($redirect_to); } // if $login_data = $this->request->post('login'); $this->smarty->assign(array('login_data' => $login_data, 'auto_focus' => true)); if ($this->request->isSubmitted()) { $errors = new ValidationErrors(); $email = trim(array_var($login_data, 'email')); $password = array_var($login_data, 'password'); $remember = (bool) array_var($login_data, 'remember'); if ($email == '') { $errors->addError(lang('Email address is required'), 'email'); } // if if (trim($password) == '') { $errors->addError(lang('Password is required'), 'password'); } // if if ($errors->hasErrors()) { $this->smarty->assign('auto_focus', false); $this->smarty->assign('errors', $errors); $this->render(); } // if $user =& $this->authentication->provider->authenticate(array('email' => $email, 'password' => $password, 'remember' => $remember)); if (!$user || is_error($user)) { $errors->addError(lang('Failed to log you in with data you provided. Please try again'), 'login'); $this->smarty->assign('errors', $errors); $this->render(); } // if flash_success(lang('Welcome back :display!', array('display' => $user->getDisplayName()), true, $user->getLanguage()), null, true); $this->redirectToUrl($redirect_to); } // if }
/** * test str_starts_with */ public function testStrStartsWith() { $this->assertTrue(str_starts_with('foobar', 'foo')); $this->assertTrue(str_starts_with('foobar', 'foobar')); $this->assertFalse(str_starts_with('foobar', 'qux')); $this->assertFalse(str_starts_with('foobar', 'bar')); $this->assertFalse(str_starts_with('foobar', 'oba')); $this->assertFalse(str_starts_with('foobar', 'foobarqux')); }
function _registerHandlers() { foreach ($this->mappings as $url => $handler) { if (!str_starts_with($url, '/')) { $url = '/' . $url; } $this->registerHandler($url, $handler); } }
public static function __callStatic($method_name, $args) { $classname = get_called_class(); if (method_exists($classname, $method_name)) { return call_user_func(array($classname, $method_name)); } elseif (str_starts_with($method_name, 'find_by_')) { $attribute = substr($method_name, 8); return static::find_by($attribute, $args[0]); } }
/** * Determine if the given controller method is routable. * * @param \ReflectionMethod $method * @return bool */ public function isRoutable(ReflectionMethod $method) { switch ($method->class) { case 'Routing\\Controller': case 'App\\Core\\Controller': return false; default: return str_starts_with($method->name, $this->verbs); } return false; }
/** * Render button * * Parameters: * * - common anchor parameter * * - method - if POST that this button will be send POST request. Method works * only if href parameter is present * - confirm - enforces confirmation dialog * codes * * @param array $params * @param string $content * @param Smarty $smarty * @param boolean $repeat * @return string */ function smarty_block_link($params, $content, &$smarty, &$repeat) { $href = ''; if (isset($params['href'])) { $href = $params['href']; if (str_starts_with($href, '?')) { $href = assemble_from_string($params['href']); } // if } // if $params['href'] = $href; $confirm = ''; if (array_key_exists('confirm', $params)) { $confirm = lang(trim($params['confirm'])); unset($params['confirm']); } // if $post = false; if (array_key_exists('method', $params)) { if (strtolower($params['method']) == 'post') { $post = true; } // if unset($params['method']); } // if if ($post || $confirm) { $execution = $post ? 'App.postLink(' . var_export($href, true) . ')' : 'location.href = ' . var_export($href, true); if ($confirm) { $params['onclick'] = "if(confirm(" . var_export($confirm, true) . ")) { {$execution}; } return false;"; } else { $params['onclick'] = "{$execution}; return false;"; } // if } // if $not_lang = false; if (isset($params['not_lang'])) { $not_lang = (bool) $params['not_lang']; unset($params['not_lang']); } // if if (array_key_exists('id', $params) && strlen($params['id']) == 0) { unset($params['id']); } // if if (array_key_exists('title', $params)) { $params['title'] = lang($params['title']); } // if $text = $not_lang ? $content : lang($content); return open_html_tag('a', $params) . $text . '</a>'; }
function url_trimAndClean($url) { $url = trim($url); if (str_starts_with($url, '/')) { $url = substr($url, 1); } if (str_ends_with($url, '/')) { $url = substr($url, 0, strlen($url) - 1); } $url = strtolower($url); return $url; }
public function call($funct, $pars, Model $model) { $splitted = explode('_', substr($funct, 3)); $splitted[0] = lcfirst($splitted[0]); if (str_starts_with($funct, 'get')) { return $this->serveGet($splitted, $model); } elseif (str_starts_with($funct, 'set')) { return $this->serveSet($splitted, $pars[0], $model); } else { return null; } }
/** * @param array $nullableSubjects * @param IValidationError $error * * @return bool */ protected function shouldErrorBeIgnored(array $nullableSubjects, IValidationError $error) { if ($error->getConstraint() instanceof NullableConstraint) { return true; } foreach ($nullableSubjects as $subject) { if (str_starts_with($error->getSubject(), $subject)) { return true; } } return false; }
/** * @param string $url * @return ControllerModel|false */ public function getController($url) { $favController = null; foreach ($this->getControllers() as $controller) { if (strlen($url) > $controller->getUrl() && str_starts_with($url, $controller->getUrl())) { if ($favController == null || strlen($favController->getUrl()) < strlen($controller->getUrl())) { $favController = $controller; } } } return $favController; }
/** * Render button * * Parameters: * * - common button parameter * - href - when button is clicked this link is opened * - method - if POST that this button will be send POST request. Method works * only if href parameter is present * - confirm - enforces confirmation dialog * - not_lang - if true content will not be matched agains registered language * codes * * @param array $params * @param string $content * @param Smarty $smarty * @param boolean $repeat * @return string */ function smarty_block_button($params, $content, &$smarty, &$repeat) { if (!isset($params['type'])) { $params['type'] = 'button'; } // if $href = ''; if (isset($params['href'])) { $href = $params['href']; if (str_starts_with($href, '?')) { $href = assemble_from_string($params['href']); } // if unset($params['href']); } // if $confirm = ''; if (isset($params['confirm'])) { $confirm = trim($params['confirm']); unset($params['confirm']); } // if $post = false; if (isset($params['method'])) { $post = strtolower($params['method']) == 'post'; unset($params['method']); } // if if ($href) { $execution = $post ? 'App.postLink(' . var_export($href, true) . ')' : 'location.href = ' . var_export($href, true); if ($confirm) { $params['onclick'] = "if(confirm(" . var_export($confirm, true) . ")) { {$execution}; } return false;"; } else { $params['onclick'] = "{$execution}; return false;"; } // if } else { if ($confirm) { $params['onclick'] = "return confirm(" . var_export($confirm, true) . ")"; } // if } // if $not_lang = false; if (isset($params['not_lang'])) { $not_lang = (bool) $params['not_lang']; unset($params['not_lang']); } // if $text = $not_lang ? $content : lang($content); return open_html_tag('button', $params) . '<span><span>' . clean($text) . '</span></span></button>'; }
function str_starts_with_any($haystack, array $needles, $returnValue = false) { foreach ($needles as $needle) { if (str_starts_with($haystack, $needle)) { if ($returnValue) { return $needle; } else { return true; } } } return false; }
private function checkEmpty($url) { if (strcmp($url, '') == 0 && ($this->pattern == null || strcmp($this->pattern, '') == 0)) { return true; } if (!str_contains($this->pattern, '/') && str_starts_with($this->pattern, ':')) { $parName = substr($this->pattern, 1); $this->matchedPars[$parName] = $url; return true; } else { return false; } }
function &transformPath($lookupPath) { $path = $lookupPath; if ($this->stripLeadingSlash && str_starts_with($path, '/')) { $path = substr($path, 1); } if ($this->stripExtension) { $path = strip_filename_extension($path); } if ('/' != $this->separator) { $path = str_replace($this->separator, '/', $path); } return $path; }
function renderMergedOutputModel(&$model, &$request, &$response) { $targetUrl = ''; if ($this->contextRelative == TRUE && str_starts_with($this->url, "/")) { // Do not apply context path to relative URLs. $targetUrl .= $request->getContextPath(); } $targetUrl .= $this->url; $targetUrl = $this->appendQueryProperties($targetUrl, $model); log_message(LOG_DEBUG, 'Redirecting to: ' . $targetUrl); $response->setStatus(SC_SEE_OTHER); $response->sendRedirect($targetUrl); return true; }
function url_trimAndClean($url) { $url = trim($url); if (str_contains($url, '?')) { $url = explode('?', $url)[0]; } if (str_starts_with($url, '/')) { $url = substr($url, 1); } if (str_ends_with($url, '/')) { $url = substr($url, 0, strlen($url) - 1); } $url = strtolower($url); return $url; }
function &_determineUrlsForServicePoint(&$point) { $urls = array(); $name =& $point->name; if (str_starts_with($name, "/")) { $urls[] = $name; } $aliases =& $point->aliases; foreach ($aliases as $alias) { if (str_starts_with($alias, "/")) { $urls[] = $alias; } } return $urls; }
function autol_db_drivers($name) { $driversPath = 'Graphene\\db\\drivers\\'; if (str_starts_with($name, $driversPath)) { $expl = explode('\\', $name); if ($expl[0] === 'Graphene') { array_shift($expl); } $name = join(DIRECTORY_SEPARATOR, $expl); if (is_dir(G_path($name))) { G_Require($name . DIRECTORY_SEPARATOR . 'impl.php'); } else { G_Require($name . ".php"); } } }
function query($sql) { $this->check_connection(); $result = $this->connection->query($sql); if (!$result) { throw new Exception($this->connection->error . ': ' . h($sql)); } if (!str_starts_with(uc($sql), array('SELECT', 'SHOW'))) { return $result; } $data = array(); while ($row = $result->fetch_assoc()) { $data[] = $row; } $result->free(); return $data; }
public static function getGroupName($groupId) { if (!str_starts_with($groupId, self::$idPrefix)) { return $groupId; } if ($groupId === self::$superUserGroupName || $groupId === self::$everyoneGroupName) { return $groupId; } else { $group = new Group(); $group->setId($groupId); $rGroup = $group->read(); if ($rGroup === null) { throw new GraphException('group id ' . $groupId . ' not found', 400); } return $rGroup->getName(); } }
/** * Constructor * * @param void * @return ThemeConfigHandler */ function __construct() { $themes_dir = with_slash(THEMES_DIR); if(is_dir($themes_dir)) { $d = dir($themes_dir); while(($entry = $d->read()) !== false) { if (str_starts_with($entry, '.') || $entry == "CVS") { continue; } // if if(is_dir($themes_dir . $entry)) { $this->available_themes[] = $entry; } // if } // while $d->close(); } // if } // __construct
/** * Constructor * * @param void * @return LocalizationConfigHandler */ function __construct() { $language_dir = with_slash(ROOT . "/language"); if (is_dir($language_dir)) { $d = dir($language_dir); while (($entry = $d->read()) !== false) { if (str_starts_with($entry, '.') || $entry == "CVS") { continue; } // if if (is_dir($language_dir . $entry)) { $this->available_locales[] = $entry; } // if } // while $d->close(); sort($this->available_locales); } // if } // __construct