diff --git a/Makefile b/Makefile index 729711b97309dc7f137d60dc1f9f4fea6e401265..42aa07cabe3bca5400d30159b898ca614053f692 100644 --- a/Makefile +++ b/Makefile @@ -1,13 +1,14 @@ -BASE=downloads_for_sale +BASE=acy_subscribe_buyer PLUGINTYPE=vmcustom -VERSION=1.1 +VERSION=1.0 PLUGINFILES=$(BASE).php $(BASE).script.php $(BASE).xml index.html TRANSLATIONS=$(call wildcard,*.plg_$(PLUGINTYPE)_$(BASE).*ini) INDEXFILES=$(BASE)/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 diff --git a/acy_subscribe_buyer.php b/acy_subscribe_buyer.php index 6b6859cd5d21aa1f94172181acee7175f8d25991..493ccab1da9da4722e8a22640f695e86ff505a98 100644 --- a/acy_subscribe_buyer.php +++ b/acy_subscribe_buyer.php @@ -15,6 +15,10 @@ defined('_JEXEC') or die( 'Direct Access to ' . basename( __FILE__ ) . ' is not * http://kainhofer.com */ 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 { @@ -67,7 +71,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { function getUserSubscriptions ($uid) { if (!($uid>0)) return array(); $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); $subscribed = $db->loadColumn(); return $subscribed; @@ -79,7 +83,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { $q = "SELECT `id`, `name`, `email` FROM `#__users` WHERE `id`=".(int)$uid; $db->setQuery($q); $userinfo = $db->loadObject(); -// print("<pre>addAcyUser ($name, $email, $uid): loaded user data <br>(SQL: $q) <br/>".print_r($userinfo,1)."</pre>"); if (empty($email)) $email = $userinfo->email; if (empty($name)) @@ -97,7 +100,7 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { } 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) { $db = &JFactory::getDBO(); foreach ($lists as $l) { @@ -109,10 +112,6 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { $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 @@ -144,29 +143,40 @@ class plgVmCustomAcy_subscribe_Buyer extends vmCustomPlugin { 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) { -$this->addAcyUser("Reinhold Kainhofer", "reinhold@kainhofer.com" , 673); $html = ''; $this->parseCustomParams($field); - $user = JFactory::getUser()->get('id'); - if ($user>0) { - $acyuid = $this->getAcyUidFromUser($user); + $user = JFactory::getUser(); + $uid = $user->get('id'); + if ($uid>0) { + $acyuid = $this->getAcyUidFromUser($uid); $allsubscriptions = $this->getUserSubscriptions($acyuid); - $subscribed = array_intersect ($field->lists, $allsubscriptions); - $notsubscribed = array_diff ($field->lists, $allsubscriptions); - if (!empty($notsubscribed)) { - $html .= $this->renderByLayout('button_subscribe', array($notsubscribed, $user, $field)); - // TODO: implement subscribe button - } - if (!empty($subscribed)) { - // TODO: implement unsubscribe button - $html .= $this->renderByLayout('button_unsubscribe', array($subscribed, $user, $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>"; + $uinfo = array( + 'id' => $uid, + 'name' => $user->get('name'), + 'email' => $user->get('email'), + 'subscribed' => array_intersect ($field->lists, $allsubscriptions), + 'notsubscribed' => array_diff ($field->lists, $allsubscriptions), + ); + $this->addAcyStuff(); + $html .= $this->renderByLayout('button_subscribe', array(acymailing_getModuleFormName(), $uinfo, $field->lists, $this->getThisURL(), $field)); } elseif ($field->allow_subscribe) { - $html .= $this->renderByLayout('button_subscribe_anon', array($field->lists, $field)); - // TODO: Display anonymous subscribe button - $html = "<pre>NO USER, SUBSCRIBE allowed</pre>"; + $this->addAcyStuff(); + $html .= $this->renderByLayout('button_subscribe', array(acymailing_getModuleFormName(), array(), $field->lists, $this->getThisURL(), $field)); } else { // Not logged in, manual subscription not allowed } @@ -245,25 +255,23 @@ $this->addAcyUser("Reinhold Kainhofer", "reinhold@kainhofer.com" , 673); $customModel = VmModel::getModel('customfields'); foreach ($order['items'] as $item) { $customs = $customModel->getproductCustomslist ($item->virtuemart_product_id); -JFactory::getApplication()->enqueueMessage("<pre>Custom fields: ".print_r($customs,1)."</pre>", 'error'); foreach ($customs as $field) { if ($field->custom_element != $this->_name) continue; if (!$field->subscribe_buyers) continue; // Add the user to the lists: 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); $this->subscribeUser($acyuid, $notsubscribed); - foreach ($notsubscribed as $l) { - $listname=$this->getAcyListname($l); - JFactory::getApplication()->enqueueMessage(JText::sprintf('VMCUSTOM_ACYBUYER_ADDED_USER', $name, $email, $listname), 'info'); - } + // TODO: Shall we display an infor message about the subscription? + // foreach ($notsubscribed as $l) { + // $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'); } } diff --git a/acy_subscribe_buyer.xml b/acy_subscribe_buyer.xml index e8df6c9da7cac786369055ba849d814c19eeacf7..7597a465ccbfc4e1c45ad176e91f0ee8bfb38120 100644 --- a/acy_subscribe_buyer.xml +++ b/acy_subscribe_buyer.xml @@ -15,16 +15,11 @@ </files> <languages> <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> <scriptfile>acy_subscribe_buyer.script.php</scriptfile> <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> </install> diff --git a/acy_subscribe_buyer/tmpl/button_subscribe.php b/acy_subscribe_buyer/tmpl/button_subscribe.php index 0b4c40e6abfea2d9bcaa22db1dd4f7bc649fcff3..72bee4b18fa311b96f3f5de479891b81035d1141 100644 --- a/acy_subscribe_buyer/tmpl/button_subscribe.php +++ b/acy_subscribe_buyer/tmpl/button_subscribe.php @@ -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(); if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'acy_subscribe_buyer'.DS.'assets'.DS.'acy_subscribe_buyer.css')) { $doc =& JFactory::getDocument(); @@ -16,5 +23,28 @@ if(JFile::exists(JPATH_SITE.DS.'plugins'.DS.'vmcustom'.DS.'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> \ No newline at end of file diff --git a/acy_subscribe_buyer/tmpl/button_subscribe_anon.php b/acy_subscribe_buyer/tmpl/button_subscribe_anon.php deleted file mode 100644 index 90fd0f89a4d31b528c672256566b6a458c6897e8..0000000000000000000000000000000000000000 --- a/acy_subscribe_buyer/tmpl/button_subscribe_anon.php +++ /dev/null @@ -1,20 +0,0 @@ -<?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 diff --git a/acy_subscribe_buyer/tmpl/button_unsubscribe.php b/acy_subscribe_buyer/tmpl/button_unsubscribe.php deleted file mode 100644 index bf1370e932feaf914eabfd70aac8695723c76648..0000000000000000000000000000000000000000 --- a/acy_subscribe_buyer/tmpl/button_unsubscribe.php +++ /dev/null @@ -1,20 +0,0 @@ -<?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 diff --git a/de-DE.plg_vmcustom_acy_subscribe_buyer.ini b/de-DE.plg_vmcustom_acy_subscribe_buyer.ini new file mode 100644 index 0000000000000000000000000000000000000000..362b07ad9816a1ce76b13f3b2e0e75143a11bfb7 --- /dev/null +++ b/de-DE.plg_vmcustom_acy_subscribe_buyer.ini @@ -0,0 +1,18 @@ +; 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 diff --git a/de-DE.plg_vmcustom_acy_subscribe_buyer.sys.ini b/de-DE.plg_vmcustom_acy_subscribe_buyer.sys.ini new file mode 100644 index 0000000000000000000000000000000000000000..ee2b586607a179cf71f9a8db752630eabe93881d --- /dev/null +++ b/de-DE.plg_vmcustom_acy_subscribe_buyer.sys.ini @@ -0,0 +1,7 @@ +; 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." diff --git a/en-GB.plg_vmcustom_acy_subscribe_buyer.ini b/en-GB.plg_vmcustom_acy_subscribe_buyer.ini index c5d85a32b29c1b4e3f5403cb8826b257375ad41d..f640671ec5ae2c0a97dc25aa016e5c8b7aae5478 100644 --- a/en-GB.plg_vmcustom_acy_subscribe_buyer.ini +++ b/en-GB.plg_vmcustom_acy_subscribe_buyer.ini @@ -6,7 +6,6 @@ VMCUSTOM_ACYBUYER="VM Subscribe Buyers to AcyMailing" 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_DESC="Automatically add users to the mailing list after a successful purchase." VMCUSTOM_ACYBUYER_ALLOW_SUBSCRIBE="Allow manual subscription" @@ -16,4 +15,4 @@ VMCUSTOM_ACYBUYER_NO_LISTS="No AcyMailing lists are available" VMCUSTOM_ACYBUYER_LIST="AcyMailing lists:" 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" \ No newline at end of file +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 diff --git a/releases/plg_vmcustom_acy_subscribe_buyer_v1.0.zip b/releases/plg_vmcustom_acy_subscribe_buyer_v1.0.zip new file mode 100644 index 0000000000000000000000000000000000000000..eacb7ee7c7a86ec072b575b47a2de18f60bf1336 Binary files /dev/null and b/releases/plg_vmcustom_acy_subscribe_buyer_v1.0.zip differ