/**
  * Execute the action
  * 
  * @return mixed
  * @access public
  */
 public function execute()
 {
     try {
         if (!$this->isAuthorizedToExecute()) {
             throw new PermissionDeniedException();
         }
         ob_start();
         $harmoni = Harmoni::instance();
         $component = SiteDispatcher::getCurrentNode();
         $site = SiteDispatcher::getCurrentRootNode();
         $slotMgr = SlotManager::instance();
         $slot = $slotMgr->getSlotBySiteId($site->getId());
         $exportDirname = $slot->getShortname() . "-html";
         $exportDir = DATAPORT_TMP_DIR . "/" . $exportDirname;
         $archivePath = DATAPORT_TMP_DIR . '/' . $exportDirname . ".zip";
         if (!file_exists($exportDir)) {
             header('HTTP/1.1 404 Not Found');
             print "Not Found";
             exit;
         }
         header("Content-Type: text/html;");
         $this->printStatus($exportDir);
     } catch (PermissionDeniedException $e) {
         header('HTTP/1.1 403 Forbidden');
         header("Content-Type: text/plain;");
         print _("You are not authorized to monitor the export this component.");
         exit;
     }
     exit;
 }
 /**
  * Process changes to the site components. This is the method that the various
  * actions that modify the site should override.
  * 
  * @param object SiteDirector $director
  * @return void
  * @access public
  * @since 4/14/06
  */
 function processChanges(SiteDirector $director)
 {
     $component = $director->getSiteComponentById(SiteDispatcher::getCurrentNodeId());
     // Do not allow delete of the root menu.
     if (method_exists($component, 'isRootMenu')) {
         if ($component->isRootMenu()) {
             $this->returnToCallerPage();
             exit;
         }
     }
     $this->findSafeReturnNode($director, $component);
     $organizer = $component->getParentComponent();
     if ($organizer) {
         $organizer->detatchSubcomponent($component);
     }
     $rootSiteComponent = $director->getRootSiteComponent(SiteDispatcher::getCurrentNodeId());
     // If we are deleting the site unhitch it from the slot
     if ($rootSiteComponent->getId() == SiteDispatcher::getCurrentNodeId()) {
         $slotMgr = SlotManager::instance();
         $idMgr = Services::getService("Id");
         try {
             $slot = $slotMgr->getSlotBySiteId($idMgr->getId(SiteDispatcher::getCurrentNodeId()));
             $slot->deleteSiteId();
         } catch (Exception $e) {
         }
     }
     $director->deleteSiteComponent($component);
 }
 /**
  * This class implements the Singleton pattern. There is only ever
  * one instance of the this class and it is accessed only via the 
  * ClassName::instance() method.
  * 
  * @return object 
  * @access public
  * @since 5/26/05
  * @static
  */
 public static function instance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new SlotManager();
     }
     return self::$instance;
 }
Exemple #4
0
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 10/9/08
  */
 public function execute()
 {
     header('Content-Type: text/plain;');
     try {
         if (!$this->isAuthorizedToExecute()) {
             throw new PermissionDeniedException("You must be logged in.");
         }
         $mgr = SlotManager::instance();
         $slot = $mgr->getSlotByShortname(RequestContext::value('slot'));
         $slot->makeAlias($mgr->getSlotByShortname(RequestContext::value('target_slot')));
         print _("Success");
         /*********************************************************
          * Log the success
          *********************************************************/
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Segue");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
             $item = new AgentNodeEntryItem("Alias Made", "'" . $slot->getShortname() . "' has been made an alias of '" . RequestContext::value('target_slot') . "'.");
             $item->addNodeId($slot->getSiteId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     } catch (OperationFailedException $e) {
         print $e->getMessage();
     } catch (UnknownIdException $e) {
         print $e->getMessage();
     }
     exit;
 }
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 1/11/08
  */
 function runUpdate()
 {
     $dbc = Services::getService('DatabaseManager');
     $slotMgr = SlotManager::instance();
     $query = new GenericSQLQuery();
     $query->addSQLQuery("CREATE TABLE segue_plugin_version (\n  version_id int(10) unsigned NOT NULL auto_increment,\n  node_id varchar(170) collate utf8_bin NOT NULL,\n  tstamp timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,\n  `comment` varchar(255) collate utf8_bin NOT NULL,\n  agent_id varchar(170) collate utf8_bin NOT NULL,\n  version_xml longblob NOT NULL,\n  PRIMARY KEY  (version_id),\n  KEY node_id (node_id)\n)\nCHARACTER SET utf8\nTYPE=InnoDB;");
     $dbc->query($query);
     return true;
 }
Exemple #6
0
 /**
  * Execute the action
  * 
  * @return mixed
  * @access public
  */
 public function execute()
 {
     ob_start();
     $harmoni = Harmoni::instance();
     $component = SiteDispatcher::getCurrentNode();
     $site = SiteDispatcher::getCurrentRootNode();
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotBySiteId($site->getId());
     $exportDirname = $slot->getShortname() . "-files";
     $exportDir = DATAPORT_TMP_DIR . "/" . $exportDirname;
     mkdir($exportDir);
     $archivePath = DATAPORT_TMP_DIR . '/' . $exportDirname . ".zip";
     try {
         // Do the export
         $visitor = new FileExportSiteVisitor($exportDir);
         $component->acceptVisitor($visitor);
         $archive = new ZipArchive();
         if ($archive->open($archivePath, ZIPARCHIVE::CREATE) !== TRUE) {
             throw new Exception("Could not create zip archive.");
         }
         foreach (scandir($exportDir) as $file) {
             if (!is_dir($exportDir . '/' . $file)) {
                 $archive->addFile($exportDir . '/' . $file, $exportDirname . '/' . $file);
             }
         }
         $archive->close();
         // Remove the directory
         $this->deleteRecursive($exportDir);
         if ($output = ob_get_clean()) {
             print $output;
             throw new Exeception("Errors occurred, output wasn't clean.");
         }
         header("Content-Type: application/zip;");
         header('Content-Disposition: attachment; filename="' . basename($archivePath) . '"');
         header('Content-Length: ' . filesize($archivePath));
         print file_get_contents($archivePath);
         // Clean up the archive
         unlink($archivePath);
     } catch (PermissionDeniedException $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($archivePath)) {
             unlink($archivePath);
         }
         return new Block(_("You are not authorized to export this component."), ALERT_BLOCK);
     } catch (Exception $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($archivePath)) {
             unlink($archivePath);
         }
         throw $e;
     }
     error_reporting(0);
     exit;
 }
 /**
  * Answer an array of the slots in this category.
  * 
  * @return array of Slot objects
  * @access public
  * @since 4/1/08
  */
 public function getSlots()
 {
     $slotMgr = SlotManager::instance();
     $courses = $this->getCourses();
     $slots = array();
     if (count($courses)) {
         foreach ($courses as $course) {
             $slots[] = $slotMgr->getSlotByShortname($course->getId()->getIdString());
         }
     }
     return $slots;
 }
 /**
  * Answer an array of the slots in this category.
  * 
  * @return array of Slot objects
  * @access public
  * @since 4/1/08
  */
 public function getSlots()
 {
     $slots = array();
     $slotMgr = SlotManager::instance();
     foreach (Segue_AccessLog::instance()->getRecentSlots() as $shortname) {
         try {
             $slots[] = $slotMgr->getSlotByShortname($shortname);
         } catch (UnknownIdException $e) {
         }
     }
     return $slots;
 }
 /**
  * Execute the action
  * 
  * @return mixed
  * @access public
  * @since 1/17/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException("You are not authorized to update this slot.");
     }
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotByShortname(RequestContext::value('slot'));
     $slot->setMigrationStatus(RequestContext::value('status'), RequestContext::value('url'));
     header("Content-Type: text/plain");
     print "Success.";
     exit;
 }
 /**
  * Answer an array of the slots in this category.
  * 
  * @return array of Slot objects
  * @access public
  * @since 4/1/08
  */
 public function getSlots()
 {
     $slotMgr = SlotManager::instance();
     // process of elimination.
     $otherCategorizedSlotNames = $this->getOtherCategorizedSlotNames();
     $slots = array();
     foreach ($slotMgr->getSlots() as $slot) {
         if (!in_array($slot->getShortName(), $otherCategorizedSlotNames)) {
             $slots[] = $slot;
         }
     }
     return $slots;
 }
 /**
  * Build a list of the sites for which users are admins
  * 
  * @return null
  */
 protected function buildUserSiteList()
 {
     $slotMgr = SlotManager::instance();
     $slots = $slotMgr->getAllSlots();
     $roleMgr = SegueRoleManager::instance();
     $agentMgr = Services::getService('Agent');
     $increment = round($slots->count() / 100);
     $i = 0;
     $numSites = 0;
     $incomplete = 0;
     $this->slots = array();
     // Get the users who can adminster each slot.
     while ($slots->hasNext()) {
         $i++;
         if ($i % $increment == 0) {
             print '.';
             flush();
         }
         $slot = $slots->next();
         if (!$slot->isAlias() && $slot->siteExists()) {
             $this->slots[$slot->getShortname()] = array('slot' => $slot, 'users' => array());
             $adminIds = $roleMgr->getAgentsWithExplicitRoleAtLeast($roleMgr->getRole('admin'), $slot->getSiteId(), true);
             $numAdmins = 0;
             foreach ($adminIds as $adminId) {
                 // Skip the special groups of
                 // 	edu.middlebury.institute
                 // 	edu.middlebury.agents.users
                 // 	edu.middlebury.agents.anonymous
                 // etc.
                 if (preg_match('/^edu\\.middlebury\\./', $adminId->getIdString())) {
                     continue;
                 }
                 try {
                     $agent = $agentMgr->getAgentOrGroup($adminId);
                     if ($agent->isGroup()) {
                         $numAdmins = $numAdmins + $this->addSlotForGroup($agent, $slot);
                     } else {
                         $numAdmins = $numAdmins + $this->addSlotForAgent($agent, $slot);
                     }
                 } catch (UnknownIdException $e) {
                 }
             }
             if (!$numAdmins) {
                 $this->slotsWithoutAdmins[] = $slot->getShortname();
             }
         }
     }
 }
 /**
  * Answer an array of the slots in this category.
  * 
  * @return array of Slot objects
  * @access public
  * @since 4/1/08
  */
 public function getSlots()
 {
     $slotMgr = SlotManager::instance();
     // process of elimination.
     $slots = array();
     foreach ($this->getSiteIds() as $siteId) {
         try {
             $slots[] = $slotMgr->getSlotBySiteId($siteId);
         } catch (UnknownIdException $e) {
             $slot = new CustomSlot(null);
             $slot->populateSiteId($siteId);
             $slots[] = $slot;
         }
     }
     return $slots;
 }
Exemple #13
0
 /**
  * Execute
  * 
  * @return void
  * @access public
  * @since 3/26/08
  */
 public function execute()
 {
     $slotMgr = SlotManager::instance();
     if (is_null(RequestContext::value('site'))) {
         throw new NullArgumentException("No site specified.");
     }
     $slot = $slotMgr->getSlotByShortname(RequestContext::value('site'));
     $exists = $slot->siteExists();
     header("Content-Type: text/plain");
     if ($exists) {
         print "true";
     } else {
         print "false";
     }
     exit;
 }
Exemple #14
0
 /**
  * Execute the action
  * 
  * @return mixed
  * @access public
  * @since 1/17/08
  */
 public function execute()
 {
     $harmoni = Harmoni::instance();
     $component = SiteDispatcher::getCurrentNode();
     $site = SiteDispatcher::getCurrentRootNode();
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotBySiteId($site->getId());
     $exportDir = DATAPORT_TMP_DIR . "/" . $slot->getShortname() . "-" . str_replace(':', '_', DateAndTime::now()->asString());
     mkdir($exportDir);
     try {
         // Do the export
         $visitor = new DomExportSiteVisitor($exportDir);
         $component->acceptVisitor($visitor);
         // Validate the result
         // 			printpre(htmlentities($visitor->doc->saveXMLWithWhitespace()));
         // 			$tmp = new Harmoni_DomDocument;
         // 			$tmp->loadXML($visitor->doc->saveXMLWithWhitespace());
         // 			$tmp->schemaValidateWithException(MYDIR."/doc/raw/dtds/segue2-site.xsd");
         $visitor->doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd");
         // Write out the XML
         $visitor->doc->saveWithWhitespace($exportDir . "/site.xml");
         $archive = new Archive_Tar($exportDir . ".tar.gz");
         $archive->createModify($exportDir, '', DATAPORT_TMP_DIR);
         // Remove the directory
         $this->deleteRecursive($exportDir);
         header("Content-Type: application/x-gzip;");
         header('Content-Disposition: attachment; filename="' . basename($exportDir . ".tar.gz") . '"');
         print file_get_contents($exportDir . ".tar.gz");
         // Clean up the archive
         unlink($exportDir . ".tar.gz");
     } catch (PermissionDeniedException $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($exportDir . ".tar.gz")) {
             unlink($exportDir . ".tar.gz");
         }
         return new Block(_("You are not authorized to export this component."), ALERT_BLOCK);
     } catch (Exception $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($exportDir . ".tar.gz")) {
             unlink($exportDir . ".tar.gz");
         }
         throw $e;
     }
     error_reporting(0);
     exit;
 }
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 10/9/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException("You must be logged in.");
     }
     header('Content-Type: text/xml;');
     print "<ul>";
     $search = RequestContext::value('search');
     if ($search && preg_match('/^[a-z0-9\\._-]+$/i', $search)) {
         $slots = SlotManager::instance()->getSlotsWithSitesBySearch($search . '*');
         foreach ($slots as $slot) {
             print "\n\t<li>" . $slot->getShortName() . "</li>";
         }
     }
     print "\n</ul>";
     exit;
 }
 /**
  * Check Authorizations
  * 
  * @return boolean
  * @access public
  * @since 4/26/05
  */
 function isAuthorizedToExecute()
 {
     // Check that the user can create an asset here.
     if (RequestContext::value("slot")) {
         $slotMgr = SlotManager::instance();
         $slot = $slotMgr->getSlotByShortname(RequestContext::value("slot"));
         if ($slot->isUserOwner()) {
             return true;
         } else {
             return false;
         }
     } else {
         $authZ = Services::getService("AuthZ");
         $idManager = Services::getService("Id");
         return $authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.add_children"), $idManager->getId("edu.middlebury.segue.sites_repository"));
     }
 }
Exemple #17
0
 /**
  * Execute the action
  * 
  * @return mixed
  * @access public
  * @since 1/17/08
  */
 public function execute()
 {
     $harmoni = Harmoni::instance();
     $component = SiteDispatcher::getCurrentNode();
     $site = SiteDispatcher::getCurrentRootNode();
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotBySiteId($site->getId());
     $this->setupTextTemplates();
     $pluginManager = Services::getService('PluginManager');
     $audioType = new Type('SeguePlugins', 'edu.middlebury', 'AudioPlayer');
     $pluginManager->_loadPlugins();
     // Ensure that the original plugin is loaded.
     require_once MYDIR . '/plugins-dist/SeguePlugins/edu.middlebury/AudioPlayer/WordpressExportAudioPlayerPlugin.class.php';
     $pluginManager->setPluginClass($audioType, 'WordpressExportAudioPlayerPlugin');
     $textType = new Type('SeguePlugins', 'edu.middlebury', 'TextBlock');
     require_once MYDIR . '/plugins-dist/SeguePlugins/edu.middlebury/TextBlock/WordpressExportTextBlockPlugin.class.php';
     $pluginManager->setPluginClass($textType, 'WordpressExportTextBlockPlugin');
     try {
         // Do the export
         $visitor = new WordpressExportSiteVisitor();
         $component->acceptVisitor($visitor);
         // Validate the result
         // 			printpre(htmlentities($visitor->doc->saveXMLWithWhitespace()));
         // 			$tmp = new Harmoni_DomDocument;
         // 			$tmp->loadXML($visitor->doc->saveXMLWithWhitespace());
         // 			$tmp->schemaValidateWithException(MYDIR."/doc/raw/dtds/segue2-site.xsd");
         // 			$visitor->doc->schemaValidateWithException(MYDIR."/doc/raw/dtds/segue2-site.xsd");
         header("Content-Type: text/xml");
         header('Content-Disposition: attachment; filename="' . basename($slot->getShortname() . ".xml") . '"');
         $xml = $visitor->doc->saveXMLWithWhitespace();
         header('Content-Length: ' . strlen($xml));
         print $xml;
     } catch (PermissionDeniedException $e) {
         return new Block(_("You are not authorized to export this component."), ALERT_BLOCK);
     } catch (Exception $e) {
         throw $e;
     }
     error_reporting(0);
     exit;
 }
Exemple #18
0
 /**
  * Execute
  * 
  * @return void
  * @access public
  * @since 12/7/07
  */
 public function buildContent()
 {
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace("slots");
     $name = strtolower(RequestContext::value("name"));
     $harmoni->request->passthrough("name");
     $harmoni->request->endNamespace();
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotByShortname($name);
     if ($slot->siteExists()) {
         throw new PermissionDeniedException("You cannot delete a placeholder that has an existing site.");
     }
     $slotMgr->deleteSlot($name);
     // Log this change
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Segue");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
         $item = new AgentNodeEntryItem("Delete Placeholder", "Placeholder deleted:  '" . $name . "'.");
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $harmoni->request->sendTo($this->getReturnUrl());
 }
Exemple #19
0
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 10/9/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException("You must be logged in.");
     }
     $mgr = SlotManager::instance();
     $slot = $mgr->getSlotByShortname(RequestContext::value('slot'));
     $oldTarget = $slot->getAliasTarget();
     $slot->makeNotAlias();
     /*********************************************************
      * Log the success
      *********************************************************/
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Segue");
         $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
         $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events.");
         $item = new AgentNodeEntryItem("Alias Removed", "'" . $slot->getShortname() . "' is no longer an alias of '" . $oldTarget->getShortname() . "'.");
         $item->addNodeId($oldTarget->getSiteId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $harmoni = Harmoni::instance();
     RequestContext::sendTo($harmoni->request->quickURL('portal', 'list'));
 }
Exemple #20
0
 /**
  * Answer the slot that is the target if this slot is an alias.
  * 
  * @return object Slot
  * @access public
  * @since 10/8/08
  */
 public function getAliasTarget()
 {
     if (!$this->isAlias()) {
         printpre($this);
         throw new OperationFailedException("Cannot get a target for a slot (" . get_class($this) . ": " . $this->getShortname() . ") that is not an alias.");
     }
     return SlotManager::instance()->getSlotByShortname($this->aliasTarget);
 }
Exemple #21
0
        $authZManager->createAuthorization($adminGroup->getId(), $function->getId(), $allOfSegueId);
        // Administration Functions
        $type = new Type("Authorization", "edu.middlebury.harmoni", "Group Administration", "Functions for administering groups.");
        $id = $idManager->getId("edu.middlebury.authorization.create_group");
        $function = $authZManager->createFunction($id, "Create Groups", "Add Groups to the system.", $type, $qualifierHierarchyId);
        $authZManager->createAuthorization($adminGroup->getId(), $function->getId(), $allOfSegueId);
        $id = $idManager->getId("edu.middlebury.authorization.delete_group");
        $function = $authZManager->createFunction($id, "Delete Groups", "Remove Groups from the system.", $type, $qualifierHierarchyId);
        $authZManager->createAuthorization($adminGroup->getId(), $function->getId(), $allOfSegueId);
        $id = $idManager->getId("edu.middlebury.authorization.modify_group_membership");
        $function = $authZManager->createFunction($id, "Modify Group Membership", "Modify Group membership.", $type, $qualifierHierarchyId);
        $authZManager->createAuthorization($adminGroup->getId(), $function->getId(), $allOfSegueId);
        /*********************************************************
         * Add a site for the administrator user to use for testing
         * new installations.
         *********************************************************/
        $slotMgr = SlotManager::instance();
        $testSlot = $slotMgr->getSlotByShortname('jadministrator-test_site');
        $testSlot->addOwner($adminAgent->getId());
        $testSlot->setLocationCategory('community');
        $slotMgr->convertSlotToType($testSlot, Slot::personal);
        // Set the 'personal' folder as the last visited so that admins logging into
        // a new install will see their personal test site.
        UserData::instance()->setPreference('segue_portal_last_folder', 'personal');
        // 		print "\n<br> ...done";
        $_SESSION['table_setup_complete'] = TRUE;
        unset($_SESSION['installation_underway']);
        // 		$dbHandler->commitTransaction($dbID);
        RequestContext::locationHeader($_SERVER['REQUEST_URI']);
    }
}
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/20/08
  */
 function runUpdate()
 {
     $dbc = Services::getService('DatabaseManager');
     $slotMgr = SlotManager::instance();
     try {
         $query = new GenericSQLQuery();
         $query->addSQLQuery("ALTER TABLE `segue_slot` ADD `media_quota` INT;");
         $dbc->query($query);
     } catch (QueryDatabaseException $e) {
         print "<p>" . $e->getMessage() . "</p>";
     }
     try {
         $query = new GenericSQLQuery();
         $query->addSQLQuery("CREATE TABLE segue1_id_map (\n  segue1_slot_name varchar(50) NOT NULL,\n  segue1_id varchar(50) NOT NULL,\n  segue2_slot_name varchar(50) NOT NULL,\n  segue2_id varchar(170) NOT NULL,\n  PRIMARY KEY  (segue1_id),\n  UNIQUE KEY old_id_unique (segue1_slot_name,segue1_id),\n  UNIQUE KEY new_id_unique (segue2_slot_name,segue2_id),\n  KEY segue2_id (segue2_id)\n) ENGINE=InnoDB COMMENT='Mapping between segue1 and segue2 ids for auto-redirects.';");
         $dbc->query($query);
     } catch (QueryDatabaseException $e) {
         print "<p>" . $e->getMessage() . "</p>";
     }
     return $this->isInPlace();
 }
Exemple #23
0
namespace bybzmt\NumberGenerator;

require __DIR__ . "/../src/load.php";
//这里有$pdo, $table
require __DIR__ . "/test_db.php";
//存储时加锁器, 应该要有 lock($key), unlock($key) 两个方法
//为了简单起见这里置空掉,实际例用中它是必需的
$locker = null;
//可以用这个修改锁Key的前缀,一般默认就行,默认是'bybzmt_number_generator:'
//ToMysql::$_locker_key_prefix = '';
$persistent = new ToMysql($pdo, $table, $locker);
//base必需要8的倍数
$base = 32;
$dep = 3;
//实例化对像
$obj = new SlotManager($base, $dep, $persistent);
//增加10个slot
$ids = $obj->inrcSlot(10);
var_dump('inrcSlot ids:', implode(',', $ids));
//设置指定区间状态
//实际使用中base ^ dep经常与需要生成的数字区间不一至,关掉不需要的部分就行
$obj->setRange(100, 1000, 0);
//如果有特殊需要,也可以直接操作指定slot的数据
//$slot = $obj->getSlot($slot_id);
//$slot->setRange(100, 1000, 0);
//$obj->setSlot($slot_id, $slot);
//得到一个随军机的可用值
//如果需要多个调用多次即可
$id = $obj->getByRand();
var_dump("getByRand:", $id);
//得到最小的可用值
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 7/9/07
  */
 function runUpdate()
 {
     $dbc = Services::getService('DatabaseManager');
     $slotMgr = SlotManager::instance();
     $query = new GenericSQLQuery();
     $query->addSQLQuery("ALTER TABLE `segue_slot_owner` ADD UNIQUE `unique_owner` ( `shortname` , `owner_id` ) ;");
     $dbc->query($query);
     return true;
 }
Exemple #25
0
 /**
  * Answer the slot.
  * 
  * @return object Slot
  * @access protected
  * @since 7/28/08
  */
 protected function getDestSlot()
 {
     if (!preg_match('/^[a-z0-9_\\.-]+$/i', RequestContext::value('destSlot'))) {
         throw new InvalidArgumentException("Invalid slot name.");
     }
     $slotMgr = SlotManager::instance();
     $slot = $slotMgr->getSlotByShortname(RequestContext::value('destSlot'));
     if ($slot->siteExists()) {
         throw new OperationFailedException("Cannot copy site, slot already full.");
     }
     return $slot;
 }
 /**
  * Convert a single wiki link [[SomeTitle]] to an html link.
  *
  * Forms:
  *		[[Some Title]]
  *		[[Some Title|alternate text to display]]
  *		[[site:my_other_slot_name Some Title]]
  *		[[site:my_other_slot_name Some Title|alternate text to display]]
  *		[[node:12345 Some Title]]
  *		[[node:12345|alternate text to display]]
  *
  * Local URL form:
  *		[[localurl:module=modName&amp;action=actName&amp;param1=value1]]
  * File URL form:
  *		[[fileurl:repository_id=123&amp;asset_id=1234&amp;record_id=12345]]
  * Unlike other forms, the local URL form and the file URL form do not write link tags. 
  * They gets replaced with only the URL string itself.
  * 
  * @param string $wikiText
  * @param object SiteComponent $startingSiteComponent
  * @return string An HTML version of the link
  * @access private
  * @since 11/30/07
  */
 private function makeHtmlLink($wikiText, SiteComponent $startingSiteComponent)
 {
     $regexp = "/\n\n^\t\t# Anchor for the beginning of the line\n\\[\\[\t# The opening link tags\n\n\t\\s*\t\t# optional whitespace\n\n\t(?: site:([a-z0-9_\\-]+) \\s+ )?\t# An optional designator for linking to another site\n\t\n\t([^\\]#\\|]+)\t# The Title of the linked section, page, story\n\t\t\n\t(?: \\s*\\|\\s* ([^\\]]+) )?\t# The optional link-text to display instead of the title\n\n\t\\s*\t\t# optional whitespace\n\n\\]\\]\t# The closing link tags\n\$\t\t# Anchor for the end of the line\n\n/xi";
     $siteOnlyRegexp = "/\n\n^\t\t# Anchor for the beginning of the line\n\\[\\[\t# The opening link tags\n\n\t\\s*\t\t# optional whitespace\n\n\t(?: site:([a-z0-9_\\-]+) )?\t# A designator for linking to another site\n\t\n\t(?: \\s*\\|\\s* ([^\\]]+) )?\t# The optional link-text to display instead of the title\n\n\t\\s*\t\t# optional whitespace\n\n\\]\\]\t# The closing link tags\n\$\t\t# Anchor for the end of the line\n\n/xi";
     $nodeRegexp = "/\n\n^\t\t# Anchor for the beginning of the line\n\\[\\[\t# The opening link tags\n\n\t\\s*\t\t# optional whitespace\n\n\t(?: node:([a-z0-9_\\-]+) )?\t# A designator for linking to a particular node\n\t\n\t(?: \\s*\\|\\s* ([^\\]]+) )?\t# The optional link-text to display instead of the title\n\n\t\\s*\t\t# optional whitespace\n\n\\]\\]\t# The closing link tags\n\$\t\t# Anchor for the end of the line\n\n/xi";
     $localUrlRegexp = "/\n\n^\t\t# Anchor for the beginning of the line\n\\[\\[\t# The opening link tags\n\n\t\\s*\t\t# optional whitespace\n\n\t(?: localurl:([^\\]]+) )?\t# A designator for linking to a local url\n\n\\]\\]\t# The closing link tags\n\$\t\t# Anchor for the end of the line\n\n/xi";
     $fileUrlRegexp = "/\n\n^\t\t# Anchor for the beginning of the line\n\\[\\[\t# The opening link tags\n\n\t\\s*\t\t# optional whitespace\n\n\t(?: fileurl:([^\\]]+) )?\t# A designator for linking to a local file\n\n\\]\\]\t# The closing link tags\n\$\t\t# Anchor for the end of the line\n\n/xi";
     // Check for a link only to a site [[site:my_other_site]]
     if (preg_match($siteOnlyRegexp, $wikiText, $matches)) {
         $slotName = $matches[1];
         if (isset($matches[2]) && $matches[2]) {
             $display = $matches[2];
             $slotMgr = SlotManager::instance();
             $slot = $slotMgr->getSlotByShortName($slotName);
             if (!$slot->siteExists()) {
                 return $display . " ?";
             }
         } else {
             $slotMgr = SlotManager::instance();
             $slot = $slotMgr->getSlotByShortName($slotName);
             if ($slot->siteExists()) {
                 $director = $startingSiteComponent->getDirector();
                 $site = $director->getSiteComponentById($slot->getSiteId()->getIdString());
                 if (strlen($site->getDisplayName())) {
                     $display = $site->getDisplayName();
                 } else {
                     $display = $slotName;
                 }
             } else {
                 return $slotName . " ?";
             }
         }
         return $this->getSlotLink($slotName, $display);
     }
     // Check for a link to a node [[node:12345]]
     if (preg_match($nodeRegexp, $wikiText, $matches)) {
         $nodeIdString = $matches[1];
         try {
             if (isset($matches[2]) && $matches[2]) {
                 $display = $matches[2];
                 // Try getting the title to check if the node exists
                 $title = $this->getNodeTitle($nodeIdString, $startingSiteComponent);
             } else {
                 $display = $this->getNodeTitle($nodeIdString, $startingSiteComponent);
             }
         } catch (UnknownIdException $e) {
             if (isset($display)) {
                 return $display . " ?";
             } else {
                 return $nodeIdString . " ?";
             }
         }
         return $this->getNodeLink($nodeIdString, $display);
     }
     // Check for a link to a local url:
     // [[localurl:module=modName&amp;action=actName&amp;param1=value1]]
     if (preg_match($localUrlRegexp, $wikiText, $matches)) {
         preg_match_all('/(&(amp;)?)?([^&=]+)=([^&=]+)/', $matches[1], $paramMatches);
         $args = array();
         for ($i = 0; $i < count($paramMatches[1]); $i++) {
             $key = $paramMatches[3][$i];
             $value = $paramMatches[4][$i];
             if ($key == 'module') {
                 $module = $value;
             } else {
                 if ($key == 'action') {
                     $action = $value;
                 } else {
                     $args[$key] = $value;
                 }
             }
         }
         // If no params are specified, return our base url
         if (!count($args) && !isset($module) && !isset($action)) {
             return MYURL;
         }
         if (!isset($module)) {
             $module = 'ui1';
         }
         if (!isset($action)) {
             $action = 'view';
         }
         // Convert thumbnail urls
         if ($module == 'repository' && $action == 'viewthumbnail' && !empty($args['polyphony-repository___repository_id']) && !empty($args['polyphony-repository___asset_id']) && !empty($args['polyphony-repository___record_id'])) {
             $repositoryId = $args['polyphony-repository___repository_id'];
             $assetId = $args['polyphony-repository___asset_id'];
             $recordId = $args['polyphony-repository___record_id'];
             $file = MediaFile::withIdStrings($repositoryId, $assetId, $recordId);
             return $file->getThumbnailUrl();
         }
         $harmoni = Harmoni::instance();
         $harmoni->request->startNamespace(null);
         $newUrl = $harmoni->request->mkURLWithoutContext($module, $action, $args);
         $harmoni->request->endNamespace();
         return $newUrl->write();
     }
     // Check for a link to a file url:
     // [[fileurl:repository_id=123&amp;asset_id=1234&amp;record_id=12345]]
     if (preg_match($fileUrlRegexp, $wikiText, $matches)) {
         try {
             return MediaFile::withIdString($matches[1])->getUrl();
         } catch (InvalidArgumentException $e) {
         } catch (UnknownIdException $e) {
         }
     }
     // Links of the form [[Assignments]]
     if (preg_match($regexp, $wikiText, $matches)) {
         if (isset($matches[1]) && $matches[1]) {
             $slotMgr = SlotManager::instance();
             $slot = $slotMgr->getSlotByShortName($matches[1]);
             if ($slot->siteExists()) {
                 $director = $startingSiteComponent->getDirector();
                 $startingSiteComponent = $director->getSiteComponentById($slot->getSiteId()->getIdString());
             } else {
                 $title = $matches[2];
                 if (isset($matches[3]) && $matches[3]) {
                     $display = $matches[3];
                 } else {
                     $display = $title;
                 }
                 return $display . " ?";
             }
         }
         $title = $matches[2];
         if (isset($matches[3]) && $matches[3]) {
             $display = $matches[3];
         } else {
             $display = $title;
         }
         try {
             $nodeIdString = $this->titleSearcher->getNodeId($title, $startingSiteComponent);
             return $this->getNodeLink($nodeIdString, $display);
         } catch (UnknownTitleException $e) {
             return $this->getAddLink($title, $display, $startingSiteComponent);
         }
     }
     // If invalid, just return the wiki text.
     return $wikiText;
 }
Exemple #27
0
 /**
  * Answer a component containing either all slots or the search results.
  *
  * @return object Component
  * @access private
  * @since 12/4/07
  */
 private function getSlotList()
 {
     $slotMgr = SlotManager::instance();
     if ($this->getSearchTerm()) {
         $slots = $this->getSlotsBySearch($this->getSearchTerm());
     } else {
         $slots = $slotMgr->getAllSlots();
     }
     $headRow = "\n\t<tr>\n\t\t<th>" . _("Placeholder Name") . "</th>\n\t\t<th>" . _("Type") . "</th>\n\t\t<th>" . _("Category") . "</th>\n\t\t<th>" . _("Media Quota") . "</th>\n\t\t<th>" . _("Site Exists") . "</th>\n\t\t<th>" . _("Owners") . "</th>\n\t\t<th>" . _("Actions") . "</th>\n\t</tr>";
     $printer = new TableIteratorResultPrinter($slots, $headRow, 50, array($this, 'getSlotComponent'));
     return new Block($printer->getTable(), STANDARD_BLOCK);
 }
 /**
  * Answer the slot for the site.
  *
  * @return object Slot
  * @access protected
  * @since 3/26/08
  */
 protected function getSlot()
 {
     if (!isset($this->slot)) {
         $slotMgr = SlotManager::instance();
         $this->slot = $slotMgr->getSlotBySiteId($this->getSiteAsset($this->getContentAsset())->getId());
     }
     return $this->slot;
 }
 /**
  * Answer an array of the slots in this category.
  * 
  * @return array of Slot objects
  * @access public
  * @since 4/1/08
  */
 public function getSlots()
 {
     $slotMgr = SlotManager::instance();
     return $slotMgr->getSlotsByType(Slot::personal);
 }
Exemple #30
0
 /**
  * Answer the slot for this action.
  * 
  * @return object SegueSlot
  * @access protected
  * @since 1/28/08
  */
 protected function getSlot()
 {
     $slotMgr = SlotManager::instance();
     return $slotMgr->getSlotByShortname($this->getSlotName());
 }