Пример #1
0
 /** {@inheritdoc} */
 public function render($content)
 {
     $element = $this->getElement();
     $view = $element->getView();
     if (null === $view) {
         return $content;
     }
     $placement = $this->getPlacement();
     $separator = $this->getSeparator();
     $attr = array('onchange' => '$(this).prev().val(this.value.split("|")[1]); this.selectedIndex = 0;');
     $options = array('' => 'Select page...');
     foreach (PageQuery::create()->orderByBranch()->find() as $page) {
         if (Curry_Backend_Page::isTemplatePage($page)) {
             continue;
         }
         $options[$page->getPageId() . '|' . $page->getUrl()] = str_repeat(Curry_Core::SELECT_TREE_PREFIX, $page->getLevel()) . $page->getName();
     }
     $options = Curry_Html::createSelectOptions($options, '');
     $markup = Curry_Html::createTag('select', $attr, $options);
     switch ($placement) {
         case 'PREPEND':
             $content = $markup . $separator . $content;
             break;
         case 'APPEND':
         default:
             $content = $content . $separator . $markup;
     }
     return $content;
 }
Пример #2
0
 /** {@inheritdoc} */
 public function showMain()
 {
     $this->addMainMenu();
     $form = new Curry_Form(array('action' => url('', array("module", "view")), 'method' => 'post', 'elements' => array('keywords' => array('text', array('label' => 'Keywords', 'required' => true)), 'search' => array('submit', array('label' => 'Search')))));
     // Validate
     if (isPost() && $form->isValid($_POST)) {
         $this->addMainContent($form);
         $index = Curry_Core::getSearchIndex();
         $hits = $index->find($form->keywords->getValue());
         $html = "";
         foreach ($hits as $hit) {
             $fieldNames = $hit->getDocument()->getFieldNames();
             $title = in_array('title', $fieldNames) ? (string) $hit->title : '<Untitled>';
             $url = in_array('url', $fieldNames) ? (string) $hit->url : null;
             $model = in_array('model', $fieldNames) ? (string) $hit->model : 'Unknown type';
             $item = $url !== null ? Curry_Html::createTag('a', array('href' => $url), $title) : $title;
             $item .= ' (' . htmlspecialchars($model) . ')<br/>';
             $html .= '<li>' . $item . '<small>Fields: ' . htmlspecialchars(join(', ', $fieldNames)) . '</small></li>';
         }
         $html .= "<li>Hits: " . count($hits) . " / " . $index->numDocs() . "</li>";
         $this->addMainContent("<ul>" . $html . "</ul>");
     } else {
         $this->addMainContent($form);
     }
 }
Пример #3
0
 protected function getPageInheritance($page, $wrappers)
 {
     $ret = Curry_Html::createTag('a', array('href' => url('', array('module', 'view', 'page_id' => $page->getPageId())), 'title' => $page->getUrl()), $page->getName());
     // Module sorting
     $sorted = ModuleSortorderQuery::create()->filterByPageRevisionId($page->getWorkingPageRevisionId())->count() > 0;
     if ($sorted) {
         $ret .= ' <i class="icon-reorder" title="Sorted"></i>';
     }
     // Modules
     $moduleDatas = ModuleDataQuery::create()->filterByPageRevisionId($page->getWorkingPageRevisionId())->filterByPageModuleId(array_keys($wrappers))->find();
     $list = array();
     foreach ($moduleDatas as $moduleData) {
         $id = $moduleData->getPageModuleId();
         $wrapper = $wrappers[$id];
         if (!isset($list[$id])) {
             $list[$id] = $wrapper->getName() . ' ';
         }
         if ($moduleData->getLangcode()) {
             $list[$id] .= ' (' . $moduleData->getLangcode() . ' ';
         }
         if ($moduleData->getData() !== null) {
             $list[$id] .= '<i class="icon-picture" title="Content"></i>';
         }
         if ($moduleData->getTemplate() !== null) {
             $list[$id] .= '<i class="icon-file-alt" title="Template"></i>';
         }
         if ($moduleData->getEnabled() !== null) {
             $list[$id] .= '<i class="icon-lightbulb" title="Module ' . ($moduleData->getEnabled() ? 'enabled' : 'disabled') . '"></i>';
         }
         if ($moduleData->getLangcode()) {
             $list[$id] .= ')';
         }
     }
     if (count($list)) {
         $ret .= '<br/>' . join('<br/>', $list);
     }
     // Subpages
     $subPages = PageQuery::create()->useWorkingPageRevisionQuery('', Criteria::INNER_JOIN)->filterByBasePage($page)->endUse()->find();
     $list = array();
     foreach ($subPages as $subPage) {
         $list[] .= $this->getPageInheritance($subPage, $wrappers);
     }
     if (count($list)) {
         $ret .= '<ul>' . join('', $list) . '</ul>';
     }
     return '<li>' . $ret . '</li>';
 }
Пример #4
0
 /**
  * Generates SWFObject static embedding code.
  *
  * @param string $source
  * @param int $width
  * @param int $height
  * @param string $version
  * @param array $options
  * @return array
  */
 private static function swfobjectStatic($source, $width, $height, $version, array $options)
 {
     $attributes = (array) $options['attributes'];
     $params = (array) $options['params'];
     if (isset($options['flashvars'])) {
         $params['flashvars'] = http_build_query($options['flashvars']);
     }
     $objectAttr = array('id' => $options['target'], 'classid' => 'clsid:D27CDB6E-AE6D-11cf-96B8-444553540000', 'width' => $width, 'height' => $height);
     $object2Attr = array('type' => 'application/x-shockwave-flash', 'data' => $source, 'width' => $width, 'height' => $height);
     $attributes2 = $attributes;
     unset($attributes2['id']);
     unset($attributes2['name']);
     $paramHtml = "";
     foreach ($params as $k => $v) {
         $paramHtml .= Curry_Html::createTag("param", array('name' => $k, 'value' => $v), '', true);
     }
     return array('html' => Curry_Html::createTag("object", array_merge($objectAttr, $attributes), Curry_Html::createTag("param", array('name' => 'movie', 'value' => $source), '', true) . $paramHtml . '<!--[if !IE]>-->' . Curry_Html::createTag("object", array_merge($object2Attr, $attributes2), $paramHtml . '<!--<![endif]-->' . $options['alternativeContent'] . '<!--[if !IE]>-->') . '<!--<![endif]-->'), 'script' => 'swfobject.registerObject("' . $options['target'] . '", "' . $version . '"' . ($options['expressInstall'] ? ', "' . $options['expressInstall'] . '"' : '') . ');');
 }
Пример #5
0
 public function getHtml($params)
 {
     $parentAction = isset($params['action']) ? $params['action'] . '.' : '';
     $options = $this->options;
     $baseUrl = (string) url('', $_GET)->remove('curry_context');
     $options['url'] = (string) url($baseUrl)->add(array('_parent' => array_diff_key($params, array('module' => '', 'view' => '', 'action' => '')), 'action' => $parentAction . 'json'));
     if ($options['sortable']) {
         $options['sortable'] = (string) url($baseUrl)->remove('item')->add(array('_parent' => array_diff_key($params, array('module' => '', 'view' => '', 'action' => '')), 'action' => $parentAction . 'sort'));
     }
     $options['actions'] = array();
     foreach ($this->actions as $name => $action) {
         if (isset($action['action']) && !isset($action['href'])) {
             $action['href'] = (string) url($baseUrl)->remove('item')->add(array('_parent' => array_diff_key($params, array('module' => '', 'view' => '', 'action' => '')), 'action' => $parentAction . $name));
             unset($action['action']);
         }
         $allowed = array('label', 'href', 'class', 'single', 'multi', 'general');
         $options['actions'][$name] = array_intersect_key($action, array_flip($allowed));
     }
     $options['columns'] = array();
     foreach ($this->columns as $name => $column) {
         $allowed = array('label', 'sortable', 'escape', 'action', 'hide');
         $options['columns'][$name] = array_intersect_key($column, array_flip($allowed));
     }
     $allowed = array('title', 'url', 'model', 'paginate', 'maxPerPage', 'currentPage', 'numItems', 'sortable', 'quickSearch', 'actions', 'columns', 'idColumn');
     $options = array_intersect_key($options, array_flip($allowed));
     $options = Zend_Json::encode($options, false, array('enableJsonExprFinder' => true));
     return Curry_Html::createTag('div', array('class' => 'modelview', 'data-modelview' => $options));
 }
Пример #6
0
 /**
  * Edit / Save picture via pixlr
  *
  * @todo not very clever to send the logintoken to a 3rd party service...
  */
 public function showPixlrEdit()
 {
     $image = $_GET['image'];
     $physical = self::virtualToPhysical(self::publicToVirtual($image));
     if (!self::isPhysicalWritable($physical)) {
         throw new Exception('Access denied');
     }
     $user = User::getUser();
     $mtime = filemtime($image);
     $imageUrl = url($image . '?' . $mtime)->getAbsolute();
     $saveParams = array('module', 'view' => 'PixlrSave', 'original' => $image);
     if (!isset($_COOKIE[User::COOKIE_NAME])) {
         $saveParams['logintoken'] = $user->getLoginToken(1440);
     }
     $saveParams['digest'] = hash_hmac('sha1', $image, $user->getPassword());
     $saveUrl = url('', $saveParams)->getAbsolute();
     $exitUrl = url('', array('module', 'view' => 'PixlrExit'))->getAbsolute();
     $pixlrUrl = url('http://pixlr.com/editor/', array('target' => $saveUrl, 'exit' => $exitUrl, 'method' => 'get', 'image' => $imageUrl, 'referrer' => Curry_Core::$config->curry->name, 'title' => basename($image)));
     $this->addMainContent(Curry_Html::createTag('iframe', array('frameborder' => 0, 'style' => 'width: 100%; height: 100%; border: none; display: block;', 'src' => $pixlrUrl)));
 }
Пример #7
0
 /**
  * Send error notification email.
  *
  * @param Exception $e
  */
 public static function sendErrorNotification(Exception $e)
 {
     try {
         // Create form to recreate error
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $hidden = Curry_Html::createHiddenFields($method == 'POST' ? $_POST : $_GET);
         $action = url(Curry_URL::getRequestUri())->getAbsolute();
         $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>';
         // Create mail
         $mail = new Curry_Mail();
         $mail->addTo(Curry_Core::$config->curry->adminEmail);
         $mail->setSubject('Error on ' . Curry_Core::$config->curry->name);
         $mail->setBodyHtml('<html><body>' . '<h1>' . get_class($e) . '</h1>' . '<h2>' . htmlspecialchars($e->getMessage()) . '</h2>' . '<p><strong>Method:</strong> ' . $method . '<br/>' . '<strong>URL:</strong> ' . $action . '<br/>' . '<strong>File:</strong> ' . htmlspecialchars($e->getFile()) . '(' . $e->getLine() . ')</p>' . '<h2>Recreate</h2>' . $form . '<h2>Trace</h2>' . '<pre>' . htmlspecialchars($e->getTraceAsString()) . '</pre>' . '<h2>Variables</h2>' . '<h3>$_GET</h3>' . '<pre>' . htmlspecialchars(print_r($_GET, true)) . '</pre>' . '<h3>$_POST</h3>' . '<pre>' . htmlspecialchars(print_r($_POST, true)) . '</pre>' . '<h3>$_SERVER</h3>' . '<pre>' . htmlspecialchars(print_r($_SERVER, true)) . '</pre>' . '</body></html>');
         $mail->send();
         trace_notice('Sent error notification');
     } catch (Exception $e) {
         trace_warning('Failed to send error notification');
     }
 }
Пример #8
0
 /**
  * Scan table for errors.
  * 
  * @param string $table
  * @param bool $fix
  * @param bool $delete
  * @param Curry_Backend|null $backend
  * @return int Number of invalid rows.
  */
 public static function scanTable($table, $fix, $delete, $backend = null)
 {
     $query = PropelQuery::from($table);
     $tableMap = $query->getTableMap();
     $numInvalidRows = 0;
     foreach ($query->find() as $obj) {
         if ($obj->isDeleted()) {
             continue;
         }
         $objName = 'PK(' . join(',', (array) $obj->getPrimaryKey()) . ')';
         // Check all columns for errors
         $error = array();
         foreach ($tableMap->getColumns() as $column) {
             $columnName = $column->getPhpName();
             $columnValue = $obj->{'get' . $columnName}();
             if ($columnValue === null) {
                 if ($column->isNotNull()) {
                     $error[] = "required {$columnName} = {$columnValue} is null";
                 }
                 continue;
             }
             if ($column->isForeignKey()) {
                 $relObjects = PropelQuery::from($column->getRelatedTable()->getPhpName())->filterBy($column->getRelatedColumn()->getPhpName(), $columnValue)->limit(1)->count();
                 if (!$relObjects) {
                     if ($column->isNotNull()) {
                         if ($delete) {
                             if ($backend) {
                                 $backend->addMessage("Deleting {$objName} (required {$columnName} was invalid).", Curry_Backend::MSG_WARNING);
                             }
                             $obj->delete();
                             $error = array();
                             break;
                             // dont have to check the other columns
                         } else {
                             $error[] = "required {$columnName} = {$columnValue} is invalid";
                         }
                     } else {
                         if ($fix) {
                             // attempt to fix
                             if ($backend) {
                                 $backend->addMessage("Fixing {$objName} (invalid {$columnName} will be set to null).", Curry_Backend::MSG_WARNING);
                             }
                             $obj->{'set' . $column->getPhpName()}(null);
                             $obj->save();
                         } else {
                             $error[] = "{$columnName} = {$columnValue} is invalid";
                         }
                     }
                 }
             }
         }
         if (count($error)) {
             ++$numInvalidRows;
             if ($backend) {
                 // Add message with link to edit row
                 $url = (string) url('', array('module' => 'Curry_Backend_Database', 'view' => 'Row', 'table' => $table, 'pk' => self::getObjectPk($obj)));
                 $link = Curry_Html::createTag('a', array('href' => $url, 'title' => 'Edit ' . $objName, 'class' => 'dialog'), $objName);
                 $backend->addMessage("{$link}: " . join(', ', $error) . '.', Curry_Backend::MSG_WARNING, false);
             }
         }
     }
     return $numInvalidRows;
 }
Пример #9
0
 /**
  * Get page permission table row.
  *
  * @param Page $page
  * @param string $name
  * @param User|null $user
  * @param UserRole|null $role
  * @return string
  */
 protected static function getPagePermissionRow(Page $page, $name, User $user = null, UserRole $role = null)
 {
     $inheritPermission = $page->getPageAccess($user, $role ? $role : ($user ? $user->getUserRole() : null));
     $userPermission = Curry_Backend_Page::getPagePermission($page);
     $access = PageAccessQuery::create()->filterByPage($page)->filterByUserAndRole($user, $role)->findOne();
     $row = '';
     foreach (PageAccess::getPermissionTypes() as $colName => $phpName) {
         $fieldName = $name . '[' . $colName . ']';
         $val = $access ? $access->{'get' . $phpName}() : null;
         if ($colName == PageAccessPeer::PERM_SUBPAGES) {
             if ($val === null) {
                 $val = $inheritPermission[$colName];
             }
             $row .= '<td><input type="hidden" name="' . $fieldName . '" value="no" /><input type="checkbox" name="' . $fieldName . '" value="yes" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . ($val ? 'checked="checked" ' : '') . '/></td>';
             continue;
         }
         $options = array('' => '(inherited)', 'yes' => 'Yes', 'no' => 'No');
         if ($val === null) {
             $options[''] = ($inheritPermission[$colName] ? 'Yes ' : 'No ') . $options[''];
         }
         $val = $val === null ? '' : ($val ? 'yes' : 'no');
         $selectedColor = 'black';
         $opts = '';
         foreach ($options as $optionValue => $optionLabel) {
             $attr = array('value' => $optionValue);
             $color = $optionValue ? $optionValue == 'yes' ? 'green' : 'red' : '#aaa';
             $attr['style'] = 'color:' . $color;
             if ($optionValue === $val) {
                 $selectedColor = $color;
                 $attr['selected'] = 'selected';
             }
             $opts .= Curry_Html::createTag('option', $attr, $optionLabel);
         }
         $row .= '<td><select name="' . $fieldName . '" ' . ($userPermission[$colName] ? '' : 'disabled="disabled" ') . 'style="color:' . $selectedColor . '" onchange="this.style.color = this.options[this.selectedIndex].style.color">';
         $row .= $opts;
         $row .= '</select></td>';
     }
     return $row;
 }