/**
  * The generate functions outputs the correct headers for
  * this `XMLPage`, adds `$this->getHttpStatusCode()` code to the root attribute
  * before calling the parent generate function and generating
  * the `$this->_Result` XMLElement
  *
  * @param null $page
  * @return string
  */
 public function generate($page = null)
 {
     // Set the actual status code in the xml response
     $this->_Result->setAttribute('status', $this->getHttpStatusCode());
     parent::generate($page);
     return $this->_Result->generate(true);
 }
 public function view()
 {
     header('Content-Type: text/xml');
     $response = new XMLElement('response');
     $id = $_GET['id'];
     $version = Symphony::Configuration()->get('version', 'symphony');
     // remove text followed by numbers e.g. 2.3beta2 or 2.3rc1
     $version = preg_replace("/[a-z]+[0-9]+/i", '', $version);
     // remove text e.g. 2.3beta
     $version = preg_replace("/[a-z]+/i", '', $version);
     $symphony_version = self::normaliseVersionNumber($version);
     $response->setAttribute('symphony-version', $symphony_version);
     if (empty($id)) {
         $response->setAttribute('error', '404');
         echo $response->generate();
         die;
     }
     $ch = curl_init();
     curl_setopt($ch, CURLOPT_URL, sprintf('http://symphonyextensions.com/api/extensions/%s/', $id));
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     curl_setopt($ch, CURLOPT_USERAGENT, 'extension_status; Symphony ' . Symphony::Configuration()->get('version', 'symphony'));
     curl_setopt($ch, CURLOPT_REFERER, URL);
     $xml = curl_exec($ch);
     if (!$xml) {
         $response->setAttribute('error', '404');
         echo $response->generate();
         die;
     }
     $extension = simplexml_load_string($xml);
     $compatibility = $extension->xpath("//compatibility/symphony[@version='" . $symphony_version . "']");
     $extensions = ExtensionManager::fetch();
     $current_version = $extensions[$id]['version'];
     $response->setAttribute('current-local-version', $current_version);
     if (count($compatibility) == 0) {
         $response->setAttribute('compatible-version-exists', 'no');
     } else {
         $latest_version = $compatibility[0]->attributes()->use;
         $github_url = $extension->xpath("//link[@rel='github:page']/@href");
         $extension_url = $extension->xpath("//link[@rel='site:extension']/@href");
         $response->setAttribute('compatible-version-exists', 'yes');
         $response->setAttribute('latest-url', (string) $github_url[0] . '/tree/' . $latest_version);
         $response->setAttribute('latest', $latest_version);
         $response->setAttribute('can-update', version_compare($latest_version, $current_version, '>') ? 'yes' : 'no');
         $response->setAttribute('extension-url', 'http://symphonyextensions.com' . (string) $extension_url[0]);
     }
     echo $response->generate();
     die;
 }
Beispiel #3
0
 public function transform($data)
 {
     $txtElement = new XMLElement('data');
     $txtElement->setValue(General::wrapInCDATA($data));
     $data = $txtElement->generate();
     return $data;
 }
 public function getXPath($entry)
 {
     $entry_xml = new XMLElement('entry');
     $section_id = $entry->_fields['section_id'];
     $data = $entry->getData();
     $fields = array();
     $entry_xml->setAttribute('id', $entry->get('id'));
     $associated = $entry->fetchAllAssociatedEntryCounts();
     if (is_array($associated) and !empty($associated)) {
         foreach ($associated as $section => $count) {
             $handle = $this->_Parent->Database->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t");
             $entry_xml->setAttribute($handle, (string) $count);
         }
     }
     // Add fields:
     foreach ($data as $field_id => $values) {
         if (empty($field_id)) {
             continue;
         }
         $field =& $entry->_Parent->fieldManager->fetch($field_id);
         $field->appendFormattedElement($entry_xml, $values, false);
     }
     $xml = new XMLElement('data');
     $xml->appendChild($entry_xml);
     $dom = new DOMDocument();
     $dom->loadXML($xml->generate(true));
     return new DOMXPath($dom);
 }
 public function getXPath($entry)
 {
     $fieldManager = new FieldManager(Symphony::Engine());
     $entry_xml = new XMLElement('entry');
     $section_id = $entry->get('section_id');
     $data = $entry->getData();
     $fields = array();
     $entry_xml->setAttribute('id', $entry->get('id'));
     $associated = $entry->fetchAllAssociatedEntryCounts();
     if (is_array($associated) and !empty($associated)) {
         foreach ($associated as $section => $count) {
             $handle = Symphony::Database()->fetchVar('handle', 0, "\n\t\t\t\t\t\tSELECT\n\t\t\t\t\t\t\ts.handle\n\t\t\t\t\t\tFROM\n\t\t\t\t\t\t\t`tbl_sections` AS s\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\ts.id = '{$section}'\n\t\t\t\t\t\tLIMIT 1\n\t\t\t\t\t");
             $entry_xml->setAttribute($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);
     }
     $xml = new XMLElement('data');
     $xml->appendChild($entry_xml);
     $dom = new DOMDocument();
     $dom->strictErrorChecking = false;
     $dom->loadXML($xml->generate(true));
     $xpath = new DOMXPath($dom);
     if (version_compare(phpversion(), '5.3', '>=')) {
         $xpath->registerPhpFunctions();
     }
     return $xpath;
 }
 function notify($context)
 {
     var_dump($context);
     include_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init();
     $ch->setopt('URL', 'http://rpc.pingomatic.com/');
     $ch->setopt('POST', 1);
     $ch->setopt('CONTENTTYPE', 'text/xml');
     $ch->setopt('HTTPVERSION', '1.0');
     ##Create the XML request
     $xml = new XMLElement('methodCall');
     $xml->appendChild(new XMLElement('methodName', 'weblogUpdates.ping'));
     $params = new XMLElement('params');
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', $this->_Parent->Configuration->get('sitename', 'general')));
     $params->appendChild($param);
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', URL));
     $params->appendChild($param);
     $xml->appendChild($params);
     ####
     $ch->setopt('POSTFIELDS', $xml->generate(true, 0));
     //Attempt the ping
     $ch->exec(GATEWAY_FORCE_SOCKET);
 }
    public static function documentation()
    {
        // Fetch all the Email Templates available and add to the end of the documentation
        $templates = extension_Members::fetchEmailTemplates();
        $div = new XMLElement('div');
        if (!empty($templates)) {
            $label = new XMLElement('label', __('Regenerate Activation Code Email Template'));
            $regenerate_activation_code_templates = extension_Members::setActiveTemplate($templates, 'regenerate-activation-code-template');
            $label->appendChild(Widget::Select('members[regenerate-activation-code-template][]', $regenerate_activation_code_templates, array('multiple' => 'multiple')));
            $div->appendChild($label);
            $div->appendChild(Widget::Input('members[event]', 'reset-password', 'hidden'));
            $div->appendChild(Widget::Input(null, __('Save Changes'), 'submit', array('accesskey' => 's')));
        }
        return '
				<p>This event will regenerate an activation code for a user and is useful if their current
				activation code has expired. The activation code can be sent to a Member\'s email after
				this event has executed.</p>
				<h3>Example Front-end Form Markup</h3>
				<p>This is an example of the form markup you can use on your front end. An input field
				accepts either the member\'s email address or username.</p>
				<pre class="XML"><code>
				&lt;form method="post"&gt;
					&lt;label&gt;Username: &lt;input name="fields[username]" type="text" value="{$username}"/&gt;&lt;/label&gt;
					or
					&lt;label&gt;Email: &lt;input name="fields[email]" type="text" value="{$email}"/&gt;&lt;/label&gt;
					&lt;input type="submit" name="action[' . self::ROOTELEMENT . ']" value="Regenerate Activation Code"/&gt;
					&lt;input type="hidden" name="redirect" value="{$root}/"/&gt;
				&lt;/form&gt;
				</code></pre>
				<h3>More Information</h3>
				<p>For further information about this event, including response and error XML, please refer to the
				<a href="https://github.com/symphonycms/members/wiki/Members%3A-Regenerate-Activation-Code">wiki</a>.</p>
				' . $div->generate() . '
			';
    }
 public function prepareTableValue($data, XMLElement $link = NULL)
 {
     $value = $data['value'];
     if ($link) {
         $link->setValue($value);
         return $link->generate();
     } else {
         return $value;
     }
 }
    public static function documentation()
    {
        // Fetch all the Email Templates available and add to the end of the documentation
        $templates = extension_Members::fetchEmailTemplates();
        $div = new XMLElement('div');
        if (!empty($templates)) {
            //Template
            $label = new XMLElement('label', __('Reset Password Email Template'));
            $reset_password_templates = extension_Members::setActiveTemplate($templates, 'reset-password-template');
            $label->appendChild(Widget::Select('members[reset-password-template][]', $reset_password_templates, array('multiple' => 'multiple')));
            $div->appendChild($label);
        }
        // Auto Login
        $div->appendChild(Widget::Input("members[auto-login]", 'no', 'hidden'));
        $label = new XMLElement('label');
        $input = Widget::Input("members[auto-login]", 'yes', 'checkbox');
        if (extension_Members::getSetting('reset-password-auto-login') == 'yes') {
            $input->setAttribute('checked', 'checked');
        }
        $label->setValue(__('%s Automatically log the member in after changing their password', array($input->generate())));
        $div->appendChild($label);
        $div->appendChild(Widget::Input('members[event]', 'reset-password', 'hidden'));
        $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
        return '
				<p>This event requires the user to enter their recovery code and then their new password. Should the recovery code
				be correct and the new password validate, the member\'s password will be changed to their new password.</p><p>
				A recovery code is available by including the
				Member: Password field in a data source on the same page as this event, or by using
				the event\'s result.</p>
				<h3>Example Front-end Form Markup</h3>
				<p>This is an example of the form markup you can use on your front end. An input field
				accepts the member\'s recovery code, either the member\'s email address or username and two password
				fields (one for password, one to confirm) will allow the member to change their password.</p>
				<pre class="XML"><code>
				&lt;form method="post"&gt;
					&lt;label&gt;Username: &lt;input name="fields[username]" type="text" value="{$username}"/&gt;&lt;/label&gt;
					or
					&lt;label&gt;Email: &lt;input name="fields[email]" type="text" value="{$email}"/&gt;&lt;/label&gt;
					&lt;label&gt;Recovery Code: &lt;input name="fields[password][recovery-code]" type="text" value="{$code}"/&gt;&lt;/label&gt;
					&lt;label&gt;Password: &lt;input name="fields[password][password]" type="password" /&gt;&lt;/label&gt;
					&lt;label&gt;Confirm Password: &lt;input name="fields[password][confirm]" type="password" /&gt;&lt;/label&gt;
					&lt;input type="hidden" name="members-section-id" value="{$your-section-id}"/&gt;
					&lt;input type="submit" name="action[' . self::ROOTELEMENT . ']" value="Recover Account"/&gt;
					&lt;input type="hidden" name="redirect" value="{$root}/"/&gt;
				&lt;/form&gt;
				</code></pre>
				<h3>More Information</h3>
				<p>For further information about this event, including response and error XML, please refer to the
				<a href="https://github.com/symphonycms/members/wiki/Members%3A-Reset-Password">wiki</a>.</p>
				' . $div->generate() . '
			';
    }
 function grab($param = array())
 {
     extract($this->_env, EXTR_PREFIX_ALL, 'env');
     include_once TOOLKIT . '/class.entrymanager.php';
     $entryManager = new EntryManager($this->_parent);
     $section_id = $entryManager->fetchSectionIDFromHandle($this->__resolveDefine("dsFilterPARENTSECTION"));
     $schema = $entryManager->fetchEntryFieldSchema($section_id, NULL, $this->_dsFilterCUSTOMFIELD);
     $schema = $schema[0];
     ##Check the cache
     $hash_id = md5(get_class($this));
     if ($param['caching'] && ($cache = $this->check_cache($hash_id))) {
         return $cache;
         exit;
     }
     ##------------------------------
     ##Create the XML container
     $xml = new XMLElement("categories-list");
     $xml->setAttribute("section", "customfield");
     ##Populate the XML
     if (empty($schema) || !is_array($schema)) {
         $xml->addChild(new XMLElement("error", "No Records Found."));
         return $xml;
     } else {
         $ops = preg_split('/,/', $schema['values'], -1, PREG_SPLIT_NO_EMPTY);
         $ops = array_map("trim", $ops);
         $xml->addChild(new XMLElement("name", $schema['name']));
         $xml->setAttribute("handle", $schema['handle']);
         $options = new XMLElement("options");
         foreach ($ops as $o) {
             if ($schema['type'] == 'multiselect') {
                 $table = 'tbl_entries2customfields_list';
             } else {
                 $table = 'tbl_entries2customfields';
             }
             $count = $this->_db->fetchVar('count', 0, "SELECT count(id) AS `count` FROM `{$table}` WHERE `field_id` = '" . $schema['id'] . "' AND value_raw = '{$o}' ");
             $xO = new XMLElement("option", $o);
             $xO->setAttribute('entry-count', $count);
             $xO->setAttribute('handle', Lang::createHandle($o, $this->_parent->getConfigVar('handle_length', 'admin')));
             $options->addChild($xO);
         }
         $xml->addChild($options);
     }
     ##------------------------------
     ##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;
 }
 function preview()
 {
     $xml = new XMLElement("post-comment");
     $xml->addChild(new XMLElement("notice", "Missing Author Name"));
     $code = $xml->generate(true);
     $xml = new XMLElement("post-comment");
     $cookie = new XMLElement("cookie");
     $cookie->addChild(new XMLElement("name", "fred"));
     $cookie->addChild(new XMLElement("email", "*****@*****.**"));
     $cookie->addChild(new XMLElement("url", "http://www.fred.com"));
     $xml->addChild($cookie);
     $code .= CRLF . $xml->generate(true);
     return $code;
 }
Beispiel #12
0
 function view()
 {
     $vimeo_videos = array();
     $mode = 'view';
     if (isset($_POST['update'])) {
         $mode = 'update';
     }
     try {
         $vimeo_fields = $this->Database()->query("SELECT field_id FROM tbl_fields_vimeo_video");
         foreach ($vimeo_fields as $field) {
             $videos = $this->Database()->query(sprintf("SELECT entry_id, clip_id, title, caption, plays, user_name, user_url, thumbnail_url FROM tbl_entries_data_%d", $field->field_id));
             foreach ($videos as $video) {
                 if ($mode == 'update') {
                     VimeoHelper::updateClipInfo($video->clip_id, $field->field_id, $video->entry_id, $this->Database());
                 } else {
                     array_push($vimeo_videos, $video);
                 }
             }
         }
     } catch (Exception $e) {
         print_r($this->Database()->lastError());
         die;
     }
     if ($mode == 'update') {
         header('location: ' . URL . '/symphony/extension/vimeo_videos/videos/');
     }
     usort($vimeo_videos, array($this, 'comparePlays'));
     $this->setPageType('table');
     $this->addStylesheetToHead(URL . '/extensions/vimeo_videos/assets/vimeo_video.css', 'screen', 190);
     $update = new XMLElement('span', '<input type="submit" value="Update video info" name="update" />');
     $update->setAttribute('id', 'update');
     $heading = new XMLElement('h2', $update->generate() . 'Vimeo Videos (ordered by most plays)');
     $this->Form->appendChild($heading);
     $aTableHead = array(array('', 'col'), array('Plays', 'col'), array('Description', 'col'), array('User', 'col'));
     $aTableBody = array();
     if (count($vimeo_videos) == 0) {
         $aTableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', NULL, count($aTableHead)))));
     } else {
         foreach ($vimeo_videos as $video) {
             $thumbnail = Widget::TableData(Widget::Anchor('<img src="' . URL . '/image/2/75/75/5/1/' . str_replace('http://', '', $video->thumbnail_url) . '" alt="' . $video->title . '" width="75" height="75"/>', "http://vimeo.com/{$video->clip_id}/", 'View video'));
             $description = Widget::TableData("<strong>" . $video->title . "</strong><br />" . $video->caption);
             $user = Widget::TableData(Widget::Anchor($video->user_name, $video->user_url, 'View user profile'));
             $plays = Widget::TableData($video->plays);
             $aTableBody[] = Widget::TableRow(array($thumbnail, $plays, $description, $user));
         }
     }
     $table = Widget::Table(Widget::TableHead($aTableHead), NULL, Widget::TableBody($aTableBody));
     $this->Form->appendChild($table);
 }
    public static function documentation()
    {
        // Fetch all the Email Templates available and add to the end of the documentation
        $templates = extension_Members::fetchEmailTemplates();
        $div = new XMLElement('div');
        if (!empty($templates)) {
            // Template
            $label = new XMLElement('label', __('Activate Account Email Template'));
            $activate_account_templates = extension_Members::setActiveTemplate($templates, 'activate-account-template');
            $label->appendChild(Widget::Select('members[activate-account-template][]', $activate_account_templates, array('multiple' => 'multiple')));
            $div->appendChild($label);
        }
        // Auto Login
        $div->appendChild(Widget::Input("members[auto-login]", 'no', 'hidden'));
        $label = new XMLElement('label');
        $input = Widget::Input("members[auto-login]", 'yes', 'checkbox');
        if (extension_Members::getSetting('activate-account-auto-login') == 'yes') {
            $input->setAttribute('checked', 'checked');
        }
        $label->setValue(__('%s Automatically log the member in after activation', array($input->generate())));
        $div->appendChild($label);
        // Add Save Changes
        $div->appendChild(Widget::Input('members[event]', 'activate-account', 'hidden'));
        $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
        return '
				<p>This event takes an activation code and an identifier for the Member (either Email or Username) to activate their account.
				An activation code is available by including the Members: Activation field in a data source on the same page as this event, or by using
				the event\'s result.</p>
				<h3>Example Front-end Form Markup</h3>
				<p>This is an example of the form markup you can use on your front end. An input field
				accepts the member\'s activation code and either the member\'s email address or username.</p>
				<pre class="XML"><code>
				&lt;form method="post"&gt;
					&lt;label&gt;Username: &lt;input name="fields[username]" type="text" value="{$username}"/&gt;&lt;/label&gt;
					or
					&lt;label&gt;Email: &lt;input name="fields[email]" type="text" value="{$email}"/&gt;&lt;/label&gt;
					&lt;label&gt;Activation: &lt;input name="fields[activation]" type="text" value="{$code}"/&gt;&lt;/label&gt;
					&lt;input type="hidden" name="members-section-id" value="{$your-section-id}"/&gt;
					&lt;input type="submit" name="action[' . self::ROOTELEMENT . ']" value="Activate Account"/&gt;
					&lt;input type="hidden" name="redirect" value="{$root}/"/&gt;
				&lt;/form&gt;
				</code></pre>
				<h3>More Information</h3>
				<p>For further information about this event, including response and error XML, please refer to the
				<a href="https://github.com/symphonycms/members/wiki/Members%3A-Activate-Account">wiki</a>.</p>
				' . $div->generate() . '
			';
    }
Beispiel #14
0
 /**
  * The generate functions outputs the correct headers for
  * this AJAXPage, adds `$this->_status` code to the root attribute
  * before calling the parent generate function and generating
  * the `$this->_Result` XMLElement
  *
  * @return string
  */
 public function generate()
 {
     switch ($this->_status) {
         case self::STATUS_OK:
             $status_message = '200 OK';
             break;
         case self::STATUS_BAD:
         case self::STATUS_ERROR:
             $status_message = '400 Bad Request';
             break;
         case self::STATUS_UNAUTHORISED:
             $status_message = '401 Unauthorized';
             break;
     }
     $this->addHeaderToPage('HTTP/1.0 ' . $status_message);
     $this->_Result->setAttribute('status', $this->_status);
     parent::generate();
     return $this->_Result->generate(true);
 }
 public function notify($context)
 {
     include_once TOOLKIT . '/class.gateway.php';
     $ch = new Gateway();
     $ch->init();
     $ch->setopt('URL', 'http://rpc.pingomatic.com/');
     $ch->setopt('POST', 1);
     $ch->setopt('CONTENTTYPE', 'text/xml');
     $xml = new XMLElement('methodCall');
     $xml->appendChild(new XMLElement('methodName', 'weblogUpdates.ping'));
     $params = new XMLElement('params');
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', Symphony::Configuration()->get('sitename', 'general')));
     $params->appendChild($param);
     $param = new XMLElement('param');
     $param->appendChild(new XMLElement('value', URL));
     $params->appendChild($param);
     $xml->appendChild($params);
     $ch->setopt('POSTFIELDS', $xml->generate(true, 0));
     $ch->exec(GATEWAY_FORCE_SOCKET);
 }
    public static function documentation()
    {
        // Fetch all the Email Templates available and add to the end of the documentation
        $templates = extension_Members::fetchEmailTemplates();
        $div = new XMLElement('div');
        if (!empty($templates)) {
            $label = new XMLElement('label', __('Generate Recovery Code Email Template'));
            $generate_recovery_code_templates = extension_Members::setActiveTemplate($templates, 'generate-recovery-code-template');
            $label->appendChild(Widget::Select('members[generate-recovery-code-template][]', $generate_recovery_code_templates, array('multiple' => 'multiple')));
            $div->appendChild($label);
            $div->appendChild(Widget::Input('members[event]', 'generate-recovery-code', 'hidden'));
            $div->appendChild(Widget::Input('action[save]', __('Save Changes'), 'submit', array('accesskey' => 's')));
        }
        return '
				<p>This event takes a member\'s email address or username to validate the existence of the Member before
				generating a recovery code for that member. A member\'s password is not completely reset until their 
				recovery code is used in the Members: Reset Password event. This recovery code can be seen
				by including the Member: Password field in a data source on the same page as this event, or by using
				the event\'s result.</p>
				<h3>Example Front-end Form Markup</h3>
				<p>This is an example of the markup you can use on your front end to create a form for this event. An input field
				accepts either the member\'s email address or username.</p>
				<pre class="XML"><code>
				&lt;form method="post"&gt;
					&lt;label&gt;Username: &lt;input name="fields[username]" type="text" value="{$username}"/&gt;&lt;/label&gt;
					or
					&lt;label&gt;Email: &lt;input name="fields[email]" type="text" value="{$email}"/&gt;&lt;/label&gt;
					&lt;input type="hidden" name="members-section-id" value="{$your-section-id}"/&gt;
					&lt;input type="submit" name="action[' . self::ROOTELEMENT . ']" value="Reset Password"/&gt;
					&lt;input type="hidden" name="redirect" value="{$root}/"/&gt;
				&lt;/form&gt;
				</code></pre>
				<h3>More Information</h3>
				<p>For further information about this event, including response and error XML, please refer to the
				<a href="https://github.com/symphonycms/members/wiki/Members%3A-Generate-Recovery-Code">wiki</a>.</p>
				' . $div->generate() . '
			';
    }
 /**
  * Constructor for SymphonyErrorPage sets it's class variables
  *
  * @param string|XMLElement $message
  *  A description for this error, which can be provided as a string
  *  or as an XMLElement.
  * @param string $heading
  *  A heading for the error page, by default this is "Symphony Fatal Error"
  * @param string $template
  *  A string for the error page template to use, defaults to 'generic'. This
  *  can be the name of any template file in the `TEMPLATES` directory.
  *  A template using the naming convention of `tpl.*.php`.
  * @param array $additional
  *  Allows custom information to be passed to the Symphony Error Page
  *  that the template may want to expose, such as custom Headers etc.
  * @param integer $status
  *  Properly sets the HTTP status code for the response. Defaults to
  *  `Page::HTTP_STATUS_ERROR`
  */
 public function __construct($message, $heading = 'Symphony Fatal Error', $template = 'generic', array $additional = array(), $status = Page::HTTP_STATUS_ERROR)
 {
     if ($message instanceof XMLElement) {
         $this->_messageObject = $message;
         $message = $this->_messageObject->generate();
     }
     parent::__construct($message);
     $this->_heading = $heading;
     $this->_template = $template;
     $this->_additional = (object) $additional;
     $this->_status = $status;
 }
Beispiel #18
0
 public function prepareTableValue($data, XMLElement $link = NULL)
 {
     $max_length = $this->_engine->Configuration->get('cell_truncation_length', 'symphony');
     $max_length = $max_length ? $max_length : 75;
     $value = strip_tags($data['value']);
     $value = strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '...';
     if (strlen($value) == 0) {
         $value = __('None');
     }
     if ($link) {
         $link->setValue($value);
         return $link->generate();
     }
     return $value;
 }
 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     // When DS is called out of the Frontend context, this will enable
     // {$root} and {$workspace} parameters to be evaluated
     if (empty($this->_env)) {
         $this->_env['env']['pool'] = array('root' => URL, 'workspace' => WORKSPACE);
     }
     try {
         require_once TOOLKIT . '/class.gateway.php';
         require_once TOOLKIT . '/class.xsltprocess.php';
         require_once CORE . '/class.cacheable.php';
         $this->dsParamURL = $this->parseParamURL($this->dsParamURL);
         if (isset($this->dsParamXPATH)) {
             $this->dsParamXPATH = $this->__processParametersInString(stripslashes($this->dsParamXPATH), $this->_env);
         }
         // Builds a Default Stylesheet to transform the resulting XML with
         $stylesheet = new XMLElement('xsl:stylesheet');
         $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'));
         $output = new XMLElement('xsl:output');
         $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
         $stylesheet->appendChild($output);
         $template = new XMLElement('xsl:template');
         $template->setAttribute('match', '/');
         $instruction = new XMLElement('xsl:copy-of');
         // Namespaces
         if (isset($this->dsParamNAMESPACES) && is_array($this->dsParamNAMESPACES)) {
             foreach ($this->dsParamNAMESPACES as $name => $uri) {
                 $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri);
             }
         }
         // XPath
         $instruction->setAttribute('select', $this->dsParamXPATH);
         $template->appendChild($instruction);
         $stylesheet->appendChild($template);
         $stylesheet->setIncludeHeader(true);
         $xsl = $stylesheet->generate(true);
         // Check for an existing Cache for this Datasource
         $cache_id = self::buildCacheID($this);
         $cache = Symphony::ExtensionManager()->getCacheProvider('remotedatasource');
         $cachedData = $cache->check($cache_id);
         $writeToCache = null;
         $isCacheValid = true;
         $creation = DateTimeObj::get('c');
         // Execute if the cache doesn't exist, or if it is old.
         if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
             if (Mutex::acquire($cache_id, $this->dsParamTIMEOUT, TMP)) {
                 $ch = new Gateway();
                 $ch->init($this->dsParamURL);
                 $ch->setopt('TIMEOUT', $this->dsParamTIMEOUT);
                 // Set the approtiate Accept: headers depending on the format of the URL.
                 if ($this->dsParamFORMAT == 'xml') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*'));
                 } elseif ($this->dsParamFORMAT == 'json') {
                     $ch->setopt('HTTPHEADER', array('Accept: application/json, */*'));
                 } elseif ($this->dsParamFORMAT == 'csv') {
                     $ch->setopt('HTTPHEADER', array('Accept: text/csv, */*'));
                 }
                 self::prepareGateway($ch);
                 $data = $ch->exec();
                 $info = $ch->getInfoLast();
                 Mutex::release($cache_id, TMP);
                 $data = trim($data);
                 $writeToCache = true;
                 // Handle any response that is not a 200, or the content type does not include XML, JSON, plain or text
                 if ((int) $info['http_code'] != 200 || !preg_match('/(xml|json|csv|plain|text)/i', $info['content_type'])) {
                     $writeToCache = false;
                     $result->setAttribute('valid', 'false');
                     // 28 is CURLE_OPERATION_TIMEOUTED
                     if ($info['curl_error'] == 28) {
                         $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout)));
                     } else {
                         $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type'])));
                     }
                     return $result;
                 } else {
                     if (strlen($data) > 0) {
                         // Handle where there is `$data`
                         // If it's JSON, convert it to XML
                         if ($this->dsParamFORMAT == 'json') {
                             try {
                                 require_once TOOLKIT . '/class.json.php';
                                 $data = JSON::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'csv') {
                             try {
                                 require_once EXTENSIONS . '/remote_datasource/lib/class.csv.php';
                                 $data = CSV::convertToXML($data);
                             } catch (Exception $ex) {
                                 $writeToCache = false;
                                 $errors = array(array('message' => $ex->getMessage()));
                             }
                         } elseif ($this->dsParamFORMAT == 'txt') {
                             $txtElement = new XMLElement('entry');
                             $txtElement->setValue(General::wrapInCDATA($data));
                             $data = $txtElement->generate();
                             $txtElement = null;
                         } else {
                             if (!General::validateXML($data, $errors, false, new XsltProcess())) {
                                 // If the XML doesn't validate..
                                 $writeToCache = false;
                             }
                         }
                         // If the `$data` is invalid, return a result explaining why
                         if ($writeToCache === false) {
                             $error = new XMLElement('errors');
                             $error->setAttribute('valid', 'false');
                             $error->appendChild(new XMLElement('error', __('Data returned is invalid.')));
                             foreach ($errors as $e) {
                                 if (strlen(trim($e['message'])) == 0) {
                                     continue;
                                 }
                                 $error->appendChild(new XMLElement('item', General::sanitize($e['message'])));
                             }
                             $result->appendChild($error);
                             return $result;
                         }
                     } elseif (strlen($data) == 0) {
                         // If `$data` is empty, set the `force_empty_result` to true.
                         $this->_force_empty_result = true;
                     }
                 }
             } else {
                 // Failed to acquire a lock
                 $result->appendChild(new XMLElement('error', __('The %s class failed to acquire a lock.', array('<code>Mutex</code>'))));
             }
         } else {
             // The cache is good, use it!
             $data = trim($cachedData['data']);
             $creation = DateTimeObj::get('c', $cachedData['creation']);
         }
         // Visit the data
         $this->exposeData($data);
         // If `$writeToCache` is set to false, invalidate the old cache if it existed.
         if (is_array($cachedData) && !empty($cachedData) && $writeToCache === false) {
             $data = trim($cachedData['data']);
             $isCacheValid = false;
             $creation = DateTimeObj::get('c', $cachedData['creation']);
             if (empty($data)) {
                 $this->_force_empty_result = true;
             }
         }
         // If `force_empty_result` is false and `$result` is an instance of
         // XMLElement, build the `$result`.
         if (!$this->_force_empty_result && is_object($result)) {
             $proc = new XsltProcess();
             $ret = $proc->process($data, $xsl);
             if ($proc->isErrors()) {
                 $result->setAttribute('valid', 'false');
                 $error = new XMLElement('error', __('Transformed XML is invalid.'));
                 $result->appendChild($error);
                 $errors = new XMLElement('errors');
                 foreach ($proc->getError() as $e) {
                     if (strlen(trim($e['message'])) == 0) {
                         continue;
                     }
                     $errors->appendChild(new XMLElement('item', General::sanitize($e['message'])));
                 }
                 $result->appendChild($errors);
                 $result->appendChild(new XMLElement('raw-data', General::wrapInCDATA($data)));
             } elseif (strlen(trim($ret)) == 0) {
                 $this->_force_empty_result = true;
             } else {
                 if ($this->dsParamCACHE > 0 && $writeToCache) {
                     $cache->write($cache_id, $data, $this->dsParamCACHE);
                 }
                 $result->setValue(PHP_EOL . str_repeat("\t", 2) . preg_replace('/([\\r\\n]+)/', "\$1\t", $ret));
                 $result->setAttribute('status', $isCacheValid === true ? 'fresh' : 'stale');
                 $result->setAttribute('cache-id', $cache_id);
                 $result->setAttribute('creation', $creation);
             }
         }
     } catch (Exception $e) {
         $result->appendChild(new XMLElement('error', $e->getMessage()));
     }
     if ($this->_force_empty_result) {
         $result = $this->emptyXMLSet();
     }
     $result->setAttribute('url', General::sanitize($this->dsParamURL));
     return $result;
 }
$output = new XMLElement('xsl:output');
$output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
$stylesheet->appendChild($output);
$template = new XMLElement('xsl:template');
$template->setAttribute('match', '/');
$instruction = new XMLElement('xsl:copy-of');
## Namespaces
foreach ($this->dsParamFILTERS as $name => $uri) {
    $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : NULL), $uri);
}
## XPath
$instruction->setAttribute('select', $this->dsParamXPATH);
$template->appendChild($instruction);
$stylesheet->appendChild($template);
$stylesheet->setIncludeHeader(true);
$xsl = $stylesheet->generate(true);
$proc =& new XsltProcess();
$cache_id = md5($this->dsParamURL . serialize($this->dsParamFILTERS) . $this->dsParamXPATH);
$cache = new Cacheable($this->_Parent->Database);
$cachedData = $cache->check($cache_id);
$writeToCache = false;
$valid = true;
$result = NULL;
$creation = DateTimeObj::get('c');
if (!$cachedData || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
    if (Mutex::acquire($cache_id, 6, TMP)) {
        $ch = new Gateway();
        $ch->init();
        $ch->setopt('URL', $this->dsParamURL);
        $ch->setopt('TIMEOUT', 6);
        $xml = $ch->exec();
        global $languages;
        $Page->setTemplateVar('languages', $languages);
    }
}
$Log = new SymphonyLog('install-log.txt');
$Page = new Page($Log);
$Page->setHeader(kHEADER);
$Page->setFooter(kFOOTER);
$Contents = new XMLElement('body');
$Contents->appendChild(new XMLElement('h1', '<!-- TITLE --> <em><!-- TAGLINE --></em> <em><!-- LANGUAGES --></em>'));
if (defined('__IS_UPDATE__') && __IS_UPDATE__ == true) {
    $Page->setPage('update');
} elseif (defined('__ALREADY_UP_TO_DATE__') && __ALREADY_UP_TO_DATE__ == true) {
    $Page->setPage('uptodate');
} else {
    $Page->setPage('index');
    Action::requirements($Page);
}
if (is_array($Page->missing) && !empty($Page->missing)) {
    $Page->setPage('requirements');
} elseif (isset($_POST['action'])) {
    $action = array_keys($_POST['action']);
    $action = $action[0];
    call_user_func_array(array('Action', $action), array(&$Page, $fields));
}
call_user_func_array(array('Display', $Page->getPage()), array(&$Page, &$Contents, $fields));
$Page->setContent($Contents->generate(true, 2));
$output = $Page->display();
header('Content-Type: text/html; charset=UTF-8');
header(sprintf('Content-Length: %d', strlen($output)));
echo $output;
    public function __formAction()
    {
        $fields = $_POST['fields'];
        $this->_errors = array();
        if (trim($fields['name']) == '') {
            $this->_errors['name'] = __('This is a required field');
        }
        if (trim($fields['source']) == '') {
            $this->_errors['source'] = __('This is a required field');
        }
        $filters = is_array($fields['filters']) ? $fields['filters'] : array();
        $classname = Lang::createHandle($fields['name'], NULL, '_', false, true, array('@^[^a-z]+@i' => '', '/[^\\w-\\.]/i' => ''));
        $rootelement = str_replace('_', '-', $classname);
        $file = EVENTS . '/event.' . $classname . '.php';
        $isDuplicate = false;
        $queueForDeletion = NULL;
        if ($this->_context[0] == 'new' && is_file($file)) {
            $isDuplicate = true;
        } elseif ($this->_context[0] == 'edit') {
            $existing_handle = $this->_context[1];
            if ($classname != $existing_handle && is_file($file)) {
                $isDuplicate = true;
            } elseif ($classname != $existing_handle) {
                $queueForDeletion = EVENTS . '/event.' . $existing_handle . '.php';
            }
        }
        ##Duplicate
        if ($isDuplicate) {
            $this->_errors['name'] = __('An Event with the name <code>%s</code> name already exists', array($classname));
        }
        if (empty($this->_errors)) {
            $multiple = in_array('expect-multiple', $filters);
            $eventShell = file_get_contents(TEMPLATE . '/event.tpl');
            $about = array('name' => $fields['name'], 'version' => '1.0', 'release date' => DateTimeObj::getGMT('c'), 'author name' => Administration::instance()->Author->getFullName(), 'author website' => URL, 'author email' => Administration::instance()->Author->get('email'), 'trigger condition' => $rootelement);
            $source = $fields['source'];
            $filter = NULL;
            $elements = NULL;
            $this->__injectAboutInformation($eventShell, $about);
            $this->__injectFilters($eventShell, $filters);
            $documentation = NULL;
            $documentation_parts = array();
            $documentation_parts[] = new XMLElement('h3', __('Success and Failure XML Examples'));
            $documentation_parts[] = new XMLElement('p', __('When saved successfully, the following XML will be returned:'));
            if ($multiple) {
                $code = new XMLElement($rootelement);
                $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'success', 'type' => 'create | edit'));
                $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
                $code->appendChild($entry);
            } else {
                $code = new XMLElement($rootelement, NULL, array('result' => 'success', 'type' => 'create | edit'));
                $code->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
            }
            $documentation_parts[] = self::processDocumentationCode($code);
            ###
            $documentation_parts[] = new XMLElement('p', __('When an error occurs during saving, due to either missing or invalid fields, the following XML will be returned') . ($multiple ? __(' (<b>Notice that it is possible to get mixtures of success and failure messages when using the "Allow Multiple" option</b>)') : NULL) . ':');
            if ($multiple) {
                $code = new XMLElement($rootelement);
                $entry = new XMLElement('entry', NULL, array('index' => '0', 'result' => 'error'));
                $entry->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
                $entry->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing')));
                $code->appendChild($entry);
                $entry = new XMLElement('entry', NULL, array('index' => '1', 'result' => 'success', 'type' => 'create | edit'));
                $entry->appendChild(new XMLElement('message', __('Entry [created | edited] successfully.')));
                $code->appendChild($entry);
            } else {
                $code = new XMLElement($rootelement, NULL, array('result' => 'error'));
                $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
                $code->appendChild(new XMLElement('field-name', NULL, array('type' => 'invalid | missing')));
            }
            $code->setValue('...', false);
            $documentation_parts[] = self::processDocumentationCode($code);
            ###
            if (is_array($filters) && !empty($filters)) {
                $documentation_parts[] = new XMLElement('p', __('The following is an example of what is returned if any options return an error:'));
                $code = new XMLElement($rootelement, NULL, array('result' => 'error'));
                $code->appendChild(new XMLElement('message', __('Entry encountered errors when saving.')));
                $code->appendChild(new XMLElement('filter', NULL, array('name' => 'admin-only', 'status' => 'failed')));
                $code->appendChild(new XMLElement('filter', __('Recipient not found'), array('name' => 'send-email', 'status' => 'failed')));
                $code->setValue('...', false);
                $documentation_parts[] = self::processDocumentationCode($code);
            }
            ###
            $documentation_parts[] = new XMLElement('h3', __('Example Front-end Form Markup'));
            $documentation_parts[] = new XMLElement('p', __('This is an example of the form markup you can use on your frontend:'));
            $container = new XMLElement('form', NULL, array('method' => 'post', 'action' => '', 'enctype' => 'multipart/form-data'));
            $container->appendChild(Widget::Input('MAX_FILE_SIZE', Symphony::Configuration()->get('max_upload_size', 'admin'), 'hidden'));
            $sectionManager = new SectionManager($this->_Parent);
            $section = $sectionManager->fetch($fields['source']);
            $section_fields = $section->fetchFields();
            if (is_array($section_fields) && !empty($section_fields)) {
                foreach ($section_fields as $f) {
                    if ($f->getExampleFormMarkup() instanceof XMLElement) {
                        $container->appendChild($f->getExampleFormMarkup());
                    }
                }
            }
            $container->appendChild(Widget::Input('action[' . $rootelement . ']', __('Submit'), 'submit'));
            $code = $container->generate(true);
            $documentation_parts[] = self::processDocumentationCode($multiple ? str_replace('fields[', 'fields[0][', $code) : $code);
            $documentation_parts[] = new XMLElement('p', __('To edit an existing entry, include the entry ID value of the entry in the form. This is best as a hidden field like so:'));
            $documentation_parts[] = self::processDocumentationCode(Widget::Input('id' . ($multiple ? '[0]' : NULL), 23, 'hidden'));
            $documentation_parts[] = new XMLElement('p', __('To redirect to a different location upon a successful save, include the redirect location in the form. This is best as a hidden field like so, where the value is the URL to redirect to:'));
            $documentation_parts[] = self::processDocumentationCode(Widget::Input('redirect', URL . '/success/', 'hidden'));
            if (in_array('send-email', $filters)) {
                $documentation_parts[] = new XMLElement('h3', __('Send Notification Email'));
                $documentation_parts[] = new XMLElement('p', __('Upon the event successfully saving the entry, this option takes input from the form and send an email to the desired recipient. <b>It currently does not work with "Allow Multiple".</b> The following are the recognised fields:'));
                $documentation_parts[] = self::processDocumentationCode('send-email[sender-email] // ' . __('Optional') . self::CRLF . 'send-email[sender-name] // ' . __('Optional') . self::CRLF . 'send-email[reply-to-email] // ' . __('Optional') . self::CRLF . 'send-email[reply-to-name] // ' . __('Optional') . self::CRLF . 'send-email[subject]' . self::CRLF . 'send-email[body]' . self::CRLF . 'send-email[recipient] // ' . __('list of comma-separated author usernames.'));
                $documentation_parts[] = new XMLElement('p', __('All of these fields can be set dynamically using the exact field name of another field in the form as shown below in the example form:'));
                $documentation_parts[] = self::processDocumentationCode('<form action="" method="post">
	<fieldset>
		<label>' . __('Name') . ' <input type="text" name="fields[author]" value="" /></label>
		<label>' . __('Email') . ' <input type="text" name="fields[email]" value="" /></label>
		<label>' . __('Message') . ' <textarea name="fields[message]" rows="5" cols="21"></textarea></label>
		<input name="send-email[sender-email]" value="fields[email]" type="hidden" />
		<input name="send-email[sender-name]" value="fields[author]" type="hidden" />
		<input name="send-email[reply-to-email]" value="fields[email]" type="hidden" />
		<input name="send-email[reply-to-name]" value="fields[author]" type="hidden" />
		<input name="send-email[subject]" value="You are being contacted" type="hidden" />
		<input name="send-email[body]" value="fields[message]" type="hidden" />
		<input name="send-email[recipient]" value="fred" type="hidden" />
		<input id="submit" type="submit" name="action[save-contact-form]" value="Send" />
	</fieldset>
</form>');
            }
            /**
             * Allows adding documentation for new filters. A reference to the $documentation
             * array is provided, along with selected filters
             * @delegate AppendEventFilterDocumentation
             * @param string $context
             * '/blueprints/events/(edit|new|info)/'
             * @param array $selected
             *  An array of all the selected filters for this Event
             * @param array $documentation
             *  An array of all the documentation XMLElements, passed by reference
             */
            Symphony::ExtensionManager()->notifyMembers('AppendEventFilterDocumentation', '/blueprints/events/' . $this->_context[0] . '/', array('selected' => $filters, 'documentation' => &$documentation_parts));
            $documentation = join(self::CRLF, array_map(create_function('$x', 'return rtrim($x->generate(true, 4));'), $documentation_parts));
            $documentation = str_replace('\'', '\\\'', $documentation);
            $eventShell = str_replace('<!-- CLASS NAME -->', $classname, $eventShell);
            $eventShell = str_replace('<!-- SOURCE -->', $source, $eventShell);
            $eventShell = str_replace('<!-- DOCUMENTATION -->', General::tabsToSpaces($documentation, 2), $eventShell);
            $eventShell = str_replace('<!-- ROOT ELEMENT -->', $rootelement, $eventShell);
            ## Remove left over placeholders
            $eventShell = preg_replace(array('/<!--[\\w ]++-->/'), '', $eventShell);
            if ($this->_context[0] == 'new') {
                /**
                 * Prior to creating an Event, the file path where it will be written to
                 * is provided and well as the contents of that file.
                 *
                 * @delegate EventsPreCreate
                 * @since Symphony 2.2
                 * @param string $context
                 * '/blueprints/events/'
                 * @param string $file
                 *  The path to the Event file
                 * @param string $contents
                 *  The contents for this Event as a string passed by reference
                 * @param array $filters
                 *  An array of the filters attached to this event
                 */
                Symphony::ExtensionManager()->notifyMembers('EventPreCreate', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters));
            } else {
                /**
                 * Prior to editing an Event, the file path where it will be written to
                 * is provided and well as the contents of that file.
                 *
                 * @delegate EventPreEdit
                 * @since Symphony 2.2
                 * @param string $context
                 * '/blueprints/events/'
                 * @param string $file
                 *  The path to the Event file
                 * @param string $contents
                 *  The contents for this Event as a string passed by reference
                 * @param array $filters
                 *  An array of the filters attached to this event
                 */
                Symphony::ExtensionManager()->notifyMembers('EventPreEdit', '/blueprints/events/', array('file' => $file, 'contents' => &$eventShell, 'filters' => $filters));
            }
            // Write the file
            if (!is_writable(dirname($file)) || !($write = General::writeFile($file, $eventShell, Symphony::Configuration()->get('write_mode', 'file')))) {
                $this->pageAlert(__('Failed to write Event to <code>%s</code>. Please check permissions.', array(EVENTS)), Alert::ERROR);
            } else {
                if ($queueForDeletion) {
                    General::deleteFile($queueForDeletion);
                    $sql = "SELECT * FROM `tbl_pages` WHERE `events` REGEXP '[[:<:]]" . $existing_handle . "[[:>:]]' ";
                    $pages = Symphony::Database()->fetch($sql);
                    if (is_array($pages) && !empty($pages)) {
                        foreach ($pages as $page) {
                            $page['events'] = preg_replace('/\\b' . $existing_handle . '\\b/i', $classname, $page['events']);
                            Symphony::Database()->update($page, 'tbl_pages', "`id` = '" . $page['id'] . "'");
                        }
                    }
                }
                if ($this->_context[0] == 'new') {
                    /**
                     * After creating the Event, the path to the Event file is provided
                     *
                     * @delegate EventPostCreate
                     * @since Symphony 2.2
                     * @param string $context
                     * '/blueprints/events/'
                     * @param string $file
                     *  The path to the Event file
                     */
                    Symphony::ExtensionManager()->notifyMembers('EventPostCreate', '/blueprints/events/', array('file' => $file));
                } else {
                    /**
                     * After editing the Event, the path to the Event file is provided
                     *
                     * @delegate EventPostEdit
                     * @since Symphony 2.2
                     * @param string $context
                     * '/blueprints/events/'
                     * @param string $file
                     *  The path to the Event file
                     */
                    Symphony::ExtensionManager()->notifyMembers('EventPostEdit', '/blueprints/events/', array('file' => $file));
                }
                redirect(SYMPHONY_URL . '/blueprints/events/edit/' . $classname . '/' . ($this->_context[0] == 'new' ? 'created' : 'saved') . '/');
            }
        }
    }
 public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
 {
     if (empty($data)) {
         return;
     }
     $img = sprintf("<img src='http://maps.google.com/maps/api/staticmap?zoom=6&size=160x90&sensor=false&markers=color:red|size:small|%s' alt=''/>", implode(',', array($data['latitude'], $data['longitude'])));
     if ($link) {
         $link->setValue($img);
         return $link->generate();
     }
     return $img;
 }
 /**
  * The generate function calls the `__build()` function before appending
  * all the current page's headers and then finally calling the `$Html's`
  * generate function which generates a HTML DOM from all the
  * XMLElement children.
  *
  * @param null $page
  * @return string
  */
 public function generate($page = null)
 {
     $this->__build();
     parent::generate($page);
     return $this->Html->generate(true);
 }
 public function execute(array &$param_pool = null)
 {
     $result = new XMLElement($this->dsParamROOTELEMENT);
     $this->dsParamURL = $this->parseParamURL($this->dsParamURL);
     if (isset($this->dsParamXPATH)) {
         $this->dsParamXPATH = $this->__processParametersInString($this->dsParamXPATH, $this->_env);
     }
     $stylesheet = new XMLElement('xsl:stylesheet');
     $stylesheet->setAttributeArray(array('version' => '1.0', 'xmlns:xsl' => 'http://www.w3.org/1999/XSL/Transform'));
     $output = new XMLElement('xsl:output');
     $output->setAttributeArray(array('method' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'indent' => 'yes', 'omit-xml-declaration' => 'yes'));
     $stylesheet->appendChild($output);
     $template = new XMLElement('xsl:template');
     $template->setAttribute('match', '/');
     $instruction = new XMLElement('xsl:copy-of');
     // Namespaces
     if (isset($this->dsParamFILTERS) && is_array($this->dsParamFILTERS)) {
         foreach ($this->dsParamFILTERS as $name => $uri) {
             $instruction->setAttribute('xmlns' . ($name ? ":{$name}" : null), $uri);
         }
     }
     // XPath
     $instruction->setAttribute('select', $this->dsParamXPATH);
     $template->appendChild($instruction);
     $stylesheet->appendChild($template);
     $stylesheet->setIncludeHeader(true);
     $xsl = $stylesheet->generate(true);
     $cache_id = md5($this->dsParamURL . serialize($this->dsParamFILTERS) . $this->dsParamXPATH);
     $cache = new Cacheable(Symphony::Database());
     $cachedData = $cache->read($cache_id);
     $writeToCache = false;
     $valid = true;
     $creation = DateTimeObj::get('c');
     $timeout = isset($this->dsParamTIMEOUT) ? (int) max(1, $this->dsParamTIMEOUT) : 6;
     // Execute if the cache doesn't exist, or if it is old.
     if (!is_array($cachedData) || empty($cachedData) || time() - $cachedData['creation'] > $this->dsParamCACHE * 60) {
         if (Mutex::acquire($cache_id, $timeout, TMP)) {
             $ch = new Gateway();
             $ch->init($this->dsParamURL);
             $ch->setopt('TIMEOUT', $timeout);
             $ch->setopt('HTTPHEADER', array('Accept: text/xml, */*'));
             $data = $ch->exec();
             $info = $ch->getInfoLast();
             Mutex::release($cache_id, TMP);
             $data = trim($data);
             $writeToCache = true;
             // Handle any response that is not a 200, or the content type does not include XML, plain or text
             if ((int) $info['http_code'] !== 200 || !preg_match('/(xml|plain|text)/i', $info['content_type'])) {
                 $writeToCache = false;
                 $result->setAttribute('valid', 'false');
                 // 28 is CURLE_OPERATION_TIMEOUTED
                 if ($info['curl_error'] == 28) {
                     $result->appendChild(new XMLElement('error', sprintf('Request timed out. %d second limit reached.', $timeout)));
                 } else {
                     $result->appendChild(new XMLElement('error', sprintf('Status code %d was returned. Content-type: %s', $info['http_code'], $info['content_type'])));
                 }
                 return $result;
                 // Handle where there is `$data`
             } elseif (strlen($data) > 0) {
                 // If the XML doesn't validate..
                 if (!General::validateXML($data, $errors, false, new XsltProcess())) {
                     $writeToCache = false;
                 }
                 // If the `$data` is invalid, return a result explaining why
                 if ($writeToCache === false) {
                     $element = new XMLElement('errors');
                     $result->setAttribute('valid', 'false');
                     $result->appendChild(new XMLElement('error', __('Data returned is invalid.')));
                     foreach ($errors as $e) {
                         if (strlen(trim($e['message'])) == 0) {
                             continue;
                         }
                         $element->appendChild(new XMLElement('item', General::sanitize($e['message'])));
                     }
                     $result->appendChild($element);
                     return $result;
                 }
                 // If `$data` is empty, set the `force_empty_result` to true.
             } elseif (strlen($data) == 0) {
                 $this->_force_empty_result = true;
             }
             // Failed to acquire a lock
         } else {
             $result->appendChild(new XMLElement('error', __('The %s class failed to acquire a lock, check that %s exists and is writable.', array('<code>Mutex</code>', '<code>' . TMP . '</code>'))));
         }
         // The cache is good, use it!
     } else {
         $data = trim($cachedData['data']);
         $creation = DateTimeObj::get('c', $cachedData['creation']);
     }
     // If `$writeToCache` is set to false, invalidate the old cache if it existed.
     if (is_array($cachedData) && !empty($cachedData) && $writeToCache === false) {
         $data = trim($cachedData['data']);
         $valid = false;
         $creation = DateTimeObj::get('c', $cachedData['creation']);
         if (empty($data)) {
             $this->_force_empty_result = true;
         }
     }
     // If `force_empty_result` is false and `$result` is an instance of
     // XMLElement, build the `$result`.
     if (!$this->_force_empty_result && is_object($result)) {
         $proc = new XsltProcess();
         $ret = $proc->process($data, $xsl);
         if ($proc->isErrors()) {
             $result->setAttribute('valid', 'false');
             $error = new XMLElement('error', __('Transformed XML is invalid.'));
             $result->appendChild($error);
             $element = new XMLElement('errors');
             foreach ($proc->getError() as $e) {
                 if (strlen(trim($e['message'])) == 0) {
                     continue;
                 }
                 $element->appendChild(new XMLElement('item', General::sanitize($e['message'])));
             }
             $result->appendChild($element);
         } elseif (strlen(trim($ret)) == 0) {
             $this->_force_empty_result = true;
         } else {
             if ($writeToCache) {
                 $cache->write($cache_id, $data, $this->dsParamCACHE);
             }
             $result->setValue(PHP_EOL . str_repeat("\t", 2) . preg_replace('/([\\r\\n]+)/', "\$1\t", $ret));
             $result->setAttribute('status', $valid === true ? 'fresh' : 'stale');
             $result->setAttribute('creation', $creation);
         }
     }
     return $result;
 }
Beispiel #26
0
 /**
  * Format this field value for display in the publish index tables. By default,
  * Symphony will truncate the value to the configuration setting `cell_truncation_length`.
  * This function will attempt to use PHP's `mbstring` functions if they are available.
  *
  * @param array $data
  *	an associative array of data for this string. At minimum this requires a
  *  key of 'value'.
  * @param XMLElement $link (optional)
  *	an XML link structure to append the content of this to provided it is not
  *	null. it defaults to null.
  * @param integer $entry_id (optional)
  *  An option entry ID for more intelligent processing. defaults to null
  * @return string
  *	the formatted string summary of the values of this field instance.
  */
 public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
 {
     $max_length = Symphony::Configuration()->get('cell_truncation_length', 'symphony');
     $max_length = $max_length ? $max_length : 75;
     $value = strip_tags($data['value']);
     if (function_exists('mb_substr') && function_exists('mb_strlen')) {
         $value = mb_strlen($value, 'utf-8') <= $max_length ? $value : mb_substr($value, 0, $max_length, 'utf-8') . '…';
     } else {
         $value = strlen($value) <= $max_length ? $value : substr($value, 0, $max_length) . '…';
     }
     if (strlen($value) == 0) {
         $value = __('None');
     }
     if ($link) {
         $link->setValue($value);
         return $link->generate();
     }
     return $value;
 }
Beispiel #27
0
 /**
  * Constructor for SymphonyErrorPage sets it's class variables
  *
  * @param string|XMLElement $message
  *  A description for this error, which can be provided as a string
  *  or as an XMLElement.
  * @param string $heading
  *  A heading for the error page, by default this is "Symphony Fatal Error"
  * @param string $template
  *  A string for the error page template to use, defaults to 'generic'. This
  *  can be the name of any template file in the `TEMPLATES` directory.
  *  A template using the naming convention of `tpl.*.php`.
  * @param array $additional
  *  Allows custom information to be passed to the Symphony Error Page
  *  that the template may want to expose, such as custom Headers etc.
  */
 public function __construct($message, $heading = 'Symphony Fatal Error', $template = 'generic', array $additional = NULL)
 {
     if ($message instanceof XMLElement) {
         $this->_messageObject = $message;
         $message = $this->_messageObject->generate();
     }
     parent::__construct($message);
     $this->_heading = $heading;
     $this->_template = $template;
     $this->_additional = (object) $additional;
 }
 /**
  * Format this field value for display in the publish index tables.
  *
  * Since Symphony 2.5.0, this function will call `Field::prepareReadableValue`
  * in order to get the field's human readable value.
  *
  * @param array $data
  *  an associative array of data for this string. At minimum this requires a
  *  key of 'value'.
  * @param XMLElement $link (optional)
  *  an XML link structure to append the content of this to provided it is not
  *  null. it defaults to null.
  * @param integer $entry_id (optional)
  *  An option entry ID for more intelligent processing. defaults to null
  * @return string
  *  the formatted string summary of the values of this field instance.
  */
 public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
 {
     $value = $this->prepareReadableValue($data, $entry_id, true, __('None'));
     if ($link) {
         $link->setValue($value);
         return $link->generate();
     }
     return $value;
 }
Beispiel #29
0
 public function prepareTableValue($data, XMLElement $link = null, $entry_id = null)
 {
     if (empty($data) or strlen(trim($data['value'])) == 0) {
         $value = __('None');
     } else {
         $max_length = (int) $this->get('column_length');
         $max_length = $max_length ? $max_length : 75;
         $value = strip_tags(isset($data['value_formatted']) ? $data['value_formatted'] : $data['value']);
         if ($max_length < strlen($value)) {
             $lines = explode("\n", wordwrap($value, $max_length - 1, "\n"));
             $value = array_shift($lines);
             $value = rtrim($value, "\n\t !?.,:;");
             $value .= '...';
         }
         if ($max_length > 75) {
             $value = wordwrap($value, 75, '<br />');
         }
     }
     if ($link) {
         $link->setValue($value);
         return $link->generate();
     }
     return $value;
 }
Beispiel #30
0
 public function prepareTableValue($data, XMLElement $link = NULL, $entry_id = null)
 {
     if (!($file = $data['file'])) {
         return NULL;
     }
     if ($link) {
         $link->setValue(basename($file));
         return $link->generate();
     } else {
         $link = Widget::Anchor(basename($file), URL . '/workspace' . $file);
         return $link->generate();
     }
 }