예제 #1
0
function DLM_convertData()
{
    global $_PLUGINS, $_DLM_CONF, $_GROUPS, $_CONF, $_TABLES, $_USER, $_FM_TABLES, $_FM_CONF, $_LANG_CONV, $_SUCCESS;
    $retval = '';
    if (is_readable($_FM_CONF['filemgmt_FileStore'])) {
        $retval .= '<p>' . $_LANG_CONV['readable_fm_file_dir'] . $_FM_CONF['filemgmt_FileStore'] . '</p>' . LB;
    } else {
        $retval .= '<p>' . $_LANG_CONV['unreadable_fm_file_dir'] . $_FM_CONF['filemgmt_FileStore'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    if (is_writeable($_DLM_CONF['path_filestore'])) {
        $retval .= '<p>' . $_LANG_CONV['writeable_dm_file_dir'] . $_DLM_CONF['path_filestore'] . '</p>' . LB;
    } else {
        $retval .= '<p>' . $_LANG_CONV['unwriteable_dm_file_dir'] . $_DLM_CONF['path_filestore'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $sql = "SELECT COUNT(*) FROM {$_TABLES['downloadcategories']}";
    list($count) = DB_fetchArray(DB_query($sql));
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $retval .= '<p>' . $_LANG_CONV['num_dm_cat_data'] . $count . '</p>' . LB;
    if ($count > 0) {
        $retval .= '<p>' . $_LANG_CONV['del_dm_cat_data'] . '</p>' . LB;
        DB_query("DELETE FROM {$_TABLES['downloadcategories']}");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT COUNT(*) FROM {$_TABLES['downloads']}";
    list($count) = DB_fetchArray(DB_query($sql));
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $retval .= '<p>' . $_LANG_CONV['num_dm_info_data'] . $count . '</p>' . LB;
    if ($count > 0) {
        $retval .= '<p>' . $_LANG_CONV['del_dm_info_data'] . '</p>' . LB;
        DB_query("DELETE FROM {$_TABLES['downloads']}");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT COUNT(*) FROM {$_TABLES['downloadvotes']}";
    list($count) = DB_fetchArray(DB_query($sql));
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $retval .= '<p>' . $_LANG_CONV['num_dm_vote_data'] . $count . '</p>' . LB;
    if ($count > 0) {
        $retval .= '<p>' . $_LANG_CONV['del_dm_vote_data'] . '</p>' . LB;
        DB_query("DELETE FROM {$_TABLES['downloadvotes']}");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT COUNT(*) FROM {$_TABLES['downloadhistories']}";
    list($count) = DB_fetchArray(DB_query($sql));
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $retval .= '<p>' . $_LANG_CONV['num_dm_history_data'] . $count . '</p>' . LB;
    if ($count > 0) {
        $retval .= '<p>' . $_LANG_CONV['del_dm_history_data'] . '</p>' . LB;
        DB_query("DELETE FROM {$_TABLES['downloadhistories']}");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT COUNT(*) FROM {$_TABLES['downloadsubmission']}";
    list($count) = DB_fetchArray(DB_query($sql));
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $retval .= '<p>' . $_LANG_CONV['num_dm_submission_data'] . $count . '</p>' . LB;
    if ($count > 0) {
        $retval .= '<p>' . $_LANG_CONV['del_dm_submission_data'] . '</p>' . LB;
        DB_query("DELETE FROM {$_TABLES['downloadsubmission']}");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    if (!$_SUCCESS) {
        return $retval;
    }
    $owner_id = $_USER['uid'];
    if (isset($_GROUPS['Downloads Admin'])) {
        $group_id = $_GROUPS['Downloads Admin'];
    } else {
        $group_id = SEC_getFeatureGroup('downloads.edit');
    }
    SEC_setDefaultPermissions($P, $_DLM_CONF['default_permissions']);
    foreach ($P as $key => $val) {
        ${$key} = $val;
    }
    $sql = "SELECT * FROM {$_FM_TABLES['filemgmt_cat']}";
    $result = DB_query($sql);
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    $corder = 0;
    while ($A = DB_fetchArray($result)) {
        foreach ($A as $key => $val) {
            ${$key} = $val;
        }
        if ($pid == 0) {
            $pid = ROOTID;
        }
        $corder += 10;
        $is_enabled = 1;
        if (!empty($imgurl)) {
            $imgurl = rawurldecode($imgurl);
            $catimg_src = $_FM_CONF['filemgmt_SnapCat'] . $imgurl;
            if (!is_readable($catimg_src)) {
                $retval .= '<p>' . $_LANG_CONV['unable_to_read_catimg'] . $catimg_src . '</p>' . LB;
                $_SUCCESS = false;
                return $retval;
            }
            $catimg_dest = $_DLM_CONF['path_snapcat'] . DLM_createSafeFileName(DLM_createCatImgFilename($imgurl));
            $_SUCCESS = DLM_copyFile_fm2dm($catimg_src, $catimg_dest);
            if (!$_SUCCESS) {
                $retval .= '<p>' . $_LANG_CONV['unable_to_conv_catimg'] . $catimg_src . '</p>' . LB;
                return $retval;
            }
        }
        DB_query("INSERT INTO {$_TABLES['downloadcategories']} " . "(cid, pid, title, imgurl, corder, is_enabled, owner_id, group_id, " . "perm_owner, perm_group, perm_members, perm_anon) " . "VALUES ('{$cid}', '{$pid}', '{$title}', '{$imgurl}', {$corder}, {$is_enabled}, {$owner_id}, {$group_id}, " . "{$perm_owner}, {$perm_group}, {$perm_members}, {$perm_anon})");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT * FROM {$_FM_TABLES['filemgmt_filedetail']}";
    $result = DB_query($sql);
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    while ($A = DB_fetchArray($result)) {
        foreach ($A as $key => $val) {
            ${$key} = $val;
        }
        $project = '';
        $description = '';
        $detail = '';
        $postmode = 'plaintext';
        $commentcode = $comments == 1 ? 0 : -1;
        $is_released = $status;
        $is_listing = $status;
        $createddate = date('Y-m-d H:i:s', $date);
        $owner_id = $submitter;
        $secret_id = md5(uniqid());
        $mg_autotag = '';
        $tags = '';
        $url = rawurldecode($url);
        $src_url = $_FM_CONF['filemgmt_FileStore'] . $url;
        if (!is_readable($src_url)) {
            $retval .= '<p>' . $_LANG_CONV['unable_to_read_dlfile'] . $src_url . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
        $size = filesize($src_url);
        $md5 = md5_file($src_url);
        $dest_url = $_DLM_CONF['path_filestore'] . DLM_createSafeFileName($url, $secret_id);
        $_SUCCESS = DLM_copyFile_fm2dm($src_url, $dest_url);
        if (!$_SUCCESS) {
            $retval .= '<p>' . $_LANG_CONV['unable_to_conv_dlfile'] . $src_url . '</p>' . LB;
            return $retval;
        }
        if (!empty($logourl)) {
            $logourl = rawurldecode($logourl);
            $snap_src = $_FM_CONF['filemgmt_SnapStore'] . $logourl;
            if (!is_readable($snap_src)) {
                $retval .= '<p>' . $_LANG_CONV['unable_to_read_snapimg'] . $snap_src . '</p>' . LB;
                $_SUCCESS = false;
                return $retval;
            }
            $logourl = DLM_createSnapFilename($logourl, $_TABLES['downloads'], 'logourl');
            $snap_dest = $_DLM_CONF['path_snapstore'] . DLM_createSafeFileName($logourl);
            $_SUCCESS = DLM_copyFile_fm2dm($snap_src, $snap_dest);
            if (!$_SUCCESS) {
                $retval .= '<p>' . $_LANG_CONV['unable_to_conv_snapimg'] . $snap_src . '</p>' . LB;
                return $retval;
            }
            $_SUCCESS = DLM_makeThumbnail(DLM_createSafeFileName($logourl));
            if (!$_SUCCESS) {
                $retval .= '<p>' . $_LANG_CONV['unable_to_make_tn'] . $snap_src . '</p>' . LB;
                return $retval;
            }
        }
        DB_query("INSERT INTO {$_TABLES['downloads']} " . "(lid, cid, title, url, homepage, version, size, secret_id, md5, " . "project, description, detail, postmode, logourl, mg_autotag, tags, " . "date, hits, rating, votes, commentcode, is_released, is_listing, createddate, owner_id" . ") " . "VALUES ('{$lid}', '{$cid}', '{$title}', '{$url}', '{$homepage}', '{$version}', '{$size}', '{$secret_id}', '{$md5}', " . "'{$project}', '{$description}', '{$detail}', '{$postmode}', '{$logourl}', '{$mg_autotag}', '{$tags}', " . "{$date}, {$hits}, {$rating}, {$votes}, '{$commentcode}', {$is_released}, {$is_listing}, '{$createddate}', '{$owner_id}'" . ")");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT * FROM {$_FM_TABLES['filemgmt_filedesc']}";
    $result = DB_query($sql);
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    while ($A = DB_fetchArray($result)) {
        foreach ($A as $key => $val) {
            ${$key} = $val;
        }
        $description = addslashes(stripslashes($description));
        $descri = '';
        $detail = '';
        // Search break page position
        $breakPosition = strpos($description, "\r\n\r\n");
        if ($breakPosition > 0 and $breakPosition < strlen($description)) {
            $descri = substr($description, 0, $breakPosition);
            $detail = substr($description, $breakPosition + 4, strlen($description) - $breakPosition - 4);
        } else {
            $breakPosition = strpos($description, "\n\n");
            if ($breakPosition > 0 and $breakPosition < strlen($description)) {
                $descri = substr($description, 0, $breakPosition);
                $detail = substr($description, $breakPosition + 2, strlen($description) - $breakPosition - 2);
            } else {
                $breakPosition = strpos($description, "\r\r");
                if ($breakPosition > 0 and $breakPosition < strlen($description)) {
                    $descri = substr($description, 0, $breakPosition);
                    $detail = substr($description, $breakPosition + 2, strlen($description) - $breakPosition - 2);
                } else {
                    $descri = $description;
                }
            }
        }
        DB_query("UPDATE {$_TABLES['downloads']} " . "SET description='{$descri}', detail='{$detail}' " . "WHERE lid='{$lid}'");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT * FROM {$_FM_TABLES['filemgmt_votedata']}";
    $result = DB_query($sql);
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    while ($A = DB_fetchArray($result)) {
        foreach ($A as $key => $val) {
            ${$key} = $val;
        }
        DB_query("INSERT INTO {$_TABLES['downloadvotes']} " . "(ratingid, lid, ratinguser, rating, ratinghostname, ratingtimestamp) " . "VALUES ('{$ratingid}', '{$lid}', '{$ratinguser}', '{$rating}', '{$ratinghostname}', '{$ratingtimestamp}')");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    $sql = "SELECT * FROM {$_FM_TABLES['filemgmt_history']}";
    $result = DB_query($sql);
    if (DB_error()) {
        $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
        $_SUCCESS = false;
        return $retval;
    }
    while ($A = DB_fetchArray($result)) {
        foreach ($A as $key => $val) {
            ${$key} = $val;
        }
        DB_query("INSERT INTO {$_TABLES['downloadhistories']} " . "(uid, lid, remote_ip, date) " . "VALUES ('{$uid}', '{$lid}', '{$remote_ip}', '{$date}')");
        if (DB_error()) {
            $retval .= '<p>' . $_LANG_CONV['db_error'] . '</p>' . LB;
            $_SUCCESS = false;
            return $retval;
        }
    }
    return $retval;
}
예제 #2
0
function DLM_approveNewDownload($id)
{
    global $_TABLES, $_CONF, $_DLM_CONF;
    $result = DB_query("SELECT url, logourl, date, secret_id " . "FROM {$_TABLES['downloads']} " . "WHERE lid = '" . addslashes($id) . "'");
    list($url, $logourl, $date, $secret_id) = DB_fetchArray($result);
    $safename = DLM_encodeFileName($url);
    $tmpfile = $_DLM_CONF['path_filestore'] . 'tmp' . date('YmdHis', $date) . $safename;
    $newfile = $_DLM_CONF['path_filestore'] . $secret_id . '_' . $safename;
    $success = DLM_moveNewFile($tmpfile, $newfile);
    if ($success && !empty($logourl)) {
        $safename = DLM_encodeFileName($logourl);
        $tmpfile = $_DLM_CONF['path_snapstore'] . 'tmp' . date('YmdHis', $date) . $safename;
        $newfile = $_DLM_CONF['path_snapstore'] . $safename;
        $success = DLM_moveNewFile($tmpfile, $newfile);
        if ($success) {
            DLM_makeThumbnail($safename);
        }
    }
    if ($success) {
        // PLG_itemSaved($lid, 'downloads');
        // COM_rdfUpToDateCheck('downloads', $cid, $lid);
        // Send a email to submitter notifying them that file was approved
        if ($_DLM_CONF['download_emailoption']) {
            DLM_sendNotification($id);
        }
    }
}
예제 #3
0
 function submitNewDownload(&$A)
 {
     global $_CONF, $_TABLES, $_DLM_CONF;
     $this->_initVars();
     $this->_loadFromArgs($A);
     $this->_secret_id = $this->_createSecretID();
     $this->_url = $_FILES['newfile']['name'];
     //        $this->_logourl = $_FILES['newfileshot']['name'];
     if (empty($this->_lid)) {
         $this->_lid = $this->_old_lid;
     }
     // Validate the input values ----------------------->
     if (empty($this->_title)) {
         $this->_errno[] = '1101';
     }
     if (empty($this->_url)) {
         $this->_errno[] = '1102';
     } else {
         if ($this->_lid != $this->_old_lid) {
             $count = DB_count($_TABLES['downloads'], 'lid', addslashes($this->_lid));
             if ($count > 0) {
                 $this->_errno[] = '1202';
             }
         }
     }
     if (empty($this->_description)) {
         $this->_errno[] = '1103';
     }
     if (!empty($this->_errno)) {
         $this->_retry = true;
         $this->_reedit('showEditor', array($this->_editor_mode));
     }
     // Validate the input values -----------------------<
     if (empty($this->_cid)) {
         $this->_cid = ROOTID;
     }
     $success = false;
     if (!SEC_hasRights('downloads.submit')) {
         // Upload New file
         if (!empty($this->_url)) {
             $tmpfilename = 'tmp' . date('YmdHis', $this->_date) . DLM_createSafeFileName($this->_url);
             $success = DLM_uploadNewFile($_FILES['newfile'], $_DLM_CONF['path_filestore'], $tmpfilename);
             if ($success) {
                 $this->_size = filesize($_DLM_CONF['path_filestore'] . $tmpfilename);
                 $this->_md5 = md5_file($_DLM_CONF['path_filestore'] . $tmpfilename);
             }
         }
         // Upload New file snapshot image
         if ($success && !empty($_FILES['newfileshot']['name'])) {
             $this->_logourl = $_FILES['newfileshot']['name'];
             $tmpshotname = 'tmp' . date('YmdHis', $this->_date) . DLM_createSafeFileName($this->_logourl);
             $success = DLM_uploadNewFile($_FILES['newfileshot'], $_DLM_CONF['path_snapstore'], $tmpshotname);
         }
         $mode = 'submission';
     } else {
         // Upload New file
         if (!empty($this->_url)) {
             $safename = DLM_createSafeFileName($this->_url, $this->_secret_id);
             $success = DLM_uploadNewFile($_FILES['newfile'], $_DLM_CONF['path_filestore'], $safename);
             if ($success) {
                 $this->_size = filesize($_DLM_CONF['path_filestore'] . $safename);
                 $this->_md5 = md5_file($_DLM_CONF['path_filestore'] . $safename);
             }
         }
         // Upload New file snapshot image
         if ($success) {
             $this->_uploadSnapImage();
             DLM_makeThumbnail(DLM_createSafeFileName($this->_logourl));
         }
         $mode = '';
     }
     if ($success) {
         $this->_addToDatabase($mode);
         $msg = $_DLM_CONF['download_emailoption'] ? 109 : 115;
         echo PLG_afterSaveSwitch('home', '', 'downloads', $msg);
     } else {
         echo PLG_afterSaveSwitch('home', '', 'downloads', 108);
     }
     exit;
 }