Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function: The better menu_data(), zegnat_menu_data()!
#1
The more new things you want to do with menu_data() the more outdated the function feels. This is not so weird, menu_data() has changed very little since the initial GetSimple release. So for my (currently being updated) menu plugin I sat down and rewrote the whole thing.

——— ——— ——— –—— –——

The function:

Code:
zegnat_menu_data($xml=true, $elements=array(), $overwrite=false);
Any or all arguments can be ommitted.

——— ——— ——— –—— –——

Changes from the original menu_data():
  • It went from about 95 to 40 lines of code.
    Why? It just did. This probably because a lot of data has become more flexible instead of all inputs being hard-coded into the function.



  • The ability to only output the information for 1 page is removed.
    Why? I created this function so it would be easy to create menus. menu_data() should not have been used for getting 1 page’s information anyway.



  • The standard output is now a SimpleXML Object.
    Why? GetSimple takes pride in storing everything away in the form of XML. Returning the data in the form of XML also means you can use XPath to walk through it.



  • All file names starting with a dot (.) are ignored. No separate checking for ., .. or .htaccess anymore.
    Why? All hidden files in non-Windows file systems start with a dot, these should not be treated as pages.



  • Not only private files but also files that do not have the menu box checked are skipped.
    Why? We are collecting data for a menu, so I don’t see why it should return information about items that are not going to be used.



  • It will never output an empty ‘menu’ element.
    Why? GetSimple assumes an empty ‘menu’ to be the same as the value for ‘title’, everywhere. So now the function returns it as such.



  • Some elements are no longer outputted by default.
    Which? ‘title’ would not be needed, for menus because we get ‘menu’. Both ‘private’ and ‘menuStatus’ are taken away as well. If you still want it, use the functions second argument as described below.

——— ——— ——— –—— –——

The different arguments:
  • $xml
    By setting this one to false the function will return an array instead of a Simple XML Object.



  • $elements
    Here you can supply an array() stating one or more names of the elements from the page’s XML-file that should be included in the output. These will by default extend on the standard output. This way you can get information such as custom tags to be included.


    Keep in mind that the function defines ‘slug’ as what the XML-file calls for ‘url’ and ‘url’ is the actual linkable address for the page.



  • $overwrite
    By setting this one to true the function will only return elements defined by $elements. Otherwise it takes all the standard elements and supplements these with those defined by $elements.

——— ——— ——— –—— –——

Examples:

Code:
zegnat_menu_data(false,array('url'),true)
$xml = false ⇒ The output will be a normal array.
$elements = array('url') ⇒ We want to make sure we’re getting the page URL.
$overwrite = true ⇒ We only want to get the elements we defined, only the URLs.
Code:
array(1) {
  [0]=>
  array(1) {
    ["url"]=>
    string(32) "http://localhost/GetSimple/"
  }
}

——— ——— ——— –—— –——

How to use it:

You’ll find a ZIP-archive attached to this post containing the latest version of the function. Unzip it and put the resulting PHP-file anywhere you want. Now include the PHP file somewhere in your code.

The file will check whether the function already exists or not to prevent double defining of functions. This means you can safely bundle the PHP-file with your plugin without it breaking the users GetSimple installation in case an other plugin was already using it.

——— ——— ——— –—— –——

FAQ:
  • Is this going to be included in the next version of GetSimple?
    The official answer is no.



  • How is it licensed?
    If you download it you are licensed to include it somewhere in your website and make use of the function. You are also allowed to bundle the file with your plugin, but only if you make your plugin publicly available on this forum. You do not have the right to distribute it in any other way or sell it. If you wish to do something not defined (and therefore not allowed) by this license don’t hesitate to contact me.


    Normal (international) copyright law applies, so yes, I can state the above and it will (should) hold in court.
“Don’t forget the important ˚ (not °) on the a,” says the Unicode lover.
Help us test a key change for the core! ¶ Problems with GetSimple? Be sure to enable debug mode!
Reply
#2
How about having this function ignore any file that does not have the extension 'xml', rather than just those starting with '.'?
-- Sam
Reply
#3
Sorry, I do in PHP - 0, could you explain where to put the file and where and how to turn it on?
Reply
#4
Oleg06,

Just like menu_data(), zegnat_menu_data() is a function that can be useful for developers.

They can be used as a base for creating plugins or functions. Both return the menu structure, but do nothing else. :-)
Reply
#5
thanks :-(
Reply
#6
:-?
Did you expect anything?
Reply
#7
just wanted to know why this file needs ...
By the way, I still have not learned to use and plug-in "CustomFields" :-D
Reply




Users browsing this thread: 1 Guest(s)