Esempio n. 1
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 = $this->app->index;
         $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 ? Html::tag('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);
     }
 }
Esempio n. 2
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(" ", $page->getLevel() * 3) . $page->getName();
     }
     $options = Html::createSelectOptions($options, '');
     $markup = Html::tag('select', $attr, $options);
     switch ($placement) {
         case 'PREPEND':
             $content = $markup . $separator . $content;
             break;
         case 'APPEND':
         default:
             $content = $content . $separator . $markup;
     }
     return $content;
 }
Esempio n. 3
0
 protected function getPageInheritance($page, $wrappers)
 {
     $ret = Html::tag('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>';
 }
Esempio n. 4
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' => $this->app['name'], 'title' => basename($image)));
     $this->addMainContent(Html::tag('iframe', array('frameborder' => 0, 'style' => 'width: 100%; height: 100%; border: none; display: block;', 'src' => $pixlrUrl)));
 }
Esempio n. 5
0
 /**
  * Scan table for errors.
  * 
  * @param string $table
  * @param bool $fix
  * @param bool $delete
  * @param AbstractLegacyBackend|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).", AbstractBackend::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).", AbstractBackend::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 = Html::tag('a', array('href' => $url, 'title' => 'Edit ' . $objName, 'class' => 'dialog'), $objName);
                 $backend->addMessage("{$link}: " . join(', ', $error) . '.', AbstractBackend::MSG_WARNING, false);
             }
         }
     }
     return $numInvalidRows;
 }
Esempio n. 6
0
 /**
  * Send error notification email.
  *
  * @param Exception $e
  */
 public function sendErrorNotification(Exception $e, Inspector $inspector, Run $run)
 {
     try {
         // Create form to recreate error
         $method = strtoupper($_SERVER['REQUEST_METHOD']);
         $hidden = Html::createHiddenFields($method == 'POST' ? $_POST : $_GET);
         $action = url(URL::getRequestUri())->getAbsolute();
         $form = '<form action="' . $action . '" method="' . $method . '">' . $hidden . '<button type="submit">Execute</button></form>';
         // Compose mail
         $content = '<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>';
         // Create and send mail
         $mail = new Mail();
         $mail->addTo($this['adminEmail']);
         $mail->setSubject('Error on ' . $this['name']);
         $mail->setBodyHtml($content);
         $mail->send();
         $this->logger->info('Sent error notification');
     } catch (Exception $e) {
         $this->logger->error('Failed to send error notification');
     }
     return Handler::DONE;
 }
Esempio n. 7
0
 public function getHtml($params)
 {
     $options = $this->options;
     if (!isset($options['url'])) {
         $options['url'] = $this->parent ? $this->json->url() : (string) url('', $_GET)->add(array('json' => true));
     }
     if ($options['sortable']) {
         $options['sortable'] = 'TODO';
     }
     $options['actions'] = array();
     foreach ($this->actions as $name => $action) {
         if (isset($action['action']) && !isset($action['href'])) {
             if (!$action['action'] instanceof \Curry\View) {
                 throw new \Exception("{$name} action is not of type View");
             }
             $action['href'] = $this->{$name}->url();
             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', 'align', 'width');
         $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 Html::tag('div', array('class' => 'modelview', 'data-modelview' => $options));
 }
Esempio n. 8
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 .= Html::tag('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;
 }