function clearPageCache() { require_once dirname(__FILE__) . '/../../embed.php'; GalleryEmbed::init(); $ret1 = GalleryCoreApi::removeAllMapEntries('GalleryCacheMap'); $ret2 = GalleryEmbed::done(); if ($ret1 || $ret2) { $status[] = array('error', 'Error deleting page cache!'); } else { $status[] = array('info', 'Successfully deleted page cache'); } return $status; }
function clearPageCache() { global $gallery; $storage =& $gallery->getStorage(); $ret = GalleryCoreApi::removeAllMapEntries('GalleryCacheMap', true); if ($ret) { $status = array(array('error', 'Error deleting page cache!')); } else { $status = array(array('info', 'Successfully deleted page cache')); } $ret = $storage->checkPoint(); if ($ret) { $status[] = array('error', 'Error committing transaction!'); } return $status; }
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); }
static function import($task) { $start = microtime(true); g2_import::init(); $stats = $task->get("stats"); $done = $task->get("done"); $total = $task->get("total"); $completed = $task->get("completed"); $mode = $task->get("mode"); $queue = $task->get("queue"); if (!isset($mode)) { $stats = g2_import::stats(); $stats["items"] = $stats["photos"] + $stats["movies"]; unset($stats["photos"]); unset($stats["movies"]); $stats["highlights"] = $stats["albums"]; $task->set("stats", $stats); $task->set("total", $total = array_sum(array_values($stats))); $completed = 0; $mode = 0; $done = array(); foreach (array_keys($stats) as $key) { $done[$key] = 0; } $task->set("done", $done); $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId()); $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find(); if (!$root->loaded()) { $root->g2_id = $root_g2_id; $root->g3_id = 1; $root->save(); } } $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done"); while (!$task->done && microtime(true) - $start < 1.5) { if ($done[$modes[$mode]] == $stats[$modes[$mode]]) { // Nothing left to do for this mode. Advance. $mode++; $task->set("last_id", 0); $queue = array(); // Start the loop from the beginning again. This way if we get to a mode that requires no // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments // queries.. in the next iteration we'll just skip over that mode. if ($modes[$mode] != "done") { continue; } } switch ($modes[$mode]) { case "groups": if (empty($queue)) { $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchGroupNames()))); } $log_message = g2_import::import_group($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"])); break; case "users": if (empty($queue)) { $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY)))); } $log_message = g2_import::import_user($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"])); break; case "albums": if (empty($queue)) { $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree())); } $log_message = g2_import::import_album($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"])); break; case "items": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_item($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"])); break; case "comments": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_comment($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"])); break; case "tags": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_tags_for_item($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"])); break; case "highlights": if (empty($queue)) { $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree())); } $log_message = g2_import::set_album_highlight($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Album highlights (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["albums"])); break; case "done": $task->status = t("Import complete"); $task->done = true; $task->state = "success"; break; } if (!$task->done) { $done[$modes[$mode]]++; $completed++; } } $task->percent_complete = 100 * ($completed / $total); $task->set("completed", $completed); $task->set("mode", $mode); $task->set("queue", $queue); $task->set("done", $done); }
/** * 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 smtpmail($config, $to, $subject, $body, $headers = null) { // Fix any bare linefeeds in the message to make it RFC821 Compliant. $body = preg_replace("#(?<!\r)\n#si", "\r\n", $body); $cc = $bcc = array(); if (isset($headers)) { $headers = rtrim($headers); // Make sure there are no bare linefeeds in the headers $headers = preg_replace('#(?<!\\r)\\n#si', "\r\n", $headers); if (preg_match('#^cc:\\s*(.*?)\\s*$#mi', $headers, $match)) { $cc = split(', *', $match[1]); } if (preg_match('#^bcc:\\s*(.*?)\\s*$#mi', $headers, $match)) { $bcc = split(', *', $match[1]); $headers = preg_replace('#^bcc:.*$#mi', '', $headers); } } if (trim($subject) == '') { return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "No email Subject specified"); } if (trim($body) == '') { return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Email message was blank"); } // Connect list($config['smtp.host'], $port) = array_merge(explode(':', $config['smtp.host']), array(25)); if (!($socket = fsockopen($config['smtp.host'], $port, $errno, $errstr, 20))) { return GalleryCoreApi::error(ERROR_PLATFORM_FAILURE, __FILE__, __LINE__, "Could not connect to smtp host : {$errno} : {$errstr}"); } // Wait for reply $ret = server_parse($socket, "220"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } // Do we want to use AUTH?, send RFC2554 EHLO, else send RFC821 HELO if (!empty($config['smtp.username']) && !empty($config['smtp.password'])) { fputs($socket, "EHLO " . $config['smtp.host'] . "\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } fputs($socket, "AUTH LOGIN\r\n"); $ret = server_parse($socket, "334"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } fputs($socket, base64_encode($config['smtp.username']) . "\r\n"); $ret = server_parse($socket, "334"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } fputs($socket, $config['smtp.password'] . "\r\n"); // Already encoded $ret = server_parse($socket, "235"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } } else { fputs($socket, "HELO " . $config['smtp.host'] . "\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } } // From this point onward most server response codes should be 250 // Specify who the mail is from.... fputs($socket, "MAIL FROM: <" . $config['smtp.from'] . ">\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } // Add an additional bit of error checking to the To field. $to = trim($to) == '' ? 'Undisclosed-recipients:;' : trim($to); if (preg_match('#[^ ]+\\@[^ ]+#', $to)) { fputs($socket, "RCPT TO: <{$to}>\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } } // Ok now do the CC and BCC fields... foreach (array_merge($cc, $bcc) as $address) { $address = trim($address); if (preg_match('#[^ ]+\\@[^ ]+#', $address)) { fputs($socket, "RCPT TO: <{$address}>\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } } } // Ok now we tell the server we are ready to start sending data fputs($socket, "DATA\r\n"); // This is the last response code we look for until the end of the message. $ret = server_parse($socket, "354"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } // Send the Subject Line... fputs($socket, "Subject: {$subject}\r\n"); // Now the To Header. fputs($socket, "To: {$to}\r\n"); // Now any custom headers.... if (isset($headers)) { fputs($socket, "{$headers}\r\n"); } // Ok now we are ready for the message... fputs($socket, "\r\n{$body}\r\n"); // Ok the all the ingredients are mixed in let's cook this puppy... fputs($socket, ".\r\n"); $ret = server_parse($socket, "250"); if ($ret) { return $ret->wrap(__FILE__, __LINE__); } // Now tell the server we are done and close the socket... fputs($socket, "QUIT\r\n"); fclose($socket); return null; }
} } else { if ($type == "gallery") { $alluserslink = ""; if ($_POST['addselect']) { foreach ($_POST['addselect'] as $user) { $alluserslink .= $user . ":"; } } echo "<h2>Gallery:</h2><br />"; echo '<a href="get_csv.php?id=' . $id . '&type=gallery&addselect=' . $alluserslink . '">Download CSV</a><br /><br />'; require_once $CFG->dirroot . "/gallery2/bootstrap.inc"; require_once $CFG->dirroot . "/gallery2/embed.php"; $embed = new GalleryEmbed(); $embed->init(); $g_api = new GalleryCoreApi(); list($ret, $usersdata) = $g_api->fetchUsernames(); if ($_POST['addselect']) { foreach ($_POST['addselect'] as $user) { list($ret, $items) = $g_api->fetchAllItemIdsByOwnerId($user); //---------------------????????? ? ????????????---------------------// list($ret, $usr) = $g_api->fetchUserByUserName($usersdata[$user]); $summary = ""; $summary_s = ""; foreach ($items as $item) { $r_tb = mysql_query("SELECT * FROM " . $storeConfig['tablePrefix'] . "Item WHERE " . $storeConfig['columnPrefix'] . "id = '" . $item . "'"); $row_tb = mysql_fetch_array($r_tb); if ($row_tb[$storeConfig['columnPrefix'] . 'summary'] != $usr->userName) { $summarysize = strlen(trim($row_tb[$storeConfig['columnPrefix'] . 'summary'])); $descriptionsize = strlen(trim($row_tb[$storeConfig['columnPrefix'] . 'description'])); if ($summarysize > $descriptionsize) {
static function import($task) { g2_import::lower_error_reporting(); $start = microtime(true); g2_import::init(); $stats = $task->get("stats"); $done = $task->get("done"); $total = $task->get("total"); $completed = $task->get("completed"); $mode = $task->get("mode"); $queue = $task->get("queue"); if (!isset($mode)) { $stats = g2_import::g2_stats(); $stats["items"] = $stats["photos"] + $stats["movies"]; unset($stats["photos"]); unset($stats["movies"]); $stats["highlights"] = $stats["albums"]; $task->set("stats", $stats); $task->set("total", $total = array_sum(array_values($stats))); $completed = 0; $mode = 0; $done = array(); foreach (array_keys($stats) as $key) { $done[$key] = 0; } $task->set("done", $done); // Ensure G2 ACLs are compacted to speed up import. g2(GalleryCoreApi::compactAccessLists()); } $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done"); while (!$task->done && microtime(true) - $start < 1.5) { if ($done[$modes[$mode]] == $stats[$modes[$mode]]) { // Nothing left to do for this mode. Advance. $mode++; $task->set("last_id", 0); $queue = array(); // Start the loop from the beginning again. This way if we get to a mode that requires no // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments // queries.. in the next iteration we'll just skip over that mode. if ($modes[$mode] != "done") { continue; } } switch ($modes[$mode]) { case "groups": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_group_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_group($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"])); break; case "users": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_user_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_user($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"])); break; case "albums": if (empty($queue)) { $g2_root_id = g2(GalleryCoreApi::getDefaultAlbumId()); $tree = g2(GalleryCoreApi::fetchAlbumTree()); $task->set("queue", $queue = array($g2_root_id => $tree)); // Update the root album to reflect the Gallery2 root album. $root_album = item::root(); g2_import::set_album_values($root_album, g2(GalleryCoreApi::loadEntitiesById($g2_root_id))); $root_album->save(); } $log_message = g2_import::import_album($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"])); break; case "items": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_item($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"])); break; case "comments": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_comment($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"])); break; case "tags": if (empty($queue)) { $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0))); $task->set("last_id", end($queue)); } $log_message = g2_import::import_tags_for_item($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"])); break; case "highlights": if (empty($queue)) { $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree())); } $log_message = g2_import::set_album_highlight($queue); if ($log_message) { $task->log($log_message); } $task->status = t("Album highlights (%count of %total)", array("count" => $done["highlights"] + 1, "total" => $stats["highlights"])); break; case "done": $task->status = t("Import complete"); $task->done = true; $task->state = "success"; break; } if (!$task->done) { $done[$modes[$mode]]++; $completed++; } } $task->percent_complete = 100 * ($completed / $total); $task->set("completed", $completed); $task->set("mode", $mode); $task->set("queue", $queue); $task->set("done", $done); g2_import::restore_error_reporting(); }
/** * 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; }
/** * Returns the fully-qualified URL for the given image resource * * @param int $elementId * @return string */ function getElementUrl($elementId) { global $mosConfig_live_site; $path = $mosConfig_live_site . GalleryService::G2ALBUM_BASE_URL; $parents = GalleryCoreApi::fetchParentSequence($elementId); if (isset($parents[1])) { foreach ($parents[1] as $nodeId) { $node = GalleryCoreApi::loadEntitiesById($nodeId); $comp = $node[1]->getPathComponent(); if ($comp != '') { $path .= "/" . $comp; } } } $self = GalleryCoreApi::loadEntitiesById($elementId); $path .= "/" . $self[1]->getPathComponent(); return $path; }
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 smarty_modifier_utf8($string) { return GalleryCoreApi::convertToUtf8($string); }
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); }
function gimage_thumb($photo_path, $params) { global $serendipity; $path_parts = pathinfo($photo_path); //The pathinfo funtion returns 'filename' from PHP 5.2 upwards, but until that has wide support, the below returns it too... if (strlen($path_parts["extension"]) > 0) { $path_parts['filename'] = substr($path_parts["basename"], 0, strlen($path_parts["basename"]) - (strlen($path_parts["extension"]) + 1)); } else { $path_parts['filename'] = $path_parts["basename"]; } $album = $path_parts['dirname']; $photo = $path_parts['filename']; $extension = $path_parts['extension']; $gallery_base = $this->get_config('gallery_base'); $album_base = $this->get_config('album_base'); $album_abs = $this->get_config('album_abs'); $photo_ext = $extension ? "{$extension}" : "jpg"; if ($this->get_config('gversion') == 2) { $album_base = $this->get_config('album_base') . "/albums"; } // get popup max image size, default if not good. $popup_max = $this->get_config('popup_max'); if ($popup_max < 100) { $popup_max = 640; } $paramlist = explode(";", $params); //split up the parameters $param_array = array(); foreach ($paramlist as $parameter) { $temp = explode("=", $parameter); $param_array[trim(strtolower($temp[0]))] = trim($temp[1]); } if ($this->get_config('gversion') == 2) { $image = $album_abs . '/albums/' . $album . '/' . $photo . '.' . $photo_ext; $image_path = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_path .= "album=" . $album; $image_path .= "&image=" . $photo; $image_path .= "&ext=" . $photo_ext; //handle the parameters // size = thumb sized or full image? switch (strtolower($param_array['size'])) { case 'sized': $image_path .= "&size=sized"; break; case 'full': $image_path .= "&size=full"; break; case 'thumb': default: $image_path .= "&size=thumb"; break; } } //handle the parameters // size = thumb sized or full image? switch (strtolower($param_array['size'])) { case 'sized': $image_size = ".sized."; break; case 'full': $image_size = "."; break; case 'thumb': default: $image_size = ".thumb."; break; } // link = image, page, album, none? if ($this->get_config('gversion') == 2) { switch (strtolower($param_array['link'])) { case 'image': $image_link = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_link .= "album=" . $album; $image_link .= "&image=" . $photo; $image_link .= "&ext=" . $photo_ext; $image_link .= "&size="; break; case 'image_sized': $image_link = $serendipity['baseURL'] . ($serendipity['rewrite'] == "none" ? $serendipity['indexFile'] . "?/" : "/") . "plugin/g2wrapper?"; $image_link .= "album=" . $album; $image_link .= "&image=" . $photo; $image_link .= "&ext=" . $photo_ext; $image_link .= "&size=sized"; break; case 'album': include_once $this->get_config('gallery_abs') . "/embed.php"; if (!class_exists('GalleryEmbed')) { break; } $ret = GalleryEmbed::init(array('fullInit' => true, 'activeUserId' => '')); if (is_object($ret) && $ret->isError()) { echo $ret->getAsHtml(); exit; } $ret_aid = GalleryCoreApi::fetchItemIdByPath($album); $album_id = is_array($ret_aid) && intval($ret_aid[1]) >= 1 ? intval($ret_aid[1]) : 0; $image_link = $gallery_base . '/main.php?g2_view=core.ShowItem&g2_itemId=' . $album_id; break; case 'page': default: include_once $this->get_config('gallery_abs') . "/embed.php"; if (!class_exists('GalleryEmbed')) { break; } $ret = GalleryEmbed::init(array('fullInit' => true, 'activeUserId' => '')); if (is_object($ret) && $ret->isError()) { echo $ret->getAsHtml(); exit; } $ret_iid = GalleryCoreApi::fetchItemIdByPath($album . "/" . $photo . "." . $photo_ext); $fullsize_id = is_array($ret_iid) && intval($ret_iid[1]) >= 1 ? intval($ret_iid[1]) : 0; $image_link = $gallery_base . '/main.php?g2_view=core.ShowItem&g2_itemId=' . $fullsize_id; break; } } else { switch (strtolower($param_array['link'])) { case 'image': $image_link = $album_base . '/' . $album . '/' . $photo . '.' . $photo_ext; break; case 'image_sized': $image_link = $album_base . '/' . $album . '/' . $photo . '.sized.' . $photo_ext; break; case 'album': $image_link = $gallery_base . '/view_album.php?set_albumName=' . $album; break; case 'page': default: $image_link = $gallery_base . '/view_photo.php?set_albumName=' . $album . '&id=' . $photo; break; } } if ($this->get_config('gversion') != 2) { // get thumbnail image attributes list($width, $height, $type, $attr) = getimagesize($album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext); } else { $thissize = getimagesize($album_abs . '/albums/' . $album . '/' . $photo . "." . $photo_ext); if (strtolower($param_array['size']) == 'sized') { $newsize = $this->g2_imagesize($thissize[0], $thissize[1], $this->get_config('popup_max')); $width = $newsize[0]; $height = $newsize[1]; $attr = 'width="' . $width . '" height="' . $height . '"'; } elseif (strtolower($param_array['size']) == 'thumb') { $newsize = $this->g2_imagesize($thissize[0], $thissize[1], $this->get_config('thumb_max')); $width = $newsize[0]; $height = $newsize[1]; $attr = 'width="' . $width . '" height="' . $height . '"'; } else { list($width, $height, $type, $attr) = getimagesize($album_abs . "/albums/" . $album . "/" . $photo . "." . $photo_ext); } } // target=default|new|popup only allow popup for link=image and link-image_sized switch (strtolower($param_array['target'])) { case 'popup': if ($this->get_config('gversion') != 2) { if (strtolower($param_array['link']) == 'image' || strtolower($param_array['link']) == 'image_sized') { // get target image attributes list($pwidth, $pheight, $ptype, $pattr) = getimagesize($image_link); //work out popup image window size if ($pwidth >= $pheight && $pwidth > $popup_max) { $pwidth = $popup_max; $pheight = round($popup_max * $height / $width); //from thumbnail } elseif ($pheight >= $pwidth && $pheight > $popup_max) { $pheight = $popup_max; $pwidth = round($popup_max * $width / $height); //from thumbnail } //standard spacing for windows and title bars $pwidth += 30; $pheight += 50; $link_target = '<a href="javascript:;" '; $link_target .= ' onclick="w = window.open('; $link_target .= "'" . $image_link . "', 'GImage Popup','width={$pwidth},height={$pheight},menubar=no,resizable=yes,scrollbars=yes,status=no,toolbar=no');"; $link_target .= 'w.resizeTo(' . $pwidth . ',' . $pheight . ')">'; } else { $link_target = '<a href="' . $image_link . '">'; } } else { $link_target = '<a href="' . $image_link . '">'; } break; case 'new': $link_target = '<a href="' . $image_link . '" target="_blank">'; break; case 'none': $link_target = ''; break; case 'default': default: $link_target = '<a href="' . $image_link . '">'; break; } // align = left, center, right? default center switch (strtolower($param_array['align'])) { case 'left': $div_align = 'left'; $img_align = 'align=left'; $img_pre = ''; $img_post = ''; break; case 'right': $div_align = 'right'; $img_align = 'align=right'; $img_pre = ''; $img_post = ''; break; case 'center': $div_align = 'center'; $img_align = ''; $img_pre = '<center>'; $img_post = '</center>'; break; case 'none': default: $div_align = 'center'; $img_align = ''; $img_pre = ''; $img_post = ''; break; } // caption = image alt text or caption if ($param_array['caption'] == "") { $param_array['caption'] = "[PHOTO]"; } $param_array['caption'] = str_replace("\"", "", $param_array['caption']); $param_array['caption'] = str_replace("'", "", $param_array['caption']); $param_array['caption'] = str_replace(""", "", $param_array['caption']); // style = link, image or fancy (s9y stylesheet image amanager style)? switch (strtolower($param_array['style'])) { case 'image': if ($this->get_config('gversion') == 2) { $output = $img_pre . '<img ' . $img_align . ' src="' . $image_path . '" alt="' . $param_array['caption'] . '" />' . $img_post; } else { $output = $img_pre . '<img ' . $img_align . ' src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" alt="' . $param_array['caption'] . '" />' . $img_post; } break; case 'fancy': $output = '<div class="serendipity_imageComment_' . $div_align . '" style="width: ' . $width . 'px">'; $output .= '<div class="serendipity_imageComment_img">'; if ($this->get_config('gversion') == 2) { $output .= $link_target . '<img src="' . $image_path . '" border="0" hspace="5" ' . $attr . ' /></a>'; } else { $output .= $link_target . '<img src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" border="0" hspace="5" ' . $attr . ' /></a>'; } $output .= '</div><div class="serendipity_imageComment_txt">' . $param_array['caption'] . '</div></div>'; break; case 'link': default: if ($this->get_config('gversion') == 2) { $output = $img_pre . $link_target . '<img ' . $img_align . ' src="' . $image_path . '" alt="' . $param_array['caption'] . '" /></a>' . $img_post; } else { $output = $img_pre . $link_target . '<img ' . $img_align . ' src="' . $album_base . '/' . $album . '/' . $photo . $image_size . $photo_ext . '" alt="' . $param_array['caption'] . '" /></a>' . $img_post; } break; } return $output; }
list($ret, $errors) = $importer->importToDb($verifiedFile, 'importProgressCallback'); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } else { if ($errors != null) { if (!is_array($errors)) { $templateData['errors'][] = $errors->getAsHtml(); } else { foreach ($errors as $status) { $templateData['errors'][] = $status->getAsHtml(); } } } } /* The import processing sets Gallery into maintenance mode, undo that now */ $ret = GalleryCoreApi::setMaintenanceMode(false); if ($ret) { $templateData['errors'][] = $ret->getAsHtml(); } $templateData['bodyFile'] = 'ImportFinished.html'; $templateData['hideStatusBlock'] = 1; $renderFullPage = false; } } else { getBackupFiles($templateData); /* Render the output */ $templateData['bodyFile'] = 'ImportRequest.html'; } } if (!$ret) { $ret = GalleryEmbed::done();
/** * If the thumbnails and resizes created for the Gallery 2 photo match the dimensions of the * ones we expect to create for Gallery 3, then copy the files over instead of recreating them. */ static function copy_matching_thumbnails_and_resizes($item) { // We only operate on items that are being imported if (empty(self::$current_g2_item)) { return; } // Precaution: if the Gallery 2 item was watermarked, or we have the Gallery 3 watermark module // active then we'd have to do something a lot more sophisticated here. For now, just skip // this step in those cases. // @todo we should probably use an API here, eventually. if (module::is_active("watermark") && module::get_var("watermark", "name")) { return; } // For now just do the copy for photos and movies. Albums are tricky because we're may not // yet be setting their album cover properly. // @todo implement this for albums also if (!$item->is_movie() && !$item->is_photo()) { return; } $g2_item_id = self::$current_g2_item->getId(); $derivatives = g2(GalleryCoreApi::fetchDerivativesByItemIds(array($g2_item_id))); $target_thumb_size = module::get_var("gallery", "thumb_size"); $target_resize_size = module::get_var("gallery", "resize_size"); if (!empty($derivatives[$g2_item_id])) { foreach ($derivatives[$g2_item_id] as $derivative) { if ($derivative->getPostFilterOperations()) { // Let's assume for now that this is a watermark operation, which we can't handle. continue; } if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_THUMBNAIL && $item->thumb_dirty && ($derivative->getWidth() == $target_thumb_size || $derivative->getHeight() == $target_thumb_size)) { if (@copy(g2($derivative->fetchPath()), $item->thumb_path())) { $item->thumb_height = $derivative->getHeight(); $item->thumb_width = $derivative->getWidth(); $item->thumb_dirty = false; } } if ($derivative->getDerivativeType() == DERIVATIVE_TYPE_IMAGE_RESIZE && $item->resize_dirty && ($derivative->getWidth() == $target_resize_size || $derivative->getHeight() == $target_resize_size)) { if (@copy(g2($derivative->fetchPath()), $item->resize_path())) { $item->resize_height = $derivative->getHeight(); $item->resize_width = $derivative->getWidth(); $item->resize_dirty = false; } } } } $item->save(); }
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 getG2Tree(&$xmap, &$parent, $params, &$items, &$urlGenerator) { if (!$items) { return null; } $xmap->changeLevel(1); $media = array(); foreach ($items as $itemId) { // Fetch the details for this item list($ret, $entity) = GalleryCoreApi::loadEntitiesById($itemId); if ($ret) { // error, skip and continue, catch this error in next component version continue; } $node = new stdClass(); $node->id = $entity->getId(); $node->uid = $parent->uid . 'a' . $entity->getId(); $node->name = $entity->getTitle(); $node->pid = $entity->getParentId(); $node->modified = $entity->getModificationTimestamp(); $node->link = $urlGenerator->generateUrl(array('view' => 'core.ShowItem', 'itemId' => $node->id), array('forceSessionId' => false, 'forceFullUrl' => false)); // Fix for the navigator view if ($xmap->view == 'navigator') { $node->link = str_replace('/administrator/index.php', '', $node->link); } // If it is an album if ($entity->getCanContainChildren()) { $node->priority = $params['cat_priority']; $node->changefreq = $params['cat_changefreq']; $node->expandible = true; // Get all child items contained in this album and add them to the tree list($ret, $childIds) = GalleryCoreApi::fetchChildItemIdsWithPermission($node->id, 'core.view'); if ($ret) { // error, skip and continue, catch this error in next component version continue; } if ($xmap->printNode($node) !== false) { xmap_com_g2bridge::getG2Tree($xmap, $parent, $params, $childIds, $urlGenerator); } } elseif ($params['include_items']) { $node->priority = $params['item_priority']; $node->changefreq = $params['item_changefreq']; $node->uid = $parent->uid . 'p' . $entity->getId(); $node->expandible = false; $media[] = $node; } } foreach ($media as $pic) { $xmap->printNode($pic); } $xmap->changeLevel(-1); }
/** * 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()); } }