Esempio n. 1
0
 /**
  * DOCUMENT ME
  * @param mixed $editing
  * @return mixed
  */
 protected function setup($editing = false)
 {
     $this->reopen = false;
     // Sometimes it's more convenient to call with a pageid rather than a slug
     if ($this->hasRequestParameter('slug')) {
         $this->slug = $this->getRequestParameter('slug');
         $this->page = aPageTable::retrieveBySlugWithSlots($this->slug);
     } else {
         $this->pageid = $this->getRequestParameter('id');
         $this->page = aPageTable::retrieveByIdWithSlots($this->pageid);
     }
     $this->name = $this->getRequestParameter('slot');
     $this->value = $this->getRequestParameter('value');
     $this->permid = $this->getRequestParameter('permid');
     $this->forward404Unless($this->page);
     $this->pageid = $this->page->getId();
     aTools::setCurrentPage($this->page);
     $this->user = sfContext::getInstance()->getUser();
     // Used to name value parameters, among other things
     $this->id = $this->pageid . '-' . $this->name . '-' . $this->permid;
     // This was stored when the slot's editing view was rendered. If it
     // isn't present we must refuse to play for security reasons.
     $user = $this->getUser();
     $pageid = $this->pageid;
     $name = $this->name;
     $permid = $this->permid;
     $lookingFor = "slot-options-{$pageid}-{$name}-{$permid}";
     $this->options = $user->getAttribute($lookingFor, false, 'apostrophe');
     // We ought to check for this, although we also check your privileges
     // on the page
     $this->forward404Unless($this->options !== false);
     if ($editing) {
         if (!($this->getOption('edit') || $this->page->userHasPrivilege('edit'))) {
             return $this->redirect(sfConfig::get('secure_module') . '/' . sfConfig::get('secure_action'));
         }
     } else {
         if (!($this->getOption('edit') || $this->page->userHasPrivilege('view'))) {
             return $this->redirect(sfConfig::get('login_module') . '/' . sfConfig::get('login_action'));
         }
     }
     $this->forward404Unless($this->options !== false);
     // Clever no?
     $this->type = str_replace("SlotActions", "", get_class($this));
     $slot = $this->page->getSlot($this->name, $this->permid);
     if ($slot && $slot->type !== $this->type) {
         // Ignore a slot of the wrong type (template edits can cause this)
         $slot = false;
     }
     // Copy the slot- we'll be making a new version of it,
     // if we do decide to save that is.
     if ($slot) {
         $this->slot = $slot->copy();
     } else {
         $this->slot = $this->page->createSlot($this->type);
         $this->newSlot = true;
     }
 }
Esempio n. 2
0
 /**
  * DOCUMENT ME
  * @param mixed $parameter
  * @param mixed $slug
  * @return mixed
  */
 protected function sortBodyWrapper($parameter, $slug = false)
 {
     $request = $this->getRequest();
     if ($slug !== false) {
         $page = aPageTable::retrieveBySlugWithSlots($slug);
         $this->validAndEditable($page, 'edit');
     } else {
         $page = $this->retrievePageForEditingByIdParameter('page');
     }
     $this->flunkUnless($page);
     if (!$page->getNode()->hasChildren()) {
         $page = $page->getNode()->getParent();
         $this->flunkUnless($page);
     }
     $order = $this->getRequestParameter($parameter);
     $this->flunkUnless(is_array($order));
     $this->sortBody($page, $order);
     return sfView::NONE;
 }
Esempio n. 3
0
 /**
  * This does the entire thing at one go, which may be too memory intensive.
  * The apostrophe:rebuild-search-index task instead invokes apostrophe:update-search-index
  * for batches of 100 pages
  */
 public function rebuildLuceneIndex()
 {
     aZendSearch::purgeLuceneIndex($this);
     $pages = $this->createQuery('p')->innerJoin('p.Areas a')->execute(array(), Doctrine::HYDRATE_ARRAY);
     foreach ($pages as $page) {
         $cultures = array();
         foreach ($page['Areas'] as $area) {
             $cultures[$area['culture']] = true;
         }
         $cultures = array_keys($cultures);
         foreach ($cultures as $culture) {
             $cpage = aPageTable::retrieveBySlugWithSlots($page['slug'], $culture);
             $cpage->updateLuceneIndex();
         }
     }
 }
 protected function sortBodyWrapper($parameter, $slug = false)
 {
     $request = $this->getRequest();
     $this->logMessage("ZZ sortBodyWrapper");
     if ($slug !== false) {
         $page = aPageTable::retrieveBySlugWithSlots($slug);
         $this->logMessage("ZZ got slug by slots");
         $this->validAndEditable($page, 'edit');
         $this->logMessage("ZZ is valid and editable");
     } else {
         $page = $this->retrievePageForEditingByIdParameter('page');
         $this->logMessage("ZZ got page for editing by id");
     }
     $this->logMessage("ZZ Page is " . $page->id, "info");
     $this->flunkUnless($page);
     if (!$page->getNode()->hasChildren()) {
         $page = $page->getNode()->getParent();
         $this->logMessage("ZZ bumping up to parent");
         $this->flunkUnless($page);
     }
     $order = $this->getRequestParameter($parameter);
     ob_start();
     var_dump($_REQUEST);
     $this->logMessage("ZZ request is " . ob_get_clean());
     $this->logMessage("ZZ is_array order: " . is_array($order));
     $this->flunkUnless(is_array($order));
     $this->sortBody($page, $order);
     return sfView::NONE;
 }
Esempio n. 5
0
 public static function globalSetup($options)
 {
     if (isset($options['global']) && $options['global']) {
         if (!isset($options['slug'])) {
             $options['slug'] = 'global';
         }
     }
     if (isset($options['slug'])) {
         $page = self::getCurrentPage();
         if ($page) {
             if ($page->slug === $options['slug']) {
                 // Nothing to do. This can happen if, for instance, a template used on all pages
                 // including the chemistry home page fetches a footer from the chemistry home page
                 return;
             }
         }
         $slug = $options['slug'];
         self::$savedCurrentPage = self::getCurrentPage();
         // Caching the global page speeds up pages with two or more global slots
         if (isset(self::$globalCache[$slug])) {
             $global = self::$globalCache[$slug];
         } else {
             $global = aPageTable::retrieveBySlugWithSlots($slug);
             if (!$global) {
                 $global = new aPage();
                 $global->slug = $slug;
                 $global->save();
             }
             self::$globalCache[$slug] = $global;
         }
         self::setCurrentPage($global);
         self::$global = true;
     }
 }
Esempio n. 6
0
 /**
  * DOCUMENT ME
  * @param mixed $options
  */
 public static function globalSetup($options)
 {
     if (isset($options['global']) && $options['global']) {
         if (!isset($options['slug'])) {
             $options['slug'] = 'global';
         }
     }
     if (isset($options['slug'])) {
         // Note that we push onto the stack even if the page specified is the same page
         // we're looking at. This doesn't hurt because of caching, and it allows us
         // to keep the stack count properly
         $slug = $options['slug'];
         aTools::$pageStack[] = aTools::getCurrentPage();
         // Caching the global page speeds up pages with two or more global slots
         if (isset(aTools::$globalCache[$slug])) {
             $global = aTools::$globalCache[$slug];
         } else {
             $global = aPageTable::retrieveBySlugWithSlots($slug);
             if (!$global) {
                 $global = new aPage();
                 $global->slug = $slug;
                 $global->save();
             }
             aTools::$globalCache[$slug] = $global;
         }
         aTools::setCurrentPage($global);
         aTools::$global = true;
     }
 }