Пример #1
0
 public function executeView()
 {
     sfLoader::loadHelpers(array('General', 'MetaLink'));
     parent::executeView();
     // we get the user (id + name) who first uploaded this picture:
     $this->creator = $this->document->getCreator();
     $this->image_type = $this->document['image_type'];
     if (!$this->document->isArchive() && $this->document['redirects_to'] == NULL) {
         // here, we add the summit name to route names :
         $associated_routes = array_filter($this->associated_docs, array('c2cTools', 'is_route'));
         $associated_routes = Route::addBestSummitName($associated_routes, $this->__(' :') . ' ');
         $associated_docs = array_filter($this->associated_docs, array('c2cTools', 'is_not_route'));
         $associated_docs = array_filter($associated_docs, array('c2cTools', 'is_not_image'));
         $associated_docs = array_merge($associated_docs, $associated_routes);
         // sort by document type, name
         if (!empty($associated_docs)) {
             foreach ($associated_docs as $key => $row) {
                 $module[$key] = $row['module'];
                 $name[$key] = remove_accents($row['name']);
             }
             array_multisort($module, SORT_STRING, $name, SORT_STRING, $associated_docs);
         }
         $this->associated_documents = $associated_docs;
         // add linked docs areas (except users and images)
         $parent_ids = array();
         $associated_areas = array();
         foreach ($this->associated_docs as $doc) {
             if (!in_array($doc['module'], array('images', 'users'))) {
                 $parent_ids[] = $doc['id'];
             }
         }
         if (count($parent_ids)) {
             $prefered_cultures = $this->getUser()->getCulturesForDocuments();
             $associated_docs_areas = GeoAssociation::findAreasWithBestName($parent_ids, $prefered_cultures);
             $associated_areas = $this->associated_areas;
             $areas_ids = array();
             foreach ($associated_areas as $area) {
                 $areas_ids[] = $area['id'];
             }
             foreach ($associated_docs_areas as $area) {
                 if (!in_array($area['id'], $areas_ids)) {
                     $associated_areas[] = $area;
                 }
             }
         }
         $this->associated_areas = $associated_areas;
         $related_portals = array();
         $activities = $this->document->get('activities');
         if (in_array(5, $activities)) {
             $related_portals[] = 'ice';
         }
         Portal::getLocalPortals($related_portals, $associated_areas);
         $this->related_portals = $related_portals;
         // link for facebook
         list($image_name, $image_ext) = Images::getFileNameParts($this->document['filename']);
         $image_url = DIRECTORY_SEPARATOR . sfConfig::get('app_upload_dir') . DIRECTORY_SEPARATOR . sfConfig::get('app_images_directory_name') . DIRECTORY_SEPARATOR . $image_name . 'SI' . $image_ext;
         addMetaLink('image_src', $image_url);
     }
 }
Пример #2
0
 /**
  * Executes view action.
  */
 public function executeView()
 {
     $timer = new sfTimer('executeView');
     $this->timer = $timer;
     sfLoader::loadHelpers(array('General', 'MetaLink'));
     $id = $this->getRequestParameter('id');
     $lang = $this->getRequestParameter('lang');
     $version = $this->getRequestParameter('version');
     $slug = $this->getRequestParameter('slug');
     // and if not, redirect to true module...
     if ($this->model_class == 'Document') {
         $doc = Document::find('Document', $id, array('module'));
         $module = $doc->get('module');
     }
     $user = $this->getUser();
     $prefered_cultures = $user->getCulturesForDocuments();
     $module = isset($module) ? $module : $this->getModuleName();
     // we check here if document id requested corresponds to $module model
     if (empty($lang)) {
         // if lang isn't set, we use the prefered language session and redirect to the good URL
         // (for caching reasons, this cannot be silent)
         if (!($lang = DocumentI18n::findBestCulture($id, $prefered_cultures, $this->model_class))) {
             c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
             $this->setNotFoundAndRedirect();
         } else {
             $document = $this->getDocument($id, $lang, $version);
             c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
             $this->redirectIfSlugMissing($document, $id, $lang, $module);
         }
     }
     $document = $this->getDocument($id, $lang, $version);
     // no need to test whether document has been found :
     // already done in getDocument method.
     if (empty($version) && $module != 'users' && (empty($slug) || $module != 'routes' && $slug != get_slug($document))) {
         c2cActions::statsdTiming('document.executeView.redirect', $timer->getElapsedTime('executeView'));
         $this->redirectIfSlugMissing($document, $id, $lang, $module);
     }
     // case where module = documents, and lang, version or slug already given
     if ($this->model_class == 'Document') {
         $this->redirect("@document_by_id_lang_slug?module={$module}&id={$id}&lang={$lang}&slug={$slug}", 301);
     }
     if ($to_id = $document->get('redirects_to')) {
         $this->setWarning('Current document has been merged into document %1%', array('%1%' => $to_id), false);
     }
     $title = $document->get('name');
     if ($document->isArchive()) {
         $this->getResponse()->addMeta('robots', 'noindex, nofollow');
         $this->metadata = $document->getMetadatas();
         $this->created_at = $this->metadata->get('written_at');
         $this->current_version = $version;
         $title .= ' :: ' . $this->__('revision') . ' ' . $version;
         $this->associated_docs = array();
         // we need associated images for displaying them
         $prefered_cultures = $this->getUser()->getCulturesForDocuments();
         $association_type = c2cTools::Module2Letter($module) . 'i';
         $this->associated_images = Document::fetchAdditionalFieldsFor(Association::findAllWithBestName($id, $prefered_cultures, $association_type), 'Image', array('filename', 'image_type', 'date_time'));
     } else {
         if (isset($to_id)) {
             $this->getResponse()->addMeta('robots', 'noindex, follow');
         } else {
             $this->getResponse()->addMeta('robots', 'index, follow');
         }
         $this->metadata = NULL;
         if ($module != 'portals') {
             $version_infos = Document::getCurrentVersionInfosFromIdAndCulture($id, $lang);
             $this->current_version = $version_infos['version'];
             $this->created_at = $version_infos['created_at'];
         }
         // retrieve associated docs
         // some additional docs can be retrieved in module/executeView, like two hops summits
         // contains all documents directly linked
         $association_type = $module == 'users' ? array('ui') : null;
         $associated_docs = Association::findAllWithBestName($id, $prefered_cultures, $association_type);
         // mark them (useful information)
         foreach ($associated_docs as &$doc) {
             $doc['directly_linked'] = true;
         }
         $this->associated_docs = $associated_docs;
         // all the linked articles
         $this->associated_articles = array_filter($this->associated_docs, array('c2cTools', 'is_article'));
         // linked sites
         $this->associated_sites = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_site')));
         // linked books. For summits and huts, the displayed books are the one linked to the linked routes
         if (!in_array($module, array('summits', 'huts'))) {
             $this->associated_books = c2cTools::sortArrayByName(array_filter($this->associated_docs, array('c2cTools', 'is_book')));
         }
         // linked images
         // For sites and summits, we will dislay images linked to the summit/site AND its subsummits/subsites
         if (!in_array($module, array('summits', 'sites'))) {
             $this->associated_images = Document::fetchAdditionalFieldsFor(array_filter($this->associated_docs, array('c2cTools', 'is_image')), 'Image', array('filename', 'image_type', 'date_time', 'width', 'height'));
         }
         // Geo associated docs
         if (!in_array($module, array('articles', 'books'))) {
             $associated_areas = GeoAssociation::findAreasWithBestName($id, $prefered_cultures);
             $this->associated_areas = $associated_areas;
         }
         if (!in_array($module, array('outings', 'articles', 'books', 'portals'))) {
             $associated_maps = GeoAssociation::findMapsWithBestName($id, $prefered_cultures);
             $this->associated_maps = Map::getAssociatedMapsData($associated_maps);
         }
     }
     // nb comments
     $this->nb_comments = PunbbComm::retrieveNbComments($id . '_' . $lang);
     // js translation code if needed
     $this->needs_translation = $lang == $user->getCulture() ? false : $lang;
     $response = $this->getResponse();
     if ($this->needs_translation && !c2cTools::mobileVersion()) {
         $response->addJavascript('/static/js/translation.js', 'last');
     }
     if (!in_array($module, array('summits', 'routes', 'sites', 'huts', 'products'))) {
         $title .= ' :: ' . $this->__(substr($module, 0, -1));
         $this->setPageTitle($title);
     }
     $response->addMeta('description', $title);
     /* image_src fixes the image proposed eg by facebook
           - for an image, force it to be the image miniature
           - for a doc with attached images, leave facebook decide
           - for a book without attached image, force the c2c logo
        */
     if ($module != 'images' && !count($this->associated_images)) {
         addMetaLink('image_src', sfConfig::get('app_images_default_meta'));
     }
     /* small js code to append QR code when printing page */
     if (!$document->isArchive() && !c2cTools::mobileVersion()) {
         $response->addJavascript('/static/js/qrcode.js', 'last');
     }
     $this->document = $document;
     $this->languages = $document->getLanguages();
     c2cActions::statsdTiming('document.executeView', $timer->getElapsedTime('executeView'));
 }