Ejemplo n.º 1
0
 /**
  *  This function counts visits of a object
  *
  *  @param $id       Object id (content_id)
  *  @param $user_id  (Optional) User id (0 means visitors)
  *  @param $period   (Optional) Period for count. Valid values: 'week', 'month', year'
  *
  *  @returns    an array of labels => values
  */
 function getObjectVisits($id, $user_id = 0, $period = 'week')
 {
     YDInclude('YDDate.php');
     // compute start date
     $date = new YDDate();
     $labels = array();
     if ($period == 'week') {
         for ($i = 0; $i < 7; $i++) {
             $labels[] = $date->getDayName();
             $date->addDay(-1);
         }
     }
     if ($period == 'month') {
         for ($i = 0; $i < 4; $i++) {
             $labels[] = $date->getMonthName();
             $date->addMonth(-1);
         }
     }
     if ($period == 'year') {
         for ($i = 0; $i < 3; $i++) {
             $labels[] = $date->getYear();
             $date->addYear(-1);
         }
     }
     $labels = array_reverse($labels);
     $this->resetAll();
     $this->user_id = intval($user_id);
 }
 /**
  *	Using this static function, you can get an instance of a YDDatabaseDriver class.
  *
  *	@param $driver	Name of the database driver.
  *	@param $db		Database name to use for the connection.
  *	@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.
  */
 function getInstance($driver, $db, $user = '', $pass = '', $host = '')
 {
     // The list of known drivers
     $regDrivers = array();
     // Register the standard drives
     $regDrivers[strtolower('mysql')] = array('class' => 'YDDatabaseDriver_mysql', 'file' => '');
     $regDrivers[strtolower('oracle')] = array('class' => 'YDDatabaseDriver_oracle', 'file' => 'YDDatabaseDriver_oracle.php');
     $regDrivers[strtolower('postgres')] = array('class' => 'YDDatabaseDriver_postgres', 'file' => 'YDDatabaseDriver_postgres.php');
     $regDrivers[strtolower('sqlite')] = array('class' => 'YDDatabaseDriver_sqlite', 'file' => 'YDDatabaseDriver_sqlite.php');
     // Check if the driver exists
     if (!array_key_exists(strtolower($driver), $regDrivers)) {
         trigger_error('Unsupported database type: "' . $driver . '".', YD_ERROR);
     }
     // Include the driver
     if (!empty($regDrivers[strtolower($driver)]['file'])) {
         YDInclude($regDrivers[strtolower($driver)]['file']);
     }
     // Check if the driver is supported
     if (!call_user_func(array($regDrivers[strtolower($driver)]['class'], 'isSupported'))) {
         trigger_error('Unsupported database type: "' . $driver . '". Extension is not loaded.', YD_ERROR);
     }
     // Make a new connection object and return it
     $className = $regDrivers[strtolower($driver)]['class'];
     return new $className($db, $user, $pass, $host);
 }
/**
 *	This function will add a marker to the global timer.
 *
 *	@param $name	The name of the marker.
 */
function YDGlobalTimerMarker($name)
{
    if (!isset($GLOBALS['timer'])) {
        YDInclude('YDUtil.php');
        $GLOBALS['timer'] = new YDTimer();
    }
    $GLOBALS['timer']->addMarker($name);
}
 function getMailInfo()
 {
     // Includes
     YDInclude('phpmailer/class.phpmailer.php');
     $p = new PHPMailer();
     $settings = array('system' => 'PHPMailer', 'version' => $p->Version);
     ksort($settings);
     return $settings;
 }
 function actionRestore()
 {
     // Include filesystem functions
     YDInclude('YDFileSystem.php');
     // Create file object
     $file = new YDFSFile($this->dump->getFilePath());
     // Restore the database dump
     $this->dump->restore($file->getContents());
     // Show the properties of the database backup
     YDDebugUtil::dump($file->getContents(), $this->dump->getFilePath());
 }
 function actionShowCaptcha()
 {
     // include captcha lib
     YDInclude('YDCaptcha.php');
     // create captcha object
     $captcha = new YDCaptcha();
     //			$captcha->useColour( true );
     //			$captcha->setNumChars( 3 );
     // return image
     return $captcha->Create();
 }
Ejemplo n.º 7
0
 /**
  *  This function returns the page form (form admin edition)
  *
  *  @returns    YDForm object
  */
 function getFormPage()
 {
     YDInclude('YDForm.php');
     // get template and language object
     $templates = YDCMComponent::module('YDCMTemplates');
     $languages = YDCMComponent::module('YDCMLanguages');
     // create access options
     $access = array(0 => t('public'), 1 => t('private'));
     // create 'template pack' options
     $template_pack = array(1 => t('use templatepack') . ' (' . $templates->template_pack() . ')', 0 => t('use custom template'));
     // create form object
     $form = new YDForm(YDConfig::get('YDCMPAGE_FORMPAGE'));
     $form->addElement('text', 'reference', t('page_reference'), array('size' => 25, 'maxlength' => 35));
     $form->addElement('text', 'title', t('page_title'), array('size' => 70, 'maxlength' => 70));
     $form->addElement('textarea', 'html', t('page_html'));
     $form->addElement('textarea', 'xhtml', t('page_xhtml'));
     $form->addElement('select', 'access', t('page_access'), array(), $access);
     $form->addElement('select', 'state', t('page_state'), array(), array(1 => t('yes'), 0 => t('no'), 2 => t('schedule')));
     $form->addElement('datetimeselect', 'published_date_start', t('page_startdate'));
     $form->addElement('datetimeselect', 'published_date_end', t('page_enddate'));
     $form->addElement('select', 'template_pack', '', array(), $template_pack);
     $form->addElement('select', 'template', t('page_template'), array(), $templates->visitors_templates());
     $form->addElement('select', 'metatags', t('page_metatags'), array(), array(0 => t('no'), 1 => t('yes')));
     $form->addElement('textarea', 'description', t('page_description'), array('cols' => 50, 'rows' => 5));
     $form->addElement('textarea', 'keywords', t('page_keywords'), array('cols' => 50, 'rows' => 5));
     $form->addElement('select', 'searcheable', t('page_search'), array(), array(0 => t('no'), 1 => t('yes')));
     $form->addElement('hidden', 'content_id');
     $form->addElement('hidden', 'parent_id');
     $form->addElement('hidden', 'language_id');
     // parent of new page is 0 by default
     $form->setDefault('content_id', 0);
     $form->setDefault('parent_id', 0);
     $form->setDefault('language_id', $languages->adminDefault());
     // add form rules
     $form->addRule('reference', 'required', t('reference_required'));
     $form->addRule('reference', 'alphanumeric', t('reference_alphanumeric'));
     $form->addRule('reference', 'maxwords', t('reference_maxwords'), 1);
     $form->addRule('reference', 'maxlength', t('reference_maxlength'), 100);
     $form->addRule('title', 'required', t('title_required'));
     $form->addRule('title', 'maxlength', t('title_maxlength'), 255);
     $form->addRule('content_id', 'required', t('content_id_required'));
     $form->addRule('content_id', 'numeric', t('content_id_numeric'));
     $form->addRule('parent_id', 'required', t('parent_id_required'));
     $form->addRule('parent_id', 'numeric', t('parent_id_numeric'));
     $form->addRule('html', 'maxlength', t('html_maxlength'), 50000);
     $form->addRule('xhtml', 'maxlength', t('xhtml_maxlength'), 50000);
     $form->addRule('template_pack', 'in_array', t('template_pack_invalid'), array(0, 1));
     $form->addRule('template', 'in_array', t('template_invalid'), array_keys($templates->visitors_templates()));
     $form->addRule('metatags', 'in_array', t('metatags_invalid'), array(0, 1));
     $form->addRule('description', 'maxlength', t('description_maxlength'), 2000);
     $form->addRule('keywords', 'maxlength', t('keywords_maxlength'), 2000);
     return $form;
 }
 function getcontries()
 {
     // include Select lib
     YDInclude('YDFormElement_Select.php');
     // create new select element assigned to form 'myform'
     $contries = new YDFormElement_Select($this->form->getName(), 'contries', '', '', array('Portugal', 'Brasil', 'Belgium'));
     // assign form element code with span
     $this->ajax->addResult('myspan', $contries->toHtml());
     // disable previous event (myspan was assigned with a call to 'getcountries')
     $this->ajax->addResult('myspan', 'return false;', 'onclick');
     // return response to client browser
     return $this->ajax->processResults();
 }
 function result($option)
 {
     // compute message
     switch ($option) {
         case 1:
             $message = YD_FW_NAMEVERS;
             break;
         default:
             YDInclude('YDUtil.php');
             $message = YDStringUtil::formatDate(time(), '%d %B %Y %H:%M:%S');
     }
     // assign span 'myspanresult' of 'myform' with dynamic message
     $this->ajax->addResult('myspanresult', $message);
     // return response to client browser
     return $this->ajax->processResults();
 }
Ejemplo n.º 10
0
 function createGraph($name, $type)
 {
     YDInclude('YDGraph.php');
     // generate chart
     $values = array();
     for ($i = 0; $i < 12; $i++) {
         $values[] = rand(20, 60);
     }
     $labels = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
     // Create a new graph
     $g1 = new YDGraph(550, 250);
     $g1->setLimits(0, 20);
     $g1->setOffset(5);
     $g1->setFormat(1, ',', '.');
     $g1->addSeries($values, $type, 'Series1', SOLID, '#444444', '#4682B4');
     $g1->setYAxis('#4682B4', SOLID, 5, 'example');
     $g1->setLabels($labels, '#000000', 1, HORIZONTAL);
     $g1->plot(dirname(__FILE__) . '/' . $name);
 }
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// set components path
YDConfig::set('YD_DBOBJECT_PATH', YD_DIR_HOME_ADD . '/YDCMComponent', false);
// include YDF libs
YDInclude('YDDatabaseObject.php');
YDInclude('YDResult.php');
// add translations directory for generic translations
YDLocale::addDirectory(dirname(__FILE__) . '/languages/');
class YDCMPermission extends YDDatabaseObject
{
    function YDCMPermission()
    {
        // init component as non default
        $this->YDDatabaseObject();
        // register database as default
        $this->registerDatabase();
        // register table for this component
        $this->registerTable('YDCMPermission');
        // register fields
        $this->registerField('permission_id');
        $this->registerField('class');
	This library is free software; you can redistribute it and/or
		modify it under the terms of the GNU Lesser General Public
		License as published by the Free Software Foundation; either
		version 2.1 of the License, or (at your option) any later version.
	This library is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
		Lesser General Public License for more details.
	You should have received a copy of the GNU Lesser General Public
		License along with this library; if not, write to the Free Software
		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
YDInclude('YDDatabase.php');
/**
 *	This class defines a database driver for Oracle8i using the OCI8 interface.
 */
class YDDatabaseDriver_oracle extends YDDatabaseDriver
{
    /**
     *	This is the class constructor for the YDDatabaseDriver_oracle class.
     *
     *	@param $db		Name of the database.
     *	@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.
     *	@param $host	(optional) Host name to use for the connection.
     *	@param $options	(optional) Options to pass to the driver.
     */
Ejemplo n.º 13
0
 /**
  *	This function will be executed if there is no post data found. This is happening when there is no XML/RPC
  *	request found.
  */
 function requestNotXmlRpc()
 {
     // Get the list of methods
     $methods = array();
     $methodNames = $this->_server->listMethods(null);
     // Loop over the methods
     foreach ($methodNames as $method) {
         if (isset($this->_server->signatures[$method])) {
             if (sizeof($this->_server->signatures[$method]) == 1) {
                 $paramsIn = null;
                 $paramsOut = $this->_server->signatures[$method];
             } else {
                 $paramsIn = $this->_server->signatures[$method];
                 $paramsOut = array_shift($paramsIn);
             }
         } else {
             $paramsIn = null;
             $paramsOut = null;
         }
         $methodInfo = array();
         $methodInfo['signature'] = @$this->_server->signatures[$method];
         $methodInfo['paramsIn'] = $paramsIn;
         $methodInfo['paramsOut'] = $paramsOut;
         $methodInfo['help'] = @$this->_server->help[$method];
         $methods[$method] = $methodInfo;
     }
     // Create a new template
     YDInclude('YDTemplate.php');
     $template = new YDTemplate();
     $template->template_dir = dirname(__FILE__);
     $template->assign('methods', $methods);
     $template->assign('xmlRpcUrl', $this->getCurrentUrl());
     $template->assign('capabilities', $this->_server->getCapabilities(null));
     $template->assign('rowcolor', '#EEEEEE');
     $template->display('YDXmlRpcServer.tpl');
 }
        License as published by the Free Software Foundation; either
        version 2.1 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// Includes
YDInclude('YDForm.php');
/**
 *	This is the class that define a password form element.
 */
class YDFormElement_Password extends YDFormElement
{
    /**
     *	This is the class constructor for the YDFormElement_Password class.
     *
     *	@param $form		The name of the form to which this element is connected.
     *	@param $name		The name of the form element.
     *	@param $label		(optional) The label for the form element.
     *	@param $attributes	(optional) The attributes for the form element.
     *	@param $options		(optional) The options for the elment.
     */
    function YDFormElement_Password($form, $name, $label = '', $attributes = array(), $options = array())
 /**
  *	This function returns true if the variable is an array and each element is in opts.
  *
  *	@param $val			The value to test.
  *	@param $opts		The array in which the value should be.
  *	@param $formelement	(not required)
  */
 function valid($val, $opts = '', $formelement = null)
 {
     $opts = $formelement->getOptions();
     switch ($formelement->getType()) {
         case 'checkboxgroup':
             foreach ($val as $value => $enable) {
                 if (!in_array($value, $opts) || $enable != 'on') {
                     return false;
                 }
             }
             return true;
         case 'select':
             return in_array($val, $opts);
         case 'country':
             YDInclude('YDList.php');
             return in_array($val, YDList::countries('keys'));
         case 'timezone':
             YDInclude('YDList.php');
             return in_array($val, YDList::gmts('keys'));
         default:
             die('YDValidateRule "valid" is not supported in element type ' . $formelement->getType());
     }
 }
 /**
  *  This function returns an instance of a YDDatabaseObject class.
  *
  *  @param $class  (optional) The class name.
  *  @param $params (optional) The params to use when instantiating the instance.
  *
  *  @returns    An instance of a YDDatabaseObject class.
  *
  *  @static
  */
 function getInstance($class = '', $params = false)
 {
     $path = YDConfig::get('YD_DBOBJECT_PATH') . '/';
     $ext = YDConfig::get('YD_DBOBJECT_EXT');
     $prefix = YDConfig::get('YD_DBOBJECT_PREFIX');
     $sufix = YDConfig::get('YD_DBOBJECT_SUFIX');
     if (!strlen($class)) {
         $class = $this->getClassName();
     }
     $path = $path . $class . $ext;
     $class = $prefix . $class . $sufix;
     if (!class_exists($class)) {
         YDInclude($path);
     }
     if ($params !== false) {
         $obj = new $class($params);
     } else {
         $obj = new $class();
     }
     if (!$obj->_fields || !$obj->_table || !$obj->_db) {
         trigger_error('The "' . $class . '" class is not correctly configured.', YD_ERROR);
     }
     return $obj;
 }
Ejemplo n.º 17
0
 function actionShowCaptcha()
 {
     // include captcha lib
     YDInclude('YDCaptcha.php');
     // Create captcha object
     $captcha = new YDCaptcha();
     $captcha->_img->SetCharSet("2-4,6,8-9,2-4,6,8-9");
     // Return the image
     return $captcha->Create();
 }
 *  YDDatabaseObjects file extension.
 *  Default: YD_SCR_EXT
 */
YDConfig::set('YD_DATABASEOBJECT_EXT', YD_SCR_EXT, false);
/**
 *  This constant defines if a DELETE query with no conditions can be executed.
 *  Default: false.
 */
YDConfig::set('YD_DATABASEOBJECT_DELETE', false, false);
/**
 *  This constant defines if a UPDATE query with no conditions can be executed.
 *  Default: false.
 */
YDConfig::set('YD_DATABASEOBJECT_UPDATE', false, false);
YDInclude('YDDatabase.php');
YDInclude('YDSqlQuery.php');
/**
 *  This class defines a YDDatabaseObject object.
 */
class YDDatabaseObject extends YDBase
{
    var $__db = null;
    var $__table = null;
    var $__sql = null;
    var $__last = array();
    var $__fields = array();
    var $__keys = array();
    var $__relations = array();
    var $__protected = array();
    var $__results = array();
    var $__limit = -1;
        version 2.1 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// Includes
YDInclude('YDForm.php');
YDInclude('YDFormElements/YDFormElement_Select.php');
/**
 *	This is the class that define a date select form element.
 */
class YDFormElement_DateSelect extends YDFormElement
{
    /**
     *	This is the class constructor for the YDFormElement_DateSelect class.
     *
     *	@param $form		The name of the form to which this element is connected.
     *	@param $name		The name of the form element.
     *	@param $label		(optional) The label for the form element.
     *	@param $attributes	(optional) The attributes for the form element.
     *	@param $options		(optional) The options for the elment.
     */
    function YDFormElement_DateSelect($form, $name, $label = '', $attributes = array(), $options = array())
Ejemplo n.º 20
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'));
Ejemplo n.º 21
0
		modify it under the terms of the GNU Lesser General Public
		License as published by the Free Software Foundation; either
		version 2.1 of the License, or (at your option) any later version.
	This library is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
		Lesser General Public License for more details.
	You should have received a copy of the GNU Lesser General Public
		License along with this library; if not, write to the Free Software
		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
YDInclude('YDRequest.php');
YDInclude('class.template/src/class.template.php');
define('YD_TPL_CACHEEXT', '.phc');
define('YD_TPL_CACHEPRE', YD_TMP_PRE . 'T_');
/**
 *	This class is a wrapper around Smarty Light. Documentation can be found on:
 *	http://www.paullockaby.com/projects/smarty-light/docs/
 */
class YDTemplate extends template
{
    /**
     *	This is the class constructor for the YDTemplate class. By default, it looks in the same directory as the
     *	current script to find the templates.
     */
    function YDTemplate()
    {
        // Set the default template directory
Ejemplo n.º 22
0
 /**
  *  This method will delete a category from db
  *
  *  @param $category_id   Category id
  *
  *  @returns    YDResult object
  */
 function deleteElement($category_id)
 {
     YDInclude('YDResult.php');
     $this->reset();
     $this->set('id', intval($category_id));
     $result = $this->delete();
     if ($result) {
         return YDResult::ok(t('forum category deleted'), $result);
     } else {
         return YDResult::fatal(t('impossible to delete forum category'), $result);
     }
 }
Ejemplo n.º 23
0
<?php

// Initialize the Yellow Duck Framework
require_once dirname(__FILE__) . '/../../YDFramework2/YDF2_init.php';
YDConfig::set('YD_DATABASEOBJECT_PATH', YD_SELF_DIR . YD_DIRDELIM . 'includes');
YDInclude('User.php');
echo "<h1>Loading and finding all relations</h1>";
echo "<p>There is way of loading all relations and making a single query to all relations.</p>";
echo "<p>You can use the findAllRelations method or findRelation( 'relation', 'relation', ... ) to<br>";
echo "join only a few relations in a single query.</p>";
echo "<p>Let's do that with my user.</p>";
$user = new User();
$user->loadAllRelations();
$user->id = 1;
$user->findAllRelations();
while ($user->fetchRelation()) {
    YDDebugUtil::dump($user->getRelationValues());
}
echo "<p>With getRelationValues I've returned all values in a single array, but we still are<br>";
echo "able to access the individual relation objects.</p>";
echo "<p>Let's do that with Pieter's user.</p>";
$user->resetRelation();
$user->id = 2;
$user->findAllRelations();
while ($user->fetchRelation()) {
    YDDebugUtil::dump($user->getRelationValues());
}
echo "<p>That's it! Enjoy! =)</p>";
echo "<p><a href=\"index.php?YD_DEBUG=" . YDConfig::get('YD_DEBUG') . "\">Click here to return</a></p>";
echo "<p></p><p>&nbsp;</p>";
Ejemplo n.º 24
0
 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();
 }
Ejemplo n.º 25
0
<?php

YDInclude('YDDatabaseObject.php');
class Address extends YDDatabaseObject
{
    function Address()
    {
        $this->YDDatabaseObject();
    }
    function setDatabase()
    {
        $this->__db = YDDatabase::getInstance('mysql', 'test', 'root', '', 'localhost');
    }
    function setTable()
    {
        $this->__table = 'address';
    }
    function setFields()
    {
        $this->__fields['user_id'] = array('type' => YD_DATABASEOBJECT_NUM);
        $this->__fields['address'] = array('type' => YD_DATABASEOBJECT_STR);
        $this->__fields['city'] = array('type' => YD_DATABASEOBJECT_STR);
        $this->__fields['state'] = array('type' => YD_DATABASEOBJECT_STR);
        $this->__fields['country'] = array('type' => YD_DATABASEOBJECT_STR, 'default' => 'Brazil');
    }
    function setKeys()
    {
        $this->__keys = array('user_id');
    }
    function setRelations()
    {
Ejemplo n.º 26
0
		modify it under the terms of the GNU Lesser General Public
		License as published by the Free Software Foundation; either
		version 2.1 of the License, or (at your option) any later version.
	This library is distributed in the hope that it will be useful,
		but WITHOUT ANY WARRANTY; without even the implied warranty of
		MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
		Lesser General Public License for more details.
	You should have received a copy of the GNU Lesser General Public
		License along with this library; if not, write to the Free Software
		Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
YDInclude('YDFileSystem.php');
YDInclude('htmlMimeMail/htmlMimeMail.php');
/**
 *	This class defines an email message.
 */
class YDEmail extends YDBase
{
    /**
     *	This is the class constructor for the YDEmail class.
     */
    function YDEmail($crlf = "\n")
    {
        // Initialize YDBase
        $this->YDBase();
        // Intialize a new mime message
        $this->_msg = new htmlMimeMail();
        // Start with empty variables
include_once dirname(__FILE__) . '/../../../YDFramework2/YDF2_init.php';
// Redirect to the installer if the config file doesn't exist
if (!is_file(dirname(__FILE__) . '/config.php')) {
    $root_path = str_replace('\\', '/', dirname(dirname(__FILE__))) . '/';
    $current_path = str_replace('\\', '/', dirname(YD_SELF_FILE)) . '/';
    $install_path = str_replace($root_path, '', $current_path);
    $install_path = explode('/', $install_path);
    $install_path_rel = '';
    for ($i = 1; $i < sizeof($install_path); $i++) {
        $install_path_rel .= '../';
    }
    $install_path_rel .= 'install.php';
    header('Location: ' . $install_path_rel);
}
// Include the standard modules
YDInclude('YDUtil.php');
YDInclude('YDForm.php');
YDInclude('YDBBCode.php');
YDInclude('YDRequest.php');
YDInclude('YDTemplate.php');
YDInclude('YDDatabase.php');
YDInclude('YDFormElements/YDFormElement_BBTextArea.php');
// Include other libraries
YDInclude(dirname(__FILE__) . '/config.php');
YDInclude(dirname(__FILE__) . '/YDWeblogAPI.php');
YDInclude(dirname(__FILE__) . '/YDWeblogTemplate.php');
YDInclude(dirname(__FILE__) . '/YDWeblogTranslate.php');
YDInclude(dirname(__FILE__) . '/YDWeblogForm.php');
YDInclude(dirname(__FILE__) . '/YDWeblogRequest.php');
YDInclude(dirname(__FILE__) . '/YDWeblogAdminRequest.php');
        License as published by the Free Software Foundation; either
        version 2.1 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful,
        but WITHOUT ANY WARRANTY; without even the implied warranty of
        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
        Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public
        License along with this library; if not, write to the Free Software
        Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
// Check if the framework is loaded
if (!defined('YD_FW_NAME')) {
    die('Yellow Duck Framework is not loaded.');
}
// Includes
YDInclude('HttpClient.class.php');
// Configure the default for this class
YDConfig::set('YD_HTTP_USES_GZIP', 1, false);
YDConfig::set('YD_HTTP_CACHE_TIMEOUT', 3600, false);
YDConfig::set('YD_HTTP_CACHE_USEHEAD', 1, false);
/**
 *	This is the YDHttpClient class. It extends the HttpClient class and adds support for specifying the content
 *	type.
 *
 *	@todo
 *		Redirects to different sites are not supported, and make retrieving of images from pbase fail. This might 
 *		result in the fact that we need to move to a different HTTP library. Another option is to rewrite the ]
 *		library completely.
 */
class YDHttpClient extends HttpClient
{
Ejemplo n.º 29
0
        // Add a rule
        $form->addRule('title', 'required', 'Title is required');
        $form->addRule('body', 'required', 'Contents is required');
        // Process the form
        if ($form->validate()) {
            // Save the entries in an array
            $entry = array('id' => md5($form->getValue('title') . $form->getValue('body')), 'title' => $form->getValue('title'), 'body' => $form->getValue('body'));
            // Save the serialized entry to a file
            $this->dataDir->createFile($entry['id'] . '.dat', YDObjectUtil::serialize($entry));
            // Forward to the list view
            $this->forward('default');
            // Return
            return;
        }
        // Add the form to the template
        $this->template->assignForm('form', $form);
        // Output the template
        $this->template->display();
    }
    // Delete note action
    function actionDeleteNote()
    {
        // Delete the file related to the entry
        $this->dataDir->deleteFile($_GET['id'] . '.dat');
        // Forward to the list view
        $this->forward('default');
    }
}
// Process the request
YDInclude('YDF2_process.php');
<?php

// Include the Yellow Duck Framework
include_once dirname(__FILE__) . '/../../../YDFramework2/YDF2_init.php';
// Include the classes you need on all pages
YDInclude('YDRequest.php');
YDInclude('YDTemplate.php');
YDInclude('YDUtil.php');
YDInclude('YDFileSystem.php');
// Define the constants we want to override for the Framework
YDConfig::set('YD_DEBUG', 1);
// Here, we define our custom request class
class MyAppRequest extends YDRequest
{
    // Class constructor
    function MyAppRequest()
    {
        // Initialize the parent request
        $this->YDRequest();
        // Make the template object available for all requests
        $this->tpl = new YDTemplate();
        // Instantiate a timer as well
        $this->timer = new YDTimer();
    }
}