PDA

View Full Version : Help Please:- Displaying a CMS Widget in a Pop Up Window


B16MCC
10-04-2011, 07:35 AM
Hi guys, I've taken on a little project that has taught me quite a lot so far but now I'm a little stuck.
I've written a php direct exec widget and have it displayed on my CMS.
It simply takes all the mp3 file names from a given folder on the server and lists them as the $output.
I then use the yahoo player to turn them into links.
This is all done and working.

What I'd like to do is to replace the widget with a link on my CMS that then shows this output in a pop up window.
The image below is what it look like so far on my CMS.

https://vborg.vbsupport.ru/attachment.php?attachmentid=133451&stc=1&d=1317717301

So, I've made a custom template and created the link to show the template page as a pop up, this is shown below.

https://vborg.vbsupport.ru/attachment.php?attachmentid=133452&stc=1&d=1317717301

So basically what I'm asking is, how do I move the output from the widget so that its displayed in my pop up window.

I hope I've explained myself adequately.
Thanks for your time.

Lynne
10-04-2011, 04:07 PM
I think you'd need to move the php for the widget into it's own php page. You may have to change it a bit and echo instead of putting it into a variable to output (although I guess you can just echo the variable at the end). Then write the javascript for the popup that points to that php page.

B16MCC
10-04-2011, 04:39 PM
Thanks for the tip Lynne. I've tried making a custom php page, but I'm struggling positioning the output from my code. The page renders just fine, but my custom php output is at the top of the page . How would I position it under the navbar for example ?

Lynne
10-04-2011, 05:50 PM
That is hard to say since you haven't posted the code. Post the code, using the code tags, so that I may see what is going on.

B16MCC
10-04-2011, 06:22 PM
Ok Lynne here's what I've got so far.

I created a template called custom_jukebox

{vb:stylevar htmldoctype}
<html xmlns="http://www.w3.org/1999/xhtml"<vb:if condition="$vboptions['enablefacebookconnect']"> xmlns:fb="http://www.facebook.com/2008/fbml"</vb:if> dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
<head>
{vb:raw headinclude}
<title>{vb:raw vboptions.bbtitle}</title>

<vb:if condition="$vboptions['storecssasfile']">
{vb:cssfile forumhome-rollup.css}
<vb:else />
{vb:cssfile forumbits.css,forumhome.css,widgets.css,sidebar.cs s,options.css,tagcloud.css}
</vb:if>

<!--[if lt IE 8]>{vb:cssfile forumbits-ie.css,sidebar-ie.css,options-ie.css}<![endif]-->
<vb:if condition="$show['sidebar']">
<script type="text/javascript" src="{vb:stylevar yuipath}/animation/animation-min.js?v={vb:raw vboptions.simpleversion}"></script>
<script type="text/javascript">
var sidebar_align = '{vb:raw show.sidebarposition}';
var content_container_margin = parseInt('{vb:math {vb:stylevar forum_sidebar_width}+{vb:math {vb:stylevar padding}*2}}');
var sidebar_width = parseInt('{vb:stylevar forum_sidebar_width}');
</script>
<script type="text/javascript" src="{vb:raw vboptions.bburl}/clientscript/vbulletin-sidebar.js?v={vb:raw vboptions.simpleversion}"></script>
</vb:if>
{vb:raw headinclude_bottom}
</head>
<body>

{vb:raw header}
{vb:raw navbar}

<div class="cms_widget">
<div class="block">
<div class="cms_widget_header widget_header">
<h3><img src="{vb:stylevar imgdir_siteicons}/php.png" alt="" /> {vb:raw title}</h3>
</div>
<div class="cms_widget_content widget_content">
{vb:raw output}

</div>
</div>
</div>

{vb:raw footer}

</body>
</html>



I also created a new php file called jukebox.php

<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT', 'jukebox');
define('CSRF_PROTECTION', true);
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('custom_jukebox',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// ################################################## #####################
// ######################## START MAIN SCRIPT ############################
// ################################################## #####################

$navbits = construct_navbits(array('' => 'Mambo Hats Jukebox'));
$navbar = render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
// Define the full path to your folder from root
$path = "./mp3";

// Open the folder
$dir_handle = @opendir($path) or die("Unable to open $path");

// Loop through the files
while ($file = readdir($dir_handle)) {

if($file == "." || $file == ".." || $file == "index.php" )

continue;
echo "<a href=\"/mp3/$file\">$file</a><br />";

}
// Close
closedir($dir_handle);


$pagetitle = 'Mambo Hats JukeBox';

// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater = vB_Template::create('custom_jukebox');
$templater->register_page_templates();
$templater->register('navbar', $navbar);
$templater->register('pagetitle', $pagetitle);
print_output($templater->render());

?>

B16MCC
10-05-2011, 07:10 PM
Anyone got any ideas please ?

Lynne
10-05-2011, 10:21 PM
As I said before, you need to output your output to a variable. you cannot echo it. You output it into a variable and then register it for use in the template. You are using echo in your php page. ie.....
not:
echo "<a href=\"/mp3/$file\">$file</a><br />";
but:
$output .= "<a href=\"/mp3/$file\">$file</a><br />";
then register the variable like you do the otehrs.

B16MCC
10-06-2011, 12:38 PM
sorry for being a pain, I understand the difference but I don't know what to add to the template to make it output my variable. Could you expand just a little please ?

--------------- Added 1317908887 at 1317908887 ---------------

Lynne, I've done it, thankyou for your help.

I also found this which helped me over the final hurdle.

https://vborg.vbsupport.ru/showthread.php?t=228078

Lynne
10-07-2011, 01:16 AM
Glad you finally got it. :)

And yes, that is a very good article by Cellarius.