Example #1
0
 function actionStatus()
 {
     // Create the URL object
     $url = new YDUrl('http://www.yellowduck.be/index.xml');
     // Dump the headers
     YDDebugUtil::dump($url->getStatus());
 }
 function pbase()
 {
     // Initialize the parent
     $this->YDRequest();
     // Initialize the template
     $this->template = new YDTemplate();
     // Set the home url
     $this->homeUrl = 'http://www.pbase.com/beachshop/';
     $this->template->assign('homeUrl', $this->homeUrl);
     // Title for the image gallery
     $this->template->assign('galTitle', 'Beachshop Pictures');
     // Start with no galleries and no selected gallery
     $this->galleries = array();
     $this->gallery = null;
     // Download the gallery index
     $pIndex = '/HREF="http:\\/\\/www.pbase.com\\/beachshop\\/(.*?)" class="thumbnail".*? src="http:\\/\\/.*?.image.pbase.com\\/.*?\\/.*?\\/small\\/([0-9]+).*?alt="(.*?)">/ism';
     $objUrl = new YDUrl($this->homeUrl . 'root&page=all');
     $contents = $objUrl->getContentsWithRegex($pIndex);
     // Loop over the matching patterns to construct the galleries list
     for ($i = 0; $i < sizeof($contents[1]); $i++) {
         // Initialize the array if needed
         if (!isset($this->galleries[$i])) {
             $this->galleries[$i] = array();
         }
         // Fill in the details
         $this->galleries[$i]['title'] = $contents[3][$i];
         $this->galleries[$i]['url'] = $this->homeUrl . $contents[1][$i] . '&page=all';
         $this->galleries[$i]['thumbnail'] = $this->homeUrl . 'image/' . $contents[2][$i] . '/small.jpg';
         $this->galleries[$i]['id'] = md5($this->galleries[$i]['url']);
         // Get the contents of the URL
         $pGallery = '/www\\.pbase\\.com\\/beachshop\\/image\\/([0-9]+)/ism';
         $objUrl = new YDUrl($this->galleries[$i]['url']);
         $pcontents = $objUrl->getContentsWithRegex($pGallery);
         // Add the list of images
         $this->galleries[$i]['images'] = $pcontents[1];
     }
     // If a gallery is selected, assign it to the gallery variable
     if (isset($_GET['gal'])) {
         foreach ($this->galleries as $gallery) {
             if ($gallery['id'] == $_GET['gal']) {
                 $this->gallery = $gallery;
                 $this->template->assign('gallery', $gallery);
             }
         }
     }
 }
 function actionDefault()
 {
     // create options and attributes
     $options = array('pt' => 'Portugal', 'br' => 'Brasil', 'be' => 'Belgium');
     $attributes = array('src' => YDUrl::makeLinkAbsolute('./flags/'), 'ext' => 'gif');
     // Create the form and add element
     $form = new YDForm('form1');
     $form->addElement('selectimage', 'si', 'Select country', $attributes, $options);
     // Display the template
     $form->display();
 }
Example #4
0
 function initCommentsFeed()
 {
     // Get the weblog items
     $comments = $this->weblog->getComments(null, 'CREATED DESC', YDConfig::get('max_syndicated_items', 15));
     // Initialize the feed
     $this->feed = new YDFeedCreator();
     $this->feed->setTitle(YDConfig::get('weblog_title', 'Untitled Weblog') . ' - ' . t('comments'));
     $this->feed->setDescription(YDConfig::get('weblog_description', 'Untitled Weblog Description'));
     $this->feed->setLink(YDUrl::makeLinkAbsolute('index.php'));
     // Add the items
     foreach ($comments as $comment) {
         $body = $comment['comment'] . "\n\n" . t('by') . ' ' . $comment['username'];
         $this->feed->addItem($comment['item_title'], YDTplModLinkItem($comment['item_id'], '#comment'), YDTplModBBCode($body));
     }
 }
Example #5
0
<?php

// initialize the Yellow Duck Framework
include_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php';
YDInclude('YDDatabase.php');
YDInclude('YDUrl.php');
// BASIC CONFIGURATION: set YDDatabase instance connection
YDDatabase::registerInstance('default', 'mysql', 'xpto', 'root', '', 'localhost');
// BASIC CONFIGURATION: set portal language. Currently you can use 'en' and 'pt'.
YDLocale::set('en');
// set admin template path
YDConfig::set('YDCMTEMPLATES_ADMIN_PATH', dirname(__FILE__) . '/backend/templates');
YDConfig::set('YDCMTEMPLATES_ADMIN_URL', YDUrl::makeLinkAbsolute('./templates'));
 /**
  *  This function loads any type of content based on the YD_XML constants.
  *
  *  @param $mixed   A string, file, url or array for loading when instantiating
  *                  the object. Default: empty.
  *  @param $type    The type of the $mixed input. Must be one of the following:
  *                  YD_XML_FILE, YD_XML_URL, YD_XML_STRING or YD_XML_ARRAY.
  */
 function load($mixed, $type = YD_XML_FILE)
 {
     if (empty($mixed)) {
         trigger_error('No file, string, array or url specified', YD_ERROR);
     }
     switch ($type) {
         case YD_XML_URL:
             include_once YD_DIR_HOME_CLS . '/YDUrl.php';
             $url = new YDUrl($mixed);
             $contents = $url->getContents(false);
             break;
         case YD_XML_FILE:
             include_once YD_DIR_HOME_CLS . '/YDFileSystem.php';
             $file = new YDFSFile($mixed);
             $contents = $file->getContents();
             break;
         case YD_XML_STRING:
             $contents = $mixed;
             break;
         case YD_XML_ARRAY:
             $this->loadArray($mixed);
             return;
         default:
             trigger_error('Type of input unknown.', YD_ERROR);
     }
     $this->reset();
     $this->parseXML($contents);
 }
 function downloadFile($file)
 {
     YDUpdateLog::info('Downloading: ' . YDUpdateTools::shortPath($file));
     $url = new YDUrl(YDConfig::get('chkoutUrl') . $file);
     $data = $url->getContents(false);
     if (strpos($data, 'Index of') === false) {
         $f = new YDFSFile(YDUpdateTools::tempPath($file), true);
         $f->setContents($data);
     }
 }
Example #8
0
 function initGalleryFeed()
 {
     // Get the weblog items
     $items = $this->weblog->getItems();
     // Initialize the feed
     $this->feed = new YDFeedCreator();
     $this->feed->setTitle(YDConfig::get('weblog_title', 'Untitled Weblog') . ' - ' . t('archives_gallery'));
     $this->feed->setDescription(YDConfig::get('weblog_description', 'Untitled Weblog Description'));
     $this->feed->setLink(YDUrl::makeLinkAbsolute('index.php'));
     // Add the items
     foreach ($items as $item) {
         if (sizeof($item['images']) > 0) {
             $body = '';
             foreach ($item['images'] as $image) {
                 $body .= '<img src="' . YDTplModLinkThumb($image) . '"/> ';
             }
             $this->feed->addItem($item['title'], YDTplModLinkItemGallery($item), YDTplModBBCode($body));
         }
     }
 }
Example #9
0
 function actionMerge()
 {
     $urla = new YDUrl('http://www.yellowduck.be/directory/test/index.php?do=x&id=1&var[]=big&good=#10');
     $urlb = new YDUrl('http://www.yellowduck.be/directory/test/index.php?do=x&id=3&name=blah&var[]=small&good=yes');
     $urlc = new YDUrl('http://www.yellowduck.be/directory/test/index.php?var[]=medium&c=123');
     // Show the original URLs
     YDDebugUtil::dump($urla->getUrl(), 'URL A');
     YDDebugUtil::dump($urlb->getUrl(), 'URL B');
     YDDebugUtil::dump($urlc->getUrl(), 'URL C');
     // Merge the objects
     $urla->merge($urlb);
     $urlb->merge(array($urla, $urlc));
     // Show the new URLs
     YDDebugUtil::dump($urla->getUrl(), 'The new URL A - merged B');
     YDDebugUtil::dump($urlb->getUrl(), 'The new URL B - merged A and C');
 }
 function initTemplate()
 {
     // Assign the userdata to the template
     $this->tpl->assign('user', $this->user);
     // Standard stuff for the sidebar
     $categories = $this->weblog->getCategories();
     $pages = $this->weblog->getPages();
     $links = $this->weblog->getLinks();
     // Assign them to the template
     $this->tpl->assign('categories', $categories);
     $this->tpl->assign('pages', $pages);
     $this->tpl->assign('links', $links);
     // Assign the weblog details
     $this->tpl->assign('weblog_title', YDConfig::get('weblog_title', 'Untitled Weblog'));
     $this->tpl->assign('weblog_description', YDConfig::get('weblog_description', 'Untitled Weblog Description'));
     $this->tpl->assign('weblog_dir', YDUrl::makeLinkAbsolute('.'));
     $this->tpl->assign('weblog_link', YDUrl::makeLinkAbsolute('index.php'));
     $this->tpl->assign('weblog_link_rss', YDUrl::makeLinkAbsolute('xml.php?do=rss'));
     $this->tpl->assign('weblog_link_atom', YDUrl::makeLinkAbsolute('xml.php?do=atom'));
     $this->tpl->assign('weblog_link_comments_rss', YDUrl::makeLinkAbsolute('xml.php?do=rsscomments'));
     $this->tpl->assign('weblog_link_comments_atom', YDUrl::makeLinkAbsolute('xml.php?do=atomcomments'));
     $this->tpl->assign('weblog_link_archive', YDUrl::makeLinkAbsolute('archive.php'));
     $this->tpl->assign('weblog_link_archive_gallery', YDUrl::makeLinkAbsolute('archive_gallery.php'));
     // Get the link to the different directories
     $uploads_dir = YDUrl::makeLinkAbsolute($this->dir_uploads);
     $skin_dir = YDUrl::makeLinkAbsolute($this->dir_skins . $this->skin);
     $image_dir = YDUrl::makeLinkAbsolute($skin_dir . '/images');
     // Add the different directories to the template
     $this->tpl->assign('uploads_dir', $uploads_dir);
     $this->tpl->assign('skin_dir', $skin_dir);
     $this->tpl->assign('image_dir', $image_dir);
 }
 function initTemplate()
 {
     // Assign the userdata to the template
     $this->tpl->assign('user', $this->user);
     // Assign the weblog details
     $this->tpl->assign('weblog_title', YDConfig::get('weblog_title', 'Untitled Weblog'));
     $this->tpl->assign('weblog_description', YDConfig::get('weblog_description', 'Untitled Weblog Description'));
     $this->tpl->assign('weblog_language', YDConfig::get('weblog_language', 'en'));
     $this->tpl->assign('google_analytics', YDConfig::get('google_analytics', '') != '');
     // Get the link to the different directories
     $uploads_dir = YDUrl::makeLinkAbsolute('../' . $this->dir_uploads);
     $skin_dir = YDUrl::makeLinkAbsolute('../' . $this->dir_skins . $this->skin);
     $image_dir = YDUrl::makeLinkAbsolute($skin_dir . '/images');
     // Add the different directories to the template
     $this->tpl->assign('uploads_dir', $uploads_dir);
     $this->tpl->assign('skin_dir', $skin_dir);
     $this->tpl->assign('image_dir', $image_dir);
 }
Example #12
0
 function actionAlter()
 {
     // Create the URL object
     $url = new YDUrl('http://www.yellowduck.be:8080/directory/test/?do=x&id=1#10');
     // Show the original URL
     YDDebugUtil::dump($url->getUrl(), 'The original URL');
     // Get the contents of a query variable
     $do = $url->getQueryVar('do', 'y');
     // Update a query variable
     $url->setQueryVar('do', 'y');
     // setQueryVar can also be used to add a query variable
     $url->setQueryVar('new', 'value');
     // Deleting a query variable
     $url->deleteQueryVar('new');
     // Set a named part
     $url->setNamedPart('host', 'yellowduck.be');
     $url->setNamedPart('user', 'pieter');
     $url->setNamedPart('pass', 'kermit');
     $url->setNamedPart('port', '8081');
     $url->setNamedPart('path', '/dir/index.php');
     $url->setNamedPart('fragment', '12');
     $url->setQueryVar('id', '22');
     // Show the new URL
     YDDebugUtil::dump($url->getUrl(), 'The new URL');
 }
 /**
  *  This function returns the path string to a node
  *
  *  @param $separator    Html separator string
  *  @param $classParents Html class for html links of parents
  *  @param $classCurrent Html class for span ( current element )
  *
  *  @returns    An html string
  */
 function getBreadcrum($separator, $classParents, $classCurrent)
 {
     // init array for results
     $res = array();
     // init url object
     $url = new YDUrl(YD_SELF_SCRIPT);
     // cycle elements to get titles
     foreach ($this->getPath() as $elements) {
         // set url var ID to this element
         $url->setQueryVar('id', $elements['component_id']);
         $url->setQueryVar('component', $elements['type']);
         // compute class name
         if ($this->_id != $elements['content_id']) {
             $res[] = '<a class="' . $classParents . '" href="' . $url->getUrl() . '">' . $elements['title'] . '</a>';
         } else {
             $res[] = '<span class="' . $classCurrent . '">' . $elements['title'] . '</span>';
         }
     }
     // return html string
     return implode($separator, $res);
 }
 function doRequest()
 {
     // Performs the actual HTTP request, returning true or false depending on outcome
     if (!($fp = @fsockopen($this->host, $this->port, $errno, $errstr, $this->timeout))) {
         // Set error message
         switch ($errno) {
             case -3:
                 $this->errormsg = 'Socket creation failed (-3)';
             case -4:
                 $this->errormsg = 'DNS lookup failure (-4)';
             case -5:
                 $this->errormsg = 'Connection refused or timed out (-5)';
             default:
                 $this->errormsg = 'Connection failed (' . $errno . ')';
                 $this->errormsg .= ' ' . $errstr;
                 $this->debug($this->errormsg);
         }
         return false;
     }
     socket_set_timeout($fp, $this->timeout);
     $request = $this->buildRequest();
     $this->debug('Request', $request);
     fwrite($fp, $request);
     // Reset all the variables that should not persist between requests
     $this->headers = array();
     $this->content = '';
     $this->errormsg = '';
     // Set a couple of flags
     $inHeaders = true;
     $atStart = true;
     // Now start reading back the response
     while (!feof($fp)) {
         $line = fgets($fp, 4096);
         if ($atStart) {
             // Deal with first line of returned data
             $atStart = false;
             if (!preg_match('/HTTP\\/(\\d\\.\\d)\\s*(\\d+)\\s*(.*)/', $line, $m)) {
                 $this->errormsg = "Status code line invalid: " . htmlentities($line);
                 $this->debug($this->errormsg);
                 return false;
             }
             $http_version = $m[1];
             // not used
             $this->status = $m[2];
             $status_string = $m[3];
             // not used
             $this->debug(trim($line));
             continue;
         }
         if ($inHeaders) {
             if (trim($line) == '') {
                 $inHeaders = false;
                 $this->debug('Received Headers', $this->headers);
                 if ($this->headers_only) {
                     break;
                     // Skip the rest of the input
                 }
                 continue;
             }
             if (!preg_match('/([^:]+):\\s*(.*)/', $line, $m)) {
                 // Skip to the next header
                 continue;
             }
             $key = strtolower(trim($m[1]));
             $val = trim($m[2]);
             // Deal with the possibility of multiple headers of same name
             if (isset($this->headers[$key])) {
                 if (is_array($this->headers[$key])) {
                     $this->headers[$key][] = $val;
                 } else {
                     $this->headers[$key] = array($this->headers[$key], $val);
                 }
             } else {
                 $this->headers[$key] = $val;
             }
             continue;
         }
         // We're not in the headers, so append the line to the contents
         $this->content .= $line;
     }
     fclose($fp);
     // If data is compressed, uncompress it
     if (isset($this->headers['content-encoding']) && $this->headers['content-encoding'] == 'gzip') {
         $this->debug('Content is gzip encoded, unzipping it');
         $this->content = substr($this->content, 10);
         // See http://www.php.net/manual/en/function.gzencode.php
         $this->content = gzinflate($this->content);
     }
     // If $persist_cookies, deal with any cookies
     if ($this->persist_cookies && isset($this->headers['set-cookie']) && $this->host == $this->cookie_host) {
         $cookies = $this->headers['set-cookie'];
         if (!is_array($cookies)) {
             $cookies = array($cookies);
         }
         foreach ($cookies as $cookie) {
             if (preg_match('/([^=]+)=([^;]+);/', $cookie, $m)) {
                 $this->cookies[$m[1]] = $m[2];
             }
         }
         // Record domain of cookies for security reasons
         $this->cookie_host = $this->host;
     }
     // If $persist_referers, set the referer ready for the next request
     if ($this->persist_referers) {
         $this->debug('Persisting referer: ' . $this->getRequestURL());
         $this->referer = $this->getRequestURL();
     }
     // Finally, if handle_redirects and a redirect is sent, do that
     if ($this->handle_redirects) {
         if (++$this->redirect_count >= $this->max_redirects) {
             $this->errormsg = 'Number of redirects exceeded maximum (' . $this->max_redirects . ')';
             $this->debug($this->errormsg);
             $this->redirect_count = 0;
             return false;
         }
         $location = isset($this->headers['location']) ? $this->headers['location'] : '';
         $uri = isset($this->headers['uri']) ? $this->headers['uri'] : '';
         if ($location || $uri) {
             $url = parse_url($location . $uri);
             // This will FAIL if redirect is to a different site
             if (!empty($url['path'])) {
                 return $this->get($url['path']);
             } else {
                 // Note from Rene (rene@fsfe.org): Now it won't fail anymore.
                 // Quick&Dirty hack... don't blame me... :)
                 $u = new YDUrl($this->headers['location']);
                 $c = new YDHttpClient($u->getHost());
                 $c->setUserAgent($this->user_agent);
                 $c->setAuthorization($this->username, $this->password);
                 $c->setCookies($this->cookies);
                 $c->useGzip($this->use_gzip);
                 $c->setPersistCookies($this->persist_cookies);
                 $c->setPersistReferers($this->persist_referers);
                 $c->setHandleRedirects($this->handle_redirects);
                 $c->setMaxRedirects($this->max_redirects);
                 $c->setHeadersOnly($this->headers_only);
                 $c->setDebug($this->debug);
                 $r = $c->get('/' . $u->getPath());
                 $this->status = $c->getStatus();
                 $this->content = $c->getContent();
                 $this->headers = $c->getHeaders();
                 $this->errormsg = $c->getError();
                 $this->cookies = $c->getCookies();
                 return $r;
             }
         }
     }
     return true;
 }
 function actionEdit()
 {
     // Get the list of categories
     $categories = $this->weblog->getCategoriesAsAssoc();
     // Create the edit form
     $form = new YDWeblogForm('itemForm', 'POST', YD_SELF_SCRIPT . '?do=edit');
     $form->addElement('text', 'title', t('item_title'), array('class' => 'tfM'));
     $form->addElement('textarea', 'body', t('item_body'), array('class' => 'tfM'));
     $form->addElement('textarea', 'body_more', t('item_body_more'), array('class' => 'tfM'));
     $form->addElement('select', 'category_id', t('category'), array('class' => 'tfM', 'style' => 'width: 100%'), $categories);
     $form->addElement('datetimeselect', 'created', t('created_on'), array('class' => 'tfM'));
     $form->addElement('datetimeselect', 'modified', t('last_modified_on'), array('class' => 'tfM'));
     $form->addElement('checkbox', 'is_draft', t('is_draft'), array('style' => 'border: none;'));
     $form->addElement('hidden', 'id');
     $form->addElement('submit', '_cmdSubmit', t('OK'), array('class' => 'button'));
     // Add the form rules
     $form->addRule('title', 'required', t('err_item_title'));
     $form->addRule('body', 'required', t('err_item_body'));
     // Add the filters
     $form->addFilters(array('title'), 'strip_html');
     // Get the ID from the query string
     $id = $this->getIdFromQS();
     // If there is something, set the defaults
     if ($id != -1) {
         // Get the comment by ID
         $defaults = $this->weblog->getItemById($id);
         $defaults['body'] = YDTemplate_modifier_bbcode($defaults['body']);
         $defaults['body_more'] = YDTemplate_modifier_bbcode($defaults['body_more']);
         $defaults['modified'] = gmmktime();
         // Add delete button with existing items
         $form->addElement('button', '_cmdDelete', t('delete'), array('class' => 'button', 'onClick' => 'return YDConfirmDeleteAndRedirect( \'' . addslashes($defaults['title']) . '\', \'' . YD_SELF_SCRIPT . '?do=delete&id=' . $defaults['id'] . '\' );'));
         // Assign the values to the template
         $this->tpl->assign('item', $defaults);
         // Set the defaults
         $form->setDefaults($defaults);
     } else {
         // Get the defaults
         $defaults = array();
         $defaults['is_draft'] = YDConfig::get('dflt_is_draft', false);
         // Set the form defaults
         $form->setDefaults($defaults);
     }
     // Process the form
     if ($form->validate() === true) {
         // Get the form values
         $values = $form->getValues();
         // Update the datetimes
         $values['created'] = $values['created']['timestamp'];
         $values['modified'] = $values['modified']['timestamp'];
         // Set the user
         $values['user_id'] = $this->user['id'];
         // Check if we need to publish or not
         $needs_publish_email = false;
         // If there is an ID, we do an edit
         if ($values['id']) {
             // Get the item by ID
             $item = $this->weblog->getItemByID($values['id']);
             // Check if the item changes from draft to published
             if ($item['is_draft'] && !$values['is_draft']) {
                 // Remember this
                 $needs_publish_email = true;
                 // Update the created timestamp
                 $values['created'] = time();
                 $values['modified'] = time();
             }
             // Update the database
             $this->weblog->updateItem($values);
         } else {
             // Check if the item is draft or not
             if (!$values['is_draft']) {
                 // Remember this
                 $needs_publish_email = true;
                 // Update the created timestamp
                 $values['created'] = time();
                 $values['modified'] = time();
             }
             // Add it to the database
             $this->weblog->addItem($values);
         }
         // Check if we need to send an email
         if ($needs_publish_email) {
             // Send an email if configured
             if (YDConfig::get('email_new_item', true)) {
                 // Add the item ID
                 $values['id'] = $this->weblog->db->getLastInsertID();
                 // Include the YDEmail library
                 YDInclude('YDEmail.php');
                 // Get the list of subscriptions
                 $subscribers = $this->weblog->getUsers();
                 // Add the comment to the email template
                 $this->tpl->assign('item', $values);
                 $this->tpl->assign('weblog_link', YDUrl::makeLinkAbsolute('../index.php'));
                 $this->tpl->assign('item_link', YDTplModLinkWithID('../item.php', $values['id']));
                 // Create the email and send it
                 $eml = new YDEmail();
                 if (!empty($item['user_email'])) {
                     $eml->setFrom($item['user_email'], YDConfig::get('weblog_title', 'Untitled Weblog'));
                 } else {
                     $eml->setFrom('*****@*****.**', YDConfig::get('weblog_title', 'Untitled Weblog'));
                 }
                 $eml->setReplyTo('*****@*****.**');
                 foreach ($subscribers as $subscriber) {
                     $eml->addBcc($subscriber['email'], $subscriber['name']);
                 }
                 $eml->setSubject(t('new_item') . ': ' . strip_tags($values['title']));
                 $eml->setHtmlBody($this->fetch(dirname(__FILE__) . '/../' . $this->dir_skins . $this->skin . '/item_email.tpl'));
                 $eml->send();
             }
         }
         // Redirect to the default action
         if ($values['is_draft']) {
             $this->redirect(YD_SELF_SCRIPT . '?filter=drafts');
         } else {
             $this->redirectToAction();
         }
     }
     // Add the form to the template
     $this->tpl->assignForm('form', $form);
     // Display the template
     $this->display();
 }
function YDTplModLinkThumbSmall($img)
{
    return YDUrl::makeLinkAbsolute(YDConfig::get('dir_uploads', 'uploads') . '/' . dirname($img->relative_path) . '/s_' . basename($img->relative_path));
}
 /**
  *  This function will convert all relative URLs to absolute ones using the given base.
  *
  *  @param  $text   The text in which you want to have the links converted to absolute ones.
  *  @param  $base   (optional) The base url. By default, it uses the current url.
  *
  *  @returns    The text with all links converted to absolute ones.
  *
  *  @static
  */
 function makeLinksAbsolute($text, $base = null)
 {
     while (eregi("(href|src|action)=\"(([^/])[[:alnum:]/+=%&_.~?-]*)\"", $text, $regs)) {
         $input_uri = str_replace('?', '\\?', $regs[2]);
         $output_uri = YDUrl::makeLinkAbsolute($regs[2], $base);
         $text = eregi_replace("((href|src|action)=\"){$input_uri}(\")", "\\1{$output_uri}\\3", $text);
     }
     return $text;
 }
 /**
  *	This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can
  *	optionally convert line breaks as well as convert the remaining HTML tags to their entities.
  *
  *	@param $data			The data you want to convert.
  *	@param $convertBr		(optional) Boolean to indicate that new lines should be converted to &lt;br/&gt; tags.
  *							This is turned on by default.
  *	@param $convertTags		(optional) Boolean to indicate that tags should be converted to HTML. This is turned
  *							on by default.
  *	@param $convertLinks	(optional) Boolean to indicate if links should be automatically highlighted or not.
  *							This is turned on by default.
  *  @param $baseUrl         (optional) If you give this a non-null value, it will convert all links to absolute
  *                          links using this url as the base url.
  *
  *	@returns	The HTML equivalent of the string with all the BBCode's converted according to the conversion table
  *				of this class.
  */
 function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null)
 {
     // Encode the references
     $data = YDStringUtil::encodeString($data);
     // Convert the links to BBcode
     if ($convertLinks === true) {
         $data = $this->convertLinks($data);
     }
     // Convert tags if needed
     if ($convertTags === true) {
         $data = str_replace('<', '&lt;', $data);
         $data = str_replace('>', '&gt;', $data);
     }
     // Fix common problems
     $data = str_replace("\r\n", "\n", $data);
     $data = str_replace("\r", "\n", $data);
     $data = str_replace("[/quote]\n\n", "[/quote]\n", $data);
     // Convert the tags
     $data = $this->parser->parse($data);
     // Strip the leftover tags
     $data = trim(preg_replace('/\\[\\/[a-z]+\\]/i', '', $data));
     // Open http links in a new window
     $data = str_replace(' href="http://', ' target="_blank" href="http://', $data);
     // Convert tags if needed
     if ($convertBr === true) {
         $data = nl2br(trim($data));
     }
     // Convert smilies if needed
     $smilies_path = YDConfig::get('YD_BBCODE_SMILIES_DIR', '');
     $smilies_url = YDConfig::get('YD_BBCODE_SMILIES_URL', '');
     if (is_dir($smilies_path)) {
         foreach ($this->smilies as $smilie => $file) {
             $data = str_replace($smilie, '<img src="' . $smilies_url . '/' . $file . '" width="15" height="15" />', $data);
         }
     }
     // Make links absolute if needed
     if (!is_null($baseUrl)) {
         include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php';
         $data = YDUrl::makeLinksAbsolute($data, $baseUrl);
     }
     // Return the data
     return $data;
 }
 /**
  *	This function will add a new item to the feed. You need to at least give in a title, link. A description is
  *	advised but optional. Also a GUID is optional. If no GUID is given, an automatic one will be created which
  *	is the md5 checksum of the different elememts.
  *
  *	@param $title	        The title of the feed item.
  *	@param $link	        The link to the feed item.
  *	@param $desc	        (optional) The description for the feed item.
  *	@param $guid	        (optional) The guid for the feed item.
  *  @param $enclosure       (optional) The url of the enclosure.
  *  @param $enclosure_size  (optional) The size in bytes of the enclosure.
  *  @param $enclosure_type  (optional) The mime-type of the enclosure.
  *  @param $commentlink     (optional) The link to the comment page for the item.
  *
  *  @remark
  *      Enclosures are only supported for ATOM and RSS 2.0 feeds.
  */
 function addItem($title, $link, $desc = null, $guid = null, $enclosure = null, $enclosure_size = null, $enclosure_type = null, $commentlink = null)
 {
     $link = YDUrl::makeLinkAbsolute($link, $this->_link);
     $desc = YDUrl::makeLinksAbsolute($desc, $this->_link);
     if (empty($guid)) {
         $checkSum = $this->_link . $title . $link;
         if ($desc != null) {
             $checkSum .= $desc;
         }
         $guid = md5($checkSum);
     }
     if (!is_null($enclosure) && (is_null($enclosure_size) || is_null($enclosure_type))) {
         trigger_error('Enclosures must have both type and size specified!', YD_ERROR);
     }
     $item = array('title' => $this->_encodeStrings ? YDStringUtil::encodeString($title) : $title, 'link' => $link, 'description' => $this->_encodeStrings ? YDStringUtil::encodeString($desc) : $desc, 'guid' => $guid, 'enclosure' => $enclosure, 'enclosure_size' => $enclosure_size, 'enclosure_type' => $enclosure_type, 'comments' => $commentlink);
     $this->_items[$guid] = $item;
 }
 /**
  *  This is the class constructor for the YDForm class.
  *
  *  @param $name        The name of the form.
  *  @param $method      (optional) Method used for submitting the form.
  *                      Normally, this is either POST or GET.
  *  @param $action      (optional) Action used for submitting the form.
  *                      If not specified, it will default to the URI of
  *                      the current request.
  *  @param $target      (optional) HTML target for the form.
  *  @param $attributes  (optional) Attributes for the form.
  */
 function YDForm($name, $method = 'post', $action = '', $target = '_self', $attributes = array())
 {
     // Initialize the parent
     $this->YDBase();
     // Initialize the variables
     $this->_name = $name;
     $this->_method = strtoupper($method) == 'GET' ? 'get' : 'post';
     $this->_action = empty($action) ? $_SERVER['REQUEST_URI'] : $action;
     $this->_target = empty($target) ? '_self' : $target;
     $this->_attributes = $attributes;
     $this->_legend = null;
     // The list of known elements, rules, filters and validators
     $this->_regElements = array();
     $this->_regRules = array();
     $this->_regFilters = array();
     $this->_regValidators = array();
     $this->_regRenderers = array();
     // The list of elements, rules and filters
     $this->_elements = array();
     $this->_rules = array();
     $this->_comparerules = array();
     $this->_formrules = array();
     $this->_filters = array();
     // The list of errors
     $this->_errors = array();
     // The list of default values
     $this->_defaults = array();
     // Some static HTML things
     $this->_htmlRequiredStart = '';
     // Check default translations
     if (!isset($GLOBALS['t']['form_required'])) {
         $GLOBALS['t']['form_required'] = '(required)';
     }
     if (!isset($GLOBALS['t']['form_error'])) {
         $GLOBALS['t']['form_error'] = 'Error: ';
     }
     $this->_htmlRequiredEnd = ' <font color="red">' . t('form_required') . '</font>';
     $this->_htmlErrorStart = '<font color="red">' . t('form_error');
     $this->_htmlErrorEnd = '</font>';
     $this->_requiredNote = '';
     // Check for post or get variables
     if ($this->_method == 'get') {
         $this->_formVars = $_GET;
     } else {
         $this->_formVars = $_POST;
     }
     // Add the standard elements
     $this->registerElement('bbtextarea', 'YDFormElement_BBTextArea', 'YDFormElement_BBTextArea.php');
     $this->registerElement('button', 'YDFormElement_Button', 'YDFormElement_Button.php');
     $this->registerElement('checkbox', 'YDFormElement_Checkbox', 'YDFormElement_Checkbox.php');
     $this->registerElement('checkboxgroup', 'YDFormElement_CheckboxGroup', 'YDFormElement_CheckboxGroup.php');
     $this->registerElement('date', 'YDFormElement_Date', 'YDFormElement_Date.php');
     $this->registerElement('dateselect', 'YDFormElement_DateSelect', 'YDFormElement_DateSelect.php');
     $this->registerElement('datetimeselect', 'YDFormElement_DateTimeSelect', 'YDFormElement_DateTimeSelect.php');
     $this->registerElement('timeselect', 'YDFormElement_TimeSelect', 'YDFormElement_TimeSelect.php');
     $this->registerElement('file', 'YDFormElement_File', 'YDFormElement_File.php');
     $this->registerElement('hidden', 'YDFormElement_Hidden', 'YDFormElement_Hidden.php');
     $this->registerElement('image', 'YDFormElement_Image', 'YDFormElement_Image.php');
     $this->registerElement('password', 'YDFormElement_Password', 'YDFormElement_Password.php');
     $this->registerElement('radio', 'YDFormElement_Radio', 'YDFormElement_Radio.php');
     $this->registerElement('reset', 'YDFormElement_Reset', 'YDFormElement_Reset.php');
     $this->registerElement('select', 'YDFormElement_Select', 'YDFormElement_Select.php');
     $this->registerElement('selectimage', 'YDFormElement_SelectImage', 'YDFormElement_SelectImage.php');
     $this->registerElement('submit', 'YDFormElement_Submit', 'YDFormElement_Submit.php');
     $this->registerElement('text', 'YDFormElement_Text', 'YDFormElement_Text.php');
     $this->registerElement('textarea', 'YDFormElement_TextArea', 'YDFormElement_TextArea.php');
     $this->registerElement('textareacounter', 'YDFormElement_TextAreaCounter', 'YDFormElement_TextAreaCounter.php');
     $this->registerElement('span', 'YDFormElement_Span', 'YDFormElement_Span.php');
     $this->registerElement('img', 'YDFormElement_Img', 'YDFormElement_Img.php');
     $this->registerElement('link', 'YDFormElement_Link', 'YDFormElement_Link.php');
     $this->registerElement('div', 'YDFormElement_Div', 'YDFormElement_Div.php');
     $this->registerElement('autocompleter', 'YDFormElement_Autocompleter', 'YDFormElement_Autocompleter.php');
     $this->registerElement('switchmenu', 'YDFormElement_SwitchMenu', 'YDFormElement_SwitchMenu.php');
     $this->registerElement('grid', 'YDFormElement_Grid', 'YDFormElement_Grid.php');
     $this->registerElement('captcha', 'YDFormElement_Captcha', 'YDFormElement_Captcha.php');
     $this->registerElement('timezone', 'YDFormElement_Timezone', 'YDFormElement_Timezone.php');
     // Add the rules
     $this->registerRule('value', array('YDValidateRules', 'value'), 'YDValidateRules.php');
     $this->registerRule('required', array('YDValidateRules', 'required'), 'YDValidateRules.php');
     $this->registerRule('maxlength', array('YDValidateRules', 'maxlength'), 'YDValidateRules.php');
     $this->registerRule('minlength', array('YDValidateRules', 'minlength'), 'YDValidateRules.php');
     $this->registerRule('rangelength', array('YDValidateRules', 'rangelength'), 'YDValidateRules.php');
     $this->registerRule('regex', array('YDValidateRules', 'regex'), 'YDValidateRules.php');
     $this->registerRule('email', array('YDValidateRules', 'email'), 'YDValidateRules.php');
     $this->registerRule('not_email', array('YDValidateRules', 'not_email'), 'YDValidateRules.php');
     $this->registerRule('ip', array('YDValidateRules', 'ip'), 'YDValidateRules.php');
     $this->registerRule('lettersonly', array('YDValidateRules', 'lettersonly'), 'YDValidateRules.php');
     $this->registerRule('character', array('YDValidateRules', 'character'), 'YDValidateRules.php');
     $this->registerRule('alphanumeric', array('YDValidateRules', 'alphanumeric'), 'YDValidateRules.php');
     $this->registerRule('numeric', array('YDValidateRules', 'numeric'), 'YDValidateRules.php');
     $this->registerRule('digit', array('YDValidateRules', 'digit'), 'YDValidateRules.php');
     $this->registerRule('nopunctuation', array('YDValidateRules', 'nopunctuation'), 'YDValidateRules.php');
     $this->registerRule('nonzero', array('YDValidateRules', 'nonzero'), 'YDValidateRules.php');
     $this->registerRule('exact', array('YDValidateRules', 'exact'), 'YDValidateRules.php');
     $this->registerRule('in_array', array('YDValidateRules', 'in_array'), 'YDValidateRules.php');
     $this->registerRule('not_in_array', array('YDValidateRules', 'not_in_array'), 'YDValidateRules.php');
     $this->registerRule('i_in_array', array('YDValidateRules', 'i_in_array'), 'YDValidateRules.php');
     $this->registerRule('i_not_in_array', array('YDValidateRules', 'i_not_in_array'), 'YDValidateRules.php');
     $this->registerRule('maxwords', array('YDValidateRules', 'maxwords'), 'YDValidateRules.php');
     $this->registerRule('minwords', array('YDValidateRules', 'minwords'), 'YDValidateRules.php');
     $this->registerRule('callback', array('YDValidateRules', 'callback'), 'YDValidateRules.php');
     $this->registerRule('uploadedfile', array('YDValidateRules', 'uploadedfile'), 'YDValidateRules.php');
     $this->registerRule('maxfilesize', array('YDValidateRules', 'maxfilesize'), 'YDValidateRules.php');
     $this->registerRule('mimetype', array('YDValidateRules', 'mimetype'), 'YDValidateRules.php');
     $this->registerRule('filename', array('YDValidateRules', 'filename'), 'YDValidateRules.php');
     $this->registerRule('extension', array('YDValidateRules', 'extension'), 'YDValidateRules.php');
     $this->registerRule('date', array('YDValidateRules', 'date'), 'YDValidateRules.php');
     $this->registerRule('time', array('YDValidateRules', 'time'), 'YDValidateRules.php');
     $this->registerRule('datetime', array('YDValidateRules', 'datetime'), 'YDValidateRules.php');
     $this->registerRule('minlength_escape', array('YDValidateRules', 'minlength_escape'), 'YDValidateRules.php');
     $this->registerRule('maxlength_escape', array('YDValidateRules', 'maxlength_escape'), 'YDValidateRules.php');
     $this->registerRule('rangelength_escape', array('YDValidateRules', 'rangelength_escape'), 'YDValidateRules.php');
     $this->registerRule('httpurl', array('YDValidateRules', 'httpurl'), 'YDValidateRules.php');
     $this->registerRule('maxhyperlinks', array('YDValidateRules', 'maxhyperlinks'), 'YDValidateRules.php');
     $this->registerRule('captcha', array('YDValidateRules', 'captcha'), 'YDValidateRules.php');
     $this->registerRule('timezone', array('YDValidateRules', 'timezone'), 'YDValidateRules.php');
     // Add the filters
     $this->registerFilter('trim', 'trim');
     $this->registerFilter('lower', 'strtolower');
     $this->registerFilter('upper', 'strtoupper');
     $this->registerFilter('utf8_decode', 'utf8_decode');
     $this->registerFilter('strip_html', 'strip_tags');
     $this->registerFilter('safe_html', 'YDFormFilter_safe_html');
     $this->registerFilter('dateformat', 'YDFormFilter_dateformat');
     // Add the renderers
     $this->registerRenderer('array', 'YDFormRenderer_array', 'YDFormRenderer_array.php');
     $this->registerRenderer('html', 'YDFormRenderer_html', 'YDFormRenderer_html.php');
     $this->registerRenderer('xml', 'YDFormRenderer_xml', 'YDFormRenderer_xml.php');
     // Clean the action URL
     $url = new YDUrl($this->_action);
     $this->_action = $url->getUri();
 }
 /**
  *  This function registers a named database instance.
  *
  *  @param $name    The name of the database instance.
  *  @param $driver  Name of the database driver, DNS string or array containing drivername, file name and class name.
  *  @param $db      (optional) Database name to use for the connection. If empty, we are using a DSN string in driver.
  *  @param $user    (optional) User name to use for the connection.
  *  @param $pass    (optional) Password to use for the connection.
  *  @param $host    (optional) Host name to use for the connection.
  *
  *  @static
  */
 function registerInstance($name, $driver, $db = '', $user = '', $pass = '', $host = '')
 {
     // Check if the global array exists
     YDDatabase::_initNamedInstances();
     // Check if we are using a DSN string, e.g. "mysql://*****:*****@host/database"
     if ($db == '') {
         $dsn = new YDUrl($driver);
         $driver = $dsn->getScheme();
         $db = substr($dsn->getPath(), 1);
         $user = $dsn->getUser();
         $pass = $dsn->getPassword();
         $host = $dsn->getHost();
     }
     // Register the instance
     $GLOBALS['YD_DB_INSTANCES'][strtolower($name)] = array($driver, $db, $user, $pass, $host);
 }
 /**
  *	This function will take a piece of text and convert the BBCode tags to their HTML equivalents. You can
  *	optionally convert line breaks as well as convert the remaining HTML tags to their entities.
  *
  *	@param $data			The data you want to convert.
  *	@param $convertBr		(optional) Boolean to indicate that new lines should be converted to <br/> tags.
  *							This is turned on by default.
  *	@param $convertTags		(optional) Boolean to indicate that tags should be converted to HTML. This is turned
  *							on by default.
  *	@param $convertLinks	(optional) Boolean to indicate if links should be automatically highlighted or not.
  *							This is turned on by default.
  *  @param $baseUrl         (optional) If you give this a non-null value, it will convert all links to absolute
  *                          links using this url as the base url.
  *
  *	@returns	The HTML equivalent of the string with all the BBCode's converted according to the conversion table
  *				of this class.
  */
 function toHtml($data, $convertBr = true, $convertTags = true, $convertLinks = true, $baseUrl = null)
 {
     // Encode the references
     $data = YDStringUtil::encodeString($data);
     // Convert the links to BBcode
     if ($convertLinks === true) {
         $data = $this->convertLinks($data);
     }
     // Convert tags if needed
     if ($convertTags === true) {
         $data = str_replace('<', '&lt;', $data);
         $data = str_replace('>', '&gt;', $data);
     }
     // Convert the tags
     $data = preg_replace(array_keys($this->_conversions), array_values($this->_conversions), $data);
     // Open http links in a new window
     $data = str_replace(' href="http://', ' target="_blank" href="http://', $data);
     // Convert tags if needed
     if ($convertBr === true) {
         $data = nl2br(trim($data));
     }
     // Make links absolute if needed
     if (!is_null($baseUrl)) {
         include_once dirname(__FILE__) . '/../../YDClasses/YDUrl.php';
         $data = YDUrl::makeLinksAbsolute($data, $baseUrl);
     }
     // Return the data
     return $data;
 }