/** * Report resource */ public function report($resource_id, $resource_type, $reason) { if (!Zend_Auth::getInstance()->hasIdentity()) { return null; } $user_id = Zend_Auth::getInstance()->getIdentity()->id; if ($this->isReported($resource_id, $resource_type)) { return false; } $data = array('user_id' => $user_id, 'resource_type' => $resource_type, 'resource_id' => $resource_id, 'reason' => $reason, 'created_on' => Application_Plugin_Common::now(), 'reviewed_by' => 0, 'is_accepted' => 0); // new report email notification if (Zend_Registry::get('config')->get('report_notify_email')) { $to = Zend_Registry::get('config')->get('report_notify_email'); $subject = 'New report'; // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $body = $view->render('newreport.phtml'); $ret = Application_Plugin_Common::sendEmail($to, $subject, $body, true); } return $this->insert($data); }
/** * * Load & submit invitation form * */ function getBetterInvitaionForm() { require_once 'InviteForm.php'; $form = new Addon_Form_BetterInvite(); $translator = Zend_Registry::get('Zend_Translate'); // form is submitted and valid? if (isset($_POST['identifier']) && $_POST['identifier'] == 'Invite') { if ($form->isValid($_POST)) { $to = $form->getValue('email'); $subject = $translator->translate('Invitation'); $base_url = Application_Plugin_Common::getFullBaseUrl(); $user_id = Zend_Auth::getInstance()->getIdentity()->id; $user_name = Zend_Auth::getInstance()->getIdentity()->name; $user_screenname = Zend_Auth::getInstance()->getIdentity()->screen_name; $invitation_link = $base_url . '/?ref=' . $user_id; $profile_link = $base_url . '/' . $user_name . '/?ref=' . $user_id; // prepare phtml email template $view = new Zend_View(); $view->setScriptPath(realpath(dirname(__FILE__))); $view->assign('invitation_link', $invitation_link); $body = $view->render('email.phtml'); $body = str_replace("NETWORK_NAME", Zend_Registry::get('config')->get('network_name'), $body); $body = str_replace("INVITATION_LINK", $invitation_link, $body); $body = str_replace("INVITED_BY_SCREENNAME", $user_screenname, $body); $body = str_replace("INVITED_BY_PROFILE_LINK", $profile_link, $body); // send email $ret = Application_Plugin_Common::sendEmail($to, $subject, $body, true); // show info message if ($ret) { Application_Plugin_Alerts::success(Zend_Registry::get('Zend_Translate')->translate('Invitation has been sent'), 'on'); } } // flush field $form->getElement('email')->setValue(''); } return $form; }
/** * Retrive all unreaded notifications */ public function getNotifications($only_new = false, $fixed_limit = false, $send_emails = false) { if (!Zend_Auth::getInstance()->hasIdentity()) { return; } $current_user_id = (int) Zend_Auth::getInstance()->getIdentity()->id; // application now time $now = Application_Plugin_Common::now(); if ($this->page_number < 1) { $this->page_number = 1; } $limit_from = ((int) $this->page_number - 1) * (int) Zend_Registry::get('config')->get('pagination_limit'); $limit_to = (int) Zend_Registry::get('config')->get('pagination_limit'); $sql = "\n\t\tSELECT\n\n\t\tn.id AS notification_id,\n\t\tn.type AS notification_type,\n\t\tn.resource_type AS notification_resource_type,\n\t\tn.resource_id AS notification_resource_id,\n\t\tn.created_on AS notification_date,\n\t\t\t\t\n\t\tt.email AS to_email,\n\t\tt.name AS to_name,\n\t\tt.screen_name AS to_screen_name,\n\n\t\tc.resource_type AS comment_resource_type,\n\t\tc_authors.name AS comment_author_name,\n\t\tc_authors.screen_name AS comment_author_screen_name,\n\t\tc_authors.avatar AS comment_author_avatar,\n\t\tc_posts.id AS commented_post_id,\n\t\tc.content AS comment_content,\n\t\tc_images.uid AS commented_image_uid,\n\t\tc_profile_wall.name AS commented_post_on_wall,\n\n\t\tl.id AS like_id,\n\t\tl.resource_type AS like_resource_type,\n\t\tl_users.name AS like_user_name,\n\t\tl_users.screen_name AS like_user_screen_name,\n\t\tl_users.avatar AS like_user_avatar,\n\n\t\tp.id AS profile_id,\n\t\tp.name AS profile_name,\n\t\tp.screen_name AS profile_screen_name,\n\t\tp.avatar AS profile_avatar,\n\n\t\tpo.id AS post_id,\n\t\tpo.content AS post_content,\n\t\tpo_authors.name AS post_author_name,\n\t\tpo_authors.screen_name AS post_author_screen_name,\n\t\tpo_authors.avatar AS post_author_avatar,\n\n\t\tp_meta.meta_value AS bulk_notifications\n\n\t\tFROM notifications n\n\n\t\tLEFT JOIN profiles t ON t.id = n.to_user\n\t\t\t\t\n\t\tLEFT JOIN comments c ON c.id = n.resource_id AND n.resource_type = 'comment'\n\t\tLEFT JOIN profiles c_authors ON c_authors.id = c.author_id\n\t\tLEFT JOIN posts c_posts ON c_posts.id = c.resource_id AND c.resource_type = 'post'\n\t\tLEFT JOIN profiles c_profile_wall ON c_profile_wall.id = c_posts.wall_id\n\t\tLEFT JOIN images c_images ON c_images.id = c.resource_id AND c.resource_type = 'image'\n\n\t\tLEFT JOIN likes l ON l.id = n.resource_id AND n.resource_type = 'like'\n\t\tLEFT JOIN profiles l_users ON l_users.id = l.user_id\n\n\t\tLEFT JOIN profiles p ON p.id = n.resource_id AND n.resource_type = 'profile'\n\n\t\tLEFT JOIN posts po ON po.id = n.resource_id AND n.resource_type = 'post'\n\t\tLEFT JOIN profiles po_authors ON po_authors.id = po.author_id\n\n\t\tLEFT JOIN profile_meta p_meta ON p_meta.profile_id = n.to_user AND p_meta.meta_key = 'bulk_notifications'\n\t\t\t\t\n\t\tWHERE 1\n\n\t\tAND (n.type <> 2 OR l.id IS NOT NULL)\n\t\t\t\n\t\t"; // if ($send_emails) { $sql .= "\n\t\t\t\t\tAND n.email_sent = 0\n\t\t\t\t\tAND n.created_on < '{$now}' - INTERVAL 5 MINUTE\n\t\t\t\t\tAND n.created_on > DATE(DATE_SUB('{$now}', INTERVAL 1 DAY))\n\t\t\t\t\t"; } else { $sql .= " AND n.to_user = {$current_user_id} "; } if ($only_new == true) { $sql .= " AND n.is_new = 1 "; } $sql .= " ORDER BY n.created_on DESC "; if ($fixed_limit) { // fixed limit, for notification box $sql .= " LIMIT " . (int) $fixed_limit; } elseif (!$send_emails) { // go with pagination $sql .= " LIMIT {$limit_from}, {$limit_to} "; } $result = $this->getAdapter()->fetchAll($sql); $transl = Zend_Registry::get('Zend_Translate'); // save locale since we might change it below $locale_saved = $transl->getLocale(); $result_rows = $this->fixData($result, $send_emails); // send emails if ($send_emails) { // set default language to network default $transl->setLocale(Zend_Registry::get('config')->get('default_language')); foreach ($result_rows as $row) { // update this notification to email_sent = 1, never mind if it wan't be really sent later on $data = array('email_sent' => '1'); $where = array('id = ?' => $row['notification_id']); $result = $this->update($data, $where); $notification_key = 'notification_email_' . $row['notification_type']; // if row is not updated then email was probably already sent // also, check if this user has enabled this notification if ($result == 1 && $row['do_send_email'] && $row['bulk_notifications'][$notification_key]) { $to = $row['to_email']; $subject = $row['subject_email']; // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $view->assign('top', sprintf($transl->translate('Hello %s'), $row['to_screen_name'])); $view->assign('message', '<p>' . $row['html_link'] . '</p>'); $view->assign('footer', $transl->translate('Thank you')); $body = $view->render('notifications.phtml'); Application_Plugin_Common::sendEmail($to, $subject, $body); $row['view_from_name'] = $row['profile_name']; $row['view_from_screen_name'] = $row['profile_screen_name']; $row['view_from_avatar'] = $row['profile_avatar']; } } return 1; } // restore locale $transl->setLocale($locale_saved); return $result_rows; }
/** * Create new user - add defaults & save */ public function createNewUser(Application_Model_Profiles_Row $profile, $origin = null) { $session = new Zend_Session_Namespace('Default'); $language = $session->language ? $session->language : Zend_Registry::get('config')->get('default_language'); $profile->role = 'user'; $profile->screen_name = $profile->name; $profile->type = 'user'; $profile->avatar = 'default/generic.jpg'; $profile->cover = 'default/' . rand(1, 3) . '.jpg'; $profile->is_hidden = 0; $profile->owner = 0; $profile->default_privacy = 'everyone'; $profile->profile_privacy = 'everyone'; $profile->language = $language; // trigger hooks Zend_Registry::get('hooks')->trigger('hook_app_preadduser', $profile); try { $created_id = $profile->save(); } catch (Zend_Db_Exception $e) { Application_Plugin_Common::log($e->getMessage()); } $ProfilesMeta = new Application_Model_ProfilesMeta(); $ProfilesMeta->metaUpdate('date_created', Application_Plugin_Common::now(), $created_id); // referral user cookie if (isset($_COOKIE['ref'])) { $ref_by_user = $this->getProfileByField('id', base64_decode($_COOKIE['ref'])); if ($ref_by_user) { $ProfilesMeta->metaUpdate('referred_by', $ref_by_user->id, $profile->id); } } if ($origin) { $ProfilesMeta->metaUpdate('registration_origin', $origin, $profile->id); } // new user notification if (Zend_Registry::get('config')->get('newuser_notify_email')) { $to = Zend_Registry::get('config')->get('newuser_notify_email'); $subject = 'New user - ' . $profile->name; // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $view->assign('user_name', $profile->name); $body = $view->render('newuser.phtml'); Application_Plugin_Common::sendEmail($to, $subject, $body); } // auto follow users if (Zend_Registry::get('config')->get('auto_follow_users')) { $Connections = new Application_Model_Connections(); $users = explode(",", Zend_Registry::get('config')->get('auto_follow_users')); foreach ($users as $user) { $follow = $this->getProfileByField('name', trim($user)); if ($follow && $follow->type == 'user') { $Connections->followUser($profile->id, $follow->id); } elseif ($follow && $follow->type == 'group') { $Connections->followUser($profile->id, $follow->id); $Connections->approveConnection($profile->id, $follow->id); } } } // trigger hooks Zend_Registry::get('hooks')->trigger('hook_app_postadduser', $profile); return $profile; }
/** * Send recovery email */ public static function sendRecoveryEmail($email, $name, $key) { // password recovery email $subject = Zend_Registry::get('Zend_Translate')->translate('New Password:'******'/editprofile/recoverpassword/key/' . $key; // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $view->assign('recovery_link', $pw_recovery_url); $body = $view->render('resetpassword.phtml'); $ret = Application_Plugin_Common::sendEmail($email, $subject, $body, true); return $ret; }
/** * Change password with recover key */ public function recoverpasswordAction() { $this->_helper->_layout->setLayout('layout_wide'); $request = $this->getRequest(); // Get password change key if any $key = $request->getParam('key', false); $Profiles = new Application_Model_Profiles(); $ProfilesMeta = new Application_Model_ProfilesMeta(); if ($key) { $form = new Application_Form_ChangeForgottenPassword(); $profile_id = $ProfilesMeta->getProfileId('password_reset', $key); if ($profile_id) { $profile = $Profiles->getProfileByField('id', $profile_id); } } // Redirect if bad or no user if (!$key || !isset($profile) || !$profile) { $this->redirect(''); } $this->view->form = $form; // Form Submitted... if ($request->isPost() && $form->isValid($_POST)) { Application_Plugin_Common::redirectOnDemoAccount(); $newpassword = $form->getValue('password2'); $hash = new Application_Plugin_Phpass(); $hashed_password = $hash->HashPassword($newpassword); // update password $Profiles->updateField($profile->name, 'password', $hashed_password); // remove password reset key $ProfilesMeta->deletePair('password_reset', $key); Application_Plugin_Alerts::success($this->view->translate('Password updated')); // prepare phtml email template $mail_template_path = APPLICATION_PATH . '/views/emails/'; $view = new Zend_View(); $view->setScriptPath($mail_template_path); $body = $view->render('passwordnotice.phtml'); // send email as a security measure $ret = Application_Plugin_Common::sendEmail($profile->email, $this->view->translate('Password updated'), $body, true); $this->redirect(''); } }