本文整理匯總了PHP中waContact::getPhoto方法的典型用法代碼示例。如果您正苦於以下問題:PHP waContact::getPhoto方法的具體用法?PHP waContact::getPhoto怎麽用?PHP waContact::getPhoto使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類waContact
的用法示例。
在下文中一共展示了waContact::getPhoto方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: execute
public function execute()
{
$id = $this->getId();
$this->contact = $contact = new waContact($id);
// Show an uploaded image to crop?
if (waRequest::get('uploaded')) {
// Is there an uploaded file in session?
$photoEditors = $this->getStorage()->read('photoEditors');
if (isset($photoEditors[$id]) && file_exists($photoEditors[$id])) {
$url = $this->getPreviewUrl(basename($photoEditors[$id]));
$this->view->assign('oldPreview', $url);
$this->view->assign('oldImage', $url);
}
} else {
// Is there a photo for this contact?
$filename = wa()->getDataPath(waContact::getPhotoDir($id) . "{$contact['photo']}.original.jpg", TRUE);
if (file_exists($filename)) {
$this->view->assign('oldPreview', $contact->getPhoto());
$this->view->assign('oldImage', $contact->getPhoto('original'));
$this->view->assign('orig', 1);
}
}
$this->view->assign('contactId', $id);
$this->view->assign('logged_user_id', wa()->getUser()->getId());
$this->view->assign('contact', $contact);
$this->view->assign('env', wa()->getEnv());
$this->assignUrls();
}
示例2: execute
public function execute()
{
if (!$this->getRequest()->request('json', 0)) {
$action = new contactsContactsInfoAction();
echo $action->display();
return;
}
$m = new waContactModel();
$contact_id = $this->getRequest()->request('id', 0, 'int');
$contact = new waContact($contact_id);
$values = $contact->load('js', true);
if (isset($values['company_contact_id'])) {
if (!$m->getById($values['company_contact_id'])) {
$values['company_contact_id'] = 0;
$contact->save(array('company_contact_id' => 0));
}
}
$values['photo_url_96'] = $contact->getPhoto(96);
$values['photo_url_20'] = $contact->getPhoto(20);
$fields = waContactFields::getInfo($contact['is_company'] ? 'company' : 'person', true);
echo json_encode(array('fields' => $fields, 'values' => $values, 'top' => $contact->getTopFields()));
}
示例3: execute
public function execute()
{
$id = $this->getId();
// Delete the old photos if they exist
$oldDir = wa()->getDataPath(waContact::getPhotoDir($id), TRUE);
if (file_exists($oldDir)) {
waFiles::delete($oldDir);
}
// Update record in DB for this user
$contact = new waContact($id);
$contact['photo'] = 0;
$contact->save();
// Update recent history to reload thumbnail correctly (if not called from personal account)
if (wa()->getUser()->get('is_user')) {
$history = new contactsHistoryModel();
$history->save('/contact/' . $id, null, null, '--');
}
$this->response = array('done' => 1, 'url' => $contact->getPhoto());
}
示例4: getFormFieldsHtml
/**
* @description Get HTML with contact info (field name => field html)
* @return array
*/
protected function getFormFieldsHtml()
{
if (!$this->contact) {
$this->contact = $this->getContact();
}
if (!$this->form) {
$this->form = $this->getForm();
}
$user_info = array();
foreach ($this->form->fields as $id => $field) {
if (!in_array($id, array('password', 'password_confirm'))) {
if ($id === 'photo') {
$user_info[$id] = array('name' => _ws('Photo'), 'value' => '<img src="' . $this->contact->getPhoto() . '">');
} else {
$user_info[$id] = array('name' => $this->form->fields[$id]->getName(null, true), 'value' => $this->contact->get($id, 'html'));
}
}
}
return $user_info;
}
示例5: execute
public function execute()
{
$this->response = array();
// Initialize all needed post vars as $vars in current namespace
foreach (array('x1', 'y1', 'x2', 'y2', 'w', 'h', 'ww', 'orig') as $var) {
if (null === (${$var} = (int) waRequest::post($var))) {
// $$ black magic...
$this->response['error'] = 'wrong parameters';
return;
}
}
$id = $this->getId();
$contact = new waContact($id);
// Path to file we need to crop
$rand = mt_rand();
$dir = waContact::getPhotoDir($id, true);
$filename = wa()->getDataPath("{$dir}{$rand}.original.jpg", true, 'contacts');
$oldDir = wa()->getDataPath("{$dir}", true, 'contacts');
$no_old_photo = false;
if (!$orig) {
// Delete the old photos if they exist
if (file_exists($oldDir)) {
waFiles::delete($oldDir);
$no_old_photo = true;
}
waFiles::create($oldDir);
// Is there an uploaded file in session?
$photoEditors = $this->getStorage()->read('photoEditors');
if (!isset($photoEditors[$id]) || !file_exists($photoEditors[$id])) {
$this->response['error'] = 'Photo editor session is not found or already expired.';
return;
}
$newFile = $photoEditors[$id];
// Save the original image in jpeg for future use
try {
$img = waImage::factory($newFile)->save($filename);
} catch (Exception $e) {
$this->response['error'] = 'Unable to save new file ' . $filename . ' (' . pathinfo($filename, PATHINFO_EXTENSION) . ') as jpeg: ' . $e->getMessage();
return;
}
// Remove uploaded file
unset($photoEditors[$id]);
$this->getStorage()->write('photoEditors', $photoEditors);
unlink($newFile);
} else {
// cropping an old file. Move it temporarily to temp dir to delete all cached thumbnails
$oldFile = wa()->getDataPath("{$dir}{$contact['photo']}.original.jpg", TRUE, 'contacts');
$tempOldFile = wa()->getTempPath("{$id}/{$rand}.original.jpg", 'contacts');
waFiles::move($oldFile, $tempOldFile);
// Delete thumbnails
if (file_exists($oldDir)) {
waFiles::delete($oldDir);
}
waFiles::create($oldDir);
// return original image to its proper place
waFiles::move($tempOldFile, $filename);
}
if (!file_exists($filename)) {
$this->response['error'] = 'Image to crop not found (check directory access rights).';
return;
}
// Crop and save selected area
$croppedFilename = wa()->getDataPath("{$dir}{$rand}.jpg", TRUE, 'contacts');
try {
$img = waImage::factory($filename);
$scale = $img->width / $ww;
$img->crop(floor($w * $scale), floor($h * $scale), floor($x1 * $scale), floor($y1 * $scale))->save($croppedFilename);
} catch (Exception $e) {
$this->response['error'] = 'Unable to crop an image: ' . $e->getMessage();
return;
}
// Update record in DB for this user
$contact['photo'] = $rand;
$contact->save();
if ($no_old_photo) {
$old_app = null;
if (wa()->getApp() !== 'contacts') {
$old_app = wa()->getApp();
waSystem::setActive('contacts');
}
$this->logAction('photo_add', null, $contact->getId());
if ($old_app) {
waSystem::setActive($old_app);
}
}
// Update recent history to reload thumbnail correctly (if not called from personal account)
if (wa()->getUser()->get('is_user')) {
$history = new contactsHistoryModel();
$history->save('/contact/' . $id, null, null, '--');
}
$this->response = array('url' => $contact->getPhoto());
}
示例6: extendUser
/**
* Extend items by adding contact info into $rows[i]['user']
* Uses:
* - $rows[i]['contact_id']
* - $rows[i]['name'] or $rows[i]['contact_name'] when contact is not found or its name is empty
* - $rows[i]['auth_provider'] for default userpic URL
*
* @param array $rows
* @param array $fields
* @param bool $get_link pass true to get $rows[i]['user']['posts_link']
*/
public static function extendUser(&$rows, $fields = array(), $get_link = false)
{
$default_fields = array('id', 'name', 'firstname', 'middlename', 'lastname');
$fields = array_unique(array_merge($fields, $default_fields));
// All contact ids
$ids = array();
foreach ($rows as $row) {
if ($row['contact_id']) {
$ids[] = intval($row['contact_id']);
}
}
$ids = array_unique($ids);
// Fetch contacts using collection
$collection = new waContactsCollection($ids);
$contacts = $collection->getContacts(implode(',', $fields), 0, count($ids));
// Prepare data row to use as a placeholder when contact is not found
$contact = new waContact(0);
$contacts[0] = array('name' => '');
$photo_fields = array();
foreach ($fields as $field) {
if (preg_match('@^photo_url_(\\d+)$@', $field, $matches)) {
$photo_fields[] = $field;
$contacts[0][$field] = $contact->getPhoto($matches[1], $matches[1]);
} else {
$contacts[0][$field] = $contact->get($field);
}
}
// Format contact names
foreach ($contacts as &$c) {
$c['name'] = waContactNameField::formatName($c);
}
unset($c);
// Add data as 'user' key to each row in $rows
$app_static_url = wa()->getAppStaticUrl();
foreach ($rows as &$row) {
$row['user'] = array();
$id = $row['contact_id'] = max(0, intval($row['contact_id']));
if (!isset($contacts[$id])) {
$id = 0;
}
if (isset($contacts[$id])) {
if (isset($row['url']) && $get_link && !isset($contacts[$id]['posts_link'])) {
$contacts[$id]['posts_link'] = blogPost::getUrl($row, 'author');
}
$row['user'] = $contacts[$id];
}
if (!$id || !isset($contacts[$id])) {
if (isset($row['name'])) {
$row['user']['name'] = $row['name'];
} elseif (isset($row['contact_name'])) {
$row['user']['name'] = $row['contact_name'];
}
if (isset($row['auth_provider'])) {
if ($row['auth_provider'] && $row['auth_provider'] != blogCommentModel::AUTH_GUEST) {
$row['user']['photo_url'] = "{$app_static_url}img/{$row['auth_provider']}.png";
foreach ($photo_fields as $field) {
$row['user'][$field] =& $row['user']['photo_url'];
}
}
}
}
unset($row);
}
}
示例7: getAuthorInfo
public static function getAuthorInfo($id, $photo_size = self::SMALL_AUTHOR_PHOTO_SIZE)
{
static $authors_info = array();
$id = max(0, intval($id));
if (!isset($authors_info[$id][$photo_size])) {
$contact = new waContact($id);
$authors_info[$id][$photo_size] = array();
$authors_info[$id][$photo_size]['id'] = $id;
if ($id) {
$authors_info[$id][$photo_size]['name'] = $contact->getName();
}
$authors_info[$id][$photo_size]['photo'] = $contact->getPhoto($photo_size);
}
return $authors_info[$id][$photo_size];
}
示例8: execute
public function execute()
{
$id = waRequest::request('id', null, waRequest::TYPE_INT);
$scm = new shopCustomerModel();
$customer = $scm->getById($id);
try {
$contact = new waContact($id);
$contact->getName();
} catch (waException $e) {
// !!! What to do when shop_customer exists, but no wa_contact found?
throw $e;
}
$ccsm = new waContactCategoriesModel();
$contact_categories = $ccsm->getContactCategories($id);
$contacts_url = wa()->getAppUrl('contacts');
// Info above tabs
$top = array();
foreach (array('email', 'phone', 'im') as $f) {
if ($v = $contact->get($f, 'top,html')) {
$top[] = array('id' => $f, 'name' => waContactFields::get($f)->getName(), 'value' => is_array($v) ? implode(', ', $v) : $v);
}
}
// Get photo
$photo = $contact->get('photo');
$config = $this->getConfig();
$use_gravatar = $config->getGeneralSettings('use_gravatar');
$gravatar_default = $config->getGeneralSettings('gravatar_default');
if (!$photo && $use_gravatar) {
$photo = shopHelper::getGravatar($contact->get('email', 'default'), 96, $gravatar_default);
} else {
$photo = $contact->getPhoto(96);
}
$contact['photo'] = $photo;
// Customer orders
$im = new shopOrderItemsModel();
$orders_collection = new shopOrdersCollection('search/contact_id=' . $id);
$total_count = $orders_collection->count();
$orders = $orders_collection->getOrders('*,items,params', 0, $total_count);
shopHelper::workupOrders($orders);
foreach ($orders as &$o) {
$o['total_formatted'] = waCurrency::format('%{s}', $o['total'], $o['currency']);
$o['shipping_name'] = ifset($o['params']['shipping_name'], '');
$o['payment_name'] = ifset($o['params']['payment_name'], '');
// !!! TODO: shipping and payment icons
}
// Customer reviews
$prm = new shopProductReviewsModel();
$reviews = $prm->getList('*,is_new,product', array('escape' => false, 'where' => array('contact_id' => $id), 'limit' => false));
// Customer affiliate transactions history
$atm = new shopAffiliateTransactionModel();
$affiliate_history = $atm->getByContact($id);
$this->view->assign('top', $top);
$this->view->assign('orders', $orders);
$this->view->assign('reviews', $reviews);
$this->view->assign('contact', $contact);
$this->view->assign('customer', $customer);
$this->view->assign('contacts_url', $contacts_url);
$this->view->assign('affiliate_history', $affiliate_history);
$this->view->assign('contact_categories', $contact_categories);
$this->view->assign('def_cur_tmpl', str_replace('0', '%s', waCurrency::format('%{s}', 0, wa()->getConfig()->getCurrency())));
$this->view->assign('point_rate', str_replace(',', '.', (double) str_replace(',', '.', wa()->getSetting('affiliate_usage_rate'))));
$fields = waContactFields::getAll('person');
if (isset($fields['name'])) {
unset($fields['name']);
}
$this->view->assign('fields', $fields);
$this->view->assign('orders_default_view', $config->getOption('orders_default_view'));
/*
* @event backend_customer
* @return array[string]array $return[%plugin_id%] array of html output
* @return array[string][string]string $return[%plugin_id%]['info_section'] html output
* @return array[string][string]string $return[%plugin_id%]['name_suffix'] html output
* @return array[string][string]string $return[%plugin_id%]['header'] html output
* @return array[string][string]string $return[%plugin_id%]['action_link'] html output
*/
$this->view->assign('backend_customer', wa()->event('backend_customer', $customer));
}
示例9: renderAuthorInfo
private function renderAuthorInfo()
{
// author info
$contact = new waContact($this->photo['contact_id']);
$author = array('id' => $contact['id'], 'name' => $contact['name'], 'photo_url' => $contact->getPhoto(photosPhoto::AUTHOR_PHOTO_SIZE), 'photo_upload_datetime' => $this->photo['upload_datetime']);
return $this->renderer->getAuthorInfo($author);
}
示例10: getOrder
public function getOrder($id, $extend = false, $escape = true)
{
$order = $this->getById($id);
if (!$order) {
return array();
}
$order_params_model = new shopOrderParamsModel();
$order['params'] = $order_params_model->get($id);
if ($order['contact_id']) {
$contact = new waContact($order['contact_id']);
$order['contact'] = array('id' => $order['contact_id'], 'name' => $contact->getName(), 'email' => $contact->get('email', 'default'), 'phone' => $contact->get('phone', 'default'));
$config = wa('shop')->getConfig();
$use_gravatar = $config->getGeneralSettings('use_gravatar');
$gravatar_default = $config->getGeneralSettings('gravatar_default');
if (!$contact->get('photo') && $use_gravatar) {
$order['contact']['photo_50x50'] = shopHelper::getGravatar($order['contact']['email'], 50, $gravatar_default);
} else {
$order['contact']['photo_50x50'] = $contact->getPhoto(50);
}
} else {
$order['contact'] = $this->extractConctactInfo($order['params']);
}
if (!empty($order['params']['coupon_id'])) {
$coupon_model = new shopCouponModel();
$coupon = $coupon_model->getById($order['params']['coupon_id']);
$order['coupon'] = array();
if ($coupon) {
$order['coupon'] = $coupon;
} else {
if (!empty($order['params']['coupon_code'])) {
$order['coupon']['code'] = $order['params']['coupon_code'];
}
}
}
$order_items_model = new shopOrderItemsModel();
$order['items'] = $order_items_model->getItems($id, $extend);
if ($escape) {
if (!empty($order['items'])) {
foreach ($order['items'] as &$product) {
if (!empty($product['name'])) {
$product['name'] = htmlspecialchars($product['name']);
}
if (!empty($product['item']['name'])) {
$product['item']['name'] = htmlspecialchars($product['item']['name']);
}
if (!empty($product['skus'])) {
foreach ($product['skus'] as &$sku) {
if (!empty($sku['name'])) {
$sku['name'] = htmlspecialchars($sku['name']);
}
unset($sku);
}
}
if (!empty($product['services'])) {
foreach ($product['services'] as &$service) {
if (!empty($service['name'])) {
$service['name'] = htmlspecialchars($service['name']);
}
if (!empty($service['item']['name'])) {
$service['item']['name'] = htmlspecialchars($service['item']['name']);
}
if (!empty($service['variants'])) {
foreach ($service['variants'] as &$variant) {
$variant['name'] = htmlspecialchars($variant['name']);
unset($variant);
}
}
unset($service);
}
}
unset($product);
}
}
$order['contact']['name'] = htmlspecialchars($order['contact']['name']);
}
return $order;
}
示例11: customersAutocomplete
public function customersAutocomplete($q)
{
$scm = new shopCustomerModel();
$result = array();
list($list, $total) = $scm->getList(null, $q, 0, $this->limit);
$term_safe = htmlspecialchars($q);
foreach ($list as $c) {
$name = $this->prepare($c['name'], $term_safe);
$email = $this->prepare(ifset($c['email'], ''), $term_safe);
$phone = $this->prepare(ifset($c['phone'], ''), $term_safe);
$phone && ($phone = '<i class="icon16 phone"></i>' . $phone);
$email && ($email = '<i class="icon16 email"></i>' . $email);
$result[] = array('value' => $c['name'], 'label' => implode(' ', array_filter(array($name, $email, $phone))), 'id' => $c['id']);
}
foreach ($result as &$c) {
$contact = new waContact($c['id']);
$c['label'] = "<i class='icon16 userpic20' style='background-image: url(\"" . $contact->getPhoto(20) . "\");'></i>" . $c['label'];
}
unset($c);
return $result;
}
示例12: extendUser
/**
*
* Extend items by contact info
* @param array $rows
* @param array $fields
* @param bool $get_link
*/
public static function extendUser(&$rows, $fields = array(), $get_link = false)
{
$default_fields = array('id', 'name');
$fields = array_unique(array_merge($fields, $default_fields));
$ids = array();
foreach ($rows as $row) {
if ($row['contact_id']) {
$ids[] = intval($row['contact_id']);
}
}
$ids = array_unique($ids);
$collection = new waContactsCollection($ids);
$contacts = $collection->getContacts(implode(',', $fields), 0, count($ids));
$contact = new waContact(0);
$contacts[0] = array('name' => '');
$photo_fields = array();
foreach ($fields as $field) {
if (preg_match('@^photo_url_(\\d+)$@', $field, $matches)) {
$photo_fields[] = $field;
$contacts[0][$field] = $contact->getPhoto($matches[1], $matches[1]);
} else {
$contacts[0][$field] = $contact->get($field);
}
}
$app_static_url = wa()->getAppStaticUrl();
foreach ($rows as &$row) {
$row['user'] = array();
$id = $row['contact_id'] = max(0, intval($row['contact_id']));
if (!isset($contacts[$id])) {
$id = 0;
}
if (isset($contacts[$id])) {
if (isset($row['url']) && $get_link && !isset($contacts[$id]['posts_link'])) {
$contacts[$id]['posts_link'] = blogPost::getUrl($row, 'author');
}
$row['user'] = $contacts[$id];
}
if (!$id || !isset($contacts[$id])) {
if (isset($row['name'])) {
$row['user']['name'] = $row['name'];
} elseif (isset($row['contact_name'])) {
$row['user']['name'] = $row['contact_name'];
}
if (isset($row['auth_provider'])) {
if ($row['auth_provider'] && $row['auth_provider'] != blogCommentModel::AUTH_GUEST) {
$row['user']['photo_url'] = "{$app_static_url}img/{$row['auth_provider']}.png";
foreach ($photo_fields as $field) {
$row['user'][$field] =& $row['user']['photo_url'];
}
}
}
}
unset($row);
}
}
示例13: execute
public function execute()
{
$id = waRequest::post('id', 0, waRequest::TYPE_INT);
$in_stack = waRequest::post('in_stack', 0, waRequest::TYPE_INT);
$hash = waRequest::post('hash', null, waRequest::TYPE_STRING_TRIM);
$hash = urldecode($hash);
// get photo
$this->photo_model = new photosPhotoModel();
$this->photo = $this->photo_model->getById($id);
if (!$this->photo) {
throw new waException(_w("Photo doesn't exists"), 404);
}
$photo_rights_model = new photosPhotoRightsModel();
if (!$photo_rights_model->checkRights($this->photo)) {
throw new waRightsException(_w("You don't have sufficient access rights"));
}
$this->photo['name_not_escaped'] = $this->photo['name'];
$this->photo = photosPhoto::escapeFields($this->photo);
$this->photo['upload_datetime_formatted'] = waDateTime::format('humandate', $this->photo['upload_datetime']);
$this->photo['upload_timestamp'] = strtotime($this->photo['upload_datetime']);
$this->photo['edit_rights'] = $photo_rights_model->checkRights($this->photo, true);
$this->photo['private_url'] = photosPhotoModel::getPrivateUrl($this->photo);
$this->photo['thumb'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getThumbPhotoSize());
$this->photo['thumb_big'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getBigPhotoSize());
$this->photo['thumb_middle'] = photosPhoto::getThumbInfo($this->photo, photosPhoto::getMiddlePhotoSize());
$original_photo_path = photosPhoto::getOriginalPhotoPath($this->photo);
if (wa('photos')->getConfig()->getOption('save_original') && file_exists($original_photo_path)) {
$this->photo['original_exists'] = true;
} else {
$this->photo['original_exists'] = false;
}
$photo_tags_model = new photosPhotoTagsModel();
$tags = $photo_tags_model->getTags($id);
$this->photo['tags'] = $tags;
$this->response['photo'] = $this->photo;
// get stack if it's possible
if (!$in_stack && ($stack = $this->photo_model->getStack($id, array('thumb' => true, 'thumb_crop' => true, 'thumb_big' => true, 'thumb_middle' => true)))) {
$this->response['stack'] = $stack;
}
// get albums
$album_photos_model = new photosAlbumPhotosModel();
$albums = $album_photos_model->getAlbums($id, array('id', 'name'));
$this->response['albums'] = isset($albums[$id]) ? array_values($albums[$id]) : array();
// exif info
$exif_model = new photosPhotoExifModel();
$exif = $exif_model->getByPhoto($this->photo['id']);
if (isset($exif['DateTimeOriginal'])) {
$exif['DateTimeOriginal'] = waDateTime::format('humandatetime', $exif['DateTimeOriginal'], date_default_timezone_get());
}
$this->response['exif'] = $exif;
// get author
$contact = new waContact($this->photo['contact_id']);
$this->response['author'] = array('id' => $contact['id'], 'name' => photosPhoto::escape($contact['name']), 'photo_url' => $contact->getPhoto(photosPhoto::AUTHOR_PHOTO_SIZE), 'backend_url' => $this->getConfig()->getBackendUrl(true) . 'contacts/#/contact/' . $contact['id']);
// for making inline-editable widget
$this->response['frontend_link_template'] = photosFrontendPhoto::getLink(array('url' => '%url%'));
$hooks = array();
$parent_id = $this->photo_model->getStackParentId($this->photo);
$photo_id = $parent_id ? $parent_id : $id;
/**
* Extend photo page
* Add extra widget(s)
* @event backend_photo
* @return array[string][string]string $return[%plugin_id%]['bottom'] In bottom, under photo any widget
*/
$hooks['backend_photo'] = wa()->event('backend_photo', $photo_id);
$this->response['hooks'] = $hooks;
if ($hash !== null) {
$collection = new photosCollection($hash);
if (strstr($hash, 'rate>0') !== false) {
$collection->orderBy('p.rate DESC, p.id');
}
$this->response['photo_stream'] = $this->getPhotoStream($collection);
if ($collection->getAlbum()) {
$this->response['album'] = $collection->getAlbum();
}
}
}
示例14: html
/**
* HTML for the whole form or single form field.
* @param string $field_id
* @param boolean $with_errors whether to add class="error" and error text next to form fields
*/
public function html($field_id = null, $with_errors = true, $placeholders = false)
{
$this->validateFields();
// Single field?
if ($field_id) {
if (empty($this->fields[$field_id])) {
return '';
}
$opts = $this->options;
$opts['id'] = $field_id;
$opts['my_profile'] = $this->fields[$field_id]->getParameter('my_profile');
if (empty($this->contact)) {
$this->contact = new waContact();
}
if ($this->post() !== null) {
$opts['value'] = $this->fields[$field_id]->set($this->contact, $this->post($field_id), array());
} else {
if (isset($this->values[$field_id]) && (is_array($this->values[$field_id]) && count($this->values[$field_id]) > 0 || !is_array($this->values[$field_id]) && strlen((string) $this->values[$field_id]))) {
$opts['value'] = $this->fields[$field_id]->set($this->contact, $this->values[$field_id], array());
} else {
$default_value = $this->fields[$field_id]->getParameter('value');
if ($default_value) {
$opts['value'] = $this->fields[$field_id]->set($this->contact, $default_value, array());
}
}
}
// HTML with no errors?
if ($with_errors && !empty($this->errors[$field_id]) && !empty($this->errors[$field_id])) {
$opts['validation_errors'] = $this->errors[$field_id];
}
// output password field with 'confirm password' field like composite fields
if ($field_id === 'password') {
$this->fields[$field_id]->setParameter('localized_names', _ws('New password'));
$opts['add_password_confirm'] = true;
}
if ($placeholders) {
$opts['placeholder'] = true;
}
return $this->fields[$field_id]->getHTML($opts);
}
// Whole form
$class_field = $this->opt('css_class_field', wa()->getEnv() == 'frontend' ? 'wa-field' : 'field');
$class_value = $this->opt('css_class_value', wa()->getEnv() == 'frontend' ? 'wa-value' : 'value');
$class_name = $this->opt('css_class_name', wa()->getEnv() == 'frontend' ? 'wa-name' : 'name');
$result = '';
foreach ($this->fields() as $fid => $f) {
if ($fid === 'password_confirm') {
continue;
}
if ($fid === 'photo') {
$fake_user = new waContact();
$result .= '<div class="' . $class_field . ' ' . ($class_field . '-' . $f->getId()) . '"><div class="' . $class_name . '">' . _ws('Photo') . '</div><div class="' . $class_value . '">';
if (wa()->getUser()->get($fid)) {
$result .= "\n" . '<img src="' . wa()->getUser()->getPhoto() . '">';
}
$result .= "\n" . '<img src="' . $fake_user->getPhoto() . '">';
$result .= "\n" . '<p><input type="file" name="' . $fid . '_file"></p>';
$result .= $this->html($fid, true);
$result .= "\n</div></div>";
continue;
}
if ($f instanceof waContactHiddenField) {
$result .= $this->html($fid, true);
continue;
}
$field_class = $class_field . '-' . $f->getId();
if (strpos($fid, '.') !== false) {
$field_class .= ' ' . $class_field . '-' . str_replace('.', '-', $fid);
}
if ($f->isRequired()) {
$field_class .= ' ' . (wa()->getEnv() == 'frontend' ? 'wa-required' : 'required');
}
$result .= '<div class="' . $class_field . ' ' . $field_class . '"><div class="' . $class_name . '">' . $f->getName(null, true) . '</div><div class="' . $class_value . '">';
$result .= "\n" . $this->html($fid, $with_errors, $placeholders);
$result .= "\n</div></div>";
}
$result .= '<input type="hidden" name="_csrf" value="' . waRequest::cookie('_csrf', '') . '" />';
return $result;
}
示例15: execute
public function execute()
{
$this->prepare();
if ($query = trim(waRequest::post('query'), '/')) {
if (strpos($query, '/') === false) {
$h = $hash = 'search/' . $query;
} else {
$h = $hash = $query;
if (substr($hash, 0, 14) == 'import/results') {
$h = str_replace('import/results', 'import', $hash);
}
}
} else {
$h = $hash = '';
}
$h_parts = explode('/', $h, 2);
$add_fields = array();
if ($h_parts[0] == 'explore') {
$collection = new contactsCollection();
$event_params = array('collection' => $collection, 'hash' => $h_parts[1]);
$result = wa()->event('explore', $event_params);
if ($result) {
$result = reset($result);
$add_fields = ifset($result['fields']);
$this->response['add_fields'] = $add_fields;
$this->response['name'] = $result['name'];
}
} else {
$collection = new contactsCollection($h);
}
$this->response['fields'] = array();
$fields = '*,photo_url_32,photo_url_96';
if ($h_parts[0] === 'users') {
$fields .= ',_access';
$this->response['fields']['_access'] = array('id' => '_access', 'name' => _w('Access'), 'type' => 'Access', 'vertical' => true);
}
$collection->orderBy($this->sort, $this->order);
$this->response['count'] = $collection->count();
$view = waRequest::post('view');
if ($view == 'list') {
// Preload info to cache to avoid excess DB access
$cm = new waCountryModel();
$cm->preload();
}
$this->response['contacts'] = array_values($collection->getContacts($fields, $this->offset, $this->limit));
$this->workupContacts($this->response['contacts']);
$this->response['total_count'] = $collection->count();
foreach ($this->response['contacts'] as $i => &$c) {
$c['offset'] = $this->offset + $i;
}
unset($c);
if ($view == 'list') {
// Need to format field values correctly for this view.
foreach ($this->response['contacts'] as &$cdata) {
$c = new waContact($cdata['id']);
$c->setCache($cdata);
$data = $c->load('list,js') + $cdata;
contactsHelper::normalzieContactFieldValues($data, waContactFields::getInfo($c['is_company'] ? 'company' : 'person', true));
if (isset($data['photo'])) {
$data['photo'] = $c->getPhoto();
}
$c->removeCache(array_keys($cdata));
$cdata = $data;
}
$this->response['fields'] = array_merge($this->response['fields'], contactsHelper::getFieldsDescription(array('title', 'name', 'photo', 'firstname', 'middlename', 'lastname', 'locale', 'timezone', 'jobtitle', 'company', 'sex', 'company_contact_id'), true));
unset($cdata);
}
// for companies set name to company name
// for contacts with empty name, set it to <no name>
foreach ($this->response['contacts'] as &$c) {
if (isset($c['name']) && trim($c['name'])) {
continue;
}
if (isset($c['company']) && trim($c['company'])) {
$c['name'] = $c['company'];
unset($c['company']);
continue;
}
$c['name'] = '<' . _w('no name') . '>';
}
unset($c);
$title = $collection->getTitle();
$hm = new contactsHistoryModel();
if ($hash) {
$type = explode('/', $hash);
$hash = substr($hash, 0, 1) == '/' ? $hash : '/contacts/' . $hash;
$type = $type[0];
// if search query looks like a quick search then remove field name from header
if ($type == 'search' && preg_match('~^/contacts/search/(name\\*=[^/]*|email\\*=[^/]*@[^/]*)/?$~i', $hash)) {
$title = preg_replace("~^[^=]+=~", '', $title);
}
// save history
if ($type == 'search') {
$hm->save($hash, $title, $type, $this->response['count']);
$this->logAction('search');
}
// Information about system category in categories view
if (substr($hash, 0, 19) === '/contacts/category/') {
$category_id = (int) substr($hash, 19);
$cm = new waContactCategoryModel();
//.........這裏部分代碼省略.........