public static function get_instance() { if (self::$instance === NULL) { self::$instance = new FW4_Type_Manager(); } return self::$instance; }
function print_row($field, $shownfields, $row, $object, $show_edit = true, $level = 0, $currentslug = '', $parenturl = '', $delete_limits = array()) { if ($level == 0) { echo '<tbody data-id="' . $row->id . '">'; } $user = FW4_User::get_user(); $typemanager = FW4_Type_Manager::get_instance(); ?> <tr<?php echo $level > 0 ? ' data-root="' . $GLOBALS['root_id'] . '"' : ''; ?> data-id="<?php echo $row->id; ?> " onclick="window.location='<?php echo $parenturl . ($level > 0 ? $GLOBALS['recursive_name'] : $field['name']); ?> /<?php echo $row->id; ?> /';"> <?php if (isset($field['sortable']) && $field['sortable']) { ?> <td valign="middle"> <?php if ($level == 0) { ?> <img class="sort-handle" src="<?php echo url(ADMINRESOURCES . 'images/sort.png'); ?> " width="10" height="11"/><input type="hidden" name="sort-<?php echo $row->id; ?> " value="<?php echo $row->_sort_order; ?> " /> <?php } ?> </td> <?php } $i = 0; foreach ($shownfields as $name => $subfield) { ?> <td<?php if ($subfield->getName() == "price") { ?> align="right"<?php } ?> ><div class="overflow"> <?php if ($i++ == 0 && $level > 0) { echo ' '; for ($s = 0; $s < $level - 1; $s++) { echo ' '; } echo '<span style="opacity:0.5">└</span> '; } if ($subfield->getName() == "bool") { if ($row->{$name} == 1) { ?> <img src="<?php echo url(ADMINRESOURCES . 'images/tick.png'); ?> " class="bool" width="16" height="16"/> <?php } else { ?> <img src="<?php echo url(ADMINRESOURCES . 'images/cross.png'); ?> " class="bool" width="16" height="16"/> <?php } } else { if ($subfield->getName() == "date") { if ($row->{$name}) { echo date('j/m/Y', $row->{$name}); } } else { if ($subfield->getName() == "float") { if ($row->{$name}) { echo rtrim(rtrim(number_format($row->{$name}, 2, ',', '.'), '0'), ','); } } else { if ($subfield->getName() == "timedate") { if ($row->{$name}) { if (date('H:i', $row->{$name}) == '00:00') { echo date('j/m/Y', $row->{$name}); } else { echo date('j/m/Y H:i', $row->{$name}); } } } else { if ($subfield->getName() == "text") { if (isset($row->{$name})) { if ($subfield['summary'] == 'bool') { if (trim($row->{$name})) { ?> <img src="<?php echo url(ADMINRESOURCES . 'images/tick.png'); ?> " class="bool" width="16" height="16"/> <?php } else { ?> <img src="<?php echo url(ADMINRESOURCES . 'images/cross.png'); ?> " class="bool" width="16" height="16"/> <?php } } else { echo excerpt($row->{$name}, 50); } } } else { if ($subfield->getName() == "slug") { foreach ($field->children() as $child) { $childname = strval($child['name']); if (is_numeric($row->{$childname}) && isset($subfield['format_' . $child['name'] . '_' . $row->{$childname}])) { if (!$name) { $name = 'slug'; } $i = 0; foreach (languages() as $key => $lang) { $childlang = $name . '_' . $key; if ($i++ != 0) { echo ' • '; } $link = url((count(languages()) > 1 ? $key . '/' : '') . str_replace('$slug', $row->{$childlang}, $subfield['format_' . $child['name'] . '_' . $row->{$childname}]), false); if (count(languages()) > 1) { echo '<a href="' . $link . '">' . strtoupper($key) . '</a>'; } else { echo '<a href="' . $link . '">' . $link . '</a>'; } } $currentslug = str_replace('$slug', $row->{$name}, $subfield['format_' . $child['name'] . '_' . $row->{$childname}]) . '/'; } } } else { if ($type = $typemanager->get_type(strval($subfield->getName()))) { echo $type->summary($subfield, $row, $object); } else { echo htmlentities_all($row->{$name}); } } } } } } } ?> </div></td> <?php } ?> <?php $deletable = true; ?> <?php foreach ($delete_limits as $delete_limit_key => $delete_limit_value) { if (!isset($row->{$delete_limit_key}) || $row->{$delete_limit_key} != $delete_limit_value) { $deletable = false; } } ?> <td align="right"> <?php if ($deletable && !isset($field['delete_disabled'])) { ?> <div style="white-space:nowrap;"> <?php if ($field['name'] != 'user' || $row->id != $user->id) { ?> <a class="delete" href="<?php echo $parenturl . ($level > 0 ? $GLOBALS['recursive_name'] : $field['name']); ?> /<?php echo $row->id; ?> /delete/" onclick="event.stopPropagation();return confirm('<?php echo l(array('nl' => 'Bent u zeker dat u dit item wilt verwijderen?', 'fr' => 'Êtes-vous sûr de vouloir supprimer cet élément?', 'en' => 'Are you sure you want to remove this item?')); ?> ');"><img alt="<?php echo l(array('nl' => 'Verwijderen', 'fr' => 'Supprimer', 'en' => 'Delete')); ?> " title="<?php echo l(array('nl' => 'Verwijderen', 'fr' => 'Supprimer', 'en' => 'Delete')); ?> " src="<?php echo url(ADMINRESOURCES . 'images/del.png'); ?> " width="22" height="23"></a> <?php } ?> </div> <?php } ?> </td> </tr> <?php if (isset($GLOBALS['recursive_name']) && $GLOBALS['recursive_name']) { if ($level == 0) { $GLOBALS['root_id'] = $row->id; } foreach ($row->{$GLOBALS}['recursive_name'] as $subrow) { print_row($field, $shownfields, $subrow, $object, $show_edit, $level + 1, $currentslug, $parenturl . ($level == 0 ? $field['name'] : $GLOBALS['recursive_name']) . '/' . $row->id . '/'); } } if ($level == 0) { echo '</tbody>'; } }
private function _delete($structure, $stack, $data) { $ids = $data->ids(); if (count($ids)) { if (isset($structure['archived']) && $structure['name'] != '_versions') { where('id IN %$', $ids)->delete($structure['stack'] . '>_versions'); } // Remove from search index where('object_id IN %$ AND object_name = %s', $ids, $stack)->delete('_search_index'); $types = FW4_Type_Manager::get_instance(); foreach ($structure->children() as $type => $child) { if ($type == 'object' && strval($child['name']) != '_versions' && !isset($child['child'])) { $ids = array(); $childname = strval($child['name']); foreach ($data as $row) { $ids[] = $row->id; } if (count($ids)) { $childstructure = FW4_Structure::get_object_structure($stack . '>' . $childname); $childdata = where($structure['name'] . '_id IN %$', $ids)->get($childstructure['path']); $this->_delete($childstructure, $childstructure['path'], $childdata); } } else { if ($type == 'recursive' && strval($child['name']) != '_versions') { $ids = array(); foreach ($data as $row) { $ids[] = $row->id; } if (count($ids)) { $childdata = where('parent_id IN %$', $ids)->get($structure['path']); $this->_delete($structure, $structure['path'], $childdata); } } else { if (isset($child['type_name']) && ($type_obj = $types->get_type(strval($child['type_name'])))) { $type_obj->deleted($child, $data); } } } } if (isset($structure['type_name']) && ($type_obj = $types->get_type(strval($structure['type_name'])))) { $type_obj->deleted($structure, $data); } foreach ($ids as $id) { if ($structure['name'] == '_versions') { $this->db->query('DELETE FROM `' . $structure['path'] . '` WHERE version_id = ' . $id); } else { $this->db->query('DELETE FROM `' . $structure['path'] . '` WHERE id = ' . $id); } } return true; } return false; }
private static function object_list_details($field) { $shownfields = array(); $headers = array(); $typemanager = FW4_Type_Manager::get_instance(); $filters = array(); $searchable = false; $delete_limits = array(); $i = 0; $user = FW4_User::get_user(); $recursive_name = false; foreach ($field->children() as $subfield) { if (isset($subfield['hidden'])) { continue; } $i++; $dolimit = true; if (isset($subfield['limit_condition'])) { $invert = false; $condition = $subfield['limit_condition']; if (substr($condition, 0, 1) == '!') { $invert = true; $condition = substr($condition, 1); } $limit_fields = explode('.', $condition); $limit_field = $user; foreach ($limit_fields as $current_field) { if (isset($limit_field->{$current_field})) { $limit_field = $limit_field->{$current_field}; } else { if (isset($limit_field->{$current_field})) { $limit_field = false; break; } else { $limit_field = true; break; } } } if ($limit_field) { $limit_field = true; } $dolimit = $invert ? !$limit_field : $limit_field; } if (isset($subfield['limit']) && $user->id != 0) { if ($dolimit) { continue; } } if (isset($subfield['limit_delete']) && $user->id != 0) { if ($dolimit) { $limit_fields = explode('.', $subfield['limit_delete']); $limit_field = $user; foreach ($limit_fields as $current_field) { if (isset($limit_field[$current_field])) { $limit_field = $limit_field[$current_field]; } else { $limit_field = false; break; } } $delete_limits[strval($subfield['name'])] = $limit_field; } } if (isset($subfield['summary_label'])) { $subfield['label'] = $subfield['summary_label']; } if ($subfield->getName() == "string" || $subfield->getName() == "email") { if (isset($subfield['filterable'])) { $searchable = true; } if (count($shownfields) > 6 || isset($subfield['summary']) && $subfield['summary'] == 'false') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } elseif ($subfield->getName() == "fieldset") { $fielddetails = self::object_list_details($subfield); $shownfields = array_merge($shownfields, $fielddetails['shownfields']); $headers = array_merge($headers, $fielddetails['headers']); $searchable = $searchable || $fielddetails['searchable']; $filters = array_merge($filters, $fielddetails['filters']); } elseif ($subfield->getName() == "date" || $subfield->getName() == "timedate" || $subfield->getName() == "bool") { if (isset($subfield['filterable'])) { if ($subfield->getName() == "bool") { $filters[strval($subfield['name'])] = array('label' => isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])), 'values' => array(1 => l(array('nl' => 'Ja', 'fr' => 'Oui', 'en' => 'Yes')), 0 => l(array('nl' => 'Nee', 'fr' => 'Non', 'en' => 'No')))); } else { $filters[strval($subfield['name'])] = array('label' => isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])), 'values' => array(1 => l(array('nl' => 'Vandaag', 'fr' => 'Vandaag', 'en' => 'Vandaag')), 2 => l(array('nl' => 'Gisteren', 'fr' => 'Gisteren', 'en' => 'Gisteren')), 3 => l(array('nl' => 'Voorbije 7 dagen', 'fr' => 'Voorbije 7 dagen', 'en' => 'Voorbije 7 dagen')), 6 => l(array('nl' => 'Deze maand', 'fr' => 'Deze maand', 'en' => 'Deze maand')), 9 => ucfirst(strftime('%B', mktime(0, 0, 0, date("n") - 1, 1))), 10 => ucfirst(strftime('%B', mktime(0, 0, 0, date("n") - 2, 1))), 11 => ucfirst(strftime('%B', mktime(0, 0, 0, date("n") - 3, 1))), 4 => l(array('nl' => 'Voorbije 30 dagen', 'fr' => 'Voorbije 30 dagen', 'en' => 'Voorbije 30 dagen')), 7 => l(array('nl' => 'Dit kwartaal', 'fr' => 'Dit kwartaal', 'en' => 'Dit kwartaal')), 8 => l(array('nl' => 'Vorig kwartaal', 'fr' => 'Vorig kwartaal', 'en' => 'Vorig kwartaal')), 5 => l(array('nl' => 'Voorbije jaar', 'fr' => 'Voorbije jaar', 'en' => 'Voorbije jaar')))); } } if (count($shownfields) > 6 || isset($subfield['summary']) && $subfield['summary'] == 'false') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } elseif ($subfield->getName() == "filter") { $values = array(); foreach ($subfield->children() as $child) { $value = isset($child['value']) ? strval($child['value']) : strval($child); $values[$value] = strval($child); } $filters[strval($subfield['name'])] = array('label' => isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])), 'values' => $values); } elseif ($subfield->getName() == "number") { if (count($shownfields) > 6 || isset($subfield['summary']) && $subfield['summary'] == 'false') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } elseif ($subfield->getName() == "float") { if (count($shownfields) > 6 || isset($subfield['summary']) && $subfield['summary'] == 'false') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } elseif ($subfield->getName() == "text") { if (isset($subfield['filterable'])) { $searchable = true; } if (count($shownfields) > 6 || !isset($subfield['summary']) || $subfield['summary'] != 'excerpt' && $subfield['summary'] != 'bool') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } elseif ($subfield->getName() == "recursive") { $recursive_name = strval($subfield['name']); } elseif ($type = $typemanager->get_type(strval($subfield->getName()))) { if ($subfield->getName() == "choice" && isset($subfield['filterable'])) { $parent_item = self::$parent_item; self::$parent_item = self::$current_item; $values = array(); if (isset($subfield['source'])) { if (!($structure = FW4_Structure::get_object_structure(strval($subfield['source']), false))) { continue; } $titlefields = $structure->xpath('string'); if (!($titlefield = reset($titlefields))) { continue; } $titlefield = strval($titlefield['name']); foreach ($type->get_source_rows(strval($subfield['source']), $subfield) as $child) { $value = $child->id; if (isset($subfield['format'])) { $displayvalue = $subfield['format']; preg_match_all('/\\[([a-z0-9\\_]+)\\]/is', $subfield['format'], $matches, PREG_SET_ORDER); foreach ($matches as $match) { $match_name = $match[1]; $displayvalue = str_ireplace($match[0], $child->{$match_name}, $displayvalue); } $values[$value] = $displayvalue; } else { $values[$value] = $child->{$titlefield}; } } } else { foreach ($subfield->children() as $child) { $value = isset($child['value']) ? strval($child['value']) : strval($child); $values[$value] = strval($child); } } $filters[strval($subfield['name'])] = array('label' => isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])), 'values' => $values); self::$parent_item = $parent_item; } if (!method_exists($type, 'summary') || count($shownfields) > 6 || isset($subfield['summary']) && $subfield['summary'] == 'false') { continue; } $headers[] = isset($subfield['label']) ? $subfield['label'] : ucwords(strval($subfield['name'])); $shownfields[strval($subfield['name'])] = $subfield; } } return array('shownfields' => $shownfields, 'headers' => $headers, 'searchable' => $searchable, 'filters' => $filters, 'delete_limits' => $delete_limits, 'recursive_name' => $recursive_name); }
<?php $videotype = FW4_Type_Manager::get_instance()->get_type('video'); $site = current_site(); if (segment(1) == 'delete') { $video = where('id = %d', intval(segment(2)))->get_row('site/videos'); $video->video->image->clear_thumbnails(); @unlink(FILESPATH . $video->image->filename); where('id = %d', intval(segment(2)))->delete('site/videos'); redirect('/admin/_youtubepopup'); } if (count($_POST)) { $data = $videotype->edit(array(), array('name' => 'video'), $_POST, new stdClass(), NULL); $data['site_id'] = $site->id; if ($data['video_url']) { insert('site/videos', $data); } redirect('/admin/_youtubepopup'); } $site = where('id = %d', $site->id)->get_row('site'); ?> <!doctype html> <!--[if lt IE 7 ]> <html class="no-js ie6" lang="en"> <![endif]--> <!--[if IE 7 ]> <html class="no-js ie7" lang="en"> <![endif]--> <!--[if IE 8 ]> <html class="no-js ie8" lang="en"> <![endif]--> <!--[if (gte IE 9)|!(IE)]><!--> <html class="no-js" lang="en"> <!--<![endif]--> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
private static function rebuild_search_index_for_object($structure) { $searchable_objects = array(); $search_index = array(); $languages = languages(); $types = FW4_Type_Manager::get_instance(); $language_field = false; $language = language(); foreach ($structure->xpath('string[@type_name="language"]') as $possible_language_field) { $language_field = $possible_language_field; $language = 0; } foreach ($structure->children() as $type => $field) { if ($type == 'page' || $type == 'object' || $type == 'site') { $searchable_objects = array_merge($searchable_objects, self::rebuild_search_index_for_object($field)); } else { if (isset($field['searchable']) && isset($field['type_name']) && ($type_obj = $types->get_type(strval($field['type_name'])))) { if (method_exists($type_obj, 'get_search_index')) { $fieldname = strval($field['searchable']); if (isset($field['translatable'])) { foreach ($languages as $key => $lang) { if (!isset($search_index[$key])) { $search_index[$key] = array(); } $search_index[$key][$fieldname] = array('type' => $type_obj, 'field' => $field); } } else { if (!isset($search_index[$language])) { $search_index[$language] = array(); } $search_index[$language][$fieldname] = array('type' => $type_obj, 'field' => $field); } } } else { if (isset($field['searchable'])) { $fieldname = strval($field['searchable']); if (isset($field['translatable'])) { foreach ($languages as $key => $lang) { if (!isset($search_index[$key])) { $search_index[$key] = array(); } $search_index[$key][$fieldname] = strval($field['name']) . '_' . $key; } } else { if (!isset($search_index[$language])) { $search_index[$language] = array(); } $search_index[$language][$fieldname] = strval($field['name']); } } } } } if (count($search_index)) { $page = 1; do { $results = limit(50)->page($page++)->get(strval($structure['stack'])); foreach ($results as $result) { foreach ($search_index as $language => $searchfields) { if ($language === 0) { $language_field_name = strval($language_field['name']); $language = $result->{$language_field_name}; where('object_id = %d', $result->id)->where('_language != %s', $language)->where('object_name = %s', strval($structure['stack']))->delete('_search_index'); } $data = array(); foreach ($searchfields as $searchfieldname => $searchfield) { if (is_array($searchfield)) { $data[$searchfieldname] = $searchfield['type']->get_search_index($searchfield['field'], $result, $structure, $language); } else { if (isset($result->{$searchfield})) { $data[$searchfieldname] = $result->{$searchfield}; } } } if (count($data)) { $existing = where('object_id = %d', $result->id)->where('_language = %s', $language)->where('object_name = %s', strval($structure['stack']))->get_row('_search_index'); if ($existing) { where('id = %d', $existing->id)->update('_search_index', $data); where('id != %d', $existing->id)->where('object_id = %d', $result->id)->where('_language = %s', $language)->where('object_name = %s', strval($structure['stack']))->delete('_search_index'); } else { $data['object_id'] = $result->id; $data['object_name'] = strval($structure['stack']); $data['_language'] = $language; insert('_search_index', $data); } } } } } while (count($results) == 50); $searchable_objects[] = strval($structure['stack']); } return $searchable_objects; }
public static function reload_site() { $db = FW4_Db::get_instance(); $site = false; if (!$site) { try { if (count(languages()) > 1) { $query = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%'); $language_codes = array_keys(languages()); if ($countries = Config::countries()) { $language_codes = array_keys($countries); } foreach ($language_codes as $code) { $query->or_where('`url_' . $code . '` LIKE %s', $_SERVER['HTTP_HOST'] . '%'); } $site = $query->get_row(); } else { $site = from('site')->where('url LIKE %s', $_SERVER['HTTP_HOST'] . '%')->get_row(); } } catch (PDOException $exception) { FW4_Structure::check_structure('', true); } if (!$site) { if (!($site = get_row('site'))) { $name = str_ireplace('www.', '', $_SERVER['HTTP_HOST']); $name = ucfirst(substr($name, 0, strpos($name, '.'))); $url = $_SERVER['HTTP_HOST']; if (stristr(getcwd(), 'httpdocs')) { $url .= substr(getcwd(), stripos(getcwd(), 'httpdocs') + strlen('httpdocs')); } insert('site', array("url" => $url, "name" => $name)); FW4_Structure::check_structure(); $site = where('url LIKE %s', $_SERVER['HTTP_HOST'])->get_row('site'); } else { $domain_handled = false; // Process minisites $types = FW4_Type_Manager::get_instance()->get_types(); foreach ($types as $typename => $type) { if (method_exists($type, 'handle_domain')) { if (!$site->structure_xml_expanded) { FW4_Structure::check_structure("", true); return self::reload_site(); } $structure = new SimpleXMLElement($site->structure_xml_expanded); $fields = $structure->xpath('//*[@type_name="' . $typename . '"]'); if (count($fields)) { $prev = self::$current; self::$current = $site; if (call_user_func_array(array($type, 'handle_domain'), array($_SERVER['HTTP_HOST'], $fields))) { $domain_handled = true; break; } self::$current = $prev; } } } // Process subdomains foreach (Config::subdomains() as $subdomain => $handler) { //if () Router::set_content_prefix($handler); } if (!$domain_handled && $site->live) { redirect((Config::https() ? 'https' : 'http') . '://' . $site->url . $_SERVER['REQUEST_URI']); } } } } if (!$site->live && false === stristr($_SERVER['HTTP_HOST'], '.fw4.') && false === stristr($_SERVER['HTTP_HOST'], 'local')) { $db->query("UPDATE site SET live = 1 WHERE id = " . $site->id); if (stristr($site->url, '.fw4.be')) { where('id = %d', $site->id)->update('site', array('url' => $_SERVER['HTTP_HOST'])); } } self::$current = $site; return $site; }