OSDN Git Service

NP_DragAndDropUploader v1.1
[nucleus-jp/nucleus-plugins.git] / trunk / NP_Pholiot / NP_Pholiot.php
1 <?php
2
3 //history
4 //      0.5:    test version
5 //      0.51    htmlspecialchars text
6 //      0.52    linkurl ready :: rename to pholiot
7 //      0.53    Security fix.
8
9 // plugin needs to work on Nucleus versions <=2.0 as well
10 if (!function_exists('sql_table')){
11         function sql_table($name) {
12                 return 'nucleus_' . $name;
13         }
14 }
15
16 class NP_Pholiot extends NucleusPlugin {
17         function getName () {return 'Pholiot'; }
18         function getAuthor () {return 'nakahara21'; }
19         function getURL () {return 'http://xx.nakahara21.net/';}
20         function getVersion () {return '0.53';}
21         function supportsFeature($what) {
22                 switch($what){
23                         case 'SqlTablePrefix':
24                                 return 1;
25                         default:
26                                 return 0;
27                 }
28         }
29         function getDescription () {
30                 return 'Extract image in items, and embed these images into Pholiot!';
31         }
32
33         function install () {
34 /*
35                 $this->createOption('default_catname','Default Category Name.','text','');
36 */      
37         }
38
39         function init() {
40                 $this->fileex = array('.jpg','.swf');
41         }
42         
43         function doSkinVar($skinType, $ss='', $amount=30, $random=0, $exmode=0) {
44                 global $CONF, $blog,$manager;
45                 ($blog)?
46                         $b =& $blog :
47                         $b =& $manager->getBlog($CONF['DefaultBlog']);
48                 
49                 if($amount=='') $amount = 30;
50                 if($exmode != 'all') $exmode = 0;
51                 $this->exquery = '';
52
53                 switch($skinType){
54                         case 'archive': 
55                                 global $archive;
56                                 sscanf($archive,'%d-%d-%d',$year,$month,$day);
57                                 if ($day == 0) {
58                                         $timestamp_start = mktime(0,0,0,$month,1,$year);
59                                         $timestamp_end = mktime(0,0,0,$month+1,1,$year);  // also works when $month==12
60                                 } else {
61                                         $timestamp_start = mktime(0,0,0,$month,$day,$year);
62                                         $timestamp_end = mktime(0,0,0,$month,$day+1,$year);  
63                                 }
64                                 $this->exquery .= ' and itime>=' . mysqldate($timestamp_start)
65                                                 . ' and itime<' . mysqldate($timestamp_end);
66                                 break;
67                         default:
68                                 break;
69                 }
70                 if(!$exmode){
71                         $this->exquery .= ' and iblog =' . intval($b->getID());
72                         global $catid;
73                         if($catid)      $this->exquery .= ' and icat =' . intval($catid);
74                 }
75
76                 $filelist = array();
77                 $this->imglists = array();
78                 $this->imgfilename = array();
79                 if(!($filelist = $this->listup())){
80                         $durl = $this->getAdminURL().'pholiot.xml';
81                 }else{
82 //              print_r($filelist);
83                         $amount = min($amount,count($filelist));
84                         if($random){
85                                 srand((float)microtime()*1000000);
86                                 shuffle($filelist);
87                         }
88         
89                                         $feed = '<';
90                                         $feed .= '?';
91                                         $feed .= 'xml version="1.0" encoding="UTF-8"';
92                                         $feed .= '?';
93                                         $feed .= '>';
94                                         $feed .= <<<EOD
95 <pholiotdata>
96         <customize defaultmode="slideshow" fitimagetoview="true" fitviewtoimage="true" pan="false" zoom="true" zoomrandomxy="true" zoomdepth="2" zoomrandomdepth="false" panzoomtime="5000" crossfadetime="3000" slidedelaytime="6000" motionmode="liner" playallgalleries="true" returntobrowse="false" galleries="true" thumbnail="true" xmargin="0" ymargin="0" />
97         <gallery name="pholiot" description="TEST"> 
98 EOD;
99                                         foreach($filelist as $imglist){
100                                                 $linkurl = $this->createGlobalItemLink($imglist[1],'');
101                                                 $feed .= '<image>';
102                                                 $feed .= '<imageurl>'.$CONF['MediaURL'].$imglist[0].'</imageurl>';
103                                                 $feed .= '<caption>'.$imglist[2].'</caption>';
104                                                 $feed .= '<linkurl name="'.$imglist[3].' ID:'.$imglist[1].'">'.$linkurl.'</linkurl>';
105                                                 $feed .= '</image>';
106                                         }
107                                         $feed .= <<<EOD
108         </gallery>
109 </pholiotdata>
110 EOD;
111                         $feed = mb_convert_encoding($feed, "UTF-8", _CHARSET);
112         
113                         $fp = @fopen($this->getDirectory()."feed.xml","w+"); 
114                         if (!$fp)
115                                 $durl = $this->getAdminURL().'pholiot.xml';
116                         fputs($fp,$feed); 
117                         fclose($fp); 
118                         
119                         $durl = $this->getAdminURL().'feed.xml';
120                 }
121
122                 switch($ss){
123                         case 'head':
124                                 echo '<script type="text/javascript" language="JavaScript" src="'.$this->getAdminURL().'pholiot.js"></script>';
125                                 break;
126                         default:
127                                 $surl = $this->getAdminURL().'pholiot.swf';
128                                 echo <<<EOD
129 <script type="text/javascript" language="JavaScript"> 
130 showPholiot({url: '{$surl}', data_url: '{$durl}', bgcolor: '#e8e9da', width: '120', height: '160', menu: 'false'}); 
131 </script>
132 EOD;
133
134
135                 }
136         }
137
138         function listup(){
139                 global $blog,$manager,$CONF;
140                 ($blog)?
141                         $b =& $blog :
142                         $b =& $manager->getBlog($CONF['DefaultBlog']);
143
144                 $query = 'SELECT inumber as itemid, ititle as title, ibody as body, iauthor, itime, imore as more,' ;
145                 $query .= ' icat as catid, iclosed as closed' ;
146                 $query .= ' FROM '.sql_table('item');
147                 $query .= ' WHERE idraft=0';
148                 $query .= ' and itime <=' . mysqldate($b->getCorrectTime());    // don't show future items!
149                 $query .= $this->exquery;
150                 $query .= ' ORDER BY itime DESC'; 
151 //              echo $query;
152         
153                 $res = sql_query($query);
154                 
155                 if(!mysql_num_rows($res)) return FALSE;
156                 
157                 while ($it = mysql_fetch_object($res)){
158                         $ititle = $it->title;
159                         $txt = $it->body.$it->more;
160                         $item_ymd = date("Y-m-d",strtotime($it->itime));
161                         $capt = htmlspecialchars(shorten(strip_tags( (!$ititle)? $txt: $ititle ),30,'..'));
162                         preg_match_all("/\<\%image\((.*)\)\%\>/Us",$txt,$imgpnt,PREG_PATTERN_ORDER);
163                         @array_walk($imgpnt[1], array(&$this, "exarray"), array($it->itemid,$it->iauthor,$capt,$item_ymd));
164                         preg_match_all("/\<\%popup\((.*)\)\%\>/Us",$txt,$imgpntp,PREG_PATTERN_ORDER);
165                         @array_walk($imgpntp[1], array(&$this, "exarray"), array($it->itemid,$it->iauthor,$capt,$item_ymd));
166                 }
167                 return $this->imglists;
168         }
169
170         function exarray($imginfo,$key,$iaid){
171                 list($iid, $auid, $capt,$item_ymd) = $iaid;
172                 $imginfo = explode("|",$imginfo);
173                 if(trim($imginfo[3])) $capt = htmlspecialchars(shorten(strip_tags($imginfo[3]),30,'..'),ENT_QUOTES);
174                 
175                 if(!in_array(strtolower(strrchr($imginfo[0], "." )),$this->fileex)) return;
176                 if(in_array($imginfo[0],$this->imgfilename)) return;
177                 $this->imgfilename[] = $imginfo[0];
178                 
179                 if (!strstr($imginfo[0],'/')) {
180                         $imginfo[0] = $auid . '/' . $imginfo[0];
181                 }
182                 
183                 $this->imglists[] = array($imginfo[0],$iid,$capt,$item_ymd);
184         }
185
186         function canEdit() {
187                 global $member, $manager;
188                 if (!$member->isLoggedIn()) return 0;
189                 return $member->isAdmin();
190         }
191
192
193         function createGlobalItemLink($itemid, $extra = '') {
194                 global $CONF, $manager;
195
196                 if ($CONF['URLMode'] == 'pathinfo'){
197                         $link = $CONF['ItemURL'] . '/item/' . $itemid;
198                 }else{
199                         $blogid = getBlogIDFromItemID($itemid);
200                         $b_tmp =& $manager->getBlog($blogid);
201                         $blogurl = $b_tmp->getURL() ;
202                         if(!$blogurl){
203                                 $blogurl = $CONF['IndexURL'];
204                         }
205                         if(substr($blogurl, -4) != '.php'){
206                                 if(substr($blogurl, -1) != '/')
207                                         $blogurl .= '/';
208                                 $blogurl .= 'index.php';
209                         }
210                         $link = $blogurl . '?itemid=' . $itemid;
211                 }
212                 return addLinkParams($link, $extra);
213         }
214
215
216 }
217 ?>