/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); if (!$g3_item->loaded()) { return; } try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => (string) $e)); } foreach ($tag_names as $tag_name) { tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { if (!module::is_active("tag")) { return t("Gallery 3 tag module is inactive, no tags will be imported"); } GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { return t("Failed to import Gallery 2 tags for item with id: %id\n%exception", array("id" => $g2_item_id, "exception" => $e->__toString())); } $tags = ""; // Multiword tags have the space changed to dots.s foreach ($tag_names as $tag_name) { $tags .= (strlen($tags) ? ", " : "") . tag::add($g3_item, preg_replace('/\\s+/', '.', $tag_name)); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
function GalleryBbcodeMarkupParser() { GalleryCoreApi::requireOnce('lib/bbcode/bbcode.class'); $this->_bbcode = new GalleryBbcode(); /* Convert line breaks everywhere */ $this->_bbcode->addParser(array($this, 'convertLineBreaks'), array('block', 'inline', 'link', 'listitem', 'list')); /* * Escape all characters everywhere * We don't need to do this 'cause G2 doesn't allow raw entities into the database * $this->_bbcode->addParser('htmlspecialchars', * array('block', 'inline', 'link', 'listitem')); */ /* Convert line endings */ $this->_bbcode->addParser('nl2br', array('block', 'inline', 'link', 'listitem')); /* Strip last line break in list items */ $this->_bbcode->addParser(array($this, 'stripLastLineBreak'), array('listitem')); /* Strip contents in list elements */ $this->_bbcode->addParser(array($this, 'stripContents'), array('list')); /* [b], [i] */ $this->_bbcode->addCode('b', 'simple_replace', null, array('<b>', '</b>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $this->_bbcode->addCode('i', 'simple_replace', null, array('<i>', '</i>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); /* [url]http://...[/url], [url=http://...]Text[/url] */ $this->_bbcode->addCode('url', 'usecontent?', array($this, 'url'), array('default'), 'link', array('listitem', 'block', 'inline'), array('link')); /* [img]http://...[/img] */ $this->_bbcode->addCode('img', 'usecontent', array($this, 'image'), array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); /* [list] [*]Element [/list] */ $this->_bbcode->addCode('list', 'simple_replace', null, array('<ul>', '</ul>'), 'list', array('block', 'listitem'), array()); $this->_bbcode->addCode('*', 'simple_replace', null, array('<li>', "</li>\n"), 'listitem', array('list'), array()); $this->_bbcode->setCodeFlag('*', 'no_close_tag', true); }
/** * Import all the tags for a single item */ static function import_tags_for_item(&$queue) { GalleryCoreApi::requireOnce("modules/tags/classes/TagsHelper.class"); $g2_item_id = array_shift($queue); $g3_item = ORM::factory("item", self::map($g2_item_id)); try { $tag_names = array_values(g2(TagsHelper::getTagsByItemId($g2_item_id))); } catch (Exception $e) { g2_import::log("Failed to import tags for Gallery 2 item with id: %id", array("id" => $g2_item_id)); return; } foreach ($tag_names as $tag_name) { $tag = tag::add($g3_item, $tag_name); } // Tag operations are idempotent so we don't need to map them. Which is good because we don't // have an id for each individual tag mapping anyway so it'd be hard to set up the mapping. }
/** * Create the HTML for the image controls * * @return string $html The HTML for the image controls */ function g2ic_make_html_controls() { global $gallery, $g2ic_imginsert_options, $g2ic_options; // "How to insert:" radio buttons $html = " <fieldset>\n" . ' <legend>' . T_('Insertion Options') . '</legend>' . "\n" . ' <label for="alignment">' . T_('How to Insert Image') . '</label>' . "\n" . g2ic_make_html_select('imginsert', $g2ic_imginsert_options, 'toggleTextboxes();') . ' <br />' . "\n" . ' <br />' . "\n" . ' <div name="custom_url_textbox"'; if ($g2ic_options['default_action'] == 'thumbnail_custom_url') { $html .= ' class="displayed_textbox"'; } else { $html .= 'class="hidden_textbox"'; } $html .= '>' . "\n" . ' <label for="custom_url">' . T_('Custom URL') . '<br /></label>' . "\n" . ' <input type="text" name="custom_url" size="84" maxlength="150" value="' . $g2ic_options['custom_url'] . '" />' . "\n" . ' <br />' . "\n" . ' <br />' . "\n" . ' </div>' . "\n" . ' <div name="link_text_textbox"'; if ($g2ic_options['default_action'] == 'link_image' || $g2ic_options['default_action'] == 'link_album') { $html .= ' class="displayed_textbox"'; } else { $html .= 'class="hidden_textbox"'; } $html .= '>' . "\n" . ' <label for="link_text">' . T_('Text for text link') . '<br /></label>' . "\n" . ' <input type="text" name="link_text" size="84" maxlength="150" value="" />' . "\n" . ' <br />' . "\n" . ' <br />' . "\n" . ' </div>' . "\n" . ' <div name="lightbox_group_textbox"'; if ($g2ic_options['default_action'] == 'thumbnail_lightbox') { $html .= ' class="displayed_textbox"'; } else { $html .= 'class="hidden_textbox"'; } $html .= '>' . "\n" . ' <label for="lightbox_group">' . T_('LightBox Group (Leave blank to not group with other images)') . '<br /></label>' . "\n" . ' <input type="text" name="lightbox_group" size="84" maxlength="150" value="g2image" />' . "\n" . ' <br />' . "\n" . ' <br />' . "\n" . ' </div>' . "\n"; // WPG2 tag "size" box. if ($g2ic_options['wpg2_valid']) { GalleryCoreApi::requireOnce('modules/imageblock/module.inc'); GalleryCoreApi::requireOnce('modules/core/classes/GalleryRepositoryUtilities.class'); $plugin = new ImageBlockModule(); $version = $plugin->getVersion(); $version_comparison = GalleryRepositoryUtilities::compareRevisions($version, '1.0.9'); if ($version_comparison != 'older') { $html .= ' <div name="wpg2_tag_size_textbox"'; if ($g2ic_options['default_action'] == 'wpg2_image') { $html .= ' class="displayed_textbox"'; } else { $html .= 'class="hidden_textbox"'; } $html .= '>' . "\n" . ' <label for="wpg2_tag_size">' . T_('WPG2 tag "size" attribute (Leave blank for the default size of: ') . $g2ic_options['wpg2_tag_size'] . 'px)' . '<br /></label>' . "\n" . ' <input type="text" name="wpg2_tag_size" size="84" maxlength="150" value="" />' . "\n" . ' <br />' . "\n" . ' <br />' . "\n" . ' </div>' . "\n"; } else { $html .= ' <input type="hidden" name="wpg2_tag_size" value="" />' . "\n"; } } // Drupal G2 Filter "exactsize" attribute box. if ($g2ic_options['drupal_g2_filter']) { GalleryCoreApi::requireOnce('modules/imageblock/module.inc'); GalleryCoreApi::requireOnce('modules/core/classes/GalleryRepositoryUtilities.class'); $plugin = new ImageBlockModule(); $version = $plugin->getVersion(); $version_comparison = GalleryRepositoryUtilities::compareRevisions($version, '1.0.9'); if ($version_comparison != 'older') { $html .= ' <div name="drupal_exactsize_textbox"'; if ($g2ic_options['default_action'] == 'drupal_g2_filter') { $html .= ' class="displayed_textbox"'; } else { $html .= 'class="hidden_textbox"'; } $html .= '>' . "\n" . ' <label for="drupal_exactsize">' . T_('Drupal G2 Filter "exactsize" attribute (Leave blank for no exactsize attribute)') . '<br /></label>' . "\n" . ' <input type="text" name="drupal_exactsize" size="84" maxlength="150" value="" />' . "\n" . ' <br />' . "\n" . ' <br />' . "\n" . ' </div>' . "\n"; } else { $html .= ' <input type="hidden" name="drupal_exactsize" value="" />' . "\n"; } } // Alignment selection $html .= ' <label for="alignment">' . T_('G2Image Alignment Class') . '</label>' . "\n" . g2ic_make_html_alignment_select() . " </fieldset>\n\n"; // "Insert" button $html .= " <fieldset>\n" . ' <legend>' . T_('Press button to insert checked image(s)') . '</legend>' . "\n" . " <input disabled type='button'\n" . " name='insert_button'\n" . ' onclick="insertItems();"' . "\n" . ' value="' . T_('Insert') . '"' . "\n" . ' />' . "\n" . ' <a href="javascript: checkAllImages();">' . T_('Check all') . '</a> | <a href="javascript: uncheckAllImages();">' . T_('Uncheck all') . '</a>' . "\n" . " </fieldset>\n\n"; return $html; }
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; } }
function GalleryBbcodeMarkupParser() { if (!class_exists('StringParser_BBCode')) { GalleryCoreApi::requireOnce('lib/bbcode/stringparser_bbcode.class.php'); } $this->_bbcode = new StringParser_BBCode(); $this->_bbcode->setGlobalCaseSensitive(false); /* Convert line breaks everywhere */ $this->_bbcode->addParser(array('block', 'inline', 'link', 'listitem', 'list'), array($this, 'convertLineBreaks')); /* * Escape all characters everywhere * We don't need to do this 'cause G2 doesn't allow raw entities into the database * $this->_bbcode->addParser('htmlspecialchars', * array('block', 'inline', 'link', 'listitem')); */ /* Convert line endings */ $this->_bbcode->addParser(array('block', 'inline', 'link', 'listitem'), 'nl2br'); /* Strip last line break in list items */ $this->_bbcode->addParser(array('listitem'), array($this, 'stripLastLineBreak')); /* Strip contents in list elements */ $this->_bbcode->addParser(array('list'), array($this, 'stripContents')); /* [b], [i] */ $this->_bbcode->addCode('b', 'simple_replace', null, array('start_tag' => '<b>', 'end_tag' => '</b>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); $this->_bbcode->addCode('i', 'simple_replace', null, array('start_tag' => '<i>', 'end_tag' => '</i>'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); /* [url]http://...[/url], [url=http://...]Text[/url] */ $this->_bbcode->addCode('url', 'usecontent?', array($this, 'url'), array('usecontent_param' => 'default'), 'link', array('listitem', 'block', 'inline'), array('link')); /* [color=...]Text[/color] */ $this->_bbcode->addCode('color', 'callback_replace', array($this, 'color'), array('usecontent_param' => 'default'), 'inline', array('listitem', 'block', 'inline', 'link'), array()); /* [img]http://...[/img] */ $this->_bbcode->addCode('img', 'usecontent', array($this, 'image'), array(), 'image', array('listitem', 'block', 'inline', 'link'), array()); /* [list] [*]Element [/list] */ $this->_bbcode->addCode('list', 'simple_replace', null, array('start_tag' => '<ul>', 'end_tag' => '</ul>'), 'list', array('block', 'listitem'), array()); $this->_bbcode->addCode('*', 'simple_replace', null, array('start_tag' => '<li>', 'end_tag' => "</li>\n"), 'listitem', array('list'), array()); $this->_bbcode->setCodeFlag('*', 'closetag', BBCODE_CLOSETAG_OPTIONAL); }
/** * Handle an error condition that happened somewhere in our main request processing code. If the * error cannot be handled, then add an error in the event log. * @param GalleryStatus a status code * @param array $g2Data the results from _GalleryMain */ function _GalleryMain_errorHandler($error, $g2Data = null) { global $gallery; GalleryCoreApi::requireOnce('modules/core/ErrorPage.inc'); $handledError = ErrorPageView::errorHandler($error, $g2Data); if (!$handledError) { $summary = $error->getErrorMessage(); if (empty($summary)) { $summary = join(', ', $error->getErrorCodeConstants($error->getErrorCode())); } GalleryCoreApi::addEventLogEntry('Gallery Error', $summary, $error->getAsText()); } }
/** * 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; }