Oh no! Where's the JavaScript?
Your Web browser does not have JavaScript enabled or does not support JavaScript. Please enable JavaScript on your Web browser to properly view this Web site, or upgrade to a Web browser that does support JavaScript.
Not a member yet? Click here to register.
Forgot Password?

function add_to_head how work?

Asked Modified Viewed 1,158 times
D
DjordjeB
D
  • Member, joined since
  • Contributed 50 posts on the community forums.
  • Started 13 threads in the forums
  • Started this discussions
asked
Member

Hello i have question about that script. For one my project i don't use any CMS solution for all other i use php-fusion and i use very offten add_to_head for my meta tags and seo stuff.
I find that function in output_themes.... but i don't know how it works? How function in PHP take content and place on top of php page.. This is confused for me becouse in php is like timeline executed code lines.

How can i copy that function to my website?
0 replies

2 posts

D
DjordjeB
D
  • Member, joined since
  • Contributed 50 posts on the community forums.
  • Started 13 threads in the forums
  • Started this discussions
answered
Member

Yes! That is that direction! Now i know what i need to search. Thank you very much!
ob_start() is track for solution.
0 replies
S
skpacman
S
My PHP-Fusion site: https://skpacman.live
  • Member, joined since
  • Contributed 150 posts on the community forums.
  • Started 25 threads in the forums
answered
Member

As far as I can tell, with my limited knowledge:

in output_handling_include.php, the code is first passed to:
function add_to_head($tag=""){
   global $fusion_page_head_tags;
   
   if(!stristr($fusion_page_head_tags, $tag)){
      $fusion_page_head_tags .= $tag."\n";
   }
}


Where it's forced into the $output by:
function handle_output($output){
   global $fusion_page_head_tags ,$fusion_page_footer_tags, $fusion_page_title, $fusion_page_meta, $fusion_page_replacements, $fusion_output_handlers, $settings;

   if(!empty($fusion_page_footer_tags)){
      $output = preg_replace("#</body>#", $fusion_page_footer_tags."</body>", $output, 1);
   }
   if(!empty($fusion_page_head_tags)){
      $output = preg_replace("#</head>#", $fusion_page_head_tags."</head>", $output, 1);
   }
   if($fusion_page_title != $settings['sitename']){
      $output = preg_replace("#<title>.*</title>#i", "<title>".$fusion_page_title."</title>", $output, 1);
   }
   if(!empty($fusion_page_meta)){
      foreach($fusion_page_meta as $name => $content){
         $output = preg_replace("#<meta (http-equiv|name)='$name' content='.*' />#i", "<meta \\1='".$name."' content='".$content."' />", $output, 1);
      }
   }
   if(!empty($fusion_page_replacements)){
      eval($fusion_page_replacements);
   }
   if(!empty($fusion_output_handlers)){
      eval($fusion_output_handlers);
   }
   
   return $output;
}
Notice the "$fusion_page_head_tags" being returned to $output in there?

Then, in the header.php, it sets up the rest of the header and starts the content of the page with ob_start(), basically making the output of the page an object.

In footer.php, it closes the object, takes its output, combines it with the rest of $output, then returns the whole thing to the browser.

The preg_replace stuff in handle_output() is where the magic happens.

I don't know how you would implement this in your own code outside of php-fusion, but at least it helps to (mostly) know how php-fusion does it.
Edited by skpacman on 23-01-2015 21:34,
0 replies

Labels

None yet

Statistics

  • Views 0 views
  • Posts 2 posts
  • Votes 0 votes
  • Topic users 2 members

2 participants

D
D
  • Member, joined since
  • Contributed 50 posts on the community forums.
  • Started 13 threads in the forums
  • Started this discussions
S
S
My PHP-Fusion site: https://skpacman.live
  • Member, joined since
  • Contributed 150 posts on the community forums.
  • Started 25 threads in the forums

Notifications

Track thread

You are not receiving notifications from this thread.

Related Questions

Not yet