Exemple #1
0
 protected function _delete($pk, $location, $base)
 {
     $id = JCckDatabase::loadResult('SELECT id FROM #__cck_core WHERE storage_location = "' . (string) $location . '" AND pk = ' . (int) $pk);
     if (!$id) {
         return true;
     }
     $table = JCckTable::getInstance('#__cck_core', 'id', $id);
     $type = $table->cck;
     $pkb = (int) $table->pkb;
     $table->delete();
     if ($pkb > 0) {
         $table = JTable::getInstance('content');
         $table->delete($pkb);
     }
     $tables = JCckDatabase::loadColumn('SHOW TABLES');
     $prefix = JFactory::getApplication()->getCfg('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_' . $type, $tables)) {
         $table = JCckTable::getInstance('#__cck_store_form_' . $type, 'id', $pk);
         if ($table->id) {
             $table->delete();
         }
     }
 }
Exemple #2
0
 public function save($key = null, $urlVar = null)
 {
     JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
     $app = JFactory::getApplication();
     $model = $this->getModel('form');
     $preconfig = $app->input->post->get('config', array(), 'array');
     $task = $this->getTask();
     $config = $model->store($preconfig);
     $id = $config['pk'];
     if ($config['validate'] == 'retry') {
         parent::display();
         return true;
     }
     if ($id) {
         if ($config['stage'] > -1) {
             $link = 'index.php?option=' . CCK_COM . '&view=form&type=' . $preconfig['type'] . '&id=' . $id . $this->_getRedirectQuery();
             if ($config['stage'] > 0) {
                 $link .= '&stage=' . $config['stage'];
             }
             $this->setRedirect(htmlspecialchars_decode($link));
             return;
         }
         if ($config['message_style']) {
             if (isset($config['message'])) {
                 $msg = $config['doTranslation'] ? JText::_('COM_CCK_' . str_replace(' ', '_', trim($config['message']))) : $config['message'];
             } else {
                 $msg = JText::_('COM_CCK_SUCCESSFULLY_SAVED');
             }
             $msgType = $config['message_style'];
         } else {
             $msg = '';
             $msgType = '';
         }
     } else {
         $msg = JText::_('JERROR_AN_ERROR_HAS_OCCURRED');
         $msgType = 'error';
     }
     switch ($task) {
         case 'apply':
             $link = 'index.php?option=' . CCK_COM . '&view=form&type=' . $preconfig['type'] . '&id=' . $id . $this->_getRedirectQuery();
             break;
         case 'save2new':
             $link = 'index.php?option=' . CCK_COM . '&view=form&type=' . $preconfig['type'] . $this->_getRedirectQuery();
             break;
         case 'save2view':
             $location = JCckDatabase::loadResult('SELECT storage_location FROM #__cck_core WHERE id = ' . (int) $id);
             $sef = 0;
             $itemId2 = 0;
             if ($location) {
                 require_once JPATH_SITE . '/plugins/cck_storage_location/' . $location . '/' . $location . '.php';
                 $link = JCck::callFunc_Array('plgCCK_Storage_Location' . $location, 'getRoute', array($config['pk'], $sef, $itemId2, array('type' => $config['type'])));
                 $link = str_replace('/administrator/', '/', $link);
                 break;
             }
         default:
             $link = $this->_getRedirectQuery(true);
             break;
     }
     $this->setRedirect(htmlspecialchars_decode($link), $msg, $msgType);
 }
Exemple #3
0
 public static function g_onCCK_PaymentValidate($data, $success, &$config)
 {
     $update = 'pay_return = "' . JCckDatabase::escape(json_encode($data['order'])) . '",' . 'pay_return_payments = "' . JCckDatabase::escape(json_encode($data['payments'])) . '",' . 'state = ' . $data['order_state'];
     JCckDatabase::execute('UPDATE #__cck_more_ecommerce_orders SET ' . $update . ' WHERE pay_key = "' . $config['pay_key'] . '"');
     if (!$success) {
         return;
     }
     // Cart
     $cart_id = (int) JCckDatabase::loadResult('SELECT a.id FROM #__cck_more_ecommerce_carts AS a WHERE a.pay_key = "' . $config['pay_key'] . '"');
     if ($cart_id) {
         JCckDatabase::execute('UPDATE #__cck_more_ecommerce_carts SET pay_key = "" WHERE id = ' . $cart_id);
         JCckDatabase::execute('DELETE a.* FROM #__cck_more_ecommerce_cart_product AS a WHERE a.cart_id = ' . $cart_id);
     }
     // Execute Processings (Invoice, Notifications, ...)
     if (JCckToolbox::getConfig()->get('processing', 0)) {
         $event = 'onCckPaymentSuccess';
         $processing = JCckDatabaseCache::loadObjectListArray('SELECT type, scriptfile, options FROM #__cck_more_processings WHERE published = 1 ORDER BY ordering', 'type');
         if (isset($processing[$event])) {
             foreach ($processing[$event] as $p) {
                 if (is_file(JPATH_SITE . $p->scriptfile)) {
                     $options = new JRegistry($p->options);
                     include_once JPATH_SITE . $p->scriptfile;
                 }
             }
         }
     }
 }
Exemple #4
0
 public static function getGateway()
 {
     $user = JFactory::getUser();
     $access = implode(',', $user->getAuthorisedViewLevels());
     $name = JCckDatabase::loadResult('SELECT type' . ' FROM #__cck_more_ecommerce_gateways' . ' WHERE published = 1 AND access IN (' . $access . ')' . ' ORDER BY id DESC');
     return $name;
 }
 public static function getRow($id, $content_type = '')
 {
     if (!$id) {
         return NULL;
     }
     $index = $id . '_' . $content_type;
     if (isset(self::$_items[$index])) {
         return self::$_items[$index];
     }
     $row = JTable::getInstance('content');
     $row->load($id);
     if (!$content_type) {
         $content_type = JCckDatabase::loadResult('SELECT cck FROM #__cck_core WHERE storage_location = "joomla_article" AND pk = ' . $row->id);
     }
     if ($content_type) {
         $fields = JCckDatabase::loadObject('SELECT * FROM #__cck_store_form_' . $content_type . ' WHERE id = ' . $row->id);
         if (count($fields)) {
             foreach ($fields as $k => $v) {
                 $row->{$k} = $v;
             }
         }
     }
     self::$_items[$index] = $row;
     return $row;
 }
 public static function getAttribute($fieldname, $attribute)
 {
     if (!$fieldname || !$attribute) {
         return false;
     }
     $res = JCckDatabase::loadResult('SELECT s.' . $attribute . ' FROM #__cck_core_fields AS s' . ' WHERE s.name="' . $fieldname . '"');
     return $res;
 }
Exemple #7
0
 public static function loadResult($query)
 {
     static $cache = array();
     $idx = md5($query);
     if (!isset($cache[$idx])) {
         $cache[$idx] = parent::loadResult($query);
     }
     return $cache[$idx];
 }
Exemple #8
0
 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;
     }
 }
Exemple #9
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];
 }
Exemple #10
0
 public static function countItems($store_id, $object = 'joomla_article')
 {
     $cache = array();
     $count = 0;
     $user = JFactory::getUser();
     if (!isset($cache[$store_id])) {
         $cache[$store_id] = JCckDatabase::loadResult('SELECT COUNT(a.id) FROM #__cck_core AS a' . ' LEFT JOIN #__content AS b ON (b.id = a.pk AND a.storage_location = "joomla_article")' . ' WHERE a.store_id = ' . $store_id . ' AND b.state = 1');
     }
     return $cache[$store_id];
 }
Exemple #11
0
 public static function &getUser($userid = 0, $content_type = '', $profile = true)
 {
     if (!$userid) {
         $user = JFactory::getUser();
     } else {
         $user = JFactory::getUser($userid);
     }
     // Core
     if ($user->id && $user->guest != 1) {
         $user->session_id = null;
         $user->where_clause = 'user_id=' . $user->id;
     } else {
         $user->session_id = JFactory::getSession()->getId();
         if (empty($user->session_id)) {
             $user->session_id = uniqid();
             /* Not good, but better than empty */
         }
         $user->where_clause = 'session_id="' . $user->session_id . '"';
     }
     // IP
     $user->ip = getenv('REMOTE_ADDR');
     // $_SERVER["REMOTE_ADDR"];
     // More
     if ($user->id && $profile) {
         if (!$content_type) {
             $content_type = '';
             // todo: config
             if (!$content_type) {
                 $content_type = JCckDatabase::loadResult('SELECT cck FROM #__cck_core WHERE storage_location = "joomla_user" AND pk = ' . (int) $user->id);
             }
         }
         $db = JFactory::getDbo();
         $prefix = $db->getPrefix();
         $tables = $db->getTableList();
         $tables = array_flip($tables);
         if (isset($tables[$prefix . 'cck_store_item_users'])) {
             $fields = JCckDatabase::loadObject('SELECT * FROM #__cck_store_item_users WHERE id = ' . (int) $user->id);
             if (count($fields)) {
                 foreach ($fields as $k => $v) {
                     $user->{$k} = $v;
                 }
             }
         }
         if (isset($tables[$prefix . 'cck_store_form_' . $content_type])) {
             $fields = JCckDatabase::loadObject('SELECT * FROM #__cck_store_form_' . $content_type . ' WHERE id = ' . (int) $user->id);
             if (count($fields)) {
                 foreach ($fields as $k => $v) {
                     $user->{$k} = $v;
                 }
             }
         }
     }
     return $user;
 }
Exemple #12
0
 function prepareDisplay()
 {
     $app = JFactory::getApplication();
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->option = $app->input->get('option', '');
     $this->state = $this->get('State');
     // Check Errors
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->item->cck_type = $this->state->get('content_type', '');
     $this->item->skip = $this->state->get('skip');
     if (@$this->item->id > 0) {
         $this->isNew = 0;
         $this->panel_class = 'closed';
         $this->panel_style = 'display:none; ';
         $name = $this->item->name;
         $app->setUserState(CCK_COM . '.edit.search.client', NULL);
     } else {
         $this->isNew = 1;
         $this->panel_class = 'open';
         $this->panel_style = '';
         $name = '';
         if ($this->item->cck_type != '') {
             $this->item->storage_location = JCckDatabase::loadResult('SELECT storage_location FROM #__cck_core_types WHERE name = "' . $this->item->cck_type . '"');
             if ($this->item->storage_location == 'none') {
                 $this->item->storage_location = '';
             }
         }
         $this->tpl_list = $this->state->get('tpl.list');
     }
     $this->item->folder = Helper_Admin::getSelected($this->vName, 'folder', $this->item->folder, 1);
     $this->item->published = Helper_Admin::getSelected($this->vName, 'state', $this->item->published, 1);
     if ($this->item->skip != '') {
         $this->item->client = $this->item->skip;
         $this->item->master = $this->item->client == 'list' || $this->item->client == 'item' ? 'content' : ($this->item->client == 'order' ? 'order' : 'search');
         $this->item->layer = $app->input->getString('layer', 'fields');
         $P = 'template_' . $this->item->client;
         $force_template = $this->item->client == 'list' ? $this->state->get('tpl.list') : Helper_Workshop::getDefaultTemplate();
     } else {
         $this->item->client = $this->isNew ? 'search' : $this->state->get('client', $app->input->cookie->getString('cck_search' . $name . '_client', 'search'));
         $this->item->master = $this->item->client == 'list' || $this->item->client == 'item' ? 'content' : ($this->item->client == 'order' ? 'order' : 'search');
         $this->item->layer = $app->input->getString('layer', 'fields');
         $P = 'template_' . $this->item->client;
         $force_template = $this->item->client == 'list' ? '' : Helper_Workshop::getDefaultTemplate();
     }
     $this->style = $this->item->client != 'order' ? Helper_Workshop::getTemplateStyle($this->vName, $this->item->{$P}, $this->state->get('tpl.' . $this->item->client, $force_template)) : '';
     $this->item->template = isset($this->style->template) ? $this->style->template : '';
     $this->insidebox = Helper_Admin::addInsidebox($this->isNew);
     Helper_Admin::addToolbarEdit($this->vName, 'COM_CCK_' . _C4_TEXT, array('isNew' => $this->isNew, 'folder' => $this->state->get('filter.folder'), 'checked_out' => $this->item->checked_out), array('template' => $this->item->template));
 }
Exemple #13
0
 protected function postSaveHook(CCKModelSite &$model, $validData = array())
 {
     $recordId = $model->getState($this->context . '.id');
     if ($recordId == 10 || $recordId == 500) {
         $db = JFactory::getDbo();
         $params = JCckDatabase::loadResult('SELECT params FROM #__extensions WHERE element = "com_cck"');
         $config = JCckDev::fromJSON($params, 'object');
         $config->multisite = 1;
         $params = $db->escape(JCckDev::toJSON($config));
         JCckDatabase::execute('UPDATE #__extensions SET params = "' . $params . '" WHERE element = "com_cck"');
     }
 }
Exemple #14
0
 public function getItems()
 {
     if ($items = parent::getItems()) {
         $group_map = JCckDatabase::loadObjectList('SELECT a.group_id, COUNT( DISTINCT a.user_id ) AS num FROM #__user_usergroup_map AS a GROUP BY a.group_id', 'group_id');
         foreach ($items as $item) {
             $viewlevels = $item->guest_only_viewlevel ? $item->guest_only_viewlevel . ',' . $item->viewlevels : $item->viewlevels;
             $query = 'SELECT COUNT(a.id) FROM #__cck_core AS a LEFT JOIN #__content AS b ON b.id = a.pk WHERE a.storage_location = "joomla_article" AND b.access IN (' . $viewlevels . ');';
             $item->articles = JCckDatabase::loadResult($query);
             $groups = $item->guest_only_group ? $item->guest_only_group . ',' . $item->groups : $item->groups;
             $query = 'SELECT COUNT(DISTINCT a.user_id) FROM #__user_usergroup_map AS a WHERE a.group_id IN (' . $groups . ');';
             $item->users = JCckDatabase::loadResult($query);
         }
     }
     return $items;
 }
Exemple #15
0
 public static function applyTypeOptions(&$config)
 {
     $options = JCckDatabase::loadResult('SELECT options_' . $config['client'] . ' FROM #__cck_core_types WHERE name ="' . (string) $config['type'] . '"');
     $options = JCckDev::fromJSON($options);
     if (isset($options['message']) && $options['message'] != '') {
         $config['message'] = $options['message'];
     }
     if (isset($options['data_integrity_excluded'])) {
         $options['data_integrity_excluded'] = explode(',', str_replace(' ', ',', trim($options['data_integrity_excluded'])));
     } else {
         $options['data_integrity_excluded'] = array();
     }
     $config['message_style'] = isset($options['message_style']) ? $options['message_style'] : 'message';
     $config['options'] = $options;
 }
Exemple #16
0
 public static function getCartDefinition($name)
 {
     static $definitions = array();
     if (!isset($definitions[$name])) {
         $definitions[$name] = JCckDatabase::loadObject('SELECT title, name, storage_location, storage_table, storage_field, multicart, multistore, ordering, quantity, request, request_code, request_payment, request_payment_table, request_payment_field, request_shipping, request_shipping_field, request_state_id' . ' FROM #__cck_more_ecommerce_cart_definitions WHERE name = "' . $name . '"');
         if (strpos($definitions[$name]->request_payment_field, '$') !== false) {
             $definitions[$name]->request_payment_field = str_replace('$', strtolower(JCckEcommerce::getCurrency()->code), $definitions[$name]->request_payment_field);
         }
         $definitions[$name]->request_state = 0;
         if ($definitions[$name]->request_state_id) {
             $definitions[$name]->request_state = JCckDatabase::loadResult('SELECT value FROM #__cck_more_ecommerce_order_states WHERE id = ' . (int) $definitions[$name]->request_state_id);
         }
     }
     return $definitions[$name];
 }
Exemple #17
0
 function prepareDisplay()
 {
     $app = JFactory::getApplication();
     $model = $this->getModel();
     $this->form = $this->get('Form');
     $this->item = $this->get('Item');
     $this->option = $app->input->get('option', '');
     $this->state = $this->get('State');
     // Check Errors
     if (count($errors = $this->get('Errors'))) {
         JError::raiseError(500, implode("\n", $errors));
         return false;
     }
     $this->isNew = @$this->item->id > 0 ? 0 : 1;
     $type = $this->item->e_type ? $this->item->e_type : 'type';
     $this->item->title = JCckDatabase::loadResult('SELECT title FROM #__cck_core_' . $type . 's WHERE id = ' . (int) $this->item->e_id);
     Helper_Admin::addToolbarEdit($this->vName, _C6_TEXT, array('isNew' => $this->isNew, 'folder' => 0, 'checked_out' => $this->item->checked_out));
 }
Exemple #18
0
 public function delete($pk = null)
 {
     if ($this->id) {
         if (strpos($this->storage_table, '#__cck_store_item_') !== false || strpos($this->storage_table, '#__cck_store_form_') !== false) {
             if (!$this->storage_field2) {
                 $db = JFactory::getDbo();
                 $table = (string) $this->storage_table;
                 $column = $this->storage_field ? $this->storage_field : $this->name;
                 $columns = $db->getTableColumns($table);
                 if (isset($columns[$column])) {
                     if (JCckDatabase::loadResult('SELECT COUNT(id) FROM #__cck_core_fields WHERE storage_table = "' . (string) $table . '" AND storage_field = "' . (string) $column . '"') == 1) {
                         JCckDatabase::execute('ALTER TABLE ' . JCckDatabase::quoteName($table) . ' DROP COLUMN ' . JCckDatabase::quoteName((string) $column));
                     }
                 }
             }
         }
     }
     return parent::delete();
 }
Exemple #19
0
 public function prepareExport($id = 0)
 {
     $config = JFactory::getConfig();
     $tmp_path = $config->get('tmp_path');
     $tmp_dir = uniqid('cck_');
     $path = $tmp_path . '/' . $tmp_dir;
     $extension = JCckDatabase::loadObject('SELECT name, type, element, folder FROM #__extensions WHERE extension_id=' . (int) $id);
     if (!$extension) {
         return;
     }
     jimport('cck.base.install.export');
     $name = $extension->element;
     $prefix = CCK_Export::getPrefix($extension->type);
     $src = JPATH_SITE . '/plugins/' . $extension->folder . '/' . $extension->element;
     $xml = JCckDev::fromXML($src . '/' . $name . '.xml');
     $version = isset($xml->version) ? '_' . $xml->version : '';
     $filename = $prefix . '_' . $extension->folder . '_' . $name . $version;
     $path_zip = $tmp_path . '/' . $filename . '.zip';
     if (!$filename) {
         return;
     }
     if (JCckDatabase::loadResult('SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "com_cck_packager"') > 0) {
         $params = JComponentHelper::getParams('com_cck_packager');
         $copyright = $params->get('copyright');
     } else {
         $copyright = '';
     }
     if ($src && JFolder::exists($src)) {
         if ($copyright) {
             CCK_Export::update($src, $copyright);
         }
         JFolder::copy($src, $path);
         CCK_Export::clean($path);
     }
     CCK_Export::exportLanguage($src . '/' . $name . '.xml', JPATH_ADMINISTRATOR, $path, $copyright);
     CCK_Export::findFields(array($src . '/tmpl/edit.php', $src . '/tmpl/edit2.php'), $path . '/install');
     CCK_Export::update($path . '/install', $copyright);
     return CCK_Export::zip($path, $path_zip);
 }
 public function postStore($pk)
 {
     $data = JRequest::get('post');
     $client = $data['client'];
     if (isset($data['li_end']) && $data['li_end'] == '1') {
         $this->storeMore($pk, $data['client'], $data['ff'], $data['ffp']);
         if (isset($data['cck_type']) && $data['cck_type'] != '') {
             $data['ff2'] = array('cck' => 1);
             $data['ffp2'] = array('cck' => array('access' => '1', 'conditional' => '', 'conditional_options' => '', 'label' => 'Type', 'label2' => 'Type', 'live' => '', 'live_options' => '', 'live_value' => $data['cck_type'], 'match_collection' => '', 'match_mode' => 'exact', 'match_value' => '', 'required' => '', 'required_alert' => '', 'stage' => '0', 'validation' => '', 'validation_options' => '', 'variation' => 'hidden', 'variation_override' => ''));
             $this->storeMore($pk, 'search', $data['ff2'], $data['ffp2']);
         }
     }
     if (isset($data['quick_menuitem']) && $data['quick_menuitem']) {
         if (is_file(JPATH_SITE . '/libraries/joomla/database/table/menu.php')) {
             require_once JPATH_SITE . '/libraries/joomla/database/table/menu.php';
         }
         $quick_item = explode('.', $data['quick_menuitem']);
         $item = JTable::getInstance('Menu');
         $item->id = 0;
         $item->title = $data['title'];
         $item->menutype = $quick_item[0];
         $item->parent_id = $quick_item[1];
         $item->published = 1;
         $item->component_id = JCckDatabase::loadResult('SELECT extension_id FROM #__extensions WHERE type = "component" AND element = "com_cck"');
         $item->link = 'index.php?option=com_cck&view=list&search=' . $data['name'] . '&task=search';
         $item->params = '{}';
         $item->type = 'component';
         $item->client_id = 0;
         $item->home = 0;
         $item->language = '*';
         $item->template_style_id = 0;
         $item->setLocation($quick_item[1], 'last-child');
         $item->check();
         $item->store();
     }
 }
Exemple #21
0
			<th width="20%" class="center hidden-phone nowrap" colspan="2"><?php 
echo JHtml::_('grid.sort', 'COM_CCK_' . _C0_TEXT, 'folder_title', $listDir, $listOrder);
?>
</th>
			<th width="15%" class="center hidden-phone nowrap"><?php 
echo JText::_('COM_CCK_STORAGE');
?>
</th>
			<th width="15%" class="center hidden-phone nowrap"><?php 
echo JHtml::_('grid.sort', 'COM_CCK_TYPE', 'a.type', $listDir, $listOrder);
?>
</th>
            <?php 
if ($location == 'folder_id' && $search > 0) {
    $canOrder = $user->authorise('core.edit.state', 'com_cck.folder');
    $saveOrder = JCckDatabase::loadResult('SELECT featured FROM #__cck_core_folders WHERE id = ' . (int) $search);
    ?>
                <th width="10%" class="center hidden-phone nowrap">
                    <?php 
    echo JHtml::_('grid.sort', 'JGRID_HEADING_ORDERING', 'a.ordering', $listDir, $listOrder);
    if ($canOrder && $saveOrder) {
        echo JHtml::_('grid.order', $this->items, 'filesave.png', 'fields.saveorder');
    }
    ?>
                </th>
            <?php 
} else {
    ?>
                <th width="10%" class="center nowrap"><?php 
    echo JHtml::_('grid.sort', 'COM_CCK_STATUS', 'a.published', $listDir, $listOrder);
    ?>
 public static function afterImportTemplate_Style($elemtype, &$table, $xml, &$data)
 {
     if ($table->client_id == '') {
         $table->client_id = 0;
     }
     if ($table->home == '') {
         $table->home = 0;
     }
     // Store
     $pk = JCckDatabase::loadResult('SELECT id FROM #__' . $elemtype . 's WHERE template = "' . (string) $table->template . '" AND title = "' . (string) $table->title . '"');
     if ($pk > 0) {
         $table->id = $pk;
     }
     $table->store();
 }
 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 : '') : '';
     }
 }
Exemple #24
0
    public function onCCK_FieldPrepareForm(&$field, $value = '', &$config = array(), $inherit = array(), $return = false)
    {
        if (self::$type != $field->type) {
            return;
        }
        self::$path = parent::g_getPath(self::$type . '/');
        parent::g_onCCK_FieldPrepareForm($field, $config);
        if (is_file(JPATH_LIBRARIES . '/joomla/html/html/category.php')) {
            require_once JPATH_LIBRARIES . '/joomla/html/html/category.php';
        }
        // Init
        if (count($inherit)) {
            $id = isset($inherit['id']) && $inherit['id'] != '' ? $inherit['id'] : $field->name;
            $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name;
        } else {
            $id = $field->name;
            $name = $field->name;
        }
        $app = JFactory::getApplication();
        $value = $value != '' ? $value : $field->defaultvalue;
        $value = $value != ' ' ? $value : '';
        // Validate
        $validate = '';
        if ($config['doValidation'] > 1) {
            plgCCK_Field_ValidationRequired::onCCK_Field_ValidationPrepareForm($field, $id, $config);
            $validate = count($field->validate) ? ' validate[' . implode(',', $field->validate) . ']' : '';
        }
        // Prepare
        if (parent::g_isStaticVariation($field, $field->variation, true)) {
            $form = '';
            $field->text = '';
            parent::g_getDisplayVariation($field, $field->variation, $value, $field->text, $form, $id, $name, '<select', '', '', $config);
        } elseif ($field->variation == 'value') {
            $form = '';
            $field->text = JCckDatabase::loadResult('SELECT title FROM #__categories WHERE id = ' . (int) $value);
            parent::g_getDisplayVariation($field, $field->variation, $value, $field->text, $form, $id, $name, '<select', '', '', $config);
        } else {
            $opt = '';
            $options2 = JCckDev::fromJSON($field->options2);
            if (trim($field->selectlabel)) {
                if ($config['doTranslation']) {
                    $field->selectlabel = JText::_('COM_CCK_' . str_replace(' ', '_', trim($field->selectlabel)));
                }
                $opt = '<option value="' . ($field->storage_field == 'parent_id' ? 1 : '') . '">' . '- ' . $field->selectlabel . ' -' . '</option>';
            }
            if ($config['client'] == 'search') {
                $opt .= '<option value="">' . '- ' . JText::_('COM_CCK_ALL_CATEGORIES') . ' -' . '</option>';
            }
            $multiple = $field->bool3 == 1 ? 'multiple="multiple"' : '';
            $size = $field->rows ? $field->rows : 1;
            $extension = $app->input->getString('extension', @$options2['extension']);
            $extension = $extension ? $extension : 'com_content';
            $class = 'inputbox select' . $validate . ($field->css ? ' ' . $field->css : '');
            $xml = '
						<form>
							<field
								type="' . self::$type2 . '"
								name="' . $name . '"
								id="' . $id . '"
								label="' . htmlspecialchars($field->label) . '"
								extension="' . $extension . '"
								' . $multiple . '
								class="' . $class . '"
								size="' . $size . '"
							>' . $opt . '</field>
						</form>
					';
            $form = JForm::getInstance($id, $xml);
            if ($config['client'] == 'admin' || $config['client'] == 'site' || $config['client'] == 'search') {
                if ($config['pk']) {
                    $form->setFieldAttribute($name, 'action', 'core.edit');
                    $form->setFieldAttribute($name, 'action', 'core.edit.own');
                } else {
                    $form->setFieldAttribute($name, 'action', 'core.create');
                }
            }
            $form = $form->getInput($name, '', $value);
            if ($field->attributes) {
                $form = str_replace('<select', '<select ' . $field->attributes, $form);
            }
            // Set
            if (!$field->variation) {
                $field->form = $form;
                if ($field->script) {
                    parent::g_addScriptDeclaration($field->script);
                }
            } else {
                $field->text = JCckDatabase::loadResult('SELECT title FROM #__categories WHERE id = ' . (int) $value);
                parent::g_getDisplayVariation($field, $field->variation, $value, $field->text, $form, $id, $name, '<select', '', '', $config);
            }
        }
        $field->value = $value;
        // Return
        if ($return === true) {
            return $field;
        }
    }
Exemple #25
0
 public function onCCK_FieldPrepareStore(&$field, $value = '', &$config = array(), $inherit = array(), $return = false)
 {
     if (self::$type != $field->type) {
         return;
     }
     // Init
     if (count($inherit)) {
         $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name;
     } else {
         $name = $field->name;
     }
     // Validate
     parent::g_onCCK_FieldPrepareStore_Validation($field, $name, $value, $config);
     if ($field->state != 'disabled') {
         parent::g_addProcess('afterStore', self::$type, $config, array('name' => $field->storage_field2 ? $field->storage_field2 : $field->storage_field, 'value' => $value));
     }
     // Set or Return
     if ($return === true) {
         return $value;
     }
     if ($value > 0) {
         $field->text = JCckDatabase::loadResult('SELECT title FROM ' . self::$table . ' WHERE id =' . (int) $value);
     }
     $field->value = $value;
     parent::g_onCCK_FieldPrepareStore($field, $name, $value, $config);
 }
Exemple #26
0
 public static function onCCK_Storage_LocationAfterImport($fields, &$config = array())
 {
     if (!count($config['tasks'])) {
         return true;
     }
     // Reorder
     if (count($config['tasks']['reorder'])) {
         foreach ($config['tasks']['reorder'] as $task) {
             $pk = JCckDatabase::loadResult('SELECT ' . self::$key . ' FROM ' . self::$table . ' WHERE ' . $task . ' ORDER BY ' . self::$key . ' DESC LIMIT 1');
             if ($pk > 0) {
                 $table = self::_getTable($pk);
                 $table->reorder($task);
             }
         }
     }
 }
Exemple #27
0
 public static function getId($config)
 {
     return JCckDatabase::loadResult('SELECT id FROM #__cck_core WHERE storage_location="' . self::$type . '" AND storage_table="' . (string) $config['base']->table . '" AND pk=' . (int) $config['pk']);
 }
Exemple #28
0
 public function rebuild($cid)
 {
     $lft = 1;
     if (!$cid) {
         return false;
     } elseif ($cid != 2) {
         $lft = JCckDatabase::loadResult('SELECT a.lft FROM #__cck_core_folders AS a WHERE a.id = ' . (int) $cid);
     }
     Helper_Folder::rebuildTree($cid, $lft);
     return true;
 }
Exemple #29
0
 public function onCCK_FieldPrepareForm(&$field, $value = '', &$config = array(), $inherit = array(), $return = false)
 {
     if (self::$type != $field->type) {
         return;
     }
     self::$path = parent::g_getPath(self::$type . '/');
     parent::g_onCCK_FieldPrepareForm($field, $config);
     // Init
     if (count($inherit)) {
         $id = isset($inherit['id']) && $inherit['id'] != '' ? $inherit['id'] : $field->name;
         $name = isset($inherit['name']) && $inherit['name'] != '' ? $inherit['name'] : $field->name;
         $inherited = true;
     } else {
         $id = $field->name;
         $name = $field->name;
         $inherited = false;
     }
     $value = $value != '' ? htmlspecialchars($value, ENT_COMPAT, 'UTF-8') : @$field->defaultvalue;
     $value = $value != ' ' ? $value : '';
     // Validate
     $validate = '';
     if ($config['doValidation'] > 1) {
         plgCCK_Field_ValidationRequired::onCCK_Field_ValidationPrepareForm($field, $id, $config);
         $validate = count($field->validate) ? ' validate[' . implode(',', $field->validate) . ']' : '';
     }
     // Prepare
     $app = JFactory::getApplication();
     $options2 = JCckDev::fromJSON($field->options2);
     $user = JFactory::getUser();
     if ($config['pk'] && @$options2['import'] && $field->storage_location) {
         if (!JCckDatabase::loadResult('SELECT pk FROM #__cck_core WHERE pk=' . (int) $config['pk'] . ' AND storage_location="' . (string) $field->storage_location . '"')) {
             $properties = array('custom', 'table');
             $properties = JCck::callFunc('plgCCK_Storage_Location' . $field->storage_location, 'getStaticProperties', $properties);
             $custom = $options2['import'] == 2 ? 'fulltext' : $properties['custom'];
             $value = $config['storages'][$properties['table']]->{$custom};
         }
     }
     if (!$user->id && $this->params->get('guest_access', 0) == 0) {
         $form = '';
     } else {
         $width = @$options2['width'] ? str_replace('px', '', $options2['width']) : '100%';
         $height = @$options2['height'] ? str_replace('px', '', $options2['height']) : '280';
         $asset = $config['asset_id'] > 0 ? $config['asset_id'] : $config['asset'];
         if ($app->input->get('option') == 'com_cck' && $app->input->get('view') == 'form' && $config['client'] == '') {
             $field->bool = 1;
         }
         if ($field->bool) {
             // Default
             $buttons = array('pagebreak', 'readmore');
             $editor = JFactory::getEditor(@$options2['editor'] ? $options2['editor'] : null);
             $form = '<div>' . $editor->display($name, $value, $width, $height, '60', '20', $buttons, $id, $asset) . '</div>';
         } else {
             // Modal Box
             if (trim($field->selectlabel)) {
                 if ($config['doTranslation']) {
                     $field->selectlabel = JText::_('COM_CCK_' . str_replace(' ', '_', trim($field->selectlabel)));
                 }
                 $buttonlabel = $field->selectlabel;
             } else {
                 $buttonlabel = JText::_('COM_CCK_EDITOR');
             }
             $e_type = @$options2['editor'] != '' ? '&type=' . $options2['editor'] : '';
             $link = 'index.php?option=com_cck&task=box.add&tmpl=component&file=plugins/cck_field/' . self::$type . '/tmpl/form.php' . '&id=' . $id . '&name=' . $name . $e_type . '&params=' . urlencode(urlencode($width)) . '||' . $height . '||' . $asset;
             $app = JFactory::getApplication();
             $class = 'wysiwyg_editor_box variation_href';
             $component = $app->input->get('option');
             if ($component == 'com_cck' && $app->input->get('view') != 'form' || $component == 'com_cck_ecommerce' || $component == 'com_cck_toolbox' || $component == 'com_cck_webservices') {
                 // todo: remove later
                 $class .= ' btn';
             }
             $class = 'class="' . $class . '" ';
             $attr = $class;
             $form = '<textarea style="display: none;" id="' . $id . '" name="' . $name . '">' . $value . '</textarea>';
             $form .= '<a href="' . $link . '" ' . $attr . '>' . $buttonlabel . '</a>';
             $field->markup_class .= ' cck_form_wysiwyg_editor_box';
         }
     }
     // Set
     if (!$field->variation) {
         $field->form = $form;
         self::_addScripts($field->bool, array('height' => @$height, 'inherited' => $inherited), $config);
     } else {
         $hidden = '<textarea class="inputbox" style="display: none;" id="' . $id . '" name="' . $name . '" />' . $value . '</textarea>';
         parent::g_getDisplayVariation($field, $field->variation, $value, $value, $form, $id, $name, '<textarea', $hidden, '', $config);
     }
     $field->value = $value;
     // Return
     if ($return === true) {
         return $field;
     }
 }
Exemple #30
0
 public static function getMethod()
 {
     $name = JCckDatabase::loadResult('SELECT type FROM #__cck_more_ecommerce_shipping_methods WHERE published = 1 ORDER BY id DESC');
     return $name;
     /* JFactory::getApplication()->input->post->get( 'seb_order_method' ); */
 }