XOOPS データベースで取得した数をGET list($count)
XOOPS list($count) fetchRow
ソース
$result = $this->db->query($sql);
if (!$result) {
return 0;
}
list($count) = $this->db->fetchRow($result);
return $count;
以上です。
入力フォーム xoops
Xoops モジュール module 管理者日記
のソースを参考に紹介します。
storyform.inc.php
include XOOPS_ROOT_PATH."/include/xoopscodes.php";
if(!isset($submit_page)){
$submit_page = $HTTP_SERVER_VARS['PHP_SELF'];
}
?>
<table><tr><td>
<form action='<?php echo $submit_page;?>' method='POST' name='coolsus'>
<?php
echo "<p><b>"._AM_TITLE."</b><br />";
echo "<input type='text' name='title' id='title' value='";
if(isset($title)){
echo $title;
}
echo "' size='70' maxlength='80' />";
echo "</p><p>";
echo "<br /></p><p><b>"._AM_INTROTEXT."</b><br /><br />\n";
xoopsCodeTarea("bodytext", 60, 15, 2);
xoopsSmilies("bodytext");
echo "</p>\n";
if ( !empty($xoopsConfig['allow_html']) ) {
echo "<p>"._AM_ALLOWEDHTML."<br />";
//echo get_allowed_html();
echo "</p>";
}
echo "<p><input type='checkbox' name='nosmily' value='1'";
if(isset($nosmily) && $nosmily==1){
echo " checked='checked'";
}
echo " /> "._AM_DISAMILEY."<br />\n";
echo "<input type='checkbox' name='nohtml' value='1'";
if(isset($nohtml) && $nohtml==1){
echo " checked='checked'";
}
echo " /> "._AM_DISHTML."<br />";
echo "<select name='op'>\n";
echo "<option value='preview' selected='selected'>"._AM_PREVIEW."</option>\n";
echo "<option value='save'>"._AM_SAVE."</option>\n";
if (!empty($storyid)) {
echo "<option value='delete'>"._AM_DELETE."</option>\n";
}
echo "</select>";
if(isset($storyid)){
echo "<input type='hidden' name='storyid' value='".$storyid."' />\n";
}
echo "<input type='hidden' name='type' value='".$type."' />\n";
echo "<input type='hidden' name='fct' value='articles' />\n";
echo "<input type='submit' value='"._AM_GO."' />\n";
echo "</p></form>";
echo "</td></tr></table>";
unset($submit_page);
?>
include XOOPS_ROOT_PATH."/include/xoopscodes.php";
のファイル
function xoopsCodeTarea($textarea_id, $cols=60, $rows=15, $suffix=null)
{
$hiddentext = isset($suffix) ? 'xoopsHiddenText'.trim($suffix) : 'xoopsHiddenText';
//Hack for url, email ...., the anchor is for having a link on [_More...]
// echo "<a name='moresmiley'></a><img src='".XOOPS_URL."/images/url.gif' alt='url' onmouseover='style.cursor=\"hand\"' onclick='xoopsCodeUrl(\"$textarea_id\", \"".htmlspecialchars(_ENTERURL, ENT_QUOTES)."\", \"".htmlspecialchars(_ENTERWEBTITLE, ENT_QUOTES)."\");'/> <img src='".XOOPS_URL."/images/email.gif' alt='email' onmouseover='style.cursor=\"hand\"' onclick='xoopsCodeEmail(\"$textarea_id\", \"".htmlspecialchars(_ENTEREMAIL, ENT_QUOTES)."\");' /> <img src='".XOOPS_URL."/images/imgsrc.gif' alt='imgsrc' onmouseover='style.cursor=\"hand\"' onclick='xoopsCodeImg(\"$textarea_id\", \"".htmlspecialchars(_ENTERIMGURL, ENT_QUOTES)."\", \"".htmlspecialchars(_ENTERIMGPOS, ENT_QUOTES)."\", \"".htmlspecialchars(_IMGPOSRORL, ENT_QUOTES)."\", \"".htmlspecialchars(_ERRORIMGPOS, ENT_QUOTES)."\");' /> <img src='".XOOPS_URL."/images/image.gif' alt='image' onmouseover='style.cursor=\"hand\"' onclick='openWithSelfMain(\"".XOOPS_URL."/imagemanager.php?target=".$textarea_id."\",\"imgmanager\",400,430);' /> <img src='".XOOPS_URL."/images/code.gif' alt='code' onmouseover='style.cursor=\"hand\"' onclick='xoopsCodeCode(\"$textarea_id\", \"".htmlspecialchars(_ENTERCODE, ENT_QUOTES)."\");' /> <img src='".XOOPS_URL."/images/quote.gif' alt='quote' onmouseover='style.cursor=\"hand\"' onclick='xoopsCodeQuote(\"$textarea_id\");'/><br />\n";
$sizearray = array("xx-small"=>"小さい","large"=>"少し大きい", "x-large"=>"大きい", "xx-large"=>"とても大きい");
echo "<select id='".$textarea_id."Size' onchange='setVisible(\"xoopsHiddenText\");setElementSize(\"".$hiddentext."\",this.options[this.selectedIndex].value);'>\n";
echo "<option value='SIZE'>文字のサイズ</option>\n";//._SIZE.
foreach ( $sizearray as $key=>$size ) {
echo "<option value='$key'>$size</option>\n";
}
echo "</select>\n";
$fontarray = array("Arial", "Courier", "Georgia", "Helvetica", "Impact", "Verdana");
echo "<select id='".$textarea_id."Font' onchange='setVisible(\"xoopsHiddenText\");setElementFont(\"".$hiddentext."\",this.options[this.selectedIndex].value);'>\n";
echo "<option value='FONT'>"._FONT."</option>\n";
foreach ( $fontarray as $font ) {
echo "<option value='$font'>$font</option>\n";
}
echo "</select>\n";
$colorarray = array("00", "33", "66", "99", "CC", "FF");
echo "<select id='".$textarea_id."Color' onchange='setVisible(\"xoopsHiddenText\");setElementColor(\"".$hiddentext."\",this.options[this.selectedIndex].value);'>\n";
echo "<option value='COLOR'>"._COLOR."</option>\n";
foreach ( $colorarray as $color1 ) {
foreach ( $colorarray as $color2 ) {
foreach ( $colorarray as $color3 ) {
echo "<option value='".$color1.$color2.$color3."' style='background-color:#".$color1.$color2.$color3.";color:#".$color1.$color2.$color3.";'>#".$color1.$color2.$color3."</option>\n";
}
}
}
echo "</select><span id='".$hiddentext."'>"._EXAMPLE."</span>\n";
echo "<br />\n";
//Hack smilies move for bold, italic ...
$areacontent = isset( $GLOBALS[$textarea_id] ) ? $GLOBALS[$textarea_id] : '';
echo "<img src='".XOOPS_URL."/images/bold.gif' alt='bold' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"".$hiddentext."\");makeBold(\"".$hiddentext."\");' />
<img src='".XOOPS_URL."/images/italic.gif' alt='italic' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"".$hiddentext."\");makeItalic(\"".$hiddentext."\");' />
<img src='".XOOPS_URL."/images/underline.gif' alt='underline' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"".$hiddentext."\");makeUnderline(\"".$hiddentext."\");'/>
<img src='".XOOPS_URL."/images/linethrough.gif' alt='linethrough' onmouseover='style.cursor=\"hand\"' onclick='setVisible(\"".$hiddentext."\");makeLineThrough(\"".$hiddentext."\");' />
<input type='text' id='".$textarea_id."Addtext' size='20' />
<input type='button' onclick='xoopsCodeText(\"$textarea_id\", \"".$hiddentext."\", \"".htmlspecialchars(_ENTERTEXTBOX, ENT_QUOTES)."\")' value='"._ADD."' />
<br /><br /><textarea id='".$textarea_id."' name='".$textarea_id."' cols='$cols' rows='$rows'>".$areacontent."</textarea><br />\n";
//Fin du hack
}
/*
* Displays smilie image buttons used to insert smilie codes to a target textarea in a form
* $textarea_id is a unique of the target textarea
*/
function xoopsSmilies($textarea_id)
{
$myts =& MyTextSanitizer::getInstance();
$smiles = $myts->getSmileys();
if (empty($smileys)) {
$db =& Database::getInstance();
if ($result = $db->query('SELECT * FROM '.$db->prefix('smiles').' WHERE display=1')) {
while ($smiles = $db->fetchArray($result)) {
//hack smilies move for the smilies !!
echo "<img src='".XOOPS_UPLOAD_URL."/".htmlspecialchars($smiles['smile_url'])."' border='0' onmouseover='style.cursor=\"hand\"' alt='' onclick='xoopsCodeSmilie(\"".$textarea_id."\", \" ".$smiles['code']." \");' />";
//fin du hack
}
}
} else {
$count = count($smiles);
for ($i = 0; $i < $count; $i++) {
if ($smiles[$i]['display'] == 1) {
//hack bis
echo "<img src='".XOOPS_UPLOAD_URL."/".$myts->oopsHtmlSpecialChars($smiles['smile_url'])."' border='0' alt='' onclick='xoopsCodeSmilie(\"".$textarea_id."\", \" ".$smiles[$i]['code']." \");' onmouseover='style.cursor=\"hand\"' />";
//fin du hack
}
}
}
//hack for more
echo " [<a href='#moresmiley' onmouseover='style.cursor=\"hand\"' alt='' onclick='openWithSelfMain(\"".XOOPS_URL."/misc.php?action=showpopups&type=smilies&target=".$textarea_id."\",\"smilies\",300,475);'>"._MORE."</a>]";
} //fin du hack
?>
コメントアウトがあるのは、不必要な機能をとっぱらったからです。
また、文字の色を6色に限定しています。
JavaScript アメブロのソースを覗く (°∀°)b
JavaScript ソースを覗く アメブロの自動プレビュー機能のソースをちょこっと覗いて見ました(°∀°)b
すると、prototypeという文字を発見しました。
prototype(プロトタイプ)(-з-)
プロトタイプ・・・ なんかガンダムっぽぃ!!
JavaScriptは、自分は正直勉強しようと思っては、逃げてしまっていたのでなんのことかわかりませんでした。
ただ、ここで逃げてばかりいてはいけないと思い、勉強してみました。
実は、ただのクラスのことでした。
JavaのScript言語のJavaScript。
Scriptって手書きとかいう意味があるので、簡単な感じなものだと捉えてます。
でも、Javaなのでバリバリ オブジェクト指向
だから、クラスがあるのは当たり前。
読んでいくと別にたいして難しくないんだなぁっということが判明しました。
これからは、JavaScriptについても紹介していきます。
今流行の、Domとかajaxとかのソースを色々載せます。
でも、たいした説明できないので、すいません((o(-゛-;)
AUTO_INCREMENTカラムのIDを返す方法 xoops
XOOPS module eストア
データーベースに新しいデータを入力したとき(INSERT)、AUTO_INCREMENTで新しくできたIDを入手する方法です。
if($this->cartid<0){
$this->cartid=$this->db->getInsertId();
}
function getInsertId(){
return mysql_insert_id($this->conn);
}
なぞぃ関数
mysql_insert_id()
前回実行されたクエリで生成したAUTO_INCREMENTカラムのIDを返す。この関数はAUTO_INCREMENTフィールドを含むテーブルにたいしてINSERTクエリを実行したあとで使用される。
以上です。
画像をアップする方法 xoops
XOOPS module eストア
eストアのソースを使います。
index.php 管理者
・form
echo "<form action='$selfurl' enctype='multipart/form-data' method='POST'>";
echo "<input type='hidden' name='page' value='$page'>";
echo "<input type='hidden' name='storynum' value='$storynum'>";
echo "<input type='hidden' name='op' value='save'>";
echo "<input type='hidden' name='matterid' value='$matterid'>";
echo _AM_SELIMAGE ."<input type='file' name='image' > ";
echo "<input type='submit' value='保存'>";
・save
case "save":
if(!isset($matterid)){
$matterid = -1;
}
$matter = new ShoppingMatter($matterid);
if(isset($_FILES['image']) && $matterid >= 0){
$matter->imageSet($_FILES['image']['tmp_name']);
}
else{
$matter->title = $title;
$matter->bodytext = $bodytext;
$nosmily = (empty($nosmily)) ? 0 : 1;
$nohtml = (empty($nohtml)) ? 0 : 1;
$matter->nosmily = $nosmily;
$matter->nohtml = $nohtml;
$matter->max = $max;
$matter->price = $price;
$matter->disporder = $disporder;
}
if($matter->matterid < 0){
$matter->imageSet(XOOPS_ROOT_PATH. '/modules/shoppingcart/images/noimage.jpg');
}
$matter->store();
if($matterid < 0){
redirect_header($admuri . "?op=newarticle",2,_AM_DBUPDATED);
}
else{
redirect_header($admuri . "?op=editlist&page=$page&storynum=$storynum",2,_AM_DBUPDATED);
}
exit();
break;
function imageSet
function imageSet($fn)
{
$fp = fopen($fn ,"rb");
if(feof($fp)){
return(FALSE);
}
$imgstr = fread($fp,filesize($fn));
fclose($fp);
$img = imagecreatefromstring($imgstr);
$tmpfn = tempnam(XOOPS_ROOT_PATH.'/modules/shoppingcart/images/','jpeg_') ;
if(!imagejpeg($img,$tmpfn)){
return(FALSE);
}
imagedestroy($img);
$fp = fopen($tmpfn ,"rb");
if(feof($fp)){
return(FALSE);
}
$imgstr = fread($fp,filesize($tmpfn));
fclose($fp);
unlink($tmpfn);
$this->image = $imgstr;
return(TRUE);
}
function store
function store()
{
$myts =& MyTextSanitizer::getInstance();
$ttl =$myts->censorString($this->title);
$ttl = $myts->makeTboxData4Save($ttl);
$btext =$myts->censorString($this->bodytext);
$btext = $myts->makeTareaData4Save($btext);
$img = mysql_escape_string ($this->image);
if ( !isset($this->nosmily) || $this->nosmily != 1 ) {
$this->nosmily = 0;
}
if ( !isset($this->nohtml) || $this->nohtml != 1 ) {
$this->nohtml = 0;
}
if ( $this->matterid < 0 ){
$sql = sprintf("INSERT INTO ".$this->db->prefix('shoppingcart_matter')." (disporder,title,cdate,price,max,nohtml,nosmily,bodytext,image) VALUES ('%d','%s',NOW(),%u,%u,%u,%u,'%s','%s')", $this->disporder,$ttl,$this->price,$this->max,$this->nohtml, $this->nosmily,$this->bodytext,$img);
}
else
{
$sql = sprintf("UPDATE ".$this->db->prefix('shoppingcart_matter')." SET disporder=%d,title ='%s',price=%u,max=%u,bodytext = '%s',nohtml = %u,nosmily = %u ,image='%s' WHERE matterid = %u ",$this->disporder,$ttl, $this->price,$this->max,$btext,$this->nohtml,$this->nosmily,$img,$this->matterid);
$newmatterid = $this->matterid;
}
if (!($result = $this->db->queryF($sql))) {
return false;
}
if ( empty($newmatterid) ) {
$newmatterid = $this->db->getInsertId();
$this->matterid = $newmatterid;
}
return $newmatterid;
}
なぞぃ関数
$_FILES['image']['tmp_name'] // 一時的に付けられたファイル名
$_FILES['image']['type'] //ファイルのMIME型
$_FILES['image']['size'] //ファイルのサイズ
$_FILES['image']['name'] //アップロードファイル名
$_FILES['image']['error'] //エラーコード
feof($fp) //ファイルの終端まで読み込んだか確認
imagejpeg($img,$file) //$imgからJPEGファイル$fileを作成する。$fileを省略した場合はそのまま画像を出力
説明
<form action='$selfurl' enctype='multipart/form-data' method='POST'>
<input type='file' name='image' >
<input type='submit' value='保存'>
で送った一次ファイルを開き、JPEG_~というファイルで保存(jpegなら)
そして、 $this->image にイメージデータを入れる。
store関数を使い、サニタイズしたデータをデータベースにいれる。