Exemple #1
0
 function add_edge($_previous_as, $_as, $attrs = array())
 {
     global $edges, $graph;
     $edge_array = array($_previous_as => $_as);
     if (!array_key_exists(gek($_previous_as, $_as), $edges)) {
         $attrs['splines'] = "true";
         $edge = array($edge_array, $attrs);
         $graph->addEdge($edge_array, $attrs);
         $edges[gek($_previous_as, $_as)] = $edge;
     } else {
         if (array_key_exists('label', $attrs)) {
             $e =& $edges[gek($_previous_as, $_as)];
             $label_without_star = str_replace("*", "", $attrs['label']);
             $labels = explode("\r", $e[1]['label']);
             if (!in_array($label_without_star . "*", $labels)) {
                 $tmp_labels = array();
                 foreach ($labels as $l) {
                     if (!startsWith($l, $label_without_star)) {
                         $labels[] = $l;
                     }
                 }
                 $labels = array_merge(array($attrs['label']), $tmp_labels);
                 $cmp = function ($a, $b) {
                     return endsWith($a, "*") ? -1 : 1;
                 };
                 usort($labels, $cmp);
                 $label = escape(implode("\r", $labels));
                 $e[1]['label'] = $label;
             }
         }
     }
     return $edges[gek($_previous_as, $_as)];
 }
 /**
  * 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 'empty':
         case '(empty)':
             return '';
         case 'null':
         case '(null)':
             return;
     }
     if (startsWith($value, '"') && endsWith($value, '"')) {
         return substr($value, 1, -1);
     }
     return $value;
 }
Exemple #3
0
function parseCommand($file, $message)
{
    $output = '';
    if (startsWith($message, '/')) {
        $message = substr($message, 1);
        $splits = explode(' ', $message);
        $output = $splits[2];
        switch ($splits[0]) {
            case 'facebook':
                switch ($splits[1]) {
                    case '-user':
                        $analyzer = new FacebookProfiler($splits[2]);
                        $analyzer->analyze();
                        $output = $analyzer->getResponse();
                        break;
                    case '-search':
                        $searcher = new FacebookSearcher($splits[2]);
                        $output = $searcher->getResponse();
                        break;
                }
                break;
            case 'whitespace':
                $name = $splits[1];
                $city = $splits[2];
                $state = $splits[3];
                //$whitepages = new WhitePages('537775405e1660bfb260b59ace642e37');
                break;
        }
        if (strlen($output) > 0) {
            fwrite(fopen($file, 'a'), "<span>Salty Stalker</span>" . '<span class="test">' . ($output = str_replace("\n", " ", $output) . '</span>' . "\n"));
        }
        return true;
    }
    return false;
}
function search($title)
{
    $str = strtolower($title);
    $str = str_replace(array(" "), "_", $str);
    $str = str_replace(array("(", ")", "-", ":", ".", ";", ",", "'", '"', "+", "#"), "", $str);
    if (strlen($str) <= 2) {
        return FALSE;
    }
    do {
        $str2 = urlencode($str);
        $data = @file_get_contents("http://sg.media-imdb.com/suggests/" . substr($str2, 0, 1) . "/{$str2}.json");
        $str = substr($str, 0, -1);
    } while ($data === FALSE && strlen($str) > 2);
    if ($data === FALSE) {
        #		http_response_code(404);
        #       echo "Nope";
        return FALSE;
    }
    $json = substr($data, 5 + strlen($str) + 2, -1);
    $obj = json_decode($json, TRUE);
    #print_r($obj);
    $res = array('show' => array());
    if (isset($obj['d'])) {
        foreach ($obj['d'] as $show) {
            #echo strtolower($show['l'])."\n";
            if (isset($show['q']) && $show['q'] == "TV series" && startsWith(strtolower($show['l']), strtolower($title))) {
                $res['show'][] = array('imdb_id' => $show['id'], 'name' => $show['l'], 'year' => $show['y'], 'img' => isset($show['i']) ? $show['i'][0] : '');
            }
        }
    }
    return $res;
}
Exemple #5
0
function loadUpdatesFromDir($output, $outputIndexes, $dir, $fileFilter, $timestamp)
{
    if (is_dir($dir)) {
        if ($dh = opendir($dir)) {
            while (($file = readdir($dh)) !== false) {
                if (startsWith(strtolower($file), strtolower($fileFilter))) {
                    $indexName = $file;
                    $filename = $dir . $file;
                    //"./test112.zip";
                    $size = number_format(filesize($filename) / (1024.0 * 1024.0), 1, '.', '');
                    $containerSize = filesize($filename);
                    $contentSize = filesize($filename);
                    $date = date('d.m.Y', filemtime($filename));
                    $timestampF = filemtime($filename);
                    if ($timestampF > intval(substr($timestamp, 0, -3))) {
                        $out = $output->createElement('update');
                        $outputIndexes->appendChild($out);
                        $out->setAttribute("updateDate", substr($file, -strlen('.obf.gz') - 8, -strlen('.obf.gz')));
                        $out->setAttribute("containerSize", $containerSize);
                        $out->setAttribute("contentSize", $contentSize);
                        $out->setAttribute("timestamp", $timestampF * 1000);
                        $out->setAttribute("date", $date);
                        $out->setAttribute("size", $size);
                        $out->setAttribute("name", $indexName);
                    }
                }
            }
            closedir($dh);
        }
    } else {
        print $dir . " not a directory!\n";
    }
}
function generateUrl() {
	//$newHost = "https://nowsci.com/s/";
	$host = OCP\Config::getAppValue('shorten', 'host', '');
	$type = OCP\Config::getAppValue('shorten', 'type', '');
	$api = OCP\Config::getAppValue('shorten', 'api', '');
	$curUrl = $_POST['curUrl'];
	$ret = "";
	if (isset($type) && ($type == "" || $type == "internal")) {
		if ($host == "" || startsWith($curUrl, $host)) {
			$ret = $curUrl;
		} else {
			$shortcode = getShortcode($curUrl);
			$newUrl = $host."?".$shortcode;
			$ret = $newUrl;
		}
	} elseif ($type == "googl") {
		if ($api && $api != "") {
			require_once __DIR__ . '/../lib/class.googl.php';
			$googl = new googl($api);
			$short = $googl->s($curUrl);
			$ret = $short;
		} else {
			$ret = $curUrl;
		}
	} else {
		$ret = $curUrl;
	}
	return $ret;
}
Exemple #7
0
function run_sql_file($location)
{
    //load file
    $commands = file_get_contents($location);
    //delete comments
    $lines = explode("\n", $commands);
    $commands = '';
    foreach ($lines as $line) {
        $line = trim($line);
        if ($line && !startsWith($line, '--')) {
            $commands .= $line . "\n";
        }
    }
    //convert to array
    $commands = explode(";", $commands);
    //run commands
    $total = $success = 0;
    foreach ($commands as $command) {
        if (trim($command)) {
            $success += @mysql_query($command) == false ? 0 : 1;
            $total += 1;
        }
    }
    //return number of successful queries and total number of queries found
    return array("success" => $success, "total" => $total);
}
/**
 * URL Utility
 */
function join_url($url1, $url2)
{
    if (strlen($url1) <= 0 || strlen($url2) <= 0) {
        return '';
    } elseif (strlen($url1) <= 0) {
        return trim($url2);
    } elseif (strlen($url2) <= 0) {
        return trim($url1);
    }
    $url1 = preg_match('{^https?:/{0,2}$}i', $url1) ? '' : trim($url1);
    $url2 = trim($url2);
    if (preg_match('{^https?://}i', $url2)) {
        return $url2;
    } elseif (startsWith($url2, '/')) {
        if ((startsWith($url1, 'http://') || startsWith($url1, 'https://')) && preg_match('{^(https?://[^/]+)/?}i', $url1, $match)) {
            return "{$match[1]}{$url2}";
        } else {
            return $url2;
        }
    } elseif (preg_match('{^[?#]}i', $url2)) {
        return "{$url1}{$url2}";
    } elseif (preg_match('{^(https?://[^/]+)$}i', $url1, $match)) {
        return "{$match[1]}/{$url2}";
    } elseif (preg_match('{^(.+/)[^/]*$}i', $url1, $match)) {
        return "{$match[1]}{$url2}";
    } else {
        return $url2;
    }
}
Exemple #9
0
 public function __construct()
 {
     $lines = file(PATH . ".htaccess");
     $activated = false;
     foreach ($lines as $line) {
         if (startsWith($line, '#URLS_PY START#')) {
             $activated = true;
         } elseif (startsWith($line, '#URLS_PY END#')) {
             $activated = false;
         }
         if ($activated && $line != '' && startsWith($line, 'RewriteRule ^')) {
             $string_before_url = '\\^';
             $string_after_url = '\\$';
             $regex_url = "/" . $string_before_url . "(.*?)" . $string_after_url . "/";
             preg_match_all($regex_url, $line, $matches_url);
             $match_url = $matches_url[1][0];
             $match_url = '/' . str_replace('([^/\\.]+)/?', '%s/', $match_url);
             $string_before_namespace = '###';
             $string_after_namespace = '###';
             $regex_namespace = "/" . $string_before_namespace . "(.*?)" . $string_after_namespace . "/";
             preg_match_all($regex_namespace, $line, $matches_namespace);
             $match_namespace = $matches_namespace[1][0];
             if (isset(UrlsPy::$patterns[$match_namespace])) {
                 if (is_array(UrlsPy::$patterns[$match_namespace])) {
                     UrlsPy::$patterns[$match_namespace][] = $match_url;
                 } else {
                     UrlsPy::$patterns[$match_namespace] = array(UrlsPy::$patterns[$match_namespace], $match_url);
                 }
             } else {
                 UrlsPy::$patterns[$match_namespace] = $match_url;
             }
         }
     }
 }
Exemple #10
0
 function _identify($str)
 {
     $msg_identifier = "]8úü";
     $server_delivery_identifier = "Œ";
     $client_delivery_identifier = "½­";
     $acc_info_iden = "™½§”";
     $last_seen_ident = "H8úü";
     $last_seen_ident2 = "{½L‹";
     if (startsWith($str, $msg_identifier, 3)) {
         if (endsWith($str, $server_delivery_identifier)) {
             return 'server_delivery_report';
         } else {
             if (endsWith($str, $client_delivery_identifier)) {
                 return 'client_delivery_report';
             } else {
                 return 'msg';
             }
         }
     } else {
         if (startsWith($str, $acc_info_iden, 3)) {
             return 'account_info';
         } else {
             if (startsWith($str, $last_seen_ident, 3) && strpos($str, $last_seen_ident2)) {
                 return 'last_seen';
             }
         }
     }
 }
Exemple #11
0
 /**
  * @constructor
  *
  * @param {array}  $rules Redirect rules
  * @param {callable|string} $rules[][source] Regex, plain string startsWith() or callback matcher func,
  * @param {string} $rules[][target] String for redirection, can use backreference on regex,
  * @param {?int}   $rules[][options] Redirection $options, or internal by default,
  * @param {?string} $options[source] Base path to match against requests, defaults to root.
  * @param {string|callable} $options[target] Redirects to a static target, or function($request) returns a string;
  */
 public function __construct($rules)
 {
     // rewrite all URLs
     if (is_string($rules)) {
         $rules = array('*' => $rules);
     }
     $rules = util::wrapAssoc($rules);
     $this->rules = array_reduce($rules, function ($result, $rule) {
         $rule = array_select($rule, array('source', 'target', 'options'));
         // note: make sure source is callback
         if (is_string($rule['source'])) {
             // regex
             if (@preg_match($rule['source'], null) !== false) {
                 $rule['source'] = matches($rule['source']);
                 if (is_string($rule['target'])) {
                     $rule['target'] = compose(invokes('uri', array('path')), replaces($rule['source'], $rule['target']));
                 }
             } else {
                 if (!is_callable($rule['source'])) {
                     $rule['source'] = startsWith($rule['source']);
                     if (is_string($rule['target'])) {
                         $rule['target'] = compose(invokes('uri', array('path')), replaces('/^' . preg_quote($rule['source']) . '/', $rule['target']));
                     }
                 }
             }
         }
         if (!is_callable($rule['source'])) {
             throw new InvalidArgumentException('Source must be string, regex or callable.');
         }
         $result[] = $rule;
         return $result;
     }, array());
 }
Exemple #12
0
 public function __call($sName, $aArg)
 {
     if (startsWith($sName, '_')) {
         return Curry::make(array($this, '__force'), array(substr($sName, 1), $aArg));
     }
     return call_user_func_array(array($this->__obj->{$this->__name}, $sName), $aArg);
 }
Exemple #13
0
 private static function routeRequests()
 {
     //CHECK REQUEST LENGHT. MAX=256
     if (strstr(self::$requestURI, 'index.php') || strlen($_SERVER['REQUEST_URI']) > 256) {
         header('Location: /' . Core::readConfig('SITE/WWW'));
         exit;
     }
     self::$requestURI = str_replace(Core::readConfig('SITE/WWW'), '', self::$requestURI);
     self::$requestURI = explode('?', self::$requestURI);
     self::$requestURI = self::$requestURI[0];
     // fuq de ?
     while (strstr(self::$requestURI, '//')) {
         self::$requestURI = str_replace('//', '/', self::$requestURI);
     }
     $requestParams = explode('/', self::$requestURI);
     $requestPage = strtolower(startsWith($requestParams[1], '/') ? $requestParams[1] : '/' . $requestParams[1]);
     $requestParams = array_slice($requestParams, 2);
     if (array_key_exists($requestPage, self::$routes)) {
         if (isset($requestParams[0]) && $requestParams[0] == '') {
             $requestParams = null;
         }
         Core::requireController(self::$routes[$requestPage], $requestParams);
     } else {
         Core::requireController('Redirect', array_slice(explode('/', self::$requestURI), 1));
     }
 }
Exemple #14
0
 public function testIsHtmlAndNoWarningFound()
 {
     assertThat($this->pageContent, startsWith('<!DOCTYPE html>'));
     $this->assertCriticalStringNotfound('PHP Notice');
     $this->assertCriticalStringNotfound('PHP Fatal error');
     $this->assertCriticalStringNotfound('PHP Warning');
 }
 public static function getBaseUrl($append_suffix = false)
 {
     $candidates = array();
     if (isset($_GET[self::QUERY_STRING_PARAM_NAME])) {
         $url = substr($_GET[self::QUERY_STRING_PARAM_NAME], 1);
         $candidates[] = $url;
     }
     if (isset($_SERVER['HTTP_ORIGIN'])) {
         $candidates[] = $_SERVER['HTTP_ORIGIN'];
     }
     if (isset($_SERVER['HTTP_REFERER'])) {
         $candidates[] = $_SERVER['HTTP_REFERER'];
     }
     // Default fallback.
     $base_url = self::$alt_base_urls[0];
     foreach ($candidates as $candidate) {
         foreach (self::$alt_base_urls as $alt_base_url) {
             if ($candidate && startsWith($candidate, $alt_base_url)) {
                 $base_url = $alt_base_url;
             }
         }
     }
     if ($append_suffix) {
         $base_url .= self::$base_url_suffix;
     }
     return $base_url;
 }
Exemple #16
0
/**
 * Removes prefix from start of string
 *
 * @param string $input
 * @param string $prefix
 *
 * @return string
 *
 * @author Lucantis Swann <*****@*****.**>
 */
function chompLeft($input, $prefix)
{
    if (startsWith($input, $prefix)) {
        return mb_substr($input, mb_strlen($prefix));
    }
    return $input;
}
function processUpload($file, $username = null)
{
    if (!$username) {
        $username = fpCurrentUsername();
    }
    $tmpFile = $file["tmp_name"];
    $mimeType = $file["type"];
    $filename = utf8_decode($file["name"]);
    $filename = cleanupFilename($filename);
    $getcwd = getcwd();
    $freeSpace = disk_free_space("/");
    $uploaded = is_uploaded_file($tmpFile);
    $message = "OK";
    if (!$uploaded) {
        return errorMessage("Uploaded file not found.");
    }
    //verify file type
    if (!startsWith($mimeType, "image")) {
        return errorMessage("Uploaded file {$filename} is not an image. ({$mimeType})");
    }
    //move file to destination dir
    $dataRoot = getConfig("upload._diskPath");
    $dataRootUrl = getConfig("upload.baseUrl");
    createDir($dataRoot, $username);
    $uploadDir = combine($dataRoot, $username);
    $uploadedFile = combine($dataRoot, $username, $filename);
    $filesize = filesize($tmpFile);
    $success = move_uploaded_file($tmpFile, $uploadedFile);
    debug("move to {$uploadedFile}", $success);
    if (!$success) {
        return errorMessage("Cannot move file into target dir.");
    }
    return processImage($uploadDir, $filename);
}
function url_add_dots_for_relative($base, $url)
{
    if (empty($url) || empty($base)) {
        return $url;
    }
    $parts = split_url($base);
    $base_path = $parts['path'];
    $parts = split_url($url);
    $url_path = empty($parts['path']) ? '' : $parts['path'];
    if (startsWith($base_path, "/") && startsWith($url, "/")) {
        // Remove the slash and create the ../../.. going to the root
        $url_segments = explode("/", $url_path);
        $path_segments = explode("/", $base_path);
        //print_r ($url_segments);
        //print_r ($path_segments);
        while (count($url_segments) && $url_segments[0] == $path_segments[0]) {
            array_shift($url_segments);
            array_shift($path_segments);
        }
        //print_r ($url_segments);
        //print_r ($path_segments);
        $depth = count($path_segments) - 1;
        //$url = substr($url, 1);
        $url = implode("/", $url_segments);
        while ($depth > 0) {
            $url = '../' . $url;
            $depth--;
        }
    }
    if (empty($url)) {
        return ".";
    }
    return $url;
}
 /**
  * @param $resourceLoader ResourceLoader
  * @param $request WebRequest
  */
 public function __construct($resourceLoader, WebRequest $request)
 {
     global $wgDefaultSkin, $wgResourceLoaderDebug;
     $this->resourceLoader = $resourceLoader;
     $this->request = $request;
     // Interpret request
     // List of modules
     $modules = $request->getVal('modules');
     $this->modules = $modules ? self::expandModuleNames($modules) : array();
     // Various parameters
     $this->skin = $request->getVal('skin');
     $this->user = $request->getVal('user');
     $this->debug = $request->getFuzzyBool('debug', $wgResourceLoaderDebug);
     $this->only = $request->getVal('only');
     $this->version = $request->getVal('version');
     // Wikia - change begin - @author: wladek
     $this->sassParams = array();
     foreach ($request->getValues() as $key => $value) {
         if (startsWith($key, 'sass_')) {
             $this->sassParams[substr($key, strlen('sass_'))] = $value;
         }
     }
     ksort($this->sassParams);
     // Wikia - change end
     $skinnames = Skin::getSkinNames();
     // If no skin is specified, or we don't recognize the skin, use the default skin
     if (!$this->skin || !isset($skinnames[$this->skin])) {
         $this->skin = $wgDefaultSkin;
     }
 }
 protected function parseTitle($titleText)
 {
     global $wgCanonicalNamespaceNames;
     wfProfileIn(__METHOD__);
     $text = $titleText;
     $namespace = NS_MAIN;
     foreach ($wgCanonicalNamespaceNames as $namespaceId => $namespacePrefix) {
         // check only standard namespaces
         if ($namespaceId < 0 || $namespaceId >= 100) {
             continue;
         }
         $namespacePrefix = strtolower($namespacePrefix) . ':';
         if (startsWith(strtolower($titleText), $namespacePrefix)) {
             $text = substr($titleText, strlen($namespacePrefix));
             $namespace = $namespaceId;
             break;
         }
     }
     $text = str_replace(' ', '_', $text);
     $text = trim($text, '_');
     if ($text === '') {
         $text = false;
     }
     wfProfileOut(__METHOD__);
     return array($text, $namespace);
 }
Exemple #21
0
 /**
  * Run all new updates.
  * Update methods have to start with 'updateMethod' and return true (on success).
  *
  * @return array An array containing ran updates.
  *
  * @throws UpdaterException If something went wrong.
  */
 public function update()
 {
     $updatesRan = array();
     // If the user isn't logged in, exit without updating.
     if ($this->isLoggedIn !== true) {
         return $updatesRan;
     }
     if ($this->methods == null) {
         throw new UpdaterException('Couldn\'t retrieve Updater class methods.');
     }
     foreach ($this->methods as $method) {
         // Not an update method or already done, pass.
         if (!startsWith($method->getName(), 'updateMethod') || in_array($method->getName(), $this->doneUpdates)) {
             continue;
         }
         try {
             $method->setAccessible(true);
             $res = $method->invoke($this);
             // Update method must return true to be considered processed.
             if ($res === true) {
                 $updatesRan[] = $method->getName();
             }
         } catch (Exception $e) {
             throw new UpdaterException($method, $e);
         }
     }
     $this->doneUpdates = array_merge($this->doneUpdates, $updatesRan);
     return $updatesRan;
 }
Exemple #22
0
 public function getList($path)
 {
     $this->ensureAccess($path);
     header('Content-Type: application/json');
     $dir = array_map(function ($scan_entry) use($path) {
         if (startsWith($scan_entry, '.')) {
             return;
         }
         $entry = new FileBrowserEntry();
         $fullpath = realpath($path . $scan_entry);
         $entry->name = $scan_entry;
         $entry->type = is_dir($fullpath) ? 'd' : 'f';
         $entry->size = filesize($fullpath);
         if ($entry->type == 'f' && preg_match('/\\.(txt|doc|docx|xls|xlsx|ppt|pptx|zip|rar|jpg|jpeg|gif|png)$/i', $scan_entry) == 0) {
             return;
         }
         return $entry;
     }, scandir($path));
     $entries = array();
     foreach ($dir as $entry) {
         if ($entry) {
             $entries[] = $entry;
         }
     }
     echo json_encode($entries);
 }
 public function testNoneOfEvaluatesToTheLogicalDisjunctionOfTwoOtherMatchers()
 {
     assertThat('good', not(noneOf('bad', 'good')));
     assertThat('good', not(noneOf('good', 'good')));
     assertThat('good', not(noneOf('good', 'bad')));
     assertThat('good', noneOf('bad', startsWith('b')));
 }
 public static function make($string)
 {
     $logger = Logger::getLogger('ActionFactory.make');
     $logger->debug("\$string= '{$string}'");
     $action = null;
     $inside = null;
     if ($string != null) {
         $match = preg_match("/^[a-z]+\\((.+)\\)\$/", $string, $matches);
         if ($match) {
             $inside = $matches[1];
         }
     }
     if ($string == null || $string == '-' || $string == '0') {
         //***
         $action = null;
         //new Nulle();
     } elseif ($string == '?') {
         //***
         $action = Unknown_Action::singleton();
     } elseif (startsWith($string, 'i(') || startsWith($string, 'ins(')) {
         //***
         $action = Insertion_Action::singleton($inside);
     } elseif ($string == 's(' || $string == 'suppr(') {
         //***
         $action = Specific_Deletion_Action::singleton($inside);
     } elseif (startsWith($string, 'si(') || startsWith($string, 'sins(') || startsWith($string, 'suppri(') || startsWith($string, 'supprins(')) {
         //***
         $action = Deletion_and_Insertion_Action::singleton($inside);
     } elseif ($string == 's' || $string == 'suppr') {
         //***
         $action = Deletion_Action::singleton();
     } elseif ($string == 'son' || $string == 'sonor') {
         //***
         $action = Voicing_Action::singleton();
     } elseif ($string == 'nas' || $string == 'nasal') {
         //***
         $action = Nasalization_Action::singleton();
     } elseif ($string == 'n' || $string == 'neutre') {
         //***
         $action = Neutral_Action::singleton();
     } elseif ($string == 'a' || $string == 'assim') {
         //***
         $action = Assimilation_Action::singleton();
     } elseif ($string == 'allV') {
         //***
         $action = Vowel_Lengthening_Action::singleton();
     } elseif ($string == 'decap') {
         //***
         $action = Self_Decapitation_Action::singleton();
     }
     //		else if (chaine.startsWith("iallV(") || chaine.startsWith("insallV(")) //***
     //		    action = new InsertionEtAllongementDeVoyelle(chaine);
     //		else if (chaine.equals("sallV") || chaine.equals("supprallV")) //***
     //		    action = new SuppressionEtAllongementDeVoyelle();
     if ($action != null) {
         $action->defString($string);
     }
     return $action;
 }
 public function testMixedEncodingStartingWithLatin1IsConvertedAndCoercedToUtf8()
 {
     $inputString = iconv("UTF-8", "ISO-8859-15", $this->testString);
     $inputString .= $this->testString;
     $outputString = $this->converter->convert($inputString);
     assertThat($outputString, startsWith($this->testString));
     assertThat(strlen($outputString), is(greaterThan(2 * strlen($this->testString))));
 }
 /**
  * Verifica se o valor não possui espaços vazios no início ou final
  * @param string $value
  * @return boolean
  */
 protected function validTrim($value)
 {
     if (startsWith($value, ' ') || endsWith($value, ' ')) {
         Factory::log()->warn('Valor possui espaços no início ou no final');
         return false;
     }
     return true;
 }
 protected function prepareShowFolderTree($parentFolderId = 'parentFolderId')
 {
     $this->folderDao->shouldReceive('getFolderTreeCte')->with($parentFolderId)->andReturn($parentFolderId . 'Cte');
     $this->dbManager->shouldReceive('prepare')->withArgs(array(anything(), startsWith($parentFolderId . 'Cte')));
     $this->dbManager->shouldReceive('execute')->withArgs(array(anything(), array($parentFolderId)))->andReturn($res = $parentFolderId . 'Res');
     $this->dbManager->shouldReceive('freeResult')->with($res);
     return $res;
 }
 function has_acces($user, $fct, $obj = null)
 {
     if ($user->is_root) {
         return true;
     } elseif (strpos($fct, 'my_') !== false) {
         return true;
     }
     if ($fct == '/profile/edit/') {
         return true;
     }
     /*************    Profile    *******************/
     if ($fct == '/home/') {
         return true;
     } elseif ($fct == '/profile/edit/' . $user->id) {
         return true;
     } elseif ($fct == '/profile/all') {
         return true;
     } elseif (startsWith($fct, '/profile/view')) {
         return true;
     } elseif (startsWith($fct, '/circle/view')) {
         return true;
     } elseif ($fct == '/circle/all/') {
         return true;
     } elseif ($fct == '/circle/all/' . $user->id) {
         return true;
     } elseif ($fct == '/card/') {
         return true;
     } elseif (startsWith($fct, '/card/all')) {
         return true;
     } elseif (startsWith($fct, '/card/add')) {
         return true;
     } elseif (startsWith($fct, '/card/edit')) {
         return true;
     } elseif (startsWith($fct, '/card/submit')) {
         return true;
     } elseif (startsWith($fct, '/card/view')) {
         return true;
     } elseif (startsWith($fct, '/card/save')) {
         return true;
     } elseif (startsWith($fct, '/explore/explore_rank')) {
         return true;
     } elseif ($fct == '/storyboard/') {
         return true;
     } elseif (startsWith($fct, '/storyboard/all')) {
         return true;
     } elseif (startsWith($fct, '/storyboard/add')) {
         return true;
     } elseif (startsWith($fct, '/storyboard/edit')) {
         return true;
     } elseif (startsWith($fct, '/storyboard/submit')) {
         return true;
     } elseif (startsWith($fct, '/storyboard/view')) {
         return true;
     } elseif (startsWith($fct, '/storyboard/save')) {
         return true;
     }
     return false;
 }
function Deserialize($files)
{
    $events = array();
    foreach ($files as $filepath) {
        $file = fopen($filepath, 'r');
        $event = array();
        $pictures = array();
        $event['pictures'] = $pictures;
        $parsingEvents = false;
        $parsingContent = false;
        $currentContent = '';
        while (!feof($file)) {
            $line = fgets($file);
            if ($parsingContent) {
                if (startsWith($line, '---')) {
                    $event['content'] = Markdown($currentContent);
                    $parsingContent = false;
                    $currentContent = '';
                } else {
                    $currentContent .= $line;
                }
            } else {
                if (startsWith($line, '# ')) {
                    if ($parsingEvents) {
                        array_push($events, $event);
                        $event = array();
                        $event['pictures'] = array();
                    } else {
                        $parsingEvents = true;
                    }
                    $eventNameArray = explode('# ', $line);
                    $eventName = $eventNameArray[1];
                    $event['name'] = trim($eventName);
                } else {
                    if (startsWith($line, '## ')) {
                        $eventDateArray = explode('## ', $line);
                        $eventDate = $eventDateArray[1];
                        $event['date'] = trim($eventDate);
                    } else {
                        if (startsWith($line, '*')) {
                            $picLinkArray = explode('* ', $line);
                            $picLink = $picLinkArray[1];
                            array_push($event['pictures'], trim($picLink));
                        } else {
                            if (startsWith($line, '---')) {
                                $parsingContent = true;
                            }
                        }
                    }
                }
            }
        }
        array_push($events, $event);
        fclose($file);
    }
    return $events;
}
Exemple #30
0
 /**
  * Reproducing renderPage() if hell, to avoid regression.
  *
  * This highlights how bad this needs to be rewrite,
  * but let's focus on plugins for now.
  *
  * @param string $query    $_SERVER['QUERY_STRING'].
  * @param array  $get      $_SERVER['GET'].
  * @param bool   $loggedIn true if authenticated user.
  *
  * @return self::page found.
  */
 public static function findPage($query, $get, $loggedIn)
 {
     $loggedIn = $loggedIn === true ? true : false;
     if (empty($query) && !isset($get['edit_link']) && !isset($get['post'])) {
         return self::$PAGE_LINKLIST;
     }
     if (startswith($query, 'do=' . self::$PAGE_LOGIN) && $loggedIn === false) {
         return self::$PAGE_LOGIN;
     }
     if (startswith($query, 'do=' . self::$PAGE_PICWALL)) {
         return self::$PAGE_PICWALL;
     }
     if (startswith($query, 'do=' . self::$PAGE_TAGCLOUD)) {
         return self::$PAGE_TAGCLOUD;
     }
     if (startswith($query, 'do=' . self::$PAGE_OPENSEARCH)) {
         return self::$PAGE_OPENSEARCH;
     }
     if (startsWith($query, 'do=' . self::$PAGE_DAILY)) {
         return self::$PAGE_DAILY;
     }
     // At this point, only loggedin pages.
     if (!$loggedIn) {
         return self::$PAGE_LINKLIST;
     }
     if (startswith($query, 'do=' . self::$PAGE_TOOLS)) {
         return self::$PAGE_TOOLS;
     }
     if (startswith($query, 'do=' . self::$PAGE_CHANGEPASSWORD)) {
         return self::$PAGE_CHANGEPASSWORD;
     }
     if (startswith($query, 'do=' . self::$PAGE_CONFIGURE)) {
         return self::$PAGE_CONFIGURE;
     }
     if (startswith($query, 'do=' . self::$PAGE_CHANGETAG)) {
         return self::$PAGE_CHANGETAG;
     }
     if (startswith($query, 'do=' . self::$PAGE_ADDLINK)) {
         return self::$PAGE_ADDLINK;
     }
     if (isset($get['edit_link']) || isset($get['post'])) {
         return self::$PAGE_EDITLINK;
     }
     if (startswith($query, 'do=' . self::$PAGE_EXPORT)) {
         return self::$PAGE_EXPORT;
     }
     if (startswith($query, 'do=' . self::$PAGE_IMPORT)) {
         return self::$PAGE_IMPORT;
     }
     if (startswith($query, 'do=' . self::$PAGE_PLUGINSADMIN)) {
         return self::$PAGE_PLUGINSADMIN;
     }
     if (startswith($query, 'do=' . self::$PAGE_SAVE_PLUGINSADMIN)) {
         return self::$PAGE_SAVE_PLUGINSADMIN;
     }
     return self::$PAGE_LINKLIST;
 }