function sendQueue($pQueueMixed)
 {
     global $gBitSmarty, $gBitSystem, $gBitLanguage;
     static $body = array();
     if (is_array($pQueueMixed)) {
         $pick = $pQueueMixed;
     } elseif (is_numeric($pQueueMixed)) {
         $pick = $this->mDb->GetRow("SELECT * FROM `" . BIT_DB_PREFIX . "mail_queue` mq WHERE `mail_queue_id` = ? " . $this->mDb->SQLForUpdate(), array($pQueueMixed));
     }
     if (!empty($pick)) {
         $startTime = microtime(TRUE);
         $this->mDb->query("UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `begin_date`=? WHERE `mail_queue_id` = ? ", array(time(), $pick['mail_queue_id']));
         if (!empty($pick['user_id'])) {
             $userHash = $this->mDb->getRow("SELECT * FROM `" . BIT_DB_PREFIX . "users_users` WHERE `user_id`=?", array($pick['user_id']));
             $pick['full_name'] = BitUser::getDisplayName(FALSE, $userHash);
         } else {
             $pick['full_name'] = NULL;
         }
         if (!isset($body[$pick['content_id']])) {
             $gBitSmarty->assign('sending', TRUE);
             // We only support sending of newsletters currently
             $content = new BitNewsletterEdition(NULL, $pick['content_id']);
             if ($content->load()) {
                 $body[$pick['content_id']]['body'] = $content->render();
                 $body[$pick['content_id']]['subject'] = $content->getTitle();
                 $body[$pick['content_id']]['reply_to'] = $content->getField('reply_to', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN']));
                 $body[$pick['content_id']]['object'] = $content;
             } else {
                 bit_error_log($this->mErrors);
             }
             //				$content[$pick['content_id']] = LibertyBase::getLibertyObject();
         }
         print "[ {$pick['mail_queue_id']} ] {$pick['content_id']} TO: {$pick['email']}\t";
         $unsub = $this->getUnsubscription($pick['email'], $pick['nl_content_id']);
         if (!empty($unsub)) {
             print " SKIPPED (unsubscribed) <br/>\n";
             $this->mDb->query("DELETE FROM `" . BIT_DB_PREFIX . "mail_queue` WHERE `mail_queue_id`=?", array($pick['mail_queue_id']));
         } elseif (!empty($body[$pick['content_id']])) {
             $pick['url_code'] = md5($pick['content_id'] . $pick['email'] . $pick['queue_date']);
             $unsub = '';
             if ($body[$pick['content_id']]['object']->mNewsletter->getField('unsub_msg')) {
                 $gBitSmarty->assign('url_code', $pick['url_code']);
             }
             $gBitSystem->preDisplay('');
             $gBitSmarty->assign('sending', TRUE);
             $gBitSmarty->assign('unsubMessage', $unsub);
             $gBitSmarty->assign('trackCode', $pick['url_code']);
             $gBitSmarty->assign('mid', 'bitpackage:newsletters/view_edition.tpl');
             $htmlBody = $gBitSmarty->fetch('bitpackage:newsletters/mail_edition.tpl');
             $htmlBody = bit_add_clickthrough($htmlBody, $pick['url_code']);
             $mailer = new PHPMailer();
             if ($gBitSystem->getConfig('bitmailer_errors_to')) {
                 $mailer->Sender = $gBitSystem->getConfig('bitmailer_errors_to');
                 $mailer->addCustomHeader("Errors-To: " . $gBitSystem->getConfig('bitmailer_errors_to'));
             }
             $mailer->From = $gBitSystem->getConfig('bitmailer_sender_email', $gBitSystem->getConfig('site_sender_email', $_SERVER['SERVER_ADMIN']));
             $mailer->FromName = $gBitSystem->getConfig('bitmailer_from', $gBitSystem->getConfig('site_title'));
             $mailer->Host = $gBitSystem->getConfig('bitmailer_servers', $gBitSystem->getConfig('kernel_server_name', '127.0.0.1'));
             $mailer->Mailer = $gBitSystem->getConfig('bitmailer_protocol', 'smtp');
             // Alternative to IsSMTP()
             $mailer->CharSet = 'UTF-8';
             if ($gBitSystem->getConfig('bitmailer_smtp_username')) {
                 $mailer->SMTPAuth = TRUE;
                 $mailer->Username = $gBitSystem->getConfig('bitmailer_smtp_username');
             }
             if ($gBitSystem->getConfig('bitmailer_smtp_password')) {
                 $mailer->Password = $gBitSystem->getConfig('bitmailer_smtp_password');
             }
             $mailer->WordWrap = $gBitSystem->getConfig('bitmailer_word_wrap', 75);
             if (!$mailer->SetLanguage($gBitLanguage->getLanguage(), UTIL_PKG_PATH . 'phpmailer/language/')) {
                 $mailer->SetLanguage('en');
             }
             $mailer->ClearReplyTos();
             $mailer->AddReplyTo($body[$pick['content_id']]['reply_to'], $gBitSystem->getConfig('bitmailer_from'));
             $mailer->Body = $htmlBody;
             $mailer->Subject = $body[$pick['content_id']]['subject'];
             $mailer->IsHTML(TRUE);
             $mailer->AltBody = '';
             $mailer->AddAddress($pick['email'], $pick["full_name"]);
             if ($mailer->Send()) {
                 print " SENT " . round(microtime(TRUE) - $startTime, 2) . " secs<br/>\n";
                 flush();
                 $updateQuery = "UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `sent_date`=?,`url_code`=?  WHERE `content_id`=? AND `email`=?";
                 $this->mDb->query($updateQuery, array(time(), $pick['url_code'], $pick['content_id'], $pick['email']));
             } else {
                 $updateQuery = "UPDATE `" . BIT_DB_PREFIX . "mail_queue` SET `mail_error`=?,`sent_date`=?  WHERE `content_id`=? AND `email`=?";
                 $this->mDb->query($updateQuery, array($mailer->ErrorInfo, time(), $pick['content_id'], $pick['email']));
                 $pick['error'] = $mailer->ErrorInfo;
                 $this->logError($pick);
             }
         }
     }
 }
Exemple #2
0
            if (!empty($feed['th_sticky'])) {
                $item->title = "[!] " . $item->title;
            }
            if (!empty($feed['th_locked'])) {
                $item->title = "[#] " . $item->title;
            }
            $item->link = 'http://' . $_SERVER['HTTP_HOST'] . $feed['url'];
            $data = BitBoard::getBoard($feed['llc_content_id']);
            $item->description = $data['data'];
            //TODO allow proper sort order
            //$item->date = ( int )$feed['event_date'];
            $item->date = (int) $feed['llc_last_modified'];
            $user = new BitUser($feed['llc_user_id']);
            break;
    }
    $user->load();
    $item->author = $user->getDisplayName();
    //$gBitUser->getDisplayName( FALSE, array( 'user_id' => $feed['modifier_user_id'] ) );
    $item->authorEmail = $user->mInfo['email'];
    $item->descriptionTruncSize = $gBitSystem->getConfig('rssfeed_truncate', 1000);
    $item->descriptionHtmlSyndicated = FALSE;
    /*
    	var_dump($item);
    	echo "</pre>";
    	die();
    	//*/
    // pass the item on to the rss feed creator
    $rss->addItem($item);
}
// finally we are ready to serve the data
echo $rss->saveFeed($rss_version_name, $cacheFile);
Exemple #3
0
function data_spytext($data, $params)
{
    global $gLibertySystem;
    global $gBitUser;
    extract($params, EXTR_SKIP);
    if (empty($data)) {
        // If there is NO data to display - why do anything - get out of here
        return " ";
    }
    // **************** Elvis has left the building!
    $isSpy = $gBitUser->isAdmin() ? TRUE : FALSE;
    // Admin should always see SpyText
    $isRealSpy = FALSE;
    // So Admin does not see EVERY Alert
    if (isset($spy)) {
        // Is the current user on the Spy List
        $spyArray = explode("|", trim(strtolower($spy)));
        // spy's allowed to see the message
        foreach ($spyArray as $i) {
            if ($i == strtolower($gBitUser->getTitle())) {
                $isSpy = TRUE;
                $isRealSpy = TRUE;
            }
        }
    }
    if (isset($agency)) {
        // Is the current user in one of the Spy Agencies
        $spyArray = explode("|", trim(strtolower($agency)));
        // create an array from the string
        $groups = $gBitUser->getGroups();
        foreach ($spyArray as $i) {
            foreach ($groups as $g) {
                if (trim(strtolower($g['group_name'])) == $i) {
                    $isSpy = TRUE;
                    $isRealSpy = TRUE;
                }
            }
        }
    }
    if (!$isSpy) {
        // The current user is NOT a Spy - get out of here
        return " ";
    }
    // **************** Elvis has left the building!
    $addToBox = isset($to) ? TRUE : FALSE;
    if ($addToBox) {
        $toLine = 'To the Spy: ';
        // Set Default
        $agencyLine = 'To the Agency: ';
        // Set Default
        $senderLine = 'From Your Source: ';
        // Set Default
        $header = explode("|", $to);
        $toLine = isset($header[0]) && ($header[0] != '*' && $header[0] != 'TRUE') ? $header[0] . ' ' : $toLine;
        $agencyLine = isset($header[1]) && $header[1] != '*' ? $header[1] . ' ' : $agencyLine;
        $senderLine = isset($header[2]) && $header[2] != '*' ? $header[2] . ' ' : $senderLine;
        $addToLine = FALSE;
        if (isset($spy)) {
            // Provide a Listing of all spys tested
            $spyArray = explode("|", $spy);
            // Strip Out the | character
            natcasesort($spyArray);
            // Sort it
            foreach ($spyArray as $i) {
                if ($gBitUser->userExists(array('login' => $i))) {
                    $toLine = $addToLine ? $toLine . ', ' : $toLine;
                    // misses the first and last Spy
                    $toLine = $toLine . BitUser::getDisplayName(TRUE, array('login' => $i));
                    $addToLine = True;
                }
            }
            $toLine = '<tr><td style="vertical-align: top;">' . $toLine . '</td></tr>';
        }
        $addAgencyLine = FALSE;
        if (isset($agency)) {
            // Provide a Listing of all agencies tested
            $agency_array = explode("|", $agency);
            // Strip Out the | character
            natcasesort($agency_array);
            // Sort it
            $listHash = array('sort_mode' => 'group_name_asc');
            $groups = $gBitUser->getAllGroups($listHash);
            foreach ($agency_array as $i) {
                // TODO - Remove all Non-valid groups - ($i == $i)
                if ($groupId = $gBitUser->groupExists($i)) {
                    $validGroups[$groupId] = $i;
                    $agencyLine = $addAgencyLine ? $agencyLine . ', ' : $agencyLine;
                    // misses the first and last Agency
                    $agencyLine = $agencyLine . '<strong>' . $i . '</strong>';
                    $addAgencyLine = True;
                } else {
                    $k = key($agency_array);
                    unset($agency_array[$k]);
                }
            }
            $agencyLine = '<tr><td style="vertical-align: top;">' . $agencyLine . '</td></tr>';
        }
        $addSenderLine = FALSE;
        if (isset($sender)) {
            // Provide a Listing of all senders tested
            $spyArray = explode("|", $sender);
            // Strip Out the | character
            natcasesort($spyArray);
            // Sort it
            foreach ($spyArray as $i) {
                // TODO - Remove All Non-valid users - ($i == $i)
                if ($gBitUser->userExists(array('login' => $i))) {
                    $senderLine = $addSenderLine ? $senderLine . ', ' : $senderLine;
                    // misses the first and last Spy
                    $senderLine = $senderLine . BitUser::getDisplayName(TRUE, array('login' => $i));
                    $addSenderLine = TRUE;
                }
            }
            $senderLine = '<tr><td style="vertical-align: top;">' . $senderLine . '</td></tr>';
        }
        $spyId = 'spydata' . microtime() * 1000000;
        $toHeader = '<div>' . '<table width="100%" border="0" cellspacing="0" cellpadding="0">' . '<tr>' . '<td width=42%><hr></td>' . '<td style="text-align:center">' . '<a title="Expand/Contract for Addresses" href="javascript:flip(' . $spyId . ')">Address</a>' . '</td>' . '<td width=42%><hr></td>' . '</tr>' . '</table>' . '</div>';
        $addToBox = $addToBox && ($addToLine || ($addAgencyLine || $addSenderLine)) ? TRUE : FALSE;
        if ($addToBox) {
            $toBox = '<div>';
            // Wrap's Arround Everything in toBox
            $toBox = $toBox . $toHeader . '<div style="display:none;" id="' . $spyId . '"><table border="1">';
            $toBox = $addToLine ? $toBox . $toLine : $toBox;
            // Drop toLine if nothing on it
            $toBox = $addAgencyLine ? $toBox . $agencyLine : $toBox;
            // Drop agencyLine if nothing on it
            $toBox = $addSenderLine ? $toBox . $senderLine : $toBox;
            // Drop fromLine if nothing on it
            $toBox = $toBox . '</table></div>';
            $toBox = $toBox . '</div>';
        }
    }
    $spyId = 'spydata' . microtime() * 1000000;
    $hidden = isset($hidden) ? TRUE : FALSE;
    if ($hidden) {
        $useIcon = isset($icon) ? TRUE : FALSE;
        if ($useIcon) {
            if (trim(strtoupper($icon)) == 'TRUE') {
                $spyLink = '<a href="javascript:flip(' . $spyId . ')"><img src="' . LIBERTY_PKG_URL . 'icons/spy.gif"></img></a>';
            }
            // Default
            // --------------------------> TODO - Need to set with Content Id No's
            if (!isset($spyLink)) {
                $spyLink = '<a href="javascript:flip(' . $spyId . ')"><img src="' . $icon . '"></img></a>';
                // Last Choice - A URL
            } else {
                $spyLink = '<a href="javascript:flip(' . $spyId . ')"><img src="' . LIBERTY_PKG_URL . 'icons/spy.gif"></img></a>';
                // Default
            }
            // Place the default last
        } else {
            // It's not linked to an Icon - so - It needs Title Bar
            $width = isset($width) ? $width : '20';
            $width = (100 - $width) / 2 . '%';
            $title = isset($title) ? $title : 'A Hidden Message';
            $spyLink = '<div>' . '<table width="100%" border="0" cellspacing="0" cellpadding="0">' . '<tr>' . '<td width=' . $width . '><hr></td>' . '<td style="text-align:center">' . '<a title="Expand/Contract for Hidden Text" href="javascript:flip(' . $spyId . ')">' . $title . '</a>' . '</td>' . '<td width=' . $width . '><hr></td>' . '</tr>' . '</table>' . '</div>';
        }
    }
    $ret = $hidden ? $spyLink . '<div class="help box" style="display:none;" id="' . $spyId . '">' : '';
    $ret = $addToBox ? $ret . $toBox : $ret;
    $ret = $ret . '<div class="help box" style="text-align:left;">' . $data . '</div>';
    $ret = $hidden ? $ret . '</div>' : $ret;
    // I'm NOT Sure if this should be include or not - especially the way I have it set up
    // I have reduced the number of Alerts that an Admin would recieve - Only Hidden Messages
    $spyAlert = FALSE;
    if (isset($alert)) {
        if (strtoupper(trim($alert)) == 'TRUE') {
            $spyAlert = TRUE;
            $spyMsg = $isRealSpy ? 'Wake Up *UserName*!\\nThere is a message on this page for you.\\nUse your Secret Decoder Ring!' : '';
        } else {
            $spyAlert = TRUE;
            $spyMsg = $alert;
        }
    }
    if ($gBitUser->isAdmin() && $hidden) {
        $spyMsg = '*UserName*\\nThere is Hidden SpyText on this page.';
        $spyAlert = TRUE;
    }
    if ($spyAlert) {
        $spyArray = explode("*", $spyMsg);
        // Process the *UserName*
        for ($i = 0; $i <= count($spyArray) - 1; $i++) {
            $spyArray[$i] = trim(strtoupper($spyArray[$i])) == 'USERNAME' ? $gBitUser->getTitle() : $spyArray[$i];
        }
        $spyMsg = implode(" ", $spyArray);
        echo "<script>window.alert(\"" . $spyMsg . "\");</script>";
    }
    return $ret;
}
 /**
  * store Any method named Store inherently implies data will be written to the database
  * @param pParamHash be sure to pass by reference in case we need to make modifcations to the hash
  * This is the ONLY method that should be called in order to store( create or update )an suggestion!
  * It is very smart and will figure out what to do for you. It should be considered a black box.
  * 
  * @param array $pParamHash hash of values that will be used to store the page
  * @access public
  * @return boolean TRUE on success, FALSE on failure - mErrors will contain reason for failure
  */
 function store(&$pParamHash)
 {
     if ($this->verify($pParamHash) && LibertyMime::store($pParamHash)) {
         $this->mDb->StartTrans();
         $table = BIT_DB_PREFIX . "suggestion_data";
         if ($this->mSuggestionId) {
             $locId = array("suggestion_id" => $pParamHash['suggestion_id']);
             $result = $this->mDb->associateUpdate($table, $pParamHash['suggestion_store'], $locId);
         } else {
             $pParamHash['suggestion_store']['content_id'] = $pParamHash['content_id'];
             if (@$this->verifyId($pParamHash['suggestion_id'])) {
                 // if pParamHash['suggestion_id'] is set, some is requesting a particular suggestion_id. Use with caution!
                 $pParamHash['suggestion_store']['suggestion_id'] = $pParamHash['suggestion_id'];
             } else {
                 $pParamHash['suggestion_store']['suggestion_id'] = $this->mDb->GenID('suggestion_data_id_seq');
             }
             $this->mSuggestionId = $pParamHash['suggestion_id'] = $pParamHash['suggestion_store']['suggestion_id'];
             if ($result = $this->mDb->associateInsert($table, $pParamHash['suggestion_store'])) {
                 // send an email notification to subscribers
                 // load up creator user in case user_id was forced and is not the same as gBitUser
                 $user = new BitUser($pParamHash['user_id']);
                 $user->load();
                 $userName = $user->getDisplayName();
                 $userEmail = $user->getField('email');
                 // Draft the message body:
                 $body = "/----- " . tra('A new suggestion was submitted.') . " -----/\n\n" . "Submitted by: \n" . $userName . "\n" . $userEmail . "\n\n" . "Title: \n" . $pParamHash['title'] . "\n\n" . "Megawatt Hours / Year: \n" . $pParamHash['suggestion_store']['mwh'] . "\n\n" . "Description: \n" . $pParamHash['edit'] . "\n\n" . "Sources: \n" . $pParamHash['suggestion_store']['sources'];
                 $msgHash = array('subject' => tra('New Suggestion') . ': ' . $pParamHash['title'], 'alt_message' => $body);
                 global $gSwitchboardSystem;
                 // register the sender to be able to access it
                 $gSwitchboardSystem->registerSender(SUGGESTION_PKG_TITLE, 'new suggestion');
                 // fire a notification
                 $gSwitchboardSystem->sendEvent(SUGGESTION_PKG_TITLE, 'new suggestion', $pParamHash['content_id'], $msgHash);
                 // cheating by accessing directly - remove the sender because access should be restricted
                 unset($gSwitchboardSystem->mSenders[SUGGESTION_PKG_TITLE]);
             }
         }
         // $this->storeRefs( $pParamHash );
         $this->mDb->CompleteTrans();
         $this->load();
     } else {
         $this->mErrors['store'] = 'Failed to save this suggestion.';
     }
     return count($this->mErrors) == 0;
 }