File: /home/httpd/html/stoptube.com/wp-content/themes/tubetheme-2017-v3-filled/functions.php
<?php
define('MY_WORDPRESS_FOLDER',$_SERVER['DOCUMENT_ROOT']);
define('MY_THEME_FOLDER',str_replace('\\','/',dirname(__FILE__)));
define('MY_THEME_PATH','/' . substr(MY_THEME_FOLDER,stripos(MY_THEME_FOLDER,'wp-content')));
add_action('admin_init','my_meta_init');
function my_meta_init()
{
// review the function reference for parameter details
// http://codex.wordpress.org/Function_Reference/wp_enqueue_script
// http://codex.wordpress.org/Function_Reference/wp_enqueue_style
//wp_enqueue_script('my_meta_js', MY_THEME_PATH . '/custom/meta.js', array('jquery'));
wp_enqueue_style('my_meta_css', MY_THEME_PATH . '/custom/meta.css');
// review the function reference for parameter details
// http://codex.wordpress.org/Function_Reference/add_meta_box
foreach (array('post','page') as $type)
{
add_meta_box('my_all_meta', 'Tube Theme v2 Custom Field', 'my_meta_setup', $type, 'normal', 'high');
}
add_action('save_post','my_meta_save');
}
function my_meta_setup()
{
global $post;
// using an underscore, prevents the meta variable
// from showing up in the custom fields section
$meta = get_post_meta($post->ID,'_my_meta',TRUE);
// instead of writing HTML here, lets do an include
include(MY_THEME_FOLDER . '/custom/meta.php');
// create a custom nonce for submit verification later
echo '<input type="hidden" name="my_meta_noncename" value="' . wp_create_nonce(__FILE__) . '" />';
}
function my_meta_save($post_id)
{
// authentication checks
// make sure data came from our meta box
if (!wp_verify_nonce($_POST['my_meta_noncename'],__FILE__)) return $post_id;
// check user permissions
if ($_POST['post_type'] == 'page')
{
if (!current_user_can('edit_page', $post_id)) return $post_id;
}
else
{
if (!current_user_can('edit_post', $post_id)) return $post_id;
}
// authentication passed, save data
// var types
// single: _my_meta[var]
// array: _my_meta[var][]
// grouped array: _my_meta[var_group][0][var_1], _my_meta[var_group][0][var_2]
$current_data = get_post_meta($post_id, '_my_meta', TRUE);
$new_data = $_POST['_my_meta'];
my_meta_clean($new_data);
if ($current_data)
{
if (is_null($new_data)) delete_post_meta($post_id,'_my_meta');
else update_post_meta($post_id,'_my_meta',$new_data);
}
elseif (!is_null($new_data))
{
add_post_meta($post_id,'_my_meta',$new_data,TRUE);
}
return $post_id;
}
function my_meta_clean(&$arr)
{
if (is_array($arr))
{
foreach ($arr as $i => $v)
{
if (is_array($arr[$i]))
{
my_meta_clean($arr[$i]);
if (!count($arr[$i]))
{
unset($arr[$i]);
}
}
else
{
if (trim($arr[$i]) == '')
{
unset($arr[$i]);
}
}
}
if (!count($arr))
{
$arr = NULL;
}
}
}
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Index Sidebar',
'before_widget' => '<div class="block">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'Post Sidebar',
'before_widget' => '<div class="block">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?>
<?php
if ( function_exists('register_sidebar') )
register_sidebar(array('name'=>'List Links',
'before_widget' => '<div id="listlinks">',
'after_widget' => '</div>',
'before_title' => '<h3>',
'after_title' => '</h3>',
));
?>
<?php
function my_get_avatar_filter($avatar_html) {
$exp1 = explode("src='", $avatar_html);
$exp2 = explode("'", $exp1[1]);
return $exp2[0];
}
?>
<?php
function tubetheme_add_theme_page() {
if ( $_GET['page'] == basename(__FILE__) ) {
if ( 'save' == $_REQUEST['action'] ) {
update_option( 'tubetheme_ImageColour', $_REQUEST[ 'set_ImageColour' ] );
header("Location: themes.php?page=functions.php&saved=true");
die;
} else if( 'reset' == $_REQUEST['action'] ) {
delete_option( 'tubetheme_ImageColour' );
header("Location: themes.php?page=functions.php&reset=true");
die;
}
}
add_theme_page("TubeTheme Theme Options", "TubeTheme Options", 'edit_themes', basename(__FILE__), 'tubetheme_theme_page');
}
function tubetheme_theme_page() {
if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>Settings saved.</strong></p></div>';
if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>Settings reset.</strong></p></div>';
?>
<div class="wrap">
<h1>TubeTheme v2.0</h1>
<p>TubeTheme version 2.0 was designed by <a href="http://www.tubetheme.com">Tube Ninja</a></p>
<h3>Available Theme Color:</h3>
<style>
ul.horizontal {padding-top: 5px; padding-bottom: 5px; width: 90%;}
.horizontal li {list-style: none; padding: 5px 0 5px 10px; margin: 10px; color: #FFFFFF; border: 1px solid #000000; font-weight: bold;}
li.white { background: url(<?php bloginfo('template_url'); ?>/images/bgwhite.gif); color: #000000;}
li.black { background: url(<?php bloginfo('template_url'); ?>/images/bgblack.gif);}
.center {text-align: center;}
</style>
<ul class="horizontal">
<li class="white">Clean White</li>
<li class="black">Hot Black</li>
</ul>
<h3>Image Colour Settings</h3>
<form method="post">
<p>Select colour from list:
<?php
$value = get_settings( 'tubetheme_ImageColour' );
echo "<select name=\"set_ImageColour\" style=\"width:200px;\" onchange=\"updateColour( this )\">";
tubetheme_input( "set_ImageColour", "option", "Clean White", "white", $value );
tubetheme_input( "set_ImageColour", "option", "Hot Black", "black", $value );
echo "</select>";
?>
</p>
<!-- Save Settings Button -->
<?php tubetheme_input( "save", "submit", "", "Save Settings" ); ?>
<input type="hidden" name="action" value="save" />
</form>
</div>
<?php
}
add_action('admin_menu', 'tubetheme_add_theme_page');
function tubetheme_input( $var, $type, $description = "", $value = "", $selected="" ) {
echo "\n";
switch( $type ){
case "submit":
echo "<p class=\"submit\"><input name=\"$var\" type=\"$type\" value=\"$value\" /></p>";
clear;
case "option":
if( $selected == $value ) { $extra = "selected=\"true\""; }
echo "<option value=\"$value\" $extra >$description</option>";
clear;
}
}
function tubetheme_nav($args = '') {
global $wp_query;
parse_str($args, $r);
if (!isset($r['current'])) $r['current'] = -1;
if (!isset($r['show_all_parents'])) $r['show_all_parents'] = 0;
if (!isset($r['show_root'])) $r['show_root'] = 0;
if (!isset($r['list_tag'])) $r['show_root'] = 1;
if($r['current'] == "")
return;
if($r['current'] == -1 && $wp_query->is_page == true) {
$r['current'] = $wp_query->post->ID;
}
if($r['current'] == -1 && $r['show_root'] != 0) {
$r['current'] = 0;
}
// Query pages.
$pages = get_pages($args);
if ( $pages ) {
// Now loop over all pages that were selected
$page_tree = Array();
$parent_page_id = null;
$parents= Array();
foreach($pages as $page) {
// set the title for the current page
$page_tree[$page->ID]['title'] = $page->post_title;
$page_tree[$page->ID]['parent'] = $page->post_parent;
// set the selected date for the current page
// depending on the query arguments this is either
// the createtion date or the modification date
// as a unix timestamp. It will also always be in the
// ts field.
if (! empty($r['show_date'])) {
if ('modified' == $r['show_date'])
$page_tree[$page->ID]['ts'] = $page->time_modified;
else
$page_tree[$page->ID]['ts'] = $page->time_created;
}
// The tricky bit!!
// Using the parent ID of the current page as the
// array index we set the curent page as a child of that page.
// We can now start looping over the $page_tree array
// with any ID which will output the page links from that ID downwards.
$page_tree[$page->post_parent]['children'][] = $page->ID;
if( $r['current'] == $page->ID) {
if($page->post_parent != 0 || $r['show_root'] == true)
$parents[] = $page->post_parent;
}
}
$len = count($parents);
for($i = 0; $i < $len ; $i++) {
$parent_page_id = $parents[$i];
$parent_page = $page_tree[$parent_page_id];
if(isset($parent_page['parent']) && !in_array($parent_page['parent'], $parents)) {
if($parent_page['parent'] != 0 || $r['show_root'] == true) {
$parents[] = $parent_page['parent'];
$len += 1;
if( $len >= 2 && $r['show_all_parents'] == 0) {
clear;
}
}
}
}
$parents = array_reverse($parents);
$level = 0;
$parent_out == false;
foreach( $parents as $parent_page_id ) {
$level += 1;
$css_class = 'level' . $level;
if( $r['list_tag'] == true || $parent_out == true)
echo "<ul class='". $css_class . "'>";
foreach( $page_tree[$parent_page_id]['children'] as $page_id) {
$cur_page = $page_tree[$page_id];
$title = $cur_page['title'];
$css_class = '';
if( $page_id == $r['current']) {
$css_class .= ' current';
}
if( $page_id == $page_tree[$r['current']]['parent']){
$css_class .= 'currentparent';
}
echo "<li class='" . $css_class . "' ><a href='" . get_page_link($page_id) . "' title='" . wp_specialchars($title) . "'>" . $title . "</a></li>\n";
}
echo "</ul>";
$parent_out = true;
}
if( is_array($page_tree[$r['current']]['children']) === true ) {
$level += 1;
$css_class = 'level' . $level;
if( $r['list_tag'] == true || $parent_out == true)
echo "<ul class='". $css_class . " children'>";
foreach( $page_tree[$r['current']]['children'] as $page_id) {
$cur_page = $page_tree[$page_id];
$title = $cur_page['title'];
echo "<li class='" . $css_class . "'><a href='" . get_page_link($page_id) . "' title='" . wp_specialchars($title) . "'>" . $title . "</a></li>\n";
}
echo "</ul>";
}
}
}
?>
<?php
function wp_corenavi() {
global $wp_query, $wp_rewrite;
$pages = '';
$max = $wp_query->max_num_pages;
if (!$current = get_query_var('paged')) $current = 1;
$a['base'] = str_replace(999999999, '%#%', get_pagenum_link(999999999));
$a['total'] = $max;
$a['current'] = $current;
$total = 1; //1 - display the text "Page N of N", 0 - not display
$a['mid_size'] = 5; //how many links to show on the left and right of the current
$a['end_size'] = 1; //how many links to show in the beginning and end
$a['prev_text'] = '« Previous'; //text of the "Previous page" link
$a['next_text'] = 'Next »'; //text of the "Next page" link
if ($max > 1) echo '<div class="navigation">';
if ($total == 1 && $max > 1) $pages = '<span class="pages">Page ' . $current . ' of ' . $max . '</span>'."\r\n";
echo $pages . paginate_links($a);
if ($max > 1) echo '</div>';
}
?>
<?php
function getPostViews($postID){
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
return "0 View";
}
return $count.' Views';
}
function setPostViews($postID) {
$count_key = 'post_views_count';
$count = get_post_meta($postID, $count_key, true);
if($count==''){
$count = 0;
delete_post_meta($postID, $count_key);
add_post_meta($postID, $count_key, '0');
}else{
$count++;
update_post_meta($postID, $count_key, $count);
}
}
// Remove issues with prefetching adding extra views
remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
?>