/** * @package Komento * @copyright Copyright (C) 2012 Stack Ideas Private Limited. All rights reserved. * @license GNU/GPL, see LICENSE.php * * Komento is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Restricted access'); /* * String utilities class. * */ class KomentoStringHelper { public static function getLangCode() { $lang = JFactory::getLanguage(); $locale = $lang->getLocale(); $langCode = null; if(empty($locale)) { $langCode = 'en-GB'; } else { $langTag = $locale[0]; $langData = explode('.', $langTag); $langCode = JString::str_ireplace('_', '-', $langData[0]); } return $langCode; } public static function getNoun( $var , $count , $includeCount = false ) { static $zeroIsPlural; if (!isset($zeroIsPlural)) { $config = Komento::getConfig(); $zeroIsPlural = $config->get( 'layout_zero_as_plural' ); } $count = (int) $count; $var = ($count===1 || $count===-1 || ($count===0 && !$zeroIsPlural)) ? $var . '_SINGULAR' : $var . '_PLURAL'; return ( $includeCount ) ? JText::sprintf( $var , $count ) : JText::_( $var ); } /* * Convert string from ejax post into assoc-array * param - string * return - assc-array */ public static function ejaxPostToArray($params) { $post = array(); foreach($params as $item) { $pair = explode('=', $item); if( isset( $pair[ 0 ] ) && isset( $pair[ 1 ] ) ) { $key = $pair[0]; $value = KomentoStringHelper::ejaxUrlDecode( $pair[ 1 ] ); if( JString::stristr( $key , '[]' ) !== false ) { $key = JString::str_ireplace( '[]' , '' , $key ); $post[ $key ][] = $value; } else { $post[ $key ] = $value; } } } return $post; } /* * decode the encoded url string * param - string * return - string */ public static function ejaxUrlDecode($string) { $rawStr = urldecode( rawurldecode( $string ) ); if( function_exists( 'html_entity_decode' ) ) { return html_entity_decode($rawStr); } else { return KomentoStringHelper::unhtmlentities($rawStr); } } /** * A pior php 4.3.0 version of * html_entity_decode */ public static function unhtmlentities($string) { // replace numeric entities $string = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $string); $string = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $string); // replace literal entities $trans_tbl = get_html_translation_table(HTML_ENTITIES); $trans_tbl = array_flip($trans_tbl); return strtr($string, $trans_tbl); } public static function linkTweets( $source ) { // Link hashes $pattern = '/\#(\w*)/i'; $replace = '$0'; $source = preg_replace( $pattern , $replace , $source ); // Link authors $pattern = '/\@(\w*)/i'; $replace = '$0'; $source = preg_replace( $pattern , $replace , $source ); return $source; } public static function url2link( $string ) { $newString = $string; preg_match('/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms', $newString, $matches); $patterns = array('/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms', "/([\w]+:\/\/[\w-?&;#~=\.\/\@]+[\w\/])/i", "/([^\w\/])(www\.[a-z0-9\-]+\.[a-z0-9\-]+)/i"); $replace = array('[bbcode-url]', "$1", "$2"); $newString = preg_replace($patterns, $replace, $newString); //now convert back again. if(count($matches) > 0) { $patterns = array('/\[bbcode\-url\]/ms'); $replace = array($matches[0]); $newString = preg_replace($patterns, $replace, $newString); } return $newString; } public static function htmlAnchorLink( $URL, $string ) { if ($string == '') return ''; $pos = JString::strpos($URL, 'http://'); if( $pos === false) { $URL = 'http://' . $URL; } $pattern = "/(((http[s]?:\/\/)|(www\.))(([a-z][-a-z0-9]+\.)?[a-z][-a-z0-9]+\.[a-z]+(\.[a-z]{2,2})?)\/?[a-z0-9._\/~#&=;%+?-]+[a-z0-9\/#=?]{1,1})/is"; $newString = preg_replace($pattern, '' . $string. '', $URL); //this is not a link if( $newString == $URL) { return $string; } return $newString; } public static function escape( $var ) { return htmlspecialchars( $var, ENT_COMPAT, 'UTF-8' ); } public static function tidyHTMLContent( $content ) { require_once( JPATH_ROOT . DIRECTORY_SEPARATOR . 'components' . DIRECTORY_SEPARATOR . 'com_komento' . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'htmlawed' . DIRECTORY_SEPARATOR . 'htmlawed.php' ); $htmLawedConfig = array( 'cdata' => 1, 'clean_ms_char' => 1, 'comment' => 1, 'safe' => 1, 'tidy' => 1, 'valid_xhtml' =>1, 'deny_attribute' => '* -title -href -target -alt', 'keep_bad' => 6, 'anti_link_spam' => array('`.`','') ); //return htmLawed( $content, $htmLawedConfig); return htmLawed( $content ); } // function convert2UTF8( $html ) // { // $encoding = 'iso-8859-1'; // $encoding = strtoupper( $encoding ); // // $html = @mb_convert_encoding($html, 'UTF-8', $encoding); // return $html; // } /* reference: http://publicmind.in/blog/url-encoding/ */ public static function encodeURL( $url ) { $reserved = array( ":" => '!%3A!ui', "/" => '!%2F!ui', "?" => '!%3F!ui', "#" => '!%23!ui', "[" => '!%5B!ui', "]" => '!%5D!ui', "@" => '!%40!ui', "!" => '!%21!ui', "$" => '!%24!ui', "&" => '!%26!ui', "'" => '!%27!ui', "(" => '!%28!ui', ")" => '!%29!ui', "*" => '!%2A!ui', "+" => '!%2B!ui', "," => '!%2C!ui', ";" => '!%3B!ui', "=" => '!%3D!ui', "%" => '!%25!ui', ); $url = str_replace(array('%09','%0A','%0B','%0D'),'',$url); // removes nasty whitespace $url = rawurlencode($url); $url = preg_replace(array_values($reserved), array_keys($reserved), $url); return $url; } public static function rel2abs($rel, $base) { /* return if already absolute URL */ if (parse_url($rel, PHP_URL_SCHEME) != '') return $rel; /* queries and anchors */ if (@$rel[0]=='#' || @$rel[0]=='?') return $base.$rel; /* parse base URL and convert to local variables: $scheme, $host, $path */ extract(parse_url($base)); /* remove non-directory element from path */ $path = preg_replace('#/[^/]*$#', '', $path); /* destroy path if relative url points to root */ if ( @$rel[0] == '/') $path = ''; /* dirty absolute URL */ $abs = "$host$path/$rel"; /* replace '//' or '/./' or '/foo/../' with '/' */ $re = array('#(/\.?/)#', '#/(?!\.\.)[^/]+/\.\./#'); for($n=1; $n>0; $abs=preg_replace($re, '/', $abs, -1, $n)) {} /* absolute URL is ready! */ return $scheme.'://'.$abs; } /** * @author "Sebastián Grignoli" * @package forceUTF8 * @version 1.1 * @link http://www.framework2.com.ar/dzone/forceUTF8-es/ * @example http://www.framework2.com.ar/dzone/forceUTF8-es/ */ public static function forceUTF8($text){ /** * Function forceUTF8 * * This function leaves UTF8 characters alone, while converting almost all non-UTF8 to UTF8. * * It may fail to convert characters to unicode if they fall into one of these scenarios: * * 1) when any of these characters: ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞß * are followed by any of these: ("group B") * ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶•¸¹º»¼½¾¿ * For example: %ABREPRESENT%C9%BB. «REPRESENTÉ» * The "«" (%AB) character will be converted, but the "É" followed by "»" (%C9%BB) * is also a valid unicode character, and will be left unchanged. * * 2) when any of these: àáâãäåæçèéêëìíîï are followed by TWO chars from group B, * 3) when any of these: ðñòó are followed by THREE chars from group B. * * @name forceUTF8 * @param string $text Any string. * @return string The same string, UTF8 encoded * */ if(is_array($text)) { foreach($text as $k => $v) { $text[$k] = KomentoStringHelper::forceUTF8($v); } return $text; } $max = strlen($text); $buf = ""; for($i = 0; $i < $max; $i++){ $c1 = $text{$i}; if($c1>="\xc0"){ //Should be converted to UTF8, if it's not UTF8 already $c2 = $i+1 >= $max? "\x00" : $text{$i+1}; $c3 = $i+2 >= $max? "\x00" : $text{$i+2}; $c4 = $i+3 >= $max? "\x00" : $text{$i+3}; if($c1 >= "\xc0" & $c1 <= "\xdf"){ //looks like 2 bytes UTF8 if($c2 >= "\x80" && $c2 <= "\xbf"){ //yeah, almost sure it's UTF8 already $buf .= $c1 . $c2; $i++; } else { //not valid UTF8. Convert it. $cc1 = (chr(ord($c1) / 64) | "\xc0"); $cc2 = ($c1 & "\x3f") | "\x80"; $buf .= $cc1 . $cc2; } } elseif($c1 >= "\xe0" & $c1 <= "\xef"){ //looks like 3 bytes UTF8 if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf"){ //yeah, almost sure it's UTF8 already $buf .= $c1 . $c2 . $c3; $i = $i + 2; } else { //not valid UTF8. Convert it. $cc1 = (chr(ord($c1) / 64) | "\xc0"); $cc2 = ($c1 & "\x3f") | "\x80"; $buf .= $cc1 . $cc2; } } elseif($c1 >= "\xf0" & $c1 <= "\xf7"){ //looks like 4 bytes UTF8 if($c2 >= "\x80" && $c2 <= "\xbf" && $c3 >= "\x80" && $c3 <= "\xbf" && $c4 >= "\x80" && $c4 <= "\xbf"){ //yeah, almost sure it's UTF8 already $buf .= $c1 . $c2 . $c3; $i = $i + 2; } else { //not valid UTF8. Convert it. $cc1 = (chr(ord($c1) / 64) | "\xc0"); $cc2 = ($c1 & "\x3f") | "\x80"; $buf .= $cc1 . $cc2; } } else { //doesn't look like UTF8, but should be converted $cc1 = (chr(ord($c1) / 64) | "\xc0"); $cc2 = (($c1 & "\x3f") | "\x80"); $buf .= $cc1 . $cc2; } } elseif(($c1 & "\xc0") == "\x80"){ // needs conversion $cc1 = (chr(ord($c1) / 64) | "\xc0"); $cc2 = (($c1 & "\x3f") | "\x80"); $buf .= $cc1 . $cc2; } else { // it doesn't need convesion $buf .= $c1; } } return $buf; } public static function forceLatin1($text) { if(is_array($text)) { foreach($text as $k => $v) { $text[$k] = KomentoStringHelper::forceLatin1($v); } return $text; } return utf8_decode( KomentoStringHelper::forceUTF8($text) ); } public static function fixUTF8($text){ if(is_array($text)) { foreach($text as $k => $v) { $text[$k] = KomentoStringHelper::fixUTF8($v); } return $text; } $last = ""; while($last <> $text){ $last = $text; $text = KomentoStringHelper::forceUTF8( utf8_decode( KomentoStringHelper::forceUTF8($text) ) ); } return $text; } } /** * @package Komento * @copyright Copyright (C) 2012 Stack Ideas Private Limited. All rights reserved. * @license GNU/GPL, see LICENSE.php * * Komento is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ defined('_JEXEC') or die('Restricted access'); /** * Comment utilities class. * */ class KomentoCommentHelper { /** * Process comments data **/ static public function process( $row, $admin = 0 ) { if( isset( $row->processed ) && $row->processed ) { return $row; } if( $row->component == '' || $row->cid == '' ) { return false; } Komento::setCurrentComponent( $row->component ); $config = Komento::getConfig(); $konfig = Komento::getKonfig(); $user = JFactory::getUser()->id; $commentsModel = Komento::getModel( 'comments' ); Komento::import( 'helper', 'date' ); // Duplicate created date first before lapsed time messing up the original date $row->unformattedDate = $row->created; // get number of child for each comment $row->childs = $commentsModel->getTotalChilds( $row->id ); // set url to proper url if( !empty($row->url) ) { // Add 'http://' if not present $row->url = ( 0 === strpos( $row->url, 'http' ) ) ? $row->url : 'http://' . $row->url; } // 1. Load article and article details $application = Komento::loadApplication( $row->component )->load( $row->cid ); if( $application === false ) { $application = Komento::getErrorApplication( $row->component, $row->cid ); } // set component title $row->componenttitle = $application->getComponentName(); // set content title $row->contenttitle = $application->getContentTitle(); // get permalink $row->pagelink = $application->getContentPermalink(); $row->permalink = $row->pagelink . '#kmt-' . $row->id; // set parentlink if( $row->parent_id != 0 ) { $row->parentlink = $row->pagelink . '#kmt-' . $row->parent_id; } // to be reassign $row->shortlink = $row->permalink; // set extension object // use this to check if application is able to load article details // if row->extension is false, means error loading article details $row->extension = $application; if( $admin == 0 ) { // frontend $actionsModel = Komento::getModel( 'actions' ); $socialHelper = Komento::getHelper( 'social' ); // parse comments HTML $row->comment = self::parseComment( $row->comment ); // author's object $row->author = Komento::getProfile( $row->created_by ); // don't convert for guest if( $row->created_by != 0 && $row->created_by != $row->author->id ) { if( $config->get( 'enable_orphanitem_convert' ) ) { KomentoCommentHelper::convertOrphanitem( $row->id ); } } if( $row->created_by != 0 ) { switch( $config->get( 'name_type' ) ) { case 'username': // force username $row->name = $row->author->getUsername(); break; case 'name': $row->name = $row->author->getName(); break; case 'default': default: // default name to profile if name is null if( empty( $row->name ) ) { $row->name = $row->author->getName(); } break; } } else { if( empty( $row->name ) ) { $row->name = JText::_( 'COM_KOMENTO_GUEST' ); } else { if( $config->get( 'guest_label' ) ) { $row->name = JText::_( 'COM_KOMENTO_GUEST' ) . ' ('. $row->name . ')'; } } } // set datetime if( $config->get( 'enable_lapsed_time' ) ) { $row->created = KomentoDateHelper::getLapsedTime( $row->unformattedDate ); } else { $dateformat = $config->get( 'date_format' ); $row->created = KomentoDateHelper::toFormat( KomentoDateHelper::dateWithOffSet( $row->created ), $dateformat ); // $row->created = Komento::getDate( $row->created )->toFormat( $dateformat ); } // get actions likes $row->likes = $actionsModel->countAction( 'likes', $row->id ); // get user liked $row->liked = $actionsModel->liked( $row->id, $user ); // get user reported $row->reported = $actionsModel->reported( $row->id, $user ); } else { // backend // format comments $row->comment = nl2br( Komento::getHelper( 'comment' )->parseBBCode( $row->comment ) ); $row->created = KomentoDateHelper::dateWithOffSet( $row->created ); } $row->processed = true; return $row; } static public function parseComment( $comment ) { $config = Komento::getConfig(); // word censoring if( $config->get( 'filter_word' ) ) { $comment = self::parseCensor( $comment ); } // parseBBcode to HTML $comment = self::parseBBCode( $comment ); // parse newline to br tags // $comment = nl2br( $comment ); return $comment; } public static function parseCensor($text) { // Komento::getHelper('filter'); // $filterHelper = new KomentoFilterHelper; $filterHelper = Komento::getHelper('filter'); $config = Komento::getConfig(); $textToBeFilter = explode(',', $config->get('filter_word_text')); // lets do some AI here. for each string, if there is a space, // remove the space and make it as a new filter text. if( count($textToBeFilter) > 0 ) { $newFilterSet = array(); foreach( $textToBeFilter as $item) { $item = trim( $item ); if( JString::stristr($item, ' ') !== false ) { $newKeyWord = JString::str_ireplace(' ', '', $item); $newFilterSet[] = $newKeyWord; } } if( count($newFilterSet) > 0 ) { $tmpNewFitler = array_merge($textToBeFilter, $newFilterSet); $textToBeFilter = array_unique($tmpNewFitler); } } $filterHelper->strings = $textToBeFilter; $filterHelper->text = $text; return $filterHelper->filter(); } public static function parseBBCode($text) { $config = Komento::getConfig(); $nofollow = $config->get( 'links_nofollow' ) ? ' rel="nofollow"' : ''; $maxdimension = ''; if( $config->get( 'max_image_width' ) || $config->get( 'max_image_height' ) ) { $maxdimension = ' style="'; if( $config->get( 'max_image_width' ) ) { $maxdimension .= 'max-width:' . $config->get( 'max_image_width' ) . 'px;'; } if( $config->get( 'max_image_height' ) ) { $maxdimension .= 'max-height:' . $config->get( 'max_image_width' ) . 'px;'; } $maxdimension .= '"'; } // Converts all html entities properly $text = htmlspecialchars( $text , ENT_NOQUOTES ); $text = trim($text); $text = preg_replace_callback('/\[code( type="(.*?)")?\](.*?)\[\/code\]/ms', 'escape' , $text ); // avoid smileys in pre tag gets replaced $text = KomentoCommentHelper::encodePre( $text ); // change new line to br (without affecting pre) $text = nl2br( $text ); // BBCode to find... $in = array( '/\[b\](.*?)\[\/b\]/ms', '/\[i\](.*?)\[\/i\]/ms', '/\[u\](.*?)\[\/u\]/ms', '/\[img\](.*?)\[\/img\]/ms', '/\[email\](.*?)\[\/email\]/ms', '/\[url\="?(.*?)"?\](.*?)\[\/url\]/ms', '/\[size\="?(.*?)"?\](.*?)\[\/size\]/ms', '/\[color\="?(.*?)"?\](.*?)\[\/color\]/ms', '/\[quote\](.*?)\[\/quote\]/ms', '/\[list\=(.*?)\](.*?)\[\/list\]/ms', '/\[list\](.*?)\[\/list\]/ms', '/\[\*\](.*?)\[\/\*\]/ms' ); // And replace them by... $out = array( '\1', '\1', '\1', '\1', '\1', '\2', '\2', '\2', '
\1
', '
    \2
', '
    \1
', '
  • \1
  • ' ); // strip out bbcode data first $tmp = preg_replace( $in , '' , $text ); // strip out video links too $tmp = Komento::getHelper( 'videos' )->strip( $tmp ); // replace url if( $config->get( 'auto_hyperlink' ) ) { $text = self::replaceURL( $tmp, $text ); } // replace video links if( $config->get( 'allow_video' ) ) { $text = Komento::getHelper( 'videos' )->replace( $text ); } else { $text = Komento::getHelper( 'videos' )->strip( $text ); } // replace bbcode with html $text = preg_replace($in, $out, $text); // Smileys to find... $in = array( ':)', ':-)', ':D', ':o', ':p', ':P', ':(', ';)', ';-)' ); // And replace them by... $out = array( ':)', ':-)', ':D', ':o', ':p', ':P', ':(', ';)', ';-)' ); $text = str_replace($in, $out, $text); // done parsing emoticons and bbcode, decode pre text back $text = KomentoCommentHelper::decodePre( $text ); // paragraphs $text = str_replace("\r", "", $text); $text = "

    ".preg_replace("/(\n){2,}/", "

    ", $text)."

    "; // $text = preg_replace_callback('/
    (.*?)<\/pre>/ms', "removeBr", $text);
    		// $text = preg_replace('/

    (.*?)<\/pre><\/p>/ms', "\\2

    ", $text); $text = preg_replace_callback('/
      (.*?)<\/ul>/ms', "removeBr", $text); // fix [list] within [*] causing dom errors $text = preg_replace('/
    • (.*?)
        (.*?)<\/ul>(.*?)<\/li>/ms', "\\1
          \\2
        \\3", $text); $text = preg_replace('/

          (.*?)<\/ul><\/p>/ms', "
            \\1
          ", $text); return $text; } public static function replaceURL( $tmp , $text ) { $config = Komento::getConfig(); $nofollow = $config->get( 'links_nofollow' ) ? ' rel="nofollow"' : ''; // $pattern = '@(https?://[-\w\.]+(:\d+)?(/([\w/_\.-]*(\?\S+)?)?)?)@'; $pattern = '@(?i)\b((?:https?://|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:\'".,<>?«»“”‘’]))@'; preg_match_all( $pattern , $tmp , $matches ); if( isset( $matches[ 0 ] ) && is_array( $matches[ 0 ] ) ) { foreach( $matches[ 0 ] as $match ) { $text = str_ireplace( $match , '' . $match . '' , $text ); } } return $text; } public static function escape($s) { $code = $s[3]; $code = str_replace("[", "[", $code); $code = str_replace("]", "]", $code); $brush = isset( $s[2] ) && !empty( $s[2] ) ? $s[2] : 'xml'; $code = html_entity_decode( $code ); $code = Komento::getHelper( 'String' )->escape( $code ); if( $brush != '' ) { $result = '
          ' . $code . '
          '; } else { $result = '
          ' . $code . '
          '; } return $result; } public static function encodePre( $text ) { $pattern = '/(.*?)<\/pre>/s'; preg_match_all( $pattern , $text , $matches ); if( isset( $matches[ 0 ] ) && is_array( $matches[ 0 ] ) ) { foreach( $matches[ 1 ] as $match ) { $text = str_ireplace( $match , base64_encode( $match ), $text ); } } return $text; } public static function decodePre( $text ) { $pattern = '/(.*?)<\/pre>/s'; preg_match_all( $pattern , $text , $matches ); if( isset( $matches[ 0 ] ) && is_array( $matches[ 0 ] ) ) { foreach( $matches[ 1 ] as $match ) { $text = str_ireplace( $match , base64_decode( $match ) , $text ); } } return $text; } public static function removeBr($s) { return str_replace("
          ", "", $s[0]); } public static function convertOrphanitem( $id ) { $config = Komento::getConfig(); $comment = Komento::getTable( 'comments' ); $comment->load( $id ); $comment->created_by = $config->get( 'orphanitem_ownership' ); $comment->store(); return true; } } // clean some tags to remain strict // not very elegant, but it works. No time to do better ;) if (!function_exists('removeBr')) { function removeBr($s) { return KomentoCommentHelper::removeBr( $s ); } } // BBCode [code] if (!function_exists('escape')) { function escape($s) { return KomentoCommentHelper::escape( $s ); } }
          12-15-2015
          Category: Blog
          Written by Joseph Skelton
          Hits: 1215

          Chrome Domz has grown its licensed product to include 8 great schools.....and that's just the beginning!

          Iowa, Iowa State, K State, Marquette, NC State, Northern Iowa, UW- Milwaukee and UW- Whitewater

          All product available on Amazon 

          10-14-2015
          Category: Blog
          Written by Joseph Skelton
          Hits: 1847

          Most Improved Player and Most Valuable Player for the Wildcats 2014 

          "These awards are amazing! WOW!" 

          Coach Brian S.

          10-15-2014
          Category: Blog
          Written by Joseph Skelton
          Hits: 1124

          Chrome Domz is now licensed with the Wisconsin Badgers!!

          All product available on Amazon