Posts: 1,110
Threads: 61
Joined: Sep 2008
Reputation:
31
2010-01-17, 10:02 PM
(This post was last modified: 2010-01-18, 07:07 PM by querschlaeger .)
Hi,
this thread I want to use to provide a place for sharing pages made by
Page Manager .
Since version 1.4 it is possible to export and import custom pages. So it's very easy to include pages in your MyBB made by other Page Manager users. Because of the possibility to use PHP in pages I see no limitations in creating new pages (possible ideas: Imprint Page, Contact Form, [Google] Maps Page, Credits Page, Rules Page, complex Poll Page, ...).
Okay, let's go!
First I will provide 2 simple pages which demonstrate how Page Manager works. Both pages produce the same results: A simple test page. But one of them uses the
MyBB Template system (template.xml) and the other one uses
PHP (php.xml) to create the page. Try it and take them as templates to start creating own pages.
Last but not least there is another demonstration page (parser.xml). It shows how to load the MyBB message parser with the help of PHP and parses some MyCode and a Smilie.
Attached Files
php.xml (Size: 1.06 KB / Downloads: 3,189)
template.xml (Size: 754 bytes / Downloads: 2,467)
parser.xml (Size: 1.33 KB / Downloads: 2,305)
Posts: 919
Threads: 146
Joined: Sep 2009
Reputation:
0
2010-01-18, 08:30 PM
Thank you for the parser.xml!
Now I can use mycode and smilies!
Posts: 1,110
Threads: 61
Joined: Sep 2008
Reputation:
31
2010-01-24, 07:52 PM
(This post was last modified: 2010-01-24, 08:52 PM by querschlaeger .)
Okay, here is a useful page: Usermap (powered by Google Maps)!
It will display all of your users who provide there location in the default MyBB custom profile field in a nice Google Map!
You need a Google Maps API key for your website, get it here:
http://code.google.com/apis/maps/signup.html
Edit the custom page and you will see the point to type in the key (line 3).
First run of the page will take some time to create the location cache. Don't worry about it and don't abort the page loading.
By the way: I developed a plugin called
Page Converter , you will find it here:
http://mods.mybboard.net/view/page-converter
This plugin allows you to convert custom pages of various page plugins into
Page Manager pages.
Attached Files
Thumbnail(s)
usermap.xml (Size: 7.5 KB / Downloads: 1,724)
Posts: 1,028
Threads: 75
Joined: Sep 2008
Reputation:
23
2010-01-24, 08:06 PM
I got an error when trying to import the map page
Quote: Could not find an importable page with the file you uploaded. Please check the file is the correct and is not corrupt
Posts: 1,110
Threads: 61
Joined: Sep 2008
Reputation:
31
2010-01-24, 08:34 PM
Ups, my mistake... I updated the file. Now it should work.
Posts: 1,028
Threads: 75
Joined: Sep 2008
Reputation:
23
2010-01-24, 09:14 PM
Sorry to bother you again.
This time it imported correctly, I added my Google key to it, but when I enable the page and navigate to it, I get an error
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/gordie/public_html/pab/inc/plugins/pagemanager.php(748) : eval()'d code on line 30
Posts: 1,110
Threads: 61
Joined: Sep 2008
Reputation:
31
2010-01-24, 09:17 PM
Can you please copy the page content an paste it here? So I can check if there are any changes made.
Posts: 1,028
Threads: 75
Joined: Sep 2008
Reputation:
23
2010-01-24, 09:21 PM
I assume you want the contents of the map page:
<?php
$key = 'ABQIAAAAUUfna01ekpw4VVBbi_oPLBRMxyd7BM4wRZU84M8B6nOs45QWOhQffUW4xva9oiJNylK6w8Aq8XfgQg';
$location = 'United States';
$zoom = 4;
$fid = 1;
$datacache = './cache/coords';
if(!$mybb->usergroup['canviewprofiles'])
{
error_no_permission();
}
global $headerinclude, $header, $theme, $footer, $cache, $templates;
require_once MYBB_ROOT.'inc/class_xml.php';
require_once MYBB_ROOT.'inc/functions_image.php';
$contents = fetch_remote_file('http://maps.google.com/maps/geo?q=' . rawurlencode($location) . '&output=xml');
$parser = new XMLParser($contents);
$tree = $parser->get_tree();
if($tree['kml']['Response']['Placemark']['Point']['coordinates']['value'])
{
$location = explode(',', $tree['kml']['Response']['Placemark']['Point']['coordinates']['value']);
}
else
{
$location = array(0, 0);
$zoom = 2;
}
if(!file_exists($datacache) || time()-filemtime($datacache) > 169200 || ($mybb->usergroup['cancp'] && intval($mybb->input['update']) == 1))
{
$usergroups_cache = $cache->read('usergroups');
$query = $db->simple_select("usertitles", "*", "", array('order_by' => 'posts', 'order_dir' => 'DESC'));
while($usertitle = $db->fetch_array($query))
{
$usertitles_cache[$usertitle['posts']] = $usertitle;
}
$query = $db->query("
SELECT u.*, f.*
FROM ".TABLE_PREFIX."users u
LEFT JOIN ".TABLE_PREFIX."userfields f ON (f.ufid=u.uid)
WHERE f.fid" . $fid . " != ''
AND u.usergroup NOT IN (5, 7)
");
$usercache = array();
while($user = $db->fetch_array($query))
{
$user['username'] = format_name($user['username'], $user['usergroup'], $user['displaygroup']);
$user['profilelink'] = build_profile_link($user['username'], $user['uid']);
if(!$user['displaygroup'])
{
$user['displaygroup'] = $user['usergroup'];
}
$usergroup = $usergroups_cache[$user['displaygroup']];
if(!empty($usergroup['image']))
{
if(!empty($mybb->user['language']))
{
$language = $mybb->user['language'];
}
else
{
$language = $mybb->settings['bblanguage'];
}
$usergroup['image'] = str_replace("{lang}", $language, $usergroup['image']);
$usergroup['image'] = str_replace("{theme}", $theme['imgdir'], $usergroup['image']);
$usergroup['groupimage'] = '<img src="' . $usergroup['image'] . '" alt="' . $usergroup['title'] . '" title="' . $usergroup['title'] . '" />';
}
$has_custom_title = 0;
if(trim($user['usertitle']) != "")
{
$has_custom_title = 1;
}
if($usergroup['usertitle'] != "" && !$has_custom_title)
{
$user['usertitle'] = $usergroup['usertitle'];
}
elseif(is_array($usertitles_cache) && !$usergroup['usertitle'])
{
foreach($usertitles_cache as $posts => $titleinfo)
{
if($user['postnum'] >= $posts)
{
if(!$has_custom_title)
{
$user['usertitle'] = $titleinfo['title'];
}
$user['stars'] = $titleinfo['stars'];
$user['starimage'] = $titleinfo['starimage'];
break;
}
}
}
if($usergroup['stars'])
{
$user['stars'] = $usergroup['stars'];
}
if(!$user['starimage'])
{
$user['starimage'] = $usergroup['starimage'];
}
$user['starimage'] = str_replace("{theme}", $theme['imgdir'], $user['starimage']);
for($i = 0; $i < $user['stars']; ++$i)
{
$user['userstars'] .= "<img src=\"".$user['starimage']."\" border=\"0\" alt=\"*\" />";
}
if($user['userstars'] && $usergroup['groupimage'])
{
$user['userstars'] = "<br />".$user['userstars'];
}
if($user['avatar'] != '')
{
$user['avatar'] = htmlspecialchars_uni($user['avatar']);
$avatar_dimensions = explode("|", $user['avatardimensions']);
if($avatar_dimensions[0] && $avatar_dimensions[1])
{
list($max_width, $max_height) = explode("x", my_strtolower($mybb->settings['memberlistmaxavatarsize']));
if($avatar_dimensions[0] > $max_width || $avatar_dimensions[1] > $max_height)
{
$scaled_dimensions = scale_image($avatar_dimensions[0], $avatar_dimensions[1], $max_width, $max_height);
$avatar_width_height = "width=\"{$scaled_dimensions['width']}\" height=\"{$scaled_dimensions['height']}\"";
}
else
{
$avatar_width_height = "width=\"{$avatar_dimensions[0]}\" height=\"{$avatar_dimensions[1]}\"";
}
}
$user['avatar'] = '<img src="' . $user['avatar'] . '" alt="" ' . $avatar_width_height . ' />';
}
else
{
$user['avatar'] = "";
}
$html = '<table><tr><td>' . $user['avatar'] . '</td><td>' . $user['profilelink'] . '<br /><span class="smalltext">' . $user['usertitle'] . '<br />' . $usergroup['groupimage'] . $user['userstars'] . '</span></td></tr></table>';
$home = strtolower($user['fid' . $fid]);
if(isset($usercache[$home]))
{
$usercache[$home] .= '<hr>'.$html;
}
else
{
$usercache[$home] = $html;
}
}
$coordscache = array();
foreach($usercache as $index => $value)
{
$contents = fetch_remote_file('http://maps.google.com/maps/geo?q=' . rawurlencode($index) . '&output=xml');
$parser = new XMLParser($contents);
$tree = $parser->get_tree();
sleep(1);
if($tree['kml']['Response']['Placemark']['Point']['coordinates']['value'])
{
if(isset($coordscache[$tree['kml']['Response']['Placemark']['Point']['coordinates']['value']]))
{
$coordscache[$tree['kml']['Response']['Placemark']['Point']['coordinates']['value']] .= '<hr>'.$value;
}
else
{
$coordscache[$tree['kml']['Response']['Placemark']['Point']['coordinates']['value']] = $value;
}
}
}
file_put_contents($datacache, serialize($coordscache));
}
else
{
$coordscache = unserialize(file_get_contents($datacache));
}
$run = 1;
foreach($coordscache as $index => $value)
{
$point = explode(',', $index);
$output .= '
var point' . $run . ' = new GLatLng(' . $point[1] . ',' . $point[0] . ');
var html' . $run . ' = "' . str_replace('"', "'", $value) . '";
var info' . $run . ' = new GMarker(point' . $run . ');
GEvent.addListener(info' . $run . ', "click", function() {
info' . $run . '.openInfoWindowHtml(html' . $run . ')
});
map.addOverlay(info' . $run . ');
';
$run++;
}
$template = '<html>
<head>
<title>' . $pages['name'] . '</title>
{$headerinclude}
<script src="http://maps.google.com/maps?file=api&v=2&key=' . $key . '&sensor=false" type="text/javascript"></script>
<script type="text/javascript">
' . html_entity_decode('<!--/*--><![CDATA[/*><!--*/') . '
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(' . $location[1] . ',' . $location[0] . '), ' . $zoom . ');
map.setUIToDefault();
{$output}
}
}
' . html_entity_decode('/*]]>*/-->') . '
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
{$header}
<table border="0" cellspacing="' . $theme['borderwidth'] . '" cellpadding="' . $theme['tablespace'] . '" class="tborder">
<thead>
<tr>
<td class="thead">
<strong>' . $pages['name'] . '</strong>
</td>
</tr>
</thead>
<tbody>
<tr>
<td class="trow1" style="padding: 0;"><div id="map" style="width: 100%; height: 500px;"></div></td>
</tr>
</tbody>
</table>
<br />
{$footer}
</body>
</html>';
$template = str_replace("\'", "'", addslashes($template));
add_breadcrumb($pages['name']);
eval("\$page = \"" . $template . "\";");
output_page($page);
?>
Posts: 1,110
Threads: 61
Joined: Sep 2008
Reputation:
31
2010-01-24, 09:31 PM
(This post was last modified: 2010-01-24, 09:33 PM by querschlaeger .)
Hm, strange... everything seems to be okay. At the moment I have no idea. PHP says there is an error close to line 30 but I can't find anything...
Maybe you can try to remove this block:
else
{
$location = array(0, 0);
$zoom = 2;
}
Posts: 1,028
Threads: 75
Joined: Sep 2008
Reputation:
23
2010-01-25, 12:02 PM
(This post was last modified: 2010-01-25, 12:08 PM by x-Treme .)
That doesn't work either
EDIT: NVM...it's working with the original imported page. I turned off "Use MyBB Template" and everything is fine.
Just a quick question... It's not showing the location of my members. We have the profile field filled out, but no markers are showing on the map.