2012年3月10日土曜日

 個々最近のCMS事情を所感でまとめると、開発ベースとしての枠組みはCakePHPを始めとするMVCフレームワークが担うのでそれほど重用視されなくなった。だから世界的にみてもDrupal,Joomlaが弱くなったと思う。

 で、WordPressが健在なのはノンプログラムでユーザーのやりたい事を実現させている事だと思う。デザイナーやコーダ、ブロガーがコンテンツを仕事や趣味に切り盛りする手段という事です。

 さて、ではXOOPSはどこにという事で、現況の立ち位置はDrupal,Joomla組なんですね。だからマインドマップではデザイナーやコーダ向けの枝葉とCakePHP向けの枝葉を延ばすのが生き残り策だと思います。

 もしも、デザイナーやコーダがハッピーになれて、MVCフレームワークの開発者がハッピーに慣れるなら最高の環境を提供できるじゃないですか。そしてMVCならXOOPS独自の作法を考えなくてもいいのがCakeCMSモジュールでCake流にCMSを調理できるという事です。そしてCakeのViewをsmartyに出せばコーダはハッピーにコードが掛けるという目論見です。

 Smartyがデザイナーに取って難しいという議論はまた次回。。

 雑感でした。

2012年2月25日土曜日

XOOPS Cube weblinks モジュールのハッキング

XOOPS Cube weblinks モジュールのハッキング

登録データを編集する際のフォーム生成プロセス

modlink.php 修正用コントローラ
+ print_modify_form()    //修正ビューの生成
  + show_user_form()
    + $this->_link_form_handler->show_user_form()
      + $this->_load_define();
        + $this->_linkitem_define_handler->load();
          実体:weblinks_get_handler( 'linkitem_define',  $dirname );
       の実体:happy_linux_get_handler($name, $module_dir, 'weblinks');
                       ⬆class
                       
       $class = 'weblinks_linkitem_define_handler';
      
       これが呼ばれる。結果、
      
       weblinks_linkitem_define_handler.php の load() 関数が呼び出される。

2012年2月14日火曜日

galleria 1.2.6js bug

galleria 1.2.6js bug







Error message : Could not extract width/height from image: brabra.....


Before
                    // Delay the callback to "fix" the Adblock Bug
                    // http://code.google.com/p/adblockforchrome/issues/detail?id=3701
                    if ( ( !this.width || !this.height ) ) {
                        window.setTimeout( (function( img ) {
                            return function() {
                                if ( img.width && img.height ) {
                                    complete.call( img );
                                } else {
                                    Galleria.raise('Could not extract width/height from image: ' + img.src +
                                        '. Traced measures: width:' + img.width + 'px, height: ' + img.height + 'px.');
                                }
                            };
                        }( this )), 2);
                    } else {
                        complete.call( this );
                    }
After
                    // Delay the callback to "fix" the Adblock Bug
                    // http://code.google.com/p/adblockforchrome/issues/detail?id=3701
                    if ( ( !this.width || !this.height ) ) {
                        window.setTimeout( (function( img ) {
                            return function() {
                                if ( img.width && img.height ) {
                                    complete.call( img );
                                } else {
                                    try {
                                        $('<img/>').attr('src',$(img).attr("src")).load(function() {complete.call( this )})
                                        } catch(error_message) {
                                        Galleria.raise('Could not extract width/height from image: ' + img.src +
                                        '. Traced measures: width:' + img.width + 'px, height: ' + img.height + 'px.');
                                    }
                                }
                            };
                        }( this )), 2);
                    } else {
                        complete.call( this );
                    }

2011年9月22日木曜日

カスタムBB(XOOPSショートコード)のご案内

XOOPSのプリロードに置くと、[bbcode]を自由に拡張できます。例えば、以下の様なニッチなbbcodeも自在に作れてコアハックもせずにサイト全体で利用できてとても便利です。

[xoops_imageurl] テンプレートの画像フォルダ文字列を取得
[mod_jump] 任意のモジュールのURIへ自動ジャンプ
[iine_bulletintopic_count] ブリティンに貼付けたいいねモジュールのカウント
[xoops_theme] テーマフォルダの文字列を取得
[pm_count] メッセージのカウントを取得
[d3comment_count] コメントのカウントを取得
[d3comment_unread] コメントに未読があるか取得

以下ソースをCustomBB.class.phpとしてpreloadへ保管下さい。

<?php
class CustomBB extends XCube_ActionFilter
{
    function preBlockFilter() {
        $this->mController->mRoot->mDelegateManager->add("MyTextSanitizer.XoopsCodePre",array(&$this,"BBCodePre"));
    }
    /*
     * Add Short code into Delegate BBCode
     */
    function BBCodePre(&$patterns, &$replacements, $allowimage) {

        // Replacement rules for [xoops_imageurl] tag
        $patterns[] = '/\[xoops_imageurl\]/es';
        $replacements[] = "CustomBB::xoops_imageurl();";     
        // Replacement rules for [mod_jump]
        $patterns[] = '/\[mod_jump (.*?)\]/es';
        $replacements[] = "CustomBB::mod_jump('\\1');";
        // Replacement rules for [iine_bulletintopic_count] tag
        $patterns[] = '/\[iine_bulletintopic_count (.*?)\]/es';
        $replacements[] = "CustomBB::iine_bulletintopic_count('\\1');";
        // Replacement rules for [xoops_theme] tag
        $patterns[] = '/\[xoops_theme\]/es';
        $replacements[] = "CustomBB::xoops_theme();";
        // Replacement rules for [pm_count] tag
        $patterns[] = '/\[pm_count (.*?)\]/es';
        $replacements[] = "CustomBB::pm_count('\\1');";
        $patterns[] = '/\[pm_count\]/es';
        $replacements[] = "CustomBB::pm_count();";
        // Replacement rules for [d3comment_count] tag
        $patterns[] = '/\[d3comment_count (.*?)\]/es';
        $replacements[] = "CustomBB::d3comment_count('\\1');";
        // Replacement rules for [d3comment_unread] tag
        $patterns[] = '/\[d3comment_unread (.*?)\]/es';
        $replacements[] = "CustomBB::d3comment_unread('\\1');";
    }
    /*
     * Make Shrot code return strings
     */
    function xoops_theme($args='') {
        return XOOPS_THEME_URL;
    }
    function xoops_imageurl($args='') {
        return $GLOBALS['xoopsTpl']->get_template_vars('xoops_imageurl');
    }
    function mod_jump($args='') {
        // Short code parser start
        $args = html_entity_decode(stripslashes($args));
        $args = preg_replace('/(")/',"",$args);
        $keyval = explode(" ",$args);
        preg_match('/^url=(.*)/',$keyval[0],$matches);
        // Short code parser end
        $ret = "";
        if ($matches){
            $ret = '<script type="text/javascript">window.location.href="';
            $ret .= XOOPS_URL . "/modules/" . $matches[1];
            $ret .= '";</script>';
            return $ret;
        }
    }
    function pm_count($args='') {
        global $xoopsDB;

        // Short code parser start
        $args = preg_replace('/(&quot;|")/',"",stripslashes($args));
        $keyval = explode(" ",$args);
        foreach($keyval as $k){
            preg_match("/(.*)=(.*)/",$k,$matches);
            $params[$matches[1]] = $matches[2];
        }       
        // Short code parser end
       
        $sql = "SELECT count(*) FROM " . $xoopsDB->prefix("message_inbox");
        switch ($params['type']){
            case 'unread':
                $sql .= " WHERE is_read=0";
                if ($params['from_uid']) $sql .= " AND from_uid=".$params['from_uid'];
        }
        $res = $xoopsDB->query($sql);
        list($cnt) = $xoopsDB->fetchRow($res);
        return $cnt;
    }
    function d3comment_count($args='') {
        global $xoopsDB;

        // Short code parser start
        $args = preg_replace('/(&quot;|")/',"",stripslashes($args));
        $keyval = explode(" ",$args);
        foreach($keyval as $k){
            preg_match("/(.*)=(.*)/",$k,$matches);
            $params[$matches[1]] = $matches[2];
        }       
        // Short code parser end
        $mydirname = "d3forum";
        $sql = "SELECT topic_posts_count FROM " . $xoopsDB->prefix($mydirname."_topics");
        if ($params['link_id']) $sql .= " WHERE topic_external_link_id=".$params['link_id'];
        $res = $xoopsDB->query($sql);
        list($cnt) = $xoopsDB->fetchRow($res);
        return $cnt;
    }
    function d3comment_unread($args='') {
        global $xoopsDB,$xoopsUser;

        // Short code parser start
        $args = preg_replace('/(&quot;|")/',"",stripslashes($args));
        $keyval = explode(" ",$args);
        foreach($keyval as $k){
            preg_match("/(.*)=(.*)/",$k,$matches);
            $params[$matches[1]] = $matches[2];
        }       
        // Short code parser end
        $mydirname = "d3forum";
        $sql = "SELECT t.topic_last_post_time, u2t.u2t_time FROM ".$xoopsDB->prefix($mydirname."_topics").
            " t LEFT JOIN ".$xoopsDB->prefix($mydirname."_users2topics")." u2t ON t.topic_id=u2t.topic_id AND u2t.uid="
            . $xoopsUser->uid();
        if ($params['link_id']) $sql .= " WHERE topic_external_link_id=".$params['link_id'];
        $res = $xoopsDB->query($sql);
        list($pt,$ut) = $xoopsDB->fetchRow($res);
        return $pt > $ut ? 1 : 0;
    }
    function iine_bulletintopic_count($args='') {
        global $xoopsDB;

        // Short code parser start
        $args = preg_replace('/(&quot;|")/',"",stripslashes($args));
        $keyval = explode(" ",$args);
        foreach($keyval as $k){
            preg_match("/(.*)=(.*)/",$k,$matches);
            $params[$matches[1]] = $matches[2];
        }
        // Short code parser end
        $mydirname = "bulletin";
        $sql = "SELECT count(id) FROM " . $xoopsDB->prefix("iine_votes") ." where dirname = '" . $mydirname. "' and content_id in (select storyid from ".$xoopsDB->prefix("bulletin_stories")." where topicid = ".$params['topic_id'] .")";
        //print($sql);
        $res = $xoopsDB->query($sql);
        list($cnt) = $xoopsDB->fetchRow($res);
        return $cnt;
    }
}
?>

2011年9月18日日曜日

XOOOPS ショートコード習作1

プライベートメッセージの受信総数、未読数、指定ユーザーIDからの未読数を表示する為のXOOOPS ショートコード

書式1:[pm_count type="unread" from_uid="1"] 返り値はユーザーID1からの未読数
書式2:[pm_count type="unread"]  返り値は未読数
書式3:[pm_count]  返り値はメッセージ総数



<?php
class CustomSanitizer extends XCube_ActionFilter
{
    function preBlockFilter() {
        $this->mController->mRoot->mDelegateManager->add("MyTextSanitizer.XoopsCodePre",array(&$this,"BBCodePre"));
    }
    /*
     * Add Short code into Delegate BBCode
     */
    function BBCodePre(&$patterns, &$replacements, $allowimage) {
        // Replacement rules for [pm_count] tag
        $patterns[] = '/\[pm_count (.*?)\]/es';
        $replacements[] = "CustomSanitizer::pm_count('\\1');";
        $patterns[] = '/\[pm_count\]/es';
        $replacements[] = "CustomSanitizer::pm_count();";
    }
    /*
     * Make Shrot code return strings
     */
    function pm_count($args='') {
        global $xoopsDB;

        // Short code parser start
        $args = preg_replace('/(&quot;|")/',"",stripslashes($args));
        $keyval = explode(" ",$args);
        foreach($keyval as $k){
            preg_match("/(.*)=(.*)/",$k,$matches);
            $params[$matches[1]] = $matches[2];
        }       
        // Short code parser end
       
        $sql = "SELECT count(*) FROM " . $xoopsDB->prefix("message_inbox");
        switch ($params['type']){
            case 'unread':
                $sql .= " WHERE is_read=0";
                if ($params['from_uid']) $sql .= " AND from_uid=".$params['from_uid'];
        }
        $res = $xoopsDB->query($sql);
        list($cnt) = $xoopsDB->fetchRow($res);
        return $cnt;
    }
}
?>

2011年7月29日金曜日

d3blogのコメントがWizMobileでエラーになる件

少々込み入っているのでブログにまとめる。

まず、いきなりリダイレクトされて面食らうのだが、WizMobileではpostメソッドで呼ばれたら$_GETパラメータは取得できないらしい。という事でPOSTメソッドを使うにも関わらず、URLにGETパラメータを埋め込んで呼び出している変則的な部分をPOSTパラメータに埋め込み直す。

xoops_trust_path/modules/d3blog /templates/inc_comment_form.html
themes/wmb_default/templates/d3blog/inc_comment_form.html
themes/mbxoops6/templates/d3blog/inc_comment_form.html


上記のいずれもpostメソッドなのにgetパラメータ渡しを目論んでいた。
<form name='d3blogCommentForm' id='d3blogCommentForm' action='<{$xoops_url}>/modules/<{$mydirname}>/index.php?page=comment_post' method='post'>


(そりゃないぜセニョール)なのでpostへ変更

<form name='d3blogCommentForm' id='d3blogCommentForm' action='<{$xoops_url}>/modules/<{$mydirname}>/index.php' method='post'>

  <!-- comment rule -->
  <div style="text-align: center; <{$smarty.const.MBX_FS_XSMALL}>">
    (<{$rule_text}>)
  </div>
  <{$smarty.const.MBX_BLANK_TAG}>

  <!-- hidden items -->
  <input type='hidden' name='page' id='page' value='comment_post' />

こんな感じで hidden items 欄へパラメータを埋め込み直す。しかーし、このpageという変数はgetでしか受け取ってくれない。という事で次は受け取り部にpost処理を追加

xoops_trust_path/modules/d3blog /main.php

$mytrustdirpath = dirname( __FILE__ ) ;

$page = preg_replace( '/[^a-zA-Z0-9_-]/' , '' , @$_GET['page'] );

の1行下に追加。

// Hacked by a.k.a Bluemoon
if (isset($_POST['page'])) $page = preg_replace( '/[^a-zA-Z0-9_-]/' , '' , @$_POST['page'] );

で、気を取り直してデバッグするとリダイレクトされる。しかしコメント投稿は成功していた。じゃリダイレクトがへんじゃねとさらにハックする。

xoops_trust_path/modules/d3blog /main/comment_post.php

以下、書込み成功後のリダイレクトがどーだったかというと


        if (!isset($comment_post_results)) {

            // if the comment is active, redirect to posted comment
            if ($comment->getVar('com_status') == XOOPS_COMMENT_ACTIVE) {
                redirect_header($redirect_page.'='.$com_itemid.'&amp;com_id='.$newcid.'&amp;com_rootid='.$com_rootid.'&amp;com_mode='.$com_mode.'&amp;com_order='.$com_order.'#comment'.$newcid, 2, _CM_THANKSPOST);
            } else {
                // not active, so redirect to top comment page
                redirect_header($redirect_page.'='.$com_itemid.'&amp;com_mode='.$com_mode.'&amp;com_order='.$com_order.'#comment'.$newcid, 2, _CM_THANKSPOST);
            }
        }
まあ、通常のブラウザなら問題ないんだけどWizMobile的にはきちんとXOOPS_URLが記載されていないのとNGらしい。という事でちゃんと頭から正式なURIを入れてみる。

        if (!isset($comment_post_results)) {
            // Hacked by a.k.a Bluemoon  start
            // if the comment is active, redirect to posted comment
            if ($comment->getVar('com_status') == XOOPS_COMMENT_ACTIVE) {
                $redirect = sprintf('%s/modules/%s/', XOOPS_URL, $mydirname) . $redirect_page.'='.$com_itemid.'&amp;com_id='.$newcid.'&amp;com_rootid='.$com_rootid.'&amp;com_mode='.$com_mode.'&amp;com_order='.$com_order.'#comment'.$newcid;
            } else {
                // not active, so redirect to top comment page
                $redirect = sprintf('%s/modules/%s/', XOOPS_URL, $mydirname) . $redirect_page.'='.$com_itemid.'&amp;com_mode='.$com_mode.'&amp;com_order='.$com_order.'#comment'.$newcid;
            }
            redirect_header($redirect, 2, _CM_THANKSPOST);
            // Hack end
        }


おK。やたらハマって他の作業しながらだが1週間位掛かってしまった。orz

最近マックに開発環境が移行したのでimodeシュミレータとかVMwareで済ましていたのだが、流石にVMwareにxampp入れるのも面倒なのでサーバ直でつついていたのがいけなかった.。しかも前に使っていたWindowsXPな環境がimodeシュミレータ何故かローカルにつながらず最後はauの openwave SDK 6.2でのソース表示に助けられた始末。これってもうダウンロードできないんじゃなかったっけ?(未確認)まあそんなこんなで、WindowsXPな環境はガラケーがある限り取っておかねばなるまい。

ああ、これらGPL V2なので訂正したら私のコメントも(いじってみた)記念に入れておいて欲しい。

2011年7月25日月曜日

Multiple fileupload class for Actung Baby

<?php
class commonCtrl {
    var $getUploadFileName = array();
    function commonCtrl(){
    }
    private function getRandomString($nLengthRequired = 8){
        $rdm_str = md5(uniqid(rand(), true));
        $rdm_str = substr($rdm_str,0,$nLengthRequired);
        return $rdm_str.date("ymdHis");
    }
    private function is_image($file){
        if (!(file_exists($file) && ($fp=fopen($file, "rb")))) return NULL;
        $data = fread($fp, 8);
        fclose($fp);
        if (strncmp("\x00\x00\x01\x00", $data, 4) == 0) {                                   // ICO
            return "ico";
        } else if (strncmp("\x89PNG\x0d\x0a\x1a\x0a", $data, 8) == 0) {                        // PNG
            return "pmg";
        } else if (strncmp('BM', $data, 2) == 0) {                                            // BMP
            return "bmp";
        } else if (strncmp('GIF87a', $data, 6) == 0 || strncmp('GIF89a', $data, 6) == 0) {    // GIF
            return "gif";
        } else if (strncmp("\xff\xd8", $data, 2) == 0) {                                    // JPEG
            return "jpg";
        } else {
            return NULL;
        }
    }
    /*
     * $files = $_FILES
     * $formName = form tag name as <input type="file".... />
     */
    function getUploadFiles($files,$formName,$prefix="img"){
        $this->getUploadFileName = array();
        for($i=0;$i<count($files[$formName]);$i++) {
            $myrow = array(
                'name' => $files[$formName]['name'][$i],
                'type' => $files[$formName]['type'][$i],
                 'tmp_name' => $files[$formName]['tmp_name'][$i],
                'error' => $files[$formName]['error'][$i],
                'size' => intval($files[$formName]['size'][$i])
            );
            if ( $myrow['size']>0 ){
                if ( !is_null($ext = $this->is_image($myrow['tmp_name'])) ){
                    $info = pathinfo($myrow['tmp_name']);
                    $upfile_name = $prefix . $this->getRandomString() . "." . $ext;
                    $upfile_path = XOOPS_ROOT_PATH."/uploads/" . $upfile_name;
                    move_uploaded_file($myrow['tmp_name'], $upfile_path);
                    chmod($upfile_path,0644);
                    $this->getUploadFileName[$i] = $upfile_name;
                }
            }
        }
        //var_dump($this->getUploadFileName); die;
        return $this->getUploadFileName;
    }
}
?>