Overview

Packages

  • Push

Classes

  • Horde_Push
  • Horde_Push_Cli
  • Horde_Push_Exception
  • Horde_Push_Factory_Push
  • Horde_Push_Factory_Recipients
  • Horde_Push_Recipient_Base
  • Horde_Push_Recipient_Blogger
  • Horde_Push_Recipient_Facebook
  • Horde_Push_Recipient_Mail
  • Horde_Push_Recipient_Mock
  • Horde_Push_Recipient_Twitter
  • Horde_Push_Translation

Interfaces

  • Horde_Push_Recipient
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Command line tool for pushing content to social networks.
  4:  *
  5:  * PHP version 5
  6:  *
  7:  * @category Horde
  8:  * @package  Push
  9:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 10:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 11:  * @link     http://www.horde.org/components/Horde_Push
 12:  */
 13: 
 14: /**
 15:  * Command line tool for pushing content to social networks.
 16:  *
 17:  * Copyright 2011-2012 Horde LLC (http://www.horde.org/)
 18:  *
 19:  * See the enclosed file COPYING for license information (LGPL). If you did not
 20:  * receive this file, see http://www.horde.org/licenses/lgpl21.
 21:  *
 22:  * @category Horde
 23:  * @package  Push
 24:  * @author   Gunnar Wrobel <wrobel@pardus.de>
 25:  * @license  http://www.horde.org/licenses/lgpl21 LGPL 2.1
 26:  * @link     http://www.horde.org/components/Horde_Push
 27:  */
 28: class Horde_Push_Cli
 29: {
 30:     /**
 31:      * The main entry point for the application.
 32:      *
 33:      * @param array $parameters A list of named configuration parameters.
 34:      */
 35:     static public function main(array $parameters = array())
 36:     {
 37:         $parser = new Horde_Argv_Parser(
 38:             array('usage' => '%prog [OPTIONS] [SOURCE://ID]')
 39:         );
 40:         $parser->addOptions(
 41:             array(
 42:                 new Horde_Argv_Option(
 43:                     '-c',
 44:                     '--config',
 45:                     array(
 46:                         'action' => 'store',
 47:                         'help'   => Horde_Push_Translation::t('Path to the configuration file.'),
 48:                     )
 49:                 ),
 50:                 new Horde_Argv_Option(
 51:                     '-S',
 52:                     '--summary',
 53:                     array(
 54:                         'action' => 'store',
 55:                         'help'   => Horde_Push_Translation::t('A summary replacing the value provided by the source.'),
 56:                     )
 57:                 ),
 58:                 new Horde_Argv_Option(
 59:                     '-R',
 60:                     '--recipients',
 61:                     array(
 62:                         'action' => 'store',
 63:                         'help'   => Horde_Push_Translation::t('A comma delimited list of recipients.'),
 64:                     )
 65:                 ),
 66:                 new Horde_Argv_Option(
 67:                     '-T',
 68:                     '--tags',
 69:                     array(
 70:                         'action' => 'store',
 71:                         'help'   => Horde_Push_Translation::t('A comma delimited list of tags.'),
 72:                     )
 73:                 ),
 74:                 new Horde_Argv_Option(
 75:                     '-L',
 76:                     '--links',
 77:                     array(
 78:                         'action' => 'store',
 79:                         'help'   => Horde_Push_Translation::t('A comma delimited list of links.'),
 80:                     )
 81:                 ),
 82:                 new Horde_Argv_Option(
 83:                     '-p',
 84:                     '--pretend',
 85:                     array(
 86:                         'action' => 'store_true',
 87:                         'help'   => Horde_Push_Translation::t('Do not push the content but display what would be done.'),
 88:                     )
 89:                 ),
 90:             )
 91:         );
 92:         list($options, $arguments) = $parser->parseArgs();
 93: 
 94:         global $conf;
 95: 
 96:         if (isset($options['config'])) {
 97:             if (!file_exists($options['config'])) {
 98:                 throw new Horde_Push_Exception(
 99:                     sprintf(
100:                         'The specified config file %s does not exist!',
101:                         $options['config']
102:                     )
103:                 );
104:             }
105:             include $options['config'];
106:         } else {
107:             $conf = array('recipients' => array('mock'));
108:         }
109: 
110:         if (empty($arguments)) {
111:             $arguments = explode(' ', trim(file_get_contents('php://stdin')));
112:         }
113:         $push_factory = new Horde_Push_Factory_Push();
114:         $pushes = $push_factory->create($arguments, $options, $conf);
115:         $fail = false;
116:         foreach ($pushes as $push) {
117:             if (isset($options['summary'])) {
118:                 $push->setSummary($options['summary']);
119:             }
120:             if (isset($options['tags'])) {
121:                 foreach (explode(',', $options['tags']) as $tag) {
122:                     $push->addTag($tag);
123:                 }
124:             }
125:             if (isset($options['links'])) {
126:                 foreach (explode(',', $options['links']) as $reference) {
127:                     $push->addReference($reference);
128:                 }
129:             }
130: 
131:             $recipient_factory = new Horde_Push_Factory_Recipients();
132:             $recipients = $recipient_factory->create($options, $conf);
133: 
134:             foreach ($recipients as $recipient) {
135:                 $push->addRecipient($recipient);
136:             }
137: 
138:             $results = $push->push(array('pretend' => !empty($options['pretend'])));
139: 
140:             $cli = Horde_Cli::init();
141:             foreach ($results as $result) {
142:                 if ($result instanceOf Exception) {
143:                     $cli->message($result->getMessage(), 'cli.error');
144:                     $fail = true;
145:                 } else {
146:                     $cli->message((string)$result, 'cli.success');
147:                 }
148:             }
149:         }
150:         if ($fail === true) {
151:             $status = 1;
152:         } else {
153:             $status = 0;
154:         }
155:         if (empty($parameters['no_exit'])) {
156:             exit($status);
157:         } else {
158:             return $status;
159:         }
160:     }
161: }
API documentation generated by ApiGen