/** * Loads Target Model for the Comment * It needs to be a SiContentBehavior Object * * @return type */ private function loadTargetModel() { // Fast lane if ($this->cachedLoadedTarget != null) { return $this->cachedLoadedTarget; } // Request Params $targetModelClass = Yii::app()->request->getParam('model'); $targetModelId = (int) Yii::app()->request->getParam('id'); $targetModelClass = Yii::app()->input->stripClean(trim($targetModelClass)); if ($targetModelClass == "" || $targetModelId == "") { throw new CHttpException(500, Yii::t('CommentModule.controllers_CommentController', 'Model & Id Parameter required!')); } if (!Helpers::CheckClassType($targetModelClass, 'HActiveRecordContent')) { throw new CHttpException(500, Yii::t('CommentModule.controllers_CommentController', 'Invalid target class given')); } $model = call_user_func(array($targetModelClass, 'model')); $target = $model->findByPk($targetModelId); if (!$target instanceof HActiveRecordContent) { throw new CHttpException(500, Yii::t('CommentModule.controllers_CommentController', 'Invalid target class given')); } if ($target == null) { throw new CHttpException(404, Yii::t('CommentModule.controllers_CommentController', 'Target not found!')); } // Check if we can read the target model, so we can comment it? if (!$target->content->canRead(Yii::app()->user->id)) { throw new CHttpException(403, Yii::t('CommentModule.controllers_CommentController', 'Access denied!')); } // Create Fastlane: $this->cachedLoadedTarget = $target; return $target; }
public function init() { if (!Helpers::CheckClassType($this->parserClass, "cebe\\markdown\\Parser")) { throw new CException("Invalid markdown parser class given!"); } Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/resources/highlight.js/highlight.pack.js'); Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/resources/highlight.js/styles/' . $this->highlightJsCss . '.css'); Yii::app()->clientScript->registerScript("highlightJs", '$("pre code").each(function(i, e) { hljs.highlightBlock(e); });'); }
protected function instantiate($attributes) { $className = $attributes['class']; if (Helpers::CheckClassType($className, 'Notification')) { // Instanciate correct Asset Model $model = new $className(null); return $model; } return null; }
/** * Redirects to given HActiveRecordContent or HActiveRecordContentAddon */ public function actionContent() { $id = (int) Yii::app()->request->getParam('id', ""); $model = Yii::app()->request->getParam('model'); // Check given model if (!Helpers::CheckClassType($model, array('HActiveRecordContent', 'HActiveRecordContentAddon'))) { throw new CHttpException(404, Yii::t('WallModule.controllers_PermaController', 'Invalid model given!')); } $model = call_user_func(array($model, 'model')); $object = $model->findByPk($id); if ($object == null) { throw new CHttpException(404, Yii::t('WallModule.controllers_PermaController', 'Could not find requested content!')); } $this->redirect($object->content->getUrl()); }
/** * Returns an array of instances of all available field types. * * @return Array */ public static function getTypeInstances($profileField = null) { $types = array(); foreach (self::getFieldTypes() as $className => $title) { if (Helpers::CheckClassType($className, 'ProfileFieldType')) { $instance = new $className(); if ($profileField != null) { $instance->profileField = $profileField; // Seems current type, so try load data if ($profileField->field_type_class == $className) { $instance->load(); } } $types[] = $instance; } } return $types; }
/** * On given Content Class and id redirect the user to it. */ public function actionContent() { $content = Content::model()->findByAttributes(array('object_model' => Yii::app()->request->getParam('model'), 'object_id' => Yii::app()->request->getParam('id'))); if ($content != null) { $url = $this->createUrl('WallEntry', array('id' => $content->getFirstWallEntryId())); $this->redirect($url); return; } $id = (int) Yii::app()->request->getParam('id', ""); $model = Yii::app()->request->getParam('model'); // Check given model if (!Helpers::CheckClassType($model, 'HActiveRecord')) { throw new CHttpException(404, Yii::t('WallModule.controllers_PermaController', 'Unknown content class!')); } $model = call_user_func(array($model, 'model')); $object = $model->findByPk($id); if ($object == null) { throw new CHttpException(404, Yii::t('WallModule.controllers_PermaController', 'Could not find requested content!')); } $url = $this->createUrl('WallEntry', array('id' => $object->content->getFirstWallEntryId())); $this->redirect($url); }
/** * Returns the ProfileFieldType Class for this Profile Field * * @return ProfileFieldType */ public function getFieldType() { if ($this->_fieldType != null) { return $this->_fieldType; } if ($this->field_type_class != "" && Helpers::CheckClassType($this->field_type_class, 'ProfileFieldType')) { $type = $this->field_type_class; $this->_fieldType = new $type(); $this->_fieldType->setProfileField($this); return $this->_fieldType; } return null; }
/** * Loads Content Addon * We also validates that the content addon corresponds to the loaded content. * * @param string $className * @param int $pk */ public function loadContentAddon($className, $pk) { if (!Helpers::CheckClassType($className, 'HActiveRecordContentAddon')) { throw new CException("Given className is not a content addon model!"); } $model = call_user_func(array($className, 'model')); $target = $model->findByPk($pk); if ($target === null) { throw new CHttpException(500, 'Could not find content addon record!'); } if ($target->object_model != get_class($this->parentContent) && $target->object_id != $this->parentContent->getPrimaryKey()) { throw new CHttpException(500, 'Content addon not belongs to given content record!'); } $this->contentAddon = $target; }