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 . '/'); $field->label2 = trim(@$field->label2); 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; } else { $id = $field->name; $name = $field->name; } $value = $field->label; $field->label = ''; // Prepare $pre_task = ''; $options2 = JCckDev::fromJSON($field->options2); $task = isset($options2['task']) && $options2['task'] ? $options2['task'] : 'save'; $task_auto = isset($options2['task_auto']) && $options2['task_auto'] == '0' ? 0 : 1; $task_id = isset($options2['task_id']) && $options2['task_id'] ? $options2['task_id'] : 0; if (JFactory::getApplication()->isAdmin()) { $task = $config['client'] == 'admin' ? 'form.' . $task : 'list.' . $task; } if ($task_id) { $pre_task = htmlspecialchars('jQuery("#' . $config['formId'] . '").append(\'<input type="hidden" name="tid" value="' . $task_id . '">\');'); } $class = 'button btn' . ($field->css ? ' ' . $field->css : ''); if ($task == 'cancel') { $click = ' onclick="JCck.Core.submitForm(\'' . $task . '\', document.getElementById(\'seblod_form\'));"'; } else { if ($task == 'export' || $task == 'process' || $task == 'list.export' || $task == 'list.process') { $click = $pre_task . $config['submit'] . '(\'' . $task . '\');return false;'; if ($field->variation != 'toolbar_button') { parent::g_addProcess('beforeRenderForm', self::$type, $config, array('name' => $field->name, 'task' => $task, 'task_auto' => $task_auto, 'task_id' => $task_id)); } if (!$task_auto) { $click = 'if (document.' . $config['formId'] . '.boxchecked.value==0){alert(\'' . JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST') . '\');}else{' . $click . '}'; } $click = isset($config['submit']) ? ' onclick="' . $click . '"' : ''; } elseif ($task == 'save2redirect') { $custom = ''; if (isset($options2['custom']) && $options2['custom']) { $custom = JCckDevHelper::replaceLive($options2['custom']); $custom = $custom ? '&' . $custom : ''; } if ($config['client'] == 'search') { $pre_task = htmlspecialchars('jQuery("#' . $config['formId'] . '").attr(\'action\', \'' . JRoute::_('index.php?Itemid=' . $options2['itemid'] . $custom) . '\');'); } else { $pre_task = htmlspecialchars('jQuery("#' . $config['formId'] . ' input[name=\'config[url]\']").val(\'' . JRoute::_('index.php?Itemid=' . $options2['itemid'] . $custom) . '\');'); } $click = isset($config['submit']) ? ' onclick="' . $pre_task . $config['submit'] . '(\'' . $task . '\');return false;"' : ''; } else { $click = isset($config['submit']) ? ' onclick="' . $pre_task . $config['submit'] . '(\'' . $task . '\');return false;"' : ''; } } if ($field->attributes && strpos($field->attributes, 'onclick="') !== false) { $matches = array(); $search = '#onclick\\=\\"([a-zA-Z0-9_\\(\\)\\\'\\;\\.]*)"#'; preg_match($search, $field->attributes, $matches); if (count($matches) && $matches[0]) { if ($matches[0] == $field->attributes) { $field->attributes = substr(trim($field->attributes), 0, -1); $click = ' ' . $field->attributes . '"'; $field->attributes = ''; } else { $click = ' onclick="' . $matches[1] . '"'; $field->attributes = trim(str_replace($matches[0], '', $field->attributes)); } } } $attr = 'class="' . $class . '"' . $click . ($field->attributes ? ' ' . $field->attributes : ''); if ($field->bool) { $label = $value; if (JCck::on()) { if ($field->bool6 == 3) { $label = '<span class="icon-' . $options2['icon'] . '"></span>'; $attr .= ' title="' . $value . '"'; } elseif ($field->bool6 == 2) { $label = $value . "\n" . '<span class="icon-' . $options2['icon'] . '"></span>'; } elseif ($field->bool6 == 1) { $label = '<span class="icon-' . $options2['icon'] . '"></span>' . "\n" . $value; } } $type = $field->bool7 == 1 ? 'submit' : 'button'; $form = '<button type="' . $type . '" id="' . $id . '" name="' . $name . '" ' . $attr . '>' . $label . '</button>'; $tag = 'button'; } else { $form = '<input type="submit" id="' . $id . '" name="' . $name . '" value="' . $value . '" ' . $attr . ' />'; $tag = 'input'; } if ($field->bool2 == 1) { $alt = $field->bool3 ? ' ' . JText::_('COM_CCK_OR') . ' ' : "\n"; if ($config['client'] == 'search') { $onclick = 'onclick="jQuery(\'#' . $config['formId'] . '\').clearForm();"'; $form .= $alt . '<a href="javascript: void(0);" ' . $onclick . ' title="' . JText::_('COM_CCK_RESET') . '">' . JText::_('COM_CCK_RESET') . '</a>'; } else { $onclick = 'onclick="JCck.Core.submitForm(\'cancel\', document.getElementById(\'seblod_form\'));"'; $form .= $alt . '<a href="javascript: void(0);" ' . $onclick . ' title="' . JText::_('COM_CCK_CANCEL') . '">' . JText::_('COM_CCK_CANCEL') . '</a>'; } } elseif ($field->bool2 == 2) { $alt = $field->bool3 ? ' ' . JText::_('COM_CCK_OR') . ' ' : "\n"; $field2 = (object) array('link' => $options2['alt_link'], 'link_options' => $options2['alt_link_options'], 'id' => $id, 'name' => $name, 'text' => htmlspecialchars($options2['alt_link_text']), 'value' => ''); JCckPluginLink::g_setLink($field2, $config); JCckPluginLink::g_setHtml($field2, 'text'); $form .= $alt . $field2->html; } // Set if (!$field->variation) { $field->form = $form; if ($field->script) { parent::g_addScriptDeclaration($field->script); } } else { if ($field->variation == 'toolbar_button') { $field->form = ''; $icon = isset($options2['icon']) && $options2['icon'] ? 'icon-' . $options2['icon'] : ''; $onclick = $pre_task . 'JCck.Core.submit(\'' . $task . '\')'; if (!$task_auto) { $onclick = 'if (document.' . $config['formId'] . '.boxchecked.value==0){alert(\'' . JText::_('JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST') . '\');}else{' . $onclick . '}'; } $html = '<button class="btn btn-small' . ($field->css ? ' ' . $field->css : '') . '" onclick="' . $onclick . '" href="#"><i class="' . $icon . '"></i> ' . $value . '</button>'; parent::g_addProcess('beforeRenderForm', self::$type, $config, array('name' => $field->name, 'button' => array('html' => $html, 'icon' => @$options2['icon']), 'pre_task' => $pre_task, 'task' => $task, 'task_auto' => $task_auto, 'task_id' => $task_id)); } else { parent::g_getDisplayVariation($field, $field->variation, $value, $value, $form, $id, $name, '<' . $tag, ' ', '', $config); } } $field->value = ''; // Return if ($return === true) { return $field; } }
public function onCCK_FieldPrepareContent(&$field, $value = '', &$config = array()) { if (self::$type != $field->type) { return; } parent::g_onCCK_FieldPrepareContent($field, $config); $app = JFactory::getApplication(); $user = JFactory::getUser(); $access = implode(',', $user->getAuthorisedViewLevels()); $text = ''; if ($field->extended && $field->extended != @$config['type']) { $options2 = JCckDev::fromJSON($field->options2); $name = $field->storage_field2 ? $field->storage_field2 : $field->storage_field; $value = array(); if (@$options2['child_language']) { $language = $options2['child_language'] == '-1' ? JFactory::getLanguage()->getTag() : $options2['child_language']; $language = ' AND a.language = "' . $language . '"'; } else { $language = ''; } $location = @$options2['child_location'] ? $options2['child_location'] : 'joomla_article'; $order = @$options2['child_orderby'] ? ' ORDER BY a.' . $options2['child_orderby'] . ' ' . $options2['child_orderby_direction'] : ' ORDER BY a.title ASC'; $limit = @$options2['child_limit'] ? ' LIMIT ' . $options2['child_limit'] : ''; switch ($field->bool2) { case 2: $properties = array('table', 'access', 'custom', 'status'); $properties = JCck::callFunc('plgCCK_Storage_Location' . $location, 'getStaticProperties', $properties); $and = $properties['status'] ? ' AND a.' . $properties['status'] . ' = 1' : ''; $and .= $properties['access'] ? ' AND a.' . $properties['access'] . ' IN (' . $access . ')' : ''; $items = JCckDatabase::loadObjectList('SELECT a.id as pk, a.' . $properties['custom'] . ' FROM ' . $properties['table'] . ' AS a LEFT JOIN #__cck_store_join_' . $name . ' AS b on b.id = a.id' . ' WHERE b.id2 = ' . (int) $config['pk'] . $and . $language . $order . $limit); if (count($items)) { foreach ($items as $item) { $text .= JHtml::_('content.prepare', $item->{$properties}['custom']); $value[] = $item->pk; } } break; case 1: $properties = array('table', 'access', 'status'); $properties = JCck::callFunc('plgCCK_Storage_Location' . $location, 'getStaticProperties', $properties); $and = $properties['status'] ? ' AND a.' . $properties['status'] . ' = 1' : ''; $and .= $properties['access'] ? ' AND a.' . $properties['access'] . ' IN (' . $access . ')' : ''; $items = JCckDatabase::loadObjectList('SELECT a.id as pk, a.title FROM ' . $properties['table'] . ' AS a LEFT JOIN #__cck_store_join_' . $name . ' AS b ON b.id = a.id' . ' WHERE b.id2 = ' . (int) $config['pk'] . $and . $language . $order . $limit); if (count($items)) { foreach ($items as $item) { $text .= ', ' . $item->title; $value[] = $item->pk; } } if ($text) { $text = substr($text, 2); } break; default: $options2 = new JRegistry(); $options2->loadString($field->options2); $options3_json = $options2->get('child_link_options'); $options3 = new JRegistry(); $options3->loadString($options3_json); // todo >> href $properties = array('table', 'access', 'status', 'to_route'); $properties = JCck::callFunc('plgCCK_Storage_Location' . $location, 'getStaticProperties', $properties); $and = $properties['status'] ? ' AND a.' . $properties['status'] . ' = 1' : ''; $and .= $properties['access'] ? ' AND a.' . $properties['access'] . ' IN (' . $access . ')' : ''; $items = JCckDatabase::loadObjectList('SELECT ' . $properties['to_route'] . ' FROM ' . $properties['table'] . ' AS a LEFT JOIN #__cck_store_join_' . $name . ' AS b ON b.id = a.id' . ' WHERE b.id2 = ' . (int) $config['pk'] . $and . $language . $order . $limit); if (count($items)) { $sef = JFactory::getConfig()->get('sef') ? $options3->get('sef', 2) : 0; JCck::callFunc_Array('plgCCK_Storage_Location' . $location, 'setRoutes', array(&$items, $sef, $options3->get('itemid', $app->input->getInt('Itemid', 0)))); foreach ($items as $item) { $text .= ', ' . '<a href="' . $item->link . '">' . $item->title . '</a>'; $value[] = $item->pk; } if ($text) { $text = substr($text, 2); } } break; } $field->divider = ','; $value = implode($field->divider, $value); } else { if ($value) { switch ($field->bool) { case 2: $text = JCckDatabase::loadResult('SELECT a.introtext FROM ' . self::$table . ' AS a WHERE a.id = ' . (int) $value . ' AND a.state = 1 AND a.access IN (' . $access . ')'); $text = JHtml::_('content.prepare', $text); break; case 1: $text = JCckDatabase::loadResult('SELECT a.title FROM ' . self::$table . ' AS a WHERE a.id = ' . (int) $value . ' AND a.state = 1 AND a.access IN (' . $access . ')'); break; default: require_once JPATH_SITE . '/plugins/cck_storage_location/' . self::$type . '/' . self::$type . '.php'; $item = JCckDatabase::loadObject('SELECT a.id, a.title, a.alias, a.catid, a.language FROM ' . self::$table . ' AS a WHERE a.id = ' . (int) $value . ' AND a.state = 1 AND a.access IN (' . $access . ')'); if (is_object($item)) { $options2 = new JRegistry(); $options2->loadString($field->options2); $options3_json = $options2->get('parent_link_options'); $options3 = new JRegistry(); $options3->loadString($options3_json); $field2 = (object) array('link' => 'content', 'link_options' => $options3_json, 'id' => $field->name, 'name' => $field->name, 'text' => htmlspecialchars($item->title), 'value' => ''); JCckPluginLink::g_setLink($field2, $config); $field2->link = plgCCK_Storage_LocationJoomla_Article::getRoute($item, $options3->get('sef', 2), $options3->get('itemid', $app->input->getInt('Itemid', 0))); JCckPluginLink::g_setHtml($field2, 'text'); $text = $field2->html; $field->link = $field2->link; $field->html = $field2->html; } break; } } } $field->value = $value; $field->text = $text; $field->typo_target = 'text'; }
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 . '/'); $field->label2 = trim(@$field->label2); 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; } else { $id = $field->name; $name = $field->name; } $value = $field->label; $field->label = ''; // Prepare $pre_task = ''; $options2 = JCckDev::fromJSON($field->options2); $task = isset($options2['task']) && $options2['task'] ? $options2['task'] : 'save'; $task_id = isset($options2['task_id']) && $options2['task_id'] ? $options2['task_id'] : 0; if (JFactory::getApplication()->isAdmin()) { $task = $config['client'] == 'admin' ? 'form.' . $task : 'list.' . $task; } if ($task_id) { $pre_task = htmlspecialchars('jQuery("#' . $config['formId'] . '").append(\'<input type="hidden" name="tid" value="' . $task_id . '">\');'); } $class = 'button btn' . ($field->css ? ' ' . $field->css : ''); if ($task == 'cancel') { $click = ' onclick="Joomla.submitform(\'' . $task . '\', document.getElementById(\'seblod_form\'));"'; } else { if ($task == 'export') { parent::g_addProcess('beforeRenderForm', self::$type, $config, array('name' => $field->name, 'task' => $task, 'task_id' => $task_id)); } $click = isset($config['submit']) ? ' onclick="' . $pre_task . $config['submit'] . '(\'' . $task . '\');return false;"' : ''; } // $click = isset( $config['formId'] ) ? ' onclick="if (document.'.$config['formId'].'.boxchecked.value==0){alert(\''.addslashes( JText::_( 'JLIB_HTML_PLEASE_MAKE_A_SELECTION_FROM_THE_LIST' ) ).'\');}else{ Joomla.submitbutton(\''.$task.'\')};return false;"' : ''; $attr = 'class="' . $class . '"' . $click . ($field->attributes ? ' ' . $field->attributes : ''); if ($field->bool) { $label = $value; if (JCck::on()) { if ($field->bool6 == 3) { $label = '<span class="icon-' . $options2['icon'] . '"></span>'; $attr .= ' title="' . $value . '"'; } elseif ($field->bool6 == 2) { $label = $value . "\n" . '<span class="icon-' . $options2['icon'] . '"></span>'; } elseif ($field->bool6 == 1) { $label = '<span class="icon-' . $options2['icon'] . '"></span>' . "\n" . $value; } } $type = $field->bool7 == 1 ? 'submit' : 'button'; $form = '<button type="' . $type . '" id="' . $id . '" name="' . $name . '" ' . $attr . '>' . $label . '</button>'; $tag = 'button'; } else { $form = '<input type="submit" id="' . $id . '" name="' . $name . '" value="' . $value . '" ' . $attr . ' />'; $tag = 'input'; } if ($field->bool2 == 1) { $alt = $field->bool3 ? ' ' . JText::_('COM_CCK_OR') . ' ' : "\n"; if ($config['client'] == 'search') { $onclick = 'onclick="jQuery(\'#' . $config['formId'] . '\').clearForm();"'; $form .= $alt . '<a href="javascript: void(0);" ' . $onclick . ' title="' . JText::_('COM_CCK_RESET') . '">' . JText::_('COM_CCK_RESET') . '</a>'; } else { $onclick = 'onclick="Joomla.submitform(\'cancel\', document.getElementById(\'seblod_form\'));"'; $form .= $alt . '<a href="javascript: void(0);" ' . $onclick . ' title="' . JText::_('COM_CCK_CANCEL') . '">' . JText::_('COM_CCK_CANCEL') . '</a>'; } } elseif ($field->bool2 == 2) { $alt = $field->bool3 ? ' ' . JText::_('COM_CCK_OR') . ' ' : "\n"; $field2 = (object) array('link' => $options2['alt_link'], 'link_options' => $options2['alt_link_options'], 'id' => $id, 'name' => $name, 'text' => htmlspecialchars($options2['alt_link_text']), 'value' => ''); JCckPluginLink::g_setLink($field2, $config); JCckPluginLink::g_setHtml($field2, 'text'); $form .= $alt . $field2->html; } // Set if (!$field->variation) { $field->form = $form; if ($field->script) { parent::g_addScriptDeclaration($field->script); } } else { if ($field->variation == 'toolbar_button') { $field->form = ''; $icon = isset($options2['icon']) && $options2['icon'] ? 'icon-' . $options2['icon'] : ''; $html = '<button class="btn btn-small' . ($field->css ? ' ' . $field->css : '') . '" onclick="' . $pre_task . 'JCck.Core.submit(\'' . $task . '\')" href="#"><i class="' . $icon . '"></i> ' . $value . '</button>'; JToolBar::getInstance('toolbar')->appendButton('Custom', $html, @$options2['icon']); // JToolBar::getInstance( 'toolbar' )->appendButton( 'Standard', $options2['icon'], $value, $task, true ); todo: check } else { parent::g_getDisplayVariation($field, $field->variation, $value, $value, $form, $id, $name, '<' . $tag, ' ', '', $config); } } $field->value = ''; // Return if ($return === true) { return $field; } }