Пример #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 : '') : '';
     }
 }
Пример #2
0
 protected static function _link($link, &$field, &$config)
 {
     $list = $link->get('list', '');
     $itemId = (int) $link->get('itemid', '');
     $search_field = $link->get('search_field', 0);
     $name = $search_field == -1 ? '' : ($search_field == 1 ? $link->get('search_fieldname', $field->name) : $field->name);
     $custom = $link->get('custom', '');
     if (!$list) {
         return;
     }
     // Prepare
     $link_class = $link->get('class', '');
     $link_rel = $link->get('rel', '');
     $link_target = $link->get('target', '');
     $tmpl = $link->get('tmpl', '');
     $tmpl = $tmpl ? '&tmpl=' . $tmpl : '';
     $vars = '&task=search' . $tmpl;
     // Set
     if (isset($field->values)) {
         foreach ($field->values as $f) {
             $c = $custom;
             $c = parent::g_getCustomSelfVars(self::$type, $f, $c, $config);
             $c = $c ? '&' . $c : '';
             $search_for = $search_field > -1 ? '&' . $name . '=' . $f->value : '';
             $f->link = 'index.php?option=com_cck&view=list&search=' . $list . $vars . '&Itemid=' . $itemId . $search_for . $c;
             if ($itemId > 0) {
                 $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 : '');
         }
         $field->link = '#';
         //todo
     } elseif (is_array($field->value)) {
         foreach ($field->value as $f) {
             $c = $custom;
             $c = parent::g_getCustomSelfVars(self::$type, $f, $c, $config);
             $c = $c ? '&' . $c : '';
             $search_for = $search_field > -1 ? '&' . $name . '=' . $f->value : '';
             $f->link = 'index.php?option=com_cck&view=list&search=' . $list . $vars . '&Itemid=' . $itemId . $search_for . $c;
             if ($itemId > 0) {
                 $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 : '');
         }
         $field->link = '#';
         //todo
     } else {
         $custom = parent::g_getCustomVars(self::$type, $field, $custom, $config);
         $search_for = $search_field > -1 ? '&' . $name . '=' . $field->value : '';
         $field->link = 'index.php?option=com_cck&view=list&search=' . $list . $vars . '&Itemid=' . $itemId . $search_for;
         if ($itemId > 0) {
             $field->link = JRoute::_($field->link);
         }
         $separator = strpos($field->link, '?') !== false ? '&' : '?';
         if ($custom) {
             $field->link .= $separator . $custom;
         }
         $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 : '');
     }
 }
Пример #3
0
 protected static function _link($link, &$field, &$config)
 {
     $app = JFactory::getApplication();
     $sef = $link->get('sef', $config['doSEF']);
     if (!JFactory::getConfig()->get('sef')) {
         $sef = 0;
     }
     $itemId = $sef ? $link->get('itemid', '') : '';
     $content = $link->get('content', '');
     $custom = $link->get('custom', '');
     // Prepare
     if (!$itemId) {
         $view = $app->input->get('view', '');
         $layout = $app->input->get('layout', '');
         if ($view == 'category' && $layout == 'blog' || $view == 'featured') {
             $sef = 0;
         }
         if ($sef) {
             $itemId = $app->input->getInt('Itemid', 0);
         }
     }
     $lang_tag = $link->get('language', '');
     $link_attr = $link->get('attributes', '');
     $link_class = $link->get('class', '');
     $link_rel = $link->get('rel', '');
     $link_target = $link->get('target', '');
     $tmpl = $link->get('tmpl', '');
     $tmpl = $tmpl ? 'tmpl=' . $tmpl : '';
     $vars = $tmpl;
     if (($content == '2' || (int) $itemId < 0) && $sef) {
         $field->link = '';
         $pk = $content == '2' ? 0 : $config['pk'];
         parent::g_addProcess('beforeRenderContent', self::$type, $config, array('name' => $field->name, 'fieldname' => $link->get('content_fieldname', ''), 'fieldname2' => $link->get('itemid_fieldname', ''), 'fieldnames' => $link->get('itemid_mapping', ''), 'itemId' => $itemId, 'location' => $link->get('content_location', $config['location']), 'pk' => $pk, 'sef' => $sef, 'vars' => $vars, 'custom' => $custom));
     }
     $custom = parent::g_getCustomVars(self::$type, $field, $custom, $config);
     // Set
     if ($content == '4' || $content == '5') {
         //$goto				=	self::_goTo( $app->input->getInt( 'Itemid', $config['Itemid'] ) );
         $field->link = '';
         if ($content == '5') {
             //
         } else {
             //
         }
     } else {
         $field->link = $config['location'] ? JCck::callFunc_Array('plgCCK_Storage_Location' . $config['location'], 'getRouteByStorage', array(&$config['storages'], $sef, $itemId, $config, $lang_tag)) : '';
     }
     if ($field->link) {
         if ($vars) {
             $field->link .= strpos($field->link, '?') !== false ? '&' . $vars : '?' . $vars;
         }
         if ($custom) {
             $field->link .= $custom[0] == '#' ? $custom : (strpos($field->link, '?') !== false ? '&' . $custom : '?' . $custom);
         }
     }
     if ($app->isAdmin()) {
         $field->link = str_replace('/administrator', '', $field->link);
     }
     if ($link->get('path_type', 0)) {
         $field->link = JUri::getInstance()->toString(array('scheme', 'host')) . $field->link;
     }
     $field->link_attributes = $link_attr ? $link_attr : (isset($field->link_attributes) ? $field->link_attributes : '');
     $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 : '');
 }
Пример #4
0
 public static function onCCK_Field_LinkBeforeRenderContent($process, &$fields, &$storages, &$config = array())
 {
     $itemId = @$process['itemId'];
     $name = $process['name'];
     $fieldname = $process['fieldname'];
     $location = $process['location'];
     if (isset($process['pk']) && $process['pk']) {
         $pk = $process['pk'];
     } else {
         $pk = isset($fields[$fieldname]) ? (int) $fields[$fieldname]->value : 0;
     }
     if (!$pk) {
         if (isset($process['matches']) && count($process['matches'][1])) {
             parent::g_setCustomVars($process, $fields, $name);
         }
         return;
     }
     if ($itemId == '-2') {
         $itemId = JFactory::getApplication()->input->get('Itemid');
         $fieldname2 = $process['fieldname2'];
         if (isset($fields[$fieldname2])) {
             $itemId = (int) $fields[$fieldname2]->value;
         }
     } elseif ($itemId == '-3') {
         $itemId = JFactory::getApplication()->input->get('Itemid');
         $itemIds = $process['fieldnames'];
         $items = explode('||', $itemIds);
         if (count($items)) {
             foreach ($items as $item) {
                 if ($item != '') {
                     $parts = explode('=', $item);
                     if ($parts[1]) {
                         $checks = json_decode($parts[0], true);
                         $count = count($checks);
                         $found = 0;
                         if ($count) {
                             foreach ($checks as $k => $v) {
                                 if (isset($fields[$k]) && $fields[$k]->value == $v) {
                                     $found++;
                                 }
                             }
                         }
                         if ($found == $count) {
                             $itemId = $parts[1];
                             break;
                         }
                     }
                 }
             }
         }
     }
     $fields[$name]->link = JCck::callFunc_Array('plgCCK_Storage_Location' . $location, 'getRoute', array($pk, $process['sef'], $itemId, $config));
     $target = $fields[$name]->typo_target;
     if ($fields[$name]->link) {
         if ($process['vars']) {
             $fields[$name]->link .= strpos($fields[$name]->link, '?') !== false ? '&' . $process['vars'] : '?' . $process['vars'];
         }
         if ($process['custom']) {
             $process['custom'] = parent::g_getCustomVars(self::$type, $fields[$name], $process['custom'], $config);
             $fields[$name]->link .= $process['custom'][0] == '#' ? $process['custom'] : (strpos($fields[$name]->link, '?') !== false ? '&' . $process['custom'] : '?' . $process['custom']);
         }
         JCckPluginLink::g_setHtml($fields[$name], $target);
     }
     if ($fields[$name]->typo) {
         $html = isset($fields[$name]->html) ? $fields[$name]->html : '';
         if (strpos($fields[$name]->typo, $fields[$name]->{$target}) === false) {
             $fields[$name]->typo = $html;
         } else {
             $fields[$name]->typo = str_replace($fields[$name]->{$target}, $html, $fields[$name]->typo);
         }
     }
     if (isset($process['matches']) && count($process['matches'][1])) {
         parent::g_setCustomVars($process, $fields, $name);
     }
 }