function result($currentdate, $operation, $number, $type) { // create date object with timestamp from the 'currentdate' form element $date = new YDDate(); $date->set(intval($currentdate)); // if operation is 1 we want subtract the number if ($operation == 1) { $number = -intval($number); } else { $number = intval($number); } // add number to date switch (intval($type)) { case 0: $date->addMinute($number); break; case 1: $date->addDay($number); break; case 2: $date->addMonth($number); break; default: $date->addYear($number); } // assign span with date $this->ajax->addResult('myspanresult', YDStringUtil::formatDate($date->getTimestamp(), 'datetime')); // return response to client browser return $this->ajax->processResults(); }
function actionDefault() { // Test the formatting of filesizes $filesizes = array('1152921504606846977', '1125899906842625', '1099511627777', '75715455455', '1048577', '6543', '42'); // Format the filesizes foreach ($filesizes as $filesize) { YDDebugUtil::dump(YDStringUtil::formatFileSize($filesize), 'Formatting filesize: ' . $filesize); } // Test the formatDate function YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'date'), 'Formatting date - date'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'time'), 'Formatting date - time'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), 'datetime'), 'Formatting date - datetime'); YDDebugUtil::dump(YDStringUtil::formatDate(time(), '%x'), 'Formatting date - %x'); // Test the encode string function $string = 'Pieter Claerhout @ creo.com "générales obsolète"'; YDDebugUtil::dump(YDStringUtil::encodeString($string), 'Encoding: ' . $string); // Test the truncate function YDDebugUtil::dump(YDStringUtil::truncate($string), 'Truncate (default): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20), 'Truncate (20): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]'), 'Truncate (20/more): ' . $string); YDDebugUtil::dump(YDStringUtil::truncate($string, 20, ' [more]', true), 'Truncate (20/more/true): ' . $string); // Test the normalizing of newlines $string = "line1\nline2\rline3\r\nline4"; YDDebugUtil::dump(explode("\n", $string), 'Original string'); YDDebugUtil::dump(explode(YD_CRLF, YDStringUtil::normalizeNewlines($string)), 'normalizeNewlines'); // Test the normalizing of newlines $string = " line1 \n line2 \r line3 \r\n line4 "; YDDebugUtil::dump(YDStringUtil::removeWhiteSpace($string), 'removeWhiteSpace'); }
function addentry($items) { // create element name $element = time(); // add element name and value to previous items $items[$element] = 'New option added at ' . YDStringUtil::formatDate(time(), '%d %B %Y %H:%M:%S'); // assign items to select box (because it's an array, will replace all values) $this->ajax->addResult('items', $items); // define the last element as the element selected (because it's a string will define a new selection) $this->ajax->addResult('items', $element); // return response to client browser return $this->ajax->processResults(); }
function actionDefault() { // create a pdfReport object $pdf = new YDPdfReport(); // set Report title (optional) $pdf->setTitle(YD_FW_NAMEVERS . ' PDF Report'); // set pdf author, a pdf meta-tag (optional) $pdf->setAuthor('ximian'); // create translations (optional) $pdf->setLanguage(array('page' => 'Page ', 'createdby' => 'Created by the YDF addon (v' . $pdf->_version . ') on ' . YDStringUtil::formatDate(time(), "datetime"), 'createdlink' => '', 'pageseparator' => ' of ')); // use this html $pdf->setHTML("<h1>Example 1</h1>Hello World!"); // create pdf file $pdf->output('inline'); }
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(); }
function actionDefault() { // Create the form $form = new YDForm('form1'); // Add a first set of elements $elementDate = $form->addElement('dateselect', 'dateSelect1', 'Enter data:'); $elementTime = $form->addElement('timeselect', 'timeSelect1', 'Enter data:'); $elementDateTime = $form->addElement('datetimeselect', 'datetimeSelect1', 'Enter data:'); // Add a second set of elements $form->addElement('dateselect', 'dateSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050')); $form->addElement('timeselect', 'timeSelect2', 'Enter data:'); $form->addElement('datetimeselect', 'datetimeSelect2', 'Enter data:', array(), array('yearstart' => 1970, 'yearend' => '2050')); $form->addElement('datetimeselect', 'datetimeSelect3', 'Enter data with seconds:', array(), array('seconds' => true)); // Add the send button $form->addElement('submit', 'cmd1', 'Send'); // Set the defaults $form->setDefaults(array('dateSelect1' => array('month' => 4, 'day' => 4, 'year' => 2002), 'dateSelect2' => strval(time()), 'timeSelect2' => strval(time()), 'datetimeSelect2' => time() + 3600 * 24)); // Display the form $form->display(); // Show the contents of the form if (YDConfig::get('YD_DEBUG') == 1) { YDDebugUtil::dump($form->_regElements, 'Registered elements'); YDDebugUtil::dump($form->_regRules, 'Registered rules'); YDDebugUtil::dump($form->_regFilters, 'Registered filters'); YDDebugUtil::dump($form->_filters, 'Filters'); YDDebugUtil::dump($form->_rules, 'Rules'); YDDebugUtil::dump($form->_formrules, 'Form Rules'); YDDebugUtil::dump($form->getValue('dateSelect1'), 'dateSelect1'); YDDebugUtil::dump($form->getValue('timeSelect1'), 'timeSelect1'); YDDebugUtil::dump($form->getValue('datetimeSelect1'), 'datetimeSelect1'); YDDebugUtil::dump($form->getValues(), '$form->getValues()'); YDDebugUtil::dump($_POST, '$_POST'); YDDebugUtil::dump($_FILES, '$_FILES'); } if ($form->validate()) { YDDebugUtil::dump($form->getValues(), '$form->getValues()'); YDDebugUtil::dump($elementDate->getTimeStamp(), '$elementDate->getTimeStamp()'); YDDebugUtil::dump($elementDate->getTimeStamp('%d/%m/%Y'), '$elementDate->getTimeStamp( "%d/%m/%Y" )'); YDDebugUtil::dump(date('M-d-Y', $elementDate->getTimeStamp()), '$elementDate->gdate( getTimeStamp() )'); YDDebugUtil::dump($elementTime->getTimeStamp(), '$elementTime->getTimeStamp()'); YDDebugUtil::dump($elementTime->getTimeStamp('%H:%M'), '$elementTime->getTimeStamp( "%H:%M" )'); YDDebugUtil::dump($elementDateTime->getTimeStamp(), '$elementDateTime->getTimeStamp()'); YDDebugUtil::dump($elementDateTime->getTimeStamp('%d/%m/%Y %H:%M'), '$elementDateTime->getTimeStamp( "%H:%M" )'); YDDebugUtil::dump(YDStringUtil::formatDate($elementDateTime, 'datetime', 'pt'), 'YDStringUtil::formatDate'); } }
/** * Function to get the last modification date of the object. * * @param $format (optional) The date format to use to format the date. * @param $locale (optional) The locale to use for formatting the date. * * @returns String containing the last modification date of the object. */ function getLastModified($format = 'timestamp', $locale = null) { if ($format == 'timestamp') { return filemtime($this->getAbsolutePath()); } return YDStringUtil::formatDate(filemtime($this->getAbsolutePath()), $format, $locale); }
$form = new YDForm('ydcmforumpost'); $form->addElement('textarea', 'content', 'Content'); $form->addElement('button', 'cmdLogin', 'Submit'); // if we are replying to someone, let's get the content if (is_numeric($quote_id)) { // get replying post $posts = new YDCMForum_posts(); $post = $posts->getElement($quote_id); // apply default to content textarea $form->setDefault('content', $post['post_content']); } return $form; } } // last user login date. YDConfig::set('YD_FORUM_LASTLOGINDATE', YDStringUtil::formatDate(time(), 'datetimesql'), false); class YDCMForum_topics extends YDDatabaseObject { function YDCMForum_topics() { // init DB object $this->YDDatabaseObject(); // register database as default $this->registerDatabase(); // register table for this component $this->registerTable('YDCMForum_topics'); // register fields $this->registerKey('topic_id', true); $this->registerField('topic_forum_id'); $this->registerField('topic_title'); $this->registerField('topic_user_id');
/** * This filter reads a date form element result and returns a custom result * * @param $data The data to filter. * @param $option (Optional) Filter option. By default, is returned the timestamp * * @returns The filtered data as a string. */ function YDFormFilter_dateformat($data, $option = "timestamp") { if (isset($data[$option])) { return $data[$option]; } YDInclude('YDUtil.php'); return YDStringUtil::formatDate($data, $option); }
/** * This function updates current user login details * * @returns true if user login details updated, false if user is not valid or details not updated */ function updateLogin() { $this->resetAll(); // set our user_id for search $this->set('user_id', $this->currentID()); // get all attributes $this->find(); // increase login counter value $this->set('login_counter', 1 + $this->get('login_counter')); // set last login date $this->set('login_last', $this->get('login_current')); // set current login $this->set('login_current', YDStringUtil::formatDate(time(), 'datetimesql')); // because we don't have a primary key we must do this $this->where('user_id = ' . $this->get('user_id')); // return update result if ($this->update() == 1) { return true; } return false; }
function addResponse($post_id, $user_id, $message) { YDInclude('YDUtil.php'); $this->resetValues(); // create response // TODO: check if post_id and user_id are valid $this->post_id = intval($post_id); $this->user_id = intval($user_id); $this->date = YDStringUtil::formatDate(time(), 'datetimesql'); $this->description = $message; return $this->insert(); }
/** * This function updates a node fields ( that are NOT RESERVED only ) * * @param $values The field values of the node. Do NOT update position, parent_id, lineage or level * @param $id (optional) The ID of the node to update. * @param $onDate (optional) When element of $values is a date (read: array ), we should convert to this format. Default: 'datetimesql' * @param $updateChildren (optional) Flag that defines is children nodes of $id should be updated too. By default: false. * * @returns Total of lines affected */ function updateNode($values, $id, $onDate = 'datetimesql', $updateChildren = false) { // check values foreach ($values as $element => $value) { if (is_array($value)) { $values[$element] = YDStringUtil::formatDate($value, $onDate); } } $this->resetAll(); // apply custom values $this->setValues($values); // unset reserved fields $this->unsetVar($this->__parent); $this->unsetVar($this->__lineage); $this->unsetVar($this->__level); $this->unsetVar($this->__position); if ($updateChildren) { $this->where('(' . $this->__table_lineage . ' LIKE "%/' . intval($id) . '/%" OR ' . $this->__table_id . ' = ' . intval($id) . ')'); } else { $this->set($this->__id, intval($id)); } return $this->update(); }
/** * This function adds/updates a page (if content_id is 0 will add a page, otherwise will update) * * @param $formvalues Array with page attributes from the standard form * * @returns content_id updated or new content_id */ function savePageForm($formvalues = array()) { // get page YDForm object $form = $this->getFormPage(); // check form validation if (!$form->validate($formvalues)) { return $form->getErrors(); } // init node values $node = array(); $node['type'] = 'YDCMPage'; $node['reference'] = $form->getValue('reference'); $node['state'] = $form->getValue('state'); $node['access'] = $form->getValue('access'); $node['searcheable'] = $form->getValue('searcheable'); // convert published date start/end timestamp to a db datetime format $node['published_date_start'] = YDStringUtil::formatDate($form->getValue('published_date_start'), 'datetimesql'); $node['published_date_end'] = YDStringUtil::formatDate($form->getValue('published_date_end'), 'datetimesql'); // get id of this node $id = $form->getValue('content_id'); // if content_id is 0 we are trying to add a new node, otherwise we only need to update it if ($id == 0) { $id = $this->addNode($node, intval($form->getValue('parent_id'))); } else { $this->updateNode($node, intval($form->getValue('content_id'))); } // create page $page = array(); $page['content_id'] = $id; $page['language_id'] = $form->getValue('language_id'); $page['title'] = $form->getValue('title'); $page['html'] = $form->getValue('html'); $page['xhtml'] = $form->getValue('xhtml'); $page['template_pack'] = $form->getValue('template_pack'); $page['template'] = $form->getValue('template'); $page['metatags'] = $form->getValue('metatags'); $page['description'] = $form->getValue('description'); $page['keywords'] = $form->getValue('keywords'); // TODO: care about version control $page['current_version'] = 1; // add page $this->resetValues(); $this->setValues($page); $this->insert(); return $id; }