class GlmMembersAdmin_member_social extends GlmDataSocial
{
-
+
/**
* WordPress Database Object
*
* @access public
*/
public $contactID = false;
-
+
/*
* Constructor
}
+
+
+ public function updateUrlList(&$existingUrls) {
+ $getExistingUrls = "
+ SELECT *
+ FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_urls
+ ;";
+ $existingUrls = $this->wpdb->get_results($getExistingUrls, ARRAY_A);
+// $existingUrls = $queryUrls[0];
+ return;
+ }
+
+ public function printSocialList(&$array,$name="Array list") {
+ echo "<hr />$name:<table>";
+ foreach($array[0] as $key=>$value) {
+ echo("<tr><td>$key</td><td>$value</td></tr>");
+ }
+ echo "</table>";
+ }
+
public function modelAction($actionData = false)
{
$displayData = 'Hello, World! This is the Social Add-On "social" model talking to you from inside WordPress.';
$socialError = false;
$newSocial = false;
$option = false;
-
+ $debug = true;
+
$socialArray = array(
'facebook' => array(
'name' => 'Facebook',
'baseurl' => 'www.pinterest.com'
),
'googleplus' => array(
- 'name' => 'Google Plus',
+ 'name' => 'GooglePlus',
'xpos' => -124,
'ypos' => -5,
'baseurl' => 'www.google.com'
'ypos' => -45,
'baseurl' => 'www.photobucket.com'
),
+ 'rss' => array(
+ 'name' => 'RSS',
+ 'xpos' => -282,
+ 'ypos' => -5,
+ 'baseurl' => '#'
+ )
);
-
+ // The above array needs to be inserted into the Database
+
+ $getExistingUrls = "
+ SELECT *
+ FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_urls
+ ;";
+ $existingUrls = $this->wpdb->get_results($getExistingUrls, ARRAY_A);
// If there's an action option
if (isset($_REQUEST['option'])) {
$option = trim(filter_var($_REQUEST['option'],FILTER_SANITIZE_STRING));
} else {
$option = "default";
}
- if (isset($_REQUEST['socialname-facebook'])) {
- $socialUrl = trim(filter_var($_REQUEST['socialname-facebook'],FILTER_SANITIZE_STRING));
- } else {
- echo "FAIL socialUrl REQUEST";
- }
+
echo "<hr />Request:<table>";
foreach($_REQUEST as $key=>$value) {
echo("<tr><td>$key</td><td>$value</td></tr>");
}
echo "</table>";
- $socialarray = array_filter($_REQUEST, function($k) {
- return preg_match('/^socialname-/',$k);
- }, ARRAY_FILTER_USE_KEY);
- echo "<hr />SocialArray:<table>";
- echo "<pre>";print_r($socialarray,true);echo "</pre>";
- foreach($socialarray as $key=>$value) {
- echo("<tr><td>$key</td><td>$value</td></tr>");
- }
- echo "</table><hr />";
-
+// $formUrls = array_filter($_REQUEST, function($k) {
+// return preg_match('/^socialname-/',$k);
+// }, ARRAY_FILTER_USE_KEY);
- // this causes ALERT: Empty Fields List in data abstract buildFieldsList()! Likely programming error.
- // $socialData = $this->editEntry($memberID);
-
-// if (!$socialData) {
-// $socialData = $this->newEntry($memberID);
-// $newSocial = true;
-// }
-
-
-
-
-// switch($option) {
-// case 'update':
-// default:
-// $this->updateEntry($memberID);
-// if ($socialData) {
-// $socialUpdated = true;
-// } else {
-// $socialError = true;
-// }
-//
-// $option = 'update';
-// break;
-// }
-
+ // Get the Member ID
$memberID = 0;
if (isset($_REQUEST['member']) && ($_REQUEST['member']-0) > 0) {
$memberID = $_REQUEST['member'] - 0;
}
if ($memberID == 0) {
-
// There should have been a member ID - So failure
return array(
'status' => false,
}
-
switch ($option) {
case "submit":
- // if (isset($_REQUEST['option']) && $_REQUEST['option'] == 'submit') {
-
- $socialData = $this->updateEntry($memberID);
-
if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG) {
glmMembersAdmin::addNotice("<b> Social Update:</b> $memberID", 'Process');
}
- // echo $option;
- // echo $socialUrl;
- // echo $memberID;
- // If update was successful then use editEntry() to setup for the edit again.
- if ($socialData) {
- $social = 'facebook';
- $socialData = $this->editEntry($memberID);
- $socialUpdated = true;
-
- // Also update all member info records with any possible name change
- $sql = "
- INSERT INTO ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
- (member_id,".$social."_url)
- VALUES (".$memberID.", '".$socialUrl."')
- ;";
- echo "<div>".$sql."</div>";
- $sql2 = "
- UPDATE ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
- SET ".$social."_url = '".$socialUrl."'
- WHERE member_id = $memberID
- ;";
- echo "<div>".$sql2."</div>";
- $this->wpdb->query($sql);
- $this->wpdb->query($sql2);
-
- }
+
+ // Refresh the list of URLs based on the Database values
+ $this->updateUrlList($existingUrls);
+ if ($debug) {
+ $this->printSocialList($existingUrls,"Existing Urls Pre Submit");
+ }
+ $socialUpdated = false;
+ $statusMessage="";
+
+ foreach($existingUrls[0] as $social=>$socialUrl) {
+ // Reset the query
+ $sql = "";
+
+ // Grab the URL for the current Social Media from the form
+ if (isset($_REQUEST['socialname-'.$social])) {
+ $formUrl = trim(filter_var($_REQUEST['socialname-'.$social],FILTER_SANITIZE_STRING));
+ } else {
+ $formUrl = 1;
+ if ($debug) {
+ echo "<div>FAILED socialUrl REQUEST for ".$social."</div>";
+ }
+ }
+ if ($socialUrl == 1 || $formUrl == $socialUrl || $formUrl == 1) {
+ // If it encounters the Member ID from the DB, the error code for the form,
+ // or the form does not differ from the database: skip this iteration
+ continue;
+ } else {
+ $sql = "
+ UPDATE ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."media_urls
+ SET ".$social." = '".$formUrl."'
+ WHERE member_id = $memberID
+ ;";
+ $statusMessage = "The selected social links have been updated.";
+ $socialUpdated = true;
+ $this->wpdb->query($sql);
+ }
+ if ($socialUpdated) {
+ echo "<hr><div>".$statusMessage."</div>";
+ if ($debug){
+ echo "<div>Social:".$social."</div>";
+ echo "<div>Social url:".$socialUrl."</div>";
+ echo "<div>statement:".$sql."</div>";
+ }
+ }
+ }
+ if ($debug) {
+ $this->updateUrlList($existingUrls);
+ $this->printSocialList($existingUrls,"Existing Urls Post Submit");
+ }
break;
+ case "social";
default:
- $sql = "
- SELECT *
- FROM ".GLM_MEMBERS_SOCIAL_PLUGIN_DB_PREFIX."socialURL
- ;";
- $existingUrls = $this->wpdb->get_results($sql, ARRAY_A);
- echo "<table>";
- foreach($existingUrls[0] as $key=>$value) {
- echo("<tr><td>$key</td><td>$value</td></tr>");
+ if ($debug) {
+ $this->updateUrlList($existingUrls);
+ $this->printSocialList($existingUrls,"Existing Urls Default:");
}
- echo "</table>";
- echo "<pre>";
- var_dump($existingUrls);
- echo "</pre>";
break;
}
// If we had a fatal error, redirect to the error page
if ($socialError) {
return array(
- 'status' => $success,
- 'option' => $option,
- 'menuItemRedirect' => 'error',
- 'modelRedirect' => 'index',
- 'view' => 'admin/error/index.html',
- 'data' => false
+ 'status' => $success,
+ 'option' => $option,
+ 'menuItemRedirect' => 'error',
+ 'modelRedirect' => 'index',
+ 'view' => 'admin/error/index.html',
+ 'data' => false
);
}
if (GLM_MEMBERS_PLUGIN_ADMIN_DEBUG_VERBOSE) {
glmMembersAdmin::addNotice($memberTypes, 'DataBlock', 'Member Types Data');
}
-
+ // Refresh the URL list before sending it to the front
+ $this->updateUrlList($existingUrls);
// Compile template data
$templateData = array(
'displayData' => $displayData,
'socialError' => $socialError,
'haveMember' => $haveMember,
'memberID' => $memberID,
- 'option' => $option
+ 'option' => $option,
+ 'existingUrls' => $existingUrls[0],
+ 'statusMessage' => $statusMessage
);
// Return status, any suggested view, and any data to controller
return array(
- 'status' => true,
- 'modelRedirect' => false,
- 'view' => 'admin/member/social.html',
- 'data' => $templateData
+ 'status' => true,
+ 'modelRedirect' => false,
+ 'view' => 'admin/member/social.html',
+ 'data' => $templateData
);
}
}