</div>
    </div>
    <div class="contentfull">
        
<?php 
if ($_SESSION['do_ofuz_fb']->fb_uid) {
    $_SESSION['do_ofuz_fb']->connected = true;
    $do_contact = new Contact();
    // Adding to the JOB QUEUE
    if ($GLOBALS['ENABLE_JOB_QUEUE'] === true) {
        $data_fb = serialize($_SESSION['do_ofuz_fb']);
        /*$qry = new sqlQuery($conx);
          $qry->query("insert into fb_test (data,iduser) values ('".$data_fb."',".$_SESSION['do_User']->iduser.")");
          */
        $OfuzBeanstalkd = new OfuzBeanstalkd();
        $OfuzBeanstalkd->addToQueue($data_fb, 'jobqueue_fb_friend_import', $_SESSION['do_User']->iduser);
        echo '<H2>Request has been added in the Job Queue, you can enjoy browsing the other part and Ofuz will do the import for you without having to wait for a long time on this page.</H2>';
        exit;
    }
    try {
        @($friends = $_SESSION['do_ofuz_fb']->getFbFriends());
        // will contain the fbid of friends
    } catch (Exception $e) {
        $_SESSION['do_ofuz_fb']->setUserNull(null, null);
        echo _('Oops ! something wrong, seems like the facebook session is no longer valid, please clear the bowser cookies and retry. We appriciate your patience');
        //echo '<br /><a href="/fb_import_friends.php">'._('Click Here').'</a>';
        exit;
    }
    $list = $_SESSION['do_ofuz_fb']->getFriendsList();
    $count = count(@$friends);
    $i = 1;
Exemple #2
0
 /**
  *  sendMessage
  *  This abstract the message sending so we use a general function
  *  that will send email or facebook or twitter based on the user
  *  preferences and settings.
  *  its possible to generate an EmailTemplate on the fly with no records in the DB
  *  Here is an exemple:
  *  <code php>
  *  $do_template = new EmailTemplate();
  *  $do_template->senderemail = "*****@*****.**";
  *  $do_template->sendername = "Philippe Lewicki";
  *  $do_template->subject = "This is an example";
  *  $do_template->bodytext = "This is the content of the sample message";
  *  $do_template->bodyhtml = nl2br($do_template->bodytext);
  *  </code>
  * 
  *  An other example more OO / stylish
  *  <code php>
  *  $do_template = new EmailTemplate();
  *  $do_template->setFrom("*****@*****.**", "Philippe Lewicki")
  *              ->setSubject("This is an example")
  *              ->setMessage("This is the content of the sample message");
  *  </code>
  *  setFrom() is optional, if not provided it takes the do_User data
  *  
  *  Then send the message with:  $contact->sendMessage($do_template);
  * 
  *  If you used a saved EmailTemplate like
  *  $do_template = new EmailTemplate("my template in email template table");
  *  and want the sender to be the currently signed in user, make sure the senderemail field
  *  is empty.
  * 
  *  @param $message an EmailTemplate object.
  *  @param $values an array with values to merge, optional.
  *  
  */
 function sendMessage($template, $values = array())
 {
     if (!is_object($template)) {
         return false;
     }
     if (empty($values)) {
         $values = $this->getValues();
     }
     $this->last_message_sent = false;
     $do_contact_email = $this->getChildContactEmail();
     $email_to = $do_contact_email->getDefaultEmail();
     $this->setLog("\n Sending message to:" . $email_to);
     $contact_link = '<a href="/Contact/' . $this->idcontact . '">' . $this->firstname . ' ' . $this->lastname . '</a>';
     $do_ofuzBeanstalkd = new OfuzBeanstalkd();
     $do_ofuzBeanstalkd->addToQueue($mail_data, 'jobqueue_send_mail', $_SESSION['do_User']->iduser);
     echo 'Job Queue requested';
     exit;
     if (strlen($email_to) > 4) {
         if ($this->email_optout != 'y') {
             /*    
                if (strlen($email_to) > 4) { 
                         if ($this->email_optout != 'y') {
                             $emailer = new Ofuz_Emailer('UTF-8');
                             if (strlen($template->senderemail) == 0) {
                                 $template->setFrom($_SESSION['do_User']->email,  $_SESSION['do_User']->getFullName());				
                             }
                             $emailer->setEmailTemplate($template);
                             $emailer->mergeArrayWithFooter($values);
                             $emailer->addTo($email_to);
                             $this->last_message_sent = true;
                             echo "<pre>";
                             print_r($emailer);
                             echo "</pre>";
                             exit;
                             return $emailer->send();*/
         } else {
             $_SESSION['in_page_message'] .= _("<br>" . $contact_link . " has opt-out and will not receive this email");
         }
     } elseif (strlen($this->tw_user_id) > 0) {
         // send direct message using twitter api.
         try {
             $do_twitter = new OfuzTwitter();
             $tw_config = $do_twitter->getTwitterConfig();
             $serialized_token = $do_twitter->getAccessToken();
             $token = unserialize($serialized_token);
             $ofuz_twitter = new Ofuz_Service_Twitter($token->getParam('user_id'), $tw_config, $token);
             $followers = $ofuz_twitter->userFollowers(false);
             if (is_object($followers) && count($followers->user) > 0) {
                 foreach ($followers->user as $follower) {
                     if ($follower->id == $this->tw_user_id) {
                         $merge = new MergeString();
                         $message = $merge->withArray($template->bodytext, $values);
                         $ofuz_twitter->directMessageNew($this->tw_user_id, $message);
                         $do_contact_notes = new ContactNotes();
                         $do_contact_notes->iduser = $_SESSION['do_User']->iduser;
                         $do_contact_notes->note = $message;
                         $do_contact_notes->date_added = date('Y-m-d');
                         $do_contact_notes->idcontact = $this->idcontact;
                         $do_contact_notes->add();
                         return true;
                     }
                 }
             }
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         } catch (Exception $e) {
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         }
     } elseif ($this->fb_userid && $_SESSION["do_User"]->global_fb_connected) {
         // send message using facebook api.
         include_once 'facebook_client/facebook.php';
         include_once 'class/OfuzFacebook.class.php';
         $facebook = new Facebook(FACEBOOK_API_KEY, FACEBOOK_APP_SECRET);
         try {
             $msg = _(' has sent the following message using ofuz') . '<br />';
             $msg .= '<b>' . $template->subject . '</b><br/>' . $template->bodyhtml;
             $facebook->api_client->notifications_send($this->fb_userid, $msg, 'user_to_user');
             //$this->last_message_sent = true;
         } catch (Exception $e) {
             $_SESSION['in_page_message'] .= _("<br>Notification can not be sent to " . $contact_link);
         }
     } else {
         $_SESSION['in_page_message'] .= _("<br>" . $contact_link . " doesn't have a valid email address, facebook account, or twitter id.");
     }
     if ($this->last_message_sent) {
         return true;
     } else {
         return false;
     }
 }