Example #1
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 . '/');
     $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_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;
     }
 }