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(); }
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)); } }
/** * 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 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; }
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(); }
<?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'));
function YDTplModLinkThumbSmall($img) { return YDUrl::makeLinkAbsolute(YDConfig::get('dir_uploads', 'uploads') . '/' . dirname($img->relative_path) . '/s_' . basename($img->relative_path)); }
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); }
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)); } } }