function display_page_header($module, $document, $id, $metadata, $current_version, $options = array()) { $is_archive = $document->isArchive(); $mobile_version = c2cTools::mobileVersion(); $content_class = $module . '_content'; $lang = $document->getCulture(); $version = $is_archive ? $document->getVersion() : NULL; $slug = ''; $prepend = _option($options, 'prepend', ''); $separator = _option($options, 'separator', ''); $nav_options = _option($options, 'nav_options'); $item_type = _option($options, 'item_type', ''); $nb_comments = _option($options, 'nb_comments'); $creator_id = _option($options, 'creator_id'); if (!$is_archive) { if ($module != 'users') { $slug = get_slug($document); $url = "@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug={$slug}"; } else { $url = "@document_by_id_lang?module={$module}&id={$id}&lang={$lang}"; } } else { $url = "@document_by_id_lang_version?module={$module}&id={$id}&lang={$lang}&version={$version}"; } if (!empty($prepend)) { $prepend .= $separator; } echo display_title($prepend . $document->get('name'), $module, true, 'default_nav', $url); if (!$mobile_version) { echo '<div id="nav_space"> </div>'; sfLoader::loadHelpers('WikiTabs'); $tabs = tabs_list_tag($id, $lang, $document->isAvailable(), 'view', $version, $slug, $nb_comments); echo $tabs; // liens internes vers les sections repliables du document if ($nav_options == null) { include_partial("{$module}/nav_anchor"); } else { include_partial("{$module}/nav_anchor", array('section_list' => $nav_options)); } // boutons vers des fonctions annexes et de gestion du document include_partial("{$module}/nav", isset($creator_id) ? array('id' => $id, 'document' => $document, 'creator_id' => $creator_id) : array('id' => $id, 'document' => $document)); if ($module != 'users') { sfLoader::loadHelpers('Button'); echo '<div id="nav_share" class="nav_box">' . button_share() . '</div>'; } } echo display_content_top('doc_content', $item_type); echo start_content_tag($content_class); if ($merged_into = $document->get('redirects_to')) { include_partial('documents/merged_warning', array('merged_into' => $merged_into)); } if ($is_archive) { include_partial('documents/versions_browser', array('id' => $id, 'document' => $document, 'metadata' => $metadata, 'current_version' => $current_version)); } }
function field_coord_data_if_set($document, $name, $options = array()) { $microdata = _option($options, 'microdata', null); $raw_value = $document->get($name); if (empty($raw_value)) { return ''; } switch ($name) { case 'lat': $suffix = $raw_value < 0 ? '°S' : '°N'; break; case 'lon': $suffix = $raw_value < 0 ? '°W' : '°E'; break; default: $suffix = ''; } $value = abs($raw_value); $deg = floor($value); $minTemp = 60 * ($value - $deg); $min = floor($minTemp); $sec = floor(60 * 100 * ($minTemp - $min)) / 100; $value = $deg . '° ' . $min . "' " . $sec . '" ' . str_replace('°', '', $suffix); return _format_data($name, $value) . ($microdata ? microdata_meta($microdata, $raw_value) : ''); }
/** * Create a form that allow to link the current document with several kinds of other docs * * @param module current document module * @param id current document id * @param modules_list list of modules available for association * @param default_selected default selected module in the dropdown list * @param field_prefix used to prevent to have ids conflict when multiple forms * @param $options * $hide if true, display button to hide/show the form + some text * $indicator, the ID of the HTML object used to display indications on the ajax status (Loading, Success, ...) * $removed_id, the ID of the HTML object to hide * $suggest_near_docs, for suggesting docs based on geolocalization * $suggest_friends, for suggesting people you go out with most * * FIXME js code is quite messy, would be great to move most of it into separate js file */ function c2c_form_add_multi_module($module, $id, $modules_list, $default_selected, $options) { // optional values $field_prefix = _option($options, 'field_prefix', 'list_associated_docs'); $hide = _option($options, 'hide', true); $indicator = _option($options, 'indicator', 'indicator'); $removed_id = _option($options, 'removed_id'); $suggest_near_docs = _option($options, 'suggest_near_docs', false); $suggest_friends = _option($options, 'suggest_friends', false); $conf = sfConfig::get('app_modules_list'); $modules_list = array_intersect($conf, $modules_list); $modules_list_i18n = array_map('__', $modules_list); // modules for which lookig for neighboors has some sense $near_docs_modules_list = array_intersect($conf, array('huts', 'parkings', 'sites', 'summits', 'routes')); $near_docs_module_ids_list = array_keys($near_docs_modules_list); // for site-site, parking-parking or summit-summit associations, be explicit about association direction if (in_array($module, array('sites', 'parkings', 'summits'))) { $modules_list_i18n[array_search($module, $modules_list)] = __('sub-' . $module); } // dropdown for choosing the type of docs to link $select_modules = select_tag('dropdown_modules', options_with_classes_for_select($modules_list_i18n, array($default_selected), array(), 'picto picto_'), array('class' => 'picto picto_' . $default_selected)); $picto_add = $hide ? '' : picto_tag('picto_add', in_array('users', $modules_list) ? __('Link an existing user or document') : __('Link an existing document')) . ' '; $out = $picto_add . $select_modules; // js code fro autocompletion $js = "\$('#dropdown_modules').change(function() {" . "var \$this = \$(this), value = \$this.val(), indicator = \$('#{$indicator}').show();" . "\$this.attr('class', 'picto picto_' + value);" . "\$.get('" . url_for("/{$module}/getautocomplete") . "', 'module_id=' + value + '&field_prefix={$field_prefix}" . ($suggest_near_docs ? "' + (['" . implode("','", $near_docs_module_ids_list) . "'].indexOf(value) > -1 ?\n '&extra_params=" . urlencode("lat=" . $suggest_near_docs['lat'] . "&lon=" . $suggest_near_docs['lon']) . "' : '')" : '\'') . ")" . ".always(function() { indicator.hide(); })" . ".done(function(data) { \$('#{$field_prefix}_form').html(data);"; if ($suggest_near_docs || $suggest_friends) { $suggest_exclude = _option($options, 'suggest_exclude', []); // additional code for suggesting documents in the neighborhood or friends when relevant $js = "function getSuggestions() {" . "var input = \$('#{$field_prefix}_form').find('input[autocomplete=off]')," . "module = input.attr('name').replace('_name', '')," . "exclude = " . json_encode($suggest_exclude) . "," . "suggestions_div = \$('.autocomplete-suggestions').empty();" . "if (['" . implode("','", $near_docs_modules_list) . "'].indexOf(module) > -1 || module == 'users') {" . "var params = (module == 'users') ? { id: \$('#name_to_use').attr('data-user-id') } :" . "{ lat:" . $suggest_near_docs['lat'] . ", lon:" . $suggest_near_docs['lon'] . " };" . "if (input.not('[data-suggest-no-exclude]') && exclude[module] && exclude[module].length) {" . "params['exclude'] = exclude[module].join(',');" . "}" . "\$.getJSON('/'+module+'/suggest', params)" . ".done(function(data) {" . "if (data.length) suggestions_div.append('" . __('Suggestions: ') . "');" . "\$.each(data, function(index, obj) {" . "suggestions_div.append(\$('<a href=\"'+obj.url+'\">'+obj.name+'</a>').click(function(e) {" . "if (e.which !== 1) return;" . "e.preventDefault();" . "\$('#{$field_prefix}_form input[type=text]').triggerHandler('forceselect.autocomplete'," . "\$('<span id='+obj.id+'>'+obj.name+'</span>'));" . "}), ' ');" . "});" . "});" . "}" . "}" . "\$('#{$field_prefix}_form_association a').one('click', getSuggestions);" . $js; $js .= "getSuggestions();"; } $js .= "});});"; $out .= javascript_queue($js); // form start $out .= c2c_form_remote_add_element("{$module}/addAssociation?main_id={$id}", $field_prefix, $indicator, $removed_id); // default form content $auto_complete_options = array('field_prefix' => $field_prefix); if ($suggest_near_docs && in_array($modules_list[$default_selected], $near_docs_modules_list)) { $auto_complete_options['extra_params'] = "lat=" . $suggest_near_docs['lat'] . "&lon=" . $suggest_near_docs['lon']; } $out .= '<div id="' . $field_prefix . '_form' . '" class="ac_form">' . input_hidden_tag('document_id', '0', array('id' => $field_prefix . '_document_id')) . input_hidden_tag('document_module', $modules_list[$default_selected], array('id' => $field_prefix . '_document_module')) . c2c_auto_complete($modules_list[$default_selected], $field_prefix . '_document_id', $auto_complete_options) . '</div></form><div class="autocomplete-suggestions"></div>'; // this is where the linked docs will be displayed after ajax $out = '<div class="doc_add">' . $out . '</div>'; if ($hide) { $picto_add_rm = '<span class="assoc_img picto_add" title="' . __('show form') . '"></span>' . '<span class="assoc_img picto_rm" title="' . __('hide form') . '"></span>'; $picto_add_rm = link_to_function($picto_add_rm, "C2C.toggleForm('{$field_prefix}_form')"); $title = '<div id="_association_tool" class="section_subtitle extra" data-tooltip>' . (in_array('users', $modules_list) ? __('Link an existing user or document') : __('Link an existing document')) . __(' :') . '</div> '; $pictos = ' '; foreach ($modules_list as $module) { $pictos .= picto_tag('picto_' . $module, __($module)); } $pictos = link_to_function($pictos, "C2C.toggleForm('{$field_prefix}_form')"); $pictos = '<div class="short_data">' . $pictos . '</div>'; $out = '<div class="one_kind_association empty_content">' . '<div class="association_tool hide" id="' . $field_prefix . '_form_association">' . $picto_add_rm . $title . $pictos . '<ul id="' . $field_prefix . '"><li style="display:none"></li></ul>' . $out . '</div></div>'; } return $out; }
public static function createHierarchy($docs, $linked_docs, $options = array()) { $type = _option($options, 'type'); $sort_field = _option($options, 'sort_field'); $show_sub_docs = _option($options, 'show_sub_docs', true); $current_doc_id = _option($options, 'current_doc_id', 0); if (!count($docs)) { return $docs; } // internal order between docs of same level $order = null; if (empty($sort_field)) { switch ($type) { case 'ss': $sort_field = 'elevation'; $order = SORT_DESC; break; case 'pp': $sort_field = 'elevation'; $order = SORT_ASC; break; default: $sort_field = 'name'; } } // add relation information to 1-hop docs foreach ($docs as $id => $doc) { $doc['parent_relation'] = array(); foreach ($linked_docs as $doc2) { if (isset($doc2['parent_relation'][$doc['id']])) { $docs[$id]['parent_relation'][$doc2['id']] = $doc2['parent_relation'][$doc['id']] == 'parent' ? 'child' : 'parent'; } } } $all_docs = array_merge($docs, $linked_docs); // Mark original document foreach ($all_docs as $key => $doc) { if ($doc['id'] == $current_doc_id) { $all_docs[$key]['is_doc'] = true; break; } } // if documents from different hierarchical levels are linked, we might have duplicates at that point // we should remove them $ids = $keys = array(); foreach ($all_docs as $key => $doc) { $pos = array_search($doc['id'], $ids); if ($pos !== false) { $all_docs[$keys[$pos]]['parent_relation'] = isset($all_docs[$keys[$pos]]['parent_relation']) ? $all_docs[$keys[$pos]]['parent_relation'] + $doc['parent_relation'] : $doc['parent_relation']; unset($all_docs[$key]); } else { $ids[] = $doc['id']; $keys[] = $key; } } // get all docs that don't have parents and put them in the output list with level 1 foreach ($all_docs as $id => $doc) { if (!isset($doc['parent_relation']) || array_search('parent', $doc['parent_relation']) === false) { $doc['level'] = 1; $output[] = $doc; unset($all_docs[$id]); } } $output = c2cTools::sortArray($output, $sort_field, null, $order); // for each level 1 doc, get corresponding children and insert them into the list // repeat the same process for level 2 docs for ($level = 2; $level <= 3; $level++) { $offset = 1; foreach ($output as $pos => $sorted_doc) { // only go through level 2 docs on second run if ($level == 3 && $sorted_doc['level'] !== 2) { continue; } $sub_docs = array(); foreach ($all_docs as $id => $doc) { if (array_key_exists($sorted_doc['id'], $doc['parent_relation'])) { $doc['level'] = $level; $sub_docs[] = $doc; unset($all_docs[$id]); } } if (count($sub_docs)) { $sub_docs = c2cTools::sortArray($sub_docs, $sort_field, null, $order); array_splice($output, $pos + $offset, 0, $sub_docs); $offset = $offset + count($sub_docs); } } } if (!$show_sub_docs) { // we don't want to display extra docs that are not parent from directly linked docs // as this would be useless information in some cases (for example, if I have a route linked to zermatt // I don't want to have the sub-parkings of zermatt listed in the route document) // we simply go from deepest level and remove leaves which are not dorectly linked for ($level = 3; $level > 0; $level--) { $temp = null; foreach (array_reverse($output, true) as $key => $doc) { if ($doc['level'] === $level && !isset($doc['directly_linked']) && (!isset($temp) || $temp['level'] <= $level)) { unset($output[$key]); } $temp = $doc; } } } return $output; }
function field_value_selector($name, $conf, $options) { $blank = _option($options, 'blank', false); $keepfirst = _option($options, 'keepfirst', true); $multiple = _option($options, 'multiple', false); $size = c2cTools::mobileVersion() ? _option($options, 'msize', 1) : _option($options, 'size', 0); $filled_options = _option($options, 'filled_options', true); $exclude = _option($options, 'exclude', null); $values = array_map('__', sfConfig::get($conf)); if ($exclude) { $exclude = is_array($exclude) ? $exclude : array($exclude); foreach ($exclude as $value) { unset($values[$value]); } } if (!$keepfirst) { unset($values[0]); } if ($filled_options) { $values[' '] = __('filled in'); $values['_'] = __('nonwell informed'); } $option_tags = options_for_select($values, '', array('include_blank' => $blank)); if ($multiple) { $select_param = array('multiple' => true); if ($size == 0) { $size = count($values); if ($filled_options) { $size -= 2; } } $select_param['size'] = $size; } else { $select_param = array(); } return select_tag($name, $option_tags, $select_param); }
function bbcode_textarea_tag($object, $fieldname, $options = null) { $method = _convert_fieldname_to_method($fieldname); // we don't want no_img options to be forwarded to textarea function // moreover we need to define default rows and cols values for xhtml strict // even if they are overriden by css $bbcode_options = $options; if (isset($options['no_img'])) { unset($options['no_img']); } if (isset($options['abstract'])) { unset($options['abstract']); } if (isset($options['route_line'])) { unset($options['route_line']); } $options['rows'] = '4'; $options['cols'] = '20'; $value = $object->get($fieldname); $height = _option($options, 'class', 'smalltext'); if (!empty($value)) { switch ($height) { case 'smalltext': $height_new = 'mediumtext'; break; case 'mediumtext': $height_new = 'medlargetext'; break; case 'medlargetext': $height_new = 'largetext'; break; default: $height_new = $height; } $height = $height_new; } $options['class'] = $height; return bbcode_toolbar_tag($object, $fieldname, $bbcode_options) . object_textarea_tag($object, $method, $options); }