|
From: <luc...@us...> - 2013-09-15 15:44:51
|
Revision: 12055
http://sourceforge.net/p/xoops/svn/12055
Author: luciorota
Date: 2013-09-15 15:44:48 +0000 (Sun, 15 Sep 2013)
Log Message:
-----------
small code corrections. IMO module is ready for testing... particularly the upgrading procedure from previous module versions
Modified Paths:
--------------
XoopsModules/wfdownloads/trunk/wfdownloads/admin/categories.php
XoopsModules/wfdownloads/trunk/wfdownloads/admin/downloads.php
XoopsModules/wfdownloads/trunk/wfdownloads/submit.php
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/admin/categories.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/admin/categories.php 2013-09-15 13:46:27 UTC (rev 12054)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/admin/categories.php 2013-09-15 15:44:48 UTC (rev 12055)
@@ -129,9 +129,7 @@
}
wfdownloads_savePermissions($down_groups, $newid, 'WFDownCatPerm');
wfdownloads_savePermissions($up_groups, $newid, 'WFUpCatPerm');
- /**
- * Notify of new category
- */
+ // Notify of new category
$tags = array();
$tags['CATEGORY_NAME'] = $_POST['title'];
$tags['CATEGORY_URL'] = WFDOWNLOADS_URL . '/viewcat.php?cid=' . $newid;
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/admin/downloads.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/admin/downloads.php 2013-09-15 13:46:27 UTC (rev 12054)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/admin/downloads.php 2013-09-15 15:44:48 UTC (rev 12055)
@@ -34,13 +34,415 @@
$adminMenu->addItemButton(_MI_WFD_MENU_DOWNLOADS, "{$currentFile}?op=downloads.list", 'list');
$adminMenu->addItemButton(_AM_WFD_FFS_DOWNLOADTITLE, "{$currentFile}?op=download.add", 'add');
echo $adminMenu->renderButton();
- addDownload();
+
+ $lid = WfdownloadsRequest::getInt('lid', 0);
+
+ $category_count = $wfdownloads->getHandler('category')->getCount();
+ if ($category_count) {
+ // Allowed mimetypes list
+ echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFD_FILE_ALLOWEDAMIME . "</legend>\n";
+ echo "<div style='padding: 8px;'>\n";
+ $criteria = new Criteria("mime_admin", true);
+ $mimetypes = $wfdownloads->getHandler('mimetype')->getList($criteria);
+ $allowMimetypes = implode(' | ', $mimetypes);
+ echo $allowMimetypes;
+ echo "</div>\n";
+ echo "</fieldset><br />\n";
+
+ if ($lid) {
+ if (!$download = $wfdownloads->getHandler('download')->get($lid)) {
+ redirect_header($currentFile, 4, _AM_WFD_DOWN_ERROR_FILENOTFOUND);
+ exit();
+ }
+ $cid = $download->getVar('cid');
+ if(!$category = $wfdownloads->getHandler('category')->get($cid)) {
+ redirect_header($currentFile, 4, _AM_WFD_DOWN_ERROR_CATEGORYNOTFOUND);
+ exit();
+ }
+ $title = preg_replace("/{category}/", $category->getVar('title'), _AM_WFD_FFS_EDITDOWNLOADTITLE);
+ } else {
+ $download = $wfdownloads->getHandler('download')->create();
+ $cid = WfdownloadsRequest::getInt('cid', 0, 'POST');
+ $category = $wfdownloads->getHandler('category')->get($cid);
+ $download->setVar('cid', $cid);
+ $title = preg_replace("/{category}/", $category->getVar('title'), _AM_WFD_FFS_DOWNLOADTITLE);
+ }
+
+ // Added Formulize module support (2006/05/04) jpc - start
+ if (!wfdownloads_checkModule('formulize')) {
+ $sform = $download->getAdminForm($title);
+ } elseif ((isset($_POST['submit_category']) && !empty($_POST['submit_category'])) || $lid) {
+ $fid = $category->getVar('formulize_fid');
+ $customArray = array();
+ if($fid) {
+ include_once XOOPS_ROOT_PATH . "/modules/formulize/include/formdisplay.php";
+ include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
+ $customArray['fid'] = $fid;
+ $customArray['formulize_mgr'] =& xoops_getmodulehandler('elements', 'formulize');
+ $customArray['groups'] = $xoopsUser ? $xoopsUser->getGroups() : array(0=>XOOPS_GROUP_ANONYMOUS);
+ $customArray['prevEntry'] = getEntryValues($download->getVar('formulize_idreq'), $customArray['formulize_mgr'], $customArray['groups'], $fid);
+ $customArray['entry'] = $download->getVar('formulize_idreq');
+ $customArray['go_back'] = "";
+ $customArray['parentLinks'] = "";
+ if (wfdownloads_checkModule('formulize') < 300)
+ $owner = getEntryOwner($entry);
+ else
+ $owner = getEntryOwner($entry, $fid);
+ $ownerGroups = $member_handler->getGroupsByUser($owner, false);
+ $customArray['owner_groups'] = $ownerGroups;
+ }
+ $sform = $download->getAdminForm($title, $customArray);
+ } else {
+ $sform = $download->getCategoryForm();
+ }
+ $sform->display();
+ // Added Formulize module support (2006/05/04) jpc - end
+ } else {
+ redirect_header('categories.php', 1, _AM_WFD_CCATEGORY_NOEXISTS);
+ exit();
+ }
+
+ // Vote data list/manager
+ if ($lid) {
+ $votes_count = $wfdownloads->getHandler('rating')->getCount();
+
+ $registeredCriteria = new CriteriaCompo(new Criteria('lid', $lid));
+ $registeredCriteria->add(new Criteria('ratinguser', 0, '>'));
+ $votesreg = $wfdownloads->getHandler('rating')->getCount($registeredCriteria);
+ $registeredCriteria->setSort('ratingtimestamp');
+ $registeredCriteria->setOrder('DESC');
+ $regvotes = $wfdownloads->getHandler('rating')->getObjects($registeredCriteria);
+
+ $anonymousCriteria = new CriteriaCompo(new Criteria('lid', $lid));
+ $anonymousCriteria->add(new Criteria('ratinguser', 0, '='));
+ $votesanon = $wfdownloads->getHandler('rating')->getCount($anonymousCriteria);
+ $anonymousCriteria->setSort('ratingtimestamp');
+ $anonymousCriteria->setOrder('DESC');
+
+ echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFD_VOTE_RATINGINFOMATION . "</legend>\n";
+ echo "<div style='padding: 8px;'><b>" . _AM_WFD_VOTE_TOTALVOTES . "</b>{$votes_count}<br /><br />\n";
+
+ printf(_AM_WFD_VOTE_REGUSERVOTES, $votesreg);
+
+ echo "<br />";
+
+ printf(_AM_WFD_VOTE_ANONUSERVOTES, $votesanon);
+
+ echo "
+ </div>\n
+ <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
+ <tr>\n
+ <th>" . _AM_WFD_VOTE_USER . "</td>\n
+ <th>" . _AM_WFD_VOTE_IP . "</td>\n
+ <th>" . _AM_WFD_VOTE_RATING . "</td>\n
+ <th>" . _AM_WFD_VOTE_USERAVG . "</td>\n
+ <th>" . _AM_WFD_VOTE_TOTALRATE . "</td>\n
+ <th>" . _AM_WFD_VOTE_DATE . "</td>\n
+ <th>" . _AM_WFD_MINDEX_ACTION . "</td>\n
+ </tr>\n
+ ";
+
+ if ($votesreg == 0) {
+ echo "<tr><td colspan='7' class='even'><b>" . _AM_WFD_VOTE_NOREGVOTES . "</b></td></tr>";
+ } else {
+ foreach (array_keys($regvotes) as $i) {
+ $uids[] = $regvotes[$i]->getVar('ratinguser');
+ }
+
+ $criteria = new Criteria("ratinguser", "(".implode(',', $uids).")", "IN");
+ $criteria->setGroupby("ratinguser");
+ $userratings = $wfdownloads->getHandler('rating')->getUserAverage($criteria);
+
+ foreach (array_keys($regvotes) as $i) {
+ $formatted_date = formatTimestamp($regvotes[$i]->getVar('ratingtimestamp'), _DATESTRING);
+ $useravgrating = isset($userratings[$regvotes[$i]->getVar('ratinguser')]) ? $userratings[$regvotes[$i]->getVar('ratinguser')]["avg"] : 0;
+ $uservotes = isset($userratings[$regvotes[$i]->getVar('ratinguser')]) ? $userratings[$regvotes[$i]->getVar('ratinguser')]["count"] : 0;
+ $ratinguname = XoopsUser :: getUnameFromId($regvotes[$i]->getVar('ratinguser'));
+
+ echo "
+ <tr><td class='head'>$ratinguname</td>\n
+ <td class='even'>" . $regvotes[$i]->getVar('ratinghostname') . "</th>\n
+ <td class='even'>" . $regvotes[$i]->getVar('rating') . "</th>\n
+ <td class='even'>$useravgrating</th>\n
+ <td class='even'>$uservotes</th>\n
+ <td class='even'>$formatted_date</th>\n
+ <td class='even'>\n
+ <a href='{$currentFile}?op=vote.delete&lid={$lid}&rid=" . $regvotes[$i]->getVar('ratingid') . "'>" . $imagearray['deleteimg'] . "</a>\n
+ </th></tr>\n
+ ";
+ }
+ }
+ echo "
+ </table>\n
+ <br />\n
+ <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
+ <tr>\n
+ <th>" . _AM_WFD_VOTE_USER . "</td>\n
+ <th>" . _AM_WFD_VOTE_IP . "</td>\n
+ <th>" . _AM_WFD_VOTE_RATING . "</td>\n
+ <th>" . _AM_WFD_VOTE_USERAVG . "</td>\n
+ <th>" . _AM_WFD_VOTE_TOTALRATE . "</td>\n
+ <th>" . _AM_WFD_VOTE_DATE . "</td>\n
+ <th>" . _AM_WFD_MINDEX_ACTION . "</td>\n
+ </tr>\n
+ ";
+ if ($votesanon == 0) {
+ echo "<tr><td colspan='7' class='even'><b>" . _AM_WFD_VOTE_NOUNREGVOTES . "</b></td></tr>";
+ } else {
+ $criteria = new Criteria('ratinguser', 0);
+ $userratings = $wfdownloads->getHandler('rating')->getUserAverage($criteria);
+ $anonymousVotes = $wfdownloads->getHandler('rating')->getObjects($anonymousCriteria);
+
+ foreach (array_keys($anonymousVotes) as $i) {
+ $formatted_date = formatTimestamp($anonymousVotes[$i]->getVar('ratingtimestamp'), _DATESTRING);
+ $useravgrating = isset($userratings['avg']) ? $userratings["avg"] : 0;
+ $uservotes = isset($userratings['count']) ? $userratings["count"] : 0;
+
+ $ratinguname = $GLOBALS['xoopsConfig']['anonymous'];
+
+ echo "
+ <tr><td class='head'>$ratinguname</td>\n
+ <td class='even'>" . $anonymousVotes[$i]->getVar('ratinghostname') . "</th>\n
+ <td class='even'>" . $anonymousVotes[$i]->getVar('rating') . "</th>\n
+ <td class='even'>$useravgrating</th>\n
+ <td class='even'>$uservotes</th>\n
+ <td class='even'>$formatted_date</th>\n
+ <td class='even'>\n
+ <a href='{$currentFile}?op=vote.delete&lid={$lid}&rid=" . $anonymousVotes[$i]->getVar('ratingid') . "'>" . $imagearray['deleteimg'] . "</a>\n
+ </th></tr>\n
+ ";
+ }
+ }
+ echo "</table>\n";
+ echo "</fieldset>\n";
+ }
include 'admin_footer.php';
break;
case "download.save" :
case "addDownload" :
- saveDownload();
+ $lid = WfdownloadsRequest::getInt('lid', 0, 'POST');
+ $cid = WfdownloadsRequest::getInt('cid', 0, 'POST');
+ $status = WfdownloadsRequest::getInt('status', 2, 'POST');
+
+ if ($lid > 0) {
+ $thisIsANewRecord = false; /* Added by Lankford on 2007/3/21 */
+ $download = $wfdownloads->getHandler('download')->get($lid);
+ } else {
+ $thisIsANewRecord = true; /* Added by Lankford on 2007/3/21 */
+ $download = $wfdownloads->getHandler('download')->create();
+ }
+ // Define URL
+ if (empty($_FILES['userfile']['name'])) {
+ if ($_POST['url'] && $_POST['url'] != "" && $_POST['url'] != "http://") {
+ $url = ($_POST['url'] != "http://") ? $_POST['url'] : '';
+ $filename = '';
+ $filetype = '';
+ } else {
+ $url = ($_POST["url"] != "http://") ? $_POST['url'] : '';
+ $filename = $_POST['filename'];
+ $filetype = $_POST['filetype'];
+ }
+ $size = (empty($_POST['size']) || !is_numeric($_POST['size'])) ? 0 : (int)$_POST["size"];
+ $title = trim($_POST['title']);
+ $download->setVar('filename', $filename);
+ $download->setVar('filetype', $filetype);
+ } else {
+ $down = wfdownloads_uploading($_FILES, $wfdownloads->getConfig('uploaddir'), '', $currentFile, 0, false, true);
+ $url = ($_POST['url'] != "http://") ? $_POST["url"] : '';
+ $size = $down['size'];
+ $title = $_FILES['userfile']['name'];
+ $ext = rtrim(strrchr($title, '.'), '.');
+ $title = str_replace($ext, '', $title);
+ $title = (isset($_POST['title_checkbox']) && $_POST['title_checkbox'] == 1) ? $title : trim($_POST['title']);
+
+ $filename = $down['filename'];
+ $filetype = $_FILES['userfile']['type'];
+ $download->setVar('filename', $filename);
+ $download->setVar('filetype', $filetype);
+ }
+ // Get data from form
+ $screenshot = ($_POST['screenshot'] != 'blank.png') ? $_POST['screenshot'] : '';
+ $screenshot2 = ($_POST['screenshot2'] != 'blank.png') ? $_POST['screenshot2'] : '';
+ $screenshot3 = ($_POST['screenshot3'] != 'blank.png') ? $_POST['screenshot3'] : '';
+ $screenshot4 = ($_POST['screenshot4'] != 'blank.png') ? $_POST['screenshot4'] : '';
+
+ if (!empty($_POST['homepage']) || $_POST['homepage'] != "http://") {
+ $download->setVar('homepage', trim($_POST['homepage']));
+ $download->setVar('homepagetitle', trim($_POST['homepagetitle']));
+ }
+
+ $version = !empty($_POST['version']) ? trim($_POST['version']) : 0;
+
+ /* Added by Lankford on 2007/3/21 */
+ // Here, I want to know if:
+ // a) Are they actually changing the value of version, or is it the same?
+ // b) Are they actually modifying the record, or is this a new one?
+ // If both conditions are true, then trigger all three notifications related to modified records.
+ if (!$thisIsANewRecord and ($download->getVar('version') != $version)) {
+ // Trigger the three events related to modified files (one for the file, category, and global event categories respectively)
+ $tags = array();
+ $tags['FILE_NAME'] = $title;
+ $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}";
+ $category = $wfdownloads->getHandler('category')->get($cid);
+ $tags['FILE_VERSION'] = $version;
+ $tags['CATEGORY_NAME'] = $category->getVar('title');
+ $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . "/viewcat.php?cid='{$cid}";
+
+ if ($wfdownloads->getConfig('autoapprove') == _WFD_AUTOAPPROVE_DOWNLOAD || $wfdownloads->getConfig('autoapprove') == _WFD_AUTOAPPROVE_BOTH) {
+ // Then this change will be automatically approved, so the notification needs to go out.
+ $notification_handler->triggerEvent('global', 0, 'filemodified', $tags);
+ $notification_handler->triggerEvent('category', $cid, 'filemodified', $tags);
+ $notification_handler->triggerEvent('file', $lid, 'filemodified', $tags);
+ }
+ }
+ /* End add block */
+ $download->setVar('version', $version);
+ $download->setVar('url', $url);
+ $download->setVar('cid', $cid);
+ $download->setVar('title', $title);
+ $download->setVar('status', $status);
+ $download->setVar('size', $size);
+ $download->setVar('screenshot', $screenshot);
+ $download->setVar('screenshot2', $screenshot2);
+ $download->setVar('screenshot3', $screenshot3);
+ $download->setVar('screenshot4', $screenshot4);
+ $download->setVar('platform', trim($_POST['platform']));
+ $download->setVar('summary', trim($_POST['summary']));
+ $download->setVar('description', trim($_POST['description']));
+ $download->setVar('submitter', trim($_POST['submitter']));
+ $download->setVar('publisher', trim($_POST['publisher']));
+ $download->setVar('price', trim($_POST['price']));
+ if (!$wfdownloads->getConfig('enable_mirrors')) {
+ $download->setVar('mirror', formatURL(trim($_POST['mirror'])));
+ }
+ $download->setVar('license', trim($_POST['license']));
+ $download->setVar('features', trim($_POST['features']));
+ $download->setVar('requirements', trim($_POST['requirements']));
+ $limitations = (isset($_POST['limitations'])) ? $_POST['limitations'] : '';
+ $download->setVar('limitations', $limitations);
+ $versiontypes = (isset($_POST['versiontypes'])) ? $_POST['versiontypes'] : '';
+ $download->setVar('versiontypes', $versiontypes);
+
+ $dhistory = (isset($_POST['dhistory'])) ? $_POST['dhistory'] : '';
+ $dhistoryhistory = (isset($_POST['dhistoryaddedd'])) ? $_POST['dhistoryaddedd'] : '';
+
+ if ($lid > 0 && !empty($dhistoryhistory)) {
+ $dhistory = $dhistory . "\n\n";
+ $time = time();
+ $dhistory .= _AM_WFD_FILE_HISTORYVERS . $version . _AM_WFD_FILE_HISTORDATE . formatTimestamp($time, _DATESTRING) . "\n\n";
+ $dhistory .= $dhistoryhistory;
+ }
+ $download->setVar('dhistory', $dhistory);
+ $download->setVar('dhistoryhistory', $dhistoryhistory);
+
+ $updated = (isset($_POST['was_published']) && $_POST['was_published'] == 0) ? 0 : time();
+
+ if ($_POST['up_dated'] == 0) {
+ $updated = 0;
+ }
+ $download->setVar('updated', $updated);
+
+ $offline = ($_POST['offline'] == 1) ? 1 : 0;
+ $download->setVar('offline', $offline);
+ $approved = (isset($_POST['approved']) && $_POST['approved'] == true) ? true : false;
+ $notifypub = (isset($_POST['notifypub']) && $_POST['notifypub'] == true);
+
+ $expiredate = 0;
+ if (!$lid) {
+ $publishdate = time();
+ } else {
+ $publishdate = $_POST['was_published'];
+ $expiredate = $_POST['was_expired'];
+ }
+ if ($approved == 1 && empty($publishdate)) {
+ $publishdate = time();
+ }
+ if (isset($_POST['publishdateactivate'])) {
+ $publishdate = strtotime($_POST['published']['date']) + $_POST['published']['time'];
+ }
+ if ($_POST['clearpublish']) {
+ $publishdate = $download->getVar('published');
+ }
+ if (isset($_POST['expiredateactivate'])) {
+ $expiredate = strtotime($_POST['expired']['date']) + $_POST['expired']['time'];
+ }
+ if ($_POST['clearexpire']) {
+ $expiredate = '0';
+ }
+
+ $download->setVar('expired', $expiredate);
+ $download->setVar('published', $publishdate);
+ $download->setVar('date', time());
+ // Update or insert download data into database
+ if (!$lid) {
+ $download->setVar('ipaddress', $_SERVER['REMOTE_ADDR']);
+ }
+
+ $category = $wfdownloads->getHandler('category')->get($cid);
+
+ // Added Formulize module support (2006/05/04) jpc - start
+ if (wfdownloads_checkModule('formulize')) {
+ $fid = $category->getVar('formulize_fid');
+ if($fid) {
+ include_once XOOPS_ROOT_PATH . "/modules/formulize/include/formread.php";
+ include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
+ $formulize_mgr =& xoops_getmodulehandler('elements', 'formulize');
+ if ($lid) {
+ $entries[$fid][0] = $download->getVar('formulize_idreq');
+ if($entries[$fid][0]) {
+ if (wfdownloads_checkModule('formulize') < 300)
+ $owner = getEntryOwner($entries[$fid][0]);
+ else
+ $owner = getEntryOwner($entries[$fid][0], $fid);
+ } else {
+ print "no idreq";
+ $entries[$fid][0] = "";
+ $owner = "";
+ }
+ $cid = $download->getVar('cid');
+ } else {
+ $entries[$fid][0] = "";
+ $owner = "";
+ }
+ $ownerGroups =& $member_handler->getGroupsByUser($owner, false);
+ $uid = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
+ $groups = $xoopsUser ? $xoopsUser->getGroups() : array(0=>XOOPS_GROUP_ANONYMOUS);
+ $entries = handleSubmission($formulize_mgr, $entries, $uid, $owner, $fid, $ownerGroups, $groups, "new"); // "new" causes xoops token check to be skipped, since WF-downloads should be doing that
+ if(!$owner) {
+ $id_req = $entries[$fid][0];
+ $download->setVar('formulize_idreq', $id_req);
+ }
+ }
+ }
+ // Added Formulize module support (2006/05/04) jpc - end
+ $wfdownloads->getHandler('download')->insert($download);
+ $newid = (int)$download->getVar('lid');
+ // Send notifications
+ if (!$lid) {
+ $tags = array();
+ $tags['FILE_NAME'] = $title;
+ $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$newid}";
+ $tags['CATEGORY_NAME'] = $category->getVar('title');
+ $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
+ $notification_handler->triggerEvent('global', 0, 'new_file', $tags);
+ $notification_handler->triggerEvent('category', $cid, 'new_file', $tags);
+ }
+ if ($lid && $approved && $notifypub) {
+ $tags = array();
+ $tags['FILE_NAME'] = $title;
+ $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}";
+ $category = $wfdownloads->getHandler('category')->get($cid);
+ $tags['CATEGORY_NAME'] = $category->getVar('title');
+ $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . '/viewcat.php?cid=' . $cid;
+ $notification_handler->triggerEvent('global', 0, 'new_file', $tags);
+ $notification_handler->triggerEvent('category', $cid, 'new_file', $tags);
+ $notification_handler->triggerEvent('file', $lid, 'approve', $tags);
+ }
+ $message = (!$lid) ? _AM_WFD_FILE_NEWFILEUPLOAD : _AM_WFD_FILE_FILEMODIFIEDUPDATE ;
+ $message = ($lid && !$_POST['was_published'] && $approved) ? _AM_WFD_FILE_FILEAPPROVED : $message;
+
+ redirect_header($currentFile, 1, $message);
break;
case "download.delete" :
@@ -344,429 +746,12 @@
function addDownload()
{
- global $xoopsUser, $imagearray, $currentFile;
- $wfdownloads = WfdownloadsWfdownloads::getInstance();
- $member_handler = xoops_gethandler('member');
- $notification_handler = xoops_gethandler('notification');
-
- $lid = WfdownloadsRequest::getInt('lid', 0);
-
- $category_count = $wfdownloads->getHandler('category')->getCount();
- if ($category_count) {
- // allowed mimetypes list
- echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFD_FILE_ALLOWEDAMIME . "</legend>\n";
- echo "<div style='padding: 8px;'>\n";
- $criteria = new Criteria("mime_admin", true);
- $mimetypes = $wfdownloads->getHandler('mimetype')->getList($criteria);
- $allowMimetypes = implode(' | ', $mimetypes);
- echo $allowMimetypes;
- echo "</div>\n";
- echo "</fieldset><br />\n";
-
- if ($lid) {
- if (!$download = $wfdownloads->getHandler('download')->get($lid)) {
- redirect_header($currentFile, 4, _AM_WFD_DOWN_ERROR_FILENOTFOUND);
- exit();
- }
- $cid = $download->getVar('cid');
- if(!$category = $wfdownloads->getHandler('category')->get($cid)) {
- redirect_header($currentFile, 4, _AM_WFD_DOWN_ERROR_CATEGORYNOTFOUND);
- exit();
- }
- $title = preg_replace("/{category}/", $category->getVar('title'), _AM_WFD_FFS_EDITDOWNLOADTITLE);
- } else {
- $download = $wfdownloads->getHandler('download')->create();
- $cid = WfdownloadsRequest::getInt('cid', 0, 'POST');
- $category = $wfdownloads->getHandler('category')->get($cid);
- $download->setVar('cid', $cid);
- $title = preg_replace("/{category}/", $category->getVar('title'), _AM_WFD_FFS_DOWNLOADTITLE);
- }
-
- // Added Formulize module support (2006/05/04) jpc - start
- if (!wfdownloads_checkModule('formulize')) {
- $sform = $download->getAdminForm($title);
- } elseif ((isset($_POST['submit_category']) && !empty($_POST['submit_category'])) || $lid) {
- $fid = $category->getVar('formulize_fid');
- $customArray = array();
- if($fid) {
- include_once XOOPS_ROOT_PATH . "/modules/formulize/include/formdisplay.php";
- include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
- $customArray['fid'] = $fid;
- $customArray['formulize_mgr'] =& xoops_getmodulehandler('elements', 'formulize');
- $customArray['groups'] = $xoopsUser ? $xoopsUser->getGroups() : array(0=>XOOPS_GROUP_ANONYMOUS);
- $customArray['prevEntry'] = getEntryValues($download->getVar('formulize_idreq'), $customArray['formulize_mgr'], $customArray['groups'], $fid);
- $customArray['entry'] = $download->getVar('formulize_idreq');
- $customArray['go_back'] = "";
- $customArray['parentLinks'] = "";
- if (wfdownloads_checkModule('formulize') < 300)
- $owner = getEntryOwner($entry);
- else
- $owner = getEntryOwner($entry, $fid);
- $owner_groups = $member_handler->getGroupsByUser($owner, false);
- $customArray['owner_groups'] = $owner_groups;
- }
- $sform = $download->getAdminForm($title, $customArray);
- } else {
- $sform = $download->getCategoryForm();
- }
- $sform->display();
- // Added Formulize module support (2006/05/04) jpc - end
- } else {
- redirect_header('categories.php', 1, _AM_WFD_CCATEGORY_NOEXISTS);
- exit();
- }
-
- // Vote data list/manager
- if ($lid) {
- $totalvotes = $wfdownloads->getHandler('rating')->getCount();
-
- $reg_criteria = new CriteriaCompo(new Criteria('lid', $lid));
- $reg_criteria->add(new Criteria("ratinguser", 0, ">"));
- $votesreg = $wfdownloads->getHandler('rating')->getCount($reg_criteria);
- $reg_criteria->setSort("ratingtimestamp");
- $reg_criteria->setOrder('DESC');
- $regvotes = $wfdownloads->getHandler('rating')->getObjects($reg_criteria);
-
- $anon_criteria = new CriteriaCompo(new Criteria('lid', $lid));
- $anon_criteria->add(new Criteria("ratinguser", 0, "="));
- $votesanon = $wfdownloads->getHandler('rating')->getCount($anon_criteria);
- $anon_criteria->setSort("ratingtimestamp");
- $anon_criteria->setOrder('DESC');
-
- echo "<fieldset><legend style='font-weight: bold; color: #900;'>" . _AM_WFD_VOTE_RATINGINFOMATION . "</legend>\n";
- echo "<div style='padding: 8px;'><b>" . _AM_WFD_VOTE_TOTALVOTES . "</b>{$totalvotes}<br /><br />\n";
-
- printf(_AM_WFD_VOTE_REGUSERVOTES, $votesreg);
-
- echo "<br />";
-
- printf(_AM_WFD_VOTE_ANONUSERVOTES, $votesanon);
-
- echo "
- </div>\n
- <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
- <tr>\n
- <th>" . _AM_WFD_VOTE_USER . "</td>\n
- <th>" . _AM_WFD_VOTE_IP . "</td>\n
- <th>" . _AM_WFD_VOTE_RATING . "</td>\n
- <th>" . _AM_WFD_VOTE_USERAVG . "</td>\n
- <th>" . _AM_WFD_VOTE_TOTALRATE . "</td>\n
- <th>" . _AM_WFD_VOTE_DATE . "</td>\n
- <th>" . _AM_WFD_MINDEX_ACTION . "</td>\n
- </tr>\n
- ";
-
- if ($votesreg == 0) {
- echo "<tr><td colspan='7' class='even'><b>" . _AM_WFD_VOTE_NOREGVOTES . "</b></td></tr>";
- } else {
- foreach (array_keys($regvotes) as $i) {
- $uids[] = $regvotes[$i]->getVar('ratinguser');
- }
-
- $criteria = new Criteria("ratinguser", "(".implode(',', $uids).")", "IN");
- $criteria->setGroupby("ratinguser");
- $userratings = $wfdownloads->getHandler('rating')->getUserAverage($criteria);
-
- foreach (array_keys($regvotes) as $i) {
- $formatted_date = formatTimestamp($regvotes[$i]->getVar('ratingtimestamp'), _DATESTRING);
- $useravgrating = isset($userratings[$regvotes[$i]->getVar('ratinguser')]) ? $userratings[$regvotes[$i]->getVar('ratinguser')]["avg"] : 0;
- $uservotes = isset($userratings[$regvotes[$i]->getVar('ratinguser')]) ? $userratings[$regvotes[$i]->getVar('ratinguser')]["count"] : 0;
- $ratinguname = XoopsUser :: getUnameFromId($regvotes[$i]->getVar('ratinguser'));
-
- echo "
- <tr><td class='head'>$ratinguname</td>\n
- <td class='even'>" . $regvotes[$i]->getVar('ratinghostname') . "</th>\n
- <td class='even'>" . $regvotes[$i]->getVar('rating') . "</th>\n
- <td class='even'>$useravgrating</th>\n
- <td class='even'>$uservotes</th>\n
- <td class='even'>$formatted_date</th>\n
- <td class='even'>\n
- <a href='{$currentFile}?op=vote.delete&lid={$lid}&rid=" . $regvotes[$i]->getVar('ratingid') . "'>" . $imagearray['deleteimg'] . "</a>\n
- </th></tr>\n
- ";
- }
- }
- echo "
- </table>\n
- <br />\n
- <table width='100%' cellspacing='1' cellpadding='2' class='outer'>\n
- <tr>\n
- <th>" . _AM_WFD_VOTE_USER . "</td>\n
- <th>" . _AM_WFD_VOTE_IP . "</td>\n
- <th>" . _AM_WFD_VOTE_RATING . "</td>\n
- <th>" . _AM_WFD_VOTE_USERAVG . "</td>\n
- <th>" . _AM_WFD_VOTE_TOTALRATE . "</td>\n
- <th>" . _AM_WFD_VOTE_DATE . "</td>\n
- <th>" . _AM_WFD_MINDEX_ACTION . "</td>\n
- </tr>\n
- ";
- if ($votesanon == 0) {
- echo "<tr><td colspan='7' class='even'><b>" . _AM_WFD_VOTE_NOUNREGVOTES . "</b></td></tr>";
- } else {
- $criteria = new Criteria("ratinguser", 0);
- $userratings = $wfdownloads->getHandler('rating')->getUserAverage($criteria);
- $anonvotes = $wfdownloads->getHandler('rating')->getObjects($anon_criteria);
-
- foreach (array_keys($anonvotes) as $i) {
- $formatted_date = formatTimestamp($anonvotes[$i]->getVar('ratingtimestamp'), _DATESTRING);
- $useravgrating = isset($userratings['avg']) ? $userratings["avg"] : 0;
- $uservotes = isset($userratings['count']) ? $userratings["count"] : 0;
-
- $ratinguname = $GLOBALS['xoopsConfig']['anonymous'];
-
- echo "
- <tr><td class='head'>$ratinguname</td>\n
- <td class='even'>" . $anonvotes[$i]->getVar('ratinghostname') . "</th>\n
- <td class='even'>" . $anonvotes[$i]->getVar('rating') . "</th>\n
- <td class='even'>$useravgrating</th>\n
- <td class='even'>$uservotes</th>\n
- <td class='even'>$formatted_date</th>\n
- <td class='even'>\n
- <a href='{$currentFile}?op=vote.delete&lid={$lid}&rid=" . $anonvotes[$i]->getVar('ratingid') . "'>" . $imagearray['deleteimg'] . "</a>\n
- </th></tr>\n
- ";
- }
- }
- echo "</table>\n";
- echo "</fieldset>\n";
- }
}
function saveDownload()
{
- global $xoopsUser, $currentFile;
- $wfdownloads = WfdownloadsWfdownloads::getInstance();
- $member_handler = xoops_gethandler('member');
- $notification_handler = xoops_gethandler('notification');
-
- $lid = WfdownloadsRequest::getInt('lid', 0, 'POST');
- $cid = WfdownloadsRequest::getInt('cid', 0, 'POST');
- $status = WfdownloadsRequest::getInt('status', 2, 'POST');
-
- if ($lid > 0) {
- $thisIsANewRecord = false; /* Added by Lankford on 2007/3/21 */
- $download = $wfdownloads->getHandler('download')->get($lid);
- } else {
- $thisIsANewRecord = true; /* Added by Lankford on 2007/3/21 */
- $download = $wfdownloads->getHandler('download')->create();
- }
- /* Define URL */
- if (empty($_FILES['userfile']['name'])) {
- if ($_POST['url'] && $_POST['url'] != "" && $_POST['url'] != "http://") {
- $url = ($_POST['url'] != "http://") ? $_POST['url'] : '';
- $filename = '';
- $filetype = '';
- } else {
- $url = ($_POST["url"] != "http://") ? $_POST['url'] : '';
- $filename = $_POST['filename'];
- $filetype = $_POST['filetype'];
- }
- $size = (empty($_POST['size']) || !is_numeric($_POST['size'])) ? 0 : (int)$_POST["size"];
- $title = trim($_POST['title']);
- $download->setVar('filename', $filename);
- $download->setVar('filetype', $filetype);
- } else {
- $down = wfdownloads_uploading($_FILES, $wfdownloads->getConfig('uploaddir'), '', $currentFile, 0, false, true);
- $url = ($_POST['url'] != "http://") ? $_POST["url"] : '';
- $size = $down['size'];
- $title = $_FILES['userfile']['name'];
- $ext = rtrim(strrchr($title, '.'), '.');
- $title = str_replace($ext, '', $title);
- $title = (isset($_POST['title_checkbox']) && $_POST['title_checkbox'] == 1) ? $title : trim($_POST['title']);
-
- $filename = $down['filename'];
- $filetype = $_FILES['userfile']['type'];
- $download->setVar('filename', $filename);
- $download->setVar('filetype', $filetype);
- }
- /* Get data from form */
- $screenshot = ($_POST['screenshot'] != 'blank.png') ? $_POST['screenshot'] : '';
- $screenshot2 = ($_POST['screenshot2'] != 'blank.png') ? $_POST['screenshot2'] : '';
- $screenshot3 = ($_POST['screenshot3'] != 'blank.png') ? $_POST['screenshot3'] : '';
- $screenshot4 = ($_POST['screenshot4'] != 'blank.png') ? $_POST['screenshot4'] : '';
-
- if (!empty($_POST['homepage']) || $_POST['homepage'] != "http://") {
- $download->setVar('homepage', trim($_POST['homepage']));
- $download->setVar('homepagetitle', trim($_POST['homepagetitle']));
- }
-
- $version = !empty($_POST['version']) ? trim($_POST['version']) : 0;
-
- /* Added by Lankford on 2007/3/21 */
- // Here, I want to know if:
- // a) Are they actually changing the value of version, or is it the same?
- // b) Are they actually modifying the record, or is this a new one?
- // If both conditions are true, then trigger all three notifications related to modified records.
- if (!$thisIsANewRecord and ($download->getVar('version') != $version)) {
- // Trigger the three events related to modified files (one for the file, category, and global event categories respectively)
- $tags = array();
- $tags['FILE_NAME'] = $title;
- $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}";
- $category = $wfdownloads->getHandler('category')->get($cid);
- $tags['FILE_VERSION'] = $version;
- $tags['CATEGORY_NAME'] = $category->getVar('title');
- $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . "/viewcat.php?cid='{$cid}";
-
- if ($wfdownloads->getConfig('autoapprove') == _WFD_AUTOAPPROVE_DOWNLOAD || $wfdownloads->getConfig('autoapprove') == _WFD_AUTOAPPROVE_BOTH) {
- // Then this change will be automatically approved, so the notification needs to go out.
- $notification_handler->triggerEvent('global', 0, 'filemodified', $tags);
- $notification_handler->triggerEvent('category', $cid, 'filemodified', $tags);
- $notification_handler->triggerEvent('file', $lid, 'filemodified', $tags);
- }
- }
- /* End add block */
- $download->setVar('version', $version);
- $download->setVar('url', $url);
- $download->setVar('cid', $cid);
- $download->setVar('title', $title);
- $download->setVar('status', $status);
- $download->setVar('size', $size);
- $download->setVar('screenshot', $screenshot);
- $download->setVar('screenshot2', $screenshot2);
- $download->setVar('screenshot3', $screenshot3);
- $download->setVar('screenshot4', $screenshot4);
- $download->setVar('platform', trim($_POST['platform']));
- $download->setVar('summary', trim($_POST['summary']));
- $download->setVar('description', trim($_POST['description']));
- $download->setVar('submitter', trim($_POST['submitter']));
- $download->setVar('publisher', trim($_POST['publisher']));
- $download->setVar('price', trim($_POST['price']));
- if (!$wfdownloads->getConfig('enable_mirrors')) {
- $download->setVar('mirror', formatURL(trim($_POST['mirror'])));
- }
- $download->setVar('license', trim($_POST['license']));
- $download->setVar('features', trim($_POST['features']));
- $download->setVar('requirements', trim($_POST['requirements']));
- $limitations = (isset($_POST['limitations'])) ? $_POST['limitations'] : '';
- $download->setVar('limitations', $limitations);
- $versiontypes = (isset($_POST['versiontypes'])) ? $_POST['versiontypes'] : '';
- $download->setVar('versiontypes', $versiontypes);
-
- $dhistory = (isset($_POST['dhistory'])) ? $_POST['dhistory'] : '';
- $dhistoryhistory = (isset($_POST['dhistoryaddedd'])) ? $_POST['dhistoryaddedd'] : '';
-
- if ($lid > 0 && !empty($dhistoryhistory)) {
- $dhistory = $dhistory . "\n\n";
- $time = time();
- $dhistory .= _AM_WFD_FILE_HISTORYVERS . $version . _AM_WFD_FILE_HISTORDATE . formatTimestamp($time, _DATESTRING) . "\n\n";
- $dhistory .= $dhistoryhistory;
- }
- $download->setVar('dhistory', $dhistory);
- $download->setVar('dhistoryhistory', $dhistoryhistory);
-
- $updated = (isset($_POST['was_published']) && $_POST['was_published'] == 0) ? 0 : time();
-
- if ($_POST['up_dated'] == 0) {
- $updated = 0;
- }
- $download->setVar('updated', $updated);
-
- $offline = ($_POST['offline'] == 1) ? 1 : 0;
- $download->setVar('offline', $offline);
- $approved = (isset($_POST['approved']) && $_POST['approved'] == true) ? true : false;
- $notifypub = (isset($_POST['notifypub']) && $_POST['notifypub'] == true);
-
- $expiredate = 0;
- if (!$lid) {
- $publishdate = time();
- } else {
- $publishdate = $_POST['was_published'];
- $expiredate = $_POST['was_expired'];
- }
- if ($approved == 1 && empty($publishdate)) {
- $publishdate = time();
- }
- if (isset($_POST['publishdateactivate'])) {
- $publishdate = strtotime($_POST['published']['date']) + $_POST['published']['time'];
- }
- if ($_POST['clearpublish']) {
- $publishdate = $download->getVar('published');
- }
- if (isset($_POST['expiredateactivate'])) {
- $expiredate = strtotime($_POST['expired']['date']) + $_POST['expired']['time'];
- }
- if ($_POST['clearexpire']) {
- $expiredate = '0';
- }
-
- $download->setVar('expired', $expiredate);
- $download->setVar('published', $publishdate);
- $download->setVar('date', time());
- /**
- * Update or insert download data into database
- */
- if (!$lid) {
- $download->setVar('ipaddress', $_SERVER['REMOTE_ADDR']);
- }
-
- $category = $wfdownloads->getHandler('category')->get($cid);
-
- // Added Formulize module support (2006/05/04) jpc - start
- if (wfdownloads_checkModule('formulize')) {
- $fid = $category->getVar('formulize_fid');
- if($fid) {
- include_once XOOPS_ROOT_PATH . "/modules/formulize/include/formread.php";
- include_once XOOPS_ROOT_PATH . "/modules/formulize/include/functions.php";
- $formulize_mgr =& xoops_getmodulehandler('elements', 'formulize');
- if ($lid) {
- $entries[$fid][0] = $download->getVar('formulize_idreq');
- if($entries[$fid][0]) {
- if (wfdownloads_checkModule('formulize') < 300)
- $owner = getEntryOwner($entries[$fid][0]);
- else
- $owner = getEntryOwner($entries[$fid][0], $fid);
- } else {
- print "no idreq";
- $entries[$fid][0] = "";
- $owner = "";
- }
- $cid = $download->getVar('cid');
- } else {
- $entries[$fid][0] = "";
- $owner = "";
- }
- $owner_groups =& $member_handler->getGroupsByUser($owner, false);
- $uid = !empty($xoopsUser) ? $xoopsUser->getVar('uid') : 0;
- $groups = $xoopsUser ? $xoopsUser->getGroups() : array(0=>XOOPS_GROUP_ANONYMOUS);
- $entries = handleSubmission($formulize_mgr, $entries, $uid, $owner, $fid, $owner_groups, $groups, "new"); // "new" causes xoops token check to be skipped, since WF-downloads should be doing that
- if(!$owner) {
- $id_req = $entries[$fid][0];
- $download->setVar('formulize_idreq', $id_req);
- }
- }
- }
- // Added Formulize module support (2006/05/04) jpc - end
- $wfdownloads->getHandler('download')->insert($download);
- $newid = (int)$download->getVar('lid');
- /**
- * Send notifications
- */
- if (!$lid) {
- $tags = array();
- $tags['FILE_NAME'] = $title;
- $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$newid}";
- $tags['CATEGORY_NAME'] = $category->getVar('title');
- $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . "/viewcat.php?cid={$cid}";
- $notification_handler->triggerEvent('global', 0, 'new_file', $tags);
- $notification_handler->triggerEvent('category', $cid, 'new_file', $tags);
- }
- if ($lid && $approved && $notifypub) {
- $tags = array();
- $tags['FILE_NAME'] = $title;
- $tags['FILE_URL'] = WFDOWNLOADS_URL . "/singlefile.php?cid={$cid}&lid={$lid}";
- $category = $wfdownloads->getHandler('category')->get($cid);
- $tags['CATEGORY_NAME'] = $category->getVar('title');
- $tags['CATEGORY_URL'] = WFDOWNLOADS_URL . '/viewcat.php?cid=' . $cid;
- $notification_handler->triggerEvent('global', 0, 'new_file', $tags);
- $notification_handler->triggerEvent('category', $cid, 'new_file', $tags);
- $notification_handler->triggerEvent('file', $lid, 'approve', $tags);
- }
- $message = (!$lid) ? _AM_WFD_FILE_NEWFILEUPLOAD : _AM_WFD_FILE_FILEMODIFIEDUPDATE ;
- $message = ($lid && !$_POST['was_published'] && $approved) ? _AM_WFD_FILE_FILEAPPROVED : $message;
-
- redirect_header($currentFile, 1, $message);
}
Modified: XoopsModules/wfdownloads/trunk/wfdownloads/submit.php
===================================================================
--- XoopsModules/wfdownloads/trunk/wfdownloads/submit.php 2013-09-15 13:46:27 UTC (rev 12054)
+++ XoopsModules/wfdownloads/trunk/wfdownloads/submit.php 2013-09-15 15:44:48 UTC (rev 12055)
@@ -181,6 +181,7 @@
break;
case "download.save" :
+ // Save submitted download
if (empty($_FILES['userfile']['name'])) {
if ($_POST['url'] && $_POST['url'] != '' && $_POST['url'] != "http://") {
$url = ($_POST['url'] != "http://") ? $_POST['url'] : '';
|