User Tools

Site Tools


plugins:tips

This is an old revision of the document!


Tips & Tricks for Developers

Determining the GetSimple Version

Determining the GetSimple version is not as straight forward as it could be, as the only available function in 2.03 - return_site_ver() - outputs the version in 2.03 and returns it in 3.0b (deprecated here). The easiest way to find out, if a plugin is installed on GetSimple 2.03 or 3.0+ seems to be

$isV3 = function_exists('get_site_version');

The probably most correct one is (only use within function, in order not to pollute the global name space!)

include(GSADMININCPATH.'configuration.php');
$version = GSVERSION;

Working around the Lack of a Page-Delete Hook in 2.03

To trigger a function myplugin_function on page deletes in GetSimple 2.03 and 3.0+ use the following code:

// GetSimple 3.0+
add_action('page-delete', 'myplugin_function'); 

// GetSimple 2.03
if (!function_exists('get_site_version') && basename($_SERVER['PHP_SELF']) == 'deletefile.php') {
  myplugin_function();
}

Success and Error Messages

This describes how to display messages in back-end plugin pages. Assume you have 3 variables, $isSuccess, $canUndo and $msg holding the message. To display the message for your plugin myplugin, add the following code to your plugin:

<?php 
  if (isset($msg)) {
    if ($canUndo) $msg .= ' <a href="load.php?id=myplugin&undo">' . i18n_r('UNDO') . '</a>' 
?>
<script type="text/javascript">
  $(function() {
    $('div.bodycontent').before('<div class="<?php echo $isSuccess ? 'updated' : 'error'; ?>" style="display:block;">'+
            <?php echo json_encode($msg); ?>+'</div>');
    $(".updated, .error").fadeOut(500).fadeIn(500);
  });
</script>
<?php 
  } 
?>
plugins/tips.1300654058.txt.gz · Last modified: 2013/04/19 14:57 (external edit)