Вход Регистрация
Файл: iShort-PHP/ishort-functions.php
Строк: 922
<?php

//Buttons
function php_a_button($b_name,$b_link,$b_class="link",$b_color="1",$b_button="1",$b_target="self") {
$html = <<<HTML

<a class="color-
{$b_color} ishort-btn-{$b_button}" href="{$b_link}" target="_{$b_target}">
            <span><i class="fa 
{$b_class}"></i></span>
            <small>
{$b_name}</small>
</a>
HTML;
echo 
$html;
}


//info, warning, succes note system
function php_ap_notes($notetext="Sample Text",$notecolor="",$rounded="") {
$isround = $rounded ? " ".$rounded : "";
$notecolorx = $notecolor ? $notecolor : "";

$htmldefault = <<<HTML
<div class="ap_note{$notecolorx}{$isround}"> <p>{$notetext}</p> </div>
HTML;

$htmlred = <<<HTML
<div class="ap_note red{$isround}"> <p>{$notetext}</p> </div>
HTML;

$htmlblue = <<<HTML
<div class="ap_note blue{$isround}"> <p>{$notetext}</p> </div>
HTML;

$htmltaupe = <<<HTML
<div class="ap_note taupe{$isround}"> <p>{$notetext}</p> </div>
HTML;

if(
$notecolor == "red") {
echo 
$htmlred;
}
elseif(
$notecolor == "blue") {
echo 
$htmlblue;
}
elseif(
$notecolor == "taupe") {
echo 
$htmltaupe;
}
else {
echo 
$htmldefault;
}
}




//Social Share
function php_share_with_count($actual_link) {
$html = <<<HTML
<div class="article-share-bottom"><b>Social Share</b>                    
                        <span class="social-icon"><a href="http://www.facebook.com/sharer/sharer.php?u=
{$actual_link}" data-url="{$actual_link}" class="social-button ot-share" style="background:#495fbd;" target="_blank"><span class="icon-text fa fa-facebook"></span><font>SHARE </font></a><span class="social-count"><span class="countface">0</span><span class="social-arrow">&nbsp;</span></span></span>
                        
                        <span class="social-icon"><a href="https://twitter.com/intent/tweet?hashtags=&amp;original_referer=
{$actual_link}&amp;source=tweetbutton&amp;url={$actual_link}&amp;hashtags=#Kibris365" data-hashtags="#Kibris365" data-url="{$actual_link}"  data-text="<your-title>" class="social-button ot-tweet" style="background:#43bedd;" target="_blank"><span class="icon-text fa fa-twitter"></span><font>TWEET </font></a><span class="social-count"><span class="counttweet">0</span><span class="social-arrow">&nbsp;</span></span></span>
                        
                        <span class="social-icon"><a href="http://pinterest.com/pin/create/button/?url=
{$actual_link}&amp;description=<your-title>" data-url="{$actual_link}" class="social-button ot-pin" style="background:#d23131;"><span class="icon-text fa fa-pinterest"></span><font>PİNTEREST </font></a><span class="social-count"><span class="countpin">0</span><span class="social-arrow">&nbsp;</span></span></span>
                        
                        <span class="social-icon"><a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=
{$actual_link}&amp;title=<your-title>" class="social-button ot-link" data-url="{$actual_link}" style="background:#264c84;"><span class="icon-text fa fa-linkedin"></span><font>LİNKEDİN </font></a><span class="social-count"><span class="countlink">0</span><span class="social-arrow">&nbsp;</span></span></span>  <div class="clear-float"></div>  </div>
HTML;
echo 
$html;
}


//Change number like twitter and facebook
function ap_custom_number_format($num) {
  
$x = round($num);
  
$x_number_format = number_format($x);
  
$x_array = explode(',', $x_number_format);
  
$x_parts = array('K', 'M', 'B', 'T');
  
$x_count_parts = count($x_array) - 1;
  
$x_display = $x;
  
$x_display = $x_array[0] . ((int) $x_array[1][0] !== 0 ? '.' . $x_array[1][0] : '');
  
$x_display .= $x_parts[$x_count_parts - 1];
  return 
$x_display;
}

//Yahoo Weather
function php_weather_ap($citycode = "664942", $tempstat = "cloudy") {

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://weather.yahooapis.com/forecastrss?w='.$citycode.'&u=c');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$weather_rss = curl_exec($ch);
curl_close($ch);
$weather = new SimpleXMLElement($weather_rss);
$weather_contents = $weather->channel->item->description;

$weather_cond = $weather->channel->item->xpath('yweather:condition');
$weather_loc  = $weather->channel->xpath('yweather:location'); 

$html = <<<HTML
   <div class="ap_weather_container">
                            <div class="
{$tempstat}"></div>
                            <p>
{$weather_loc[0]->attributes()->city} 
                            
{$weather_cond[0]->attributes()->temp} &deg;C</p>
</div>
HTML;
echo 
$html;
}

//Make Clickable Text
function php_make_clickable($text) {
    
$text = preg_replace('#([s|^])(www)#i', '$1http://$2', $text);
    
$text = preg_replace('#((http|https|ftp|telnet|news|gopher|file|wais)://[^s]+)#i', '<a href="$1" target="_blank">$1</a>', $text);
    
$text = preg_replace('#([0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\.[a-wyz][a-z](fo|g|l|m|mes|o|op|pa|ro|seum|t|u|v|z)?)#i', '<a href="mailto:\1">\1</a>', $text);
    echo 
$text;
} 

//Get File Extension
function php_getExtension($filename)
{
    
$pos=strrpos($filename, ".");
    if (
$pos === false) {
        echo 
"";
    } else {
        
$ext=substr($filename, $pos+1);

        echo 
$ext;
    }
}


//Get CURL
function php_rand_pwd($numAlpha = 31, $numNonAlpha = 1){
    
$listAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    
$listNonAlpha = ',;:!?.$/*-+&@_+;./*&?$-!,';
    echo 
str_shuffle(
            
substr(str_shuffle($listAlpha),0,$numAlpha) .
            
substr(str_shuffle($listNonAlpha),0,$numNonAlpha)
    );
}

//Google Url Shortener
function php_google_short($longUrl) {

    
$apiKey  = 'AIzaSyC-au_vqcST44BnxRIRCjy1eIcFwrJcSh4';
    
//Get API key from : http://code.google.com/apis/console/
     
    
$postData = array('longUrl' => $longUrl, 'key' => $apiKey);
    
$jsonData = json_encode($postData);
     
    
$curlObj = curl_init();
     
    
curl_setopt($curlObj, CURLOPT_URL, 'https://www.googleapis.com/urlshortener/v1/url');
    
curl_setopt($curlObj, CURLOPT_RETURNTRANSFER, 1);
    
curl_setopt($curlObj, CURLOPT_SSL_VERIFYPEER, 0);
    
curl_setopt($curlObj, CURLOPT_HEADER, 0);
    
curl_setopt($curlObj, CURLOPT_HTTPHEADER, array('Content-type:application/json'));
    
curl_setopt($curlObj, CURLOPT_POST, 1);
    
curl_setopt($curlObj, CURLOPT_POSTFIELDS, $jsonData);
     
    
$response = curl_exec($curlObj);
     
    
//convert reponse to a json object
    
$json = json_decode($response);
     
    
curl_close($curlObj);
    
    
//echo result
    
if(isset($json->error)){
        echo 
$json->error->message;
    }else{
        echo 
$json->id;
    }
}


//Google QR Code
 
function php_qr_code($size,$url ) {

        
$dsize = $size .'x'.$size; // doubleSize
        
$qr = '<img src="http://chart.apis.google.com/chart?cht=qr&chs=' . $dsize . '&chld=L|0&chl=' . $url . '" width="' .$size .'" height="'.$size .'" alt="QR code" title="QR Code for your mobile device"/>';

         echo 
$qr;
}

    
    
//Facebook Like Box
function php_fb_likebox($pagelink, $width="700",$height="220",$show_faces="true",$header="true",$show_border="true",$stream="false") {
$html = <<<HTML
        <iframe src="//www.facebook.com/plugins/likebox.php?href={$pagelink}&amp;
        width=
{$width}&amp;
        height=
{$height}&amp;
        colorscheme=light&amp;
        show_faces=
{$show_faces}&amp;
        header=
{$header}&amp;
        stream=
{$stream}&amp;
        show_border=
{$show_border}&amp; 
        scrolling="no" 
        frameborder="0" 
        style="border:none; 
        overflow:hidden; 
        width:
{$width}px; 
        height:
{$height}px;" 
        allowTransparency="true">
        </iframe>
HTML;
echo 
$html;
}

//Check Whois Domain 
function php_whois_domain($domain) {

    
// fix the domain name:
    
$domain = strtolower(trim($domain));
    
$domain = preg_replace('/^http:///i', '', $domain);
    
$domain = preg_replace('/^www./i', '', $domain);
    
$domain = explode('/', $domain);
    
$domain = trim($domain[0]);

    
// split the TLD from domain name
    
$_domain = explode('.', $domain);
    
$lst = count($_domain)-1;
    
$ext = $_domain[$lst];

    
// You find resources and lists 
    // like these on wikipedia: 
    //
    // http://de.wikipedia.org/wiki/Whois
    //
    
$servers = array(
        
"biz" => "whois.neulevel.biz",
        
"com" => "whois.internic.net",
        
"us" => "whois.nic.us",
        
"coop" => "whois.nic.coop",
        
"info" => "whois.nic.info",
        
"name" => "whois.nic.name",
        
"net" => "whois.internic.net",
        
"gov" => "whois.nic.gov",
        
"edu" => "whois.internic.net",
        
"mil" => "rs.internic.net",
        
"int" => "whois.iana.org",
        
"ac" => "whois.nic.ac",
        
"ae" => "whois.uaenic.ae",
        
"at" => "whois.ripe.net",
        
"au" => "whois.aunic.net",
        
"be" => "whois.dns.be",
        
"bg" => "whois.ripe.net",
        
"br" => "whois.registro.br",
        
"bz" => "whois.belizenic.bz",
        
"ca" => "whois.cira.ca",
        
"cc" => "whois.nic.cc",
        
"ch" => "whois.nic.ch",
        
"cl" => "whois.nic.cl",
        
"cn" => "whois.cnnic.net.cn",
        
"cz" => "whois.nic.cz",
        
"de" => "whois.nic.de",
        
"fr" => "whois.nic.fr",
        
"hu" => "whois.nic.hu",
        
"ie" => "whois.domainregistry.ie",
        
"il" => "whois.isoc.org.il",
        
"in" => "whois.ncst.ernet.in",
        
"ir" => "whois.nic.ir",
        
"mc" => "whois.ripe.net",
        
"to" => "whois.tonic.to",
        
"tv" => "whois.tv",
        
"ru" => "whois.ripn.net",
        
"org" => "whois.pir.org",
        
"aero" => "whois.information.aero",
        
"nl" => "whois.domain-registry.nl"
    
);

    if (!isset(
$servers[$ext])){
        die(
'Error: No matching nic server found!');
    }

    
$nic_server = $servers[$ext];

    
$output = '';

    
// connect to whois server:
    
if ($conn = fsockopen ($nic_server, 43)) {
        
fputs($conn, $domain."rn");
        while(!
feof($conn)) {
            
$output .= fgets($conn,128);
        }
        
fclose($conn);
    }
    else { die(
'Error: Could not connect to ' . $nic_server . '!'); }

    echo 
$output;
}

//Make php tag cloud easyl
function php_make_tag_cloud( $data = array(), $linkurl="#", $bgcolor="blue" ){    
    
$cloudTags    = array();
    foreach( 
$data as $tag => $count )
    {        
        
$cloudTags[] = '<a rel="tag" class="ap_tag_'.$bgcolor.'" href="'.$linkurl.$tag.'"> <div class="ap_tag_span">' . $count . '</div>' 
        
. htmlspecialchars( stripslashes( $tag ) ) . '</a>';
    }
    echo 
join( "n", $cloudTags ) . "n";
}

//List Dir
function list_files($dir)
{
    if(
is_dir($dir))
      {
          if(
$handle = opendir($dir))
          {
              while((
$file = readdir($handle)) !== false)
              {
                  if(
$file != "." && $file != ".." && $file != "Thumbs.db")
                  {
                      echo 
'<a target="_blank" href="'.$dir.$file.'">'.$file.'</a><br>'."n";
                  }
              }
              
closedir($handle);
          }
    }
}


//Make Login with AUTH
function php_require_auth($sUsr, $sPwd) {
    
$sAuthUsr = !empty($_SERVER['PHP_AUTH_USER']) ? $_SERVER['PHP_AUTH_USER'] : '';
    
$sAuthPwd = !empty($_SERVER['PHP_AUTH_PW']) ? $_SERVER['PHP_AUTH_PW'] : '';

    if(!(
$sAuthUsr == $sUsr && $sAuthPwd == $sPwd))
    {
        
header('WWW-Authenticate: Basic realm="HTTP Basic Authentication"');
        
header('HTTP/1.1 401 Unauthorized');
        echo 
tr('You must enter a valid login ID and password to access this resource.') . "n";
        exit(
false);
    }
    else
        return 
true;
}
function 
tr() {
    
$sToken = func_get_arg(0);

    for(
$i = 1; $i < func_num_args(); $i++)
        
$sToken = str_replace('%'. ($i-1) . '%', func_get_arg($i), $sToken);

    return 
gettext($sToken);
}








//Embed Youtube or Vimeo videos...
function php_video_embed($url="", $width=500, $autoplay=FALSE, $loop=FALSE){

    if(empty(
$url)) echo "Video url is missing";

    
// Size
    
$ratio = 0.5625;
    
$height = $width * $ratio;

    
// Random ID
    
$iframe_id = 'video'.generateRandStr();

    if(
strpos($url, 'youtube') !== FALSE){
        
// YOUTUBE
        
$parsed_url = parse_url($url, PHP_URL_QUERY);
        
parse_str($parsed_url, $parsed_string);
        
$video_id = $parsed_string['v'];
        
$embed_html = '<iframe id="'.$iframe_id.'" width="'.$width.'" height="'.$height.'" src="http://www.youtube.com/embed/*|VIDEOID|*?rel=0" frameborder="0" allowfullscreen></iframe>';
        echo 
str_replace('*|VIDEOID|*', $video_id, $embed_html);

    } else if(
strpos($url, 'vimeo') !== FALSE){
        
// VIMEO
        
$parsed_url = parse_url($url);
        
$video_id = str_replace('/', '', $parsed_url['path']);
        
$embed_html = '<iframe id="'.$iframe_id.'" src="http://player.vimeo.com/video/*|VIDEOID|*?title=0&amp;byline=0&amp;portrait=0&amp;color=ffffff'.($autoplay?'&amp;autoplay=1':'').($loop?'&amp;loop=1':'').'&amp;api=1&amp;player_id='.$iframe_id.'" width="'.$width.'" height="'.$height.'" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>';
        echo 
str_replace('*|VIDEOID|*', $video_id, $embed_html);

    }

    
// Not supported
    
return 'Video url not supported.';
}









//Current Url
function current_url() {
    
// URL association for SSL and protocol compatibility
    
$sHttp = (!empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://';

    
// Determines the domain name with the port
    
$sDomain = ($_SERVER['SERVER_PORT'] != '80') ?  $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] : $_SERVER['SERVER_NAME'];

    return 
$sHttp . $sDomain . $_SERVER['REQUEST_URI'];
}


//Time codes
function php_human_time_ago( $from, $to = '', $as_text = FALSE, $suffix = ' ago' )
    {
        if ( 
$to == '' ) {
            
$to = time();
        }
        
$from = new DateTime( date( 'Y-m-d H:i:s', $from ) );
        
$to   = new DateTime( date( 'Y-m-d H:i:s', $to ) );
        
$diff = $from->diff( $to );

        if ( 
$diff->y > 1 ) {
            
$text = $diff->y . ' years';
        } else if ( 
$diff->y == 1 ) {
            
$text = '1 year';
        } else if ( 
$diff->m > 1 ) {
            
$text = $diff->m . ' months';
        } else if ( 
$diff->m == 1 ) {
            
$text = '1 month';
        } else if ( 
$diff->d > 7 ) {
            
$text = ceil( $diff->d / 7 ) . ' weeks';
        } else if ( 
$diff->d == 7 ) {
            
$text = '1 week';
        } else if ( 
$diff->d > 1 ) {
            
$text = $diff->d . ' days';
        } else if ( 
$diff->d == 1 ) {
            
$text = '1 day';
        } else if ( 
$diff->h > 1 ) {
            
$text = $diff->h . ' hours';
        } else if ( 
$diff->h == 1 ) {
            
$text = ' 1 hour';
        } else if ( 
$diff->i > 1 ) {
            
$text = $diff->i . ' minutes';
        } else if ( 
$diff->i == 1 ) {
            
$text = '1 minute';
        } else if ( 
$diff->s > 1 ) {
            
$text = $diff->s . ' seconds';
        } else {
            
$text = '1 second';
        }

        if ( 
$as_text ) {
            
$text = explode( ' ', $text, 2 );
            
$text = self::number_to_word( $text[0] ) . ' ' . $text[1];
        }

        echo 
'<span class="ap_clock"><i class="fa fa-clock-o"></i> '.trim( $text ) . $suffix. '</span>';
    }

//Make GRAVATAR
function get_gravatar( $email, $size = 32 ) {
        
$url = 'http://www.gravatar.com/';
        
$url .= 'avatar/' . md5( $email ) . '?s=' . (int) abs( $size );
        echo 
'<img src="'.$url.'" class="ap_imgborder" />';
}

# redirect the user to a different location
function php_redirect($uri = '') {
    
$url = base_url($uri);
try {
    if (!
headers_sent()) {
            
// Headers aren't sent, server-side redirecting !
            
header('Location: ' . $url);
            exit;
        } else {
            throw new 
Exception();
        }
    } catch (
Exception $ex) {
    
// Headers already sent!! Javascript?
    
echo '<script type="text/javascript">'
    
. 'window.location.href="' . $url . '";'
    
. '</script>'
    
// Javascript disabled, try metatags.
    
. '<noscript>'
    
. '<meta http-equiv="refresh" content="0;url=' . $url . '" />'
    
. '</noscript>';
    exit;
    }    
}




//  Is the file name an image
function isImage($image) {
    
$image = strtolower($image);

    
$extension = pathinfo($image, PATHINFO_EXTENSION);
    
$allowed = array('jpg', 'png', 'gif', 'jpeg');
    if(!
in_array($extension, $allowed))
        return 
false;
    else
        return 
true;
}

// Remove <script> and html comments
function cleanScript($input) {

    
$search = array(
        
'@<script[^>]*?>.*?</script>@si',   // Strip out javascript
        
'@<![sS]*?--[ tnr]*>@'         // Strip multi-line comments
    
);
    
    
// Remove JS events
    
$output = preg_replace($search, '', $input);
    
$output = str_replace(array('onabort', 'onactivate', 'onafterprint', 'onafterupdate', 'onbeforeactivate', 'onbeforecopy', 'onbeforecut', 'onbeforedeactivate', 'onbeforeeditfocus', 'onbeforepaste', 'onbeforeprint', 'onbeforeunload', 'onbeforeupdate', 'onblur', 'onbounce', 'oncellchange', 'onchange', 'onclick', 'oncontextmenu', 'oncontrolselect', 'oncopy', 'oncut', 'ondataavaible', 'ondatasetchanged', 'ondatasetcomplete', 'ondblclick', 'ondeactivate', 'ondrag', 'ondragdrop', 'ondragend', 'ondragenter', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'onerror', 'onerrorupdate', 'onfilterupdate', 'onfinish', 'onfocus', 'onfocusin', 'onfocusout', 'onhelp', 'onkeydown', 'onkeypress', 'onkeyup', 'onlayoutcomplete', 'onload', 'onlosecapture', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmoveout', 'onmouseover', 'onmouseup', 'onmousewheel', 'onmove', 'onmoveend', 'onmovestart', 'onpaste', 'onpropertychange', 'onreadystatechange', 'onreset', 'onresize', 'onresizeend', 'onresizestart', 'onrowexit', 'onrowsdelete', 'onrowsinserted', 'onscroll', 'onselect', 'onselectionchange', 'onselectstart', 'onstart', 'onstop', 'onsubmit', 'onunload'), "", $output);
    echo 
$output;
}

// Generate a random string. Arguments:
function generateRandStr($length=10){
    
$randstr = "";
    for(
$i=0; strlen($randstr)<$length; $i++){
        
$randnum = mt_rand(0,61);
        if(
$randnum>=36){
            
$randstr .= chr($randnum+61);
        }
    }
    return 
$randstr;
}


//Word Cutter
function php_truncate_end($text, $length = 1024, $ending = '...', $exact = false, $considerHtml = true) {
    
$open_tags    = [];
    if (
$considerHtml) {
        
// if the plain text is shorter than the maximum length, return the whole text
        
if (strlen(preg_replace('/<.*?>/', '', $text)) <= $length) {
            return 
$text;
        }
        
// splits all html-tags to scanable lines
        
preg_match_all('/(<.+?>)?([^<>]*)/s', $text, $lines, PREG_SET_ORDER);
        
$total_length    = mb_strlen($ending);
        
$truncate        = '';
        foreach (
$lines as $line_matchings) {
            
// if there is any html-tag in this line, handle it and add it (uncounted) to the output
            
if (!empty($line_matchings[1])) {
                
// if it's an "empty element" with or without xhtml-conform closing slash (f.e. <br/>)
                
if (preg_match('/^<(s*.+?/s*|s*(img|br|input|hr|area|base|col|frame|link|meta|param)(s.+?)?)>$/is', $line_matchings[1])) {
                    
// do nothing
                    // if tag is a closing tag (f.e. </b>)
                
} else if (preg_match('/^<s*/([^s]+?)s*>$/s', $line_matchings[1], $tag_matchings)) {
                    
// delete tag from $open_tags list
                    
$pos = array_search($tag_matchings[1], $open_tags);
                    if (
$pos !== false) {
                        unset(
$open_tags[$pos]);
                    }
                    
// if tag is an opening tag (f.e. <b>)
                
} else if (preg_match('/^<s*([^s>!]+).*?>$/s', $line_matchings[1], $tag_matchings)) {
                    
// add tag to the beginning of $open_tags list
                    
array_unshift($open_tags, mb_strtolower($tag_matchings[1]));
                }
                
// add html-tag to $truncate'd text
                
$truncate .= $line_matchings[1];
            }
            
// calculate the length of the plain text part of the line; handle entities as one character
            
$content_length = mb_strlen(preg_replace('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', ' ', $line_matchings[2]));
            if (
$total_length + $content_length > $length) {
                
// the number of characters which are left
                
$left = $length - $total_length;
                
$entities_length = 0;
                
// search for html entities
                
if (preg_match_all('/&[0-9a-z]{2,8};|&#[0-9]{1,7};|&#x[0-9a-f]{1,6};/i', $line_matchings[2], $entities, PREG_OFFSET_CAPTURE)) {
                    
// calculate the real length of all entities in the legal range
                    
foreach ($entities[0] as $entity) {
                        if (
$entity[1] + 1 - $entities_length <= $left) {
                            
$left--;
                            
$entities_length += mb_strlen($entity[0]);
                        } else {
                            
// no more characters left
                            
break;
                        }
                    }
                }
                
$truncate .= mb_substr($line_matchings[2], 0, $left + $entities_length);
                
// maximum length is reached, so get off the loop
                
break;
            } else {
                
$truncate        .= $line_matchings[2];
                
$total_length    += $content_length;
            }
            
// if the maximum length is reached, get off the loop
            
if($total_length >= $length) {
                break;
            }
        }
    } else {
        if (
mb_strlen($text) <= $length) {
            return 
$text;
        } else {
            
$truncate = mb_substr($text, 0, $length - mb_strlen($ending));
        }
    }
    
// if the words shouldn't be cut in the middle...
    
if (!$exact) {
        
// ...search the last occurrence of a space...
        
$spacepos = mb_strrpos($truncate, ' ');
        if (isset(
$spacepos)) {
            
// ...and cut the text in this position
            
$truncate = mb_substr($truncate, 0, $spacepos);
        }
    }
    
// add the defined ending to the text
    
$truncate .= $ending;
    if(
$considerHtml) {
        
// close all unclosed html-tags
        
foreach ($open_tags as $tag) {
            
$truncate .= "</$tag>";
        }
    }
    return 
$truncate;
}
    
//CONTACT FORM
function php_contact($title=NULL, $yourmail, $yourname, $mailhost, $login, $password) {

$title = $title ? $title : "Contact Form"; 

if(isset(
$_POST['sendmessage'])) {

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$comments = $_POST['comments'];

require_once(
"lib/class.phpmailer.php");

$mail = new PHPMailer();

$mail->AddAddress($yourmail,$yourname);
$mail->Subject     = "New Mail";
$mail->Body        = $comments;

$mail->IsSMTP();
$mail->Host     = $mailhost;
$mail->SMTPAuth = true;
$mail->Username = $login;
$mail->Password = $password;
$mail->IsHTML(true);
$mail->From     = $email;
$mail->FromName = $name;
$sent = $mail->Send();
if (
$sent) {
$done = '<div class="mailsuccess">Message Sent...</div>';
} else { 
$done = '<div class="mailerror">ERROR...</div>'; }
} else { 
$done = ""; }

$html = <<<PHP
        <div id="contact">
        <form method="post" action="" id="contactform" autocomplete="on">
        
            <fieldset>

                <legend>
{$title}</legend>

                <div>
                    <label for="name" accesskey="U">Your Name</label>
                    <input name="name" type="text" id="name" placeholder="Enter your name" required="required">
                </div>
                <div>
                    <label for="email" accesskey="E">Email</label>
                    <input name="email" type="email" id="email" placeholder="Enter your Email Address" pattern="^[A-Za-z0-9](([_.-]?[a-zA-Z0-9]+)*)@([A-Za-z0-9]+)(([.-]?[a-zA-Z0-9]+)*).([A-Za-z]{2,})$" required="required">
                </div>

                <div>
                    <label for="phone" accesskey="P">Phone <small>(optional)</small></label>
                    <input name="phone" type="tel" id="phone" size="30" placeholder="Enter your phone number">
                </div>
                
                <div>
                    <label for="comments" accesskey="C">Comments</label>
                    <textarea name="comments" cols="40" rows="3" id="comments" placeholder="Enter your comments" spellcheck="true" required="required"></textarea>
                </div>
                
{$done}
            </fieldset>

        
            <input type="submit" name="sendmessage" class="submit" id="submit" value="Send">

        </form>
</div>
PHP;
echo 
$html;
}


//Mysql Insert query shortcut
function php_insert_record($table_name , $data){
    foreach(
$data as $key => $value)
    {
    
//mysqli_real_escape_string
    
$data[$key] = $db->mres($value);
    }
    
$fields = implode(',' , array_keys($data));
    
$values = "'" . implode("','" , array_values($data)) . "'";
    
//Final query   
    
$query = "INSERT INTO {$table}($fields) VALUES($values)";
         
    return 
$db->query($query);
}



//Mysql Connect
function php_connect_db($host,$user,$pass,$db) {

   
$mysqli = new mysqli($host, $user, $pass, $db);

   if(
$mysqli->connect_error) 
     die(
'Connect Error (' . mysqli_connect_errno() . ') '. mysqli_connect_error());

   return 
$mysqli;
}



function 
php_view_source($url)
{
    
$url = file($url);
    
$code = '';
    foreach (
$url as $number => $line) 
    { 
        
$code .= '#<strong>' . $number . '</strong> : ' . htmlspecialchars($line) . '<br />';
    }
    echo 
$code;
}

 function 
ap_php_mkthumb($filename, $max) {
    
$thumb_width = $max;
    
$thumb_height = $thumb_width;

    
// check extension
    
if(preg_match('/.gif$/i', $filename)) {
      
$srcimage = imagecreatefromgif($filename);
    } elseif (
preg_match('/.png$/i', $filename)) {
      
$srcimage = imagecreatefrompng($filename);
    } else {
    
// assume jpg by default
      
$srcimage = imagecreatefromjpeg($filename);
    }

    
// determine file dimensions
    
$width = imagesx($srcimage);
    
$height = imagesy($srcimage);

    
// check file dimensions
    
if(($height > $thumb_height) || ($width > $thumb_width)) {
      
// determine ratio for thumb dimensions
      
if($width > $height) {
        
$ratio = $thumb_width / $width;
      } else {
        
$ratio = $thumb_height / $height;
      }

      
// set thumb dimensions
      
$new_width = round($width * $ratio);
      
$new_height = round($height * $ratio);
      
$dest_image = ImageCreateTrueColor($new_width, $new_height);

      
imagecopyresampled($dest_image, $srcimage, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

      
imagedestroy($srcimage);

    } else {
      
// image is already the correct size
      
$dest_image = $srcimage;
    }

    
imagejpeg($dest_image, $filename);
    
imagedestroy($dest_image);
  }

function 
cleanTR($s) {
    
$tr = array('ş','Ş','ı','İ','ğ','Ğ','ü','Ü','ö','Ö','Ç','ç','&#351;','&#350;','&#305;','&#304;','&#287;','&#286;','&uuml;','&Uuml;','&ouml;','&Ouml;','&Ccedil;','&ccedil;');
    
$eng = array('s','s','i','i','g','g','u','u','o','o','c','c','s','s','i','i','g','g','u','u','o','o','c','c');
    
$s = str_replace($tr,$eng,$s);
    
$s = strtolower($s);
    
$s = preg_replace('/&.+?;/', '', $s);
    
$s = preg_replace('/[^%a-z0-9 _-]/', '', $s);
    
$s = preg_replace('/s+/', '-', $s);
    
$s = preg_replace('|-+|', '-', $s);
    
$s = trim($s, '-');

    return 
$s;
}
?>
Онлайн: 2
Реклама