Exemplo n.º 1
0
 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 static function getRoute($item, $sef, $itemId, $config = array(), $lang = '')
 {
     $route = '';
     if (is_numeric($item)) {
         $item = JCckDatabaseCache::loadObject('SELECT a.id, a.alias, a.catid, a.language, b.alias AS category_alias' . ' FROM #__content AS a LEFT JOIN #__categories AS b ON b.id = a.catid' . ' WHERE a.id = ' . (int) $item);
         if (empty($item)) {
             return '';
         }
     }
     $pk = isset($item->pk) ? $item->pk : $item->id;
     $item->slug = $item->alias ? $pk . ':' . $item->alias : $pk;
     if ($sef) {
         if ($sef == '0' || $sef == '1') {
             $path = '&catid=' . $item->catid;
         } elseif ($sef[0] == '4') {
             $path = '&catid=' . (isset($item->category_alias) ? $item->category_alias : $item->catid);
         } elseif ($sef[0] == '3') {
             $path = $config['type'] ? '&typeid=' . $config['type'] : '';
         } else {
             $path = '';
         }
         $route = self::_getRoute($sef, $itemId, $item->slug, $path, '', $lang);
     } else {
         require_once JPATH_SITE . '/components/com_content/helpers/route.php';
         $route = ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language);
     }
     return JRoute::_($route);
 }
Exemplo n.º 3
0
 public static function getDefaultStyle($template)
 {
     static $styles = array();
     if (!$template) {
         $template = self::getDefaultTemplate();
     }
     if (!isset($styles[$template])) {
         $styles[$template] = JCckDatabaseCache::loadObject('SELECT id, params, template FROM #__template_styles WHERE template = "' . (string) $template . '" ORDER BY id asc');
     }
     return $styles[$template];
 }
Exemplo n.º 4
0
 public static function getRoute($item, $sef, $itemId, $config = array(), $lang = '')
 {
     $route = '';
     if (is_numeric($item)) {
         $select = $sef[0] == '5' ? ', a.created_by, d.alias AS author_alias' : '';
         $query = 'SELECT a.id, a.alias, a.catid, a.language, b.alias AS category_alias' . $select . ' FROM #__content AS a LEFT JOIN #__categories AS b ON b.id = a.catid';
         if ($sef[0] == '5') {
             $query .= ' LEFT JOIN #__cck_core AS c ON (c.storage_location = "joomla_user" AND c.pk = a.created_by)' . ' LEFT JOIN #__content AS d ON d.id = c.pkb';
         }
         $query .= ' WHERE a.id = ' . (int) $item;
         $item = JCckDatabaseCache::loadObject($query);
         if (empty($item)) {
             return '';
         }
     }
     $pk = isset($item->pk) ? $item->pk : $item->id;
     $item->slug = $item->alias ? $pk . ':' . $item->alias : $pk;
     if ($sef) {
         if ($sef == '0' || $sef == '1') {
             $path = '&catid=' . $item->catid;
         } elseif ($sef[0] == '5') {
             $path = '&userid=' . (isset($item->author_alias) ? $item->author_alias : $item->created_by);
         } elseif ($sef[0] == '4') {
             $path = '&catid=' . (isset($item->category_alias) ? $item->category_alias : $item->catid);
         } elseif ($sef[0] == '3') {
             $path = $config['type'] ? '&typeid=' . $config['type'] : '';
         } else {
             $path = '';
         }
         $route = self::_getRoute($sef, $itemId, $item->slug, $path, '', $lang);
     } else {
         require_once JPATH_SITE . '/components/com_content/helpers/route.php';
         $route = ContentHelperRoute::getArticleRoute($item->slug, $item->catid, $item->language);
     }
     return JRoute::_($route);
 }
Exemplo n.º 5
0
 protected static function _setStorage(&$tables, &$config, &$inherit)
 {
     if (isset($tables['#__cck_core']['fields']['storage_location'])) {
         $config['location'] = $tables['#__cck_core']['fields']['storage_location'];
         $inherit['table'] = '';
     } elseif (isset($tables['#__cck_core']['fields']['cck'])) {
         $cck = str_replace(array(',', ' '), array('","', '","'), $tables['#__cck_core']['fields']['cck']);
         $core = JCckDatabaseCache::loadObject('SELECT storage_location, storage_table FROM #__cck_core WHERE cck IN ("' . $cck . '") ORDER BY id DESC LIMIT 1');
         if (is_object($core)) {
             $config['location'] = $core->storage_location;
             $inherit['table'] = $core->storage_table;
         }
     }
     if (!$config['location'] && isset($config['type_object']) && $config['type_object']) {
         $config['location'] = $config['type_object'];
         $inherit['table'] = '';
     }
 }