/** * * @param string $file. The name of the plugin file * * Delete the special silo permissions if they're no longer * being used. */ public function action_plugin_deactivation( $file ) { $silos = Plugins::get_by_interface( 'MediaSilo' ); if ( count( $silos ) <= 1 ) { ACL::destroy_token( 'upload_media' ); ACL::destroy_token( 'delete_media' ); ACL::destroy_token( 'create_directories' ); ACL::destroy_token( 'delete_directories' ); } }
public function action_handler_dev_feed($handler_vars) { $rss = Plugins::get_by_interface('RSS'); if (count($rss) !== 1) { exit; } $xml = reset($rss)->create_rss_wrapper(); $connection_string = Options::get('tracfeed__connection_string'); $username = Options::get('tracfeed__username'); $password = Options::get('tracfeed__password'); $db = DatabaseConnection::ConnectionFactory($connection_string); $db->connect($connection_string, $username, $password); $times = $db->get_column('SELECT time from ticket_change group by time order by time desc limit 15;'); $mintime = array_reduce($times, 'min', reset($times)); $comments = $db->get_results("\n\t\t\tSELECT *, ticket_change.time as changetime from ticket_change \n\t\t\tINNER JOIN ticket on ticket.id = ticket_change.ticket\n\t\t\twhere \n\t\t\tchangetime >= ? and\n\t\t\tnot (field ='comment' and newvalue = '') \n\t\t\torder by ticket_change.time DESC;\n\t\t", array($mintime)); $posts = array(); foreach ($comments as $comment) { $post_id = md5($comment->ticket . ':' . $comment->changetime . ':' . $comment->author); if (!array_key_exists($post_id, $posts)) { $post = new Post(); $post->title = "Ticket #{$comment->ticket}: {$comment->summary}"; $post->content = "Changes by {$comment->author} on ticket <a href=\"http://trac.habariproject.org/habari/ticket/{$comment->ticket}\">#{$comment->ticket}</a>.\n<br>\n<br>"; $post->guid = 'tag:' . Site::get_url('hostname') . ',trac_comment,' . $post_id; $post->content_type = 'dev_feed'; $post->slug = "http://trac.habariproject.org/habari/ticket/{$comment->ticket}"; $post->pubdate = date('r', $comment->changetime); $posts[$post_id] = $post; } else { $post = $posts[$post_id]; } switch ($comment->field) { case 'comment': $content = $comment->newvalue; $content = preg_replace('/\\b(https?|ftp|file):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|]/i', '<a href="$0">[link]</a>', $content); $content = preg_replace('%\\br([0-9]+)\\b%', '<a href="http://trac.habariproject.org/habari/changeset/$1">r$1</a>', $content); $content = preg_replace('%\\b#([0-9]+)\\b%', '<a href="http://trac.habariproject.org/habari/ticket/$1">$1</a>', $content); $post->content .= "Comment #{$comment->oldvalue} by {$comment->author}:\n<blockquote><pre>{$content}</pre></blockquote>\n<br>"; break; default: if (trim($comment->oldvalue) == '') { $post->content .= "Set <b>{$comment->field}</b> to: {$comment->newvalue}\n<br>"; } else { $post->content .= "Changed <b>{$comment->field}</b> from: {$comment->oldvalue}\n<br> To: {$comment->newvalue}\n<br>"; } break; } } $xml = RSS::add_posts($xml, $posts); ob_clean(); header('Content-Type: application/xml'); echo $xml->asXML(); exit; }
/** * Returns a form for editing this post * @param string $context The context the form is being created in, most often 'admin' * @return FormUI A form appropriate for creating and updating this post. */ public function get_form( $context ) { $form = new FormUI( 'create-content' ); $form->class[] = 'create'; $newpost = ( 0 === $this->id ); // If the post has already been saved, add a link to its permalink if ( !$newpost ) { $post_links = $form->append( 'wrapper', 'post_links' ); $permalink = ( $this->status != Post::status( 'published' ) ) ? $this->permalink . '?preview=1' : $this->permalink; $post_links->append( 'static', 'post_permalink', '<a href="'. $permalink .'" class="viewpost" >'.( $this->status != Post::status( 'published' ) ? _t( 'Preview Post' ) : _t( 'View Post' ) ).'</a>' ); $post_links->class ='container'; } // Create the Title field $form->append( 'text', 'title', 'null:null', _t( 'Title' ), 'admincontrol_text' ); $form->title->class[] = 'important'; $form->title->class[] = 'check-change'; $form->title->tabindex = 1; $form->title->value = $this->title; // Create the silos if ( count( Plugins::get_by_interface( 'MediaSilo' ) ) ) { $form->append( 'silos', 'silos' ); $form->silos->silos = Media::dir(); } // Create the Content field $form->append( 'textarea', 'content', 'null:null', _t( 'Content' ), 'admincontrol_textarea' ); $form->content->class[] = 'resizable'; $form->content->class[] = 'check-change'; $form->content->tabindex = 2; $form->content->value = $this->content; $form->content->raw = true; // Create the tags field $form->append( 'text', 'tags', 'null:null', _t( 'Tags, separated by, commas' ), 'admincontrol_text' ); $form->tags->class = 'check-change'; $form->tags->tabindex = 3; $tags = (array)$this->get_tags(); array_map( create_function( '$a', '$a->term_display = MultiByte::strpos( $a->term_display, \',\' ) === false ? $a->term_display : $a->tag_text_searchable;' ), $tags ); $form->tags->value = implode( ', ', $tags ); // Create the splitter $publish_controls = $form->append( 'tabs', 'publish_controls' ); // Create the publishing controls // pass "false" to list_post_statuses() so that we don't include internal post statuses $statuses = Post::list_post_statuses( $this ); unset( $statuses[array_search( 'any', $statuses )] ); $statuses = Plugins::filter( 'admin_publish_list_post_statuses', $statuses ); $settings = $publish_controls->append( 'fieldset', 'settings', _t( 'Settings' ) ); $settings->append( 'select', 'status', 'null:null', _t( 'Content State' ), array_flip( $statuses ), 'tabcontrol_select' ); $settings->status->value = $this->status; // hide the minor edit checkbox if the post is new if ( $newpost ) { $settings->append( 'hidden', 'minor_edit', 'null:null' ); $settings->minor_edit->value = false; } else { $settings->append( 'checkbox', 'minor_edit', 'null:null', _t( 'Minor Edit' ), 'tabcontrol_checkbox' ); $settings->minor_edit->value = true; $form->append( 'hidden', 'modified', 'null:null' )->value = $this->modified; } $settings->append( 'checkbox', 'comments_enabled', 'null:null', _t( 'Comments Allowed' ), 'tabcontrol_checkbox' ); $settings->comments_enabled->value = $this->info->comments_disabled ? false : true; $settings->append( 'text', 'pubdate', 'null:null', _t( 'Publication Time' ), 'tabcontrol_text' ); $settings->pubdate->value = $this->pubdate->format( 'Y-m-d H:i:s' ); $settings->pubdate->helptext = _t( 'YYYY-MM-DD HH:MM:SS' ); $settings->append( 'hidden', 'updated', 'null:null' ); $settings->updated->value = $this->updated->int; $settings->append( 'text', 'newslug', 'null:null', _t( 'Content Address' ), 'tabcontrol_text' ); $settings->newslug->value = $this->slug; // Create the button area $buttons = $form->append( 'fieldset', 'buttons' ); $buttons->template = 'admincontrol_buttons'; $buttons->class[] = 'container'; $buttons->class[] = 'buttons'; $buttons->class[] = 'publish'; // Create the Save button $require_any = array( 'own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name( $this->content_type ) => 'create' ); if ( ( $newpost && User::identify()->can_any( $require_any ) ) || ( !$newpost && ACL::access_check( $this->get_access(), 'edit' ) ) ) { $buttons->append( 'submit', 'save', _t( 'Save' ), 'admincontrol_submit' ); $buttons->save->tabindex = 4; } // Add required hidden controls $form->append( 'hidden', 'content_type', 'null:null' ); $form->content_type->id = 'content_type'; $form->content_type->value = $this->content_type; $form->append( 'hidden', 'post_id', 'null:null' ); $form->post_id->id = 'id'; $form->post_id->value = $this->id; $form->append( 'hidden', 'slug', 'null:null' ); $form->slug->value = $this->slug; $form->on_success(array($this, 'form_publish_success')); // Let plugins alter this form Plugins::act( 'form_publish', $form, $this, $context ); // Return the form object return $form; }
/** * function load_all * Loads and stores an instance of all declared Format classes for future use **/ public static function load_all() { self::$formatters = array(); $classes = get_declared_classes(); foreach ($classes as $class) { if (get_parent_class($class) == 'Format' || $class == 'Format') { self::$formatters[] = new $class(); } } self::$formatters = array_merge(self::$formatters, Plugins::get_by_interface('FormatPlugin')); self::$formatters = array_reverse(self::$formatters, true); }
/** * Initialize the internal list of silo instances */ public static function init_silos() { if (empty(self::$silos)) { $tempsilos = Plugins::get_by_interface('MediaSilo'); self::$silos = array(); foreach ($tempsilos as $eachsilo) { $info = $eachsilo->silo_info(); if (isset($info['name'])) { self::$silos[$info['name']] = $eachsilo; } } } }
public function addon_success($form) { $plugins = Plugins::get_by_interface('PostReceive'); var_dump($plugins); $plugin = reset($plugins); var_dump($plugin->process_update(html_entity_decode($form->json->value))); }
/** * Returns a form for editing this post * @param string $context The context the form is being created in, most often 'admin' * @return FormUI A form appropriate for creating and updating this post. */ public function get_form($context) { /** @var FormUI $form */ $form = new FormUI('create-content', null, array('class' => array('create'))); $form->set_wrap_each('<div class="container">%s</div>'); $newpost = 0 === $this->id; // If the post has already been saved, add a link to its permalink if (!$newpost) { /** @var FormControlWrapper $post_links */ $post_links = $form->append(FormControlWrapper::create('post_links', null, array('class' => 'container'))); $permalink = $this->status != Post::status('published') ? $this->permalink . '?preview=1' : $this->permalink; $post_links->append(FormControlStatic::create('post_permalink')->set_static('<a href="' . $permalink . '" class="viewpost" >' . ($this->status != Post::status('published') ? _t('Preview Post') : _t('View Post')) . '</a>')); } // Store this post instance into a hidden field for later use when saving data $form->append(FormControlData::create('post')->set_value($this)); // Create the Title field $form->append(FormControlLabel::wrap(_t('Title'), FormControlText::create('title', null, array('class' => array('check-change full-width')))->set_value($this->title_internal))); // Create the silos if (count(Plugins::get_by_interface('MediaSilo'))) { $silos = FormControlSilos::create('silos')->set_setting('wrap', '<div class="container silos">%s</div>'); $form->append($silos); } // Create the Content field $form->append(FormControlLabel::wrap(_t('Content'), FormControlTextArea::create('content', null, array('class' => array('resizable', 'check-change full-width rte')))->set_value($this->content_internal))); $form->content->raw = true; // @todo What does this do? // Create the tags field /** @var FormControlAutocomplete $tags_control */ $form->append(FormControlLabel::wrap(_t('Tags, separated by, commas'), $tags_control = FormControlAutocomplete::create('tags', null, array('style' => 'width:100%;margin:0px 0px 20px;', 'class' => 'check-change full-width'), array('allow_new' => true, 'init_selection' => true)))->set_properties(array('style' => 'width:100%;margin:0px 0px 20px;'))); $tags = (array) $this->get_tags(); array_walk($tags, function (&$element, $key) { $element->term_display = MultiByte::strpos($element->term_display, ',') === false ? $element->term_display : $element->tag_text_searchable; }); $tags_control->set_value(implode(',', $tags)); $tags_control->set_ajax(URL::auth_ajax('tag_list')); // Create the splitter /** @var FormControlTabs $publish_controls */ $publish_controls = $form->append(FormControlTabs::create('publish_controls')->set_setting('wrap', '%s')->set_setting('class_each', 'container')); // Create the publishing controls // pass "false" to list_post_statuses() so that we don't include internal post statuses $statuses = Post::list_post_statuses($this); unset($statuses[array_search('any', $statuses)]); $statuses = Plugins::filter('admin_publish_list_post_statuses', $statuses); /** @var FormControlFieldset $settings */ $settings = $publish_controls->append(FormControlFieldset::create('post_settings')->set_caption(_t('Settings'))); $settings->append(FormControlLabel::wrap(_t('Content State'), FormControlSelect::create('status')->set_options(array_flip($statuses))->set_value($this->status))); // hide the minor edit checkbox if the post is new if ($newpost) { $settings->append(FormControlData::create('minor_edit')->set_value(false)); } else { $settings->append(FormControlLabel::wrap(_t('Minor Edit'), FormControlCheckbox::create('minor_edit')->set_value(true))); $form->append(FormControlData::create('modified')->set_value($this->modified)); } $settings->append(FormControlLabel::wrap(_t('Comments Allowed'), FormControlCheckbox::create('comments_enabled')->set_value($this->info->comments_disabled ? false : true))); $settings->append(FormControlLabel::wrap(_t('Publication Time'), FormControlText::create('pubdate')->set_value($this->pubdate->format('Y-m-d H:i:s')))); $settings->pubdate->set_helptext(_t('YYYY-MM-DD HH:MM:SS')); $settings->append(FormControlData::create('updated')->set_value($this->updated->int)); $settings->append(FormControlLabel::wrap(_t('Content Address'), FormControlText::create('newslug')->set_value($this->slug))); // Create the button area $buttons = $form->append(FormControlFieldset::create('buttons', null, array('class' => array('container', 'buttons', 'publish')))); // What buttons should we have? $require_any = array('own_posts' => 'create', 'post_any' => 'create', 'post_' . Post::type_name($this->content_type) => 'create'); $show_buttons = array(); if ($newpost) { if (User::identify()->can_any($require_any)) { $show_buttons['save'] = true; $show_buttons['publish'] = true; } } else { if (ACL::access_check($this->get_access(), 'edit')) { if ($this->status == Post::status('draft')) { $show_buttons['publish'] = true; } $show_buttons['save'] = true; } if (ACL::access_check($this->get_access(), 'delete')) { $show_buttons['delete'] = true; } } $show_buttons = Plugins::filter('publish_form_buttons', $show_buttons, $this); if (isset($show_buttons['delete'])) { // Create the Delete button $buttons->append(FormControlSubmit::create('delete', null, array('class' => 'three columns'))->set_caption(_t('Delete'))->on_success(array($this, 'form_publish_delete'))); } if (isset($show_buttons['save'])) { // Create the Save button $buttons->append(FormControlSubmit::create('save', null, array('class' => 'three columns'))->set_caption(_t('Save'))); } if (isset($show_buttons['publish'])) { // Create the Publish button $buttons->append(FormControlSubmit::create('publish', null, array('class' => 'three columns'))->set_caption(_t('Publish'))->add_validator(function ($value, FormControlSubmit $control, FormUI $form) { $form->status->set_value(Post::status('published')); $allow = Plugins::filter('post_publish_allow', true, $this); if (!$allow) { return array('Publishing has been denied'); } return array(); })); } // Add required hidden controls $form->append(FormControlData::create('content_type', null, array('id' => 'content_type'))->set_value($this->content_type)); $form->append(FormControlData::create('post_id', null, array('id' => 'id'))->set_value($this->id)); $form->append(FormControlData::create('slug', null, array('id' => 'originalslug'))->set_value($this->slug)); $form->on_success(array($this, 'form_publish_success')); // Let plugins alter this form Plugins::act('form_publish', $form, $this, $context); $content_types = array_flip(Post::list_active_post_types()); Plugins::act('form_publish_' . Utils::slugify($content_types[$this->content_type], '_'), $form, $this, $context); // Return the form object return $form; }