Exemplo n.º 1
0
 private function filterLinkify($text)
 {
     $urls = explode(' ', $text);
     $containsLink = FALSE;
     foreach ($urls as &$link) {
         if (Fari_Filter::isURL($link)) {
             $containsLink = TRUE;
             // do we have a YouTube video?
             // source: http://www.youtube.com/watch?v=nBBMnY7mANg&feature=popular
             // target: <img src="http://img.youtube.com/vi/nBBMnY7mANg/0.jpg" alt="0">
             if (stripos(strtolower($link), 'youtube') !== FALSE) {
                 $url = parse_url($link);
                 parse_str($url[query], $query);
                 // replace link with an image 'boosted' link :)
                 $link = '<a class="youtube" target="_blank" href="' . $link . '"><img src="http://img.youtube.com/vi/' . $query['v'] . '/0.jpg" alt="YouTube"></a>';
             } else {
                 // plain old link
                 $link = '<a target="_blank" href="' . $link . '">' . $link . '</a>';
             }
             // convert so we can insert into DB
             $link = Fari_Escape::html($link);
         }
     }
     if ($containsLink) {
         return implode(' ', $urls);
     } else {
         return $text;
     }
 }
Exemplo n.º 2
0
 public static function add($username, $password, $realname)
 {
     // escape input
     $username = Fari_Escape::html($username);
     $password = Fari_Escape::html($password);
     $realname = Fari_Escape::html(Fari_Decode::javascript($realname));
     // verify that credentials are provided in a valid form
     if (!empty($username) && ctype_alnum($username) && strlen($username) <= 10) {
         if (!empty($password) && ctype_alnum($password) && strlen($password) <= 10) {
             if (!empty($realname) && strlen($realname) <= 100) {
                 // all OK, db insert
                 Fari_Db::insert('users', array('username' => $username, 'password' => sha1($password), 'realname' => $realname));
                 Fari_Message::success("Welcome {$realname}!");
                 return TRUE;
             } else {
                 Fari_Message::fail("Please provide a valid real name.");
             }
         } else {
             Fari_Message::fail("Please provide a valid password.");
         }
     } else {
         Fari_Message::fail("Please provide a valid username.");
     }
     return FALSE;
 }
 /**
  * Format mixed variables for output
  * @param <type> $mixed
  * @return <type>
  */
 public static function formatVars($mixed)
 {
     // we are working in HTML context
     //$mixed = Fari_Escape::html($mixed);
     if ($mixed === NULL) {
         $mixed = '<em>NULL</em>';
     } else {
         if (empty($mixed)) {
             $mixed = '<em>empty</em>';
         } else {
             if (is_string($mixed)) {
                 $mixed = Fari_Escape::html($mixed);
             } else {
                 ob_start();
                 var_dump($mixed);
                 $mixed = ob_get_contents();
                 ob_clean();
                 $mixed = explode("\n", $mixed);
                 foreach ($mixed as &$line) {
                     // how big is the whitespace on the left?
                     $padding = strlen($line) - strlen(ltrim($line));
                     // add extra padding for better readability
                     for ($i = 0; $i < $padding; $i++) {
                         $line = "  " . $line;
                     }
                     // if our line contains a value give it extra pad
                     if (strpos($trimmed = ltrim($line), "[") !== FALSE) {
                         // highlight array key
                         $line = str_replace("[", "<strong>[", $line);
                         $line = str_replace("]", "]</strong>", $line);
                     } else {
                         if (substr(trim($line), 0) != "}") {
                             $line = "   " . $line;
                         }
                     }
                     $line = substr($line, 3);
                 }
                 $mixed = implode("\n", $mixed);
             }
         }
     }
     return $mixed;
 }