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')); }
public function executeTooltipPreview() { $module = $this->getRequestParameter('module'); $id = $this->getRequestParameter('id'); if ($module == 'users' && !$this->getUser()->isConnected() && !UserPrivateData::hasPublicProfile($id)) { $this->name = $this->__('not available'); } else { $model = c2cTools::module2model($module); $langs = sfContext::getInstance()->getUser()->getPreferedLanguageList(); $i18n = Doctrine_Query::create()->select('m.culture, m.name')->from("{$model}I18n m")->where('m.id = ?', array($id))->execute(); $old_lang = 200; foreach ($i18n as $name) { $lang_pos = array_search($name->get('culture'), $langs); if ($lang_pos === false) { $lang_pos = 10; } // test if language is prefered over the older if ($lang_pos < $old_lang) { $old_lang = $lang_pos; $uname = $name->get('name'); } } $this->name = $uname; } $this->setJsonResponse(); }
<?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=';
<?php use_helper('Date', 'History', 'MyForm', 'Language', 'Viewer', 'WikiTabs', 'SmartFormat', 'sfBBCode'); use_javascript('/static/js/diff.js', 'last'); use_javascript('/static/js/history_tools.js', 'last'); $is_moderator = $sf_user->hasCredential(sfConfig::get('app_credentials_moderator')); $module = $sf_context->getModuleName(); $model = c2cTools::module2model($module); $i18n_archive = $model . 'I18nArchive'; $lang = $sf_params->get('lang'); $id = $sf_params->get('id'); $table_list_even_odd = 0; $slug = make_slug($document[$i18n_archive]['name']); echo display_title(isset($title_prefix) ? $title_prefix . __(' :') . ' ' . $document_name : $document_name, $module); echo '<div id="nav_space"> </div>'; echo tabs_list_tag($id, $lang, $exists_in_lang, 'history', null, $slug, $nb_comments); echo display_content_top('doc_content'); echo start_content_tag($module . '_content'); ?> <p><?php echo __('Viewing history from %1% in %2%', array('%1%' => $document_name, '%2%' => format_language_c2c($lang))); ?> </p> <p><?php echo __('Legend:') . ' * = ' . __('current version') . ', <strong>' . __('minor_tag') . '</strong> = ' . __('minor modification'); ?> </p> <?php echo form_tag("@document_diff_post?module={$module}&id={$id}&lang={$lang}", array('method' => 'post'));
/** * Executes easy upload action * Due to a limitation in flash... only the name of the file is usable * so other informations are sent by reference... */ public function executeUpload() { $document_id = $this->getRequestParameter('document_id'); $mod = $this->getRequestParameter('mod'); $redir_route = "@document_by_id?module={$mod}&id={$document_id}"; $request = $this->getRequest(); if ($request->getMethod() == sfRequest::POST) { // check if user has the rights to upload images to the document $user = $this->getUser(); $user_id = $user->getId(); $user_valid = true; switch ($mod) { case 'users': if ($user_id != $document_id) { $user_valid = false; } break; case 'outings': if (!Association::find($user_id, $document_id, 'uo')) { $user_valid = false; } break; case 'images': $image = Document::find('Image', $document_id, array('image_type')); if (!$image) { break; } $creator = $image->getCreator(); if ($image->get('image_type') == 2 && $creator['id'] != $user_id) { $user_valid = false; } break; case 'articles': $article = Document::find('Article', $document_id, array('article_type')); if ($article->get('article_type') == 2 && !Association::find($user_id, $document_id, 'uc')) { $user_valid = false; } break; default: break; } if (!$user_valid && !$user->hasCredential('moderator')) { return $this->setErrorAndRedirect('Operation not allowed', $redir_route); } c2cTools::log('uploading files'); $temp_dir = sfConfig::get('sf_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_temp_directory_name') . DIRECTORY_SEPARATOR; if (!is_dir($temp_dir) || !is_writable($temp_dir)) { return $this->setErrorAndRedirect('image dir unavailable', $redir_route); } $uploaded_files = $request->getFiles(); $uploaded_files = $uploaded_files['image_file']; $images_names = $this->getRequestParameter('name'); $images_categories = $this->hasRequestParameter('categories') ? $this->getRequestParameter('categories') : array(); $images_types = $this->getRequestParameter('image_type'); // Note: sfWebRequest::getFile...() methods cannot be used directy since uploaded files // are transmitted in a image[] POST var that does not fit with those methods. foreach ($uploaded_files['tmp_name'] as $key => $filename) { $unique_filename = c2cTools::generateUniqueName(); $file_ext = Images::detectExtension($filename); c2cTools::log("processing file {$unique_filename}"); // upload file in a temporary folder $new_location = $temp_dir . $unique_filename . $file_ext; c2cTools::log("moving file to {$new_location}"); if (!move_uploaded_file($filename, $new_location)) { return $this->setErrorAndRedirect('Failed moving uploaded file', $redir_route); } // svg if ($file_ext == '.svg') { if (!SVG::rasterize($temp_dir, $unique_filename, $file_ext)) { return $this->setErrorAndRedirect('Failed rasterizing svg file', $redir_route); } } // if jpg, check if we need orientation changes if ($file_ext == '.jpg') { Images::correctOrientation("{$temp_dir}{$unique_filename}{$file_ext}"); } c2cTools::log('resizing image'); // generate thumbnails (ie. resized images: "BI"/"SI") Images::generateThumbnails($unique_filename, $file_ext, $temp_dir); // retrieve image caption (name) $name = array_key_exists($key, $images_names) ? $images_names[$key] : $this->__('Give me a name'); // save image in DB and move temp files in the main dir c2cTools::log('saving image'); $activities = array(); $document = Document::find('Document', $document_id, array('id', 'module')); if (!$document) { return 0; } $model = c2cTools::module2model($document->get('module')); if (in_array($model, array('Outing', 'Article', 'Book', 'Hut', 'Image', 'Route'))) { $document = Document::find($model, $document_id, array('activities')); $activities = $document->get('activities'); } elseif ($model == 'Site') { $activities = array(4); // rock_climbing for sites by default } $image_type = $images_types[$key]; $categories = array_key_exists($key, $images_categories) ? $images_categories[$key] : array(); $image_id = Image::customSave($name, $unique_filename . $file_ext, $document_id, $user_id, $model, $activities, $categories, $image_type); $nb_created = gisQuery::createGeoAssociations($image_id, false); c2cTools::log("created {$nb_created} geo associations for image {$image_id}"); // TODO: handle errors with thumbnails generation and data saving? } // remove cache of calling page $this->clearCache($mod, $document_id, false, 'view'); // a new image has been uploaded, clear cache for images lists and whatsnew $this->clearCache('images', 0, true); return $this->setNoticeAndRedirect('image successfully uploaded', $redir_route . '#images'); } else { switch ($mod) { case 'articles': // default license depends on the article type $article = Document::find('Article', $document_id); $this->default_license = $article->get('article_type'); break; case 'books': $this->default_license = 1; break; case 'huts': $this->default_license = 1; break; case 'images': // default license is that of associated image $image = Document::find('Image', $document_id); $this->default_license = $image->get('license'); break; case 'outings': $this->default_license = 2; break; case 'parkings': $this->default_license = 1; break; case 'routes': $this->default_license = 1; break; case 'sites': $this->default_license = 1; break; case 'summits': $this->default_license = 1; break; case 'products': $this->default_license = 1; break; case 'users': $this->default_license = 2; break; default: $this->default_license = 2; } } // display form }
<?php use_helper('History', 'SmartDate', 'SmartFormat', 'General', 'sfBBCode'); ?> <?php $current_module = $sf_context->getModuleName(); if (!isset($model)) { $model = c2cTools::module2model($current_module); } $archive = $model; $i18n_archive = $model . 'I18n'; if (count($items) == 0) { ?> <p id="recent-changes"><?php echo __('No recent changes available'); ?> </p> <?php } else { ?> <ul id="recent-changes"> <?php foreach ($items as $item) { ?> <li><?php $module_name = $item[$archive]['module']; $id = $item['document_id']; $lang = $item['culture']; $version = $item['version']; $link = '@document_by_id?module=users&id=' . $item['document_id'];
public static function addAssociatedDocuments(&$docs, $type, $is_main, $data_fields = array(), $i18n_fields = array()) { if (count($docs) == 0 || empty($data_fields) && empty($i18n_fields)) { return array(); } $modules = c2cTools::Type2Modules($type); $main_module = $modules['main']; $linked_module = $modules['linked']; if (empty($main_module) || empty($linked_module)) { return array(); } $doc_ids = array(); foreach (array_keys($docs) as $key) { $id = $docs[$key]['id']; $doc_ids[] = $id; $docs[$id] = $docs[$key]; unset($docs[$key]); } // retrieve associations if ($main_module == $linked_module) { $associations = Association::countAll($doc_ids, $type); $module = $main_module; } elseif ($is_main) { $associations = Association::countAllLinked($doc_ids, $type); $module = $linked_module; } else { $associations = Association::countAllMain($doc_ids, $type); $module = $main_module; } if (count($associations) == 0) { return array(); } $linked_ids = array(); foreach ($associations as $assoc) { if ($is_main) { $doc_id = $assoc['main_id']; $linked_id = $assoc['linked_id']; } else { $doc_id = $assoc['linked_id']; $linked_id = $assoc['main_id']; } $linked_ids[] = $linked_id; if (isset($docs[$doc_id]['linked_docs'])) { $docs[$doc_id]['linked_docs'] = array_merge($docs[$doc_id]['linked_docs'], array($linked_id)); } else { $docs[$doc_id]['linked_docs'] = array($linked_id); } } $linked_ids = array_unique($linked_ids); $conditions = array(); foreach ($linked_ids as $id) { $conditions[] = '?'; } // retrieve info on the linked docs (name etc) $model = c2cTools::module2model($module); $q = Doctrine_Query::create()->from("{$model} m")->where('m.id IN ( ' . implode(', ', $conditions) . ' )', $linked_ids); if (!in_array('id', $data_fields)) { $data_fields[] = 'id'; } $q->addSelect('m.' . implode(', m.', $data_fields)); $has_name = false; if (!empty($i18n_fields)) { if (in_array('name', $i18n_fields)) { if (!in_array('search_name', $i18n_fields)) { $i18n_fields[] = 'search_name'; $i18n_fields[] = 'culture'; } $has_name = true; } $q->addSelect('mi.' . implode(', mi.', $i18n_fields))->leftJoin('m.' . $model . 'I18n mi'); } $linked_docs_info = $q->execute(array(), Doctrine::FETCH_ARRAY); if ($has_name) { $user_prefered_langs = sfContext::getInstance()->getUser()->getCulturesForDocuments(); $linked_docs_info = Language::getTheBest($linked_docs_info, $model); } // add linked docs info into $docs foreach ($docs as $doc_id => $doc) { if (isset($doc['linked_docs'])) { foreach ($doc['linked_docs'] as $key => $linked_doc_id) { $docs[$doc_id]['linked_docs'][$key] = $linked_docs_info[$linked_doc_id]; } } } }
<?php use_helper('Pagination'); $module = $sf_context->getModuleName(); $module_i18n = c2cTools::module2model($module) . 'I18n'; echo 'window.c2cwgt.insertContent("'; echo $div; echo '",['; $out = array(); foreach ($items as $item) { $i18n = $item->getRaw($module_i18n); $i18n = $i18n[0]; $lang = $i18n['culture']; $id = $item['id']; array_push($out, '["' . htmlentities($i18n['name'], ENT_COMPAT, 'UTF-8') . '","' . url_for("@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug=" . make_slug($i18n['name']), true) . '"]'); } echo implode(',', $out); echo ']);';