Пример #1
0
/**
 * Get an existing story
 *
 * @param   array   args    Contains all the data provided by the client
 * @param   string  &output OUTPUT parameter containing the returned text
 * @return  int         Response code as defined in lib-plugins.php
 */
function service_get_story($args, &$output, &$svc_msg)
{
    global $_CONF, $_TABLES, $_USER;
    $output = array();
    $retval = '';
    if (!isset($_CONF['atom_max_stories'])) {
        $_CONF['atom_max_stories'] = 10;
        // set a resonable default
    }
    $svc_msg['output_fields'] = array('draft_flag', 'hits', 'numemails', 'comments', 'trackbacks', 'featured', 'commentcode', 'statuscode', 'expire_date', 'postmode', 'advanced_editor_mode', 'frontpage', 'owner_id', 'group_id', 'perm_owner', 'perm_group', 'perm_members', 'perm_anon');
    if (empty($args['sid']) && !empty($args['id'])) {
        $args['sid'] = $args['id'];
    }
    if ($args['gl_svc']) {
        if (isset($args['mode'])) {
            $args['mode'] = COM_applyBasicFilter($args['mode']);
        }
        if (isset($args['sid'])) {
            $args['sid'] = COM_applyBasicFilter($args['sid']);
        }
        if (empty($args['sid'])) {
            $svc_msg['gl_feed'] = true;
        } else {
            $svc_msg['gl_feed'] = false;
        }
    } else {
        $svc_msg['gl_feed'] = false;
    }
    if (empty($args['mode'])) {
        $args['mode'] = 'view';
    }
    if (!$svc_msg['gl_feed']) {
        $sid = $args['sid'];
        $mode = $args['mode'];
        $story = new Story();
        $retval = $story->loadFromDatabase($sid, $mode);
        if ($retval != STORY_LOADED_OK) {
            $output = $retval;
            return PLG_RET_ERROR;
        }
        reset($story->_dbFields);
        while (list($fieldname, $save) = each($story->_dbFields)) {
            $varname = '_' . $fieldname;
            $output[$fieldname] = $story->{$varname};
        }
        $output['username'] = $story->_username;
        $output['fullname'] = $story->_fullname;
        if ($args['gl_svc']) {
            if ($output['statuscode'] == STORY_ARCHIVE_ON_EXPIRE || $output['statuscode'] == STORY_DELETE_ON_EXPIRE) {
                // This date format is PHP 5 only,
                // but only the web-service uses the value
                $output['expire_date'] = date('c', $output['expire']);
            }
            $output['id'] = $output['sid'];
            $output['category'] = array($output['tid']);
            $output['published'] = date('c', $output['date']);
            $output['updated'] = date('c', $output['date']);
            if (empty($output['bodytext'])) {
                $output['content'] = $output['introtext'];
            } else {
                $output['content'] = $output['introtext'] . LB . '[page_break]' . LB . $output['bodytext'];
            }
            $output['content_type'] = $output['postmode'] == 'html' ? 'html' : 'text';
            $owner_data = SESS_getUserDataFromId($output['owner_id']);
            $output['author_name'] = $owner_data['username'];
            $output['link_edit'] = $sid;
        }
    } else {
        $output = array();
        $mode = $args['mode'];
        $sql = array();
        if (isset($args['offset'])) {
            $offset = COM_applyBasicFilter($args['offset'], true);
        } else {
            $offset = 0;
        }
        $max_items = $_CONF['atom_max_stories'] + 1;
        $limit = " LIMIT {$offset}, {$max_items}";
        $limit_pgsql = " LIMIT {$max_items} OFFSET {$offset}";
        $order = " ORDER BY unixdate DESC";
        $sql['mysql'] = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, UNIX_TIMESTAMP(s.expire) as expireunix, " . "u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t " . "WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit;
        $sql['pgsql'] = "SELECT  s.*, UNIX_TIMESTAMP(s.date) AS unixdate, UNIX_TIMESTAMP(s.expire) as expireunix, u.username, u.fullname, u.photo, u.email, t.topic, t.imageurl  FROM stories s, users u, topics t WHERE (s.uid = u.uid) AND (s.tid = t.tid) FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, {$_TABLES['topics']} AS t WHERE (s.uid = u.uid) AND (s.tid = t.tid)" . COM_getPermSQL('AND', $_USER['uid'], 2, 's') . $order . $limit_pgsql;
        $result = DB_query($sql);
        $count = 0;
        while (($story_array = DB_fetchArray($result, false)) !== false) {
            $count += 1;
            if ($count == $max_items) {
                $svc_msg['offset'] = $offset + $_CONF['atom_max_stories'];
                break;
            }
            $story = new Story();
            $story->loadFromArray($story_array);
            // This access check is not strictly necessary
            $access = SEC_hasAccess($story_array['owner_id'], $story_array['group_id'], $story_array['perm_owner'], $story_array['perm_group'], $story_array['perm_members'], $story_array['perm_anon']);
            $story->_access = min($access, SEC_hasTopicAccess($story->_tid));
            if ($story->_access == 0) {
                continue;
            }
            $story->sanitizeData();
            reset($story->_dbFields);
            $output_item = array();
            while (list($fieldname, $save) = each($story->_dbFields)) {
                $varname = '_' . $fieldname;
                $output_item[$fieldname] = $story->{$varname};
            }
            if ($args['gl_svc']) {
                if ($output_item['statuscode'] == STORY_ARCHIVE_ON_EXPIRE || $output_item['statuscode'] == STORY_DELETE_ON_EXPIRE) {
                    // This date format is PHP 5 only,
                    // but only the web-service uses the value
                    $output_item['expire_date'] = date('c', $output_item['expire']);
                }
                $output_item['id'] = $output_item['sid'];
                $output_item['category'] = array($output_item['tid']);
                $output_item['published'] = date('c', $output_item['date']);
                $output_item['updated'] = date('c', $output_item['date']);
                if (empty($output_item['bodytext'])) {
                    $output_item['content'] = $output_item['introtext'];
                } else {
                    $output_item['content'] = $output_item['introtext'] . LB . '[page_break]' . LB . $output_item['bodytext'];
                }
                $output_item['content_type'] = $output_item['postmode'] == 'html' ? 'html' : 'text';
                $owner_data = SESS_getUserDataFromId($output_item['owner_id']);
                $output_item['author_name'] = $owner_data['username'];
            }
            $output[] = $output_item;
        }
    }
    return PLG_RET_OK;
}
Пример #2
0
if ($A = DB_fetchArray($result)) {
    $story = new Story();
    $story->loadFromArray($A);
    if ($_CONF['showfirstasfeatured'] == 1) {
        $story->_featured = 1;
    }
    // display first article
    $display .= STORY_renderArticle($story, 'y');
    // get plugin center blocks after featured article
    if ($story->DisplayElements('featured') == 1) {
        $display .= PLG_showCenterblock(2, $page, $topic);
    }
    // get remaining stories
    while ($A = DB_fetchArray($result)) {
        $story = new Story();
        $story->loadFromArray($A);
        $display .= STORY_renderArticle($story, 'y');
    }
    // get plugin center blocks that follow articles
    $display .= PLG_showCenterblock(3, $page, $topic);
    // bottom blocks
    // Print Google-like paging navigation
    if (!isset($_CONF['hide_main_page_navigation']) || $_CONF['hide_main_page_navigation'] == 0) {
        if (empty($topic)) {
            $base_url = $_CONF['site_url'] . '/index.php';
            if ($newstories) {
                $base_url .= '?display=new';
            }
        } else {
            $base_url = $_CONF['site_url'] . '/index.php?topic=' . $topic;
        }
Пример #3
0
/**
* This function will allow plugins to support the use of custom autolinks
* in other site content. Plugins can now use this API when saving content
* and have the content checked for any autolinks before saving.
* The autolink would be like:  [story:20040101093000103 here]
*
* @param   string   $content   Content that should be parsed for autolinks
* @param    string  $namespace Optional Namespace or plugin name collecting tag info
* @param    string  $operation Optional Operation being performed
* @param   string   $plugin    Optional if you only want to parse using a specific plugin
*
*/
function PLG_replaceTags($content, $namespace = '', $operation = '', $plugin = '')
{
    global $_CONF, $_TABLES, $_BLOCK_TEMPLATE, $LANG32, $_AUTOTAGS, $mbMenu, $autoTagUsage;
    if (isset($_CONF['disable_autolinks']) && $_CONF['disable_autolinks'] == 1) {
        // autolinks are disabled - return $content unchanged
        return $content;
    }
    static $recursionCount = 0;
    if ($recursionCount > 5) {
        COM_errorLog("AutoTag infinite recursion detected on " . $namespace . " " . $operation);
        return $content;
    }
    $autolinkModules = PLG_collectTags();
    $autoTagUsage = PLG_autoTagPerms();
    if (!empty($namespace) && !empty($operation)) {
        $postFix = '.' . $namespace . '.' . $operation;
    } else {
        $postFix = '';
    }
    // For each supported module, scan the content looking for any AutoLink tags
    $tags = array();
    $contentlen = utf8_strlen($content);
    $content_lower = utf8_strtolower($content);
    foreach ($autolinkModules as $moduletag => $module) {
        $autotag_prefix = '[' . $moduletag . ':';
        $offset = 0;
        $prev_offset = 0;
        while ($offset < $contentlen) {
            $start_pos = utf8_strpos($content_lower, $autotag_prefix, $offset);
            if ($start_pos === false) {
                break;
            } else {
                $end_pos = utf8_strpos($content_lower, ']', $start_pos);
                $next_tag = utf8_strpos($content_lower, '[', $start_pos + 1);
                if ($end_pos > $start_pos and ($next_tag === false or $end_pos < $next_tag)) {
                    $taglength = $end_pos - $start_pos + 1;
                    $tag = utf8_substr($content, $start_pos, $taglength);
                    $parms = explode(' ', $tag);
                    // Extra test to see if autotag was entered with a space
                    // after the module name
                    if (utf8_substr($parms[0], -1) == ':') {
                        $startpos = utf8_strlen($parms[0]) + utf8_strlen($parms[1]) + 2;
                        $label = str_replace(']', '', utf8_substr($tag, $startpos));
                        $tagid = $parms[1];
                    } else {
                        $label = str_replace(']', '', utf8_substr($tag, utf8_strlen($parms[0]) + 1));
                        $parms = explode(':', $parms[0]);
                        if (count($parms) > 2) {
                            // whoops, there was a ':' in the tag id ...
                            array_shift($parms);
                            $tagid = implode(':', $parms);
                        } else {
                            $tagid = $parms[1];
                        }
                    }
                    $newtag = array('module' => $module, 'tag' => $moduletag, 'tagstr' => $tag, 'startpos' => $start_pos, 'length' => $taglength, 'parm1' => str_replace(']', '', $tagid), 'parm2' => $label);
                    $tags[] = $newtag;
                } else {
                    // Error: tags do not match - return with no changes
                    return $content . $LANG32[32];
                }
                $prev_offset = $offset;
                $offset = $end_pos;
            }
        }
    }
    // If we have found 1 or more AutoLink tag
    if (count($tags) > 0) {
        // Found the [tag] - Now process them all
        $recursionCount++;
        foreach ($tags as $autotag) {
            $permCheck = $autotag['tag'] . $postFix;
            if (empty($postFix) || !isset($autoTagUsage[$permCheck]) || $autoTagUsage[$permCheck] == 1) {
                $function = 'plugin_autotags_' . $autotag['module'];
                if ($autotag['module'] == 'glfusion' and (empty($plugin) or $plugin == 'glfusion')) {
                    $url = '';
                    $linktext = $autotag['parm2'];
                    if ($autotag['tag'] == 'story') {
                        $autotag['parm1'] = COM_applyFilter($autotag['parm1']);
                        $url = COM_buildUrl($_CONF['site_url'] . '/article.php?story=' . $autotag['parm1']);
                        if (empty($linktext)) {
                            $linktext = DB_getItem($_TABLES['stories'], 'title', "sid = '" . DB_escapeString($autotag['parm1']) . "'");
                        }
                    }
                    if (!empty($url)) {
                        $filelink = COM_createLink($linktext, $url);
                        $content = str_replace($autotag['tagstr'], $filelink, $content);
                    }
                    if ($autotag['tag'] == 'story_introtext') {
                        $url = '';
                        $linktext = '';
                        USES_lib_story();
                        if (isset($_USER['uid']) && $_USER['uid'] > 1) {
                            $result = DB_query("SELECT maxstories,tids,aids FROM {$_TABLES['userindex']} WHERE uid = {$_USER['uid']}");
                            $U = DB_fetchArray($result);
                        } else {
                            $U['maxstories'] = 0;
                            $U['aids'] = '';
                            $U['tids'] = '';
                        }
                        $sql = " (date <= NOW()) AND (draft_flag = 0)";
                        if (empty($topic)) {
                            $sql .= COM_getLangSQL('tid', 'AND', 's');
                        }
                        $sql .= COM_getPermSQL('AND', 0, 2, 's');
                        if (!empty($U['aids'])) {
                            $sql .= " AND s.uid NOT IN (" . str_replace(' ', ",", $U['aids']) . ") ";
                        }
                        if (!empty($U['tids'])) {
                            $sql .= " AND s.tid NOT IN ('" . str_replace(' ', "','", $U['tids']) . "') ";
                        }
                        $sql .= COM_getTopicSQL('AND', 0, 's') . ' ';
                        $userfields = 'u.uid, u.username, u.fullname';
                        $msql = "SELECT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t WHERE s.sid = '" . $autotag['parm1'] . "' AND (s.uid = u.uid) AND (s.tid = t.tid) AND" . $sql;
                        $result = DB_query($msql);
                        $nrows = DB_numRows($result);
                        if ($A = DB_fetchArray($result)) {
                            $story = new Story();
                            $story->loadFromArray($A);
                            $linktext = STORY_renderArticle($story, 'y');
                        }
                        $content = str_replace($autotag['tagstr'], $linktext, $content);
                    }
                    if ($autotag['tag'] == 'showblock') {
                        $blockName = COM_applyBasicFilter($autotag['parm1']);
                        $result = DB_query("SELECT * FROM {$_TABLES['blocks']} WHERE name = '" . DB_escapeString($blockName) . "'" . COM_getPermSQL('AND'));
                        if (DB_numRows($result) > 0) {
                            $skip = 0;
                            $B = DB_fetchArray($result);
                            $template = '';
                            $side = '';
                            $px = explode(' ', trim($autotag['parm2']));
                            if (is_array($px)) {
                                foreach ($px as $part) {
                                    if (substr($part, 0, 9) == 'template:') {
                                        $a = explode(':', $part);
                                        $template = $a[1];
                                        $skip++;
                                    } elseif (substr($part, 0, 5) == 'side:') {
                                        $a = explode(':', $part);
                                        $side = $a[1];
                                        $skip++;
                                        break;
                                    }
                                }
                                if ($skip != 0) {
                                    if (count($px) > $skip) {
                                        for ($i = 0; $i < $skip; $i++) {
                                            array_shift($px);
                                        }
                                        $caption = trim(implode(' ', $px));
                                    } else {
                                        $caption = '';
                                    }
                                }
                            }
                            if ($template != '') {
                                $_BLOCK_TEMPLATE[$blockName] = 'blockheader-' . $template . '.thtml,blockfooter-' . $template . '.thtml';
                            }
                            if ($side == 'left') {
                                $B['onleft'] = 1;
                            } else {
                                if ($side == 'right') {
                                    $B['onleft'] = 0;
                                }
                            }
                            $linktext = COM_formatBlock($B);
                            $content = str_replace($autotag['tagstr'], $linktext, $content);
                        } else {
                            $content = str_replace($autotag['tagstr'], '', $content);
                        }
                    }
                    if ($autotag['tag'] == 'menu') {
                        $menu = '';
                        $menuID = trim($autotag['parm1']);
                        $menuHTML = displayMenu($menuID);
                        $content = str_replace($autotag['tagstr'], $menuHTML, $content);
                    }
                    if (isset($_AUTOTAGS[$autotag['tag']])) {
                        $content = autotags_autotag('parse', $content, $autotag);
                    }
                } else {
                    if (function_exists($function) and (empty($plugin) or $plugin == $autotag['module'])) {
                        $content = $function('parse', $content, $autotag);
                    }
                }
            }
        }
        $recursionCount--;
    }
    return $content;
}
Пример #4
0
function MYCALJP_showStoriesIntro()
{
    global $_CONF, $_TABLES, $_MYCALJP2_CONF;
    if (!$_MYCALJP2_CONF['showstoriesintro']) {
        return '';
    }
    $retval = '';
    $_dateStart = COM_applyFilter($_GET['datestart']);
    $_dateEnd = COM_applyFilter($_GET['dateend']);
    if (!empty($_dateStart) && !empty($_dateEnd)) {
        $ds = explode("-", $_dateStart);
        $de = explode("-", $_dateEnd);
        $startdate = mktime(0, 0, 0, $ds[1], $ds[2], $ds[0]);
        $enddate = mktime(23, 59, 59, $de[1], $de[2], $de[0]);
        $sql = "AND (UNIX_TIMESTAMP(date) BETWEEN '{$startdate}' AND '{$enddate}') ";
    }
    $sql .= "AND (draft_flag = 0) ";
    $sql .= COM_getPermSQL('AND', 0, 2, 's') . ' ';
    $sql .= COM_getTopicSQL('AND', 0, 'ta') . ' ';
    $sql .= COM_getLangSQL('sid', 'AND', 's') . ' ';
    $userfields = 'u.username, u.fullname';
    if ($_CONF['allow_user_photo'] == 1) {
        $userfields .= ', u.photo';
        if ($_CONF['use_gravatar']) {
            $userfields .= ', u.email';
        }
    }
    $msql = array();
    $msql['mysql'] = "SELECT DISTINCT STRAIGHT_JOIN s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . "UNIX_TIMESTAMP(s.expire) AS expireunix, " . $userfields . ", t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, " . "{$_TABLES['topics']} AS t, {$_TABLES['topic_assignments']} AS ta " . "WHERE (ta.type = 'article') AND (ta.tdefault = 1) AND (s.uid = u.uid) AND (ta.tid = t.tid) AND (s.sid = ta.id) " . $sql . "ORDER BY featured DESC, date DESC";
    /*
        $msql['mssql']="SELECT STRAIGHT_JOIN s.sid, s.uid, s.draft_flag, s.tid, s.date, s.title, cast(s.introtext as text) as introtext, cast(s.bodytext as text) as bodytext, s.hits, s.numemails, s.comments, s.trackbacks, s.related, s.featured, s.show_topic_icon, s.commentcode, s.trackbackcode, s.statuscode, s.expire, s.postmode, s.frontpage, s.in_transit, s.owner_id, s.group_id, s.perm_owner, s.perm_group, s.perm_members, s.perm_anon, s.advanced_editor_mode, "
                 . " UNIX_TIMESTAMP(s.date) AS unixdate, "
                 . 'UNIX_TIMESTAMP(s.expire) as expireunix, '
                 . $userfields . ", t.topic, t.imageurl "
                 . "FROM {$_TABLES['stories']} AS s, {$_TABLES['users']} AS u, "
                 . "{$_TABLES['topics']} AS t, {$_TABLES['topic_assignments']} AS ta "
                 . "WHERE (ta.type = 'article') AND (ta.tdefault = 1) AND (s.uid = u.uid) AND (ta.tid = t.tid) AND (s.sid = ta.id) "
                 . $sql . "ORDER BY featured DESC, date DESC";
    */
    $result = DB_query($msql);
    require_once $_CONF['path_system'] . 'lib-story.php';
    $story = new Story();
    while ($A = DB_fetchArray($result)) {
        $story->loadFromArray($A);
        $retval .= STORY_renderArticle($story, 'y');
    }
    return $retval;
}
Пример #5
0
/**
 * Continues a session - handles timeout, looping, etc.
 *
 * @parm    char    session id to continue
 * @parm    int     number of items to process per run
 *                  0 indicates initial run
 * @return  char    HTML of status screen
 */
function MG_continueSession($session_id, $item_limit, $refresh_rate)
{
    global $MG_albums, $_CONF, $_MG_CONF, $_TABLES, $_USER, $LANG_MG00, $LANG_MG01, $LANG_MG02, $HTTP_SERVER_VARS;
    global $new_media_id, $_GKCONST;
    $retval = '';
    $cycle_start_time = time();
    $temp_time = array();
    $timer_expired = false;
    $num_rows = 0;
    $session_id = COM_applyFilter($session_id);
    // Pull the session status info
    $sql = "SELECT * FROM {$_TABLES['mg_sessions']} WHERE session_id='" . DB_escapeString($session_id) . "'";
    $result = DB_query($sql, 1);
    if (DB_error()) {
        COM_errorLog("MediaGallery:  Error - Unable to retrieve batch session data");
        return '';
    }
    $nRows = DB_numRows($result);
    if ($nRows > 0) {
        $session = DB_fetchArray($result);
    } else {
        COM_errorLog("MediaGallery: Error - Unable to find batch session id");
        return '';
        // no session found
    }
    // security check - make sure we are continuing a session that we own...
    if ($session['session_uid'] != $_USER['uid'] && !$MG_albums[0]->owner_id) {
        $display .= COM_startBlock('', '', COM_getBlockTemplate('_admin_block', 'header'));
        $T = new Template(MG_getTemplatePath(0));
        $T->set_file('admin', 'error.thtml');
        $T->set_var('site_url', $_CONF['site_url']);
        $T->set_var('site_admin_url', $_CONF['site_admin_url']);
        $T->set_var('errormessage', $LANG_MG00['access_denied_msg']);
        $T->parse('output', 'admin');
        $display .= $T->finish($T->get_var('output'));
        $display .= COM_endBlock(COM_getBlockTemplate('_admin_block', 'footer'));
        $display .= MG_siteFooter();
        return $display;
    }
    // Setup timer information
    $time_limit = $_MG_CONF['def_time_limit'];
    @set_time_limit($time_limit + 20);
    // get execution time
    $max_execution_time = ini_get('max_execution_time');
    if ($time_limit > $max_execution_time) {
        $time_limit = $max_execution_time;
    }
    $label = $session['session_description'];
    // Pull the detail data from the sessions_items table...
    $sql = "SELECT * FROM {$_TABLES['mg_session_items']} WHERE session_id='" . DB_escapeString($session_id) . "' AND status=0 LIMIT " . $item_limit;
    $result = DB_query($sql);
    while (($row = DB_fetchArray($result)) && $timer_expired == false) {
        // used for calculating loop duration and changing the timer condition
        $start_temp_time = time();
        switch ($session['session_action']) {
            case 'watermark':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-watermark.php';
                MG_watermarkBatchProcess($row['aid'], $row['mid']);
                break;
            case 'rebuildthumb':
                $makeSquare = 0;
                $aid = $row['aid'];
                $srcImage = $row['data'];
                $imageThumb = $row['data2'];
                $mimeExt = $row['data3'];
                $mimeType = $row['mid'];
                if ($MG_albums[$aid]->tn_size == 3 || $MG_albums[$aid]->tn_size == 4) {
                    $tnHeight = $MG_albums[$aid]->tnHeight;
                    $tnWidth = $MG_albums[$aid]->tnWidth;
                    if ($MG_albums[$aid]->tn_size == 4) {
                        $makeSquare = 1;
                    }
                } else {
                    if ($_MG_CONF['thumbnail_actual_size'] == 1) {
                        switch ($MG_albums[$aid]->tn_size) {
                            case 0:
                                $tnHeight = 100;
                                $tnWidth = 100;
                                break;
                            case 1:
                                $tnHeight = 150;
                                $tnWidth = 150;
                                break;
                            default:
                                $tnHeight = 200;
                                $tnWidth = 200;
                                break;
                        }
                    } else {
                        $tnHeight = 200;
                        $tnWidth = 200;
                    }
                }
                $tmpImage = '';
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd') {
                    $tmpImage = $_MG_CONF['tmp_path'] . '/wip' . rand() . '.jpg';
                    $rc = IMG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
                    if ($rc == false) {
                        COM_errorLog("MG_convertImage: Error converting uploaded image to jpeg format.");
                        @unlink($srcImage);
                        return false;
                    }
                    if ($makeSquare == 1) {
                        $rc = IMG_squareThumbnail($tmpImage, $imageThumb, $tnWidth, $mimeType, 0);
                    } else {
                        $rc = IMG_resizeImage($tmpImage, $imageThumb, $tnHeight, $tnWidth, $mimeType, 0);
                    }
                } else {
                    if ($makeSquare == 1) {
                        $rc = IMG_squareThumbnail($srcImage, $imageThumb, $tnWidth, $mimeType, 0);
                    } else {
                        $rc = IMG_resizeImage($srcImage, $imageThumb, $tnHeight, $tnWidth, $mimeType, 0);
                    }
                }
                if ($rc == false) {
                    COM_errorLog("MG_convertImage: Error resizing uploaded image to thumbnail size.");
                    @unlink($srcImage);
                }
                break;
            case 'rebuilddisplay':
                $srcImage = $row['data'];
                $imageDisplay = $row['data2'];
                $mimeExt = $row['data3'];
                $mimeType = $row['mid'];
                $aid = $row['aid'];
                $imgsize = @getimagesize("{$srcImage}");
                $imgwidth = $imgsize[0];
                $imgheight = $imgsize[1];
                $tmpImage = '';
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga' || $mimeType == 'image/photoshop' || $mimeType == 'image/x-photoshop' || $mimeType == 'image/psd' || $mimeType == 'application/photoshop' || $mimeType == 'application/psd' || $mimeType == 'image/tiff') {
                    $tmpImage = $_MG_CONF['tmp_path'] . '/wip' . rand() . '.jpg';
                    list($rc, $msg) = IMG_convertImageFormat($srcImage, $tmpImage, 'image/jpeg', 0);
                    if ($rc == false) {
                        COM_errorLog("MG_libBatch: Error converting uploaded image to jpeg format.");
                    }
                }
                switch ($MG_albums[$aid]->display_image_size) {
                    case 0:
                        $dImageWidth = 500;
                        $dImageHeight = 375;
                        break;
                    case 1:
                        $dImageWidth = 600;
                        $dImageHeight = 450;
                        break;
                    case 2:
                        $dImageWidth = 620;
                        $dImageHeight = 465;
                        break;
                    case 3:
                        $dImageWidth = 720;
                        $dImageHeight = 540;
                        break;
                    case 4:
                        $dImageWidth = 800;
                        $dImageHeight = 600;
                        break;
                    case 5:
                        $dImageWidth = 912;
                        $dImageHeight = 684;
                        break;
                    case 6:
                        $dImageWidth = 1024;
                        $dImageHeight = 768;
                        break;
                    case 7:
                        $dImageWidth = 1152;
                        $dImageHeight = 804;
                        break;
                    case 8:
                        $dImageWidth = 1280;
                        $dImageHeight = 1024;
                        break;
                    case 9:
                        $dImageWidth = $_MG_CONF['custom_image_width'];
                        $dImageHeight = $_MG_CONF['custom_image_height'];
                        break;
                    default:
                        $dImageWidth = 620;
                        $dImageHeight = 465;
                        break;
                }
                if ($imgsize == false || $imgwidth == 0 || $imgheight == 0) {
                    $imgwidth = $dImageWidth;
                    $imgheight = $dImageHeight;
                }
                if ($mimeType == 'image/x-targa' || $mimeType == 'image/tga') {
                    $fp = @fopen($srcImage, 'rb');
                    if ($fp == false) {
                        $imgwidth = 0;
                        $imgheight = 0;
                    } else {
                        $data = fread($fp, filesize($srcImage));
                        fclose($fp);
                        $imgwidth = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
                        $imgheight = base_convert(bin2hex(strrev(substr($data, 12, 2))), 16, 10);
                    }
                }
                if ($tmpImage != '') {
                    list($rc, $msg) = IMG_resizeImage($tmpImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0);
                } else {
                    list($rc, $msg) = IMG_resizeImage($srcImage, $imageDisplay, $dImageHeight, $dImageWidth, $mimeType, 0);
                }
                if ($tmpImage != '') {
                    @unlink($tmpImage);
                }
                break;
            case 'droporiginal':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                if ($_MG_CONF['jhead_enabled'] == 1) {
                    UTL_execWrapper('"' . $_MG_CONF['jhead_path'] . "/jhead" . '"' . " -te " . $row['data'] . " " . $row['data2']);
                }
                @unlink($row['data']);
                break;
            case 'rotate':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/rotate.php';
                MG_rotateMedia($row['aid'], $row['mid'], $row['data'], -1);
                break;
            case 'delete':
                break;
            case 'upgrade':
                break;
            case 'import':
                break;
            case 'ftpimport2':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = intval($row['data2']);
                $baseSrcFile = $row['data3'];
                // basefilename
                $directory = $row['mid'];
                if ($directory == 1) {
                    require_once $_CONF['path'] . 'plugins/mediagallery/include/albumedit.php';
                    $new_aid = MG_quickCreate($album_id, $baseSrcFile);
                    $dir = $srcFile;
                    if (!($dh = @opendir($dir))) {
                        COM_errorLog("Media Gallery: Error - unable process FTP import directory " . $dir);
                    } else {
                        while (($file = readdir($dh)) != false) {
                            if ($file == '..' || $file == '.') {
                                continue;
                            }
                            if ($file == 'Thumbs.db' || $file == 'thumbs.db') {
                                continue;
                            }
                            $filetmp = $dir . '/' . $file;
                            if (is_dir($filetmp)) {
                                $mid = 1;
                            } else {
                                $mid = 0;
                            }
                            $filename = basename($file);
                            $file_extension = strtolower(substr(strrchr($filename, "."), 1));
                            DB_query("INSERT INTO {$_TABLES['mg_session_items']} (session_id,mid,aid,data,data2,data3,status)\n                                      VALUES('" . DB_escapeString($session_id) . "','" . DB_escapeString($mid) . "',{$new_aid},'" . DB_escapeString($filetmp) . "','" . DB_escapeString($purgefiles) . "','" . DB_escapeString($filename) . "',0)");
                            if (DB_error()) {
                                COM_errorLog("Media Gallery: Error - SQL error on inserting record into session_items table");
                            }
                        }
                    }
                } else {
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, '', '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                }
                break;
            case 'galleryimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $baseSrcFile = $row['data2'];
                // basefilename
                $views = (int) $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . ",media_user_id='" . $MG_albums[$album_id]->owner_id . "' WHERE media_id='" . $new_media_id . "'");
                $sql = "SELECT * FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id'];
                $gcmtResult2 = DB_query($sql);
                $cRows = DB_numRows($gcmtResult2);
                for ($z = 0; $z < $cRows; $z++) {
                    $row2 = DB_fetchArray($gcmtResult2);
                    $row2['sid'] = $new_media_id;
                    $row2['type'] = 'mediagallery';
                    $cmtTitle = 'Gallery Comment';
                    $cmtText = $row2['data3'];
                    $cmtDate = (int) $row2['data4'];
                    $cmtIP = $row2['data5'];
                    $cmtUid = 1;
                    if ($row2['data1'] != '' && $row2['data1'] != 'everyone') {
                        $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'data1'])) . "'";
                        $uResult = DB_query($sql);
                        $uRows = DB_numRows($uResult);
                        if ($uRows > 0) {
                            $uRow = DB_fetchArray($uResult);
                            $cmtUid = $uRow['uid'];
                        }
                    }
                    $cmtDate = gmdate("Y-m-d H:i:s", $row2['data4']);
                    MG_saveComment($cmtTitle, $cmtText, $row2['sid'], 0, $row2['type'], 'plain', $cmtUid, $cmtDate, $cmtIP);
                }
                $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                DB_query("DELETE FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id']);
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'coppermineimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $sdata = unserialize($row['mid']);
                $views = (int) $sdata[0];
                $uid = (int) $sdata[1];
                $purgefiles = 0;
                $file = basename($row['data']);
                $baseSrcFile = $file;
                $baseSrcFile = MG_replace_accents($baseSrcFile);
                $baseSrcFile = preg_replace("#[ ]#", "_", $baseSrcFile);
                // change spaces to underscore
                $baseSrcFile = preg_replace('#[^()\\.\\-,\\w]#', '_', $baseSrcFile);
                //only parenthesis, underscore, letters, numbers, comma, hyphen, period - others to underscore
                $baseSrcFile = preg_replace('#(_)+#', '_', $baseSrcFile);
                //eliminate duplicate underscore
                $caption = $row['data3'];
                $description = $row['data2'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('{$session_id}','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, $description, 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                if ($rc == true) {
                    $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'";
                    $userResult = DB_query($sql);
                    $userRows = DB_numRows($userResult);
                    if ($userRows > 0) {
                        $userRow = DB_fetchArray($userResult);
                        $glUid = $userRow['uid'];
                    } else {
                        $glUid = 1;
                    }
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . ",media_user_id='" . $glUid . "' WHERE media_id='" . $new_media_id . "'");
                    $sql = "SELECT * FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id'];
                    $gcmtResult2 = DB_query($sql);
                    $cRows = DB_numRows($gcmtResult2);
                    for ($z = 0; $z < $cRows; $z++) {
                        $row2 = DB_fetchArray($gcmtResult2);
                        $row2['sid'] = $new_media_id;
                        $row2['type'] = 'mediagallery';
                        $cmtTitle = 'Coppermine Comment';
                        $cmtText = $row2['data3'];
                        $cmtDate = (int) $row2['data4'];
                        $cmtIP = $row2['data5'];
                        $cmtUid = 1;
                        if ($row2['data1'] != '' && $row2['data1'] != 'everyone') {
                            $sql = "SELECT uid FROM {$_TABLES['users']} WHERE username='******'data1']))) . "'";
                            $uResult = DB_query($sql);
                            $uRows = DB_numRows($uResult);
                            if ($uRows > 0) {
                                $uRow = DB_fetchArray($uResult);
                                $cmtUid = $uRow['uid'];
                            }
                        }
                        $cmtDate = $row2['data4'];
                        // gmdate("Y-m-d H:i:s", $row2['data4']);
                        MG_saveComment($cmtTitle, $cmtText, $row2['sid'], 0, $row2['type'], 'plain', $cmtUid, $cmtDate, $cmtIP);
                    }
                    $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                    DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                }
                DB_query("DELETE FROM {$_TABLES['mg_session_items2']} WHERE id=" . $row['id']);
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'gallery2import':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $baseSrcFile = $row['data2'];
                // basefilename
                $views = 0;
                // $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('{$session_id}','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . $new_media_id . "'");
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case '4imagesimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $srcFile = $row['data'];
                // full path
                $album_id = $row['aid'];
                $purgefiles = 0;
                $title = $row['data2'];
                $baseSrcFile = basename($row['data']);
                $views = (int) $row['mid'];
                $caption = $row['data3'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', '', 0, 0, 0);
                DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                @set_time_limit($time_limit + 20);
                break;
            case 'inmemoriamimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                global $INM_TABLES;
                $album_id = $row['aid'];
                $inm_mid = $row['mid'];
                $album_path = $row['data'];
                $inmResult = DB_query("SELECT * FROM {$INM_TABLES['media']} WHERE mid='" . DB_escapeString($inm_mid) . "'");
                $inmNumRows = DB_numRows($inmResult);
                if ($inmNumRows > 0) {
                    $M = DB_fetchArray($inmResult);
                    $srcFile = $album_path . $M['filename'];
                    $baseSrcFile = $M['filename'];
                    $views = (int) $M['hits'];
                    $caption = $M['caption'];
                    $keywords = $M['keywords'];
                    $date = $M['date'];
                    $title = $M['title'];
                    $purgefiles = 0;
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', $keywords, 0, 0, 0);
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                    $sql = "SELECT * FROM {$_TABLES['comments']} WHERE sid='" . $row['mid'] . "' AND type='inmemoriam'";
                    $inmResult2 = DB_query($sql);
                    $cRows = DB_numRows($inmResult2);
                    for ($z = 0; $z < $cRows; $z++) {
                        $row2 = DB_fetchArray($inmResult2);
                        $row2['sid'] = $new_media_id;
                        $row2['type'] = 'mediagallery';
                        MG_saveComment($row2['title'], $row2['comment'], $row2['sid'], 0, $row2['type'], 'plain', $row2['uid'], $row2['date']);
                        $comments = DB_count($_TABLES['comments'], array('sid', 'type'), array($new_media_id, 'mediagallery'));
                        DB_change($_TABLES['mg_media'], 'media_comments', $comments, 'media_id', $new_media_id);
                    }
                    // now do the rating...
                    if ($row['totalrating'] > 0) {
                        $rating = $row['totalrating'] / $row['numvotes'];
                        $new_rating = sprintf("%.2f", $rating);
                        $votes = $row['numvotes'];
                        $sql = "UPDATE {$_TABLES['mg_media']} SET media_votes = {$votes}, media_rating = '{$rating}'\n                                        WHERE media_id='" . DB_escapeString($new_media_id) . "'";
                        DB_query($sql);
                    }
                }
                break;
            case 'geekaryimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                $album_id = $row['aid'];
                $inm_mid = $row['mid'];
                $gk_album_id = $row['data2'];
                $album_path = $_GKCONST['full_geekage'];
                $inmResult = DB_query("SELECT * FROM {$_TABLES['geekary_images']} WHERE id='" . DB_escapeString($inm_mid) . "'");
                $inmNumRows = DB_numRows($inmResult);
                if ($inmNumRows > 0) {
                    $M = DB_fetchArray($inmResult);
                    $srcFile = $album_path . '/' . $gk_album_id . '/' . $M['file_name'];
                    $baseSrcFile = $M['file_name'];
                    $views = (int) $M['hits'];
                    $caption = $M['description'];
                    $title = $M['name'];
                    $purgefiles = 0;
                    $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                    if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                        COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                        $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                        DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                        continue;
                    }
                    //This will set the Content-Type to the appropriate setting for the file
                    switch ($file_extension) {
                        case "exe":
                            $filetype = "application/octet-stream";
                            break;
                        case "zip":
                            $filetype = "application/zip";
                            break;
                        case "mp3":
                            $filetype = "audio/mpeg";
                            break;
                        case "mpg":
                            $filetype = "video/mpeg";
                            break;
                        case "avi":
                            $filetype = "video/x-msvideo";
                            break;
                        default:
                            $filetype = "application/force-download";
                    }
                    list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $title, $caption, 0, $purgefiles, $filetype, 0, '', $keywords, 0, 0, 0);
                    DB_query("UPDATE {$_TABLES['mg_media']} SET media_views=" . (int) $views . " WHERE media_id='" . DB_escapeString($new_media_id) . "'");
                    $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    MG_SortMedia($album_id);
                    @set_time_limit($time_limit + 20);
                }
                break;
            case 'gl_storyimport':
                require_once $_CONF['path'] . 'plugins/mediagallery/include/lib-upload.php';
                require_once $_CONF['path'] . 'plugins/mediagallery/include/sort.php';
                require_once $_CONF['path_system'] . 'lib-story.php';
                require_once $_CONF['path_system'] . 'classes/story.class.php';
                $album_id = $row['aid'];
                $srcFile = $row['data'];
                $baseSrcFile = basename($row['data']);
                $sid = $row['data3'];
                $purgefiles = 0;
                $caption = '';
                $imageNumber = $row['data2'];
                $file_extension = strtolower(substr(strrchr($baseSrcFile, "."), 1));
                if ($MG_albums[$album_id]->max_filesize != 0 && filesize($srcFile) > $MG_albums[$album_id]->max_filesize) {
                    COM_errorLog("MediaGallery: File " . $baseSrcFile . " exceeds maximum filesize for this album.");
                    $statusMsg = DB_escapeString(sprintf($LANG_MG02['upload_exceeds_max_filesize'], $baseSrcFile));
                    DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                    continue;
                }
                //This will set the Content-Type to the appropriate setting for the file
                switch ($file_extension) {
                    case "exe":
                        $filetype = "application/octet-stream";
                        break;
                    case "zip":
                        $filetype = "application/zip";
                        break;
                    case "mp3":
                        $filetype = "audio/mpeg";
                        break;
                    case "mpg":
                        $filetype = "video/mpeg";
                        break;
                    case "avi":
                        $filetype = "video/x-msvideo";
                        break;
                    default:
                        $filetype = "application/force-download";
                }
                list($rc, $msg) = MG_getFile($srcFile, $baseSrcFile, $album_id, $caption, '', 0, $purgefiles, $filetype, 0, '', $mid, 0, 0, 0);
                $mid = $new_media_id;
                $statusMsg = DB_escapeString($baseSrcFile . " " . $msg);
                DB_query("INSERT INTO {$_TABLES['mg_session_log']} (session_id,session_log) VALUES ('" . DB_escapeString($session_id) . "','{$statusMsg}')");
                MG_SortMedia($album_id);
                // now update the tag in the article...
                $sResult = DB_query("SELECT * FROM {$_TABLES['stories']} WHERE sid='" . DB_escapeString($sid) . "'");
                $howmany = DB_numRows($sResult);
                $S = DB_fetchArray($sResult);
                $story = new Story();
                $story->loadFromArray($S);
                $intro = $story->replaceImages($S['introtext']);
                $body = $story->replaceImages($S['bodytext']);
                $atag = $session['session_var0'];
                $align = $session['session_var1'];
                $delete = $session['session_var2'];
                $norm = '[image' . $imageNumber . ']';
                $left = '[image' . $imageNumber . '_left]';
                $right = '[image' . $imageNumber . '_right]';
                $mg_norm = '[' . $atag . ':' . $mid . ' align:' . $align . ']';
                $mg_left = '[' . $atag . ':' . $mid . ' align:left]';
                $mg_right = '[' . $atag . ':' . $mid . ' align:right]';
                $intro = str_replace($norm, $mg_norm, $intro);
                $body = str_replace($norm, $mg_norm, $body);
                $intro = str_replace($left, $mg_left, $intro);
                $body = str_replace($left, $mg_left, $body);
                $intro = str_replace($right, $mg_right, $intro);
                $body = str_replace($right, $mg_right, $body);
                $norm = '[unscaled' . $imageNumber . ']';
                $left = '[unscaled' . $imageNumber . '_left]';
                $right = '[unscaled' . $imageNumber . '_right]';
                $mg_norm = '[oimage:' . $mid . ' align:' . $align . ']';
                $mg_left = '[oimage:' . $mid . ' align:left]';
                $mg_right = '[oimage:' . $mid . ' align:right]';
                $intro = str_replace($norm, $mg_norm, $intro);
                $body = str_replace($norm, $mg_norm, $body);
                $intro = str_replace($left, $mg_left, $intro);
                $body = str_replace($left, $mg_left, $body);
                $intro = str_replace($right, $mg_right, $intro);
                $body = str_replace($right, $mg_right, $body);
                DB_query("UPDATE {$_TABLES['stories']} SET introtext='" . DB_escapeString($intro) . "', bodytext='" . DB_escapeString($body) . "' WHERE sid='" . $sid . "'");
                if ($delete == 1) {
                    $sql = "DELETE FROM {$_TABLES['article_images']} WHERE ai_sid='" . DB_escapeString($sid) . "'";
                    DB_query($sql);
                }
                @set_time_limit($time_limit + 20);
                break;
            default:
                // no valid action defined...
                break;
        }
        DB_query("UPDATE {$_TABLES['mg_session_items']} SET status=1 WHERE id=" . $row['id']);
        // calculate time for each loop iteration
        $temp_time[$num_rows] = time() - $start_temp_time;
        // get the max
        $timer_time = max($temp_time);
        $num_rows++;
        // check if timer is about to expire
        if (time() - $cycle_start_time >= $time_limit - $timer_time) {
            $timer_expired_secs = time() - $cycle_start_time;
            $timer_expired = true;
        }
    }
    // end the timer
    $cycle_end_time = time();
    // find how much time the last cycle took
    $last_cycle_time = $cycle_end_time - $cycle_start_time;
    $T = new Template(MG_getTemplatePath(0));
    $T->set_file('batch', 'batch_progress.thtml');
    $processing_messages = '<span style="font-weight:bold;">';
    $processing_messages .= $timer_expired ? sprintf($LANG_MG01['timer_expired'], $timer_expired_secs) : '';
    $processing_messages .= '</span>';
    $sql = "SELECT COUNT(*) as processed FROM {$_TABLES['mg_session_items']} WHERE session_id='" . $session_id . "' AND status=1";
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $session_items_processed = $row['processed'];
    $sql = "SELECT COUNT(*) as processing FROM {$_TABLES['mg_session_items']} WHERE session_id='" . $session_id . "'";
    $result = DB_query($sql);
    $row = DB_fetchArray($result);
    $session_items_processing = $row['processing'];
    $items_remaining = $session_items_processing - $session_items_processed;
    if ($items_remaining > 0) {
        if ($item_limit == 0) {
            $processing_messages .= '<b>' . $LANG_MG01['begin_processing'] . '</b>';
            $item_limit = $_MG_CONF['def_item_limit'];
        } else {
            $processing_messages .= sprintf('<b>' . $LANG_MG01['processing_next_items'] . '</b>', $item_limit);
        }
        $form_action = $_MG_CONF['site_url'] . '/batch.php?mode=continue&amp;sid=' . $session_id . '&amp;refresh=' . $refresh_rate . '&amp;limit=' . $item_limit;
        $next_button = $LANG_MG01['next'];
        // create the meta tag for refresh
        $T->set_var(array("META" => '<meta http-equiv="refresh" content="' . $refresh_rate . ';url=' . $form_action . '"/>'));
    } else {
        if ($item_limit == 0) {
            echo COM_refresh($session['session_origin']);
            exit;
        }
        $next_button = $LANG_MG01['finished'];
        $processing_messages .= '<b>' . $LANG_MG01['all_done'] . '</b><br /><br />';
        $T->set_var(array("META" => ''));
        $refresh_rate = -1;
        $form_action = $session['session_origin'];
        $result = DB_query("SELECT * FROM {$_TABLES['mg_session_log']} WHERE session_id='" . $session_id . "'");
        $nRows = DB_numRows($result);
        for ($i = 0; $i < $nRows; $i++) {
            $row = DB_fetchArray($result);
            $processing_messages .= $row['session_log'] . '<br />';
        }
        MG_endSession($session_id);
    }
    $session_percent = $session_items_processed / $session_items_processing * 100;
    $session_time = $cycle_end_time - $session['session_start_time'];
    // create the percent boxes
    $pct_box = _mg_create_percent_box('session', _mg_create_percent_color($session_percent), $session_percent);
    $T->set_var(array('L_BATCH_PROCESS' => $label, 'L_BATCH' => $LANG_MG01['batch_processor'], 'L_NEXT' => $next_button, 'L_PROCESSING' => $LANG_MG01['processing'], 'L_CANCEL' => $LANG_MG01['cancel'], 'L_PROCESSING_DETAILS' => $LANG_MG01['processing_details'], 'L_STATUS' => $LANG_MG01['status'], 'L_TOTAL_ITEMS' => $LANG_MG01['total_items'], 'L_ITEMS_PROCESSED' => $LANG_MG01['processed_items'], 'L_ITEMS_REMAINING' => $LANG_MG01['items_remaining'], 'L_POSTS_LAST_CYCLE' => $LANG_MG01['items_last_cycle'], 'L_TIME_LIMIT' => $LANG_MG01['time_limit'], 'L_REFRESH_RATE' => $LANG_MG01['refresh_rate'], 'L_ITEM_RATE' => $LANG_MG01['item_rate'], 'L_ACTIVE_PARAMETERS' => $LANG_MG01['batch_parameters'], 'L_ITEMS_PER_CYCLE' => $LANG_MG01['items_per_cycle'], 'TOTAL_ITEMS' => $session_items_processing, 'ITEMS_PROCESSED' => $session_items_processed, 'ITEMS_REMAINING' => $session_items_processing - $session_items_processed, 'ITEM_RATE' => sprintf($LANG_MG01['seconds_per_item'], round(@($last_cycle_time / $num_rows))), 'PROCESSING_MESSAGES' => $processing_messages, 'SESSION_PERCENT_BOX' => $pct_box, 'SESSION_PERCENT' => sprintf($LANG_MG01['percent_completed'], round($session_percent, 2)), 'POST_LIMIT' => $num_rows, 'ITEM_LIMIT' => $item_limit, 'TIME_LIMIT' => $time_limit, 'REFRESH_RATE' => $refresh_rate, 'PERCENT_COMPLETE' => $session_percent, 'S_BATCH_ACTION' => $form_action));
    $T->parse('output', 'batch');
    $retval .= $T->finish($T->get_var('output'));
    return $retval;
}
Пример #6
0
function MG_buildImportAlbums()
{
    global $mgAlbums, $_TABLES, $_CONF, $_MG_CONF, $_USER;
    $mgalbum = new mgAlbumg();
    $mgalbum->id = 0;
    $mgalbum->title = 'root';
    $mgAlbums[0] = $mgalbum;
    $counter = 1;
    $sql = "SELECT * FROM {$_TABLES['stories']}";
    $result = DB_query($sql);
    $numRows = DB_numRows($result);
    for ($i = 0; $i < $numRows; $i++) {
        $I = DB_fetchArray($result);
        $story = new Story();
        $story->loadFromArray($I);
        $tmpsid = $I['sid'];
        $icount = DB_count($_TABLES['article_images'], 'ai_sid', $tmpsid);
        if ($icount == 0) {
            continue;
        }
        $mgalbum = new mgAlbumg();
        $mgalbum->id = $counter;
        $mgalbum->sid = $I['sid'];
        $mgalbum->title = $I['title'];
        $mgalbum->parent = 0;
        $intro = $story->replaceImages($I['introtext']);
        $body = $story->replaceImages($I['bodytext']);
        //        list($intro,$body) = STORY_replace_images($I['sid'],$I['introtext'],$I['bodytext']);
        list($errors, $intro_notags, $body_notags) = _MG_remove_images($I['sid'], $intro, $body, 'html');
        $mgalbum->description = '';
        //$intro_notags;
        $mgalbum->views = 0;
        $mgalbum->media_count = $icount;
        $mgalbum->owner_id = $I['owner_id'];
        $mgalbum->perm_owner = $I['perm_owner'];
        $mgalbum->perm_group = $I['perm_group'];
        $mgalbum->perm_members = $I['perm_members'];
        $mgalbum->perm_anon = $I['perm_anon'];
        $mgAlbums[$counter] = $mgalbum;
        $counter++;
    }
    foreach ($mgAlbums as $id => $mgalbum) {
        if ($id != 0 && isset($mgAlbums[$mgalbum->parent]->id)) {
            $mgAlbums[$mgalbum->parent]->setChild($id);
        }
    }
    return;
}
Пример #7
0
/**
 * article: display comment(s)
 *
 * @param   string  $id     Unique idenifier for item comment belongs to
 * @param   int     $cid    Comment id to display (possibly including sub-comments)
 * @param   string  $title  Page/comment title
 * @param   string  $order  'ASC' or 'DESC' or blank
 * @param   string  $format 'threaded', 'nested', or 'flat'
 * @param   int     $page   Page number of comments to display
 * @param   boolean $view   True to view comment (by cid), false to display (by $pid)
 * @return  mixed   results of calling the plugin_displaycomment_ function
*/
function plugin_displaycomment_article($id, $cid, $title, $order, $format, $page, $view)
{
    global $_CONF, $_TABLES, $LANG_ACCESS;
    USES_lib_story();
    USES_class_story();
    $retval = '';
    // display story
    $sql = "SELECT s.*, UNIX_TIMESTAMP(s.date) AS unixdate, " . 'UNIX_TIMESTAMP(s.expire) as expireunix, ' . "u.uid, u.username, u.fullname, t.topic, t.imageurl " . "FROM {$_TABLES['stories']} AS s LEFT JOIN {$_TABLES['users']} AS u ON s.uid=u.uid " . "LEFT JOIN {$_TABLES['topics']} AS t on s.tid=t.tid " . "WHERE (sid = '" . DB_escapeString($id) . "') " . 'AND (draft_flag = 0) AND (commentcode >= 0) AND (date <= NOW())' . COM_getPermSQL('AND', 0, 2, 's') . COM_getTopicSQL('AND', 0, 't') . ' GROUP BY sid,owner_id, group_id, perm_owner, s.perm_group,s.perm_members, s.perm_anon ';
    $result = DB_query($sql);
    $nrows = DB_numRows($result);
    if ($A = DB_fetchArray($result)) {
        $story = new Story();
        $story->loadFromArray($A);
        $retval .= STORY_renderArticle($story, 'n');
    }
    // end
    $sql = 'SELECT COUNT(*) AS count, commentcode, uid, owner_id, group_id, perm_owner, perm_group, ' . "perm_members, perm_anon FROM {$_TABLES['stories']} " . "WHERE (sid = '" . DB_escapeString($id) . "') " . 'AND (draft_flag = 0) AND (commentcode >= 0) AND (date <= NOW())' . COM_getPermSQL('AND') . COM_getTopicSQL('AND') . ' GROUP BY sid,owner_id, group_id, perm_owner, perm_group,perm_members, perm_anon ';
    $result = DB_query($sql);
    $B = DB_fetchArray($result);
    $allowed = $B['count'];
    if ($allowed == 1) {
        $delete_option = SEC_hasRights('story.edit') && SEC_hasAccess($B['owner_id'], $B['group_id'], $B['perm_owner'], $B['perm_group'], $B['perm_members'], $B['perm_anon']) == 3;
        $retval .= CMT_userComments($id, $title, 'article', $order, $format, $cid, $page, $view, $delete_option, $B['commentcode'], $B['uid']);
    } else {
        $retval .= COM_showMessageText($LANG_ACCESS['storydenialmsg'], $LANG_ACCESS['accessdenied'], true);
    }
    return $retval;
}