public function getByLogin($login) { $result = array(); $model = new waContactModel(); if ($this->options['login'] == 'login') { $result = $model->getByField('login', $login); } elseif ($this->options['login'] == 'email') { if (strpos($login, '@') === false) { $result = $model->getByField('login', $login); } else { $sql = "SELECT c.* FROM wa_contact c\n JOIN wa_contact_emails e ON c.id = e.contact_id\n WHERE " . ($this->options['is_user'] ? "c.is_user = 1 AND " : "") . "e.email LIKE s:email AND e.sort = 0 AND c.password != ''\n ORDER BY c.id LIMIT 1"; $result = $model->query($sql, array('email' => $login))->fetch(); } } if ($result) { $this->checkBan($result); } return $result; }
/** * @param array $params deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute($params) { // Получаем все удаляемые контакты $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $guestbook_model = new guestbook2Model(); foreach ($contacts as $contact) { // Обновляем записи гостевой книги, чтобы не было "битых" contact_id $guestbook_model->updateByField('contact_id', $contact['id'], array('contact_id' => 0, 'name' => $contact['name'])); } }
/** * @param array $params deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute($params) { // Getting all contacts to be deleted // Получаем все удаляемые контакты $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $guestbook_model = new guestbook2Model(); foreach ($contacts as $contact) { // Updating guestbook records to avoid appearance of non-existent contact_id values // Обновляем записи гостевой книги, чтобы не было "битых" contact_id $guestbook_model->updateByField('contact_id', $contact['id'], array('contact_id' => 0, 'name' => $contact['name'])); } }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute($params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } }
/** * @param string $login * @param waAuth $auth * @return waContact|bool */ protected function findContact($login, $auth) { $contact_model = new waContactModel(); $is_user = $auth->getOption('is_user'); if (strpos($login, '@')) { $sql = "SELECT c.* FROM wa_contact c\n JOIN wa_contact_emails e ON c.id = e.contact_id\n WHERE " . ($is_user ? "c.is_user = 1 AND " : "") . "e.email LIKE s:email AND e.sort = 0\n ORDER BY c.id LIMIT 1"; $contact_info = $contact_model->query($sql, array('email' => $login))->fetch(); } else { $contact_info = $contact_model->getByField('login', $login); } if ($contact_info && (!$is_user || $contact_info['is_user'])) { $contact = new waContact($contact_info['id']); $contact->setCache($contact_info); return $contact; } return false; }
/** * @param int[] $params Deleted contact_id * @see waEventHandler::execute() * @return void */ public function execute(&$params) { $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $params, true); $post_model = new blogPostModel(); $comment_model = new blogCommentModel(); foreach ($contacts as $contact) { $data = array('contact_id' => 0, 'contact_name' => $contact['name']); $post_model->updateByField('contact_id', $contact['id'], $data); $data = array('contact_id' => 0, 'name' => $contact['name'], 'auth_provider' => null); $comment_model->updateByField('contact_id', $contact['id'], $data); } /** * @event contacts_delete * @param array[] int $contact_ids array of contact's ID * @return void */ wa()->event(array('blog', 'contacts_delete'), $params); }
/** * @param string $login * @return array * @throws waException */ public function getByLogin($login) { $result = array(); $model = new waContactModel(); if ($this->options['login'] == 'login') { $result = $model->getByField('login', $login); if (!$result) { $result = $this->getByEmail($login); } } elseif ($this->options['login'] == 'email') { if (strpos($login, '@') !== false) { $result = $this->getByEmail($login); } if (!$result) { $result = $model->getByField('login', $login); } } if ($result) { $this->checkBan($result); } return $result; }
/** * * Get contact extra info * @param int $id * @param int|int[] $size * @return array|bool */ public static function getContactInfo($id, $size = 50) { $ids = is_array($id) ? $id : array($id); static $cache = array(); $cached = array_keys($cache); if ($search = array_unique(array_diff($ids, $cached))) { $user_model = new waContactModel(); $cache += $user_model->getByField('id', $search, 'id'); } if (is_array($id)) { $result = array(); foreach ($ids as $id) { $result[$id] = isset($cache[$id]) ? $cache[$id] : false; } return $result; } elseif (isset($cache[$id])) { if (!isset($cache[$id]['photo_url'])) { $waContact = new waContact($id); $max_size = 0; foreach ((array) $size as $s) { $cache[$id]['photo_url_' . $s] = $waContact->getPhoto($s); if ($max_size < $s) { $max_size = $s; $cache[$id]['photo_url'] = $cache[$id]['photo_url_' . $s]; } } unset($waContact); } return $cache[$id]; } else { return false; } }
public function getContacts($ids) { if (!$ids) { return array(); } $contact_model = new waContactModel(); $contacts = $contact_model->getByField('id', $ids, 'id'); $config = wa('shop')->getConfig(); $use_gravatar = $config->getGeneralSettings('use_gravatar'); $gravatar_default = $config->getGeneralSettings('gravatar_default'); // Put everything into one array foreach ($contacts as &$c) { $contact = new waContact($c['id']); if (!$contact->get('photo') && $use_gravatar) { $c['photo_50x50'] = shopHelper::getGravatar($contact->get('email', 'default'), 50, $gravatar_default); } else { $c['photo_50x50'] = $contact->getPhoto(50); } //$c += ifset($additional_fields[$c['id']], array()); } return $contacts; }