/** * Generate a new slug for the post. * * @return string The slug */ protected function setslug() { $value = ''; // determine the base value from: // - the new slug if (isset($this->newfields['term']) && $this->newfields['term'] != '') { $value = $this->newfields['term']; } elseif ($this->fields['term'] != '') { $value = $this->fields['term']; } elseif (isset($this->newfields['term_display']) && $this->newfields['term_display'] != '') { $value = $this->newfields['term_display']; } elseif ($this->fields['term_display'] != '') { $value = $this->fields['term_display']; } // make sure our slug is unique $slug = Plugins::filter('term_setslug', $value); $slug = Utils::slugify($slug); $postfix = ''; $postfixcount = 0; do { if (!($slugcount = DB::get_row('SELECT COUNT(term) AS ct FROM {terms} WHERE term = ? AND vocabulary_id = ?;', array($slug . $postfix, $this->fields['vocabulary_id'])))) { Utils::debug(DB::get_errors()); exit; } if ($slugcount->ct != 0) { $postfix = "-" . ++$postfixcount; } } while ($slugcount->ct != 0); return $this->newfields['term'] = $slug . $postfix; }
public function action_plugin_activation($file) { DB::register_table('abbrev'); /* * Create the database table, or upgrade it */ $dbms = DB::get_driver_name(); $sql = 'CREATE TABLE ' . DB::table('abbrev') . ' ' . '('; if ($dbms == 'sqlite') { $sql .= 'xid INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,'; } else { if ($dbms == 'mysql') { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } else { $sql .= 'xid INT(9) NOT NULL AUTO_INCREMENT,' . 'UNIQUE KEY xid (xid),'; } } $sql .= 'abbrev VARCHAR(255),' . 'caseful INTEGER DEFAULT 0,' . "prefix VARCHAR(16) DEFAULT '\\b'," . "postfix VARCHAR(16) DEFAULT '\\b'," . 'priority INTEGER DEFAULT 100,' . 'definition VARCHAR(255)' . ')'; if (!DB::dbdelta($sql)) { Utils::debug(DB::get_errors()); } if ($file == str_replace('\\', '/', $this->get_file())) { ACL::create_token(self::PLUGIN_TOKEN, _t('Allow use of Abbrev plugin'), 'Category', false); $group = UserGroup::get_by_name('admin'); $group->grant(self::PLUGIN_TOKEN); } }
public function grab($method, $vars = array()) { $url = 'http://api.flickr.com/services/rest/'; $url .= '?method=' . $method; foreach ($vars as $key => $val) { $url .= '&' . $val . '=' . $val; } Utils::debug($url); }
public function act_uninstall($handler, $theme) { try { $package = HabariPackages::remove($handler->handler_vars['guid']); Session::notice("{$package->name} {$package->version} was uninstalled."); } catch (Exception $e) { Session::error('Could not complete uninstall: ' . $e->getMessage()); if (DEBUG) { Utils::debug($e); } } }
public function action_block_content_textlinkads($block) { if (!Cache::has('textlinkads')) { $request_uri = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : ''; $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ''; $inventory_key = 'NYWSW7HTCIN307VV7BBD'; $tla_uri = 'http://www.text-link-ads.com/xml.php?inventory_key=' . $inventory_key . '&referer=' . urlencode($request_uri) . '&user_agent=' . urlencode($user_agent); Cache::set('textlinkads', RemoteRequest::get_contents($tla_uri)); Utils::debug('Cache set'); } $xml = new SimpleXMLElement(Cache::get('textlinkads')); $links = array(); foreach ($xml->Link as $link) { $ad = new StdClass(); $ad->before = (string) $link->BeforeText; $ad->after = (string) $link->AfterText; $ad->text = (string) $link->Text; $ad->url = (string) $link->URL; $links[(string) $link->LinkID] = $ad; } $block->links = $links; }
/** * The UserThemeHandler's act() method differs from ActionHandler's * act() method in one distinct way: if the Handler's theme variable * registers an override action via Theme->register_action(), then * that function is called instead of the default handler action. * * @param action the action that was in the URL rule * @return bool did the action succeed? */ public function act($action) { $this->action = $action; $action_method = 'act_' . $action; $before_action_method = 'before_' . $action_method; $after_action_method = 'after_' . $action_method; $this->theme->{$before_action_method}(); try { $handled = false; $handled = Plugins::filter('theme_act_' . $action, $handled, $this->theme); if (!$handled) { $this->theme->{$action_method}(); } } catch (Error $e) { EventLog::log($e->humane_error(), 'error', 'theme', 'habari', print_r($e, 1)); Session::error($e->humane_error()); //Should we display any error here? if (DEBUG) { Utils::debug($e); } } $this->theme->{$after_action_method}(); }
/** * The plugin sink for the auth_ajax_drupal_import_comments hook. * Responds via authenticated ajax to requests for comment importing. * * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_drupal_import_comments($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'import_comments', 'commentindex', 'entry_type', 'page_type', 'tag_vocab'); $inputs = array_intersect_key($_POST->getArrayCopy(), array_flip($valid_fields)); extract($inputs); $drupaldb = $this->drupal_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if ($drupaldb) { $commentcount = $drupaldb->get_value("SELECT count( c.cid ) FROM {$db_prefix}comments AS c INNER JOIN {$db_prefix}node AS n ON (n.nid = c.nid) WHERE n.type IN ('{$entry_type}', '{$page_type}')"); $min = $commentindex * DRUPAL_IMPORT_BATCH + 1; $max = min(($commentindex + 1) * DRUPAL_IMPORT_BATCH, $commentcount); echo "<p>Importing comments {$min}-{$max} of {$commentcount}.</p>"; $postinfo = DB::table('postinfo'); $post_info = DB::get_results("SELECT post_id, value FROM {$postinfo} WHERE name= 'drupal_nid';"); foreach ($post_info as $info) { $post_map[$info->value] = $info->post_id; } if ($import_comments) { $comments = $drupaldb->get_results("\n\t\t\t\t\tSELECT\n\t\t\t\t\t\tc.nid as drupal_post_nid,\n\t\t\t\t\t\tc.comment as content,\n\t\t\t\t\t\tc.name,\n\t\t\t\t\t\tc.mail as email,\n\t\t\t\t\t\tc.homepage as url,\n\t\t\t\t\t\tINET_ATON( c.hostname ) as ip,\n\t\t\t\t\t\tc.status,\n\t\t\t\t\t\tFROM_UNIXTIME( c.timestamp ) as date\n\t\t\t\t\tFROM {$db_prefix}comments AS c\n\t\t\t\t\tINNER JOIN {$db_prefix}node AS n on ( n.nid = c.nid )\n\t\t\t\t\tLIMIT {$min}, " . DRUPAL_IMPORT_BATCH, array(), 'Comment'); } else { $comments = array(); } foreach ($comments as $comment) { $comment->type = Comment::COMMENT; $comment->status = $comment->status == '0' ? 1 : 0; $comment->content = MultiByte::convert_encoding($comment->content); $comment->name = MultiByte::convert_encoding($comment->name); $carray = $comment->to_array(); if ($carray['ip'] == '') { $carray['ip'] = 0; } if (!isset($post_map[$carray['drupal_post_nid']])) { Utils::debug($carray); } else { $carray['post_id'] = $post_map[$carray['drupal_post_nid']]; unset($carray['drupal_post_nid']); $c = new Comment($carray); //Utils::debug( $c ); try { $c->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } if ($max < $commentcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'drupal_import_comments')); $commentindex++; echo <<<DRUPAL_IMPORT_AJAX1 \t\t\t\t\t<script type="text/javascript"> \t\t\t\t\t\$( '#import_progress' ).load( \t\t\t\t\t\t"{$ajax_url}", \t\t\t\t\t\t{ \t\t\t\t\t\t\tdb_host: "{$db_host}", \t\t\t\t\t\t\tdb_name: "{$db_name}", \t\t\t\t\t\t\tdb_user: "******", \t\t\t\t\t\t\tdb_pass: "******", \t\t\t\t\t\t\tdb_prefix: "{$db_prefix}", \t\t\t\t\t\t\timport_comments: "{$import_comments}", \t\t\t\t\t\t\tentry_type: "{$entry_type}", \t\t\t\t\t\t\tpage_type: "{$page_type}", \t\t\t\t\t\t\ttag_vocab: "{$tag_vocab}", \t\t\t\t\t\t\tcommentindex: {$commentindex} \t\t\t\t\t\t} \t\t\t\t\t ); \t\t\t\t</script> DRUPAL_IMPORT_AJAX1; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } } } else { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; } }
public function theme_route_download_addon($theme, $url_args) { $addon = Post::get(array('slug' => $url_args['slug'])); if (!$addon) { return; // Don't let people pass weird stuff into here } $version = $url_args['version']; $terms = $this->vocabulary->get_object_terms('addon', $addon->id); foreach ($terms as $term) { if ($version == $this->version_slugify($term)) { if (!isset($term->info->url) || !isset($term->info->hash)) { Utils::debug($term); return; // We must have a download url and a hash to get } // zip file of the requested version is located in /user/files/addon_downloads/{$addonslug}/{$versionslug}/{$hash}/{$addonslug}_{$versionslug}.zip $versiondir = '/files/addon_downloads/' . $addon->slug . '/' . $version . '/'; $dir = $versiondir . $term->info->hash . '/'; $zipfile = Site::get_dir('user') . $dir . $addon->slug . '_' . $version . '.zip'; $zipurl = Site::get_url('user') . $dir . $addon->slug . '_' . $version . '.zip'; if (!is_file($zipfile) || isset($url_args['refresh']) && $url_args['refresh'] == 'refresh') { // File does not yet exist, prepare directories and create it if (is_writable(Site::get_dir('user') . '/files/')) { if (!is_dir(Site::get_dir('user') . $versiondir)) { mkdir(Site::get_dir('user') . $versiondir, 0755, true); } $tmp_dir = sys_get_temp_dir() . '/' . $addon->slug; // Cleanup: Remove copies from older commits exec('rm -rf ' . Site::get_dir('user') . $versiondir . '*'); exec('rm -rf ' . $tmp_dir); exec('rm -rf ' . $zipfile); if (!is_dir(Site::get_dir('user') . $dir)) { mkdir(Site::get_dir('user') . $dir, 0755, true); } Plugins::act('addon_download', $term->info->source, $addon, $term, $tmp_dir); if (count(scandir($tmp_dir)) > 2) { exec('cd ' . $tmp_dir . ' && zip -9 -r ' . $zipfile . ' *'); } } } if (is_file($zipfile)) { // Everything worked fine - or the file already existed Utils::redirect($zipurl); } } } }
public function action_upgrade($oldversion) { Utils::debug('upgrade ' . $oldversion); die; }
public function action_handler_display_snippets($handler_vars) { Utils::debug($handler_vars); exit; }
public function dbg($var, $tipo = 2) { return Utils::debug($var, $tipo); }
function do_stupid_things_in_global_scope() { /** * Test for the RemoteRequest class. */ include '../htdocs/system/classes/remoterequest.php'; include '../htdocs/system/classes/curlrequestprocessor.php'; include '../htdocs/system/classes/socketrequestprocessor.php'; include '../htdocs/system/classes/utils.php'; include '../htdocs/system/classes/error.php'; error_reporting(E_ALL | E_STRICT); function bs($v) { return $v ? 'TRUE' : 'FALSE'; } $tests_failed = array(); $tests = array('GET http://test.habariproject.org/' => array("\$res"), 'GET http://test.habariproject.org/get' => array("\$res_get"), 'POST http://test.habariproject.org/post' => array("\$res_post")); print "<h1>Running tests</h1>\n"; $processors = array(new CURLRequestProcessor(), new SocketRequestProcessor()); foreach ($processors as $processor) { $rr = new RemoteRequest('http://test.habariproject.org/'); $rr->__set_processor($processor); $res = $rr->execute(); if ($res === TRUE) { $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0)); } else { $results[] = array(get_class($processor), $res); } $rr = new RemoteRequest('http://test.habariproject.org/get'); $rr->__set_processor($processor); $rr->set_params(array('query' => 'var', 'another' => 'variable')); $res_get = $rr->execute(); if ($res_get === TRUE) { $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0)); } else { $results[] = array(get_class($processor), $res_get); } $rr = new RemoteRequest('http://test.habariproject.org/post', 'POST'); $rr->__set_processor($processor); $rr->set_body('If you can read this, the test was successful.'); $res_post = $rr->execute(); if ($res_post === TRUE) { $results[] = array(get_class($processor), $rr->get_response_headers(), substr($rr->get_response_body(), 0)); } else { $results[] = array(get_class($processor), $res_post); } foreach ($tests as $name => $group) { print "<h2>{$name}</h2>\n"; foreach ($group as $test) { $result = eval('return (' . $test . ');'); printf("<p><strong>%s</strong> == ( %s )</p>\n", bs($result), var_export($test, TRUE)); Utils::debug(array_shift($results)); if (!$result) { $tests_failed[$name][] = $test; } } } } if (count($tests_failed)) { print "<h1>Failed tests</h1>\n"; foreach ($tests_failed as $name => $tests) { print "<h2>{$name}</h2>\n"; foreach ($tests as $test) { print "<p>{$test}</p>\n"; } } } else { print "<h1>All tests successful</h1>\n"; } }
public function action_plugin_act_display_column($handler) { Utils::debug(Posts::get(array('content_type' => Post::type('section'), 'nolimit' => TRUE, 'status' => Post::status('published'), 'orderby' => 'title ASC', 'fetch_fn' => 'get_perms'))); // Utils::debug($handler->handler_vars); }
<?php require_once 'config/config.conf.php'; try { $articles = Db::selectAll('SELECT * FROM posts LIMIT 5'); echo Utils::debug($articles); echo '<hr>'; $article = Db::selectOne('SELECT * FROM posts WHERE id = :id', array(':id' => 23)); echo Utils::debug($article); } catch (Exception $e) { echo $e->getMessage(); }
/** * Generate a new slug for the post. * * @return string The slug */ private function setslug() { // determine the base value from: // - the new slug if (isset($this->newfields['slug']) && $this->newfields['slug'] != '') { $value = $this->newfields['slug']; } elseif (isset($this->newfields['slug']) && $this->newfields['slug'] == '') { if ($this->fields['status'] == Post::status('draft') || $this->fields['status'] != Post::status('draft') && $this->newfields['status'] != Post::status('draft')) { if (isset($this->newfields['title']) && $this->newfields['title'] != '') { $value = $this->newfields['title']; } else { $value = $this->fields['title']; } } } elseif ($this->fields['slug'] != '') { $value = $this->fields['slug']; } elseif (isset($this->newfields['title']) && $this->newfields['title'] != '') { $value = $this->newfields['title']; } elseif ($this->fields['title'] != '') { $value = $this->fields['title']; } else { $value = 'Post'; } // make sure our slug is unique $slug = Plugins::filter('post_setslug', $value); $slug = Utils::slugify($slug); $postfix = ''; $postfixcount = 0; do { if (!($slugcount = DB::get_row('SELECT COUNT(slug) AS ct FROM {posts} WHERE slug = ?;', array($slug . $postfix)))) { Utils::debug(DB::get_errors()); exit; } if ($slugcount->ct != 0) { $postfix = "-" . ++$postfixcount; } } while ($slugcount->ct != 0); return $this->newfields['slug'] = $slug . $postfix; }
$rr->set_body( 'If you can read this, the test was successful.' ); $res_post= $rr->execute(); if ( $res_post === TRUE ) { $results[]= array( get_class( $processor ), $rr->get_response_headers(), substr( $rr->get_response_body(), 0 ) ); } else { $results[]= array( get_class( $processor ), $res_post, ); } foreach ( $tests as $name => $group ) { print( "<h2>{$name}</h2>\n" ); foreach ( $group as $test ) { $result= eval( 'return (' . $test . ');' ); printf( "<p><strong>%s</strong> == ( %s )</p>\n", bs( $result ), var_export( $test, TRUE ) ); Utils::debug( array_shift( $results ) ); if ( ! $result ) { $tests_failed[$name][]= $test; } } } } if ( count( $tests_failed ) ) { print( "<h1>Failed tests</h1>\n" ); foreach ( $tests_failed as $name => $tests ) { print( "<h2>{$name}</h2>\n" ); foreach ( $tests as $test ) { print( "<p>{$test}</p>\n" ); } }
public static function snipurl($url) { $call = new RemoteRequest('http://snipurl.com/site/getsnip', 'POST'); $call->set_params(array('sniplink' => $url, 'snipuser' => 'bcse', 'snipapi' => '9fa84accb6cee0451a91feaf37e961ad')); $call->set_timeout(5); $result = $call->execute(); if (Error::is_error($result)) { Utils::debug($call, $result); return FALSE; } $response = $call->get_response_body(); Utils::debug($response); $obj = new SimpleXMLElement($response); if ($obj instanceof SimpleXMLElement && isset($obj->id)) { return $obj->id; } return FALSE; }
public function search($search_term, $max_results = 10, $offset_index = 0) { $response = $this->api_get('search', array('query' => urlencode($search_term), 'results' => $max_results, 'offset' => $offset_index, 'auth' => $this->token, 'email' => $this->email)); if ($response['stats']['http_code'] == 200) { if (json_decode($response['body']) == '') { Utils::debug($response); } $response = json_decode($response['body']); $return = array('count' => $response->Response->totalRecords, 'results' => array()); if ($return['count'] > 0) { foreach ($response->Response->Results as $result) { if (!empty($result->key)) { $return['results'][$result->key] = $result->content; } } } return $return; } else { return false; } }
function put($method, $params = array(), $tokenize = false, $debug = false) { $url = $this->get_endpoint($method); if ($debug) { print_r($url); } $req = curl_init(); $params['api_key'] = $this->key; curl_setopt($req, CURLOPT_URL, $url); curl_setopt($req, CURLOPT_TIMEOUT, 0); // curl_setopt($req, CURLOPT_INFILESIZE, filesize($photo)); // Sign and build request parameters curl_setopt($req, CURLOPT_POSTFIELDS, $params); curl_setopt($req, CURLOPT_CONNECTTIMEOUT, $this->conntimeout); curl_setopt($req, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($req, CURLOPT_HEADER, 0); curl_setopt($req, CURLOPT_RETURNTRANSFER, 1); $this->_http_body = curl_exec($req); if (curl_errno($req)) { throw new Exception(curl_error($req)); } curl_close($req); $xml = simplexml_load_string($this->_http_body); if ($xml['stat'] == 'ok') { return $xml; } else { Utils::debug($xml, $params, $url); $result = false; } return $result; }
public function test_object_terms() { $post = Post::create( array( 'title' => 'Unit Test Post', 'content' => 'This is a unit test post to test setting and getting terms.', 'user_id' => 1, 'status' => Post::status( 'draft' ), 'content_type' => Post::type( 'entry' ), 'pubdate' => HabariDateTime::date_create(), ) ); $v = Vocabulary::get( 'tags' ); // Test setting terms with strings $new_terms = array( 'habari', 'unit test' ); $v->set_object_terms( 'post', $post->id, $new_terms ); $terms = $v->get_object_terms( 'post', $post->id ); $t = array(); foreach( $terms as $term ) { $t[] = (string)$term; } $this->assert_equal( 2, count( $terms ) ); $this->assert_equal( 0, count( array_diff( $new_terms, $t ) ) ); // Test get_all_object_terms $nv = Vocabulary::create( array( 'name' => 'animals', 'description' => 'Types of animals.', 'features' => array( 'hierarchical' ) ) ); $root = $nv->add_term( 'Animal Kingdom' ); $nv->set_object_terms( 'post', $post->id, array( $root ) ); $terms = Vocabulary::get_all_object_terms( 'post', $post->id ); $new_terms[] = 'Animal Kingdom'; $t = array(); foreach( $terms as $term ) { $t[] = (string)$term; } $this->assert_equal( 3, count( $terms ) ); Utils::debug( 3, count( $terms ) ); $this->assert_equal( 0, count( array_diff( $new_terms, $t ) ) ); Utils::debug( 0, count( array_diff( $new_terms, $t ) ) ); $v->delete_term( 'unit test' ); $post->delete(); $nv->delete(); }
/** * The plugin sink for the auth_ajax_mt_import_trackbacks hook. * Responds via authenticated ajax to requests for comment importing. * * @access public * @param AjaxHandler $handler The handler that handled the request, contains $_POST info */ public function action_auth_ajax_mt_mysql_import_trackbacks($handler) { $valid_fields = array('db_name', 'db_host', 'db_user', 'db_pass', 'db_prefix', 'blog_id', 'trackbackindex'); $inputs = Controller::get_handler_vars()->filter_keys($valid_fields)->getArrayCopy(); extract($inputs); $mtdb = $this->mt_connect($db_host, $db_name, $db_user, $db_pass, $db_prefix); if (!$mtdb) { EventLog::log(sprintf(_t('Failed to import from "%s"'), $db_name), 'crit'); echo '<p>' . _t('Failed to connect using the given database connection details.') . '</p>'; return; } $trackbackcount = $mtdb->get_value("SELECT count(trackback_id) FROM {$db_prefix}trackback WHERE trackback_blog_id = '{$blog_id}';"); $min = $trackbackindex * $this->import_batch + 1; $max = min(($trackbackindex + 1) * $this->import_batch, $trackbackcount); echo sprintf(_t('<p>Importing trackbacks %d-%d of %d.</p>'), $min, $max, $trackbackcount); $post_info = DB::get_results("SELECT post_id, value FROM " . DB::table('postinfo') . " WHERE name= 'mt_id';"); @reset($post_info); while (list(, $info) = @each($post_info)) { $post_map[$info->value] = $info->post_id; } $trackbacks = $mtdb->get_results("SELECT\n\t\t\ttrackback_title AS name,\n\t\t\ttrackback_url AS url,\n\t\t\ttrackback_description AS content,\n\t\t\ttrackback_created_on AS date,\n\t\t\ttrackback_entry_id AS mt_post_id,\n\t\t\ttrackback_id,\n\t\t\ttrackback_is_disabled\n\t\t\tFROM {$db_prefix}trackback\n\t\t\tWHERE trackback_blog_id = '{$blog_id}'\n\t\t\tLIMIT {$min}," . $this->import_batch, array(), 'Comment'); $comment_map = DB::get_column("SELECT value FROM " . DB::table('commentinfo') . " WHERE name='mt_trackback_id';"); @reset($trackbacks); while (list(, $trackback) = @each($trackback)) { // already exists skipped if (in_array($trackback->trackback_id, $comment_map)) { continue; } $trackback->type = Comment::TRACKBACK; $carray = $trackback->to_array(); $carray['ip'] = 0; if ($carray['trackback_is_disabled'] == 0) { $carray['status'] = Comment::STATUS_APPROVED; } else { $carray['status'] = Comment::STATUS_UNAPPROVED; } unset($carray['trackback_is_disabled']); if (!isset($post_map[$carray['mt_post_id']])) { Utils::debug($carray); } else { $carray['post_id'] = $post_map[$carray['wp_post_id']]; unset($carray['mt_post_id']); $trackback_id = $carray['trackback_id']; unset($carray['trackback_id']); $c = new Comment($carray); $c->info->mt_trackback_id = $trackback_id; try { $c->insert(); } catch (Exception $e) { EventLog::log($e->getMessage(), 'err', null, null, print_r(array($c, $e), 1)); $errors = Options::get('import_errors'); $errors[] = $e->getMessage(); Options::set('import_errors', $errors); } } } if ($max < $trackbackcount) { $ajax_url = URL::get('auth_ajax', array('context' => 'mt_mysql_import_trackbacks')); $trackbackindex++; } else { EventLog::log('Import complete from "' . $db_name . '"'); echo '<p>' . _t('Import is complete.') . '</p>'; $errors = Options::get('import_errors'); if (count($errors) > 0) { echo '<p>' . _t('There were errors during import:') . '</p>'; echo '<ul>'; foreach ($errors as $error) { echo '<li>' . $error . '</li>'; } echo '</ul>'; } return; } ?> <script type="text/javascript"> $( '#import_progress' ).load( "<?php echo $ajax_url; ?> ", { db_host: "<?php echo htmlspecialchars($db_host); ?> ", db_name: "<?php echo htmlspecialchars($db_name); ?> ", db_user: "******", db_pass: "******", db_prefix: "<?php echo htmlspecialchars($db_prefix); ?> ", blog_id: "<?php echo htmlspecialchars($blog_id); ?> ", trackbackindex: <?php echo $trackbackindex; ?> } ); </script> <?php }
/** * Prepare and display admin page * */ public function action_admin_theme_get_menus(AdminHandler $handler, Theme $theme) { $theme->page_content = ''; $action = isset($_GET['action']) ? $_GET['action'] : 'create'; switch ($action) { case 'edit': $vocabulary = Vocabulary::get_by_id(intval($handler->handler_vars['menu'])); if ($vocabulary == false) { $theme->page_content = '<h2>' . _t('Invalid Menu.'); // that's it, we're done. Maybe we show the list of menus instead? break; } $form = new FormUI('edit_menu'); $form->append(new FormControlText('menuname', 'null:null', _t('Name'), 'transparent_text'))->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab'))->value = $vocabulary->name; $form->append(new FormControlHidden('oldname', 'null:null'))->value = $vocabulary->name; $form->append(new FormControlText('description', 'null:null', _t('Description'), 'transparent_text'))->value = $vocabulary->description; $edit_items_array = $this->get_menu_type_data(); $edit_items = ''; foreach ($edit_items_array as $action => $menu_type) { $edit_items .= '<a class="modal_popup_form menu_button_dark" href="' . URL::get('admin', array('page' => 'menu_iframe', 'action' => $action, 'menu' => $vocabulary->id)) . "\">" . _t('Add %s', array($menu_type['label'])) . "</a>"; } if (!$vocabulary->is_empty()) { $form->append('tree', 'tree', $vocabulary->get_tree(), _t('Menu')); $form->tree->options = $vocabulary->get_tree(); $form->tree->config = array('itemcallback' => array($this, 'tree_item_callback')); // $form->tree->value = $vocabulary->get_root_terms(); // append other needed controls, if there are any. $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>'); $form->append('submit', 'save', _t('Apply Changes')); } else { $form->append('static', 'buttons', '<div id="menu_item_button_container">' . $edit_items . '</div>'); } $delete_link = URL::get('admin', Utils::WSSE(array('page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars['menu']))); //$delete_link = URL::get( 'admin', array( 'page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars[ 'menu' ] ) ); $form->append('static', 'deletebutton', '<a class="a_button" href="' . $delete_link . '">' . _t('Delete Menu') . '</a>'); $form->append(new FormControlHidden('menu', 'null:null'))->value = $handler->handler_vars['menu']; $form->on_success(array($this, 'rename_menu_form_save')); $form->properties['onsubmit'] = "return habari.menu_admin.submit_menu_update();"; $theme->page_content .= $form->get(); break; case 'create': $form = new FormUI('create_menu'); $form->append('text', 'menuname', 'null:null', _t('Menu Name'), 'transparent_text')->add_validator('validate_required', _t('You must supply a valid menu name'))->add_validator(array($this, 'validate_newvocab')); $form->append('text', 'description', 'null:null', _t('Description'), 'transparent_text'); $form->append('submit', 'submit', _t('Create Menu')); $form->on_success(array($this, 'add_menu_form_save')); $theme->page_content = $form->get(); break; case 'delete_menu': if (Utils::verify_wsse($_GET, true)) { $menu_vocab = Vocabulary::get_by_id(intval($handler->handler_vars['menu'])); // Delete blocks using this menu $at = Themes::get_active_data(true); $t = Themes::create(Themes::get_active()['name']); $i = 0; foreach ($at['areas'] as $area) { foreach ($t->get_blocks($area['name'], 0, $t) as $block) { if ($block->type == 'menu' && $block->menu_taxonomy == $handler->handler_vars['menu']) { $block->delete(); $i++; } } } Session::notice(sprintf(_n('%s block linking to this menu deleted.', '%s blocks linking to this menu deleted.', $i), $i)); $menu_vocab->delete(); // log that it has been deleted? Session::notice(_t('Menu deleted.')); // redirect to a blank menu creation form Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'create'))); } else { Session::notice(_t('Menu deletion failed - please try again.')); Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $handler->handler_vars['menu']))); } break; case 'delete_term': $term = Term::get(intval($handler->handler_vars['term'])); $menu_vocab = $term->vocabulary_id; if (Utils::verify_wsse($_GET, true)) { $term->delete(); // log that it has been deleted? Session::notice(_t('Item deleted.')); Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab))); } else { Session::notice(_t('Item deletion failed - please try again.')); Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab))); } break; default: Utils::debug($_GET, $action); die; } $theme->display('menus_admin'); // End everything exit; }
/** * @todo the server should return all versions and let hpm decide which version to take */ public static function update_packages($repo) { $client = new RemoteRequest($repo, 'GET'); if (Error::is_error($client->execute())) { return false; } try { $packages = $client->get_response_body(); //Utils::debug( $packages ); $packages = new SimpleXMLElement($packages); $package_list = array(); foreach ($packages->package as $package) { if (!$package['guid'] || !$package->versions) { continue; } $new_package = (array) $package->attributes(); $new_package = $new_package['@attributes']; $new_package['description'] = strval($package->description); $versions = array(); //Utils::debug($package->versions); foreach ($package->versions->version as $version) { $version = (array) $version->attributes(); $version = $version['@attributes']; if (isset($version['habari_version']) && self::is_compatible($version['habari_version'])) { $versions[$version['version']] = $version; } } //Utils::debug( $new_package, $versions ); uksort($versions, create_function('$a,$b', 'return version_compare($b,$a);')); $version = current($versions); if ($version) { $new_package = array_merge($version, $new_package); if ($old_package = HabariPackage::get($new_package['guid'])) { if (isset($new_package['version']) && version_compare($new_package['version'], $old_package->version, '>')) { if ($old_package->status == 'installed') { $new_package['status'] = 'upgrade'; } DB::update(DB::table('packages'), $new_package, array('guid' => $new_package['guid'])); $package_list[] = $old_package->id; } else { $package_list[] = $old_package->id; } } else { DB::insert(DB::table('packages'), $new_package); $package_list[] = DB::last_insert_id(); } } } Options::set('hpm__repo_version', Version::get_habariversion()); return $package_list; } catch (Exception $e) { Utils::debug($e); return false; } }
/** * Prepare and display admin page * **/ public function action_admin_theme_get_menus(AdminHandler $handler, Theme $theme) { $theme->page_content = ''; $action = isset($_GET['action']) ? $_GET['action'] : 'create'; switch ($action) { case 'edit': $vocabulary = Vocabulary::get_by_id(intval($handler->handler_vars['menu'])); if ($vocabulary == false) { $theme->page_content = _t('<h2>Invalid Menu.</h2>', 'termmenus'); // that's it, we're done. Maybe we show the list of menus instead? break; } $form = new FormUI('edit_menu'); $form->append(new FormControlText('menuname', 'null:null', _t('Name', 'termmenus'), 'transparent_text'))->add_validator('validate_required', _t('You must supply a valid menu name', 'termmenus'))->add_validator(array($this, 'validate_newvocab'))->value = $vocabulary->name; $form->append(new FormControlHidden('oldname', 'null:null'))->value = $vocabulary->name; $form->append(new FormControlText('description', 'null:null', _t('Description', 'termmenus'), 'transparent_text'))->value = $vocabulary->description; $edit_items_array = $this->get_menu_type_data(); $edit_items = ''; foreach ($edit_items_array as $action => $menu_type) { $edit_items .= '<a class="modal_popup_form menu_button_dark" href="' . URL::get('admin', array('page' => 'menu_iframe', 'action' => $action, 'menu' => $vocabulary->id)) . "\">" . _t('Add %s', array($menu_type['label']), 'termmenus') . "</a>"; } if (!$vocabulary->is_empty()) { $form->append('tree', 'tree', $vocabulary->get_tree(), _t('Menu', 'termmenus')); $form->tree->config = array('itemcallback' => array($this, 'tree_item_callback')); // $form->tree->value = $vocabulary->get_root_terms(); // append other needed controls, if there are any. $form->append('static', 'buttons', _t("<div id='menu_item_button_container'>{$edit_items}</div>", 'termmenus')); $form->append('submit', 'save', _t('Apply Changes', 'termmenus')); } else { $form->append('static', 'buttons', _t("<div id='menu_item_button_container'>{$edit_items}</div>", 'termmenus')); } $delete_link = URL::get('admin', array('page' => 'menus', 'action' => 'delete_menu', 'menu' => $handler->handler_vars['menu'])); $form->append('static', 'deletebutton', _t("<a class='a_button' href='{$delete_link}'>Delete Menu</a>", 'termmenus')); $form->append(new FormControlHidden('menu', 'null:null'))->value = $handler->handler_vars['menu']; $form->on_success(array($this, 'rename_menu_form_save')); $form->properties['onsubmit'] = "return habari.menu_admin.submit_menu_update();"; $theme->page_content .= $form->get(); break; case 'create': $form = new FormUI('create_menu'); $form->append('text', 'menuname', 'null:null', _t('Menu Name', 'termmenus'), 'transparent_text')->add_validator('validate_required', _t('You must supply a valid menu name', 'termmenus'))->add_validator(array($this, 'validate_newvocab')); $form->append('text', 'description', 'null:null', _t('Description', 'termmenus'), 'transparent_text'); $form->append('submit', 'submit', _t('Create Menu', 'termmenus')); $form->on_success(array($this, 'add_menu_form_save')); $theme->page_content = $form->get(); break; case 'delete_menu': $menu_vocab = Vocabulary::get_by_id(intval($handler->handler_vars['menu'])); $menu_vocab->delete(); // log that it has been deleted? Session::notice(_t('Menu deleted.', 'termmenus')); // redirect to a blank menu creation form Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'create'))); break; case 'delete_term': $term = Term::get(intval($handler->handler_vars['term'])); $menu_vocab = $term->vocabulary_id; $term->delete(); // log that it has been deleted? Session::notice(_t('Item deleted.', 'termmenus')); Utils::redirect(URL::get('admin', array('page' => 'menus', 'action' => 'edit', 'menu' => $menu_vocab))); break; default: Utils::debug($_GET, $action); die; } $theme->display('menus_admin'); // End everything exit; }
/** * Generate a new slug for the post. * * @return string The slug */ private function setslug() { // determine the base value from: // - the new slug // If the slug is new and has a length if ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] != '' ) { $value = $this->newfields['slug']; } // - the new empty slug whilst in draft or progressing directly to published or scheduled from draft. // - Also allow changing of slug whilst in scheduled state // // This happens when a draft is being updated, or a post is being directly published or scheduled, // or an existing scheduled or published post is being updated, but not made into a draft // // If a new slug is set, and it doesn't have a length elseif ( isset( $this->newfields['slug'] ) && $this->newfields['slug'] == '' ) { // If the existing status of the post is draft, no matter what status it is being changed to if ( $this->fields['status'] == Post::status( 'draft' ) || ( // or the existing status is not draft and the new status is not draft $this->fields['status'] != Post::status( 'draft' ) && $this->newfields['status'] != Post::status( 'draft' ) ) ) { // And a new title is set, use the new title if ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // Otherwise, use the existing title else { $value = $this->fields['title']; } } } // - the existing slug // If there is an existing slug, and it has a length elseif ( $this->fields['slug'] != '' ) { $value = $this->fields['slug']; } // - the new post title // If there is a new title, and it has a length elseif ( isset( $this->newfields['title'] ) && $this->newfields['title'] != '' ) { $value = $this->newfields['title']; } // - the existing post title // If there is an existing title, and it has a length elseif ( $this->fields['title'] != '' ) { $value = $this->fields['title']; } // - default //Nothing else worked. Default to 'Post' else { $value = 'Post'; } // make sure our slug is unique $slug = Plugins::filter( 'post_setslug', $value ); $slug = Utils::slugify( $slug ); $postfix = ''; $postfixcount = 0; do { if ( ! $slugcount = DB::get_row( 'SELECT COUNT(slug) AS ct FROM {posts} WHERE slug = ?;', array( $slug . $postfix ) ) ) { Utils::debug( DB::get_errors() ); exit; } if ( $slugcount->ct != 0 ) { $postfix = "-" . ( ++$postfixcount ); } } while ( $slugcount->ct != 0 ); return $this->newfields['slug'] = $slug . $postfix; }
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" [ <!ATTLIST html habari CDATA #IMPLIED> ] > <html> <head habari="rocks"> <title>Foo Bar</title> </head> <body> <h1>Hello World</h1> <p>This is a good <a href="http://google.com/search?q=html">HTML</a> document.</p> <![CDATA[This is & <a href="foo">CDATA</a>.]]><strong>Lo bob</strong>. </body> </html> _EOF_; $html_strs[] = <<<_EOF_ <html><title>Oh 'eck!<body>This is a badly tag-soupy HTML document.</html> _EOF_; $html_strs[] = <<<_EOF_ <html> <head><title>Hey</title></head> <body onLoad="window.alert('zomg.');"> <p onClick="window.alert('stole yer cookies!');">Do not click here.</p> <script>alert("See this?")</script> </body> </html> _EOF_; foreach ($html_strs as $html_str) { $t = new HTMLTokenizer($html_str); $tokens = $t->parse(); Utils::debug($html_str, $tokens); }