Changeset 6122 for trunk/plugins/CL_Moblog/index.php
- Timestamp:
- 05/31/08 20:26:24 (7 months ago)
- Files:
-
- 1 modified
-
trunk/plugins/CL_Moblog/index.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/CL_Moblog/index.php
r6026 r6122 4 4 class Moblog 5 5 { 6 function Moblog( $username, $password, $host, $port = 110, $ssl = 0, 7 $userid = 1, $minsize = 10240, $visibility = 2, $category = 0 ) 6 function Moblog( $options ) 8 7 { 9 8 global $pop3logs; … … 11 10 $pop3logs = array(); 12 11 } 13 $this->username = $username; 14 $this->password = $password; 15 $this->host = $host; 16 $this->port = $port; 17 $this->ssl = $ssl; 18 $this->userid = $userid; 19 $this->minsize = $minsize; 12 foreach( $options as $k => $v ) { 13 $this->$k = $v; 14 } 15 20 16 $this->recentCount = 100; 21 $ this->visibility= array( "private", "protected", "public", "syndicated" );22 $this->visibility = $ this->visibility[$visibility];23 $this-> category = $category;17 $visibilities = array( "private", "protected", "public", "syndicated" ); 18 $this->visibility = $visibilities[$this->visibility]; 19 $this->allow = preg_split( "@[,\s]+@", $this->allow ) ; 24 20 25 21 $this->pop3 = new Pop3(); … … 45 41 } 46 42 43 function decorate_log($s) 44 { 45 global $blogURL; 46 $s = htmlspecialchars($s); 47 $s = preg_replace( "/\(SLOGAN:([^)]+)\)/", "<a href=\"$blogURL/entry/\\1\" target=\"_blank\">click</a>", $s ); 48 return $s; 49 } 50 47 51 function log($msg) 48 52 { … … 52 56 if( $msg[0] == '*' ) { 53 57 global $pop3logs; 54 array_push( $pop3logs, substr($msg,2) );58 array_push( $pop3logs, Moblog::decorate_log(substr($msg,2)) ); 55 59 } 56 60 } … … 110 114 } 111 115 112 function isMms( & $mail ) 113 { 116 function isAllowed( & $mail ) 117 { 118 if( isset( $mail['from'] ) && is_array( $this->allow) ) { 119 foreach( $this->allow as $a ) { 120 if( strstr( $mail['from'], $a ) !== false ) return true; 121 if( isset($mail['sender']) && strstr( $mail['sender'], $a ) !== false ) return true; 122 } 123 } 124 if( $this->allowonly ) { 125 $this->logMail( $mail, "SKIP, Not in ALLOW list" ); 126 return false; 127 } 128 114 129 if( !empty($mail['mms']) ) { 130 $this->logMail( $mail, "SKIP, Not an MMS" ); 115 131 return true; 116 132 } … … 142 158 } 143 159 160 function logMail( $mail, $result ) 161 { 162 $date = isset( $mail['date_string'] ) ? "{$mail['date_string']} {$mail['time_string']} " : ''; 163 $from = isset( $mail['from'] ) ? "({$mail['sender']} <{$mail['from']}>) " : ''; 164 $this->log( "* "._t("메일").": {$mail['subject']} {$date} {$from}[{$result}]" ); 165 } 166 144 167 function retrieveCallback( $lines, $uid ) 145 168 { 146 $slogan = date( "Y-m-d" );147 $docid = date( "H:i:s" );148 169 $this->appendUid( $uid ); 149 170 $mail = $this->pop3->parse( $lines ); 171 172 if( isset( $mail['date_string'] ) ) { 173 $slogan = $mail['date_string']; 174 $docid = $mail['time_string']; 175 } else { 176 $slogan = date( "Y-m-d" ); 177 $docid = date( "H:i:s" ); 178 } 150 179 if( in_array( $mail['subject'], array( '제목없음' ) ) ) { 151 180 $mail['subject'] = ''; 152 181 } 153 if( !$this->isMms($mail) ) { 154 $this->log( "* "._t("메일").": " . $mail['subject'] . " [SKIP]" ); 182 if( !$this->isAllowed($mail) ) { 155 183 return false; 156 184 } 157 185 if( empty($mail['attachments']) ) { 158 $this->log ( "* "._t("메일").": " . $mail['subject'] . " [SKIP]" );186 $this->logMail( $mail, "SKIP" ); 159 187 return false; 160 188 } … … 164 192 165 193 if( $post->open( "slogan = '$slogan'" ) ) { 166 $this->log( "* 기존 글을 엽니다 " );194 $this->log( "* 기존 글을 엽니다. (SLOGAN:$slogan)" ); 167 195 $post->content .= $this->_getDecoratedContent( $mail, $docid ); 168 196 $post->modified = time(); 169 197 $post->visibility = $this->visibility; 170 198 } else { 171 $this->log( "* 새 글을 작성합니다" ); 172 $post->title = empty($mail['subject']) ? $slogan : $mail['subject']; 199 $this->log( "* 새 글을 작성합니다. (SLOGAN:$slogan)" ); 200 if( isset( $mail['date_year'] ) ) { 201 $post->title = str_replace( array('%Y','%M','%D'), 202 array( $mail['date_year'], $mail['date_month'], $mail['date_day'] ), $this->subject ); 203 } else { 204 $post->title = str_replace( array('%Y','%M','%D'), 205 array( date("Y"), date("m"), date("d") ), $this->subject ); 206 } 173 207 $post->userid = $this->userid; 174 208 $post->category = $this->category; … … 184 218 $post->slogan = $slogan; 185 219 if( !$post->add() ) { 186 $this->log ( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" );220 $this->logMail( $mail, "ERROR" ); 187 221 $this->log( _t("실패: 글을 추가하지 못하였습니다")." : " . $post->error ); 188 222 return false; … … 204 238 ); 205 239 if( !$att ) { 206 $this->log ( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" );240 $this->logMail( $mail, "ERROR" ); 207 241 $this->log( _t("실패: 첨부파일을 추가하지 못하였습니다")." : " . $post->error ); 208 242 return false; … … 216 250 } 217 251 if( !$post->update() ) { 218 $this->log ( "* "._t("메일").": " . $mail['subject'] . " [ERROR]" );252 $this->logMail( $mail, "ERROR" ); 219 253 $this->log( _t("실패: 첨부파일을 본문에 연결하지 못하였습니다").". : " . $post->error ); 220 254 return false; 221 255 } 222 256 } 223 $this->log ( "* "._t("메일").": " . $mail['subject'] . " [OK]" );257 $this->logMail( $mail, "OK" ); 224 258 return true; 225 259 } … … 229 263 { 230 264 if( isset($_GET['check']) && $_GET['check'] == 1 ) { 265 echo "<html><body style=\"font-size:0.9em\">"; 231 266 echo "<style>.emplog{color:red}.oklog{color:blue}</style>"; 232 267 echo "<ul>"; … … 234 269 array_map( 235 270 create_function( '$li', 'return preg_match( "/^\S+\s+\S+\s+\*/", $li ) ? 236 (preg_match( "/\[OK\] $/", $li ) ? "<li class=\"oklog\">$li</li>" : "<li class=\"emplog\">$li</li>")271 (preg_match( "/\[OK\]/", $li ) ? "<li class=\"oklog\">$li</li>" : "<li class=\"emplog\">$li</li>") 237 272 : "<li>$li</li>";'), 238 split( "\n", file_get_contents(ROOT.DS."cache".DS."moblog.txt"))273 split( "\n",Moblog::decorate_log(file_get_contents(ROOT.DS."cache".DS."moblog.txt"))) 239 274 ) 240 275 ); 241 276 echo "</ul>"; 277 echo "</body></html>"; 242 278 exit; 243 279 } 244 280 245 $pop3host = getBlogSetting( 'MmsPop3Host', 'localhost' );246 $pop3port = getBlogSetting( 'MmsPop3Port', 110 );247 $pop3ssl = getBlogSetting( 'MmsPop3Ssl', 0 );248 $pop3username = getBlogSetting( 'MmsPop3Username', '' );249 $pop3password = getBlogSetting( 'MmsPop3Password', '' );250 $pop3minsize = getBlogSetting( 'MmsPop3MinSize', 0 );251 $pop3category = getBlogSetting( 'MmsPop3Category', 0 );252 $pop3minsize *= 1024;253 $pop3fallbackuserid = getBlogSetting( 'MmsPop3Fallbackuserid', 1 );254 $pop3visibility = getBlogSetting( 'MmsPop3Visibility', '2' );255 256 281 header( "Content-type: text/html; charset:utf-8" ); 257 echo "<html><body><ul><li>"; 258 $moblog = new Moblog( $pop3username, $pop3password, $pop3host, $pop3port, $pop3ssl, $pop3fallbackuserid, $pop3minsize, $pop3visibility, $pop3category ); 282 echo '<html>'; 283 echo '<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />'; 284 echo '<body style="font-size:0.9em"><ul><li>'; 285 $moblog = new Moblog( 286 array( 287 'username' => getBlogSetting( 'MmsPop3Username', '' ), 288 'password' => getBlogSetting( 'MmsPop3Password', '' ), 289 'host' => getBlogSetting( 'MmsPop3Host', 'localhost' ), 290 'port' => getBlogSetting( 'MmsPop3Port', 110 ), 291 'ssl' => getBlogSetting( 'MmsPop3Ssl', 0 ), 292 'userid' => getBlogSetting( 'MmsPop3Fallbackuserid', 1 ), 293 'minsize' => getBlogSetting( 'MmsPop3MinSize', 0 )*1024, 294 'visibility' => getBlogSetting( 'MmsPop3Visibility', '2' ), 295 'category' => getBlogSetting( 'MmsPop3Category', 0 ), 296 'allowonly' => getBlogSetting( 'MmsPop3AllowOnly', '0' ), 297 'allow' => getBlogSetting( 'MmsPop3Allow', '' ), 298 'subject' => getBlogSetting( 'MmsPop3Subject', '%Y-%M-%D' ) ) 299 ); 259 300 $moblog->log( "--BEGIN--" ); 260 301 $moblog->check(); … … 262 303 if( Acl::check( 'group.administrators' ) ) { 263 304 global $pop3logs; 264 print join("</li> <li>",$pop3logs);265 } 266 echo "</li> </ul></body></html>";305 print join("</li>\n<li>",$pop3logs); 306 } 307 echo "</li>\n</ul></body></html>"; 267 308 return true; 268 309 } … … 283 324 setBlogSetting( 'MmsPop3Fallbackuserid', getUserId() ); 284 325 setBlogSetting( 'MmsPop3MinSize', 0 ); 326 setBlogSetting( 'MmsPop3AllowOnly', !empty($_POST['pop3allowonly'])?1:0 ); 327 setBlogSetting( 'MmsPop3Allow', $_POST['pop3allow'] ); 328 setBlogSetting( 'MmsPop3Subject', $_POST['pop3subject'] ); 285 329 } 286 330 $pop3email = getBlogSetting( 'MmsPop3Email', '' ); … … 294 338 $pop3fallheadercharset = getBlogSetting( 'MmsPop3Fallbackcharset', 'euc-kr' ); 295 339 $pop3visibility = getBlogSetting( 'MmsPop3Visibility', '2' ); 340 $pop3mmsallowonly = getBlogSetting( 'MmsPop3AllowOnly', '0' ); 341 $pop3mmsallow = getBlogSetting( 'MmsPop3Allow', '' ); 342 $pop3subject = getBlogSetting( 'MmsPop3Subject', '%Y-%M-%D' ); 296 343 ?> 297 344 <hr class="hidden" /> … … 386 433 </dd> 387 434 </dl> 435 <div class="button-box"> 436 <input type="submit" class="save-button input-button wide-button" value="<?php echo _t('저장하기');?>" /> 437 </div> 438 </div> 439 <h2 class="caption"><span class="main-text"><?php echo _t('글 쓰기 환경 설정');?></span></h2> 440 <div id="editor-section" class="section"> 441 <dl id="editor-line" class="line"> 442 <dt><span class="label"><?php echo _t('제목');?></span></dt> 443 <dd> 444 <input type="text" style="width:24em" class="input-text" id="pop3subject" name="pop3subject" value="<?php echo $pop3subject; ?>" /> 445 (<?php echo _t('%Y:년, %M:월, %D:일');?>) <input type="button" value="<?php echo _t("초기화");?>" onclick="document.getElementById('pop3subject').value='%Y-%M-%D';return false;" /> 446 </dd> 447 </dl> 388 448 <dl id="editor-line" class="line"> 389 449 <dt><span class="label"><?php echo _t('공개여부');?></span></dt> … … 413 473 </optgroup> 414 474 </select> 475 </dd> 476 </dl> 477 <div class="button-box"> 478 <input type="submit" class="save-button input-button wide-button" value="<?php echo _t('저장하기');?>" /> 479 </div> 480 </div> 481 <h2 class="caption"><span class="main-text"><?php echo _t('메일 필터링 설정');?></span></h2> 482 <div id="editor-section" class="section"> 483 <dl id="formatter-line" class="line"> 484 <dt><span class="label"><?php echo _t('허용 목록');?></span></dt> 485 <dd> 486 <input type="radio" id="pop3allowonly" name="pop3allowonly" value="1" <?php echo $pop3mmsallowonly ? 'checked="checked"':'' ?> /> 487 <label for="pop3allowonly"><?php echo _t('다음 송신자로부터 전송된 메일만 MMS로 인식하여 처리합니다') ?></label> 488 </dd> 489 <dd> 490 <input type="radio" id="pop3allowlist" name="pop3allowonly" value="0" <?php echo $pop3mmsallowonly ? '':'checked="checked"' ?> /> 491 <label for="pop3allowlist"><?php echo _t('다음 송신자로부터 전송된 메일도 MMS로 인식하여 처리합니다'); ?></label> 492 </dd> 493 <dd> 494 <input type="text" maxlength="128" name="pop3allow" value="<?php echo htmlentities($pop3mmsallow)?>" style="width:90%" /> 495 </dd> 496 <dd> 497 <?php echo _t('여러 개인 경우 전화번호 혹은 이메일 주소를 쉼표나 공백으로 구별하여 나열합니다') ?> 498 </dd> 499 <dd> 415 500 </dd> 416 501 </dl>
