Project

General

Profile

Paste
Download (971 Bytes) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / addthis / classes / Util / AddThisWidgetJsUrl.php @ 2c8c2b87

1
<?php
2
/**
3
 * @file
4
 * Class to manage a WidgetJs url.
5
 */
6

    
7
class AddThisWidgetJsUrl {
8

    
9
  protected $url;
10
  protected $attributes = array();
11

    
12
  /**
13
   * Sepecify the url through the construct.
14
   */
15
  public function __construct($url) {
16
    $this->url = $url;
17
  }
18

    
19
  /**
20
   * Add a attribute to the querystring.
21
   */
22
  public function addAttribute($name, $value) {
23
    $this->attributes[$name] = $value;
24
  }
25

    
26
  /**
27
   * Remove a attribute from the querystring.
28
   */
29
  public function removeAttribute($name) {
30
    if (isset($attributes[$name])) {
31
      unset($attributes[$name]);
32
    }
33
  }
34

    
35
  /**
36
   * Get the full url for the widgetjs.
37
   */
38
  public function getFullUrl() {
39
    $querystring_elements = array();
40
    foreach ($this->attributes as $key => $value) {
41
      if (!empty($value)) {
42
        $querystring_elements[] = $key . '=' . $value;
43
      }
44
    }
45

    
46
    $querystring = implode('&', $querystring_elements);
47

    
48
    return $this->url . '#' . $querystring;
49
  }
50

    
51
}