public static function apply($type, &$total) { $user = JCck::getUser(); $my_groups = $user->getAuthorisedGroups(); $my_zones = JCckEcommerce::getUserZones(); $currency = JCckEcommerce::getCurrency(); $tax = ''; $taxes = JCckEcommerce::getTaxes($type, $my_zones); if (count($taxes)) { foreach ($taxes as $p) { $groups = explode(',', $p->groups); if (count(array_intersect($my_groups, $groups)) > 0) { switch ($p->tax) { case 'plus': $tax = $p->tax_amount; $total += $tax; break; case 'percentage': $tax = $total * $p->tax_amount / 100; $total += $tax; break; default: break; } } } } return $tax; }
public static function apply($type, &$total, $params = array()) { $user = JCck::getUser(); $my_groups = $user->getAuthorisedGroups(); $currency = JCckEcommerce::getCurrency(); $discount = ''; $promotions = JCckEcommerce::getPromotions($type); if (count($promotions)) { foreach ($promotions as $p) { if (isset($params['target']) && $params['target']) { if ($params['target'] == 'order' && $p->target == 0) { // OK } elseif ($params['target'] == 'product') { if ($p->target == 1) { // OK } elseif ($p->target == 2) { $products = self::getTargets($p->id); if (!isset($products[$params['target_id']])) { continue; } } elseif ($p->target == -2) { $products = self::getTargets($p->id); if (isset($products[$params['target_id']])) { continue; } } else { continue; } } else { continue; } } if ($p->type == 'coupon') { if ($p->code && $p->code != @$params['code']) { continue; } } $groups = explode(',', $p->groups); if (count(array_intersect($my_groups, $groups)) > 0) { switch ($p->discount) { case 'free': $discount = 'FREE'; $total = 0; break; case 'minus': $discount = '- ' . $currency->lft . $p->discount_amount . $currency->right; $total -= $p->discount_amount; break; case 'percentage': $discount = '- ' . $p->discount_amount . ' %'; $total = $total - $total * $p->discount_amount / 100; break; default: break; } } } } return $discount; }
public function saveOrder($pks = array(), $lft = array()) { JPluginHelper::importPlugin('cck_storage_location'); if (!count($pks)) { return false; } $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->select('a.id, a.pk, a.storage_location, b.id AS type_id')->from('#__cck_core AS a')->join('LEFT', '#__cck_core_types AS b ON b.name = a.cck')->where('a.id IN (' . implode(',', $pks) . ')'); $db->setQuery($query); $results = $db->loadAssocList('id'); if (!empty($results)) { $ids = array(); $location = null; $user = JCck::getUser(); $user_id = $user->get('id'); foreach ($pks as $i => $pk) { $canEdit = $user->authorise('core.edit', 'com_cck.form.' . $results[$pk]['type_id']); $canEditOwn = $user->authorise('core.edit.own', 'com_cck.form.' . $results[$pk]['type_id']); // Check Permissions if (!($canEdit && $canEditOwn || $canEdit && !$canEditOwn && $results[$pk]['author_id'] != $user_id || $canEditOwn && $results[$pk]['author_id'] == $user_id)) { unset($lft[$i]); continue; } $ids[] = $results[$pk]['pk']; if (null === $location) { $location = $results[$pk]['storage_location']; } } if ($location && count($ids)) { return JCck::callFunc_Array('plgCCK_Storage_Location' . $location, 'onCCK_Storage_LocationSaveOrder', array($ids, $lft)); } } return false; }
protected static function _link($link, &$field, &$config) { $app = JFactory::getApplication(); $form = $config['type']; $id = $config['id']; $itemId = $link->get('itemid', $app->input->getInt('Itemid', 0)); $redirection = $link->get('redirection', ''); $return = ''; $task = JFactory::getApplication()->isAdmin() ? 'list.delete' : 'delete'; $uri = (string) JFactory::getURI(); // Return if ($redirection == 'url') { $url = $link->get('redirection_url', ''); if (strpos($url, 'Itemid=') !== false) { $url = JRoute::_($url); } elseif ($url && strpos($url, 'http') === false) { $url = JUri::base() . ($url[0] == '/' ? substr($url, 1) : $url); } $return = base64_encode($url); } elseif ($config['client'] == 'content') { $return = base64_encode(JRoute::_('index.php?Itemid=' . $itemId)); } else { $return2 = $link->get('redirection_custom', ''); if ($return2 != '') { if ($return2[0] == '#') { $uri .= $return2; } else { $uri .= (strpos($return2, '?') !== false ? '&' : '?') . $return2; } } $return = base64_encode($uri); } if ($return) { $return = '&return=' . $return; } // Check $user = JCck::getUser(); $canDelete = $user->authorise('core.delete', 'com_cck.form.' . $config['type_id']); $canDeleteOwn = $user->authorise('core.delete.own', 'com_cck.form.' . $config['type_id']); if (!$canDelete && !$canDeleteOwn || !$canDelete && $canDeleteOwn && $config['author'] != $user->get('id') || $canDelete && !$canDeleteOwn && $config['author'] == $user->get('id')) { if (!$link->get('no_access', 0)) { $field->display = 0; } return; } // Prepare $link_class = $link->get('class', ''); $link_title = $link->get('title', ''); $link_title2 = $link->get('title_custom', ''); $field->link = 'index.php?option=com_cck&task=' . $task . '&cid=' . $id . '&Itemid=' . $itemId . $return; $field->link = JRoute::_($field->link); $field->link_class = $link_class ? $link_class : (isset($field->link_class) ? $field->link_class : ''); if ($link->get('confirm', 1)) { $field->link_onclick = 'if(!confirm(\'' . addslashes(JText::_('COM_CCK_CONFIRM_DELETE')) . '\')){return false;}'; } $field->link_state = $link->get('state', 1); $field->link_title = $link_title ? $link_title == '2' ? $link_title2 : (isset($field->link_title) ? $field->link_title : '') : ''; }
public static function authorise(&$field, &$config) { $user = JCck::getUser(); $check = JCckDatabase::loadResult('SELECT COUNT(a.id) FROM #__cck_more_ecommerce_order_product AS a LEFT JOIN #__cck_more_ecommerce_orders AS b ON b.id = a.order_id' . ' WHERE a.product_id = ' . $config['pk'] . ' AND b.user_id =' . $user->id); if ((int) $check > 0) { // } else { $field->display = 0; } }
public static function countItems($definition) { static $cache = array(); $count = 0; $user = JCck::getUser(); if (!isset($cache[$definition])) { $cache[$definition] = JCckDatabase::loadResult('SELECT COUNT(a.id) FROM #__cck_more_ecommerce_cart_product AS a' . ' LEFT JOIN #__cck_more_ecommerce_carts AS b ON b.id = a.cart_id WHERE b.type = "' . $definition . '" AND b.' . (string) $user->where_clause . ' AND b.state = 1'); } return $cache[$definition]; }
public function onCCK_Field_LivePrepareForm(&$field, &$value = '', &$config = array()) { if (self::$type != $field->live) { return; } // Init $live = ''; $options = parent::g_getLive($field->live_options); // Prepare $default = $options->get('default_value', ''); $excluded = $options->get('excluded'); $property = $options->get('property'); if ($property) { $user = JCck::getUser(); if ($user->id > 0 && $user->guest == 1) { if (!($property == 'ip' || $property == 'session_id')) { $user = new JUser(0); } } if ($property == 'access') { $viewlevels = $user->getAuthorisedViewLevels(); if ($excluded != '') { $excluded = explode(',', $excluded); $viewlevels = array_diff($viewlevels, $excluded); } if (empty($viewlevels)) { $live = $default; } else { $live = implode(',', $viewlevels); } } elseif (isset($user->{$property})) { $live = $user->{$property}; if (is_array($live)) { if ($excluded != '') { $excluded = explode(',', $excluded); $live = array_diff($live, $excluded); } if (empty($live)) { $live = $default; } else { $live = implode(',', $live); } } elseif ($live == '') { $live = $default; } } else { $live = $default; } } // Set $value = (string) $live; }
public static function apply($type, &$total, $params = array()) { $user = JCck::getUser(); $my_groups = $user->groups; /* $user->getAuthorisedGroups(); */ $my_zones = JCckEcommerce::getUserZones(); $currency = JCckEcommerce::getCurrency(); $res = 0; $results = array('items' => array()); $tax = ''; $taxes = JCckEcommerce::getTaxes($type, $my_zones); if (count($taxes)) { foreach ($taxes as $p) { if (isset($params['target']) && $params['target']) { if ($params['target'] == 'order' && $p->target == 0) { // OK } elseif ($params['target'] == 'product' && $p->target == 1) { // OK } else { continue; } } $groups = explode(',', $p->groups); if (count(array_intersect($my_groups, $groups)) > 0) { switch ($p->tax) { case 'plus': $tax = $p->tax_amount; $res += $tax; $total += $tax; $results['items'][$p->id] = array('type' => $p->type, 'tax' => $p->tax, 'tax_amount' => (string) $tax, 'title' => $p->title); break; case 'percentage': $tax = $total * $p->tax_amount / 100; $res += $tax; $total += $tax; $results['items'][$p->id] = array('type' => $p->type, 'tax' => $p->tax, 'tax_amount' => (string) $tax, 'title' => $p->title); break; default: break; } } } } if ($res) { $results['total'] = (double) $res; return (object) $results; } return null; }
<?php /** * @version SEBLOD 3.x More * @package SEBLOD (App Builder & CCK) // SEBLOD nano (Form Builder) * @url http://www.seblod.com * @editor Octopoos - www.octopoos.com * @copyright Copyright (C) 2013 SEBLOD. All Rights Reserved. * @license GNU General Public License version 2 or later; see _LICENSE.php **/ defined('_JEXEC') or die; global $user; $app = JFactory::getApplication(); $path_lib = JPATH_SITE . '/libraries/cck/rendering/rendering.php'; $user = JCck::getUser(); if (!file_exists($path_lib)) { print '/libraries/cck/rendering/rendering.php file is missing.'; die; } require_once $path_lib;
public static function onCCK_Storage_LocationDelete($pk, &$config = array()) { $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $item = JCckDatabase::loadObject('SELECT id, cck as type, pk, storage_table FROM #__cck_core WHERE cck = "' . $config['type'] . '" AND pk = ' . (int) $pk); if (!is_object($item)) { return false; } $table = JCckTable::getInstance($item->storage_table, 'id'); $table->load($pk); if (!$table) { return false; } // Check $user = JCck::getUser(); $canDelete = $user->authorise('core.delete', 'com_cck.form.' . $config['type_id']); $canDeleteOwn = $user->authorise('core.delete.own', 'com_cck.form.' . $config['type_id']); if (!$canDelete && !$canDeleteOwn || !$canDelete && $canDeleteOwn && $config['author'] != $user->get('id') || $canDelete && !$canDeleteOwn && $config['author'] == $user->get('id')) { $app->enqueueMessage(JText::_('COM_CCK_ERROR_DELETE_NOT_PERMITTED'), 'error'); return; } // Process // -- onContentBeforeDelete? if (!$table->delete($pk)) { return false; } // Delete Core if ($item->id) { $table = JCckTable::getInstance('#__cck_core', 'id', $item->id); $table->delete(); } // Delete More $base = str_replace('#__', '', $item->storage_table); $tables = JCckDatabase::loadColumn('SHOW TABLES'); $prefix = JFactory::getConfig()->get('dbprefix'); if (in_array($prefix . 'cck_store_item_' . $base, $tables)) { $table = JCckTable::getInstance('#__cck_store_item_' . $base, 'id', $pk); if ($table->id) { $table->delete(); } } if (in_array($prefix . 'cck_store_form_' . $item->type, $tables)) { $table = JCckTable::getInstance('#__cck_store_form_' . $item->type, 'id', $pk); if ($table->id) { $table->delete(); } } // -- onContentAfterDelete? return true; }
public static function onCCK_Storage_LocationDelete($pk, &$config = array()) { $app = JFactory::getApplication(); $dispatcher = JDispatcher::getInstance(); $table = self::_getTable($pk); if (!$table) { return false; } // Check $user = JCck::getUser(); $canDelete = $user->authorise('core.delete', 'com_cck.form.' . $config['type_id']); $canDeleteOwn = $user->authorise('core.delete.own', 'com_cck.form.' . $config['type_id']); if (!$canDelete && !$canDeleteOwn || !$canDelete && $canDeleteOwn && $config['author'] != $user->get('id') || $canDelete && !$canDeleteOwn && $config['author'] == $user->get('id')) { $app->enqueueMessage(JText::_('COM_CCK_ERROR_DELETE_NOT_PERMITTED'), 'error'); return; } // Process $result = $dispatcher->trigger('onContentBeforeDelete', array(self::$context, $table)); if (in_array(false, $result, true)) { return false; } if (!$table->delete($pk)) { return false; } $dispatcher->trigger('onContentAfterDelete', array(self::$context, $table)); return true; }
public static function getUserZones() { $user = JCck::getUser(); $zones = array(); if (!(isset($user->country) && $user->country != '')) { return $zones; } $where = 'countries = "' . $user->country . '" OR countries LIKE "' . $user->country . '||%" OR countries LIKE "%||' . $user->country . '" OR countries LIKE "%||' . $user->country . '||%"'; $zones = JCckDatabase::loadColumn('SELECT id FROM #__cck_more_ecommerce_zones WHERE published = 1 AND (' . $where . ') ORDER BY CHARACTER_LENGTH(countries) ASC'); return $zones; }
public static function onCCK_FieldAfterStore($process, &$fields, &$storages, &$config = array()) { $isNew = $process['isNew']; $sender = $process['sender']; $send_field = $process['send_field']; if ($send_field) { $sender = 0; if (isset($fields[$send_field]->value)) { switch ($fields[$send_field]->value) { case 0: $sender = 0; break; case 1: if ($isNew) { $sender = 1; } break; case 2: if (!$isNew) { $sender = 1; } break; case 3: $sender = 1; break; } } } if (!$sender) { return; } $dest = $process['dest']; if ($process['moredest']) { $more = self::_split($process['moredest']); foreach ($more as $mor) { if (isset($fields[$mor]->value) && $fields[$mor]->value) { $more_dest = self::_split($fields[$mor]->value); $dest = array_merge($dest, $more_dest); } } } $n = count(array_filter($dest)); if ($n) { $config2 = JFactory::getConfig(); $cfg_MailFrom = $config2->get('mailfrom'); $cfg_FromName = $config2->get('fromname'); if ($cfg_MailFrom != '' && $cfg_FromName != '') { $mailFrom = $cfg_MailFrom; $fromName = $cfg_FromName; } $subject = $process['subject']; $new_message = $process['new_message'] != '' ? $fields[$process['new_message']]->value : ''; $body = strlen($new_message) > 0 ? urldecode($new_message) : $process['message']; $subject = str_replace('[id]', $config['id'], $subject); $subject = str_replace('[pk]', $config['pk'], $subject); $subject = str_replace('[sitename]', $config2->get('sitename'), $subject); $subject = str_replace('[siteurl]', JURI::base(), $subject); // J(translate) for subject if ($subject != '' && strpos($subject, 'J(') !== false) { $matches = ''; $search = '#J\\((.*)\\)#U'; preg_match_all($search, $subject, $matches); if (count($matches[1])) { foreach ($matches[1] as $text) { $subject = str_replace('J(' . $text . ')', JText::_('COM_CCK_' . str_replace(' ', '_', trim($text))), $subject); } } } if (isset($config['registration_activation'])) { $body = str_replace('[activation]', JURI::root() . 'index.php?option=com_users&task=registration.activate&token=' . $config['registration_activation'], $body); $body = str_replace('[username]', $fields['username']->value, $body); $subject = str_replace('[username]', $fields['username']->value, $subject); } // {del fieldname}{/del} if ($body != '' && strpos($body, '{del') !== false) { $dels = NULL; $body = str_replace("\n", "", $body); preg_match_all('#\\{del ([^\\{]*)\\}([^\\{]*)\\{\\/del\\}#', $body, $dels); for ($i = 0, $n = count($dels[1]); $i <= $n; $i++) { $match = str_replace('#', '', $dels[1][$i]); if (isset($fields[$match]->value) && trim($fields[$match]->value)) { $body = str_replace($dels[0][$i], $dels[2][$i], $body); } else { $body = str_replace($dels[0][$i], '', $body); } } } // #fieldnames# $matches = NULL; preg_match_all('#\\#([a-zA-Z0-9_]*)\\##U', $body, $matches); if (count($matches[1])) { foreach ($matches[1] as $match) { if (trim($match) && isset($fields[$match]->text) && trim($fields[$match]->text != '')) { $body = str_replace('#' . $match . '#', $fields[$match]->text, $body); } else { $body = trim($match) && isset($fields[$match]->value) && trim($fields[$match]->value) ? str_replace('#' . $match . '#', $fields[$match]->value, $body) : str_replace('#' . $match . '#', '', $body); } } } $matches = NULL; preg_match_all('#\\#([a-zA-Z0-9_]*)\\##U', $subject, $matches); if (count($matches[1])) { foreach ($matches[1] as $match) { if (trim($match) && isset($fields[$match]->text) && trim($fields[$match]->text) != '') { $subject = str_replace('#' . $match . '#', $fields[$match]->text, $subject); } else { $subject = trim($match) && isset($fields[$match]->value) && trim($fields[$match]->value) != '' ? str_replace('#' . $match . '#', $fields[$match]->value, $subject) : str_replace('#' . $match . '#', '', $subject); } } } // $cck->getAttr('fieldname'); if ($body != '' && strpos($body, '$cck->get') !== false) { $matches = ''; $search = '#\\$cck\\->get([a-zA-Z0-9_]*)\\( ?\'([a-zA-Z0-9_]*)\' ?\\)(;)?#'; preg_match_all($search, $body, $matches); if (count($matches[1])) { for ($i = 0, $n = count($matches); $i <= $n; $i++) { $attr = strtolower($matches[1][$i]); $match = $matches[2][$i]; if (isset($fields[$match]->{$attr}) && trim($fields[$match]->{$attr}) != '') { $body = str_replace($matches[0][$i], $fields[$match]->{$attr}, $body); } else { $body = str_replace($matches[0][$i], '', $body); } } } } // J(translate) if ($body != '' && strpos($body, 'J(') !== false) { $matches = ''; $search = '#J\\((.*)\\)#U'; preg_match_all($search, $body, $matches); if (count($matches[1])) { foreach ($matches[1] as $text) { $body = str_replace('J(' . $text . ')', JText::_('COM_CCK_' . str_replace(' ', '_', trim($text))), $body); } } } $body = str_replace('[id]', $config['id'], $body); $body = str_replace('[pk]', $config['pk'], $body); $body = str_replace('[sitename]', $config2->get('sitename'), $body); $body = str_replace('[siteurl]', JURI::base(), $body); if ($body != '' && strpos($body, '$user->') !== false) { $user = JCck::getUser(); $matches = ''; $search = '#\\$user\\->([a-zA-Z0-9_]*)#'; preg_match_all($search, $body, $matches); if (count($matches[1])) { foreach ($matches[1] as $k => $v) { $body = str_replace($matches[0][$k], $user->{$v}, $body); } } } // [date(.*)] if ($body != '' && strpos($body, '[date') !== false) { $matches = NULL; preg_match_all('#\\[date(.*)\\]#U', $body, $matches); if (count($matches[1])) { foreach ($matches[1] as $match) { $date = date($match); $body = str_replace('[date' . $match . ']', $date, $body); } } } // [fields] if (strpos($body, '[fields]') !== false) { $bodyF = NULL; if (count($fields)) { foreach ($fields as $field) { $fieldName = $field->name; if (!($field->type == 'password' && $field->value == 'XXXX') && isset($field->value) && trim($field->value) != '' && $field->variation != 'hidden') { $valF = isset($field->text) && trim($field->text) != '' ? trim($field->text) : trim($field->value); $bodyF .= '- ' . $field->label . ' : ' . $valF . '<br /><br />'; } } } $body = strpos($body, '[fields]') !== false ? str_replace('[fields]', $bodyF, $body) : $body . substr($bodyF, 0, -12); } $from = $process['from']; switch ($from) { case 3: $from = $fields[$process['from_param']]->value; $fromName = $from; break; case 1: $from = $process['from_param']; break; default: $from = $mailFrom; break; } $fromName = $process['from_name']; switch ($fromName) { case 3: $fromName = $fields[$process['from_name_param']]->value; break; case 1: $fromName = $process['from_name_param']; break; default: $fromName = $fromName; break; } $cc = $process['cc']; switch ($cc) { case 3: $cc = self::_split($fields[$process['cc_param']]->value); break; case 1: $cc = self::_split($process['cc_param']); break; default: $cc = NULL; break; } $bcc = $process['bcc']; switch ($bcc) { case 3: $bcc = self::_split($fields[$process['bcc_param']]->value); break; case 1: $bcc = self::_split($process['bcc_param']); break; default: $bcc = NULL; break; } $send_attach = $process['send_attach']; if ($send_attach != 1 && strlen($process['send_attach']) > 1) { if (isset($fields[$send_attach]->value)) { $send_attach = $fields[$send_attach]->value; } } $attach = NULL; if ($send_attach && $process['moreattach']) { $attach = array(); $more = self::_split($process['moreattach']); foreach ($more as $mor) { if (isset($fields[$mor]->attachment) && $fields[$mor]->attachment != '') { $attach[] = JPATH_SITE . '/' . $fields[$mor]->attachment; } else { if (isset($fields[$mor]->value) && $fields[$mor]->value) { $attach[] = JPATH_SITE . '/' . $fields[$mor]->value; } } } } $replyTo = NULL; $replyToName = NULL; if ($process['format'] == '0') { $format = false; $body = strip_tags($body); } elseif ($process['format'] == '2') { $format = false; } else { $format = true; } JFactory::getMailer()->sendMail($from, $fromName, $dest, $subject, $body, $format, $cc, $bcc, $attach, $replyTo, $replyToName); } }
protected static function _link($link, &$field, &$config) { $app = JFactory::getApplication(); $custom = $link->get('custom', ''); $form = $link->get('form', ''); $edit = $link->get('form_edition', 1); $edit = !$form && $edit ? '&id=' . $config['pk'] : ''; $form = $form ? $form : $config['type']; $itemId = $link->get('itemid', $app->input->getInt('Itemid', 0)); $redirection = $link->get('redirection', ''); $uri = (string) JFactory::getUri(); if (strpos($uri, 'format=raw&infinite=1') !== false) { $return = $app->input->get('return'); } else { $return = base64_encode($uri); } if (!$form) { return; } // Check if ($edit != '') { static $cache = array(); $stage = $link->get('form_edition_stage', ''); if ($stage != '') { $edit .= '&stage=' . (int) $stage; } $user = JCck::getUser(); $canEdit = $user->authorise('core.edit', 'com_cck.form.' . $config['type_id']); // if ( $user->id && !$user->guest ) { $canEditOwn = $user->authorise('core.edit.own', 'com_cck.form.' . $config['type_id']); // } else { // $canEditOwn = false; // todo: guest // } $canEditOwnContent = ''; // canEditOwnContent jimport('cck.joomla.access.access'); $canEditOwnContent = CCKAccess::check($user->id, 'core.edit.own.content', 'com_cck.form.' . $config['type_id']); if ($canEditOwnContent) { $field2 = JCckDatabaseCache::loadObject('SELECT storage, storage_table, storage_field FROM #__cck_core_fields WHERE name = "' . $canEditOwnContent . '"'); $canEditOwnContent = false; if (is_object($field2) && $field2->storage == 'standard') { $pks = isset($config['pks']) ? $config['pks'] : $config['pk']; $query = 'SELECT ' . $field2->storage_field . ' as map, id FROM ' . $field2->storage_table . ' WHERE id IN (' . $pks . ')'; $index = md5($query); if (!isset($cache[$index])) { $cache[$index . '_pks'] = JCckDatabase::loadObjectList($query, 'id'); $values = array(); if (count($cache[$index . '_pks'])) { foreach ($cache[$index . '_pks'] as $p) { $values[] = $p->map; } } $values = count($values) ? implode(',', $values) : '0'; $cache[$index] = JCckDatabase::loadObjectList('SELECT author_id, pk FROM #__cck_core WHERE storage_location = "joomla_article" AND pk IN ( ' . $values . ' )', 'pk'); } if (isset($cache[$index . '_pks'][$config['pk']]) && isset($cache[$index][$cache[$index . '_pks'][$config['pk']]->map]) && $cache[$index][$cache[$index . '_pks'][$config['pk']]->map]->author_id == $user->get('id')) { $canEditOwnContent = true; } } } else { $canEditOwnContent = ''; } // Check Permissions if (!($canEdit && $canEditOwn || $canEdit && !$canEditOwn && $config['author'] != $user->get('id') || $canEditOwn && $config['author'] == $user->get('id') || $canEditOwnContent)) { if (!$link->get('no_access', 0)) { $field->display = 0; } return; } } elseif ($form != '') { $user = JCck::getUser(); $type_id = (int) JCckDatabase::loadResult('SELECT id FROM #__cck_core_types WHERE name = "' . $form . '"'); $canCreate = $type_id ? $user->authorise('core.create', 'com_cck.form.' . $type_id) : false; // Check Permissions if (!$canCreate) { return; } } // Prepare $link_class = $link->get('class', ''); $link_rel = $link->get('rel', ''); $link_target = $link->get('target', ''); $link_title = $link->get('title', ''); $link_title2 = $link->get('title_custom', ''); $tmpl = $link->get('tmpl', ''); $tmpl = $tmpl ? '&tmpl=' . $tmpl : ''; $vars = $tmpl; // + live /* if ( $config['client'] == 'admin' || $config['client'] == 'site' || $config['client'] == 'search' ) { $redirection = '-1'; // todo } */ // Set if (is_array($field->value)) { foreach ($field->value as $f) { $c = $custom; $c = parent::g_getCustomSelfVars(self::$type, $f, $c, $config); $c = $c ? '&' . $c : ''; $f->link = 'index.php?option=com_cck&view=form&layout=edit&type=' . $form . $edit . $vars . '&Itemid=' . $itemId . $c; if ($redirection != '-1') { $f->link .= '&return=' . $return; } $f->link = JRoute::_($f->link); $f->link_class = $link_class ? $link_class : (isset($f->link_class) ? $f->link_class : ''); $f->link_rel = $link_rel ? $link_rel : (isset($f->link_rel) ? $f->link_rel : ''); $f->link_state = $link->get('state', 1); $f->link_target = $link_target ? $link_target : (isset($f->link_target) ? $f->link_target : ''); $f->link_title = $link_title ? $link_title == '2' ? $link_title2 : (isset($f->link_title) ? $f->link_title : '') : ''; } $field->link = '#'; //todo } else { $custom = parent::g_getCustomVars(self::$type, $field, $custom, $config); $field->link = JRoute::_('index.php?option=com_cck&view=form&layout=edit&type=' . $form . $edit . $vars . '&Itemid=' . $itemId); $separator = strpos($field->link, '?') !== false ? '&' : '?'; if ($custom) { $field->link .= $separator . $custom; $separator = '&'; } if ($redirection != '-1') { $field->link .= $separator . 'return=' . $return; } $field->link_class = $link_class ? $link_class : (isset($field->link_class) ? $field->link_class : ''); $field->link_rel = $link_rel ? $link_rel : (isset($field->link_rel) ? $field->link_rel : ''); $field->link_state = $link->get('state', 1); $field->link_target = $link_target ? $link_target : (isset($field->link_target) ? $field->link_target : ''); $field->link_title = $link_title ? $link_title == '2' ? $link_title2 : (isset($field->link_title) ? $field->link_title : '') : ''; } }
public function onContentSearch($text = '', $phrase = '', $ordering = '', $areas = NULL, $fields = array(), $fields_order = array(), &$config = array(), $current = array(), $options = NULL, $user = NULL) { if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } else { return array(); } if (!count($fields)) { return array(); } if (!$user) { $user = JCck::getUser(); } if (!is_object($options)) { $options = new JRegistry(); } $app = JFactory::getApplication(); $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); $doClean = false; $doCount = (int) $options->get('count'); $doLimit = false; $limit = (int) $options->get('limit'); $doLimit = $limit > 0 ? false : true; $isLoadingMore = $app->input->get('format') == 'raw' && $app->input->get('infinite') > 0 ? 1 : 0; $glues = 1; $order = ''; $order_string = ''; $where = ''; $w = -1; $where2 = array(); $t = 1; $t2 = 1; $tables = array('#__cck_core' => array('_' => 't0', 'fields' => array(), 'join' => 1)); $colums = array(); if (isset($config['joins'][$current['stage']]) && is_array($config['joins'][$current['stage']])) { foreach ($config['joins'][$current['stage']] as $j) { if ($j->table) { if (!isset($tables[$j->table])) { $tables[$j->table] = array('_' => 't' . $t++, 'fields' => array(), 'key' => $j->column, 'join' => 2, 'join_key' => $j->column2, 'join_table' => $j->table2, 'join_and' => @$j->and, 'join_type' => @$j->type, 'join_mode' => @$j->mode, 'join_query' => @$j->query); } elseif (@$j->and != '') { $tables[$j->table . '@' . md5($j->and)] = array('_' => 't' . $t++, 'fields' => array(), 'key' => $j->column, 'join' => 2, 'join_key' => $j->column2, 'join_table' => $j->table2, 'join_and' => $j->and, 'join_type' => @$j->type, 'join_mode' => @$j->mode, 'join_query' => @$j->query); } } } $t2 = count($tables); } foreach ($fields as $field) { if (!$field->state) { continue; } if ($current['stage'] != (int) $field->stage) { continue; } $hasSQL = true; $name2 = $field->match_collection != '' ? '\\\\|[0-9]+\\\\|' . $field->match_collection : ''; // - if ($field->live == 'stage') { $live_options = new JRegistry(); $live_options->loadString($field->live_options); $live_value = $live_options->get('value', $field->live_value); $live_value = $live_value ? $live_value : 1; $value = $current['stages'][$live_value]; if ($value == '' && $live_options->get('default_value') != '') { $value = (string) $live_options->get('default_value'); } } else { $value = $field->value; } // - $Pf = $field->storage_field; $Pt = $field->storage_table; if (($value !== '' && $field->match_mode != 'none' || ($field->match_mode == 'empty' || $field->match_mode == 'not_empty' || $field->match_mode == 'not_null')) && $field->storage != 'none' || $field->type == 'search_operator' && $field->match_mode != 'none') { $glue = ''; $sql = ''; if ($field->match_options != '') { $field->match_options = new JRegistry($field->match_options); } // Glue if ($glues == 1) { $glue = $where != '' ? 'AND' : ''; $where .= $glue; if ($glue != '') { $where2[++$w] = $glue; } $glue = ''; } // Sql if ($field->type == 'search_generic') { if (count($field->children)) { $sql = '('; $k = 0; foreach ($field->children as $child) { if ($k > 0) { $sql .= ' OR '; } $child->match_mode = $field->match_mode; $child->match_options = $field->match_options; $child->match_value = $field->match_value; if ($child->storage && $child->storage != 'none') { $Pf = $child->storage_field; $Pt = $child->storage_table; // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $child->storage_location; // - $name = $child->storage_field2 ? $child->storage_field2 : $child->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } if (JCck::callFunc('plgCCK_Field' . $child->type, 'isFriendly')) { if (isset($fields[$child->name])) { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($fields[$child->name], $value, $config)); } else { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($child, $value, $config)); } } else { $value2 = $value; } require_once JPATH_PLUGINS . '/cck_storage/' . $child->storage . '/' . $child->storage . '.php'; $sql .= JCck::callFunc_Array('plgCCK_Storage' . $child->storage, 'onCCK_StoragePrepareSearch', array(&$child, $child->match_mode, $value2, $name, $name2, $target, $fields, &$config)); } $k++; } $sql .= ')'; } } elseif ($field->type == 'search_ordering') { $sql = ''; array_pop($where2); if (isset($field->children[$value])) { if (!isset($fields_order[$field->children[$value]->name])) { $fields_order[$field->children[$value]->name] = $field->children[$value]; } } } elseif ($field->type == 'search_operator') { // Glue if ($field->value == '((') { $glues = 0; $sql = '('; } elseif ($field->value == '))') { $glues = 1; $sql = ')'; } else { if ($where2[$w] != '(') { $glue = $field->value; $sql = $glue; } } $doClean = true; } else { // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $field->storage_location; // - $name = $field->storage_field2 ? $field->storage_field2 : $field->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } else { $target = $Pf; $hasSQL = false; } require_once JPATH_PLUGINS . '/cck_storage/' . $field->storage . '/' . $field->storage . '.php'; $sql = JCck::callFunc_Array('plgCCK_Storage' . $field->storage, 'onCCK_StoragePrepareSearch', array(&$field, $field->match_mode, $value, $name, $name2, $target, $fields, &$config)); } if ($hasSQL === false) { if ($glues == 1) { if ($where != '') { $where = substr($where, 0, -3); $where2[$w] = ''; } } $config['query_parts']['having'][] = $sql; $sql = ''; } else { $where .= $sql; $where2[++$w] = $sql; } } else { if (@$glue) { $where2[$w] = ''; } // unset( $fields[$field->name] ); } } // Finalize $where = implode(' ', $where2); if ($doClean !== false) { $where = preg_replace('/\\s+/', ' ', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('OR OR', 'OR', $where); $where = str_replace('( OR', '(', $where); $where = str_replace('OR ) )', ')', $where); $where = str_replace('OR )', ')', $where); } $where = str_replace('AND ()', '', $where); // -------- -------- Order if (!$order) { $order = ' t1.title ASC'; } $inherit = array('bridge' => '', 'query' => ''); $query = NULL; $query2 = ''; $results = array(); self::_setStorage($tables, $config, $inherit); JPluginHelper::importPlugin('cck_storage_location'); if (isset($config['location']) && $config['location']) { $dispatcher->trigger('onCCK_Storage_LocationSearch', array($config['location'], $tables, $fields, $fields_order, &$config, &$inherit, &$results)); $query = $inherit['query']; } if ($config['doQuery'] !== false) { if ($current['stage'] == 0) { if (isset($config['query_variables']) && count($config['query_variables'])) { foreach ($config['query_variables'] as $var) { if ($var != '') { $db->setQuery($var); $db->execute(); } } } $query = $db->getQuery(true); $query->select('t0.id AS pid,t0.pk AS pk,t0.pkb AS pkb,t0.parent_id AS parent,t0.author_id AS author'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, $config['doSelect']); $query->select('t0.cck AS cck,t0.storage_location AS loc'); if ($config['location'] == 'cck_type') { $query->select($tables['#__cck_core_types']['_'] . '.id AS type_id,' . $tables['#__cck_core_types']['_'] . '.alias AS type_alias'); } else { $query->select('tt.id AS type_id,tt.alias AS type_alias'); $query->join('LEFT', '`#__cck_core_types` AS tt ON tt.name = t0.cck'); } if (isset($config['query_parts']['select'])) { if (is_string($config['query_parts']['select']) && $config['query_parts']['select'] != '' || count($config['query_parts']['select'])) { $query->select($config['query_parts']['select']); } } if ($where != '') { $query->where($where); } if (isset($config['query_parts']['having'])) { if (is_string($config['query_parts']['having']) && $config['query_parts']['having'] != '' || count($config['query_parts']['having'])) { $query->having($config['query_parts']['having']); } } if (isset($config['query_parts']['group']) && count($config['query_parts']['group'])) { $query->group($config['query_parts']['group']); } self::_buildQueryOrdering($order, $ordering, $fields_order, $dispatcher, $query, $tables, $t, $config, $current, $inherit, $user); if ($doLimit && $config['limitstart'] >= 0) { $db->setQuery($query, $config['limitstart'], $config['limitend']); } else { $db->setQuery($query, 0, $limit); } $results = $db->loadObjectList(); if ($doLimit) { $count = count($results); if ($count < $config['limitend'] && !$config['limitstart'] || $isLoadingMore) { $config['total'] = $count; } else { if ($doCount == 1 && strpos(JUri::getInstance()->toString(), 'task=') === false) { $query2 = 'SELECT COUNT(id) FROM #__cck_core WHERE cck = "' . $tables['#__cck_core']['fields']['cck'] . '"'; $config['total'] = JCckDatabaseCache::loadResult($query2); } else { if (JCck::on()) { $query1 = (string) $query; if (strpos($query1, 'HAVING') !== false) { $query->clear('order')->clear('limit'); $query2 = $db->getQuery(true); $query2->select('COUNT(*)'); $query2->from('(' . (string) $query . ') AS Count'); $db->setQuery($query2); $config['total'] = $db->loadResult(); $query2 = (string) $query2; } else { $query->clear('order')->clear('limit'); $query->clear('select')->select('COUNT(t0.id)'); $db->setQuery($query); $config['total'] = $db->loadResult(); $query2 = (string) $query; } } else { $query2 = $db->getQuery(true); $query2->select('COUNT(t0.id)'); $query2->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query2, $tables, $t, $config, $inherit, $user, $config['doSelect']); if ($where != '') { $query2->where($where); } $db->setQuery($query2, 0, 0); $config['total'] = $db->loadResult(); $query2 = (string) $query2; } } } } } else { $query = $db->getQuery(true); $query->select('t0.pk as pk'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, false); if ($where != '') { $query->where($where); } $db->setQuery($query); $results = $db->loadColumn(); } } // Debug if ($options->get('debug')) { if (!isset($query1)) { $query1 = (string) $query; } if ($query2) { $query2 .= '<br />'; } echo str_replace(array('SELECT', 'FROM', 'LEFT JOIN', 'RIGHT JOIN', 'INNER JOIN', 'WHERE', 'AND', 'ORDER BY', 'LIMIT', 'UNION', ') AS Count'), array('<br />SELECT', '<br />FROM', '<br />LEFT JOIN', '<br />RIGHT JOIN', '<br />INNER JOIN', '<br />WHERE', '<br /> AND', '<br />ORDER BY', '<br />LIMIT', '<br />UNION', '<br />) AS Count'), $query1 . '<br />' . $query2) . '<br />'; } unset($fields); unset($fields_order); unset($tables); return $results; }
public function onContentSearch($text = '', $phrase = '', $ordering = '', $areas = NULL, $fields = array(), $fields_order = array(), &$config = array(), $current = array(), $options = NULL, $user = NULL) { if (is_array($areas)) { if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) { return array(); } } else { return array(); } if (!count($fields)) { return array(); } if (!$user) { $user = JCck::getUser(); } if (!is_object($options)) { $options = new JRegistry(); } $db = JFactory::getDbo(); $dispatcher = JDispatcher::getInstance(); $doClean = false; $doLimit = false; $limit = $options->get('limit'); $glues = 1; $order = ''; $order_string = ''; $where = ''; $w = -1; $where2 = array(); $t = 1; $t2 = 1; $tables = array('#__cck_core' => array('_' => 't0', 'fields' => array(), 'join' => 1)); $colums = array(); if (isset($config['joins'][$current['stage']]) && is_array($config['joins'][$current['stage']])) { foreach ($config['joins'][$current['stage']] as $j) { if ($j->table) { if (!isset($tables[$j->table])) { $tables[$j->table] = array('_' => 't' . $t++, 'fields' => array(), 'key' => $j->column, 'join' => 2, 'join_key' => $j->column2, 'join_table' => $j->table2); } } } $t2 = count($tables); } foreach ($fields as $field) { if (!$field->state) { continue; } if ($current['stage'] != (int) $field->stage) { continue; } $name2 = $field->match_collection != '' ? '\\\\|[0-9]+\\\\|' . $field->match_collection : ''; // - if ($field->live == 'stage') { $live_options = new JRegistry(); $live_options->loadString($field->live_options); $live_value = $live_options->get('value', $field->live_value); $live_value = $live_value ? $live_value : 1; $value = $current['stages'][$live_value]; if ($value == '' && $live_options->get('default_value') != '') { $value = (string) $live_options->get('default_value'); } } else { $value = $field->value; } // - $Pf = $field->storage_field; $Pt = $field->storage_table; if (($value !== '' && $field->match_mode != 'none' || ($field->match_mode == 'empty' || $field->match_mode == 'not_empty' || $field->match_mode == 'not_null')) && $field->storage != 'none' || $field->type == 'search_operator' && $field->match_mode != 'none') { $glue = ''; $sql = ''; if ($field->match_options != '') { $field->match_options = new JRegistry($field->match_options); } // Glue if ($glues == 1) { $glue = $where != '' ? 'AND' : ''; $where .= $glue; if ($glue != '') { $where2[++$w] = $glue; } $glue = ''; } // Sql if ($field->type == 'search_generic') { if (count($field->children)) { $sql = '('; $k = 0; foreach ($field->children as $child) { if ($k > 0) { $sql .= ' OR '; } $child->match_mode = $field->match_mode; $child->match_options = $field->match_options; $child->match_value = $field->match_value; if ($child->storage && $child->storage != 'none') { $Pf = $child->storage_field; $Pt = $child->storage_table; // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $child->storage_location; // - $name = $child->storage_field2 ? $child->storage_field2 : $child->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } if (JCck::callFunc('plgCCK_Field' . $child->type, 'isFriendly')) { if (isset($fields[$child->name])) { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($fields[$child->name], $value, $config)); } else { $value2 = JCck::callFunc_Array('plgCCK_Field' . $child->type, 'getValueFromOptions', array($child, $value, $config)); } } else { $value2 = $value; } require_once JPATH_PLUGINS . '/cck_storage/' . $child->storage . '/' . $child->storage . '.php'; $sql .= JCck::callFunc_Array('plgCCK_Storage' . $child->storage, 'onCCK_StoragePrepareSearch', array(&$child, $child->match_mode, $value2, $name, $name2, $target, $fields, &$config)); } $k++; } $sql .= ')'; } } elseif ($field->type == 'search_ordering') { $sql = ''; array_pop($where2); if (isset($field->children[$value])) { if (!isset($fields_order[$field->children[$value]->name])) { $fields_order[$field->children[$value]->name] = $field->children[$value]; } } } elseif ($field->type == 'search_operator') { // Glue if ($field->value == '((') { $glues = 0; $sql = '('; } elseif ($field->value == '))') { $glues = 1; $sql = ')'; } else { if ($where2[$w] != '(') { $glue = $field->value; $sql = $glue; } } $doClean = true; } else { // - if ($Pt && !isset($tables[$Pt])) { $tables[$Pt] = array('_' => 't' . $t, 'fields' => array(), 'join' => 1); $t++; } $tables[$Pt]['location'] = $field->storage_location; // - $name = $field->storage_field2 ? $field->storage_field2 : $field->name; if ($Pt != '') { $target = $tables[$Pt]['_'] . '.' . $Pf; $tables[$Pt]['fields'][$Pf] = $Pt == '#__cck_core' ? $value : $name; } require_once JPATH_PLUGINS . '/cck_storage/' . $field->storage . '/' . $field->storage . '.php'; $sql = JCck::callFunc_Array('plgCCK_Storage' . $field->storage, 'onCCK_StoragePrepareSearch', array(&$field, $field->match_mode, $value, $name, $name2, $target, $fields, &$config)); } $where .= $sql; $where2[++$w] = $sql; } else { if (@$glue) { $where2[$w] = ''; } // unset( $fields[$field->name] ); } } // Finalize $where = implode(' ', $where2); if ($doClean !== false) { $where = preg_replace('/\\s+/', ' ', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('AND ( )', '', $where); $where = str_replace('OR OR', 'OR', $where); $where = str_replace('( OR', '(', $where); $where = str_replace('OR )', ')', $where); } $where = str_replace('AND ()', '', $where); // -------- -------- Order if (!$order) { $order = ' t1.title ASC'; } $inherit = array('bridge' => '', 'query' => ''); $query = NULL; $results = array(); self::_setStorage($tables, $config, $inherit); JPluginHelper::importPlugin('cck_storage_location'); if (isset($config['location']) && $config['location']) { $dispatcher->trigger('onCCK_Storage_LocationSearch', array($config['location'], $tables, $fields, $fields_order, &$config, &$inherit, &$results)); $query = $inherit['query']; } if ($config['doQuery'] !== false) { if ($current['stage'] == 0) { $query = $db->getQuery(true); $query->select('t0.id AS pid,t0.pk AS pk,t0.pkb AS pkb'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, $config['doSelect']); $query->select('t0.cck AS cck,t0.storage_location AS loc'); $query->select('tt.id AS type_id,tt.alias AS type_alias'); $query->join('LEFT', '`#__cck_core_types` AS tt ON tt.name = t0.cck'); if (isset($config['query_parts']['select']) && $config['query_parts']['select'] != '') { $query->select($config['query_parts']['select']); } if ($where != '') { $query->where($where); } if (isset($config['query_parts']['having']) && $config['query_parts']['having'] != '') { $query->having($config['query_parts']['having']); } $query->group('t0.pk'); self::_buildQueryOrdering($order, $ordering, $fields_order, $dispatcher, $query, $tables, $t, $config, $current, $inherit, $user); if ($doLimit) { $db->setQuery($query, $config['limitstart'], $config['limitend']); } else { $db->setQuery($query, 0, $limit > 0 ? $limit : ''); } $results = $db->loadObjectList(); } else { $query = $db->getQuery(true); $query->select('t0.pk as pk'); $query->from('`#__cck_core` AS t0'); self::_buildQuery($dispatcher, $query, $tables, $t, $config, $inherit, $user, false); if ($where != '') { $query->where($where); } $query->group('t0.pk'); $db->setQuery($query); $results = $db->loadColumn(); } } // Debug if ($options->get('debug')) { echo str_replace(array('SELECT', 'FROM', 'LEFT JOIN', 'WHERE', 'ORDER BY', 'UNION'), array('<br />SELECT', '<br />FROM', '<br />LEFT JOIN', '<br />WHERE', '<br />ORDER BY', '<br />UNION'), (string) $query) . '<br /><br />'; } unset($fields); unset($fields_order); unset($tables); return $results; }
public static function onCCK_Field_LinkBeforeRenderContent($process, &$fields, &$storages, &$config = array()) { $name = $process['name']; if (isset($process['form']) && $process['form'] == '-2') { $fieldname = $process['fieldname']; $form = isset($fields[$fieldname]) ? $fields[$fieldname]->value : ''; $user = JCck::getUser(); $type_id = (int) JCckDatabase::loadResult('SELECT id FROM #__cck_core_types WHERE name = "' . $form . '"'); $canCreate = $type_id ? $user->authorise('core.create', 'com_cck.form.' . $type_id) : false; // Check Permissions if ($canCreate) { $fields[$name]->link = str_replace('#' . $fieldname . '#', $form, $fields[$name]->link); $fields[$name]->html = str_replace('#' . $fieldname . '#', $form, $fields[$name]->html); $fields[$name]->typo = str_replace('#' . $fieldname . '#', $form, $fields[$name]->typo); } else { $fields[$name]->link = ''; $target = $fields[$name]->typo_target; if ($fields[$name]->typo) { $fields[$name]->typo = $fields[$name]->{$target}; // todo: str_replace link+target par target } else { $fields[$name]->html = $fields[$name]->{$target}; } } } else { $name = $process['name']; if (count($process['matches'][1])) { self::g_setCustomVars($process, $fields, $name); } } }
public static function replaceLive($str, $name = '') { $app = JFactory::getApplication(); if (!$name) { $name = uniqid(); } if ($str != '') { $str = str_replace('$uri->get', '$uri->get', $str); if (strpos($str, '$uri->get') !== false) { $matches = ''; $search = '#\\$uri\\->get([a-zA-Z]*)\\( ?\'?([a-zA-Z0-9_]*)\'? ?\\)(;)?#'; preg_match_all($search, $str, $matches); if (count($matches[1])) { foreach ($matches[1] as $k => $v) { $variable = $matches[2][$k]; if ($v == 'Current') { $request = $variable == 'true' ? JURI::getInstance()->toString() : JURI::current(); $str = str_replace($matches[0][$k], $request, $str); } elseif ($v == 'Array') { $value = ''; $custom_v = ''; static $custom_vars = array(); if (!isset($custom_vars[$name])) { $custom_vars[$name] = explode('&', $str); } if (count($custom_vars[$name])) { foreach ($custom_vars[$name] as $custom_var) { if (strpos($custom_var, $matches[0][$k]) !== false) { $custom_v = substr($custom_var, 0, strpos($custom_var, '=')); } } } if ($custom_v != '') { $values = $app->input->get($variable, '', 'array'); if (is_array($values) && count($values)) { foreach ($values as $val) { $value .= '&' . $custom_v . '[]=' . $val; } } } $str = str_replace('&' . $custom_v . '=' . $matches[0][$k], $value, $str); } else { $request = 'get' . $v; $str = str_replace($matches[0][$k], $app->input->{$request}($variable, ''), $str); } } } } } if ($str != '' && strpos($str, '$user->') !== false) { $user = JCck::getUser(); if (strpos($str, '$user->getAuthorisedViewLevels()') !== false) { $access = implode(',', $user->getAuthorisedViewLevels()); $str = str_replace('$user->getAuthorisedViewLevels()', $access, $str); } $matches = ''; $search = '#\\$user\\->([a-zA-Z0-9_]*)#'; preg_match_all($search, $str, $matches); if (count($matches[1])) { foreach ($matches[1] as $k => $v) { $str = str_replace($matches[0][$k], $user->{$v}, $str); } } } if ($str != '' && strpos($str, 'J(') !== false) { $matches = ''; $search = '#J\\((.*)\\)#U'; preg_match_all($search, $str, $matches); if (count($matches[1])) { foreach ($matches[1] as $text) { $str = str_replace('J(' . $text . ')', JText::_('COM_CCK_' . str_replace(' ', '_', trim($text))), $str); } } } return $str; }
protected function _setUIX($view, $layout) { if (JCck::getUIX() == 'compact') { define('_C0_TEXT', 'FOLDER'); define('_C2_TEXT', 'FORM'); define('_C4_TEXT', 'LIST'); define('CCK_BUILDER', 'FORM_BUILDER'); define('CCK_LABEL', 'SEBLOD 3.x nano'); define('CCK_LABEL1', 'SEBLOD'); define('CCK_LABEL2', 'nano'); } else { define('_C0_TEXT', 'APP_FOLDER'); define('_C2_TEXT', 'CONTENT_TYPE'); define('_C4_TEXT', 'SEARCH_TYPE'); define('CCK_BUILDER', 'APP_BUILDER'); define('CCK_LABEL', 'SEBLOD 3.x'); define('CCK_LABEL1', 'SEBLOD'); define('CCK_LABEL2', ''); } if ($view == 'form' || $view == 'list' || $view == 'cck' && $layout == 'welcome') { return; } $user = JCck::getUser(0, false, true); }
public static function apply($type, &$total, $params = array()) { $user = JCck::getUser(); $my_groups = $user->groups; /* $user->getAuthorisedGroups(); */ $currency = JCckEcommerce::getCurrency(); $promotions = JCckEcommerce::getPromotions($type); $res = 0; $results = array('items' => array()); $text = ''; if (count($promotions)) { foreach ($promotions as $p) { if (isset($params['target']) && $params['target']) { if ($params['target'] == 'order' && $p->target == 0) { // OK } elseif ($params['target'] == 'product') { if ($p->target == 1) { // OK } elseif ($p->target == 2) { $products = self::getTargets($p->id); if (!isset($products[$params['target_id']])) { continue; } } elseif ($p->target == -2) { $products = self::getTargets($p->id); if (isset($products[$params['target_id']])) { continue; } } else { continue; } } else { continue; } } if ($p->type == 'coupon') { if ($p->code && $p->code != @$params['code']) { continue; } } $groups = explode(',', $p->groups); if (count(array_intersect($my_groups, $groups)) > 0) { switch ($p->discount) { case 'free': $promotion = 0; $res = $promotion; $text = JText::_('COM_CCK_FREE'); $total = $promotion; $results['items'][$p->id] = array('type' => $p->type, 'promotion' => $p->discount, 'promotion_amount' => '', 'text' => $text, 'title' => $p->title, 'code' => @(string) $params['code']); break; case 'minus': $promotion = $p->discount_amount * -1; $res += $promotion; $text = '- ' . JCckEcommerceCurrency::format($p->discount_amount); $total += $promotion; $total = $total < 0 ? 0 : $total; $results['items'][$p->id] = array('type' => $p->type, 'promotion' => $p->discount, 'promotion_amount' => (string) $promotion, 'text' => $text, 'title' => $p->title, 'code' => @(string) $params['code']); break; case 'percentage': $promotion = $total * $p->discount_amount / 100; $res = $promotion; $text = '- ' . $p->discount_amount . ' %'; $total = $total - $promotion; $results['items'][$p->id] = array('type' => $p->type, 'promotion' => $p->discount, 'promotion_amount' => (string) $promotion, 'text' => $text, 'title' => $p->title, 'code' => @(string) $params['code']); break; default: break; } } } } if ($res) { $results['text'] = $text; $results['total'] = (double) $res; return (object) $results; } return null; }