~quam-plures-core/quam-plures/file_manager_limits

« back to all changes in this revision

Viewing changes to qp_plugins/twitter_plugin/_twitter.plugin.php

  • Committer: EdB
  • Date: 2013-03-04 07:15:41 UTC
  • mfrom: (7655.1.3 qp5_antispam)
  • Revision ID: 1912webworks@gmail.com-20130304071541-x462crs4d531rh69
http://forums.quamplures.net/viewtopic.php?f=6&t=1887

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
<?php
2
2
/**
3
 
 * This file implements the Twitter plugin for Quam Plures
4
 
 *
5
 
 * READ THE README! That's where all the answers to all your questions are!
6
 
 *
7
 
 * Some folk think licensing matters.  I guess maybe it does, but so does a 45
8
 
 * caliber semi-automatic pistol. Just sayin'  Anyway let's talk licensing.
9
 
 * This plugin is based on and built on three different programs, all of which
10
 
 * have some sort of licensing crap in them.
11
 
 *
12
 
 * -----------------------------------------------------------------------------
13
 
 *
14
 
 * First, this exact file is built on the corpse of a dead plugin with the same
15
 
 * name.  It claimed copyright by 2 persons and 1 entity, and claimed release
16
 
 * under a GPL2 license.  Were the contributions of each person and party
17
 
 * identified? No. Did it say exactly who decided it was GPL2? No. Near as I can
18
 
 * tell it's all a bunch of crap designed to make sure a lawyer could charge a
19
 
 * fortune of hourly time just reading this rubbish, but whatever: here for your
20
 
 * entertainment is the original tidbits from the original version of this file:
21
 
 *
22
 
 * This file is part of the Quam Plures project - {@link http://quamplures.net/}
23
 
 *
24
 
 * @copyright (c) 2009 - 2011 by the Quam Plures developers - {@link http://quamplures.net/}
25
 
 * @copyright (c)2009 by Francois PLANQUE - {@link http://fplanque.net/}
26
 
 * @copyright (c)2007 by Lee Turner - {@link http://leeturner.org/}.
27
 
 *
28
 
 * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
29
 
 *
30
 
 * -----------------------------------------------------------------------------
31
 
 *
32
 
 * Next up is a version of this file found by downloading b2evolution's future
33
 
 * stuff.  Stuff that may or may not ever see a public release but guess what:
34
 
 * don't put it on the internet if you don't want someone downloading it!
35
 
 * That file actually was the basis for this file even though that file failed
36
 
 * in some very fundamental ways. The connection to twitter was not done in
37
 
 * accordance with both oauth and twitter's expectations. I fixed that because
38
 
 * I care about quality code.  Anyway that file claims 2 authors, and a GPL2
39
 
 * license.  Here, again for your entertainment, is the lines that lawyers get
40
 
 * wood over:
41
 
 * @copyright (c)2009 by Francois PLANQUE - {@link http://fplanque.net/}
42
 
 * @copyright (c)2007 by Lee Turner - {@link http://leeturner.org/}.
43
 
 *
44
 
 * @license GNU General Public License 2 (GPL) - http://www.opensource.org/licenses/gpl-license.php
45
 
 *
46
 
 * -----------------------------------------------------------------------------
47
 
 *
48
 
 * Finally, we come to a file that I actually liked.  I used none of their
49
 
 * code, but most certainly drew strongly from what that author did.
50
 
 * Have you ever heard of Wordpress?  It's another open source blog app that
51
 
 * seems to be somewhat popular.  Anyway some nice folks wrote a plugin for
52
 
 * that app called tweetable
53
 
 * http://www.webmaster-source.com/tweetable-twitter-plugin-wordpress/
54
 
 * It was cool because it connected to twitter the right way, but it wasn't
55
 
 * geared towards multiple blogs and bloggers so there was only one thing I
56
 
 * could get from it.  Anyway since we're pretending licensing crap matters,
57
 
 * and noticing that their downloadable package includes ANOTHER copy of a
58
 
 * GPL license, I've included their file here as tweetable.GPL.txt.
59
 
 * Lots of bytes + no value added = pure bloat but so what! It's all about the lawyers...
60
 
 *
61
 
 * -----------------------------------------------------------------------------
62
 
 *
63
 
 * What, you may ask, have I done for this code?
64
 
 * 1) I made a plugin that works in Quam Plures based on bits and pieces of
65
 
 * three different open source plugins.
66
 
 * 2) I made it connect to twitter the way oauth and twitter expect (no storing
67
 
 * keys in code)
68
 
 * 3) I wrote the steps that walk the installation owner through registering
69
 
 * with twitter.
70
 
 * 4) I made it work with multiple bloggers on multiple blogs in one
71
 
 * installation.
72
 
 * 5) I made it capable of showing your twitter status in 3 locations instead
73
 
 * of just one.
74
 
 * 7) I skipped number six.
75
 
 * 8) I made the callback file recognize the different sources one might
76
 
 * authorize the registered app so it could return the blogger to the right
77
 
 * place.
78
 
 * 9) I wrote all this stupid crap.
79
 
 * 10) I wrote the songs that make the whole world sing.
80
 
 *
81
 
 * NEW LICENSING REQUIREMENTS!
82
 
 * Given that bits and pieces of source material that have been identified above
83
 
 * are licensed under varying licensing schemes, and noting that nobody actually
84
 
 * cares about it anyway except for lawyers but I don't care about lawyers, I
85
 
 * hereby decree that this file (noting any restrictions that a normal human
86
 
 * might magically think the GPL licenses associated with the original concepts
87
 
 * that became this plugin might contain) hereby release unto the world this
88
 
 * creative work to do with as you see fit including modify, adapt, build on,
89
 
 * use as a basis for your own creative work, use to make money, or use to
90
 
 * impress cute members of the gender of your choice for the purpose of wild
91
 
 * yet emotionally unsatisfying gratuitous sex HOWEVER you must always keep this
92
 
 * license notice intact in it's entirety.
93
 
 *
94
 
 * IF you fail to keep this licence notice intact in it's entirety then I swear
95
 
 * with words yet unwritten by Gods yet unborn that I shall lay upon your seed
96
 
 * a curse for all eternity that their operating systems will reboot randomly,
97
 
 * that the porn they download is not what they thought it was after waiting
98
 
 * forever due to seeds with crappy connections, that their apps will interfere
99
 
 * with efficient texting, that no one shall read their tweets, and that they
100
 
 * shall suffer great emotional harm from these undesirable conditions.
101
 
 *
102
 
 * Will you be able to sleep at night if you bring such a strong curse upon your
103
 
 * heir's heir's heir's heads? If so then hey that's cool.  Have a nice day :)
104
 
 *
105
 
 * I'm EdB {{http://wonderwinds.com/}} and I approve this message
106
 
 *
 
3
 * This file implements the Twitter plugin
 
4
 *
 
5
 * @author {@link http://wonderwinds.com/ Ed Bennett}
 
6
 * @author {@link http://fplanque.net/ Francois PLANQUE}
 
7
 * @author {@link http://leeturner.org/ Lee Turner}
 
8
 * @copyright (c) 2009 by {@link http://quamplures.net/ the Quam Plures project}
 
9
 * @license http://www.gnu.org/licenses/gpl.txt GNU General Public License v3
107
10
 * @package plugins
108
11
 * @subpackage Twitter
109
12
 */
110
 
 
111
 
if( !defined('QP_MAIN_INIT') ) die( 'Please, do not access this page directly.' );
 
13
if(!defined('QP_MAIN_INIT')) die('fail');
112
14
 
113
15
/**
114
 
 * Twitter Plugin
115
 
 *
116
16
 * @package plugins
117
17
 * @subpackage Twitter
118
18
 */
122
22
        var $author_url = 'http://wonderwinds.com/';
123
23
        var $code = 'twitter';
124
24
        var $group = 'pingers';
125
 
        var $help_url = 'http://1912webworks.com/plugins.php';
 
25
        var $help_url = 'http://1912webworks.com/plugins.php/twitter-plugin';
126
26
        var $number_of_installs = 1;
127
27
        var $priority = 50;
128
 
        var $version = '0.1';
 
28
        var $version = '1.0';
129
29
 
130
30
        /**
131
31
         * @see Plugin::PluginInit()
177
77
         */
178
78
        function AdminAfterMenuInit()
179
79
        {
180
 
                $this->register_menu_entry( $this->T_('Twitter Keys') );
 
80
                $this->register_menu_entry( $this->name );
 
81
        }
 
82
 
 
83
 
 
84
        /**
 
85
         * @see Plugin::AdminAfterNavbarInit()
 
86
         */
 
87
        function AdminAfterNavbarInit()
 
88
        {
 
89
                global $topleft_Menu;
 
90
 
 
91
                $topleft_Menu->add_menu_entries( 'tools', array(
 
92
                                'twitter_sep' => array( 'separator' => true ),
 
93
                                'twitter_link' => array(
 
94
                                        'text' => $this->name.'&hellip;',
 
95
                                        'href' => $this->get_tools_tab_url(),
 
96
                                        'title' => format_to_output( $this->short_desc, 'htmlattr' ),
 
97
                                ),
 
98
                        )
 
99
                );
181
100
        }
182
101
 
183
102
 
241
160
                global $current_User;
242
161
 
243
162
                if( $this->keys_check )
244
 
                { // we have registration keys
 
163
                {
 
164
                        // we have registration keys
245
165
                        $query = "SELECT * FROM ".$this->get_sql_table('twitter');
246
166
                        if( $app_data = $DB->get_row( $query, ARRAY_A ) )
247
 
                        { // get the user's twitter authentication status
 
167
                        {
 
168
                                // get the user's twitter authentication status
248
169
                                $user_id = $current_User->ID;
249
170
                                $status = $this->get_twitter_link( $user_id, 'status' );
250
171
                                $Form = & new Form( NULL, 'twitter_keys_a', 'post', 'compact' );
257
178
                                $Form->end_form();
258
179
 
259
180
                                if( $current_User->ID == '1' )
260
 
                                { // user ID#1 can drop the keys if desired, and gets a link to the app details page
 
181
                                {
 
182
                                        // user ID#1 can drop the keys if desired, and gets a link to the app details page
261
183
                                        $Form = & new Form( NULL, 'twitter_keys_b', 'post', 'compact' );
262
184
                                        $Form->begin_form( 'fform', $this->T_('Application Info') );
263
185
                                        $Form->hidden_ctrl();
282
204
 
283
205
                }
284
206
                elseif( $current_User->ID == '1' )
285
 
                { // no keys so walk through adding them
 
207
                {
 
208
                        // no keys so walk through adding them
286
209
                        global $basedomain;
287
210
                        global $basesubpath;
288
211
                        global $app_baseurl;
289
212
                        global $Settings;
290
213
                        global $BlogCache;
291
214
 
292
 
                        $default_blog_on_index = $Settings->get('default_blog_ID');
 
215
                        $default_blog_on_index = $Settings->get( 'default_blog_ID' );
293
216
                        $default_Blog = & $BlogCache->get_by_ID( $default_blog_on_index, false );
294
217
                        $callback = $this->get_plugin_url( true ).'_callback.php';
295
218
 
334
257
 
335
258
                }
336
259
                else
337
 
                { // other users get nothing
 
260
                {
 
261
                        // other users get nothing
338
262
                        return;
339
263
                }
340
264
 
379
303
                        $user_id = $current_User->ID;
380
304
                }
381
305
                if( $user_id )
382
 
                { // initialize info only once, when needs to display the link (user_id is set)
 
306
                {
 
307
                        // initialize info only once, when needs to display the link (user_id is set)
383
308
                        $info = $this->get_twitter_link( $user_id );
384
309
                        $user_settings = array(
385
310
                                'twitter_contact' => array(
386
311
                                        'label' => $this->T_('Twitter account status'),
 
312
                                        'type' => 'info',
387
313
                                        'info' => $info,
388
 
                                        'type' => 'info',
389
314
                                ),
390
315
                                'twitter_msg_format' => array(
391
316
                                        'label' => $this->T_('Message format'),
392
317
                                        'type' => 'text',
 
318
                                        'defaultvalue' => $this->T_('$twitcerpt$'),
 
319
                                        'maxlength' => 140,
393
320
                                        'size' => 30,
394
 
                                        'maxlength' => 140,
395
 
                                        'defaultvalue' => $this->T_('$twitcerpt$'),
396
321
                                        'note' => $this->T_('$twitcerpt$ is an excerpt + URL that totals 140 characters'),
397
322
                                ),
398
323
                        );
425
350
                // get twitter account info
426
351
                $oauth_token = $this->UserSettings->get( 'twitter_token' );
427
352
                $oauth_token_secret = $this->UserSettings->get( 'twitter_secret' );
428
 
                if( empty($oauth_token) || empty($oauth_token_secret) )
429
 
                { // no twitter account :(
 
353
                if( empty( $oauth_token ) || empty( $oauth_token_secret ) )
 
354
                {
 
355
                        // no twitter account :(
430
356
                        $params['xmlrpcresp'] = $this->T_('You must configure a twitter username/password before you can post to twitter.');
431
357
                        return false;
432
358
                }
433
359
                else
434
 
                { // get the message format
 
360
                {
 
361
                        // get the message format
435
362
                        $msg = $this->UserSettings->get( 'twitter_msg_format' );
436
363
                }
437
364
 
438
365
                // converitate the $message$ bits
439
 
                $title =  $params['Item']->dget('title', 'xml');
440
 
                $excerpt =  $params['Item']->dget('excerpt', 'xml');
 
366
                $title =  $params['Item']->dget( 'title', 'xml' );
 
367
                $excerpt =  $params['Item']->dget( 'excerpt', 'xml' );
441
368
                $url = $params['Item']->get_permanent_url();
442
369
                $short_url = $params['Item']->Blog->gen_blogurl().'?p='.$params['Item']->ID;
443
 
                $clip_to = 140 - ( evo_strlen( $short_url ) + 4 );
 
370
                $clip_to = 140 - ( app_strlen( $short_url ) + 4 );
444
371
                if( $excerpt != '' )
445
 
                { // if we have an excerpt then use it
446
 
                        $twitcerpt = trim( evo_substr( $excerpt, 0, $clip_to ) ).'... '.$short_url;
 
372
                {
 
373
                        // if we have an excerpt then use it
 
374
                        $twitcerpt = trim( app_substr( $excerpt, 0, $clip_to ) ).'... '.$short_url;
447
375
                }
448
376
                else
449
 
                { // no excerpt? use the title
450
 
                        $twitcerpt = trim( evo_substr( $title, 0, $clip_to ) ).'... '.$short_url;
 
377
                {
 
378
                        // no excerpt? use the title
 
379
                        $twitcerpt = trim( app_substr( $title, 0, $clip_to ) ).'... '.$short_url;
451
380
                }
452
381
 
453
382
                $msg = str_replace( '$title$', $title, $msg );
456
385
                $msg = str_replace( '$twitcerpt$', $twitcerpt, $msg );
457
386
 
458
387
                require_once 'twitteroauth/twitteroauth.php';
459
 
                $connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret );
 
388
                $connection = new TwitterOAuth( $consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret );
460
389
 
461
390
                $result = $connection->post('statuses/update', array( 'status' => $msg ));
462
391
 
463
 
                if( empty($result) )
 
392
                if( empty( $result ) )
464
393
                {
465
394
                        return false;
466
395
                }
467
396
 
468
 
                $account = $connection->get('account/verify_credentials');
 
397
                $account = $connection->get( 'account/verify_credentials' );
469
398
 
470
399
                $params['xmlrpcresp'] = $this->T_('Posted to account: @').$account->screen_name;
471
400
 
537
466
                global $BlogCache;
538
467
 
539
468
                // get and set UserSettings
540
 
                if( empty ( $this->UserSettings ) )
 
469
                if( empty( $this->UserSettings ) )
541
470
                {
542
471
                        if( $give == 'info' )
543
472
                        {
546
475
                }
547
476
 
548
477
                $oauth_token = $this->UserSettings->get( 'twitter_token', $user_id );
549
 
                if( !empty( $oauth_token ) )
550
 
                { // user has already approved app, get token secret
 
478
                if( ! empty( $oauth_token ) )
 
479
                {
 
480
                        // user has already approved app, get token secret
551
481
                        $oauth_token_secret = $this->UserSettings->get( 'twitter_secret', $user_id );
552
 
                        $connection = new TwitterOAuth($consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret );
 
482
                        $connection = new TwitterOAuth( $consumer_key, $consumer_secret, $oauth_token, $oauth_token_secret );
553
483
                        // get linked user account
554
 
                        $account = $connection->get('account/verify_credentials');
 
484
                        $account = $connection->get( 'account/verify_credentials' );
555
485
 
556
486
                        // if they turn off approval via twitter forget everything
557
487
                        if( isset( $account->error ) )
569
499
                }
570
500
 
571
501
                // create new connection
572
 
                $connection = new TwitterOAuth($consumer_key, $consumer_secret);
 
502
                $connection = new TwitterOAuth( $consumer_key, $consumer_secret );
573
503
 
574
504
                // set callback params
575
505
                $callback = $this->get_plugin_url( true ).'_callback.php';
593
523
                $redir = 'foo';
594
524
                if( $give == 'status' )
595
525
                {
596
 
                        $this_action = isset($_GET['action']) ? $_GET['action'] : '';
 
526
                        $this_action = isset( $_GET['action'] ) ? $_GET['action'] : '';
597
527
                        if( $this_action == 'edit' )
598
528
                        {
599
529
                                $redir = 'ctrl=items&action=edit&p='.$_GET['p'];
609
539
                $Session->dbsave();
610
540
 
611
541
                if( empty( $result ) )
612
 
                { // wasn't linked to twitter
 
542
                {
 
543
                        // wasn't linked to twitter
613
544
                        $result = '<a href="'.$connection->getAuthorizeURL( $req_token, false ).'" title="'.$this->T_('sign in with twitter').'"><img src="'.$this->get_plugin_url( true ).'twitter_button.png" width="151" height="24" alt="'.T_('sign in with twitter').'" /></a>';
614
545
                }
615
546
                else
616
 
                { // was linked so show it with an option to switch on user profile page
 
547
                {
 
548
                        // was linked so show it with an option to switch on user profile page
617
549
                        if( $give == 'info' )
618
550
                        {
619
551
                                $result = $result.' <a href='.$connection->getAuthorizeURL( $req_token, false ).'>'.$this->T_('Link to another account').'</a>';