Del.icio.us Digg FURL FaceBook Stumble Upon Reddit SlashDot Ask BlinkBits BlinkList Co.mments Delirious Feed Me Links Google Bookmarks Linkagogo Ma.gnolia MSN Live Netscape Netvouz Newsvine RawSugar Rojo Smarking Socializer Sphinn Spurl Squidoo Tailrank Technorati Yahoo My Web
Tags: joomla, php5, component, plugin, module, language, coding,
Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Code hữu ích sử dụng trong lập trình Joomla
30-12-2009, 08:42 PM
Post: #1
Code hữu ích sử dụng trong lập trình Joomla
Đôi khi bạn muốn tracking các biến và k0 thể theo dõi kết quả của nó, hãy sử dụng chức năng ghi để theo dõi giá trị biến bất kỳ.

Code:
function write($the_string )  //Write to a log file for checking what has been done
{
    $stored_file =JPATH_SITE.DS.'images'.DS.'rssfeed'.DS.'cached'.DS.'logged.txt';   //Outside stored image
    $fh = @fopen($stored_file, 'a+' );
    if( $fh )
    {
        $the_string .="\n";
        fputs( $fh, $the_string, strlen($the_string));
        fclose( $fh );
        return( true );
    }
    else
    {
        return( false );
    }
}

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
30-12-2009, 11:33 PM
Post: #2
RE: Code hữu ích sử dụng trong lập trình Joomla
Đang xử lý code sized ảnh cho RSS Feed. Dự định là sized ảnh ngay khi xử lý text nhưng k0 ổn.

Giải pháp là sử dụng dạng On the fly như sau:

Code:
thumb_img.php?image_link

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
31-12-2009, 06:13 PM
Post: #3
RE: Code hữu ích sử dụng trong lập trình Joomla
Lấy Itemid hiện thời:
Code:
$itemid =  @JSite::getMenu()->getActive()->id;
Find all posts by this user
Quote this message in a reply
01-01-2010, 04:07 PM
Post: #4
Code hữu ích sử dụng trong lập trình Joomla
Tham khảo từ: http://www.php.net/manual/en/function.pr....php#93694

Code này đã fixed 1 số lỗi khai báo biến.
Code:
<?php
/**
* Find and close unclosed xml tags
**/
function close_tags($text) {
    $patt_open    = "%((?<!</)(?<=<)[\s]*[^/!>\s]+(?=>|[\s]+[^>]*[^/]>)(?!/>))%";
    $patt_close    = "%((?<=</)([^>]+)(?=>))%";
    if (preg_match_all($patt_open,$text,$matches))
    {
        $m_open = $matches[1];
        if(!empty($m_open))
        {
            preg_match_all($patt_close,$text,$matches2);
            $m_close = $matches2[1];
            if (count($m_open) > count($m_close))
            {
                $c_tags = array();
                $m_open = array_reverse($m_open);
        foreach ($m_close as $tag) $c_tags[$tag] = isset($c_tags[$tag])? $c_tags[$tag]++:1;
                foreach ($m_open as $k => $tag) {
            $c_tags[$tag] = isset($c_tags[$tag])? $c_tags[$tag]--:0;
            if ($c_tags[$tag]--<=0) $text.='</'.$tag.'>';
            }
            }
        }
    }
    return $text;
}


$text = "<b>Hello</b>.<p>Hello <br /><strong>xy.<h1>jhjkhkj";
echo htmlspecialchars($text) . '<br />';
echo htmlspecialchars(close_tags($text)). '<br />';
echo close_tags($text);
?>

Tham khảo thêm:
PHP: Parsing HTML to find Links
http://www.the-art-of-web.com/php/parse-links/

http://www.the-art-of-web.com/php/

http://www.web-development-blog.com/arch...match_all/
Ultimate Regular Expression for HTML tag parsing with PHP
Code:
$regex = "/<\/?\w+((\s+(\w|\w[\w-]*\w)(\s*=\s*(?:\".*?\"|'.*?'|[^'\">\s]+))?)+\s*|\s*)\/?>/i";

PHP function for cleaning up HTML and JavaSctipt code - year 2006
Code:
<?php

//Function to seperate multiple tags one line
function fix_newlines_for_clean_html($fixthistext)
{
    $fixthistext_array = explode("\n", $fixthistext);
    foreach ($fixthistext_array as $unfixedtextkey => $unfixedtextvalue)
    {
        //Makes sure empty lines are ignores
        if (!preg_match("/^(\s)*$/", $unfixedtextvalue))
        {
            $fixedtextvalue = preg_replace("/>(\s|\t)*</U", ">\n<", $unfixedtextvalue);
            $fixedtext_array[$unfixedtextkey] = $fixedtextvalue;
        }
    }
    return implode("\n", $fixedtext_array);
}

function clean_html_code($uncleanhtml)
{
    //Set wanted indentation
    $indent = "    ";


    //Uses previous function to seperate tags
    $fixed_uncleanhtml = fix_newlines_for_clean_html($uncleanhtml);
    $uncleanhtml_array = explode("\n", $fixed_uncleanhtml);
    //Sets no indentation
    $indentlevel = 0;
    foreach ($uncleanhtml_array as $uncleanhtml_key => $currentuncleanhtml)
    {
        //Removes all indentation
        $currentuncleanhtml = preg_replace("/\t+/", "", $currentuncleanhtml);
        $currentuncleanhtml = preg_replace("/^\s+/", "", $currentuncleanhtml);
        
        $replaceindent = "";
        
        //Sets the indentation from current indentlevel
        for ($o = 0; $o < $indentlevel; $o++)
        {
            $replaceindent .= $indent;
        }
        
        //If self-closing tag, simply apply indent
        if (preg_match("/<(.+)\/>/", $currentuncleanhtml))
        {
            $cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;
        }
        //If doctype declaration, simply apply indent
        else if (preg_match("/<!(.*)>/", $currentuncleanhtml))
        {
            $cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;
        }
        //If opening AND closing tag on same line, simply apply indent
        else if (preg_match("/<[^\/](.*)>/", $currentuncleanhtml) && preg_match("/<\/(.*)>/", $currentuncleanhtml))
        {
            $cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;
        }
        //If closing HTML tag or closing JavaScript clams, decrease indentation and then apply the new level
        else if (preg_match("/<\/(.*)>/", $currentuncleanhtml) || preg_match("/^(\s|\t)*\}{1}(\s|\t)*$/", $currentuncleanhtml))
        {
            $indentlevel--;
            $replaceindent = "";
            for ($o = 0; $o < $indentlevel; $o++)
            {
                $replaceindent .= $indent;
            }
            
            $cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;
        }
        //If opening HTML tag AND not a stand-alone tag, or opening JavaScript clams, increase indentation and then apply new level
        else if ((preg_match("/<[^\/](.*)>/", $currentuncleanhtml) && !preg_match("/<(link|meta|base|br|img|hr)(.*)>/", $currentuncleanhtml)) || preg_match("/^(\s|\t)*\{{1}(\s|\t)*$/", $currentuncleanhtml))
        {
            $cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;
            
            $indentlevel++;
            $replaceindent = "";
            for ($o = 0; $o < $indentlevel; $o++)
            {
                $replaceindent .= $indent;
            }
        }
        else
        //Else, only apply indentation
        {$cleanhtml_array[$uncleanhtml_key] = $replaceindent.$currentuncleanhtml;}
    }
    //Return single string seperated by newline
    return implode("\n", $cleanhtml_array);    
}
?>

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
03-01-2010, 07:12 PM
Post: #5
RE: Code hữu ích sử dụng trong lập trình Joomla
Khái niệm về LT trong Joomla:

http://www.mightyextensions.com/knowledg...t-mvc-ajax
Kiểm tra host của 1and1.com
http://links.1and1faqs.com/check_info.php5

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
12-02-2010, 11:03 PM
Post: #6
RE: Code hữu ích sử dụng trong lập trình Joomla
Default youtube video thumbnail for video: http://www.youtube.com/watch?v=UpDtDsNJn...r_embedded - _http://www.youtube.com/watch?v=UpDtDsNJnSo&feature=player_embedded
is [Image: default.jpg] -_http://img.youtube.com/vi/UpDtDsNJnSo/default.jpg
You can get more at: http://www.bernzilla.com/item.php?id=848
Find all posts by this user
Quote this message in a reply
14-02-2010, 08:20 PM
Post: #7
RE: Code hữu ích sử dụng trong lập trình Joomla
List all of file with filetype in the directory.
Code:
function listFiles( $from = '.', $filetype='mp3')
{
    if(! is_dir($from))
        return false;
    
    $files = array();
    $dirs = array( $from);
    while( NULL !== ($dir = array_pop( $dirs)))
    {
        if( $dh = opendir($dir))
        {
            while( false !== ($file = readdir($dh)))
            {
                if( $file == '.' || $file == '..')
                    continue;
                $path = $dir . '/' . $file;
/*                if( is_dir($path))
                    $dirs[] = $path;
                else
                    $files[] = $path;
*/
        $ext = substr(strrchr($file, '.'), 1);
                if( !is_dir($path) && $ext==$filetype)
                    $files[] = basename($path);
            }
            closedir($dh);
        }
    }
    sort($mp3files);
    return $files;
}

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
17-02-2010, 11:13 PM
Post: #8
RE: Code hữu ích sử dụng trong lập trình Joomla
Hiển thị cảnh báo trong Joomla: http://docs.joomla.org/Display_error_mes...nd_notices

Có thể ứng dụng để hiển thị các biến (giá trị, kiểu ...). Cách để track 1 biến là sử dụng hàm print_r. Để in sang dạng text, sử dụng câu lệnh:
Code:
<pre>
<?php
$a = array ('a' => 'apple', 'b' => 'banana', 'c' => array ('x', 'y', 'z'));
print_r ($a);
?>
</pre>

whil show out:
<pre>
Array
(
    [a] => apple
    [b] => banana
    [c] => Array
        (
            [0] => x
            [1] => y
            [2] => z
        )
)
</pre>

A better way is:
$text = print_r ($a, true);

More at http://php.net/manual/en/function.print-r.php



Ứng dụng JDate:

Code:
JFactory::getDate()->toFormat('%a %d %b %Y - %H:%M');
Ngày trong tuần:
$dayofweek = JFactory::getDate()->toFormat('%u');
$dayofweek is 1 for Monday -> 7 for Sunday.
Nếu sử dụng array: $dayofweek = $dayofweek - 1;
0 - Monday; ... 6 - Sunday.
Chi tiết mã cho toFormat xem tại http://vn2.php.net/strftime
Find all posts by this user
Quote this message in a reply
18-02-2010, 11:56 AM
Post: #9
RE: Code hữu ích sử dụng trong lập trình Joomla
Call a plugin/plugins in a module: - only for 'content'

Code:
    $articledata = JTable::getInstance('content'); //Get the table
    $articledata ->text = 'your content...'; //Prepare your content
    $dispatcher =JDispatcher::getInstance();
    $pparams =new JParameter('');     //parameter type
    
    JPluginHelper::importPlugin('content');
    $results = $dispatcher->trigger('onPrepareContent', array ($articledata,$params, 0));
    //$dispatcher->trigger('onPrepareContent', array(&$item, &$pparams, $limitstart));

    //Output
    echo $articledata->text;

///////////////////////////////////////*****************************/
Or very simple code is:

$content = JHTML::_('content.prepare', $content);

Đã ứng dụng code trên để viết thành Joomla 1.5.x module. Download at here or at http://kulkul.xahoihoctap.net/kho-tai-li...info&id=19


Attached File(s)
.zip  mod_plugin.zip (Size: 1.76 KB / Downloads: 8)

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
18-02-2010, 10:28 PM
Post: #10
RE: Code hữu ích sử dụng trong lập trình Joomla
Google Weather API: http://www.googleapihelp.com/2009/08/goo...r-api.html

Yahoo Weather API: http://developer.yahoo.com/weather/

Code xử lý file mp3: http://getid3.org/http://www.sourcerally.net/Scripts/20-PHP-MP3-Class

Hợp tuyển các scripts: http://www.sourcerally.net/

Support us [Image: btn_donateCC_LG.gif]
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Extranews plugin - Joomla 1.5 - the pro version 3.x support 9 5,415 01-05-2012 10:32 AM
Last Post: meoit57
  Iframe plugin for Joomla 1.5, 1.6 and 1.7 support 18 8,794 14-04-2012 11:24 PM
Last Post: support
  ImageSized on Joomla 1.7 nocode 2 839 09-12-2011 04:19 PM
Last Post: support
  Content - Joomla Imagesized Plugin for Joomla 1.6 support 23 6,737 29-10-2011 10:54 PM
Last Post: nocode
  Giúp đỡ vấn đề về Imagesized Plugin Joomla 1.6 bantayden 1 707 16-10-2011 09:39 PM
Last Post: Mr. Nguyen
Star Hướng dẫn xây dựng 1 component Joomla 1.5.x gmail2 2 3,276 07-03-2011 03:57 PM
Last Post: thanhlongx4
Lightbulb Danh mục các useful Joomla 1.5.x extension hữu ích support 2 2,690 17-02-2011 12:13 PM
Last Post: thanhlongx4
  viet4777.vatlieu.us JA T3 Framework v2 based Joomla website support 0 1,632 07-08-2010 04:11 PM
Last Post: support
  Ứng dụng phpThumb for imagesized and RSS Plugins support 0 1,486 28-12-2009 09:29 PM
Last Post: support
  Content - Joomla Imagesized Plugin - old version support 3 5,158 23-12-2009 02:38 PM
Last Post: support

Forum Jump:


User(s) browsing this thread: 1 Guest(s)

 Quick Theme: