Jump to content


Call external database with API or include


  • You cannot reply to this topic
10 replies to this topic

#1 robotarchie

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 17 January 2008 - 02:36 AM

Hi

I'm having trouble calling external pages which include php into etomite. Using

example: include("./assets/content/committees.php");

within a snippet will call the page (committees.php in this instance is a query generated by a normal phpmysql call to the database) but it places the result top left ignoring all the div formatting and css. I know that this question has come up in a couple of posts but they are not resolved in this regard.

the other method that I have been attempting to use is API calls (which in many ways makes a lot more sense imho). the problem is that i don't understand how they are structured for instance:

dbExtQuery($host, $user, $pass, $dbase, $query)

would This be a chunk, a snippet or placed into the head section of the calling template document?

would I write the code like this;

dbExtQuery($host, $user, $pass, $dbase, $query)

$host="localhost";
$user="username";
$pass="password";
$dbase="databasename";
$query="SELECT
comMember.firstName,
comMember.surName,
comMember.committee,
comMember.mob,
comMember.email,
comMember.com_id,
comMember.Committee2,
comMember.committee3
FROM
comMember
WHERE
comMember.`position` = 'TreasurerSecretary'
ORDER BY
comMember.committee ASC
"

It's probably clear from the code i've included that I need some serious and clear direction, this is the first time I've attempted to do this sort of thing.

I've looked at formhandler but it is unsuitable for my needs as in far as I am only trying to populate data from an external database. All I'm doing is providing content which then needs to be formatted using css.

I've gone through what information is in the documentaion side of the site but it is clearly written with a view to "gatekeeping" or more likely in a hurry with no examples of placement or such, just syntax.

As an aside I have stripped out all the excess elements in the css associated with the moillio suckerfish menus I have fully commented what they do (makes modifying it for your own needs a lot easier ) for the [[MollioMainMenu]]. You can see an example for a limited time period at www.lawrencefrinn.com/camden08

If anyone thinks that will be usefull please let me know and i'll email it or post it in the appropriate forum area.




#2 mikef

    Loves Etomite Forums!

  • Member
  • PipPipPipPip
  • 1,551 posts

Posted 17 January 2008 - 11:19 AM

View Postrobotarchie, on Jan 17 2008, 02:36 AM, said:

Hi

I'm having trouble calling external pages which include php into etomite. Using

example: include("./assets/content/committees.php");

within a snippet will call the page (committees.php in this instance is a query generated by a normal phpmysql call to the database) but it places the result top left ignoring all the div formatting and css. I know that this question has come up in a couple of posts but they are not resolved in this regard.
This doesn't work because your script writes its output directly to the page, rather than to Etomite's output buffer. You need to rewrite the script as a snippet.

View Postrobotarchie, on Jan 17 2008, 02:36 AM, said:

As an aside I have stripped out all the excess elements in the css associated with the moillio suckerfish menus I have fully commented what they do (makes modifying it for your own needs a lot easier ) for the [[MollioMainMenu]]. You can see an example for a limited time period at www.lawrencefrinn.com/camden08

If anyone thinks that will be usefull please let me know and i'll email it or post it in the appropriate forum area.
Link doesn't work. In any case it will be helpful, so please post in the forum. I've been meaning to try to tidy up my copy, but haven't got round to sorting out what can be safely removed.

#3 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 17 January 2008 - 02:58 PM

Check my two development sites, http://dahlgren.slyip.com and http://ralphdahlgren.com, for additonal information and tutorials... There should be several examples of both internal and external data abstraction, as well as a wealth of other information...

Including external files is a problem due to the fact that Etomite uses output buffering... When ouytput buffering is used you cannot make use of any PHP functions which bypass buffering and write directly to the output streem... Examples of this type of function would be echo, print, printf, etc... all output needs to be concatenated into an output variable, or multiple output variables, which are then displayed using return $output.[other variables];... All of those returned variables go back to the caller and are placed in the output where they need to be... Using a function like echo simply writes out the data before the contents of the output buffer are released... Hope this makes sense...

#4 robotarchie

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 18 January 2008 - 02:11 PM

Soz link ought to be www.lawrencefinn.com/camden08/

apologies my bad...

Link doesn't work. In any case it will be helpful, so please post in the forum. I've been meaning to try to tidy up my copy, but haven't got round to sorting out what can be safely removed.
[/quote]

I'd like to apologise for any faults in the notation and such but it works so...
The components of the mollio suckerfish menu (as hacked to bits by myself) are:

1. CSS document (I've called it nav.css)

/* CSS Document */


.clearfix:after {
content: ".";
display: block;
height: 0;
clear: both;
visibility: hidden;
}

* html>body .clearfix {
display: inline-block;
width: 100%;
}

* html .clearfix {
/* Hides from IE-mac \*/
height: 1%;
/* End hide from IE-mac */
}
/* NAV - top horizontal nav */
#nav,
#nav ul{
padding:0;
margin:0;
list-style:none
}

/* added from the formats css */



/* controls all fonts in menu */
#nav{
font-weight:normal;
height:.95em;
font-family: Geneva, Arial, Helvetica, sans-serif;
font-size: 10pt;
margin-top: 0;
margin-right: 50px;
margin-bottom: 0;
margin-left: 50px;
}
/* controls bg color of tier 1 menus with children removed border-bottom:3px solid #888888; border-right:3px solid #cccccc; this also controls the left to right run of the menus across the horizon */
#nav li{
float:left;
width:8em;
margin:0;
padding:0;
display:block;
position:relative;
background-color: #FFFFCC;
}
/* padding:2px (controls distance to top of div or page) 10px (controls left margin) 2px; */
#nav a,
#nav a:link,
#nav a:visited,
#nav a:active,
#nav a:hover{
display:block;
color:#000000;
text-decoration:none;
cursor:pointer;
padding-top: 2px;
padding-right: 10px;
padding-bottom: 0px;
padding-left: 10px;
}
/* crop box bg color */
#nav a:active,
#nav a:hover{
background:#8fc3d7;
color:#000000
}
/* controls drop menu look (margin-top:1px; this controls the proximity of the drop menus and if it is set too far away the menus remove before the mouse can touch them) */
#nav li ul{
border-left:1px solid #1987af;
width:12em;
margin-top:0px;
font-size:90%;
font-weight:normal;
position:absolute;
left:-999em;
background-color: #FFFFCC;
background-repeat: no-repeat;
background-position: 100% 100%;
}
#nav li:hover ul,
#nav li.sfhover ul{
left:0;
z-index:8009;
min-height:0;
}
#nav li li{
float:none;
padding-left:0;
background:none;
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: ##FFCC33;
}
/* controls float menu width:18em; background mouse over color and width */
#nav li li.last{
border-bottom:none
}
/* width controls the hover mouse over bar on 2nd tier menus*/
#nav li li a,
#nav li li a:link,
#nav li li a:visited,
#nav li li a:active,
#nav li li a:hover{
width:10em;
color:#000000;
padding-top: 3px;
padding-right: 10px;
padding-bottom: 2px;
padding-left: 10px;
}
/* background controls the hover element color */
#nav li li a:active,
#nav li li a:hover{
background:#8fc3d7;
color:#FF0000}


/* controls non child bareing nav parent (1st tier) */
#nav li.active{
background-color: #FFFFCC;
}
/* click on a float menu item and go to the page this color scheme becomes active on the menu */
#nav li.active ul{
border:none;
background-color: #FFFFCC;
background-repeat: no-repeat;
background-position: 80% 80%;
border-bottom-style: solid;
border-bottom-width:thin;
border-bottom-color:#FFCC66
}
#nav li.active a:link,
#nav li.active a:visited,
#nav li.active a:active,
#nav li.active a:hover{
background:transparent;
color:#000000}
#nav li.active a:active,
#nav li.active a:hover{
background:#8fc3d7;
color:#000000
}
/* controls bottom line on 2nd tier float menu */
#nav li.active li{
border-top-style: none;
border-right-style: none;
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #FFCC33;
border-left-style: none;
}
#nav li.active li.last{
border-bottom-width: thin;
border-bottom-style: solid;
border-bottom-color: #FFCC33;
}
#nav li.active li a:link,
#nav li.active li a:visited,
#nav li.active li a:active,
#nav li.active li a:hover
{
color:#000000
}

#nav li.active li a:active,
#nav li.active li a:hover
{
background:#8fc3d7;
color:#000000
}
/* click on a float menu item and go to the page this color scheme becomes active on the menu. It shows you where you are on the menu system both the font and the bg box */

#nav li.active li.active a,
#nav li.active li.active a:link,
#nav li.active li.active a:visited,
#nav li.active li.active a:active,
#nav li.active li.active a:hover{
color:#990000;
background-color: #FFCC66;
}
/* hide from IE mac \*/
#nav li{
width:auto
}
/* end hiding from IE5 mac */

2. [[MollioMainMenu]] snippet (readily available in the default install of etomite)
3. common.js (i place mine in assets/js directory)

/*
son of suckerfish menu script from:
http://www.htmldog.com/articles/suckerfish/dropdowns/
*/
sfHover = function() {
var sfEls = document.getElementById("nav").getElementsByTagName("LI");
for (var i=0; i<sfEls.length; i++) {
sfEls[i].onmouseover=function() {
this.className+=" sfhover";
this.style.zIndex=200; //this line added to force flyout to be above relatively positioned stuff in IE
}
sfEls[i].onmouseout=function() {
this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
}
}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);

#5 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 18 January 2008 - 02:56 PM

After that last post you'll have to refresh my memory... What was the question again...??? For help with the Mollio stuff, there is documentation on their website which details customizations... You can also point your browser to the templates/mollio/ directory of your Etomite install... As far as the Etomite implementations of Mollio resources, Lloyd Borret might be able to help point you in the right direction - or perhaps someone else can chime in...

#6 robotarchie

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 18 January 2008 - 02:57 PM

Hi

I had already looked at your site and the examples that you posted. Unfortunatly for me there are too many assumptions of prior knowledge in what you have posted. ie I can understand the concepts but due to a lack of experience I have no way of knowing how to implement them. For instance, a simple include inside a snippet seems to need to be made into an array for the etomite buffer otherwise etomite drops it? How would I structure such a snippet so that etmoite handles it correctly and gives output? Can I use includes, or readfile or am I better off using the API calls, if I use the API calls how to structure it (do api calls all go into the snippet or are some elements held in the header of the template page or is there some other place that the calls are located)?

An example of a really simple snippet that does a simple include to an external page that has a simple php hello world statement would be worth a s*&*tload more to me than an example of correct syntax. Running an example of correct syntax and then the functional example above would be better still.

I really need someone to supply real world functional and simple examples.Of course I realise that the way I've put this is likely to piss people off, everyone is busy and helping people is a skill in itself. One of the things i find hardest about etomite isn't the cms as such but that the documentation is not written for access unless you are already part of the intellectual gatekeepers for the program. It's always good for a student to have some self determination and to go off and read stuff and look at examples but there is a point where that is useless (particularly when there are no starting reference points). Etomite would be a lot more popular I'm sure if there was just a properly constructed guide to the CMS and its functions. 

I'm not lazy, I've been cracking at etomite for some time now and have been doing every php tute I can find. I'm sure that I'm not the only ghost on the forums that really wishes the level of 
explanation was more expansive and less geared towards people who already know how to program.

I work as a teacher of computer skills to designers [believe it or not] (quark, indesign, photoshop, illustrator, flash dreamweaver etc). My background is in fine art (artist printmaker), design and illustration, as well as IT technical support, for fujitsu - compuserve and macromedia Quark XPress support. I mention this to illustrate that I have some depth of experience (but I am not a programmer in any way shape or form, I'm learning what I can though.)


I'm so used to having to break anything I teach into basic blocks that it is frustrating to see so much knowledge wasted because no one has structured it for first principles. Of course for those who already know roughly what they are doing then the information here is perfect. Guess its a case of deciding if you want your cms to be accessible or just for those already in the cult!

I also work as a designer and desktop publisher. An earlier offer I made in this forum to work on a manual fell on deaf ears, as I said then it would have to be a collaboration with someone who knows how the cms functions. Writing a manual of this sort is not the kind of thing that can be done by one person with imperfect knowledge of the cms. It has to be a collaboration with someone who understands the cms, snippets and chunks. Its kind of typical but the reponses I received where along the lines of give it a go then we'll come on board (fair enough as the people who replied seem to be doing a shitload of work on etomite and proably have less time than me, but... This is no way forward for anyone).

On the positive I appreciate that you have taken the time to answer my question, I really wish that I knew enough to make your effort worthwhile.







View PostRalph, on Jan 18 2008, 01:58 AM, said:

Check my two development sites, http://dahlgren.slyip.com and http://ralphdahlgren.com, for additonal information and tutorials... There should be several examples of both internal and external data abstraction, as well as a wealth of other information...

Including external files is a problem due to the fact that Etomite uses output buffering... When ouytput buffering is used you cannot make use of any PHP functions which bypass buffering and write directly to the output streem... Examples of this type of function would be echo, print, printf, etc... all output needs to be concatenated into an output variable, or multiple output variables, which are then displayed using return $output.[other variables];... All of those returned variables go back to the caller and are placed in the output where they need to be... Using a function like echo simply writes out the data before the contents of the output buffer are released... Hope this makes sense...


#7 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 18 January 2008 - 03:23 PM

I've been hunting around for some documentation regarding porting stand-alone scripts into Etomite but haven't found it as yet... We are always looking for people to contribute to better documentation - a major weakness in many open source projects... As confirmed by your previous post, I'm not the person to write documentation as I accidentally make assumptions on how much people already understand about Etomite because I am so totally immersed in the code base every day...

Anyway, I'm a firm believer in porting external scripts into Etomite and running them as snippets as opposed to using includes... But, just to clarify, I do run some snippets as includes during development on my local server because it speeds my development cycle... But there are times when it doesn't work as well as simply editing the snippet code internally... The guidelines regarding not using certain function calls remains, however... The following piece of code is what I use to include those external files...

$module = "<path_to_external_php_script>";
ob_start();
$inc = file_get_contents($module);
ob_end_clean();
return eval($inc);

The external files should not have opening or closing PHP tags although I do use //<?php so my external editor can properly highlight the PHP source... Etomite ignores this remarked opening tag...

Not sure if any of this helps or just clouds the subject further...

#8 Cris D.

    Loves Etomite Forums!

  • Developers
  • PipPipPipPip
  • 1,104 posts
  • Gender:Male

Posted 18 January 2008 - 09:37 PM

Quote

I'm not lazy, I've been cracking at etomite for some time now and have been doing every php tute I can find. I'm sure that I'm not the only ghost on the forums that really wishes the level of
explanation was more expansive and less geared towards people who already know how to program.
Well said, here here!
One of the main problems with this is though it that Etomite is SO flexible, that there is not a lot it can't do but everyone's background is SO different and individual needs so varied one person' starting point will be helpful, but for another a turn-off. Also, if someone does not know how to do ANY code before using etomite, it is very difficult to modify let alone create snippets, therefore learning code is a big part of using Etomite to its fullest. There are already several good sites that teach code which is why they are referred to elsewhere in these forums. It would be silly to try to replicate those sites here. Any solutions for an "Etomite Orientation tutorial" I'm sure would be gladly received.
Rest assured that the frustration you are experiencing at having to learn some PHP, html, sql, javascript, is normal at this point but it will be worth it!

PS. As a teacher you may understand this concept: Rather than reading every tutorial available it is much better in this instance to get a DEEP UNDERSTANDING of one or two. If there is a single function or expression that you don't understand, google it, and you will piece it together eventually. There is massive overlaps between code blocks and languages once you start to "get it".

Edited by Cris D., 18 January 2008 - 09:45 PM.


#9 robotarchie

    Etomite Forum Newbie

  • Member
  • 10 posts

Posted 19 January 2008 - 04:07 AM

Thanks that does help bit I think!

I'm still interested in doing a manual. If I create a structure for it, is there somewhere here that I can post it to and then people can offer their expertise to the aspects ofthe structure they specialise in. I'll get it professionally edited, desktopped and illustrated.

What I want in return is only a commitment from some people that know what they are doing to look it over and write sections (I'll rewrite for clarity) and answer questions from me (via direct email or pm) for the manual.

I'm willing to put the time in because I want to learn how to do it myself, if that helps others then it is a good thing. Also I've funted about with a lot of CMS's now and etomite (in spite of my whinging) is the mostdesign flexible I have ever seen or used).

It deserves a wider user base.

My personal email is lawrence atvurtmedia dotcom (I'd appreciate it if an admin would remove the email address at some later stage from this post) for anyone that would like to get on board to make a proper manual, not just a collection of notes, please email me directly.

Also the manual would be opensource, no copyright unless it is retained by the etomite community of developers (I'm not working on this if it is a sold item and I'm sure that the spirit of the etomite developers would probably agree).

Thanks

Lawrence

PS I'm also willing to pay someone to help me with my problem with the external files or to show me how to make the database calls via api.


View PostRalph, on Jan 19 2008, 02:23 AM, said:

I've been hunting around for some documentation regarding porting stand-alone scripts into Etomite but haven't found it as yet... We are always looking for people to contribute to better documentation - a major weakness in many open source projects... As confirmed by your previous post, I'm not the person to write documentation as I accidentally make assumptions on how much people already understand about Etomite because I am so totally immersed in the code base every day...

Anyway, I'm a firm believer in porting external scripts into Etomite and running them as snippets as opposed to using includes... But, just to clarify, I do run some snippets as includes during development on my local server because it speeds my development cycle... But there are times when it doesn't work as well as simply editing the snippet code internally... The guidelines regarding not using certain function calls remains, however... The following piece of code is what I use to include those external files...

$module = "<path_to_external_php_script>";<BR/> ob_start();<BR/> $inc = file_get_contents($module);<BR/> ob_end_clean();<BR/> return eval($inc);

The external files should not have opening or closing PHP tags although I do use //<?php so my external editor can properly highlight the PHP source... Etomite ignores this remarked opening tag...

Not sure if any of this helps or just clouds the subject further...


#10 darren

    Likes Etomite Forums!

  • Member
  • PipPip
  • 251 posts

Posted 22 January 2008 - 05:22 PM

View Postrobotarchie, on Jan 19 2008, 04:07 AM, said:

PS I'm also willing to pay someone to help me with my problem with the external files or to show me how to make the database calls via api.

no need to pay anyone, just stick around and help someone else out when you can. (like that manual...)

I struggled with getting some information from a Simple Machines Forum into my eto template, with help from everyone here we came up with this... it connects to my external database and displays the last 3 registered users with links to their profiles. I had an include file (made with dreamweaver that did what i wanted), so just copied that into a snippet, then had to edit a bit to use output instead of echo/print. ( everything above do {... is straight from my include) maybe this can help?

# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_sccsmf = "***";
$database_sccsmf = "***";
$username_sccsmf = "***";
$password_sccsmf = "***";
$sccsmf = mysql_pconnect($hostname_sccsmf, $username_sccsmf, $password_sccsmf) or die(mysql_error());


$maxRows_forumnews = 3;
$pageNum_forumnews = 0;
if (isset($HTTP_GET_VARS['pageNum_forumnews'])) {
  $pageNum_forumnews = $HTTP_GET_VARS['pageNum_forumnews'];
}
$startRow_forumnews = $pageNum_forumnews * $maxRows_forumnews;

mysql_select_db($database_sccsmf, $sccsmf);
$query_forumnews = "SELECT ID_MEMBER, memberName FROM smf_members ORDER BY dateRegistered DESC";
$query_limit_forumnews = sprintf("%s LIMIT %d, %d", $query_forumnews, $startRow_forumnews, $maxRows_forumnews);
$forumnews = mysql_query($query_limit_forumnews, $sccsmf) or die(mysql_error());
$row_forumnews = mysql_fetch_assoc($forumnews);

if (isset($HTTP_GET_VARS['totalRows_forumnews'])) {
  $totalRows_forumnews = $HTTP_GET_VARS['totalRows_forumnews'];
} else {
  $all_forumnews = mysql_query($query_forumnews);
  $totalRows_forumnews = mysql_num_rows($all_forumnews);
}
$totalPages_forumnews = ceil($totalRows_forumnews/$maxRows_forumnews)-1;

do {
$output .=('<a href="forums/index.php?action=profile;u=');
$output .=$row_forumnews['ID_MEMBER'];
$output .=('">');
$output .=$row_forumnews['memberName'];
$output .=('</a><br>');
     } while ($row_forumnews = mysql_fetch_assoc($forumnews));

return $output;

 
mysql_free_result($forumnews);



maybe needs some explanation:
external database is sccsmf
the connections stuff at the top is pretty straightforward
the rest makes a recordset called forumnews...

Edited by darren, 05 February 2008 - 10:34 PM.


#11 Ralph

    Loves Etomite Forums!

  • Admin
  • 6,524 posts
  • Gender:Male

Posted 22 January 2008 - 05:33 PM

I was working on several options for including external pages within Etomite, in my spare time, until my server decided to shit the bed in observance of Martin Luther King Jr's birthday... One used the <script> tag method and the other used XMLHttpRequest()... Both render just fine, but the <script> method had scrollbar issues that I never got a chance to investigate and resolve... The XMLHttpRequest() method worked perfectly, however...





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users