DokuWiki

It's better when it's simple

User Tools

Site Tools


plugin:usersubscriptions

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
plugin:usersubscriptions [2010-08-09 09:22] – [2009-11-30] 82.210.255.132plugin:usersubscriptions [2019-08-11 18:14] – a new download link Aleksandr
Line 1: Line 1:
-====== usersubscriptions plugin ======+====== usersubscriptions Plugin ======
  
 ---- plugin ---- ---- plugin ----
-description: allows connected user to see which pages / namespaces he have subscribed to and to subscribe or unsubscribe in a quick way+description: Allows connected user to see which pages / namespaces he have subscribed to and to subscribe or unsubscribe in a quick way
 author     : Etienne Meleard author     : Etienne Meleard
 email      : etienne.meleard@free.fr email      : etienne.meleard@free.fr
Line 12: Line 12:
 similar    : listeabo similar    : listeabo
 tags       : subscription listing syntax tags       : subscription listing syntax
----- 
  
-^ Download | [[http://dokuwiki.yent.eu/usersubscriptions.zip|usersubscriptions.zip]] |+downloadurl: https://trello-attachments.s3.amazonaws.com/5af4815352fa15728c62aaae/5d503d902dd91087fcb95e97/3b886f7022eedd08271de220d547829c/usersubscriptions.zip 
 +bugtracker :  
 +sourcerepo :  
 +donationurl:  
 + 
 +screenshot_img:  
 +----
  
 ===== Description ===== ===== Description =====
  
-The Syntax [[plugins|Plugin]] allows to display the subscription list of the current user. It can display list for a specific namespace, the current namespace or all namespaces. In addition, it provides a quick way to subscribe or unsubscribe.+The Syntax Plugin allows to display the subscription list of the current user. It can display list for a specific namespace, the current namespace or all namespaces. In addition, it provides a quick way to subscribe or unsubscribe.
  
-//2009-01-27 Added ACL check for quick subscribe dropdown filling//\\  +  * 2010-09-24merged some patches (thx to "MR") and fixed caching issue 
-//2009-01-26 : inherited subscription display option added, recursive parent subscription check fixed//\\  +  2009-09-15: added template for easy styling, fixed some bugs (img paths...) and added regexp based item exclusion (for _template, sidebar...) 
-//2009-09-15 : added template for easy styling, fixed some bugs (img paths ...) and added regexp based item exclusion (for _template, sidebar ...)//\\ +  * 2009-01-27: Added ACL check for quick subscribe dropdown filling 
 +  * 2009-01-26: inherited subscription display option added, recursive parent subscription check fixed
  
-//En, De, Pt, Es and Fr lang files included, translations are welcome ...//\\ +//En, De, Pt, Es and Fr lang files included, translations are welcome...//
  
 //**Many thanks to Thomas and Mark for the De lang file, to RC for Pt lang file and to Federico for Es lang file**// //**Many thanks to Thomas and Mark for the De lang file, to RC for Pt lang file and to Federico for Es lang file**//
Line 32: Line 38:
   <usersubscriptions [ns] [r[=[N]]] [deletelink] [quicksubscribe] [displayinheritedsubscriptions] />   <usersubscriptions [ns] [r[=[N]]] [deletelink] [quicksubscribe] [displayinheritedsubscriptions] />
  
-  * [ns] base namespace, MUST BE PRESENT IF OTHER OPTIONS ARE USED\\ Can be either empty or . for targeting the current namespace,\\ * for targeting all namespaces or a specific namespace\\ (must be absolute) +  * ''[ns]'' --- base namespace, MUST BE PRESENT IF OTHER OPTIONS ARE USED.\\ Can be either empty or\\ ''.'' for targeting the current namespace,\\ ''*'' for targeting all namespaces or a specific namespace (must be absolute) 
-  * [r[=[N]]] recursive option, if only "ror "r=are mentioned the\\ maximum depth is infinite, if a number is passed it indicates\\ how much successive namespaces will be explored\\ (ex : r=0 means only the current namespace, r=3 means 3 levels in depth) +  * ''[r[=[N]]]'' --- recursive option, if only ''r'' or ''r='' are mentioned the maximum depth is infinite, if a number is passed it indicates how much successive namespaces will be explored (ex.''r=0'' means only the current namespace, ''r=3'' means 3 levels in depth) 
-  * [deletelink] if present a link to unsubscribe is displayed +  * ''[deletelink]'' --- if present a link to unsubscribe is displayed 
-  * [quicksubscribe] if present a form is displayed to allow the user\\ to quick-subscribe +  * ''[quicksubscribe]'' --- if present a form is displayed to allow the user to quick-subscribe 
-  * [displayinheritedsubscriptions] if present elements that are subscribed\\ because the user subscribed to a parent namespace.+  * ''[displayinheritedsubscriptions]'' --- if present elements that are subscribed because the user subscribed to a parent namespace.
  
  
 ===== Download and Installation ===== ===== Download and Installation =====
  
-Download and install the plugin using the [[plugin:plugin|Plugin Manager]] using the following URL. Refer to [[:Plugins]] on how to install plugins manually.+Search and install the plugin using the [[plugin:extension|Extension Manager]]. Refer to [[:Plugins]] on how to install plugins manually.
  
-  * [[http://dokuwiki.yent.eu/usersubscriptions.zip]]+  * [[https://trello-attachments.s3.amazonaws.com/5af4815352fa15728c62aaae/5d503d902dd91087fcb95e97/3b886f7022eedd08271de220d547829c/usersubscriptions.zip|usersubscriptions.zip]]
  
 ==== Translations ==== ==== Translations ====
  
 ===== Screenshot ===== ===== Screenshot =====
-   Generated by putting <usersubscriptions * r deletelink quicksubscribe /> in the page. 
  
-{{ http://dokuwiki.yent.eu/usersubscriptions_screenshot.png?nocache }}+Generated by putting ''<usersubscriptions * r deletelink quicksubscribe />'' in the page.
  
-===== Sources =====+{{ https://trello-attachments.s3.amazonaws.com/5af4815352fa15728c62aaae/5d503d902dd91087fcb95e97/94da646037bba57eebd3b2bbee011665/usersubscriptions_screenshot.png }}
  
-==== syntax.php ====+===== Discussion =====
  
-<code php> +==== 2009-05-01 ====
-<?php +
-/** +
- * User Subscriptions Plugin: allows connected user to see which pages / namespaces he have subscribed to and to subscribe or unsubscribe in a quick way +
- * +
- * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html) +
- * @author     Etienne Meleard <etienne.meleard@free.fr> +
- *  +
- 2009/01/23 : Creation +
- * 2009/01/26 : inherited subscription display option added, recursive parent subscription check fixed +
- * 2009/01/27 : Added ACL check for quick subscribe dropdown filling +
- */ +
-  +
-if(!defined('DOKU_INC')) define('DOKU_INC',realpath(dirname(__FILE__).'/../../').'/'); +
-if(!defined('DOKU_PLUGIN')) define('DOKU_PLUGIN',DOKU_INC.'lib/plugins/'); +
-require_once(DOKU_PLUGIN.'syntax.php'); +
-  +
-/** +
- * All DokuWiki plugins to extend the parser/rendering mechanism +
- * need to inherit from this class +
- */ +
-class syntax_plugin_usersubscriptions extends DokuWiki_Syntax_Plugin { +
-  +
- /** +
- * return some info +
- */ +
- function getInfo(){ +
- return confToHash(dirname(__FILE__).'/INFO'); +
-+
-  +
- function getType(){ return 'substition';+
- function getPType(){ return 'block';+
- function getSort(){ return 167; } +
-  +
- /** +
- * Connect pattern to lexer +
- */ +
- function connectTo($mode){ +
- $this->Lexer->addSpecialPattern('<usersubscriptions [^/]*/>', $mode, 'plugin_usersubscriptions'); +
- }+
  
- /** 
- * Handle the match 
- */ 
- function handle($match, $state, $pos, &$handler) { 
- $match = strtolower(trim(substr($match, 19, -2))); 
- $options = preg_split('/\s/u', $match); 
- $recursive = false; 
- $deletelink = false; 
- $quicksubscribe = false; 
- $displayinheritedsubscriptions = false; 
- $ns = ''; 
- if(count($options) > 0) { 
- $ns = trim($options[0]); 
- if(count($options) > 1) { 
- $os = array_slice($options, 1); 
- $opts = array(); 
- for($i=0; $i<count($os); $i++) { 
- $o = explode('=', $os[$i]); 
- $opts[$o[0]] = isset($o[1]) ? $o[1] : true;; 
- } 
- $recursive = isset($opts['r']) ? $opts['r'] : 0; 
- if(!is_numeric($recursive)) $recursive = -2; 
- $deletelink = isset($opts['deletelink']); 
- $quicksubscribe = isset($opts['quicksubscribe']); 
- $displayinheritedsubscriptions = isset($opts['displayinheritedsubscriptions']); 
- } 
- } 
- return array($ns, $recursive, $deletelink, $quicksubscribe, $displayinheritedsubscriptions); 
- } 
- 
- /** 
- * Create output 
- */ 
- function render($mode, &$renderer, $data) { 
- global $INFO; 
- if(($mode == 'xhtml') && isset($INFO['userinfo'])) { 
- global $ID; 
-  
- $ns = $data[0]; 
- $recursive = $data[1]; 
- $deletelink = $data[2]; 
- $quicksubscribe = $data[3]; 
- $displayinheritedsubscriptions = $data[4]; 
-  
- // prevent caching to ensure the subscriptions list is fresh 
- $renderer->info['cache'] = false; 
-  
- $status = ''; 
-  
- // check if user requested a subscription deletion 
- if($unsubscribe = $_REQUEST['pluginusersubscriptions_unsubscribe']) { 
- // user chooses to unsubscribe -> update mlist file 
- list($type, $id) = preg_split('/-/u', $unsubscribe, 2); 
- if($type == 'pg') { 
- $file = metaFN($id, '.mlist'); 
- }else{ 
- if(!getNS($id)) { 
- $file = metaFN(getNS($id), '.mlist'); 
- }else{ 
- $file = metaFN(getNS($id), '/.mlist'); 
- } 
- } 
- if(@file_exists($file)) { 
- $status = io_deleteFromFile($file, $INFO['client']."\n") ? 'success' : 'failure'; 
- } 
- } 
-  
- // check if user requested a new subscription 
- if($subscribe = $_REQUEST['pluginusersubscriptions_subscribe']) { 
- if($subscribe != '') { 
- // user chooses to subscribe -> update mlist file 
- list($type, $id) = preg_split('/-/u', $subscribe, 2); 
- if(auth_quickaclcheck($id) >= AUTH_READ) { 
- if($type == 'pg') { 
- $file = metaFN($id, '.mlist'); 
- $update = !is_subscribed($id, $INFO['client'], false); 
- }else{ 
- $file = metaFN($id, '/.mlist'); 
- $update = !is_subscribed($id.':', $INFO['client'], true); 
- } 
- if($update) { 
- $status = io_saveFile($file, $INFO['client']."\n", @file_exists($file)) ? 'success' : 'failure'; 
- } 
- } 
- } 
- }  
-           
- // output the list 
-  
- if($ns == '' || $ns == '.') { 
- $nss = $this->getLang('current_namespace'); 
- $ns = getNS($ID); 
- }else if($ns == '*') { 
- $nss = $this->getLang('all_namespaces'); 
- $ns = ''; 
- }else $nss = $this->getLang('the_namespace').' '.$fmtns; 
-  
- // get subscriptions 
- $elements = array(); 
-  
- $elements = $this->_getUserSubscriptions($ns, $recursive); 
- ksort($elements); 
-  
- $tius = false; 
- $usersubscriptions = array(); 
- foreach($elements as $id => $info) { 
- $info['inheritedsubscription'] = $info['subscribedfromparent'] && !$info['selfsubscribed']; 
-  
- $info['deleteoption'] = $info['selfsubscribed'] && $deletelink; 
- $info['display'] = $info['usersubscribed'] && ($displayinheritedsubscriptions || (!$displayinheritedsubscriptions && $info['selfsubscribed'])); 
- $id = preg_replace('/:$/', '', $id); 
- $usersubscriptions[$id] = $info; 
- } 
-  
- if(file_exists(DOKU_TPLINC.'usersubscriptions.tpl.php')) include DOKU_TPLINC.'usersubscriptions.tpl.php'; 
- else include DOKU_PLUGIN.'usersubscriptions/usersubscriptions.tpl.php'; 
-  
- return true; 
- } 
-    return false; 
- } 
-  
- function _getUserSubscriptions($ns, $recursive, $lvl=0, $nss=false) { 
- global $INFO; 
- $us = array(); 
- $exclude = array( 
- '`\_+template\.txt:?$`', 
- '`sidebar\.txt:?$`' 
- ); 
- $isns = !preg_match('/\.txt:$/', $ns); 
- foreach($exclude as $r) if(preg_match($r, $ns)) return $us; 
- if(auth_quickaclcheck($ns) < AUTH_READ) return $us; 
- $cns = preg_replace('/\.txt:$/', '', $ns); 
- $s = is_subscribed($cns, $INFO['client'], false); 
- $sns = is_subscribed($cns, $INFO['client'], true); 
- $us[$cns] = array( 
- 'isnamespace' => $isns, 
- 'usersubscribed' => ($s || $sns || $nss), 
- 'selfsubscribed' => ($isns && $sns) || (!$isns && $s), 
- 'subscribedfromparent' => (!$isns && $sns) || $nss, 
- 'lvl' => $lvl 
- ); 
- if($ns == $cns) { 
- foreach(new DirectoryIterator(preg_replace('/\.txt$/', '', wikiFN($cns))) as $item) { 
- if(!$item->isDot() && ($recursive != -1)) { 
- $scns = strtolower($cns.$item->getFilename().':'); 
- if($item->isFile() && !preg_match('/\.txt:?$/', $scns)) continue; 
- $us = array_merge($us, $this->_getUserSubscriptions($scns, $recursive-1, $lvl+1, $nss || ($sns && !$s))); 
- } 
- } 
- } 
- return $us; 
- } 
-} 
- 
-?> 
-</code> 
- 
-==== usersubscriptions.tpl.php ==== 
- 
-<code php> 
-<?php 
- // DEFAULT TEMPLATE FOR THE USERSUBSCRIPTIONS PLUGIN 
- // You can copy it to your current template directory to customize it 
-  
- /* Useful variables and methods available in the template : 
- * $deletelink (bool) : tells whether delete subscription link must be active 
- * $nss (string) : contains the name of the base namespace specified in plugin parameters 
- * $status (string) : contains nothing if no action was triggered, "success" or "failure" otherwise, usable for CSS class selection for example 
- * $this->getLang(FLAG) : returns localized string from lang files 
- * $usersubscriptions (array) : contains the list of subscriptions to display, with ns path as id and fields : 
- * usersubscribed (bool) : tells whether the user subscribed to the namespace (directly or inherited) 
- * selfsubscribed (bool) : tells whether the user subscribed directly to the namespace 
- * subscribedfromparent (bool) : tells whether the user subscribed to a parent namespace of the namespace 
- * inheritedsubscription (bool) : tells whether the user only subscribed to a parent namespace of the namespace and not directly to it 
- * itemdelete (bool) : tells whether the delete subscription link can be displayed 
- * isnamespace (bool) : tells whether id refers to a page or a namespace 
- 
- * $quicksubscribe (bool) : tells whether the quicksubscribe panel must be displayed 
- */ 
-?> 
-<a name="usersubscriptions_anchor"></a> 
-<table class="usersubscriptions"> 
- <tr> 
- <th colspan="<?php echo $deletelink ? '2' : '1'; ?>" class="usersubscriptions_namespace"><?php echo $renderer->_xmlEntities($nss); ?></th> 
- </tr> 
-<?php if($status != '') { ?> 
- <tr> 
- <td colspan="<?php echo $deletelink ? '2' : '1'; ?>" class="usersubscriptions_nothing usersubscription_<?php echo $status; ?>"><?php echo $this->getLang('usersubscription_'.$status); ?></td> 
- </tr> 
-<?php } 
-foreach($usersubscriptions as $id => $info) { 
- if(!$info['display']) continue; // skips not displayable items 
-?> 
- <tr> 
- <td> 
- <p class="usersubscriptions_description"> 
- <a href="<?php echo wl($id); ?>"> 
- <img src="<?php echo DOKU_BASE; ?>lib/plugins/usersubscriptions/images/<?php echo $info['isnamespace'] ? 'namespace' : 'page'; ?>.png" alt="<?php echo $this->getLang($info['isnamespace'] ? 'it_is_a_namespace' : 'it_is_a_page'); ?>" title="<?php echo $this->getLang($info['isnamespace'] ? 'it_is_a_namespace' : 'it_is_a_page'); ?>" /> 
- </a> 
- <span class="usersubscriptions_id"> 
- <a href="<?php echo wl($id); ?>"><?php echo ($id != '') ? $id : $this->getLang('quick_subscription_root'); ?></a> 
- </span> 
- <br /> 
- <?php echo $info['inheritedsubscription'] ? $this->getLang('because_parent_ns_subscribed') : '&nbsp;'; ?> 
- </p> 
- </td> 
- <td class="usersubscriptions_delete"> 
- <?php if($info['deleteoption']) { ?><a href="<?php echo wl($ID); ?>?pluginusersubscriptions_unsubscribe=<?php echo ($info['isnamespace'] ? 'ns' : 'pg').'-'.$id.($info['isnamespace'] ? ':' : ''); ?>#usersubscriptions_anchor"> 
- <img src="<?php echo DOKU_BASE; ?>lib/plugins/usersubscriptions/images/delete.png" alt="<?php echo $this->getLang('delete'); ?>" title="<?php echo $this->getLang('delete'); ?>" /> 
- </a><?php } ?> 
- </td> 
- </tr> 
-<?php 
-} 
-if(!count($usersubscriptions)) { 
-?> 
- <tr> 
- <td colspan="<?php echo $deletelink ? '2' : '1'; ?>" class="usersubscriptions_nothing"><?php echo $this->getLang('no_subscriptions'); ?></td> 
- </tr> 
-<?php 
-} 
- 
-if($quicksubscribe) { 
-?> 
- <tr> 
- <td colspan="<?php echo $deletelink ? '2' : '1'; ?>" class="usersubscriptions_nothing"> 
- <?php echo $this->getLang('quick_subscription'); ?> : <form method="get" action="<?php echo wl($ID); ?>#usersubscriptions_anchor"> 
- <select name="pluginusersubscriptions_subscribe" onchange="this.form.submit();"> 
- <option value=""><?php echo $this->getLang('quick_subscription_select'); ?></option> 
-<?php 
- foreach($usersubscriptions as $id => $info) { 
- if($info['selfsubscribed']) continue; // don't display already subscribed items 
-?> 
- <option value="<?php echo ($info['isnamespace'] ? 'ns' : 'pg').'-'.$id.($info['isnamespace'] ? ':' : '').'" class="'.($info['isnamespace'] ? 'usersubscriptions_nsopt' : '').' '.($info['selfsubscribed'] ? 'usersubscriptions_selopt' : ''); ?>"> 
- <!--<?php echo str_repeat('&nbsp;&nbsp;&nbsp;', max(0, $info['lvl'] - 1)); ?>--> 
- <?php echo ($id != '') ? $id : $this->getLang('quick_subscription_root'); ?> 
- </option> 
-<?php 
- } 
-?> 
- </select> 
- <noscript><input type="submit" value="<?php echo $this->getLang('quick_subscription_post'); ?>" /></noscript> 
- </form> 
- </td> 
- </tr> 
-<?php 
-} 
-?> 
-</table> 
-</code> 
- 
-==== style.css ==== 
- 
-<code css> 
-div.dokuwiki table.usersubscriptions { 
- position: relative; 
- border: 1px solid __text_alt__; 
- width: 75%; 
- margin: 10px auto 15px auto; 
- border-collapse: collapse; 
-} 
- 
-div.dokuwiki table.usersubscriptions th.usersubscriptions_namespace { 
- text-align: center; 
- padding: 3px; 
- border-bottom: 1px solid __text_alt__; 
- background: transparent url(images/bkg.png) 0 0 repeat-x; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscriptions_nothing { 
- text-align: center; 
- padding: 5px; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscription_success { 
- font-style: italic; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscription_failure { 
- color: red; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscriptions_nothing select option.usersubscriptions_nsopt { 
- font-weight: bold; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscriptions_nothing select option.usersubscriptions_selopt { 
- font-style: italic; 
-} 
- 
-div.dokuwiki table.usersubscriptions td p.usersubscriptions_description { 
- font-style: italic; 
- margin: 1px 0 1px 10px; 
- font-size: 90%; 
- padding: 5px; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscriptions_delete img { 
- vertical-align: middle; 
- margin: 5px; 
-} 
- 
-div.dokuwiki table.usersubscriptions td p.usersubscriptions_description img { 
- float: left; 
- margin: 5px; 
-} 
- 
-div.dokuwiki table.usersubscriptions td p.usersubscriptions_description span.usersubscriptions_id { 
- font-style: normal; 
- font-weight: bold; 
- font-size: 130%; 
-} 
- 
-div.dokuwiki table.usersubscriptions td.usersubscriptions_delete { 
- text-align: center; 
- width: 50px; 
-} 
-</code> 
- 
-===== Discussion ===== 
-==== 2009-05-01 ==== 
   * "src" values for <img> elements are broken for any site that has a non-default directory structure.  For example we have DokuWiki installed to /wiki instead of /.   * "src" values for <img> elements are broken for any site that has a non-default directory structure.  For example we have DokuWiki installed to /wiki instead of /.
   * A similar problem exists for the URL of a background element in the style.css file.   * A similar problem exists for the URL of a background element in the style.css file.
Line 551: Line 195:
 --------------- ---------------
 Did you add NOCACHE to the page? Did you add NOCACHE to the page?
 +>no, I didn't - it works properly after including a <code>~~NOCACHE~~</code> to the page - thx!
 +
 +==== 2010-09-24 ====
 +
 +Included all patches, block now shows where it is expected to ... Also moved cache disabling line a bit upper, because when user disconnected, cache was not disabled so a version of the page without the form was cached and then served again even if the user reconnected ... my bad ...
 +
 +==== 2010-12-05 ====
 +
 +After an Dokuwiki-upgrade to the newest version (Anteater) i get an error, when i want to open the subscription-page. 
 +"Fatal error: Call to undefined function is_subscribed() in /.../lib/plugins/usersubscriptions/syntax.php on line 174"
 +Is there a new Plugin-Version on the horizon or can you help me?
 +
 +> Indeed the is_subscribed() function has disappeared from Dokuwiki (it was used through an include inside the plugin).
 +> A quick "dirty" fix is to copy the function in the syntax.php file of the plugin. A good place is between the includes and the class (the function shall absolutely be out of the class definition).
 +> Below a copy of the code coming from the former release of Dokuwiki
 +  function is_subscribed($id,$uid,$ns=false){
 +    if(!$ns) {
 +      $file=metaFN($id,'.mlist');
 +    } else {
 +      if(!getNS($id)) {
 +        $file = metaFN(getNS($id),'.mlist');
 +      } else {
 +        $file = metaFN(getNS($id),'/.mlist');
 +      }
 +    }
 +    if (@file_exists($file)) {
 +      $mlist = file($file);
 +      $pos = array_search($uid."\n",$mlist);
 +      return is_int($pos);
 +    }
 +    return false;
 +  }
 +  
 +It should probably be more proper to work on a patch that will use the new Dokuwiki functions, but I don't have enough time at now.
 +> Hope this help, waiting for a better solution
 +> MR (2010-12-08)
 +
 +**Thank you very much, it works fine now! thumbup**
 +
 +
 +==== 2014-04-04 ====
 +
 +I have installed this plug in, yet now this appears
 +  Fatal error: Call to undefined function is_subscribed() 
 +  in lib\plugins\usersubscriptions\syntax.php on line 178
 +Can someone help me please?
plugin/usersubscriptions.txt · Last modified: 2023-12-17 21:29 by Aleksandr

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki