function smarty_modifier_markup($text) { static $parsers = array(); static $cacheKey = 'smarty_modifier_markup'; $stripTags = false; $args = func_get_args(); array_shift($args); foreach ($args as $arg) { if ($arg == 'strip') { $stripTags = true; } else { $markupType = $arg; } } if (!isset($markupType)) { if (!GalleryDataCache::containsKey($cacheKey)) { list($ret, $defaultMarkupType) = GalleryCoreApi::getPluginParameter('module', 'core', 'misc.markup'); if ($ret) { /* This code is used by the UI -- we can't return an error. Choose something safe */ $defaultMarkupType = 'none'; } GalleryDataCache::put($cacheKey, $defaultMarkupType); } $markupType = GalleryDataCache::get($cacheKey); } if (!isset($parsers[$markupType])) { switch ($markupType) { case 'bbcode': $parsers[$markupType] = new GalleryBbcodeMarkupParser(); break; case 'html': $parsers[$markupType] = new GalleryHtmlMarkupParser(); break; case 'none': default: $parsers[$markupType] = new GalleryNoMarkupParser(); } } $text = $parsers[$markupType]->parse($text); return $stripTags ? strip_tags($text) : $text; }
/** * Import a single user. */ static function import_user(&$queue) { $g2_user_id = array_shift($queue); if (self::map($g2_user_id)) { return t("User with id: %id already imported, skipping", array("id" => $g2_user_id)); } if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) { self::set_map($g2_user_id, user::guest()->id); return t("Skipping Anonymous User"); } $g2_admin_group_id = g2(GalleryCoreApi::getPluginParameter("module", "core", "id.adminGroup")); try { $g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id)); } catch (Exception $e) { return t("Failed to import Gallery 2 user with id: %id\n%exception", array("id" => $g2_user_id, "exception" => $e->__toString())); } $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); try { $user = user::create($g2_user->getUsername(), $g2_user->getfullname(), ""); $message = t("Created user: '******'.", array("name" => $user->name)); } catch (Exception $e) { // @todo For now we assume this is a "duplicate user" exception $user = user::lookup_by_name($g2_user->getUsername()); $message = t("Loaded existing user: '******'.", array("name" => $user->name)); } $user->hashed_password = $g2_user->getHashedPassword(); $user->email = $g2_user->getEmail(); $user->locale = $g2_user->getLanguage(); foreach ($g2_groups as $g2_group_id => $g2_group_name) { if ($g2_group_id == $g2_admin_group_id) { $user->admin = true; $message .= t("\n\tAdded 'admin' flag to user"); } else { $group = ORM::factory("group", self::map($g2_group_id)); $user->add($group); $message .= t("\n\tAdded user to group '%group'.", array("group" => $group->name)); } } $user->save(); self::set_map($g2_user->getId(), $user->id); return $message; }
/** * Import a single user. */ static function import_user(&$queue) { $messages = array(); $g2_user_id = array_shift($queue); if (self::map($g2_user_id)) { return t("User with id: %id already imported, skipping", array("id" => $g2_user_id)); } if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) { self::set_map($g2_user_id, identity::guest()->id, "group"); return t("Skipping anonymous user"); } $g2_admin_group_id = g2(GalleryCoreApi::getPluginParameter("module", "core", "id.adminGroup")); try { $g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id)); } catch (Exception $e) { throw new G2_Import_Exception(t("Failed to import Gallery 2 user with id: %id\n%exception", array("id" => $g2_user_id, "exception" => (string) $e)), $e); } $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); $user = identity::lookup_user_by_name($g2_user->getUsername()); if ($user) { $messages[] = t("Loaded existing user: '******'.", array("name" => $user->name)); } else { $email = $g2_user->getEmail(); if (empty($email) || !valid::email($email)) { $email = "*****@*****.**"; } try { $user = identity::create_user($g2_user->getUserName(), $g2_user->getFullName(), $g2_user->getHashedPassword(), $email); } catch (Exception $e) { throw new G2_Import_Exception(t("Failed to create user: '******' (id: %id)", array("name" => $g2_user->getUserName(), "id" => $g2_user_id)), $e, $messages); } if (class_exists("User_Model") && $user instanceof User_Model) { // This will work if G2's password is a PasswordHash password as well. $user->hashed_password = $g2_user->getHashedPassword(); } $messages[] = t("Created user: '******'.", array("name" => $user->name)); if ($email == "*****@*****.**") { $messages[] = t("Fixed invalid email (was '%invalid_email')", array("invalid_email" => $g2_user->getEmail())); } } $user->locale = $g2_user->getLanguage(); foreach ($g2_groups as $g2_group_id => $g2_group_name) { if ($g2_group_id == $g2_admin_group_id) { $user->admin = true; $messages[] = t("Added 'admin' flag to user"); } else { $group = identity::lookup_group(self::map($g2_group_id)); $user->add($group); $messages[] = t("Added user to group '%group'.", array("group" => $group->name)); } } try { $user->save(); self::set_map($g2_user->getId(), $user->id, "user"); } catch (Exception $e) { throw new G2_Import_Exception(t("Failed to create user: '******'", array("name" => $user->name)), $e, $messages); } return $messages; }
/** * Import a single user. */ static function import_user(&$queue) { $g2_user_id = array_shift($queue); if (self::map($g2_user_id)) { return; } if (g2(GalleryCoreApi::isAnonymousUser($g2_user_id))) { self::set_map($g2_user_id, user::guest()->id); return; } $g2_admin_group_id = g2(GalleryCoreApi::getPluginParameter("module", "core", "id.adminGroup")); try { $g2_user = g2(GalleryCoreApi::loadEntitiesById($g2_user_id)); } catch (Exception $e) { g2_import::log(t("Failed to import Gallery 2 user with id: %id", array("id" => $g2_user_id))); return; } $g2_groups = g2(GalleryCoreApi::fetchGroupsForUser($g2_user->getId())); try { $user = user::create($g2_user->getUsername(), $g2_user->getfullname(), ""); } catch (Exception $e) { // @todo For now we assume this is a "duplicate user" exception $user = user::lookup_by_name($g2_user->getUsername()); } $user->hashed_password = $g2_user->getHashedPassword(); $user->email = $g2_user->getEmail(); $user->locale = $g2_user->getLanguage(); foreach ($g2_groups as $g2_group_id => $g2_group_name) { if ($g2_group_id == $g2_admin_group_id) { $user->admin = true; } else { $user->add(ORM::factory("group", self::map($g2_group_id))); } } $user->save(); self::set_map($g2_user->getId(), $user->id); }
/** * 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; }
/** * Transfer over all the values from a G2 album to a G3 album. */ static function set_album_values($album, $g2_album) { $album->name = $g2_album->getPathComponent(); $album->title = self::_decode_html_special_chars($g2_album->getTitle()); $album->title or $album->title = $album->name; $album->description = self::_decode_html_special_chars(self::extract_description($g2_album)); $album->owner_id = self::map($g2_album->getOwnerId()); try { $album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album->getId())); } catch (Exception $e) { // @todo log $album->view_count = 0; } $album->created = $g2_album->getCreationTimestamp(); $order_map = array("originationTimestamp" => "captured", "creationTimestamp" => "created", "description" => "description", "modificationTimestamp" => "updated", "orderWeight" => "weight", "pathComponent" => "name", "summary" => "description", "title" => "title", "viewCount" => "view_count"); $direction_map = array(1 => "ASC", ORDER_ASCENDING => "ASC", ORDER_DESCENDING => "DESC"); // G2 sorts can either be <sort> or <presort>|<sort>. Right now we can't // map presorts so ignore them. $g2_order = explode("|", $g2_album->getOrderBy() . ""); $g2_order = end($g2_order); if (empty($g2_order)) { $g2_order = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderBy')); } $g2_order_direction = explode("|", $g2_album->getOrderDirection() . ""); $g2_order_direction = $g2_order_direction[0]; if (empty($g2_order_direction)) { $g2_order_direction = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderDirection')); } if (array_key_exists($g2_order, $order_map)) { $album->sort_column = $order_map[$g2_order]; $album->sort_order = $direction_map[$g2_order_direction]; } }
foreach ($lines as $lineno => $line) { echo htmlspecialchars($line) . "<br />\n"; } } else { require_once 'embed.php'; $activeUserId = $gBitUser->isRegistered() ? $gBitUser->mUserId : NULL; $status = GalleryEmbed::init(array('embedUri' => 'index.php', 'relativeG2Path' => '', 'loginRedirect' => '/users/login.php', 'activeUserId' => $activeUserId)); $gallerySessionId = GalleryEmbed::getSessionId(); //print " $status = GalleryEmbed::init( array( 'embedUri' => 'index.php', 'relativeG2Path' => '', 'loginRedirect' => '/users/login.php', 'activeUserId' => $activeUserId ))"; if ($status->isError()) { if ($status->getErrorCode() & ERROR_MISSING_OBJECT) { //vd( $gBitUser->mUserId ); //vd( $gallery->getActiveUserId() ); if ($g2User = GalleryEmbed::createUser($gBitUser->mUserId, array('username' => $gBitUser->mInfo['login'], 'email' => $gBitUser->mInfo['email'], 'fullname' => $gBitUser->mInfo['real_name'], 'creationtimestamp' => $gBitUser->mInfo['registration_date']))) { if ($gBitUser->isAdmin()) { list($ret, $adminGroupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup'); if ($ret->isError()) { return array($ret->wrap(__FILE__, __LINE__), false); } GalleryEmbed::addUserToGroup($activeUserId, 2); } //'language' => $gBitUser->mInfo['language'], //'password' => string, //'hashedpassword' => string, //'hashmethod' => string, } else { fatalError(tra($status->getAsHtml())); exit; } } }
function _GalleryMain_errorHandler($error, $g2Data = null, $initOk = true) { global $gallery; $failsafe = false; if (!$initOk) { $failsafe = true; } if (!$failsafe) { list($ret, $themeId) = GalleryCoreApi::getPluginParameter('module', 'core', 'default.theme'); if ($ret) { $failsafe = true; } } if (!$failsafe) { list($ret, $theme) = GalleryCoreApi::loadPlugin('theme', $themeId); if ($ret) { $failsafe = true; } $templateAdapter =& $gallery->getTemplateAdapter(); $templateAdapter->setTheme($theme); } if (!$failsafe) { list($ret, $view) = GalleryView::loadView('core.ErrorPage'); if ($ret) { $failsafe = true; } } if (!$failsafe) { $dummyForm = array(); GalleryCoreApi::requireOnce('modules/core/classes/GalleryTemplate.class'); $template = new GalleryTemplate(dirname(__FILE__)); $view->setError($error); list($ret, $results) = $view->loadTemplate($template, $dummyForm); if ($ret) { $failsafe = true; } $t =& $template->getVariableByReference('theme'); $t['errorTemplate'] = $results['body']; } if (!$failsafe) { $template->setVariable('l10Domain', 'modules_core'); list($ret, $templatePath) = $theme->showErrorPage($template); if ($ret) { $failsafe = true; } } if (!$failsafe) { $template->setVariable('l10Domain', 'themes_' . $themeId); $ret = $template->display("themes/{$themeId}/templates/{$templatePath}"); if ($ret) { $failsafe = true; } } if ($failsafe) { /* Some kind of catastrophic failure. Just dump the error out to the browser. */ print '<h2>Error</h2>' . $error->getAsHtml(false); if ($gallery->getDebug() == 'buffered') { print '<h3>Debug Output</h3><pre>' . $gallery->getDebugBuffer() . '</pre>'; } return; } }
/** * Import a single album. */ static function import_album(&$queue) { // The queue is a set of nested associative arrays where the key is the album id and the // value is an array of similar arrays. We'll do a breadth first tree traversal using the // queue to keep our state. Doing it breadth first means that the parent will be created by // the time we get to the child. // 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; } if (self::map($g2_album_id)) { return; } try { // Load the G2 album item, and figure out its parent in G3. $g2_album = g2(GalleryCoreApi::loadEntitiesById($g2_album_id)); } catch (Exception $e) { return t("Failed to load Gallery 2 album with id: %id\n%exception", array("id" => $g2_album_id, "exception" => (string) $e)); } if ($g2_album->getParentId() == null) { $album = item::root(); } else { $parent_album = ORM::factory("item", self::map($g2_album->getParentId())); $album = ORM::factory("item"); $album->type = "album"; $album->parent_id = self::map($g2_album->getParentId()); $album->name = $g2_album->getPathComponent(); $album->title = self::_decode_html_special_chars($g2_album->getTitle()); $album->title or $album->title = $album->name; $album->description = self::_decode_html_special_chars(self::extract_description($g2_album)); $album->owner_id = self::map($g2_album->getOwnerId()); try { $album->view_count = (int) g2(GalleryCoreApi::fetchItemViewCount($g2_album_id)); } catch (Exception $e) { // @todo log $album->view_count = 0; } $album->created = $g2_album->getCreationTimestamp(); $order_map = array("originationTimestamp" => "captured", "creationTimestamp" => "created", "description" => "description", "modificationTimestamp" => "updated", "orderWeight" => "weight", "pathComponent" => "name", "summary" => "description", "title" => "title", "viewCount" => "view_count"); $direction_map = array(1 => "ASC", ORDER_ASCENDING => "ASC", ORDER_DESCENDING => "DESC"); // Only consider G2's first sort order $g2_order = explode("|", $g2_album->getOrderBy() . ""); $g2_order = $g2_order[0]; if (empty($g2_order)) { $g2_order = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderBy')); } $g2_order_direction = explode("|", $g2_album->getOrderDirection() . ""); $g2_order_direction = $g2_order_direction[0]; if (empty($g2_order_direction)) { $g2_order_direction = g2(GalleryCoreApi::getPluginParameter('module', 'core', 'default.orderDirection')); } if (array_key_exists($g2_order, $order_map)) { $album->sort_column = $order_map[$g2_order]; $album->sort_order = $direction_map[$g2_order_direction]; } try { $album->save(); } catch (Exception $e) { throw new G2_Import_Exception(t("Failed to import Gallery 2 album with id %id and name %name.", array("id" => $g2_album_id, "name" => $album->name)), $e); } self::import_keywords_as_tags($g2_album->getKeywords(), $album); } self::set_map($g2_album_id, $album->id, "album", self::g2_url(array("view" => "core.ShowItem", "itemId" => $g2_album->getId()))); self::_import_permissions($g2_album, $album); }
/** * Find admin user and set as active user * @param bool $fallback (optional) whether we should try to fall back if the * API to load the admin user object fails * @return GalleryStatus a status code */ function selectAdminUser($fallback = false) { global $gallery; list($ret, $siteAdminGroupId) = GalleryCoreApi::getPluginParameter('module', 'core', 'id.adminGroup'); if ($ret) { return $ret; } list($ret, $adminUserInfo) = GalleryCoreApi::fetchUsersForGroup($siteAdminGroupId, 1); if ($ret) { return $ret; } if (empty($adminUserInfo)) { return GalleryCoreApi::error(ERROR_MISSING_VALUE); } /* Fetch the first admin from list */ list($userId, $userName) = each($adminUserInfo); list($ret, $adminUser) = GalleryCoreApi::loadEntitiesById($userId, 'GalleryUser'); if ($ret) { if ($fallback) { /* Initialize a GalleryUser with the id of a real admin */ $gallery->debug('Unable to load admin user. Using in-memory user object as fallback'); GalleryCoreApi::requireOnce('modules/core/classes/GalleryUser.class'); $adminUser = new GalleryUser(); $adminUser->setId((int) $userId); $adminUser->setUserName($userName); } else { return $ret; } } $gallery->setActiveUser($adminUser); $session =& $gallery->getSession(); $session->put('isUpgrade', true); return null; }