晋太元中,武陵人捕鱼为业。缘溪行,忘路之远近。忽逢桃花林,夹岸数百步,中无杂树,芳草鲜美,落英缤纷。渔人甚异之,复前行,欲穷其林。 林尽水源,便得一山,山有小口,仿佛若有光。便舍船,从口入。初极狭,才通人。复行数十步,豁然开朗。土地平旷,屋舍俨然,有良田、美池、桑竹之属。阡陌交通,鸡犬相闻。其中往来种作,男女衣着,悉如外人。黄发垂髫,并怡然自乐。 见渔人,乃大惊,问所从来。具答之。便要还家,设酒杀鸡作食。村中闻有此人,咸来问讯。自云先世避秦时乱,率妻子邑人来此绝境,不复出焉,遂与外人间隔。问今是何世,乃不知有汉,无论魏晋。此人一一为具言所闻,皆叹惋。余人各复延至其家,皆出酒食。停数日,辞去。此中人语云:“不足为外人道也。”(间隔 一作:隔绝) 既出,得其船,便扶向路,处处志之。及郡下,诣太守,说如此。太守即遣人随其往,寻向所志,遂迷,不复得路。 南阳刘子骥,高尚士也,闻之,欣然规往。未果,寻病终。后遂无问津者。
| DIR:/proc/self/root/home/salvufkx/public_html/wp-contentmmm/themes/vega/lib/ |
| Current File : //proc/self/root/home/salvufkx/public_html/wp-contentmmm/themes/vega/lib/custom.lib.php |
<?php
/**
* Custom function to get current URL
**/
function curPageURL() {
$pageURL = 'http';
if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
function pp_debug($arr)
{
echo '<pre>';
print_r($arr);
echo '</pre>';
}
function wpapi_pagination($pages = '', $range = 4)
{
$showitems = ($range * 2)+1;
global $paged;
if(empty($paged)) $paged = 1;
if($pages == '')
{
global $wp_query;
$pages = $wp_query->max_num_pages;
if(!$pages)
{
$pages = 1;
}
}
if(1 != $pages)
{
echo "<div class=\"pagination\">";
if($paged > 2 && $paged > $range+1 && $showitems < $pages) echo "<a href='".esc_url(get_pagenum_link(1))."'>« First</a>";
if($paged > 1 && $showitems < $pages) echo "<a href='".esc_url(get_pagenum_link($paged - 1))."'>‹ Previous</a>";
for ($i=1; $i <= $pages; $i++)
{
if (1 != $pages &&( !($i >= $paged+$range+1 || $i <= $paged-$range-1) || $pages <= $showitems ))
{
echo ($paged == $i)? "<span class=\"current\">".$i."</span>":"<a href='".esc_url(get_pagenum_link($i))."' class=\"inactive\">".$i."</a>";
}
}
if ($paged < $pages && $showitems < $pages) echo "<a href=\"".esc_url(get_pagenum_link($paged + 1))."\">Next ›</a>";
if ($paged < $pages-1 && $paged+$range-1 < $pages && $showitems < $pages) echo "<a href='".esc_url(get_pagenum_link($pages))."'>Last »</a>";
echo "</div><br class='clear'/>\n";
}
}
function gen_pagination($total,$currentPage,$baseLink,$nextPrev=true,$limit=10)
{
if(!$total OR !$currentPage OR !$baseLink)
{
return false;
}
//Total Number of pages
$totalPages = ceil($total/$limit);
//Text to use after number of pages
//$txtPagesAfter = ($totalPages==1)? " page": " pages";
//Start off the list.
//$txtPageList = '<br />'.$totalPages.$txtPagesAfter.' : <br />';
//Show only 3 pages before current page(so that we don't have too many pages)
$min = ($page - 3 < $totalPages && $currentPage-3 > 0) ? $currentPage-3 : 1;
//Show only 3 pages after current page(so that we don't have too many pages)
$max = ($page + 3 > $totalPages) ? $totalPages : $currentPage+3;
//Variable for the actual page links
$pageLinks = "";
$baseLinkArr = parse_url($baseLink);
$start = '';
if(isset($baseLinkArr['query']) && !empty($baseLinkArr['query']))
{
$start = '&';
}
else
{
$start = '?';
}
//Loop to generate the page links
for($i=$min;$i<=$max;$i++)
{
if($currentPage==$i)
{
//Current Page
$pageLinks .= '<a href="#" class="active">'.$i.'</a>';
}
elseif($max <= $totalPages OR $i <= $totalPages)
{
$pageLinks .= '<a href="'.esc_url($baseLink.$start).'page='.$i.'" class="slide">'.$i.'</a>';
}
}
if($nextPrev)
{
//Next and previous links
$next = ($currentPage + 1 > $totalPages) ? false : '<a href="'.esc_url($baseLink.$start).'page='.($currentPage + 1).'" class="slide">Next</a>';
$prev = ($currentPage - 1 <= 0 ) ? false : '<a href="'.esc_url($baseLink.$start).'page='.($currentPage - 1).'" class="slide">Previous</a>';
}
if($totalPages > 1)
{
return '<br class="clear"/><div class="pagination">'.$txtPageList.$prev.$pageLinks.$next.'</div>';
}
else
{
return '';
}
}
function count_shortcode($content = '')
{
$return = array();
if(!empty($content))
{
$pattern = get_shortcode_regex();
$count = preg_match_all('/'.$pattern.'/s', $content, $matches);
$return['total'] = $count;
if(isset($matches[0]))
{
foreach($matches[0] as $match)
{
$return['content'][] = substr_replace($match ,"",-1);
}
}
}
return $return;
}
function dimox_breadcrumbs() {
$delimiter = '/';
$home = 'Home'; // text for the 'Home' link
$before = '<span class="current">'; // tag before the current crumb
$after = '</span>'; // tag after the current crumb
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
$homeLink = home_url();
echo '<a href="' . esc_url($homeLink) . '">' . $home . '</a> ' . $delimiter . ' ';
if ( is_category() ) {
global $wp_query;
$cat_obj = $wp_query->get_queried_object();
$thisCat = $cat_obj->term_id;
$thisCat = get_category($thisCat);
$parentCat = get_category($thisCat->parent);
if ($thisCat->parent != 0) echo(get_category_parents($parentCat, TRUE, ' ' . $delimiter . ' '));
echo $before . 'Archive by category "' . single_cat_title('', false) . '"' . $after;
} elseif ( is_day() ) {
echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo '<a href="' . esc_url(get_month_link(get_the_time('Y'),get_the_time('m'))) . '">' . get_the_time('F') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('d') . $after;
} elseif ( is_month() ) {
echo '<a href="' . esc_url(get_year_link(get_the_time('Y'))) . '">' . get_the_time('Y') . '</a> ' . $delimiter . ' ';
echo $before . get_the_time('F') . $after;
} elseif ( is_year() ) {
echo $before . get_the_time('Y') . $after;
} elseif ( is_single() && !is_attachment() ) {
if ( get_post_type() != 'post' ) {
$post_type = get_post_type_object(get_post_type());
$slug = $post_type->rewrite;
echo $post_type->labels->singular_name . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} else {
$cat = get_the_category(); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo $before . get_the_title() . $after;
}
} elseif ( !is_single() && !is_page() && get_post_type() != 'post' && !is_404() && !is_search()) {
$post_type = get_post_type_object(get_post_type());
echo $before . $post_type->labels->singular_name . $after;
} elseif ( is_attachment() ) {
$parent = get_post($post->post_parent);
$cat = get_the_category($parent->ID); $cat = $cat[0];
echo get_category_parents($cat, TRUE, ' ' . $delimiter . ' ');
echo '<a href="' . esc_url(get_permalink($parent)) . '">' . $parent->post_title . '</a> ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_page() && !$post->post_parent ) {
echo $before . get_the_title() . $after;
} elseif ( is_page() && $post->post_parent ) {
$parent_id = $post->post_parent;
$breadcrumbs = array();
while ($parent_id) {
$page = get_page($parent_id);
$breadcrumbs[] = '<a href="' . esc_url(get_permalink($page->ID)) . '">' . get_the_title($page->ID) . '</a>';
$parent_id = $page->post_parent;
}
$breadcrumbs = array_reverse($breadcrumbs);
foreach ($breadcrumbs as $crumb) echo $crumb . ' ' . $delimiter . ' ';
echo $before . get_the_title() . $after;
} elseif ( is_search() ) {
echo $before . 'Search results for "' . get_search_query() . '"' . $after;
} elseif ( is_tag() ) {
echo $before . 'Posts tagged "' . single_tag_title('', false) . '"' . $after;
} elseif ( is_author() ) {
global $author;
$userdata = get_userdata($author);
echo $before . 'Articles posted by ' . $userdata->display_name . $after;
} elseif ( is_404() ) {
echo $before . 'Error 404' . $after;
}
if ( get_query_var('paged') ) {
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ' (';
echo __('Page', THEMEDOMAIN) . ' ' . get_query_var('paged');
if ( is_category() || is_day() || is_month() || is_year() || is_search() || is_tag() || is_author() ) echo ')';
}
echo '</div>';
}
} // end dimox_breadcrumbs()
/**
* Setup blog comment style
**/
function pp_comment($comment, $args, $depth)
{
$GLOBALS['comment'] = $comment;
?>
<div class="comment" id="comment-<?php comment_ID() ?>">
<div class="gravatar">
<?php echo get_avatar($comment,$size='60',$default='' ); ?>
</div>
<div class="comment_arrow"></div>
<div class="right">
<?php
if($depth < 3)
{
?>
<p class="comment-reply-link"><?php comment_reply_link(array_merge( $args, array('depth' => $depth,
'reply_text' => __('Reply', THEMEDOMAIN), 'login_text' => __('Login to Reply', THEMEDOMAIN), 'max_depth' => $args['max_depth']))) ?></p>
<?php
}
?>
<?php if ($comment->comment_approved == '0') : ?>
<em><?php echo _e('(Your comment is awaiting moderation.)', THEMEDOMAIN) ?></em>
<br />
<?php endif; ?>
<?php
if(!empty($comment->comment_author_url))
{
?>
<a href="<?php echo esc_url($comment->comment_author_url); ?>"><strong style="float:left;margin-top:1px"><?php echo $comment->comment_author; ?></strong></a>
<?php
}
else
{
?>
<h7 style="float:left;margin-top:1px"><?php echo $comment->comment_author; ?></h7>
<?php
}
?>
<div class="comment_date"><?php echo date_i18n(THEMEDATEFORMAT.", ".THEMETIMEFORMAT, strtotime($comment->comment_date)); ?></div>
<?php comment_text() ?>
</div>
</div>
<?php
}
function pp_ago($timestamp){
$difference = time() - $timestamp;
$periods = array("second", "minute", "hour", "day", "week", "month", "years", "decade");
$lengths = array("60","60","24","7","4.35","12","10");
for($j = 0; $difference >= $lengths[$j]; $j++)
$difference /= $lengths[$j];
$difference = round($difference);
if($difference != 1) $periods[$j].= "s";
$text = "$difference $periods[$j] ago";
return $text;
}
// Substring without losing word meaning and
// tiny words (length 3 by default) are included on the result.
// "..." is added if result do not reach original string length
function pp_substr($str, $length, $minword = 3)
{
$sub = '';
$len = 0;
foreach (explode(' ', $str) as $word)
{
$part = (($sub != '') ? ' ' : '') . $word;
$sub .= $part;
$len += strlen($part);
if (strlen($word) > $minword && strlen($sub) >= $length)
{
break;
}
}
return $sub . (($len < strlen($str)) ? '...' : '');
}
/**
* Setup recent posts widget
**/
function pp_posts($sort = 'recent', $items = 3, $echo = TRUE, $bg_color = 'black' , $echo_title = TRUE)
{
$return_html = '';
if($sort == 'recent')
{
$posts = get_posts('numberposts='.$items.'&order=DESC&orderby=date&post_type=post&post_status=publish');
$title = __('Recent Posts', THEMEDOMAIN);
}
else
{
global $wpdb;
$query = "SELECT ID, post_title, post_content, post_date FROM {$wpdb->prefix}posts WHERE post_type = 'post' AND post_status= 'publish' ORDER BY comment_count DESC LIMIT 0,".$items;
$posts = $wpdb->get_results($query);
$title = __('Popular Posts', THEMEDOMAIN);
}
if(!empty($posts))
{
if($echo_title)
{
$return_html.= '<h2 class="widgettitle">'.$title.'</h2>';
}
$return_html.= '<ul class="posts blog '.esc_attr($bg_color).'_wrapper">';
foreach($posts as $post)
{
$image_thumb = '';
if(has_post_thumbnail($post->ID, 'large'))
{
$image_id = get_post_thumbnail_id($post->ID);
$image_thumb = wp_get_attachment_image_src($image_id, 'thumbnail', true);
}
$return_html.= '<li>';
if(!empty($image_thumb))
{
$return_html.= '<a href="'.esc_url(get_permalink($post->ID)).'"><img src="'.esc_url($image_thumb[0]).'" alt="" class="img_nofade frame"/></a>';
}
$return_html.= '<strong class="header"><a href="'.esc_url(get_permalink($post->ID)).'">'.$post->post_title.'</a></strong>';
$return_html.= '<div class="post_detail">'.get_the_time(THEMEDATEFORMAT, $post->ID).'</div>';
}
$return_html.= '</ul>';
}
if($echo)
{
echo $return_html;
}
else
{
return $return_html;
}
}
function pp_cat_posts($cat_id = '', $items = 5, $echo = TRUE)
{
$return_html = '';
$posts = get_posts('numberposts='.$items.'&order=DESC&orderby=date&category='.$cat_id);
$title = get_cat_name($cat_id);
$category_link = get_category_link($cat_id);
$count_post = count($posts);
if(!empty($posts))
{
$return_html.= '<h2 class="widgettitle">'.$title.'</h2>';
$return_html.= '<ul class="posts blog">';
foreach($posts as $post)
{
$image_thumb = '';
if(has_post_thumbnail($post->ID, 'large'))
{
$image_id = get_post_thumbnail_id($post->ID);
$image_thumb = wp_get_attachment_image_src($image_id, 'thumbnails', true);
}
$return_html.= '<li>';
if(!empty($image_thumb))
{
$return_html.= '<a href="'.esc_url(get_permalink($post->ID)).'"><img src="'.esc_url($image_thumb[0]).'" alt="" class="img_nofade frame"/></a>';
}
$return_html.= '<strong class="header"><a href="'.esc_url(get_permalink($post->ID)).'">'.$post->post_title.'</a></strong>';
}
$return_html.= '</ul>';
}
if($echo)
{
echo $return_html;
}
else
{
return $return_html;
}
}
function _substr($str, $length, $minword = 3)
{
$sub = '';
$len = 0;
foreach (explode(' ', $str) as $word)
{
$part = (($sub != '') ? ' ' : '') . $word;
$sub .= $part;
$len += strlen($part);
if (strlen($word) > $minword && strlen($sub) >= $length)
{
break;
}
}
return $sub . (($len < strlen($str)) ? '...' : '');
}
function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
$pp_blog_read_more_title = get_option('pp_blog_read_more_title');
if(empty($pp_blog_read_more_title))
{
$pp_blog_read_more_title = 'Read More';
}
$content = get_the_content('', $stripteaser, $more_file);
$content = strip_shortcodes($content);
$content = str_replace(']]>', ']]>', $content);
$content = '<div class="post_excerpt">'._substr(strip_tags(strip_shortcodes($content)), 320).'</div>';
return $content;
}
function image_from_description($data) {
preg_match_all('/<img src="([^"]*)"([^>]*)>/i', $data, $matches);
return $matches[1][0];
}
function select_image($img, $size) {
$img = explode('/', $img);
$filename = array_pop($img);
// The sizes listed here are the ones Flickr provides by default. Pass the array index in the
// 0 for square, 1 for thumb, 2 for small, etc.
$s = array(
'_s.', // square
'_t.', // thumb
'_m.', // small
'.', // medium
'_b.' // large
);
$img[] = preg_replace('/(_(s|t|m|b))?\./i', $s[$size], $filename);
return implode('/', $img);
}
function get_flickr($settings) {
if (!function_exists('MagpieRSS')) {
// Check if another plugin is using RSS, may not work
include_once (ABSPATH . WPINC . '/class-simplepie.php');
error_reporting(E_ERROR);
}
if(!isset($settings['items']) || empty($settings['items']))
{
$settings['items'] = 9;
}
// get the feeds
if ($settings['type'] == "user") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?id=' . $settings['id'] . '&tags=' . $settings['tags'] . '&per_page='.$settings['items'].'&format=rss_200'; }
elseif ($settings['type'] == "favorite") { $rss_url = 'http://api.flickr.com/services/feeds/photos_faves.gne?id=' . $settings['id'] . '&format=rss_200'; }
elseif ($settings['type'] == "set") { $rss_url = 'http://api.flickr.com/services/feeds/photoset.gne?set=' . $settings['set'] . '&nsid=' . $settings['id'] . '&format=rss_200'; }
elseif ($settings['type'] == "group") { $rss_url = 'http://api.flickr.com/services/feeds/groups_pool.gne?id=' . $settings['id'] . '&format=rss_200'; }
elseif ($settings['type'] == "public" || $settings['type'] == "community") { $rss_url = 'http://api.flickr.com/services/feeds/photos_public.gne?tags=' . $settings['tags'] . '&format=rss_200'; }
else {
print '<strong>No "type" parameter has been setup. Check your settings, or provide the parameter as an argument.</strong>';
die();
}
# get rss file
$feed = new SimplePie($rss_url);
$photos_arr = array();
foreach ($feed->get_items() as $key => $item)
{
$enclosure = $item->get_enclosure();
$img = image_from_description($item->get_description());
$thumb_url = select_image($img, 0);
$large_url = select_image($img, 4);
$photos_arr[] = array(
'title' => $enclosure->get_title(),
'thumb_url' => $thumb_url,
'url' => $large_url,
);
$current = intval($key+1);
if($current == $settings['items'])
{
break;
}
}
return $photos_arr;
}
function html2rgb($color)
{
if ($color[0] == '#')
$color = substr($color, 1);
if (strlen($color) == 6)
list($r, $g, $b) = array($color[0].$color[1],
$color[2].$color[3],
$color[4].$color[5]);
elseif (strlen($color) == 3)
list($r, $g, $b) = array($color[0].$color[0], $color[1].$color[1], $color[2].$color[2]);
else
return false;
$r = hexdec($r); $g = hexdec($g); $b = hexdec($b);
return array($r, $g, $b);
}
function hex_lighter($hex,$factor = 30)
{
$new_hex = '';
$base['R'] = hexdec($hex{0}.$hex{1});
$base['G'] = hexdec($hex{2}.$hex{3});
$base['B'] = hexdec($hex{4}.$hex{5});
foreach ($base as $k => $v)
{
$amount = 255 - $v;
$amount = $amount / 100;
$amount = round($amount * $factor);
$new_decimal = $v + $amount;
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2)
{ $new_hex_component = "0".$new_hex_component; }
$new_hex .= $new_hex_component;
}
return $new_hex;
}
function hex_darker($hex,$factor = 30)
{
$new_hex = '';
$base['R'] = hexdec($hex{0}.$hex{1});
$base['G'] = hexdec($hex{2}.$hex{3});
$base['B'] = hexdec($hex{4}.$hex{5});
foreach ($base as $k => $v)
{
$amount = $v / 100;
$amount = round($amount * $factor);
$new_decimal = $v - $amount;
$new_hex_component = dechex($new_decimal);
if(strlen($new_hex_component) < 2)
{ $new_hex_component = "0".$new_hex_component; }
$new_hex .= $new_hex_component;
}
return $new_hex;
}
function get_image_sizes($sourceImageFilePath,
$maxResizeWidth, $maxResizeHeight) {
// Get width and height of original image
$size = getimagesize($sourceImageFilePath);
if($size === FALSE) return FALSE; // Error
$origWidth = $size[0];
$origHeight = $size[1];
// Change dimensions to fit maximum width and height
$resizedWidth = $origWidth;
$resizedHeight = $origHeight;
if($resizedWidth > $maxResizeWidth) {
$aspectRatio = $maxResizeWidth / $resizedWidth;
$resizedWidth = round($aspectRatio * $resizedWidth);
$resizedHeight = round($aspectRatio * $resizedHeight);
}
if($resizedHeight > $maxResizeHeight) {
$aspectRatio = $maxResizeHeight / $resizedHeight;
$resizedWidth = round($aspectRatio * $resizedWidth);
$resizedHeight = round($aspectRatio * $resizedHeight);
}
// Return an array with the original and resized dimensions
return array($resizedWidth,
$resizedHeight);
}
function XML2Array ( $xml , $recursive = false )
{
if ( ! $recursive )
{
$array = simplexml_load_string ( $xml ) ;
}
else
{
$array = $xml ;
}
$newArray = array () ;
$array = ( array ) $array ;
foreach ( $array as $key => $value )
{
$value = ( array ) $value ;
if ( isset ( $value [ 0 ] ) )
{
$newArray [ $key ] = trim ( $value [ 0 ] ) ;
}
else
{
$newArray [ $key ] = XML2Array ( $value , true ) ;
}
}
return $newArray ;
}
/**
* Converts a simpleXML element into an array. Preserves attributes and everything.
* You can choose to get your elements either flattened, or stored in a custom index that
* you define.
* For example, for a given element
* <field name="someName" type="someType"/>
* if you choose to flatten attributes, you would get:
* $array['field']['name'] = 'someName';
* $array['field']['type'] = 'someType';
* If you choose not to flatten, you get:
* $array['field']['@attributes']['name'] = 'someName';
* _____________________________________
* Repeating fields are stored in indexed arrays. so for a markup such as:
* <parent>
* <child>a</child>
* <child>b</child>
* <child>c</child>
* </parent>
* you array would be:
* $array['parent']['child'][0] = 'a';
* $array['parent']['child'][1] = 'b';
* ...And so on.
* _____________________________________
* @param simpleXMLElement $xml the XML to convert
* @param boolean $flattenValues Choose wether to flatten values
* or to set them under a particular index.
* defaults to true;
* @param boolean $flattenAttributes Choose wether to flatten attributes
* or to set them under a particular index.
* Defaults to true;
* @param boolean $flattenChildren Choose wether to flatten children
* or to set them under a particular index.
* Defaults to true;
* @param string $valueKey index for values, in case $flattenValues was set to
* false. Defaults to "@value"
* @param string $attributesKey index for attributes, in case $flattenAttributes was set to
* false. Defaults to "@attributes"
* @param string $childrenKey index for children, in case $flattenChildren was set to
* false. Defaults to "@children"
* @return array the resulting array.
*/
function simpleXMLToArray($xml,
$flattenValues=true,
$flattenAttributes = true,
$flattenChildren=true,
$valueKey='@value',
$attributesKey='@attributes',
$childrenKey='@children'){
$return = array();
if(!($xml instanceof SimpleXMLElement)){return $return;}
$name = $xml->getName();
$_value = trim((string)$xml);
if(strlen($_value)==0){$_value = null;};
if($_value!==null){
if(!$flattenValues){$return[$valueKey] = $_value;}
else{$return = $_value;}
}
$children = array();
$first = true;
foreach($xml->children() as $elementName => $child){
$value = simpleXMLToArray($child, $flattenValues, $flattenAttributes, $flattenChildren, $valueKey, $attributesKey, $childrenKey);
if(isset($children[$elementName])){
if($first){
$temp = $children[$elementName];
unset($children[$elementName]);
$children[$elementName][] = $temp;
$first=false;
}
$children[$elementName][] = $value;
}
else{
$children[$elementName] = $value;
}
}
if(count($children)>0){
if(!$flattenChildren){$return[$childrenKey] = $children;}
else{$return = array_merge($return,$children);}
}
$attributes = array();
foreach($xml->attributes() as $name=>$value){
$attributes[$name] = trim($value);
}
if(count($attributes)>0){
if(!$flattenAttributes){$return[$attributesKey] = $attributes;}
else{$return = array_merge($return, $attributes);}
}
return $return;
}
function theme_queue_js(){
if (!is_admin()){
if (!is_page() AND is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
wp_enqueue_script( 'comment-reply' );
}
}
}
add_action('get_header', 'theme_queue_js');
function pp_apply_content($pp_content) {
$pp_content = apply_filters('the_content', $pp_content);
$pp_content = str_replace(']]>', ']]>', $pp_content);
return $pp_content;
}
//Clean Up WordPress Shortcode Formatting - important for nested shortcodes
//adjusted from http://donalmacarthur.com/articles/cleaning-up-wordpress-shortcode-formatting/
function parse_shortcode_content( $content ) {
/* Parse nested shortcodes and add formatting. */
$content = trim( do_shortcode( shortcode_unautop( $content ) ) );
/* Remove '' from the start of the string. */
if ( substr( $content, 0, 4 ) == '' )
$content = substr( $content, 4 );
/* Remove '' from the end of the string. */
if ( substr( $content, -3, 3 ) == '' )
$content = substr( $content, 0, -3 );
/* Remove any instances of ''. */
$content = str_replace( array( '<p></p>' ), '', $content );
$content = str_replace( array( '<p> </p>' ), '', $content );
return $content;
}
function HexToRGB($hex)
{
$hex = str_replace("#", "", $hex);
$color = array();
if(strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
}
else if(strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}
/*
* Resize images dynamically using wp built in functions
* Victor Teixeira
*
* php 5.2+
*
* Exemplo de uso:
*
* <?php
* $thumb = get_post_thumbnail_id();
* $image = vt_resize( $thumb, '', 140, 110, true );
* ?>
* <img src="<?php echo $image[url]; ?>" width="<?php echo $image[width]; ?>" height="<?php echo $image[height]; ?>" />
*
* @param int $attach_id
* @param string $img_url
* @param int $width
* @param int $height
* @param bool $crop
* @return array
*/
if ( !function_exists( 'vt_resize') ) {
function vt_resize( $attach_id = null, $img_url = null, $width, $height, $crop = false ) {
// this is an attachment, so we have the ID
if ( $attach_id ) {
$image_src = wp_get_attachment_image_src( $attach_id, 'full' );
$file_path = get_attached_file( $attach_id );
// this is not an attachment, let's use the image url
} else if ( $img_url ) {
$file_path = parse_url( $img_url );
$file_path = $_SERVER['DOCUMENT_ROOT'] . $file_path['path'];
// Look for Multisite Path
if(file_exists($file_path) === false){
global $blog_id;
$file_path = parse_url( $img_url );
if (preg_match("/files/", $file_path['path'])) {
$path = explode('/',$file_path['path']);
foreach($path as $k=>$v){
if($v == 'files'){
$path[$k-1] = 'wp-content/blogs.dir/'.$blog_id;
}
}
$path = implode('/',$path);
}
$file_path = $_SERVER['DOCUMENT_ROOT'].$path;
}
//$file_path = ltrim( $file_path['path'], '/' );
//$file_path = rtrim( ABSPATH, '/' ).$file_path['path'];
$orig_size = getimagesize( $file_path );
$image_src[0] = $img_url;
$image_src[1] = $orig_size[0];
$image_src[2] = $orig_size[1];
}
$file_info = pathinfo( $file_path );
// check if file exists
$base_file = $file_info['dirname'].'/'.$file_info['filename'].'.'.$file_info['extension'];
if ( !file_exists($base_file) )
return;
$extension = '.'. $file_info['extension'];
// the image path without the extension
$no_ext_path = $file_info['dirname'].'/'.$file_info['filename'];
$cropped_img_path = $no_ext_path.'-'.$width.'x'.$height.$extension;
// checking if the file size is larger than the target size
// if it is smaller or the same size, stop right here and return
if ( $image_src[1] > $width ) {
// the file is larger, check if the resized version already exists (for $crop = true but will also work for $crop = false if the sizes match)
if ( file_exists( $cropped_img_path ) ) {
$cropped_img_url = str_replace( basename( $image_src[0] ), basename( $cropped_img_path ), $image_src[0] );
$vt_image = array (
'url' => $cropped_img_url,
'width' => $width,
'height' => $height
);
return $vt_image;
}
// $crop = false or no height set
if ( $crop == false OR !$height ) {
// calculate the size proportionaly
$proportional_size = wp_constrain_dimensions( $image_src[1], $image_src[2], $width, $height );
$resized_img_path = $no_ext_path.'-'.$proportional_size[0].'x'.$proportional_size[1].$extension;
// checking if the file already exists
if ( file_exists( $resized_img_path ) ) {
$resized_img_url = str_replace( basename( $image_src[0] ), basename( $resized_img_path ), $image_src[0] );
$vt_image = array (
'url' => $resized_img_url,
'width' => $proportional_size[0],
'height' => $proportional_size[1]
);
return $vt_image;
}
}
// check if image width is smaller than set width
$img_size = getimagesize( $file_path );
if ( $img_size[0] <= $width ) $width = $img_size[0];
// Check if GD Library installed
if (!function_exists ('imagecreatetruecolor')) {
echo 'GD Library Error: imagecreatetruecolor does not exist - please contact your webhost and ask them to install the GD library';
return;
}
// no cache files - let's finally resize it
$new_img_path = wp_get_image_editor( $file_path, $width, $height, $crop );
$new_img_size = getimagesize( $new_img_path );
$new_img = str_replace( basename( $image_src[0] ), basename( $new_img_path ), $image_src[0] );
// resized output
$vt_image = array (
'url' => $new_img,
'width' => $new_img_size[0],
'height' => $new_img_size[1]
);
return $vt_image;
}
// default output - without resizing
$vt_image = array (
'url' => $image_src[0],
'width' => $width,
'height' => $height
);
return $vt_image;
}
}
function pp_detect_ie()
{
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;
else
return false;
}
function getBrowser()
{
$u_agent = $_SERVER['HTTP_USER_AGENT'];
$bname = 'Unknown';
$platform = 'Unknown';
$version= "";
//First get the platform?
if (preg_match('/linux/i', $u_agent)) {
$platform = 'linux';
}
elseif (preg_match('/macintosh|mac os x/i', $u_agent)) {
$platform = 'mac';
}
elseif (preg_match('/windows|win32/i', $u_agent)) {
$platform = 'windows';
}
// Next get the name of the useragent yes seperately and for good reason
if(preg_match('/MSIE/i',$u_agent) && !preg_match('/Opera/i',$u_agent))
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
elseif(preg_match('/Firefox/i',$u_agent))
{
$bname = 'Mozilla Firefox';
$ub = "Firefox";
}
elseif(preg_match('/Chrome/i',$u_agent))
{
$bname = 'Google Chrome';
$ub = "Chrome";
}
elseif(preg_match('/Safari/i',$u_agent))
{
$bname = 'Apple Safari';
$ub = "Safari";
}
elseif(preg_match('/Opera/i',$u_agent))
{
$bname = 'Opera';
$ub = "Opera";
}
elseif(preg_match('/Netscape/i',$u_agent))
{
$bname = 'Netscape';
$ub = "Netscape";
}
else
{
$bname = 'Internet Explorer';
$ub = "MSIE";
}
// finally get the correct version number
$known = array('Version', $ub, 'other');
$pattern = '#(?<browser>' . join('|', $known) .
')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
// see how many we have
$i = count($matches['browser']);
if ($i != 1) {
if (strripos($u_agent,"Version") < strripos($u_agent,$ub)){
$version= $matches['version'][0];
}
elseif(isset($matches['version'][1])) {
$version= $matches['version'][1];
}
else
{
$version = 11;
}
}
else {
$version= $matches['version'][0];
}
// check if we have a number
if ($version==null || $version=="") {$version="?";}
return array(
'userAgent' => $u_agent,
'name' => $bname,
'version' => $version,
'platform' => $platform,
'pattern' => $pattern
);
}
function auto_link_twitter ($text)
{
// properly formatted URLs
$urls = "/(((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";
$text = preg_replace($urls, " <a href='$1'>$1</a>", $text);
// URLs without protocols
$text = preg_replace("/href=\"www/", "href=\"http://www", $text);
// Twitter usernames
$twitter = "/@([A-Za-z0-9_]+)/is";
$text = preg_replace ($twitter, " <a href='http://twitter.com/$1'>@$1</a>", $text);
// Twitter hashtags
$hashtag = "/#([A-Aa-z0-9_-]+)/is";
$text = preg_replace ($hashtag, " <a href='http://hashtags.org/$1'>#$1</a>", $text);
return $text;
}
function pp_resort_gallery_img($all_photo_arr)
{
$sorted_all_photo_arr = array();
$pp_gallery_sort = get_option('pp_gallery_sort');
if(!empty($pp_gallery_sort) && !empty($all_photo_arr))
{
switch($pp_gallery_sort)
{
case 'drag':
default:
foreach($all_photo_arr as $key => $gallery_img)
{
$sorted_all_photo_arr[$key] = $gallery_img;
}
break;
case 'post_date':
foreach($all_photo_arr as $key => $gallery_img)
{
$gallery_img_meta = get_post($gallery_img);
$gallery_img_date = strtotime($gallery_img_meta->post_date);
$sorted_all_photo_arr[$gallery_img_date] = $gallery_img;
krsort($sorted_all_photo_arr);
}
break;
case 'post_date_old':
foreach($all_photo_arr as $key => $gallery_img)
{
$gallery_img_meta = get_post($gallery_img);
$gallery_img_date = strtotime($gallery_img_meta->post_date);
$sorted_all_photo_arr[$gallery_img_date] = $gallery_img;
ksort($sorted_all_photo_arr);
}
break;
case 'rand':
shuffle($all_photo_arr);
$sorted_all_photo_arr = $all_photo_arr;
break;
case 'title':
foreach($all_photo_arr as $key => $gallery_img)
{
$gallery_img_meta = get_post($gallery_img);
$gallery_img_title = $gallery_img_meta->post_title;
if(empty($gallery_img_title) OR is_null($gallery_img_title))
{
$gallery_img_title = $gallery_img_meta->ID;
}
if(!isset($sorted_all_photo_arr[$gallery_img_title]))
{
$sorted_all_photo_arr[$gallery_img_title] = $gallery_img;
}
else
{
$sorted_all_photo_arr[$gallery_img_title.$gallery_img_meta->ID] = $gallery_img;
}
ksort($sorted_all_photo_arr);
}
break;
}
return $sorted_all_photo_arr;
}
else
{
return $all_photo_arr;
}
}
function pp_get_the_excerpt($id=false)
{
global $post;
$old_post = $post;
if ($id != $post->ID) {
$post = get_page($id);
}
if (!$excerpt = trim($post->post_excerpt)) {
$excerpt = $post->post_content;
$excerpt = strip_shortcodes( $excerpt );
$excerpt = apply_filters('the_content', $excerpt);
$excerpt = str_replace(']]>', ']]>', $excerpt);
$excerpt = strip_tags($excerpt);
$excerpt_length = apply_filters('excerpt_length', 55);
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
$words = preg_split("/[\n\r\t ]+/", $excerpt, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
if ( count($words) > $excerpt_length ) {
array_pop($words);
$excerpt = implode(' ', $words);
$excerpt = $excerpt . $excerpt_more;
} else {
$excerpt = implode(' ', $words);
}
}
$post = $old_post;
return $excerpt;
}
function pp_get_image_id($image_url) {
global $wpdb;
$prefix = $wpdb->prefix;
$attachment = $wpdb->get_col($wpdb->prepare("SELECT ID FROM " . $prefix . "posts" . " WHERE guid='%s';", $image_url ));
if(isset($attachment[0]))
{
return $attachment[0];
}
else
{
return '';
}
}
function tg_apply_content($pp_content) {
$pp_content = apply_filters('the_content', $pp_content);
$pp_content = str_replace(']]>', ']]>', $pp_content);
return $pp_content;
}
function tg_apply_builder($page_id, $post_type = 'page', $print = TRUE)
{
$ppb_form_data_order = get_post_meta($page_id, 'ppb_form_data_order');
$ppb_page_content = '';
if(isset($ppb_form_data_order[0]))
{
$ppb_form_item_arr = explode(',', $ppb_form_data_order[0]);
}
$ppb_shortcodes = array();
if($post_type=='page')
{
require_once (get_template_directory() . "/lib/contentbuilder.shortcode.lib.php");
}
//pp_debug($ppb_shortcodes);
if(isset($ppb_form_item_arr[0]) && !empty($ppb_form_item_arr[0]))
{
$ppb_shortcode_code = '';
foreach($ppb_form_item_arr as $key => $ppb_form_item)
{
$ppb_form_item_data = get_post_meta($page_id, $ppb_form_item.'_data');
$ppb_form_item_size = get_post_meta($page_id, $ppb_form_item.'_size');
$ppb_form_item_data_obj = json_decode($ppb_form_item_data[0]);
//pp_debug(rawurldecode($ppb_form_item_data_obj->ppb_text_content));
$ppb_shortcode_content_name = $ppb_form_item_data_obj->shortcode.'_content';
if(isset($ppb_form_item_data_obj->$ppb_shortcode_content_name))
{
$ppb_shortcode_code = '['.$ppb_form_item_data_obj->shortcode.' size="'.$ppb_form_item_size[0].'" ';
//Get shortcode title
$ppb_shortcode_title_name = $ppb_form_item_data_obj->shortcode.'_title';
if(isset($ppb_form_item_data_obj->$ppb_shortcode_title_name))
{
$ppb_shortcode_code.= 'title="'.esc_attr(rawurldecode($ppb_form_item_data_obj->$ppb_shortcode_title_name), ENT_QUOTES, "UTF-8").'" ';
}
//Get shortcode attributes
if(isset($ppb_shortcodes[$ppb_form_item_data_obj->shortcode]))
{
$ppb_shortcode_arr = $ppb_shortcodes[$ppb_form_item_data_obj->shortcode];
foreach($ppb_shortcode_arr['attr'] as $attr_name => $attr_item)
{
$ppb_shortcode_attr_name = $ppb_form_item_data_obj->shortcode.'_'.$attr_name;
if(isset($ppb_form_item_data_obj->$ppb_shortcode_attr_name))
{
$ppb_shortcode_code.= $attr_name.'="'.esc_attr(rawurldecode($ppb_form_item_data_obj->$ppb_shortcode_attr_name)).'" ';
}
}
}
$ppb_shortcode_code.= ']'.rawurldecode($ppb_form_item_data_obj->$ppb_shortcode_content_name).'[/'.$ppb_form_item_data_obj->shortcode.']';
}
else if(isset($ppb_shortcodes[$ppb_form_item_data_obj->shortcode]))
{
$ppb_shortcode_code = '['.$ppb_form_item_data_obj->shortcode.' size="'.$ppb_form_item_size[0].'" ';
//Get shortcode title
$ppb_shortcode_title_name = $ppb_form_item_data_obj->shortcode.'_title';
if(isset($ppb_form_item_data_obj->$ppb_shortcode_title_name))
{
$ppb_shortcode_code.= 'title="'.esc_attr(rawurldecode($ppb_form_item_data_obj->$ppb_shortcode_title_name), ENT_QUOTES, "UTF-8").'" ';
}
//Get shortcode attributes
if(isset($ppb_shortcodes[$ppb_form_item_data_obj->shortcode]))
{
$ppb_shortcode_arr = $ppb_shortcodes[$ppb_form_item_data_obj->shortcode];
foreach($ppb_shortcode_arr['attr'] as $attr_name => $attr_item)
{
$ppb_shortcode_attr_name = $ppb_form_item_data_obj->shortcode.'_'.$attr_name;
if(isset($ppb_form_item_data_obj->$ppb_shortcode_attr_name))
{
$ppb_shortcode_code.= $attr_name.'="'.esc_attr(rawurldecode($ppb_form_item_data_obj->$ppb_shortcode_attr_name)).'" ';
}
}
}
$ppb_shortcode_code.= ']';
}
//pp_debug($ppb_shortcode_code);
if($print)
{
echo tg_apply_content($ppb_shortcode_code);
}
else
{
$ppb_page_content.= tg_apply_content($ppb_shortcode_code);
}
}
}
if(!$print)
{
return $ppb_page_content;
}
}
function vega_set_map_api()
{
//Get Google Map API Key
$pp_googlemap_api_key = get_option('pp_googlemap_api_key');
if(empty($pp_googlemap_api_key))
{
wp_enqueue_script("google_maps", "https://maps.googleapis.com/maps/api/js", false, THEMEVERSION, true);
}
else
{
wp_enqueue_script("google_maps", "https://maps.googleapis.com/maps/api/js?key=".$pp_googlemap_api_key, false, THEMEVERSION, true);
}
}
?> |