Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.87 KB | None | 0 0
  1.  
  2. /************************************************
  3. *                                               *
  4. *             OUTPUT THE TNG PAGE               *
  5. *                                               *
  6. * mbtng_use_tng_homepage                        *
  7. * mbtng_frontend_header                         *
  8. * mbtng_frontend_footer                         *
  9. * mbtng_fake_post                               *
  10. * mbtng_output_page                             *
  11. * mbtng_buffer_start                            *
  12. * mbtng_buffer_end                              *
  13. * mbtng_discard_output                          *
  14. * mbtng_eval_php                                *
  15. ************************************************/
  16.  
  17. function mbtng_use_tng_homepage() {
  18.     if (get_option('mbtng_use_wordpress_homepage')==TRUE && mbtng_requested_url() == get_option('mbtng_url'))
  19.         return false;
  20.     else
  21.         return true;
  22. }
  23.  
  24. //Adds TNG header to Wordpress header
  25. function mbtng_frontend_header() {
  26.     global $tng_head;
  27.     $tng_head = "<style type=\"text/css\">
  28.     #tng_main {line-height: 1.4em}
  29.     #tng_main tr td {padding: 2px 4px; margin:0; border-top: none}
  30.     </style>\r\n".$tng_head;
  31.     if (strpos(mbtng_filename(), 'admin') !== FALSE)
  32.         $tng_head .= '<base href = "'.get_permalink(get_option('mbtng_wordpress_page')).'"/>';
  33.     $tng_head .= "<style type=\"text/css\">#tng_main td.menuback, #tng_main td.spacercol, #tng_main table.page td.section td.fieldname {display:none}</style>";
  34.     if ($tng_head != '')
  35.         echo $tng_head;
  36. }
  37.  
  38. //Adds TNG footer to Wordpress footer
  39. function mbtng_frontend_footer() {
  40.     global $tng_footer;
  41.     if ($tng_footer != '')
  42.         echo $tng_footer;
  43. }
  44.  
  45. // Returns the TNG Wordpress post whenever a TNG page is requested
  46. function mbtng_fake_post($posts){
  47.     if (mbtng_display_page()){
  48.         $posts = get_pages('include='.get_option('mbtng_wordpress_page'));
  49.         add_filter('user_trailingslashit', 'mbtng_smart_trailingslashit');
  50.     }
  51.     return $posts;
  52. }
  53.  
  54. //Outputs the TNG code (outside the loop to minimise CSS conflicts)
  55. function mbtng_output_page() {
  56.     global $tng_output;
  57.     if (mbtng_display_page() && mbtng_use_tng_homepage()) {
  58.         echo $tng_output;
  59.         ob_start();
  60.     }
  61. }
  62.  
  63. // Buffers Wordpress and TNG code to allow for correct merging of HTML
  64. function mbtng_buffer_start() {
  65.     global $tng_output, $tng_head, $tng_footer;
  66.     $query = mbtng_requested('query');
  67.     if (mbtng_display_page()) {
  68.         $tng_folder = get_option('mbtng_path');
  69.         $filename = mbtng_filename();
  70.         if (mbtng_extension() == 'php') {
  71.             if ($filename == 'newacctform.php' && get_option('mbtng_integrate_logins')) {
  72.                 header("Location: ".trailingslashit(get_bloginfo('wpurl'))."wp-login.php?action=register");
  73.                 die();
  74.             }
  75.             if ($filename == 'login.php' && get_option('mbtng_integrate_logins')) {
  76.                 header("Location: ".trailingslashit(get_bloginfo('wpurl'))."wp-login.php");
  77.                 die();
  78.             }
  79.             if ($filename == 'logout.php' && get_option('mbtng_integrate_logins')) {
  80.                 if (function_exists('wp_logout_url'))
  81.                     header("Location: ".html_entity_decode(wp_logout_url()));
  82.                 else
  83.                     header("Location: ".trailingslashit(get_bloginfo('wpurl'))."wp-login.php?action=logout");
  84.                 die();
  85.             }
  86.             $tng_output = mbtng_eval_php($filename);
  87.             $non_template_files = array ('tngrss.php', 'addbookmark.php', 'fpdf.php', 'ufpdf.php');
  88.             if (in_array($filename, $non_template_files) || (isset($_REQUEST['tngprint']) && $_REQUEST['tngprint']==1) || stripos($filename, 'admin') !== FALSE || stripos($filename, 'ajx_') !== FALSE || stripos($filename, 'img_') !== FALSE || stripos($filename, 'find') !== FALSE || stripos($filename, 'rpt_') !== FALSE || stripos($tng_output, '<!-- The Next Generation of Genealogy Sitebuilding') === FALSE) {
  89.                 echo $tng_output;
  90.                 die();
  91.             } else {
  92.                 if ($filename == 'admin/index.php') {
  93.                     $tng_output = '<div id="tng_main">'.mbtng_display_tng_admin(false).'</div>';
  94.                 }
  95.                 else {
  96.                     $head_start = stripos ($tng_output, '<head>')+6;
  97.                     $head_end = stripos ($tng_output, '</head>');
  98.                     $tng_head = substr ($tng_output, $head_start, $head_end-$head_start);
  99.                     $tng_head = str_replace('.css?', '.css?frontend&', $tng_head);
  100.                     $tng_head = str_replace('.css" rel', '.css?frontend" rel', $tng_head);
  101.                     $footer_start = stripos ($tng_output, '</body>')+7;
  102.                     $footer_end = stripos ($tng_output, '</html>');
  103.                     $tng_footer = substr ($tng_output, $footer_start, $footer_end-$footer_start);
  104.                     $output_start = stripos($tng_output, '>', stripos ($tng_output, '<body'))+1;
  105.                     $output_end = $footer_start-8;
  106.                     $tng_output = '<div id="tng_main">'.substr ($tng_output, $output_start, $output_end-$output_start).'</div>';
  107.                 }
  108.                 ob_start('');
  109.             }
  110.         }
  111.     }
  112. }
  113.  
  114. //Flushes the output buffer
  115. function mbtng_buffer_end() {
  116.     @ob_end_flush();
  117. }
  118.  
  119. // Discards contents of page if TNG is displayed
  120. function mbtng_discard_output() {
  121.     if (mbtng_display_page() && mbtng_use_tng_homepage()) {
  122.         ob_clean();
  123.         // Remove actions in case loop used elsewhere (e.g. in sidebar)
  124.         //remove_action('loop_start', 'mbtng_output_page');
  125.         //remove_action('loop_end', 'mbtng_discard_output');
  126.     }
  127.  
  128. }
  129.  
  130. //Runs the TNG PHP code and returns the HTML
  131. function mbtng_eval_php($filename) {
  132.     global $tng_output;
  133.     if ($tng_output == '') {
  134.         $tng_folder = get_option('mbtng_path');
  135.         if (stripos($filename, 'admin') !== FALSE) {
  136.             //$filename = substr ($filename, 6);
  137.             $admin = true;
  138.             //$tng_folder .= 'admin';
  139.         } else {
  140.             ini_set('include_path', ini_get('include_path').PATH_SEPARATOR.$tng_folder);
  141.             $admin = false;
  142.         }
  143.         eval('?>'.get_option('mbtng_globals').'<?php ');
  144.         ob_start();
  145.         $code = file_get_contents(mbtng_folder_trailingslashit($tng_folder).$filename);
  146.         if ($admin | $filename == 'pdfform.php')
  147.             chdir($tng_folder);
  148.         eval("?>$code<?php ");
  149.         $output = ob_get_contents();
  150.         ob_end_clean();
  151.         $tng_output = $output;
  152.     }
  153.     mbtng_close_tng_table();
  154.     return $tng_output;
  155. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement