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Fq}o	vl5asśhkz= o31*	؇.vՍ3caֳ@XD=A?¡F-aPy|l$ZBYOׁ2(*"-g?	@ؒ[,[w -BoS7;cx(<@r̈sWAg-/^_0{u2˞0|e5ΆQРȅ̅MH32]J댈ǓCуK3ޥ zi-
YVpfkdҥ6uZM}'jB36b:؍#<ʁ%IFs	ȱz f.?bf;.TkY4eN
5hǂ_\hO_*h9/r-E*	D@Z_\vv,9+"Ȋ0|kdɪ0Enх&r|BƬ 4}\	[ 1~1Γ܉md>E}
@|$fR4@_⃓,ُfkSs+f?)#R|PAhqc>ϩc{<ǦP?	hߩteAVpt.Hn_4֊K_韗K@xTtAy~f9e8^'SHz+b_LsG%EH\,MپrJhȒ$m0g'_%_^ZlP2	l̫{K=k|MB훋9bNenkRrY$uۂ6W9rv܈#f4 W8
ோ@kS@b[Zp^G9b/>]kjv*; a>jXdX("/P(#I)Ol˘(U]Qvow N^f߮Vd/@4Iwa	Kױ+QUc(PiMdq2-%{SMZ0T/w'󟛲*bu2i5S赗VgBqqtß8([>4^eƂC5k?˧O&4CW~W̱'I
&ECnrih+gVyjndS*a ?jB<uR:U1nUKٱ[Zh<>iC{*ܳ?Bpq;^e v-hRJ3Nᾣ1#ɎzWSdxd#q@p0)XW>^w;	:cm:k7s=w.h< 8fw»R5w;`>o{Tn> 5xtK^,uSoȒ0DBUz.3Nᾣ1#Ɏz[Nfcu\7(Y ??\Gy +/"Z)XW>^w;	:cm:k7s=w0Y
Y3rdX8cr$mIn@v5DvRK7`>o{Tn> 5xtK^,'<;#Yu33G>{Ĥ=LbX);aB.f1*ȟh[t\Ğp&+hkV!L=8ӼYs
 ~~0~9N9yv.杪͊aRR=R<pKlvS
y,>[7q2h꘶3
(MvXV,?欘;

                if ($base != 'global') {
                    $mimetype = str_replace('_', '/', $base);
                    $stack['mimetype'][$mimetype] = $mimetype;
                    $stack['empty_mimetype'][$mimetype] = $mimetype;
                }
            }
        }
    }
    return $stack;
}

/**
 * Returns the class name of the transformation
 *
 * @param string $filename transformation file name
 *
 * @return string the class name of transformation
 */
function PMA_getTransformationClassName($filename)
{
    // get the transformation class name
    $class_name = explode(".php", $filename);
    $class_name = 'PMA\\' . str_replace('/', '\\', $class_name[0]);

    return $class_name;
}

/**
 * Returns the description of the transformation
 *
 * @param string $file transformation file
 *
 * @return String the description of the transformation
 */
function PMA_getTransformationDescription($file)
{
    $include_file = 'libraries/plugins/transformations/' . $file;
    /* @var $class_name PMA\libraries\plugins\TransformationsInterface */
    $class_name = PMA_getTransformationClassName($include_file);
    // include and instantiate the class
    include_once $include_file;
    return $class_name::getInfo();
}

/**
 * Returns the name of the transformation
 *
 * @param string $file transformation file
 *
 * @return String the name of the transformation
 */
function PMA_getTransformationName($file)
{
    $include_file = 'libraries/plugins/transformations/' . $file;
    /* @var $class_name PMA\libraries\plugins\TransformationsInterface */
    $class_name = PMA_getTransformationClassName($include_file);
    // include and instantiate the class
    include_once $include_file;
    return $class_name::getName();
}

/**
 * Gets the mimetypes for all columns of a table
 *
 * @param string  $db       the name of the db to check for
 * @param string  $table    the name of the table to check for
 * @param boolean $strict   whether to include only results having a mimetype set
 * @param boolean $fullName whether to use full column names as the key
 *
 * @access public
 *
 * @return array [field_name][field_key] = field_value
 */
function PMA_getMIME($db, $table, $strict = false, $fullName = false)
{
    $cfgRelation = PMA_getRelationsParam();

    if (! $cfgRelation['commwork']) {
        return false;
    }

    $com_qry = '';
    if ($fullName) {
        $com_qry .= "SELECT CONCAT("
            . "`db_name`, '.', `table_name`, '.', `column_name`"
            . ") AS column_name, ";
    } else {
        $com_qry  = "SELECT `column_name`, ";
    }
    $com_qry .= '`mimetype`,
                `transformation`,
                `transformation_options`,
                `input_transformation`,
                `input_transformation_options`
         FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
        . PMA\libraries\Util::backquote($cfgRelation['column_info']) . '
         WHERE `db_name`    = \'' . $GLOBALS['dbi']->escapeString($db) . '\'
           AND `table_name` = \'' . $GLOBALS['dbi']->escapeString($table) . '\'
           AND ( `mimetype` != \'\'' . (!$strict ? '
              OR `transformation` != \'\'
              OR `transformation_options` != \'\'
              OR `input_transformation` != \'\'
              OR `input_transformation_options` != \'\'' : '') . ')';
    $result = $GLOBALS['dbi']->fetchResult(
        $com_qry, 'column_name', null, $GLOBALS['controllink']
    );

    foreach ($result as $column => $values) {
        // replacements in mimetype and transformation
        $values = str_replace("jpeg", "JPEG", $values);
        $values = str_replace("png", "PNG", $values);

        // convert mimetype to new format (f.e. Text_Plain, etc)
        $delimiter_space = '- ';
        $delimiter = "_";
        $values['mimetype'] = str_replace(
            $delimiter_space,
            $delimiter,
            ucwords(
                str_replace(
                    $delimiter,
                    $delimiter_space,
                    $values['mimetype']
                )
            )
        );

        // For transformation of form
        // output/image_jpeg__inline.inc.php
        // extract dir part.
        $dir = explode('/', $values['transformation']);
        $subdir = '';
        if (count($dir) === 2) {
            $subdir = $dir[0] . '/';
            $values['transformation'] = $dir[1];
        }

        $values['transformation'] = str_replace(
            $delimiter_space,
            $delimiter,
            ucwords(
                str_replace(
                    $delimiter,
                    $delimiter_space,
                    $values['transformation']
                )
            )
        );
        $values['transformation'] = $subdir . $values['transformation'];
        $result[$column] = $values;
    }

    return $result;
} // end of the 'PMA_getMIME()' function

/**
 * Set a single mimetype to a certain value.
 *
 * @param string  $db                 the name of the db
 * @param string  $table              the name of the table
 * @param string  $key                the name of the column
 * @param string  $mimetype           the mimetype of the column
 * @param string  $transformation     the transformation of the column
 * @param string  $transformationOpts the transformation options of the column
 * @param string  $inputTransform     the input transformation of the column
 * @param string  $inputTransformOpts the input transformation options of the column
 * @param boolean $forcedelete        force delete, will erase any existing
 *                                    comments for this column
 *
 * @access  public
 *
 * @return boolean  true, if comment-query was made.
 */
function PMA_setMIME($db, $table, $key, $mimetype, $transformation,
    $transformationOpts, $inputTransform, $inputTransformOpts, $forcedelete = false
) {
    $cfgRelation = PMA_getRelationsParam();

    if (! $cfgRelation['commwork']) {
        return false;
    }

    // lowercase mimetype & transformation
    $mimetype = mb_strtolower($mimetype);
    $transformation = mb_strtolower($transformation);

    $test_qry = '
         SELECT `mimetype`,
                `comment`
           FROM ' . PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
        . PMA\libraries\Util::backquote($cfgRelation['column_info']) . '
          WHERE `db_name`     = \'' . $GLOBALS['dbi']->escapeString($db) . '\'
            AND `table_name`  = \'' . $GLOBALS['dbi']->escapeString($table) . '\'
            AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key) . '\'';

    $test_rs   = PMA_queryAsControlUser(
        $test_qry, true, PMA\libraries\DatabaseInterface::QUERY_STORE
    );

    if ($test_rs && $GLOBALS['dbi']->numRows($test_rs) > 0) {
        $row = @$GLOBALS['dbi']->fetchAssoc($test_rs);
        $GLOBALS['dbi']->freeResult($test_rs);

        $transformationLength = mb_strlen($transformation);
        if (! $forcedelete
            && (mb_strlen($mimetype) || $transformationLength
            || mb_strlen($transformationOpts)
            || mb_strlen($row['comment']))
        ) {
            $upd_query = 'UPDATE '
                . PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
                . PMA\libraries\Util::backquote($cfgRelation['column_info'])
                . ' SET '
                . '`mimetype` = \''
                . $GLOBALS['dbi']->escapeString($mimetype) . '\', '
                . '`transformation` = \''
                . $GLOBALS['dbi']->escapeString($transformation) . '\', '
                . '`transformation_options` = \''
                . $GLOBALS['dbi']->escapeString($transformationOpts) . '\', '
                . '`input_transformation` = \''
                . $GLOBALS['dbi']->escapeString($inputTransform) . '\', '
                . '`input_transformation_options` = \''
                . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\'';
        } else {
            $upd_query = 'DELETE FROM '
                . PMA\libraries\Util::backquote($cfgRelation['db'])
                . '.' . PMA\libraries\Util::backquote($cfgRelation['column_info']);
        }
        $upd_query .= '
            WHERE `db_name`     = \'' . $GLOBALS['dbi']->escapeString($db) . '\'
              AND `table_name`  = \'' . $GLOBALS['dbi']->escapeString($table)
                . '\'
              AND `column_name` = \'' . $GLOBALS['dbi']->escapeString($key)
                . '\'';
    } elseif (mb_strlen($mimetype)
        || mb_strlen($transformation)
        || mb_strlen($transformationOpts)
    ) {

        $upd_query = 'INSERT INTO '
            . PMA\libraries\Util::backquote($cfgRelation['db'])
            . '.' . PMA\libraries\Util::backquote($cfgRelation['column_info'])
            . ' (db_name, table_name, column_name, mimetype, '
            . 'transformation, transformation_options, '
            . 'input_transformation, input_transformation_options) '
            . ' VALUES('
            . '\'' . $GLOBALS['dbi']->escapeString($db) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($table) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($key) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($mimetype) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($transformation) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($transformationOpts) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($inputTransform) . '\','
            . '\'' . $GLOBALS['dbi']->escapeString($inputTransformOpts) . '\')';
    }

    if (isset($upd_query)) {
        return PMA_queryAsControlUser($upd_query);
    } else {
        return false;
    }
} // end of 'PMA_setMIME()' function


/**
 * GLOBAL Plugin functions
 */

/**
 * Delete related transformation details
 * after deleting database. table or column
 *
 * @param string $db     Database name
 * @param string $table  Table name
 * @param string $column Column name
 *
 * @return boolean State of the query execution
 */
function PMA_clearTransformations($db, $table = '', $column = '')
{
    $cfgRelation = PMA_getRelationsParam();

    if (! isset($cfgRelation['column_info'])) {
        return false;
    }

    $delete_sql = 'DELETE FROM '
        . PMA\libraries\Util::backquote($cfgRelation['db']) . '.'
        . PMA\libraries\Util::backquote($cfgRelation['column_info'])
        . ' WHERE ';

    if (($column != '') && ($table != '')) {

        $delete_sql .= '`db_name` = \'' . $db . '\' AND '
            . '`table_name` = \'' . $table . '\' AND '
            . '`column_name` = \'' . $column . '\' ';

    } else if ($table != '') {

        $delete_sql .= '`db_name` = \'' . $db . '\' AND '
            . '`table_name` = \'' . $table . '\' ';

    } else {
        $delete_sql .= '`db_name` = \'' . $db . '\' ';
    }

    return $GLOBALS['dbi']->tryQuery($delete_sql);

}

