/**
	 * Handles autoedit Ajax call from #autoedit parser function and from save
	 * and continue button.
	 *
	 * @param String $optionsString the options/data string
	 * @param String $prefillFromExisting String set to 'true' to retain existing form values (unset by save and continue)
	 * @return String
	 */
	static function handleAutoEdit( $optionsString = null, $prefillFromExisting = 'true' ) {

		global $wgParser;

		$handler = new self( null, 'sfautoedit' );
		$handler->isApiQuery( false );
		$options = $handler->setOptionsString( $optionsString );

		// get oktext (or use default)
		if ( array_key_exists( 'ok text', $options ) ) {
			$oktext = $options['ok text'];
		} else {
			$oktext = wfMsg( 'sf_autoedit_success' );
		}

		// get errortext (or use default)
		if ( array_key_exists( 'error text', $options ) ) {
			$errortext = $options['error text'];
		} else {
			$errortext = '$1';
		}

		// process data
		// result will be true or an error message
		$result = $handler->storeSemanticData( $prefillFromExisting === 'true' );

		// wrap result in ok/error message
		if ( $result === true ) {

			$options = $handler->getOptions();
			$result = wfMsgReplaceArgs( $oktext, array( $options['target'], $options['form'] ) );

		} else {

			$result->setResponseCode( '400 Bad Request' );
			$result = wfMsgReplaceArgs( $errortext, array( $result ) );
		}

		// initialize parser
		$title = Title::newFromText( 'DummyTitle' );

		if ( !StubObject::isRealObject( $wgParser ) ) {
			$wgParser->_unstub();
		}

		$parseroptions = $wgParser->getOptions();

		if ( $parseroptions == null ) {
			$parseroptions = new ParserOptions();
			$wgParser->Options( $parseroptions );
		}

		$parseroptions->enableLimitReport( false );


		$result = new AjaxResponse( $wgParser->parse( $result, $title, $parseroptions )->getText() );
		$result->setContentType( 'text/html' );

		return $result;
	}
 public function get($ogID)
 {
     $db = Loader::db();
     $og = new self();
     $ogData = $db->getRow("SELECT * FROM " . TABLE_FORMIFY_OPTION_GROUPS . " WHERE ogID = ?", array($ogID));
     if ($ogData['ogID'] == $ogID && $ogID != 0) {
         foreach ($ogData as $col => $val) {
             if ($val != '') {
                 $og->{$col} = $val;
             }
         }
         $og->getOptions();
         return $og;
     } else {
         return false;
     }
 }
Example #3
0
 public function getByID($ffID, $fID = 0)
 {
     $db = Loader::db();
     $field = new self();
     if ($fID != 0) {
         $fieldData = $db->getRow("SELECT * FROM " . TABLE_FORMIFY_FIELDS . " WHERE ffID = ? AND fID = ?", array($ffID, $fID));
     } else {
         $fieldData = $db->getRow("SELECT * FROM " . TABLE_FORMIFY_FIELDS . " WHERE ffID = ?", array($ffID));
     }
     if ($fieldData['ffID'] == $ffID && $ffID != 0) {
         foreach ($fieldData as $col => $val) {
             if ($val != '') {
                 $field->{$col} = $val;
             }
         }
         $field->shortLabel = self::shortenText(strip_tags($field->label), 25);
         if ($fieldData['maxLength'] == 0) {
             $field->maxLength = '';
         }
         $field->isPrimary = (bool) $field->isPrimary;
         $field->isRequired = (bool) $field->isRequired;
         $field->isIndexable = (bool) $field->isIndexable;
         $field->includeInEmail = (bool) $field->includeInEmail;
         $field->options = $field->getOptions();
         $field->optionsValues = $field->getOptionsValues();
         if ($field->isRequired) {
             $formInfo = $field->getFormInfo();
             $field->requiredIndicator = '<span style="color:' . $formInfo['requiredColor'] . '">' . $formInfo['requiredIndicator'] . '</span>';
         } else {
             $field->requiredIndicator = '';
         }
         switch ($field->defaultValueSource) {
             case 'username':
                 $u = new User();
                 $field->defaultValue = $u->getUserName();
                 break;
             case 'email':
                 $u = new User();
                 if ($u->isLoggedIn()) {
                     $ui = UserInfo::getByID($u->getUserID());
                     $field->defaultValue = $ui->getUserEmail();
                 }
                 break;
             case 'uID':
                 $u = new User();
                 $field->defaultValue = $u->getUserID();
                 break;
             default:
                 if ($field->populateWith != '') {
                     $u = new User();
                     if ($u->isLoggedIn()) {
                         $ui = UserInfo::getByID($u->getUserID());
                         $field->defaultValue = $ui->getAttribute($field->populateWith);
                     }
                 }
         }
         return $field;
     } else {
         return false;
     }
 }