IT Knowledge Base

~ Without sacrifice, there can be no victory ~

發佈日期:

分類:

,

如何自訂phpList設定(2)

還以為phplist的工作完成了,誰不知今天又來了新玩法,在訂閱與取消訂閱之後,還要加上一個可更改通訊訂閱的選項。明明phplist己內建一個這樣的功能,但硬是要把它加到自己的網頁當中,當然,很多問題便出來了。

首先出現是有關流程的問題。在phplist中,更改通訊訂閱需先輸入一個已登記自己的電郵,再到郵箱中查看有關更改網址,再到網址更改選項。

而為了方便,決定免去中間電郵的步驟。當用戶輸入自己電郵後,直接跳到更改版面,完成後再轉到(redirect)去指定網址。

01. 打開lists目錄下的index.php檔案。找尋以下部份:function sendPersonalLocationPage($id)。

將整個function更改為:
function sendPersonalLocationPage($id) {
global $data ;
list($attributes,$attributedata) = PageAttributes($data);
$html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
$html .= $data["header"];
$html .= '<b>'.$GLOBALS["strPreferencesTitle"].'</b><br/>';
$html .= $GLOBALS["msg"];
if ($_REQUEST["email"]) {
$email = $_REQUEST["email"];
} elseif ($_SESSION["userdata"]["email"]["value"]) {
$email = $_SESSION["userdata"]["email"]["value"];
}
$html .= '<form method="get" action="findUserid.php">';
$html .= '<table border=0>';
$html .= '<tr><td>Enter your registered email: </td><td><input type=text name="email" value="'.$email.'" size="30"></td></tr>';
$html .= '</table>';
$html .= '<p><input type=submit name="sendpersonallocation" value="'.$GLOBALS["strContinue"].'"></p>';
$html .= '</form>'.$GLOBALS["PoweredBy"];
$html .= $data["footer"];
return $html;
}

更改的目的,主要是把form action動作,指向一個新建立的findUserid.php檔案,再由此檔案中,找尋相關uid,再跳到更改版面。

02. 在lists目錄下,新建findUserid.php檔案,並貼上以下內容:

<?php
require "/config/config.php";
$email = $_GET["email"];
$link = mysql_connect($database_host, $database_user, $database_password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
else {
$db_selected = mysql_select_db($database_name, $link);
if (!$db_selected) {
die ('Could not connect to database: ' . mysql_error());
}
else {
$query = sprintf('select uniqid from %s where email = "%s"','phplist_user_user',$email);
$result = mysql_query($query);
$row = mysql_fetch_row($result);
$redirect = 'index.php?p=preferences&uid='.$row[0];
}
}
mysql_close($link);
echo '<script type="text/javascript">';
echo 'window.location = "'.$redirect.'";';
echo '</script>';
?>

這檔案的目的,是在用戶輸入電郵後,從數據庫中找尋相關的uid及之前用戶選項,再跳到phplist預設更改版面。

03. 再次打開lists目錄下的index.php檔案。找尋以下部份:function preferencesPage($id,$userid)

將整個function更改為:
function preferencesPage($id,$userid) {
$uniqid = $_GET['uid'];
$query = sprintf('select email from %s where uniqid = "%s"','phplist_user_user',$uniqid);
$result = mysql_query($query);
$row = mysql_fetch_row($result);
global $data;
list($attributes,$attributedata) = PageAttributes($data);
$selected_lists = explode(',',$data["lists"]);
$html = '<title>'.$GLOBALS["strPreferencesTitle"].'</title>';
$html .= $data["header"];
$html .= '<b>'.$GLOBALS["strPreferencesInfo"].'</b><br />';
$html .= '<span class="required">'.$row[0].'</span>';
$html .= '

<script language="Javascript" type="text/javascript">
var fieldstocheck = new Array();
fieldnames = new Array();

function checkform() {
for (i=0;i<fieldstocheck.length;i++) {
if (eval("document.subscribeform.elements[\\'"+fieldstocheck[i]+"\\'].value") == "") {
alert("'.$GLOBALS["strPleaseEnter"].' "+fieldnames[i]);
eval("document.subscribeform.elements[\\'"+fieldstocheck[i]+"\\'].focus()");
return false;
}
}
';
if ($data['emaildoubleentry']=='yes')
{
$html .='
if(! compareEmail())
{
alert("Email addresses you entered do not match"); 
return false;
}';
}

$html .='
return true;
}

function addFieldToCheck(value,name) {
fieldstocheck[fieldstocheck.length] = value;
fieldnames[fieldnames.length] = name;
}

function compareEmail()
{
return (document.subscribeform.elements["email"].value == document.subscribeform.elements["emailconfirm"].value);
}
</script>';
$html .= formStart('name="subscribeform"');
$html .= '<table border=0>';
$html .= '
<tr>
<td class="attributeinput"><input type=hidden name=email value="'.$row[0].'" size="40"><script language="Javascript" type="text/javascript">addFieldToCheck("email","Email");</script></td>
</tr>
<tr>
<td class="attributeinput"><input type=hidden name=emailconfirm value="'.$row[0].'" size="40"><script language="Javascript" type="text/javascript">addFieldToCheck("emailconfirm","Confirm your email address");</script></td>
</tr>
<tr>
<td><span class="attributeinput"><input type=hidden name="htmlemail" value="1" checked /></span></td>
</tr>
';
$html .= '</table>';
if (ENABLE_RSS) {
$html .= RssOptions($data,$userid);
}
$html .= ListAvailableLists($userid,$data["lists"]);
if (isBlackListedID($userid)) {
$html .= $GLOBALS["strYouAreBlacklisted"];
}
</form><br/><br/>
<p><a href="'.getConfig("unsubscribeurl").'&id='.$id.'">'.$GLOBALS["strUnsubscribe"].'</a></p>
'.$GLOBALS["PoweredBy"];*/
$html .= '<p><input type=submit name="update" value="'.$GLOBALS["strUpdatePreferences"].'" onClick="return checkform();"></p>
</form>'.$GLOBALS["PoweredBy"];
$html .= $data["footer"];
return $html;
}

04. 打開lists/admin目錄下的subscribelib2.php檔案。

將:
if ($ok) {
print '<h3>'.$GLOBALS["strPreferencesUpdated"].'</h3>';
if ($emailchanged)
echo $strPreferencesEmailChanged;
print "<br/>";
echo $strPreferencesNotificationSent;
} else {
print '<h3>'.$strEmailFailed.'</h3>';
}
print "<P>".$PoweredBy.'</p>';
print $subscribepagedata["footer"];
return 3;
更改為:
if ($ok) {
header("location: ../subscribe.php?id=update");
}

更改目的,是讓用戶輸入更改後,phplist發出電郵通知後,再轉到(redirect)去指定網址。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *