function wikiplugin_relations($data, $params) { $object = current_object(); if (isset($params['object']) && false !== strpos($params['object'], ':')) { list($object['type'], $object['object']) = explode(':', $params['object'], 2); } if (!isset($params['qualifiers'])) { return WikiParser_PluginOutput::argumentError(array('qualifiers')); } $singlelist = false; if (isset($params['singlelist']) && $params['singlelist']) { $singlelist = true; } $emptymsg = "No relations found."; if (isset($params['emptymsg']) && $params['emptymsg']) { $emptymsg = $params['emptymsg']; } $data = array(); $relationlib = TikiLib::lib('relation'); foreach ($params['qualifiers'] as $qualifier) { $name = $singlelist ? 'singlelist' : tra($qualifier); $found = $relationlib->get_relations_from($object['type'], $object['object'], $qualifier); foreach ($found as $relation) { $type = $relation['type']; $id = $relation['itemId']; $data[$name]["{$type}:{$id}"] = array('type' => $type, 'object' => $id); } } $smarty = TikiLib::lib('smarty'); $smarty->assign('wp_relations', $data); $smarty->assign('wp_singlelist', $singlelist); $smarty->assign('wp_emptymsg', $emptymsg); return $smarty->fetch('wiki-plugins/wikiplugin_relations.tpl'); }
function wikiplugin_zoterolist($data, $params) { if (! isset($params['tag'])) { return WikiParser_PluginOutput::argumentError(array('tag')); } $cachelib = TikiLib::lib('cache'); $tikilib = TikiLib::lib('tiki'); $cacheKey = 'zoterolist.' . $params['tag']; if ($cached = $cachelib->getSerialized($cacheKey, 'zotero')) { if (($cached['created'] + 3600) > $tikilib->now) { return WikiParser_PluginOutput::html($cached['data']); } } $zoterolib = TikiLib::lib('zotero'); $html = $zoterolib->get_formatted_references($params['tag']); $cachelib->cacheItem($cacheKey, serialize(array('created' => $tikilib->now, 'data' => $html)), 'zotero'); if ($html) { return WikiParser_PluginOutput::html($html); } else { return WikiParser_PluginOutput::error(tra('Error'), tra('No results obtained. The Zotero citation server may be down.')); } }
function wikiplugin_rss($data, $params) { global $smarty; global $rsslib; require_once 'lib/rss/rsslib.php'; $params = array_merge(array('max' => 10, 'date' => 0, 'desc' => 0, 'author' => 0, 'icon' => '', 'showtitle' => 1, 'ticker' => 0, 'desclen' => 0), $params); if (!isset($params['id'])) { return WikiParser_PluginOutput::argumentError(array('id')); } $params['id'] = (array) $params['id']; $items = $rsslib->get_feed_items($params['id'], $params['max']); $title = null; if (count($params['id']) == 1) { $module = $rsslib->get_rss_module(reset($params['id'])); if ($module['sitetitle']) { $title = array('title' => $module['sitetitle'], 'link' => $module['siteurl']); } } if ($params['desc'] > 0 && $params['desclen'] > 0) { foreach ($items as &$item) { $item['description'] = limit_text($item['description'], $params['desclen']); } } global $smarty; $smarty->assign('rsstitle', $title); $smarty->assign('items', $items); $smarty->assign('showdate', $params['date'] > 0); $smarty->assign('showtitle', $params['showtitle'] > 0); $smarty->assign('showdesc', $params['desc'] > 0); $smarty->assign('showauthor', $params['author'] > 0); $smarty->assign('icon', $params['icon']); $smarty->assign('ticker', $params['ticker']); return $smarty->fetch('wiki-plugins/wikiplugin_rss.tpl'); }
function wikiplugin_transclude( $data, $params ) { if ( ! isset( $params['page'] ) ) { return WikiParser_PluginOutput::argumentError(array( 'page' )); } $page = $params['page']; unset($params['page']); global $tikilib; if ( ! Perms::get('wiki page', $page)->view ) { return WikiParser_PluginOutput::error(tra('Permission Denied'), tra('Attempt to include a page that cannot be viewed.')); } if ( $info = $tikilib->get_page_info($page) ) { $parts = preg_split('/%%%text%%%/', $info['data']); $data = $tikilib->parse_data($data); $pass = $parts[0] . $data . $parts[1]; return preg_replace_callback( '/%%%([A-z0-9]+)%%%/', array( new WikiPlugin_Transclude_Replacer($params), 'callback' ), $pass ); } else { return WikiParser_PluginOutput::error(tr('Page not found'), tr('Page named "%0" does not exist at this time.', $page)); } }
function wikiplugin_zotero($data, $params) { $zotero = TikiLib::lib('zotero'); $cachelib = TikiLib::lib('cache'); $tag = null; $key = null; $note = null; if (isset($params['key'])) { $key = $params['key']; $cacheKey = "key_{$key}"; } elseif (isset($params['tag'])) { $tag = $params['tag']; $cacheKey = "tag_{$tag}"; } else { return WikiParser_PluginOutput::argumentError(array('key', 'tag')); } if (isset($params['note'])) { $note = $params['note']; } if ($cached = $cachelib->getCached($cacheKey, 'zotero')) { $info = unserialize($cached); } else { if ($key) { $info = $zotero->get_entry($key); } else { $info = $zotero->get_first_entry($tag); } $cachelib->cacheItem($cacheKey, serialize($info), 'zotero'); } $content = $info['content']; $content = str_replace('<div', '<span', $content); $content = str_replace('</div>', '</span>', $content); return "{FOOTNOTE()}~np~{$content} {$note}~/np~{FOOTNOTE}"; }
function wikiplugin_poll($data, $params) { global $smarty, $polllib, $trklib, $tikilib, $dbTiki, $userlib, $tiki_p_admin, $prefs, $_REQUEST, $user; $default = array('showtitle' => 'y', 'showresult' => 'link', 'showtotal' => 'y'); $params = array_merge($default, $params); extract($params, EXTR_SKIP); if (!isset($pollId)) { return WikiParser_PluginOutput::argumentError(array('pollId')); } global $polllib; include_once 'lib/polls/polllib.php'; $poll_info = $polllib->get_poll($pollId); $options = $polllib->list_poll_options($pollId); $hasVoted = $tikilib->user_has_voted($user, 'poll' . $pollId); $ret = ''; $smarty->assign_by_ref('showresult', $showresult); $smarty->assign_by_ref('showtotal', $showtotal); $smarty->assign_by_ref('hasVoted', $hasVoted); $smarty->assign_by_ref('showtitle', $showtitle); if (!$hasVoted || $prefs['feature_poll_revote'] == 'y') { $smarty->assign_by_ref('menu_info', $poll_info); $smarty->assign_by_ref('channels', $options); $smarty->assign_by_ref('poll_title', $data); $smarty->assign('ownurl', $tikilib->httpPrefix() . $_SERVER['REQUEST_URI']); ask_ticket('poll-form'); $ret = $smarty->fetch('tiki-plugin_poll.tpl'); } if ($showresult == 'voted' && $hasVoted || $showresult == 'always') { $total = $polllib->options_percent($poll_info, $options); $poll_info['options'] = $options; $smarty->assign_by_ref('poll_info', $poll_info); $ret .= $smarty->fetch('tiki-poll_results_bar.tpl'); } return '~np~' . $ret . '~/np~'; }
function wikiplugin_modulelist($data, $params) { // Pre-emptively load the modules, this normally would not happen until the final call to $smarty->display(...) // May have some side effects if not all of the information required to filter the modules is available at this time. include_once 'tiki-modules.php'; $smarty = TikiLib::lib('smarty'); $smarty->loadPlugin('smarty_function_modulelist'); if (!isset($params['zone'])) { return WikiParser_PluginOutput::argumentError(array('zone')); } return smarty_function_modulelist(array('zone' => $params['zone'], 'id' => $params['zone'] . '_plugin_modules'), $smarty); }
function testMissingArguments() { $output = WikiParser_PluginOutput::argumentError(array('id', 'test')); $this->assertContains('<li>id</li>', $output->toHtml()); }
function wikiplugin_addtocart($data, $params) { global $cartuserlist, $globalperms; $smarty = TikiLib::lib('smarty'); $userlib = TikiLib::lib('user'); $headerlib = TikiLib::lib('header'); $cartlib = TikiLib::lib('cart'); if (!session_id()) { session_start(); } if (!isset($params['code'], $params['description'], $params['price'])) { return WikiParser_PluginOutput::argumentError(array_diff(array('code', 'description', 'price'), array_keys($params))); } $plugininfo = wikiplugin_addtocart_info(); $default = array(); foreach ($plugininfo['params'] as $key => $param) { $default["{$key}"] = $param['default']; } $params = array_merge($default, $params); // once forceanon is set it will have to affect the whole shopping cart otherwise it will be inconsistent if ($params['forceanon'] == 'y') { $_SESSION['forceanon'] = 'y'; } foreach ($params as &$p) { $p = trim($p); // remove some line ends picked up in pretty tracker } $params['price'] = preg_replace('/[^\\d^\\.^,]/', '', $params['price']); $smarty->assign('params', $params); if ($params['onbehalf'] == 'y' && $globalperms->payment_admin) { $smarty->assign('onbehalf', 'y'); // Do not load the user list unless it is needed, this light function is not as light as one would expect if (!isset($cartuserlist)) { $cartuserlist = $userlib->get_users_light(); } $smarty->assign('cartuserlist', $cartuserlist); } if (!empty($params['exchangeorderitemid']) && !empty($params['exchangetoproductid'])) { $smarty->assign('hideamountfield', 'y'); } else { $smarty->assign('hideamountfield', 'n'); } if (is_numeric($params['productclass'])) { $information_form = $cartlib->get_missing_user_information_form($params['productclass'], 'required'); $missing_information = $cartlib->get_missing_user_information_fields($params['productclass'], 'required'); $skip_information_form = $cartlib->skip_user_information_form_if_not_missing($params['productclass']) && empty($missing_information); if ($information_form && !$skip_information_form) { $headerlib->add_jq_onready("\$('form.addProductToCartForm{$params['productclass']}')\n\t\t\t\t\t.cartProductClassMissingForm({\n\t\t\t\t\t\tinformationForm: '{$information_form}'\n\t\t\t\t\t});"); } } if ($params['ajaxaddtocart'] == 'y') { $headerlib->add_jq_onready("\$('.wp_addtocart_form').cartAjaxAdd();"); $smarty->assign('form_data', ' data-params=\'' . str_replace("'", "\\u0027", json_encode(array_filter($params))) . '\''); } else { $smarty->assign('form_data', ''); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { global $jitPost, $user; $quantity = $jitPost->quantity->int(); if ($jitPost->code->text() == $params['code'] && $quantity > 0) { $previous_cart_content = $cartlib->get_content(); $addedOk = $cartlib->add_to_cart($params, $jitPost); global $tikiroot, $prefs; $access = TikiLib::lib('access'); $tikilib = TikiLib::lib('tiki'); if ($addedOk && $params['autocheckout'] == 'y' && empty($previous_cart_content)) { $invoice = $cartlib->request_payment(); if ($invoice) { $paymenturl = 'tiki-payment.php?invoice=' . intval($invoice); $paymenturl = $tikilib->httpPrefix(true) . $tikiroot . $paymenturl; if (!$user || $params['forceanon'] == 'y' && !Perms::get('payment', $invoice)->manual_payment) { // token access needs to be an optional feature // and needs to depend on auth_token_access pref require_once 'lib/auth/tokens.php'; $tokenlib = AuthTokens::build($prefs); $tokenpaymenturl = $tokenlib->includeToken($paymenturl, array('Temporary Shopper', 'Anonymous')); } if ($globalperms->payment_admin || Perms::get('payment', $invoice)->manual_payment) { // if able to do manual payment it means it is admin and don't need token $access->redirect($paymenturl, tr('The order was recorded and is now awaiting payment. Reference number is %0.', $invoice)); } else { $access->redirect($tokenpaymenturl, tr('The order was recorded and is now awaiting payment. Reference number is %0.', $invoice)); } } else { if (!empty($params['forwardafterfree'])) { $access->redirect($params['forwardafterfree'], tr('Your free order of %0 (%1) has been processed. An email has been sent to you for your records.', $params['description'], $quantity)); } else { $access->redirect($_SERVER['REQUEST_URI'], tr('Your free order of %0 (%1) has been processed', $params['description'], $quantity)); } } die; } $access->redirect($_SERVER['REQUEST_URI'], tr('%0 (%1) was added to your cart', $params['description'], $quantity)); } } return $smarty->fetch('wiki-plugins/wikiplugin_addtocart.tpl'); }
function wikiplugin_addrelation($data, $params) { if (isset($params['source_object']) && false !== strpos($params['source_object'], ':')) { list($source_object['type'], $source_object['object']) = explode(':', $params['source_object'], 2); } else { $source_object = current_object(); } if (isset($params['target_object']) && false !== strpos($params['target_object'], ':')) { list($target_object['type'], $target_object['object']) = explode(':', $params['target_object'], 2); } else { $target_object = current_object(); } if ($source_object == $target_object) { return tra('Source and target object cannot be the same'); } if (!isset($params['qualifier'])) { return WikiParser_PluginOutput::argumentError(array('qualifier')); } else { $qualifier = $params['qualifier']; } if (!empty($params['label_add'])) { $labeladd = $params['label_add']; } else { $labeladd = tra('Add Relation'); } if (!empty($params['label_remove'])) { $labelremove = $params['label_remove']; } else { $labelremove = tra('Remove Relation'); } if (!empty($params['label_added'])) { $labeladded = $params['label_added']; } else { $labeladded = tra('Relation Added'); } if (!empty($params['button_id'])) { $id = 'wp_addrelation_' . $params['button_id']; } else { $id = 'wp_addrelation_0'; } $relationlib = TikiLib::lib('relation'); if (isset($_POST[$id])) { if ($_POST[$id] == 'y') { $relationlib->add_relation($qualifier, $source_object['type'], $source_object['object'], $target_object['type'], $target_object['object']); } elseif ($_POST[$id] == 'n') { $relation_id = $relationlib->add_relation($qualifier, $source_object['type'], $source_object['object'], $target_object['type'], $target_object['object']); $relationlib->remove_relation($relation_id); } require_once 'lib/search/refresh-functions.php'; refresh_index($source_object['type'], $source_object['object']); refresh_index($target_object['type'], $target_object['object']); } $relationsfromsource = $relationlib->get_relations_from($source_object['type'], $source_object['object'], $qualifier); $relationexists = false; foreach ($relationsfromsource as $r) { if ($r['itemId'] == $target_object['object'] && $r['type'] == $target_object['type']) { $relationexists = true; break; } } $smarty = TikiLib::lib('smarty'); $smarty->assign('wp_addrelation_id', $id); $smarty->assign('wp_addrelation_action', $relationexists ? 'n' : 'y'); $smarty->assign('label_add', $labeladd); $smarty->assign('label_added', $labeladded); $smarty->assign('label_remove', $labelremove); return $smarty->fetch('wiki-plugins/wikiplugin_addrelation.tpl'); }
function wikiplugin_addtocart($data, $params) { global $cartlib, $headerlib; require_once 'lib/payment/cartlib.php'; $headerlib->add_jsfile('lib/payment/cartlib.js'); if (!session_id()) { return WikiParser_PluginOutput::internalError(tra('A session must be active to use the cart.')); } if (!isset($params['code'], $params['description'], $params['price'])) { return WikiParser_PluginOutput::argumentError(array_diff(array('code', 'description', 'price'), array_keys($params))); } if (!isset($params['href'])) { $params['href'] = null; } if (!isset($params['label'])) { $params['label'] = tra('Add to cart'); } if (!isset($params['forceanon'])) { $params['forceanon'] = 'n'; } // once forceanon is set it will have to affect the whole shopping cart otherwise it will be inconsistent if ($params['forceanon'] == 'y') { $_SESSION['forceanon'] = 'y'; } if (!isset($params['ajaxaddtocart'])) { $params['ajaxaddtocart'] = 'y'; } foreach ($params as &$p) { $p = trim($p); // remove some line ends picked up in pretty tracker } $code = $params['code']; $product_class = $params['productclass']; $product_type = $params['producttype']; $product_bundle = $params['productbundle']; $bundle_class = $params['bundleclass']; $gift_certificate = $params['giftcertificate']; $eventcode = $params['eventcode']; $price = preg_replace('/[^\\d^\\.^,]/', '', $params['price']); $add_label = $params['label']; $ajax_add_to_cart = $params['ajaxaddtocart']; global $smarty; $smarty->assign('code', $code); $smarty->assign('productclass', $product_class); $smarty->assign('giftcertificate', $gift_certificate); $smarty->assign('price', $price); $smarty->assign('add_label', $add_label); global $cartuserlist, $userlib, $globalperms; if (!isset($cartuserlist)) { $cartuserlist = $userlib->get_users_light(); } $smarty->assign('cartuserlist', $cartuserlist); if ($params['onbehalf'] == 'y' && $globalperms->payment_admin) { $smarty->assign('onbehalf', 'y'); } if (!empty($params['exchangeorderitemid']) && !empty($params['exchangetoproductid'])) { $smarty->assign('exchangeorderitemid', $params['exchangeorderitemid']); $smarty->assign('exchangetoproductid', $params['exchangetoproductid']); $smarty->assign('hideamountfield', 'y'); } else { $smarty->assign('hideamountfield', 'n'); } if (is_numeric($product_class)) { $information_form = $cartlib->get_missing_user_information_form($product_class, 'required'); $missing_information = $cartlib->get_missing_user_information_fields($product_class, 'required'); $skip_information_form = $cartlib->skip_user_information_form_if_not_missing($product_class) && empty($missing_information); if ($information_form && !$skip_information_form) { $headerlib->add_jq_onready("\$('form.addProductToCartForm{$product_class}')\n\t\t\t\t\t.cartProductClassMissingForm({\n\t\t\t\t\t\tinformationForm: '{$information_form}'\n\t\t\t\t\t});"); } } if ($ajax_add_to_cart == 'y') { $headerlib->add_jq_onready("\$('form.addProduct').cartAjaxAdd();"); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { global $jitPost, $access, $user; if (!empty($params['exchangeorderitemid']) && !empty($params['exchangetoproductid'])) { if ($jitPost->exchangeorderitemid->int() == $params['exchangeorderitemid'] && $jitPost->exchangetoproductid->int() == $params['exchangetoproductid']) { $correct_exchange = true; } else { $correct_exchange = false; } } else { $correct_exchange = true; } $quantity = $jitPost->quantity->int(); if ($jitPost->code->text() == $params['code'] && $quantity > 0 && $correct_exchange) { $behaviors = array(); if ($prefs['payment_cart_anonymous'] === 'y' && (!$user || $params['forceanon'] == 'y') && empty($_SESSION['shopperinfo'])) { $access->redirect($_SERVER['REQUEST_URI'], tr('Please enter your shopper information first')); } // There needs to be a shopperinfo plugin on the page if ($globalperms->payment_admin && !empty($_POST['buyonbehalf']) && $userlib->user_exists($_POST['buyonbehalf'])) { $onbehalf = $_POST['buyonbehalf']; } else { $onbehalf = ''; } $gift_certificate_error = tra("Invalid gift certificate: "); if ($_REQUEST['gift_certificate'] && isset($gift_certificate)) { if (!$cartlib->add_gift_certificate($_REQUEST['gift_certificate'])) { $smarty->assign('gift_certificate', $_REQUEST['gift_certificate']); $smarty->assign('gift_certificate_error', $gift_certificate_error); return $smarty->fetch('wiki-plugins/wikiplugin_addtocart.tpl'); //TODO: Notify user if gift certificate is invalid } } $product_info = array('description' => $params['description'], 'price' => $price, 'href' => $params['href'], 'behaviors' => $behaviors, 'eventcode' => $eventcode, 'onbehalf' => $onbehalf, 'producttype' => $product_type, 'productclass' => $product_class, 'productbundle' => $product_bundle, 'bundleclass' => $bundle_class); // Generate behavior for exchanges if (!empty($params['exchangeorderitemid']) && !empty($params['exchangetoproductid'])) { $product_info['behaviors'][] = array('event' => 'complete', 'behavior' => 'cart_exchange_product', 'arguments' => array($params["exchangeorderitemid"], $params["exchangetoproductid"])); $product_info['exchangeorderitemid'] = $params["exchangeorderitemid"]; $product_info['exchangetoproductid'] = $params["exchangetoproductid"]; if (!isset($params['exchangeorderamount']) || !$params['exchangeorderamount']) { $exchangeorderamount = 1; } else { $exchangeorderamount = $params["exchangeorderamount"]; } $product_info['exchangeorderamount'] = $exchangeorderamount; } // Generate behavior for gift certificate purchase if (strtolower($product_type) == 'gift certificate') { if ($onbehalf) { $giftcert_email = $userlib->get_user_email($onbehalf); } elseif (!$user && !empty($_SESSION['shopperinfo']['email'])) { $giftcert_email = $_SESSION['shopperinfo']['email']; } elseif ($user) { $giftcert_email = $userlib->get_user_email($user); } $product_info['behaviors'][] = array('event' => 'complete', 'behavior' => 'cart_gift_certificate_purchase', 'arguments' => array($code, $giftcert_email)); } // Now add product to cart $previous_cart_content = $cartlib->get_content(); $cartlib->add_product($params['code'], $quantity, $product_info); global $access, $tikilib, $tikiroot, $prefs; if ($params['autocheckout'] == 'y' && empty($previous_cart_content)) { $invoice = $cartlib->request_payment(); if ($invoice) { $paymenturl = 'tiki-payment.php?invoice=' . intval($invoice); $paymenturl = $tikilib->httpPrefix(true) . $tikiroot . $paymenturl; if (!$user || $params['forceanon'] == 'y' && !Perms::get('payment', $invoice)->manual_payment) { // token access needs to be an optional feature // and needs to depend on auth_token_access pref require_once 'lib/auth/tokens.php'; $tokenlib = AuthTokens::build($prefs); $tokenpaymenturl = $tokenlib->includeToken($paymenturl, array('Temporary Shopper', 'Anonymous')); } if ($globalperms->payment_admin || Perms::get('payment', $invoice)->manual_payment) { // if able to do manual payment it means it is admin and don't need token $access->redirect($paymenturl, tr('The order was recorded and is now awaiting payment. Reference number is %0.', $invoice)); } else { $access->redirect($tokenpaymenturl, tr('The order was recorded and is now awaiting payment. Reference number is %0.', $invoice)); } } else { if (!empty($params['forwardafterfree'])) { $access->redirect($params['forwardafterfree'], tr('Your free order of %0 (%1) has been processed. An email has been sent to you for your records.', $params['description'], $quantity)); } else { $access->redirect($_SERVER['REQUEST_URI'], tr('Your free order of %0 (%1) has been processed', $params['description'], $quantity)); } } die; } $access->redirect($_SERVER['REQUEST_URI'], tr('%0 (%1) was added to your cart', $params['description'], $quantity)); } } return $smarty->fetch('wiki-plugins/wikiplugin_addtocart.tpl'); }