Commit f95eac33 authored by Aaron Wells's avatar Aaron Wells

UI improvements for SocialProfile artefact

Bug 1381729:

1. Renaming it on the user side to "Social media"

2. Not asking the user for the network name if they choose a known network type

3. Adding some of the current popular networks to the dropdown list

Change-Id: I7e38656cd174e6d6ccc2c5c61a5c844d207164ab
parent 91c9e3c3
......@@ -22,5 +22,5 @@ $string['dontshowprofileicon'] = "Don't show a profile picture";
$string['dontshowemail'] = "Don't show email address";
$string['uploadaprofileicon'] = "You have no profile pictures. <a href=\"%sartefact/file/profileicons.php\" target=\"_blank\">Upload one</a>.";
$string['dontshowsocialprofiles'] = "Don't show social profiles";
$string['showsocialprofiles'] = "Show selected social profiles";
$string['dontshowsocialprofiles'] = "Don't show social media accounts";
$string['showsocialprofiles'] = "Show selected social media accounts";
......@@ -16,7 +16,7 @@
<ul>
{foreach from=$profileinfo.socialprofiles item=item}
<li><strong>{$item.description}:</strong>
<a href="{$item.link}" title="{$item.link}" target="_blank">{$item.title|clean_html|safe}</a>
{if $item.link}<a href="{$item.link}" title="{$item.link}" target="_blank">{/if}{$item.title|clean_html|safe}{if $item.link}</a>{/if}
</li>
{/foreach}
</ul>
......
......@@ -12,12 +12,12 @@
defined('INTERNAL') || die();
$string['title'] = 'Social profile';
$string['description'] = 'Choose social profile URLs to display';
$string['title'] = 'Social media';
$string['description'] = 'Choose social media accounts to display';
$string['profilestoshow'] = 'Social profiles to show';
$string['profilestoshow'] = 'Social media accounts to show';
$string['displaysettings'] = 'Display settings';
$string['displayaddressesas'] = 'Display social profile adresses as:';
$string['displayaddressesas'] = 'Display social media accounts as:';
$string['optionicononly'] = 'buttons with icons only';
$string['optiontexticon'] = 'buttons with icons and text';
$string['optiontextonly'] = 'buttons with text only';
......
<p>
{foreach from=$profiles item=p}
<a href="{$p->link}" title="{$p->link}" class="btn socialbtn" target="_blank">
{if $p->link}<a href="{$p->link}" title="{$p->link}" class="btn socialbtn" target="_blank">
{if $showicon}<img src="{$p->icon}" alt="{$p->link}" class="valign-top">{/if}
{if $showicon && $showtext}&nbsp;{/if}
{if $showtext}{$p->description}{/if}
</a>
</a>{/if}
{/foreach}
{if $email}
<a href="mailto:{$email}" title="{$email}" class="btn socialbtn" target="_blank">
......
......@@ -137,14 +137,6 @@ class LeapExportElementInternal extends LeapExportElement {
'faxnumber' => 'fax'
);
static $idmapping = array(
'jabberusername' => 'jabber',
'skypeusername' => 'skype',
'yahoochat' => 'yahoo',
'aimscreenname' => 'aim',
'icqnumber' => 'icq',
);
static $spacialmapping = array(
'country' => 'country',
'city' => 'addressline',
......@@ -156,10 +148,10 @@ class LeapExportElementInternal extends LeapExportElement {
return array('field' => $mapping[$artefacttype]);
}
if ($artefacttype == 'socialprofile') {
if (array_search($artefactnote, $idmapping) !== false) {
if (in_array($artefactnote, ArtefactTypeSocialprofile::$socialnetworks)) {
// Export old messaging system accounts as
// persondata fields with leap:field="id".
return array('field' => 'website', 'service' => $artefactnote);
return array('field' => 'id', 'service' => $artefactnote);
}
else {
// Export new social site profiles as persondata fields
......
......@@ -599,20 +599,17 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
throw new ImportException($importer, "TODO: get_string: persondata field was 'id' but had no service set");
}
// Lack of 'grep' and closures is annoying...
foreach (self::$services as $service) {
if ($service['service'] == $leapattributes['service'] || $service['uri'] == $leapattributes['service']) {
PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'internal', array(
'owner' => $importer->get('usr'),
'type' => 'socialprofile',
'content' => array(
'title' => (string)$item,
'description' => (isset($leapattributes['label'])) ? (string)$leapattributes['label'] : null,
'note' => (!empty($leapattributes['service']) ? $leapattributes['service'] : 'webpage'),
),
));
return;
}
if (in_array($leapattributes['service'], ArtefactTypeSocialprofile::$socialnetworks)) {
PluginImportLeap::add_import_entry_request($importer->get('importertransport')->get('importid'), $persondataid, self::STRATEGY_IMPORT_AS_PROFILE_FIELD, 'internal', array(
'owner' => $importer->get('usr'),
'type' => 'socialprofile',
'content' => array(
'title' => (string)$item,
'description' => (isset($leapattributes['label'])) ? (string)$leapattributes['label'] : null,
'note' => $leapattributes['service'],
),
));
return;
}
}
......@@ -627,16 +624,13 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
throw new ImportException($importer, "TODO: get_string: persondata field was 'id' but had no service set");
}
// Lack of 'grep' and closures is annoying...
foreach (self::$services as $service) {
if ($service['service'] == $leapattributes['service'] || $service['uri'] == $leapattributes['service']) {
// we have the old messaging profiles so we need to adjust them to allow for importing
self::create_artefact($importer, 'socialprofile', (string)$item, array(
'description' => (!empty($leapattributes['label']) ? (string)$leapattributes['label'] : null),
'note' => (!empty($leapattributes['service']) ? (string)$leapattributes['service'] : 'webpage'),
));
return;
}
if (in_array($leapattributes['service'], ArtefactTypeSocialprofile::$socialnetworks)) {
// we have the old messaging profiles so we need to adjust them to allow for importing
self::create_artefact($importer, 'socialprofile', (string)$item, array(
'description' => (!empty($leapattributes['label']) ? (string)$leapattributes['label'] : null),
'note' => (!empty($leapattributes['service']) ? (string)$leapattributes['service'] : 'website'),
));
return;
}
// TODO what do we do here?
......@@ -723,7 +717,7 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
'content' => array(
'title' => (string)$item,
'description' => (isset($leapattributes['label'])) ? (string)$leapattributes['label'] : null,
'note' => (!empty($leapattributes['service']) ? $leapattributes['service'] : 'webpage'),
'note' => (!empty($leapattributes['service']) ? $leapattributes['service'] : 'website'),
),
));
return;
......@@ -769,7 +763,7 @@ class LeapImportInternal extends LeapImportArtefactPlugin {
case 'socialprofile':
self::create_artefact($importer, $maharaattributes['artefacttype'], (string)$item, array(
'description' => (!empty($leapattributes['label']) ? (string)$leapattributes['label'] : null),
'note' => (!empty($leapattributes['service']) ? (string)$leapattributes['service'] : 'webpage'),
'note' => (!empty($leapattributes['service']) ? (string)$leapattributes['service'] : 'website'),
)
);
return;
......
......@@ -28,8 +28,8 @@ $string['aboutprofilelinkdescription'] = '<p>Please go to your <a href="%s">Prof
// profile categories
$string['aboutme'] = 'About me';
$string['contact'] = 'Contact information';
$string['social'] = 'Social profiles';
$string['messaging'] = 'Social profiles';
$string['social'] = 'Social media';
$string['messaging'] = 'Social media';
// profile fields
$string['firstname'] = 'First name';
......@@ -52,11 +52,26 @@ $string['homenumber'] = 'Home phone';
$string['businessnumber'] = 'Business phone';
$string['mobilenumber'] = 'Mobile phone';
$string['faxnumber'] = 'Fax number';
$string['aim'] = 'AIM screen name';
$string['icq'] = 'ICQ number';
$string['jabber'] = 'Jabber username';
$string['skype'] = 'Skype username';
$string['yahoo'] = 'Yahoo chat';
$string['aim.input'] = 'AIM screen name';
$string['aim'] = 'AIM';
$string['icq.input'] = 'ICQ number';
$string['icq'] = 'ICQ';
$string['jabber.input'] = 'Jabber username';
$string['jabber'] = 'Jabber';
$string['skype.input'] = 'Skype username';
$string['skype'] = 'Skype';
$string['yahoo.input'] = 'Yahoo Messenger';
$string['yahoo'] = 'Yahoo Messenger';
$string['facebook.input'] = 'Facebook URL';
$string['facebook'] = 'Facebook';
$string['twitter.input'] = 'Twitter username';
$string['twitter'] = 'Twitter';
$string['instagram.input'] = 'Instagram username';
$string['instagram'] = 'Instagram';
$string['tumblr.input'] = 'Tumblr URL';
$string['tumblr'] = 'Tumblr';
$string['pinterest.input'] = 'Pinterest username';
$string['pinterest'] = 'Pinterest';
$string['occupation'] = 'Occupation';
$string['industry'] = 'Industry';
......@@ -164,24 +179,22 @@ $string['progress_makefriend'] = array(
);
// Social profiles
$string['socialprofile'] = 'Social profile';
$string['socialprofiles'] = 'Social profiles';
$string['service'] = 'Social site name';
$string['servicedesc'] = 'Enter the name of the social site, e.g.: Facebook, LinkedIn, Twitter, etc.';
$string['profileurl'] = 'Social profile URL';
$string['profileurldesc'] = 'For the old messaging services enter your username, screen name or number, otherwise enter your social profile URL address.';
$string['profileurlexists'] = 'This social profile URL cannot be added because it already exists.';
$string['profiletype'] = 'Social profile type';
$string['profiletypedesc'] = 'If you want to add one of the old messaging services select it from the list. For all the new social services leave the option \'Web page\' selected.';
$string['webpage'] = 'Web page';
$string['deleteprofile'] = 'Delete social profile';
$string['deletethisprofile'] = 'Delete social profile: \'%s\'';
$string['deleteprofileconfirm'] = 'Are you sure you wish to delete this social profile?';
$string['editthisprofile'] = 'Edit social profile: \'%s\'';
$string['newsocialprofile'] = 'New social profile';
$string['socialprofile'] = 'Social media';
$string['socialprofiles'] = 'Social media accounts';
$string['service'] = 'Social network';
$string['servicedesc'] = 'Enter the name of the social media network, e.g.: Facebook, LinkedIn, Twitter, etc.';
$string['profileurl'] = 'Your URL or username';
$string['profileurldesc'] = 'The URL of your profile page, or your username.';
$string['profileurlexists'] = 'This social media account cannot be added because its username or URL is a duplicate of one you\'ve already entered.';
$string['profiletype'] = 'Social network';
$string['deleteprofile'] = 'Delete social media account';
$string['deletethisprofile'] = 'Delete social media account: \'%s\'';
$string['deleteprofileconfirm'] = 'Are you sure you wish to delete this social media account?';
$string['editthisprofile'] = 'Edit social media account: \'%s\'';
$string['newsocialprofile'] = 'New social media account';
$string['notvalidprofileurl'] = 'This is not a valid social profile URL address. Please enter a valid URL address or select appropriate messaging service from the list above.';
$string['profiledeletedsuccessfully'] = 'Social profile deleted successfully';
$string['profilesavedsuccessfully'] = 'Social profile saved successfully';
$string['socialprofilerequired'] = 'At least one social profile is required.';
$string['duplicateurl'] = 'This social profile URL is a duplicate.';
$string['profiledeletedsuccessfully'] = 'Social media account deleted successfully';
$string['profilesavedsuccessfully'] = 'Social media account saved successfully';
$string['socialprofilerequired'] = 'At least one social media account is required.';
$string['duplicateurl'] = 'This social media account username or URL is a duplicate of one you\'ve already entered.';
......@@ -903,6 +903,19 @@ class ArtefactTypeHtml extends ArtefactType {
class ArtefactTypeSocialprofile extends ArtefactTypeProfileField {
public static $socialnetworks = array(
'facebook',
'twitter',
'tumblr',
'instagram',
'pinterest',
'aim',
'icq',
'jabber',
'skype',
'yahoo',
);
public static function is_singular() {
return false;
}
......@@ -914,7 +927,13 @@ class ArtefactTypeSocialprofile extends ArtefactTypeProfileField {
public function render_self($options) {
if (array_key_exists('link', $options) && $options['link'] == true) {
$link = self::get_profile_link($this->title, $this->note);
$html = '<a href="' . hsc($link) . '">' . hsc($this->title) . '</a>';
if ($link) {
$html = '<a href="' . hsc($link) . '">' . hsc($this->title) . '</a>';
}
else {
// No valid link, even though you asked for one.
$html = hsc($this->title);
}
}
else {
$html = $this->title;
......@@ -956,8 +975,31 @@ class ArtefactTypeSocialprofile extends ArtefactTypeProfileField {
* @param string $type Social profile subtype; one of icq, aim, yahoo, skype, jabber or webpage (default)
* @return string The URL address
*/
public function get_profile_link($data, $type) {
public static function get_profile_link($data, $type) {
// If they've entered a full URL, just use that
if (filter_var($data, FILTER_VALIDATE_URL)) {
return $data;
}
switch ($type) {
case 'twitter':
// Strip an "@" sign if they put one on.
if (strlen($data) && $data[0] == '@') {
$data = substr($data, 1);
}
$link = 'https://twitter.com/' . hsc($data);
break;
case 'instagram':
// Strip an "@" sign if they put one on.
if (strlen($data) && $data[0] == '@') {
$data = substr($data, 1);
}
$link = 'https://instagram.com/' . hsc($data) . '/';
break;
case 'pinterest':
$link = 'https://www.pinterest.com/' . hsc($data) . '/';
break;
case 'icq':
$link = 'http://www.icq.com/people/' . hsc($data);
break;
......@@ -974,7 +1016,7 @@ class ArtefactTypeSocialprofile extends ArtefactTypeProfileField {
$link = 'xmpp:' . hsc($data);
break;
default:
$link = $data;
$link = false;
}
return $link;
......@@ -993,42 +1035,57 @@ class ArtefactTypeSocialprofile extends ArtefactTypeProfileField {
* $newdata[]->icon - the URL of the icon.
* $newdata[]->link - URL or application call.
*/
public function get_profile_icons($data) {
public static function get_profile_icons($data) {
$newdata = array();
foreach ($data as $record) {
$record->link = self::get_profile_link($record->title, $record->note);
switch ($record->note) {
case 'facebook':
$record->icon = favicon_display_url('facebook.com');
break;
case 'tumblr':
$record->icon = favicon_display_url('tumblr.com');
break;
case 'twitter':
$record->icon = favicon_display_url('twitter.com');
break;
case 'instagram':
$record->icon = favicon_display_url('instagram.com');
break;
case 'pinterest':
$record->icon = favicon_display_url('www.pinterest.com');
break;
case 'icq':
$record->icon = favicon_display_url('www.icq.com');
$record->link = 'http://www.icq.com/people/' . hsc($record->title);
break;
case 'aim':
$record->icon = favicon_display_url('www.aim.com');
$record->link = 'aim:goim?screenname=' . hsc($record->title);
break;
case 'yahoo':
$record->icon = favicon_display_url('messenger.yahoo.com');
$record->link = 'ymsgr:chat?' . hsc($record->title);
break;
case 'skype':
// Since www.skype.com favicon is not working...
$record->icon = favicon_display_url('support.skype.com');
$record->link = 'skype:' . hsc($record->title) . '?call';
break;
case 'jabber':
// Since www.jabber.org favicon is not working...
$record->icon = favicon_display_url('planet.jabber.org');
$record->link = 'xmpp:' . hsc($record->title);
break;
default:
$url = parse_url($record->title);
$record->link = $record->title;
// Check if $url['host'] actually exists - just in case
// it was badly formatted.
if (isset($url['host'])) {
$record->icon = favicon_display_url($url['host']);
}
else {
$record->icon = '';
// We'll fall back to the "no favicon" default icon
$record->icon = favicon_display_url('example.com');
// If they've supplied a URL, use its favicon
if (filter_var($record->title, FILTER_VALIDATE_URL)) {
$url = parse_url($record->title);
// Check if $url['host'] actually exists - just in case
// it was badly formatted.
if (isset($url['host'])) {
$record->icon = favicon_display_url($url['host']);
}
}
}
$newdata[] = $record;
......
......@@ -75,44 +75,36 @@ else {
$title = $toedit->get('title');
$description = $toedit->get('description');
$note = $toedit->get('note');
if ($note == 'website') {
$note = $description;
}
}
else {
// Set default values
$title = '';
$description = '';
$note = 'webpage';
$note = '';
}
$socialnetworkoptions = array();
foreach (ArtefactTypeSocialprofile::$socialnetworks as $socialnetwork) {
$socialnetworkoptions[$socialnetwork] = get_string($socialnetwork . '.input', 'artefact.internal');
}
$editform = array(
'name' => 'editprofileform',
'plugintype' => 'artefact',
'pluginname' => 'internal',
'renderer' => 'table',
'elements' => array(
'id' => array(
'type' => 'hidden',
'value' => $id,
),
'service' => array(
'type' => 'text',
'title' => get_string('service', 'artefact.internal'),
'description' => get_string('servicedesc', 'artefact.internal'),
'defaultvalue' => $description,
'size' => 20,
'rules' => array('required' => true),
),
'profiletype' => array(
'type' => 'select',
'title' => get_string('profiletype', 'artefact.internal'),
'description' => get_string('profiletypedesc', 'artefact.internal'),
'options' => array(
'webpage' => get_string('webpage', 'artefact.internal'),
'aim' => get_string('aim', 'artefact.internal'),
'icq' => get_string('icq', 'artefact.internal'),
'jabber' => get_string('jabber', 'artefact.internal'),
'skype' => get_string('skype', 'artefact.internal'),
'yahoo' => get_string('yahoo', 'artefact.internal'),
),
'options' => $socialnetworkoptions,
'allowother' => true,
'defaultvalue' => $note,
'width' => 171,
'rules' => array('required' => true),
......@@ -162,18 +154,25 @@ function deleteprofileform_submit(Pieform $form, $values) {
function editprofileform_validate(Pieform $form, $values) {
global $USER;
if ($values['profiletype'] == 'webpage' && !filter_var($values['profileurl'], FILTER_VALIDATE_URL)) {
$form->set_error('profileurl', get_string('notvalidprofileurl', 'artefact.internal'));
if (in_array($values['profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) {
$desc = get_string($values['profiletype'], 'artefact.internal');
$type = $values['profiletype'];
}
else {
$desc = $values['profiletype'];
$type = 'website';
}
// We're editing. Make sure it's not a duplicate.
$data = ArtefactTypeSocialprofile::get_social_profiles();
foreach ($data as $i => $socialprofile) {
// don't compare to itself.
if ($socialprofile->id != $values['id']) {
if ($socialprofile->title == $values['profileurl'] &&
$socialprofile->description == $values['service'] &&
$socialprofile->note == $values['profiletype']
) {
$socialprofile->description == $desc &&
$socialprofile->note == $type
) {
$form->set_error('profileurl', get_string('duplicateurl', 'artefact.internal'));
break;
}
......@@ -189,11 +188,20 @@ function editprofileform_submit(Pieform $form, $values) {
$toedit = new ArtefactTypeSocialprofile();
}
if (in_array($values['profiletype'], ArtefactTypeSocialprofile::$socialnetworks)) {
$desc = get_string($values['profiletype'], 'artefact.internal');
$type = $values['profiletype'];
}
else {
$desc = $values['profiletype'];
$type = 'website';
}
$toedit->set('owner', $USER->get('id'));
$toedit->set('author', $USER->get('id'));
$toedit->set('title', $values['profileurl']);
$toedit->set('description', $values['service']);
$toedit->set('note', $values['profiletype']);
$toedit->set('description', $desc);
$toedit->set('note', $type);
$toedit->commit();
$SESSION->add_ok_msg(get_string('profilesavedsuccessfully', 'artefact.internal'));
......
......@@ -17,7 +17,7 @@
<tr class="{cycle values='r0,r1'}">
<td class="center"><img src="{$row->icon}" alt="{$row->description}"></td>
<td><span>{$row->description}</span></td>
<td><a href="{$row->link}" title="{$row->link}" target="_blank" class="socialprofile">{$row->title}</a></td>
<td>{if $row->link}<a href="{$row->link}" title="{$row->link}" target="_blank" class="socialprofile">{/if}{$row->title}{if $row->link}</a>{/if}</td>
{if $controls}<td class="right buttonscell btns2">
<a href="{$WWWROOT}artefact/internal/socialprofile.php?id={$row->id}" title="{str tag='edit'}"><img src="{theme_url filename='images/btn_edit.png'}" alt="{str tag='edit'}"></a>
{if $candelete}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment