Skip to content
Snippets Groups Projects
Commit ca2559a6 authored by Reinhold Kainhofer's avatar Reinhold Kainhofer
Browse files

Version 1.0: First version, automatic and manual subscription works

parent f2c3b93e
No related branches found
No related tags found
No related merge requests found
BASE=downloads_for_sale BASE=acy_subscribe_buyer
PLUGINTYPE=vmcustom PLUGINTYPE=vmcustom
VERSION=1.1 VERSION=1.0
PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html
TRANSLATIONS=$(call wildcard,*.plg_$(PLUGINTYPE)_$(BASE).*ini) TRANSLATIONS=$(call wildcard,*.plg_$(PLUGINTYPE)_$(BASE).*ini)
INDEXFILES=$(BASE)/index.html INDEXFILES=$(BASE)/index.html
TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(BASE)/index.html $(BASE)/tmpl/index.html TMPLFILES=$(call wildcard,$(BASE)/tmpl/*.php) $(BASE)/index.html $(BASE)/tmpl/index.html
ASSETS=$(call wildcard,assets/*.png) $(call wildcard,assets/*.css) assets/index.html ASSETS=$(call wildcard,assets/*.png) $(call wildcard,assets/*.css)
# assets/index.html
ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip ZIPFILE=plg_$(PLUGINTYPE)_$(BASE)_v$(VERSION).zip
......
...@@ -15,6 +15,10 @@ defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not ...@@ -15,6 +15,10 @@ defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not
* http://kainhofer.com * http://kainhofer.com
*/ */
if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php'); if (!class_exists('vmCustomPlugin')) require(JPATH_VM_PLUGINS . DS . 'vmcustomplugin.php');
if(!include_once(rtrim(JPATH_ADMINISTRATOR,DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR.'components'.DIRECTORY_SEPARATOR.'com_acymailing'.DIRECTORY_SEPARATOR.'helpers'.DIRECTORY_SEPARATOR.'helper.php')){
echo 'This plugin requires the AcyMailing Component to be installed';
return;
};
class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
...@@ -67,7 +71,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { ...@@ -67,7 +71,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
function getUserSubscriptions ($uid) { function getUserSubscriptions ($uid) {
if (!($uid>0)) return array(); if (!($uid>0)) return array();
$db = &JFactory::getDBO(); $db = &JFactory::getDBO();
$q = "SELECT `listid` FROM `#__acymailing_listsub` WHERE `subid` = '".(int)$uid."'"; $q = "SELECT `listid` FROM `#__acymailing_listsub` WHERE `subid` = '".(int)$uid."' AND `status`='1'";
$db->setQuery($q); $db->setQuery($q);
$subscribed = $db->loadColumn(); $subscribed = $db->loadColumn();
return $subscribed; return $subscribed;
...@@ -79,7 +83,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { ...@@ -79,7 +83,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
$q = "SELECT `id`, `name`, `email` FROM `#__users` WHERE `id`=".(int)$uid; $q = "SELECT `id`, `name`, `email` FROM `#__users` WHERE `id`=".(int)$uid;
$db->setQuery($q); $db->setQuery($q);
$userinfo = $db->loadObject(); $userinfo = $db->loadObject();
// print("<pre>addAcyUser ($name, $email, $uid): loaded user data <br>(SQL: $q) <br/>".print_r($userinfo,1)."</pre>");
if (empty($email)) if (empty($email))
$email = $userinfo->email; $email = $userinfo->email;
if (empty($name)) if (empty($name))
...@@ -97,7 +100,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { ...@@ -97,7 +100,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
} }
return $db->insertid(); return $db->insertid();
} }
/** Adds the acy user to all the given lists (the subscriber has already been created).*/ /** Adds the acy user to all the given lists (the subscriber has already been created). If the user has unsubscribed, he will not be subscribed again! */
function subscribeUser ($acyuid, $lists) { function subscribeUser ($acyuid, $lists) {
$db = &JFactory::getDBO(); $db = &JFactory::getDBO();
foreach ($lists as $l) { foreach ($lists as $l) {
...@@ -109,10 +112,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { ...@@ -109,10 +112,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
$db->query(); $db->query();
} }
} }
/** Removes the user from all the given lists */
function unsubscribeUser ($acyuid, $lists) {
// TODO
}
/** /**
* @see Form displayed in the product edit page in the BE, configure the download file * @see Form displayed in the product edit page in the BE, configure the download file
...@@ -144,29 +143,40 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { ...@@ -144,29 +143,40 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin {
return true ; return true ;
} }
function addAcyStuff () {
acymailing_initModule('header',null);
}
function getThisURL() {
if (isset ($_SERVER['REQUEST_URI'])) {
$request_uri = $_SERVER['REQUEST_URI'];
} else {
$request_uri = $_SERVER['PHP_SELF'];
if (!empty($_SERVER['QUERY_STRING'])) $request_uri .= '?' . $_SERVER['QUERY_STRING'];
}
return ((empty($_SERVER['HTTPS']) OR strtolower($_SERVER['HTTPS']) != "on") ? "http://" : "https://") . $_SERVER['HTTP_HOST'].$request_uri;
}
function displayProduct($field) { function displayProduct($field) {
$this->addAcyUser("Reinhold Kainhofer", "reinhold@kainhofer.com" , 673);
$html = ''; $html = '';
$this->parseCustomParams($field); $this->parseCustomParams($field);
$user = JFactory::getUser()->get('id'); $user = JFactory::getUser();
if ($user>0) { $uid = $user->get('id');
$acyuid = $this->getAcyUidFromUser($user); if ($uid>0) {
$acyuid = $this->getAcyUidFromUser($uid);
$allsubscriptions = $this->getUserSubscriptions($acyuid); $allsubscriptions = $this->getUserSubscriptions($acyuid);
$subscribed = array_intersect ($field->lists, $allsubscriptions); $uinfo = array(
$notsubscribed = array_diff ($field->lists, $allsubscriptions); 'id' => $uid,
if (!empty($notsubscribed)) { 'name' => $user->get('name'),
$html .= $this->renderByLayout('button_subscribe', array($notsubscribed, $user, $field)); 'email' => $user->get('email'),
// TODO: implement subscribe button 'subscribed' => array_intersect ($field->lists, $allsubscriptions),
} 'notsubscribed' => array_diff ($field->lists, $allsubscriptions),
if (!empty($subscribed)) { );
// TODO: implement unsubscribe button $this->addAcyStuff();
$html .= $this->renderByLayout('button_unsubscribe', array($subscribed, $user, $field)); $html .= $this->renderByLayout('button_subscribe', array(acymailing_getModuleFormName(), $uinfo, $field->lists, $this->getThisURL(), $field));
}
// $html .= "<pre>USER: $user, field: ".print_r($field,1).", all subscriptions: ".print_r($allsubscriptions,1).", subscriptions: ".print_r($subscribed,1).", unsubscriptions: ".print_r($notsubscribed,1).", lists: ".print_r($field->lists, 1)."</pre>";
} elseif ($field->allow_subscribe) { } elseif ($field->allow_subscribe) {
$html .= $this->renderByLayout('button_subscribe_anon', array($field->lists, $field)); $this->addAcyStuff();
// TODO: Display anonymous subscribe button $html .= $this->renderByLayout('button_subscribe', array(acymailing_getModuleFormName(), array(), $field->lists, $this->getThisURL(), $field));
$html = "<pre>NO USER, SUBSCRIBE allowed</pre>";
} else { } else {
// Not logged in, manual subscription not allowed // Not logged in, manual subscription not allowed
} }
...@@ -245,25 +255,23 @@ $this->addAcyUser("Reinhold Kainhofer", "reinhold@kainhofer.com" , 673); ...@@ -245,25 +255,23 @@ $this->addAcyUser("Reinhold Kainhofer", "reinhold@kainhofer.com" , 673);
$customModel = VmModel::getModel('customfields'); $customModel = VmModel::getModel('customfields');
foreach ($order['items'] as $item) { foreach ($order['items'] as $item) {
$customs = $customModel->getproductCustomslist ($item->virtuemart_product_id); $customs = $customModel->getproductCustomslist ($item->virtuemart_product_id);
JFactory::getApplication()->enqueueMessage("<pre>Custom fields: ".print_r($customs,1)."</pre>", 'error');
foreach ($customs as $field) { foreach ($customs as $field) {
if ($field->custom_element != $this->_name) continue; if ($field->custom_element != $this->_name) continue;
if (!$field->subscribe_buyers) continue; if (!$field->subscribe_buyers) continue;
// Add the user to the lists: // Add the user to the lists:
if(!($acyuid>0)) { if(!($acyuid>0)) {
$acyuid = $this->addAcyUser($name, $email, $uid); $acyuid = $this->addAcyUser ($name, $email, $uid);
} }
$allsubscriptions = $this->getUserSubscriptions($acyuid); $allsubscriptions = $this->getUserSubscriptions ($acyuid);
$notsubscribed = array_diff ($field->lists, $allsubscriptions); $notsubscribed = array_diff ($field->lists, $allsubscriptions);
$this->subscribeUser($acyuid, $notsubscribed); $this->subscribeUser($acyuid, $notsubscribed);
foreach ($notsubscribed as $l) { // TODO: Shall we display an infor message about the subscription?
$listname=$this->getAcyListname($l); // foreach ($notsubscribed as $l) {
JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_ACYBUYER_ADDED_USER', $name, $email, $listname), 'info'); // $listname=$this->getAcyListname($l);
} // JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_ACYBUYER_ADDED_USER', $name, $email, $listname), 'info');
// }
} }
} }
// TODO: If auto-subscribe
JFactory::getApplication()->enqueueMessage("plgVmConfirmedOrder, cart: <pre>".print_r($cart,1)."</pre><br><h2>ORDER:</h2><pre>".print_r($order,1)."</pre>", 'error');
} }
} }
......
...@@ -15,16 +15,11 @@ ...@@ -15,16 +15,11 @@
</files> </files>
<languages> <languages>
<language tag="en-GB">en-GB.plg_vmcustom_acy_subscribe_buyer.ini</language> <language tag="en-GB">en-GB.plg_vmcustom_acy_subscribe_buyer.ini</language>
<language tag="de-DE">de-DE.plg_vmcustom_acy_subscribe_buyer.ini</language>
<language tag="en-GB">en-GB.plg_vmcustom_acy_subscribe_buyer.sys.ini</language>
<language tag="de-DE">de-DE.plg_vmcustom_acy_subscribe_buyer.sys.ini</language>
</languages> </languages>
<scriptfile>acy_subscribe_buyer.script.php</scriptfile> <scriptfile>acy_subscribe_buyer.script.php</scriptfile>
<params addpath="/administrator/components/com_virtuemart/elements"> <params addpath="/administrator/components/com_virtuemart/elements">
<param name="auto_subscribe" type="radio" default="1" label="VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE" description="VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE_DESC" >
<option value="0">COM_VIRTUEMART_NO</option>
<option value="1">COM_VIRTUEMART_YES</option>
</param>
<param name="allow_registered_subscribe" type="radio" default="1" label="VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE" description="VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE_DESC" >
<option value="0">COM_VIRTUEMART_NO</option>
<option value="1">COM_VIRTUEMART_YES</option>
</param>
</params> </params>
</install> </install>
...@@ -9,6 +9,13 @@ ...@@ -9,6 +9,13 @@
* *
**/ **/
// Data passed to this template (as $viewData array):
// $viewData[0] ... acy mailing form name
// $viewData[1] ... user info (id, mail, name, subscribed, notsubscribed), typically extracted from the registered user
// $viewData[2] ... list ids for this product
// $viewData[3] ... Redirect URL
// $viewData[4] ... the whole custom field
defined('_JEXEC') or die(); defined('_JEXEC') or die();
if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.DS.'assets'.DS.'acy_subscribe_buyer.css')) { if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.DS.'assets'.DS.'acy_subscribe_buyer.css')) {
$doc =& JFactory::getDocument(); $doc =& JFactory::getDocument();
...@@ -16,5 +23,28 @@ if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'. ...@@ -16,5 +23,28 @@ if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.
} }
?> ?>
<div class="acy_subscribe_buyer"> <div class="acy_subscribe_buyer">
<div style="background: #00FF00;">Subscribe user <?php echo $viewData[1]; ?> to: <?php print_r($viewData[0]); ?></div> <form name="<?php echo $viewData[0]?>" method="post" onsubmit="return submitacymailingform('optin','<?php echo $viewData[0]?>')" action="<?php echo JRoute::_('index.php'); ?>" id="<?php echo $viewData[0]?>">
<?php if (empty($viewData[1]['name']) && empty($viewData[1]['email'])) { ?>
<input type="text" value="Your Name" name="user[name]" id="user_name_<?php echo $viewData[0]?>">
<input type="text" value="email@example.com" name="user[email]" id="user_email_<?php echo $viewData[0]?>">
<?php } else { ?>
<input type="hidden" value="<?php echo $viewData[1]['name'];?>" name="user[name]" id="user_name_<?php echo $viewData[0]?>">
<input type="hidden" value="<?php echo $viewData[1]['email'];?>" name="user[email]" id="user_email_<?php echo $viewData[0]?>">
<?php } ?>
<input type="hidden" value="0" name="ajax">
<input type="hidden" value="sub" name="ctrl">
<input type="hidden" value="notask" name="task">
<input type="hidden" value="<?php echo $viewData[3];?>" name="redirect">
<input type="hidden" value="<?php echo $viewData[3];?>" name="redirectunsub">
<input type="hidden" value="com_acymailing" name="option">
<input type="hidden" value="" name="visiblelists">
<input type="hidden" value="<?php echo implode (',', $viewData[2]); ?>" name="hiddenlists">
<input type="hidden" value="<?php echo $viewData[0]?>" name="acyformname">
<?php if (!isset($viewData[1]['notsubscribed']) or !empty($viewData[1]['notsubscribed'])) { ?>
<input type="submit" onclick="try{ return submitacymailingform('optin','<?php echo $viewData[0]?>'); }catch(err){alert('The form could not be submitted '+err);return false;}" name="Submit" value="Subscribe" class="button subbutton btn btn-primary">
<?php }
if (!isset($viewData[1]['subscribed']) or !empty($viewData[1]['subscribed'])) { ?>
<input type="button" onclick="return submitacymailingform('optout','<?php echo $viewData[0]?>')" name="Submit" value="Unsubscribe" class="button unsubbutton btn btn-inverse">
<?php } ?>
</form>
</div> </div>
\ No newline at end of file
<?php
/**
*
* @author Reinhold Kainhofer
* @package VirtueMart
* @subpackage custom
* @copyright Copyright (C) 2013 RK - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*
**/
defined('_JEXEC') or die();
if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.DS.'assets'.DS.'acy_subscribe_buyer.css')) {
$doc =& JFactory::getDocument();
$doc->addStyleSheet(JURI::root().'plugins/vmcustom/acy_subscribe_buyer/assets/acy_subscribe_buyer.css');
}
?>
<div class="acy_subscribe_buyer">
<div style="background: #00FF00;">Subscribing anonymous to: <?php print_r($viewData[0]); ?></div>
</div>
\ No newline at end of file
<?php
/**
*
* @author Reinhold Kainhofer
* @package VirtueMart
* @subpackage custom
* @copyright Copyright (C) 2013 RK - All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL, see LICENSE.php
*
**/
defined('_JEXEC') or die();
if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.DS.'assets'.DS.'acy_subscribe_buyer.css')) {
$doc =& JFactory::getDocument();
$doc->addStyleSheet(JURI::root().'plugins/vmcustom/acy_subscribe_buyer/assets/acy_subscribe_buyer.css');
}
?>
<div class="acy_subscribe_buyer">
<div style="background: red">Unsubscribe user <?php echo $viewData[1]; ?> from: <?php print_r($viewData[0]); ?></div>
</div>
\ No newline at end of file
; Virtuemart! Project
; Copyright (C) 2011 Virtuemart Team. All rights reserved.
; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM
VMCUSTOM_ACYBUYER="VM Käufer zu AcyMailing Listen hinzufügen"
VMCUSTOM_ACYBUYER_DESC="VirtueMart Benutzerfeld-Plugin, um Käufer automatisch zu AcyMailing Listen hinzuzufügen, bzw. die manuelle Bestellung/Abbestellung von Newslettern auf der Produkseite zu ermöglichen."
VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE="Käufer automatisch eintragen"
VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE_DESC="Trägt jeden Käufer des Produkts automatisch nach Abschluss der Bestellung in die Mailingliste ein."
VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE="Manuelle Eintragung erlauben"
VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE_DESC="Zeigt auf der Produktseite die Möglichkeit, die AcyMailing Listen des jeweiligen Produktes zu abonnieren oder abzubestellen. Für registrierte Benutzer wird dabei die Mail-Adresse des Joomla Kontos benutzt, anonyme Benutzer können die Adresse eingeben."
VMCUSTOM_ACYBUYER_NO_LISTS="Es sind keine AcyMailing Listen verfügbar"
VMCUSTOM_ACYBUYER_LIST="AcyMailing Listen:"
VMCUSTOM_ACYBUYER_ADDED_USER="Benutzer '%s' (%s) zur Liste '%s' hinzugefügt."
VMCUSTOM_ACYBUYER_SQL_ERROR="SQL Fehler! Bitte <a href='mailto:reinhold@kainhofer.com'>kontaktieren Sie den Autor</a> und geben Sie folgende Fehlermeldung an:<br/>%s"
\ No newline at end of file
; Virtuemart! Project
; Copyright (C) 2011 Virtuemart Team. All rights reserved.
; License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
; Note : All ini files need to be saved as UTF-8 - No BOM
VMCUSTOM_ACYBUYER="VM Käufer zu AcyMailing Listen hinzufügen"
VMCUSTOM_ACYBUYER_DESC="VirtueMart Benutzerfeld-Plugin, um Käufer automatisch zu AcyMailing Listen hinzuzufügen, bzw. die manuelle Bestellung/Abbestellung von Newslettern auf der Produkseite zu ermöglichen."
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
VMCUSTOM_ACYBUYER="VM Subscribe Buyers to AcyMailing" VMCUSTOM_ACYBUYER="VM Subscribe Buyers to AcyMailing"
VMCUSTOM_ACYBUYER_DESC="VirtueMart custom field plugin to automatically subscribe buyers to AcyMailing lists." VMCUSTOM_ACYBUYER_DESC="VirtueMart custom field plugin to automatically subscribe buyers to AcyMailing lists."
VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE
VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE="Auto-subscribe buyers" VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE="Auto-subscribe buyers"
VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE_DESC="Automatically add users to the mailing list after a successful purchase." VMCUSTOM_ACYBUYER_AUTO_SUBSCRIBE_DESC="Automatically add users to the mailing list after a successful purchase."
VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE="Allow manual subscription" VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE="Allow manual subscription"
...@@ -16,4 +15,4 @@ VMCUSTOM_ACYBUYER_NO_LISTS="No AcyMailing lists are available" ...@@ -16,4 +15,4 @@ VMCUSTOM_ACYBUYER_NO_LISTS="No AcyMailing lists are available"
VMCUSTOM_ACYBUYER_LIST="AcyMailing lists:" VMCUSTOM_ACYBUYER_LIST="AcyMailing lists:"
VMCUSTOM_ACYBUYER_ADDED_USER="User '%s' (%s) added to mailing list %s." VMCUSTOM_ACYBUYER_ADDED_USER="User '%s' (%s) added to mailing list %s."
VMCUSTOM_ACYBUYER_SQL_ERROR="SQL error, please contact the author with the following information:<br/>%s" VMCUSTOM_ACYBUYER_SQL_ERROR="SQL error, please <a href='mailto:reinhold@kainhofer.com'>contact the author</a> with the following information:<br/>%s"
\ No newline at end of file \ No newline at end of file
File added
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment