CMS  Version 3.9
sharing_manager.inc
Go to the documentation of this file.
1 <?php
8 interface ShareHandler
9 {
10  public function getTitle($key);
11  public function draw($key);
12 }
13 
21 {
22  static $shareHandlerMap = null;
23 
24  function SharingManager()
25  {
26 
27  }
28 
29  static function setDefaults()
30  {
31  //TODO: Set default configuration parameters here
32  }
33 
34  static function getShareHandler($type)
35  {
37  {
39  ComponentManager::fireEvent("RegisterShareHandlers");
40  }
41 
43  {
44  throw new FakoliException("Unknown share handler");
45  }
46 
48  }
49 
51  {
53  }
54 
56  {
58  }
59 
60  static function drawShare($token)
61  {
62  global $user;
63 
65  if (!$share->active)
66  {
67  throw new FakoliException("This shared item is no longer available");
68  }
69 
71  $handler->draw($share->item_key);
72 
73  $access = new ShareAccess();
74  $access->share_id = $share->share_id;
75  $access->user_id = $user ? $user->user_id : 0;
76  $access->access_timestamp = now();
77  $access->ip_address = $_SERVER["REMOTE_ADDR"];
78  $access->save();
79  }
80 
85  static function shareItem($item)
86  {
87  global $user;
88 
89  $type = get_class($item);
90  SharingManager::getShareHandler($type); // Trigger an exception if the item is not a registered type
91 
92  $token = new ShareToken();
93  $token->token = plainGUID();
94  $token->item_type = $type;
95  $token->item_key = $item->getPrimaryKeyValue();
96  $token->user_id = $user->user_id;
97  $token->created_date = now();
98  $token->last_updated = now();
99  $token->last_updated_by_id = $user->user_id;
100  $token->active = true;
101  $token->save();
102 
103  return $token;
104  }
105 
106  static function embedSharedItem($template)
107  {
108  $match = [];
109  while(preg_match("/\\[share:(.*?)\\]/", $template, $match))
110  {
111  $id = $match[1];
112 
114 
115  if (!$token) continue;
116 
117  ob_start();
118 
120  $handler->draw($token->item_key);
121 
122  $out = ob_get_contents();
123  ob_end_clean();
124  $template = str_replace($match[0], $out, $template);
125  }
126 
127  return $template;
128  }
129 
130  static function getURL($token)
131  {
132  global $config;
133 
134  $sharing = Query::create('Section', "WHERE section_type='Sharing'")->execute();
135  if (count($sharing) == 0) return "No Sharing Section";
136  $sharing = $sharing[0];
137 
138  return "https://".$config['http_host']."/".$sharing->section."/".$token->token;
139  }
140 
141  static function formatStatusToggle($token)
142  {
143  if ($token->active)
144  {
145  $out = $token->format("<a href='#' data-share_id='{share_id}' class='share_enabled' onclick='SharingManager.toggleStatus(this); return false;'><i class='icon-ok'></i> Enabled</a>");
146  }
147  else
148  {
149  $out = $token->format("<a href='#' data-share_id='{share_id}' class='share_disabled' onclick='SharingManager.toggleStatus(this); return false;'><i class='icon-cancel'></i> Disabled</a>");
150  }
151 
152  return $out;
153  }
154 
155  static function upgradeComponent($version)
156  {
157  $mgr = new SharingUpgradeManager();
158  $mgr->upgrade($version);
159  }
160 }
161 ?>
$handler
Definition: event_form.inc:62
$out
Definition: page.inc:66
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
FakoliException is the base exception class for all Fakoli errors.
Definition: core.inc:53
static registerManager($type, $manager)
Registers a SectionContentManager for handling a specified section type.
static getShare($token)
Definition: share_token.inc:45
Provides a central management class for event handlers and common functionality for the sharing compo...
static registerShareHandler($type, $handler)
static drawShare($token)
static getShareHandler($type)
static getURL($token)
static setDefaults()
static embedSharedItem($template)
static upgradeComponent($version)
static shareItem($item)
Creates a ShareToken for the specified item.
static formatStatusToggle($token)
static registerSectionContentManager()
global $user
global $config
Definition: import.inc:4
getTitle($key)
$share