コード例 #1
0
ファイル: start.php プロジェクト: rijojoy/MyIceBerg
function westorElggMan_cron_handler($hook, $entity_type, $returnvalue, $params)
{
    global $CONFIG;
    // old elgg bevore 1.7.0
    global $is_admin;
    $is_admin = true;
    if (function_exists("elgg_set_ignore_access")) {
        // new function for access overwrite
        elgg_set_ignore_access(true);
    }
    $context = westorElggMan_get_context();
    westorElggMan_set_context('westorElggMan');
    $prefix = $CONFIG->dbprefix;
    $sql = "SELECT {$prefix}metadata.entity_guid\nFROM (({$prefix}metadata AS {$prefix}metadata_1 INNER JOIN {$prefix}metastrings AS {$prefix}metastrings_3\nON {$prefix}metadata_1.name_id = {$prefix}metastrings_3.id) INNER JOIN {$prefix}metastrings\nAS {$prefix}metastrings_2 ON {$prefix}metadata_1.value_id = {$prefix}metastrings_2.id) INNER JOIN (({$prefix}metadata INNER JOIN {$prefix}metastrings ON {$prefix}metadata.name_id = {$prefix}metastrings.id) INNER JOIN {$prefix}metastrings AS {$prefix}metastrings_1 ON {$prefix}metadata.value_id = {$prefix}metastrings_1.id) ON {$prefix}metadata_1.entity_guid = {$prefix}metadata.entity_guid\nWHERE ((({$prefix}metastrings.string)='waitForSend') AND (({$prefix}metastrings_1.string)='1')\nAND (({$prefix}metastrings_3.string)='hiddenTo') AND (({$prefix}metastrings_2.string)<>'1'))";
    // and (scheduled is null || scheduled <= now());
    try {
        $result = get_data($sql);
    } catch (Exception $e) {
        westorElggMan_set_context($context);
        throw new Exception($e);
    }
    if (is_array($result)) {
        $elggMan = new class_elggMan();
        $now = date("Y-m-d H:i:s");
        foreach ($result as $row) {
            $message = westorElggMan_get_entity($row->entity_guid);
            if (is_object($message) && $message->getSubtype() == "messages" && ($message->scheduled == null || $message->scheduled <= $now)) {
                $elggMan->sendMsgNow($message);
            }
        }
    }
    westorElggMan_set_context($context);
}
コード例 #2
0
ファイル: elggMan.php プロジェクト: rijojoy/MyIceBerg
 function method_pushMessage($params, $error = null)
 {
     if (!$this->is_loggedin()) {
         return array("err" => SESSION_ERROR);
     }
     global $CONFIG;
     $context = westorElggMan_get_context();
     westorElggMan_set_context('westorElggMan');
     // Plugin Settings
     // 'FullMail', 'Notify', 'NoMessage', 'NoInbox'
     $messageSendOption = westorElggMan_get_plugin_setting('messageSendOption', 'westorElggMan');
     if (!$messageSendOption) {
         $messageSendOption = 'FullMail';
     }
     $useCronOption = westorElggMan_get_plugin_setting('useCronOption', 'westorElggMan');
     if (!$useCronOption) {
         $useCronOption = 'no';
     }
     $allowSendToAllOption = westorElggMan_get_plugin_setting('allowSendToAllOption', 'westorElggMan');
     $owner = $_SESSION['user'];
     $from = (int) $owner->guid;
     $options = unserialize($owner->smsOptions);
     // SMS-HQ, SMS-BASIC, EMAIL, EMAILTXT, MMS
     $mType = $params[0];
     $lastSMSAccountBalance = $options["lastSMSAccountBalance"];
     $recipients = $params[1];
     $body = $params[2];
     $subject = $params[3];
     if (($mType == "EMAIL" || $mType == "EMAILTXT") && !($subject > '')) {
         $subject = elgg_echo("ElggMan_:noSubject");
     }
     // message empty?
     if ($subject == elgg_echo("ElggMan_:noSubject") && (!strlen($body) || $body == '<br />')) {
         return array("err" => elgg_echo("ElggMan_:noMessageTxt"));
     }
     // shedule
     if ($params[4]) {
         // in Form yyyy-mm-tt hh:mm:ss
         // $messageSchedule = "'" . mysql_real_escape_string($params[4]) . "'";
         $messageSchedule = mysql_real_escape_string($params[4]);
     } else {
         $messageSchedule = null;
     }
     $count = 0;
     if (is_array($recipients)) {
         foreach ($recipients as $recipient) {
             // Ersetzungen
             $link = $CONFIG->wwwroot . 'account/register.php?friend_guid=' . $_SESSION['guid'] . '&invitecode=' . generate_invite_code($_SESSION['user']->username);
             //            $search = array("/%%name%%/", "/%%registration_link%%/", "/%%sender_name%%/");
             //            $replace = array($recipient[1], $link, $owner->name);
             //            $body = preg_replace($search, $replace, $body);
             if (is_array($recipient)) {
                 $to = $recipient[0];
             } else {
                 $to = $recipient;
             }
             $recp = westorElggMan_get_entity($to);
             if ($recp instanceof ElggUser || $recp->getSubtype() == "PrivateContact") {
                 // if the user shall only send messages to friends and private contacs, continue
                 // normally this only occures when someone hacks the client code.
                 if ($allowSendToAllOption == 'no' && !($this->is_admin() || $recp->isFriendsWith($_SESSION['guid']) || $recp->getSubtype() == "PrivateContact")) {
                     continue;
                 }
                 if ($recp == $_SESSION['user']) {
                     continue;
                 }
                 // no message to current user
                 $msgObjToSend = $this->createMessageObject("messages", $mType, $from, $to, $subject, $body, $messageSchedule);
                 if ($recp->getSubtype() != "PrivateContact" && ($mType == "EMAIL" || $mType == "EMAILTXT")) {
                     $message_copy_for_recipient = clone $msgObjToSend;
                     $message_copy_for_recipient->waitForSend = 0;
                     $message_copy_for_recipient->state = 'copy';
                     $message_copy_for_recipient->save();
                     $message_copy_for_recipient->access_id = ACCESS_PRIVATE;
                     $message_copy_for_recipient->changeOwner($to);
                 }
                 if ($recp->getSubtype() != "PrivateContact" && $messageSendOption == 'Notify') {
                     $this->sendDirectNotification($recp, $body);
                 }
                 ///////////////////////////////
                 // for DEMO Account send direct
                 ///////////////////////////////
                 if ($useCronOption == 'yes' && $mType == "HQ-SMS") {
                     $smsRes[] = $this->sendMsgNow($msgObjToSend);
                 }
                 if ($useCronOption == 'no' && ($messageSendOption == 'FullMail' || $recp->getSubtype() == "PrivateContact" || $mType == "HQ-SMS")) {
                     $smsRes[] = $this->sendMsgNow($msgObjToSend);
                 }
                 $count++;
             }
         }
     }
     westorElggMan_set_context($context);
     $result["txt"] = sprintf(elgg_echo('ElggMan_:messagesSaved'), $count);
     if (is_array($smsRes)) {
         foreach ($smsRes as $smsR) {
             if ($smsR["txt"]) {
                 $result["txt"] .= "\n" . $smsR["txt"];
             }
         }
     }
     return $result;
 }