コード例 #1
0
ファイル: locale.php プロジェクト: BackupTheBerlios/tip
 protected static function checkOptions(&$options)
 {
     if (!isset($options['locale'])) {
         return false;
     }
     // The 'data' option must be defined before calling parent::checkOptions()
     // so I can force the 'fieldset' option on the 'data' object
     isset($options['data']) || ($options['data'] = $options['id']);
     if (is_string($options['data'])) {
         $options['data'] = array('path' => TIP_Application::getGlobal('data_prefix') . $options['data'], 'fieldset' => array('id', $options['locale']));
     }
     return parent::checkOptions($options);
 }
コード例 #2
0
ファイル: template.php プロジェクト: BackupTheBerlios/tip
 /**
  * Check the options
  *
  * Builds an unique 'id' from the 'path' option (required).
  * It also checks for the template engine definition and
  * builds the template path, by checking its existence inside
  * "template_root" directory before and in "fallback_root" after.
  *
  * @param  array &$options Properties values
  * @return bool            true on success or false on error
  */
 protected static function checkOptions(&$options)
 {
     if (!isset($options['engine'])) {
         $options['engine'] =& TIP_Application::getGlobal('engine');
     }
     if (!isset($options['path']) || !$options['engine'] instanceof TIP_Template_Engine) {
         return false;
     }
     $path =& $options['path'];
     $engine =& $options['engine'];
     if (is_null($path = $engine->getTemplatePath($path))) {
         return false;
     }
     $options['id'] = implode(DIRECTORY_SEPARATOR, $path);
     return parent::checkOptions($options);
 }
コード例 #3
0
ファイル: application.php プロジェクト: BackupTheBerlios/tip
 public static function setRobots($index, $follow)
 {
     $robots =& TIP_Application::getGlobal('robots');
     $values = explode(',', $robots);
     if (is_bool($index)) {
         if ($index) {
             $old_value = 'noindex';
             $new_value = 'index';
         } else {
             $old_value = 'index';
             $new_value = 'noindex';
         }
         if (!in_array($new_value, $values)) {
             $key = array_search($old_value, $values);
             $key === false && ($key = count($values));
             $values[$key] = $new_value;
         }
     }
     if (is_bool($follow)) {
         if ($follow) {
             $old_value = 'nofollow';
             $new_value = 'follow';
         } else {
             $old_value = 'follow';
             $new_value = 'nofollow';
         }
         if (!in_array($new_value, $values)) {
             $key = array_search($old_value, $values);
             $key === false && ($key = count($values));
             $values[$key] = $new_value;
         }
     }
     $robots = implode(',', $values);
 }
コード例 #4
0
ファイル: content.php プロジェクト: BackupTheBerlios/tip
 /**
  * Perform the browse query throught a pager
  *
  * $params is a string in the form "quanto,query_adds".
  *
  * The quanto is the number of rows per page: leave it undefined to disable
  * the pager. In query_adds you can specify additional SQL commands to
  * append to the query, such as ORDER clauses.
  *
  * This function checks if there is a row more than what specified in the
  * quanto: this provides a simple way to know whether the 'NEXT' button
  * must be rendered or not.
  */
 protected function tagPager($params)
 {
     if (is_null($this->_pager_conditions)) {
         TIP::error('no active browse action');
         return null;
     }
     @(list($quanto, $query_template) = explode(',', $params, 2));
     $quanto = (int) $quanto;
     $pager = $quanto > 0;
     if (empty($this->_pager_conditions)) {
     } elseif (is_array($this->_pager_conditions)) {
         $conditions = array();
         foreach ($this->_pager_conditions as $id => $value) {
             $conditions[] = $this->getData()->addFilter('', $id, $value);
         }
         $filter = 'WHERE (' . implode(' AND ', $conditions) . ')';
     } elseif (empty($this->search_field)) {
         $filter = $this->_pager_conditions;
     } else {
         is_string($this->search_field) && ($this->search_field = explode(',', $this->search_field));
         $this->_search_tokens = explode(' ', $this->_pager_conditions);
         $pattern = '%' . implode('%', $this->_search_tokens) . '%';
         $conditions = array();
         foreach ($this->search_field as $id) {
             $conditions[] = $this->getData()->addFilter('', $id, $pattern, 'LIKE');
         }
         $filter = 'WHERE (' . implode(' OR ', $conditions) . ')';
     }
     if (isset($filter)) {
         $filter .= ' ' . $query_template;
     } else {
         $filter = $query_template;
     }
     $filter .= $this->getData()->order($this->default_order);
     if ($pager) {
         $offset = TIP::getGet('pg_offset', 'int');
         $offset > 0 || ($offset = 0);
         $filter .= $this->getData()->limit($quanto + 1, $offset);
     } else {
         $offset = 0;
     }
     if (is_null($view = $this->startDataView($filter))) {
         TIP::notifyError('select');
         $this->_search_tokens = null;
         return null;
     }
     ob_start();
     if (!$view->isValid()) {
         $this->tryRun(array($main_id, $this->pager_empty_template));
     } else {
         $main_id = TIP_Application::getGlobal('id');
         $partial = $pager && $view->nRows() == $quanto + 1;
         if ($partial) {
             // Remove the trailing row from the view
             $rows =& $view->getProperty('rows');
             array_splice($rows, $quanto);
         }
         if ($pager) {
             if ($offset > 0) {
                 $this->keys['PREV'] = TIP::modifyActionUri(null, null, null, array('pg_offset' => $offset - $quanto > 0 ? $offset - $quanto : 0));
             }
             if ($partial) {
                 $this->keys['NEXT'] = TIP::modifyActionUri(null, null, null, array('pg_offset' => $offset + $quanto));
             }
             $pager = $partial || $offset > 0;
         }
         // Pager rendering BEFORE the rows
         $pager && $this->tryRun(array($main_id, $this->pager_pre_template));
         // Rows rendering
         $empty = true;
         $path = array($this->id, $this->pager_template);
         foreach ($view as $row) {
             $this->run($path);
             $empty = false;
         }
         // Empty result set
         $empty && $this->tryRun(array($main_id, $this->pager_empty_template));
         // Pager rendering AFTER the rows
         $pager && $this->tryRun(array($main_id, $this->pager_post_template));
     }
     $this->endView();
     $this->_search_tokens = null;
     return ob_get_clean();
 }
コード例 #5
0
ファイル: form.php プロジェクト: BackupTheBerlios/tip
 /**
  * Render the form
  *
  * @param  bool|null $valid Whether the form was validated
  * @return bool             true if the renderer was performed,
  *                          false on errors
  */
 public function render($valid)
 {
     $mode = $valid === false ? $this->invalid_render : $this->valid_render;
     if ($mode == TIP_FORM_RENDER_NOTHING) {
         return true;
     } elseif ($mode == TIP_FORM_RENDER_REDIRECT) {
         // Pass a notification message throught the session
         if ($valid === false) {
             $notify = array(TIP_SEVERITY_ERROR, $this->action_id);
         } elseif ($this->notify_done) {
             $notify = array(TIP_SEVERITY_INFO, 'done');
         }
         isset($notify) && HTTP_Session2::set('notify', $notify);
         // Forcibly close the current session
         HTTP_Session2::pause();
         // Perform the redirection
         HTTP::redirect($this->follower, true);
     }
     if ($this->_stage > 1) {
         foreach ($this->_trailing_elements as &$element) {
             // Update the tabindex property
             ++$this->_tabindex;
             $element->setAttribute('tabindex', $this->_tabindex);
             $this->_form->addElement($element);
         }
     }
     // Execute the prerender callbacks
     foreach ($this->_prerender as $field => $data) {
         call_user_func_array($data['callback'], $data['args']);
     }
     // Add buttons
     $this->_addButtons($valid);
     // Form template initialization
     $template =& TIP_Application::getSharedTemplate($this->form_template);
     if (is_null($template)) {
         TIP::error("form template not found ({$this->form_template})");
         return false;
     }
     $this->_form->setRequiredNote($this->getLocale('label.requirednote'));
     // Some global keys
     $this->keys['ATTRIBUTES'] = $this->_form->getAttributes(true);
     // DEPRECATED: the tag {form(getRequiredNote)} must be used instead
     $this->keys['REQUIREDNOTE'] = $this->_form->getRequiredNote();
     // Populate the array (if not yet done)
     if (is_null($this->_array)) {
         $renderer =& TIP_Renderer::getForm();
         $this->_form->accept($renderer);
         $this->_array = $renderer->toArray();
     }
     // Call the renderer
     if ($mode == TIP_FORM_RENDER_IN_PAGE) {
         $content =& TIP_Application::getGlobal('content');
         ob_start();
         $done = $template->run($this);
         $content .= ob_get_clean();
     } else {
         $done = $template->run($this);
     }
     return $done;
 }
コード例 #6
0
ファイル: devhelp2.php プロジェクト: BackupTheBerlios/tip
 /**
  * Perform a view action
  *
  * Runs the file identified by the 'view_template' property for the
  * specified row. The rendered result is appended to the page.
  *
  * @param  mixed $id The identifier of the row to view
  * @return bool      true on success or false on errors
  */
 protected function actionView($id)
 {
     // The query is not strictly necessary but it is still performed
     // to avoid read actions on arbitrary files
     if (is_null($row =& $this->fromRow($id, false)) || !$this->_onView($row)) {
         return false;
     }
     // Check for html file existence
     $file = TIP::buildDataPath($this->id, $id);
     if (!is_readable($file)) {
         $this->endView();
         return false;
     }
     $content =& TIP_Application::getGlobal('content');
     $this->keys['id'] = $id;
     $this->keys[$this->title_field] = str_replace('.html', '', $id);
     $this->keys['content'] = file_get_contents($file);
     $this->keys[$this->creation_field] = TIP::formatDate('datetime_sql', filectime($file));
     $this->keys[$this->edited_field] = TIP::formatDate('datetime_sql', filemtime($file));
     if (empty($this->view_template)) {
         // On empty template, output the whole html file content
         // and set a viable "title" metatag
         $content .= $this->keys['content'];
         $title =& TIP_Application::getGlobal('title');
         $title = $this->keys[$this->title_field] . ' (' . $title . ')';
     } else {
         // Use a custom template
         $content .= $this->tagRun($this->view_template);
     }
     // Discard the generated content to decrease memory consumption
     unset($this->keys);
     $this->endView();
     return true;
 }
コード例 #7
0
ファイル: Type.php プロジェクト: BackupTheBerlios/tip
 /**
  * Type instantiation
  *
  * Gets the singleton of a configured object. $id could be any identifier
  * defined in $GLOBALS['cfg'].
  *
  * An internal register is mantained to avoid singleton() calls with the
  * same $id.
  *
  * @param  mixed    $id       Instance identifier
  * @param  bool     $required true if errors must be fatals
  * @return TIP_Type           The reference to the requested instance or
  *                            false on errors
  */
 public static function &getInstance($id, $required = true)
 {
     static $register = array();
     global $cfg;
     $id = strtolower($id);
     if (class_exists('TIP_Application')) {
         $namespace = TIP_Application::getGlobal('namespace');
         if (!empty($namespace) && isset($cfg[$namespace . '_' . $id])) {
             $id = $namespace . '_' . $id;
         }
     }
     if (array_key_exists($id, $register)) {
         return $register[$id];
     }
     if (isset($cfg[$id])) {
         $options = $cfg[$id];
         isset($options['id']) || ($options['id'] = $id);
         $instance =& TIP_Type::singleton($options);
     } else {
         $instance = null;
     }
     if (is_null($instance) && $required) {
         TIP::fatal("unable to instantiate the requested object ({$id})");
         exit;
     }
     $register[$id] =& $instance;
     return $instance;
 }
コード例 #8
0
ファイル: module.php プロジェクト: BackupTheBerlios/tip
 /**
  * Build an icon URI
  */
 protected function tagIconUri()
 {
     $pieces = func_get_args();
     return TIP::buildUri(TIP_Application::getGlobal('icon_root'), $pieces);
 }
コード例 #9
0
ファイル: TIP.php プロジェクト: BackupTheBerlios/tip
 /**
  * Get the default fallback privilege for the specified module
  *
  * Returns the default privilege for a module and a specified user.
  *
  * @param  string           $module The requesting module identifier
  * @param  mixed            $user   A user id
  * @return TIP_PRIVILEGE...         The requested privilege
  */
 public static function getDefaultPrivilege($module, $user)
 {
     $privilege_type = $user ? 'default_privilege' : 'anonymous_privilege';
     $result = @$GLOBALS['cfg'][(string) $module][$privilege_type];
     if (is_null($result)) {
         $result = TIP_Application::getGlobal($privilege_type);
     }
     return $result;
 }
コード例 #10
0
ファイル: chronology.php プロジェクト: BackupTheBerlios/tip
 /**
  * Perform a browse action
  *
  * In $conditions, you must specify an associative array of
  * 'field_id' => 'value' to impose for this browse action. Only equal
  * conditions are allowed.
  *
  * @param  array &$conditions The browse conditions
  * @return bool               true on success or false on errors
  */
 protected function actionBrowse($id)
 {
     if (!TIP_AHAH) {
         // Browse actions implemented only as AHAH response
         return false;
     }
     sscanf($id, '%04s%02s', $year, $month);
     if (!$year || !$this->_render()) {
         return false;
     }
     if (array_key_exists($year, $this->_tree)) {
         $tree =& $this->_tree[$year]['sub'];
     } else {
         return true;
     }
     if (array_key_exists($id, $tree)) {
         $tree =& $tree[$id]['sub'];
     } elseif (isset($month)) {
         return true;
     }
     require_once 'HTML/Menu.php';
     $model =& new HTML_Menu($tree);
     $renderer =& TIP_Renderer::getMenu(0);
     $model->render($renderer, 'sitemap');
     $content =& TIP_Application::getGlobal('content');
     $content .= $renderer->toHtml();
     return true;
 }