/[drupal]/contributions/modules/hidden_content/hidden_content.module
ViewVC logotype

Contents of /contributions/modules/hidden_content/hidden_content.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Mon Feb 5 22:22:30 2007 UTC (2 years, 9 months ago) by 1stangel
Branch: MAIN
CVS Tags: DRUPAL-4-7--1-0, DRUPAL-5--1-0, HEAD
Branch point for: DRUPAL-5, DRUPAL-4-7
File MIME type: text/x-php
Initial import.
Sorry for my bad english. Please correct me.
1st-angel@gmx.net
1 <?php
2 /* $Id$ */
3
4 /**
5 * Implementation of hook_help().
6 *
7 */
8 function hidden_content_help($section) {
9 switch ($section) {
10 case 'admin/modules#description':
11 // This description is shown in the listing at admin/modules.
12 return t('This is a filter module that enables you to make parts of your homepage hidden to users that are not in a special role or user.');
13 }
14 }
15
16 /**
17 * Implementation of hook_filter_tips().
18 *
19 */
20 function hidden_content_filter_tips($delta, $format, $long = false){
21 if($long){
22 $text = "To make a part of your page hidden put it into [hidden] and [/hidden] tags.<br />\n";
23 $text .= "You can specify which role is able to see the content by using the attribute role like this:<br />\n";
24 $text .= "[hidden role=5]text[/hidden]. This will enable role 5 to see the text.\n<br />";
25 $text .= "You can specify that only one user is able to see it with the user parameter:<br />\n";
26 $text .= "[hidden user=2]text[/hidden]. This will enable user 2 to see the text.\n<br />";
27 $text .= "You may only specify one parameter.\n<br />";
28 $text .= "You may specify multiple users OR roles as a ';' seperated list.\n<br />";
29 $text .= "[hidden role=2;3]text[/hidden]. This will enable role 2 and 3 to see the text.\n<br />";
30 $text .= "If you ommit both parameters only user 1 will be able to see it.\n<br />";
31 return t($text);
32 }else{
33 return t("You may insert [hidden]text[/hidden] into your text.");
34 }
35 }
36
37 /**
38 * Implementation of hook_filter().
39 *
40 */
41 function hidden_content_filter($op, $delta = 0, $format = -1, $text = ''){
42 global $user;
43 switch ($op) {
44 case 'no cache':
45 return true;
46
47 case 'list':
48 return array(0 => t('hidden content'));
49
50 case 'description':
51 return t('Provides [hidden] and [/hidden] tags wich create a hidden area in your text that only a specified role or user can see.');
52 case 'prepare':
53 return $text;
54
55 case 'process':
56 if(!ereg('\[hidden',$text)){
57 return $text;
58 }
59 $parts=explode('[hidden',$text);
60 $new_text=$parts[0];
61 for($part_num=1;$part_num<count($parts);$part_num++){
62 $part=$parts[$part_num];
63 if(ereg('^ role=([0-9;]+)\]',$part,$hit)){
64 $roles=$hit[1];
65 $part=ereg_replace('^ role=([0-9;]+)\]','',$part);
66 $show=false;
67 $roles=explode(';',$roles);
68 foreach($roles as $role){
69 if($user->roles[$role]!=""){
70 $show=true;
71 }
72 }
73 }else if(ereg('^ user=([0-9;]+)\]',$part,$hit)){
74 $users=$hit[1];
75 $part=ereg_replace('^ user=([0-9;]+)\]','',$part);
76 $show=false;
77 $users=explode(';',$users);
78 foreach($users as $user_id){
79 if($user->uid==$user_id){
80 $show=true;
81 }
82 }
83 }else if(ereg('^\]',$part,$hit)){
84 $part=ereg_replace('^\]','',$part);
85 if($user->uid==1){
86 $show=true;
87 }else{
88 $show=false;
89 }
90 }else{
91 $show=false;
92 }
93
94 $small_parts=explode('[/hidden]',$part);
95 $first=array_shift($small_parts);
96 if($show){
97 $new_text.=$first;
98 }
99 $new_text.=implode('[/hidden]',$small_parts);
100 }
101 return $new_text;
102 break;
103 }
104 }
105
106 /**
107 * Valid permissions for this module
108 * @return array An array of valid permissions for the onthisdate module
109 */
110 function hidden_content_perm() {
111 return array();
112 } // function onthisdate_perm()

  ViewVC Help
Powered by ViewVC 1.1.2