User Tools

Site Tools


plugins:tips

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
plugins:tips [2011/03/20 11:18]
mvlcek created
plugins:tips [2014/02/07 10:07] (current)
datiswous [Working around the broken sitewide cookies in GS 3.0]
Line 1: Line 1:
 ====== Tips & Tricks for Developers ====== ====== Tips & Tricks for Developers ======
 +
 +If you are a plugin developer, you should be aware of the new update system that is being integrated into GetSimple 3.1. Starting with this release, the GetSimple installation will now notify a user when a new version of that particular plugin is available for download within Extend. [[plugins:​update notifications|These steps]] will help you as a developer to ensure that your plugin is compatible with this new process. ​
  
 ===== Determining the GetSimple Version ===== ===== Determining the GetSimple Version =====
Line 5: Line 7:
 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  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 
  
-<​code>​+<​code ​php>
 $isV3 = function_exists('​get_site_version'​);​ $isV3 = function_exists('​get_site_version'​);​
 </​code>​ </​code>​
Line 11: Line 13:
 The probably most correct one is (only use within function, in order not to pollute the global name space!) The probably most correct one is (only use within function, in order not to pollute the global name space!)
  
-<​code>​+<​code ​php>
 include(GSADMININCPATH.'​configuration.php'​);​ include(GSADMININCPATH.'​configuration.php'​);​
 $version = GSVERSION; $version = GSVERSION;
Line 20: Line 22:
 To trigger a function myplugin_function on page deletes in GetSimple 2.03 and 3.0+ use the following code: To trigger a function myplugin_function on page deletes in GetSimple 2.03 and 3.0+ use the following code:
  
-<​code>​+<​code ​php>
 // GetSimple 3.0+ // GetSimple 3.0+
 add_action('​page-delete',​ '​myplugin_function'​); ​ add_action('​page-delete',​ '​myplugin_function'​); ​
Line 30: Line 32:
 </​code>​ </​code>​
  
 +===== 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:
 +
 +<code php>
 +<?​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 ​
 +  } 
 +?>
 +</​code>​
 +
 +===== Displaying custom and localized Dates  =====
 +
 +The publication date in the page XML files is stored in an english text format, which can be converted to a UNIX timestamp with
 +
 +<code php>
 +$timestamp = strtotime($data->​pubDate);​
 +</​code>​
 +
 +GetSimple itself uses the ''​date''​ function to display dates, which will work with other languages only when no weekday or month names are displayed, as these will always be in english.
 +
 +To display a truly localized date, use:
 +
 +<code php>
 +$dateLocale = '​de_DE,​de,​ger,​deu'; ​     // or use $LANG or a setting in your plugin, ​
 +                                       // for OS compatibility multiple locales should be possible
 +$dateFormat = "%A, %d.%m.%Y - %H:​%M"; ​ // should be a entry in the i18n language file of your plugin
 +                                       // for the format see PHP function strftime
 +$oldlocale = setLocale(LC_TIME,​ '​0'​); ​ // save old locale
 +setlocale(LC_TIME,​ preg_split('/​s*,​s*/',​ $dateLocale))
 +echo strftime($dateFormat,​ $date); ​    // $date is a UNIX timestamp
 +setLocale(LC_TIME,​ $oldlocale); ​       // restore old locale
 +</​code>​
 +
 +===== Working around the broken sitewide cookies in GS 3.0 =====
 +
 +The important cookie is only valid for path /admin.
 +There is no (easy?) way to correct the problem for the frontend.
 +However, if you need it for the backend, e.g. linking to a php somewhere in the plugins folder, you can add the following code to your plugin (e.g. directly after setting up the hooks):
 +
 +<code php>
 +if (!myplugin_is_frontend() && myplugin_gsversion() == '​3.0'​) {
 +  // workaround for GetSimple 3.0:
 +  if (isset($_COOKIE['​GS_ADMIN_USERNAME'​])) setcookie('​GS_ADMIN_USERNAME',​ $_COOKIE['​GS_ADMIN_USERNAME'​],​ 0, '/'​);​
 +}
 +
 +function myplugin_is_frontend() {
 +  return function_exists('​get_site_url'​);​
 +}
 +
 +function myplugin_gsversion() {
 +  @include(GSADMININCPATH.'​configuration.php'​);​
 +  return GSVERSION;
 +}
 +</​code>​
 +Replace //​myplugin//​ with your plugin name.
  
plugins/tips.1300619910.txt.gz ยท Last modified: 2013/04/19 14:57 (external edit)