/** * Executes view action. */ public function executeView() { parent::executeView(); if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) { $user = $this->getUser(); $prefered_cultures = $user->getCulturesForDocuments(); $associated_parkings = c2cTools::sortArray(array_filter($this->associated_docs, array('c2cTools', 'is_parking')), 'elevation'); if (count($associated_parkings)) { $associated_parkings = Association::createHierarchyWithBestName($associated_parkings, $prefered_cultures, array('type' => 'pp')); $associated_parkings = Parking::getAssociatedParkingsData($associated_parkings); } $this->associated_parkings = $associated_parkings; $related_portals = array(); Portal::getLocalPortals($related_portals, $this->associated_areas); $this->related_portals = $related_portals; $product_type_list = sfConfig::get('mod_products_types_list'); $product_type_index_list = $this->document->get('product_type'); $product_type_name_list = array(); foreach ($product_type_index_list as $product_type_index) { $product_type_name_list[] = $this->__($product_type_list[$product_type_index]); } $product_types = implode(', ', $product_type_name_list); $doc_name = $this->document->get('name'); $title = $doc_name; if ($this->document->isArchive()) { $version = $this->getRequestParameter('version'); $title .= ' :: ' . $this->__('revision') . ' ' . $version; } $title .= ' :: ' . $product_types; $this->setPageTitle($title); $description = array($product_types . ' :: ' . $doc_name, $this->getAreasList()); $this->getResponse()->addMeta('description', implode(' - ', $description)); } }
public function executeSwitchformfactor() { $user = $this->getUser(); if ($user->getAttribute('form_factor', 'desktop') === 'mobile') { $user->setAttribute('form_factor', 'desktop'); if (!c2cTools::mobileRegexp()) { // delete form_factor cookie (not needed) $this->getResponse()->setCookie('form_factor', null, -1); } else { // set cookie so that we are sure to prevent redirection on next sessions $this->getResponse()->setCookie('form_factor', 'desktop', time() + 60 * 60 * 24 * 30); } } else { $user->setAttribute('form_factor', 'mobile'); if (c2cTools::mobileRegexp()) { // delete form_factor cookie (not needed) $this->getResponse()->setCookie('form_factor', null, -1); } else { // set cookie so that we are sure to set form factor correctly on next sessions $this->getResponse()->setCookie('form_factor', 'mobile', time() + 60 * 60 * 24 * 30); } } // redirect to referer return $this->redirect($this->getRequest()->getReferer()); }
public function execute($filterChain) { $context = $this->getContext(); $user = $context->getUser(); if ($this->isFirstCall() && !$user->hasAttribute('form_factor')) { // if you make changes here, be sure also to check web/forums/include/common.php // and check varnish vcl file $cookie = $context->getRequest()->getCookie('form_factor'); if ($cookie === 'mobile' || $cookie === null && c2cTools::mobileRegexp()) { $user->setAttribute('form_factor', 'mobile'); } else { $user->setAttribute('form_factor', 'desktop'); } } if ($user->getAttribute('form_factor', 'desktop') === 'mobile') { // change layout for mobile_layout $context->getResponse()->setParameter($context->getModuleName() . '_' . $context->getActionName() . '_layout', 'mobile_layout', 'symfony/action/view'); $context->getResponse()->addStylesheet('/static/css/mobile.css', 'last'); } else { $context->getResponse()->addStylesheet('/static/css/default.css'); $context->getResponse()->addStylesheet('/static/css/menu.css'); $context->getResponse()->addStylesheet('/static/css/print.css', 'print'); } // execute next filter $filterChain->execute(); }
function loadRessources() { $response = sfContext::getInstance()->getResponse(); if (!c2cTools::mobileVersion()) { $response->addJavascript('/static/js/modal.js', 'last'); $response->addStylesheet('/static/css/modal.css', 'last'); } }
public function execute(&$value, &$error) { // file upload check foreach ($value['error'] as $error_code) { if ($error_code) { $error = $this->getParameter('upload_error'); return false; } } $validation = sfConfig::get('app_images_validation'); // weight check foreach ($value['size'] as $file_size) { if ($file_size > $validation['weight']) { $error = $this->getParameter('weight_error'); return false; } } // type check // FIXME with symfony 1.0, the type is the one given by the browser // we prefer to use or own mime type checker (this is what is done in further // versions of symfony, using system file check) foreach ($value['tmp_name'] as $file) { $file_type = c2cTools::getMimeType($file); if (!in_array($file_type, $validation['mime_types'])) { $error = $this->getParameter('type_error'); return false; } } foreach ($value['tmp_name'] as $k => $filename) { if ($value['type'][$k] != 'image/svg+xml') { list($width, $height) = getimagesize($filename); } else { // are there any script? if (SVG::hasScript($filename)) { $error = $this->getParameter('svg_script_error'); return false; } // dimensions $dimensions = SVG::getSize($filename); if ($dimensions === false) { $error = $this->getParameter('svg_error'); return false; } else { list($width, $height) = $dimensions; } } // height/width check if ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height']) { $error = $this->getParameter('max_dim_error'); return false; } if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) { $error = $this->getParameter('min_dim_error'); return false; } } return true; }
function phone_link($phone = '') { if (!empty($phone) && c2cTools::mobileVersion()) { $simple_phone = preg_replace('/\\(0\\)/', '', str_replace(array(' ', '.'), '', $phone)); // if number is not only digits,+,- do not try to present it as a link if (!ereg('[0-9\\+-]+', $simple_phone)) { return $phone; } $link = content_tag('a', $phone, array('href' => 'tel:' . $simple_phone)); return $link; } else { return $phone; } }
/** * Display flash message if needed */ function display_flash_message($type) { $flash = sfContext::getInstance()->getUser()->getAttribute($type, null, 'symfony/flash'); if ($flash) { $message = '<div class="' . $type . '" id="' . $type . '"><div>' . $flash . '</div></div>'; if (!c2cTools::mobileVersion()) { // show feedback div, highlight it, and then fade it out and remove it $js = javascript_queue("\$('#{$type}').delay(3000).animate({opacity:0}, {duration:1500, complete: function() { \$(this).hide(); }});"); } else { $js = javascript_queue("\$('#{$type}').click(function() { \$(this).hide(); });"); } return $message . $js; } }
public function execute(&$value, &$error) { $allowed_mime_types = $this->getParameterHolder()->get('allowed'); $allowed_mime_types = is_array($allowed_mime_types) ? $allowed_mime_types : array($allowed_mime_types); // FIXME with symfony 1.0, the type is the one given by the browser // we prefer to use or own mime type checker (this is what is done in further // versions of symfony, using system file check) $mime_type = c2cTools::getMimeType($value['tmp_name']); if (!in_array($mime_type, $allowed_mime_types)) { $error = $this->getParameter('type_error'); return false; } return true; }
function geocode_auto_complete($name, $service) { $mobile_version = c2cTools::mobileVersion(); $service_class = $service === 'nominatim' ? ' nominatim' : ' geonames'; $out = input_tag($name, '', array('class' => 'geocode_auto_complete' . $service_class, 'placeholder' => __('enter place name'), 'data-noresult' => __('no results'))); if ($mobile_version) { $out .= content_tag('span', '<br />' . __('autocomplete_help'), array('class' => 'mobile_auto_complete_background')); $out .= content_tag('span', 'X', array('class' => 'mobile_auto_complete_escape')); } // following script will automatically intanciate geocode autocompleter $out .= javascript_queue('$.ajax({ url: "' . minify_get_combined_files_url('/static/js/geocode_autocompleter.js') . '", dataType: "script", cache: true});'); return $out; }
/** * Move given image and its resized versions. */ public static function moveAll($file, $pathFrom, $pathTo) { c2cTools::log("moving {$file} from {$pathFrom} to {$pathTo}"); $types = sfConfig::get('app_images_types', array()); list($file_name, $file_ext) = self::getFileNameParts($file); // move original $success = rename($pathFrom . DIRECTORY_SEPARATOR . $file, $pathTo . DIRECTORY_SEPARATOR . $file); // move thumbs foreach ($types as $type) { $success = $success && rename($pathFrom . DIRECTORY_SEPARATOR . $file_name . $type['suffix'] . $file_ext, $pathTo . DIRECTORY_SEPARATOR . $file_name . $type['suffix'] . $file_ext); } // move svg if any if (file_exists($pathFrom . DIRECTORY_SEPARATOR . $file_name . '.svg')) { $success = $success && rename($pathFrom . DIRECTORY_SEPARATOR . $file_name . '.svg', $pathTo . DIRECTORY_SEPARATOR . $file_name . '.svg'); } return $success; }
/** * Adds given address to given mailing list. * @param string listname * @param string email * @return boolean status (true=success, false=failure) */ public static function subscribe($listname, $email) { $conn = sfDoctrine::Connection(); try { $conn->beginTransaction(); $sympa = new Sympa(); $sympa->list_subscriber = $listname; $sympa->user_subscriber = $email; $sympa->save(); $conn->commit(); return true; } catch (Exception $e) { // Subscription failed! For instance because email address was already registered. $conn->rollback(); c2cTools::log("Failed adding address {$email} to list {$listname}: " . $e->getMessage()); return false; } }
function language_select_list($module, $id, $current_language, $translated_languages) { $mobile_version = c2cTools::mobileVersion(); $items = array(); foreach (Language::getAll() as $language => $value) { $lang = format_language_c2c($language); if ($current_language == $language) { $items[] = '<div class="current_lang">' . ($mobile_version ? $language : $lang) . '</div>'; } else { $existing_lang = in_array($language, $translated_languages); $options = $existing_lang ? array('class' => 'translated') : array('class' => 'not_translated', 'rel' => 'nofollow'); if (!$mobile_version) { $items[] = link_to($lang, "@document_by_id_lang?module={$module}&id={$id}&lang={$language}", $options); } else { $items[] = $existing_lang ? link_to($language, "@document_by_id_lang?module={$module}&id={$id}&lang={$language}", $options) : '<span class="not_translated">' . $language . '</span>'; } } } return implode(' | ', $items); }
public function executeGetmultipleselect() { $mobile_version = c2cTools::mobileVersion(); $separate_prefs = $this->hasRequestParameter('sep_prefs') ? $this->getRequestParameter('sep_prefs') : 'true'; $separate_prefs = $separate_prefs == 'false' ? false : true; $area_type = $this->getRequestParameter('area_type'); if (!$mobile_version) { $default_width = 'auto'; $default_height = '350px'; } else { $default_width = '216px'; $default_height = '3.8em'; } $height = $this->hasRequestParameter('height') ? $this->getRequestParameter('height') . 'px' : $default_height; $width = $this->hasRequestParameter('width') ? $this->getRequestParameter('width') . 'px' : $default_width; $select_id = $this->hasRequestParameter('select_id') ? $this->getRequestParameter('select_id') : 'places'; $select_name = $this->hasRequestParameter('select_id') ? $this->getRequestParameter('select_name') : 'areas'; $areas = $this->getAreas($area_type, $separate_prefs); sfLoader::loadHelpers(array('Tag', 'Form')); return $this->renderText(select_tag($select_name, options_for_select($areas, $separate_prefs ? null : c2cPersonalization::getInstance()->getPlacesFilter()), array('id' => $select_id, 'multiple' => true, 'style' => 'width:' . $width . '; height:' . $height . ';')) . input_hidden_tag($select_id . '_type', $area_type)); }
public function execute($filterChain) { $context = $this->getContext(); $session_user = $context->getUser(); $cookie_name = sfConfig::get('app_remember_key_cookie_name', 'c2corg_remember'); $cookie_value = $context->getRequest()->getCookie($cookie_name); if ($this->isFirstCall() && !$session_user->isConnected() && !is_null($cookie_value)) { c2cTools::log('{rememberFilter} user has a cookie, trying to auto login'); $remember_key = RememberKey::getKey($cookie_value); if ($remember_key) { c2cTools::log('{rememberFilter} user found from his cookie'); $user = $remember_key->getUser(); if ($user->exists()) { $session_user->signIn($user->get('private_data')->getLoginName(), $user->get('private_data')->getPassword(), true, true); } // User has signed in, and is now correctly in symfony session. However, forums // and several personnalization functions rely on cookies, that will be sent with the request, // but are not yet 'available' from javascript if the value expired from previous sessions (they will be on next page) // easiest solution is to force the browser to reload the current page // we only do this for GET requests $request = $this->getContext()->getRequest(); if ($request->getMethod() == sfRequest::GET) { // symfony 1.0 getUriPrefix is not working well with https on haproxy // it then tries to redirect to https://site.org:80, which is wrong $proto = $request->isSecure() ? 'https' : 'http'; $request_uri = $proto . '://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']; $this->getContext()->getController()->redirect($request_uri); exit; } } else { // delete cookie value in client so that no more requests are made to the db sfContext::getInstance()->getResponse()->setCookie($cookie_name, ''); // log this c2cTools::log('{rememberFilter} user has unknown remember key!'); c2cActions::statsdIncrement('bad_remember_cookie', 'symfony.' . sfConfig::get('sf_environment') . '.users.'); } } $filterChain->execute(); }
function start_section_tag($label, $container_id, $state = 'opened', $map = false, $first = false, $hide = false, $show_tip = true) { $class = 'article_titre_bg'; if ($first) { $class .= ' hfirst'; } $picto_class = $state == 'opened' ? 'picto_close' : 'picto_open'; $status = __($state == 'opened' ? 'section close' : 'section open'); $label = picto_tag($picto_class, '', array('id' => $container_id . '_toggle')) . __($label); if ($show_tip && !c2cTools::mobileVersion()) { $label .= '<span id="tip_' . $container_id . '" class="tips">[' . $status . ']</span>'; $up = '<a href="#header">' . picto_tag('action_up', __('menu'), array('class' => 'go_up')) . '</a>'; } else { $up = ''; } $style = $hide ? '" style="display:none' : ''; $html = '<div class="' . $class . '" id="' . $container_id . '_tbg' . $style . '">' . '<div class="title" id="' . $container_id . '_section_title" title="' . $status . '">' . '<a href="#" id="' . $container_id . '" data-toggle-view="' . $container_id . '">' . $label . '</a>' . $up . '</div>' . '</div>'; if (!$map) { $display = $state == 'opened' && !$hide ? '' : ' style="display:none;"'; $html .= '<section id="' . $container_id . '_section_container" class="section"' . $display . '>'; } return $html; }
<?php use_helper('Language', 'Sections', 'Viewer', 'AutoComplete', 'General', 'MyForm'); $is_connected = $sf_user->isConnected(); $is_moderator = $sf_user->hasCredential(sfConfig::get('app_credentials_moderator')); $id = $sf_params->get('id'); $lang = $document->getCulture(); $is_not_archive = !$document->isArchive(); $is_not_merged = !$document->get('redirects_to'); $mobile_version = c2cTools::mobileVersion(); $show_link_tool = $is_not_archive && $is_not_merged && $is_connected && !$mobile_version; display_page_header('articles', $document, $id, $metadata, $current_version, array('item_type' => 'http://schema.org/Article', 'nb_comments' => $nb_comments)); // lang-dependent content echo start_section_tag('Article', 'description'); include_partial('documents/i18n_section', array('document' => $document, 'languages' => $sf_data->getRaw('languages'), 'needs_translation' => $needs_translation, 'images' => $associated_images, 'filter_image_type' => $document->get('article_type') == 1)); echo end_section_tag(); // lang-independent content starts here echo start_section_tag('Information', 'data'); include_partial('data', array('document' => $document, 'nb_comments' => $nb_comments)); if ($is_not_archive) { echo '<div class="all_associations">'; include_partial('areas/association', array('associated_docs' => $associated_areas, 'module' => 'areas')); echo '</div>'; } echo end_section_tag(); if ($is_not_archive && $is_not_merged) { $is_personal_article = $document->get('article_type') == 2; // if the user is not a moderator, and personal article, use javascript to distinguish // between document author(s) and others $author_specific = !$is_moderator && $is_connected && $is_personal_article; if ($author_specific) {
public function execute(&$value, &$error) { // whether the image was sent via plupload or not $plupload = (bool) (!$this->getContext()->getRequest()->getParameter('noplupload', false)); // file upload check if ($value['error']) { // if plupload was used, most probably the resized image // was too big, so provide custom error message if ($plupload) { $error = $this->getParameter('upload_resize_error'); } else { $error = $this->getParameter('upload_error'); } return false; } $validation = sfConfig::get('app_images_validation'); if ($value['size'] > $validation['weight']) { // same as above (in this case, max_file_size from php.ini is bigger than $validation['weight']) if ($plupload) { $error = $this->getParameter('weight_resize_error'); } else { $error = $this->getParameter('weight_error'); } return false; } // type check // with symfony 1.0, the type is the one given by the browser // we prefer to use or own mime type checker (this is what is done in further // versions of symfony, using system file check) $mime_type = c2cTools::getMimeType($value['tmp_name']); if (!in_array($mime_type, $validation['mime_types'])) { $error = $this->getParameter('type_error'); return false; } if ($mime_type != 'image/svg+xml') { list($width, $height) = getimagesize($value['tmp_name']); } else { // are there any script? if (SVG::hasScript($value['tmp_name'])) { $error = $this->getParameter('svg_script_error'); return false; } // dimensions $dimensions = SVG::getSize($value['tmp_name']); if ($dimensions === false) { $error = $this->getParameter('svg_error'); return false; } else { list($width, $height) = $dimensions; } } // height/width check (max width not checked for SVG, it is automatically resized) if ($mime_type != 'image/svg+xml' && ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height'])) { $error = $this->getParameter('max_dim_error'); return false; } if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) { $error = $this->getParameter('min_dim_error'); return false; } return true; }
<?php use_helper('Language'); $module = $sf_context->getModuleName(); if (!$document->isArchive()) { ?> <div class="switch_lang"> <div class="article_infos_titre"> <?php echo (c2cTools::mobileVersion() ? __('Switch lang short:') : __('Switch lang:')) . '</div>'; echo language_select_list($module, $document->get('id'), $document->getCulture(), $sf_data->getRaw('languages')); // instead of $languages: XSS protection deactivation ?> </div> <?php } ?> <?php if ($document->isAvailable()) { ?> <div class="article_contenu"> <?php $i18n_args = array('document' => $document, 'needs_translation' => isset($needs_translation) ? $needs_translation : false, 'images' => isset($images) ? $images : null); if (isset($filter_image_type)) { $i18n_args['filter_image_type'] = $filter_image_type; } if (isset($associated_books)) { $i18n_args['associated_books'] = $associated_books; $i18n_args['main_id'] = $document->get('id'); }
function button_next($module, $current_id) { $modname = strtolower(c2cTools::module2model($module)); return link_to(__("next {$modname}"), "@goto_next?module={$module}&id={$current_id}", array('title' => __("Go to next {$modname}"), 'class' => 'action_next nav_edit')); }
<?php use_helper('Pagination', 'GeoJson'); $id = $sf_params->get('id'); $lang = $sf_params->get('lang'); $module = $sf_context->getModuleName(); $format = $sf_data->getRaw('format'); $use_keys = in_array('keys', $format); $text_html = in_array('html', $format); $add_gpx_track = in_array('track', $format); $add_all_fields = in_array('full', $format); $add_conditions = $add_all_fields || in_array('cond', $format); $add_text = !in_array('notext', $format); if (!isset($items) && $nb_results > 0) { $items = $pager->getResults('array', ESC_RAW); $items = Language::parseListItems($items, c2cTools::module2model($module)); } elseif ($nb_results == 0) { $items = array(); $totalItems = $startIndex = $count = $hasPreviousPage = $hasNextPage = 0; } if (isset($pager)) { $totalItems = $pager->getNbResults(); $startIndex = $pager->getMaxPerPage() * ($pager->getPage() - 1) + 1; $count = min($pager->getMaxPerPage(), $pager->getNbResults() - ($pager->getPage() - 1) * $pager->getMaxPerPage()); $hasPreviousPage = $pager->getPage() != 1; $hasNextPage = $pager->getPage() != $pager->getLastPage() && $nb_results; } // compute prev and next uris if ($hasPreviousPage || $hasNextPage) { $uri = _addUrlParameters(_getBaseUri(), array('page')); $uri .= _getSeparator($uri) . 'page=';
// If the posting user is logged in, increment his/her post count if (!$pun_user['is_guest']) { if ($pun_user['num_posts'] == 0) { } $low_prio = $db_type == 'mysql' ? 'LOW_PRIORITY ' : ''; $db->query('UPDATE ' . $low_prio . $db->prefix . 'users SET num_posts=num_posts+1, last_post=' . $now . ' WHERE id=' . $pun_user['id']) or error('Unable to update user', __FILE__, __LINE__, $db->error()); } // Redirect to "symfony app" after comment has been posted if ($is_comment) { $doc_param = get_doc_param($cur_posting['subject'] ? $cur_posting['subject'] : $subject); // clear symfony cache for the corresponding docs view, diff, history.. - in order to have number of comments properly displayed) c2cTools::clearCommentCache($doc_param[0], $doc_param[1]); // if this is the first comment on an outing or an image, we should send notifications to concerned people // and subscribe them to topic if ($fid) { $users = c2cTools::getUsersToNotify($doc_param[0]); if (!empty($users)) { // subscribe users to topic $values = array(); foreach ($users as $user) { $values[] = '(\'' . $user . "', '{$new_tid}')"; } $db->query('INSERT INTO ' . $db->prefix . 'subscriptions (user_id, topic_id) VALUES ' . implode(', ', $values)) or error('Unable to add subscription', __FILE__, __LINE__, $db->error()); // TODO maybe just continue silently if subscription fails? // send mails to concerned users require PUN_ROOT . 'include/email.php'; $result = $db->query('SELECT id, language, email FROM ' . $db->prefix . 'users WHERE id IN (' . implode(', ', $users) . ')') or error('Unable to fetch user languages', __FILE__, __LINE__, $db->error()); // TODO idem if ($db->num_rows($result) != count($users)) { message($lang_common['Bad request']); }
echo '<div class="all_associations col_right col_66 no_print">'; include_partial('routes/association', array('associated_docs' => $associated_routes, 'module' => 'routes', 'document' => $document, 'show_link_to_delete' => $show_link_to_delete, 'type' => 'rr', 'strict' => false, 'display_info' => true, 'title' => 'variants')); if ($show_link_tool && !$mobile_version) { $modules_list = array('summits', 'sites', 'huts', 'parkings', 'routes', 'books', 'articles'); $options = array('field_prefix' => 'multi_1'); // try to determine the "center" of the route: // - centroid if it has track // - highest linked summits with coordinates if (check_not_empty_doc($document, 'lon')) { $options['suggest_near_docs'] = array('lon' => $document['lon'], 'lat' => $document['lat']); } else { $summits_with_geom = array_filter($sf_data->getRaw('associated_summits'), function ($n) { return isset($n['pointwkt']); }); if (count($summits_with_geom)) { $ref_summit = c2cTools::extractHighest($summits_with_geom); $options['suggest_near_docs'] = array('lon' => $ref_summit['lon'], 'lat' => $ref_summit['lat']); } } if (isset($options['suggest_near_docs'])) { $options['suggest_exclude'] = array('summits' => get_directly_linked_ids($associated_summits), 'sites' => get_directly_linked_ids($associated_sites), 'huts' => get_directly_linked_ids($associated_huts), 'parkings' => get_directly_linked_ids($associated_parkings)); } echo c2c_form_add_multi_module('routes', $id, $modules_list, 3, $options); } echo '</div>'; } include_partial('documents/geom_warning', array('document' => $document, 'message' => 'No GPX track, please edit this document to add some')); } echo end_section_tag(); // lang-dependent content echo start_section_tag('Description', 'description');
/** * Overriddes the one in parent class * this is because we sometimes have to do things when centroid coordinates have moved. */ protected function refreshGeoAssociations($id) { c2cTools::log("Entering refreshGeoAssociations for outings linked with route {$id}"); $associated_outings = Association::findAllAssociatedDocs($id, array('id', 'geom_wkt'), 'ro'); if (count($associated_outings)) { $geoassociations = GeoAssociation::findAllAssociations($id, null, 'main'); // we create new associations : // (and delete old associations before creating the new ones) // (and do not create outings-maps associations) foreach ($associated_outings as $outing) { $i = $outing['id']; if (!$outing['geom_wkt']) { // replicate geoassoces from doc $id to outing $i and delete previous ones // (because there might be geoassociations created by this same process) // and we do not replicate map associations to outings $nb_created = GeoAssociation::replicateGeoAssociations($geoassociations, $i, true, false); c2cTools::log("created {$nb_created} geo associations for outing N° {$i}"); $this->clearCache('outings', $i, false, 'view'); } } } }
/* In this section we put code for immediately hiding some sections according * to preferences stored in fold cookie * * The sections are hidden (or not) right after they are created in the DOM in * order to prevent visual glitches. Thus, the javascript has to be ready from * the beginning. As the file is kept very small (less than 1kb) it is ok to inline * it, avoiding an extra request. * * Following js code is the minified version of the web/static/fold_init*.js files * We have different vesions depending on the different use cases. Basically, the * following sections can be concerned: * - left navigation on standard version (every page) * - sections on home and portals * - map section (n that cases, some additional code is added by the map partials) */ $mobile = c2cTools::mobileVersion(); $module = $sf_context->getModuleName(); $action = $sf_context->getActionName(); if ($mobile) { if ($action == 'home' || $module == 'portals' && $action == 'view') { // fold_init_home_mobile.js ~ 510b ?> (function(e,t){e.shouldHide=function(e,n){var o=/(?:^|;)\s?fold=([tfx]{20})(?:;|$)/.exec(t.cookie) if(o)switch(o[1].charAt(e)){case"t":return!1 case"f":return!0}return!n},e.setSectionStatus=function(n,o,a){if(e.shouldHide(o,a)){if("map_container"==n)return!0 var s=e.section_open t.getElementById(n+"_section_container").style.display="none",t.getElementById(n+"_toggle").title=s for(var l=t.querySelectorAll("#"+n+" .nav_box_top"),i=0;i<l.length;i++)l[i].className+=" small"}}})(window.C2C=window.C2C||{},document) <?php } else { // fold init_default_mobile.js ~280b
/** This function is used to validate an uploaded image. * It is quite similar to myImageValidator, except * that we cannot validate images one by one (when several ones * are uploaded at the same time). Thus, we have some custom * validation mechanism here */ public static function validate_image(&$value, &$error, $i) { // file upload check if ($value['error'][$i]) { $error = 'file failed to upload'; return false; } $validation = sfConfig::get('app_images_validation'); if ($value['size'][$i] > $validation['weight']) { $error = 'file is too big'; return false; } // type check // FIXME with symfony 1.0, the type is the one given by the browser // we prefer to use or own mime type checker (this is what is done in further // versions of symfony, using system file check) $mime_type = c2cTools::getMimeType($value['tmp_name'][$i]); if (!in_array($mime_type, $validation['mime_types'])) { $error = 'file has incorrect type'; return false; } if ($mime_type != 'image/svg+xml') { list($width, $height) = getimagesize($value['tmp_name'][$i]); } else { // are there any script? if (SVG::hasScript($value['tmp_name'][$i])) { $error = 'file cannot contain scripts'; return false; } // dimensions $dimensions = SVG::getSize($value['tmp_name'][$i]); if ($dimensions === false) { $error = 'file is malformed SVG'; return false; } else { list($width, $height) = $dimensions; } } // height/width check if ($width > $validation['max_size']['width'] || $height > $validation['max_size']['height']) { $error = 'file is too large'; return false; } if ($width < $validation['min_size']['width'] || $height < $validation['min_size']['height']) { $error = 'min_dim_error'; return false; } return true; }
public function executeCdaredirect() { if ($this->getRequest()->getMethod() == sfRequest::POST) { $module = $this->getRequestParameter('module'); $join = ''; $criteria = array(); // tc criteria if ($module == 'routes') { $criteria[] = 'tp=1-2-4-5'; } elseif ($module == 'outings') { $criteria[] = 'owtp=1'; } // area criteria $this->addListParam($criteria, 'areas'); // activities criteria $this->addListParam($criteria, 'stags'); // for paragliding activity $activities = $this->getRequestParameter('act'); $group_activities = $activities; if ($key = array_search(8, $group_activities)) { unset($group_activities[$key]); } $nb_grp = count($group_activities); $group_name = ''; if ($nb_grp == 1) { $group_list = sfConfig::get('app_cda_activities_id'); $group_name = $group_list[reset($group_activities)]; } if ($group_name == 'crag') { $key = array_search(400, $activities); if ($module == 'outings') { $activities[$key] = 4; } else { unset($activities[$key]); } } if (count($activities)) { $criteria[] = 'act=' . implode('-', $activities); } // module criteria if ($nb_grp == 1 && in_array($group_name, array('crag', 'climbing'))) { if ($module == 'routes' && $group_name == 'crag') { $module = 'sites'; } if ($module == 'outings') { if ($group_name == 'crag') { $join = 'sites'; } else { $join = 'routes'; } } } // around criteria if ($module == 'routes') { $around = 'parnd'; } elseif ($module == 'sites') { $around = 'tarnd'; } elseif ($module == 'outings') { if ($nb_grp == 1 && $group_name == 'crag') { $around = 'tarnd'; } else { $around = 'sarnd'; } } $has_around = $this->addAroundParam($criteria, 'arnd', $around); if ($has_around) { $join = ''; } // elevation critera if (!($nb_grp == 1 && $group_name == 'crag')) { $elevation = $this->getRequestParameter('elevation'); if ($elevation >= 1 && $elevation <= 3) { $elevation_range = sfConfig::get('app_cda_elevation_range'); $param = $elevation_range[$module . '_param']; $value = $elevation_range[$elevation]; $criteria[] = "{$param}={$value}"; } } // difficulty criteria if (!($nb_grp == 1 && $group_name == 'crag' && $module == 'outings')) { $difficulty = $this->getRequestParameter('difficulty'); if ($nb_grp == 1 && $difficulty >= 1 && $difficulty <= 3) { $group_info = sfConfig::get('app_cda_difficulty_range_' . $group_name); $param = $group_info['param']; $value = $group_info[$difficulty]; $criteria[] = "{$param}={$value}"; $join = ''; } } // join criteria if (!empty($join)) { $criteria[] = "{$join}= "; } $route = '@default?module=' . $module . '&action=list&' . implode('&', $criteria); c2cTools::log("redirecting to {$route}"); $this->redirect($route); } else { $this->setErrorAndRedirect('Invalid request parameters', '@cdasearch'); } }
public static function buildListCriteria($params_list) { $criteria = $conditions = $values = $joins = $joins_order = array(); $criteria[0] = array(); // conditions $criteria[1] = array(); // values $criteria[2] = array(); // joins $criteria[3] = array(); // joins for order // criteria for disabling personal filter self::buildPersoCriteria($conditions, $values, $joins, $params_list, 'sites'); // orderby criteria $orderby_list = c2cTools::getRequestParameterArray(array('orderby', 'orderby2', 'orderby3')); self::buildOrderCondition($joins_order, $orderby_list, array('tnam'), array('site_i18n', 'join_site')); // area criteria self::buildAreaCriteria($criteria, $params_list, 's'); // return if no criteria if (isset($joins['all']) || empty($params_list)) { $criteria[0] = array_merge($criteria[0], $conditions); $criteria[1] = array_merge($criteria[1], $values); $criteria[2] += $joins; $criteria[3] += $joins_order; return $criteria; } // site criteria $has_name = Site::buildSiteListCriteria($criteria, $params_list, true); if ($has_name === 'no_result') { return $has_name; } // summit criteria $has_name = Summit::buildSummitListCriteria($criteria, $params_list, false, 'main_id'); if ($has_name === 'no_result') { return $has_name; } // hut criteria $has_name = Hut::buildHutListCriteria($criteria, $params_list, false, 'main_id'); if ($has_name === 'no_result') { return $has_name; } // parking criteria $has_name = Parking::buildParkingListCriteria($criteria, $params_list, false, 'main_id'); if ($has_name === 'no_result') { return $has_name; } // outing criteria $has_name = Outing::buildOutingListCriteria($criteria, $params_list, false, 'linked_id'); if ($has_name === 'no_result') { return $has_name; } // user criteria $has_name = User::buildUserListCriteria($criteria, $params_list, false, 'main_id'); if ($has_name === 'no_result') { return $has_name; } // image criteria $has_name = Image::buildImageListCriteria($criteria, $params_list, false); if ($has_name === 'no_result') { return $has_name; } $criteria[0] = array_merge($criteria[0], $conditions); $criteria[1] = array_merge($criteria[1], $values); $criteria[2] += $joins; $criteria[3] += $joins_order; return $criteria; }
} } $is_first = false; if ($module != 'users') { // name hierarchical display $name = $doc['name']; if ($level > 1 || $reduce_name) { if ($level > 1) { $cut_level = 3; } else { $cut_level = 2; } $name_list = explode(' - ', $name, $cut_level); $name = array_pop($name_list); } $name = c2cTools::multibyte_ucfirst($name); if (!$is_doc) { $url = "@document_by_id_lang_slug?module={$module}&id={$doc_id}" . '&lang=' . $doc['culture'] . '&slug=' . make_slug($doc['name']); } } else { $name = $doc['name']; if (!$is_doc) { $url = "@document_by_id_lang?module={$module}&id={$doc_id}" . '&lang=' . $doc['culture']; } } echo $is_doc ? '<span class="current">' . $name . '</span>' : link_to($name, $url); // elevation info if (isset($doc['lowest_elevation']) && is_scalar($doc['lowest_elevation']) && $doc['lowest_elevation'] != $doc['elevation']) { echo ' ' . $doc['lowest_elevation'] . __('meters') . __('range separator') . $doc['elevation'] . __('meters'); } else { if (isset($doc['elevation']) && is_scalar($doc['elevation'])) {
} catch (Exception $e) { $items = array(); } if (count($items) == 0) { ?> <p><?php echo __('No recent changes available'); ?> </p> <?php } else { ?> <ul class="docs_changes"> <?php $list_item = 0; $max_items = c2cTools::mobileVersion() ? sfConfig::get('app_recent_documents_latest_docs_mobile_limit') : 100; foreach ($items as $item) { ?> <?php if ($list_item > $max_items) { break; } // Add class to know if li is odd or even if ($list_item % 2 == 1) { ?> <li class="odd"> <?php } else { ?> <li class="even"> <?php
function format_book_data($books, $type, $main_id, $is_moderator = false) { $type_list = $type . '_list'; $module = 'books'; $main_module = c2cTools::Letter2Module(substr($type, 1, 1)); $strict = 1; $html = '<div class="association_content_inside_field">'; foreach ($books as $book) { $doc_id = $book['id']; $idstring = $type . '_' . $doc_id; $class = 'linked_elt'; $html .= '<div class="' . $class . '" id="' . $idstring . '">' . '<div class="assoc_img picto_' . $module . '" title="' . ucfirst(__($module)) . '"></div>'; $name = ucfirst($book['name']); $url = "@document_by_id_lang_slug?module={$module}&id={$doc_id}" . '&lang=' . $book['culture'] . '&slug=' . make_slug($book['name']); $html .= link_to($name, $url); if (isset($book['author']) && trim($book['author']) != '') { $html .= ' - ' . $book['author']; } if (isset($book['publication_date']) && trim($book['publication_date']) != '') { $html .= ' - ' . $book['publication_date']; } if ($is_moderator && $main_id && !c2cTools::mobileVersion()) { $html .= c2c_link_to_delete_element($type, $doc_id, $main_id, false, $strict); } $html .= '</div>'; } $html .= '</div>'; return $html; }