Beispiel #1
0
 /**
  * Parses the content of the page.
  *
  * @return array
  */
 private static function content($content)
 {
     // Remove any JavaScript from the Content
     $content = preg_replace('/<script\\b[^>]*>(.*?)<\\/script>/is', ' ', $content);
     // Remove any in-line CSS from the Content
     $content = preg_replace('/<style\\b[^>]*>(.*?)<\\/style>/is', ' ', $content);
     // Ensure there are spaces between tags
     $content = str_replace('><', '> <', $content);
     // Remove the HTML tags from the Content while cleaning up whitespace
     $content = preg_replace('/\\s+/', ' ', strip_tags($content));
     // Remove special HTML characters
     $content = preg_replace('/&#?[a-z0-9]{2,8};/i', '', $content);
     // Get the list of SEO stop words
     $stopArr = \io::helpers('web')->stop_words();
     // Iterate through content and generate keyword usage
     foreach (explode(' ', $content) as $word) {
         /*
          * Normalize words (remove commas, colons, semi-colons, etc.) This also
          * casts integers as strings and ignores casing for words for SEO purposes.
          */
         $word = (string) strtolower(preg_replace("/[^A-Za-z0-9]/", '', $word));
         // Remove short words
         if (!isset($word[2])) {
             // Words 2 characters or less are excluded
             continue;
         }
         // Check if a word exists
         if (isset($keywords['Occurrence'][$word])) {
             // Increment the keyword count
             $keywords['Occurrence'][$word]++;
         } else {
             // Add the word
             $keywords['Occurrence'][$word] = 1;
         }
         // Check against SEO stop words
         if (!in_array($word, $stopArr)) {
             // Add to the SEO relevant keywords
             $keywords['SEO'][$word] = $keywords['Occurrence'][$word];
         }
     }
     // Check for content
     if (isset($keywords)) {
         // Sort Keywords by Occurrence
         arsort($keywords['Occurrence']);
         arsort($keywords['SEO']);
         // Top 10 keywords in order
         $keywords['Top'] = array_keys(array_slice($keywords['SEO'], 0, 10, true));
     } else {
         // No content
         $keywords = array('Occurrence' => array(), 'SEO' => array(), 'Top' => array());
     }
     // Normalize content
     $content = trim($content);
     // Check for empty content
     if ($content == '') {
         // Make developer friendly variable
         $content = false;
     }
     // Digest content
     return array('Content' => $content, 'Words' => str_word_count($content), 'Unique' => count($keywords['Occurrence']), 'Keywords' => $keywords);
 }
Beispiel #2
0
 /**
  * Generate a temporary password.
  *
  * @return string
  */
 public static function tmp_password($length = 8)
 {
     // Random password from string helper
     return \io::helpers('str')->uuid($length);
 }
Beispiel #3
0
 /**
  * Returns a URL slug with or without SEO stop words removed.
  *
  * @param str
  * @param boolean
  *
  * @return str
  */
 public static function slug($str, $seo = false)
 {
     // Normalize the string
     $str = \io::helpers('str')->human(strtolower($str));
     // Optional SEO stop word removal
     if ($seo) {
         // Get a purified string
         $str = self::seo($str);
     }
     // Provide a title slug
     return str_replace(' ', '-', $str);
 }