Пример #1
0
 public function renderFields($groupId = null, $catid = null)
 {
     $lang = JFactory::getLanguage();
     $lang->load('com_tz_portfolio', JPATH_ADMINISTRATOR);
     $html = '';
     // if inherit category
     if ($groupId == 0) {
         $query = 'SELECT f.* FROM #__tz_portfolio_fields AS f' . ' LEFT JOIN #__tz_portfolio_xref AS x ON x.fieldsid=f.id' . ' LEFT JOIN #__tz_portfolio_categories AS c ON c.groupid = x.groupid' . ' WHERE f.published=1 AND c.catid = ' . $catid . ' ORDER BY f.ordering ASC';
     } else {
         $query = 'SELECT f.* FROM #__tz_portfolio_fields AS f' . ' LEFT JOIN #__tz_portfolio_xref  AS x ON f.id=x.fieldsid' . ' WHERE f.published=1 AND x.groupid=' . $groupId . ' ORDER BY f.ordering ASC';
     }
     $db = JFactory::getDbo();
     $db->setQuery($query);
     if (!$db->query()) {
         var_dump($db->getErrorMsg());
         return false;
     }
     $rows = $db->loadObjectList();
     // if have fields
     if (count($rows) > 0) {
         // require file artilce  in helpers
         require_once JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . 'helpers' . DIRECTORY_SEPARATOR . 'article.php';
         foreach ($rows as $row) {
             $param = str_replace('[', '', $row->value);
             $param = str_replace(']', '', $param);
             $param = str_replace('},{', '}/////{', $param);
             $param = explode('/////', $param);
             //                if($row -> type=='link')
             //                for($i=0;$i<count($param);$i++){
             //                    $param[$i]  = json_decode($param[$i]);
             //                    $param[$i] -> fieldsid  = $row -> id;
             //                }
             $fieldEdits = null;
             $defaultValue = null;
             if ($row->default_value != '') {
                 $defaultValue = explode(',', $row->default_value);
             }
             if (!($fieldEdits = $this->FieldsEdit($row->id))) {
                 $fieldEdits = null;
             }
             $j = 0;
             for ($i = 0; $i < count($param); $i++) {
                 if (!empty($param[$i])) {
                     $param[$i] = json_decode($param[$i]);
                     $param[$i]->fieldsid = $row->id;
                     //new
                     if ($row->type != 'link' && $row->type != 'textfield' && $row->type != 'textarea') {
                         if (isset($defaultValue) && $defaultValue) {
                             if (!isset($fieldEdits) || isset($fieldEdits) && count($fieldEdits) <= 0) {
                                 if (in_array($param[$i]->value, $defaultValue)) {
                                     $_fieldEdits[$j] = new stdClass();
                                     $_fieldEdits[$j]->fieldsid = $row->id;
                                     $_fieldEdits[$j]->value = $param[$i]->name;
                                     $j++;
                                 }
                             }
                         }
                     }
                 }
                 ///////////////
             }
             if ($row->type != 'link' && $row->type != 'textfield' && $row->type != 'textarea') {
                 if (isset($_fieldEdits)) {
                     $fieldEdits = $_fieldEdits;
                 }
             }
             $value = null;
             if ($fieldEdits) {
                 foreach ($fieldEdits as &$item) {
                     $item->value = htmlspecialchars($item->value);
                     if ($row->type == 'textfield' || $row->type == 'textarea') {
                         if ($row->id == $item->fieldsid) {
                             $value = $item->value;
                         }
                     }
                 }
             }
             $name = 'tzfields' . $row->id;
             $html .= '<tr><td style="background: #F6F6F6; min-width:100px;" align="right" valign="top">' . $row->title . '</td><td>';
             //                $param  = array_filter($param);
             switch ($row->type) {
                 case 'textfield':
                     $html .= ArticleHTML::renderTextField($name, $value);
                     break;
                 case 'textarea':
                     $this->fieldsid[] = $row->id;
                     $html .= ArticleHTML::renderTextArea($name, $value, '', $param[0]->editor, '90%', '200', '', '', array('image' => true));
                     $html .= '<input type="hidden" name="tz_textarea_hidden[]" value="' . ($param[0]->editor == 1 ? $row->id : '') . '" class="tzidhidden">';
                     break;
                 case 'select':
                     $html .= ArticleHTML::renderDropDown($name, $param, $fieldEdits);
                     break;
                 case 'multipleSelect':
                     $name .= '[]';
                     $html .= ArticleHTML::renderDropdown($name, $param, $fieldEdits, '', true, 10, 'style="min-width:130px;"');
                     break;
                 case 'radio':
                     $html .= ArticleHTML::renderRadio($name . '[]', $param, $fieldEdits);
                     break;
                 case 'checkbox':
                     $html .= ArticleHTML::renderCheckBox($name . '[]', $param, '', $fieldEdits);
                     break;
                 case 'link':
                     $url = null;
                     $target = null;
                     $text = '';
                     if ($fieldEdits) {
                         $linkValue = htmlspecialchars_decode($fieldEdits[0]->value);
                         $linkValue = html_entity_decode($linkValue);
                         if (preg_match('/>.*</i', $linkValue, $a)) {
                             $text = $a[0];
                         }
                         $text = str_replace('>', '', $text);
                         $text = str_replace('<', '', $text);
                         if (preg_match('/target=".*"/i', $linkValue, $a)) {
                             if (preg_match('/\\".*\\"/i', $a[0], $a)) {
                                 $target = str_replace('"', '', $a[0]);
                             }
                         }
                         if (preg_match('/href=".*"\\s/i', $linkValue, $a)) {
                             if (preg_match('/".*"/', $a[0], $a)) {
                                 $url = str_replace('"', '', $a[0]);
                                 $url = str_replace('http://', '', $url);
                             }
                         }
                     } else {
                         $text = $param[0]->name;
                         $target = $param[0]->target;
                         $url = str_replace('http://', '', $param[0]->value);
                     }
                     $html .= ArticleHTML::renderLink($name . '[]', $text, $url, $target);
                     $html .= '<input type="hidden" name="tz_link_hidden[]" value="' . $row->id . '">';
                     //                    case 'file':
                     //                        $html   .= ArticleHTML::renderFile($name.'[]');
                     //                        break;
             }
             $html .= '</td></tr>';
         }
     } else {
         $html = '<div id="system-message-container">' . '<div id="system-message">
                         <div class="alert alert-message">
                             <h4 class="alert-heading">' . JText::_('WARNING') . '</h4>
                             <div>
                                     <p>' . JText::_('COM_TZ_PORTFOLIO_FIELD_GROUP_DESC') . '</p>
                             </div>
                         </div>
                     </div>
                 </div>';
     }
     return $html;
 }
Пример #2
0
 static function renderCheckBox($name, $rows, $id = null, $checked = null, $javascript = null, $image = false, $imageWidth = null, $imageHeight = null, $imageCrop = null, $prefix = '@[{(&*_')
 {
     $html = '<table cellspacing="0" cellpadding="0">';
     $str = '';
     $id = $id ? ' id="' . $id . '"' : '';
     if (count($rows) > 0) {
         foreach ($rows as $row) {
             if ($checked) {
                 if (count($checked) > 0) {
                     foreach ($checked as $item) {
                         if ($item->fieldsid == $row->fieldsid && $item->value == $row->name) {
                             $_checked = ' checked="checked"';
                             break;
                         } else {
                             $_checked = '';
                         }
                     }
                 }
             } else {
                 $_checked = '';
             }
             //                $checked    = ($checked==$row -> value)?' checked = "'.$checked.'"':'';
             $str .= '<tr>';
             $str .= '<td>';
             if ($image != false) {
                 if (isset($row->image) && !empty($row->image)) {
                     $str .= ArticleHTML::renderImg(JURI::root() . $row->image, $imageWidth, $imageHeight, $imageCrop);
                 }
             }
             $str .= '</td>';
             $str .= '<td>';
             $str .= '<input type="checkbox" name="' . $name . '"' . ' value="' . addslashes($row->name) . $prefix . $row->value . '"' . $id . $_checked . $javascript . '/>';
             $str .= '&nbsp;' . $row->name . '</td>';
             $str .= '</tr>';
         }
     }
     $html .= $str . '</table>';
     return $html;
 }