/** * Returns an array of instances of all available field types. * * @return Array */ public function getTypeInstances($profileField = null) { $types = array(); foreach ($this->getFieldTypes() as $className => $title) { if (\humhub\libs\Helpers::CheckClassType($className, self::className())) { $instance = new $className(); if ($profileField != null) { $instance->profileField = $profileField; // Seems current type, so try load data if ($profileField->field_type_class == $className) { $instance->loadFieldConfig(); } } $types[] = $instance; } } return $types; }
/** * Action which handles file uploads * * The result is an json array of all uploaded files. */ public function actionUpload() { Yii::$app->response->format = 'json'; // Object which the uploaded file(s) belongs to (optional) $object = null; $objectModel = Yii::$app->request->get('objectModel'); $objectId = Yii::$app->request->get('objectId'); if ($objectModel != "" && $objectId != "" && \humhub\libs\Helpers::CheckClassType($objectModel, \yii\db\ActiveRecord::className())) { $givenObject = $objectModel::findOne(['id' => $objectId]); // Check if given object is HActiveRecordContent or HActiveRecordContentAddon and can be written by the current user if ($givenObject !== null && ($givenObject instanceof ContentActiveRecord || $givenObject instanceof ContentAddonActiveRecord) && $givenObject->content->canWrite()) { $object = $givenObject; } } $files = array(); foreach (UploadedFile::getInstancesByName('files') as $cFile) { $files[] = $this->handleFileUpload($cFile, $object); } return ['files' => $files]; }
/** * 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 != "" && \humhub\libs\Helpers::CheckClassType($this->field_type_class, fieldtype\BaseType::className())) { $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 (!\humhub\libs\Helpers::CheckClassType($className, ContentAddonActiveRecord::className())) { throw new \yii\base\Exception("Given className is not a content addon model!"); } $target = $className::findOne(['id' => $pk]); if ($target === null) { throw new HttpException(500, 'Could not find content addon record!'); } if ($target->object_model != get_class($this->parentContent) && $target->object_id != $this->parentContent->getPrimaryKey()) { throw new HttpException(500, 'Content addon not belongs to given content record!'); } $this->contentAddon = $target; }
public function init() { if (!\humhub\libs\Helpers::CheckClassType($this->parserClass, "cebe\\markdown\\Parser")) { throw new Exception("Invalid markdown parser class given!"); } }