예제 #1
0
 public function redimensionner_image($image_src, $image_dest, $largeur, $hauteur)
 {
     if (!class_exists('imageTransform')) {
         require_once 'tools/attach/libs/class.imagetransform.php';
     }
     $imgTrans = new imageTransform();
     $imgTrans->sourceFile = $image_src;
     $imgTrans->targetFile = $image_dest;
     $imgTrans->resizeToWidth = $largeur;
     $imgTrans->resizeToHeight = $hauteur;
     if (!$imgTrans->resize()) {
         // in case of error, show error code
         return $imgTrans->error;
         // if there were no errors
     } else {
         return $imgTrans->targetFile;
     }
 }
예제 #2
0
 /**
  *  Resize Image
  *
  *  @param  string   $sourceFile           Source image file
  *  @param  string   $targetFile           Target image file
  *  @param  integer  $width                Image width
  *  @param  integer  $height               Image height
  *  @param  boolean  $resizeIfSmaller      Resize if image size smaller
  *  @param  boolean  $maintainAspectRatio  Maintain aspect ration of image
  *  @param  boolean  $fixedResize          Fixed resize (crop if needed)
  *
  *  return  boolean  True if resized, False if not resized
  *
  */
 public function ResizeImage($sourceFile, $targetFile, $width, $height, $resizeIfSmaller = false, $maintainAspectRatio = true, $fixedResize = false)
 {
     global $rootPath;
     require_once $rootPath . INC_IMAGETRANSFORM . "class.imagetransform.php";
     $imgTransformer = new imageTransform();
     $imgTransformer->jpegOutputQuality = 90;
     $imgTransformer->sourceFile = $sourceFile;
     $imgTransformer->targetFile = $targetFile;
     $imgTransformer->resizeIfSmaller = $resizeIfSmaller;
     $imgTransformer->maintainAspectRatio = $maintainAspectRatio;
     if ($fixedResize && $maintainAspectRatio) {
         $imgTransformer->readSourceImageSize();
         $relativePercent = $height * 100 / $width;
         $correctHeight = floor($imgTransformer->sourceImageWidth / 100 * $relativePercent);
         if (abs($imgTransformer->sourceImageHeight - $correctHeight) > 1 && $imgTransformer->sourceImageHeight > $correctHeight) {
             $imgTransformer->resizeToWidth = $width;
             $imgTransformer->resize();
             $imgTransformer->readTargetImageSize();
             $imgTransformer->sourceFile = $targetFile;
             $imgTransformer->crop(0, round(($imgTransformer->targetImageHeight - $height) / 2), $width, $height + round(($imgTransformer->targetImageHeight - $height) / 2));
         } elseif (abs($imgTransformer->sourceImageHeight - $correctHeight) > 1 && $imgTransformer->sourceImageHeight < $correctHeight) {
             $imgTransformer->resizeToHeight = $height;
             $imgTransformer->resize();
             $imgTransformer->readTargetImageSize();
             $imgTransformer->sourceFile = $targetFile;
             $imgTransformer->crop(round(($imgTransformer->targetImageWidth - $width) / 2), 0, $width + round(($imgTransformer->targetImageWidth - $width) / 2), $height);
         } else {
             $imgTransformer->resizeToWidth = $width;
             $imgTransformer->resizeToHeight = $height;
             $imgTransformer->resize();
         }
     } else {
         $imgTransformer->resizeToWidth = $width;
         $imgTransformer->resizeToHeight = $height;
         $imgTransformer->resize();
     }
     if ($imgTransformer->error != "") {
         $this->SetError($imgTransformer->error, __FILE__, __LINE__);
         return false;
     } else {
         return true;
     }
 }
function show_form_theme_selector($mode = 'selector', $formclass = 'form-horizontal')
{
    // en mode edition on recupere aussi les images de fond
    if ($mode == 'edit') {
        $id = 'form_graphical_options';
        // recuperation des images de fond
        $backgroundsdir = 'files/backgrounds';
        $dir = is_dir($backgroundsdir) ? opendir($backgroundsdir) : false;
        while ($dir && ($file = readdir($dir)) !== false) {
            $imgextension = strtolower(substr($file, -4, 4));
            // les jpg sont les fonds d'ecrans, ils doivent etre mis en miniature
            if ($imgextension == '.jpg') {
                if (!is_file($backgroundsdir . '/thumbs/' . $file)) {
                    require_once 'tools/attach/libs/class.imagetransform.php';
                    $imgTrans = new imageTransform();
                    $imgTrans->sourceFile = $backgroundsdir . '/' . $file;
                    $imgTrans->targetFile = $backgroundsdir . '/thumbs/' . $file;
                    $imgTrans->resizeToWidth = 100;
                    $imgTrans->resizeToHeight = 75;
                    if ($imgTrans->resize()) {
                        $backgrounds[] = $imgTrans->targetFile;
                    }
                } else {
                    $backgrounds[] = $backgroundsdir . '/thumbs/' . $file;
                }
            } elseif ($imgextension == '.png') {
                $backgrounds[] = $backgroundsdir . '/' . $file;
            }
        }
        if ($dir) {
            closedir($dir);
        }
        $bgselector = '';
        if (isset($backgrounds) && is_array($backgrounds)) {
            $bgselector .= '<h3>' . _t('TEMPLATE_BG_IMAGE') . '</h3>
            <div id="bgCarousel" class="carousel" data-interval="5000" data-pause="true">
        <!-- Carousel items -->
        <div class="carousel-inner">' . "\n";
            $nb = 0;
            $thumbs_per_slide = 8;
            $firstitem = true;
            sort($backgrounds);
            foreach ($backgrounds as $background) {
                $nb++;
                if ($nb == 1) {
                    $bgselectorlist = '';
                    $class = '';
                }
                // dans le cas ou il n'y a pas d'image de fond selectionnee on bloque la premiere diapo
                if ($GLOBALS['wiki']->config['favorite_background_image'] == '' && $firstitem) {
                    $class = ' active';
                    $firstitem = false;
                }
                $choosen = $background == 'files/backgrounds/' . $GLOBALS['wiki']->config['favorite_background_image'];
                if ($choosen) {
                    $class = ' active';
                }
                $imgextension = strtolower(substr($background, -4, 4));
                if ($imgextension == '.jpg') {
                    $bgselectorlist .= '<img class="bgimg' . ($choosen ? ' choosen' : '') . '" src="' . $background . '" width="100" height="75" />' . "\n";
                } elseif ($imgextension == '.png') {
                    $bgselectorlist .= '<div class="mozaicimg' . ($choosen ? ' choosen' : '') . '" style="background:url(' . $background . ') repeat top left;"></div>' . "\n";
                }
                // on finit la diapositive
                if ($nb == $thumbs_per_slide) {
                    $nb = 0;
                    $bgselector .= '<div class="item' . $class . '">' . "\n" . $bgselectorlist . '</div>' . "\n";
                }
            }
            // si la boucle se termine et qu'on ne vient pas de finir une diapositive
            if ($nb != 0) {
                $bgselector .= '<div class="item' . $class . '">' . "\n" . $bgselectorlist . '</div>' . "\n";
            }
            $bgselector .= '</div>
        <!-- Carousel nav -->
        <a class="carousel-control left" href="#bgCarousel" data-slide="prev">&lsaquo;</a>
        <a class="carousel-control right" href="#bgCarousel" data-slide="next">&rsaquo;</a>
        </div>' . "\n";
        }
    } else {
        $id = 'form_theme_selector';
        $bgselector = '';
    }
    $selecteur = '      <form class="' . $formclass . '" id="' . $id . '">' . "\n";
    //on cherche tous les dossiers du repertoire themes et des sous dossier styles et squelettes, et on les range dans le tableau $wakkaConfig['templates']
    $repertoire_initial = 'tools' . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . 'themes';
    $GLOBALS['wiki']->config['templates'] = search_template_files($repertoire_initial);
    //s'il y a un repertoire themes a la racine, on va aussi chercher les templates dedans
    if (is_dir('themes')) {
        $repertoire_racine = 'themes';
        $GLOBALS['wiki']->config['templates'] = array_merge($GLOBALS['wiki']->config['templates'], search_template_files($repertoire_racine));
        if (is_array($GLOBALS['wiki']->config['templates'])) {
            ksort($GLOBALS['wiki']->config['templates']);
        }
    }
    $selecteur .= '         <div class="control-group form-group">' . "\n" . '               <label class="control-label col-lg-4">' . _t('TEMPLATE_THEME') . '</label>' . "\n" . '               <div class="controls col-lg-7">' . "\n" . '                   <select class="form-control" id="changetheme" name="theme">' . "\n";
    foreach (array_keys($GLOBALS['wiki']->config['templates']) as $key => $value) {
        if ($value !== $GLOBALS['wiki']->config['favorite_theme']) {
            $selecteur .= '                     <option value="' . $value . '">' . $value . '</option>' . "\n";
        } else {
            $selecteur .= '                     <option value="' . $value . '" selected="selected">' . $value . '</option>' . "\n";
        }
    }
    $selecteur .= '                 </select>' . "\n" . '               </div>' . "\n" . '          </div>' . "\n";
    $selecteur .= '           <div class="control-group form-group">' . "\n" . '               <label class="control-label col-lg-4">' . _t('TEMPLATE_SQUELETTE') . '</label>' . "\n" . '               <div class="controls col-lg-7">' . "\n" . '                   <select class="form-control" id="changesquelette" name="squelette">' . "\n";
    ksort($GLOBALS['wiki']->config['templates'][$GLOBALS['wiki']->config['favorite_theme']]['squelette']);
    foreach ($GLOBALS['wiki']->config['templates'][$GLOBALS['wiki']->config['favorite_theme']]['squelette'] as $key => $value) {
        if ($value !== $GLOBALS['wiki']->config['favorite_squelette']) {
            $selecteur .= '                     <option value="' . $key . '">' . $value . '</option>' . "\n";
        } else {
            $selecteur .= '                     <option value="' . $GLOBALS['wiki']->config['favorite_squelette'] . '" selected="selected">' . $value . '</option>' . "\n";
        }
    }
    $selecteur .= '                 </select>' . "\n" . '               </div>' . "\n" . '          </div>' . "\n";
    ksort($GLOBALS['wiki']->config['templates'][$GLOBALS['wiki']->config['favorite_theme']]['style']);
    $selecteur .= '           <div class="control-group form-group">' . "\n" . '               <label class="control-label col-lg-4">' . _t('TEMPLATE_STYLE') . '</label>' . "\n" . '               <div class="controls col-lg-7">' . "\n" . '                   <select class="form-control" id="changestyle" name="style">' . "\n";
    foreach ($GLOBALS['wiki']->config['templates'][$GLOBALS['wiki']->config['favorite_theme']]['style'] as $key => $value) {
        if ($value !== $GLOBALS['wiki']->config['favorite_style']) {
            $selecteur .= '                     <option value="' . $key . '">' . $value . '</option>' . "\n";
        } else {
            $selecteur .= '                     <option value="' . $GLOBALS['wiki']->config['favorite_style'] . '" selected="selected">' . $value . '</option>' . "\n";
        }
    }
    $selecteur .= '                   </select>' . "\n" . '               </div>' . "\n" . '              </div>' . "\n" . $bgselector . "\n";
    if ($mode == 'edit') {
        $selecteur .= '
            <div class="panel-group accordion" id="accordion-avanced-page-settings">
                <div class="panel panel-default accordion-group">
                    <div class="panel-heading accordion-heading">
                      <h4 class="panel-title accordion-trigger" data-parent="#accordion-avanced-page-settings" href="#avanced-page-settings" data-target="#avanced-page-settings" data-toggle="collapse" title="' . _t('SEE_THE_ADVANCED_PARAMETERS') . '">' . _t('ADVANCED_PARAMETERS') . '</h4>
                    </div>
                    <div id="avanced-page-settings" class="panel-collapse accordion-body collapse">
                        <div class="panel-body accordion-inner">
                            <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('PAGE_LANGUAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <select class="form-control" name="lang">' . "\n";
        // choice of language
        foreach ($GLOBALS['available_languages'] as $value) {
            $selecteur .= "                                <option value=\"" . $value . "\"" . ($value == $GLOBALS['prefered_language'] ? ' selected="selected"' : '') . ">" . ucfirst(htmlentities($GLOBALS['languages_list'][$value]['nativeName'], ENT_COMPAT | ENT_HTML401, 'UTF-8')) . "</option>\n";
        }
        $selecteur .= '                             </select>
                            </div>
                        </div>' . "\n";
        $tablistWikinames = $GLOBALS['wiki']->LoadAll('SELECT DISTINCT tag FROM ' . $GLOBALS['wiki']->GetConfigValue('table_prefix') . 'pages WHERE latest="Y"');
        foreach ($tablistWikinames as $tag) {
            $listWikinames[] = $tag['tag'];
        }
        $listWikinames = '["' . implode('","', $listWikinames) . '"]';
        $selecteur .= '         <fieldset>
                            <legend>' . _t('CHOOSE_PAGE_FOR') . ' : </legend>
                            <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('HORIZONTAL_MENU_PAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <input class="form-control" type="text" autocomplete="off" name="PageMenuHaut" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageMenuHaut']) ? $GLOBALS['wiki']->page["metadatas"]['PageMenuHaut'] : 'PageMenuHaut') . '" />
                                </div>
                            </div>' . "\n";
        $selecteur .= '
                            <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('FAST_ACCESS_RIGHT_PAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <input class="form-control" type="text" autocomplete="off" name="PageRapideHaut" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageRapideHaut']) ? $GLOBALS['wiki']->page["metadatas"]['PageRapideHaut'] : 'PageRapideHaut') . '" />
                                </div>
                            </div>' . "\n";
        $selecteur .= '
                            <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('HEADER_PAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <input class="form-control" type="text" autocomplete="off" name="PageHeader" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageHeader']) ? $GLOBALS['wiki']->page["metadatas"]['PageHeader'] : 'PageHeader') . '" />
                                </div>
                            </div>' . "\n";
        $selecteur .= '
                            <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('FOOTER_PAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <input class="form-control" type="text" autocomplete="off" name="PageFooter" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageFooter']) ? $GLOBALS['wiki']->page["metadatas"]['PageFooter'] : 'PageFooter') . '" />
                                </div>
                            </div>' . "\n";
        $selecteur .= '         <div class="control-group form-group">
                                <label class="control-label col-lg-4">' . _t('VERTICAL_MENU_PAGE') . '</label>
                                <div class="controls col-lg-7">
                                    <input class="form-control" type="text" autocomplete="off" name="PageMenu" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageMenu']) ? $GLOBALS['wiki']->page["metadatas"]['PageMenu'] : 'PageMenu') . '" />
                                </div>
                            </div>' . "\n";
        $selecteur .= '
                <div class="control-group form-group">
                    <label class="control-label col-lg-4">' . _t('RIGHT_COLUMN_PAGE') . '</label>
                    <div class="controls col-lg-7">
                        <input class="form-control" type="text" autocomplete="off" name="PageColonneDroite" data-provide="typeahead" data-items="5" data-source=\'' . $listWikinames . '\' value="' . (isset($GLOBALS['wiki']->page["metadatas"]['PageColonneDroite']) ? $GLOBALS['wiki']->page["metadatas"]['PageColonneDroite'] : 'PageColonneDroite') . '" />
                    </div>
                </div>' . "\n" . '</fieldset>
            </div>
        </div>
    </div>
</div> <!-- /#avanced-page-settings -->';
    }
    $selecteur .= '</form>' . "\n";
    $GLOBALS['js'] = (isset($GLOBALS['js']) ? $GLOBALS['js'] : '') . add_templates_list_js() . "\n";
    return $selecteur;
}
예제 #4
0
     } else {
         print json_encode(array('success' => false, 'message' => 'Error: No image specified'));
     }
     exit;
     break;
 case "resize_image":
     if ($_POST['image']) {
         // Make sure we are editing our temp image, and not the original
         $temp_image = str_replace(basename($_POST['image']), '_fm_' . basename($_POST['image']), $_POST['image']);
         $image = new imageTransform();
         $image->jpegOutputQuality = 80;
         $image->sourceFile = DIRECTORY . $temp_image;
         $image->targetFile = DIRECTORY . $temp_image;
         $image->resizeToWidth = $_POST['resize_width'];
         $image->resizeToHeight = $_POST['resize_height'];
         if ($image->resize()) {
             print json_encode(array('success' => true, 'message' => 'Image successfully resized'));
         } else {
             print json_encode(array('success' => false, 'message' => 'Error: Could not resize image'));
         }
     } else {
         print json_encode(array('success' => false, 'message' => 'Error: No image specified'));
     }
     exit;
     break;
 case "rotate_image":
     if ($_POST['image']) {
         // Make sure we are editing our temp image, and not the original
         $temp_image = str_replace(basename($_POST['image']), '_fm_' . basename($_POST['image']), $_POST['image']);
         $image = new imageTransform();
         $image->jpegOutputQuality = 80;