Skip to content

Commit

Permalink
+ Tons of new features in the contact lists editor. And they're ALL A…
Browse files Browse the repository at this point in the history
…JAX POWERED! Yayz! No Save button! (Profile.php, Profile-Modify.php, Profile.template.php, pages.css)

  Reorder members in a list by grabbing their handles. What you do with them is none of my business.
  Rename any list.
  Remove any list.
  Change any list's type.
  Change any list's visibility. (Note, this isn't actually followed through, will come soon.)
  Permission to view this page is tied to profile_extra, which has _any and _own variants. Just what I needed.
  Contact list widget on people profile summaries are a bit more readable. Custom type is no longer the same as 'New list'.

- Commented out most of the unused code in the new contact list system. Buh-bye buddies! Until I get some time to clean this up... (Profile-Modify.php)

@ I actually committed pages.css instead of index.css earlier, so I'm committing index.css now, and marking it as pages.css above, because it's funnier.
  • Loading branch information
Nao committed Jul 5, 2014
1 parent 8f69758 commit e17a1a1
Show file tree
Hide file tree
Showing 7 changed files with 307 additions and 100 deletions.
152 changes: 108 additions & 44 deletions core/app/Profile-Modify.php
Expand Up @@ -1233,32 +1233,21 @@ function editContacts($memID)
global $context, $txt, $settings;

// Do a quick check to ensure people aren't getting here illegally!
if (!we::$user['is_owner'] || empty($settings['enable_buddylist']))
if (empty($settings['enable_buddylist']))
fatal_lang_error('no_access', false);

$subActions = array(
'new' => array('addContactList', $txt['editBuddies']),
'edit' => array('editContactList', $txt['editIgnoreList']),
);

$context['list_area'] = isset($_GET['sa'], $subActions[$_GET['sa']]) ? $_GET['sa'] : 'buddies';

// Create the tabs for the template.
$context[$context['profile_menu_name']]['tab_data'] = array(
'title' => $txt['buddies'],
'description' => $txt['buddy_ignore_desc'],
'icon' => 'profile_sm.gif',
'tabs' => array(
'new' => array(),
'edit' => array(),
),
);
// $subActions = array(
// 'new' => array('addContactList', $txt['editBuddies']),
// 'edit' => array('editContactList', $txt['editIgnoreList']),
// );

// Pass on to the actual function.
wetem::load($subActions[$context['list_area']][0]);
$subActions[$context['list_area']][0]($memID);
wetem::load('editContactList');
editContactList($memID);
}

// !! Currently not being used; to remove.
/*
function addContactList($memID)
{
global $context, $user_profile, $memberContext;
Expand Down Expand Up @@ -1361,16 +1350,19 @@ function addContactList($memID)
$context['buddies'][$buddy] = $memberContext[$buddy];
}
}
*/

function editContactList($memID)
{
global $context, $user_profile, $memberContext;

// For making changes!
$buddiesArray = array_filter(explode(',', $user_profile[$memID]['buddy_list']));
$canChangeOther = allowedTo('profile_extra_any');
$canChange = $canChangeOther || allowedTo('profile_extra_own');

// Adding or removing a contact from one or more lists, maybe..?
if (isset($_POST['uid']))
if (isset($_POST['uid']) && $canChange)
{
checkSession('post');

Expand All @@ -1385,6 +1377,9 @@ function editContactList($memID)
{
if ((int) $clist == 0)
{
// 'New lists' should be of the custom type by default.
if ($clist === 'new')
$clist = 'custom';
wesql::insert('ignore',
'{db_prefix}contact_lists',
array('id_owner' => 'int', 'name' => 'string', 'list_type' => 'string', 'added' => 'int'),
Expand All @@ -1411,21 +1406,47 @@ function editContactList($memID)
wesql::query('
DELETE FROM {db_prefix}contacts
WHERE id_member = {int:user}
AND id_list = {int:list}
AND id_owner = {int:me}',
AND id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}'),
array(
'user' => $user,
'list' => $clist,
'me' => $memID, // Make sure we're the legitimate owner!
)
);

// At this point, would be nice to know if we're friendly to each other.
/* $request = wesql::query('
SELECT id_list FROM {db_prefix}contacts
WHERE (id_owner = {int:user} AND id_member = {int:me} AND list_type != {literal:restrict})
OR (id_owner = {int:me} AND id_member = {int:user} AND list_type != {literal:restrict})',
array(
'user' => $user,
'me' => we::$id,
)
);
$is_synchronous = wesql::num_rows($request) > 0;
wesql::free_result($request);
// And then save it. Not sure it'll be very useful, but it's not too costly...
wesql::query('
UPDATE {db_prefix}contacts
SET id_synchronous = {int:sync}
WHERE (id_owner = {int:user} AND id_member = {int:me})
OR (id_owner = {int:me} AND id_member = {int:user})',
array(
'user' => $user,
'me' => we::$id,
'sync' => (int) $is_synchronous,
)
);*/
}
cache_put_data('contacts_' . $memID, null, 3000);
redirectexit('action=profile;u=' . $user);
}

// !! The rest should be removed, once it's all set and done.

// !! This should be removed, once it's all set and done.
/*
// Removing a buddy?
if (isset($_GET['remove']))
{
Expand Down Expand Up @@ -1486,45 +1507,86 @@ function editContactList($memID)
// Back to the buddy list!
redirectexit('action=profile;u=' . $memID . ';area=lists;sa=buddies');
}
elseif (isset($_GET['uli']))
*/

if (isset($_GET['uli']) && $canChange)
{
checkSession('get');
$data = explode('_', $_GET['uli']);

// Deleting a contact from a list, or an entire list..?
if (isset($_GET['del']))
{
cache_put_data('contacts_' . $memID, null, 3000);
wesql::query('
DELETE FROM {db_prefix}contacts
WHERE id_member = {int:user}
AND id_list = {int:list}
AND id_owner = {int:me}',
WHERE ' . (isset($data[1]) ? 'id_member = {int:user}
AND ' : '') . 'id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}'),
array(
'user' => $data[1],
'user' => isset($data[1]) ? $data[1] : 0,
'list' => $data[0],
'me' => $memID, // Make sure we're the legitimate owner!
)
);
if (!isset($data[1]))
wesql::query('
DELETE FROM {db_prefix}contact_lists
WHERE id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}'),
array(
'list' => $data[0],
'me' => $memID, // Make sure we're the legitimate owner!
)
);
return_raw('ok');
}

wesql::query('
UPDATE {db_prefix}contacts
SET hidden = !hidden
WHERE id_member = {int:user}
AND id_list = {int:list}
AND id_owner = {int:me}',
array(
'user' => $data[1],
'list' => $data[0],
'me' => $memID,
)
);
if (isset($_GET['order'], $_POST['order']))
{
$query = '
UPDATE {db_prefix}contacts
SET position = CASE id_member';

foreach (explode(',', $_POST['order']) as $sort => $id)
$query .= '
WHEN ' . (int) $id . ' THEN ' . (int) $sort;

$query .= '
ELSE 0
END
WHERE id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}');

wesql::query($query, array('list' => $data[0]));
return_raw('ok');
}

if (isset($_GET['name']) || isset($_GET['type']) || isset($_GET['visi']))
{
$what = isset($_GET['name']) ? 'name' : (isset($_GET['type']) ? 'list_type' : (isset($_GET['visi']) ? 'visibility' : ''));
$target = isset($_GET['name']) ? $_POST['target'] : (isset($_GET['type']) ? $_GET['type'] : (isset($_GET['visi']) ? $_GET['to'] : ''));
cache_put_data('contacts_' . $memID, null, 3000);
wesql::query('
UPDATE {db_prefix}contact_lists
SET ' . $what . ' = {string:target}
WHERE id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}'),
array(
'target' => $target,
'list' => $data[0],
'me' => $memID,
)
);
return_raw(isset($_GET['name']) ? generic_contacts($target) : $target);
}

$request = wesql::query('
SELECT hidden
FROM {db_prefix}contacts
WHERE id_member = {int:user}
AND id_list = {int:list}',
AND id_list = {int:list}' . ($canChangeOther ? '' : '
AND id_owner = {int:me}'),
array(
'user' => $data[1],
'list' => $data[0],
Expand Down Expand Up @@ -1585,8 +1647,9 @@ function editContactList($memID)
$context['profile_contacts'] = $contacts;
$context['profile_lists'] = $lists;


// !! This should be removed, once it's all set and done.
// Get all the user's "buddies"...
/*
$buddies = array();
if (!empty($buddiesArray))
Expand Down Expand Up @@ -1619,6 +1682,7 @@ function editContactList($memID)
loadMemberContext($buddy);
$context['buddies'][$buddy] = $memberContext[$buddy];
}
*/
}

// Show all the user's buddies, as well as an add/delete interface.
Expand Down
9 changes: 3 additions & 6 deletions core/app/Profile.php
Expand Up @@ -235,17 +235,14 @@ function ModifyProfile($post_errors = array())
),
),
'contacts' => array(
'label' => $txt['editBuddyIgnoreLists'],
'label' => $txt['buddies'],
'file' => 'Profile-Modify',
'function' => 'editContacts',
'enabled' => false, // !! !empty($settings['enable_buddylist']) && we::$user['is_owner'],
'enabled' => !empty($settings['enable_buddylist']),
'sc' => 'post',
'subsections' => array(
'edit' => array($txt['editBuddies']),
),
'permission' => array(
'own' => array('profile_extra_any', 'profile_extra_own'),
'any' => array(),
'any' => array('profile_extra_any'),
),
),
'lists' => array(
Expand Down

0 comments on commit e17a1a1

Please sign in to comment.