-
Notifications
You must be signed in to change notification settings - Fork 0
/
_twitter_card.plugin.php
161 lines (151 loc) · 4.85 KB
/
_twitter_card.plugin.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
<?php
/**
* This file implements the Latest posts widget for {@link http://b2evolution.net/}.
* @copyright (c)2008 by Emin Özlem - {@link http://eminozlem.com/}.
* @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
* @package plugins
* @author Emin Özlem
*/
if( !defined('EVO_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
class twitter_card_plugin extends Plugin
{
/**
* Variables below MUST be overriden by plugin implementations,
* either in the subclass declaration or in the subclass constructor.
*/
var $name = 'Twitter Card';
/**
* Code, if this is a renderer or pingback plugin.
*/
var $code = 'eo_twitter_card';
var $priority = 49;
var $version = '0.1';
var $author = 'Emin Özlem';
var $author_url = 'http://eminozlem.com';
var $help_url = 'http://forums.b2evolution.net/twitter-card-plugin';
var $apply_rendering = 'never';
var $number_of_installs = 1;
/**
* Init
*
* This gets called after a plugin has been registered/instantiated.
*/
function PluginInit( & $params )
{
$this->short_desc = $this->T_('Integrate Twitter cards');
$this->long_desc = $this->T_('Twitter card integration for your blog');
}
/**
* Define here default collection/blog settings that are to be made available in the backoffice.
*
* @param array Associative array of parameters.
* @return array See {@link Plugin::get_coll_setting_definitions()}.
*/
function get_coll_setting_definitions( & $params )
{
$domain = preg_replace('/^www\./','',$_SERVER['HTTP_HOST']);
// global $Blog;
return array_merge( parent::get_coll_setting_definitions( $params ),
array(
'card_type' => array(
'label' => T_('Card Type'),
'note' => T_('The card type'),
'type' => 'select',
'options' => array(
'summary' => T_('Summary Card'),
'summary_large_image' => T_('Summary Card with Large Image'),
// array( 'app', T_('App Card') ),
// array( 'player', T_('Player Card') ),
),
'defaultvalue' => 'summary_large_image',
),
'site_id' => array(
'label' => T_( 'Site ID' ),
'size' => 25,
'note' => T_( 'REQUIRED. @username of website.' ),
'defaultvalue' => $domain,
// . $Blog->siteurl,
),
)
);
}
function eo_get_featured_image_url($size=NULL) {
global $Item;
// Get list of attached files
$feat_img_uri = false;
$params = array(
'before' => '',
'before_image' => '',
'before_image_legend' => '',
'after_image_legend' => '',
'after_image' => '',
'after' => '',
'limit' => 1,
'image_link_to' => 'original',
'before_gallery' => '',
'after_gallery' => '',
// Optionally restrict to files/images linked to specific position: 'teaser'|'aftermore'
'restrict_to_image_position' => 'teaser',
);
if(isset($size)) $params['image_size'] = $size;
$post_images = $Item->get_images( $params,'raw' );
if( ! empty ($post_images) ) {
preg_match('/(src)=("[^"]*")/',$post_images, $img_parts);
$feat_img_uri = str_replace(array('src="','"','&'),array('','','&'),$img_parts[0]);
}
return $feat_img_uri;
/*if( $app_version < 5 ) {
if( ! $FileList = $Item->get_attachment_FileList(1, 'teaser') )
{
return '';
}
$r = '';
$File = NULL;
while( $File = & $FileList->get_next() )
{
if( $File->is_image() ) {
$feat_img_uri = $File->_FileRoot->ads_url . $File->_rdfp_rel_path;
// var_dump($feat_img_uri);
}
}
}*/
}
function SkinBeginHtmlHead( & $params )
{
global $Item,$Chapter,$Blog,$baseurl;
$tw_img = false;
$blogdesc = $Blog->longdesc;
if( isset($Item) && ! empty($Item) ) {
$id = $Item->ID;
// $og_uri = $baseurl .'index.php?p='.$id.'&blog='.$Blog->ID.'&redir=no';
$tw_desc = $Item->excerpt;
$tw_title = $Item->title;
$tw_img = $this->eo_get_featured_image_url();
}
else if ( isset($Chapter) && ! empty($Chapter) ) {
//if we are on category
$tw_desc = $Chapter->description;
$tw_title = $Chapter->name;
}
else {
// Just in case, for everything else.
$tw_desc = $blogdesc;
$tw_title = $Blog->name;
}
$card_type = ( $tw_img ) ? $this->get_coll_setting( 'card_type', $Blog ) : 'summary';
add_headline('<meta name="twitter:card" content="'.$card_type.'">');
add_headline('<meta name="twitter:site" content="'.$this->get_coll_setting( 'site_id', $Blog ).'">');
add_headline('<meta name="twitter:title" content="'.format_to_output($tw_title,'htmlattr').'">');
add_headline('<meta name="twitter:description" content="'.format_to_output($tw_desc,'htmlattr').'">');
if( $tw_img ) add_headline('<meta name="twitter:image" content="'.$tw_img.'">');
}
/**
* Event handler: SkinTag (widget)
*
* @param array Associative array of parameters.
* @return boolean did we display?
*
*/
// function SkinTag( $params ) {}
}
?>