XpressEngine Core  1.11.2
 All Classes Namespaces Files Functions Variables Pages
rss.admin.controller.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) NAVER <http://www.navercorp.com> */
8 class rssAdminController extends rss
9 {
15  function init()
16  {
17  }
18 
25  {
26  $oModuleModel = getModel('module');
27  $total_config = $oModuleModel->getModuleConfig('rss');
28 
29  $config_vars = Context::getRequestVars();
30  $config_vars->feed_document_count = (int)$config_vars->feed_document_count;
31 
32  if(!$config_vars->use_total_feed) $alt_message = 'msg_invalid_request';
33  if(!in_array($config_vars->use_total_feed, array('Y','N'))) $config_vars->open_rss = 'Y';
34 
35  if($config_vars->image || $config_vars->del_image)
36  {
37  $image_obj = $config_vars->image;
38  $config_vars->image = $total_config->image;
39  // Get a variable for the delete request
40  if($config_vars->del_image == 'Y' || $image_obj)
41  {
42  FileHandler::removeFile($config_vars->image);
43  $config_vars->image = '';
44  $total_config->image = '';
45  }
46  // Ignore if the file is not the one which has been successfully uploaded
47  if($image_obj['tmp_name'] && is_uploaded_file($image_obj['tmp_name']) && checkUploadedFile($image_obj['tmp_name']))
48  {
49  // Ignore if the file is not an image
50  $image_obj['name'] = Context::convertEncodingStr($image_obj['name']);
51 
52  if(!preg_match("/\.(jpg|jpeg|gif|png)$/i", $image_obj['name'])) $alt_message = 'msg_rss_invalid_image_format';
53  else
54  {
55  // Upload the file to a path
56  $path = './files/attach/images/rss/';
57  // Create a directory
58  if(!FileHandler::makeDir($path)) $alt_message = 'msg_error_occured';
59  else
60  {
61  $filename = $path.$image_obj['name'];
62 
63  // Move the file
64  if(!move_uploaded_file($image_obj['tmp_name'], $filename)) $alt_message = 'msg_error_occured';
65  else
66  {
67  $config_vars->image = $filename;
68  }
69  }
70  }
71  }
72  }
73  if(!$config_vars->image && $config_vars->del_image != 'Y') $config_vars->image = $total_config->image;
74 
75  $output = $this->setFeedConfig($config_vars);
76 
77  if(!$alt_message) $alt_message = 'success_updated';
78 
79  $alt_message = Context::getLang($alt_message);
80  $this->setMessage($alt_message, 'info');
81 
82  //$this->setLayoutPath('./common/tpl');
83  //$this->setLayoutFile('default_layout.html');
84  //$this->setTemplatePath($this->module_path.'tpl');
85  //$this->setTemplateFile("top_refresh.html");
86 
87  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispRssAdminIndex');
88  $this->setRedirectUrl($returnUrl);
89  }
90 
91  public function procRssAdminDeleteFeedImage()
92  {
93  $delImage = Context::get('del_image');
94 
95  $oModuleModel = getModel('module');
96  $originConfig = $oModuleModel->getModuleConfig('rss');
97 
98  // Get a variable for the delete request
99  if($delImage == 'Y')
100  {
101  FileHandler::removeFile($originConfig->image);
102 
103  $originConfig->image = '';
104  $output = $this->setFeedConfig($originConfig);
105  return new BaseObject(0, 'success_updated');
106  }
107  return new BaseObject(-1, 'fail_to_delete');
108  }
109 
116  {
117  $config_vars = Context::getRequestVars();
118 
119  $openRssList = $config_vars->open_rss;
120  $openTotalFeedList = $config_vars->open_total_feed;
121  $feedDescriptionList = $config_vars->feed_description;
122  $feedCopyrightList = $config_vars->feed_copyright;
123  $targetModuleSrl = $config_vars->target_module_srl;
124 
125  if($targetModuleSrl && !is_array($openRssList))
126  {
127  $openRssList = array($targetModuleSrl => $openRssList);
128  $openTotalFeedList = array($targetModuleSrl => $openTotalFeedList);
129  $feedDescriptionList = array($targetModuleSrl => $feedDescriptionList);
130  $feedCopyrightList = array($targetModuleSrl => $feedCopyrightList);
131  }
132 
133  if(is_array($openRssList))
134  {
135  foreach($openRssList AS $module_srl=>$open_rss)
136  {
137  if(!$module_srl || !$open_rss)
138  {
139  return new BaseObject(-1, 'msg_invalid_request');
140  }
141 
142  if(!in_array($open_rss, array('Y','H','N'))) $open_rss = 'N';
143 
144  $this->setRssModuleConfig($module_srl, $open_rss, $openTotalFeedList[$module_srl], $feedDescriptionList[$module_srl], $feedCopyrightList[$module_srl]);
145  }
146  }
147 
148  //$this->setError(0);
149  $this->setMessage('success_updated', 'info');
150 
151  $returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispBoardAdminContent');
152  $this->setRedirectUrl($returnUrl);
153  }
154 
161  function setFeedConfig($config)
162  {
163  $oModuleController = getController('module');
164  $oModuleController->insertModuleConfig('rss',$config);
165  return new BaseObject();
166  }
167 
178  function setRssModuleConfig($module_srl, $open_rss, $open_total_feed = 'N', $feed_description = 'N', $feed_copyright = 'N')
179  {
180  $oModuleController = getController('module');
181  $config = new stdClass;
182  $config->open_rss = $open_rss;
183  $config->open_total_feed = $open_total_feed;
184  if($feed_description != 'N') { $config->feed_description = $feed_description; }
185  if($feed_copyright != 'N') { $config->feed_copyright = $feed_copyright; }
186  $oModuleController->insertModulePartConfig('rss',$module_srl,$config);
187  return new BaseObject();
188  }
189 }
190 /* End of file rss.admin.controller.php */
191 /* Location: ./modules/rss/rss.admin.controller.php */
$oModuleModel
Definition: ko.install.php:236
setMessage($message= 'success', $type=NULL)
getController($module_name)
Definition: func.inc.php:90
removeFile($filename)
$output
Definition: ko.install.php:193
getNotEncodedUrl()
Definition: func.inc.php:316
$module_srl
integer value to represent a run-time instance of Module (XE Module)
setRedirectUrl($url= './', $output=NULL)
makeDir($path_string)
getLang($code)
setRssModuleConfig($module_srl, $open_rss, $open_total_feed= 'N', $feed_description= 'N', $feed_copyright= 'N')
getModel($module_name)
Definition: func.inc.php:145
convertEncodingStr($str)
Definition: rss.class.php:8
$oModuleController
Definition: ko.install.php:287
checkUploadedFile($file)
Definition: func.inc.php:1165