Completed
Push — master ( 85914a...2ce878 )
by Harald
06:39 queued 03:01
created

sb_google_plus_share::getOutput()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 33
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 11
nc 4
nop 0
dl 0
loc 33
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/*
3
  $Id$
4
5
  osCommerce, Open Source E-Commerce Solutions
6
  http://www.oscommerce.com
7
8
  Copyright (c) 2015 osCommerce
9
10
  Released under the GNU General Public License
11
*/
12
13
  use OSC\OM\HTML;
14
  use OSC\OM\OSCOM;
15
  use OSC\OM\Registry;
16
17
  class sb_google_plus_share {
18
    var $code = 'sb_google_plus_share';
19
    var $title;
20
    var $description;
21
    var $sort_order;
22
    var $icon;
23
    var $enabled = false;
24
25
    protected $lang;
26
27 View Code Duplication
    function __construct() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
      $this->lang = Registry::get('Language');
29
30
      $this->title = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_TITLE;
31
      $this->public_title = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_PUBLIC_TITLE;
0 ignored issues
show
Bug introduced by
The property public_title does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
32
      $this->description = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_DESCRIPTION;
33
34
      if ( defined('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_STATUS') ) {
35
        $this->sort_order = MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_SORT_ORDER;
36
        $this->enabled = (MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_STATUS == 'True');
37
      }
38
    }
39
40
    function getOutput() {
41
      $button_height = (int)MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_HEIGHT;
42
43
      if (MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ANNOTATION == 'Vertical-Bubble') {
44
        $button_height = 60;
45
      }
46
47
      $output = '<div class="g-plus" data-action="share" data-href="' . OSCOM::link('product_info.php', 'products_id=' . $_GET['products_id'], false) . '" data-annotation="' . strtolower(MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ANNOTATION) . '"';
48
49
      if ((int)MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_WIDTH > 0) {
50
        $output .= ' data-width="' . (int)MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_WIDTH . '"';
51
      }
52
53
      $output .= ' data-height="' . $button_height . '" data-align="' . strtolower(MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ALIGN) . '"></div>';
54
55
      $output .= '<script>
56
  if ( typeof window.___gcfg == "undefined" ) {
57
    window.___gcfg = { };
58
  }
59
60
  if ( typeof window.___gcfg.lang == "undefined" ) {
61
    window.___gcfg.lang = "' . HTML::outputProtected($this->lang->get('code')) . '";
62
  }
63
64
  (function() {
65
    var po = document.createElement(\'script\'); po.type = \'text/javascript\'; po.async = true;
66
    po.src = \'https://apis.google.com/js/plusone.js\';
67
    var s = document.getElementsByTagName(\'script\')[0]; s.parentNode.insertBefore(po, s);
68
  })();
69
</script>';
70
71
      return $output;
72
    }
73
74
    function isEnabled() {
75
      return $this->enabled;
76
    }
77
78
    function getIcon() {
79
      return $this->icon;
80
    }
81
82
    function getPublicTitle() {
83
      return $this->public_title;
84
    }
85
86
    function check() {
87
      return defined('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_STATUS');
88
    }
89
90 View Code Duplication
    function install() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91
      $OSCOM_Db = Registry::get('Db');
92
93
      $OSCOM_Db->save('configuration', [
94
        'configuration_title' => 'Enable Google+ Share Module',
95
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_STATUS',
96
        'configuration_value' => 'True',
97
        'configuration_description' => 'Do you want to allow products to be shared through Google+?',
98
        'configuration_group_id' => '6',
99
        'sort_order' => '1',
100
        'set_function' => 'tep_cfg_select_option(array(\'True\', \'False\'), ',
101
        'date_added' => 'now()'
102
      ]);
103
104
      $OSCOM_Db->save('configuration', [
105
        'configuration_title' => 'Annotation',
106
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ANNOTATION',
107
        'configuration_value' => 'Bubble',
108
        'configuration_description' => 'The annotation to display next to the button.',
109
        'configuration_group_id' => '6',
110
        'sort_order' => '1',
111
        'set_function' => 'tep_cfg_select_option(array(\'Inline\', \'Bubble\', \'Vertical-Bubble\', \'None\'), ',
112
        'date_added' => 'now()'
113
      ]);
114
115
      $OSCOM_Db->save('configuration', [
116
        'configuration_title' => 'Width',
117
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_WIDTH',
118
        'configuration_value' => '',
119
        'configuration_description' => 'The maximum width of the button.',
120
        'configuration_group_id' => '6',
121
        'sort_order' => '1',
122
        'date_added' => 'now()'
123
      ]);
124
125
      $OSCOM_Db->save('configuration', [
126
        'configuration_title' => 'Height',
127
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_HEIGHT',
128
        'configuration_value' => '20',
129
        'configuration_description' => 'Sets the height of the button.',
130
        'configuration_group_id' => '6',
131
        'sort_order' => '1',
132
        'set_function' => 'tep_cfg_select_option(array(\'15\', \'20\', \'24\', \'60\'), ',
133
        'date_added' => 'now()'
134
      ]);
135
136
      $OSCOM_Db->save('configuration', [
137
        'configuration_title' => 'Alignment',
138
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ALIGN',
139
        'configuration_value' => 'Left',
140
        'configuration_description' => 'The alignment of the button assets.',
141
        'configuration_group_id' => '6',
142
        'sort_order' => '1',
143
        'set_function' => 'tep_cfg_select_option(array(\'Left\', \'Right\'), ',
144
        'date_added' => 'now()'
145
      ]);
146
147
      $OSCOM_Db->save('configuration', [
148
        'configuration_title' => 'Sort Order',
149
        'configuration_key' => 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_SORT_ORDER',
150
        'configuration_value' => '0',
151
        'configuration_description' => 'Sort order of display. Lowest is displayed first.',
152
        'configuration_group_id' => '6',
153
        'sort_order' => '0',
154
        'date_added' => 'now()'
155
      ]);
156
    }
157
158
    function remove() {
159
      return Registry::get('Db')->exec('delete from :table_configuration where configuration_key in ("' . implode('", "', $this->keys()) . '")');
160
    }
161
162
    function keys() {
163
      return array('MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_STATUS', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ANNOTATION', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_WIDTH', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_HEIGHT', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_ALIGN', 'MODULE_SOCIAL_BOOKMARKS_GOOGLE_PLUS_SHARE_SORT_ORDER');
164
    }
165
  }
166
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
167