Ejemplo n.º 1
0
 /**
  * go through all accounts and collect information
  *
  * returns array of count of... [$num_notification_sent, $num_warnings]
  */
 public static function sendNotifications()
 {
     global $PH;
     $people = Person::getPeople(array('visible_only' => false, 'can_login' => true));
     $num_notifications_sent = 0;
     $num_warnings = 0;
     foreach ($people as $p) {
         if ($p->settings & USER_SETTING_NOTIFICATIONS) {
             if ($p->office_email || $p->personal_email) {
                 $now = time();
                 $last = strToGMTime($p->notification_last);
                 $period = $p->notification_period * 60 * 60 * 24;
                 if (strToGMTime($p->notification_last) + $period < time() || $period == -1) {
                     $email = new EmailNotification($p);
                     if ($email->information_count) {
                         $result = $email->send();
                         if ($result === true) {
                             ### reset activation-flag ###
                             $p->settings &= USER_SETTING_SEND_ACTIVATION ^ RIGHT_ALL;
                             $p->notification_last = gmdate("Y-m-d H:i:s");
                             $p->update();
                             $num_notifications_sent++;
                         } else {
                             if ($result !== false) {
                                 $num_warnings++;
                                 new FeedbackWarning(sprintf(__('Failure sending mail: %s'), $result));
                             }
                         }
                     }
                 }
             }
         }
     }
     return array($num_notifications_sent, $num_warnings);
 }
Ejemplo n.º 2
0
 function run()
 {
     $enotif = new EmailNotification();
     // Get the user from ID (rename safe). Anons are 0, so defer to name.
     if (isset($this->params['editorID']) && $this->params['editorID']) {
         $editor = User::newFromId($this->params['editorID']);
         // B/C, only the name might be given.
     } else {
         $editor = User::newFromName($this->params['editor'], false);
     }
     $enotif->actuallyNotifyOnPageChange($editor, $this->title, $this->params['timestamp'], $this->params['summary'], $this->params['minorEdit'], $this->params['oldid'], $this->params['watchers']);
     return true;
 }
Ejemplo n.º 3
0
 public function emailFollowNotifications($initiatingUser, $aWatchers, $iUserId, $iNamespace, $sMessage, $sAction)
 {
     $wg = F::app()->wg;
     $wg->DBname = WikiFactory::IDtoDB($this->getWikiId());
     $wg->Server = trim(WikiFactory::DBtoUrl(F::app()->wg->DBname), '/');
     if (!empty($wg->DevelEnvironment)) {
         $wg->Server = WikiFactory::getLocalEnvURL($wg->Server);
     }
     $wg->User = User::newFromId($initiatingUser);
     $targetUser = User::newFromId($iUserId);
     $this->logWatchers($aWatchers, $sAction);
     foreach ($aWatchers as $sKey => $sValue) {
         $oTitle = Title::makeTitle($iNamespace, $sKey);
         $oEmailNotification = new EmailNotification($targetUser, $oTitle, wfTimestampNow(), $sMessage, false, $currentRevId = 0, $previousRevId = 0, $sAction, ['notisnull' => 1, 'childTitle' => $this->title]);
         $oEmailNotification->notifyOnPageChange();
     }
 }
Ejemplo n.º 4
0
 /**
  * main entry point
  *
  * @access public
  */
 public function run()
 {
     global $wgUseEnotif;
     wfProfileIn(__METHOD__);
     if (!$wgUseEnotif) {
         wfProfileOut(__METHOD__);
         return true;
     }
     if ($this->mParams['user_id']) {
         /* registered User */
         $editor = User::newFromID($this->mParams['user_id']);
     } elseif ($this->mParams['user_name']) {
         /* anons */
         $editor = User::newFromName($this->mParams['user_name'], false);
     } else {
         /* invalid user */
         wfProfileOut(__METHOD__);
         return true;
     }
     /**
      * get title of page, take main part from this title which will be
      * main page for user blogs (listing)
      */
     $ownerTitle = BlogArticle::getOwnerTitle($this->title);
     /**
      * check who watches this page
      */
     $dbr = wfGetDB(DB_SLAVE);
     $res = $dbr->select(array("watchlist"), array("wl_user"), array("wl_namespace" => $ownerTitle->getNamespace(), "wl_title" => $ownerTitle->getDBKey()), __METHOD__);
     while ($row = $dbr->fetchObject($res)) {
         $watchers[] = intval($row->wl_user);
     }
     if (!empty($watchers)) {
         $enotif = new EmailNotification();
         $title = Title::makeTitle($ownerTitle->getNamespace(), $ownerTitle->getDBKey());
         $enotif->actuallyNotifyOnPageChange($editor, $title, $this->params['timestamp'], $this->params['comment'], $this->params['minor'], 0, $watchers, $this->params['log_action']);
         /* Update wl_notificationtimestamp for all watching users except the editor */
         $dbw = wfGetDB(DB_MASTER);
         $dbw->begin();
         $dbw->update('watchlist', array('wl_notificationtimestamp' => $dbw->timestamp(wfTimestampNow())), array('wl_title' => $ownerTitle->getDBkey(), 'wl_namespace' => $ownerTitle->getNamespace(), 'wl_user' => $watchers), __METHOD__);
         $dbw->commit();
     }
     wfProfileOut(__METHOD__);
     return true;
 }
 public function testIsNotificationValid()
 {
     $this->resetEvents();
     $c = $this->createCompany();
     $en = EmailNotification::createUpdateNotification("Company", $c->id, EmailNotification::COMPANY_NO_CREDIT);
     $this->assertTrue($en->isValidNotification(24 * 60 * 60));
     $en->notification_sent = date('Y-m-d H:i:s', strtotime('-1 days'));
     $en->save();
     $this->assertFalse($en->isValidNotification(24 * 60 * 60));
     $this->resetEvents();
 }
 public function testUpdateAndResetNotificationTimestamp()
 {
     $user = $this->getUser();
     $otherUser = (new TestUser('WatchedItemIntegrationTestUser_otherUser'))->getUser();
     $title = Title::newFromText('WatchedItemIntegrationTestPage');
     WatchedItem::fromUserTitle($user, $title)->addWatch();
     $this->assertNull(WatchedItem::fromUserTitle($user, $title)->getNotificationTimestamp());
     EmailNotification::updateWatchlistTimestamp($otherUser, $title, '20150202010101');
     $this->assertEquals('20150202010101', WatchedItem::fromUserTitle($user, $title)->getNotificationTimestamp());
     WatchedItem::fromUserTitle($user, $title)->resetNotificationTimestamp();
     $this->assertNull(WatchedItem::fromUserTitle($user, $title)->getNotificationTimestamp());
 }
Ejemplo n.º 7
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $this->info('Started...');
     Subscription::chunk(200, function ($subscriptions) {
         $accepted = 0;
         $declined = 0;
         $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
         foreach ($subscriptions as $subscription) {
             $expiration = Carbon::createFromTimeStamp(strtotime($subscription->expires_at));
             if ($expiration->isToday() || $expiration->isPast()) {
                 $sale = $subscription->payment()->orderBy('id', 'desc')->where('is_success', '=', 1)->orWhere('is_success', '=', 2)->first();
                 if ($sale->is_success == 2) {
                     $resale_params = array('id_authorization' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                     $status = $client->resaleByAuthorization($resale_params);
                 } else {
                     if ($sale->is_success == 1) {
                         $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                         $status = $client->resaleBySale($params);
                     }
                 }
                 if ($client->isSuccess()) {
                     $accepted++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     $subscription->is_active = 1;
                     $subscription->save();
                     $user = User::find($subscription->user_id);
                     $user->level = 2;
                     $user->save();
                     $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
                     if ($configs->count() > 0) {
                         foreach ($configs as $config) {
                             $config->is_active = 1;
                             $config->save();
                         }
                     }
                     EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                     $faktura = $subscription->company_id == 0 ? false : true;
                     Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
                 } else {
                     $declined++;
                     $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0, 'sale_id' => $status['error']['error_number']));
                     Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
                 }
             }
         }
         $this->info('Accepted:' . $accepted);
         $this->info('Declined:' . $declined);
     });
     $this->info('Done');
 }
Ejemplo n.º 8
0
 /**
  * emailNotification -- sent Notification for all related article  ,
  *
  * @static
  * @access public
  *
  *
  * @return bool
  */
 function emailNotification($childTitle, $list, $namespace, $user, $action, $message)
 {
     global $wgTitle;
     wfProfileIn(__METHOD__);
     if (count($list) < 1) {
         wfProfileOut(__METHOD__);
         return true;
     }
     $dbw = wfGetDB(DB_SLAVE);
     $queryIn = array();
     foreach ($list as $value) {
         $queryIn[] = $dbw->addQuotes($value);
     }
     /* Wikia change begin - @author: wladek */
     /* RT#55604: Add a timeout to the watchlist email block */
     global $wgEnableWatchlistNotificationTimeout, $wgWatchlistNotificationTimeout;
     $now = wfTimestampNow();
     if (!empty($wgEnableWatchlistNotificationTimeout) && isset($wgWatchlistNotificationTimeout)) {
         // not using !empty() to allow setting integer value 0
         $blockTimeout = wfTimestamp(TS_MW, wfTimestamp(TS_UNIX, $now) - intval($wgWatchlistNotificationTimeout));
         $notificationTimeoutSql = "(wl_notificationtimestamp IS NULL OR wl_notificationtimestamp < '{$blockTimeout}')";
     } else {
         $notificationTimeoutSql = "wl_notificationtimestamp IS NULL";
     }
     if ($action == "blogpost") {
         $notificationTimeoutSql = "1";
     }
     $res = $dbw->select(array('watchlist'), array('wl_user, wl_title'), array('wl_user != ' . intval($user->getID()), 'wl_namespace' => $namespace, 'wl_title in(' . implode(",", $queryIn) . ') ', $notificationTimeoutSql), __METHOD__);
     $watchers = array();
     while ($row = $dbw->fetchObject($res)) {
         if (empty($watchers[$row->wl_title])) {
             $watchers[$row->wl_title] = array($row->wl_user);
         } else {
             if (in_array($row->wl_user, $watchers[$row->wl_title])) {
                 $watchers[$row->wl_title][] = $row->wl_user;
             }
         }
     }
     foreach ($watchers as $key => $value) {
         $enotif = new EmailNotification();
         $title = Title::makeTitle($namespace, $key);
         $enotif->notifyOnPageChange($user, $title, $now, $message, 0, 0, $action, array('notisnull' => 1, 'childTitle' => $childTitle));
     }
     wfProfileOut(__METHOD__);
 }
function auto_email_notification_members($activity_type, $params)
{
    if (!PA::$network_info) {
        return;
    }
    //setting common variables
    $notification = new EmailNotification();
    // mail to
    // FIXME: these two seemed not to be set in occasion
    $gid = @$params['gid'] ? $params['gid'] : @$_GET['gid'];
    $rid = @$params['related_uid'];
    if ($gid) {
        $network_owner_id = Group::get_owner_id($gid);
        $notification->network_owner = User::map_ids_to_logins($network_owner_id['user_id']);
        $group_owner = new User();
        $group_owner->load((int) $network_owner_id['user_id']);
        $notification->to = $group_owner->email;
        $group_owner_name = $group_owner->login_name;
        //mail from
        $notification->from = (int) PA::$login_uid;
        $array_of_data = array('to' => $notification->to, 'from' => $notification->from, 'owner_name' => $group_owner_name, 'group_owner_id' => $network_owner_id['user_id']);
    }
    if ($rid) {
        $notification->network_owner = User::map_ids_to_logins(array($rid));
        foreach ($notification->network_owner as $key => $value) {
            $rel_user = new User();
            $rel_user->load((int) $key);
            $related_name = $rel_user->login_name;
            $notification->to = $rel_user->email;
        }
        $notification->from = (int) PA::$login_uid;
        $array_of_data = array('to' => $notification->to, 'from' => $notification->from, 'related_name' => $related_name);
    }
    $array_of_data['params'] = $params;
    $notification->send($activity_type, $array_of_data);
}
Ejemplo n.º 10
0
/**
* Send notication mail for one person right now @ingroup pages
*/
function peopleFlushNotifications()
{
    global $PH;
    global $auth;
    ### get person ####
    $ids = getPassedIds('person', 'people_*');
    if (!$ids) {
        $PH->abortWarning(__("Select some people to notify"));
        return;
    }
    $counter = 0;
    $errors = 0;
    foreach ($ids as $id) {
        if (!($person = Person::getEditableById($id))) {
            $PH->abortWarning("Invalid person-id!");
        }
        require_once confGet('DIR_STREBER') . 'std/class_email_notification.inc.php';
        $email = new EmailNotification($person);
        if ($email->information_count) {
            $send_result = $email->send();
            if ($send_result === true) {
                $counter++;
            } else {
                $errors++;
            }
        }
    }
    ### reset language ###
    setLang($auth->cur_user->language);
    if ($errors) {
        new FeedbackWarning(sprintf(__("Failed to mail %s people"), $errors));
    } else {
        new FeedbackMessage(sprintf(__("Sent notification to %s person(s)"), $counter));
    }
    ### display taskView ####
    if (!$PH->showFromPage()) {
        $PH->show('projView', array('prj' => $person->project));
    }
}
Ejemplo n.º 11
0
function local_delivery($importer, $data)
{
    $a = get_app();
    if ($importer['readonly']) {
        // We aren't receiving stuff from this person. But we will quietly ignore them
        // rather than a blatant "go away" message.
        logger('local_delivery: ignoring');
        return 0;
        //NOTREACHED
    }
    // Consume notification feed. This may differ from consuming a public feed in several ways
    // - might contain email or friend suggestions
    // - might contain remote followup to our message
    //		- in which case we need to accept it and then notify other conversants
    // - we may need to send various email notifications
    $feed = new SimplePie();
    $feed->set_raw_data($data);
    $feed->enable_order_by_date(false);
    $feed->init();
    $reloc = $feed->get_feed_tags(NAMESPACE_DFRN, 'relocate');
    if (isset($reloc[0]['child'][NAMESPACE_DFRN])) {
        $base = $reloc[0]['child'][NAMESPACE_DFRN];
        $newloc = array();
        $newloc['uid'] = $importer['importer_uid'];
        $newloc['cid'] = $importer['id'];
        $newloc['name'] = notags(unxmlify($base['name'][0]['data']));
        $newloc['photo'] = notags(unxmlify($base['photo'][0]['data']));
        $newloc['url'] = notags(unxmlify($base['url'][0]['data']));
        $newloc['request'] = notags(unxmlify($base['request'][0]['data']));
        $newloc['confirm'] = notags(unxmlify($base['confirm'][0]['data']));
        $newloc['notify'] = notags(unxmlify($base['notify'][0]['data']));
        $newloc['poll'] = notags(unxmlify($base['poll'][0]['data']));
        $newloc['site-pubkey'] = notags(unxmlify($base['site-pubkey'][0]['data']));
        $newloc['pubkey'] = notags(unxmlify($base['pubkey'][0]['data']));
        $newloc['prvkey'] = notags(unxmlify($base['prvkey'][0]['data']));
        // TODO
        // merge with current record, current contents have priority
        // update record, set url-updated
        // update profile photos
        // schedule a scan?
    }
    // handle friend suggestion notification
    $sugg = $feed->get_feed_tags(NAMESPACE_DFRN, 'suggest');
    if (isset($sugg[0]['child'][NAMESPACE_DFRN])) {
        $base = $sugg[0]['child'][NAMESPACE_DFRN];
        $fsugg = array();
        $fsugg['uid'] = $importer['importer_uid'];
        $fsugg['cid'] = $importer['id'];
        $fsugg['name'] = notags(unxmlify($base['name'][0]['data']));
        $fsugg['photo'] = notags(unxmlify($base['photo'][0]['data']));
        $fsugg['url'] = notags(unxmlify($base['url'][0]['data']));
        $fsugg['request'] = notags(unxmlify($base['request'][0]['data']));
        $fsugg['body'] = escape_tags(unxmlify($base['note'][0]['data']));
        // Does our member already have a friend matching this description?
        $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `nurl` = '%s' AND `uid` = %d LIMIT 1", dbesc($fsugg['name']), dbesc(normalise_link($fsugg['url'])), intval($fsugg['uid']));
        if (count($r)) {
            return 0;
        }
        // Do we already have an fcontact record for this person?
        $fid = 0;
        $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `request` = '%s' LIMIT 1", dbesc($fsugg['url']), dbesc($fsugg['name']), dbesc($fsugg['request']));
        if (count($r)) {
            $fid = $r[0]['id'];
        }
        if (!$fid) {
            $r = q("INSERT INTO `fcontact` ( `name`,`url`,`photo`,`request` ) VALUES ( '%s', '%s', '%s', '%s' ) ", dbesc($fsugg['name']), dbesc($fsugg['url']), dbesc($fsugg['photo']), dbesc($fsugg['request']));
        }
        $r = q("SELECT * FROM `fcontact` WHERE `url` = '%s' AND `name` = '%s' AND `request` = '%s' LIMIT 1", dbesc($fsugg['url']), dbesc($fsugg['name']), dbesc($fsugg['request']));
        if (count($r)) {
            $fid = $r[0]['id'];
        } else {
            return 0;
        }
        $hash = random_string();
        $r = q("INSERT INTO `intro` ( `uid`, `fid`, `contact-id`, `note`, `hash`, `datetime`, `blocked` )\n\t\t\tVALUES( %d, %d, %d, '%s', '%s', '%s', %d )", intval($fsugg['uid']), intval($fid), intval($fsugg['cid']), dbesc($fsugg['body']), dbesc($hash), dbesc(datetime_convert()), intval(0));
        // TODO - send email notify (which may require a new notification preference)
        return 0;
    }
    $ismail = false;
    $rawmail = $feed->get_feed_tags(NAMESPACE_DFRN, 'mail');
    if (isset($rawmail[0]['child'][NAMESPACE_DFRN])) {
        logger('local_delivery: private message received');
        $ismail = true;
        $base = $rawmail[0]['child'][NAMESPACE_DFRN];
        $msg = array();
        $msg['uid'] = $importer['importer_uid'];
        $msg['from-name'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['name'][0]['data']));
        $msg['from-photo'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['avatar'][0]['data']));
        $msg['from-url'] = notags(unxmlify($base['sender'][0]['child'][NAMESPACE_DFRN]['uri'][0]['data']));
        $msg['contact-id'] = $importer['id'];
        $msg['title'] = notags(unxmlify($base['subject'][0]['data']));
        $msg['body'] = escape_tags(unxmlify($base['content'][0]['data']));
        $msg['seen'] = 0;
        $msg['replied'] = 0;
        $msg['uri'] = notags(unxmlify($base['id'][0]['data']));
        $msg['parent-uri'] = notags(unxmlify($base['in-reply-to'][0]['data']));
        $msg['created'] = datetime_convert(notags(unxmlify('UTC', 'UTC', $base['sentdate'][0]['data'])));
        dbesc_array($msg);
        $r = dbq("INSERT INTO `mail` (`" . implode("`, `", array_keys($msg)) . "`) VALUES ('" . implode("', '", array_values($msg)) . "')");
        // send email notification if requested.
        require_once 'bbcode.php';
        if ($importer['notify-flags'] & NOTIFY_MAIL) {
            push_lang($importer['language']);
            // name of the automated email sender
            $msg['notificationfromname'] = t('Administrator');
            // noreply address to send from
            $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
            // text version
            // process the message body to display properly in text mode
            // 		1) substitute a \n character for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
            //		2) remove escape slashes
            //		3) decode any bbcode from the message editor
            //		4) decode any encoded html tags
            //		5) remove html tags
            $msg['textversion'] = strip_tags(html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n"), "\n", $msg['body']))), ENT_QUOTES, 'UTF-8'));
            // html version
            // process the message body to display properly in text mode
            // 		1) substitute a <br /> tag for the "\" then "n", so it behaves properly (it doesn't come in as a \n character)
            //		2) remove escape slashes
            //		3) decode any bbcode from the message editor
            //		4) decode any encoded html tags
            $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $msg['body']))));
            // load the template for private message notifications
            $tpl = get_intltext_template('mail_received_html_body_eml.tpl');
            $email_html_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$siteName' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $importer['thumb'], '$email' => $importer['email'], '$url' => $importer['url'], '$from' => $msg['from-name'], '$title' => stripslashes($msg['title']), '$htmlversion' => $msg['htmlversion'], '$mimeboundary' => $msg['mimeboundary'], '$hostname' => $a->get_hostname()));
            // load the template for private message notifications
            $tpl = get_intltext_template('mail_received_text_body_eml.tpl');
            $email_text_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$siteName' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $importer['thumb'], '$email' => $importer['email'], '$url' => $importer['url'], '$from' => $msg['from-name'], '$title' => stripslashes($msg['title']), '$textversion' => $msg['textversion'], '$mimeboundary' => $msg['mimeboundary'], '$hostname' => $a->get_hostname()));
            // use the EmailNotification library to send the message
            require_once "include/EmailNotification.php";
            EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], $msg['notificationfromemail'], $msg['notificationfromemail'], $importer['email'], t('New mail received at ') . $a->config['sitename'], $email_html_body_tpl, $email_text_body_tpl);
            pop_lang();
        }
        return 0;
        // NOTREACHED
    }
    logger('local_delivery: feed item count = ' . $feed->get_item_quantity());
    // process any deleted entries
    $del_entries = $feed->get_feed_tags(NAMESPACE_TOMB, 'deleted-entry');
    if (is_array($del_entries) && count($del_entries)) {
        foreach ($del_entries as $dentry) {
            $deleted = false;
            if (isset($dentry['attribs']['']['ref'])) {
                $uri = $dentry['attribs']['']['ref'];
                $deleted = true;
                if (isset($dentry['attribs']['']['when'])) {
                    $when = $dentry['attribs']['']['when'];
                    $when = datetime_convert('UTC', 'UTC', $when, 'Y-m-d H:i:s');
                } else {
                    $when = datetime_convert('UTC', 'UTC', 'now', 'Y-m-d H:i:s');
                }
            }
            if ($deleted) {
                $r = q("SELECT `item`.*, `contact`.`self` FROM `item` left join contact on `item`.`contact-id` = `contact`.`id`\n\t\t\t\t\tWHERE `uri` = '%s' AND `item`.`uid` = %d AND `contact-id` = %d LIMIT 1", dbesc($uri), intval($importer['importer_uid']), intval($importer['id']));
                if (count($r)) {
                    $item = $r[0];
                    if ($item['deleted']) {
                        continue;
                    }
                    logger('local_delivery: deleting item ' . $item['id'] . ' uri=' . $item['uri'], LOGGER_DEBUG);
                    if ($item['verb'] === ACTIVITY_TAG && $item['object-type'] === ACTVITY_OBJ_TAGTERM) {
                        $xo = parse_xml_string($item['object'], false);
                        $xt = parse_xml_string($item['target'], false);
                        if ($xt->type === ACTIVITY_OBJ_NOTE) {
                            $i = q("select * from `item` where uri = '%s' and uid = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
                            if (count($i)) {
                                // For tags, the owner cannot remove the tag on the author's copy of the post.
                                $owner_remove = $item['contact-id'] == $i[0]['contact-id'] ? true : false;
                                $author_remove = $item['origin'] && $item['self'] ? true : false;
                                $author_copy = $item['origin'] ? true : false;
                                if ($owner_remove && $author_copy) {
                                    continue;
                                }
                                if ($author_remove || $owner_remove) {
                                    $tags = explode(',', $i[0]['tag']);
                                    $newtags = array();
                                    if (count($tags)) {
                                        foreach ($tags as $tag) {
                                            if (trim($tag) !== trim($xo->body)) {
                                                $newtags[] = trim($tag);
                                            }
                                        }
                                    }
                                    q("update item set tag = '%s' where id = %d limit 1", dbesc(implode(',', $newtags)), intval($i[0]['id']));
                                }
                            }
                        }
                    }
                    if ($item['uri'] == $item['parent-uri']) {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s'\n\t\t\t\t\t\t\tWHERE `parent-uri` = '%s' AND `uid` = %d", dbesc($when), dbesc(datetime_convert()), dbesc($item['uri']), intval($importer['importer_uid']));
                    } else {
                        $r = q("UPDATE `item` SET `deleted` = 1, `edited` = '%s', `changed` = '%s' \n\t\t\t\t\t\t\tWHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($when), dbesc(datetime_convert()), dbesc($uri), intval($importer['importer_uid']));
                        if ($item['last-child']) {
                            // ensure that last-child is set in case the comment that had it just got wiped.
                            q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d ", dbesc(datetime_convert()), dbesc($item['parent-uri']), intval($item['uid']));
                            // who is the last child now?
                            $r = q("SELECT `id` FROM `item` WHERE `parent-uri` = '%s' AND `type` != 'activity' AND `deleted` = 0 AND `uid` = %d\n\t\t\t\t\t\t\t\tORDER BY `created` DESC LIMIT 1", dbesc($item['parent-uri']), intval($importer['importer_uid']));
                            if (count($r)) {
                                q("UPDATE `item` SET `last-child` = 1 WHERE `id` = %d LIMIT 1", intval($r[0]['id']));
                            }
                        }
                    }
                }
            }
        }
    }
    foreach ($feed->get_items() as $item) {
        $is_reply = false;
        $item_id = $item->get_id();
        $rawthread = $item->get_item_tags(NAMESPACE_THREAD, 'in-reply-to');
        if (isset($rawthread[0]['attribs']['']['ref'])) {
            $is_reply = true;
            $parent_uri = $rawthread[0]['attribs']['']['ref'];
        }
        if ($is_reply) {
            $community = false;
            if ($importer['page-flags'] == PAGE_COMMUNITY) {
                $sql_extra = '';
                $community = true;
                logger('local_delivery: community reply');
            } else {
                $sql_extra = " and contact.self = 1 and item.wall = 1 ";
            }
            // was the top-level post for this reply written by somebody on this site?
            // Specifically, the recipient?
            $r = q("select `item`.`id`, `item`.`uri`, `item`.`tag`, \n\t\t\t\t`contact`.`name`, `contact`.`url`, `contact`.`thumb` from `item` \n\t\t\t\tLEFT JOIN `contact` ON `contact`.`id` = `item`.`contact-id` \n\t\t\t\tWHERE `item`.`uri` = '%s' AND `item`.`parent-uri` = '%s'\n\t\t\t\tAND `item`.`uid` = %d \n\t\t\t\t{$sql_extra}\n\t\t\t\tLIMIT 1", dbesc($parent_uri), dbesc($parent_uri), intval($importer['importer_uid']));
            if ($r && count($r)) {
                logger('local_delivery: received remote comment');
                $is_like = false;
                // remote reply to our post. Import and then notify everybody else.
                $datarray = get_atom_elements($feed, $item);
                // TODO: make this next part work against both delivery threads of a community post
                //				if((! link_compare($datarray['author-link'],$importer['url'])) && (! $community)) {
                //					logger('local_delivery: received relay claiming to be from ' . $importer['url'] . ' however comment author url is ' . $datarray['author-link'] );
                // they won't know what to do so don't report an error. Just quietly die.
                //					return 0;
                //				}
                $datarray['type'] = 'remote-comment';
                $datarray['wall'] = 1;
                $datarray['parent-uri'] = $parent_uri;
                $datarray['uid'] = $importer['importer_uid'];
                $datarray['owner-name'] = $r[0]['name'];
                $datarray['owner-link'] = $r[0]['url'];
                $datarray['owner-avatar'] = $r[0]['thumb'];
                $datarray['contact-id'] = $importer['id'];
                if ($datarray['verb'] === ACTIVITY_LIKE || $datarray['verb'] === ACTIVITY_DISLIKE) {
                    $is_like = true;
                    $datarray['type'] = 'activity';
                    $datarray['gravity'] = GRAVITY_LIKE;
                    $datarray['last-child'] = 0;
                }
                if ($datarray['verb'] === ACTIVITY_TAG && $datarray['object-type'] === ACTIVITY_OBJ_TAGTERM) {
                    $xo = parse_xml_string($datarray['object'], false);
                    $xt = parse_xml_string($datarray['target'], false);
                    if ($xt->type == ACTIVITY_OBJ_NOTE && $xt->id == $r[0]['uri']) {
                        // extract tag, if not duplicate, and this user allows tags, add to parent item
                        if ($xo->id && $xo->content) {
                            $newtag = '#[url=' . $xo->id . ']' . $xo->content . '[/url]';
                            if (!stristr($r[0]['tag'], $newtag)) {
                                $i = q("SELECT `blocktags` FROM `user` where `uid` = %d LIMIT 1", intval($importer['importer_uid']));
                                if (count($i) && !$i[0]['blocktags']) {
                                    q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . $newtag), intval($r[0]['id']));
                                }
                            }
                        }
                    }
                }
                // 				if($community) {
                //					$newtag = '@[url=' . $a->get_baseurl() . '/profile/' . $importer['nickname'] . ']' . $importer['username'] . '[/url]';
                //					if(! stristr($datarray['tag'],$newtag)) {
                //						if(strlen($datarray['tag']))
                //							$datarray['tag'] .= ',';
                //						$datarray['tag'] .= $newtag;
                //					}
                //				}
                $posted_id = item_store($datarray);
                $parent = 0;
                if ($posted_id) {
                    $r = q("SELECT `parent` FROM `item` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($posted_id), intval($importer['importer_uid']));
                    if (count($r)) {
                        $parent = $r[0]['parent'];
                    }
                    if (!$is_like) {
                        $r1 = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `uid` = %d AND `parent` = %d", dbesc(datetime_convert()), intval($importer['importer_uid']), intval($r[0]['parent']));
                        $r2 = q("UPDATE `item` SET `last-child` = 1, `changed` = '%s' WHERE `uid` = %d AND `id` = %d LIMIT 1", dbesc(datetime_convert()), intval($importer['importer_uid']), intval($posted_id));
                    }
                    if ($posted_id && $parent) {
                        proc_run('php', "include/notifier.php", "comment-import", "{$posted_id}");
                        if (!$is_like && $importer['notify-flags'] & NOTIFY_COMMENT && !$importer['self']) {
                            push_lang($importer['language']);
                            require_once 'bbcode.php';
                            $from = stripslashes($datarray['author-name']);
                            // name of the automated email sender
                            $msg['notificationfromname'] = stripslashes($datarray['author-name']);
                            // noreply address to send from
                            $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
                            // text version
                            // process the message body to display properly in text mode
                            $msg['textversion'] = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
                            // html version
                            // process the message body to display properly in text mode
                            $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $datarray['body']))));
                            $imgtouse = link_compare($datarray['author-link'], $importer['url']) ? $importer['thumb'] : $datarray['author-avatar'];
                            // load the template for private message notifications
                            $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
                            $email_html_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$email' => $importer['email'], '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['htmlversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
                            // load the template for private message notifications
                            $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
                            $email_text_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$email' => $importer['email'], '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['textversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
                            // use the EmailNotification library to send the message
                            require_once "include/EmailNotification.php";
                            EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], t("Administrator") . '@' . $a->get_hostname(), t("noreply") . '@' . $a->get_hostname(), $importer['email'], sprintf(t('%s commented on an item at %s'), $from, $a->config['sitename']), $email_html_body_tpl, $email_text_body_tpl);
                            pop_lang();
                        }
                    }
                    return 0;
                    // NOTREACHED
                }
            } else {
                // regular comment that is part of this total conversation. Have we seen it? If not, import it.
                $item_id = $item->get_id();
                $datarray = get_atom_elements($feed, $item);
                $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']));
                // Update content if 'updated' changes
                if (count($r)) {
                    if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
                        $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($datarray['body']), dbesc(datetime_convert('UTC', 'UTC', $datarray['edited'])), dbesc($item_id), intval($importer['importer_uid']));
                    }
                    // update last-child if it changes
                    $allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
                    if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
                        $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent-uri` = '%s' AND `uid` = %d", dbesc(datetime_convert()), dbesc($parent_uri), intval($importer['importer_uid']));
                        $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s'  WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", intval($allow[0]['data']), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
                    }
                    continue;
                }
                $datarray['parent-uri'] = $parent_uri;
                $datarray['uid'] = $importer['importer_uid'];
                $datarray['contact-id'] = $importer['id'];
                if ($datarray['verb'] == ACTIVITY_LIKE || $datarray['verb'] == ACTIVITY_DISLIKE) {
                    $datarray['type'] = 'activity';
                    $datarray['gravity'] = GRAVITY_LIKE;
                }
                if ($datarray['verb'] === ACTIVITY_TAG && $datarray['object-type'] === ACTIVITY_OBJ_TAGTERM) {
                    $xo = parse_xml_string($datarray['object'], false);
                    $xt = parse_xml_string($datarray['target'], false);
                    if ($xt->type == ACTIVITY_OBJ_NOTE) {
                        $r = q("select * from item where `uri` = '%s' AND `uid` = %d limit 1", dbesc($xt->id), intval($importer['importer_uid']));
                        if (!count($r)) {
                            continue;
                        }
                        // extract tag, if not duplicate, add to parent item
                        if ($xo->content) {
                            if (!stristr($r[0]['tag'], trim($xo->content))) {
                                q("UPDATE item SET tag = '%s' WHERE id = %d LIMIT 1", dbesc($r[0]['tag'] . (strlen($r[0]['tag']) ? ',' : '') . '#[url=' . $xo->id . ']' . $xo->content . '[/url]'), intval($r[0]['id']));
                            }
                        }
                    }
                }
                $posted_id = item_store($datarray);
                // find out if our user is involved in this conversation and wants to be notified.
                if ($datarray['type'] != 'activity' && $importer['notify-flags'] & NOTIFY_COMMENT) {
                    $myconv = q("SELECT `author-link`, `author-avatar` FROM `item` WHERE `parent-uri` = '%s' AND `uid` = %d AND `parent` != 0 ", dbesc($parent_uri), intval($importer['importer_uid']));
                    if (count($myconv)) {
                        $importer_url = $a->get_baseurl() . '/profile/' . $importer['nickname'];
                        foreach ($myconv as $conv) {
                            if (!link_compare($conv['author-link'], $importer_url)) {
                                continue;
                            }
                            push_lang($importer['language']);
                            require_once 'bbcode.php';
                            $from = stripslashes($datarray['author-name']);
                            // name of the automated email sender
                            $msg['notificationfromname'] = stripslashes($datarray['author-name']);
                            // noreply address to send from
                            $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
                            // text version
                            // process the message body to display properly in text mode
                            $msg['textversion'] = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
                            // html version
                            // process the message body to display properly in text mode
                            $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $datarray['body']))));
                            $imgtouse = link_compare($datarray['author-link'], $importer['url']) ? $importer['thumb'] : $datarray['author-avatar'];
                            // load the template for private message notifications
                            $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
                            $email_html_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['htmlversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
                            // load the template for private message notifications
                            $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
                            $email_text_body_tpl = replace_macros($tpl, array('$username' => $importer['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $imgtouse, '$url' => $datarray['author-link'], '$from' => $from, '$body' => $msg['textversion'], '$display' => $a->get_baseurl() . '/display/' . $importer['nickname'] . '/' . $posted_id));
                            // use the EmailNotification library to send the message
                            require_once "include/EmailNotification.php";
                            EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], t("Administrator@") . $a->get_hostname(), t("noreply") . '@' . $a->get_hostname(), $importer['email'], sprintf(t('%s commented on an item at %s'), $from, $a->config['sitename']), $email_html_body_tpl, $email_text_body_tpl);
                            pop_lang();
                            break;
                        }
                    }
                }
                continue;
            }
        } else {
            // Head post of a conversation. Have we seen it? If not, import it.
            $item_id = $item->get_id();
            $datarray = get_atom_elements($feed, $item);
            if (x($datarray, 'object-type') && $datarray['object-type'] === ACTIVITY_OBJ_EVENT) {
                $ev = bbtoevent($datarray['body']);
                if (x($ev, 'desc') && x($ev, 'start')) {
                    $ev['cid'] = $importer['id'];
                    $ev['uid'] = $importer['uid'];
                    $ev['uri'] = $item_id;
                    $ev['edited'] = $datarray['edited'];
                    $ev['private'] = $datarray['private'];
                    $r = q("SELECT * FROM `event` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['uid']));
                    if (count($r)) {
                        $ev['id'] = $r[0]['id'];
                    }
                    $xyz = event_store($ev);
                    continue;
                }
            }
            $r = q("SELECT `uid`, `last-child`, `edited`, `body` FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($item_id), intval($importer['importer_uid']));
            // Update content if 'updated' changes
            if (count($r)) {
                if (x($datarray, 'edited') !== false && datetime_convert('UTC', 'UTC', $datarray['edited']) !== $r[0]['edited']) {
                    $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($datarray['body']), dbesc(datetime_convert('UTC', 'UTC', $datarray['edited'])), dbesc($item_id), intval($importer['importer_uid']));
                }
                // update last-child if it changes
                $allow = $item->get_item_tags(NAMESPACE_DFRN, 'comment-allow');
                if ($allow && $allow[0]['data'] != $r[0]['last-child']) {
                    $r = q("UPDATE `item` SET `last-child` = %d , `changed` = '%s' WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", intval($allow[0]['data']), dbesc(datetime_convert()), dbesc($item_id), intval($importer['importer_uid']));
                }
                continue;
            }
            // This is my contact on another system, but it's really me.
            // Turn this into a wall post.
            if ($contact['remote_self']) {
                $datarray['wall'] = 1;
            }
            $datarray['parent-uri'] = $item_id;
            $datarray['uid'] = $importer['importer_uid'];
            $datarray['contact-id'] = $importer['id'];
            $r = item_store($datarray);
            continue;
        }
    }
    return 0;
    // NOTREACHED
}
 /**
  * Abort notifications regarding occupied pages coming from the RecentChange class.
  * Flow has its own notifications through Echo.
  *
  * Also don't notify for actions made by the talk page manager.
  *
  * @param User $editor
  * @param Title $title
  * @return bool false to abort email notification
  */
 public static function onAbortEmailNotification($editor, $title)
 {
     if (self::$occupationController->isTalkpageOccupied($title)) {
         // Since we are aborting the notification we need to manually update the watchlist
         EmailNotification::updateWatchlistTimestamp($editor, $title, wfTimestampNow());
         return false;
     }
     $talkPageManagerUser = self::$occupationController->getTalkpageManager();
     if ($editor->equals($talkPageManagerUser)) {
         return false;
     }
     return true;
 }
Ejemplo n.º 13
0
<?php

/*
 * Bluethrust Clan Scripts v4
 * Copyright 2014
 *
 * Author: Bluethrust Web Development
 * E-mail: support@bluethrust.com
 * Website: http://www.bluethrust.com
 *
 * License: http://www.bluethrust.com/license.php
 *
 */
if (!isset($member) || substr($_SERVER['PHP_SELF'], -11) != "console.php") {
    exit;
} else {
    $memberInfo = $member->get_info_filtered();
    $consoleObj->select($_GET['cID']);
    if (!$member->hasAccess($consoleObj)) {
        exit;
    }
}
$emailNotification = new EmailNotification($mysqli);
print_r($emailNotification->getNotificationItems("tournaments", "tournament_id", "Tournaments", "startdate"));
$cID = $_GET['cID'];
$i = 0;
$arrComponents = array("emailnotification" => array("type" => "section", "options" => array("section_title" => "E-mail me when:"), "sortorder" => $i++), "pm" => array("type" => "select", "display_name" => "I receive a PM", "options" => array(1 => "Yes", "0" => "No"), "sortorder" => $i++, "attributes" => array("class" => "formInput textBox"), "value" => 1), "tournament" => array("type" => "select", "display_name" => "A tournament is starting", "options" => array(1 => "Yes", "0" => "No"), "sortorder" => $i++, "attributes" => array("class" => "formInput textBox"), "value" => 1), "event" => array("type" => "select", "display_name" => "An event is starting", "options" => array(1 => "Yes", "0" => "No"), "sortorder" => $i++, "attributes" => array("class" => "formInput textBox"), "value" => 1), "submit" => array("type" => "submit", "value" => "Save", "sortorder" => $i++, "attributes" => array("class" => "submitButton formSubmitButton")));
$setupFormArgs = array("name" => "console-" . $cID, "components" => $arrComponents, "saveObject" => $member, "saveType" => "update", "saveMessage" => "Successfully changed username!", "attributes" => array("action" => $MAIN_ROOT . "members/console.php?cID=" . $cID, "method" => "post"), "description" => "Use the form below to set your e-mail notification settings.");
Ejemplo n.º 14
0
function item_post(&$a)
{
    if (!local_user() && !remote_user()) {
        return;
    }
    require_once 'include/security.php';
    $uid = local_user();
    if (x($_POST, 'dropitems')) {
        require_once 'include/items.php';
        $arr_drop = explode(',', $_POST['dropitems']);
        drop_items($arr_drop);
        $json = array('success' => 1);
        echo json_encode($json);
        killme();
    }
    call_hooks('post_local_start', $_POST);
    $api_source = x($_POST, 'api_source') && $_POST['api_source'] ? true : false;
    $return_path = x($_POST, 'return') ? $_POST['return'] : '';
    /**
     * Is this a reply to something?
     */
    $parent = x($_POST, 'parent') ? intval($_POST['parent']) : 0;
    $parent_uri = x($_POST, 'parent_uri') ? trim($_POST['parent_uri']) : '';
    $parent_item = null;
    $parent_contact = null;
    $thr_parent = '';
    $parid = 0;
    $r = false;
    if ($parent || $parent_uri) {
        if (!x($_POST, 'type')) {
            $_POST['type'] = 'net-comment';
        }
        if ($parent) {
            $r = q("SELECT * FROM `item` WHERE `id` = %d LIMIT 1", intval($parent));
        } elseif ($parent_uri && local_user()) {
            // This is coming from an API source, and we are logged in
            $r = q("SELECT * FROM `item` WHERE `uri` = '%s' AND `uid` = %d LIMIT 1", dbesc($parent_uri), intval(local_user()));
        }
        // if this isn't the real parent of the conversation, find it
        if ($r !== false && count($r)) {
            $parid = $r[0]['parent'];
            if ($r[0]['id'] != $r[0]['parent']) {
                $r = q("SELECT * FROM `item` WHERE `id` = `parent` AND `parent` = %d LIMIT 1", intval($parid));
            }
        }
        if ($r === false || !count($r)) {
            notice(t('Unable to locate original post.') . EOL);
            if (x($_POST, 'return')) {
                goaway($a->get_baseurl() . "/" . $return_path);
            }
            killme();
        }
        $parent_item = $r[0];
        $parent = $r[0]['id'];
        // multi-level threading - preserve the info but re-parent to our single level threading
        if ($parid && $parid != $parent) {
            $thr_parent = $parent_uri;
        }
        if ($parent_item['contact-id'] && $uid) {
            $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($parent_item['contact-id']), intval($uid));
            if (count($r)) {
                $parent_contact = $r[0];
            }
        }
    }
    if ($parent) {
        logger('mod_post: parent=' . $parent);
    }
    $profile_uid = x($_POST, 'profile_uid') ? intval($_POST['profile_uid']) : 0;
    $post_id = x($_POST['post_id']) ? intval($_POST['post_id']) : 0;
    $app = x($_POST['source']) ? strip_tags($_POST['source']) : '';
    if (!can_write_wall($a, $profile_uid)) {
        notice(t('Permission denied.') . EOL);
        if (x($_POST, 'return')) {
            goaway($a->get_baseurl() . "/" . $return_path);
        }
        killme();
    }
    // is this an edited post?
    $orig_post = null;
    if ($post_id) {
        $i = q("SELECT * FROM `item` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($post_id));
        if (!count($i)) {
            killme();
        }
        $orig_post = $i[0];
    }
    $user = null;
    $r = q("SELECT * FROM `user` WHERE `uid` = %d LIMIT 1", intval($profile_uid));
    if (count($r)) {
        $user = $r[0];
    }
    if ($orig_post) {
        $str_group_allow = $orig_post['allow_gid'];
        $str_contact_allow = $orig_post['allow_cid'];
        $str_group_deny = $orig_post['deny_gid'];
        $str_contact_deny = $orig_post['deny_cid'];
        $title = $orig_post['title'];
        $location = $orig_post['location'];
        $coord = $orig_post['coord'];
        $verb = $orig_post['verb'];
        $emailcc = $orig_post['emailcc'];
        $app = $orig_post['app'];
        $body = escape_tags(trim($_POST['body']));
        $private = $orig_post['private'];
        $pubmail_enable = $orig_post['pubmail'];
    } else {
        $str_group_allow = perms2str($_POST['group_allow']);
        $str_contact_allow = perms2str($_POST['contact_allow']);
        $str_group_deny = perms2str($_POST['group_deny']);
        $str_contact_deny = perms2str($_POST['contact_deny']);
        $title = notags(trim($_POST['title']));
        $location = notags(trim($_POST['location']));
        $coord = notags(trim($_POST['coord']));
        $verb = notags(trim($_POST['verb']));
        $emailcc = notags(trim($_POST['emailcc']));
        $body = escape_tags(trim($_POST['body']));
        $private = strlen($str_group_allow) || strlen($str_contact_allow) || strlen($str_group_deny) || strlen($str_contact_deny) ? 1 : 0;
        if ($parent_item && ($parent_item['private'] || strlen($parent_item['allow_cid']) || strlen($parent_item['allow_gid']) || strlen($parent_item['deny_cid']) || strlen($parent_item['deny_gid']))) {
            $private = 1;
        }
        $pubmail_enable = x($_POST, 'pubmail_enable') && intval($_POST['pubmail_enable']) && !$private ? 1 : 0;
        // if using the API, we won't see pubmail_enable - figure out if it should be set
        if ($api_source && $profile_uid && $profile_uid == local_user() && !$private) {
            $mail_disabled = function_exists('imap_open') && !get_config('system', 'imap_disabled') ? 0 : 1;
            if (!$mail_disabled) {
                $r = q("SELECT * FROM `mailacct` WHERE `uid` = %d AND `server` != '' LIMIT 1", intval(local_user()));
                if (count($r) && intval($r[0]['pubmail'])) {
                    $pubmail_enabled = true;
                }
            }
        }
        if (!strlen($body)) {
            info(t('Empty post discarded.') . EOL);
            if (x($_POST, 'return')) {
                goaway($a->get_baseurl() . "/" . $return_path);
            }
            killme();
        }
    }
    if ($api_source && !array_key_exists('allow_cid', $_REQUEST) && !array_key_exists('allow_gid', $_REQUEST) && !array_key_exists('deny_cid', $_REQUEST) && !array_key_exists('deny_gid', $_REQUEST)) {
        $str_group_allow = $user['allow_gid'];
        $str_contact_allow = $user['allow_cid'];
        $str_group_deny = $user['deny_gid'];
        $str_contact_deny = $user['deny_cid'];
    }
    // get contact info for poster
    $author = null;
    $self = false;
    if ($_SESSION['uid'] && $_SESSION['uid'] == $profile_uid) {
        $self = true;
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($_SESSION['uid']));
    } else {
        if (x($_SESSION, 'visitor_id') && intval($_SESSION['visitor_id'])) {
            $r = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1", intval($_SESSION['visitor_id']));
        }
    }
    if (count($r)) {
        $author = $r[0];
        $contact_id = $author['id'];
    }
    // get contact info for owner
    if ($profile_uid == $_SESSION['uid']) {
        $contact_record = $author;
    } else {
        $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `self` = 1 LIMIT 1", intval($profile_uid));
        if (count($r)) {
            $contact_record = $r[0];
        }
    }
    $post_type = notags(trim($_POST['type']));
    if ($post_type === 'net-comment') {
        if ($parent_item !== null) {
            if ($parent_item['wall'] == 1) {
                $post_type = 'wall-comment';
            } else {
                $post_type = 'remote-comment';
            }
        }
    }
    /**
     *
     * When a photo was uploaded into the message using the (profile wall) ajax 
     * uploader, The permissions are initially set to disallow anybody but the
     * owner from seeing it. This is because the permissions may not yet have been
     * set for the post. If it's private, the photo permissions should be set
     * appropriately. But we didn't know the final permissions on the post until
     * now. So now we'll look for links of uploaded messages that are in the
     * post and set them to the same permissions as the post itself.
     *
     */
    $match = null;
    if (preg_match_all("/\\[img\\](.*?)\\[\\/img\\]/", $body, $match)) {
        $images = $match[1];
        if (count($images)) {
            foreach ($images as $image) {
                if (!stristr($image, $a->get_baseurl() . '/photo/')) {
                    continue;
                }
                $image_uri = substr($image, strrpos($image, '/') + 1);
                $image_uri = substr($image_uri, 0, strpos($image_uri, '-'));
                if (!strlen($image_uri)) {
                    continue;
                }
                $srch = '<' . intval($profile_uid) . '>';
                $r = q("SELECT `id` FROM `photo` WHERE `allow_cid` = '%s' AND `allow_gid` = '' AND `deny_cid` = '' AND `deny_gid` = ''\n\t\t\t\t\tAND `resource-id` = '%s' AND `uid` = %d LIMIT 1", dbesc($srch), dbesc($image_uri), intval($profile_uid));
                if (!count($r)) {
                    continue;
                }
                $r = q("UPDATE `photo` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'\n\t\t\t\t\tWHERE `resource-id` = '%s' AND `uid` = %d AND `album` = '%s' ", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), dbesc($image_uri), intval($profile_uid), dbesc(t('Wall Photos')));
            }
        }
    }
    /**
     * Next link in any attachment references we find in the post.
     */
    $match = false;
    if (preg_match_all("/\\[attachment\\](.*?)\\[\\/attachment\\]/", $body, $match)) {
        $attaches = $match[1];
        if (count($attaches)) {
            foreach ($attaches as $attach) {
                $r = q("SELECT * FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($attach));
                if (count($r)) {
                    $r = q("UPDATE `attach` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s'\n\t\t\t\t\t\tWHERE `uid` = %d AND `id` = %d LIMIT 1", dbesc($str_contact_allow), dbesc($str_group_allow), dbesc($str_contact_deny), dbesc($str_group_deny), intval($profile_uid), intval($attach));
                }
            }
        }
    }
    // embedded bookmark in post? set bookmark flag
    $bookmark = 0;
    if (preg_match_all("/\\[bookmark\\=([^\\]]*)\\](.*?)\\[\\/bookmark\\]/ism", $body, $match, PREG_SET_ORDER)) {
        $bookmark = 1;
        //		foreach($match as $mtch) {
        //			$body = str_replace(
        //				'[bookmark=' . $mtch[1] . ']' . $mtch[2] . '[/bookmark]',
        //				'[url=' . $mtch[1] . ']' . $mtch[2] . '[/url]',
        //				$body
        //			);
        //		}
    }
    $body = bb_translate_video($body);
    /**
     * Fold multi-line [code] sequences
     */
    $body = preg_replace('/\\[\\/code\\]\\s*\\[code\\]/ism', "\n", $body);
    /**
     * Look for any tags and linkify them
     */
    $str_tags = '';
    $inform = '';
    $tags = get_tags($body);
    /**
     * add a statusnet style reply tag if the original post was from there
     * and we are replying, and there isn't one already
     */
    if ($parent_contact && $parent_contact['network'] === NETWORK_OSTATUS && $parent_contact['nick'] && !in_array('@' . $parent_contact['nick'], $tags)) {
        $body = '@' . $parent_contact['nick'] . ' ' . $body;
        $tags[] = '@' . $parent_contact['nick'];
    }
    if (count($tags)) {
        foreach ($tags as $tag) {
            if (isset($profile)) {
                unset($profile);
            }
            if (strpos($tag, '#') === 0) {
                if (strpos($tag, '[url=')) {
                    continue;
                }
                $basetag = str_replace('_', ' ', substr($tag, 1));
                $body = str_replace($tag, '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]', $body);
                if (strlen($str_tags)) {
                    $str_tags .= ',';
                }
                $str_tags .= '#[url=' . $a->get_baseurl() . '/search?search=' . rawurlencode($basetag) . ']' . $basetag . '[/url]';
                continue;
            }
            if (strpos($tag, '@') === 0) {
                if (strpos($tag, '[url=')) {
                    continue;
                }
                $stat = false;
                $name = substr($tag, 1);
                if (strpos($name, '@') || strpos($name, 'http://')) {
                    $newname = $name;
                    $links = @lrdd($name);
                    if (count($links)) {
                        foreach ($links as $link) {
                            if ($link['@attributes']['rel'] === 'http://webfinger.net/rel/profile-page') {
                                $profile = $link['@attributes']['href'];
                            }
                            if ($link['@attributes']['rel'] === 'salmon') {
                                if (strlen($inform)) {
                                    $inform .= ',';
                                }
                                $inform .= 'url:' . str_replace(',', '%2c', $link['@attributes']['href']);
                            }
                        }
                    }
                } else {
                    $newname = $name;
                    $alias = '';
                    $tagcid = 0;
                    if (strrpos($newname, '+')) {
                        $tagcid = intval(substr($newname, strrpos($newname, '+') + 1));
                        if (strpos($name, ' ')) {
                            $name = substr($name, 0, strpos($name, ' '));
                        }
                    }
                    if ($tagcid) {
                        $r = q("SELECT * FROM `contact` WHERE `id` = %d AND `uid` = %d LIMIT 1", intval($tagcid), intval($profile_uid));
                    } elseif (strstr($name, '_') || strstr($name, ' ')) {
                        $newname = str_replace('_', ' ', $name);
                        $r = q("SELECT * FROM `contact` WHERE `name` = '%s' AND `uid` = %d LIMIT 1", dbesc($newname), intval($profile_uid));
                    } else {
                        $r = q("SELECT * FROM `contact` WHERE `attag` = '%s' OR `nick` = '%s' AND `uid` = %d ORDER BY `attag` DESC LIMIT 1", dbesc($name), dbesc($name), intval($profile_uid));
                    }
                    if (count($r)) {
                        $profile = $r[0]['url'];
                        if ($r[0]['network'] === 'stat') {
                            $newname = $r[0]['nick'];
                            $stat = true;
                            if ($r[0]['alias']) {
                                $alias = $r[0]['alias'];
                            }
                        } else {
                            $newname = $r[0]['name'];
                        }
                        if (strlen($inform)) {
                            $inform .= ',';
                        }
                        $inform .= 'cid:' . $r[0]['id'];
                    }
                }
                if ($profile) {
                    $body = str_replace('@' . $name, '@' . '[url=' . $profile . ']' . $newname . '[/url]', $body);
                    $profile = str_replace(',', '%2c', $profile);
                    $newtag = '@[url=' . $profile . ']' . $newname . '[/url]';
                    if (!stristr($str_tags, $newtag)) {
                        if (strlen($str_tags)) {
                            $str_tags .= ',';
                        }
                        $str_tags .= $newtag;
                    }
                    // Status.Net seems to require the numeric ID URL in a mention if the person isn't
                    // subscribed to you. But the nickname URL is OK if they are. Grrr. We'll tag both.
                    if (strlen($alias)) {
                        $newtag = '@[url=' . $alias . ']' . $newname . '[/url]';
                        if (!stristr($str_tags, $newtag)) {
                            if (strlen($str_tags)) {
                                $str_tags .= ',';
                            }
                            $str_tags .= $newtag;
                        }
                    }
                }
            }
        }
    }
    $attachments = '';
    $match = false;
    if (preg_match_all('/(\\[attachment\\]([0-9]+)\\[\\/attachment\\])/', $body, $match)) {
        foreach ($match[2] as $mtch) {
            $r = q("SELECT `id`,`filename`,`filesize`,`filetype` FROM `attach` WHERE `uid` = %d AND `id` = %d LIMIT 1", intval($profile_uid), intval($mtch));
            if (count($r)) {
                if (strlen($attachments)) {
                    $attachments .= ',';
                }
                $attachments .= '[attach]href="' . $a->get_baseurl() . '/attach/' . $r[0]['id'] . '" length="' . $r[0]['filesize'] . '" type="' . $r[0]['filetype'] . '" title="' . ($r[0]['filename'] ? $r[0]['filename'] : '') . '"[/attach]';
            }
            $body = str_replace($match[1], '', $body);
        }
    }
    $wall = 0;
    if ($post_type === 'wall' || $post_type === 'wall-comment') {
        $wall = 1;
    }
    if (!strlen($verb)) {
        $verb = ACTIVITY_POST;
    }
    $gravity = $parent ? 6 : 0;
    // even if the post arrived via API we are considering that it
    // originated on this site by default for determining relayability.
    $origin = x($_REQUEST, 'origin') ? intval($_REQUEST['origin']) : 1;
    $notify_type = $parent ? 'comment-new' : 'wall-new';
    $uri = item_new_uri($a->get_hostname(), $profile_uid);
    $datarray = array();
    $datarray['uid'] = $profile_uid;
    $datarray['type'] = $post_type;
    $datarray['wall'] = $wall;
    $datarray['gravity'] = $gravity;
    $datarray['contact-id'] = $contact_id;
    $datarray['owner-name'] = $contact_record['name'];
    $datarray['owner-link'] = $contact_record['url'];
    $datarray['owner-avatar'] = $contact_record['thumb'];
    $datarray['author-name'] = $author['name'];
    $datarray['author-link'] = $author['url'];
    $datarray['author-avatar'] = $author['thumb'];
    $datarray['created'] = datetime_convert();
    $datarray['edited'] = datetime_convert();
    $datarray['commented'] = datetime_convert();
    $datarray['received'] = datetime_convert();
    $datarray['changed'] = datetime_convert();
    $datarray['uri'] = $uri;
    $datarray['title'] = $title;
    $datarray['body'] = $body;
    $datarray['app'] = $app;
    $datarray['location'] = $location;
    $datarray['coord'] = $coord;
    $datarray['tag'] = $str_tags;
    $datarray['inform'] = $inform;
    $datarray['verb'] = $verb;
    $datarray['allow_cid'] = $str_contact_allow;
    $datarray['allow_gid'] = $str_group_allow;
    $datarray['deny_cid'] = $str_contact_deny;
    $datarray['deny_gid'] = $str_group_deny;
    $datarray['private'] = $private;
    $datarray['pubmail'] = $pubmail_enable;
    $datarray['attach'] = $attachments;
    $datarray['bookmark'] = intval($bookmark);
    $datarray['thr-parent'] = $thr_parent;
    $datarray['postopts'] = '';
    $datarray['origin'] = $origin;
    /**
     * These fields are for the convenience of plugins...
     * 'self' if true indicates the owner is posting on their own wall
     * If parent is 0 it is a top-level post.
     */
    $datarray['parent'] = $parent;
    $datarray['self'] = $self;
    //	$datarray['prvnets']       = $user['prvnets'];
    if ($orig_post) {
        $datarray['edit'] = true;
    } else {
        $datarray['guid'] = get_guid();
    }
    call_hooks('post_local', $datarray);
    if ($orig_post) {
        $r = q("UPDATE `item` SET `body` = '%s', `edited` = '%s' WHERE `id` = %d AND `uid` = %d LIMIT 1", dbesc($body), dbesc(datetime_convert()), intval($post_id), intval($profile_uid));
        proc_run('php', "include/notifier.php", 'edit_post', "{$post_id}");
        if (x($_POST, 'return') && strlen($return_path)) {
            logger('return: ' . $return_path);
            goaway($a->get_baseurl() . "/" . $return_path);
        }
        killme();
    } else {
        $post_id = 0;
    }
    $r = q("INSERT INTO `item` (`guid`, `uid`,`type`,`wall`,`gravity`,`contact-id`,`owner-name`,`owner-link`,`owner-avatar`, \n\t\t`author-name`, `author-link`, `author-avatar`, `created`, `edited`, `commented`, `received`, `changed`, `uri`, `thr-parent`, `title`, `body`, `app`, `location`, `coord`, \n\t\t`tag`, `inform`, `verb`, `postopts`, `allow_cid`, `allow_gid`, `deny_cid`, `deny_gid`, `private`, `pubmail`, `attach`, `bookmark`,`origin` )\n\t\tVALUES( '%s', %d, '%s', %d, %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', %d, %d, '%s', %d, %d )", dbesc($datarray['guid']), intval($datarray['uid']), dbesc($datarray['type']), intval($datarray['wall']), intval($datarray['gravity']), intval($datarray['contact-id']), dbesc($datarray['owner-name']), dbesc($datarray['owner-link']), dbesc($datarray['owner-avatar']), dbesc($datarray['author-name']), dbesc($datarray['author-link']), dbesc($datarray['author-avatar']), dbesc($datarray['created']), dbesc($datarray['edited']), dbesc($datarray['commented']), dbesc($datarray['received']), dbesc($datarray['changed']), dbesc($datarray['uri']), dbesc($datarray['thr-parent']), dbesc($datarray['title']), dbesc($datarray['body']), dbesc($datarray['app']), dbesc($datarray['location']), dbesc($datarray['coord']), dbesc($datarray['tag']), dbesc($datarray['inform']), dbesc($datarray['verb']), dbesc($datarray['postopts']), dbesc($datarray['allow_cid']), dbesc($datarray['allow_gid']), dbesc($datarray['deny_cid']), dbesc($datarray['deny_gid']), intval($datarray['private']), intval($datarray['pubmail']), dbesc($datarray['attach']), intval($datarray['bookmark']), intval($datarray['origin']));
    $r = q("SELECT `id` FROM `item` WHERE `uri` = '%s' LIMIT 1", dbesc($datarray['uri']));
    if (count($r)) {
        $post_id = $r[0]['id'];
        logger('mod_item: saved item ' . $post_id);
        if ($parent) {
            // This item is the last leaf and gets the comment box, clear any ancestors
            $r = q("UPDATE `item` SET `last-child` = 0, `changed` = '%s' WHERE `parent` = %d ", dbesc(datetime_convert()), intval($parent));
            // Inherit ACL's from the parent item.
            $r = q("UPDATE `item` SET `allow_cid` = '%s', `allow_gid` = '%s', `deny_cid` = '%s', `deny_gid` = '%s', `private` = %d\n\t\t\t\tWHERE `id` = %d LIMIT 1", dbesc($parent_item['allow_cid']), dbesc($parent_item['allow_gid']), dbesc($parent_item['deny_cid']), dbesc($parent_item['deny_gid']), intval($parent_item['private']), intval($post_id));
            // Send a notification email to the conversation owner, unless the owner is me and I wrote this item
            if ($user['notify-flags'] & NOTIFY_COMMENT && $contact_record != $author) {
                push_lang($user['language']);
                require_once 'bbcode.php';
                $from = $author['name'];
                // name of the automated email sender
                $msg['notificationfromname'] = stripslashes($datarray['author-name']);
                // noreply address to send from
                $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
                // text version
                // process the message body to display properly in text mode
                $msg['textversion'] = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
                // html version
                // process the message body to display properly in text mode
                $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $datarray['body']))));
                // load the template for private message notifications
                $tpl = get_intltext_template('cmnt_received_html_body_eml.tpl');
                $email_html_body_tpl = replace_macros($tpl, array('$username' => $user['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $author['thumb'], '$email' => $importer['email'], '$url' => $author['url'], '$from' => $from, '$body' => $msg['htmlversion'], '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id));
                // load the template for private message notifications
                $tpl = get_intltext_template('cmnt_received_text_body_eml.tpl');
                $email_text_body_tpl = replace_macros($tpl, array('$username' => $user['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $author['thumb'], '$email' => $importer['email'], '$url' => $author['url'], '$from' => $from, '$body' => $msg['textversion'], '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id));
                // use the EmailNotification library to send the message
                require_once "include/EmailNotification.php";
                EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], t("Administrator@") . $a->get_hostname(), t("noreply") . '@' . $a->get_hostname(), $user['email'], sprintf(t('%s commented on an item at %s'), $from, $a->config['sitename']), $email_html_body_tpl, $email_text_body_tpl);
                pop_lang();
            }
            // We won't be able to sign Diaspora comments for authenticated visitors - we don't have their private key
            if ($self) {
                require_once 'include/bb2diaspora.php';
                $signed_body = html_entity_decode(bb2diaspora($datarray['body']));
                $myaddr = $a->user['nickname'] . '@' . substr($a->get_baseurl(), strpos($a->get_baseurl(), '://') + 3);
                if ($datarray['verb'] === ACTIVITY_LIKE) {
                    $signed_text = $datarray['guid'] . ';' . 'Post' . ';' . $parent_item['guid'] . ';' . 'true' . ';' . $myaddr;
                } else {
                    $signed_text = $datarray['guid'] . ';' . $parent_item['guid'] . ';' . $signed_body . ';' . $myaddr;
                }
                $authorsig = base64_encode(rsa_sign($signed_text, $a->user['prvkey'], 'sha256'));
                q("insert into sign (`iid`,`signed_text`,`signature`,`signer`) values (%d,'%s','%s','%s') ", intval($post_id), dbesc($signed_text), dbesc(base64_encode($authorsig)), dbesc($myaddr));
            }
        } else {
            $parent = $post_id;
            // let me know if somebody did a wall-to-wall post on my profile
            if ($user['notify-flags'] & NOTIFY_WALL && $contact_record != $author) {
                push_lang($user['language']);
                require_once 'bbcode.php';
                $from = $author['name'];
                // name of the automated email sender
                $msg['notificationfromname'] = $from;
                // noreply address to send from
                $msg['notificationfromemail'] = t('noreply') . '@' . $a->get_hostname();
                // text version
                // process the message body to display properly in text mode
                $msg['textversion'] = html_entity_decode(strip_tags(bbcode(stripslashes($datarray['body']))), ENT_QUOTES, 'UTF-8');
                // html version
                // process the message body to display properly in text mode
                $msg['htmlversion'] = html_entity_decode(bbcode(stripslashes(str_replace(array("\\r\\n", "\\r", "\\n\\n", "\\n"), "<br />\n", $datarray['body']))));
                // load the template for private message notifications
                $tpl = load_view_file('view/wall_received_html_body_eml.tpl');
                $email_html_body_tpl = replace_macros($tpl, array('$username' => $user['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $author['thumb'], '$url' => $author['url'], '$from' => $from, '$body' => $msg['htmlversion'], '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id));
                // load the template for private message notifications
                $tpl = load_view_file('view/wall_received_text_body_eml.tpl');
                $email_text_body_tpl = replace_macros($tpl, array('$username' => $user['username'], '$sitename' => $a->config['sitename'], '$siteurl' => $a->get_baseurl(), '$thumb' => $author['thumb'], '$url' => $author['url'], '$from' => $from, '$body' => $msg['textversion'], '$display' => $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id));
                // use the EmailNotification library to send the message
                require_once "include/EmailNotification.php";
                EmailNotification::sendTextHtmlEmail($msg['notificationfromname'], t("Administrator@") . $a->get_hostname(), t("noreply") . '@' . $a->get_hostname(), $user['email'], sprintf(t('%s posted to your profile wall at %s'), $from, $a->config['sitename']), $email_html_body_tpl, $email_text_body_tpl);
                pop_lang();
            }
        }
        // fallback so that parent always gets set to non-zero.
        if (!$parent) {
            $parent = $post_id;
        }
        $r = q("UPDATE `item` SET `parent` = %d, `parent-uri` = '%s', `plink` = '%s', `changed` = '%s', `last-child` = 1, `visible` = 1\n\t\t\tWHERE `id` = %d LIMIT 1", intval($parent), dbesc($parent == $post_id ? $uri : $parent_item['uri']), dbesc($a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id), dbesc(datetime_convert()), intval($post_id));
        // photo comments turn the corresponding item visible to the profile wall
        // This way we don't see every picture in your new photo album posted to your wall at once.
        // They will show up as people comment on them.
        if (!$parent_item['visible']) {
            $r = q("UPDATE `item` SET `visible` = 1 WHERE `id` = %d LIMIT 1", intval($parent_item['id']));
        }
    } else {
        logger('mod_item: unable to retrieve post that was just stored.');
        notify(t('System error. Post not saved.'));
        goaway($a->get_baseurl() . "/" . $return_path);
        // NOTREACHED
    }
    // update the commented timestamp on the parent
    q("UPDATE `item` set `commented` = '%s', `changed` = '%s' WHERE `id` = %d LIMIT 1", dbesc(datetime_convert()), dbesc(datetime_convert()), intval($parent));
    $datarray['id'] = $post_id;
    $datarray['plink'] = $a->get_baseurl() . '/display/' . $user['nickname'] . '/' . $post_id;
    call_hooks('post_local_end', $datarray);
    if (strlen($emailcc) && $profile_uid == local_user()) {
        $erecips = explode(',', $emailcc);
        if (count($erecips)) {
            foreach ($erecips as $recip) {
                $addr = trim($recip);
                if (!strlen($addr)) {
                    continue;
                }
                $disclaimer = '<hr />' . sprintf(t('This message was sent to you by %s, a member of the Friendica social network.'), $a->user['username']) . '<br />';
                $disclaimer .= sprintf(t('You may visit them online at %s'), $a->get_baseurl() . '/profile/' . $a->user['nickname']) . EOL;
                $disclaimer .= t('Please contact the sender by replying to this post if you do not wish to receive these messages.') . EOL;
                $subject = '[Friendica]' . ' ' . sprintf(t('%s posted an update.'), $a->user['username']);
                $headers = 'From: ' . $a->user['username'] . ' <' . $a->user['email'] . '>' . "\n";
                $headers .= 'MIME-Version: 1.0' . "\n";
                $headers .= 'Content-Type: text/html; charset=UTF-8' . "\n";
                $headers .= 'Content-Transfer-Encoding: 8bit' . "\n\n";
                $link = '<a href="' . $a->get_baseurl() . '/profile/' . $a->user['nickname'] . '"><img src="' . $author['thumb'] . '" alt="' . $a->user['username'] . '" /></a><br /><br />';
                $html = prepare_body($datarray);
                $message = '<html><body>' . $link . $html . $disclaimer . '</body></html>';
                @mail($addr, $subject, $message, $headers);
            }
        }
    }
    // This is a real juggling act on shared hosting services which kill your processes
    // e.g. dreamhost. We used to start delivery to our native delivery agents in the background
    // and then run our plugin delivery from the foreground. We're now doing plugin delivery first,
    // because as soon as you start loading up a bunch of remote delivey processes, *this* page is
    // likely to get killed off. If you end up looking at an /item URL and a blank page,
    // it's very likely the delivery got killed before all your friends could be notified.
    // Currently the only realistic fixes are to use a reliable server - which precludes shared hosting,
    // or cut back on plugins which do remote deliveries.
    proc_run('php', "include/notifier.php", $notify_type, "{$post_id}");
    logger('post_complete');
    // figure out how to return, depending on from whence we came
    if ($api_source) {
        return;
    }
    if ($return_path) {
        goaway($a->get_baseurl() . "/" . $return_path);
    }
    $json = array('success' => 1);
    if (x($_POST, 'jsreload') && strlen($_POST['jsreload'])) {
        $json['reload'] = $a->get_baseurl() . '/' . $_POST['jsreload'];
    }
    logger('post_json: ' . print_r($json, true), LOGGER_DEBUG);
    echo json_encode($json);
    killme();
    // NOTREACHED
}
Ejemplo n.º 15
0
 /**
  * After we've either updated or inserted the article, update
  * the link tables and redirect to the new page.
  */
 function showArticle($text, $subtitle, $sectionanchor = '', $me2, $now, $summary, $oldid)
 {
     global $wgUseDumbLinkUpdate, $wgAntiLockFlags, $wgOut, $wgUser, $wgLinkCache, $wgEnotif;
     global $wgUseEnotif;
     $fname = 'Article::showArticle';
     wfProfileIn($fname);
     $wgLinkCache = new LinkCache();
     if (!$wgUseDumbLinkUpdate) {
         # Preload links to reduce lock time
         if ($wgAntiLockFlags & ALF_PRELOAD_LINKS) {
             $wgLinkCache->preFill($this->mTitle);
             $wgLinkCache->clear();
         }
     }
     # Parse the text and replace links with placeholders
     $wgOut = new OutputPage();
     # Pass the current title along in case we're creating a wiki page
     # which is different than the currently displayed one (e.g. image
     # pages created on file uploads); otherwise, link updates will
     # go wrong.
     $wgOut->addWikiTextWithTitle($text, $this->mTitle);
     if (!$wgUseDumbLinkUpdate) {
         # Move the current links back to the second register
         $wgLinkCache->swapRegisters();
         # Get old version of link table to allow incremental link updates
         # Lock this data now since it is needed for an update
         $wgLinkCache->forUpdate(true);
         $wgLinkCache->preFill($this->mTitle);
         # Swap this old version back into its rightful place
         $wgLinkCache->swapRegisters();
     }
     if ($this->isRedirect($text)) {
         $r = 'redirect=no';
     } else {
         $r = '';
     }
     $wgOut->redirect($this->mTitle->getFullURL($r) . $sectionanchor);
     if ($wgUseEnotif) {
         # this would be better as an extension hook
         include_once "UserMailer.php";
         $wgEnotif = new EmailNotification();
         $wgEnotif->notifyOnPageChange($this->mTitle, $now, $summary, $me2, $oldid);
     }
     wfProfileOut($fname);
 }
Ejemplo n.º 16
0
                        $params = array('id_sale' => $sale->sale_id, 'amount' => 149.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info');
                        $status = $client->resaleBySale($params);
                    }
                }
                if ($client->isSuccess()) {
                    $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale']));
                    $subscription->expires_at = Carbon::now()->addDays(30);
                    $subscription->is_active = 1;
                    $subscription->save();
                    $user = User::find($subscription->user_id);
                    $user->level = 2;
                    $user->save();
                    $configs = BoardConfig::where('user_id', '=', $subscription->user_id)->get();
                    if ($configs->count() > 0) {
                        foreach ($configs as $config) {
                            $config->is_active = 1;
                            $config->save();
                        }
                    }
                    EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                    $faktura = $subscription->company_id == 0 ? false : true;
                    Event::fire('invoice.email', array($subscription->user_id, $subscription->id, $payment->id, $faktura));
                } else {
                    $payment = Payment::create(array('user_id' => $subscription->user_id, 'subscription_id' => $subscription->id, 'is_success' => 0));
                    Event::fire('deactivate.subscription', array($subscription->id, $payment->created_at));
                }
            }
        }
    });
});
require app_path() . '/helpers.php';
Ejemplo n.º 17
0
 public function postPayment()
 {
     if (Auth::check()) {
         $rules = array('paylane_token' => 'required', 'first_name' => 'required', 'last_name' => 'required', 'email' => 'required|email', 'address' => 'required', 'zip' => 'required', 'city' => 'required', 'state' => 'required', 'company_name' => 'required_with:faktura', 'company_id' => 'required_with:faktura', 'company_address' => 'required_with:faktura', 'company_zip' => 'required_with:faktura', 'company_city' => 'required_with:faktura', 'company_state' => 'required_with:faktura');
         $validator = Validator::make(Input::all(), $rules);
         if ($validator->fails()) {
             $messages = $validator->messages();
             return Redirect::to('/konto/pro/platnosci')->withInput(Input::flash())->withErrors($validator)->with('alert', array('type' => 'error', 'content' => 'Błąd! Sprawdź wszystkie pola.'));
         } else {
             $user = Auth::user();
             $client = new Paylane\PayLaneRestClient('adubiel', 'dru9pra2');
             $card_params = array('sale' => array('amount' => 189.0, 'currency' => 'PLN', 'description' => 'Subskrypcja Hasztag.info'), 'customer' => array('name' => Input::get('first_name') . ' ' . Input::get('last_name'), 'email' => Input::get('email'), 'ip' => '127.0.0.1', 'address' => array('street_house' => Input::get('address'), 'city' => Input::get('city'), 'state' => Input::get('state'), 'zip' => Input::get('zip'), 'country_code' => 'PL')), 'card' => array('token' => Input::get('paylane_token')));
             $status = $client->cardSaleByToken($card_params);
             if ($client->isSuccess()) {
                 $subscription = Subscription::where('user_id', '=', $user->id);
                 $faktura = false;
                 if ($subscription->count() > 0) {
                     $subscription = $subscription->first();
                     $subscription->user_id = $user->id;
                     $subscription->is_active = 1;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->is_active = 1;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 } else {
                     $subscription = new Subscription();
                     $subscription->user_id = $user->id;
                     $subscription->first_name = Input::get('first_name');
                     $subscription->last_name = Input::get('last_name');
                     $subscription->email = Input::get('email');
                     $subscription->address = Input::get('address');
                     $subscription->zip = Input::get('zip');
                     $subscription->city = Input::get('city');
                     $subscription->state = Input::get('state');
                     $subscription->expires_at = Carbon::now()->addDays(30);
                     if (Input::has('faktura')) {
                         $faktura = true;
                         $subscription->company_name = Input::get('company_name');
                         $subscription->company_id = preg_replace('/\\D/', '', Input::get('company_id'));
                         $subscription->company_address = Input::get('company_address');
                         $subscription->company_city = Input::get('company_city');
                         $subscription->company_state = Input::get('company_state');
                         $subscription->company_zip = Input::get('company_zip');
                     }
                     $subscription->save();
                 }
                 $payment = Payment::create(array('user_id' => $user->id, 'subscription_id' => $subscription->id, 'sale_id' => $status['id_sale'], 'is_success' => 1));
                 Event::fire('invoice.email', array($user->id, $subscription->id, $payment->id, $faktura));
                 EmailNotification::where('subscription_id', '=', $subscription->id)->delete();
                 //here
                 $user->level = 2;
                 $user->save();
                 return Redirect::to('/konto/pro/subskrypcja')->with('alert', array('type' => 'success', 'content' => 'Dziękujemy! Płatność zaakceptowana.'));
             } else {
                 if (isset($status['error'])) {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['error_description']));
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => $status['error']['description']));
                 } else {
                     return Redirect::back()->with('alert', array('type' => 'error', 'content' => 'Błąd! Coś poszło nie tak!'));
                 }
             }
         }
     }
 }
Ejemplo n.º 18
0
/**
 * sets up the sales container
 */
function sendContainer($sales, $deletePDF)
{
    // loops through all selected sales
    foreach ($sales as $sale) {
        // skips "non existent" sales (dev issue: was: deprecated)
        if (null === ($customer = Mage::getModel("customer/customer")->load($sale->getCustomerId()))) {
            continue;
        }
        // skips "premium" orders
        $cgid = $customer->getGroupId();
        $code = Mage::getSingleton("customer/group")->load($cgid)->getCustomerGroupCode();
        if ("General" != $code) {
            print $code . PHP_EOL;
            print $cgid . PHP_EOL;
            continue;
        }
        // Gerdt Vladimir @ Karli (and fills)
        //
        $shipaddr = $sale->getShippingAddress();
        //
        $firstName = $shipaddr->getFirstname();
        $lastName = $shipaddr->getLastname();
        $email = $shipaddr->getEmail();
        $telephone = $shipaddr->getTelephone();
        $street = implode(" ", $shipaddr->getStreet());
        $country = $shipaddr->getCountry();
        $city = $shipaddr->getCity();
        $postcode = $shipaddr->getPostcode();
        ///////
        $kvg_arr_order = array();
        $kvg_lfdnr = getTransactionId($customer, $sale);
        // Eindeutige Auftragsnummer
        /////// Kopfdaten
        $kvg_arr_order[$kvg_lfdnr]['key'] = $kvg_lfdnr;
        // Eindeutige Auftragsnummer
        $kvg_arr_order[$kvg_lfdnr]['order_number'] = $sale->getIncrementId();
        // Bestellnummer, optional
        $kvg_arr_order[$kvg_lfdnr]['customer_note'] = $sale->getCustomerNote();
        // Kommentar zum Auftrag max. 200 Zeichen, optional
        $d = DateTime::createFromFormat("Y-m-d H:i:s", $sale->getCreatedAt());
        $createdAt = $d->format("Y-m-d H:i");
        $createdAtDate = $d->format("Y-m-d");
        $createdAtTime = $d->format("H:i");
        $kvg_arr_order[$kvg_lfdnr]['order_date'] = $createdAtDate;
        // Auftragsdatum
        $kvg_arr_order[$kvg_lfdnr]['order_time'] = $createdAtTime;
        // Auftragszeit
        /////// Kundendaten
        $kvg_arr_order[$kvg_lfdnr]['customer_first_name'] = $firstName;
        // Vorname
        $kvg_arr_order[$kvg_lfdnr]['customer_last_name'] = $lastName;
        // Nachname
        $kvg_arr_order[$kvg_lfdnr]['customer_county'] = $country;
        // Land
        $kvg_arr_order[$kvg_lfdnr]['customer_city'] = $city;
        // Stadt
        $kvg_arr_order[$kvg_lfdnr]['customer_postal_code'] = $postcode;
        // Postleitzahl
        $kvg_arr_order[$kvg_lfdnr]['customer_street'] = $street;
        // Strasse
        $kvg_arr_order[$kvg_lfdnr]['customer_phone'] = $telephone;
        // Telefon
        $kvg_arr_order[$kvg_lfdnr]['customer_mobile'] = $mobile;
        // Mobile Telefon
        $kvg_arr_order[$kvg_lfdnr]['customer_fax'] = $fax;
        // Fax
        $kvg_arr_order[$kvg_lfdnr]['customer_email'] = $email;
        // Email
        /////// Produkte
        foreach ($sale->getAllItems() as $item) {
            $articleID = $item->getSku();
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['article_number'] = $articleID;
            // Artikelnummer
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['amount'] = $item->getQtyOrdered();
            // Menge
            $kvg_arr_order[$kvg_lfdnr]['position'][$articleID]['price'] = $item->getPrice();
            // Preis
            $i++;
        }
        // -->
        //////
        // writes the invoice PDF document
        exec(ExportInvoiceCommand . $sale->getIncrementId());
        // writes the retoure PDF document
        exec(ExportRetoureCommand . $sale->getIncrementId());
        //
        $invoicePDF = PDFPath . $kvg_lfdnr . "_invoice.pdf";
        $retourePDF = PDFPath . $kvg_lfdnr . "_retoure.pdf";
        // checks invoice PDF; skips the sale without an invoice
        if (!file_exists($invoicePDF)) {
            // logs the fail
            logger("No Invoice. Will not send the order: " . $kvg_lfdnr);
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span style='color:red'>Bestellung {$kvg_lfdnr} konnte wegen der fehlenden Quittung nicht zu Karlie gesandt werden.</span>");
            // skips the sale
            continue;
        }
        // sends the order to karlie
        if ("true" === sendOrder($kvg_arr_order, $invoicePDF, $retourePDF)) {
            // writes DB record (order is referred to karlie)
            $sale->setKarlieOrderId($kvg_lfdnr);
            $sale->setState("processing", true, "Die Bestellung ist zu Karlie weitergeleitet. " . $sale->getKarlieOrderId());
            $sale->setStatus("referred_to_karlie");
            $sale->save();
            // logs the CRON success
            logger("Order sent to Karlie");
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span class='green'>Bestellung {$kvg_lfdnr} ist zu Karlie gesandt worden.</span>");
            // sends customer notification email
            foreach ($sale->getInvoiceCollection() as $invoice) {
                try {
                    $invoice->sendEmail();
                } catch (Exception $e) {
                    logger("Could not sent Customer Notification Email: " . $e);
                }
            }
        } else {
            // logs send fail
            logger("Could not send the order");
            // fills up CRON notification email (administrative issue)
            EmailNotification::add("<span class='red'>Bestellung {$kvg_lfdnr} konnte nicht zu Karlie gesandt werden.</span>");
        }
    }
}
Ejemplo n.º 19
0
 /**
  * Writes the data in this object to the database
  * @param bool $noudp
  */
 public function save($noudp = false)
 {
     global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = [];
     }
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     # Strict mode fixups (not-NULL fields)
     foreach (['minor', 'bot', 'new', 'patrolled', 'deleted'] as $field) {
         $this->mAttribs["rc_{$field}"] = (int) $this->mAttribs["rc_{$field}"];
     }
     # ...more fixups (NULL fields)
     foreach (['old_len', 'new_len'] as $field) {
         $this->mAttribs["rc_{$field}"] = isset($this->mAttribs["rc_{$field}"]) ? (int) $this->mAttribs["rc_{$field}"] : null;
     }
     # If our database is strict about IP addresses, use NULL instead of an empty string
     $strictIPs = in_array($dbw->getType(), ['oracle', 'postgres']);
     // legacy
     if ($strictIPs && $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Trim spaces on user supplied text
     $this->mAttribs['rc_comment'] = trim($this->mAttribs['rc_comment']);
     # Make sure summary is truncated (whole multibyte characters)
     $this->mAttribs['rc_comment'] = $wgContLang->truncate($this->mAttribs['rc_comment'], 255);
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('recentchanges_rc_id_seq');
     # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, __METHOD__);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Notify extensions
     Hooks::run('RecentChange_save', [&$this]);
     if (count($this->tags)) {
         ChangeTags::addTags($this->tags, $this->mAttribs['rc_id'], $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_logid'], null, $this);
     }
     # Notify external application via UDP
     if (!$noudp) {
         $this->notifyRCFeeds();
     }
     # E-mail notifications
     if ($wgUseEnotif || $wgShowUpdatedMarker) {
         $editor = $this->getPerformer();
         $title = $this->getTitle();
         // Never send an RC notification email about categorization changes
         if ($this->mAttribs['rc_type'] != RC_CATEGORIZE && Hooks::run('AbortEmailNotification', [$editor, $title, $this])) {
             // @FIXME: This would be better as an extension hook
             // Send emails or email jobs once this row is safely committed
             $dbw->onTransactionIdle(function () use($editor, $title) {
                 $enotif = new EmailNotification();
                 $enotif->notifyOnPageChange($editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_last_oldid'], $this->mExtra['pageStatus']);
             }, __METHOD__);
         }
     }
     // Update the cached list of active users
     if ($this->mAttribs['rc_user'] > 0) {
         JobQueueGroup::singleton()->lazyPush(RecentChangesUpdateJob::newCacheUpdateJob());
     }
 }
Ejemplo n.º 20
0
foreach ($sales as $sale) {
    // loads the sale
    $sale = $sale->load($sale->getId());
    // loads order id of current sale
    $orderID = $sale->getIncrementId();
    // loads customer id of the current sale
    $customerID = $sale->getCustomerId();
    // customer of current sale might be a guest
    if (null === $customerID) {
        $customerID = "guest";
    }
    // loads parcel id of the sale (from karlie)
    $message = exec(GetParcelIDCommand . $customerID . "_" . $orderID);
    // fills up CRON notification email
    $color = "green";
    switch ($message) {
        case "":
        case "null":
        case "parcelID: null":
        case null:
            $color = "red";
            break;
    }
    EmailNotification::add("<span style='color:{$color}'>Bestellung: " . $customerID . "_" . $orderID . " {$message}</span>");
}
// sends CRON notification email
EmailNotification::add("<span style='color:black'>Der CRON Job Check Parcel ID endet.</span>");
EmailNotification::send();
// logs done message
logger("Done: mygassi-check-parcels");
exit(1);
Ejemplo n.º 21
0
 /**
  * Writes the data in this object to the database
  * @param $noudp bool
  */
 public function save($noudp = false)
 {
     global $wgLocalInterwiki, $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = array();
     }
     $this->mExtra['lang'] = $wgLocalInterwiki;
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     # If our database is strict about IP addresses, use NULL instead of an empty string
     if ($dbw->strictIPs() and $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Trim spaces on user supplied text
     $this->mAttribs['rc_comment'] = trim($this->mAttribs['rc_comment']);
     # Make sure summary is truncated (whole multibyte characters)
     $this->mAttribs['rc_comment'] = $wgContLang->truncate($this->mAttribs['rc_comment'], 255);
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('recentchanges_rc_id_seq');
     ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, __METHOD__);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Notify extensions
     wfRunHooks('RecentChange_save', array(&$this));
     # Notify external application via UDP
     if (!$noudp) {
         $this->notifyRC2UDP();
     }
     # E-mail notifications
     if ($wgUseEnotif || $wgShowUpdatedMarker) {
         $editor = $this->getPerformer();
         $title = $this->getTitle();
         if (wfRunHooks('AbortEmailNotification', array($editor, $title))) {
             # @todo FIXME: This would be better as an extension hook
             $enotif = new EmailNotification();
             $enotif->notifyOnPageChange($editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_last_oldid'], $this->mExtra['pageStatus']);
         }
     }
 }
Ejemplo n.º 22
0
function removeTag($action, $article)
{
    if ($action != 'removeTag') {
        return true;
    }
    global $wgRequest, $wgOut, $wgUser;
    wfProfileIn(__METHOD__);
    $wgOut->setArticleBodyOnly(true);
    $tagID = $wgRequest->getVal('tagID');
    $tagName = $wgRequest->getText('tagName');
    $imgName = $wgRequest->getText('imgName');
    $userText = $wgUser->getName();
    $tagID = preg_replace("/[\"'<>]/", '', $tagID);
    $tagName = preg_replace("/[\"'<>]/", '', $tagName);
    $imgName = preg_replace("/[\"'<>]/", '', $imgName);
    $img = wfFindFile($imgName);
    if ($img) {
        $imgTitle = $img->getTitle();
        wfPurgeTitle($imgTitle);
        $dbw = wfGetDB(DB_MASTER);
        $dbw->delete('imagetags', array('unique_id' => $tagID), __METHOD__);
        $wgOut->clearHTML();
        $wgOut->addHTML('<!-- removed tag from the database! -->');
        $wgOut->addHTML(wfGetImageTags($img, $imgName));
        $logPage = new LogPage('tag');
        $logComment = wfMsg('imagetagging-logentry', $tagName, $userText);
        $logPage->addEntry('tag', $imgTitle, $logComment);
        $enotif = new EmailNotification();
        $enotif->notifyOnPageChange($wgUser, $imgTitle, wfTimestampNow(), $logComment, false);
    } else {
        $wgOut->clearHTML();
        $wgOut->addHTML("<!-- ERROR: img named {$imgName} -->\n\t\t\t<script type='text/javascript'>\n\t\t\talert(\"Error removing tag!\");\n\t\t\t</script>");
    }
    wfProfileOut(__METHOD__);
    return false;
}
Ejemplo n.º 23
0
 /**
  * Writes the data in this object to the database
  * @param bool $noudp
  */
 public function save($noudp = false)
 {
     global $wgPutIPinRC, $wgUseEnotif, $wgShowUpdatedMarker, $wgContLang;
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = array();
     }
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     # If our database is strict about IP addresses, use NULL instead of an empty string
     if ($dbw->strictIPs() && $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Trim spaces on user supplied text
     $this->mAttribs['rc_comment'] = trim($this->mAttribs['rc_comment']);
     # Make sure summary is truncated (whole multibyte characters)
     $this->mAttribs['rc_comment'] = $wgContLang->truncate($this->mAttribs['rc_comment'], 255);
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('recentchanges_rc_id_seq');
     # # If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($dbw->cascadingDeletes() && $this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, __METHOD__);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Notify extensions
     Hooks::run('RecentChange_save', array(&$this));
     # Notify external application via UDP
     if (!$noudp) {
         $this->notifyRCFeeds();
     }
     # E-mail notifications
     if ($wgUseEnotif || $wgShowUpdatedMarker) {
         $editor = $this->getPerformer();
         $title = $this->getTitle();
         // Never send an RC notification email about categorization changes
         if ($this->mAttribs['rc_type'] != RC_CATEGORIZE) {
             if (Hooks::run('AbortEmailNotification', array($editor, $title, $this))) {
                 # @todo FIXME: This would be better as an extension hook
                 $enotif = new EmailNotification();
                 $enotif->notifyOnPageChange($editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_last_oldid'], $this->mExtra['pageStatus']);
             }
         }
     }
     // Update the cached list of active users
     if ($this->mAttribs['rc_user'] > 0) {
         JobQueueGroup::singleton()->lazyPush(RecentChangesUpdateJob::newCacheUpdateJob());
     }
 }
Ejemplo n.º 24
0
 public static function setSubject($subject)
 {
     self::$subject = $subject;
 }
Ejemplo n.º 25
0
 /**
  * Writes the data in this object to the database
  * @param $noudp bool
  */
 public function save($noudp = false)
 {
     global $wgLocalInterwiki, $wgPutIPinRC, $wgContLang;
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = array();
     }
     $this->mExtra['lang'] = $wgLocalInterwiki;
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     # If our database is strict about IP addresses, use NULL instead of an empty string
     if ($dbw->strictIPs() and $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Make sure summary is truncated (whole multibyte characters)
     $this->mAttribs['rc_comment'] = $wgContLang->truncate($this->mAttribs['rc_comment'], 255);
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('recentchanges_rc_id_seq');
     ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     /* Wikia change begin - @author: Macbre */
     /* Wysiwyg: add extra data before row is added */
     wfRunHooks('RecentChange_beforeSave', array(&$this));
     /* Wikia change end */
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, __METHOD__);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Notify extensions
     wfRunHooks('RecentChange_save', array(&$this));
     # Notify external application via UDP
     if (!$noudp) {
         $this->notifyRC2UDP();
     }
     # E-mail notifications
     global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
     if ($wgUseEnotif || $wgShowUpdatedMarker) {
         // Users
         if ($this->mAttribs['rc_user']) {
             $editor = $wgUser->getId() == $this->mAttribs['rc_user'] ? $wgUser : User::newFromID($this->mAttribs['rc_user']);
             // Anons
         } else {
             $editor = $wgUser->getName() == $this->mAttribs['rc_user_text'] ? $wgUser : User::newFromName($this->mAttribs['rc_user_text'], false);
         }
         $title = Title::makeTitle($this->mAttribs['rc_namespace'], $this->mAttribs['rc_title']);
         # @todo FIXME: This would be better as an extension hook
         $enotif = new EmailNotification($editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_this_oldid'], $this->mAttribs['rc_last_oldid'], $this->mAttribs['rc_log_action']);
         $enotif->notifyOnPageChange();
     }
     // temporary code begin /Inez
     if ($this->mAttribs['rc_type'] == RC_NEW) {
         $eventType = 'new';
     } else {
         if ($this->mAttribs['rc_type'] == RC_EDIT) {
             $eventType = 'edit';
         } else {
             if ($this->mAttribs['rc_type'] == RC_LOG && $this->mAttribs['rc_namespace'] == NS_IMAGE) {
                 $eventType = 'upload';
             }
         }
     }
     if (!empty($eventType)) {
         global $wgMemc;
         $key = $eventType . gmdate('Ymd_Hi00');
         $ret = $wgMemc->incr($key);
         if (empty($ret)) {
             $wgMemc->set($key, 1, 60 * 5);
         }
     }
     // temporary code end
 }
Ejemplo n.º 26
0
 public static function findNotification($model, $modelId, $type)
 {
     return EmailNotification::where('model', '=', $model)->where("model_id", "=", $modelId)->where("type", "=", $type)->first();
 }
 private function sendEmailToPublisherAdminsNoCredits($publisherAdmins, $companyId)
 {
     $en = EmailNotification::findNotification("Company", $companyId, EmailNotification::COMPANY_NO_CREDIT);
     if (empty($en) || !$en->isValidNotification()) {
         Mail::send('emails.import.no_credits', [], function ($message) use($publisherAdmins) {
             $emails = array_map(function ($ar) {
                 return $ar["email"];
             }, $publisherAdmins->toApiArray());
             $message->from('*****@*****.**')->to($emails)->bcc(Config::get("mail.admins"))->subject('[MINT NOTIFICATION - NO CREDITS LEFT]');
         });
         EmailNotification::createUpdateNotification("Company", $companyId, EmailNotification::COMPANY_NO_CREDIT);
     }
 }
Ejemplo n.º 28
0
 function save()
 {
     global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPPort, $wgRC2UDPPrefix;
     $fname = 'RecentChange::save';
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = array();
     }
     $this->mExtra['lang'] = $wgLocalInterwiki;
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     ## If our database is strict about IP addresses, use NULL instead of an empty string
     if ($dbw->strictIPs() and $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('rc_rc_id_seq');
     ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, $fname);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Update old rows, if necessary
     if ($this->mAttribs['rc_type'] == RC_EDIT) {
         $lastTime = $this->mExtra['lastTimestamp'];
         #$now = $this->mAttribs['rc_timestamp'];
         #$curId = $this->mAttribs['rc_cur_id'];
         # Don't bother looking for entries that have probably
         # been purged, it just locks up the indexes needlessly.
         global $wgRCMaxAge;
         $age = time() - wfTimestamp(TS_UNIX, $lastTime);
         if ($age < $wgRCMaxAge) {
             # live hack, will commit once tested - kate
             # Update rc_this_oldid for the entries which were current
             #
             #$oldid = $this->mAttribs['rc_last_oldid'];
             #$ns = $this->mAttribs['rc_namespace'];
             #$title = $this->mAttribs['rc_title'];
             #
             #$dbw->update( 'recentchanges',
             #	array( /* SET */
             #		'rc_this_oldid' => $oldid
             #	), array( /* WHERE */
             #		'rc_namespace' => $ns,
             #		'rc_title' => $title,
             #		'rc_timestamp' => $dbw->timestamp( $lastTime )
             #	), $fname
             #);
         }
         # Update rc_cur_time
         #$dbw->update( 'recentchanges', array( 'rc_cur_time' => $now ),
         #	array( 'rc_cur_id' => $curId ), $fname );
     }
     # Notify external application via UDP
     if ($wgRC2UDPAddress) {
         $conn = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
         if ($conn) {
             $line = $wgRC2UDPPrefix . $this->getIRCLine();
             socket_sendto($conn, $line, strlen($line), 0, $wgRC2UDPAddress, $wgRC2UDPPort);
             socket_close($conn);
         }
     }
     # E-mail notifications
     global $wgUseEnotif;
     if ($wgUseEnotif) {
         # this would be better as an extension hook
         global $wgUser;
         $enotif = new EmailNotification();
         $title = Title::makeTitle($this->mAttribs['rc_namespace'], $this->mAttribs['rc_title']);
         $enotif->notifyOnPageChange($wgUser, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_last_oldid']);
     }
     # Notify extensions
     wfRunHooks('RecentChange_save', array(&$this));
 }
Ejemplo n.º 29
0
 public function save()
 {
     global $wgLocalInterwiki, $wgPutIPinRC, $wgRC2UDPAddress, $wgRC2UDPOmitBots;
     $fname = 'RecentChange::save';
     $dbw = wfGetDB(DB_MASTER);
     if (!is_array($this->mExtra)) {
         $this->mExtra = array();
     }
     $this->mExtra['lang'] = $wgLocalInterwiki;
     if (!$wgPutIPinRC) {
         $this->mAttribs['rc_ip'] = '';
     }
     # If our database is strict about IP addresses, use NULL instead of an empty string
     if ($dbw->strictIPs() and $this->mAttribs['rc_ip'] == '') {
         unset($this->mAttribs['rc_ip']);
     }
     # Fixup database timestamps
     $this->mAttribs['rc_timestamp'] = $dbw->timestamp($this->mAttribs['rc_timestamp']);
     $this->mAttribs['rc_cur_time'] = $dbw->timestamp($this->mAttribs['rc_cur_time']);
     $this->mAttribs['rc_id'] = $dbw->nextSequenceValue('recentchanges_rc_id_seq');
     ## If we are using foreign keys, an entry of 0 for the page_id will fail, so use NULL
     if ($dbw->cascadingDeletes() and $this->mAttribs['rc_cur_id'] == 0) {
         unset($this->mAttribs['rc_cur_id']);
     }
     # Insert new row
     $dbw->insert('recentchanges', $this->mAttribs, $fname);
     # Set the ID
     $this->mAttribs['rc_id'] = $dbw->insertId();
     # Notify extensions
     wfRunHooks('RecentChange_save', array(&$this));
     # Notify external application via UDP
     if ($wgRC2UDPAddress && (!$this->mAttribs['rc_bot'] || !$wgRC2UDPOmitBots)) {
         self::sendToUDP($this->getIRCLine());
     }
     # E-mail notifications
     global $wgUseEnotif, $wgShowUpdatedMarker, $wgUser;
     if ($wgUseEnotif || $wgShowUpdatedMarker) {
         // Users
         if ($this->mAttribs['rc_user']) {
             $editor = $wgUser->getId() == $this->mAttribs['rc_user'] ? $wgUser : User::newFromID($this->mAttribs['rc_user']);
             // Anons
         } else {
             $editor = $wgUser->getName() == $this->mAttribs['rc_user_text'] ? $wgUser : User::newFromName($this->mAttribs['rc_user_text'], false);
         }
         # FIXME: this would be better as an extension hook
         $enotif = new EmailNotification();
         $title = Title::makeTitle($this->mAttribs['rc_namespace'], $this->mAttribs['rc_title']);
         $enotif->notifyOnPageChange($editor, $title, $this->mAttribs['rc_timestamp'], $this->mAttribs['rc_comment'], $this->mAttribs['rc_minor'], $this->mAttribs['rc_last_oldid']);
     }
 }
Ejemplo n.º 30
0
 function notifyNew($timestamp, &$title, $minor, &$user, $comment, $bot = "default", $ip = '', $size = 0, $newId = 0)
 {
     if (!$ip) {
         global $wgIP;
         $ip = empty($wgIP) ? '' : $wgIP;
     }
     if ($bot == 'default') {
         $bot = $user->isBot();
     }
     $rc = new RecentChange();
     $rc->mAttribs = array('rc_timestamp' => $timestamp, 'rc_cur_time' => $timestamp, 'rc_namespace' => $title->getNamespace(), 'rc_title' => $title->getDBkey(), 'rc_type' => RC_NEW, 'rc_minor' => $minor ? 1 : 0, 'rc_cur_id' => $title->getArticleID(), 'rc_user' => $user->getID(), 'rc_user_text' => $user->getName(), 'rc_comment' => $comment, 'rc_this_oldid' => $newId, 'rc_last_oldid' => 0, 'rc_bot' => $bot ? 1 : 0, 'rc_moved_to_ns' => 0, 'rc_moved_to_title' => '', 'rc_ip' => $ip, 'rc_patrolled' => 0, 'rc_new' => 1);
     $rc->mExtra = array('prefixedDBkey' => $title->getPrefixedDBkey(), 'lastTimestamp' => 0, 'oldSize' => 0, 'newSize' => $size);
     $rc->save();
     include_once "UserMailer.php";
     $wgEnotif = new EmailNotification();
     $wgEnotif->notifyOnPageChangeOrNewpage($title, $timestamp, $comment, $minor, 0);
 }