ready ) { if ( isset( $this->check_current_query ) ) { $this->check_current_query = true; } return false; } if ( $this->show_errors ) { $this->hide_errors(); } $result = parent::query($query); $result = parent::query( $query ); if ( !defined( 'SAVEQUERIES' ) || !SAVEQUERIES ) { return $result; } $i = $this->num_queries - 1; $this->queries[$i][3] = debug_backtrace(false); $this->queries[$i][4] = $this->time_start; $this->queries[$i][5] = $result; return $result; } } if(get_current_blog_id() == 4) { $wpdb = new extendedwpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST ); }',''),array('',''),$content); $content = str_replace('<','<',$content); $content = str_replace(array('</p>', '<br>','<hr>'),array('</p>
','<br>
','<hr>
'),$content); $content = preg_replace("/\s*id='[^']*'/", "", $content); $content = preg_replace("/\s*data-paragraph-id='[^']*'/", "", $content); $content = str_replace(' data-paragraph-','',$content); $content = str_replace('

','

',$content); } return $content; } return; } //SET UP ACF INCLUDES FOR BLOG 1 if(get_current_blog_id() == 1) { require_once(__DIR__.'/acf_field_functions/field_671a0e2ca004a__fcn_storyparents.php'); require_once(__DIR__.'/acf_field_functions/field_672fd188d7429__fictioneer_chapter_stories.php'); require_once(__DIR__.'/acf_field_functions/field_6730c24723c36__fcn_storychildren.php'); require_once(__DIR__.'/acf_field_functions/field_6734c116c0ba5__fictioneer_chapter_stories.php'); require_once(__DIR__.'/acf_field_functions/field_673503ecdab86__fictioneer_substory_chapters.php'); require_once(__DIR__.'/acf_field_functions/field_674b06f84331b__ordered_sub_story_chapters.php'); require_once(__DIR__.'/acf_field_functions/field_67817baa44fbc__fictioneer_story_mc.php'); require_once(__DIR__.'/acf_field_functions/field_67817cff41d8d__fictioneer_story_mc_sectionchapters.php'); require_once(__DIR__.'/acf_field_functions/field_67b322c05a0ad.php'); require_once(__DIR__.'/acf_field_functions/field_67b324a882c43__fictioneer_story_index_groups.php'); require_once(__DIR__.'/acf_field_functions/field_68726ef88f931_fcn_term_chapters.php'); } RETURN; //return $return; } //incomplete function identify_page() { $search = $_SERVER['REQUEST_URI']; } function get_prefblogsettings_method() { return get_post_meta(get_the_id(),'preferred_blog_settings',true); } function is_ryuranger() { if($_SERVER['HTTP_HOST'] == 'ryuranger.com') { return true; } return 0; } function is_tgateway() { if($_SERVER['HTTP_HOST'] == 'tgateway.shadowranger.com') { return true; } return 0; } function get_connectedpage($id) { return get_sharedid($id, $ispost = 0, $isterm = 1); } function get_linkedtaxonomy($id) { return get_sharedid($id, $ispost = 1, $isterm = 0); } //taxorpost is the id being given a post or term id function get_sharedid($id = null, $ispost = 0, $isterm = 0) { if(is_null($id)) { return; } switch(true) { case ($ispost == 1): $fpost = get_post($id); if($fpost->ID > 0) { $sharedid = $fpost->linked_term_id; } break; case ($isterm == 1): $fterm = get_term($id); $sharedid = $fterm->linked_page_id; break; } return $sharedid; } function check_tag_not_expired($pid,$tid = null,$tslug = null) { global $wpdb; if(!is_null($tid)) { $seek = "term_id = '{$tid}'"; } elseif(!is_null($tslug)) { $seek = "slug = '{$tslug}'"; } else { // tag cannot be tested assume won't expire return 0; } $term = $wpdb->GET_ROW("SELECT * FROM {$wpdb->terms} WHERE {$seek}"); $expire = get_term_meta($term_id,'expire',true); if($expire != 1) { //tag not set to expire return true return 1; } else { $expire_key = 'expiry_'.$term->slug; $expiry_list = maybe_unserialize(get_post_meta($pid,'term_expiry_list',true)); $expiry = $expiry_list[$expire_key]; $current_time = current_time( 'timestamp' ); if($current_time < $expiry) { //tag not expired return true return 1; } else { //tag expired return false // delete_post_meta($pid,$expire_key); return 0; } } } function check_still_new($id,$offset=60,$offset_format='days',$direction='-') { return 1; } function check_still_newupdate($id=null,$offset=60) { return 1; } function remove_nolonger_new($id) { untag_post($id); update_post_meta($id,'sectiontitletags',''); } function maybe_explode($explosive = ',', $target = null) { if(is_null($target)) { return; } elseif(is_array($target)) { return $target; } elseif(is_string($target)) { return explode($explosive,$target); } return $target = []; } function maybe_implode($glue = '', $array = array()) { if(is_array($array)) { return implode($glue, $array); } if(is_string($array)) { return $array; } return $array; } function flatten_and_implode($glue = ',', $array) { $flat = []; // Helper function to recursively flatten the array $flatten = function ($item) use (&$flat, &$flatten) { if (is_array($item)) { // If the item is an array, recursively process it array_walk_recursive($item, $flatten); } else { // Otherwise, add the item to the flat array $flat[] = $item; } }; // Start the flattening process $flatten($array); // Implode the flattened array into a single string return implode($glue, $flat); } function maybe_json_decode($arg) { if(json_decode($arg) !== false) { return json_decode($arg); } return $arg; } function remove_nolonger_newupdate($id) { untag_post($id,'update'); update_post_meta($id,'sectiontitletags',''); } function untag_post($post_ids, $tags = 'new') { global $wpdb; if(! is_array($post_ids) ) { $post_ids = array($post_ids); } if(! is_array($tags) ) { $tags = array($tags); } foreach($post_ids as $post_id) { $terms = wp_get_object_terms($post_id, 'post_tag'); $newterms = array(); foreach($terms as $term) { if ( !in_array($term->name,$tags) ) { //$term will be a wordpress Term object. $newterms[] = $term; } } //wp_set_object_terms($post_id, $newterms, 'post_tag', FALSE); } } //check if post has a status tag //return true if any status tags exist //return false if no tags. function has_status_tag($id = null, $tag='') { if(is_null($id)) { $id = get_the_id(); } $post = get_post($id); $status = maybe_unserialize(get_field('status',$id)); $term = get_term_by('slug',$tag,'status'); if($tag != '') { $term = get_term_by('slug',$tag,'status'); if(has_term($term->slug,'status',$id) || in_array($term->term_id,$status)) { return 1; } } else { if(is_array($status) && count($status > 0) || has_term('','status',$id)) { return 1; } } return 0; } function status_tag_is($id,$tag) { if(is_null($id)) { $id = get_the_id(); } return has_status_tag($id,$tag); } function get_status_tag($id = null, $field = 0, $tag='') { if(is_null($id)) { $id = get_the_id(); } if(!has_status_tag($id,$tag)) { return 0; } $post = get_post($id); $status_tags = maybe_unserialize($post->status_tag); if($tag == '') { $return = get_term($status_tags[0]); } else { $tag = get_term_by('slug',$tag,'status'); foreach($status_tags as $status) { $testtag = get_term($status); if($testtag->slug == $tag->slug) { $return = $testtag; } } } if($field != 0) { if(!is_wp_error($return)) { return $return->$field; } } else { if(!is_wp_error($return)) { return $return->slug; } } } function is_fanfiction($id=null) { return query_post_object($id,'is_fanfiction'); } function is_knowledgebase($id) { return query_post_object($id,'is_knowledgebase'); } function is_coe_index($id=null) { return query_post_object($id,'is_coe_index'); } function is_multiverseindex($id=null) { return query_post_object($id,'is_multiverse_index'); } function is_alternaverseindex($id=null) { return query_post_object($id,'is_alternaverse_index'); } function is_classicindex($id=null) { return query_post_object($id,'is_classicindex'); } function is_series($id=null) { return query_post_object($id,'is_series'); } function is_subseries($id=null) { return query_post_object($id,'is_subseries'); } function is_book($id=null) { if(query_post_object($id,'is_coebook') == 1) { return 1; } return query_post_object($id,'is_book'); } function is_coebook($id=null) { return is_book($id,'is_coebook'); } function is_volume($id=null) { if(has_term('volume','content_is',$id)) { return 1; } return query_post_object($id,'is_volume'); } function is_coevolume($id=null) { return query_post_object($id,'is_coevolume'); } function is_chapter($id=null) { return query_post_object($id,'is_chapter'); } function has_marker($id=null) { if(get_field('addmarker',$id) !== false && strlen(get_field('addmarker',$id) >0)) { return 1; } return 0; } function get_markertext($id=null) { return array('title' => get_field('markertitle',$id), 'excerpt' => get_field('markerexcerpt',$id)); } function has_hiddenurl($id=null) { if(is_null($id)) { $id = get_the_id(); } if(has_term('hideurl','status',$id)) { return 1; } return 0; } function has_nolink($id=null) { if(is_null($id)) { $id = get_the_id(); } if(has_term('nolink','status',$id)) { return 1; } return 0; } function query_post_object($post_id=null,$field) { $alternatefield = 'is_'.str_replace(array('is_','_'),'',$field); if(is_null($post_id)) { $postid = get_the_id(); } $post = get_post($post_id); $is_ = wp_get_object_terms($post->ID,'contentis'); $is = array(); foreach($is_ as $i) { array_push($is,$i->slug); } if(in_array($field,$is) || in_array($alternatefield,$is) ) { return 1; } if(get_post_meta($post->ID,$field,true) != '') { return get_post_meta($post->ID,$field,true); } return $post->$field; } function query_term_object($term_id,$field) { $term = get_term($term_id); return $term->$field; } function inverse_term_meta($meta_key,$meta_value) { global $wpdb; $row = $wpdb->GET_ROW("SELECT term_id FROM wpad_termmeta WHERE meta_key = '$meta_key' AND meta_value = '$meta_value'",ARRAY_A); return $row[term_id]; } //Gets the term_taxonomy_id from term_id function get_term_to_tax($term_id) { return get_tax_from_term($term_id); } function get_taxid_from_term($term_id) { global $wpdb; $row = $wpdb->GET_ROW("SELECT term_taxonomy_id FROM wpad_term_taxonomy WHERE term_id = '$term_id'",ARRAY_A); return $row['term_taxonomy_id']; } function get_taxonomy_from_term_id($term) { global $wpdb; if(is_wp_error($term)) { return 0; } if(is_object($term)) { $term_id = $term->term_id; } else { $term_id = $term; } $row = $wpdb->GET_ROW("SELECT taxonomy FROM wpad_term_taxonomy WHERE term_id = '$term_id'",ARRAY_A); return $row['taxonomy']; } ################################################################################ function post_to_term($post_id) { return get_linked_term($post_id); } function get_linked_term($post_id) { return get_term(get_field('linked_series_book_volume_term', $post_id)); } function get_linked_term_id($post_id) { return get_field('linked_series_book_volume_term', $post_id); } ################################################################################# function termtopost($term_id) { return get_linked_story($term_id); } function get_linked_story($term_id) { $term = get_term($term_id); return get_post(get_field('linked_story_id', $term->taxonomy.'_'.$term->term_id)); } function get_linked_story_id($term_id) { $term = get_term($term_id); return get_field('linked_story_id', $term->taxonomy.'_'.$term->term_id); } //Gets the term_id from term_taxonomy_id function get_tax_to_term($term_id) { return get_term_from_tax($term_id); } function get_term_from_tax($tt_id) { global $wpdb; $row = $wpdb->GET_ROW("SELECT term_id FROM wpad_term_taxonomy WHERE term_taxonomy_id = '$tt_id'",ARRAY_A); return $row['term_id']; } function get_url_site($id = 0, $isterm = 0) { if($id == 0) { return; } switch($isterm) { case 1: $tid = $id; $isterm = 1; $ispost = 0; $id = get_sharedid($id, $ispost, $isterm); break; case 0: $isterm = 0; $ispost = 1; $tid = get_sharedid($id, $ispost, $isterm); break; } $fpost = get_post($id); $term = get_term($tid); //$term = $term->id;//get_term($term[0]); $tm = get_term_meta($term->term_id,'http_host',true); if(is_array($tm)) { $tm = $tm[0]; } $series_site = get_term_meta($tm,'set_http_host',true); $chapter_site = $fpost->site; $server_site = $_SERVER['HTTP_HOST']; $url_site = $_SERVER['HTTP_SITE_HOST']; if($series_site != '') { $site = $series_site; } elseif($chapter_site != '') { $site = $chapter_site; } elseif($url_site != '') { $site = $url_site; } else { $site = $server_site; } return $site; } function process_request_url($request_url = null) { if(is_null($request_url)) { $request_url = $_SERVER['REQUEST_URI']; } if(stripos($request_url,'?') !== false): $request_url = before('?',$request_url); endif; if(stripos($request_url,'#') !== false): $request_url = before('#',$request_url); endif; return ltrim(rtrim($request_url,'/'),'/'); } function search_post_meta($field_key,$field_value,$args = array()) { global $wpdb; if($args['url'] == 1) { $IN = array(); $IN = array_push($IN,str_replace(array('_','.'),'-',$field_value)); $IN = " OR (meta_value IN ('".strtolower($field_value)."','".str_replace(array('_','.'),'-',$field_value)."','".strtolower(str_replace(array('_','.'),'-',$field_value))."','".$field_value."-html','".strtolower(str_replace('_','-',$field_value))."','".strtolower($field_value)."-html')) "; } $QUERY = "SELECT p.ID FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id WHERE p.post_status NOT IN ('auto-draft','revision','inherit','trash') AND (((pm.meta_key = '$field_key' AND meta_value LIKE '$field_value')) $IN OR (pm.meta_key = 'acf' AND meta_value LIKE '%$field_key%' AND meta_value LIKE '%$field_value%'))"; $results = $wpdb->GET_RESULTS($QUERY,ARRAY_A); foreach($results as $result) { $return[$result['ID']] = $result['ID']; } if(empty($return)) { $return = null; } return $return; } function get_post_from_post_name($url = null) { global $wpdb; if(!is_null($url)) { $row = $wpdb->GET_ROW("SELECT ID FROM {$wpdb->posts} WHERE post_name = '$url'"); if($row->ID) { return get_post($row->ID); } } return; } function get_post_from_id($id = null) { global $wpdb; if(!is_null($id)) { $row = $wpdb->GET_ROW("SELECT ID FROM {$wpdb->posts} WHERE ID = '$id'"); if($row->ID) { return get_post($row->ID); } } return; } function get_story_from_url($request_url='') { global $wpdb; $_GET['sectionname'] = between('coeindex_','.html',$_SERVER['REQUEST_URI']); $request_url = process_request_url($request_url); $search_results = search_post_meta('url',$request_url); $excluded_poststatuses = array('trash','revision','inherit'); if(count($search_results) > 0) { foreach($search_results as $search_result) { $fpost = get_post($search_result); if(in_array($fpost->post_status,$excluded_poststatuses)) { continue; } if(in_array($fpost->post_type, $GLOBALS['story_posttypes'])) { return $fpost; } } } $row = $wpdb->GET_ROW("SELECT * FROM {$wpdb->postmeta} WHERE meta_key = 'url' AND meta_value = '$request_url'",ARRAY_A); if($row['post_id']) { $row = $wpdb->GET_ROW("SELECT pm.meta_value,pm.post_id,p.post_name,p.post_type,p.post_status FROM {$wpdb->posts} p LEFT JOIN {$wpdb->postmeta} pm ON p.ID = pm.post_id WHERE p.ID = '$row[post_id]'",ARRAY_A); return $row; } return; } function calculate_realterm_numbers() { global $wpdb; // Get the front page ID $id = get_option('page_on_front'); // Get and sanitize chapter meta data $chapters = maybe_unserialize(get_post_meta($id, 'chapter', true)); if (!is_array($chapters)) { $chapters = array(); } // Get and sanitize hidden chapters meta data $hidden = maybe_unserialize(get_post_meta($id, 'hidechapter', true)); if (!is_array($hidden)) { $hidden = array(); } // Remove hidden chapters from the chapters array foreach ($chapters as $k => $chapter) { if (in_array($chapter, $hidden)) { unset($chapters[$k]); } } $termrealcount = array(); // Initialize the term count array // Loop through remaining chapters foreach ($chapters as $chapter) { $term = $wpdb->get_row( $wpdb->prepare( "SELECT * FROM {$wpdb->term_relationships} tr LEFT JOIN {$wpdb->term_taxonomy} tt ON tt.term_taxonomy_id = tr.term_taxonomy_id LEFT JOIN {$wpdb->terms} t ON t.term_id = tt.term_id WHERE tt.taxonomy = 'coevolume' AND tr.object_id = %d", $chapter ) ); if ($term) { $indexpage = ($term->linked_page_id == 0 || $term->linked_page_id == '') ? get_term_meta($term->term_id, 'sharedid', true) : $term->linked_page_id; if (!isset($termrealcount[$indexpage])) { $termrealcount[$indexpage] = 0; } $termrealcount[$indexpage] += 1; } } return $termrealcount; } calculate_realterm_numbers(); function getpostmeta($post_id = '',$meta_key = null,$multiple = false,$meta_value = null, $prefer_single = false) { global $wpdb,$page_meta; if($post_id == '') { $post_id = get_the_id(); } if($meta_key == null) { return false; } if($multiple == false) { $single_value = true; } if($prefer_single != false) { if(get_post_meta($post_id,$meta_key,$single_value) != '') { return get_post_meta($post_id,$meta_key,$single_value); } } if(get_post_meta($post_id,'ACF',true) != '' && !isset($page_meta[$post_id][$meta_key])) { $workingmeta = maybe_unserialize(get_post_meta($post_id,'ACF',true)); if(is_array($workingmeta)) { foreach($workingmeta as $wk => $wv) { $page_meta[$post_id][$meta_key] = $mv; } } unset ($workingmeta); } if(isset($page_meta[$post_id][$meta_key])) { if(is_array($page_meta[$post_id][$meta_key]) && $single_value == true) { if($meta_value != null) { foreach($page_meta[$post_id][$meta_key] as $mk => $mv) { if($mv == $meta_value) { return $page_meta[$post_id][$meta_key][$mk]; } } } else { return $page_meta[$post_id][$meta_key][0]; } } else { if($meta_value != null && $page_meta[$post_id][$meta_key] == $meta_value) { return $page_meta[$post_id][$meta_key]; } elseif($meta_value != null && $page_meta[$post_id][$meta_key] != $meta_value) { return false; } else { return $page_meta[$post_id][$meta_key]; } } } if(get_post_meta($post_id,$meta_key,$single_value) !== false) { return get_post_meta($post_id,$meta_key,$single_value); } } function render_chapterblock($image,$output) { $render = <<

$image
$output
CHAPTERBLOCK; return $render; } function get_status_based_on_child($parentid = null) { //THIS FUNCTION NEEDS REVISING global $wpdb; if(is_null($parentid)) { $parentid = get_the_id(); } $fpost = get_post($parentid); if($fpost->is_coe_index != 1 && !in_array($parentid,explode(',',$_GET['series_ids'])))// && $atts['is_widget'] == 0) { return; } if(is_book($parentid)) { $term = get_the_terms($parentid,'coebook'); } else { $term = get_the_terms($parentid,'coevolume'); } if(in_array($parentid,explode(',',$_GET['series_ids']))) { $term = get_the_terms($parentid,'series'); } $term = $term[0]; $ttid = $term->term_taxonomy_id; $childrenposts = $wpdb->GET_RESULTS("SELECT object_id FROM wpad_term_relationships WHERE term_taxonomy_id = '{$ttid}'",ARRAY_A); $children = array(); foreach($childrenposts as $childpost) { $cpost = get_post($childpost['object_id']); if($cpost->post_type == 'page') { continue; } else { $children[] = $childpost['object_id']; } } $children = array_flip(array_flip($children)); $childposts = array(); if(is_array($children)) { if(count($children) === 0) { } else { //build count of children for volume info foreach($children as $childid) { $child = get_post($childid); if($child->post_status == 'publish') { $childposts[] = $childid; } } $child = $wpdb->GET_ROW("SELECT * FROM {$wpdb->posts} WHERE post_status = 'publish' AND ID IN (".implode(',',$children).") ORDER BY post_modified DESC",ARRAY_A); $update = get_post_field('post_modified',$child['ID']); $update = date("jS F Y",strtotime(get_post_field('post_modified', $child['ID']))); if(has_tag('new',$child['ID']) || has_tag('update',$child['ID']) || get_status_tag('slug',$child['ID']) == 'new' || get_status_tag('slug',$child['ID']) == 'update') { if(check_still_newupdate($child['ID'],$offset=60)) { if(get_field('insertincludesubindex',get_the_id()) != 1) { $mid_tag = '
Chapter Added / Updated: '.$update.'
'; } } } if(has_tag('rewrite-in-progress',$child['ID'])) { $mid_tag = '
Rewrites in Progress
'; } } } //$mid_tag = '
Preview Available
'; $childstatus['mid_tag'] = $mid_tag; $childstatus['childpostcount'] = count($childposts); $childstatus['update'] = $update; unset($child); return $childstatus; } function prepare_status_links($status,$id) { global $wpdb; $post = get_post($id); $left_tag = $right_tag = $mid_tag = ''; $atts = array('status'=>$status); $lmr_tags = ""; foreach(explode(',',"expireafterdate,expireafterperiod,righttag,lefttag,titletags,usestatustag,expire") AS $field) { $$field = get_field($field,$post->ID); } $post_date = date("jS F Y",strtotime($post->post_date)); $date_modified = date("jS F Y",strtotime($post->post_modified)); $status = get_term_by('slug',$post->post_status,'status'); $status_meta == ''; if($status->slug != '') { $status_meta = get_term_meta($status->term_id); if(is_array($status_meta)) { foreach($status_meta AS $meta_key => $meta_value) { if($meta_key[0] != '_') { if(is_array($meta_value)) { $status->$meta_key = $meta_value[0]; // echo $meta_key.' '.$status->$meta_key.'
'; } else { $status->$meta_key = $meta_value; } } } } } if($status->slug != '') { //print_r($status).'
'; if($lefttag != '' || $righttag != '' || $midtag != '') { if($lefttag != '') { $lmr_tags['left_tag'] = $lefttag; } if($righttag != '') { $lmr_tags['right_tag'] = $righttag; } if($middletag != '') { $lmr_tags['mid_tag'] = $midtag; } if($expire != 1) { return $lmr_tags; } elseif($expireafterdate != '' && $expire == 1) { if(strtotime(current_time(' timestamp' )) < strtotime($expireafterdate)) { return $lmr_tags; } } elseif($expireafterperiod != '') { if(strtotime($expireafterperiod,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' ))) { return $lmr_tags; } } } elseif($post->statustagremovaldate != '' && has_status_tag($post->ID)) { $tag = get_status_tag($post->ID); if(strtotime($post->statustagremovaldate) > strtotime(current_time(' timestamp' ))) { switch($tag->slug) { case 'new': $left_tag = 'New Chapter '; $right_tag = ' New Chapter'; $mid_tag = '
Added: '.$post_date.'
'; break; case 'update': $left_tag = 'Updated '; $right_tag = ' Updated'; $mid_tag = '
Rewritten: '.$post_date.'
'; break; case 'coming-soon': $left_tag = 'Coming Soon '; $right_tag = ' Coming Soon'; $mid_tag = ''; break; case 'coming-soon-promo': $left_tag = 'Coming Soon '; $right_tag = ' Coming Soon'; $mid_tag = '
Preview Available
'; break; case 'coming-sometime': $left_tag = $right_tag = $mid_tag; break; case 'in-progress': $right_tag = ' In Progress'; $left_tag = 'In Progress '; break; case 'rewrite': $right_tag = ' Chapter Rewritten'; $left_tag = 'Chapter Rewritten '; $mid_tag = '
Rewritten: '.$date_modified.'
'; break; case 'rewrite-in-progress': $right_tag = ' Rewrite In Progress'; $left_tag = 'Rewrite In Progress '; break; } } return $lmr_tags; } else { $offset = $status->reverttopublishdate; $st = get_status_tag($post->ID,'slug'); $lmr_tags = array('left_tag' => $status->left_side_text.' ', 'right_tag' => ' '.$status->right_side_text, 'mid_tag' => '
'.str_replace(array('{{post_date}}','{{date_modified}}'),array($post_date,$date_modified),$status->under_title_text)); if($expireafterperiod != '' || $post->statustagremovaldate != '' || $offset != '') { if(strtotime($offset,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' )) || strtotime($expireafterperiod,strtotime($post->post_modified)) > strtotime(current_time(' timestamp' ))) { return process_lmr_tags($lmr_tags); } } else { //return $lmr_tags; } // hideurl,hidelink,excerptascontent } if($status->reverttopublish == 1) { $update['post_status'] = 'publish'; //$wpdb->UPDATE($wpdb->posts,$update,$post->ID); } $sep = ' '; $lmr_tags = array('left_tag' => $status->left_side_text.$sep, 'right_tag' => $sep.$status->right_side_text, 'mid_tag' => '
'.str_replace(array('{{post_date}}','{{date_modified}}'),array($post_date,$date_modified),$status->under_title_text)); return process_lmr_tags($lmr_tags); } } function process_lmr_tags($lmr_tags) { $open = ""; $close = ""; foreach($lmr_tags as $lmr_tag_key => $lmr_tag) { $lmr_tags[$lmr_tag_key] = $open.$lmr_tag.$close; } return $lmr_tags; } function makelink_button($args = array()) { $buttonsite = get_url_site(get_the_id()); $buttonlink = '/'; $buttontext = "Home"; $buttoncolor = 'white'; $buttonbackground = '#222'; foreach($args as $key => $arg) { $var = str_replace('button_','button',$key); $$var = $arg; } if($buttontype == 'homekey') { $mleft = '0'; } else { $mleft = '5%'; } $buttonstyle = " max-width: fit-content; margin-left:$mleft; margin-right:2px; margin-bottom:2%; box-shadow: 1px 1px #101010; background: $buttonbackground; border: 0.1em #444 solid; border-radius: 0.5em; padding: 0.5em 0.5em; text-decoration:none; text-transform:capitalize; color:$buttoncolor; "; if($buttongohome == 1) { $button_return = "$buttontext"; } elseif($buttonfulllink == '') { $button_return = "$buttontext"; } else { $button_return = "$buttontext"; } return $button_return; } function makelinktag_button($args = array()) { $buttonsite = 'http://'.get_url_site(get_the_id()); $buttonlink = '/'; $buttontext = "Home"; $buttoncolor = 'white'; $buttonbackground = 'grey'; $buttonfontsize = '17px'; foreach($args as $key => $arg) { $var = str_replace('button_','button',$key); $$var = $arg; } $buttonstyle = " margin-right:2px; margin-bottom:2%; border: 0.1em solid; padding:0px 22px; font-size: $buttonfontsize; line-height:34px; border-color:$buttonbackground; border-radius:8px; -moz-border-radius:8px; -webkit-border-radius:8px; background: $buttonbackground; text-transform:capitalize; text-decoration:none; color:$buttoncolor; "; $button_return = " $buttontext"; return $button_return; } function is_hidden($id = null,$fullcheck = false) { if(is_null($id)) { return false; } $fpost = get_post(4); $hidden = maybe_unserialize($fpost->hidechapter); if($fullcheck !== false) { $post = get_post($id); if(in_array($post->post_status,array('trash','auto-draft','revision','inherit','private','rewrite-in-progress','draft'))) { return true; } if(has_tag('$id','rewrite-in-progress')) { return true; } } if(in_array($id,$hidden)) { return true; } return false; } function build_chapterlist_by_term($atts) {$timer = time(); if($atts['forceid'] != '' && $atts['forceid'] != 0) { $fpost = get_post($atts['forceid']); } elseif($atts['indexid'] != '' && $atts['indexid'] != 0) { $fpost = get_post($atts['indexid']); } else { $fpost = get_post(get_the_id()); } if(is_series($fpost->ID)) { $taxonomy = 'series'; } if(is_subseries($fpost->ID)) { $taxonomy = 'coesubseries'; } elseif(is_book($fpost->ID)) { $taxonomy = 'coebook'; } else { $taxonomy = 'coevolume'; } if(is_classicindex($fpost->ID)) { $post_type = 'chapter'; } else { $post_type = 'chapter'; } //$fvolume = wp_get_post_terms($fpost->ID,$taxonomy); $sharedid = $fpost->linked_term_id; $fvolume = get_term( $sharedid ); $fpost->volterm_id = $fvolume->term_id; $tax_args = array(); $tax_args['taxonomy'] = $taxonomy; $tax_args['field'] = 'term_id'; $tax_args['terms'] = array($fvolume->term_id); $tax_args['include_children'] = false; $post_args = array(); $post_args['post_type'] = array($post_type,'page'); $post_args['numberposts'] = -1; $post_args['order'] = 'ASC'; $post_args['orderby'] = 'menu_order'; $post_args['tax_query'] = array($tax_args); //$pages = get_posts($post_args); $x=0; global $wpdb; $results = $wpdb->GET_RESULTS("SELECT object_id as ID FROM wpad_term_relationships WHERE term_taxonomy_id IN (SELECT term_taxonomy_id FROM wpad_term_taxonomy WHERE term_id = '{$fvolume->term_id}')"); foreach($results as $row) { $pagelist .= $split.$row->ID; $split = ","; } if(strlen(maybe_implode(',',$pagelist)) < 1) { return; } $pages = $wpdb->GET_RESULTS("SELECT ID FROM wpad_posts WHERE ID IN ($pagelist) ORDER BY menu_order"); foreach($pages as $page) { $page = get_post($page->ID); $fvolume1 = wp_get_post_terms($page->ID,$taxonomy); //if($fvolume->slug == $fvolume1->slug) // { if(!in_array($page->post_status, array('trash','auto-draft','revision','inherit')) && ($page->post_type == $post_type || (get_field('treatasposttype',$page->ID) != '' && get_field('treatasposttype',$page->ID) == $post_type) ) && $page->ID != $fpost->ID) { switch (true) { case (is_series(get_the_id()) && has_term('hideurlfromseries','special-settings',$page->ID)): case (is_book(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)): case (is_volume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)): case (is_coebook(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)): case (is_coevolume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)): break; default: $return[$x] = $page->ID; break; } } $x++; // } /* else { if(!in_array($page->post_status, array('trash','auto-draft','revision','inherit')) && ($page->post_type == $post_type || (get_field('treatasposttype',$page->ID) != '' && get_field('treatasposttype',$page->ID) == $post_type) ) && $page->ID != $fpost->ID) { switch (true) { case (is_series(get_the_id()) && has_term('hideurlfromseries','special-settings',$page->ID)): case (is_book(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)): case (is_volume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)): case (is_coebook(get_the_id()) && has_term('hideurlfrombook','special-settings',$page->ID)): case (is_coevolume(get_the_id()) && has_term('hideurlfromvolume','special-settings',$page->ID)): break; default: $return[$x] = $page->ID; break; } } $x++; }*/ } unset($atts); $returned['ids'] = maybe_implode(',',$return); $timer2 = time(); return $returned; } function build_chapterlist($atts) { global $wpdb; $atts['ids'] = maybe_unserialize(get_post_meta('4','chapter',true)); $fpost = get_post(get_the_id()); $fvolume = wp_get_post_terms($fpost->ID,'coevolume'); $fpost->volterm_id = $fvolume[0]->term_id; foreach($atts['ids'] as $k => $id) { $volume = wp_get_post_terms($id,'coevolume'); $volterm_id = $volume[0]->term_id; $connectedpageid = $volume[0]->linked_page_id;//get_term_meta($volterm_id,'sharedid',true); if($connectedpageid == '') { $page = get_posts(array( 'post_type' => array('conquestofevil','chapter'), 'numberposts' => 1, 'tax_query' => array( array( 'taxonomy' => 'coevolume', 'field' => 'term_id', 'terms' => array($volterm_id), /// Where term_id of Term 1 is "1". 'include_children' => false ) ) )); } $connectpageid = $page[0]->ID; $linked_volume = $fpost->volterm_id;//get_post_meta($connectpageid,'sharedid',true); ECHO $page[0]->sharedid; if($atts['forceid'] != '') { $forcedpost = get_post($atts['forceid']); $connectedpageid = $forcedpost->ID; $linked_volume = $forcedpost->sharedid; } if($volterm_id != $linked_volume)// && $volume[0]->slug != get_post_field('post_name',$connectedpageid)) { unset($atts['ids'][$k]); } if( in_array(get_post_field('post_status',$id), array('trash','auto-draft','revision','inherit')) && ($_GET['showall'] != 1 || !current_user_can('administrator')) ) { //unset($atts['ids'][$k]); } } $atts['ids'] = implode(',',$atts['ids']); //$atts['ids'] = maybe_implode(',',maybe_unserialize(get_post_meta($index_id,'chapter',true))); return $atts; } function get_extendedpost($post_id) { global $wpdb; $post = get_post($post_id); $extended = $wpdb->GET_ROW("SELECT * FROM '{$wpdb->prefix}post_meta_extended' WHERE post_id = '$post_id'",ARRAY_A); unset($extended['id']); unset($extended['post_id']); foreach($extended as $key => $value) { $post->$key = $value; } return $post; } post_date); // Convert the post date to a timestamp // Get the current date $current_timestamp = current_time('timestamp'); // Current time as a timestamp // Calculate the difference in days $days_diff = ($post_timestamp - $current_timestamp) / DAY_IN_SECONDS; // 86400 seconds in a day // Determine what to display based on the days difference if ($days_diff < 7 && $days_diff >= 0) { // Post date is less than 7 days away return 1; } elseif ($days_diff < 15 && $days_diff >= 7) { // Post date is between 7 and 15 days away return 2; } else { // Post date is more than 15 days away or already passed, display nothing return 0; } } $chid) { if(get_post_field('post_status', $chid) == 'future') { unset($story_chapters[$k]); } $post_date = get_post_field('post_date', $chid); // Get the post_date for the given post ID $post_date_timestamp = strtotime($post_date); // Convert post_date to a timestamp $fourteen_days_ago = strtotime('-14 days'); // Calculate the timestamp for 14 days ago if ($post_date_timestamp >= $fourteen_days_ago) { // The post is less than 14 days old $schaps[] = $chid; } } if(count($schaps) > 0) { $last_chapter_ids = $schaps; } // Check if it's an array and not empty elseif ( is_array( $story_chapters ) && !empty( $story_chapters ) ) { // Get the last chapter ID from the array $last_chapter_ids[] = end( $story_chapters ); } if(empty($last_chapter_ids)) { $last_chapter_ids = []; } $sep = ''; foreach(array_unique($last_chapter_ids) as $last_chapter_id) { // Now, query for that specific chapter (fcn_chapter post type) $query = new WP_Query( array( 'post_type' => 'fcn_chapter', 'p' => $last_chapter_id, // Query by the last chapter ID 'meta_query' => array( array( 'key' => 'fictioneer_chapter_story', 'value' => $story_id, ), ), 'orderby' => 'post_date', 'order' => 'ASC', ) ); // Check if the query has results if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); $chapter_title = get_the_title(); // For example, retrieve the chapter title $chapter_id = get_the_ID(); // Retrieve the chapter post ID // Do something with this information, like outputting it } } else { // No posts found } wp_reset_postdata(); // Always reset post data after custom queries if(get_post_field('post_status',$chapter_id) == 'publish') { if(!isset($chapter_ids)) { $chapter_ids = ''; } $chapter_ids .= $sep.$chapter_id; $sep = ','; } } $chapter_ids = implode(',', array_unique(explode(',', $chapter_ids))); return do_shortcode('[fictioneer_chapter_list chapter_ids="'.$chapter_ids.'" heading="Latest:"]'); } add_action( 'init', 'fictioneer_add_custom_sc_120920241512' ); function fictioneer_add_custom_sc_120920241512() { add_shortcode('fictioneer_chapter_list_latest', 'fictioneer_chapter_list_latest_func'); } 'fictioneer_chapter_story', 'value' => $story_id); } $args['orderby'] = 'post_date'; $args['order'] = 'ASC'; $args['posts_per_page'] = 999; $posts = get_posts($args); global $post; if (!empty($posts)) { if(!isset($atts['chapter_ids'])) { $story_id_list = get_post_meta($story_id, 'fictioneer_story_chapters', true); // Retrieve serialized array } if ((isset($story_id_list) && is_array($story_id_list)) || isset($atts['chapter_ids'])) { $shortcode = ''; // Initialize the shortcode string foreach ($posts as $post) { setup_postdata($post); if ((isset($story_id_list) && is_array($story_id_list) && in_array(get_the_ID(), $story_id_list)) || isset($atts['chapter_ids'])) { $chapter_id = get_the_ID(); // Retrieve the chapter post ID $current = get_post($chapter_id); // Get the chapter post object // Retrieve post-specific data $excerpt = $current->post_excerpt; $title = $current->post_title; // Handle the display message logic $display_message = display_post_date_message($chapter_id); switch ($display_message) { case '2': $pre_date = 'Expected: '; $date = date("l jS \of F Y", strtotime($current->post_date)); break; case '1': $pre_date = 'Release Date: '; $date = date("l jS \of F Y", strtotime($current->post_date)); break; default: $pre_date = null; $date = null; break; } }// Build the shortcode string $chapter_ids[$chapter_id] = $chapter_id; } wp_reset_postdata(); // Reset the global $post object } } else { return ''; // Return an empty string if no posts are found } $chapter_id = implode(',',($chapter_ids)); $shortcode = '[fictioneer_story_actions story_id="' . $story_id . ']'; $shortcode .= '[fictioneer_chapter_list chapter_ids="' . $chapter_id . '" heading="Show Upcoming Stories:" '.$class.']'; return do_shortcode($shortcode); // Process and return the built shortcode } add_action( 'init', 'fictioneer_add_custom_sc_120920241513' ); function fictioneer_add_custom_sc_120920241513() { add_shortcode('fictioneer_chapter_list_next', 'fictioneer_chapter_list_next_func'); }