Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function: is_component() and return_component().
#1
For those times you need to test the existence of a component or run some extra code on it before executing.

is_component()

Pass the id of the component to this function. It will return either true or false, depending on whether the component exists.
Code:
function is_component($id) {
    if (file_exists(GSDATAOTHERPATH.'components.xml')) {
        $d = getXML(GSDATAOTHERPATH.'components.xml');
        return count($d->xpath('//item[slug="'.$id.'"]'))>0?true:false;
    }
}

return_component()

Pass the id of the component to this function. It will return either the contents of the component in the form of a string or false, depending on whether the component exists.
Code:
function return_component($id) {
    if (file_exists(GSDATAOTHERPATH.'components.xml')) {
        $d = getXML(GSDATAOTHERPATH.'components.xml');
        $v = $d->xpath('//item[slug="'.$id.'"]/value');
        return !$v?false:stripslashes(htmlspecialchars_decode((string)$v[0],ENT_QUOTES));
    }
}

Can I use it with the per page components function?

I do not think this is compatible with my per page components function, but I didn’t test it. I will not work on making it compatible if it isn’t because these two functions should be seen as extensions to the core functions and not as extensions to another extension.
“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




Users browsing this thread: 1 Guest(s)