-
Notifications
You must be signed in to change notification settings - Fork 13
/
qa-social-share-layer.php
172 lines (133 loc) · 7.16 KB
/
qa-social-share-layer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
if ( !defined( 'QA_VERSION' ) ) { // don't allow this page to be requested directly from browser
exit;
}
class qa_html_theme_layer extends qa_html_theme_base
{
public function head_metas()
{
parent::head_metas();
if ( qa_opt( qa_sss_opt::ENABLE_OPEN_GRAPH_SUPPORT ) && $this->template != 'admin' ) {
if ( in_array( $this->template, array( 'question', 'blog' ) ) ) {
$content = @$this->content['q_view']['raw']['content'];
$image_url = ami_social_get_first_image_from_html( $content );
$description = @$this->content['description'];
} else if ( $this->template == 'user' ) {
$image_html = @$this->content['form_profile']['fields']['avatar']['html'];
$image_url = ami_social_get_first_image_from_html( $image_html );
$description = @$this->content['form_profile']['fields']['about']['value'];
$first_name = @$this->content['form_profile']['fields']['name']['value'];
$username = qa_request_part( 1 );
} else {
$description = qa_opt( qa_sss_opt::WEBSITE_DESCRIPTION );
if ( empty( $description ) )
$description = @$this->content['sidebar'];
}
if ( empty( $image_url ) ) {
//if the image URL is not found then take the default from the admin panel
$image_url = qa_opt( qa_sss_opt::DEFAULT_SHARE_IMAGE );
}
if ( empty( $image_url ) ) {
//if still empty then consider the logo URL
$image_url = qa_opt( 'logo_url' );
}
$image_url = htmlspecialchars_decode( urldecode( $image_url ) );
$site_lang = qa_opt( 'site_language' );
$locale = $site_lang ? $site_lang : 'en_US';
$ogp = new OpenGraphProtocol();
$ogp->setLocale( $locale );
$ogp->setSiteName( qa_opt( 'site_title' ) );
if ( isset($this->content['title']) ) {
$ogp->setTitle( strip_tags( $this->content['title'] ) );
}
$ogp->setDescription( strip_tags( $description ) );
$ogp->setType( 'website' );
$ogp->setURL( qa_path_absolute( qa_request() ) );
$ogp->setDeterminer( 'the' );
if ( $this->template == 'user' ) {
$ogp->setType( 'profile' );
$profile = new OpenGraphProtocolProfile();
$profile->setFirstName( $first_name );
$profile->setUsername( $username );
$ogp_html_arr = explode( PHP_EOL, $profile->toHTML() );
if(count($ogp_html_arr)) {
foreach ($ogp_html_arr as $key => $ogp_html) {
$this->output_raw( $ogp_html );
}
}
}
if ( !empty( $image_url ) ) {
$image_data = @getimagesize( $image_url );
$imageOg = new OpenGraphProtocolImage();
$imageOg->setURL( $image_url );
$imageOg->setWidth( !empty( $image_data[0] ) ? $image_data[0] : 1200 );
$imageOg->setHeight( !empty( $image_data[0] ) ? $image_data[0] : 630 );
if ( !empty( $image_data['mime'] ) ) {
$imageOg->setType( $image_data['mime'] );
}
$ogp->addImage( $imageOg );
}
$ogp_html_arr = explode( PHP_EOL, $ogp->toHTML() );
if(count($ogp_html_arr)) {
foreach ($ogp_html_arr as $key => $ogp_html) {
$this->output_raw( $ogp_html );
}
}
$facebook_app_id = qa_opt( qa_sss_opt::FACEBOOK_APP_ID );
if ( !empty( $facebook_app_id ) ) {
$this->output_raw( '<meta property="fb:app_id" content="' . $facebook_app_id . '">' );
}
$twitter_username = trim( qa_opt( qa_sss_opt::TWITTER_HANDLE ) );
if ( !empty( $twitter_username ) ) {
if ( strpos( $twitter_username, '@' ) !== 0 )
$twitter_username = '@' . $twitter_username;
$this->output_raw( '<meta name="twitter:card" content="summary">' );
$this->output_raw( '<meta name="twitter:site" content=' . $twitter_username . '>' );
$this->output_raw( '<meta name="twitter:creator" content="' . $twitter_username . '">' );
}
}
}
function head_css()
{
parent::head_css();
//$this->output( '<link rel="stylesheet" href="' . qa_path_to_root() . 'qa-plugin/' . SOCIAL_SHARE_PLUGIN_DIR_NAME . '/css/icons.css?'.SOCIAL_SHARE_PLUGIN_VERSION.'">' );
$this->output( '<link rel="stylesheet" href="' . qa_path_to_root() . 'qa-plugin/' . SOCIAL_SHARE_PLUGIN_DIR_NAME . '/css/social-share.css?'.SOCIAL_SHARE_PLUGIN_VERSION.'">' );
$style_open = '<style type="text/css">';
$style_close = '</style>';
$style_final = $style_open . qa_opt( qa_sss_opt::CUSTOM_CSS ) ;
if(strtolower(qa_opt('site_theme')) == 'snow'){
$style_final .= ".qa-widget-side .btn-share.with-icon .btn {width: 145px; }" ;
}
if(strtolower(qa_opt('site_theme')) == 'candy'){
$style_final .= ".qa-widget-side .btn-share.with-icon .btn {width: 90px; }" ;
}
if(strtolower(qa_opt('site_theme')) == 'classic'){
$style_final .= ".qa-widget-side .btn-share.with-icon .btn {width: 105px; }" ;
}
$style_final .= $style_close;
$this->output( $style_final );
}
function q_view_buttons( $q_view )
{
if ( (int) qa_opt( qa_sss_opt::BUTTON_STATUS ) ) {
$page_url = qa_path_absolute( qa_request() );
$page_title = $q_view['raw']['title'];
$args = array(
'title' => $page_title,
'url' => $page_url,
'template' => $this->template,
'themeobject' => $this,
'target' => '_blank',
'style' => qa_opt( qa_is_mobile_probably() ? qa_sss_opt::SHARE_TYPE_POST_MOBILE_OPTION : qa_sss_opt::SHARE_TYPE_POST_DESKTOP_OPTION ),
);
$social_share = new Ami_SocialShare( $args );
$this->output( '<div class="social-wrapper">' );
$social_share->generateShareButtons();
$this->output( '</div>' );
}
parent::q_view_buttons( $q_view );
}
}
/*
Omit PHP closing tag to help avoid accidental output
*/