public function appendFormattedElement(&$wrapper, $data, $encode = false) { return; if (isset($data['gmt']) && !is_null($data['gmt'])) { $wrapper->appendChild(General::createXMLDateObject($data['local'], $this->get('element_name'))); } }
public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = NULL, $entry_id = NULL) { $row = self::__dateFromEntryID($entry_id); if (isset($row['local']) && !is_null($row['local'])) { $wrapper->appendChild(General::createXMLDateObject($data['local'], $this->get('element_name'))); } }
/** * Append the formatted xml output of this field as utilized as a data source. * * @param XMLElement $wrapper * the xml element to append the xml representation of this to. * @param array $data * the current set of values for this field. the values are structured as * for displayPublishPanel. * @param boolean $encode (optional) * flag as to whether this should be html encoded prior to output. this * defaults to false. * @param string $mode * A field can provide ways to output this field's data. For instance a mode * could be 'items' or 'full' and then the function would display the data * in a different way depending on what was selected in the datasource * included elements. * @param integer $entry_id (optional) * the identifier of this field entry instance. defaults to null. */ public function appendFormattedElement($wrapper, $data, $encode = false) { $dates = $this->_driver->getEntryDates($data, $this->get('id'), $this->filter); $element = new XMLElement($this->get('element_name')); $element->appendChild(General::createXMLDateObject($data['start'], 'start')); foreach ($dates[0] as $index => $date) { $element->appendChild(General::createXMLDateObject($date['value'], 'before')); } foreach ($dates[1] as $index => $date) { $element->appendChild(General::createXMLDateObject($date['value'], $index == 0 ? 'current' : 'after')); } $element->appendChild(General::createXMLDateObject($data['end'], 'end')); $element->setAttribute('date-mode', isset($data['mode']) ? $data['mode'] : null); $element->setAttribute('date-units', isset($data['units']) ? $data['units'] : null); $wrapper->appendChild($element); }
private function __search($query) { $result = new XMLElement($this->dsParamROOTELEMENT); if (strlen(trim($query)) == 0) { return $this->emptyXMLSet($result); } $db = ASDCLoader::instance(); $result->appendChild(new XMLElement('query-string', General::sanitize($query), array('encoded' => urlencode($query)))); $sql = "SELECT SQL_CALC_FOUND_ROWS \n\t\t\t\t\t\tMATCH(comment.value) AGAINST ('%6\$s') AS `score`,\n\t\t\t\t\t\tcomment.entry_id AS `id`,\n\t\t\t\t\t\tdate.local AS `date`,\n\t\t\t\t\t\tcomment.value_formatted AS `description`,\n\t\t\t\t\t\tmember.member_id AS `member-id`, \n\t\t\t\t\t\tmember.username AS `username`,\n\t\t\t\t\t\ttopic.value AS `topic`,\n\t\t\t\t\t\tparent.relation_id AS `discussion-id`\n\t\t\t\t\t\t\n\t\t\t\t\tFROM `tbl_entries_data_%1\$d` AS `date`\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%2\$d` AS `comment` ON date.entry_id = comment.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%3\$d` AS `member` ON date.entry_id = member.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%4\$d` AS `parent` ON date.entry_id = parent.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%5\$d` AS `topic` ON parent.relation_id = topic.entry_id\n\n\t\t\t\t\tWHERE MATCH(comment.value) AGAINST ('%6\$s')\n\t\t\t\t\tORDER BY `score` DESC\n\t\t\t\t\tLIMIT %7\$d, %8\$d"; //MATCH(comment.value) AGAINST ('%s') AS `score`, //OR MATCH(comment.value) AGAINST ('%1\$s') //WITH QUERY EXPANSION //member.username = '******' OR comment.value LIKE '%%%6\$s%%' OR topic.value LIKE '%%%6\$s%%' try { $rows = $db->query(sprintf($sql, self::findFieldID('date', 'comments'), self::findFieldID('comment', 'comments'), self::findFieldID('created-by', 'comments'), self::findFieldID('parent-id', 'comments'), self::findFieldID('topic', 'discussions'), $db->escape($query), max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT)); } catch (Exception $e) { $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError())))); return $result; } if ($rows->length() == 0) { return $this->emptyXMLSet($result); } $total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total; $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE)); /* <entry id="19753"> <name>Section Schema</name> <member id="2101">Allen</member> <description><p>Sect ... ollow).</p></description> </entry> */ foreach ($rows as $r) { $entry = new XMLElement('entry', NULL, array('discussion-id' => $r->{'discussion-id'}, 'id' => $r->id, 'score' => number_format($r->score, 3))); // Topic $entry->appendChild(new XMLElement('topic', General::sanitize($r->topic))); // Date $entry->appendChild(General::createXMLDateObject($r->date, 'date')); // Member $entry->appendChild(new XMLElement('member', General::sanitize($r->{'username'}), array('id' => $r->{'member-id'}))); // Comment $entry->appendChild(new XMLElement('comment', trim($r->description))); $result->appendChild($entry); } return $result; }
public function grab(&$param_pool) { $result = new XMLElement($this->dsParamROOTELEMENT); self::__init(); $db = ASDCLoader::instance(); $sql = "SELECT \n\t\t\t\t\t\te.id,\n\t\t\t\t\t\te.creation_date_gmt AS `date`,\n\t\t\t\t\t\tname.value AS `name`,\n\t\t\t\t\t\trole.name AS `role`,\n\t\t\t\t\t\twebsite.value AS `website`,\n\t\t\t\t\t\tcity.value AS `city`,\n\t\t\t\t\t\ttimezone_offset.value AS `timezone-offset`,\t\t\t\t\t\t\n\t\t\t\t\t\tusername.username AS `username`,\n\t\t\t\t\t\temail.value AS `email`,\n\t\t\t\t\t\tMD5(email.value) AS `hash`\n\t\t\t\t\t\t\n\t\t\t\t\tFROM `tbl_entries_data_%d` AS `name`\n\t\t\t\t\tLEFT JOIN `tbl_entries` AS `e` ON name.entry_id = e.id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `r` ON e.id = r.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_members_roles` AS `role` ON r.role_id = role.id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `username` ON e.id = username.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `email` ON e.id = email.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `city` ON e.id = city.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `website` ON e.id = website.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `timezone_offset` ON e.id = timezone_offset.entry_id\n\t\t\t\t\t\n\t\t\t\t\tWHERE username.username = '******'\n\t\t\t\t\tLIMIT 0, 1"; try { $member = $db->query(sprintf($sql, self::findFieldID('name', 'members'), self::findFieldID('role', 'members'), self::findFieldID('username-and-password', 'members'), self::findFieldID('email-address', 'members'), self::findFieldID('city', 'members'), self::findFieldID('website', 'members'), self::findFieldID('timezone-offset', 'members'), $db->escape($this->dsParamFILTERS['username'])))->current(); } catch (Exception $e) { $result->appendChild(new XMLElement('error', $e->getMessage())); return $result; } if (!$member instanceof StdClass || is_null($member)) { $this->__redirectToErrorPage(); } /* <entry id="2101"> <creation-date time="19:31" weekday="3">2009-01-07</creation-date> <name handle="allen-chang">Allen Chang</name> <role id="2">Administrator</role> <username-and-password username="******" password="******" /> </entry> */ $entry = new XMLElement('entry', NULL, array('id' => $member->id, 'email-hash' => $member->hash)); $entry->appendChild(new XMLElement('name', General::sanitize($member->name))); if (isset($member->website) && strlen(trim($member->website)) > 0) { $entry->appendChild(new XMLElement('website', General::sanitize($member->website))); } if (isset($member->city) && strlen(trim($member->city)) > 0) { $entry->appendChild(new XMLElement('city', General::sanitize($member->city))); } $offset = !is_null($member->{'timezone-offset'}) ? min(max($member->{'timezone-offset'}, -12), 12) : 0; $entry->appendChild(new XMLElement('timezone-offset', $offset)); $entry->appendChild(new XMLElement('role', General::sanitize($member->role))); $entry->appendChild(new XMLElement('username', General::sanitize($member->username))); $entry->appendChild(General::createXMLDateObject(strtotime($member->date . '+00:00'), 'date-joined')); $result->appendChild($entry); return $result; }
public function grab(&$param_pool) { $Members = Frontend::instance()->ExtensionManager->create('members'); $Members->initialiseCookie(); if ($Members->isLoggedIn() !== true) { // Oi! you can't be here redirect(URL . '/forbidden/'); exit; } $result = new XMLElement($this->dsParamROOTELEMENT); self::__init(); $db = ASDCLoader::instance(); $sql = 'SELECT SQL_CALC_FOUND_ROWS pinned.entry_id AS `id`, pinned.value AS `pinned`, closed.value AS `closed`, creation_date.local AS `creation-date`, last_active.local AS `last-active`, created_by.member_id AS `created-by-member-id`, created_by.username AS `created-by-username`, last_post.member_id AS `last-post-member-id`, last_post.username AS `last-post-username`, topic.value AS `topic` FROM `tbl_entries_data_%d` AS `pinned` LEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id LEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id LEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id LEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id LEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id LEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id LEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id LEFT JOIN `tbl_entries_data_%d` AS `discussion_comments_member` ON comments.entry_id = discussion_comments_member.entry_id WHERE 1 %s AND (created_by.member_id = %11$d || discussion_comments_member.member_id = %11$d) GROUP BY pinned.entry_id ORDER BY pinned.value ASC, last_active.local DESC LIMIT %12$d, %13$d'; try { $rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), self::findFieldID('created-by', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id = " . (int) $this->dsParamFILTERS['id'] : NULL, (int) $Members->Member->get('id'), max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT)); } catch (Exception $e) { $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError())))); return $result; } if ($rows->length() == 0) { return $this->emptyXMLSet(); } $total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total; $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE)); /* stdClass Object ( [id] => 666 [pinned] => yes [closed] => no [creation-date] => 1233599808 [last-active] => 1237161637 [created-by-member-id] => 2126 [created-by-username] => Lewis [last-post-member-id] => 2126 [last-post-username] => Lewis [topic] => Symphony 2 Documentation [comments] => 18 ) <entry id="595" comments="7"> <created-by id="2150">newnomad</created-by> <closed>No</closed> <last-active time="18:30" weekday="1">2009-02-09</last-active> <last-post id="2150">newnomad</last-post> <pinned>No</pinned> <topic handle="viewing-feeds">viewing feeds</topic> <creation-date time="19:31" weekday="3">2009-01-07</creation-date> </entry> */ $param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id'); foreach ($rows as $r) { // Need to do a seperate query to find the comment counts. try { $comments = $db->query(sprintf("SELECT COUNT(*) AS `count` FROM `tbl_entries_data_%d` WHERE `relation_id` = %d ", self::findFieldID('parent-id', 'comments'), $r->id))->current()->count; } catch (Exception $e) { $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError())))); return $result; } $entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $comments)); $entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'}))); $entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'}))); $entry->appendChild(new XMLElement('closed', ucfirst($r->closed))); $entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned))); $entry->appendChild(new XMLElement('topic', General::sanitize($r->topic))); $entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date')); $entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active')); $result->appendChild($entry); } return $result; }
public function appendFormattedElement($wrapper, $data, $encode = false) { if (isset($data['gmt']) && !is_null($data['gmt'])) { // Get date if (is_array($data['local'])) { $date = current($data['local']); } else { $date = $data['local']; } // Append date $wrapper->appendChild(General::createXMLDateObject($date, $this->get('element_name'))); } }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { $dates = $this->_driver->getEntryDates($data, $this->get('id'), $this->_Parent->filter); $element = new XMLElement($this->get('element_name')); $element->appendChild(General::createXMLDateObject($data['start'], 'start')); // make sure not to print all the dates without a filter otherwise it pollutes the xml if ($this->_Parent->filter) { foreach ($dates[0] as $index => $date) { $element->appendChild(General::createXMLDateObject($date['value'], 'current')); } } // foreach ($dates[1] as $index => $date) { // $element->appendChild(General::createXMLDateObject($date['value'], ($index == 0 ? 'current' : 'after'))); // } $element->appendChild(General::createXMLDateObject($data['end'], 'end')); $element->setAttribute('mode', @$data['mode']); $element->setAttribute('units', @$data['units']); $wrapper->appendChild($element); }
/** * Given an Entry object, this function will generate an XML representation * of the Entry to be returned. It will also add any parameters selected * by this datasource to the parameter pool. * * @param Entry $entry * @return XMLElement|boolean * Returns boolean when only parameters are to be returned. */ public function processEntry(Entry $entry) { $data = $entry->getData(); $xEntry = new XMLElement('entry'); $xEntry->setAttribute('id', $entry->get('id')); if (!empty($this->_associated_sections)) { $this->setAssociatedEntryCounts($xEntry, $entry); } if ($this->_can_process_system_parameters) { $this->processSystemParameters($entry); } foreach ($data as $field_id => $values) { if (!isset(self::$_fieldPool[$field_id]) || !is_object(self::$_fieldPool[$field_id])) { self::$_fieldPool[$field_id] =& FieldManager::fetch($field_id); } $this->processOutputParameters($entry, $field_id, $values); if (!$this->_param_output_only) { foreach ($this->dsParamINCLUDEDELEMENTS as $handle) { list($handle, $mode) = preg_split('/\\s*:\\s*/', $handle, 2); if (self::$_fieldPool[$field_id]->get('element_name') == $handle) { self::$_fieldPool[$field_id]->appendFormattedElement($xEntry, $values, $this->dsParamHTMLENCODE ? true : false, $mode, $entry->get('id')); } } } } if ($this->_param_output_only) { return true; } if (in_array('system:date', $this->dsParamINCLUDEDELEMENTS)) { $xEntry->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->creationDate), 'system-date')); } return $xEntry; }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { if (isset($data['value'])) { // Get date if (is_array($data['value'])) { $date = current($data['value']); } else { $date = $data['value']; } // Append date $wrapper->appendChild(General::createXMLDateObject($date, $this->get('element_name'))); } }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { $pw = new XMLElement($this->get('element_name')); // If reset is set, return the recovery-code if ($data['reset'] == 'yes') { $pw->setAttribute('reset-requested', 'yes'); $pw->appendChild(new XMLElement('recovery-code', $data['recovery-code'])); // Add expiry timestamp, including how long the code is valid for $expiry = General::createXMLDateObject(strtotime($data['timestamp'] . ' + ' . $this->get('code_expiry')), 'expires'); $expiry->setAttribute('expiry', $this->get('code_expiry')); $pw->appendChild($expiry); } else { if ($data['password']) { $pw->setValue($data['password']); } } $wrapper->appendChild($pw); }
function grab($param = array()) { ## Decide if we return an emtpy set or not if ($this->__forceEmptySet()) { ##Create the XML container $xml = new XMLElement("archive-entry-list"); $xml->setAttribute("section", $this->getType()); $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } $obDate = $this->_parent->getDateObj(); extract($this->_env, EXTR_PREFIX_ALL, 'env'); $where = $sort = $joins = NULL; include_once TOOLKIT . '/class.entrymanager.php'; $entryManager = new EntryManager($this->_parent); $section_id = $entryManager->fetchSectionIDFromHandle($this->getType()); ##Prepare the Query if ($handle = $this->__resolveDefine("dsFilterHANDLE")) { $entries = $entryManager->fetchEntryIDFromPrimaryFieldHandle($section_id, $handle); $where .= " AND t1.`id`" . ($this->__isDefineNotClause("dsFilterHANDLE") ? ' NOT' : '') . " IN ('" . @implode("', '", $entries) . "') "; } if ($date = $this->__resolveDefine("dsFilterDAY")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%d') " . ($this->__isDefineNotClause("dsFilterDAY") ? '!' : '') . "= '" . $date . "' "; } if ($month = $this->__resolveDefine("dsFilterMONTH")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%m') " . ($this->__isDefineNotClause("dsFilterMONTH") ? '!' : '') . "= '" . $month . "' "; } if ($year = $this->__resolveDefine("dsFilterYEAR")) { $where .= " AND DATE_FORMAT(t1.publish_date, '%Y') " . ($this->__isDefineNotClause("dsFilterYEAR") ? '!' : '') . "= '" . $year . "' "; } if ($this->_dsFilterINCLUDEPOSTDATED != 'yes') { $where .= " AND UNIX_TIMESTAMP(t1.publish_date_gmt) <= '" . $obDate->get(false, false) . "' "; } if (is_array($this->_dsFilterCUSTOM) && !empty($this->_dsFilterCUSTOM)) { $table_id = 15; foreach ($this->_dsFilterCUSTOM as $handle => $value) { $field = $this->_db->fetchRow(0, "SELECT `id`, `type`, `foreign_select_multiple` FROM `tbl_customfields` WHERE `parent_section` = '{$section_id}' AND `handle` = '{$handle}' LIMIT 1"); $value_handle = Lang::createHandle($value, $this->_parent->getConfigVar('handle_length', 'admin')); if ($field['type'] == 'multiselect' || $field['type'] == 'foreign' && $field['foreign_select_multiple'] == 'yes') { $joins .= " LEFT JOIN `tbl_entries2customfields_list` AS t{$table_id} ON t1.`id` = t{$table_id}.`entry_id` AND t{$table_id}.field_id = " . $field['id'] . " "; $where .= " AND (t{$table_id}.value_raw = '{$value}' OR t{$table_id}.handle = '{$value_handle}') "; } else { $joins .= " LEFT JOIN `tbl_entries2customfields` AS t{$table_id} ON t1.`id` = t{$table_id}.`entry_id` AND t{$table_id}.field_id = " . $field['id'] . " "; $where .= " AND (t{$table_id}.value_raw = '{$value}' OR t{$table_id}.handle = '{$value_handle}') "; } $table_id++; } } if ($this->_dsFilterSORT != '') { $sort = strtoupper($this->_dsFilterSORT); } if ($max_months = $this->__resolveDefine("dsFilterLIMIT_MONTHS")) { $sql = "SELECT UNIX_TIMESTAMP(t1.publish_date) AS publish_timestamp " . "FROM `tbl_entries` AS t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` " . "AND t2.`class` = 'entry' " . "LEFT JOIN `tbl_authors` AS t4 ON t1.`author_id` = t4.`id` " . $joins . "LEFT JOIN `tbl_entries2sections` AS t8 ON t1.id = t8.entry_id " . "WHERE t8.section_id = '{$section_id}' " . $where . "GROUP BY t1.`id` " . "ORDER BY t1.`publish_date` {$sort} " . "LIMIT 1"; $relative_start = $this->_db->fetchVar('publish_timestamp', 0, $sql); switch ($sort) { case "DESC": $end = mktime(0, 0, 0, date('m', $relative_start) - $max_months + 1, 1, date('Y', $relative_start)); $where .= " AND (UNIX_TIMESTAMP(t1.publish_date) <= '{$relative_start}' AND UNIX_TIMESTAMP(t1.publish_date) >= '{$end}')"; break; case "ASC": ## Since this is assending, we need to start from 0. The DS editor will give us 1+ $max_months--; $last_day = date('d', mktime(0, 0, 0, date('m', $relative_start) + 1, 0, date('Y', $relative_start))); $end = mktime(23, 59, 59, date('m', $relative_start) + $max_months, $last_day, date('Y', $relative_start)); $where .= " AND (UNIX_TIMESTAMP(t1.publish_date) >= '{$relative_start}' AND UNIX_TIMESTAMP(t1.publish_date) <= '{$end}')"; break; } } else { ##We are trying to preview if (isset($param['limit'])) { $limit = " LIMIT 0, " . $param['limit']; } elseif ($this->_dsFilterLIMIT != '') { $limit = " LIMIT 0, " . $this->_dsFilterLIMIT; } elseif ($where == NULL) { $limit = " LIMIT 0, 50"; } } $sql = "SELECT t1.id " . "FROM `tbl_entries` AS t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` " . "AND t2.`class` = 'entry' " . "LEFT JOIN `tbl_authors` AS t4 ON t1.`author_id` = t4.`id` " . $joins . "LEFT JOIN `tbl_entries2sections` AS t8 ON t1.id = t8.entry_id " . "WHERE t8.section_id = '{$section_id}' " . $where . "GROUP BY t1.`id` " . "ORDER BY t1.`publish_date_gmt` " . $sort . $limit; ##Check the cache $hash_id = md5(get_class($this) . serialize($env_url)); if ($param['caching'] && ($cache = $this->check_cache($hash_id))) { return $cache; exit; } ##------------------------------ ##Create the XML container $xml = new XMLElement("archive-entry-list"); $xml->setAttribute("section", $this->getType()); $xml->setAttribute("section-id", $section_id); ##Grab the records $entries = $this->_db->fetchCol("id", $sql); ##Populate the XML if (empty($entries) || !is_array($entries)) { $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } else { $bin = array(); foreach ($entries as $id) { $row = $entryManager->fetchEntriesByID($id, false, true); list($dYear, $dMonth, $dDay) = explode("-", date("Y-m-d", $obDate->get(true, false, strtotime($row['publish_date_gmt'])))); $bin[$dYear][$dMonth][$dDay][] = $row; } foreach ($bin as $year => $months) { $xYear = new XMLElement("year"); $xYear->setAttribute("value", $year); foreach ($months as $month => $days) { $xMonth = new XMLElement("month"); $xMonth->setAttribute("value", $month); foreach ($days as $day => $entries) { $xDay = new XMLElement("day"); $xDay->setAttribute("value", $day); foreach ($entries as $row) { $entry = new XMLElement("entry"); $entry->setAttribute("id", $row['id']); $entry->setAttribute("handle", trim($row['fields'][$row['primary_field']]['handle'])); $entry->setAttribute('linked-count', '' . count($row['linked_entries']) . ''); $date_local = $obDate->get(true, false, $row['timestamp_gmt']); $entry_fields = array("date" => General::createXMLDateObject($date_local), "time" => General::createXMLTimeObject($date_local), "rfc822-date" => date("D, d M Y H:i:s \\G\\M\\T", $obDate->get(false, false, $row['timestamp_gmt']))); $this->__addChildFieldsToXML($entry_fields, $entry); ##Author Details $author_rec = $this->_db->fetchRow(0, "SELECT * FROM `tbl_authors` WHERE `id` = '" . $row['author_id'] . "' LIMIT 1"); $author = new XMLElement("author"); $author_fields = array("first-name" => $author_rec['firstname'], "last-name" => $author_rec['lastname'], "email" => $author_rec['email'], "username" => $author_rec['username']); $this->__addChildFieldsToXML($author_fields, $author, "author"); $entry->addChild($author); ##Custom Fields $fields = $row['fields']; if (is_array($fields) && !empty($fields)) { $customFields = new XMLElement("fields"); foreach ($fields as $f) { if (@in_array($f['field_handle'], $this->_dsFilterXMLFIELDS)) { $newField = new XMLElement($f['field_handle']); if ($f['type'] == 'list' || $f['type'] == 'multiselect') { foreach ($f['value_raw'] as $val) { $item = new XMLElement("item", $val); $item->setAttribute("handle", Lang::createHandle($val, $this->_parent->getConfigVar('handle_length', 'admin'))); $newField->addChild($item); } } elseif ($f['type'] == 'foreign') { $sid = $f['foreign_section']; $section_handle = $this->_db->fetchVar('handle', 0, "SELECT `handle` FROM `tbl_sections` WHERE `id` = '{$sid} ' LIMIT 1"); $newField->setAttribute("handle", $f['handle']); $newField->setAttribute("type", 'foreign'); $newField->setAttribute("section-id", $sid); $newField->setAttribute("section-handle", $sid); if (!is_array($f['value_raw'])) { $f['value_raw'] = array($f['value_raw']); } foreach ($f['value_raw'] as $h) { $entry_id = $entryManager->fetchEntryIDFromPrimaryFieldHandle($sid, $h); $e = $entryManager->fetchEntriesByID($entry_id, false, true); $item = new XMLElement("item", trim($e['fields'][$e['primary_field']]['value'])); $item->setAttribute("entry-id", $entry_id[0]); $item->setAttribute("entry-handle", $e['fields'][$e['primary_field']]['handle']); $newField->addChild($item); } } elseif ($f['type'] == 'upload') { foreach ($f['value_raw'] as $val) { $item = new XMLElement("item"); $item->addChild(new XMLElement("path", trim($val['path'], '/'))); $item->addChild(new XMLElement("type", $val['type'])); $item->addChild(new XMLElement("size", General::formatFilesize($val['size']))); $newField->addChild($item); } } elseif ($f['type'] == 'checkbox') { $newField->setValue($f['value_raw']); } elseif ($f['type'] == 'select') { $newField->setValue($f['value_raw']); $newField->setAttribute("handle", $f['handle']); } else { $key = 'value'; if ($f['format'] != 1) { $key = 'value_raw'; } $f[$key] = trim($f[$key]); $value = $f[$key]; if ($this->_dsFilterENCODE == "yes") { $value = trim(General::sanitize($f[$key])); } if ($f['type'] == 'textarea') { $newField->setValue($value); $newField->setAttribute("word-count", General::countWords(strip_tags($f['value']))); } elseif ($f['type'] == 'input' && $f['field_id'] != $row['primary_field']) { $newField->setAttribute("handle", $f['handle']); $newField->setValue($value); } } $customFields->addChild($newField); } } $entry->addChild($customFields); } ##Comments $commenting = $this->_db->fetchVar('commenting', 0, "SELECT `commenting` FROM `tbl_sections` WHERE `id` = '{$section_id}' LIMIT 1"); if ($commenting == 'on') { $comments = new XMLElement("comments"); $sql = "SELECT count(*) as `count` " . "FROM `tbl_comments` " . "WHERE `entry_id` = '" . $row['id'] . "'"; $comment_count = max(0, @intval($this->_db->fetchVar("count", 0, $sql . " AND `spam` = 'no'"))); $spam_count = max(0, @intval($this->_db->fetchVar("count", 0, $sql . " AND `spam` = 'yes'"))); $comments->setAttribute("count", "" . $comment_count . ""); $comments->setAttribute("spam", "" . $spam_count . ""); $entry->addChild($comments); } $xDay->addChild($entry); } $xMonth->addChild($xDay); } $xYear->addChild($xMonth); } $xml->addChild($xYear); } } ##------------------------------ ##Write To Cache if ($param['caching']) { $result = $xml->generate($param['indent'], $param['indent-depth']); $this->write_to_cache($hash_id, $result, $this->_cache_sections); return $result; } return $xml; }
public function grab(&$param_pool) { $result = new XMLElement($this->dsParamROOTELEMENT); self::__init(); $db = ASDCLoader::instance(); $sql = "SELECT SQL_CALC_FOUND_ROWS \n\t\t\t\t\t\tpinned.entry_id AS `id`, \n\t\t\t\t\t\tpinned.value AS `pinned`, \n\t\t\t\t\t\tclosed.value AS `closed`, \n\t\t\t\t\t\tcreation_date.local AS `creation-date`,\n\t\t\t\t\t\tlast_active.local AS `last-active`,\t\t\t\t\t\t\t\n\t\t\t\t\t\tcreated_by.member_id AS `created-by-member-id`,\n\t\t\t\t\t\tcreated_by.username AS `created-by-username`,\n\t\t\t\t\t\tlast_post.member_id AS `last-post-member-id`,\n\t\t\t\t\t\tlast_post.username AS `last-post-username`,\t\t\t\t\t\t\t\n\t\t\t\t\t\ttopic.value AS `topic`,\n\t\t\t\t\t\tCOUNT(comments.relation_id) AS `comments`\n\t\t\t\t\t\n\t\t\t\t\tFROM `tbl_entries_data_%d` AS `pinned`\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `closed` ON pinned.entry_id = closed.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `creation_date` ON pinned.entry_id = creation_date.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_active` ON pinned.entry_id = last_active.entry_id\t\t\t\t\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `created_by` ON pinned.entry_id = created_by.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `last_post` ON pinned.entry_id = last_post.entry_id\t\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `topic` ON pinned.entry_id = topic.entry_id\n\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `comments` ON pinned.entry_id = comments.relation_id\n\t\t\t\t\tWHERE 1 %s\n\t\t\t\t\tGROUP BY pinned.entry_id\n\t\t\t\t\tORDER BY pinned.value ASC, last_active.local DESC\n\t\t\t\t\tLIMIT %d, %d"; try { $rows = $db->query(sprintf($sql, self::findFieldID('pinned', 'discussions'), self::findFieldID('closed', 'discussions'), self::findFieldID('creation-date', 'discussions'), self::findFieldID('last-active', 'discussions'), self::findFieldID('created-by', 'discussions'), self::findFieldID('last-post', 'discussions'), self::findFieldID('topic', 'discussions'), self::findFieldID('parent-id', 'comments'), isset($this->dsParamFILTERS['id']) && (int) $this->dsParamFILTERS['id'] > 0 ? " AND pinned.entry_id = " . (int) $this->dsParamFILTERS['id'] : NULL, max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), $this->dsParamLIMIT)); } catch (Exception $e) { $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', $db->lastError())))); return $result; } if ($rows->length() == 0 && strlen(trim($dsParamFILTERS['id'])) > 0) { $this->__redirectToErrorPage(); } elseif ($rows->length() == 0) { return $this->emptyXMLSet(); } $total = $db->query('SELECT FOUND_ROWS() AS `total`;')->current()->total; $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE)); /* stdClass Object ( [id] => 666 [pinned] => yes [closed] => no [creation-date] => 1233599808 [last-active] => 1237161637 [created-by-member-id] => 2126 [created-by-username] => Lewis [last-post-member-id] => 2126 [last-post-username] => Lewis [topic] => Symphony 2 Documentation [comments] => 18 ) <entry id="595" comments="7"> <created-by id="2150">newnomad</created-by> <closed>No</closed> <last-active time="18:30" weekday="1">2009-02-09</last-active> <last-post id="2150">newnomad</last-post> <pinned>No</pinned> <topic handle="viewing-feeds">viewing feeds</topic> <creation-date time="19:31" weekday="3">2009-01-07</creation-date> </entry> */ $param_pool['ds-' . $this->dsParamROOTELEMENT] = DatabaseUtilities::resultColumn($rows, 'id'); foreach ($rows as $r) { $entry = new XMLElement('entry', NULL, array('id' => $r->id, 'comments' => $r->comments)); $entry->appendChild(new XMLElement('created-by', General::sanitize($r->{'created-by-username'}), array('id' => $r->{'created-by-member-id'}))); $entry->appendChild(new XMLElement('last-post', General::sanitize($r->{'last-post-username'}), array('id' => $r->{'last-post-member-id'}))); $entry->appendChild(new XMLElement('closed', ucfirst($r->closed))); $entry->appendChild(new XMLElement('pinned', ucfirst($r->pinned))); $entry->appendChild(new XMLElement('topic', General::sanitize($r->topic))); $entry->appendChild(General::createXMLDateObject($r->{'creation-date'}, 'creation-date')); $entry->appendChild(General::createXMLDateObject($r->{'last-active'}, 'last-active')); $result->appendChild($entry); } return $result; }
function grab($param = array()) { ## Decide if we return an emtpy set or not if ($this->__forceEmptySet()) { ##Create the XML container $xml = new XMLElement("comments"); $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } $obDate = $this->_parent->getDateObj(); extract($this->_env, EXTR_PREFIX_ALL, 'env'); $where = NULL; include_once TOOLKIT . "/class.entrymanager.php"; $entryManager = new EntryManager($this->_parent); ##Prepare the Query if ($section_id = $entryManager->fetchSectionIDFromHandle($this->_dsFilterSECTION)) { $comment_where .= " AND t4.`section_id` = '{$section_id}' "; if ($entries = $this->__resolveDefine("dsFilterHANDLE", true)) { $entry_ids = $entryManager->fetchEntryIDFromPrimaryFieldHandle($section_id, $entries); $comment_where .= " AND t3.`id`" . ($this->__isDefineNotClause("dsFilterHANDLE") ? ' NOT' : '') . " IN ('" . @implode("', '", $entry_ids) . "') "; } } if ($date = $this->__resolveDefine("dsFilterDAY")) { $comment_where .= " AND DATE_FORMAT(t2.creation_date, '%d') " . ($this->__isDefineNotClause("dsFilterDAY") ? '!' : '') . "= '" . $date . "' "; } if ($month = $this->__resolveDefine("dsFilterMONTH")) { $comment_where .= " AND DATE_FORMAT(t2.creation_date, '%m') " . ($this->__isDefineNotClause("dsFilterMONTH") ? '!' : '') . "= '" . $month . "' "; } if ($year = $this->__resolveDefine("dsFilterYEAR")) { $comment_where .= " AND DATE_FORMAT(t2.creation_date, '%Y') " . ($this->__isDefineNotClause("dsFilterYEAR") ? '!' : '') . "= '" . $year . "' "; } $sort = "DESC"; if ($this->_dsFilterSORT != '') { $sort = strtoupper($this->_dsFilterSORT); } if (!isset($this->_dsFilterSHOWSPAM) || $this->_dsFilterSHOWSPAM != 'yes') { $comment_where .= " AND `t1`.`spam` = 'no' "; } if ($max_months = $this->__resolveDefine("dsFilterLIMIT_MONTHS")) { $sql = "SELECT UNIX_TIMESTAMP(t2.creation_date_gmt) as `creation_timestamp_gmt` " . "FROM `tbl_comments` as t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` AND t2.`class` = 'comment' " . "INNER JOIN `tbl_entries` as t3 ON t1.`entry_id` = t3.`id` " . "LEFT JOIN `tbl_entries2sections` AS t4 ON t3.`id` = t4.`entry_id` " . "WHERE 1 " . $comment_where . "GROUP BY t1.`id` " . "ORDER BY `creation_timestamp_gmt` {$sort} " . "LIMIT 1"; $relative_start = $this->_db->fetchVar('creation_timestamp_gmt', 0, $sql); switch ($sort) { case "DESC": $end = mktime(0, 0, 0, date('m', $relative_start) - $max_months + 1, 1, date('Y', $relative_start)); $comment_where .= " AND (UNIX_TIMESTAMP(t2.creation_date_gmt) <= '{$relative_start}' AND UNIX_TIMESTAMP(t2.creation_date_gmt) >= '{$end}')"; break; case "ASC": ## Since this is assending, we need to start from 0. The DS editor will give us 1+ $max_months--; $last_day = date('d', mktime(0, 0, 0, date('m', $relative_start) + 1, 0, date('Y', $relative_start))); $end = mktime(23, 59, 59, date('m', $relative_start) + $max_months, $last_day, date('Y', $relative_start)); $comment_where .= " AND (UNIX_TIMESTAMP(t2.creation_date_gmt) >= '{$relative_start}' AND UNIX_TIMESTAMP(t2.creation_date_gmt) <= '{$end}')"; break; } } else { ##We are trying to preview if (isset($param['limit'])) { $limit = $param['limit']; } elseif ($this->_dsFilterLIMIT != '') { $limit = intval($this->_dsFilterLIMIT); ##Prevent things from getting too big } else { $limit = 50; } } $start = 0; $sql = "SELECT count(t1.id) AS `total-comments` " . "FROM `tbl_comments` AS t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` AND t2.`class` = 'comment' " . "INNER JOIN `tbl_entries` as t3 ON t1.`entry_id` = t3.`id` " . "LEFT JOIN `tbl_entries2sections` AS t4 ON t3.`id` = t4.`entry_id` " . "WHERE 1 " . $comment_where; $kTotalCommentCount = $this->_db->fetchVar('total-comments', 0, $sql); if (isset($this->_dsFilterPAGENUMBER)) { $pagenumber = $this->__resolveDefine("dsFilterPAGENUMBER"); $kPageNumber = max(1, intval($pagenumber)); if (!$limit) { $limit = 50; } $kTotalPages = ceil($kTotalCommentCount * (1 / $limit)); $start = $limit * ($kPageNumber - 1); } $sql = "SELECT t1.*, UNIX_TIMESTAMP(t2.creation_date_gmt) as `creation_timestamp_gmt` " . "FROM `tbl_comments` as t1 " . "LEFT JOIN `tbl_metadata` AS t2 ON t1.`id` = t2.`relation_id` AND t2.`class` = 'comment' " . "INNER JOIN `tbl_entries` as t3 ON t1.`entry_id` = t3.`id` " . "LEFT JOIN `tbl_entries2sections` AS t4 ON t3.`id` = t4.`entry_id` " . "WHERE 1 " . $comment_where . "GROUP BY t1.`id` " . "ORDER BY `creation_timestamp_gmt` {$sort} " . ($limit ? " LIMIT {$start}, {$limit}" : ''); ##Check Cache $hash_id = md5(get_class($this) . $sql); if ($param['caching'] && ($cache = $this->check_cache($hash_id))) { return $cache; exit; } ##------------------------------ ##Create the XML container $xml = new XMLElement("comments"); ##Grab the records $comments = $this->_db->fetch($sql); ##Populate the XML if (empty($comments) || !is_array($comments)) { $xml->addChild(new XMLElement("error", "No Records Found.")); return $xml; } else { $entries = array(); foreach ($comments as $c) { $entries[$c['entry_id']]['commenting'] = $c['commenting']; $entries[$c['entry_id']]['comments'][] = $c; } if (in_array("pagination-info", $this->_dsFilterXMLFIELDS)) { $pageinfo = new XMLElement("pagination-info"); $pageinfo->setAttribute("total-comments", $kTotalCommentCount); $pageinfo->setAttribute("total-pages", $kTotalPages); $pageinfo->setAttribute("comment-per-page", $limit); $pageinfo->setAttribute("current-page", $kPageNumber); $xml->addChild($pageinfo); } foreach ($entries as $id => $row) { $entry_data = $entryManager->fetchEntriesByID($id, false, true); $entry = new XMLElement("entry"); $entry->setAttribute("id", $id); $entry->setAttribute('section-id', $entry_data['section_id']); $entry->setAttribute("handle", trim($entry_data['fields'][$entry_data['primary_field']]['handle'])); $entry->setAttribute("commenting", $row['commenting']); $entry->addChild(new XMLElement("entry-title", trim($entry_data['fields'][$entry_data['primary_field']]['value']))); $fields = $row['comments']; $entry->setAttribute("count", $kTotalCommentCount); if (is_array($fields) && !empty($fields)) { foreach ($fields as $c) { $comment = new XMLElement("comment"); $comment->setAttribute("id", $c['id']); if ($c['author_id'] != NULL) { $comment->setAttribute('authorised', 'yes'); $comment->setAttribute('author_id', $c['author_id']); } if (@in_array('spam', $this->_dsFilterXMLFIELDS)) { $comment->setAttribute("spam", $c['spam']); } $date_local = $obDate->get(true, false, $c['creation_timestamp_gmt']); $comment_fields = array("author" => $c['author_name'], "date" => General::createXMLDateObject($date_local), "time" => General::createXMLTimeObject($date_local), "rfc822-date" => date("D, d M Y H:i:s \\G\\M\\T", $obDate->get(false, false, $row['creation_timestamp_gmt'])), "message" => $this->_dsFilterENCODE != 'yes' ? $c['body'] : General::sanitize($c['body']), "url" => $c['author_url'], "email" => $c['author_email'], "email-hash" => md5($c['author_email'])); $this->__addChildFieldsToXML($comment_fields, $comment); $entry->addChild($comment); } } $xml->addChild($entry); } } ##------------------------------ ##Write To Cache if ($param['caching']) { $result = $xml->generate($param['indent'], $param['indent-depth']); $this->write_to_cache($hash_id, $result, $this->_cache_sections); return $result; } return $xml; }
public function appendFormattedElement(&$wrapper, $data, $encode = false, $mode = null) { $element = new XMLElement($this->get('element_name')); if (!empty($data) and strlen(trim($data['from_value'])) != 0) { $value = General::sanitize(__('%s until %s', array(date(__SYM_DATE_FORMAT__, $data['from_date']), date(__SYM_DATE_FORMAT__, $data['to_date'])))); if ($encode) { $value = General::sanitize($value); } $element->setAttribute('mode', $data['mode']); $element->setAttribute('value', $value); $date = General::createXMLDateObject($data['from_date'], 'from-date'); $date->setAttribute('value', $data['from_value']); $element->appendChild($date); $date = General::createXMLDateObject($data['to_date'], 'to-date'); $date->setAttribute('value', $data['to_value']); $element->appendChild($date); } $wrapper->appendChild($element); }
public function processResults(SymRead $query, Section $section, array $pagination, array $entries) { $root_element = $this->createElement($this->root_element); $section_element = $this->createElement('section'); $pagination_element = $this->createElement('pagination'); // Build section information: $section_element->setAttribute('id', $section->get('id')); $section_element->setAttribute('handle', $section->get('handle')); $section_element->appendChild($this->createTextNode($section->get('name'))); $root_element->appendChild($section_element); // Build pagination information: $pagination_element->setAttribute('total-entries', $pagination['total-entries']); $pagination_element->setAttribute('total-pages', $pagination['total-pages']); $pagination_element->setAttribute('entries-per-page', $pagination['entries-per-page']); $pagination_element->setAttribute('current-page', $pagination['current-page']); $root_element->appendChild($pagination_element); foreach ($entries as $entry) { $entry_xml = new XMLElement('entry'); $entry_xml->setAttribute('id', $entry->get('id')); foreach ($query->selects as $select) { $field = $select->get('object'); if ($field == SymQuery::SYSTEM_DATE) { $entry_xml->appendChild(General::createXMLDateObject(strtotime($entry->creationDate), 'system-date')); } if (!$field instanceof Field) { continue; } $data = $entry->getData($field->get('id')); if ($select->has('mode')) { $field->appendFormattedElement($entry_xml, $data, false, $select->get('mode')); } else { $field->appendFormattedElement($entry_xml, $data, false); } } $fragment = $this->createDocumentFragment(); $fragment->appendXML($entry_xml->generate()); $root_element->appendChild($fragment); } $this->appendChild($root_element); return $this; }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { if (isset($data->value) && !is_null($data->value)) { $wrapper->appendChild(General::createXMLDateObject($wrapper->ownerDocument, DateTimeObj::fromGMT($data->value), $this->{'element-name'})); } }
public function appendFormattedElement(XMLElement &$wrapper, $data, $encode = false, $mode = null, $entry_id = null) { if (!is_array($data) or !isset($data['activated'])) { return; } $el = new XMLElement($this->get('element_name')); $el->setAttribute('activated', $data['activated']); if ($data['activated'] == 'yes') { // Append the time the person was activated $el->appendChild(General::createXMLDateObject(strtotime($data['timestamp']), 'date')); } else { // Append the code $el->appendChild(new XMLElement('code', $data['code'])); // Add expiry timestamp, including how long the code is valid for $expiry = General::createXMLDateObject(strtotime($data['timestamp'] . ' + ' . $this->get('code_expiry')), 'expires'); $expiry->setAttribute('expiry', $this->get('code_expiry')); $el->appendChild($expiry); } $wrapper->appendChild($el); }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { $wrapper->appendChild(General::createXMLDateObject($data['local'], $this->get('element_name'))); }
public function render(Register $ParameterOutput, $joins = NULL, array $where = array(), $filter_operation_type = self::FILTER_AND) { $execute = true; $result = new XMLDocument(); $result->appendChild($result->createElement($this->parameters()->{'root-element'})); $root = $result->documentElement; // Conditions // If any one condtion returns true (that is, do not execute), the DS will not execute at all if (is_array($this->parameters()->conditions)) { foreach ($this->parameters()->conditions as $condition) { if (preg_match('/:/', $condition['parameter'])) { $c = Datasource::replaceParametersInString($condition['parameter'], $ParameterOutput); } else { $c = Datasource::resolveParameter($condition['parameter'], $ParameterOutput); } // Is Empty if ($condition['logic'] == 'empty' && (is_null($c) || strlen($c) == 0)) { $execute = false; } elseif ($condition['logic'] == 'set' && !is_null($c)) { $execute = false; } if ($execute !== true) { return NULL; } } } // Grab the section try { $section = Section::loadFromHandle($this->parameters()->section); } catch (SectionException $e) { } catch (Exception $e) { } $pagination = (object) array('total-entries' => NULL, 'entries-per-page' => max(1, (int) self::replaceParametersInString($this->parameters()->limit, $ParameterOutput)), 'total-pages' => NULL, 'current-page' => max(1, (int) self::replaceParametersInString($this->parameters()->page, $ParameterOutput))); $pagination->{'record-start'} = max(0, ($pagination->{'current-page'} - 1) * $pagination->{'entries-per-page'}); $order = $sort = NULL; // Apply the Sorting & Direction if ($this->parameters()->{'sort-order'} == 'random') { $order = 'RAND()'; } else { $sort = strtolower($this->parameters()->{'sort-order'}) == 'asc' ? 'ASC' : 'DESC'; // System Field if (preg_match('/^system:/i', $this->parameters()->{'sort-field'})) { switch (preg_replace('/^system:/i', NULL, $this->parameters()->{'sort-field'})) { case 'id': $order = "e.id {$sort}"; break; case 'creation-date': $order = "e.creation_date {$sort}"; break; case 'modification-date': $order = "e.modification_date {$sort}"; break; } } else { $join = NULL; $sort_field = $section->fetchFieldByHandle($this->parameters()->{'sort-field'}); if ($sort_field instanceof Field && $sort_field->isSortable() && method_exists($sort_field, "buildSortingQuery")) { $sort_field->buildSortingQuery($join, $order); $joins .= sprintf($join, $sort_field->section, $sort_field->{'element-name'}); $order = sprintf($order, $sort); } } } // Process Datasource Filters for each of the Fields if (is_array($this->parameters()->filters) && !empty($this->parameters()->filters)) { foreach ($this->parameters()->filters as $k => $filter) { if ($filter['element-name'] == 'system:id') { $filter_value = $this->prepareFilterValue($filter['value'], $ParameterOutput); if (!is_array($filter_value)) { continue; } $filter_value = array_map('intval', $filter_value); if (empty($filter_value)) { continue; } $where[] = sprintf("(e.id %s IN (%s))", $filter['type'] == 'is-not' ? 'NOT' : NULL, implode(',', $filter_value)); } else { $field = $section->fetchFieldByHandle($filter['element-name']); if ($field instanceof Field) { $field->buildFilterQuery($filter, $joins, $where, $ParameterOutput); } } } } // Escape percent symbold: $where = array_map(create_function('$string', 'return str_replace(\'%\', \'%%\', $string);'), $where); $query = sprintf('SELECT DISTINCT SQL_CALC_FOUND_ROWS e.* FROM `tbl_entries` AS `e` %1$s WHERE `section` = "%2$s" %3$s ORDER BY %4$s LIMIT %5$d, %6$d', $joins, $section->handle, is_array($where) && !empty($where) ? 'AND (' . implode($filter_operation_type == self::FILTER_AND ? ' AND ' : ' OR ', $where) . ')' : NULL, $order, $pagination->{'record-start'}, $pagination->{'entries-per-page'}); try { $entries = Symphony::Database()->query($query, array($section->handle, $section->{'publish-order-handle'}), 'EntryResult'); if (isset($this->parameters()->{'append-pagination'}) && $this->parameters()->{'append-pagination'} === true) { $pagination->{'total-entries'} = (int) Symphony::Database()->query("SELECT FOUND_ROWS() AS `total`")->current()->total; $pagination->{'total-pages'} = (int) ceil($pagination->{'total-entries'} * (1 / $pagination->{'entries-per-page'})); // Pagination Element $root->appendChild(General::buildPaginationElement($result, $pagination->{'total-entries'}, $pagination->{'total-pages'}, $pagination->{'entries-per-page'}, $pagination->{'current-page'})); } if (isset($this->parameters()->{'append-sorting'}) && $this->parameters()->{'append-sorting'} === true) { $sorting = $result->createElement('sorting'); $sorting->setAttribute('field', $this->parameters()->{'sort-field'}); $sorting->setAttribute('order', $this->parameters()->{'sort-order'}); $root->appendChild($sorting); } $schema = array(); // Build Entry Records if ($entries->valid()) { // Do some pre-processing on the include-elements. if (is_array($this->parameters()->{'included-elements'}) && !empty($this->parameters()->{'included-elements'})) { $included_elements = (object) array('system' => array(), 'fields' => array()); foreach ($this->parameters()->{'included-elements'} as $element) { $element_name = $mode = NULL; if (preg_match_all('/^([^:]+):\\s*(.+)$/', $element, $matches, PREG_SET_ORDER)) { $element_name = $matches[0][1]; $mode = $matches[0][2]; } else { $element_name = $element; } if ($element_name == 'system') { $included_elements->system[] = $mode; } else { $field = $section->fetchFieldByHandle($element_name); if (!$field instanceof Field) { continue; } $schema[] = $element_name; $included_elements->fields[] = array('element-name' => $element_name, 'instance' => $field, 'mode' => !is_null($mode) > 0 ? trim($mode) : NULL); } } } // Do some pre-processing on the param output array if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { $parameter_output = (object) array('system' => array(), 'fields' => array()); foreach ($this->parameters()->{'parameter-output'} as $element) { if (preg_match('/^system:/i', $element)) { $parameter_output->system[preg_replace('/^system:/i', NULL, $element)] = array(); } else { $schema[] = $element; $parameter_output->fields[$element] = array(); } } } $entries->setSchema($schema); foreach ($entries as $e) { // If there are included elements, need an entry element. if (is_array($this->parameters()->{'included-elements'}) && !empty($this->parameters()->{'included-elements'})) { $entry = $result->createElement('entry'); $entry->setAttribute('id', $e->id); $root->appendChild($entry); foreach ($included_elements->system as $field) { switch ($field) { case 'creation-date': $entry->appendChild(General::createXMLDateObject($result, DateTimeObj::fromGMT($e->creation_date), 'creation-date')); break; case 'modification-date': $entry->appendChild(General::createXMLDateObject($result, DateTimeObj::fromGMT($e->modification_date), 'modification-date')); break; case 'user': $obj = User::load($e->user_id); $user = $result->createElement('user', $obj->getFullName()); $user->setAttribute('id', $e->user_id); $user->setAttribute('username', $obj->username); $user->setAttribute('email-address', $obj->email); $entry->appendChild($user); break; } } foreach ($included_elements->fields as $field) { $field['instance']->appendFormattedElement($entry, $e->data()->{$field['element-name']}, false, $field['mode'], $e); } } if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { foreach ($parameter_output->system as $field => $existing_values) { switch ($field) { case 'id': $parameter_output->system[$field][] = $e->id; break; case 'creation-date': $parameter_output->system[$field][] = DateTimeObj::get('Y-m-d H:i:s', DateTimeObj::fromGMT($e->creation_date)); break; case 'modification-date': $parameter_output->system[$field][] = DateTimeObj::get('Y-m-d H:i:s', DateTimeObj::fromGMT($e->modification_date)); break; case 'user': $parameter_output->system[$field][] = $e->user_id; break; } } foreach ($parameter_output->fields as $field => $existing_values) { if (!isset($e->data()->{$field}) or is_null($e->data()->{$field})) { continue; } $o = $section->fetchFieldByHandle($field)->getParameterOutputValue($e->data()->{$field}, $e); if (is_array($o)) { $parameter_output->fields[$field] = array_merge($o, $parameter_output->fields[$field]); } else { $parameter_output->fields[$field][] = $o; } } } } // Add in the param output values to the ParameterOutput object if (is_array($this->parameters()->{'parameter-output'}) && !empty($this->parameters()->{'parameter-output'})) { foreach ($parameter_output->system as $field => $values) { $key = sprintf('ds-%s.system.%s', $this->parameters()->{'root-element'}, $field); $values = array_filter($values); if (is_array($values) && !empty($values)) { $ParameterOutput->{$key} = array_unique($values); } } foreach ($parameter_output->fields as $field => $values) { $key = sprintf('ds-%s.%s', $this->parameters()->{'root-element'}, $field); $values = array_filter($values); if (is_array($values) && !empty($values)) { $ParameterOutput->{$key} = array_unique($values); } } } } elseif ($this->parameters()->{'redirect-404-on-empty'} === true) { throw new FrontendPageNotFoundException(); } else { $this->emptyXMLSet($root); } } catch (DatabaseException $e) { $root->appendChild($result->createElement('error', $e->getMessage())); } return $result; }
public function getXPath($entry, $XSLTfilename = NULL, $fetch_associated_counts = NULL) { $entry_xml = new XMLElement('entry'); $data = $entry->getData(); $fields = array(); $entry_xml->setAttribute('id', $entry->get('id')); //Add date created and edited values $date = new XMLElement('system-date'); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('creation_date')), 'created')); $date->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->get('modification_date')), 'modified')); $entry_xml->appendChild($date); //Reflect Workspace and Siteroot params $workspace = new XMLElement('workspace', URL . '/workspace'); $root = new XMLElement('root', URL); // Add associated entry counts if ($fetch_associated_counts == 'yes') { $associated = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated) and !empty($associated)) { foreach ($associated as $section_id => $count) { $section = SectionManager::fetch($section_id); if ($section instanceof Section === false) { continue; } $entry_xml->setAttribute($section->get('handle'), (string) $count); } } } // Add fields: foreach ($data as $field_id => $values) { if (empty($field_id)) { continue; } $field = FieldManager::fetch($field_id); $field->appendFormattedElement($entry_xml, $values, false, null, $entry->get('id')); } $xml = new XMLElement('data'); $xml->appendChild($entry_xml); $xml->appendChild($workspace); $xml->appendChild($root); // Build some context $section = SectionManager::fetch($entry->get('section_id')); $params = new XMLElement('params'); $params->appendChild(new XMLElement('section-handle', $section->get('handle'))); $params->appendChild(new XMLElement('entry-id', $entry->get('id'))); $xml->prependChild($params); $dom = new DOMDocument(); $dom->strictErrorChecking = false; $dom->loadXML($xml->generate(true)); if (!empty($XSLTfilename)) { $XSLTfilename = UTILITIES . '/' . preg_replace(array('%/+%', '%(^|/)../%'), '/', $XSLTfilename); if (file_exists($XSLTfilename)) { $XSLProc = new XsltProcessor(); $xslt = new DomDocument(); $xslt->load($XSLTfilename); $XSLProc->importStyleSheet($xslt); // Set some context $XSLProc->setParameter('', array('section-handle' => $section->get('handle'), 'entry-id' => $entry->get('id'))); $temp = $XSLProc->transformToDoc($dom); if ($temp instanceof DOMDocument) { $dom = $temp; } } } $xpath = new DOMXPath($dom); if (version_compare(phpversion(), '5.3', '>=')) { $xpath->registerPhpFunctions(); } return $xpath; }
function processRecordGroup(&$wrapper, $element, $group, $ds, &$Parent, &$entryManager, &$fieldPool, &$param_pool, $param_output_only = false) { $xGroup = new XMLElement($element, NULL, $group['attr']); $key = 'ds-' . $ds->dsParamROOTELEMENT; if (is_array($group['records']) && !empty($group['records'])) { foreach ($group['records'] as $entry) { $data = $entry->getData(); $fields = array(); $xEntry = new XMLElement('entry'); $xEntry->setAttribute('id', $entry->get('id')); $associated_entry_counts = $entry->fetchAllAssociatedEntryCounts(); if (is_array($associated_entry_counts) && !empty($associated_entry_counts)) { foreach ($associated_entry_counts as $section_id => $count) { $section_handle = $Parent->Database->fetchVar('handle', 0, "SELECT `handle` FROM `tbl_sections` WHERE `id` = '{$section_id}' LIMIT 1"); $xEntry->setAttribute($section_handle, '' . $count . ''); } } if (isset($ds->dsParamPARAMOUTPUT)) { if ($ds->dsParamPARAMOUTPUT == 'system:id') { $param_pool[$key][] = $entry->get('id'); } elseif ($ds->dsParamPARAMOUTPUT == 'system:date') { $param_pool[$key][] = DateTimeObj::get('c', strtotime($entry->creationDate)); } elseif ($ds->dsParamPARAMOUTPUT == 'system:author') { $param_pool[$key][] = $entry->get('author_id'); } } foreach ($data as $field_id => $values) { if (!isset($fieldPool[$field_id]) || !is_object($fieldPool[$field_id])) { $fieldPool[$field_id] =& $entryManager->fieldManager->fetch($field_id); } if (isset($ds->dsParamPARAMOUTPUT) && $ds->dsParamPARAMOUTPUT == $fieldPool[$field_id]->get('element_name')) { $param_pool[$key][] = $fieldPool[$field_id]->getParameterPoolValue($values); } if (!$param_output_only) { foreach ($ds->dsParamINCLUDEDELEMENTS as $handle) { list($handle, $mode) = preg_split('/\\s*:\\s*/', $handle, 2); if ($fieldPool[$field_id]->get('element_name') == $handle) { $fieldPool[$field_id]->appendFormattedElement($xEntry, $values, $ds->dsParamHTMLENCODE ? true : false, $mode); } } } } if (!$param_output_only) { if (in_array('system:date', $ds->dsParamINCLUDEDELEMENTS)) { $xEntry->appendChild(General::createXMLDateObject(strtotime($entry->creationDate), 'system-date')); } $xGroup->appendChild($xEntry); } } } if (is_array($group['groups']) && !empty($group['groups'])) { foreach ($group['groups'] as $element => $group) { foreach ($group as $g) { processRecordGroup($xGroup, $element, $g, $ds, $Parent, $entryManager, $fieldPool, $param_pool, $param_output_only); } } } if (!$param_output_only) { $wrapper->appendChild($xGroup); } return; }
function processRecordGroup(&$wrapper, $element, $group, $ds, &$entryManager, &$fieldPool, &$param_pool, $param_output_only = false) { $associated_sections = NULL; $xGroup = new XMLElement($element, NULL, $group['attr']); $key = 'ds-' . $ds->dsParamROOTELEMENT; if (!($section = $entryManager->sectionManager->fetch($ds->getSource()))) { $about = $ds->about(); throw new Exception(__('The section associated with the data source <code>%s</code> could not be found.', array($about['name']))); } if (!isset($ds->dsParamASSOCIATEDENTRYCOUNTS) || $ds->dsParamASSOCIATEDENTRYCOUNTS == 'yes') { $associated_sections = $section->fetchAssociatedSections(); } if (is_array($group['records']) && !empty($group['records'])) { foreach ($group['records'] as $entry) { $data = $entry->getData(); $fields = array(); $xEntry = new XMLElement('entry'); $xEntry->setAttribute('id', $entry->get('id')); if (is_array($associated_sections)) { $associated_entry_counts = $entry->fetchAllAssociatedEntryCounts($associated_sections); if (is_array($associated_entry_counts) && !empty($associated_entry_counts)) { foreach ($associated_entry_counts as $section_id => $count) { foreach ($associated_sections as $section) { if ($section['id'] == $section_id) { $xEntry->setAttribute($section['handle'], (string) $count); } } } } } if (isset($ds->dsParamPARAMOUTPUT)) { if ($ds->dsParamPARAMOUTPUT == 'system:id') { $param_pool[$key][] = $entry->get('id'); } elseif ($ds->dsParamPARAMOUTPUT == 'system:date') { $param_pool[$key][] = DateTimeObj::get('c', $entry->creationDate); } elseif ($ds->dsParamPARAMOUTPUT == 'system:author') { $param_pool[$key][] = $entry->get('author_id'); } } foreach ($data as $field_id => $values) { if (!isset($fieldPool[$field_id]) || !is_object($fieldPool[$field_id])) { $fieldPool[$field_id] =& $entryManager->fieldManager->fetch($field_id); } if (isset($ds->dsParamPARAMOUTPUT) && $ds->dsParamPARAMOUTPUT == $fieldPool[$field_id]->get('element_name')) { if (!isset($param_pool[$key]) || !is_array($param_pool[$key])) { $param_pool[$key] = array(); } $param_pool_values = $fieldPool[$field_id]->getParameterPoolValue($values); if (is_array($param_pool_values)) { $param_pool[$key] = array_merge($param_pool_values, $param_pool[$key]); } else { $param_pool[$key][] = $param_pool_values; } } if (!$param_output_only) { if (is_array($ds->dsParamINCLUDEDELEMENTS)) { foreach ($ds->dsParamINCLUDEDELEMENTS as $handle) { list($handle, $mode) = preg_split('/\\s*:\\s*/', $handle, 2); if ($fieldPool[$field_id]->get('element_name') == $handle) { $fieldPool[$field_id]->appendFormattedElement($xEntry, $values, $ds->dsParamHTMLENCODE ? true : false, $mode, $entry->get('id')); } } } } } if (!$param_output_only) { if (is_array($ds->dsParamINCLUDEDELEMENTS) && in_array('system:date', $ds->dsParamINCLUDEDELEMENTS)) { $xEntry->appendChild(General::createXMLDateObject(DateTimeObj::get('U', $entry->creationDate), 'system-date')); } $xGroup->appendChild($xEntry); } } } if (is_array($group['groups']) && !empty($group['groups'])) { foreach ($group['groups'] as $element => $group) { foreach ($group as $g) { processRecordGroup($xGroup, $element, $g, $ds, $entryManager, $fieldPool, $param_pool, $param_output_only); } } } if (!$param_output_only) { $wrapper->appendChild($xGroup); } return; }
public function grab(&$param_pool) { self::__init(); /* var $dsParamINCLUDEDELEMENTS = array( 'system:pagination', 'comment', 'date', 'created-by' ); <pagination total-entries="28" total-pages="2" entries-per-page="20" current-page="2" /> <section id="39" handle="comments">Comments</section> */ $result = new XMLElement($this->dsParamROOTELEMENT); try { $comments = ASDCLoader::instance()->query(sprintf("SELECT SQL_CALC_FOUND_ROWS\n\t\t\t\t\t\t\tcomment.entry_id AS `id`,\n\t\t\t\t\t\t\tcomment.value_formatted AS `comment`, \n\t\t\t\t\t\t\tcreated_by.member_id, \n\t\t\t\t\t\t\tcreated_by.username, \n\t\t\t\t\t\t\tdate.local AS `date`,\n\t\t\t\t\t\t\temail.value AS `email`\n\n\t\t\t\t\t\tFROM `tbl_entries_data_%d` AS `comment`\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `created_by` ON comment.entry_id = created_by.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `date` ON comment.entry_id = date.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `email` ON created_by.member_id = email.entry_id\n\t\t\t\t\t\tLEFT JOIN `tbl_entries_data_%d` AS `discussion` ON comment.entry_id = discussion.entry_id\n\t\t\t\t\t\tWHERE discussion.relation_id = %d\n\t\t\t\t\t\tORDER BY date.local ASC\n\t\t\t\t\t\tLIMIT %d, %d", self::findFieldID('comment', 'comments'), self::findFieldID('created-by', 'comments'), self::findFieldID('date', 'comments'), self::findFieldID('email-address', 'members'), self::findFieldID('parent-id', 'comments'), (int) $this->dsParamFILTERS['discussion_id'], max(0, ($this->dsParamSTARTPAGE - 1) * $this->dsParamLIMIT), (int) $this->dsParamLIMIT)); } catch (Exception $e) { $result->appendChild(new XMLElement('error', General::sanitize(vsprintf('%d: %s on query %s', ASDCLoader::instance()->lastError())))); return $result; } if ($comments->length() == 0) { $this->__redirectToErrorPage(); } $total = ASDCLoader::instance()->query('SELECT FOUND_ROWS() AS `total`;')->current()->total; $result->prependChild(General::buildPaginationElement($total, ceil($total * (1 / $this->dsParamLIMIT)), $this->dsParamLIMIT, $this->dsParamSTARTPAGE)); foreach ($comments as $c) { /* stdClass Object ( [id] => 20589 [comment] => <p>blah blah</p> [member_id] => 2103 [username] => Alistair [date] => 1241576727 [email] => alistair@21degrees.com.au ) <entry id="20515"> <date time="01:32" weekday="3">2009-05-06</date> <comment word-count="6"><p>This site looks awesome guys! Congrats!</p></comment> <created-by id="2694">davethegr8</created-by> </entry> */ $entry = new XMLElement('entry', NULL, array('id' => $c->id)); $entry->appendChild(new XMLElement('created-by', General::sanitize($c->username), array('email-address-hash' => md5($c->email), 'email-address' => General::sanitize($c->email), 'id' => $c->member_id))); $entry->appendChild(General::createXMLDateObject($c->date, 'date')); $c->comment = str_replace(array('<script', '</script'), array('<script', '</script'), $c->comment); $entry->appendChild(new XMLElement('comment', trim($c->comment))); $result->appendChild($entry); } return $result; }
public function appendFormattedElement(DOMElement $wrapper, $data, $encode = false, $mode = NULL, Entry $entry = NULL) { if (isset($data->value) && !is_null($data->value)) { if ($mode == 'gmt') { $timestamp = strtotime($data->value); } else { $timestamp = DateTimeObj::toGMT($data->value); } $wrapper->appendChild(General::createXMLDateObject($wrapper->ownerDocument, $timestamp, $this->{'element-name'})); } }
public function appendFormattedElement(&$wrapper, $data, $encode = false) { if (empty($data)) { return; } if (!is_array($data['local'])) { $data['local'] = array($data['local']); } $list = new XMLElement($this->get('element_name')); sort($data['local'], SORT_NUMERIC); foreach ($data['local'] as $value) { $list->appendChild(General::createXMLDateObject($value, 'item')); } $wrapper->appendChild($list); }