/**
 * Smarty truncate modifier plugin.  This differs from the standard Smarty plugin
 * in that it respects HTML entities and doesn't split them.
 *
 * Type:     modifier<br>
 * Name:     entitytruncate<br>
 * Purpose:  Truncate a string to a certain length if necessary,
 *           optionally splitting in the middle of a word, and
 *           appending the $etc string.  Won't split an HTML entity.
 *
 * @param string the input string
 * @param integer what to truncate it to (max length upon return)
 * @param string what to use to indicate that there was more (default: "...")
 * @param boolean break words or not?
 * @return string
 */
function smarty_modifier_entitytruncate($string, $length, $etc = '...', $breakWords = false)
{
    if (empty($string)) {
        return '';
    }
    /*
     * Convert multibyte characters to html entities and then get an entity-safe substring.
     * Split the string exactly on the boundary.  If there's no change, then we're done.
     */
    $string = GalleryUtilities::utf8ToUnicodeEntities($string);
    list($tmp, $piece) = GalleryUtilities::entitySubstr($string, 0, $length);
    if ($piece == $string) {
        return GalleryUtilities::unicodeEntitiesToUtf8($piece);
    }
    $etcLength = strlen($etc);
    if ($etcLength < $length) {
        /* Make room for the $etc string */
        list($tmp, $piece) = GalleryUtilities::entitySubstr($piece, 0, $length - $etcLength);
        $pieceLength = strlen($piece);
        if (!$breakWords && $string[$pieceLength - 1] != ' ' && $string[$pieceLength] != ' ') {
            /* We split a word, and we're not allowed to.  Try to back up to the last space */
            $splitIndex = strrpos($piece, ' ');
            if ($splitIndex > 0) {
                /* Found a space, truncate there. */
                $piece = substr($piece, 0, $splitIndex);
            }
        }
        $piece .= $etc;
    }
    /* Unicode entities back to UTF-8; may convert entities in original string, but that's ok */
    return GalleryUtilities::unicodeEntitiesToUtf8($piece);
}
Exemple #2
0
 /**
  * Set the highlight properly for a single album
  */
 static function set_album_highlight(&$queue)
 {
     // Dequeue the current album and enqueue its children
     list($g2_album_id, $children) = each($queue);
     unset($queue[$g2_album_id]);
     foreach ($children as $key => $value) {
         $queue[$key] = $value;
     }
     $g3_album_id = self::map($g2_album_id);
     if (!$g3_album_id) {
         return t("Album with id: %id not imported", array("id" => $g3_album_id));
     }
     $table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id)));
     if (isset($table[$g2_album_id])) {
         // Backtrack the source id to an item
         $g2_source = $table[$g2_album_id];
         while (GalleryUtilities::isA($g2_source, "GalleryDerivative")) {
             $g2_source = g2(GalleryCoreApi::loadEntitiesById($g2_source->getDerivativeSourceId()));
         }
         $item_id = self::map($g2_source->getId());
         if ($item_id) {
             $item = ORM::factory("item", $item_id);
             $g2_album = ORM::factory("item", $g3_album_id);
             $g2_album->album_cover_item_id = $item->id;
             $g2_album->thumb_dirty = 1;
             $g2_album->view_count = g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
             $g2_album->save();
             graphics::generate($g2_album);
         }
     }
 }
Exemple #3
0
 function parse($text)
 {
     return GalleryUtilities::htmlEntityDecode($text);
 }
Exemple #4
0
/**
 * Get all of the options set in $_REQUEST and/or $_SESSION
 */
function g2ic_get_request_and_session_options()
{
    global $g2ic_options;
    // Get the root album
    // Check for G2 Core API >= 7.5.  getDefaultAlbumId only available at 7.5 or above
    if (GalleryUtilities::isCompatibleWithApi(array(7, 5), GalleryCoreApi::getApiVersion())) {
        list($error, $g2ic_options['root_album']) = GalleryCoreApi::getDefaultAlbumId();
    } else {
        list($error, $g2ic_options['root_album']) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.rootAlbum');
    }
    g2ic_magic_quotes_remove($_REQUEST);
    // Is this a TinyMCE window?
    if (isset($_REQUEST['g2ic_tinymce'])) {
        $g2ic_options['tinymce'] = $_REQUEST['g2ic_tinymce'];
        $_SESSION['g2ic_tinymce'] = $_REQUEST['g2ic_tinymce'];
    } else {
        if (isset($_SESSION['g2ic_tinymce'])) {
            $g2ic_options['tinymce'] = $_SESSION['g2ic_tinymce'];
        } else {
            $g2ic_options['tinymce'] = 0;
        }
    }
    // Get the form name (if set) for insertion (not TinyMCE or FCKEditor)
    if (isset($_REQUEST['g2ic_form'])) {
        $g2ic_options['form'] = $_REQUEST['g2ic_form'];
        $_SESSION['g2ic_form'] = $_REQUEST['g2ic_form'];
    } else {
        if (isset($_SESSION['g2ic_form'])) {
            $g2ic_options['form'] = $_SESSION['g2ic_form'];
        } else {
            $g2ic_options['form'] = '';
        }
    }
    // Get the field name (if set) for insertion (not TinyMCE or FCKEditor)
    if (isset($_REQUEST['g2ic_field'])) {
        $g2ic_options['field'] = $_REQUEST['g2ic_field'];
        $_SESSION['g2ic_field'] = $_REQUEST['g2ic_field'];
    } else {
        if (isset($_SESSION['g2ic_field'])) {
            $g2ic_options['field'] = $_SESSION['g2ic_field'];
        } else {
            $g2ic_options['field'] = '';
        }
    }
    // Get the last album visited
    if (isset($_SESSION['g2ic_last_album_visited'])) {
        $g2ic_options['last_album'] = $_SESSION['g2ic_last_album_visited'];
    } else {
        $g2ic_options['last_album'] = $g2ic_options['root_album'];
    }
    // Get the current album
    if (isset($_REQUEST['current_album'])) {
        $g2ic_options['current_album'] = $_REQUEST['current_album'];
    } else {
        $g2ic_options['current_album'] = $g2ic_options['last_album'];
    }
    // Get the current page
    if (isset($_REQUEST['g2ic_page']) and is_numeric($_REQUEST['g2ic_page'])) {
        $g2ic_options['current_page'] = floor($_REQUEST['g2ic_page']);
    } else {
        $g2ic_options['current_page'] = 1;
    }
    // Get the current sort method
    if (isset($_REQUEST['sortby'])) {
        $g2ic_options['sortby'] = $_REQUEST['sortby'];
    }
    // Determine whether to display the titles or keep them hidden
    if (isset($_REQUEST['display'])) {
        if ($_REQUEST['display'] == 'filenames') {
            $g2ic_options['display_filenames'] = TRUE;
        }
    }
    // Determine how many images to display per page
    if (isset($_REQUEST['images_per_page'])) {
        $g2ic_options['images_per_page'] = $_REQUEST['images_per_page'];
    }
    return;
}
Exemple #5
0
 /**
  * Set the highlight properly for a single album
  */
 static function set_album_highlight(&$queue)
 {
     // Dequeue the current album and enqueue its children
     list($g2_album_id, $children) = each($queue);
     unset($queue[$g2_album_id]);
     if (!empty($children)) {
         foreach ($children as $key => $value) {
             $queue[$key] = $value;
         }
     }
     $messages = array();
     $g3_album_id = self::map($g2_album_id);
     if (!$g3_album_id) {
         return t("Album with id: %id not imported", array("id" => $g3_album_id));
     }
     $table = g2(GalleryCoreApi::fetchThumbnailsByItemIds(array($g2_album_id)));
     if (isset($table[$g2_album_id])) {
         // Backtrack the source id to an item
         $orig_g2_source = $g2_source = $table[$g2_album_id];
         while (GalleryUtilities::isA($g2_source, "GalleryDerivative")) {
             $g2_source = g2(GalleryCoreApi::loadEntitiesById($g2_source->getDerivativeSourceId()));
         }
         $item_id = self::map($g2_source->getId());
         if ($item_id) {
             $item = ORM::factory("item", $item_id);
             $g3_album = ORM::factory("item", $g3_album_id);
             $g3_album->album_cover_item_id = $item->id;
             $g3_album->thumb_dirty = 1;
             try {
                 $g3_album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id));
             } catch (Exception $e) {
                 $g3_album->view_count = 0;
             }
             try {
                 $g3_album->save();
                 graphics::generate($g3_album);
             } catch (Exception $e) {
                 return (string) new G2_Import_Exception(t("Failed to generate an album highlight for album '%name'.", array("name" => $g3_album->name)), $e);
             }
             self::set_map($orig_g2_source->getId(), $g3_album->id, "thumbnail", self::g2_url(array("view" => "core.DownloadItem", "itemId" => $orig_g2_source->getId())));
         }
     }
 }
Exemple #6
0
function _GalleryMain_doRedirect($redirectUrl, $template = null, $controller = null)
{
    global $gallery;
    /* Create a valid sessionId for guests, if required */
    $session =& $gallery->getSession();
    $ret = $session->start();
    if ($ret) {
        return array($ret->wrap(__FILE__, __LINE__), null);
    }
    $redirectUrl = $session->replaceTempSessionIdIfNecessary($redirectUrl);
    $session->doNotUseTempId();
    /*
     * UserLogin returnUrls don't have a sessionId in the URL to replace, make sure
     * there's a sessionId in the redirectUrl for users that don't use cookies
     */
    if (!$session->isUsingCookies() && $session->isPersistent() && strpos($redirectUrl, $session->getKey()) === false) {
        $redirectUrl = GalleryUrlGenerator::appendParamsToUrl($redirectUrl, array($session->getKey() => $session->getId()));
    }
    if ($gallery->getDebug() == false || $gallery->getDebug() == 'logged') {
        /*
         * The URL generator makes HTML 4.01 compliant URLs using
         * &amp; but we don't want those in our Location: header.
         */
        $redirectUrl = str_replace('&amp;', '&', $redirectUrl);
        $redirectUrl = rtrim($redirectUrl, '&? ');
        /*
         * IIS 3.0 - 5.0 webservers will ignore all other headers if the location header is set.
         * It will simply not send other headers, e.g. the set-cookie header, which is important
         * for us in the login and logout requests / redirects.
         * see: http://support.microsoft.com/kb/q176113/
         * Our solution: detect IIS version and append GALLERYSID to the Location URL if necessary
         */
        if (in_array($controller, array('core.Logout', 'core.UserLogin', 'publishxp.Login'))) {
            /* Check if it's IIS and if the version is < 6.0 */
            $webserver = GalleryUtilities::getServerVar('SERVER_SOFTWARE');
            if (!empty($webserver) && preg_match('|^Microsoft-IIS/(\\d)\\.\\d$|', trim($webserver), $matches) && $matches[1] < 6) {
                /*
                 * It is IIS and it's a version with this bug, check if GALLERYSID is already in
                 * the URL, else append it
                 */
                $session =& $gallery->getSession();
                $sessionParamString = GalleryUtilities::prefixFormVariable(urlencode($session->getKey())) . '=' . urlencode($session->getId());
                if ($session->isPersistent() && !strstr($redirectUrl, $sessionParamString)) {
                    $redirectUrl .= strpos($redirectUrl, '?') === false ? '?' : '&';
                    $redirectUrl .= $sessionParamString;
                }
            }
        }
        /* Use our PHP VM for testability */
        $phpVm = $gallery->getPhpVm();
        $phpVm->header("Location: {$redirectUrl}");
        return array('isDone' => true);
    } else {
        return array('isDone' => true, 'redirectUrl' => $redirectUrl, 'template' => $template);
    }
}
Exemple #7
0
/*
 * Simplify finding the path to embed.php by sending it as a HTTP header
 * Idea:
 *   In your integration setup you need to find out
 *     - the filesystem path for embed.php
 *     - the g2Uri and the embedUri.
 * You can get the embed.php path with your g2Uri by fetching 
 * http://example.com/gallery2/embed.php?getEmbedPath=1 via fsockopen.
 */
$getEmbedPath = GalleryUtilities::getRequestVariablesNoPrefix('getEmbedPath');
if (!empty($getEmbedPath)) {
    if (!headers_sent()) {
        /*
         * Don't use GalleryUtilities::getRemoteHostAddress() 
         * since it checks headers that can be forged easily too
         */
        $remotehost = GalleryUtilities::getServerVar('REMOTE_ADDR');
        $remotehost = !empty($remotehost) ? gethostbyname($remotehost) : '';
        $localhost = GalleryUtilities::getServerVar('HTTP_HOST');
        $localhost = !empty($localhost) ? gethostbyname($localhost) : '127.0.0.1';
        if (!empty($remotehost) && $remotehost == $localhost) {
            if (defined('GALLERY_CONFIG_DIR')) {
                /* GALLERY_CONFIG_DIR is multisite-aware */
                header('X-G2-EMBED-PATH: ' . GALLERY_CONFIG_DIR . '/embed.php');
            } else {
                /* Fallback if G2 isn't installed yet */
                header('X-G2-EMBED-PATH: ' . __FILE__);
            }
        }
    }
}
Exemple #8
0
function getBaseUrl()
{
    /* Can't use GalleryUrlGenerator::makeUrl since it's an object method */
    if (!($hostName = GalleryUtilities::getServerVar('HTTP_X_FORWARDED_HOST'))) {
        $hostName = GalleryUtilities::getServerVar('HTTP_HOST');
    }
    $protocol = GalleryUtilities::getServerVar('HTTPS') == 'on' ? 'https' : 'http';
    return sprintf('%s://%s', $protocol, $hostName);
}
Exemple #9
0
$status = array();
$ret = null;
/* The permission bit sets that we accept / handle. */
$permissionBitSets = getPermissionSets();
/* Gather a complete list of plugins in this installation. */
$plugins = getPluginList();
/* Process inputs and set some variables to default values */
$path = getRequestVariable('path');
if (empty($path)) {
    $path = getGalleryStoragePath();
} else {
    /*
     * $path is used in a chmod() call and we output the path in the HTML.
     * Just do some very basic sanitation.
     */
    GalleryUtilities::sanitizeInputValues($path);
}
/* Some basic sanitation */
$path = str_replace('..', '', $path);
if (!file_exists($path)) {
    /* TODO: add open_basedir check */
    $status['error'][] = "Folder or file '{$path}' does not exist!";
}
/* Permissions (format e.g. 755644, split after 3 characters to get 755 and 644)*/
$permissions = (string) getRequestVariable('permissions');
if (empty($permissions)) {
    $permissions = $DEFAULT_FOLDER_PERMISSIONS->getAsString() . $DEFAULT_FILE_PERMISSIONS->getAsString();
}
if (strlen($permissions) != 6) {
    $status['error'][] = "Unknown permissions '{$permissions}'! Aborting action and resetting permissions.";
}
Exemple #10
0
 function parse($text)
 {
     /* http://bugs.php.net/bug.php?id=22014 - TODO: remove empty check when min php is 4.3.2+ */
     return empty($text) ? $text : GalleryUtilities::htmlSafe(html_entity_decode($text));
 }
Exemple #11
0
if ($ret) {
    $templateData['errors'][] = $ret->getAsHtml();
} else {
    $platform =& $gallery->getPlatform();
    $storage =& $gallery->getStorage();
    $templateData['warnings'] = array();
    if (isset($_REQUEST['importDatabase'])) {
        $importFile = $_REQUEST['importFile'];
        /* Sanitize the input */
        GalleryUtilities::sanitizeInputValues($importFile);
        if (!$platform->file_exists($importFile)) {
            return GalleryCoreApi::error(ERROR_BAD_PARAMETER, null, null, 'The file "' . $importFile . '" does not exist.');
        }
        $verifiedFile = $_REQUEST['verifiedFile'];
        /* Sanitize the input */
        GalleryUtilities::sanitizeInputValues($verifiedFile);
        $doImportFlag = true;
        if ($verifiedFile != $importFile) {
            $templateData['verifiedFile'] = $importFile;
            $verifiedFile = $importFile;
            $doImportFlag = verifyVersions($templateData, $importFile);
        }
        if ($doImportFlag) {
            $template->renderHeader(true);
            $template->renderStatusMessage('Restoring Gallery Database', '', 0);
            /* Do the database import */
            $importer = $storage->getDatabaseImporter();
            list($ret, $errors) = $importer->importToDb($verifiedFile, 'importProgressCallback');
            if ($ret) {
                $templateData['errors'][] = $ret->getAsHtml();
            } else {