SimplePortal

Customization => Custom Coding => Topic started by: samborabora on March 09, 2014, 04:22:52 PM

Title: Update personal text on front page?
Post by: samborabora on March 09, 2014, 04:22:52 PM
I'd like to be able to place the personal text edit field on the front page in a SimplePortal custom php block. Is it possible to place the code that displays the personal text edit field elsewhere, other than the modify profile page?
Title: Re: Update personal text on front page?
Post by: Chen Zhen on March 14, 2014, 08:09:52 PM
samborabora,

  Here is a PHP block code that you can use for what was requested. I recommend to disallow the block for guests and to use it as a side block.


Custom PHP block code (advised to disallow for guests):
Code: [Select]
/*
 * Customize Personal Text for SMF forums c/o Underdog @ http://webdevelop.comli.com
 * Copyright 2014 underdog@webdevelop.comli.com
 * This portal block code is distributed under the terms of its CC BY 4.0 License: http://creativecommons.org/licenses/by/4.0/
*/

global $smcFunc, $user_info, $context, $txt;
loadLanguage('Profile');
$personalText = '';
$currentPage = currentPageUrlPtext();

if (!empty($context['user']['is_guest']))
return false;

if (!allowedTo('profile_identity_own'))
$disabled = 'disabled="true"';
else
$disabled = '';

$request = $smcFunc['db_query']('', "
SELECT personal_text
FROM {db_prefix}members
WHERE id_member = {int:member}",
array('member' => $user_info['id'])
);


while ($row = $smcFunc['db_fetch_assoc']($request))
$personalText = !empty($row['personal_text']) ? $row['personal_text'] : $personalText;

$smcFunc['db_free_result']($request);

echo '
<form action="', $currentPage, '" method="post">
<dl class="centertext">
<dt>
<strong>', $txt['personal_text'], '</strong>
</dt>
<dd style="position:relative;display:block;margin-left:0px;">
<input type="text" name="personal_text" id="personal_text" size="20" value="' . $personalText . '" maxlength="50" class="input_text" ' . $disabled . '/>
</dd>
<dd style="position:relative;display:block;margin-left:0px;padding-top:0.5em;">
<input type="submit" value="Submit" class="button_submit" />
<input type="hidden" name="submit_ptext" />
</dd>
</dl>
</form>';

$sanitizedData = !empty($_REQUEST['personal_text']) && isset($_REQUEST['submit_ptext']) ? htmlspecialchars__recursive($_REQUEST['personal_text']) : false;

if (!empty($sanitizedData) && empty($disabled))
{
updateMemberData($user_info['id'], array('personal_text' => $sanitizedData));
redirectexit($currentPage);
}

function currentPageUrlPtext($pageURL = 'http://')
{
if (!empty($_SERVER["HTTPS"]))
$pageURL = "https://";

if ($_SERVER["SERVER_PORT"] != "80")
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
else
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];

return $pageURL;
}

Regards.
Title: Re: Update personal text on front page?
Post by: samborabora on March 15, 2014, 07:36:45 AM
Thankyou SO MUCH!!!!!!!!! This is absolutely perfect, I can't tell you how grateful I am for this, couldn't have done it without you, really really thanks, works like a charm!! :D :D
SimplePortal 2.3.8 © 2008-2024, SimplePortal