示例#1
0
function wikiplugin_datachannel($data, $params)
{
    static $execution = 0;
    global $prefs, $smarty;
    $executionId = 'datachannel-exec-' . ++$execution;
    $fields = array();
    $lines = explode("\n", $data);
    $lines = array_map('trim', $lines);
    $lines = array_filter($lines);
    foreach ($lines as $line) {
        $parts = explode(',', $line, 2);
        if (count($parts) == 2) {
            $fields[$parts[0]] = $parts[1];
        }
    }
    require_once 'lib/profilelib/profilelib.php';
    require_once 'lib/profilelib/channellib.php';
    require_once 'lib/profilelib/installlib.php';
    $groups = Perms::get()->getGroups();
    $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']);
    if ($config->canExecuteChannels(array($params['channel']), $groups)) {
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId) {
            $input = array_intersect_key($_POST, $fields);
            $static = $params;
            unset($static['channel']);
            $userInput = array_merge($input, $static);
            Tiki_Profile::useUnicityPrefix(uniqid());
            $installer = new Tiki_Profile_Installer();
            $installer->limitGlobalPreferences(array());
            $profiles = $config->getProfiles(array($params['channel']));
            $profile = reset($profiles);
            $installer->setUserData($userInput);
            $installer->install($profile);
            header('Location: ' . $_SERVER['REQUEST_URI']);
        } else {
            $smarty->assign('datachannel_fields', $fields);
            $smarty->assign('datachannel_execution', $executionId);
            return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~';
        }
    }
}
示例#2
0
					'tiki-channel.php',
					tra('One of the requested channels cannot be requested. It does not exist or permission is denied.')
	);
}

$profiles = $config->getProfiles($channels);

if ( count($profiles) != count($channels) ) {
	$access->display_error('tiki-channel.php', tra('One of the install profiles could not be obtained.'));
}

Tiki_Profile::useUnicityPrefix(uniqid());
$installer = new Tiki_Profile_Installer;
$installer->limitGlobalPreferences(array());

foreach ( $calls as $call ) {
	list($channel, $userInput) = $call;

	// Profile can be installed multiple times
	// Only last values preserved
	$profile = $profiles[$channel];
	$installer->forget($profile);

	$installer->setUserData($userInput);
	$installer->install($profile);
}

if ( isset($_REQUEST['return_uri']) ) {
	header("Location: {$_REQUEST['return_uri']}");
}
function wikiplugin_datachannel($data, $params)
{
    static $execution = 0;
    global $prefs, $smarty, $headerlib;
    $executionId = 'datachannel-exec-' . ++$execution;
    if (isset($params['price']) && $params['price'] == 0) {
        // Convert things like 0.00 to empty
        unset($params['price']);
    }
    $fields = array();
    $inputfields = array();
    $lines = explode("\n", $data);
    $lines = array_map('trim', $lines);
    $lines = array_filter($lines);
    $js = '';
    if (!isset($params['array_values'])) {
        $params['array_values'] = 'n';
    }
    foreach ($lines as $line) {
        $parts = explode(',', $line, 2);
        $parts = array_map('trim', $parts);
        if (count($parts) == 2) {
            if (strpos($parts[1], 'external') === 0) {
                // e.g. "fieldid,external=fieldname"
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                if (count($moreparts) < 2) {
                    $moreparts[1] = $parts[0];
                    // no fieldname supplied so use same as fieldid
                }
                $fields[$parts[0]] = $moreparts[0];
                if ($params['array_values'] === 'y' && preg_match('/[\\[\\]\\.#\\=]/', $moreparts[1])) {
                    // check for [ ] = or . which would be a jQuery selector
                    // might select multiple inputs
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("' . $moreparts[1] . '").serialize()));';
                } else {
                    // otherwise it's an id
                    $js .= "\n" . '$("input[name=\'' . $parts[0] . '\']").val( unescape($("#' . $moreparts[1] . '").val()));';
                }
                $inputfields[$parts[0]] = 'external';
            } elseif (strpos($parts[1], 'hidden') === 0) {
                $moreparts = explode('=', $parts[1], 2);
                $moreparts = array_map('trim', $moreparts);
                $fields[$parts[0]] = $moreparts[1];
                $inputfields[$parts[0]] = 'hidden';
            } else {
                $fields[$parts[0]] = $parts[1];
                $inputfields[$parts[0]] = $parts[1];
            }
        }
    }
    $groups = Perms::get()->getGroups();
    $config = Tiki_Profile_ChannelList::fromConfiguration($prefs['profile_channels']);
    if ($config->canExecuteChannels(array($params['channel']), $groups, true)) {
        $smarty->assign('datachannel_execution', $executionId);
        if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['datachannel_execution']) && $_POST['datachannel_execution'] == $executionId && $config->canExecuteChannels(array($params['channel']), $groups)) {
            $input = array_intersect_key(array_map('trim', $_POST), $inputfields);
            $itemIds = array();
            // process possible arrays in post
            if ($params['array_values'] === 'y') {
                foreach ($input as $key => $val) {
                    if (!empty($val)) {
                        parse_str($val, $vals);
                        if (is_array($vals)) {
                            // serialized collection of inputs
                            $arr = array();
                            if ($key == 'itemId') {
                                foreach ($vals as $v) {
                                    // itemId[x,y,z]
                                    if (is_array($v)) {
                                        $arr = array_merge($arr, $v);
                                    }
                                }
                                $itemIds = $arr;
                            } else {
                                foreach ($vals as $v) {
                                    // fieldname[x=>a,y=>b,z=>c]
                                    if (is_array($v)) {
                                        foreach ($v as $k => $kv) {
                                            if (in_array($k, $itemIds)) {
                                                // check if sent in itemIds array
                                                $arr[] = $kv;
                                                // (e.g. from trackerlist checkboxes)
                                            }
                                        }
                                    } else {
                                        $arr = $val;
                                        // not an array, so use the initial string val
                                    }
                                }
                            }
                            $input[$key] = $arr;
                        }
                    }
                }
            }
            $inputs = array();
            if ($params['array_values'] === 'y' && !empty($itemIds)) {
                $cid = count($itemIds);
                for ($i = 0; $i < $cid; $i++) {
                    // reorganise array
                    $arr = array();
                    foreach (array_keys($input) as $k) {
                        if (isset($input[$k]) && is_array($input[$k])) {
                            $arr[$k] = $input[$k][$i];
                        } else {
                            $arr[$k] = $input[$k];
                        }
                    }
                    $inputs[] = $arr;
                }
            } else {
                $inputs[] = $input;
            }
            $static = $params;
            $unsets = wikiplugin_datachannel_info();
            // get defined params
            $unsets = array_keys($unsets['params']);
            foreach ($unsets as $un) {
                // remove defined params leaving user supplied ones
                unset($static[$un]);
            }
            if (!empty($params['price'])) {
                global $paymentlib;
                require_once 'lib/payment/paymentlib.php';
                $desc = empty($params['paymentlabel']) ? tr('Datachannel:', $prefs['site_language']) . ' ' . $params['channel'] : $params['paymentlabel'];
                $posts = array();
                foreach ($input as $key => $post) {
                    $posts[$key] = $post;
                    $desc .= '/' . $post;
                }
                $id = $paymentlib->request_payment($desc, $params['price'], $prefs['payment_default_delay']);
                $paymentlib->register_behavior($id, 'complete', 'execute_datachannel', array($data, $params, $posts, $executionId));
                require_once 'lib/smarty_tiki/function.payment.php';
                return '^~np~' . smarty_function_payment(array('id' => $id), $smarty) . '~/np~^';
            }
            foreach ($inputs as $input) {
                $userInput = array_merge($input, $static);
                Tiki_Profile::useUnicityPrefix(uniqid());
                $profiles = $config->getProfiles(array($params['channel']));
                $profile = reset($profiles);
                $profile->removeSymbols();
                Tiki_Profile::useUnicityPrefix(uniqid());
                $installer = new Tiki_Profile_Installer();
                //TODO: What is the following line for? Future feature to limit capabilities of data channels?
                //$installer->limitGlobalPreferences( array() );
                // jb tiki6: looks like if set to an empty array it would prevent any prefs being set
                // i guess the idea is to be able to restrict the settable prefs to only harmless ones for security
                $installer->setUserData($userInput);
                if (!empty($params['debug']) && $params['debug'] === 'y') {
                    $installer->setDebug();
                }
                $params['emptyCache'] = isset($params['emptyCache']) ? $params['emptyCache'] : 'all';
                $installer->install($profile, $params['emptyCache']);
            }
            if (empty($params['returnURI'])) {
                $params['returnURI'] = $_SERVER['HTTP_REFERER'];
            }
            // default to return to same page
            if (empty($params['debug']) || $params['debug'] != 'y') {
                if (isset($params['quietReturn']) && $params['quietReturn'] == 'y') {
                    return true;
                } else {
                    header('Location: ' . $params['returnURI']);
                }
                die;
            }
            $smarty->assign('datachannel_feedbacks', array_merge($installer->getFeedback(), $profile->getFeedback()));
        }
        $smarty->assign('datachannel_inputfields', $inputfields);
        $smarty->assign('datachannel_fields', $fields);
        $smarty->assign('button_label', !empty($params['buttonLabel']) ? $params['buttonLabel'] : 'Go');
        $smarty->assign('form_class_attr', !empty($params['class']) ? ' class="' . $params['class'] . '"' : '');
        if (!empty($js)) {
            $headerlib->add_js("function datachannel_form_submit{$execution}() {{$js}\nreturn true;\n}");
            $smarty->assign('datachannel_form_onsubmit', ' onsubmit="return datachannel_form_submit' . $execution . '();"');
        } else {
            $smarty->assign('datachannel_form_onsubmit', '');
        }
        return '~np~' . $smarty->fetch('wiki-plugins/wikiplugin_datachannel.tpl') . '~/np~';
    }
}
示例#4
0
         if (count($profilefeedback) > 0) {
             $smarty->assign_by_ref('profilefeedback', $profilefeedback);
         }
         // need to reload sources as cache is cleared after install
         $sources = $list->getSources();
     }
 }
 if (isset($_POST['install'], $_POST['pd'], $_POST['pp'])) {
     $data = array();
     foreach ($_POST as $key => $value) {
         if ($key != 'url' && $key != 'install') {
             $data[str_replace('_', ' ', $key)] = $value;
         }
     }
     $installer = new Tiki_Profile_Installer();
     $installer->setUserData($data);
     $profile = Tiki_Profile::fromNames($_POST['pd'], $_POST['pp']);
     $installer->install($profile);
     if ($profile != null && ($target = $profile->getInstructionPage())) {
         $wikilib = TikiLib::lib('wiki');
         $target = $wikilib->sefurl($target);
         header('Location: ' . $target);
         exit;
     } else {
         $profilefeedback = $installer->getFeedback();
         if (count($profilefeedback) > 0) {
             $smarty->assign_by_ref('profilefeedback', $profilefeedback);
         }
         // need to reload sources as cache is cleared after install
         $sources = $list->getSources();
     }
示例#5
0
文件: cartlib.php 项目: rjsmelo/tiki
 function request_payment()
 {
     global $prefs, $user;
     $tikilib = TikiLib::lib('tiki');
     $paymentlib = TikiLib::lib('payment');
     $total = $this->get_total();
     if ($total > 0 || $this->total_no_discount) {
         // if anonymous shopping to set pref as to which shopperinfo to show in description
         if (empty($user) && $prefs['payment_cart_anonymous'] === 'y') {
             $shopperinfo_descvar = 'email';
             // TODO: make this a pref
             if (!empty($_SESSION['shopperinfo'][$shopperinfo_descvar])) {
                 $shopperinfo_desc = $_SESSION['shopperinfo'][$shopperinfo_descvar];
                 $description = tra($prefs['payment_cart_heading']) . " ({$shopperinfo_desc})";
             } else {
                 $description = tra($prefs['payment_cart_heading']);
             }
         } else {
             $description = tra($prefs['payment_cart_heading']) . " ({$user})";
         }
         $invoice = $paymentlib->request_payment($description, $total, $prefs['payment_default_delay'], $this->get_description());
         foreach ($this->get_behaviors() as $behavior) {
             $paymentlib->register_behavior($invoice, $behavior['event'], $behavior['behavior'], $behavior['arguments']);
         }
     } else {
         $invoice = 0;
         foreach ($this->get_behaviors() as $behavior) {
             if ($behavior['event'] == 'complete') {
                 $name = $behavior['behavior'];
                 $file = dirname(__FILE__) . "/behavior/{$name}.php";
                 $function = 'payment_behavior_' . $name;
                 require_once $file;
                 call_user_func_array($function, $behavior['arguments']);
             }
         }
     }
     // Handle anonymous user (not logged in) shopping that require only email
     if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') {
         if (!empty($_SESSION['shopperinfo'])) {
             // should also check for pref that this anonymous shopping feature is on
             // First create shopper info in shopper tracker
             global $record_profile_items_created;
             $record_profile_items_created = array();
             if (!empty($_SESSION['shopperinfoprofile'])) {
                 $shopper_profile_name = $_SESSION['shopperinfoprofile'];
             } else {
                 $shopper_profile_name = $prefs['payment_cart_anonshopper_profile'];
             }
             $shopperprofile = Tiki_Profile::fromDb($shopper_profile_name);
             $profileinstaller = new Tiki_Profile_Installer();
             $profileinstaller->forget($shopperprofile);
             // profile can be installed multiple times
             $profileinstaller->setUserData($_SESSION['shopperinfo']);
             $profileinstaller->install($shopperprofile);
             // Then set user to shopper ID
             $cartuser = $record_profile_items_created[0];
             $record_profile_items_created = array();
         } else {
             $this->empty_cart();
             return $invoice;
         }
     } else {
         $cartuser = $user;
     }
     $userInput = array('user' => $cartuser, 'time' => $tikilib->now, 'total' => $total, 'invoice' => $invoice, 'weight' => $this->get_total_weight());
     if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') {
         $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorders_profile']);
         $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_anonorderitems_profile']);
     } else {
         $orderprofile = Tiki_Profile::fromDb($prefs['payment_cart_orders_profile']);
         $orderitemprofile = Tiki_Profile::fromDb($prefs['payment_cart_orderitems_profile']);
     }
     if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') {
         if (!$orderprofile) {
             TikiLib::lib('errorreport')->report(tra('Advanced Shopping Cart setup error: Orders profile missing.'));
             return false;
         }
         $profileinstaller = new Tiki_Profile_Installer();
         $profileinstaller->forget($orderprofile);
         // profile can be installed multiple times
         $profileinstaller->setUserData($userInput);
     } else {
         $profileinstaller = '';
     }
     global $record_profile_items_created;
     $record_profile_items_created = array();
     if ($user && $prefs['payment_cart_orders'] == 'y' || !$user && $prefs['payment_cart_anonymous'] == 'y') {
         $profileinstaller->install($orderprofile, 'none');
     }
     $content = $this->get_content();
     foreach ($content as $info) {
         if (!isset($info['is_gift_certificate']) || !$info['is_gift_certificate']) {
             $process_info = $this->process_item($invoice, $total, $info, $userInput, $cartuser, $profileinstaller, $orderitemprofile);
         }
     }
     $email_template_ids = array();
     if (isset($process_info['product_classes']) && is_array($process_info['product_classes'])) {
         $product_classes = array_unique($process_info['product_classes']);
     } else {
         $product_classes = array();
     }
     foreach ($product_classes as $pc) {
         if ($email_template_id = $this->get_tracker_value_custom($prefs['payment_cart_productclasses_tracker_name'], 'Email Template ID', $pc)) {
             $email_template_ids[] = $email_template_id;
         }
     }
     if (!empty($record_profile_items_created)) {
         if ($total > 0) {
             $paymentlib->register_behavior($invoice, 'complete', 'record_cart_order', array($record_profile_items_created));
             $paymentlib->register_behavior($invoice, 'cancel', 'cancel_cart_order', array($record_profile_items_created));
             if ($user) {
                 $paymentlib->register_behavior($invoice, 'complete', 'cart_send_confirm_email', array($user, $email_template_ids));
             }
         } else {
             require_once 'lib/payment/behavior/record_cart_order.php';
             payment_behavior_record_cart_order($record_profile_items_created);
             if ($user) {
                 require_once 'lib/payment/behavior/cart_send_confirm_email.php';
                 payment_behavior_cart_send_confirm_email($user, $email_template_ids);
             }
         }
     }
     if (!$user || isset($_SESSION['forceanon']) && $_SESSION['forceanon'] == 'y') {
         $shopperurl = 'tiki-index.php?page=' . $prefs['payment_cart_anon_reviewpage'] . '&shopper=' . intval($cartuser);
         global $tikiroot, $prefs;
         $shopperurl = $tikilib->httpPrefix(true) . $tikiroot . $shopperurl;
         require_once 'lib/auth/tokens.php';
         $tokenlib = AuthTokens::build($prefs);
         $shopperurl = $tokenlib->includeToken($shopperurl, array($prefs['payment_cart_anon_group'], 'Anonymous'));
         if (!empty($_SESSION['shopperinfo']['email'])) {
             require_once 'lib/webmail/tikimaillib.php';
             $smarty = TikiLib::lib('smarty');
             $smarty->assign('shopperurl', $shopperurl);
             $smarty->assign('email_template_ids', $email_template_ids);
             $mail_subject = $smarty->fetch('mail/cart_order_received_anon_subject.tpl');
             $mail_data = $smarty->fetch('mail/cart_order_received_anon.tpl');
             $mail = new TikiMail();
             $mail->setSubject($mail_subject);
             if ($mail_data == strip_tags($mail_data)) {
                 $mail->setText($mail_data);
             } else {
                 $mail->setHtml($mail_data);
             }
             $mail->send($_SESSION['shopperinfo']['email']);
             // the field to use probably needs to be configurable as well
         }
     }
     $this->update_gift_certificate($invoice);
     $this->update_group_discount($invoice);
     $this->empty_cart();
     return $invoice;
 }
示例#6
0
 function applyTemplate(array $template, array $data)
 {
     $profile = Tiki_Profile::fromString($template['definition'], uniqid());
     $installer = new Tiki_Profile_Installer();
     $installer->setUserData($data);
     $value = $installer->install($profile);
     if (!$value) {
         throw new Services_Exception('Profile could not be installed.');
     }
 }