Skip to content

Commit

Permalink
1.1.91 release
Browse files Browse the repository at this point in the history
  • Loading branch information
techjewel committed Nov 27, 2020
1 parent a4018eb commit 9dc94e8
Show file tree
Hide file tree
Showing 98 changed files with 2,960 additions and 1,400 deletions.
29 changes: 26 additions & 3 deletions app/Api/Classes/Contacts.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,28 +33,51 @@ public function getContact($idOrEmail)
return false;
}

public function getContactByUserRef($userIdOrEmail)
{
if(is_numeric($userIdOrEmail)) {
return Subscriber::where('user_id', $userIdOrEmail)->first();
} else if(is_string($userIdOrEmail)) {
return Subscriber::where('email', $userIdOrEmail)->first();
}
return false;
}

public function getContactByUserId($userId)
{
return Subscriber::where('user_id', $userId)->first();
}

public function createOrUpdate($data, $forceUpdate = false, $deleteOtherValues = false, $sync = false)
{
if(!isset($data['custom_fields'])) {

if(empty($data['email']) || !is_email($data['email'])) {
return false;
}

if(!$forceUpdate) {
$exist = Subscriber::where('email', $data['email'])->first();
if($exist && $exist->status != 'subscribed' && !empty($data['status'])) {
$forceUpdate = true;
}
}

if(!isset($data['custom_values'])) {
$customFieldKeys = [];
$customFields = (new CustomContactField)->getGlobalFields()['fields'];
foreach ($customFields as $field) {
$customFieldKeys[] = $field['slug'];
}
if ($customFieldKeys) {
$customFieldsData = Arr::only($data, $customFieldKeys);
$customFieldsData = array_filter($customFieldsData);
if ($customFields) {
$data['custom_fields'] = (new CustomContactField)->formatCustomFieldValues($customFieldsData);
$data['custom_values'] = (new CustomContactField)->formatCustomFieldValues($customFieldsData);
}
}
}

return $this->instance->updateOrCreate($data, $forceUpdate = false, $deleteOtherValues = false, $sync = false);
return $this->instance->updateOrCreate($data, $forceUpdate, $deleteOtherValues, $sync);
}

public function getCurrentContact()
Expand Down
1 change: 0 additions & 1 deletion app/Api/Classes/Tags.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function importBulk($tags)
return $newTags;
}


public function __construct(Tag $instance)
{
$this->instance = $instance;
Expand Down
158 changes: 151 additions & 7 deletions app/Functions/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ function fluentcrm_update_meta($objectId, $objectType, $key, $value)

if ($model) {
$model->value = $value;
return $model->save();
$model->save();
return $model;
}

return Meta::create([
Expand Down Expand Up @@ -221,8 +222,8 @@ function fluentcrm_update_option($optionName, $value)
function fluentcrm_get_campaign_meta($objectId, $key, $returnValue = false)
{
$item = fluentcrm_get_meta($objectId, 'FluentCrm\App\Models\Campaign', $key);
if($returnValue) {
if($item) {
if ($returnValue) {
if ($item) {
return $item->value;
}
return false;
Expand Down Expand Up @@ -462,7 +463,7 @@ function fluentcrm_contact_added_to_tags($attachedTagIds, Subscriber $subscriber
{
return do_action(
'fluentcrm_contact_added_to_tags',
(array) $attachedTagIds,
(array)$attachedTagIds,
$subscriber
);
}
Expand All @@ -471,7 +472,7 @@ function fluentcrm_contact_added_to_lists($attachedListIds, Subscriber $subscrib
{
return do_action(
'fluentcrm_contact_added_to_lists',
(array) $attachedListIds,
(array)$attachedListIds,
$subscriber
);
}
Expand All @@ -480,7 +481,7 @@ function fluentcrm_contact_removed_from_tags($detachedTagIds, Subscriber $subscr
{
return do_action(
'fluentcrm_contact_removed_from_tags',
(array) $detachedTagIds,
(array)$detachedTagIds,
$subscriber
);
}
Expand All @@ -489,7 +490,7 @@ function fluentcrm_contact_removed_from_lists($detachedListIds, Subscriber $subs
{
return do_action(
'fluentcrm_contact_removed_from_lists',
(array) $detachedListIds,
(array)$detachedListIds,
$subscriber
);
}
Expand All @@ -514,3 +515,146 @@ function fluentcrm_get_current_contact()

return $subscriber;
}

function fluentcrm_get_crm_profile_html($userIdOrEmail, $checkPermission = true, $withCss = true)
{
if (!$userIdOrEmail) {
return '';
}
if ($checkPermission) {
$contactPermission = apply_filters('fluentcrm_permission', 'manage_options', 'contacts', 'admin_menu');
if (!current_user_can($contactPermission)) {
return '';
}
}

$profile = FluentCrmApi('contacts')->getContactByUserRef($userIdOrEmail);
if (!$profile) {
return '';
}

$urlBase = apply_filters('fluentcrm_menu_url_base', admin_url('admin.php?page=fluentcrm-admin#/'));
$crmProfileUrl = $urlBase . 'subscribers/' . $profile->id;
$tags = $profile->tags;
$lists = $profile->lists;

$stats = $profile->stats();

ob_start();
?>
<div class="fc_profile_external">
<div class="fluentcrm_profile-photo">
<a title="View Profile: <?php echo $profile->email; ?>" href="<?php echo $crmProfileUrl; ?>">
<img src="<?php echo $profile->photo; ?>"/>
</a>
</div>
<div class="profile-info">
<div class="profile_title">
<h3>
<a title="View Profile: <?php echo $profile->email; ?>" href="<?php echo $crmProfileUrl; ?>">
<?php echo $profile->full_name; ?>
</a>
</h3>
<p><?php echo $profile->status; ?></p>
</div>
<div class="fc_tag_lists">
<div class="fc_stats" style="text-align: center">
<?php foreach ($stats as $statKey => $stat): ?>
<span><?php echo ucfirst($statKey); ?>: <?php echo $stat; ?></span>
<?php endforeach; ?>
</div>
<?php if (!$lists->isEmpty()): ?>
<div class="fc_taggables">
<i class="dashicons dashicons-list-view"></i>
<?php foreach ($lists as $list): ?>
<span><?php echo $list->title; ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if (!$tags->isEmpty()): ?>
<div class="fc_taggables">
<i class="dashicons dashicons-tag"></i>
<?php foreach ($tags as $tag): ?>
<span><?php echo $tag->title; ?></span>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
</div>
</div>
<?php if ($withCss): ?>
<style>
.fc_profile_external {
}

.fc_profile_external .fluentcrm_profile-photo {
max-width: 100px;
margin: 0 auto;
}

.fc_profile_external .fluentcrm_profile-photo img {
width: 80px;
height: 80px;
border: 6px solid #e6ebf0;
border-radius: 50%;
vertical-align: middle;
background-position: center center;
background-repeat: no-repeat;
background-size: cover;
}

.fc_profile_external .profile_title {
margin-bottom: 10px;
text-align: center;
}

.fc_profile_external .profile_title h3 {
margin: 0;
padding: 0;
display: inline-block;
}

.fc_profile_external .profile_title a {
text-decoration: none;
}

.fc_profile_external p {
margin: 0 0 5px;
padding: 0;
}

.fc_taggables span {
border: 1px solid #d3e7ff;
margin-left: 4px;
padding: 2px 5px;
display: inline-block;
margin-bottom: 10px;
font-size: 11px;
border-radius: 3px;
color: #2196F3;
}

.fc_taggables i {
font-size: 11px;
margin-top: 7px;
}
.fc_stats {
list-style: none;
margin-bottom: 20px;
padding: 0;
box-sizing: border-box;
}

.fc_stats span {
border: 1px solid #d9ecff;
margin: 0 -4px 0px 0px;
padding: 3px 6px;
display: inline-block;
background: #ecf5ff;
color: #409eff;
}
</style>
<?php endif; ?>
<?php
return ob_get_clean();
}
40 changes: 33 additions & 7 deletions app/Hooks/Handlers/AdminBar.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

namespace FluentCrm\App\Hooks\Handlers;

use FluentCrm\App\Models\Subscriber;
use FluentCrm\App\Services\Stats;
use FluentCrm\App\Http\Controllers\DashboardController;
use FluentCrm\Includes\Helpers\Arr;

class AdminBar
{
public function init()
{
if (!current_user_can('manage_options') || !is_admin()) {
$contactPermission = apply_filters('fluentcrm_permission', 'manage_options', 'contacts', 'admin_menu');

if (!is_admin() || !$contactPermission || !current_user_can($contactPermission)) {
return;
}

Expand All @@ -30,16 +33,39 @@ public function addGlobalSearch($adminBar)
admin_url('admin.php?page=fluentcrm-admin#/')
);

$currentScreen = get_current_screen();
$editingUserVars = null;
if ($currentScreen && $currentScreen->id == 'user-edit') {
$userId = Arr::get($_REQUEST, 'user_id');
$user = get_user_by('ID', $userId);

if ($userId && $user) {
$crmProfile = Subscriber::where('email', $user->user_email)
->orWhere('user_id', $user->ID)
->first();
if ($crmProfile) {
$urlBase = apply_filters('fluentcrm_menu_url_base', admin_url('admin.php?page=fluentcrm-admin#/'));
$crmProfileUrl = $urlBase . 'subscribers/' . $crmProfile->id;
$editingUserVars = [
'user_id' => $userId,
'crm_profile_id' => $crmProfile->id,
'crm_profile_url' => $crmProfileUrl
];
}
}
}

wp_localize_script('fluentcrm_global_seach', 'fc_bar_vars', [
'rest' => $this->getRestInfo(),
'links' => (new Stats)->getQuickLinks(),
'subscriber_base' => $urlBase.'subscribers/'
'rest' => $this->getRestInfo(),
'links' => (new Stats)->getQuickLinks(),
'subscriber_base' => $urlBase . 'subscribers/',
'edit_user_vars' => $editingUserVars
]);

$args = [
'parent' => 'top-secondary',
'id' => 'fc_global_search',
'title' => 'Search Contact',
'title' => 'Search Contacts',
'href' => '#',
'meta' => false
];
Expand All @@ -59,7 +85,7 @@ protected function getRestInfo()
'url' => rest_url($ns . '/' . $v),
'nonce' => wp_create_nonce('wp_rest'),
'namespace' => $ns,
'version' => $v,
'version' => $v
];
}
}
Loading

0 comments on commit 9dc94e8

Please sign in to comment.