function post_published_tweet($new_status, $old_status, $post)
{
    if ('publish' !== $new_status or 'publish' === $old_status) {
        return;
    }
    if (!get_option("tweet_new_publication")) {
        return;
    }
    $post_id = $post->ID;
    $post_type = get_post_type($post_id);
    if ($post_type == 'enlaces') {
        return;
    }
    $post_title = get_the_title($post_id);
    $post_url = get_permalink($post_id);
    $post_obj = get_post_type_object($post_type);
    $post_sin = $post_obj->labels->singular_name;
    $max_size = 80;
    if (strlen($post_title) > $max_size) {
        $leng = strlen($post_title) - $max_size;
        $post_title_s = substr($post_title, 0, -$leng);
        $post_title = $post_title_s . '...';
    }
    $mensaje = '#' . $post_sin . ' ' . $post_title . ' ' . $post_url;
    sendTweet($mensaje);
}
Example #2
0
 public function index_post()
 {
     //checkIsLoggedIn($this);
     $status = 404;
     $return["result"] = "NOOK";
     $arrOptions['publicationId'] = $this->post('publicationId') > 0 ? $this->post('publicationId') : 0;
     $arrOptions['user'] = $this->post('userId');
     $arrOptions['type'] = '2';
     $arrOptions['title'] = $this->post('title');
     $arrOptions['description'] = $this->post('description');
     $arrOptions['creationDate'] = "";
     $arrOptions['expirationDate'] = mdate("%Y/%m/%d %H:%i:%s", $this->post('expirationDate'));
     $arrOptions['category'] = $this->post('categoryId');
     $arrOptions['subcategory'] = $this->post('subcategoryId');
     $arrOptions['views'] = $this->post('views');
     $arrOptions['processState'] = $this->post('processStateId');
     $arrOptions['object'] = $this->post('objectId');
     $arrOptions['quantity'] = $this->post('quantity');
     $arrOptions['image'] = $this->post('image');
     $arrOptions['votes'] = $this->post('votes');
     $arrOptions['sponsors'] = $this->post('sponsors');
     $arrOptions['sponsorsn'] = $this->post('sponsorsn');
     $request = CI_Request::getDataFromArray($arrOptions);
     if ($request != NULL) {
         $arrInfo['user'] = $arrOptions['user'];
         $arrInfo['type'] = $arrOptions['type'];
         $arrInfo['image'] = $arrOptions['image'];
         $arrInfo['sponsors'] = $arrOptions['sponsors'];
         $arrInfo['sponsorsn'] = $arrOptions['sponsorsn'];
         $arrInfo['request'] = $request;
         $id = CI_Request::save($arrInfo);
         if ($id != NULL) {
             $status = 200;
             $return["result"] = "OK";
             $return["data"] = "";
             $return["publicationId"] = $id;
             $myRequest = CI_Request::getData($request);
             $return["data"] = $myRequest;
             if (!empty($arrOptions['sponsorsn'])) {
                 foreach ($arrOptions['sponsorsn'] as $key => $sponsor) {
                     $myMsj = "{$sponsor['label']} Han pedido que seas el padrino de http://localhost/ayudaresfacil/client/build/#/detalle-mi-pedido/{$id} Ingresa para saber mas :)";
                     sendTweet($myMsj);
                 }
             }
             if (!empty($arrOptions['sponsors'])) {
                 foreach ($arrOptions['sponsors'] as $key => $sponsor) {
                     $myMsj = "{$sponsor['label']} Han pedido que seas el padrino de http://localhost/ayudaresfacil/client/build/#/detalle-mi-pedido/{$id} Ingresa para saber mas :)";
                     sendTweet($myMsj);
                 }
             }
         }
     }
     $this->response($return, $status);
 }
function theme_wpdc_settings_twitter()
{
    if (!current_user_can('manage_options')) {
        wp_die('You do not have sufficient permissions to access this page.');
    } else {
        if (isset($_POST["update_settings"])) {
            $automate_twitter = esc_attr($_POST["automate_twitter"]);
            update_option("automate_twitter", $automate_twitter);
            $consumer_key = esc_attr($_POST["consumer_key"]);
            update_option("consumer_key", $consumer_key);
            $consumer_secret = esc_attr($_POST["consumer_secret"]);
            update_option("consumer_secret", $consumer_secret);
            $access_token = esc_attr($_POST["access_token"]);
            update_option("access_token", $access_token);
            $access_token_secret = esc_attr($_POST["access_token_secret"]);
            update_option("access_token_secret", $access_token_secret);
            if (!isset($_POST["tweet_prueba"])) {
                echo '<div id="message" class="updated">Configuración guardada</div>';
            }
        } else {
            $automate_twitter = get_option("automate_twitter");
            $consumer_key = get_option("consumer_key");
            $consumer_secret = get_option("consumer_secret");
            $access_token = get_option("access_token");
            $access_token_secret = get_option("access_token_secret");
        }
        if (isset($_POST["update_settings_twitter"])) {
            $tweet_new_user = esc_attr($_POST["tweet_new_user"]);
            update_option("tweet_new_user", $tweet_new_user);
            $follow_new_user = esc_attr($_POST["follow_new_user"]);
            update_option("follow_new_user", $follow_new_user);
            $tweet_new_publication = esc_attr($_POST["tweet_new_publication"]);
            update_option("tweet_new_publication", $tweet_new_publication);
        } else {
            $tweet_new_user = get_option("tweet_new_user");
            $follow_new_user = get_option("follow_new_user");
            $tweet_new_publication = get_option("tweet_new_publication");
        }
        if (isset($_POST["tweet_prueba"])) {
            $respuesta = sendTweet("Tweet de prueba desde diseñadoresindustriales.es");
            echo '<div id="message" class="updated">Tweet enviado! Comprueba tu perfil de twitter.</div>';
        }
        ?>

    <div class="wrap">
        <h2>Configuración general de twitter</h2>
        <p>Para configurar automáticamente una cuenta de twitter para que responda a eventos de la web, como registro de usuarios o publicación de entradas, es necesario obtener unas claves en twitter que te habilitarán como desarrollador. Estas claves se asocian a la cuenta de twitter con la que habilites la opción de desarrollador.</p>
      	<p>Puedes obtener las credenciales de twitter aquí: <a href="https://apps.twitter.com/">apps.twitter.com</a></p>
        <form method="POST" action="">
            <table class="form-table">
              <tr valign="top">
                  <th scope="row"><label for="automate_twitter">Activar automatización</label></th>
                  <td><input type="checkbox" name="automate_twitter" value="true" <?php 
        if ($automate_twitter == true) {
            echo 'checked';
        }
        ?>
/></td>
              </tr>
                <tr valign="top">
                    <th scope="row"><label for="consumer_key">Consumer key:</label></th>
                    <td><input type="text" name="consumer_key" size="50" value="<?php 
        echo $consumer_key;
        ?>
"/></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label for="consumer_secret">Consumer secret:</label></th>
                    <td><input type="text" name="consumer_secret" size="50" value="<?php 
        echo $consumer_secret;
        ?>
"/></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label for="access_token">Access token:</label></th>
                    <td><input type="text" name="access_token" size="50" value="<?php 
        echo $access_token;
        ?>
"/></td>
                </tr>
                <tr valign="top">
                    <th scope="row"><label for="access_token_secret">Access token secret:</label></th>
                    <td><input type="text" name="access_token_secret" size="50" value="<?php 
        echo $access_token_secret;
        ?>
"/></td>
                </tr>
            </table>
          <p class="submit">
            <input type="hidden" name="update_settings" value="Y" />
          	<input type="submit" class="button button-primary" value="Guardar cambios">
            <?php 
        if ($consumer_key != '' && $consumer_secret != '' && $access_token != '' && $access_token_secret != '') {
            ?>
								<input type="submit" name="tweet_prueba" class="button button-primary" style="background: cadetblue;" value="Enviar tweet de prueba">
            <?php 
        } else {
            ?>
                <input type="submit" name="" class="button button-primary" style="background: grey;" value="Enviar tweet de prueba" disabled>
						<?php 
        }
        ?>
          </p>
        </form>
      <p></p>
        <h2>Activación de servicios de twitter</h2>
        <form method="POST" action="">
          <p>¿Cuando quieres lanzar los tweets?</p>
          <table class="form-table">
              <tr valign="top">
                  <th scope="row"><label for="tweet_new_user">Anunciar confirmación de nuevos usuarios:</label></th>
                  <td><input type="checkbox" name="tweet_new_user" value="true" <?php 
        if ($tweet_new_user == true) {
            echo 'checked';
        }
        ?>
/></td>
              </tr>
              <tr valign="top">
                  <th scope="row"><label for="tweet_new_publication">Anunciar aprobación de nuevos post:</label></th>
                  <td><input type="checkbox" name="tweet_new_publication" value="true" <?php 
        if ($tweet_new_publication == true) {
            echo 'checked';
        }
        ?>
/></td>
              </tr>
          </table>
          <p>¿A qué usuarios quieres seguir automáticamente?</p>
          <table class="form-table">
              <tr valign="top">
                  <th scope="row"><label for="follow_new_user">Nuevos usuarios confirmados:</label></th>
                  <td><input type="checkbox" name="follow_new_user" value="true" <?php 
        if ($follow_new_user == true) {
            echo 'checked';
        }
        ?>
/></td>
              </tr>
          </table>
          <p class="submit">
            <input type="hidden" name="update_settings_twitter" value="Y" />
          	<input type="submit" class="button button-primary" value="Guardar cambios">
          </p>
        </form>
    </div>
<?php 
    }
}
     update_option("consumer_secret", $consumer_secret);
     $access_token = esc_attr($_POST["access_token"]);
     update_option("access_token", $access_token);
     $access_token_secret = esc_attr($_POST["access_token_secret"]);
     update_option("access_token_secret", $access_token_secret);
     $tweet_new_user = esc_attr($_POST["tweet_new_user"]);
     update_option("tweet_new_user", $tweet_new_user);
     $follow_new_user = esc_attr($_POST["follow_new_user"]);
     update_option("follow_new_user", $follow_new_user);
     $tweet_new_publication = esc_attr($_POST["tweet_new_publication"]);
     update_option("tweet_new_publication", $tweet_new_publication);
     $alerts_success .= '<p>Configuración de twitter guardada</p>';
 }
 if (!empty($_POST['updatesection']) && $_POST['updatesection'] == 'tweet-test') {
     $tweet_msg = 'Test';
     $respuesta = sendTweet($tweet_msg);
     $alerts_success .= '<p>Tweet enviado!</p>';
 }
 if (!empty($_POST['updatesection']) && $_POST['updatesection'] == 'texts-update') {
     $tos_link = esc_attr($_POST["tos_link"]);
     update_option("tos_link", $tos_link);
     $text_register = esc_attr($_POST["text_register"]);
     update_option("text_register", $text_register);
     $text_subscriber_upgrade = esc_attr($_POST["text_subscriber_upgrade"]);
     update_option("text_subscriber_upgrade", $text_subscriber_upgrade);
     $text_asociate_payfee = esc_attr($_POST["text_asociate_payfee"]);
     update_option("text_asociate_payfee", $text_asociate_payfee);
     $text_asociate_payfee_banks = esc_attr($_POST["text_asociate_payfee_banks"]);
     update_option("text_asociate_payfee_banks", $text_asociate_payfee_banks);
     $alerts_success .= '<p>Configuración de textos actualizada</p>';
 }
Example #5
0
/**
 *
 * Formats the message and calls sendTweet() on an object
 * @param object $obj
 */
function tweetObject($obj)
{
    global $_zp_UTF8;
    $error = '';
    $link = getTinyURL($obj);
    switch ($type = $obj->table) {
        case 'pages':
        case 'news':
            $text = trim(html_entity_decode(strip_tags($obj->getContent()), ENT_QUOTES));
            if (strlen($text) > 140) {
                $title = trim(html_entity_decode(strip_tags($obj->getTitle()), ENT_QUOTES));
                $c = 140 - strlen($link);
                if ($_zp_UTF8->strlen($title) >= $c - 25) {
                    //	not much point in the body if shorter than 25
                    $text = truncate_string($title, $c - 4, '... ') . $link;
                    //	allow for ellipsis
                } else {
                    $c = $c - $_zp_UTF8->strlen($title) - 5;
                    $text = $title . ':' . truncate_string($text, $c, '... ') . $link;
                }
            }
            $error = sendTweet($text);
            if ($error) {
                $error = sprintf(gettext('Error tweeting <code>%1$s</code>: %2$s'), $obj->getTitlelink(), $error);
            }
            break;
        case 'albums':
        case 'images':
            if ($type == 'images') {
                $text = sprintf(gettext('New image:[%2$s]%1$s '), $item = trim(html_entity_decode(strip_tags($obj->getTitle()), ENT_QUOTES)), trim(html_entity_decode(strip_tags($obj->album->name), ENT_QUOTES)));
            } else {
                $text = sprintf(gettext('New album:%s '), $item = trim(html_entity_decode(strip_tags($obj->getTitle()), ENT_QUOTES)));
            }
            if ($_zp_UTF8->strlen($text . $link) > 140) {
                $c = 140 - strlen($link);
                $text = truncate_string($text, $c - 4, '... ') . $link;
                //	allow for ellipsis
            } else {
                $text = $text . $link;
            }
            $error = sendTweet($text);
            if ($error) {
                $error = sprintf(gettext('Error tweeting <code>%1$s</code>: %2$s'), $item, $error);
            }
            break;
        case 'comments':
            $text = trim(html_entity_decode(strip_tags($obj->getComment()), ENT_QUOTES));
            if ($_zp_UTF8->strlen($text . $link) > 140) {
                $c = 140 - strlen($link);
                $text = truncate_string($text, $c - 4, '... ') . $link;
                //	allow for ellipsis
            } else {
                $text = $text . $link;
            }
            $error = sendTweet($text);
            if ($error) {
                $error = sprintf(gettext('Error tweeting <code>%1$s</code>: %2$s'), $item, $error);
            }
            break;
    }
    return $error;
}