Exemplo n.º 1
0
		public static function getAvailableList() {
			$blocktypes = array();
			$dir = DIR_FILES_BLOCK_TYPES;
			$db = Loader::db();
			
			$btHandles = $db->GetCol("select btHandle from BlockTypes");
			
			$aDir = array();
			if (is_dir($dir)) {
				$handle = opendir($dir);
				while(($file = readdir($handle)) !== false) {
					if (strpos($file, '.') === false) {
						$fdir = $dir . '/' . $file;
						if (is_dir($fdir) && !in_array($file, $btHandles) && file_exists($fdir . '/' . FILENAME_BLOCK_CONTROLLER)) {
							$bt = new BlockType;
							$bt->btHandle = $file;
							$class = $bt->getBlockTypeClassFromHandle($file);
							
							require_once($fdir . '/' . FILENAME_BLOCK_CONTROLLER);
							if (!class_exists($class)) {
								continue;
							}
							$bta = new $class;
							$bt->btName = $bta->getBlockTypeName();
							$bt->btDescription = $bta->getBlockTypeDescription();
							$bt->hasCustomViewTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_VIEW);
							$bt->hasCustomEditTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_EDIT);
							$bt->hasCustomAddTemplate = file_exists(DIR_FILES_BLOCK_TYPES . '/' . $file . '/' . FILENAME_BLOCK_ADD);
							
							
							$btID = $db->GetOne("select btID from BlockTypes where btHandle = ?", array($file));
							$bt->installed = ($btID > 0);
							$bt->btID = $btID;
							
							$blocktypes[] = $bt;
							
						}
					}				
				}
			}
			
			return $blocktypes;
		}
Exemplo n.º 2
0
 /**
  * installs a block type
  * @param string $btHandle
  * @param BlockType $bt
  * @param string $dir
  * @param int $btID
  */
 protected function doInstallBlockType($btHandle, $bt, $dir, $btID = 0)
 {
     $db = Loader::db();
     if (file_exists($dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER)) {
         $class = $bt->getBlockTypeClassFromHandle();
         $path = $dir . '/' . $btHandle;
         if (!class_exists($class)) {
             require_once $dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER;
         }
         if (!class_exists($class)) {
             throw new Exception(t("%s not found. Please check that the block controller file contains the correct class name.", $class));
         }
         $bta = new $class();
         // first run the subclass methods. If they work then we install the block
         $r = $bta->install($path);
         if (!$r->result) {
             return $r->message;
         }
         $btd = new BlockTypeDB();
         $btd->btHandle = $btHandle;
         $btd->btName = $bta->getBlockTypeName();
         $btd->btDescription = $bta->getBlockTypeDescription();
         $btd->btActiveWhenAdded = $bta->isActiveWhenAdded();
         $btd->btCopyWhenPropagate = $bta->isCopiedWhenPropagated();
         $btd->btIncludeAll = $bta->includeAll();
         $btd->btIsInternal = $bta->isBlockTypeInternal();
         $btd->btInterfaceHeight = $bta->getInterfaceHeight();
         $btd->btInterfaceWidth = $bta->getInterfaceWidth();
         $btd->pkgID = $bt->getPackageID();
         if ($btID > 0) {
             $btd->btID = $btID;
             $r = $btd->Replace();
         } else {
             $r = $btd->save();
         }
         // now we remove the block type from cache
         $ca = new Cache();
         $ca->delete('blockTypeByID', $btID);
         $ca->delete('blockTypeByHandle', $btHandle);
         $ca->delete('blockTypeList', false);
         if (!$r) {
             return $db->ErrorMsg();
         }
     } else {
         return t("No block found with the handle %s.", $btHandle);
     }
 }
Exemplo n.º 3
0
 /**
  * installs a block type
  * @param string $btHandle
  * @param BlockType $bt
  * @param string $dir
  * @param int $btID
  */
 protected function doInstallBlockType($btHandle, $bt, $dir, $btID = 0)
 {
     $db = Loader::db();
     $env = Environment::get();
     $env->clearOverrideCache();
     if (file_exists($dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER)) {
         $class = $bt->getBlockTypeClassFromHandle();
         $path = $dir . '/' . $btHandle;
         if (!class_exists($class)) {
             require_once $dir . '/' . $btHandle . '/' . FILENAME_BLOCK_CONTROLLER;
         }
         if (!class_exists($class)) {
             throw new Exception(t("%s not found. Please check that the block controller file contains the correct class name.", $class));
         }
         $bta = new $class();
         //Attempt to run the subclass methods (install schema from db.xml, etc.)
         $r = $bta->install($path);
         //Validate
         if ($r === false) {
             return t('Error: Block Type cannot be installed because no db.xml file can be found. Either create a db.xml file for this block type, or remove the $btTable variable from its controller.');
         } else {
             if (!$r->result && $r->message) {
                 return $r->message;
             } else {
                 if (!$r->result && !$r->message) {
                     return t('Error: Block Type cannot be installed due to an unknown database error. Please check that the db.xml file for this block type is formatted correctly.');
                 } else {
                     if ($message = BlockType::validateInstalledDatabaseTable($bta->getBlockTypeDatabaseTable())) {
                         $db->Execute('DROP TABLE IF EXISTS ' . $bta->getBlockTypeDatabaseTable());
                         return $message;
                     }
                 }
             }
         }
         $currentLocale = Localization::activeLocale();
         if ($currentLocale != 'en_US') {
             // Prevent the database records being stored in wrong language
             Localization::changeLocale('en_US');
         }
         //Install the block
         $btd = new BlockTypeDB();
         $btd->btHandle = $btHandle;
         $btd->btName = $bta->getBlockTypeName();
         $btd->btDescription = $bta->getBlockTypeDescription();
         $btd->btActiveWhenAdded = $bta->isActiveWhenAdded();
         $btd->btCopyWhenPropagate = $bta->isCopiedWhenPropagated();
         $btd->btIncludeAll = $bta->includeAll();
         $btd->btIsInternal = $bta->isBlockTypeInternal();
         $btd->btInterfaceHeight = $bta->getInterfaceHeight();
         $btd->btInterfaceWidth = $bta->getInterfaceWidth();
         $btd->pkgID = $bt->getPackageID();
         if ($currentLocale != 'en_US') {
             Localization::changeLocale($currentLocale);
         }
         if ($btID > 0) {
             $btd->btID = $btID;
             $btDisplayOrder = $db->GetOne('select btDisplayOrder from BlockTypes where btID = ?', array($btID));
             if (!$btDisplayOrder) {
                 $btDisplayOrder = 0;
             }
             $btd->btDisplayOrder = $btDisplayOrder;
             $r = $btd->Replace();
         } else {
             if ($bta->isBlockTypeInternal()) {
                 $btd->btDisplayOrder = 0;
             } else {
                 $btMax = $db->GetOne('select max(btDisplayOrder) from BlockTypes');
                 if ($btMax < 1 && $btMax !== '0') {
                     $btd->btDisplayOrder = 0;
                 } else {
                     $btd->btDisplayOrder = $btMax + 1;
                 }
             }
             $r = $btd->save();
         }
         // now we remove the block type from cache
         $ca = new Cache();
         $ca->delete('blockTypeByID', $btID);
         $ca->delete('blockTypeByHandle', $btHandle);
         $ca->delete('blockTypeList', false);
         if (!$r) {
             return $db->ErrorMsg();
         }
     } else {
         return t("No block found with the handle %s.", $btHandle);
     }
 }