Esempio n. 1
0
 public function __toString()
 {
     $string = '';
     $dom = new DOMDocument();
     $dom->preserveWhiteSpace = FALSE;
     $dom->formatOutput = TRUE;
     $string .= '<pre>';
     $string .= 'Exception: ' . $this->getMessage() . '<br><br><br><br>';
     $string .= 'If you think there is a bug in SimpleCalDAV, please report the following information on github or send it at palm.michael@gmx.de.<br><br><br>';
     $string .= '<br>For debugging purposes:<br>';
     $string .= '<br>last request:<br><br>';
     $string .= $this->requestHeader;
     if (!empty($this->requestBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->requestHeader, $matches)) {
             $dom->loadXML($this->requestBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->requestBody) . '<br><br>';
         }
     }
     $string .= '<br>last response:<br><br>';
     $string .= $this->responseHeader;
     if (!empty($this->responseBody)) {
         if (!preg_match('#^Content-type:.*?text/calendar.*?$#', $this->responseHeader, $matches)) {
             $dom->loadXML($this->responseBody);
             $string .= htmlentities($dom->saveXml());
         } else {
             $string .= htmlentities($this->responseBody);
         }
     }
     $string .= '<br><br>';
     $string .= 'Trace:<br><br>' . $this->getTraceAsString();
     $string .= '</pre>';
     return $string;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $buildNumber = $input->getArgument('buildnumber');
     $screenshotsRegex = $input->getArgument('screenshotsRegex');
     if (empty($buildNumber)) {
         throw new \InvalidArgumentException('Missing build number.');
     }
     $urlBase = sprintf('http://builds-artifacts.piwik.org/ui-tests.master/%s', $buildNumber);
     $diffviewer = Http::sendHttpRequest($urlBase . "/screenshot-diffs/diffviewer.html", $timeout = 60);
     $diffviewer = str_replace('&', '&amp;', $diffviewer);
     $dom = new \DOMDocument();
     $dom->loadHTML($diffviewer);
     foreach ($dom->getElementsByTagName("tr") as $row) {
         $columns = $row->getElementsByTagName("td");
         $nameColumn = $columns->item(0);
         $processedColumn = $columns->item(3);
         $testPlugin = null;
         if ($nameColumn && preg_match("/\\(for ([a-zA-Z_]+) plugin\\)/", $dom->saveXml($nameColumn), $matches)) {
             $testPlugin = $matches[1];
         }
         $file = null;
         if ($processedColumn && preg_match("/href=\".*\\/(.*)\"/", $dom->saveXml($processedColumn), $matches)) {
             $file = $matches[1];
         }
         if ($file !== null && preg_match("/" . $screenshotsRegex . "/", $file)) {
             if ($testPlugin == null) {
                 $downloadTo = "tests/PHPUnit/UI/expected-ui-screenshots/{$file}";
             } else {
                 $downloadTo = "plugins/{$testPlugin}/tests/UI/expected-ui-screenshots/{$file}";
             }
             $output->write("<info>Downloading {$file} to .{$downloadTo}...</info>\n");
             Http::sendHttpRequest("{$urlBase}/processed-ui-screenshots/{$file}", $timeout = 60, $userAgent = null, PIWIK_DOCUMENT_ROOT . "/" . $downloadTo);
         }
     }
 }
function create_json_file($doc_url, $file_name)
{
    //Get the file
    $string = file_get_contents($doc_url) or die("Could not open {$doc_url} for reading");
    //Deal with character encoding
    $string = mb_convert_encoding($string, 'utf-8', mb_detect_encoding($string));
    // if you have not escaped entities use
    $file = mb_convert_encoding($string, 'html-entities', 'utf-8');
    //Set up DOMDocument
    $doc = new DOMDocument('1.0', 'UTF-8');
    $doc->substituteEntities = TRUE;
    $doc->loadHTML($file);
    $paragraphs = $doc->getElementsByTagName('p');
    //Initialize variables
    $output = array('chapters' => array());
    $heading = 0;
    //Counter.
    foreach ($paragraphs as $paragraph) {
        $elementValue = $doc->saveXml($paragraph);
        if (!empty($elementValue)) {
            /*
            	Get the attribute
            	If it has "subtitle", wrap it in h2 tags.
            	If it's wrapped in curly braces, convert to php array to describe art.
            	If it doesn't, wrap it in a p tag.
            	Put in JSON array.
            */
            if (stripos($paragraph->getAttribute('class'), 'subtitle')) {
                $heading++;
                $output['chapters'][$heading] = array('heading' => $paragraph->nodeValue, 'content' => array(), 'preview image' => '', 'short title' => '');
            } elseif (stripos($paragraph->nodeValue, '{') !== FALSE) {
                //This is a rich media asset
                //A heading should be set when it triggered a earlier in this loop.
                $clean_string = str_replace("“", "\"", $paragraph->nodeValue);
                $clean_string = str_replace("”", "\"", $clean_string);
                $rich_media = json_decode($clean_string);
                if (is_null($rich_media)) {
                    die('There is a parse error with your rich media: ' . var_dump($clean_string));
                }
                if (is_null($rich_media->filename) || is_null($rich_media->filetype)) {
                    die('Your rich media is missing attributes. ' . var_dump($clean_string));
                }
                //Provides some basic validation.
                $output['chapters'][$heading]['content'][] = array('filename' => $rich_media->filename, 'filetype' => $rich_media->filetype, 'size' => preg_match('/^(big|medium|small)$/', $rich_media->size) ? $rich_media->size : 'big', 'orientation' => preg_match('/^(left|right|full|background)$/', $rich_media->orientation) ? $rich_media->orientation : 'full', 'caption' => $rich_media->caption, 'credit' => $rich_media->credit, 'poster' => isset($rich_media->poster) ? $rich_media->poster : '');
            } else {
                $value = trim(strip_tags($doc->saveXml($paragraph), '<a>'));
                if (!empty($value)) {
                    $output['chapters'][$heading]['content'][] = array('filename' => NULL, 'filetype' => 'text', 'size' => null, 'orientation' => null, 'caption' => $value);
                }
                // $output['chapters'][$heading]['content'][] = strip_tags($paragraph->nodeValue, 'a');
            }
        }
        // if the string isn't empty
    }
    //Now write this to a file.
    file_put_contents('/Library/WebServer/Documents/portland/app/data/' . $file_name . '.json', json_encode($output)) or die('Could not open file for writing.');
    echo date("Y-m-d H:i:s") . " successful import. \r\n";
}
 /**
  *
  * @param InputInterface $input
  * @param OutputInterface $output
  * @return int|null|void
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $contentLoaderService = $container->get('blend_ez_sitemap.content');
     $locations = $contentLoaderService->loadLocations();
     $sitemap = new \DOMDocument('1.0', 'utf-8');
     $sitemap->preserveWhiteSpace = false;
     $sitemap->formatOutput = true;
     $urlSet = $sitemap->createElement('urlset');
     $sitemap->appendChild($urlSet);
     // add url blocks to sitemap xml
     //  <url>
     //    <loc>/</loc>
     //    <lastmod>2015-06-15</lastmod>
     //  </url>
     foreach ($locations as $location) {
         // create url block
         $urlBlock = $sitemap->createElement('url');
         $urlSet->appendChild($urlBlock);
         // create loc tag
         $loc = $sitemap->createElement('loc');
         $urlBlock->appendChild($loc);
         $url = $container->get('router')->generate($location);
         $locText = $sitemap->createTextNode($url);
         $loc->appendChild($locText);
         // create lastmod tag
         $lastmod = $sitemap->createElement('lastmod');
         $urlBlock->appendChild($lastmod);
         $lastmodText = $sitemap->createTextNode($location->contentInfo->modificationDate->format('Y-m-d'));
         $lastmod->appendChild($lastmodText);
     }
     $fp = fopen('web/sitemap.xml', 'w');
     fwrite($fp, $sitemap->saveXml());
     fclose($fp);
 }
Esempio n. 5
0
 function show()
 {
     $channel_id = intval($this->input['channel_id']);
     if (!$channel_id) {
         $this->errorOutput('未传入频道id');
     }
     $sql = "SELECT id, start_time, toff, theme FROM " . DB_PREFIX . "program ";
     $sql .= " WHERE channel_id = " . $channel_id . " AND start_time>=" . TIMENOW;
     $sql .= " ORDER BY start_time ASC LIMIT 1";
     $program_info = $this->db->query_first($sql);
     $sql = "SELECT name, logo_info, stream_id FROM " . DB_PREFIX . "channel ";
     $sql .= " WHERE id = " . $channel_id;
     $channel_info = $this->db->query_first($sql);
     $logo_url = '';
     if ($channel_info['logo_info']) {
         $logo_info = @unserialize($channel_info['logo_info']);
         $logo_url = hg_material_link($logo_info['host'], $logo_info['dir'], $logo_info['filepath'], $logo_info['filename']);
     }
     header('Content-Type: text/xml; charset=UTF-8');
     $dom = new DOMDocument('1.0', 'utf-8');
     $channel = $dom->createElement('channel');
     $channel->setAttribute('name', $channel_info['name']);
     $channel->setAttribute('url', $logo_url);
     $channel->setAttribute('current', $channel_info['stream_id']);
     $logos = $dom->createElement('logos');
     $item = $dom->createElement('item');
     $item->setAttribute('url', $channel_info['logo']);
     $logos->appendChild($item);
     $channel->appendChild($logos);
     $dom->appendChild($channel);
     echo $dom->saveXml();
 }
Esempio n. 6
0
 /**
  * @todo Implement testSerialize().
  */
 public function testSerialize()
 {
     $dom = new DOMDocument();
     $dom->appendChild($dom->createElement('xml'));
     $this->object->serialize('test', $dom->documentElement);
     self::assertXmlStringEqualsXmlString('<xml>test</xml>', $dom->saveXml());
 }
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => null, 'lst' => '', 'ssttid' => '', 'dest' => '', 'reason' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $lst = $dom_xml->createElement('lst');
     $ssttid = $dom_xml->createElement('ssttid');
     $dest = $dom_xml->createElement('dest');
     $reason = $dom_xml->createElement('reason');
     $lst->appendChild($dom_xml->createTextNode($params['lst']));
     $ssttid->appendChild($dom_xml->createTextNode($params['ssttid']));
     $dest->appendChild($dom_xml->createTextNode($params['dest']));
     $reason->appendChild($dom_xml->createTextNode($params['reason']));
     $root->appendChild($lst);
     $root->appendChild($ssttid);
     $root->appendChild($dest);
     $root->appendChild($reason);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['usr_id'])) {
         if (parent::email()) {
             $mailed = true;
         }
     }
     $this->broker->notify($params['usr_id'], __CLASS__, $datas, $mailed);
     return;
 }
Esempio n. 8
0
function wpr_gtrns($text, $from, $to) {
	$url = "http://translate.google.com/translate_t";
	$ref = "http://translate.google.com/translate_t";
	$text=urlencode($text);
	if($to=="tw"||$to=="cn") {
		$to="zh-".strtoupper($to);
	}
	if($to=="nor") {$to=="no";}
	$postdata="hl=en&ie=UTF8&text=".$text."&langpair=".$from."%7C".$to;
	$page = wpr_gettr($url, $postdata, $ref);
	if(!empty($page["error"]["reason"])) {
		return $page;
	}
	
		$dom = new DOMDocument();
		@$dom->loadHTML($page);
		$xpath = new DOMXPath($dom);
		$paras = $xpath->query("//span[@id='result_box']"); // additional span? //span[@id='result_box']/span
		
		$para = $paras->item(0);
		$string = $dom->saveXml($para);	
		//$string = utf8_decode($string);
	if ($string!="") {
		return stripslashes(strip_tags($string));
	} else {
		return "";
	}
}
Esempio n. 9
0
 function show()
 {
     $channel_id = $this->input['channel_id'];
     if (!$channel_id) {
         $this->errorOutput('该频道不存在或者已被删除');
     }
     $dates = $this->input['dates'];
     if (!$dates) {
         $this->errorOutput('这一天不存在节目');
     }
     $sql = "select * from " . DB_PREFIX . "program where channel_id=" . $channel_id . " AND dates='" . $dates . "' ORDER BY start_time ASC ";
     $q = $this->db->query($sql);
     header('Content-Type: text/xml; charset=UTF-8');
     $dom = new DOMDocument('1.0', 'utf-8');
     $program = $dom->createElement('program');
     while ($row = $this->db->fetch_array($q)) {
         $item = $dom->createElement('item');
         $item->setAttribute('name', urldecode($row['theme']));
         $item->setAttribute('startTime', $row['start_time'] * 1000);
         $item->setAttribute('duration', $row['toff'] * 1000);
         $program->appendChild($item);
     }
     $dom->appendChild($program);
     echo $dom->saveXml();
 }
Esempio n. 10
0
function format_xml_string($xml)
{
    if ($dom = new DOMDocument()) {
        $dom->preserveWhiteSpace = FALSE;
        $dom->formatOutput = TRUE;
        $dom->loadXML('<root><foo><bar>baz</bar></foo></root>');
        return (string) $dom->saveXml();
    } else {
        $xml = preg_replace('/(>)(<)(\\/*)/', "\$1\n\$2\$3", $xml);
        $token = strtok($xml, "\n");
        $result = '';
        $pad = 0;
        $matches = array();
        while ($token !== FALSE) {
            if (preg_match('/.+<\\/\\w[^>]*>$/', $token, $matches)) {
                $indent = 0;
            } elseif (preg_match('/^<\\/\\w/', $token, $matches)) {
                $pad--;
                $indent = 0;
            } elseif (preg_match('/^<\\w[^>]*[^\\/]>.*$/', $token, $matches)) {
                $indent = 1;
            } else {
                $indent = 0;
            }
            $line = str_pad($token, strlen($token) + $pad, ' ', STR_PAD_LEFT);
            $result .= $line . "\n";
            $token = strtok("\n");
            $pad += $indent;
        }
        return (string) $result;
        // reference
        // http://www.daveperrett.com/articles/2007/04/05/format-xml-with-php/
    }
}
Esempio n. 11
0
 /**
  * Normalizes a given xml string to be compareable.
  *
  * @param string $xml
  * @return string
  */
 protected function sanitizeXml($xml)
 {
     $dom = new \DOMDocument();
     $dom->loadXml($xml);
     //$dom->normalizeDocument();
     return $dom->saveXml();
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $buildNumber = $input->getArgument('buildnumber');
     if (empty($buildNumber)) {
         throw new \InvalidArgumentException('Missing build number.');
     }
     $screenshotsRegex = $input->getArgument('screenshotsRegex');
     $plugin = $input->getOption('plugin');
     $httpUser = $input->getOption('http-user');
     $httpPassword = $input->getOption('http-password');
     $urlBase = $this->getUrlBase($plugin, $buildNumber);
     $diffviewer = $this->getDiffviewerContent($output, $urlBase, $httpUser, $httpPassword);
     $dom = new \DOMDocument();
     $dom->loadHTML($diffviewer);
     foreach ($dom->getElementsByTagName("tr") as $row) {
         $columns = $row->getElementsByTagName("td");
         $processedColumn = $columns->item(3);
         $file = null;
         if ($processedColumn && preg_match("/href=\".*\\/(.*)\"/", $dom->saveXml($processedColumn), $matches)) {
             $file = $matches[1];
         }
         if ($file !== null && preg_match("/" . $screenshotsRegex . "/", $file)) {
             $this->downloadProcessedScreenshot($output, $urlBase, $file, $plugin, $httpUser, $httpPassword);
         }
     }
     $this->displayGitInstructions($output, $plugin);
 }
function beautify($xml)
{
    $dom = new DOMDocument();
    $dom->preserveWhiteSpace = false;
    $dom->loadXML($xml);
    $dom->formatOutput = true;
    return $dom->saveXml();
}
Esempio n. 14
0
 /**
  * Returns small XML error message if access to module has been denied.
  */
 public function moduleAccessDeniedAction()
 {
     $response = $this->getResponse();
     $response->setHttpResponseCode(401);
     $doc = new DOMDocument();
     $doc->appendChild($doc->createElement('error', 'Unauthorized: Access to module not allowed.'));
     $this->getResponse()->setBody($doc->saveXml());
 }
Esempio n. 15
0
 /**
  * @todo Implement testSerialize().
  */
 public function testSerialize()
 {
     // Remove the following lines when you implement this test.
     $dom = new DOMDocument();
     $dom->appendChild($dom->createElement('xml'));
     $this->object->serialize(array('a' => 'b'), $dom->documentElement);
     self::assertXmlStringEqualsXmlString('<xml><a>b</a></xml>', $dom->saveXml());
 }
Esempio n. 16
0
 /**
  * Test showXml
  *
  * @param   string  $form  The form.
  *
  * @return void
  */
 private function _showXml($form)
 {
     $dom = new DOMDocument('1.0');
     $dom->preserveWhiteSpace = false;
     $dom->formatOutput = true;
     $dom->loadXml($form->getXml()->asXml());
     echo $dom->saveXml();
 }
Esempio n. 17
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'order_id' => []];
     $params = array_merge($default, $params);
     $order_id = $params['order_id'];
     $users = [];
     try {
         $repository = $this->app['EM']->getRepository('Phraseanet:OrderElement');
         $results = $repository->findBy(['orderId' => $order_id]);
         $base_ids = [];
         foreach ($results as $result) {
             $base_ids[] = $result->getBaseId();
         }
         $base_ids = array_unique($base_ids);
         $query = new User_Query($this->app);
         $users = $query->on_base_ids($base_ids)->who_have_right(['order_master'])->execute()->get_results();
     } catch (\Exception $e) {
     }
     if (count($users) == 0) {
         return;
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id_dom = $dom_xml->createElement('usr_id');
     $order_id_dom = $dom_xml->createElement('order_id');
     $usr_id_dom->appendChild($dom_xml->createTextNode($params['usr_id']));
     $order_id_dom->appendChild($dom_xml->createTextNode($order_id));
     $root->appendChild($usr_id_dom);
     $root->appendChild($order_id_dom);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($orderInitiator = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($users as $user) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($user->getId())) {
             $readyToSend = false;
             try {
                 $receiver = Receiver::fromUser($user);
                 $readyToSend = true;
             } catch (\Exception $e) {
                 continue;
             }
             if ($readyToSend) {
                 $mail = MailInfoNewOrder::create($this->app, $receiver);
                 $mail->setUser($orderInitiator);
                 $this->app['notification.deliverer']->deliver($mail);
                 $mailed = true;
             }
         }
         $this->broker->notify($user->getId(), __CLASS__, $datas, $mailed);
     }
     return;
 }
Esempio n. 18
0
function escape($strin)
{
    $dom = new DOMDocument('1.0');
    $element = $dom->createElement('Element');
    $element->appendChild($dom->createTextNode($strin));
    $dom->appendChild($element);
    $x = $dom->saveXml();
    $x = substr($x, 31);
    $x = substr($x, 0, -11);
    return $x;
}
Esempio n. 19
0
 public function __toString()
 {
     $doc = new DOMDocument();
     $doc->loadXML('<add/>');
     foreach ($this->documents as $document) {
         $frag = $doc->createDocumentFragment();
         $frag->appendXml((string) $document);
         $doc->documentElement->appendChild($frag);
     }
     return $doc->saveXml($doc->documentElement);
 }
Esempio n. 20
0
 /**
  * @covers MedraWebservice
  */
 public function testViewMetadata()
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->loadXML($this->getTestData());
     $elem = $dom->getElementsByTagName('DOISerialIssueWork')->item(0);
     $attr = $dom->createAttribute('xmlns');
     $attr->value = 'http://www.editeur.org/onix/DOIMetadata/2.0';
     $elem->appendChild($attr);
     $result = str_replace('<NotificationType>07</NotificationType>', '<NotificationType>06</NotificationType>', $this->ws->viewMetadata('1749/t.v1i1'));
     self::assertXmlStringEqualsXmlString($dom->saveXml($elem), $result);
 }
Esempio n. 21
0
 /**
  * Pretty print for XML
  *
  * @param string $xmlString XML
  *
  * @return string
  *
  * @throws InvalidArgumentException
  */
 public function formatXmlString($xmlString)
 {
     if (true === $this->isXml($xmlString)) {
         $dom = new \DOMDocument();
         $dom->preserveWhiteSpace = false;
         $dom->loadXML($xmlString);
         $dom->formatOutput = true;
         return $dom->saveXml();
     } else {
         throw new InvalidArgumentException('Incorrect XML string');
     }
 }
 /**
  * Used to format all XML for display
  *
  * @return fomatted XML string
  */
 public static function formatXML($resources)
 {
     if ($resources != null) {
         $dom = new DOMDocument();
         $dom->preserveWhiteSpace = FALSE;
         $dom->loadXML($resources);
         $dom->formatOutput = TRUE;
         $resources = $dom->saveXml();
         $resources = htmlentities($resources);
     }
     return $resources;
 }
Esempio n. 23
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return Void
  */
 public function fire($event, $params, &$object)
 {
     $default = ['usr_id' => '', 'autoregister' => []];
     $params = array_merge($default, $params);
     $base_ids = array_keys($params['autoregister']);
     if (count($base_ids) == 0) {
         return;
     }
     $mailColl = [];
     try {
         $rs = $this->app['EM.native-query']->getAdminsOfBases(array_keys($base_ids));
         foreach ($rs as $row) {
             $user = $row[0];
             if (!isset($mailColl[$user->getId()])) {
                 $mailColl[$user->getId()] = [];
             }
             $mailColl[$user->getId()][] = $row['base_id'];
         }
     } catch (\Exception $e) {
     }
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $usr_id = $dom_xml->createElement('usr_id');
     $base_ids = $dom_xml->createElement('base_ids');
     $usr_id->appendChild($dom_xml->createTextNode($params['usr_id']));
     foreach ($params['autoregister'] as $base_id => $collection) {
         $base_id_node = $dom_xml->createElement('base_id');
         $base_id_node->appendChild($dom_xml->createTextNode($base_id));
         $base_ids->appendChild($base_id_node);
     }
     $root->appendChild($usr_id);
     $root->appendChild($base_ids);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     if (null === ($registered_user = $this->app['manipulator.user']->getRepository()->find($params['usr_id']))) {
         return;
     }
     foreach ($mailColl as $usr_id => $base_ids) {
         $mailed = false;
         if ($this->shouldSendNotificationFor($usr_id)) {
             if (null === ($admin_user = $this->app['manipulator.user']->getRepository()->find($usr_id))) {
                 continue;
             }
             if (self::mail($admin_user, $registered_user)) {
                 $mailed = true;
             }
         }
         $this->broker->notify($usr_id, __CLASS__, $datas, $mailed);
     }
     return;
 }
Esempio n. 24
0
 /**
  * Recreate ant build file on	 'cache:clear' call
  * @param sfEvent $event
  */
 public static function createAntBuildFile(sfEvent $event)
 {
     if (self::$calls || $event['env'] != 'dev') {
         //generate file only once and only for dev environment
         return false;
     }
     self::$calls++;
     $event->getSubject()->logSection('file+', self::BUILD_FILE);
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->formatOutput = true;
     $dom->appendChild($projectXML = $dom->createElement('project'));
     $projectXML->appendChild($propertyXML = $dom->createElement('property'));
     $propertyXML->setAttribute('name', 'symfony.command');
     $sf_command_line = isset($_SERVER['_']) && (preg_match('/php$/', $_SERVER['_']) || $_SERVER['_'] == './symfony') ? './symfony' : 'symfony';
     $propertyXML->setAttribute('value', $sf_command_line);
     $dispatcher = new sfEventDispatcher();
     $application = new sfSymfonyCommandApplication($dispatcher, null, array('symfony_lib_dir' => realpath(dirname(__FILE__) . '/../../../')));
     $tasks = $application->getTasks();
     ksort($tasks);
     foreach ($tasks as $name => $task) {
         $projectXML->appendChild($targetXML = $dom->createElement('target'));
         $targetXML->setAttribute('name', $name);
         $targetXML->setAttribute('description', $task->getBriefDescription());
         $task_arguments = array();
         foreach ($task->getArguments() as $argument) {
             if ($argument->isRequired()) {
                 $targetXML->appendChild($inputXML = $dom->createElement('input'));
                 $inputXML->setAttribute('message', $argument->getHelp());
                 $argument_name = 'symfony.' . $task->getNamespace() . '.' . $task->getName() . '.' . $argument->getName();
                 $task_arguments[] = $argument_name;
                 $inputXML->setAttribute('addproperty', $argument_name);
                 $default = $argument->getDefault();
                 if ($default) {
                     $inputXML->setAttribute('defaultvalue', $default);
                 }
             }
         }
         $targetXML->appendChild($execXML = $dom->createElement('exec'));
         $execXML->setAttribute('dir', '');
         $execXML->setAttribute('executable', '${symfony.command}');
         $execXML->appendChild($argXML = $dom->createElement('arg'));
         $task_command = $task->getNamespace() ? $task->getNamespace() . ':' . $task->getName() : $task->getName();
         $argXML->setAttribute('value', $task_command);
         foreach ($task_arguments as $argument) {
             $execXML->appendChild($argXML = $dom->createElement('arg'));
             $argXML->setAttribute('value', '${' . $argument . '}');
         }
     }
     file_put_contents(self::BUILD_FILE, $dom->saveXml());
     return false;
     //we do not stop cache:clear
 }
Esempio n. 25
0
 public function asHtml()
 {
     $dom_sxe = dom_import_simplexml($this);
     $dom_output = new \DOMDocument('1.0');
     $dom_output->formatOutput = true;
     $dom_sxe = $dom_output->importNode($dom_sxe, true);
     $dom_sxe = $dom_output->appendChild($dom_sxe);
     // $res = $dom_output->saveHtml($dom_output);
     $res = $dom_output->saveXml($dom_output);
     $res = preg_replace('/^  |\\G  /m', "\t", $res);
     $res = preg_replace('/<\\?xml[^\\n]+\\n/', '', $res);
     return $res;
 }
Esempio n. 26
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$entry)
 {
     $params = ['entry_id' => $entry->getId(), 'notify_email' => $params['notify_email']];
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $entry_id = $dom_xml->createElement('entry_id');
     $entry_id->appendChild($dom_xml->createTextNode($params['entry_id']));
     $root->appendChild($entry_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $Query = new \User_Query($this->app);
     $Query->include_phantoms(true)->include_invite(false)->include_templates(false)->email_not_null(true);
     if ($entry->getFeed()->getCollection($this->app)) {
         $Query->on_base_ids([$entry->getFeed()->getCollection($this->app)->get_base_id()]);
     }
     $start = 0;
     $perLoop = 100;
     $from = ['email' => $entry->getAuthorEmail(), 'name' => $entry->getAuthorName()];
     do {
         $results = $Query->limit($start, $perLoop)->execute()->get_results();
         foreach ($results as $user_to_notif) {
             $mailed = false;
             if ($params['notify_email'] && $this->shouldSendNotificationFor($user_to_notif->getId())) {
                 $readyToSend = false;
                 try {
                     $token = $this->app['tokens']->getUrlToken(\random::TYPE_FEED_ENTRY, $user_to_notif->getId(), null, $entry->getId());
                     $url = $this->app->url('lightbox', ['LOG' => $token]);
                     $receiver = Receiver::fromUser($user_to_notif);
                     $readyToSend = true;
                 } catch (\Exception $e) {
                 }
                 if ($readyToSend) {
                     $mail = MailInfoNewPublication::create($this->app, $receiver);
                     $mail->setButtonUrl($url);
                     $mail->setAuthor($entry->getAuthorName());
                     $mail->setTitle($entry->getTitle());
                     $this->app['notification.deliverer']->deliver($mail);
                     $mailed = true;
                 }
             }
             $this->broker->notify($user_to_notif->getId(), __CLASS__, $datas, $mailed);
         }
         $start += $perLoop;
     } while (count($results) > 0);
     return true;
 }
 public static function to_xml($results = null)
 {
     if (is_null($results)) {
         $results = self::$all_results;
     }
     $dom = new DOMDocument('1.0', 'UTF-8');
     $dom->formatOutput = true;
     $dom->appendChild($testsuites = $dom->createElement('testsuites'));
     $errors = 0;
     $failures = 0;
     $errors = 0;
     $skipped = 0;
     $assertions = 0;
     foreach ($results as $result) {
         $testsuites->appendChild($testsuite = $dom->createElement('testsuite'));
         $testsuite->setAttribute('name', basename($result['file'], '.php'));
         $testsuite->setAttribute('file', $result['file']);
         $testsuite->setAttribute('failures', count($result['stats']['failed']));
         $testsuite->setAttribute('errors', 0);
         $testsuite->setAttribute('skipped', count($result['stats']['skipped']));
         $testsuite->setAttribute('tests', $result['stats']['plan']);
         $testsuite->setAttribute('assertions', $result['stats']['plan']);
         $failures += count($result['stats']['failed']);
         $skipped += count($result['stats']['skipped']);
         $assertions += $result['stats']['plan'];
         foreach ($result['tests'] as $test) {
             $testsuite->appendChild($testcase = $dom->createElement('testcase'));
             $testcase->setAttribute('name', $test['message']);
             $testcase->setAttribute('file', $test['file']);
             $testcase->setAttribute('line', $test['line']);
             $testcase->setAttribute('assertions', 1);
             if (!$test['status']) {
                 $testcase->appendChild($failure = $dom->createElement('failure'));
                 $failure->setAttribute('type', 'lime');
                 if ($test['error']) {
                     $failure->appendChild($dom->createTextNode($test['error']));
                 }
             }
         }
     }
     $testsuites->setAttribute('failures', $failures);
     $testsuites->setAttribute('errors', $errors);
     $testsuites->setAttribute('tests', $assertions);
     $testsuites->setAttribute('assertions', $assertions);
     $testsuites->setAttribute('skipped', $skipped);
     return $dom->saveXml();
 }
Esempio n. 28
0
 /**
  *
  * @param  string  $event
  * @param  Array   $params
  * @param  Array   $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'ssel_id' => '', 'n' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $n = $dom_xml->createElement('n');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $n->appendChild($dom_xml->createTextNode($params['n']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($ssel_id);
     $root->appendChild($n);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $repository = $this->app['EM']->getRepository('Phraseanet:Basket');
             $basket = $repository->find($params['ssel_id']);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $url = $this->app->url('lightbox_compare', ['basket' => $basket->getId(), 'LOG' => $this->app['tokens']->getUrlToken(\random::TYPE_VIEW, $user_to->getId(), null, $basket->getId())]);
             $mail = MailInfoOrderDelivered::create($this->app, $receiver, $emitter, null);
             $mail->setButtonUrl($url);
             $mail->setBasket($basket);
             $mail->setDeliverer($user_from);
             $this->app['notification.deliverer']->deliver($mail);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }
Esempio n. 29
0
 protected function _toHtml()
 {
     $logview = Mage::getModel('byjuno/byjuno')->load($this->getRequest()->getParam('id'));
     /* @var $logview Byjuno_Cdp_Model_Byjuno */
     $domInput = new DOMDocument();
     $domInput->preserveWhiteSpace = FALSE;
     $domInput->loadXML($logview->getData("request"));
     $elem = $domInput->getElementsByTagName('Request');
     $elem->item(0)->removeAttribute("UserID");
     $elem->item(0)->removeAttribute("Password");
     $domInput->formatOutput = TRUE;
     libxml_use_internal_errors(true);
     $testXml = simplexml_load_string($logview->getData("response"));
     $domOutput = new DOMDocument();
     $domOutput->preserveWhiteSpace = FALSE;
     if ($testXml) {
         $domOutput->loadXML($logview->getData("response"));
         $domOutput->formatOutput = TRUE;
         echo '
         <a href="javascript:history.go(-1)">Back to log</a>
         <h1>Input & output XML</h1>
         <table width="50%">
             <tr>
                 <td>Input (Attributes Login & password removed)</td>
                 <td>Response</td>
             </tr>
             <tr>
                 <td width="50%" style="border: 1px solid #CCCCCC; padding: 5px;"><code style="width: 100%; word-wrap: break-word; white-space: pre-wrap;">' . htmlspecialchars($domInput->saveXml()) . '</code></td>
                 <td width="50%" style="border: 1px solid #CCCCCC; padding: 5px;"><code style="width: 100%; word-wrap: break-word; white-space: pre-wrap;">' . htmlspecialchars($domOutput->saveXml()) . '</code></td>
             </tr>
         </table>';
     } else {
         echo '
         <a href="javascript:history.go(-1)">Back to log</a>
         <h1>Input & output XML</h1>
         <table width="50%">
             <tr>
                 <td>Input (Attributes Login & password removed)</td>
                 <td>Response</td>
             </tr>
             <tr>
                 <td width="50%" style="border: 1px solid #CCCCCC; padding: 5px;"><code style="width: 100%; word-wrap: break-word; white-space: pre-wrap;">' . htmlspecialchars($domInput->saveXml()) . '</code></td>
                 <td width="50%" style="border: 1px solid #CCCCCC; padding: 5px;"><code style="width: 100%; word-wrap: break-word; white-space: pre-wrap;">Raw data: ' . $logview->getData("response") . '</code></td>
             </tr>
         </table>';
     }
 }
Esempio n. 30
0
 /**
  *
  * @param  string        $event
  * @param  Array         $params
  * @param  mixed content $object
  * @return boolean
  */
 public function fire($event, $params, &$object)
 {
     $default = ['from' => '', 'to' => '', 'message' => '', 'ssel_id' => ''];
     $params = array_merge($default, $params);
     $dom_xml = new DOMDocument('1.0', 'UTF-8');
     $dom_xml->preserveWhiteSpace = false;
     $dom_xml->formatOutput = true;
     $root = $dom_xml->createElement('datas');
     $from = $dom_xml->createElement('from');
     $to = $dom_xml->createElement('to');
     $message = $dom_xml->createElement('message');
     $ssel_id = $dom_xml->createElement('ssel_id');
     $from->appendChild($dom_xml->createTextNode($params['from']));
     $to->appendChild($dom_xml->createTextNode($params['to']));
     $message->appendChild($dom_xml->createTextNode($params['message']));
     $ssel_id->appendChild($dom_xml->createTextNode($params['ssel_id']));
     $root->appendChild($from);
     $root->appendChild($to);
     $root->appendChild($message);
     $root->appendChild($ssel_id);
     $dom_xml->appendChild($root);
     $datas = $dom_xml->saveXml();
     $mailed = false;
     if ($this->shouldSendNotificationFor($params['to'])) {
         $readyToSend = false;
         try {
             $user_from = $this->app['manipulator.user']->getRepository()->find($params['from']);
             $user_to = $this->app['manipulator.user']->getRepository()->find($params['to']);
             $basket = $this->app['EM']->getRepository('Phraseanet:Basket')->find($params['ssel_id']);
             $title = $basket->getName();
             $receiver = Receiver::fromUser($user_to);
             $emitter = Emitter::fromUser($user_from);
             $readyToSend = true;
         } catch (\Exception $e) {
         }
         if ($readyToSend) {
             $mail = MailInfoValidationRequest::create($this->app, $receiver, $emitter, $params['message']);
             $mail->setButtonUrl($params['url']);
             $mail->setDuration($params['duration']);
             $mail->setTitle($title);
             $mail->setUser($user_from);
             $this->app['notification.deliverer']->deliver($mail, $params['accuse']);
             $mailed = true;
         }
     }
     return $this->broker->notify($params['to'], __CLASS__, $datas, $mailed);
 }