Jump to content


- - - - -

API functions suggestions [#10]


  • Please log in to reply
21 replies to this topic

#1 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 21 May 2004 - 05:58 PM

Phase 0.6 will have a new and improved site parser (the thing that builds your pages), offering a 400~650% speed increase over the current parser.

The new parser is fully object orientated, which gives us the chance to provide functions we can use as API calls. We've already decided on a few handy ones:

string $phase->makeURL($id, $alias, $args); (implemented)
This takes an id and optionally an alias, and using the Phase configuration settings, figures out and returns the appropriate link. The args parameter is to supply additional querystring data.

$phase->messageQuit($msg (string), $query (string), $is_error (bool)); (implemented)
This call will kill Phase's parsing of the current document. The variables are $msg, which can contains the message to show, $query can contain the SQL statement Phase was working with and $is_error (true or false) tells Phase that the message is either an error or a debug message. This function can be called, for example, if an sql statement in a snippet returns invalid results. For production sites not very handy, for developing snippets and the like a great boon, because if the user is also logged into the manager (i.e. an administrator previewing a document), a lot of debug info is shown, which may help you track down what's going wrong.

mixed $phase->getActiveChildren($id, $sortField, $sortDir, $fields); (implemented)
This function will return an array containing all active (i.e. published and not deleted) documents in the folder with id $id. Leaving out $id will return all active children documents of the Phase root (i.e. $id = 0).
$sortField will specify which field the results should be sorted on, and $sortDir will specify in how they should be sorted. getActiveChildren(14, 'createdon', 'DESC') will return all active children documents of folder 14, sorted descending on field 'createdon'. You can even specify what you want returned, using the $fields parameter. If not set, it'll return id, pagetitle, alias and description. Returns FALSE on failure.


mixed $phase->getAllChildren($id, $sortField, $sortDir, $fields); (implemented)
This function is the same as the previous function, except all documents are returned, be they published/ deleted or not. Returns FALSE on failure.

mixed $phase->getConfig($setting); (implemented)
Gets the setting you specify. Returns FALSE if the setting does not exist or Phase could not retrieve it.

array $phase->getVersionData(); (implemented)
Returns an array containing named values 'release_codename', 'version' (always to be three part, i.e. 0.5.2, not 0.5.2.1), 'patchlevel'.

bool $phase->sendRedirect($url[, $type]); (implemented)
Redirects to the given URL. Returns TRUE on success and FALSE on failure (unlikely). The optional parameter 'type' should not be specified unless absolutely neccesary, as the Phase Configuration should usually specify this (it does as default). Possible parameters are: REDIRECT_HEADER (sends a 'Location: URL' header), REDIRECT_REFRESH (sends a 'Refresh: 0;URL=URL' header), REDIRECT_META (sends a '<meta http-equiv="Refresh" ... />' header).

Please note that these are not strings. Correct usage is.. $phase->sendRedirect('URL', REDIRECT_HEADER);

Note that in 99.9% of cases you will not have to specify the second parameter.


string $phase->snippetName(); (implemented)
Returns the name of the snippet that calls it, that is, the current snippet. Returns FALSE if cannot be retrieved for some reason (unlikely).

bool $phase->clearCache(); (implemented)
Clears the cache. Returns true on succes, False on failure. Note: this, like all snippets, will not work in cached pages.

mixed $phase->getParent([$pid=0, $active=1, $fields='id, pagetitle, description, alias, parent']); (implemented)
Gets some info about the current document's parent. Alternatively, you can specify a different document to do this for, whether the parent must be active to be returned (i.e. published and not deleted), and which fields you want to retrieve. $phase->getParent will return an array with the id, pagetitle, alias and parent of the current document's parent, unless of course the current document is in the root, in which case it will return false.

mixed $phase->makeList($array [, $ulroot='', $ulprefix='', $type='', $ordered=false]); (implemented, but may be removed)
Takes the array passed, and returns it as a (HTML) string containing an unordered list (or an ordered list, if $ordered is true), the type of list (alpha, roman numerals etc) can be set with $type, and $ulroot, if set, is the ID written into the first ul root. Any sub ul's after that are named the same, prepended with $ulprefix.

mixed $phase->getUserData(); (implemented)
Returns an array containg information about the visitors browser. A lot of information is returned in the array. Here's a screenshot of a simple dump I made of the array:

Posted Image

This API function uses the excellent phpSniff class!



mixed $phase->isManagerLoggedIn(); (implemented)
Gets if the user is logged into the manager or not. Good for inline editing and such. Returns an array containing id => userid, username => username, or false if not logged in.

mixed $phase->putChunk($chunkName); (implemented)
Returns the html contained in chunk $chunkName, or '' if it doesn't exist.

mixed $phase->evalSnippet($snippetName, $parameters); (implemented) :)
Runs the snippet named $snippetName, and returns the output string, or False if the snippet doesn't exist or fails (which will stop the parser). You can parameters to the snippet as an array:
$parameters = array("id" => 5, "text" => "this is a test");


mixed $phase->changeTemplate($templateName); (not yet implemented)
Switches from the current template to $templateName, and re-parses the document (this may affect generation time somewhat). Returns false if the template doesn't exist. This is still in the planning stage, and may or may not be implemented.

mixed $phase->getKeywords($id=0); (implemented)
Retrieves an array containing the keywords referenced to the current document. If you specify an $id in the function call, the keywords referenced to that $id will be retrieved.


mixed $phase->getStats([$scope="document" [, $id=0]]); (implemented)
Retrieves an array containing visit statistics for the document, or for the whole site. If it is called without any parameters, it gets the statistics for the current document. If it is called with $scope="document", and the $id of another document, it gets the hits for that document. If it is called with $scope="site", it retrieves the stats for the entire site. For documents, it retrieves the following information: unique visitors today, unique visitors this month, unique visitors all time. For the whole site, it gets the same information, plus the following: visits today, visits this month, visits all time. I may expand this to allow you to specify a time range (i.e. get all the information on this document for from 1-1-2004 to 1-2-2004). If I do, the dates you pass will need to be php timestamps.

Also note: If the document containing this snippet is cached, then the results will be cached too, which means they won't update with every page impression, only when the cache is emptied.


Now I'd like to hear if you have any suggestions for other API calls you might find helpful. Be sure to describe the variables, and give a concise, detailed of the expected functionality of the function.

Oh yeah, don't worry, exisiting snippets will still work :)
(although once you've translated your snippets, you can turn 'old snippet support' off, for improved speed. I've been mucking around with this for a week now, and translating old snippets to new snippets is very, very easy :)

P.S. Since editing a post doesn't bump the topic as new posts, every time the post is updated, the number in the subject will increase by one. -Snuffkin

#2 Snuffkin

Snuffkin

    Likes Etomite Forums!

  • Member
  • PipPip
  • 236 posts

Posted 22 May 2004 - 05:20 PM

The new API is looking good. :)

0.6 will be a fantastic release...

#3 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 22 May 2004 - 05:35 PM

Your new avatar...

Must... use... Phase...

You win first prize in the avatar competition :)

#4 Snuffkin

Snuffkin

    Likes Etomite Forums!

  • Member
  • PipPip
  • 236 posts

Posted 22 May 2004 - 05:50 PM

Mwah...

#5 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 22 May 2004 - 05:55 PM

Everybody please note:

The Phase Forums Management cannot and will not be held responsible for any detrimental effects suffered by extended staring at Snuffkin's avatar!

#6 Snuffkin

Snuffkin

    Likes Etomite Forums!

  • Member
  • PipPip
  • 236 posts

Posted 22 May 2004 - 06:12 PM

I was just thinking about that :lol:

#7 Guest_littlehouse_*

Guest_littlehouse_*
  • Guests

Posted 24 June 2004 - 11:54 AM

array $phase->getUserInfo();
Return informations about who's the visitor (username, Date_of_last_visit..., group, browser, Os)

mixed $phase->Make_Input_field(Kind_of_field, value);

set-up a form element as a file-upload field or a htmlarea input field

mixed $phase->Make_unordered_list(php_array, id, prefix)

setup an <ul> list from a php array
id= the id of the root ul element
prefix= the prefix for the descendants
ex:
<ul id=father>

<li>one</li>

<li>two

  <ul id="sub_father">

   <li>a</li>

   <li>b

    <ul id="sub_sub_father">

         <li>I</li>

          <li>II</li>

     </ul></li>

    <li>c</li>

    </ul></li>

<li> three</li>

</ul>


#8 modules

modules

    Etomite Forum Newbie

  • Member
  • 49 posts

Posted 24 June 2004 - 12:23 PM

array $phase->getUserInfo();  
Return informations about who's the visitor (username, Date_of_last_visit..., group, browser, Os)

As far as I know, there are only backend users.

mixed $phase->Make_unordered_list(php_array, id, prefix)


That is a nice idea. Would be cool to have something like this.

Regards, Tobias.

#9 Guest_littlehouse_*

Guest_littlehouse_*
  • Guests

Posted 24 June 2004 - 01:28 PM

GetUserInfo()

As far as I know, there are only backend users.


Two reasons for this api
1) sniff the browser to get informations as lang and display capability
2) display or not the content according to the new access-policy (maybe I mis-understood the point explained in the future-request)

#10 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 25 June 2004 - 07:29 AM

GetUserInfo()

As far as I know, there are only backend users.


Two reasons for this api
1) sniff the browser to get informations as lang and display capability
2) display or not the content according to the new access-policy (maybe I mis-understood the point explained in the future-request)


Might do this one, although I'll probably call it something else. Not sure though, yet. But keep 'em coming :)

The list one is pretty much the same, nice idea, might do this at some point. It would be pretty handy, but what to do if the array is multidimensional?

#11 modules

modules

    Etomite Forum Newbie

  • Member
  • 49 posts

Posted 25 June 2004 - 08:43 AM

The list one is pretty much the same, nice idea, might do this at some point. It would be pretty handy, but what to do if the array is multidimensional?


$data = array(

    'first',

    'second',

    'third');



<ul>

  <li>first</li>

  <li>second</li>

  <li>third</li>

</ul>





$data = array(

    'first' => array(

        'first_first',

        'first_second',

        'first_third'),

    'second',

    'third');



<ul>

  <li>first

    <ul>

      <li>first_first</li>

      <li>first_second</li>

      <li>first_third</li>

    </ul>

  </li>

  <li>second</li>

  <li>third</li>

</ul>



...

Regards, Tobias.

#12 Guest_littlehouse_*

Guest_littlehouse_*
  • Guests

Posted 25 June 2004 - 10:24 AM

exactly.
Not sure but I think that the smarty debug console use something similar to render the snapshot of all variables.

#13 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 25 June 2004 - 11:00 AM

The list one is pretty much the same, nice idea, might do this at some point. It would be pretty handy, but what to do if the array is multidimensional?


Snip!


Regards, Tobias.


D'oh, of course! Should have thought of that myself. :|

#14 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 26 June 2004 - 02:23 PM

OK, pretty much got makeList() done. Example:

$data = array( 

    'first level' => array('first sub level' => array('first sub sub level', 'second sub sub level'),

           'second sub level',

           'third sub level'), 

    'second level', 

    'third level');



return $phase->makeList($data, 'root', 'sub_', 'upper-alpha', false, 0);

This passes the array $data to the function, sets the class name for the root to 'root', adds 'sub_' before any sub roots, formats the list style as upper-alpha, false means it's not an ordered list (so it's UL instead of OL), and the 0 specifies the starting tab level (for indenting in source code).

Output:

Posted Image

Source:

Posted Image

Is this what you meant? :)

#15 Snuffkin

Snuffkin

    Likes Etomite Forums!

  • Member
  • PipPip
  • 236 posts

Posted 26 June 2004 - 03:03 PM

array $phase->getUserInfo();  
Return informations about who's the visitor (username - nope, Date_of_last_visit... - nope, group - nope, browser - maybe, OS - maybe)

mixed $phase->Make_Input_field(Kind_of_field, value);

set-up a form element as a file-upload field or a htmlarea input field
No. All HTML is the administrator's responsibility and it should be under his power to control it.

mixed $phase->Make_unordered_list(php_array, id, prefix)
Same. Bottom line is, if you want it, make it a snippet or write your own function.

See italics.

Anyway, I've my own suggestion:

$phase->isManagerLoggedIn();
Gets if the user is logged into the manager or not. Good for inline editing and such. Returns an array containing id => userid, username => username, or false if not logged in.

#16 modules

modules

    Etomite Forum Newbie

  • Member
  • 49 posts

Posted 26 June 2004 - 03:48 PM

$phase->isManagerLoggedIn();
 Gets if the user is logged into the manager or not. Good for inline editing and such.


/me would also like to see this feature.

Regards, Tobias.

#17 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 26 June 2004 - 11:56 PM

Inline editing...?

Erm... not too keen on that...

ManagerLoggedInThing: already in there, as an internal call. I'll extend it into the API.

makeList: already coded it. I'll prolly leave it in. Dunno yet though.

makeField: not going to happen. There will, however, be a form builder at some point.

#18 Snuffkin

Snuffkin

    Likes Etomite Forums!

  • Member
  • PipPip
  • 236 posts

Posted 27 June 2004 - 09:13 AM

Nah, talking about if people want to implement it themselves.

#19 Guest_Alex_*

Guest_Alex_*
  • Guests

Posted 27 June 2004 - 07:45 PM

ManagerLoggedInThing: already in there, as an internal call. I'll extend it into the API.


Done.

#20 modules

modules

    Etomite Forum Newbie

  • Member
  • 49 posts

Posted 27 June 2004 - 08:44 PM

Is this what you meant? :)


yeap. thats a nice one :)

Regards, Tobias.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users