예제 #1
0
파일: menu.php 프로젝트: notzen/concrete5
	public function getController() {
		if (isset($this->controller)) {
			return $this->controller;
		} else {
			$class = Object::camelcase($this->handle . 'ConcreteInterfaceMenuItemController');
			if (!class_exists($class)) {
				$file1 = DIR_FILES_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
				if ($this->pkgHandle) {
					$pkgHandle = $this->pkgHandle;
					$dir = (is_dir(DIR_PACKAGES . '/' . $pkgHandle)) ? DIR_PACKAGES : DIR_PACKAGES_CORE;
					$file2 = $dir . '/' . $pkgHandle . '/' . DIRNAME_ELEMENTS . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
				}
				$file3 = DIR_FILES_ELEMENTS_CORE . '/' . DIRNAME_ELEMENTS_HEADER_MENU . '/' . $this->handle . '/' . FILENAME_MENU_ITEM_CONTROLLER;
				if (file_exists($file1)) {
					include($file1);
				} else if (isset($file2) && file_exists($file2)) {
					include($file2);
				} else {
					include($file3);
				}
			}

			$this->controller = new $class();
			$this->controller->setMenuItem($this);
			return $this->controller;
		}
	}
예제 #2
0
	/** 
	 * When passed an "event" as a string, a user-defined method will be run INSIDE this page's controller
	 * whenever an event takes place. The name/location of this event is not customizable. If you want more
	 * customization, used extend() below.
	 */
	public static function extendPageType($ctHandle, $event = false, $params = array()) {
		Events::enableEvents();
		if ($event == false) {
			// then we're registering ALL the page type events for this particular page type
			Events::extendPageType($ctHandle, 'on_page_add', $params);
			Events::extendPageType($ctHandle, 'on_page_update', $params);
			Events::extendPageType($ctHandle, 'on_page_duplicate', $params);
			Events::extendPageType($ctHandle, 'on_page_move', $params);
			Events::extendPageType($ctHandle, 'on_page_view', $params);
			Events::extendPageType($ctHandle, 'on_page_version_approve', $params);
			Events::extendPageType($ctHandle, 'on_page_delete', $params);
		} else {
			$ce = Events::getInstance();
			$class = Object::camelcase($ctHandle) . 'PageTypeController';
			$method = $event;
			$filename = Loader::pageTypeControllerPath($ctHandle);
			$ce->registeredEvents[$event][] = array(
				Events::EVENT_TYPE_PAGETYPE,
				$class,
				$method,
				$filename,
				$params
			);
		}
	}
예제 #3
0
 private function getControllerFile()
 {
     if (file_exists(DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS . '/' . $this->filename)) {
         $filename = DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS . '/' . $this->filename;
         $class = Object::camelcase(substr($this->filename, 0, strrpos($this->filename, '.php')));
     } else {
         if (file_exists(DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS_CORE . '/' . $this->filename)) {
             $filename = DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS_CORE . '/' . $this->filename;
             $class = Object::camelcase(substr($this->filename, 0, strrpos($this->filename, '.php')));
         }
     }
     if (isset($filename)) {
         require_once $filename;
         $class .= 'ExternalFormBlockController';
         $fp = new $class($this->getBlockObject());
         return $fp;
     }
 }
예제 #4
0
 protected function getControllerFile()
 {
     if (file_exists(DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS . '/' . $this->filename)) {
         $filename = DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS . '/' . $this->filename;
         $class = Object::camelcase(substr($this->filename, 0, strrpos($this->filename, '.php')));
     } else {
         if (file_exists(DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS_CORE . '/' . $this->filename)) {
             $filename = DIR_FILES_BLOCK_TYPES_FORMS_EXTERNAL_PROCESS_CORE . '/' . $this->filename;
             $class = Object::camelcase(substr($this->filename, 0, strrpos($this->filename, '.php')));
         }
     }
     if (isset($filename)) {
         require_once $filename;
         $class .= 'ExternalFormBlockController';
         $fp = new $class($this->getBlockObject());
     }
     if (is_object($fp)) {
         $fp->on_start();
         return $fp;
     } else {
         throw new Exception(t('Unable load external form block controller file: %s', $this->filename));
     }
 }
예제 #5
0
 public function installByPackage($jHandle, $pkg)
 {
     $dir = is_dir(DIR_PACKAGES . '/' . $pkg->getPackageHandle()) ? DIR_PACKAGES . '/' . $pkg->getPackageHandle() : DIR_PACKAGES_CORE . '/' . $pkg->getPackageHandle();
     require_once $dir . '/' . DIRNAME_JOBS . '/' . $jHandle . '.php';
     $className = Object::camelcase($jHandle);
     if (class_exists($className)) {
         $j = new $className();
         $db = Loader::db();
         $db->Execute('insert into Jobs (jName, jDescription, jDateInstalled, jNotUninstallable, jHandle, pkgID) values (?, ?, ?, ?, ?, ?)', array($j->getJobName(), $j->getJobDescription(), Loader::helper('date')->getLocalDateTime(), 0, $jHandle, $pkg->getPackageID()));
         Events::fire('on_job_install', $j);
         return $j;
     }
 }
 /** 
  * Loads a controller for either a page or view
  */
 public function controller($item)
 {
     $include = false;
     if (is_string($item)) {
         $db = self::db();
         if (is_object($db)) {
             try {
                 $_item = Page::getByPath($item);
                 if ($_item->isError()) {
                     $path = $item;
                 } else {
                     $item = $_item;
                 }
             } catch (Exception $e) {
                 $path = $item;
             }
         } else {
             $path = $item;
         }
     }
     if ($item instanceof Page) {
         $c = $item;
         if ($c->getCollectionTypeID() > 0) {
             $ctHandle = $c->getCollectionTypeHandle();
             $path = self::pageTypeControllerPath($ctHandle, $item->getPackageHandle());
             if ($path != false) {
                 require_once $path;
                 $class = Object::camelcase($ctHandle) . 'PageTypeController';
             }
         } else {
             if ($c->isGeneratedCollection()) {
                 $file = $c->getCollectionFilename();
                 if ($file != '') {
                     // strip off PHP suffix for the $path variable, which needs it gone
                     if (strpos($file, '/' . FILENAME_COLLECTION_VIEW) !== false) {
                         $path = substr($file, 0, strpos($file, '/' . FILENAME_COLLECTION_VIEW));
                     } else {
                         $path = substr($file, 0, strpos($file, '.php'));
                     }
                 }
             }
         }
     } else {
         if ($item instanceof Block || $item instanceof BlockType) {
             $class = Object::camelcase($item->getBlockTypeHandle()) . 'BlockController';
             if ($item instanceof BlockType) {
                 $controller = new $class($item);
             }
             if ($item instanceof Block) {
                 $c = $item->getBlockCollectionObject();
             }
         }
     }
     $controllerFile = $path . '.php';
     if ($path != '') {
         $env = Environment::get();
         $pkgHandle = false;
         if (is_object($item)) {
             $pkgHandle = $item->getPackageHandle();
         }
         $f1 = $env->getPath(DIRNAME_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER, $pkgHandle);
         $f2 = $env->getPath(DIRNAME_CONTROLLERS . $controllerFile, $pkgHandle);
         if (file_exists($f2)) {
             $include = true;
             require_once $f2;
         } else {
             if (file_exists($f1)) {
                 $include = true;
                 require_once $f1;
             }
         }
         if ($include) {
             $class = Object::camelcase($path) . 'Controller';
         }
     }
     if (!isset($controller)) {
         if ($class && class_exists($class)) {
             // now we get just the filename for this guy, so we can extrapolate
             // what our controller is named
             $controller = new $class($item);
         } else {
             $controller = new Controller($item);
         }
     }
     if (isset($c) && is_object($c)) {
         $controller->setCollectionObject($c);
     }
     return $controller;
 }
예제 #7
0
 /**
  * Takes a string and turns it into the CamelCase or StudlyCaps version
  * @param string $string
  * @return string
  */
 public function camelcase($string)
 {
     return Object::camelcase($string);
 }
예제 #8
0
 /** 
  * Loads a controller for either a page or view
  */
 public function controller($item)
 {
     if (is_string($item)) {
         $db = Loader::db();
         if (is_object($db)) {
             try {
                 $_item = Page::getByPath($item);
                 if ($_item->isError()) {
                     $path = $item;
                 } else {
                     $item = $_item;
                 }
             } catch (Exception $e) {
                 $path = $item;
             }
         } else {
             $path = $item;
         }
     }
     if ($item instanceof Page) {
         $c = $item;
         if ($c->getCollectionTypeID() > 0) {
             $ctHandle = $c->getCollectionTypeHandle();
             $path = Loader::pageTypeControllerPath($ctHandle, $item->getPackageHandle());
             if ($path != false) {
                 require_once $path;
                 $class = Object::camelcase($ctHandle) . 'PageTypeController';
             }
         } else {
             if ($c->isGeneratedCollection()) {
                 $file = $c->getCollectionFilename();
                 if ($file != '') {
                     // strip off PHP suffix for the $path variable, which needs it gone
                     if (strpos($file, FILENAME_COLLECTION_VIEW) !== false) {
                         $path = substr($file, 0, strpos($file, '/' . FILENAME_COLLECTION_VIEW));
                     } else {
                         $path = substr($file, 0, strpos($file, '.php'));
                     }
                 }
             }
         }
     } else {
         if ($item instanceof Block || $item instanceof BlockType) {
             if (file_exists(DIR_FILES_BLOCK_TYPES . '/' . $item->getBlockTypeHandle() . '/' . FILENAME_BLOCK_CONTROLLER)) {
                 require_once DIR_FILES_BLOCK_TYPES . "/" . $item->getBlockTypeHandle() . "/" . FILENAME_BLOCK_CONTROLLER;
             } else {
                 if ($item->getPackageID() > 0 && file_exists(DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $item->getBlockTypeHandle() . '/' . FILENAME_BLOCK_CONTROLLER)) {
                     require_once DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_BLOCKS . '/' . $item->getBlockTypeHandle() . '/' . FILENAME_BLOCK_CONTROLLER;
                 } else {
                     if (file_exists(DIR_FILES_BLOCK_TYPES_CORE . '/' . $item->getBlockTypeHandle() . '/' . FILENAME_BLOCK_CONTROLLER)) {
                         require_once DIR_FILES_BLOCK_TYPES_CORE . "/" . $item->getBlockTypeHandle() . "/" . FILENAME_BLOCK_CONTROLLER;
                     }
                 }
             }
             $class = Object::camelcase($item->getBlockTypeHandle()) . 'BlockController';
             if (class_exists($class) && $item instanceof BlockType) {
                 $controller = new $class($item);
             }
             if ($item instanceof Block) {
                 $c = $item->getBlockCollectionObject();
             }
         }
     }
     $controllerFile = $path . '.php';
     if ($path != '') {
         if (file_exists(DIR_FILES_CONTROLLERS . $controllerFile)) {
             include DIR_FILES_CONTROLLERS . $controllerFile;
             $include = true;
         } else {
             if (file_exists(DIR_FILES_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER)) {
                 include DIR_FILES_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER;
                 $include = true;
             } else {
                 if (file_exists(DIR_FILES_CONTROLLERS_REQUIRED . $controllerFile)) {
                     include DIR_FILES_CONTROLLERS_REQUIRED . $controllerFile;
                     $include = true;
                 } else {
                     if (file_exists(DIR_FILES_CONTROLLERS_REQUIRED . $path . '/' . FILENAME_COLLECTION_CONTROLLER)) {
                         include DIR_FILES_CONTROLLERS_REQUIRED . $path . '/' . FILENAME_COLLECTION_CONTROLLER;
                         $include = true;
                     } else {
                         if (is_object($item)) {
                             if ($item->getPackageID() > 0 && file_exists(DIR_FILES_CONTROLLERS . $controllerFile)) {
                                 include DIR_FILES_CONTROLLERS . $controllerFile;
                                 $include = true;
                             } else {
                                 if ($item->getPackageID() > 0 && file_exists(DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $controllerFile)) {
                                     include DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $controllerFile;
                                     $include = true;
                                 } else {
                                     if ($item->getPackageID() > 0 && file_exists(DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER)) {
                                         include DIR_PACKAGES . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER;
                                         $include = true;
                                     } else {
                                         if ($item->getPackageID() > 0 && file_exists(DIR_PACKAGES_CORE . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $controllerFile)) {
                                             include DIR_PACKAGES_CORE . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $controllerFile;
                                             $include = true;
                                         } else {
                                             if ($item->getPackageID() > 0 && file_exists(DIR_PACKAGES_CORE . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER)) {
                                                 include DIR_PACKAGES_CORE . '/' . $item->getPackageHandle() . '/' . DIRNAME_CONTROLLERS . $path . '/' . FILENAME_COLLECTION_CONTROLLER;
                                                 $include = true;
                                             }
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         if ($include) {
             $class = Object::camelcase($path) . 'Controller';
         }
     }
     if (!isset($controller)) {
         if ($class && class_exists($class)) {
             // now we get just the filename for this guy, so we can extrapolate
             // what our controller is named
             $controller = new $class($item);
         } else {
             $controller = new Controller($item);
         }
     }
     if (is_object($c)) {
         $controller->setCollectionObject($c);
     }
     $controller->setupRestrictedMethods();
     return $controller;
 }
예제 #9
0
	public function getCustomInspector() {
		$script = 'file/types/' . $this->getCustomImporter();
		if ($this->pkgHandle != false) {
			Loader::library($script, $this->pkgHandle);
		} else {
			Loader::library($script);
		}
		$class = Object::camelcase($this->getCustomImporter()) . 'FileTypeInspector';
		$cl = new $class;
		return $cl;
	}