Project

General

Profile

« Previous | Next » 

Revision 1950

Added by darkviper over 11 years ago

class AccessFile implemented in modules/news

View differences:

branches/2.8.x/CHANGELOG
11 11
! = Update/Change
12 12
===============================================================================
13 13

  
14
09 Aug-2013 Build 1950 M.v.d.Decken(DarkViper)
15
! class AccessFile implemented in modules/news
14 16
09 Aug-2013 Build 1949 M.v.d.Decken(DarkViper)
15 17
! some corrections in class AccessFile
16 18
04 Aug-2013 Build 1948 M.v.d.Decken(DarkViper)
branches/2.8.x/wb/admin/interface/version.php
51 51

  
52 52
// check if defined to avoid errors during installation (redirect to admin panel fails if PHP error/warnings are enabled)
53 53
if(!defined('VERSION')) define('VERSION', '2.8.3');
54
if(!defined('REVISION')) define('REVISION', '1949');
54
if(!defined('REVISION')) define('REVISION', '1950');
55 55
if(!defined('SP')) define('SP', '');
branches/2.8.x/wb/modules/news/delete_post.php
39 39
}
40 40

  
41 41
// Unlink post access file
42
if(is_writable(WB_PATH.PAGES_DIRECTORY.$get_details['link'].PAGE_EXTENSION)) {
43
	unlink(WB_PATH.PAGES_DIRECTORY.$get_details['link'].PAGE_EXTENSION);
42
try {
43
    $sFilename = WB_PATH.PAGES_DIRECTORY.$get_details['link'].PAGE_EXTENSION;
44
    $oAF = new AccessFile($sFilename, $page_id);
45
    $oAF->delete();
46
    unset($oAF);
47
}catch(AccessFileException $e) {
48
    $admin->print_error($e,ADMIN_URL.'/pages/modify.php?page_id='.$page_id );
44 49
}
45 50

  
46 51
// Delete post
......
50 55
// Clean up ordering
51 56
require(WB_PATH.'/framework/class.order.php');
52 57
$order = new order(TABLE_PREFIX.'mod_news_posts', 'position', 'post_id', 'section_id');
53
$order->clean($section_id); 
58
$order->clean($section_id);
54 59

  
55 60
// Check if there is a db error, otherwise say successful
56 61
if($database->is_error()) {
......
60 65
}
61 66

  
62 67
// Print admin footer
63
$admin->print_footer();
68
$admin->print_footer();
branches/2.8.x/wb/modules/news/save_post.php
14 14
 * @lastmodified    $Date$
15 15
 *
16 16
 */
17

  
18
	function createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id)
19
	{
20
		global $admin, $MESSAGE;
21
		$sError = '';
22
		$sPagesPath = WB_PATH.PAGES_DIRECTORY;
23
		$sPostsPath = $sPagesPath.'/posts';
24
		$sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
25
	// delete old accessfile if link has changed
26
		if(($newLink != $oldLink) && (is_writable($sPostsPath.$oldLink.PAGE_EXTENSION))) {
27
			if(!unlink($sPostsPath.$oldLink.PAGE_EXTENSION)) {
28
				$admin->print_error($MESSAGE['PAGES_CANNOT_DELETE_ACCESS_FILE'].' - '.$oldLink,$sBackUrl);
29
			}
30
		}
31
	// all ok, now create new accessfile
32
		$newFile = $sPagesPath.$newLink.PAGE_EXTENSION;
33
		// $backSteps = preg_replace('/^'.preg_quote(WB_PATH).'/', '', $sPostsPath);
34
				$aOptionalCommands = array(
35
				         '$section_id   = '.$section_id,
36
				         '$post_id      = '.$post_id ,
37
				         '$post_section = '.$section_id
38
				);
39
		if(	($sError = create_access_file($newFile, $page_id, 0, $aOptionalCommands))!==true ) 
40
		{
41
			$admin->print_error($sError,$sBackUrl );
42
		}
43
	} // end of function createNewsAccessFile
44
/* ************************************************************************** */
17
                    error_reporting(E_ALL);
45 18
	require('../../config.php');
46 19
	require_once(WB_PATH."/include/jscalendar/jscalendar-functions.php");
47 20
// Get post_id
......
65 38
	}
66 39
	$admin->print_header();
67 40

  
68
//	$sMediaUrl = WB_URL.MEDIA_DIRECTORY;
69
//	$searchfor = '@(<[^>]*=\s*")('.preg_quote($sMediaUrl).')([^">]*".*>)@siU';
70 41
// Validate all fields
71 42
	$title      = $admin->StripCodeFromText($admin->get_post('title'));
72 43
	$commenting = $admin->StripCodeFromText($admin->get_post('commenting'));
......
81 52
	} else {
82 53
		$short      = $admin->get_post('short');
83 54
		$long       = $admin->get_post('long');
84
//		if(ini_get('magic_quotes_gpc')==true)
85
//		{
86
//			$short = $admin->strip_slashes($short);
87
//			$long = $admin->strip_slashes($long);
88
//		}
89
//		$short = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $short );
90
//		$long = preg_replace($searchfor, '$1{SYSVAR:MEDIA_REL}$3', $long );
91 55
		$short = $admin->ReplaceAbsoluteMediaUrl($short);
92 56
		$long = $admin->ReplaceAbsoluteMediaUrl($long);
93 57
	}
94 58

  
95
// Get page link URL
96
	$sql = 'SELECT `link` FROM `'.TABLE_PREFIX.'pages` WHERE `page_id`='.(int)$page_id;
97
	$oldLink = $database->get_one($sql);
98 59
// Include WB functions file
99 60
	require(WB_PATH.'/framework/functions.php');
100 61
// Work-out what the link should be
101
	$newLink = '/posts/'.page_filename($title).PAGE_SPACER.$post_id;
62
	$sNewFile = page_filename($title).PAGE_SPACER.$post_id;
63
    $newLink = '/posts/'.$sNewFile;
64
    $sPagesPath = WB_PATH.PAGES_DIRECTORY;
65
    $sBackUrl = ADMIN_URL.'/pages/modify.php?page_id='.$page_id;
66
    $sNewFilename = $sPagesPath.$newLink.PAGE_EXTENSION;
67
    $sOldFilename = $sPagesPath.$old_link.PAGE_EXTENSION;
68

  
102 69
// get publisedwhen and publisheduntil
103 70
	$publishedwhen = jscalendar_to_timestamp($admin->get_post_escaped('publishdate'));
104 71
	if($publishedwhen == '' || $publishedwhen < 1) { $publishedwhen=0; }
......
118 85
	$sql .=     '`posted_when`='.time().', ';
119 86
	$sql .=     '`posted_by`='.(int)$admin->get_user_id().' ';
120 87
	$sql .= 'WHERE `post_id`='.(int)$post_id;
121
	if( $database->query($sql) ) { 
88
	if( $database->query($sql) ) {
122 89
		// create new accessfile
123
		createNewsAccessFile($newLink, $oldLink, $page_id, $section_id, $post_id);
90
        $sDoWhat = (($newLink == $old_link) && (file_exists($sNewFilename))) ? "nothing" : "action";
91
        if($sDoWhat == "action") {
92
            $sDoWhat = (($sDoWhat == "action") && file_exists($sOldFilename)) ? "update" : "create";
93
        }
94

  
95
        switch($sDoWhat)
96
        {
97
            case "update":
98
                try {
99
                    $oAF = new AccessFile($sOldFilename, $page_id);
100
                    $oAF->rename($sNewFile);
101
                    unset($oAF);
102
                }catch(AccessFileException $e) {
103
                    $admin->print_error($e,$sBackUrl);
104
                }
105
            break;
106
            case "create":
107
                try {
108
                    $oAF = new AccessFile($sNewFilename, $page_id);
109
                    $oAF->addVar('section_id', $section_id, AccessFile::VAR_INT);
110
                    $oAF->addVar('post_id', $post_id, AccessFile::VAR_INT);
111
                    $oAF->addVar('post_section', $section_id, AccessFile::VAR_INT);
112
                    $oAF->write();
113
                    unset($oAF);
114
                }catch(AccessFileException $e) {
115
                    $admin->print_error($e,$sBackUrl);
116
                }
117
            break;
118
        }
124 119
	}
125 120
// Check if there is a db error, otherwise say successful
126 121
	if($database->is_error()) {
......
131 126
		$admin->print_success($TEXT['SUCCESS'], ADMIN_URL.'/pages/modify.php?page_id='.$page_id);
132 127
	}
133 128
// Print admin footer
134
	$admin->print_footer();
129
	$admin->print_footer();

Also available in: Unified diff