Page 1 of 1

HTML Helper Remake...

Posted: Wed Jul 06, 2011 8:44 pm
by conradk
Hello people,

Has anyone tried this out ? The HtmlHelper class by the guy who sold most on CodeCanyon.
http://codecanyon.net/item/html-helper-class/161718

Here is the list of features:
label, textfield, textarea, checkbox, radiobutton, select, ul, ol, img, a, style, script, swf (embed youtube, vimeo and other flash content)

Anyways, I believe this item is a little bit overpriced ($4) for what it is, so I'm building my own HTML Preprocess Class.

I haven't figured out every features I'm going to add. However, I might release it on this forum for free (for 24 hours more or less) before trying to get it on CodeCanyon (not sure about CodeCanyon, but we'll see: I don't like to make people pay ^^) :) Kind of a pay back even though you guys could probably do such a class rather quickly :P I'm slow, so consider this as being the most awesome gift EVAAA :lol:

Quick preview of what the head would look like with this class (can't show the rest as I'm not that far yet xD):
<?php
include_once 'lib/htmlpp.class.php';
$htmlpp = new htmlpp();

/* Changing the head settings */
$htmlpp->version('5'); // Sets the page to be HTML 5 (default: xhtml 1.1)
$htmlpp->lang('fr'); // Sets the page language to French (default: en)

/* Meta tags */
$htmlpp->add_meta_tag('keywords', 'ConradK, Webdesign, PHP tutorials');
$htmlpp->add_meta_tag('description', 'ConradK is an 18 year old programmer');

/* Stylesheets */
$htmlpp->add_css('styles.css','print',TRUE); // 2nd and 3rd params optional default: media="all" and inline = FALSE

echo $htmlpp->head();
echo $htmlpp->meta_tags();
echo $htmlpp->stylesheets();
?>
</head>
<body>

</body>
</html>
Any suggestions would be appreciated. This is a simple class, but writing meta tags or remembering the W3C DTDs is the most annoying thing IMO... so I thought I'd build a little tool to make everything easier.

Best regards,
CK

Re: HTML Helper Remake...

Posted: Thu Jul 07, 2011 7:03 am
by bowersbros
I'd suggest maybe having stuff like forms in a seperate class (makes more sense to do; new form();) and such.. Also, in __construct you might want to initialise everything that ever file has..

Doctype, html head body etc tags?

Re: HTML Helper Remake...

Posted: Fri Jul 08, 2011 2:22 am
by Dylan
I'm in agreeance with Bowers;
Separation of the class will benefit both you in terms of organization and structure, and your users in that they can approach it in a logical manner.

I do believe this is a very worthwhile class that will save buckets of time in the end of things :)

Re: HTML Helper Remake...

Posted: Wed Jul 13, 2011 9:45 am
by conradk
Somewhat of a more final version:
/* HtmlHelper class
 *
 * @created : 8.7.2011
 * @function : simplify the writing process of HTML
 */
class HtmlHelper {
   
   /* New tag
    *
    * @created : 8.7.2011
    * @function : open a new tag (not self closing), add classes and an ID
    */
   public static function newTag($type = 'div', $classes = NULL, $id = NULL) {
      $return     = '<' . $type;
      if(is_string($id))
         $return .= ' id="' . $id . '"';
      if(is_string($classes))
         $return .= ' class="' . $classes . '"';
      $return    .= '>';
      return $return;
   }
   /* Close tag
    *
    * @created : 8.7.2011
    * @function : close any non self closing tag, add structure to the HTML page by adding information about which tag is being closed
    *
    * $info : the id or class of the tag that is closed, for example '.myCustomClass' or '#myCustomId'
    */
   public static function closeTag($type = 'div', $info = NULL) {
      $return     = '</' . $type;
      if(is_string($info))
         $return .= '<!-- /' . $info . ' -->';
      $return    .='>';
      return $return;
   }
   /* Meta tag
    *
    * @created : 8.7.2011
    * @function : add any meta tags that have a name and a content attribute    
    */
   public static function metaTag($name, $content) {
      $return = '<meta name="' . $name . '" content="' . $content . '" />';
      return $return;
   }
   /* Title of the HTML page
    *
    * @created : 8.7.2011
    */
   public static function title($title) {
      $return = '<title>' . $title . '</title>';
      return $return;
   }
   /* Favicon
    *
    * @created : 8.7.2011
    * @function : add a favicon to the page
    * @filetype: PNG
    */
   public static function favIcon($filePath) {
      $return = '<link rel="shortcut icon" type="image/png" href="' . $filePath . '" />';
      return $return;
   }
   /* CSS
    *
    * @created : 8.7.2011
    * @function : add a new Cascading StyleSheet to the current page, and set the media it should apply to
    * @filetype : CSS
    */
   public static function css($filePath, $media = 'all') {
      $return = '<link rel="stylesheet" type="text/css" href="' . $filePath . '" media="' . $media . '" />';
      return $return;
   }
   /* JS
    * @created : 8.7.2011
    * @function : add a new Javascript file to the current page, and choose whether it should defer or not
    * @filetype : JS
    */
   public static function js($filePath, $defer = FALSE) {
      $return     = '<script type="text/javascript" src="' . $filePath . '"';
      if($defer === TRUE)
         $return .= ' defer="defer"';
      $return    .= '></script>';
      return $return;
   }
}

Re: HTML Helper Remake...

Posted: Wed Jul 13, 2011 10:52 am
by jacek
line 18 classes should be class. Otherwise, nice :)

I will add some of the things you submitted to the library when I get around to it.

Re: HTML Helper Remake...

Posted: Wed Jul 13, 2011 11:04 am
by conradk
Oh yeah, sorry about that :/